Fossil SCM

On this branch, the schema makes use of the STRICT keyword new to SQLite 3.37.0. Fossil does not benefit from this. The point of this branch is to beta-test the new STRICT mode of SQLite.

drh 2021-10-22 10:10 trunk
Commit 632ffb82e1658722fa5796a1a430030d8ec703f991775464ebc02639219c2c79
+1 -1
--- auto.def
+++ auto.def
@@ -32,11 +32,11 @@
3232
}
3333
3434
# Update the minimum required SQLite version number here, and also
3535
# in src/main.c near the sqlite3_libversion_number() call. Take care
3636
# that both places agree!
37
-define MINIMUM_SQLITE_VERSION "3.35.0"
37
+define MINIMUM_SQLITE_VERSION "3.37.0"
3838
3939
# This is useful for people wanting Fossil to use an external SQLite library
4040
# to compare the one they have against the minimum required
4141
if {[opt-bool print-minimum-sqlite-version]} {
4242
puts [get-define MINIMUM_SQLITE_VERSION]
4343
--- auto.def
+++ auto.def
@@ -32,11 +32,11 @@
32 }
33
34 # Update the minimum required SQLite version number here, and also
35 # in src/main.c near the sqlite3_libversion_number() call. Take care
36 # that both places agree!
37 define MINIMUM_SQLITE_VERSION "3.35.0"
38
39 # This is useful for people wanting Fossil to use an external SQLite library
40 # to compare the one they have against the minimum required
41 if {[opt-bool print-minimum-sqlite-version]} {
42 puts [get-define MINIMUM_SQLITE_VERSION]
43
--- auto.def
+++ auto.def
@@ -32,11 +32,11 @@
32 }
33
34 # Update the minimum required SQLite version number here, and also
35 # in src/main.c near the sqlite3_libversion_number() call. Take care
36 # that both places agree!
37 define MINIMUM_SQLITE_VERSION "3.37.0"
38
39 # This is useful for people wanting Fossil to use an external SQLite library
40 # to compare the one they have against the minimum required
41 if {[opt-bool print-minimum-sqlite-version]} {
42 puts [get-define MINIMUM_SQLITE_VERSION]
43
+2 -2
--- src/main.c
+++ src/main.c
@@ -698,12 +698,12 @@
698698
fossil_limit_memory(1);
699699
700700
/* When updating the minimum SQLite version, change the number here,
701701
** and also MINIMUM_SQLITE_VERSION value set in ../auto.def. Take
702702
** care that both places agree! */
703
- if( sqlite3_libversion_number()<3035000 ){
704
- fossil_panic("Unsuitable SQLite version %s, must be at least 3.35.0",
703
+ if( sqlite3_libversion_number()<3037000 ){
704
+ fossil_panic("Unsuitable SQLite version %s, must be at least 3.37.0",
705705
sqlite3_libversion());
706706
}
707707
708708
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
709709
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
710710
--- src/main.c
+++ src/main.c
@@ -698,12 +698,12 @@
698 fossil_limit_memory(1);
699
700 /* When updating the minimum SQLite version, change the number here,
701 ** and also MINIMUM_SQLITE_VERSION value set in ../auto.def. Take
702 ** care that both places agree! */
703 if( sqlite3_libversion_number()<3035000 ){
704 fossil_panic("Unsuitable SQLite version %s, must be at least 3.35.0",
705 sqlite3_libversion());
706 }
707
708 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
709 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
710
--- src/main.c
+++ src/main.c
@@ -698,12 +698,12 @@
698 fossil_limit_memory(1);
699
700 /* When updating the minimum SQLite version, change the number here,
701 ** and also MINIMUM_SQLITE_VERSION value set in ../auto.def. Take
702 ** care that both places agree! */
703 if( sqlite3_libversion_number()<3037000 ){
704 fossil_panic("Unsuitable SQLite version %s, must be at least 3.37.0",
705 sqlite3_libversion());
706 }
707
708 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
709 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
710
+46 -46
--- src/schema.c
+++ src/schema.c
@@ -82,15 +82,15 @@
8282
@ rcvid INTEGER, -- Origin of this record
8383
@ size INTEGER, -- Size of content. -1 for a phantom.
8484
@ uuid TEXT UNIQUE NOT NULL, -- hash of the content
8585
@ content BLOB, -- Compressed content of this record
8686
@ CHECK( length(uuid)>=40 AND rid>0 )
87
-@ );
87
+@ ) STRICT;
8888
@ CREATE TABLE delta(
8989
@ rid INTEGER PRIMARY KEY, -- BLOB that is delta-compressed
9090
@ srcid INTEGER NOT NULL REFERENCES blob -- Baseline for delta-compression
91
-@ );
91
+@ ) STRICT;
9292
@ CREATE INDEX delta_i1 ON delta(srcid);
9393
@
9494
@ -------------------------------------------------------------------------
9595
@ -- The BLOB and DELTA tables above hold the "global state" of a Fossil
9696
@ -- project; the stuff that is normally exchanged during "sync". The
@@ -102,14 +102,14 @@
102102
@ -- in this table records the source of the blob.
103103
@ --
104104
@ CREATE TABLE rcvfrom(
105105
@ rcvid INTEGER PRIMARY KEY, -- Received-From ID
106106
@ uid INTEGER REFERENCES user, -- User login
107
-@ mtime DATETIME, -- Time of receipt. Julian day.
107
+@ mtime REAL, -- Time of receipt. Julian day.
108108
@ nonce TEXT UNIQUE, -- Nonce used for login
109109
@ ipaddr TEXT -- Remote IP address. NULL for direct.
110
-@ );
110
+@ ) STRICT;
111111
@
112112
@ -- Information about users
113113
@ --
114114
@ -- The user.pw field can be either cleartext of the password, or
115115
@ -- a SHA1 hash of the password. If the user.pw field is exactly 40
@@ -134,14 +134,14 @@
134134
@ -- The config table holds miscellanous information about the repository.
135135
@ -- in the form of name-value pairs.
136136
@ --
137137
@ CREATE TABLE config(
138138
@ name TEXT PRIMARY KEY NOT NULL, -- Primary name of the entry
139
-@ value CLOB, -- Content of the named parameter
140
-@ mtime DATE, -- last modified. seconds since 1970
141
-@ CHECK( typeof(name)='text' AND length(name)>=1 )
142
-@ );
139
+@ value ANY, -- Content of the named parameter
140
+@ mtime INT, -- last modified. seconds since 1970
141
+@ CHECK( length(name)>=1 )
142
+@ ) STRICT;
143143
@
144144
@ -- Artifacts that should not be processed are identified in the
145145
@ -- "shun" table. Artifacts that are control-file forgeries or
146146
@ -- spam or artifacts whose contents violate administrative policy
147147
@ -- can be shunned in order to prevent them from contaminating
@@ -150,14 +150,14 @@
150150
@ -- Shunned artifacts do not exist in the blob table. Hence they
151151
@ -- have not artifact ID (rid) and we thus must store their full
152152
@ -- UUID.
153153
@ --
154154
@ CREATE TABLE shun(
155
-@ uuid UNIQUE, -- UUID of artifact to be shunned. Canonical form
156
-@ mtime DATE, -- When added. seconds since 1970
157
-@ scom TEXT -- Optional text explaining why the shun occurred
158
-@ );
155
+@ uuid TEXT PRIMARY KEY, -- UUID of artifact to be shunned. Canonical form
156
+@ mtime INT, -- When added. seconds since 1970
157
+@ scom TEXT -- Optional text explaining why the shun occurred
158
+@ ) WITHOUT ROWID, STRICT;
159159
@
160160
@ -- Artifacts that should not be pushed are stored in the "private"
161161
@ -- table. Private artifacts are omitted from the "unclustered" and
162162
@ -- "unsent" tables.
163163
@ --
@@ -174,14 +174,14 @@
174174
@ --
175175
@ CREATE TABLE reportfmt(
176176
@ rn INTEGER PRIMARY KEY, -- Report number
177177
@ owner TEXT, -- Owner of this report format (not used)
178178
@ title TEXT UNIQUE, -- Title of this report
179
-@ mtime DATE, -- Last modified. seconds since 1970
179
+@ mtime REAL, -- Last modified. seconds since 1970
180180
@ cols TEXT, -- A color-key specification
181181
@ sqlcode TEXT -- An SQL SELECT statement for this report
182
-@ );
182
+@ ) STRICT;
183183
@
184184
@ -- Some ticket content (such as the originators email address or contact
185185
@ -- information) needs to be obscured to protect privacy. This is achieved
186186
@ -- by storing an SHA1 hash of the content. For display, the hash is
187187
@ -- mapped back into the original text using this table.
@@ -189,13 +189,13 @@
189189
@ -- This table contains sensitive information and should not be shared
190190
@ -- with unauthorized users.
191191
@ --
192192
@ CREATE TABLE concealed(
193193
@ hash TEXT PRIMARY KEY, -- The SHA1 hash of content
194
-@ mtime DATE, -- Time created. Seconds since 1970
194
+@ mtime INT, -- Time created. Seconds since 1970
195195
@ content TEXT -- Content intended to be concealed
196
-@ );
196
+@ ) STRICT;
197197
@
198198
@ -- The application ID helps the unix "file" command to identify the
199199
@ -- database as a fossil repository.
200200
@ PRAGMA application_id=252006673;
201201
;
@@ -232,11 +232,11 @@
232232
@ -- Filenames
233233
@ --
234234
@ CREATE TABLE filename(
235235
@ fnid INTEGER PRIMARY KEY, -- Filename ID
236236
@ name TEXT UNIQUE -- Name of file page
237
-@ );
237
+@ ) STRICT;
238238
@
239239
@ -- Linkages between check-ins, files created by each check-in, and
240240
@ -- the names of those files.
241241
@ --
242242
@ -- Each entry represents a file that changed content from pid to fid
@@ -268,12 +268,12 @@
268268
@ pmid INTEGER, -- Check-in that contains pid
269269
@ pid INTEGER, -- Prev file content. 0 if new. -1 merge
270270
@ fnid INTEGER REFERENCES filename, -- Name of the file
271271
@ pfnid INTEGER, -- Previous name. 0 if unchanged
272272
@ mperm INTEGER, -- File permissions. 1==exec
273
-@ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
274
-@ );
273
+@ isaux INT DEFAULT 0 -- TRUE if pmid is the primary
274
+@ ) STRICT;
275275
@ CREATE INDEX mlink_i1 ON mlink(mid);
276276
@ CREATE INDEX mlink_i2 ON mlink(fnid);
277277
@ CREATE INDEX mlink_i3 ON mlink(fid);
278278
@ CREATE INDEX mlink_i4 ON mlink(pid);
279279
@
@@ -280,15 +280,15 @@
280280
@ -- Parent/child linkages between check-ins
281281
@ --
282282
@ CREATE TABLE plink(
283283
@ pid INTEGER REFERENCES blob, -- Parent manifest
284284
@ cid INTEGER REFERENCES blob, -- Child manifest
285
-@ isprim BOOLEAN, -- pid is the primary parent of cid
286
-@ mtime DATETIME, -- the date/time stamp on cid. Julian day.
285
+@ isprim INT, -- pid is the primary parent of cid
286
+@ mtime REAL, -- the date/time stamp on cid. Julian day.
287287
@ baseid INTEGER REFERENCES blob, -- Baseline if cid is a delta manifest.
288288
@ UNIQUE(pid, cid)
289
-@ );
289
+@ ) STRICT;
290290
@ CREATE INDEX plink_i2 ON plink(cid,pid);
291291
@
292292
@ -- A "leaf" check-in is a check-in that has no children in the same
293293
@ -- branch. The set of all leaves is easily computed with a join,
294294
@ -- between the plink and tagxref tables, but it is a slower join for
@@ -306,22 +306,22 @@
306306
@ -- t Ticket changes
307307
@ -- w Wiki page edit
308308
@ --
309309
@ CREATE TABLE event(
310310
@ type TEXT, -- Type of event: ci, e, f, g, t, w
311
-@ mtime DATETIME, -- Time of occurrence. Julian day.
311
+@ mtime REAL, -- Time of occurrence. Julian day.
312312
@ objid INTEGER PRIMARY KEY, -- Associated record ID
313313
@ tagid INTEGER, -- Associated ticket or wiki name tag
314314
@ uid INTEGER REFERENCES user, -- User who caused the event
315315
@ bgcolor TEXT, -- Color set by 'bgcolor' property
316316
@ euser TEXT, -- User set by 'user' property
317317
@ user TEXT, -- Name of the user
318318
@ ecomment TEXT, -- Comment set by 'comment' property
319319
@ comment TEXT, -- Comment describing the event
320320
@ brief TEXT, -- Short comment when tagid already seen
321
-@ omtime DATETIME -- Original unchanged date+time, or NULL
322
-@ );
321
+@ omtime REAL -- Original unchanged date+time, or NULL
322
+@ ) STRICT;
323323
@ CREATE INDEX event_i1 ON event(mtime);
324324
@
325325
@ -- A record of phantoms. A phantom is a record for which we know the
326326
@ -- file hash but we do not (yet) know the file content.
327327
@ --
@@ -334,11 +334,11 @@
334334
@ -- We have to track all orphan manifests so that when the baseline arrives,
335335
@ -- we know to process the orphaned deltas.
336336
@ CREATE TABLE orphan(
337337
@ rid INTEGER PRIMARY KEY, -- Delta manifest with a phantom baseline
338338
@ baseline INTEGER -- Phantom baseline of this orphan
339
-@ );
339
+@ ) STRICT;
340340
@ CREATE INDEX orphan_baseline ON orphan(baseline);
341341
@
342342
@ -- Unclustered records. An unclustered record is a record (including
343343
@ -- a cluster records themselves) that is not mentioned by some other
344344
@ -- cluster.
@@ -370,11 +370,11 @@
370370
@ -- NAME is the symbolic name.
371371
@ --
372372
@ CREATE TABLE tag(
373373
@ tagid INTEGER PRIMARY KEY, -- Numeric tag ID
374374
@ tagname TEXT UNIQUE -- Tag name.
375
-@ );
375
+@ ) STRICT;
376376
@ INSERT INTO tag VALUES(1, 'bgcolor'); -- TAG_BGCOLOR
377377
@ INSERT INTO tag VALUES(2, 'comment'); -- TAG_COMMENT
378378
@ INSERT INTO tag VALUES(3, 'user'); -- TAG_USER
379379
@ INSERT INTO tag VALUES(4, 'date'); -- TAG_DATE
380380
@ INSERT INTO tag VALUES(5, 'hidden'); -- TAG_HIDDEN
@@ -394,14 +394,14 @@
394394
@ tagid INTEGER REFERENCES tag, -- The tag that added or removed
395395
@ tagtype INTEGER, -- 0:-,cancel 1:+,single 2:*,propagate
396396
@ srcid INTEGER REFERENCES blob, -- Artifact of tag. 0 for propagated tags
397397
@ origid INTEGER REFERENCES blob, -- check-in holding propagated tag
398398
@ value TEXT, -- Value of the tag. Might be NULL.
399
-@ mtime TIMESTAMP, -- Time of addition or removal. Julian day
400
-@ rid INTEGER REFERENCE blob, -- Artifact tag is applied to
399
+@ mtime REAL, -- Time of addition or removal. Julian day
400
+@ rid INTEGER REFERENCES blob, -- Artifact tag is applied to
401401
@ UNIQUE(rid, tagid)
402
-@ );
402
+@ ) STRICT;
403403
@ CREATE INDEX tagxref_i1 ON tagxref(tagid, mtime);
404404
@
405405
@ -- When a hyperlink occurs from one artifact to another (for example
406406
@ -- when a check-in comment refers to a ticket) an entry is made in
407407
@ -- the following table for that hyperlink. This table is used to
@@ -409,28 +409,28 @@
409409
@ --
410410
@ CREATE TABLE backlink(
411411
@ target TEXT, -- Where the hyperlink points to
412412
@ srctype INT, -- 0=comment 1=ticket 2=wiki. See BKLNK_* below.
413413
@ srcid INT, -- EVENT.OBJID for the source document
414
-@ mtime TIMESTAMP, -- time that the hyperlink was added. Julian day.
414
+@ mtime REAL, -- time that the hyperlink was added. Julian day.
415415
@ UNIQUE(target, srctype, srcid)
416
-@ );
416
+@ ) STRICT;
417417
@ CREATE INDEX backlink_src ON backlink(srcid, srctype);
418418
@
419419
@ -- Each attachment is an entry in the following table. Only
420420
@ -- the most recent attachment (identified by the D card) is saved.
421421
@ --
422422
@ CREATE TABLE attachment(
423423
@ attachid INTEGER PRIMARY KEY, -- Local id for this attachment
424
-@ isLatest BOOLEAN DEFAULT 0, -- True if this is the one to use
425
-@ mtime TIMESTAMP, -- Last changed. Julian day.
424
+@ isLatest INT DEFAULT 0, -- True if this is the one to use
425
+@ mtime REAL, -- Last changed. Julian day.
426426
@ src TEXT, -- Hash of the attachment. NULL to delete
427427
@ target TEXT, -- Object attached to. Wikiname or Tkt hash
428428
@ filename TEXT, -- Filename for the attachment
429429
@ comment TEXT, -- Comment associated with this attachment
430430
@ user TEXT -- Name of user adding attachment
431
-@ );
431
+@ ) STRICT;
432432
@ CREATE INDEX attachment_idx1 ON attachment(target, filename, mtime);
433433
@ CREATE INDEX attachment_idx2 ON attachment(src);
434434
@
435435
@ -- Template for the TICKET table
436436
@ --
@@ -470,13 +470,13 @@
470470
@
471471
@ -- For tracking cherrypick merges
472472
@ CREATE TABLE cherrypick(
473473
@ parentid INT,
474474
@ childid INT,
475
-@ isExclude BOOLEAN DEFAULT false,
475
+@ isExclude INT DEFAULT false,
476476
@ PRIMARY KEY(parentid, childid)
477
-@ ) WITHOUT ROWID;
477
+@ ) WITHOUT ROWID, STRICT;
478478
@ CREATE INDEX cherrypick_cid ON cherrypick(childid);
479479
;
480480
481481
/*
482482
** Allowed values for backlink.srctype
@@ -523,13 +523,13 @@
523523
@ -- repository Full pathname of the repository database
524524
@ -- user-id Userid to use
525525
@ --
526526
@ CREATE TABLE vvar(
527527
@ name TEXT PRIMARY KEY NOT NULL, -- Primary name of the entry
528
-@ value CLOB, -- Content of the named parameter
529
-@ CHECK( typeof(name)='text' AND length(name)>=1 )
530
-@ );
528
+@ value ANY, -- Content of the named parameter
529
+@ CHECK( length(name)>=1 )
530
+@ ) STRICT, WITHOUT ROWID;
531531
@
532532
@ -- Each entry in the vfile table represents a single file in the
533533
@ -- current checkout.
534534
@ --
535535
@ -- The file.rid field is 0 for files or folders that have been
@@ -544,21 +544,21 @@
544544
@ --
545545
@ CREATE TABLE vfile(
546546
@ id INTEGER PRIMARY KEY, -- ID of the checked out file
547547
@ vid INTEGER REFERENCES blob, -- The checkin this file is part of.
548548
@ chnged INT DEFAULT 0, -- 0:unchng 1:edit 2:m-chng 3:m-add 4:i-chng 5:i-add
549
-@ deleted BOOLEAN DEFAULT 0, -- True if deleted
550
-@ isexe BOOLEAN, -- True if file should be executable
551
-@ islink BOOLEAN, -- True if file should be symlink
549
+@ deleted INT DEFAULT 0, -- True if deleted
550
+@ isexe INT, -- True if file should be executable
551
+@ islink INT, -- True if file should be symlink
552552
@ rid INTEGER, -- Originally from this repository record
553553
@ mrid INTEGER, -- Based on this record due to a merge
554554
@ mtime INTEGER, -- Mtime of file on disk. sec since 1970
555555
@ pathname TEXT, -- Full pathname relative to root
556556
@ origname TEXT, -- Original pathname. NULL if unchanged
557557
@ mhash TEXT, -- Hash of mrid iff mrid!=rid
558558
@ UNIQUE(pathname,vid)
559
-@ );
559
+@ ) STRICT;
560560
@
561561
@ -- Identifier for this file type.
562562
@ -- The integer is the same as 'FSLC'.
563563
@ PRAGMA application_id=252006674;
564564
;
@@ -579,11 +579,11 @@
579579
@
580580
@ CREATE TABLE vmerge(
581581
@ id INTEGER REFERENCES vfile, -- VFILE entry that has been merged
582582
@ merge INTEGER, -- Merged with this record
583583
@ mhash TEXT -- SHA1/SHA3 hash for merge object
584
-@ );
584
+@ ) STRICT;
585585
@ CREATE UNIQUE INDEX vmergex1 ON vmerge(id,mhash);
586586
@
587587
@ -- The following trigger will prevent older versions of Fossil that
588588
@ -- do not know about the new vmerge.mhash column from updating the
589589
@ -- vmerge table. This must be done with a trigger, since legacy Fossil
@@ -608,15 +608,15 @@
608608
@ fpid INTEGER PRIMARY KEY, -- BLOB.rid for the artifact
609609
@ froot INT, -- fpid of the thread root
610610
@ fprev INT, -- Previous version of this same post
611611
@ firt INT, -- This post is in-reply-to
612612
@ fmtime REAL -- When posted. Julian day
613
-@ );
613
+@ ) STRICT;
614614
@ CREATE INDEX repository.forumthread ON forumpost(froot,fmtime);
615615
;
616616
617617
/* Create the forum-post schema if it does not already exist */
618618
void schema_forum(void){
619619
if( !db_table_exists("repository","forumpost") ){
620620
db_multi_exec("%s",zForumSchema/*safe-for-%s*/);
621621
}
622622
}
623623
--- src/schema.c
+++ src/schema.c
@@ -82,15 +82,15 @@
82 @ rcvid INTEGER, -- Origin of this record
83 @ size INTEGER, -- Size of content. -1 for a phantom.
84 @ uuid TEXT UNIQUE NOT NULL, -- hash of the content
85 @ content BLOB, -- Compressed content of this record
86 @ CHECK( length(uuid)>=40 AND rid>0 )
87 @ );
88 @ CREATE TABLE delta(
89 @ rid INTEGER PRIMARY KEY, -- BLOB that is delta-compressed
90 @ srcid INTEGER NOT NULL REFERENCES blob -- Baseline for delta-compression
91 @ );
92 @ CREATE INDEX delta_i1 ON delta(srcid);
93 @
94 @ -------------------------------------------------------------------------
95 @ -- The BLOB and DELTA tables above hold the "global state" of a Fossil
96 @ -- project; the stuff that is normally exchanged during "sync". The
@@ -102,14 +102,14 @@
102 @ -- in this table records the source of the blob.
103 @ --
104 @ CREATE TABLE rcvfrom(
105 @ rcvid INTEGER PRIMARY KEY, -- Received-From ID
106 @ uid INTEGER REFERENCES user, -- User login
107 @ mtime DATETIME, -- Time of receipt. Julian day.
108 @ nonce TEXT UNIQUE, -- Nonce used for login
109 @ ipaddr TEXT -- Remote IP address. NULL for direct.
110 @ );
111 @
112 @ -- Information about users
113 @ --
114 @ -- The user.pw field can be either cleartext of the password, or
115 @ -- a SHA1 hash of the password. If the user.pw field is exactly 40
@@ -134,14 +134,14 @@
134 @ -- The config table holds miscellanous information about the repository.
135 @ -- in the form of name-value pairs.
136 @ --
137 @ CREATE TABLE config(
138 @ name TEXT PRIMARY KEY NOT NULL, -- Primary name of the entry
139 @ value CLOB, -- Content of the named parameter
140 @ mtime DATE, -- last modified. seconds since 1970
141 @ CHECK( typeof(name)='text' AND length(name)>=1 )
142 @ );
143 @
144 @ -- Artifacts that should not be processed are identified in the
145 @ -- "shun" table. Artifacts that are control-file forgeries or
146 @ -- spam or artifacts whose contents violate administrative policy
147 @ -- can be shunned in order to prevent them from contaminating
@@ -150,14 +150,14 @@
150 @ -- Shunned artifacts do not exist in the blob table. Hence they
151 @ -- have not artifact ID (rid) and we thus must store their full
152 @ -- UUID.
153 @ --
154 @ CREATE TABLE shun(
155 @ uuid UNIQUE, -- UUID of artifact to be shunned. Canonical form
156 @ mtime DATE, -- When added. seconds since 1970
157 @ scom TEXT -- Optional text explaining why the shun occurred
158 @ );
159 @
160 @ -- Artifacts that should not be pushed are stored in the "private"
161 @ -- table. Private artifacts are omitted from the "unclustered" and
162 @ -- "unsent" tables.
163 @ --
@@ -174,14 +174,14 @@
174 @ --
175 @ CREATE TABLE reportfmt(
176 @ rn INTEGER PRIMARY KEY, -- Report number
177 @ owner TEXT, -- Owner of this report format (not used)
178 @ title TEXT UNIQUE, -- Title of this report
179 @ mtime DATE, -- Last modified. seconds since 1970
180 @ cols TEXT, -- A color-key specification
181 @ sqlcode TEXT -- An SQL SELECT statement for this report
182 @ );
183 @
184 @ -- Some ticket content (such as the originators email address or contact
185 @ -- information) needs to be obscured to protect privacy. This is achieved
186 @ -- by storing an SHA1 hash of the content. For display, the hash is
187 @ -- mapped back into the original text using this table.
@@ -189,13 +189,13 @@
189 @ -- This table contains sensitive information and should not be shared
190 @ -- with unauthorized users.
191 @ --
192 @ CREATE TABLE concealed(
193 @ hash TEXT PRIMARY KEY, -- The SHA1 hash of content
194 @ mtime DATE, -- Time created. Seconds since 1970
195 @ content TEXT -- Content intended to be concealed
196 @ );
197 @
198 @ -- The application ID helps the unix "file" command to identify the
199 @ -- database as a fossil repository.
200 @ PRAGMA application_id=252006673;
201 ;
@@ -232,11 +232,11 @@
232 @ -- Filenames
233 @ --
234 @ CREATE TABLE filename(
235 @ fnid INTEGER PRIMARY KEY, -- Filename ID
236 @ name TEXT UNIQUE -- Name of file page
237 @ );
238 @
239 @ -- Linkages between check-ins, files created by each check-in, and
240 @ -- the names of those files.
241 @ --
242 @ -- Each entry represents a file that changed content from pid to fid
@@ -268,12 +268,12 @@
268 @ pmid INTEGER, -- Check-in that contains pid
269 @ pid INTEGER, -- Prev file content. 0 if new. -1 merge
270 @ fnid INTEGER REFERENCES filename, -- Name of the file
271 @ pfnid INTEGER, -- Previous name. 0 if unchanged
272 @ mperm INTEGER, -- File permissions. 1==exec
273 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
274 @ );
275 @ CREATE INDEX mlink_i1 ON mlink(mid);
276 @ CREATE INDEX mlink_i2 ON mlink(fnid);
277 @ CREATE INDEX mlink_i3 ON mlink(fid);
278 @ CREATE INDEX mlink_i4 ON mlink(pid);
279 @
@@ -280,15 +280,15 @@
280 @ -- Parent/child linkages between check-ins
281 @ --
282 @ CREATE TABLE plink(
283 @ pid INTEGER REFERENCES blob, -- Parent manifest
284 @ cid INTEGER REFERENCES blob, -- Child manifest
285 @ isprim BOOLEAN, -- pid is the primary parent of cid
286 @ mtime DATETIME, -- the date/time stamp on cid. Julian day.
287 @ baseid INTEGER REFERENCES blob, -- Baseline if cid is a delta manifest.
288 @ UNIQUE(pid, cid)
289 @ );
290 @ CREATE INDEX plink_i2 ON plink(cid,pid);
291 @
292 @ -- A "leaf" check-in is a check-in that has no children in the same
293 @ -- branch. The set of all leaves is easily computed with a join,
294 @ -- between the plink and tagxref tables, but it is a slower join for
@@ -306,22 +306,22 @@
306 @ -- t Ticket changes
307 @ -- w Wiki page edit
308 @ --
309 @ CREATE TABLE event(
310 @ type TEXT, -- Type of event: ci, e, f, g, t, w
311 @ mtime DATETIME, -- Time of occurrence. Julian day.
312 @ objid INTEGER PRIMARY KEY, -- Associated record ID
313 @ tagid INTEGER, -- Associated ticket or wiki name tag
314 @ uid INTEGER REFERENCES user, -- User who caused the event
315 @ bgcolor TEXT, -- Color set by 'bgcolor' property
316 @ euser TEXT, -- User set by 'user' property
317 @ user TEXT, -- Name of the user
318 @ ecomment TEXT, -- Comment set by 'comment' property
319 @ comment TEXT, -- Comment describing the event
320 @ brief TEXT, -- Short comment when tagid already seen
321 @ omtime DATETIME -- Original unchanged date+time, or NULL
322 @ );
323 @ CREATE INDEX event_i1 ON event(mtime);
324 @
325 @ -- A record of phantoms. A phantom is a record for which we know the
326 @ -- file hash but we do not (yet) know the file content.
327 @ --
@@ -334,11 +334,11 @@
334 @ -- We have to track all orphan manifests so that when the baseline arrives,
335 @ -- we know to process the orphaned deltas.
336 @ CREATE TABLE orphan(
337 @ rid INTEGER PRIMARY KEY, -- Delta manifest with a phantom baseline
338 @ baseline INTEGER -- Phantom baseline of this orphan
339 @ );
340 @ CREATE INDEX orphan_baseline ON orphan(baseline);
341 @
342 @ -- Unclustered records. An unclustered record is a record (including
343 @ -- a cluster records themselves) that is not mentioned by some other
344 @ -- cluster.
@@ -370,11 +370,11 @@
370 @ -- NAME is the symbolic name.
371 @ --
372 @ CREATE TABLE tag(
373 @ tagid INTEGER PRIMARY KEY, -- Numeric tag ID
374 @ tagname TEXT UNIQUE -- Tag name.
375 @ );
376 @ INSERT INTO tag VALUES(1, 'bgcolor'); -- TAG_BGCOLOR
377 @ INSERT INTO tag VALUES(2, 'comment'); -- TAG_COMMENT
378 @ INSERT INTO tag VALUES(3, 'user'); -- TAG_USER
379 @ INSERT INTO tag VALUES(4, 'date'); -- TAG_DATE
380 @ INSERT INTO tag VALUES(5, 'hidden'); -- TAG_HIDDEN
@@ -394,14 +394,14 @@
394 @ tagid INTEGER REFERENCES tag, -- The tag that added or removed
395 @ tagtype INTEGER, -- 0:-,cancel 1:+,single 2:*,propagate
396 @ srcid INTEGER REFERENCES blob, -- Artifact of tag. 0 for propagated tags
397 @ origid INTEGER REFERENCES blob, -- check-in holding propagated tag
398 @ value TEXT, -- Value of the tag. Might be NULL.
399 @ mtime TIMESTAMP, -- Time of addition or removal. Julian day
400 @ rid INTEGER REFERENCE blob, -- Artifact tag is applied to
401 @ UNIQUE(rid, tagid)
402 @ );
403 @ CREATE INDEX tagxref_i1 ON tagxref(tagid, mtime);
404 @
405 @ -- When a hyperlink occurs from one artifact to another (for example
406 @ -- when a check-in comment refers to a ticket) an entry is made in
407 @ -- the following table for that hyperlink. This table is used to
@@ -409,28 +409,28 @@
409 @ --
410 @ CREATE TABLE backlink(
411 @ target TEXT, -- Where the hyperlink points to
412 @ srctype INT, -- 0=comment 1=ticket 2=wiki. See BKLNK_* below.
413 @ srcid INT, -- EVENT.OBJID for the source document
414 @ mtime TIMESTAMP, -- time that the hyperlink was added. Julian day.
415 @ UNIQUE(target, srctype, srcid)
416 @ );
417 @ CREATE INDEX backlink_src ON backlink(srcid, srctype);
418 @
419 @ -- Each attachment is an entry in the following table. Only
420 @ -- the most recent attachment (identified by the D card) is saved.
421 @ --
422 @ CREATE TABLE attachment(
423 @ attachid INTEGER PRIMARY KEY, -- Local id for this attachment
424 @ isLatest BOOLEAN DEFAULT 0, -- True if this is the one to use
425 @ mtime TIMESTAMP, -- Last changed. Julian day.
426 @ src TEXT, -- Hash of the attachment. NULL to delete
427 @ target TEXT, -- Object attached to. Wikiname or Tkt hash
428 @ filename TEXT, -- Filename for the attachment
429 @ comment TEXT, -- Comment associated with this attachment
430 @ user TEXT -- Name of user adding attachment
431 @ );
432 @ CREATE INDEX attachment_idx1 ON attachment(target, filename, mtime);
433 @ CREATE INDEX attachment_idx2 ON attachment(src);
434 @
435 @ -- Template for the TICKET table
436 @ --
@@ -470,13 +470,13 @@
470 @
471 @ -- For tracking cherrypick merges
472 @ CREATE TABLE cherrypick(
473 @ parentid INT,
474 @ childid INT,
475 @ isExclude BOOLEAN DEFAULT false,
476 @ PRIMARY KEY(parentid, childid)
477 @ ) WITHOUT ROWID;
478 @ CREATE INDEX cherrypick_cid ON cherrypick(childid);
479 ;
480
481 /*
482 ** Allowed values for backlink.srctype
@@ -523,13 +523,13 @@
523 @ -- repository Full pathname of the repository database
524 @ -- user-id Userid to use
525 @ --
526 @ CREATE TABLE vvar(
527 @ name TEXT PRIMARY KEY NOT NULL, -- Primary name of the entry
528 @ value CLOB, -- Content of the named parameter
529 @ CHECK( typeof(name)='text' AND length(name)>=1 )
530 @ );
531 @
532 @ -- Each entry in the vfile table represents a single file in the
533 @ -- current checkout.
534 @ --
535 @ -- The file.rid field is 0 for files or folders that have been
@@ -544,21 +544,21 @@
544 @ --
545 @ CREATE TABLE vfile(
546 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
547 @ vid INTEGER REFERENCES blob, -- The checkin this file is part of.
548 @ chnged INT DEFAULT 0, -- 0:unchng 1:edit 2:m-chng 3:m-add 4:i-chng 5:i-add
549 @ deleted BOOLEAN DEFAULT 0, -- True if deleted
550 @ isexe BOOLEAN, -- True if file should be executable
551 @ islink BOOLEAN, -- True if file should be symlink
552 @ rid INTEGER, -- Originally from this repository record
553 @ mrid INTEGER, -- Based on this record due to a merge
554 @ mtime INTEGER, -- Mtime of file on disk. sec since 1970
555 @ pathname TEXT, -- Full pathname relative to root
556 @ origname TEXT, -- Original pathname. NULL if unchanged
557 @ mhash TEXT, -- Hash of mrid iff mrid!=rid
558 @ UNIQUE(pathname,vid)
559 @ );
560 @
561 @ -- Identifier for this file type.
562 @ -- The integer is the same as 'FSLC'.
563 @ PRAGMA application_id=252006674;
564 ;
@@ -579,11 +579,11 @@
579 @
580 @ CREATE TABLE vmerge(
581 @ id INTEGER REFERENCES vfile, -- VFILE entry that has been merged
582 @ merge INTEGER, -- Merged with this record
583 @ mhash TEXT -- SHA1/SHA3 hash for merge object
584 @ );
585 @ CREATE UNIQUE INDEX vmergex1 ON vmerge(id,mhash);
586 @
587 @ -- The following trigger will prevent older versions of Fossil that
588 @ -- do not know about the new vmerge.mhash column from updating the
589 @ -- vmerge table. This must be done with a trigger, since legacy Fossil
@@ -608,15 +608,15 @@
608 @ fpid INTEGER PRIMARY KEY, -- BLOB.rid for the artifact
609 @ froot INT, -- fpid of the thread root
610 @ fprev INT, -- Previous version of this same post
611 @ firt INT, -- This post is in-reply-to
612 @ fmtime REAL -- When posted. Julian day
613 @ );
614 @ CREATE INDEX repository.forumthread ON forumpost(froot,fmtime);
615 ;
616
617 /* Create the forum-post schema if it does not already exist */
618 void schema_forum(void){
619 if( !db_table_exists("repository","forumpost") ){
620 db_multi_exec("%s",zForumSchema/*safe-for-%s*/);
621 }
622 }
623
--- src/schema.c
+++ src/schema.c
@@ -82,15 +82,15 @@
82 @ rcvid INTEGER, -- Origin of this record
83 @ size INTEGER, -- Size of content. -1 for a phantom.
84 @ uuid TEXT UNIQUE NOT NULL, -- hash of the content
85 @ content BLOB, -- Compressed content of this record
86 @ CHECK( length(uuid)>=40 AND rid>0 )
87 @ ) STRICT;
88 @ CREATE TABLE delta(
89 @ rid INTEGER PRIMARY KEY, -- BLOB that is delta-compressed
90 @ srcid INTEGER NOT NULL REFERENCES blob -- Baseline for delta-compression
91 @ ) STRICT;
92 @ CREATE INDEX delta_i1 ON delta(srcid);
93 @
94 @ -------------------------------------------------------------------------
95 @ -- The BLOB and DELTA tables above hold the "global state" of a Fossil
96 @ -- project; the stuff that is normally exchanged during "sync". The
@@ -102,14 +102,14 @@
102 @ -- in this table records the source of the blob.
103 @ --
104 @ CREATE TABLE rcvfrom(
105 @ rcvid INTEGER PRIMARY KEY, -- Received-From ID
106 @ uid INTEGER REFERENCES user, -- User login
107 @ mtime REAL, -- Time of receipt. Julian day.
108 @ nonce TEXT UNIQUE, -- Nonce used for login
109 @ ipaddr TEXT -- Remote IP address. NULL for direct.
110 @ ) STRICT;
111 @
112 @ -- Information about users
113 @ --
114 @ -- The user.pw field can be either cleartext of the password, or
115 @ -- a SHA1 hash of the password. If the user.pw field is exactly 40
@@ -134,14 +134,14 @@
134 @ -- The config table holds miscellanous information about the repository.
135 @ -- in the form of name-value pairs.
136 @ --
137 @ CREATE TABLE config(
138 @ name TEXT PRIMARY KEY NOT NULL, -- Primary name of the entry
139 @ value ANY, -- Content of the named parameter
140 @ mtime INT, -- last modified. seconds since 1970
141 @ CHECK( length(name)>=1 )
142 @ ) STRICT;
143 @
144 @ -- Artifacts that should not be processed are identified in the
145 @ -- "shun" table. Artifacts that are control-file forgeries or
146 @ -- spam or artifacts whose contents violate administrative policy
147 @ -- can be shunned in order to prevent them from contaminating
@@ -150,14 +150,14 @@
150 @ -- Shunned artifacts do not exist in the blob table. Hence they
151 @ -- have not artifact ID (rid) and we thus must store their full
152 @ -- UUID.
153 @ --
154 @ CREATE TABLE shun(
155 @ uuid TEXT PRIMARY KEY, -- UUID of artifact to be shunned. Canonical form
156 @ mtime INT, -- When added. seconds since 1970
157 @ scom TEXT -- Optional text explaining why the shun occurred
158 @ ) WITHOUT ROWID, STRICT;
159 @
160 @ -- Artifacts that should not be pushed are stored in the "private"
161 @ -- table. Private artifacts are omitted from the "unclustered" and
162 @ -- "unsent" tables.
163 @ --
@@ -174,14 +174,14 @@
174 @ --
175 @ CREATE TABLE reportfmt(
176 @ rn INTEGER PRIMARY KEY, -- Report number
177 @ owner TEXT, -- Owner of this report format (not used)
178 @ title TEXT UNIQUE, -- Title of this report
179 @ mtime REAL, -- Last modified. seconds since 1970
180 @ cols TEXT, -- A color-key specification
181 @ sqlcode TEXT -- An SQL SELECT statement for this report
182 @ ) STRICT;
183 @
184 @ -- Some ticket content (such as the originators email address or contact
185 @ -- information) needs to be obscured to protect privacy. This is achieved
186 @ -- by storing an SHA1 hash of the content. For display, the hash is
187 @ -- mapped back into the original text using this table.
@@ -189,13 +189,13 @@
189 @ -- This table contains sensitive information and should not be shared
190 @ -- with unauthorized users.
191 @ --
192 @ CREATE TABLE concealed(
193 @ hash TEXT PRIMARY KEY, -- The SHA1 hash of content
194 @ mtime INT, -- Time created. Seconds since 1970
195 @ content TEXT -- Content intended to be concealed
196 @ ) STRICT;
197 @
198 @ -- The application ID helps the unix "file" command to identify the
199 @ -- database as a fossil repository.
200 @ PRAGMA application_id=252006673;
201 ;
@@ -232,11 +232,11 @@
232 @ -- Filenames
233 @ --
234 @ CREATE TABLE filename(
235 @ fnid INTEGER PRIMARY KEY, -- Filename ID
236 @ name TEXT UNIQUE -- Name of file page
237 @ ) STRICT;
238 @
239 @ -- Linkages between check-ins, files created by each check-in, and
240 @ -- the names of those files.
241 @ --
242 @ -- Each entry represents a file that changed content from pid to fid
@@ -268,12 +268,12 @@
268 @ pmid INTEGER, -- Check-in that contains pid
269 @ pid INTEGER, -- Prev file content. 0 if new. -1 merge
270 @ fnid INTEGER REFERENCES filename, -- Name of the file
271 @ pfnid INTEGER, -- Previous name. 0 if unchanged
272 @ mperm INTEGER, -- File permissions. 1==exec
273 @ isaux INT DEFAULT 0 -- TRUE if pmid is the primary
274 @ ) STRICT;
275 @ CREATE INDEX mlink_i1 ON mlink(mid);
276 @ CREATE INDEX mlink_i2 ON mlink(fnid);
277 @ CREATE INDEX mlink_i3 ON mlink(fid);
278 @ CREATE INDEX mlink_i4 ON mlink(pid);
279 @
@@ -280,15 +280,15 @@
280 @ -- Parent/child linkages between check-ins
281 @ --
282 @ CREATE TABLE plink(
283 @ pid INTEGER REFERENCES blob, -- Parent manifest
284 @ cid INTEGER REFERENCES blob, -- Child manifest
285 @ isprim INT, -- pid is the primary parent of cid
286 @ mtime REAL, -- the date/time stamp on cid. Julian day.
287 @ baseid INTEGER REFERENCES blob, -- Baseline if cid is a delta manifest.
288 @ UNIQUE(pid, cid)
289 @ ) STRICT;
290 @ CREATE INDEX plink_i2 ON plink(cid,pid);
291 @
292 @ -- A "leaf" check-in is a check-in that has no children in the same
293 @ -- branch. The set of all leaves is easily computed with a join,
294 @ -- between the plink and tagxref tables, but it is a slower join for
@@ -306,22 +306,22 @@
306 @ -- t Ticket changes
307 @ -- w Wiki page edit
308 @ --
309 @ CREATE TABLE event(
310 @ type TEXT, -- Type of event: ci, e, f, g, t, w
311 @ mtime REAL, -- Time of occurrence. Julian day.
312 @ objid INTEGER PRIMARY KEY, -- Associated record ID
313 @ tagid INTEGER, -- Associated ticket or wiki name tag
314 @ uid INTEGER REFERENCES user, -- User who caused the event
315 @ bgcolor TEXT, -- Color set by 'bgcolor' property
316 @ euser TEXT, -- User set by 'user' property
317 @ user TEXT, -- Name of the user
318 @ ecomment TEXT, -- Comment set by 'comment' property
319 @ comment TEXT, -- Comment describing the event
320 @ brief TEXT, -- Short comment when tagid already seen
321 @ omtime REAL -- Original unchanged date+time, or NULL
322 @ ) STRICT;
323 @ CREATE INDEX event_i1 ON event(mtime);
324 @
325 @ -- A record of phantoms. A phantom is a record for which we know the
326 @ -- file hash but we do not (yet) know the file content.
327 @ --
@@ -334,11 +334,11 @@
334 @ -- We have to track all orphan manifests so that when the baseline arrives,
335 @ -- we know to process the orphaned deltas.
336 @ CREATE TABLE orphan(
337 @ rid INTEGER PRIMARY KEY, -- Delta manifest with a phantom baseline
338 @ baseline INTEGER -- Phantom baseline of this orphan
339 @ ) STRICT;
340 @ CREATE INDEX orphan_baseline ON orphan(baseline);
341 @
342 @ -- Unclustered records. An unclustered record is a record (including
343 @ -- a cluster records themselves) that is not mentioned by some other
344 @ -- cluster.
@@ -370,11 +370,11 @@
370 @ -- NAME is the symbolic name.
371 @ --
372 @ CREATE TABLE tag(
373 @ tagid INTEGER PRIMARY KEY, -- Numeric tag ID
374 @ tagname TEXT UNIQUE -- Tag name.
375 @ ) STRICT;
376 @ INSERT INTO tag VALUES(1, 'bgcolor'); -- TAG_BGCOLOR
377 @ INSERT INTO tag VALUES(2, 'comment'); -- TAG_COMMENT
378 @ INSERT INTO tag VALUES(3, 'user'); -- TAG_USER
379 @ INSERT INTO tag VALUES(4, 'date'); -- TAG_DATE
380 @ INSERT INTO tag VALUES(5, 'hidden'); -- TAG_HIDDEN
@@ -394,14 +394,14 @@
394 @ tagid INTEGER REFERENCES tag, -- The tag that added or removed
395 @ tagtype INTEGER, -- 0:-,cancel 1:+,single 2:*,propagate
396 @ srcid INTEGER REFERENCES blob, -- Artifact of tag. 0 for propagated tags
397 @ origid INTEGER REFERENCES blob, -- check-in holding propagated tag
398 @ value TEXT, -- Value of the tag. Might be NULL.
399 @ mtime REAL, -- Time of addition or removal. Julian day
400 @ rid INTEGER REFERENCES blob, -- Artifact tag is applied to
401 @ UNIQUE(rid, tagid)
402 @ ) STRICT;
403 @ CREATE INDEX tagxref_i1 ON tagxref(tagid, mtime);
404 @
405 @ -- When a hyperlink occurs from one artifact to another (for example
406 @ -- when a check-in comment refers to a ticket) an entry is made in
407 @ -- the following table for that hyperlink. This table is used to
@@ -409,28 +409,28 @@
409 @ --
410 @ CREATE TABLE backlink(
411 @ target TEXT, -- Where the hyperlink points to
412 @ srctype INT, -- 0=comment 1=ticket 2=wiki. See BKLNK_* below.
413 @ srcid INT, -- EVENT.OBJID for the source document
414 @ mtime REAL, -- time that the hyperlink was added. Julian day.
415 @ UNIQUE(target, srctype, srcid)
416 @ ) STRICT;
417 @ CREATE INDEX backlink_src ON backlink(srcid, srctype);
418 @
419 @ -- Each attachment is an entry in the following table. Only
420 @ -- the most recent attachment (identified by the D card) is saved.
421 @ --
422 @ CREATE TABLE attachment(
423 @ attachid INTEGER PRIMARY KEY, -- Local id for this attachment
424 @ isLatest INT DEFAULT 0, -- True if this is the one to use
425 @ mtime REAL, -- Last changed. Julian day.
426 @ src TEXT, -- Hash of the attachment. NULL to delete
427 @ target TEXT, -- Object attached to. Wikiname or Tkt hash
428 @ filename TEXT, -- Filename for the attachment
429 @ comment TEXT, -- Comment associated with this attachment
430 @ user TEXT -- Name of user adding attachment
431 @ ) STRICT;
432 @ CREATE INDEX attachment_idx1 ON attachment(target, filename, mtime);
433 @ CREATE INDEX attachment_idx2 ON attachment(src);
434 @
435 @ -- Template for the TICKET table
436 @ --
@@ -470,13 +470,13 @@
470 @
471 @ -- For tracking cherrypick merges
472 @ CREATE TABLE cherrypick(
473 @ parentid INT,
474 @ childid INT,
475 @ isExclude INT DEFAULT false,
476 @ PRIMARY KEY(parentid, childid)
477 @ ) WITHOUT ROWID, STRICT;
478 @ CREATE INDEX cherrypick_cid ON cherrypick(childid);
479 ;
480
481 /*
482 ** Allowed values for backlink.srctype
@@ -523,13 +523,13 @@
523 @ -- repository Full pathname of the repository database
524 @ -- user-id Userid to use
525 @ --
526 @ CREATE TABLE vvar(
527 @ name TEXT PRIMARY KEY NOT NULL, -- Primary name of the entry
528 @ value ANY, -- Content of the named parameter
529 @ CHECK( length(name)>=1 )
530 @ ) STRICT, WITHOUT ROWID;
531 @
532 @ -- Each entry in the vfile table represents a single file in the
533 @ -- current checkout.
534 @ --
535 @ -- The file.rid field is 0 for files or folders that have been
@@ -544,21 +544,21 @@
544 @ --
545 @ CREATE TABLE vfile(
546 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
547 @ vid INTEGER REFERENCES blob, -- The checkin this file is part of.
548 @ chnged INT DEFAULT 0, -- 0:unchng 1:edit 2:m-chng 3:m-add 4:i-chng 5:i-add
549 @ deleted INT DEFAULT 0, -- True if deleted
550 @ isexe INT, -- True if file should be executable
551 @ islink INT, -- True if file should be symlink
552 @ rid INTEGER, -- Originally from this repository record
553 @ mrid INTEGER, -- Based on this record due to a merge
554 @ mtime INTEGER, -- Mtime of file on disk. sec since 1970
555 @ pathname TEXT, -- Full pathname relative to root
556 @ origname TEXT, -- Original pathname. NULL if unchanged
557 @ mhash TEXT, -- Hash of mrid iff mrid!=rid
558 @ UNIQUE(pathname,vid)
559 @ ) STRICT;
560 @
561 @ -- Identifier for this file type.
562 @ -- The integer is the same as 'FSLC'.
563 @ PRAGMA application_id=252006674;
564 ;
@@ -579,11 +579,11 @@
579 @
580 @ CREATE TABLE vmerge(
581 @ id INTEGER REFERENCES vfile, -- VFILE entry that has been merged
582 @ merge INTEGER, -- Merged with this record
583 @ mhash TEXT -- SHA1/SHA3 hash for merge object
584 @ ) STRICT;
585 @ CREATE UNIQUE INDEX vmergex1 ON vmerge(id,mhash);
586 @
587 @ -- The following trigger will prevent older versions of Fossil that
588 @ -- do not know about the new vmerge.mhash column from updating the
589 @ -- vmerge table. This must be done with a trigger, since legacy Fossil
@@ -608,15 +608,15 @@
608 @ fpid INTEGER PRIMARY KEY, -- BLOB.rid for the artifact
609 @ froot INT, -- fpid of the thread root
610 @ fprev INT, -- Previous version of this same post
611 @ firt INT, -- This post is in-reply-to
612 @ fmtime REAL -- When posted. Julian day
613 @ ) STRICT;
614 @ CREATE INDEX repository.forumthread ON forumpost(froot,fmtime);
615 ;
616
617 /* Create the forum-post schema if it does not already exist */
618 void schema_forum(void){
619 if( !db_table_exists("repository","forumpost") ){
620 db_multi_exec("%s",zForumSchema/*safe-for-%s*/);
621 }
622 }
623
--- src/shell.c
+++ src/shell.c
@@ -19960,12 +19960,10 @@
1996019960
p->openMode = SHELL_OPEN_APPENDVFS;
1996119961
}else if( optionMatch(z, "readonly") ){
1996219962
p->openMode = SHELL_OPEN_READONLY;
1996319963
}else if( optionMatch(z, "nofollow") ){
1996419964
p->openFlags |= SQLITE_OPEN_NOFOLLOW;
19965
- }else if( optionMatch(z, "excl") ){
19966
- p->openFlags |= SQLITE_OPEN_EXCLUSIVE;
1996719965
#ifndef SQLITE_OMIT_DESERIALIZE
1996819966
}else if( optionMatch(z, "deserialize") ){
1996919967
p->openMode = SHELL_OPEN_DESERIALIZE;
1997019968
}else if( optionMatch(z, "hexdb") ){
1997119969
p->openMode = SHELL_OPEN_HEXDB;
1997219970
--- src/shell.c
+++ src/shell.c
@@ -19960,12 +19960,10 @@
19960 p->openMode = SHELL_OPEN_APPENDVFS;
19961 }else if( optionMatch(z, "readonly") ){
19962 p->openMode = SHELL_OPEN_READONLY;
19963 }else if( optionMatch(z, "nofollow") ){
19964 p->openFlags |= SQLITE_OPEN_NOFOLLOW;
19965 }else if( optionMatch(z, "excl") ){
19966 p->openFlags |= SQLITE_OPEN_EXCLUSIVE;
19967 #ifndef SQLITE_OMIT_DESERIALIZE
19968 }else if( optionMatch(z, "deserialize") ){
19969 p->openMode = SHELL_OPEN_DESERIALIZE;
19970 }else if( optionMatch(z, "hexdb") ){
19971 p->openMode = SHELL_OPEN_HEXDB;
19972
--- src/shell.c
+++ src/shell.c
@@ -19960,12 +19960,10 @@
19960 p->openMode = SHELL_OPEN_APPENDVFS;
19961 }else if( optionMatch(z, "readonly") ){
19962 p->openMode = SHELL_OPEN_READONLY;
19963 }else if( optionMatch(z, "nofollow") ){
19964 p->openFlags |= SQLITE_OPEN_NOFOLLOW;
 
 
19965 #ifndef SQLITE_OMIT_DESERIALIZE
19966 }else if( optionMatch(z, "deserialize") ){
19967 p->openMode = SHELL_OPEN_DESERIALIZE;
19968 }else if( optionMatch(z, "hexdb") ){
19969 p->openMode = SHELL_OPEN_HEXDB;
19970
+775 -371
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.37.0"
456456
#define SQLITE_VERSION_NUMBER 3037000
457
-#define SQLITE_SOURCE_ID "2021-10-06 10:36:56 566e6974892ebd3d3de8d77b24655257a5efe14434c553e1a25fc680b201b336"
457
+#define SQLITE_SOURCE_ID "2021-10-21 20:08:00 559ba38b8a0f7795d781838ec78969874fd678f749b26cd49cf6112afc838732"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -843,11 +843,10 @@
843843
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
844844
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
845845
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
846846
#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
847847
#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
848
-#define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8))
849848
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
850849
#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
851850
#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
852851
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
853852
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
@@ -879,10 +878,23 @@
879878
** CAPI3REF: Flags For File Open Operations
880879
**
881880
** These bit values are intended for use in the
882881
** 3rd parameter to the [sqlite3_open_v2()] interface and
883882
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
883
+**
884
+** Only those flags marked as "Ok for sqlite3_open_v2()" may be
885
+** used as the third argument to the [sqlite3_open_v2()] interface.
886
+** The other flags have historically been ignored by sqlite3_open_v2(),
887
+** though future versions of SQLite might change so that an error is
888
+** raised if any of the disallowed bits are passed into sqlite3_open_v2().
889
+** Applications should not depend on the historical behavior.
890
+**
891
+** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
892
+** [sqlite3_open_v2()] does *not* cause the underlying database file
893
+** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
894
+** [sqlite3_open_v2()] has historically be a no-op and might become an
895
+** error in future versions of SQLite.
884896
*/
885897
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
886898
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
887899
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
888900
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
@@ -3723,22 +3735,24 @@
37233735
** the default shared cache setting provided by
37243736
** [sqlite3_enable_shared_cache()].)^
37253737
**
37263738
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
37273739
** <dd>The database filename is not allowed to be a symbolic link</dd>
3728
-**
3729
-** [[OPEN_EXCLUSIVE]] ^(<dt>[SQLITE_OPEN_EXCLUSIVE]</dt>
3730
-** <dd>This flag causes the open to fail if the database file already
3731
-** exists. The open will only be success if this flag is used in combination
3732
-** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if
3733
-** the file does not previously exist.</dd>
37343740
** </dl>)^
37353741
**
37363742
** If the 3rd parameter to sqlite3_open_v2() is not one of the
37373743
** required combinations shown above optionally combined with other
37383744
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3739
-** then the behavior is undefined.
3745
+** then the behavior is undefined. Historic versions of SQLite
3746
+** have silently ignored surplus bits in the flags parameter to
3747
+** sqlite3_open_v2(), however that behavior might not be carried through
3748
+** into future versions of SQLite and so applications should not rely
3749
+** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3750
+** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
3751
+** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
3752
+** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3753
+** by sqlite3_open_v2().
37403754
**
37413755
** ^The fourth parameter to sqlite3_open_v2() is the name of the
37423756
** [sqlite3_vfs] object that defines the operating system interface that
37433757
** the new database connection should use. ^If the fourth parameter is
37443758
** a NULL pointer then the default [sqlite3_vfs] object is used.
@@ -13162,13 +13176,15 @@
1316213176
** is significant and used at least once. On switch statements
1316313177
** where multiple cases go to the same block of code, testcase()
1316413178
** can insure that all cases are evaluated.
1316513179
**
1316613180
*/
13167
-#ifdef SQLITE_COVERAGE_TEST
13168
-SQLITE_PRIVATE void sqlite3Coverage(int);
13169
-# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
13181
+#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
13182
+# ifndef SQLITE_AMALGAMATION
13183
+ extern unsigned int sqlite3CoverageCounter;
13184
+# endif
13185
+# define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; }
1317013186
#else
1317113187
# define testcase(X)
1317213188
#endif
1317313189
1317413190
/*
@@ -13228,30 +13244,10 @@
1322813244
#else
1322913245
# define ALWAYS(X) (X)
1323013246
# define NEVER(X) (X)
1323113247
#endif
1323213248
13233
-/*
13234
-** The harmless(X) macro indicates that expression X is usually false
13235
-** but can be true without causing any problems, but we don't know of
13236
-** any way to cause X to be true.
13237
-**
13238
-** In debugging and testing builds, this macro will abort if X is ever
13239
-** true. In this way, developers are alerted to a possible test case
13240
-** that causes X to be true. If a harmless macro ever fails, that is
13241
-** an opportunity to change the macro into a testcase() and add a new
13242
-** test case to the test suite.
13243
-**
13244
-** For normal production builds, harmless(X) is a no-op, since it does
13245
-** not matter whether expression X is true or false.
13246
-*/
13247
-#ifdef SQLITE_DEBUG
13248
-# define harmless(X) assert(!(X));
13249
-#else
13250
-# define harmless(X)
13251
-#endif
13252
-
1325313249
/*
1325413250
** Some conditionals are optimizations only. In other words, if the
1325513251
** conditionals are replaced with a constant 1 (true) or 0 (false) then
1325613252
** the correct answer is still obtained, though perhaps not as quickly.
1325713253
**
@@ -13430,11 +13426,11 @@
1343013426
/* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */
1343113427
1343213428
/*
1343313429
** Number of entries in a hash table
1343413430
*/
13435
-/* #define sqliteHashCount(H) ((H)->count) // NOT USED */
13431
+#define sqliteHashCount(H) ((H)->count)
1343613432
1343713433
#endif /* SQLITE_HASH_H */
1343813434
1343913435
/************** End of hash.h ************************************************/
1344013436
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -16428,14 +16424,14 @@
1642816424
int nVdbeExec; /* Number of nested calls to VdbeExec() */
1642916425
int nVDestroy; /* Number of active OP_VDestroy operations */
1643016426
int nExtension; /* Number of loaded extensions */
1643116427
void **aExtension; /* Array of shared library handles */
1643216428
union {
16433
- void (*xLegacy)(void*,const char*); /* Legacy trace function */
16434
- int (*xV2)(u32,void*,void*,void*); /* V2 Trace function */
16429
+ void (*xLegacy)(void*,const char*); /* mTrace==SQLITE_TRACE_LEGACY */
16430
+ int (*xV2)(u32,void*,void*,void*); /* All other mTrace values */
1643516431
} trace;
16436
- void *pTraceArg; /* Argument to the trace function */
16432
+ void *pTraceArg; /* Argument to the trace function */
1643716433
#ifndef SQLITE_OMIT_DEPRECATED
1643816434
void (*xProfile)(void*,const char*,u64); /* Profiling function */
1643916435
void *pProfileArg; /* Argument to profile function */
1644016436
#endif
1644116437
void *pCommitArg; /* Argument to xCommitCallback() */
@@ -16667,11 +16663,11 @@
1666716663
void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */
1666816664
const char *zName; /* SQL name of the function. */
1666916665
union {
1667016666
FuncDef *pHash; /* Next with a different name but the same hash */
1667116667
FuncDestructor *pDestructor; /* Reference counted destructor function */
16672
- } u;
16668
+ } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */
1667316669
};
1667416670
1667516671
/*
1667616672
** This structure encapsulates a user-function destructor callback (as
1667716673
** configured using create_function_v2()) and a reference counter. When
@@ -16728,10 +16724,11 @@
1672816724
#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
1672916725
#define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
1673016726
#define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
1673116727
#define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
1673216728
#define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
16729
+#define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */
1673316730
#define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */
1673416731
1673516732
/* Identifier numbers for each in-line function */
1673616733
#define INLINEFUNC_coalesce 0
1673716734
#define INLINEFUNC_implies_nonnull_row 1
@@ -16806,48 +16803,55 @@
1680616803
** available as the function user-data (sqlite3_user_data()). The
1680716804
** FuncDef.flags variable is set to the value passed as the flags
1680816805
** parameter.
1680916806
*/
1681016807
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
16811
- {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16808
+ {nArg, SQLITE_FUNC_BUILTIN|\
16809
+ SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1681216810
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1681316811
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16814
- {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16812
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1681516813
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1681616814
#define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16817
- {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
16815
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
1681816816
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1681916817
#define MFUNCTION(zName, nArg, xPtr, xFunc) \
16820
- {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
16818
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
1682116819
xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
1682216820
#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
16823
- {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16821
+ {nArg, SQLITE_FUNC_BUILTIN|\
16822
+ SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
1682416823
SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
1682516824
#define TEST_FUNC(zName, nArg, iArg, mFlags) \
16826
- {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
16825
+ {nArg, SQLITE_FUNC_BUILTIN|\
16826
+ SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
1682716827
SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
1682816828
SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
1682916829
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16830
- {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
16830
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
1683116831
0, 0, xFunc, 0, 0, 0, #zName, {0} }
1683216832
#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
16833
- {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
16833
+ {nArg, SQLITE_FUNC_BUILTIN|\
16834
+ SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
1683416835
(void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
1683516836
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
16836
- {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
16837
+ {nArg, SQLITE_FUNC_BUILTIN|\
16838
+ SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
1683716839
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1683816840
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
16839
- {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16841
+ {nArg, SQLITE_FUNC_BUILTIN|\
16842
+ SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1684016843
pArg, 0, xFunc, 0, 0, 0, #zName, }
1684116844
#define LIKEFUNC(zName, nArg, arg, flags) \
16842
- {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
16845
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1684316846
(void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
1684416847
#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
16845
- {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
16848
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
1684616849
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
1684716850
#define INTERNAL_FUNCTION(zName, nArg, xFunc) \
16848
- {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
16851
+ {nArg, SQLITE_FUNC_BUILTIN|\
16852
+ SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
1684916853
0, 0, xFunc, 0, 0, 0, #zName, {0} }
1685016854
1685116855
1685216856
/*
1685316857
** All current savepoints are stored in a linked list starting at
@@ -17566,14 +17570,14 @@
1756617570
** code representing the ">=" operator. This same integer code is reused
1756717571
** to represent the greater-than-or-equal-to operator in the expression
1756817572
** tree.
1756917573
**
1757017574
** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
17571
-** or TK_STRING), then Expr.token contains the text of the SQL literal. If
17572
-** the expression is a variable (TK_VARIABLE), then Expr.token contains the
17575
+** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If
17576
+** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the
1757317577
** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
17574
-** then Expr.token contains the name of the function.
17578
+** then Expr.u.zToken contains the name of the function.
1757517579
**
1757617580
** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
1757717581
** binary operator. Either or both may be NULL.
1757817582
**
1757917583
** Expr.x.pList is a list of arguments if the expression is an SQL function,
@@ -17609,11 +17613,11 @@
1760917613
**
1761017614
** Expr objects can use a lot of memory space in database schema. To
1761117615
** help reduce memory requirements, sometimes an Expr object will be
1761217616
** truncated. And to reduce the number of memory allocations, sometimes
1761317617
** two or more Expr objects will be stored in a single memory allocation,
17614
-** together with Expr.zToken strings.
17618
+** together with Expr.u.zToken strings.
1761517619
**
1761617620
** If the EP_Reduced and EP_TokenOnly flags are set when
1761717621
** an Expr object is truncated. When EP_Reduced is set, then all
1761817622
** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
1761917623
** are contained within the same memory allocation. Note, however, that
@@ -17678,12 +17682,11 @@
1767817682
int regReturn; /* Register used to hold return address */
1767917683
} sub;
1768017684
} y;
1768117685
};
1768217686
17683
-/*
17684
-** The following are the meanings of bits in the Expr.flags field.
17687
+/* The following are the meanings of bits in the Expr.flags field.
1768517688
** Value restrictions:
1768617689
**
1768717690
** EP_Agg == NC_HasAgg == SF_HasAgg
1768817691
** EP_Win == NC_HasWin
1768917692
*/
@@ -17718,27 +17721,35 @@
1771817721
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
1771917722
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
1772017723
#define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
1772117724
/* 0x80000000 // Available */
1772217725
17723
-/*
17724
-** The EP_Propagate mask is a set of properties that automatically propagate
17726
+/* The EP_Propagate mask is a set of properties that automatically propagate
1772517727
** upwards into parent nodes.
1772617728
*/
1772717729
#define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
1772817730
17729
-/*
17730
-** These macros can be used to test, set, or clear bits in the
17731
+/* Macros can be used to test, set, or clear bits in the
1773117732
** Expr.flags field.
1773217733
*/
1773317734
#define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
1773417735
#define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
1773517736
#define ExprSetProperty(E,P) (E)->flags|=(P)
1773617737
#define ExprClearProperty(E,P) (E)->flags&=~(P)
1773717738
#define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
1773817739
#define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
1773917740
17741
+/* Macros used to ensure that the correct members of unions are accessed
17742
+** in Expr.
17743
+*/
17744
+#define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
17745
+#define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0)
17746
+#define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0)
17747
+#define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0)
17748
+#define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0)
17749
+#define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0)
17750
+#define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0)
1774017751
1774117752
/* Flags for use with Expr.vvaFlags
1774217753
*/
1774317754
#define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */
1774417755
#define EP_Immutable 0x02 /* Do not change this Expr node */
@@ -17817,15 +17828,16 @@
1781717828
unsigned done :1; /* A flag to indicate when processing is finished */
1781817829
unsigned reusable :1; /* Constant expression is reusable */
1781917830
unsigned bSorterRef :1; /* Defer evaluation until after sorting */
1782017831
unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
1782117832
union {
17822
- struct {
17833
+ struct { /* Used by any ExprList other than Parse.pConsExpr */
1782317834
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1782417835
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1782517836
} x;
17826
- int iConstExprReg; /* Register in which Expr value is cached */
17837
+ int iConstExprReg; /* Register in which Expr value is cached. Used only
17838
+ ** by Parse.pConstExpr */
1782717839
} u;
1782817840
} a[1]; /* One slot for each expression in the list */
1782917841
};
1783017842
1783117843
/*
@@ -17859,10 +17871,17 @@
1785917871
};
1786017872
1786117873
/*
1786217874
** The SrcItem object represents a single term in the FROM clause of a query.
1786317875
** The SrcList object is mostly an array of SrcItems.
17876
+**
17877
+** Union member validity:
17878
+**
17879
+** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc
17880
+** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy
17881
+** u2.pIBIndex fg.isIndexedBy && !fg.isCte
17882
+** u2.pCteUse fg.isCte && !fg.isIndexedBy
1786417883
*/
1786517884
struct SrcItem {
1786617885
Schema *pSchema; /* Schema to which this item is fixed */
1786717886
char *zDatabase; /* Name of database holding this table */
1786817887
char *zName; /* Name of the table */
@@ -18453,10 +18472,12 @@
1845318472
#ifndef SQLITE_OMIT_ALTERTABLE
1845418473
RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
1845518474
#endif
1845618475
};
1845718476
18477
+/* Allowed values for Parse.eParseMode
18478
+*/
1845818479
#define PARSE_MODE_NORMAL 0
1845918480
#define PARSE_MODE_DECLARE_VTAB 1
1846018481
#define PARSE_MODE_RENAME 2
1846118482
#define PARSE_MODE_UNMAP 3
1846218483
@@ -20109,12 +20130,12 @@
2010920130
** All of this is no-op for a production build. It only comes into
2011020131
** play when the SQLITE_MEMDEBUG compile-time option is used.
2011120132
*/
2011220133
#ifdef SQLITE_MEMDEBUG
2011320134
SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
20114
-SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
20115
-SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8);
20135
+SQLITE_PRIVATE int sqlite3MemdebugHasType(const void*,u8);
20136
+SQLITE_PRIVATE int sqlite3MemdebugNoType(const void*,u8);
2011620137
#else
2011720138
# define sqlite3MemdebugSetType(X,Y) /* no-op */
2011820139
# define sqlite3MemdebugHasType(X,Y) 1
2011920140
# define sqlite3MemdebugNoType(X,Y) 1
2012020141
#endif
@@ -21433,10 +21454,16 @@
2143321454
** database connections. After initialization, this table is
2143421455
** read-only.
2143521456
*/
2143621457
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
2143721458
21459
+/*
21460
+** Counter used for coverage testing. Does not come into play for
21461
+** release builds.
21462
+*/
21463
+SQLITE_PRIVATE unsigned int sqlite3CoverageCounter;
21464
+
2143821465
#ifdef VDBE_PROFILE
2143921466
/*
2144021467
** The following performance counter can be used in place of
2144121468
** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
2144221469
*/
@@ -24817,11 +24844,11 @@
2481724844
** Given an allocation, find the MemBlockHdr for that allocation.
2481824845
**
2481924846
** This routine checks the guards at either end of the allocation and
2482024847
** if they are incorrect it asserts.
2482124848
*/
24822
-static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){
24849
+static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){
2482324850
struct MemBlockHdr *p;
2482424851
int *pInt;
2482524852
u8 *pU8;
2482624853
int nReserve;
2482724854
@@ -25064,11 +25091,11 @@
2506425091
** This routine is designed for use within an assert() statement, to
2506525092
** verify the type of an allocation. For example:
2506625093
**
2506725094
** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2506825095
*/
25069
-SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
25096
+SQLITE_PRIVATE int sqlite3MemdebugHasType(const void *p, u8 eType){
2507025097
int rc = 1;
2507125098
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
2507225099
struct MemBlockHdr *pHdr;
2507325100
pHdr = sqlite3MemsysGetHeader(p);
2507425101
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -25086,11 +25113,11 @@
2508625113
** This routine is designed for use within an assert() statement, to
2508725114
** verify the type of an allocation. For example:
2508825115
**
2508925116
** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2509025117
*/
25091
-SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
25118
+SQLITE_PRIVATE int sqlite3MemdebugNoType(const void *p, u8 eType){
2509225119
int rc = 1;
2509325120
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
2509425121
struct MemBlockHdr *pHdr;
2509525122
pHdr = sqlite3MemsysGetHeader(p);
2509625123
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -30551,10 +30578,11 @@
3055130578
zOp2[0] = 0;
3055230579
}
3055330580
sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
3055430581
pExpr->iColumn, zFlgs, zOp2);
3055530582
}else{
30583
+ assert( ExprUseYTab(pExpr) );
3055630584
sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
3055730585
pExpr->iTable, pExpr->iColumn,
3055830586
pExpr->y.pTab, zFlgs);
3055930587
}
3056030588
if( ExprHasProperty(pExpr, EP_FixedCol) ){
@@ -30570,15 +30598,17 @@
3057030598
}
3057130599
break;
3057230600
}
3057330601
#ifndef SQLITE_OMIT_FLOATING_POINT
3057430602
case TK_FLOAT: {
30603
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3057530604
sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
3057630605
break;
3057730606
}
3057830607
#endif
3057930608
case TK_STRING: {
30609
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3058030610
sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
3058130611
break;
3058230612
}
3058330613
case TK_NULL: {
3058430614
sqlite3TreeViewLine(pView,"NULL");
@@ -30589,30 +30619,34 @@
3058930619
sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
3059030620
break;
3059130621
}
3059230622
#ifndef SQLITE_OMIT_BLOB_LITERAL
3059330623
case TK_BLOB: {
30624
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3059430625
sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
3059530626
break;
3059630627
}
3059730628
#endif
3059830629
case TK_VARIABLE: {
30630
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3059930631
sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
3060030632
pExpr->u.zToken, pExpr->iColumn);
3060130633
break;
3060230634
}
3060330635
case TK_REGISTER: {
3060430636
sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
3060530637
break;
3060630638
}
3060730639
case TK_ID: {
30640
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3060830641
sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
3060930642
break;
3061030643
}
3061130644
#ifndef SQLITE_OMIT_CAST
3061230645
case TK_CAST: {
3061330646
/* Expressions of the form: CAST(pLeft AS token) */
30647
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3061430648
sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
3061530649
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
3061630650
break;
3061730651
}
3061830652
#endif /* SQLITE_OMIT_CAST */
@@ -30658,10 +30692,11 @@
3065830692
zUniOp = azOp[x];
3065930693
break;
3066030694
}
3066130695
3066230696
case TK_SPAN: {
30697
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3066330698
sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
3066430699
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
3066530700
break;
3066630701
}
3066730702
@@ -30669,10 +30704,11 @@
3066930704
/* COLLATE operators without the EP_Collate flag are intended to
3067030705
** emulate collation associated with a table column. These show
3067130706
** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE
3067230707
** operators that appear in the original SQL always have the
3067330708
** EP_Collate bit set and appear in treeview output as just "COLLATE" */
30709
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3067430710
sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s",
3067530711
!ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "",
3067630712
pExpr->u.zToken, zFlgs);
3067730713
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
3067830714
break;
@@ -30684,17 +30720,19 @@
3068430720
Window *pWin;
3068530721
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
3068630722
pFarg = 0;
3068730723
pWin = 0;
3068830724
}else{
30725
+ assert( ExprUseXList(pExpr) );
3068930726
pFarg = pExpr->x.pList;
3069030727
#ifndef SQLITE_OMIT_WINDOWFUNC
3069130728
pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
3069230729
#else
3069330730
pWin = 0;
3069430731
#endif
3069530732
}
30733
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3069630734
if( pExpr->op==TK_AGG_FUNCTION ){
3069730735
sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
3069830736
pExpr->op2, pExpr->u.zToken, zFlgs,
3069930737
pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
3070030738
pExpr->iAgg, pExpr->pAggInfo);
@@ -30722,23 +30760,25 @@
3072230760
#endif
3072330761
break;
3072430762
}
3072530763
#ifndef SQLITE_OMIT_SUBQUERY
3072630764
case TK_EXISTS: {
30765
+ assert( ExprUseXSelect(pExpr) );
3072730766
sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
3072830767
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3072930768
break;
3073030769
}
3073130770
case TK_SELECT: {
30771
+ assert( ExprUseXSelect(pExpr) );
3073230772
sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
3073330773
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3073430774
break;
3073530775
}
3073630776
case TK_IN: {
3073730777
sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
3073830778
sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30739
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
30779
+ if( ExprUseXSelect(pExpr) ){
3074030780
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3074130781
}else{
3074230782
sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
3074330783
}
3074430784
break;
@@ -30755,13 +30795,16 @@
3075530795
** X is stored in pExpr->pLeft.
3075630796
** Y is stored in pExpr->pList->a[0].pExpr.
3075730797
** Z is stored in pExpr->pList->a[1].pExpr.
3075830798
*/
3075930799
case TK_BETWEEN: {
30760
- Expr *pX = pExpr->pLeft;
30761
- Expr *pY = pExpr->x.pList->a[0].pExpr;
30762
- Expr *pZ = pExpr->x.pList->a[1].pExpr;
30800
+ const Expr *pX, *pY, *pZ;
30801
+ pX = pExpr->pLeft;
30802
+ assert( ExprUseXList(pExpr) );
30803
+ assert( pExpr->x.pList->nExpr==2 );
30804
+ pY = pExpr->x.pList->a[0].pExpr;
30805
+ pZ = pExpr->x.pList->a[1].pExpr;
3076330806
sqlite3TreeViewLine(pView, "BETWEEN");
3076430807
sqlite3TreeViewExpr(pView, pX, 1);
3076530808
sqlite3TreeViewExpr(pView, pY, 1);
3076630809
sqlite3TreeViewExpr(pView, pZ, 0);
3076730810
break;
@@ -30779,10 +30822,11 @@
3077930822
break;
3078030823
}
3078130824
case TK_CASE: {
3078230825
sqlite3TreeViewLine(pView, "CASE");
3078330826
sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30827
+ assert( ExprUseXList(pExpr) );
3078430828
sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
3078530829
break;
3078630830
}
3078730831
#ifndef SQLITE_OMIT_TRIGGER
3078830832
case TK_RAISE: {
@@ -30791,10 +30835,11 @@
3079130835
case OE_Rollback: zType = "rollback"; break;
3079230836
case OE_Abort: zType = "abort"; break;
3079330837
case OE_Fail: zType = "fail"; break;
3079430838
case OE_Ignore: zType = "ignore"; break;
3079530839
}
30840
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3079630841
sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
3079730842
break;
3079830843
}
3079930844
#endif
3080030845
case TK_MATCH: {
@@ -30803,18 +30848,20 @@
3080330848
sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
3080430849
break;
3080530850
}
3080630851
case TK_VECTOR: {
3080730852
char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
30853
+ assert( ExprUseXList(pExpr) );
3080830854
sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
3080930855
sqlite3_free(z);
3081030856
break;
3081130857
}
3081230858
case TK_SELECT_COLUMN: {
3081330859
sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s",
3081430860
pExpr->iColumn, pExpr->iTable-1,
3081530861
pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : "");
30862
+ assert( ExprUseXSelect(pExpr->pLeft) );
3081630863
sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
3081730864
break;
3081830865
}
3081930866
case TK_IF_NULL_ROW: {
3082030867
sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
@@ -31887,20 +31934,10 @@
3188731934
/* #include <stdarg.h> */
3188831935
#ifndef SQLITE_OMIT_FLOATING_POINT
3188931936
#include <math.h>
3189031937
#endif
3189131938
31892
-/*
31893
-** Routine needed to support the testcase() macro.
31894
-*/
31895
-#ifdef SQLITE_COVERAGE_TEST
31896
-SQLITE_PRIVATE void sqlite3Coverage(int x){
31897
- static unsigned dummy = 0;
31898
- dummy += (unsigned)x;
31899
-}
31900
-#endif
31901
-
3190231939
/*
3190331940
** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
3190431941
** or to bypass normal error detection during testing in order to let
3190531942
** execute proceed futher downstream.
3190631943
**
@@ -32143,10 +32180,11 @@
3214332180
}
3214432181
}
3214532182
z[j] = 0;
3214632183
}
3214732184
SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
32185
+ assert( !ExprHasProperty(p, EP_IntValue) );
3214832186
assert( sqlite3Isquote(p->u.zToken[0]) );
3214932187
p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
3215032188
sqlite3Dequote(p->u.zToken);
3215132189
}
3215232190
@@ -40270,12 +40308,10 @@
4027040308
if( fd<0 ){
4027140309
if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
4027240310
/* If unable to create a journal because the directory is not
4027340311
** writable, change the error code to indicate that. */
4027440312
rc = SQLITE_READONLY_DIRECTORY;
40275
- }else if( errno==EEXIST ){
40276
- rc = SQLITE_CANTOPEN_EXISTS;
4027740313
}else if( errno!=EISDIR && isReadWrite ){
4027840314
/* Failed to open the file for read/write access. Try read-only. */
4027940315
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
4028040316
openFlags &= ~(O_RDWR|O_CREAT);
4028140317
flags |= SQLITE_OPEN_READONLY;
@@ -59613,11 +59649,11 @@
5961359649
*/
5961459650
pPg->flags &= ~PGHDR_NEED_SYNC;
5961559651
pPgOld = sqlite3PagerLookup(pPager, pgno);
5961659652
assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
5961759653
if( pPgOld ){
59618
- if( pPgOld->nRef>1 ){
59654
+ if( NEVER(pPgOld->nRef>1) ){
5961959655
sqlite3PagerUnrefNotNull(pPgOld);
5962059656
return SQLITE_CORRUPT_BKPT;
5962159657
}
5962259658
pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
5962359659
if( pPager->tempFile ){
@@ -64637,11 +64673,10 @@
6463764673
** Access to all fields of this structure is controlled by the mutex
6463864674
** stored in MemPage.pBt->mutex.
6463964675
*/
6464064676
struct MemPage {
6464164677
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
64642
- u8 bBusy; /* Prevent endless loops on corrupt database files */
6464364678
u8 intKey; /* True if table b-trees. False for index b-trees */
6464464679
u8 intKeyLeaf; /* True if the leaf of an intKey table */
6464564680
Pgno pgno; /* Page number for this page */
6464664681
/* Only the first 8 bytes (above) are zeroed by pager.c when a new page
6464764682
** is allocated. All fields that follow must be initialized before use */
@@ -70227,11 +70262,13 @@
7022770262
#endif
7022870263
7022970264
assert( pPage );
7023070265
assert( eOp==0 || eOp==1 );
7023170266
assert( pCur->eState==CURSOR_VALID );
70232
- assert( pCur->ix<pPage->nCell );
70267
+ if( pCur->ix>=pPage->nCell ){
70268
+ return SQLITE_CORRUPT_PAGE(pPage);
70269
+ }
7023370270
assert( cursorHoldsMutex(pCur) );
7023470271
7023570272
getCellInfo(pCur);
7023670273
aPayload = pCur->info.pPayload;
7023770274
assert( offset+amt <= pCur->info.nPayload );
@@ -70414,11 +70451,10 @@
7041470451
*/
7041570452
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
7041670453
assert( cursorHoldsMutex(pCur) );
7041770454
assert( pCur->eState==CURSOR_VALID );
7041870455
assert( pCur->iPage>=0 && pCur->pPage );
70419
- assert( pCur->ix<pCur->pPage->nCell );
7042070456
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
7042170457
}
7042270458
7042370459
/*
7042470460
** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -70476,11 +70512,11 @@
7047670512
int amt;
7047770513
assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
7047870514
assert( pCur->eState==CURSOR_VALID );
7047970515
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
7048070516
assert( cursorOwnsBtShared(pCur) );
70481
- assert( pCur->ix<pCur->pPage->nCell );
70517
+ assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
7048270518
assert( pCur->info.nSize>0 );
7048370519
assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
7048470520
assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
7048570521
amt = pCur->info.nLocal;
7048670522
if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
@@ -71262,20 +71298,10 @@
7126271298
** module cov1/btree78.test testcase 220 (2018-06-08) for an
7126371299
** example. */
7126471300
return SQLITE_CORRUPT_BKPT;
7126571301
}
7126671302
71267
- /* If the database file is corrupt, it is possible for the value of idx
71268
- ** to be invalid here. This can only occur if a second cursor modifies
71269
- ** the page while cursor pCur is holding a reference to it. Which can
71270
- ** only happen if the database is corrupt in such a way as to link the
71271
- ** page into more than one b-tree structure.
71272
- **
71273
- ** Update 2019-12-23: appears to long longer be possible after the
71274
- ** addition of anotherValidCursor() condition on balance_deeper(). */
71275
- harmless( idx>pPage->nCell );
71276
-
7127771303
if( idx>=pPage->nCell ){
7127871304
if( !pPage->leaf ){
7127971305
rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
7128071306
if( rc ) return rc;
7128171307
return moveToLeftmost(pCur);
@@ -71759,11 +71785,11 @@
7175971785
7176071786
assert( sqlite3_mutex_held(pBt->mutex) );
7176171787
assert( CORRUPT_DB || iPage>1 );
7176271788
assert( !pMemPage || pMemPage->pgno==iPage );
7176371789
71764
- if( iPage<2 || iPage>pBt->nPage ){
71790
+ if( NEVER(iPage<2) || iPage>pBt->nPage ){
7176571791
return SQLITE_CORRUPT_BKPT;
7176671792
}
7176771793
if( pMemPage ){
7176871794
pPage = pMemPage;
7176971795
sqlite3PagerRef(pPage->pDbPage);
@@ -74360,11 +74386,14 @@
7436074386
assert( szNew==pPage->xCellSize(pPage, newCell) );
7436174387
assert( szNew <= MX_CELL_SIZE(pBt) );
7436274388
idx = pCur->ix;
7436374389
if( loc==0 ){
7436474390
CellInfo info;
74365
- assert( idx<pPage->nCell );
74391
+ assert( idx>=0 );
74392
+ if( idx>=pPage->nCell ){
74393
+ return SQLITE_CORRUPT_BKPT;
74394
+ }
7436674395
rc = sqlite3PagerWrite(pPage->pDbPage);
7436774396
if( rc ){
7436874397
goto end_insert;
7436974398
}
7437074399
oldCell = findCell(pPage, idx);
@@ -74946,15 +74975,16 @@
7494674975
if( pgno>btreePagecount(pBt) ){
7494774976
return SQLITE_CORRUPT_BKPT;
7494874977
}
7494974978
rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
7495074979
if( rc ) return rc;
74951
- if( pPage->bBusy ){
74980
+ if( (pBt->openFlags & BTREE_SINGLE)==0
74981
+ && sqlite3PagerPageRefcount(pPage->pDbPage)!=1
74982
+ ){
7495274983
rc = SQLITE_CORRUPT_BKPT;
7495374984
goto cleardatabasepage_out;
7495474985
}
74955
- pPage->bBusy = 1;
7495674986
hdr = pPage->hdrOffset;
7495774987
for(i=0; i<pPage->nCell; i++){
7495874988
pCell = findCell(pPage, i);
7495974989
if( !pPage->leaf ){
7496074990
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
@@ -74977,11 +75007,10 @@
7497775007
}else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
7497875008
zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
7497975009
}
7498075010
7498175011
cleardatabasepage_out:
74982
- pPage->bBusy = 0;
7498375012
releasePage(pPage);
7498475013
return rc;
7498575014
}
7498675015
7498775016
/*
@@ -75056,14 +75085,14 @@
7505675085
assert( iTable>=2 );
7505775086
if( iTable>btreePagecount(pBt) ){
7505875087
return SQLITE_CORRUPT_BKPT;
7505975088
}
7506075089
75061
- rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
75062
- if( rc ) return rc;
7506375090
rc = sqlite3BtreeClearTable(p, iTable, 0);
75064
- if( rc ){
75091
+ if( rc ) return rc;
75092
+ rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
75093
+ if( NEVER(rc) ){
7506575094
releasePage(pPage);
7506675095
return rc;
7506775096
}
7506875097
7506975098
*piMoved = 0;
@@ -78434,12 +78463,14 @@
7843478463
ExprList *pList = 0; /* Function arguments */
7843578464
int i; /* Iterator variable */
7843678465
7843778466
assert( pCtx!=0 );
7843878467
assert( (p->flags & EP_TokenOnly)==0 );
78468
+ assert( ExprUseXList(p) );
7843978469
pList = p->x.pList;
7844078470
if( pList ) nVal = pList->nExpr;
78471
+ assert( !ExprHasProperty(p, EP_IntValue) );
7844178472
pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
7844278473
assert( pFunc );
7844378474
if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
7844478475
|| (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
7844578476
){
@@ -78539,11 +78570,13 @@
7853978570
** check ensures that an EP_TokenOnly expression is never passed down
7854078571
** into valueFromFunction(). */
7854178572
assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
7854278573
7854378574
if( op==TK_CAST ){
78544
- u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
78575
+ u8 aff;
78576
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
78577
+ aff = sqlite3AffinityType(pExpr->u.zToken,0);
7854578578
rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
7854678579
testcase( rc!=SQLITE_OK );
7854778580
if( *ppVal ){
7854878581
sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
7854978582
sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
@@ -78612,10 +78645,11 @@
7861278645
sqlite3VdbeMemSetNull(pVal);
7861378646
}
7861478647
#ifndef SQLITE_OMIT_BLOB_LITERAL
7861578648
else if( op==TK_BLOB ){
7861678649
int nVal;
78650
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
7861778651
assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
7861878652
assert( pExpr->u.zToken[1]=='\'' );
7861978653
pVal = valueNew(db, pCtx);
7862078654
if( !pVal ) goto no_mem;
7862178655
zVal = &pExpr->u.zToken[2];
@@ -78629,10 +78663,11 @@
7862978663
else if( op==TK_FUNCTION && pCtx!=0 ){
7863078664
rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
7863178665
}
7863278666
#endif
7863378667
else if( op==TK_TRUEFALSE ){
78668
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
7863478669
pVal = valueNew(db, pCtx);
7863578670
if( pVal ){
7863678671
pVal->flags = MEM_Int;
7863778672
pVal->u.i = pExpr->u.zToken[4]==0;
7863878673
}
@@ -80501,10 +80536,11 @@
8050180536
*/
8050280537
static void displayP4Expr(StrAccum *p, Expr *pExpr){
8050380538
const char *zOp = 0;
8050480539
switch( pExpr->op ){
8050580540
case TK_STRING:
80541
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
8050680542
sqlite3_str_appendf(p, "%Q", pExpr->u.zToken);
8050780543
break;
8050880544
case TK_INTEGER:
8050980545
sqlite3_str_appendf(p, "%d", pExpr->u.iValue);
8051080546
break;
@@ -80847,12 +80883,12 @@
8084780883
** with no indexes using a single prepared INSERT statement, bind()
8084880884
** and reset(). Inserts are grouped into a transaction.
8084980885
*/
8085080886
testcase( p->flags & MEM_Agg );
8085180887
testcase( p->flags & MEM_Dyn );
80852
- testcase( p->xDel==sqlite3VdbeFrameMemDel );
8085380888
if( p->flags&(MEM_Agg|MEM_Dyn) ){
80889
+ testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
8085480890
sqlite3VdbeMemRelease(p);
8085580891
}else if( p->szMalloc ){
8085680892
sqlite3DbFreeNN(db, p->zMalloc);
8085780893
p->szMalloc = 0;
8085880894
}
@@ -84553,12 +84589,12 @@
8455384589
/**************************** sqlite3_result_ *******************************
8455484590
** The following routines are used by user-defined functions to specify
8455584591
** the function result.
8455684592
**
8455784593
** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
84558
-** result as a string or blob but if the string or blob is too large, it
84559
-** then sets the error code to SQLITE_TOOBIG
84594
+** result as a string or blob. Appropriate errors are set if the string/blob
84595
+** is too big or if an OOM occurs.
8456084596
**
8456184597
** The invokeValueDestructor(P,X) routine invokes destructor function X()
8456284598
** on value P is not going to be used and need to be destroyed.
8456384599
*/
8456484600
static void setResultStrOrError(
@@ -84566,12 +84602,20 @@
8456684602
const char *z, /* String pointer */
8456784603
int n, /* Bytes in string, or negative */
8456884604
u8 enc, /* Encoding of z. 0 for BLOBs */
8456984605
void (*xDel)(void*) /* Destructor function */
8457084606
){
84571
- if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){
84572
- sqlite3_result_error_toobig(pCtx);
84607
+ int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel);
84608
+ if( rc ){
84609
+ if( rc==SQLITE_TOOBIG ){
84610
+ sqlite3_result_error_toobig(pCtx);
84611
+ }else{
84612
+ /* The only errors possible from sqlite3VdbeMemSetStr are
84613
+ ** SQLITE_TOOBIG and SQLITE_NOMEM */
84614
+ assert( rc==SQLITE_NOMEM );
84615
+ sqlite3_result_error_nomem(pCtx);
84616
+ }
8457384617
}
8457484618
}
8457584619
static int invokeValueDestructor(
8457684620
const void *p, /* Value to destroy */
8457784621
void (*xDel)(void*), /* The destructor */
@@ -90536,11 +90580,11 @@
9053690580
assert( aMem[pOp->p3].flags & MEM_Null );
9053790581
aMem[pOp->p3].n = 0;
9053890582
aMem[pOp->p3].z = "";
9053990583
}
9054090584
pCx = p->apCsr[pOp->p1];
90541
- if( pCx && !pCx->hasBeenDuped ){
90585
+ if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){
9054290586
/* If the ephermeral table is already open and has no duplicates from
9054390587
** OP_OpenDup, then erase all existing content so that the table is
9054490588
** empty again, rather than creating a new table. */
9054590589
assert( pCx->isEphemeral );
9054690590
pCx->seqCount = 0;
@@ -95092,11 +95136,11 @@
9509295136
/* Check that the column is not part of an FK child key definition. It
9509395137
** is not necessary to check if it is part of a parent key, as parent
9509495138
** key columns must be indexed. The check below will pick up this
9509595139
** case. */
9509695140
FKey *pFKey;
95097
- assert( !IsVirtual(pTab) );
95141
+ assert( IsOrdinaryTable(pTab) );
9509895142
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
9509995143
int j;
9510095144
for(j=0; j<pFKey->nCol; j++){
9510195145
if( pFKey->aCol[j].iFrom==iCol ){
9510295146
zFault = "foreign key";
@@ -99101,11 +99145,11 @@
9910199145
if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
9910299146
if( pExpr->pRight ){
9910399147
assert( !ExprHasProperty(pExpr, EP_WinFunc) );
9910499148
pExpr = pExpr->pRight;
9910599149
continue;
99106
- }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
99150
+ }else if( ExprUseXSelect(pExpr) ){
9910799151
assert( !ExprHasProperty(pExpr, EP_WinFunc) );
9910899152
if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
9910999153
}else{
9911099154
if( pExpr->x.pList ){
9911199155
if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
@@ -99373,10 +99417,11 @@
9937399417
sqlite3ExprDelete(db, pDup);
9937499418
pDup = 0;
9937599419
}else{
9937699420
incrAggFunctionDepth(pDup, nSubquery);
9937799421
if( pExpr->op==TK_COLLATE ){
99422
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
9937899423
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
9937999424
}
9938099425
9938199426
/* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
9938299427
** prevents ExprDelete() from deleting the Expr structure itself,
@@ -99476,10 +99521,11 @@
9947699521
SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){
9947799522
int n;
9947899523
Table *pExTab;
9947999524
9948099525
n = pExpr->iColumn;
99526
+ assert( ExprUseYTab(pExpr) );
9948199527
pExTab = pExpr->y.pTab;
9948299528
assert( pExTab!=0 );
9948399529
if( (pExTab->tabFlags & TF_HasGenerated)!=0
9948499530
&& (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
9948599531
){
@@ -99613,10 +99659,11 @@
9961399659
const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
9961499660
assert( zTabName!=0 );
9961599661
if( sqlite3StrICmp(zTabName, zTab)!=0 ){
9961699662
continue;
9961799663
}
99664
+ assert( ExprUseYTab(pExpr) );
9961899665
if( IN_RENAME_OBJECT && pItem->zAlias ){
9961999666
sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
9962099667
}
9962199668
}
9962299669
hCol = sqlite3StrIHash(zCol);
@@ -99644,10 +99691,11 @@
9964499691
pMatch = pItem;
9964599692
}
9964699693
}
9964799694
if( pMatch ){
9964899695
pExpr->iTable = pMatch->iCursor;
99696
+ assert( ExprUseYTab(pExpr) );
9964999697
pExpr->y.pTab = pMatch->pTab;
9965099698
/* RIGHT JOIN not (yet) supported */
9965199699
assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
9965299700
if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
9965399701
ExprSetProperty(pExpr, EP_CanBeNull);
@@ -99717,10 +99765,11 @@
9971799765
cnt++;
9971899766
pMatch = 0;
9971999767
#ifndef SQLITE_OMIT_UPSERT
9972099768
if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
9972199769
testcase( iCol==(-1) );
99770
+ assert( ExprUseYTab(pExpr) );
9972299771
if( IN_RENAME_OBJECT ){
9972399772
pExpr->iColumn = iCol;
9972499773
pExpr->y.pTab = pTab;
9972599774
eNewExprOp = TK_COLUMN;
9972699775
}else{
@@ -99729,10 +99778,11 @@
9972999778
eNewExprOp = TK_REGISTER;
9973099779
}
9973199780
}else
9973299781
#endif /* SQLITE_OMIT_UPSERT */
9973399782
{
99783
+ assert( ExprUseYTab(pExpr) );
9973499784
pExpr->y.pTab = pTab;
9973599785
if( pParse->bReturning ){
9973699786
eNewExprOp = TK_REGISTER;
9973799787
pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
9973899788
sqlite3TableColumnToStorage(pTab, iCol) + 1;
@@ -99803,12 +99853,12 @@
9980399853
if( pEList->a[j].eEName==ENAME_NAME
9980499854
&& sqlite3_stricmp(zAs, zCol)==0
9980599855
){
9980699856
Expr *pOrig;
9980799857
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
99808
- assert( pExpr->x.pList==0 );
99809
- assert( pExpr->x.pSelect==0 );
99858
+ assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
99859
+ assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 );
9981099860
pOrig = pEList->a[j].pExpr;
9981199861
if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
9981299862
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
9981399863
return WRC_Abort;
9981499864
}
@@ -99876,11 +99926,11 @@
9987699926
"double-quoted string literal: \"%w\"", zCol);
9987799927
#ifdef SQLITE_ENABLE_NORMALIZE
9987899928
sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
9987999929
#endif
9988099930
pExpr->op = TK_STRING;
99881
- pExpr->y.pTab = 0;
99931
+ memset(&pExpr->y, 0, sizeof(pExpr->y));
9988299932
return WRC_Prune;
9988399933
}
9988499934
if( sqlite3ExprIdToTrueFalse(pExpr) ){
9988599935
return WRC_Prune;
9988699936
}
@@ -99962,11 +100012,13 @@
99962100012
*/
99963100013
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
99964100014
Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
99965100015
if( p ){
99966100016
SrcItem *pItem = &pSrc->a[iSrc];
99967
- Table *pTab = p->y.pTab = pItem->pTab;
100017
+ Table *pTab;
100018
+ assert( ExprUseYTab(p) );
100019
+ pTab = p->y.pTab = pItem->pTab;
99968100020
p->iTable = pItem->iCursor;
99969100021
if( p->y.pTab->iPKey==iCol ){
99970100022
p->iColumn = -1;
99971100023
}else{
99972100024
p->iColumn = (ynVar)iCol;
@@ -100029,10 +100081,11 @@
100029100081
** value between 1.0 and 0.0.
100030100082
*/
100031100083
static int exprProbability(Expr *p){
100032100084
double r = -1.0;
100033100085
if( p->op!=TK_FLOAT ) return -1;
100086
+ assert( !ExprHasProperty(p, EP_IntValue) );
100034100087
sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
100035100088
assert( r>=0.0 );
100036100089
if( r>1.0 ) return -1;
100037100090
return (int)(r*134217728.0);
100038100091
}
@@ -100077,10 +100130,11 @@
100077100130
SrcList *pSrcList = pNC->pSrcList;
100078100131
SrcItem *pItem;
100079100132
assert( pSrcList && pSrcList->nSrc>=1 );
100080100133
pItem = pSrcList->a;
100081100134
pExpr->op = TK_COLUMN;
100135
+ assert( ExprUseYTab(pExpr) );
100082100136
pExpr->y.pTab = pItem->pTab;
100083100137
pExpr->iTable = pItem->iCursor;
100084100138
pExpr->iColumn--;
100085100139
pExpr->affExpr = SQLITE_AFF_INTEGER;
100086100140
break;
@@ -100109,10 +100163,11 @@
100109100163
anRef[i] = p->nRef;
100110100164
}
100111100165
sqlite3WalkExpr(pWalker, pExpr->pLeft);
100112100166
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
100113100167
testcase( ExprHasProperty(pExpr, EP_FromJoin) );
100168
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
100114100169
if( pExpr->op==TK_NOTNULL ){
100115100170
pExpr->u.zToken = "true";
100116100171
ExprSetProperty(pExpr, EP_IsTrue);
100117100172
}else{
100118100173
pExpr->u.zToken = "false";
@@ -100144,10 +100199,11 @@
100144100199
Expr *pRight;
100145100200
100146100201
if( pExpr->op==TK_ID ){
100147100202
zDb = 0;
100148100203
zTable = 0;
100204
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
100149100205
zColumn = pExpr->u.zToken;
100150100206
}else{
100151100207
Expr *pLeft = pExpr->pLeft;
100152100208
testcase( pNC->ncFlags & NC_IdxExpr );
100153100209
testcase( pNC->ncFlags & NC_GenCol );
@@ -100156,16 +100212,19 @@
100156100212
pRight = pExpr->pRight;
100157100213
if( pRight->op==TK_ID ){
100158100214
zDb = 0;
100159100215
}else{
100160100216
assert( pRight->op==TK_DOT );
100217
+ assert( !ExprHasProperty(pRight, EP_IntValue) );
100161100218
zDb = pLeft->u.zToken;
100162100219
pLeft = pRight->pLeft;
100163100220
pRight = pRight->pRight;
100164100221
}
100222
+ assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) );
100165100223
zTable = pLeft->u.zToken;
100166100224
zColumn = pRight->u.zToken;
100225
+ assert( ExprUseYTab(pExpr) );
100167100226
if( IN_RENAME_OBJECT ){
100168100227
sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
100169100228
sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
100170100229
}
100171100230
}
@@ -100186,11 +100245,11 @@
100186100245
u8 enc = ENC(pParse->db); /* The database encoding */
100187100246
int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
100188100247
#ifndef SQLITE_OMIT_WINDOWFUNC
100189100248
Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
100190100249
#endif
100191
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
100250
+ assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
100192100251
zId = pExpr->u.zToken;
100193100252
nId = sqlite3Strlen30(zId);
100194100253
pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
100195100254
if( pDef==0 ){
100196100255
pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
@@ -100350,11 +100409,11 @@
100350100409
sqlite3WalkExprList(pWalker, pList);
100351100410
if( is_agg ){
100352100411
#ifndef SQLITE_OMIT_WINDOWFUNC
100353100412
if( pWin ){
100354100413
Select *pSel = pNC->pWinSelect;
100355
- assert( pWin==pExpr->y.pWin );
100414
+ assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) );
100356100415
if( IN_RENAME_OBJECT==0 ){
100357100416
sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
100358100417
if( pParse->db->mallocFailed ) break;
100359100418
}
100360100419
sqlite3WalkExprList(pWalker, pWin->pPartition);
@@ -100399,11 +100458,11 @@
100399100458
case TK_SELECT:
100400100459
case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
100401100460
#endif
100402100461
case TK_IN: {
100403100462
testcase( pExpr->op==TK_IN );
100404
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
100463
+ if( ExprUseXSelect(pExpr) ){
100405100464
int nRef = pNC->nRef;
100406100465
testcase( pNC->ncFlags & NC_IsCheck );
100407100466
testcase( pNC->ncFlags & NC_PartIdx );
100408100467
testcase( pNC->ncFlags & NC_IdxExpr );
100409100468
testcase( pNC->ncFlags & NC_GenCol );
@@ -100456,10 +100515,11 @@
100456100515
int nLeft, nRight;
100457100516
if( pParse->db->mallocFailed ) break;
100458100517
assert( pExpr->pLeft!=0 );
100459100518
nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
100460100519
if( pExpr->op==TK_BETWEEN ){
100520
+ assert( ExprUseXList(pExpr) );
100461100521
nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
100462100522
if( nRight==nLeft ){
100463100523
nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
100464100524
}
100465100525
}else{
@@ -100504,11 +100564,13 @@
100504100564
int i; /* Loop counter */
100505100565
100506100566
UNUSED_PARAMETER(pParse);
100507100567
100508100568
if( pE->op==TK_ID ){
100509
- char *zCol = pE->u.zToken;
100569
+ const char *zCol;
100570
+ assert( !ExprHasProperty(pE, EP_IntValue) );
100571
+ zCol = pE->u.zToken;
100510100572
for(i=0; i<pEList->nExpr; i++){
100511100573
if( pEList->a[i].eEName==ENAME_NAME
100512100574
&& sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
100513100575
){
100514100576
return i+1;
@@ -101369,15 +101431,18 @@
101369101431
pExpr = pExpr->pLeft;
101370101432
assert( pExpr!=0 );
101371101433
}
101372101434
op = pExpr->op;
101373101435
if( op==TK_REGISTER ) op = pExpr->op2;
101374
- if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){
101375
- return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101436
+ if( op==TK_COLUMN || op==TK_AGG_COLUMN ){
101437
+ assert( ExprUseYTab(pExpr) );
101438
+ if( pExpr->y.pTab ){
101439
+ return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101440
+ }
101376101441
}
101377101442
if( op==TK_SELECT ){
101378
- assert( pExpr->flags&EP_xIsSelect );
101443
+ assert( ExprUseXSelect(pExpr) );
101379101444
assert( pExpr->x.pSelect!=0 );
101380101445
assert( pExpr->x.pSelect->pEList!=0 );
101381101446
assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
101382101447
return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
101383101448
}
@@ -101386,18 +101451,19 @@
101386101451
assert( !ExprHasProperty(pExpr, EP_IntValue) );
101387101452
return sqlite3AffinityType(pExpr->u.zToken, 0);
101388101453
}
101389101454
#endif
101390101455
if( op==TK_SELECT_COLUMN ){
101391
- assert( pExpr->pLeft->flags&EP_xIsSelect );
101456
+ assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
101392101457
assert( pExpr->iColumn < pExpr->iTable );
101393101458
assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
101394101459
return sqlite3ExprAffinity(
101395101460
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
101396101461
);
101397101462
}
101398101463
if( op==TK_VECTOR ){
101464
+ assert( ExprUseXList(pExpr) );
101399101465
return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
101400101466
}
101401101467
return pExpr->affExpr;
101402101468
}
101403101469
@@ -101453,11 +101519,11 @@
101453101519
** expression.
101454101520
*/
101455101521
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
101456101522
while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){
101457101523
if( ExprHasProperty(pExpr, EP_Unlikely) ){
101458
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
101524
+ assert( ExprUseXList(pExpr) );
101459101525
assert( pExpr->x.pList->nExpr>0 );
101460101526
assert( pExpr->op==TK_FUNCTION );
101461101527
pExpr = pExpr->x.pList->a[0].pExpr;
101462101528
}else{
101463101529
assert( pExpr->op==TK_COLLATE );
@@ -101486,45 +101552,46 @@
101486101552
CollSeq *pColl = 0;
101487101553
const Expr *p = pExpr;
101488101554
while( p ){
101489101555
int op = p->op;
101490101556
if( op==TK_REGISTER ) op = p->op2;
101491
- if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER)
101492
- && p->y.pTab!=0
101493
- ){
101494
- /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101495
- ** a TK_COLUMN but was previously evaluated and cached in a register */
101496
- int j = p->iColumn;
101497
- if( j>=0 ){
101498
- const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101499
- pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101500
- }
101501
- break;
101557
+ if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){
101558
+ assert( ExprUseYTab(p) );
101559
+ if( p->y.pTab!=0 ){
101560
+ /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101561
+ ** a TK_COLUMN but was previously evaluated and cached in a register */
101562
+ int j = p->iColumn;
101563
+ if( j>=0 ){
101564
+ const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101565
+ pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101566
+ }
101567
+ break;
101568
+ }
101502101569
}
101503101570
if( op==TK_CAST || op==TK_UPLUS ){
101504101571
p = p->pLeft;
101505101572
continue;
101506101573
}
101507101574
if( op==TK_VECTOR ){
101575
+ assert( ExprUseXList(p) );
101508101576
p = p->x.pList->a[0].pExpr;
101509101577
continue;
101510101578
}
101511101579
if( op==TK_COLLATE ){
101580
+ assert( !ExprHasProperty(p, EP_IntValue) );
101512101581
pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
101513101582
break;
101514101583
}
101515101584
if( p->flags & EP_Collate ){
101516101585
if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
101517101586
p = p->pLeft;
101518101587
}else{
101519101588
Expr *pNext = p->pRight;
101520101589
/* The Expr.x union is never used at the same time as Expr.pRight */
101590
+ assert( ExprUseXList(p) );
101521101591
assert( p->x.pList==0 || p->pRight==0 );
101522
- if( p->x.pList!=0
101523
- && !db->mallocFailed
101524
- && ALWAYS(!ExprHasProperty(p, EP_xIsSelect))
101525
- ){
101592
+ if( p->x.pList!=0 && !db->mallocFailed ){
101526101593
int i;
101527101594
for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
101528101595
if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
101529101596
pNext = p->x.pList->a[i].pExpr;
101530101597
break;
@@ -101603,11 +101670,11 @@
101603101670
pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
101604101671
assert( pExpr->pLeft );
101605101672
aff = sqlite3ExprAffinity(pExpr->pLeft);
101606101673
if( pExpr->pRight ){
101607101674
aff = sqlite3CompareAffinity(pExpr->pRight, aff);
101608
- }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
101675
+ }else if( ExprUseXSelect(pExpr) ){
101609101676
aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
101610101677
}else if( aff==0 ){
101611101678
aff = SQLITE_AFF_BLOB;
101612101679
}
101613101680
return aff;
@@ -101743,12 +101810,14 @@
101743101810
*/
101744101811
SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){
101745101812
u8 op = pExpr->op;
101746101813
if( op==TK_REGISTER ) op = pExpr->op2;
101747101814
if( op==TK_VECTOR ){
101815
+ assert( ExprUseXList(pExpr) );
101748101816
return pExpr->x.pList->nExpr;
101749101817
}else if( op==TK_SELECT ){
101818
+ assert( ExprUseXSelect(pExpr) );
101750101819
return pExpr->x.pSelect->pEList->nExpr;
101751101820
}else{
101752101821
return 1;
101753101822
}
101754101823
}
@@ -101771,12 +101840,14 @@
101771101840
SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
101772101841
assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR );
101773101842
if( sqlite3ExprIsVector(pVector) ){
101774101843
assert( pVector->op2==0 || pVector->op==TK_REGISTER );
101775101844
if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){
101845
+ assert( ExprUseXSelect(pVector) );
101776101846
return pVector->x.pSelect->pEList->a[i].pExpr;
101777101847
}else{
101848
+ assert( ExprUseXList(pVector) );
101778101849
return pVector->x.pList->a[i].pExpr;
101779101850
}
101780101851
}
101781101852
return pVector;
101782101853
}
@@ -101808,11 +101879,11 @@
101808101879
int iField, /* Which column of the vector to return */
101809101880
int nField /* Total number of columns in the vector */
101810101881
){
101811101882
Expr *pRet;
101812101883
if( pVector->op==TK_SELECT ){
101813
- assert( pVector->flags & EP_xIsSelect );
101884
+ assert( ExprUseXSelect(pVector) );
101814101885
/* The TK_SELECT_COLUMN Expr node:
101815101886
**
101816101887
** pLeft: pVector containing TK_SELECT. Not deleted.
101817101888
** pRight: not used. But recursively deleted.
101818101889
** iColumn: Index of a column in pVector
@@ -101833,11 +101904,13 @@
101833101904
pRet->iColumn = iField;
101834101905
pRet->pLeft = pVector;
101835101906
}
101836101907
}else{
101837101908
if( pVector->op==TK_VECTOR ){
101838
- Expr **ppVector = &pVector->x.pList->a[iField].pExpr;
101909
+ Expr **ppVector;
101910
+ assert( ExprUseXList(pVector) );
101911
+ ppVector = &pVector->x.pList->a[iField].pExpr;
101839101912
pVector = *ppVector;
101840101913
if( IN_RENAME_OBJECT ){
101841101914
/* This must be a vector UPDATE inside a trigger */
101842101915
*ppVector = 0;
101843101916
return pVector;
@@ -101897,14 +101970,16 @@
101897101970
if( op==TK_REGISTER ){
101898101971
*ppExpr = sqlite3VectorFieldSubexpr(pVector, iField);
101899101972
return pVector->iTable+iField;
101900101973
}
101901101974
if( op==TK_SELECT ){
101975
+ assert( ExprUseXSelect(pVector) );
101902101976
*ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr;
101903101977
return regSelect+iField;
101904101978
}
101905101979
if( op==TK_VECTOR ){
101980
+ assert( ExprUseXList(pVector) );
101906101981
*ppExpr = pVector->x.pList->a[iField].pExpr;
101907101982
return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree);
101908101983
}
101909101984
return 0;
101910101985
}
@@ -102075,11 +102150,11 @@
102075102150
*/
102076102151
static void exprSetHeight(Expr *p){
102077102152
int nHeight = 0;
102078102153
heightOfExpr(p->pLeft, &nHeight);
102079102154
heightOfExpr(p->pRight, &nHeight);
102080
- if( ExprHasProperty(p, EP_xIsSelect) ){
102155
+ if( ExprUseXSelect(p) ){
102081102156
heightOfSelect(p->x.pSelect, &nHeight);
102082102157
}else if( p->x.pList ){
102083102158
heightOfExprList(p->x.pList, &nHeight);
102084102159
p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102085102160
}
@@ -102114,11 +102189,11 @@
102114102189
** Propagate all EP_Propagate flags from the Expr.x.pList into
102115102190
** Expr.flags.
102116102191
*/
102117102192
SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
102118102193
if( pParse->nErr ) return;
102119
- if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
102194
+ if( p && ExprUseXList(p) && p->x.pList ){
102120102195
p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102121102196
}
102122102197
}
102123102198
#define exprSetHeight(y)
102124102199
#endif /* SQLITE_MAX_EXPR_DEPTH>0 */
@@ -102298,17 +102373,24 @@
102298102373
Select *pRet = 0;
102299102374
assert( nElem>1 );
102300102375
for(ii=0; ii<pEList->nExpr; ii++){
102301102376
Select *pSel;
102302102377
Expr *pExpr = pEList->a[ii].pExpr;
102303
- int nExprElem = (pExpr->op==TK_VECTOR ? pExpr->x.pList->nExpr : 1);
102378
+ int nExprElem;
102379
+ if( pExpr->op==TK_VECTOR ){
102380
+ assert( ExprUseXList(pExpr) );
102381
+ nExprElem = pExpr->x.pList->nExpr;
102382
+ }else{
102383
+ nExprElem = 1;
102384
+ }
102304102385
if( nExprElem!=nElem ){
102305102386
sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d",
102306102387
nExprElem, nExprElem>1?"s":"", nElem
102307102388
);
102308102389
break;
102309102390
}
102391
+ assert( ExprUseXList(pExpr) );
102310102392
pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
102311102393
pExpr->x.pList = 0;
102312102394
if( pSel ){
102313102395
if( pRet ){
102314102396
pSel->op = TK_ALL;
@@ -102374,11 +102456,11 @@
102374102456
){
102375102457
sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
102376102458
}
102377102459
pNew->x.pList = pList;
102378102460
ExprSetProperty(pNew, EP_HasFunc);
102379
- assert( !ExprHasProperty(pNew, EP_xIsSelect) );
102461
+ assert( ExprUseXList(pNew) );
102380102462
sqlite3ExprSetHeightAndFlags(pParse, pNew);
102381102463
if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
102382102464
return pNew;
102383102465
}
102384102466
@@ -102500,31 +102582,30 @@
102500102582
/*
102501102583
** Recursively delete an expression tree.
102502102584
*/
102503102585
static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
102504102586
assert( p!=0 );
102505
- /* Sanity check: Assert that the IntValue is non-negative if it exists */
102506
- assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
102507
-
102508
- assert( !ExprHasProperty(p, EP_WinFunc) || p->y.pWin!=0 || db->mallocFailed );
102509
- assert( p->op!=TK_FUNCTION || ExprHasProperty(p, EP_TokenOnly|EP_Reduced)
102510
- || p->y.pWin==0 || ExprHasProperty(p, EP_WinFunc) );
102587
+ assert( !ExprUseUValue(p) || p->u.iValue>=0 );
102588
+ assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
102589
+ assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
102590
+ assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) );
102511102591
#ifdef SQLITE_DEBUG
102512102592
if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){
102513102593
assert( p->pLeft==0 );
102514102594
assert( p->pRight==0 );
102515
- assert( p->x.pSelect==0 );
102595
+ assert( !ExprUseXSelect(p) || p->x.pSelect==0 );
102596
+ assert( !ExprUseXList(p) || p->x.pList==0 );
102516102597
}
102517102598
#endif
102518102599
if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){
102519102600
/* The Expr.x union is never used at the same time as Expr.pRight */
102520
- assert( p->x.pList==0 || p->pRight==0 );
102601
+ assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 );
102521102602
if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft);
102522102603
if( p->pRight ){
102523102604
assert( !ExprHasProperty(p, EP_WinFunc) );
102524102605
sqlite3ExprDeleteNN(db, p->pRight);
102525
- }else if( ExprHasProperty(p, EP_xIsSelect) ){
102606
+ }else if( ExprUseXSelect(p) ){
102526102607
assert( !ExprHasProperty(p, EP_WinFunc) );
102527102608
sqlite3SelectDelete(db, p->x.pSelect);
102528102609
}else{
102529102610
sqlite3ExprListDelete(db, p->x.pList);
102530102611
#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -102532,11 +102613,14 @@
102532102613
sqlite3WindowDelete(db, p->y.pWin);
102533102614
}
102534102615
#endif
102535102616
}
102536102617
}
102537
- if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
102618
+ if( ExprHasProperty(p, EP_MemToken) ){
102619
+ assert( !ExprHasProperty(p, EP_IntValue) );
102620
+ sqlite3DbFree(db, p->u.zToken);
102621
+ }
102538102622
if( !ExprHasProperty(p, EP_Static) ){
102539102623
sqlite3DbFreeNN(db, p);
102540102624
}
102541102625
}
102542102626
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
@@ -102748,11 +102832,11 @@
102748102832
memcpy(zToken, p->u.zToken, nToken);
102749102833
}
102750102834
102751102835
if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){
102752102836
/* Fill in the pNew->x.pSelect or pNew->x.pList member. */
102753
- if( ExprHasProperty(p, EP_xIsSelect) ){
102837
+ if( ExprUseXSelect(p) ){
102754102838
pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
102755102839
}else{
102756102840
pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
102757102841
}
102758102842
}
@@ -103375,11 +103459,11 @@
103375103459
** the conversion happened, and zero if the expression is unaltered.
103376103460
*/
103377103461
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
103378103462
u32 v;
103379103463
assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
103380
- if( !ExprHasProperty(pExpr, EP_Quoted)
103464
+ if( !ExprHasProperty(pExpr, EP_Quoted|EP_IntValue)
103381103465
&& (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
103382103466
){
103383103467
pExpr->op = TK_TRUEFALSE;
103384103468
ExprSetProperty(pExpr, v);
103385103469
return 1;
@@ -103392,10 +103476,11 @@
103392103476
** and 0 if it is FALSE.
103393103477
*/
103394103478
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
103395103479
pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
103396103480
assert( pExpr->op==TK_TRUEFALSE );
103481
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
103397103482
assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
103398103483
|| sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
103399103484
return pExpr->u.zToken[4]==0;
103400103485
}
103401103486
@@ -103596,11 +103681,11 @@
103596103681
}
103597103682
}
103598103683
}
103599103684
103600103685
/* Check if pExpr is a sub-select. If so, consider it variable. */
103601
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
103686
+ if( ExprUseXSelect(pExpr) ){
103602103687
pWalker->eCode = 0;
103603103688
return WRC_Abort;
103604103689
}
103605103690
103606103691
return exprNodeIsConstant(pWalker, pExpr);
@@ -103746,10 +103831,11 @@
103746103831
case TK_STRING:
103747103832
case TK_FLOAT:
103748103833
case TK_BLOB:
103749103834
return 0;
103750103835
case TK_COLUMN:
103836
+ assert( ExprUseYTab(p) );
103751103837
return ExprHasProperty(p, EP_CanBeNull) ||
103752103838
p->y.pTab==0 || /* Reference to column of index on expression */
103753103839
(p->iColumn>=0
103754103840
&& ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
103755103841
&& p->y.pTab->aCol[p->iColumn].notNull==0);
@@ -103823,11 +103909,11 @@
103823103909
Select *p;
103824103910
SrcList *pSrc;
103825103911
ExprList *pEList;
103826103912
Table *pTab;
103827103913
int i;
103828
- if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */
103914
+ if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */
103829103915
if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
103830103916
p = pX->x.pSelect;
103831103917
if( p->pPrior ) return 0; /* Not a compound SELECT */
103832103918
if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
103833103919
testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -103994,11 +104080,11 @@
103994104080
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
103995104081
** whether or not the SELECT result contains NULL values, check whether
103996104082
** or not NULL is actually possible (it may not be, for example, due
103997104083
** to NOT NULL constraints in the schema). If no NULL values are possible,
103998104084
** set prRhsHasNull to 0 before continuing. */
103999
- if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){
104085
+ if( prRhsHasNull && ExprUseXSelect(pX) ){
104000104086
int i;
104001104087
ExprList *pEList = pX->x.pSelect->pEList;
104002104088
for(i=0; i<pEList->nExpr; i++){
104003104089
if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break;
104004104090
}
@@ -104150,11 +104236,11 @@
104150104236
** then it is not worth creating an ephemeral table to evaluate
104151104237
** the IN operator so return IN_INDEX_NOOP.
104152104238
*/
104153104239
if( eType==0
104154104240
&& (inFlags & IN_INDEX_NOOP_OK)
104155
- && !ExprHasProperty(pX, EP_xIsSelect)
104241
+ && ExprUseXList(pX)
104156104242
&& (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
104157104243
){
104158104244
eType = IN_INDEX_NOOP;
104159104245
}
104160104246
@@ -104198,11 +104284,11 @@
104198104284
** string is eventually freed using sqlite3DbFree().
104199104285
*/
104200104286
static char *exprINAffinity(Parse *pParse, const Expr *pExpr){
104201104287
Expr *pLeft = pExpr->pLeft;
104202104288
int nVal = sqlite3ExprVectorSize(pLeft);
104203
- Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0;
104289
+ Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
104204104290
char *zRet;
104205104291
104206104292
assert( pExpr->op==TK_IN );
104207104293
zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
104208104294
if( zRet ){
@@ -104248,11 +104334,11 @@
104248104334
**
104249104335
** "row value misused"
104250104336
*/
104251104337
SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
104252104338
#ifndef SQLITE_OMIT_SUBQUERY
104253
- if( pExpr->flags & EP_xIsSelect ){
104339
+ if( ExprUseXSelect(pExpr) ){
104254104340
sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
104255104341
}else
104256104342
#endif
104257104343
{
104258104344
sqlite3ErrorMsg(pParse, "row value misused");
@@ -104312,22 +104398,24 @@
104312104398
/* If this routine has already been coded, but the previous code
104313104399
** might not have been invoked yet, so invoke it now as a subroutine.
104314104400
*/
104315104401
if( ExprHasProperty(pExpr, EP_Subrtn) ){
104316104402
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
104317
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104403
+ if( ExprUseXSelect(pExpr) ){
104318104404
ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
104319104405
pExpr->x.pSelect->selId));
104320104406
}
104407
+ assert( ExprUseYSub(pExpr) );
104321104408
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104322104409
pExpr->y.sub.iAddr);
104323104410
sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
104324104411
sqlite3VdbeJumpHere(v, addrOnce);
104325104412
return;
104326104413
}
104327104414
104328104415
/* Begin coding the subroutine */
104416
+ assert( !ExprUseYWin(pExpr) );
104329104417
ExprSetProperty(pExpr, EP_Subrtn);
104330104418
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
104331104419
pExpr->y.sub.regReturn = ++pParse->nMem;
104332104420
pExpr->y.sub.iAddr =
104333104421
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
@@ -104344,19 +104432,19 @@
104344104432
** RHS of the IN operator.
104345104433
*/
104346104434
pExpr->iTable = iTab;
104347104435
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
104348104436
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
104349
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104437
+ if( ExprUseXSelect(pExpr) ){
104350104438
VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
104351104439
}else{
104352104440
VdbeComment((v, "RHS of IN operator"));
104353104441
}
104354104442
#endif
104355104443
pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
104356104444
104357
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104445
+ if( ExprUseXSelect(pExpr) ){
104358104446
/* Case 1: expr IN (SELECT ...)
104359104447
**
104360104448
** Generate code to write the results of the select into the temporary
104361104449
** table allocated and opened above.
104362104450
*/
@@ -104450,10 +104538,11 @@
104450104538
sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
104451104539
}
104452104540
if( addrOnce ){
104453104541
sqlite3VdbeJumpHere(v, addrOnce);
104454104542
/* Subroutine return */
104543
+ assert( ExprUseYSub(pExpr) );
104455104544
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104456104545
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104457104546
sqlite3ClearTempRegCache(pParse);
104458104547
}
104459104548
}
@@ -104486,23 +104575,26 @@
104486104575
assert( v!=0 );
104487104576
if( pParse->nErr ) return 0;
104488104577
testcase( pExpr->op==TK_EXISTS );
104489104578
testcase( pExpr->op==TK_SELECT );
104490104579
assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
104491
- assert( ExprHasProperty(pExpr, EP_xIsSelect) );
104580
+ assert( ExprUseXSelect(pExpr) );
104492104581
pSel = pExpr->x.pSelect;
104493104582
104494104583
/* If this routine has already been coded, then invoke it as a
104495104584
** subroutine. */
104496104585
if( ExprHasProperty(pExpr, EP_Subrtn) ){
104497104586
ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
104587
+ assert( ExprUseYSub(pExpr) );
104498104588
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104499104589
pExpr->y.sub.iAddr);
104500104590
return pExpr->iTable;
104501104591
}
104502104592
104503104593
/* Begin coding the subroutine */
104594
+ assert( !ExprUseYWin(pExpr) );
104595
+ assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) );
104504104596
ExprSetProperty(pExpr, EP_Subrtn);
104505104597
pExpr->y.sub.regReturn = ++pParse->nMem;
104506104598
pExpr->y.sub.iAddr =
104507104599
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
104508104600
VdbeComment((v, "return address"));
@@ -104578,10 +104670,11 @@
104578104670
if( addrOnce ){
104579104671
sqlite3VdbeJumpHere(v, addrOnce);
104580104672
}
104581104673
104582104674
/* Subroutine return */
104675
+ assert( ExprUseYSub(pExpr) );
104583104676
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104584104677
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104585104678
sqlite3ClearTempRegCache(pParse);
104586104679
return rReg;
104587104680
}
@@ -104594,11 +104687,11 @@
104594104687
** columns as the vector on the LHS. Or, if the RHS of the IN() is not
104595104688
** a sub-query, that the LHS is a vector of size 1.
104596104689
*/
104597104690
SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
104598104691
int nVector = sqlite3ExprVectorSize(pIn->pLeft);
104599
- if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){
104692
+ if( ExprUseXSelect(pIn) && !pParse->db->mallocFailed ){
104600104693
if( nVector!=pIn->x.pSelect->pEList->nExpr ){
104601104694
sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
104602104695
return 1;
104603104696
}
104604104697
}else if( nVector!=1 ){
@@ -104728,17 +104821,19 @@
104728104821
** sequence of comparisons.
104729104822
**
104730104823
** This is step (1) in the in-operator.md optimized algorithm.
104731104824
*/
104732104825
if( eType==IN_INDEX_NOOP ){
104733
- ExprList *pList = pExpr->x.pList;
104734
- CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
104826
+ ExprList *pList;
104827
+ CollSeq *pColl;
104735104828
int labelOk = sqlite3VdbeMakeLabel(pParse);
104736104829
int r2, regToFree;
104737104830
int regCkNull = 0;
104738104831
int ii;
104739
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
104832
+ assert( ExprUseXList(pExpr) );
104833
+ pList = pExpr->x.pList;
104834
+ pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
104740104835
if( destIfNull!=destIfFalse ){
104741104836
regCkNull = sqlite3GetTempReg(pParse);
104742104837
sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
104743104838
}
104744104839
for(ii=0; ii<pList->nExpr; ii++){
@@ -105120,10 +105215,11 @@
105120105215
#endif
105121105216
}else{
105122105217
int i;
105123105218
iResult = pParse->nMem+1;
105124105219
pParse->nMem += nResult;
105220
+ assert( ExprUseXList(p) );
105125105221
for(i=0; i<nResult; i++){
105126105222
sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
105127105223
}
105128105224
}
105129105225
}
@@ -105318,10 +105414,11 @@
105318105414
** datatype by applying the Affinity of the table column to the
105319105415
** constant.
105320105416
*/
105321105417
int aff;
105322105418
iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
105419
+ assert( ExprUseYTab(pExpr) );
105323105420
if( pExpr->y.pTab ){
105324105421
aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105325105422
}else{
105326105423
aff = pExpr->affExpr;
105327105424
}
@@ -105341,13 +105438,15 @@
105341105438
** The row is unpacked into registers beginning at
105342105439
** 0-(pParse->iSelfTab). The rowid (if any) is in a register
105343105440
** immediately prior to the first column.
105344105441
*/
105345105442
Column *pCol;
105346
- Table *pTab = pExpr->y.pTab;
105443
+ Table *pTab;
105347105444
int iSrc;
105348105445
int iCol = pExpr->iColumn;
105446
+ assert( ExprUseYTab(pExpr) );
105447
+ pTab = pExpr->y.pTab;
105349105448
assert( pTab!=0 );
105350105449
assert( iCol>=XN_ROWID );
105351105450
assert( iCol<pTab->nCol );
105352105451
if( iCol<0 ){
105353105452
return -1-pParse->iSelfTab;
@@ -105381,10 +105480,11 @@
105381105480
/* Coding an expression that is part of an index where column names
105382105481
** in the index refer to the table to which the index belongs */
105383105482
iTab = pParse->iSelfTab - 1;
105384105483
}
105385105484
}
105485
+ assert( ExprUseYTab(pExpr) );
105386105486
iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
105387105487
pExpr->iColumn, iTab, target,
105388105488
pExpr->op2);
105389105489
if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
105390105490
sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
@@ -105458,10 +105558,11 @@
105458105558
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
105459105559
if( inReg!=target ){
105460105560
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
105461105561
inReg = target;
105462105562
}
105563
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
105463105564
sqlite3VdbeAddOp2(v, OP_Cast, target,
105464105565
sqlite3AffinityType(pExpr->u.zToken, 0));
105465105566
return inReg;
105466105567
}
105467105568
#endif /* SQLITE_OMIT_CAST */
@@ -105625,12 +105726,12 @@
105625105726
if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
105626105727
/* SQL functions can be expensive. So try to avoid running them
105627105728
** multiple times if we know they always give the same result */
105628105729
return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
105629105730
}
105630
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
105631105731
assert( !ExprHasProperty(pExpr, EP_TokenOnly) );
105732
+ assert( ExprUseXList(pExpr) );
105632105733
pFarg = pExpr->x.pList;
105633105734
nFarg = pFarg ? pFarg->nExpr : 0;
105634105735
assert( !ExprHasProperty(pExpr, EP_IntValue) );
105635105736
zId = pExpr->u.zToken;
105636105737
pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
@@ -105745,11 +105846,14 @@
105745105846
int nCol;
105746105847
testcase( op==TK_EXISTS );
105747105848
testcase( op==TK_SELECT );
105748105849
if( pParse->db->mallocFailed ){
105749105850
return 0;
105750
- }else if( op==TK_SELECT && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 ){
105851
+ }else if( op==TK_SELECT
105852
+ && ALWAYS( ExprUseXSelect(pExpr) )
105853
+ && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1
105854
+ ){
105751105855
sqlite3SubselectError(pParse, nCol, 1);
105752105856
}else{
105753105857
return sqlite3CodeSubselect(pParse, pExpr);
105754105858
}
105755105859
break;
@@ -105827,13 +105931,18 @@
105827105931
**
105828105932
** p1==0 -> old.rowid p1==3 -> new.rowid
105829105933
** p1==1 -> old.a p1==4 -> new.a
105830105934
** p1==2 -> old.b p1==5 -> new.b
105831105935
*/
105832
- Table *pTab = pExpr->y.pTab;
105833
- int iCol = pExpr->iColumn;
105834
- int p1 = pExpr->iTable * (pTab->nCol+1) + 1
105936
+ Table *pTab;
105937
+ int iCol;
105938
+ int p1;
105939
+
105940
+ assert( ExprUseYTab(pExpr) );
105941
+ pTab = pExpr->y.pTab;
105942
+ iCol = pExpr->iColumn;
105943
+ p1 = pExpr->iTable * (pTab->nCol+1) + 1
105835105944
+ sqlite3TableColumnToStorage(pTab, iCol);
105836105945
105837105946
assert( pExpr->iTable==0 || pExpr->iTable==1 );
105838105947
assert( iCol>=-1 && iCol<pTab->nCol );
105839105948
assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
@@ -105917,11 +106026,11 @@
105917106026
Expr *pX; /* The X expression */
105918106027
Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
105919106028
Expr *pDel = 0;
105920106029
sqlite3 *db = pParse->db;
105921106030
105922
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
106031
+ assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 );
105923106032
assert(pExpr->x.pList->nExpr > 0);
105924106033
pEList = pExpr->x.pList;
105925106034
aListelem = pEList->a;
105926106035
nExpr = pEList->nExpr;
105927106036
endLabel = sqlite3VdbeMakeLabel(pParse);
@@ -106262,11 +106371,11 @@
106262106371
106263106372
memset(&compLeft, 0, sizeof(Expr));
106264106373
memset(&compRight, 0, sizeof(Expr));
106265106374
memset(&exprAnd, 0, sizeof(Expr));
106266106375
106267
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
106376
+ assert( ExprUseXList(pExpr) );
106268106377
pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
106269106378
if( db->mallocFailed==0 ){
106270106379
exprAnd.op = TK_AND;
106271106380
exprAnd.pLeft = &compLeft;
106272106381
exprAnd.pRight = &compRight;
@@ -106737,11 +106846,16 @@
106737106846
if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
106738106847
return 1;
106739106848
}
106740106849
return 2;
106741106850
}
106742
- if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){
106851
+ if( pA->op!=TK_COLUMN
106852
+ && pA->op!=TK_AGG_COLUMN
106853
+ && ALWAYS(!ExprHasProperty(pA, EP_IntValue))
106854
+ && pA->u.zToken
106855
+ ){
106856
+ assert( !ExprHasProperty(pB, EP_IntValue) );
106743106857
if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){
106744106858
if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
106745106859
#ifndef SQLITE_OMIT_WINDOWFUNC
106746106860
assert( pA->op==pB->op );
106747106861
if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){
@@ -106844,16 +106958,17 @@
106844106958
return pNN->op!=TK_NULL;
106845106959
}
106846106960
switch( p->op ){
106847106961
case TK_IN: {
106848106962
if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
106849
- assert( ExprHasProperty(p,EP_xIsSelect)
106850
- || (p->x.pList!=0 && p->x.pList->nExpr>0) );
106963
+ assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) );
106851106964
return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
106852106965
}
106853106966
case TK_BETWEEN: {
106854
- ExprList *pList = p->x.pList;
106967
+ ExprList *pList;
106968
+ assert( ExprUseXList(p) );
106969
+ pList = p->x.pList;
106855106970
assert( pList!=0 );
106856106971
assert( pList->nExpr==2 );
106857106972
if( seenNot ) return 0;
106858106973
if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
106859106974
|| exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1)
@@ -107026,14 +107141,18 @@
107026107141
testcase( pExpr->op==TK_LE );
107027107142
testcase( pExpr->op==TK_GT );
107028107143
testcase( pExpr->op==TK_GE );
107029107144
/* The y.pTab=0 assignment in wherecode.c always happens after the
107030107145
** impliesNotNullRow() test */
107031
- if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0
107032
- && IsVirtual(pLeft->y.pTab))
107033
- || (pRight->op==TK_COLUMN && pRight->y.pTab!=0
107034
- && IsVirtual(pRight->y.pTab))
107146
+ assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
107147
+ assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
107148
+ if( (pLeft->op==TK_COLUMN
107149
+ && pLeft->y.pTab!=0
107150
+ && IsVirtual(pLeft->y.pTab))
107151
+ || (pRight->op==TK_COLUMN
107152
+ && pRight->y.pTab!=0
107153
+ && IsVirtual(pRight->y.pTab))
107035107154
){
107036107155
return WRC_Prune;
107037107156
}
107038107157
/* no break */ deliberate_fall_through
107039107158
}
@@ -107213,10 +107332,11 @@
107213107332
w.u.pSrcCount = &cnt;
107214107333
cnt.pSrc = pSrcList;
107215107334
cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
107216107335
cnt.nThis = 0;
107217107336
cnt.nOther = 0;
107337
+ assert( ExprUseXList(pExpr) );
107218107338
sqlite3WalkExprList(&w, pExpr->x.pList);
107219107339
#ifndef SQLITE_OMIT_WINDOWFUNC
107220107340
if( ExprHasProperty(pExpr, EP_WinFunc) ){
107221107341
sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
107222107342
}
@@ -107354,10 +107474,11 @@
107354107474
}
107355107475
if( (k>=pAggInfo->nColumn)
107356107476
&& (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
107357107477
){
107358107478
pCol = &pAggInfo->aCol[k];
107479
+ assert( ExprUseYTab(pExpr) );
107359107480
pCol->pTab = pExpr->y.pTab;
107360107481
pCol->iTable = pExpr->iTable;
107361107482
pCol->iColumn = pExpr->iColumn;
107362107483
pCol->iMem = ++pParse->nMem;
107363107484
pCol->iSorterColumn = -1;
@@ -107417,11 +107538,11 @@
107417107538
if( i>=0 ){
107418107539
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
107419107540
pItem = &pAggInfo->aFunc[i];
107420107541
pItem->pFExpr = pExpr;
107421107542
pItem->iMem = ++pParse->nMem;
107422
- assert( !ExprHasProperty(pExpr, EP_IntValue) );
107543
+ assert( ExprUseUToken(pExpr) );
107423107544
pItem->pFunc = sqlite3FindFunction(pParse->db,
107424107545
pExpr->u.zToken,
107425107546
pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
107426107547
if( pExpr->flags & EP_Distinct ){
107427107548
pItem->iDistinct = pParse->nTab++;
@@ -107939,10 +108060,11 @@
107939108060
*/
107940108061
assert( pDflt==0 || pDflt->op==TK_SPAN );
107941108062
if( pDflt && pDflt->pLeft->op==TK_NULL ){
107942108063
pDflt = 0;
107943108064
}
108065
+ assert( IsOrdinaryTable(pNew) );
107944108066
if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
107945108067
sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
107946108068
"Cannot add a REFERENCES column with non-NULL default value");
107947108069
}
107948108070
if( pCol->notNull && !pDflt ){
@@ -107981,11 +108103,12 @@
107981108103
while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
107982108104
*zEnd-- = '\0';
107983108105
}
107984108106
/* substr() operations on characters, but addColOffset is in bytes. So we
107985108107
** have to use printf() to translate between these units: */
107986
- assert( !IsVirtual(pTab) );
108108
+ assert( IsOrdinaryTable(pTab) );
108109
+ assert( IsOrdinaryTable(pNew) );
107987108110
sqlite3NestedParse(pParse,
107988108111
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
107989108112
"sql = printf('%%.%ds, ',sql) || %Q"
107990108113
" || substr(sql,1+length(printf('%%.%ds',sql))) "
107991108114
"WHERE type = 'table' AND name = %Q",
@@ -108075,10 +108198,11 @@
108075108198
if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
108076108199
goto exit_begin_add_column;
108077108200
}
108078108201
108079108202
sqlite3MayAbort(pParse);
108203
+ assert( IsOrdinaryTable(pTab) );
108080108204
assert( pTab->u.tab.addColOffset>0 );
108081108205
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108082108206
108083108207
/* Put a copy of the Table struct in Parse.pNewTable for the
108084108208
** sqlite3AddColumn() function and friends to modify. But modify
@@ -108105,11 +108229,11 @@
108105108229
for(i=0; i<pNew->nCol; i++){
108106108230
Column *pCol = &pNew->aCol[i];
108107108231
pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
108108108232
pCol->hName = sqlite3StrIHash(pCol->zCnName);
108109108233
}
108110
- assert( !IsVirtual(pNew) );
108234
+ assert( IsOrdinaryTable(pNew) );
108111108235
pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
108112108236
pNew->pSchema = db->aDb[iDb].pSchema;
108113108237
pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
108114108238
pNew->nTabRef = 1;
108115108239
@@ -108374,11 +108498,13 @@
108374108498
** Walker callback used by sqlite3RenameExprUnmap().
108375108499
*/
108376108500
static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
108377108501
Parse *pParse = pWalker->pParse;
108378108502
sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
108379
- sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
108503
+ if( ExprUseYTab(pExpr) ){
108504
+ sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
108505
+ }
108380108506
return WRC_Continue;
108381108507
}
108382108508
108383108509
/*
108384108510
** Iterate through the Select objects that are part of WITH clauses attached
@@ -108436,11 +108562,13 @@
108436108562
*/
108437108563
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
108438108564
Parse *pParse = pWalker->pParse;
108439108565
int i;
108440108566
if( pParse->nErr ) return WRC_Abort;
108441
- if( NEVER(p->selFlags & (SF_View|SF_CopyCte)) ){
108567
+ testcase( p->selFlags & SF_View );
108568
+ testcase( p->selFlags & SF_CopyCte );
108569
+ if( p->selFlags & (SF_View|SF_CopyCte) ){
108442108570
return WRC_Prune;
108443108571
}
108444108572
if( ALWAYS(p->pEList) ){
108445108573
ExprList *pList = p->pEList;
108446108574
for(i=0; i<pList->nExpr; i++){
@@ -108573,10 +108701,11 @@
108573108701
&& pWalker->pParse->pTriggerTab==p->pTab
108574108702
){
108575108703
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108576108704
}else if( pExpr->op==TK_COLUMN
108577108705
&& pExpr->iColumn==p->iCol
108706
+ && ALWAYS(ExprUseYTab(pExpr))
108578108707
&& p->pTab==pExpr->y.pTab
108579108708
){
108580108709
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108581108710
}
108582108711
return WRC_Continue;
@@ -109103,11 +109232,11 @@
109103109232
sqlite3WalkExpr(&sWalker, pExpr);
109104109233
}
109105109234
#endif
109106109235
}
109107109236
109108
- assert( !IsVirtual(sParse.pNewTable) );
109237
+ assert( IsOrdinaryTable(sParse.pNewTable) );
109109109238
for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109110109239
for(i=0; i<pFKey->nCol; i++){
109111109240
if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
109112109241
renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
109113109242
}
@@ -109175,11 +109304,14 @@
109175109304
/*
109176109305
** Walker expression callback used by "RENAME TABLE".
109177109306
*/
109178109307
static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
109179109308
RenameCtx *p = pWalker->u.pRename;
109180
- if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){
109309
+ if( pExpr->op==TK_COLUMN
109310
+ && ALWAYS(ExprUseYTab(pExpr))
109311
+ && p->pTab==pExpr->y.pTab
109312
+ ){
109181109313
renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab);
109182109314
}
109183109315
return WRC_Continue;
109184109316
}
109185109317
@@ -109293,11 +109425,11 @@
109293109425
#ifndef SQLITE_OMIT_FOREIGN_KEY
109294109426
if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
109295109427
&& !IsVirtual(pTab)
109296109428
){
109297109429
FKey *pFKey;
109298
- assert( !IsVirtual(pTab) );
109430
+ assert( IsOrdinaryTable(pTab) );
109299109431
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109300109432
if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109301109433
renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109302109434
}
109303109435
}
@@ -109614,11 +109746,11 @@
109614109746
if( iCol<pTab->nCol-1 ){
109615109747
RenameToken *pEnd;
109616109748
pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
109617109749
zEnd = (const char*)pEnd->t.z;
109618109750
}else{
109619
- assert( !IsVirtual(pTab) );
109751
+ assert( IsOrdinaryTable(pTab) );
109620109752
zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
109621109753
while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109622109754
}
109623109755
109624109756
zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
@@ -110789,11 +110921,11 @@
110789110921
pParse->nMem = MAX(pParse->nMem, iMem);
110790110922
v = sqlite3GetVdbe(pParse);
110791110923
if( v==0 || NEVER(pTab==0) ){
110792110924
return;
110793110925
}
110794
- if( pTab->tnum==0 ){
110926
+ if( !IsOrdinaryTable(pTab) ){
110795110927
/* Do not gather statistics on views or virtual tables */
110796110928
return;
110797110929
}
110798110930
if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
110799110931
/* Do not gather statistics on system tables */
@@ -112083,10 +112215,11 @@
112083112215
112084112216
#ifndef SQLITE_OMIT_AUTHORIZATION
112085112217
if( pAuthArg ){
112086112218
char *zAuthArg;
112087112219
if( pAuthArg->op==TK_STRING ){
112220
+ assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112088112221
zAuthArg = pAuthArg->u.zToken;
112089112222
}else{
112090112223
zAuthArg = 0;
112091112224
}
112092112225
rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
@@ -112767,21 +112900,25 @@
112767112900
Returning *pReturning = pParse->u1.pReturning;
112768112901
int addrRewind;
112769112902
int i;
112770112903
int reg;
112771112904
112772
- addrRewind =
112773
- sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
112774
- VdbeCoverage(v);
112775
- reg = pReturning->iRetReg;
112776
- for(i=0; i<pReturning->nRetCol; i++){
112777
- sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i);
112778
- }
112779
- sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i);
112780
- sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1);
112781
- VdbeCoverage(v);
112782
- sqlite3VdbeJumpHere(v, addrRewind);
112905
+ if( pReturning->nRetCol==0 ){
112906
+ assert( CORRUPT_DB );
112907
+ }else{
112908
+ addrRewind =
112909
+ sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
112910
+ VdbeCoverage(v);
112911
+ reg = pReturning->iRetReg;
112912
+ for(i=0; i<pReturning->nRetCol; i++){
112913
+ sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i);
112914
+ }
112915
+ sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i);
112916
+ sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1);
112917
+ VdbeCoverage(v);
112918
+ sqlite3VdbeJumpHere(v, addrRewind);
112919
+ }
112783112920
}
112784112921
sqlite3VdbeAddOp0(v, OP_Halt);
112785112922
112786112923
#if SQLITE_USER_AUTHENTICATION
112787112924
if( pParse->nTableLock>0 && db->init.busy==0 ){
@@ -112858,11 +112995,15 @@
112858112995
}
112859112996
}
112860112997
112861112998
if( pParse->bReturning ){
112862112999
Returning *pRet = pParse->u1.pReturning;
112863
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
113000
+ if( pRet->nRetCol==0 ){
113001
+ assert( CORRUPT_DB );
113002
+ }else{
113003
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
113004
+ }
112864113005
}
112865113006
112866113007
/* Finally, jump back to the beginning of the executable code. */
112867113008
sqlite3VdbeGoto(v, 1);
112868113009
}
@@ -113280,11 +113421,11 @@
113280113421
Table *pTab, /* The table containing the column */
113281113422
Column *pCol, /* The column to receive the new DEFAULT expression */
113282113423
Expr *pExpr /* The new default expression */
113283113424
){
113284113425
ExprList *pList;
113285
- assert( !IsVirtual(pTab) );
113426
+ assert( IsOrdinaryTable(pTab) );
113286113427
pList = pTab->u.tab.pDfltList;
113287113428
if( pCol->iDflt==0
113288113429
|| NEVER(pList==0)
113289113430
|| NEVER(pList->nExpr<pCol->iDflt)
113290113431
){
@@ -113301,11 +113442,11 @@
113301113442
** the DEFAULT clause or the AS clause of a generated column.
113302113443
** Return NULL if the column has no associated expression.
113303113444
*/
113304113445
SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){
113305113446
if( pCol->iDflt==0 ) return 0;
113306
- if( NEVER(IsVirtual(pTab)) ) return 0;
113447
+ if( NEVER(!IsOrdinaryTable(pTab)) ) return 0;
113307113448
if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
113308113449
if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
113309113450
return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
113310113451
}
113311113452
@@ -113360,17 +113501,17 @@
113360113501
for(i=0; i<pTable->nCol; i++, pCol++){
113361113502
assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
113362113503
sqlite3DbFree(db, pCol->zCnName);
113363113504
}
113364113505
sqlite3DbFree(db, pTable->aCol);
113365
- if( !IsVirtual(pTable) ){
113506
+ if( IsOrdinaryTable(pTable) ){
113366113507
sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
113367113508
}
113368113509
if( db==0 || db->pnBytesFreed==0 ){
113369113510
pTable->aCol = 0;
113370113511
pTable->nCol = 0;
113371
- if( !IsVirtual(pTable) ){
113512
+ if( IsOrdinaryTable(pTable) ){
113372113513
pTable->u.tab.pDfltList = 0;
113373113514
}
113374113515
}
113375113516
}
113376113517
}
@@ -114433,11 +114574,13 @@
114433114574
for(i=0; i<nTerm; i++){
114434114575
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
114435114576
assert( pCExpr!=0 );
114436114577
sqlite3StringToId(pCExpr);
114437114578
if( pCExpr->op==TK_ID ){
114438
- const char *zCName = pCExpr->u.zToken;
114579
+ const char *zCName;
114580
+ assert( !ExprHasProperty(pCExpr, EP_IntValue) );
114581
+ zCName = pCExpr->u.zToken;
114439114582
for(iCol=0; iCol<pTab->nCol; iCol++){
114440114583
if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
114441114584
pCol = &pTab->aCol[iCol];
114442114585
makeColumnPartOfPrimaryKey(pParse, pCol);
114443114586
break;
@@ -114805,11 +114948,10 @@
114805114948
** This is used to determine if the column number x appears in any of the
114806114949
** first nCol entries of an index.
114807114950
*/
114808114951
static int hasColumn(const i16 *aiCol, int nCol, int x){
114809114952
while( nCol-- > 0 ){
114810
- assert( aiCol[0]>=0 );
114811114953
if( x==*(aiCol++) ){
114812114954
return 1;
114813114955
}
114814114956
}
114815114957
return 0;
@@ -115181,11 +115323,11 @@
115181115323
**
115182115324
** If the root page number is 1, that means this is the sqlite_schema
115183115325
** table itself. So mark it read-only.
115184115326
*/
115185115327
if( db->init.busy ){
115186
- if( pSelect ){
115328
+ if( pSelect || (!IsOrdinaryTable(p) && db->init.newTnum) ){
115187115329
sqlite3ErrorMsg(pParse, "");
115188115330
return;
115189115331
}
115190115332
p->tnum = db->init.newTnum;
115191115333
if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
@@ -116146,10 +116288,11 @@
116146116288
pFKey = sqlite3DbMallocZero(db, nByte );
116147116289
if( pFKey==0 ){
116148116290
goto fk_end;
116149116291
}
116150116292
pFKey->pFrom = p;
116293
+ assert( IsOrdinaryTable(p) );
116151116294
pFKey->pNextFrom = p->u.tab.pFKey;
116152116295
z = (char*)&pFKey->aCol[nCol];
116153116296
pFKey->zTo = z;
116154116297
if( IN_RENAME_OBJECT ){
116155116298
sqlite3RenameTokenMap(pParse, (void*)z, pTo);
@@ -116211,11 +116354,11 @@
116211116354
pNextTo->pPrevTo = pFKey;
116212116355
}
116213116356
116214116357
/* Link the foreign key to the table as the last step.
116215116358
*/
116216
- assert( !IsVirtual(p) );
116359
+ assert( IsOrdinaryTable(p) );
116217116360
p->u.tab.pFKey = pFKey;
116218116361
pFKey = 0;
116219116362
116220116363
fk_end:
116221116364
sqlite3DbFree(db, pFKey);
@@ -116234,11 +116377,11 @@
116234116377
SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
116235116378
#ifndef SQLITE_OMIT_FOREIGN_KEY
116236116379
Table *pTab;
116237116380
FKey *pFKey;
116238116381
if( (pTab = pParse->pNewTable)==0 ) return;
116239
- if( NEVER(IsVirtual(pTab)) ) return;
116382
+ if( NEVER(!IsOrdinaryTable(pTab)) ) return;
116240116383
if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
116241116384
assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
116242116385
pFKey->isDeferred = (u8)isDeferred;
116243116386
#endif
116244116387
}
@@ -116636,10 +116779,11 @@
116636116779
*/
116637116780
for(i=0; i<pList->nExpr; i++){
116638116781
Expr *pExpr = pList->a[i].pExpr;
116639116782
assert( pExpr!=0 );
116640116783
if( pExpr->op==TK_COLLATE ){
116784
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
116641116785
nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
116642116786
}
116643116787
}
116644116788
116645116789
/*
@@ -116731,10 +116875,11 @@
116731116875
pIndex->aiColumn[i] = (i16)j;
116732116876
}
116733116877
zColl = 0;
116734116878
if( pListItem->pExpr->op==TK_COLLATE ){
116735116879
int nColl;
116880
+ assert( !ExprHasProperty(pListItem->pExpr, EP_IntValue) );
116736116881
zColl = pListItem->pExpr->u.zToken;
116737116882
nColl = sqlite3Strlen30(zColl) + 1;
116738116883
assert( nExtra>=nColl );
116739116884
memcpy(zExtra, zColl, nColl);
116740116885
zColl = zExtra;
@@ -117519,10 +117664,11 @@
117519117664
** construct "indexed_opt" for details. */
117520117665
pItem->fg.notIndexed = 1;
117521117666
}else{
117522117667
pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
117523117668
pItem->fg.isIndexedBy = 1;
117669
+ assert( pItem->fg.isCte==0 ); /* No collision on union u2 */
117524117670
}
117525117671
}
117526117672
}
117527117673
117528117674
/*
@@ -118499,10 +118645,11 @@
118499118645
int h, /* Hash of the name */
118500118646
const char *zFunc /* Name of function */
118501118647
){
118502118648
FuncDef *p;
118503118649
for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){
118650
+ assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
118504118651
if( sqlite3StrICmp(p->zName, zFunc)==0 ){
118505118652
return p;
118506118653
}
118507118654
}
118508118655
return 0;
@@ -118520,10 +118667,11 @@
118520118667
FuncDef *pOther;
118521118668
const char *zName = aDef[i].zName;
118522118669
int nName = sqlite3Strlen30(zName);
118523118670
int h = SQLITE_FUNC_HASH(zName[0], nName);
118524118671
assert( zName[0]>='a' && zName[0]<='z' );
118672
+ assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN );
118525118673
pOther = sqlite3FunctionSearch(h, zName);
118526118674
if( pOther ){
118527118675
assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] );
118528118676
aDef[i].pNext = pOther->pNext;
118529118677
pOther->pNext = &aDef[i];
@@ -118911,10 +119059,11 @@
118911119059
** and the SELECT subtree. */
118912119060
pSrc->a[0].pTab = 0;
118913119061
pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
118914119062
pSrc->a[0].pTab = pTab;
118915119063
if( pSrc->a[0].fg.isIndexedBy ){
119064
+ assert( pSrc->a[0].fg.isCte==0 );
118916119065
pSrc->a[0].u2.pIBIndex = 0;
118917119066
pSrc->a[0].fg.isIndexedBy = 0;
118918119067
sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
118919119068
}else if( pSrc->a[0].fg.isCte ){
118920119069
pSrc->a[0].u2.pCteUse->nUse++;
@@ -121495,11 +121644,15 @@
121495121644
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
121496121645
pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
121497121646
/* pGCC is always non-NULL since groupConcatStep() will have always
121498121647
** run frist to initialize it */
121499121648
if( ALWAYS(pGCC) ){
121500
- int nVS = sqlite3_value_bytes(argv[0]);
121649
+ int nVS;
121650
+ /* Must call sqlite3_value_text() to convert the argument into text prior
121651
+ ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
121652
+ (void)sqlite3_value_text(argv[0]);
121653
+ nVS = sqlite3_value_bytes(argv[0]);
121501121654
pGCC->nAccum -= 1;
121502121655
if( pGCC->pnSepLengths!=0 ){
121503121656
assert(pGCC->nAccum >= 0);
121504121657
if( pGCC->nAccum>0 ){
121505121658
nVS += *pGCC->pnSepLengths;
@@ -121610,15 +121763,16 @@
121610121763
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
121611121764
FuncDef *pDef;
121612121765
int nExpr;
121613121766
assert( pExpr!=0 );
121614121767
assert( pExpr->op==TK_FUNCTION );
121768
+ assert( ExprUseXList(pExpr) );
121615121769
if( !pExpr->x.pList ){
121616121770
return 0;
121617121771
}
121618
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
121619121772
nExpr = pExpr->x.pList->nExpr;
121773
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
121620121774
pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
121621121775
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
121622121776
if( pDef==0 ) return 0;
121623121777
#endif
121624121778
if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
@@ -121638,10 +121792,11 @@
121638121792
aWc[3] = 0;
121639121793
}else{
121640121794
Expr *pEscape = pExpr->x.pList->a[2].pExpr;
121641121795
char *zEscape;
121642121796
if( pEscape->op!=TK_STRING ) return 0;
121797
+ assert( !ExprHasProperty(pEscape, EP_IntValue) );
121643121798
zEscape = pEscape->u.zToken;
121644121799
if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
121645121800
if( zEscape[0]==aWc[0] ) return 0;
121646121801
if( zEscape[0]==aWc[1] ) return 0;
121647121802
aWc[3] = zEscape[0];
@@ -122019,10 +122174,11 @@
122019122174
for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
122020122175
printf("FUNC-HASH %02d:", i);
122021122176
for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){
122022122177
int n = sqlite3Strlen30(p->zName);
122023122178
int h = p->zName[0] + n;
122179
+ assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
122024122180
printf(" %s(%d)", p->zName, h);
122025122181
}
122026122182
printf("\n");
122027122183
}
122028122184
}
@@ -122541,10 +122697,11 @@
122541122697
int iCursor, /* The open cursor on the table */
122542122698
i16 iCol /* The column that is wanted */
122543122699
){
122544122700
Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
122545122701
if( pExpr ){
122702
+ assert( ExprUseYTab(pExpr) );
122546122703
pExpr->y.pTab = pTab;
122547122704
pExpr->iTable = iCursor;
122548122705
pExpr->iColumn = iCol;
122549122706
}
122550122707
return pExpr;
@@ -122751,17 +122908,16 @@
122751122908
** the table from the database. Triggers are disabled while running this
122752122909
** DELETE, but foreign key actions are not.
122753122910
*/
122754122911
SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
122755122912
sqlite3 *db = pParse->db;
122756
- if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
122913
+ if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){
122757122914
int iSkip = 0;
122758122915
Vdbe *v = sqlite3GetVdbe(pParse);
122759122916
122760122917
assert( v ); /* VDBE has already been allocated */
122761
- assert( !IsView(pTab) ); /* Not a view */
122762
- assert( !IsVirtual(pTab) );
122918
+ assert( IsOrdinaryTable(pTab) );
122763122919
if( sqlite3FkReferences(pTab)==0 ){
122764122920
/* Search for a deferred foreign key constraint for which this table
122765122921
** is the child table. If one cannot be found, return without
122766122922
** generating any VDBE code. If one can be found, then jump over
122767122923
** the entire DELETE if there are no outstanding deferred constraints
@@ -122921,17 +123077,17 @@
122921123077
/* Exactly one of regOld and regNew should be non-zero. */
122922123078
assert( (regOld==0)!=(regNew==0) );
122923123079
122924123080
/* If foreign-keys are disabled, this function is a no-op. */
122925123081
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
123082
+ if( !IsOrdinaryTable(pTab) ) return;
122926123083
122927123084
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122928123085
zDb = db->aDb[iDb].zDbSName;
122929123086
122930123087
/* Loop through all the foreign key constraints for which pTab is the
122931123088
** child table (the table that the foreign key definition is part of). */
122932
- assert( !IsVirtual(pTab) );
122933123089
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
122934123090
Table *pTo; /* Parent table of foreign key pFKey */
122935123091
Index *pIdx = 0; /* Index on key columns in pTo */
122936123092
int *aiFree = 0;
122937123093
int *aiCol;
@@ -123110,14 +123266,13 @@
123110123266
SQLITE_PRIVATE u32 sqlite3FkOldmask(
123111123267
Parse *pParse, /* Parse context */
123112123268
Table *pTab /* Table being modified */
123113123269
){
123114123270
u32 mask = 0;
123115
- if( pParse->db->flags&SQLITE_ForeignKeys ){
123271
+ if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123116123272
FKey *p;
123117123273
int i;
123118
- assert( !IsVirtual(pTab) );
123119123274
for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
123120123275
for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
123121123276
}
123122123277
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
123123123278
Index *pIdx = 0;
@@ -123164,11 +123319,11 @@
123164123319
int *aChange, /* Non-NULL for UPDATE operations */
123165123320
int chngRowid /* True for UPDATE that affects rowid */
123166123321
){
123167123322
int eRet = 1; /* Value to return if bHaveFK is true */
123168123323
int bHaveFK = 0; /* If FK processing is required */
123169
- if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){
123324
+ if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123170123325
if( !aChange ){
123171123326
/* A DELETE operation. Foreign key processing is required if the
123172123327
** table in question is either the child or parent table for any
123173123328
** foreign key constraint. */
123174123329
bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
@@ -123452,11 +123607,11 @@
123452123607
*/
123453123608
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123454123609
FKey *pFKey; /* Iterator variable */
123455123610
FKey *pNext; /* Copy of pFKey->pNextFrom */
123456123611
123457
- assert( !IsVirtual(pTab) );
123612
+ assert( IsOrdinaryTable(pTab) );
123458123613
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
123459123614
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123460123615
123461123616
/* Remove the FK from the fkeyHash hash table. */
123462123617
if( !db || db->pnBytesFreed==0 ){
@@ -125711,10 +125866,11 @@
125711125866
** (5) No FK constraint counters need to be updated if a conflict occurs.
125712125867
**
125713125868
** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
125714125869
** must be explicitly deleted in order to ensure any pre-update hook
125715125870
** is invoked. */
125871
+ assert( IsOrdinaryTable(pTab) );
125716125872
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
125717125873
if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
125718125874
&& pPk==pIdx /* Condition 2 */
125719125875
&& onError==OE_Replace /* Condition 1 */
125720125876
&& ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
@@ -126391,11 +126547,13 @@
126391126547
/* Default values for second and subsequent columns need to match. */
126392126548
if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126393126549
Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
126394126550
Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
126395126551
assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
126552
+ assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
126396126553
assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
126554
+ assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
126397126555
if( (pDestExpr==0)!=(pSrcExpr==0)
126398126556
|| (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
126399126557
pSrcExpr->u.zToken)!=0)
126400126558
){
126401126559
return 0; /* Default values must be the same for all columns */
@@ -126431,10 +126589,11 @@
126431126589
** But the main beneficiary of the transfer optimization is the VACUUM
126432126590
** command, and the VACUUM command disables foreign key constraints. So
126433126591
** the extra complication to make this rule less restrictive is probably
126434126592
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126435126593
*/
126594
+ assert( IsOrdinaryTable(pDest) );
126436126595
if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
126437126596
return 0;
126438126597
}
126439126598
#endif
126440126599
if( (db->flags & SQLITE_CountRows)!=0 ){
@@ -129423,11 +129582,15 @@
129423129582
goto pragma_out;
129424129583
}
129425129584
129426129585
/* Locate the pragma in the lookup table */
129427129586
pPragma = pragmaLocate(zLeft);
129428
- if( pPragma==0 ) goto pragma_out;
129587
+ if( pPragma==0 ){
129588
+ /* IMP: R-43042-22504 No error messages are generated if an
129589
+ ** unknown pragma is issued. */
129590
+ goto pragma_out;
129591
+ }
129429129592
129430129593
/* Make sure the database schema is loaded if the pragma requires that */
129431129594
if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
129432129595
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
129433129596
}
@@ -130073,10 +130236,18 @@
130073130236
if( sqlite3GetBoolean(zRight, 0) ){
130074130237
db->flags |= mask;
130075130238
}else{
130076130239
db->flags &= ~mask;
130077130240
if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
130241
+ if( (mask & SQLITE_WriteSchema)!=0
130242
+ && sqlite3_stricmp(zRight, "reset")==0
130243
+ ){
130244
+ /* IMP: R-60817-01178 If the argument is "RESET" then schema
130245
+ ** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
130246
+ ** in addition, the schema is reloaded. */
130247
+ sqlite3ResetAllSchemasOfConnection(db);
130248
+ }
130078130249
}
130079130250
130080130251
/* Many of the flag-pragmas modify the code generated by the SQL
130081130252
** compiler (eg. count_changes). So add an opcode to expire all
130082130253
** compiled SQL statements after modifying a pragma value.
@@ -130113,10 +130284,11 @@
130113130284
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
130114130285
pParse->nMem = 7;
130115130286
sqlite3ViewGetColumnNames(pParse, pTab);
130116130287
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
130117130288
int isHidden = 0;
130289
+ const Expr *pColExpr;
130118130290
if( pCol->colFlags & COLFLAG_NOINSERT ){
130119130291
if( pPragma->iArg==0 ){
130120130292
nHidden++;
130121130293
continue;
130122130294
}
@@ -130133,20 +130305,20 @@
130133130305
}else if( pPk==0 ){
130134130306
k = 1;
130135130307
}else{
130136130308
for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
130137130309
}
130138
- assert( sqlite3ColumnExpr(pTab,pCol)==0
130139
- || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN
130140
- || isHidden>=2 );
130310
+ pColExpr = sqlite3ColumnExpr(pTab,pCol);
130311
+ assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 );
130312
+ assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue)
130313
+ || isHidden>=2 );
130141130314
sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
130142130315
i-nHidden,
130143130316
pCol->zCnName,
130144130317
sqlite3ColumnType(pCol,""),
130145130318
pCol->notNull ? 1 : 0,
130146
- isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 :
130147
- sqlite3ColumnExpr(pTab,pCol)->u.zToken,
130319
+ (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken,
130148130320
k,
130149130321
isHidden);
130150130322
}
130151130323
}
130152130324
}
@@ -130170,12 +130342,39 @@
130170130342
pParse->nMem = 6;
130171130343
sqlite3CodeVerifyNamedSchema(pParse, zDb);
130172130344
for(ii=0; ii<db->nDb; ii++){
130173130345
HashElem *k;
130174130346
Hash *pHash;
130347
+ int initNCol;
130175130348
if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
130349
+
130350
+ /* Ensure that the Table.nCol field is initialized for all views
130351
+ ** and virtual tables. Each time we initialize a Table.nCol value
130352
+ ** for a table, that can potentially disrupt the hash table, so restart
130353
+ ** the initialization scan.
130354
+ */
130176130355
pHash = &db->aDb[ii].pSchema->tblHash;
130356
+ initNCol = sqliteHashCount(pHash);
130357
+ while( initNCol-- ){
130358
+ for(k=sqliteHashFirst(pHash); 1; k=sqliteHashNext(k) ){
130359
+ Table *pTab;
130360
+ if( k==0 ){ initNCol = 0; break; }
130361
+ pTab = sqliteHashData(k);
130362
+ if( pTab->nCol==0 ){
130363
+ char *zSql = sqlite3MPrintf(db, "SELECT*FROM\"%w\"", pTab->zName);
130364
+ if( zSql ){
130365
+ sqlite3_stmt *pDummy = 0;
130366
+ (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
130367
+ (void)sqlite3_finalize(pDummy);
130368
+ sqlite3DbFree(db, zSql);
130369
+ }
130370
+ pHash = &db->aDb[ii].pSchema->tblHash;
130371
+ break;
130372
+ }
130373
+ }
130374
+ }
130375
+
130177130376
for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){
130178130377
Table *pTab = sqliteHashData(k);
130179130378
const char *zType;
130180130379
if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
130181130380
if( IsView(pTab) ){
@@ -130326,15 +130525,17 @@
130326130525
FuncDef *p;
130327130526
int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
130328130527
pParse->nMem = 6;
130329130528
for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
130330130529
for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
130530
+ assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
130331130531
pragmaFunclistLine(v, p, 1, showInternFunc);
130332130532
}
130333130533
}
130334130534
for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
130335130535
p = (FuncDef*)sqliteHashData(j);
130536
+ assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
130336130537
pragmaFunclistLine(v, p, 0, showInternFunc);
130337130538
}
130338130539
}
130339130540
break;
130340130541
@@ -130364,11 +130565,11 @@
130364130565
#ifndef SQLITE_OMIT_FOREIGN_KEY
130365130566
case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
130366130567
FKey *pFK;
130367130568
Table *pTab;
130368130569
pTab = sqlite3FindTable(db, zRight, zDb);
130369
- if( pTab && !IsVirtual(pTab) ){
130570
+ if( pTab && IsOrdinaryTable(pTab) ){
130370130571
pFK = pTab->u.tab.pFKey;
130371130572
if( pFK ){
130372130573
int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130373130574
int i = 0;
130374130575
pParse->nMem = 8;
@@ -130424,19 +130625,19 @@
130424130625
k = 0;
130425130626
}else{
130426130627
pTab = (Table*)sqliteHashData(k);
130427130628
k = sqliteHashNext(k);
130428130629
}
130429
- if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue;
130630
+ if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue;
130430130631
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130431130632
zDb = db->aDb[iDb].zDbSName;
130432130633
sqlite3CodeVerifySchema(pParse, iDb);
130433130634
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130434130635
if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130435130636
sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130436130637
sqlite3VdbeLoadString(v, regResult, pTab->zName);
130437
- assert( !IsVirtual(pTab) );
130638
+ assert( IsOrdinaryTable(pTab) );
130438130639
for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130439130640
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130440130641
if( pParent==0 ) continue;
130441130642
pIdx = 0;
130442130643
sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -130455,11 +130656,11 @@
130455130656
}
130456130657
assert( pParse->nErr>0 || pFK==0 );
130457130658
if( pFK ) break;
130458130659
if( pParse->nTab<i ) pParse->nTab = i;
130459130660
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130460
- assert( !IsVirtual(pTab) );
130661
+ assert( IsOrdinaryTable(pTab) );
130461130662
for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130462130663
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130463130664
pIdx = 0;
130464130665
aiCols = 0;
130465130666
if( pParent ){
@@ -130659,11 +130860,11 @@
130659130860
int loopTop;
130660130861
int iDataCur, iIdxCur;
130661130862
int r1 = -1;
130662130863
int bStrict;
130663130864
130664
- if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
130865
+ if( !IsOrdinaryTable(pTab) ) continue;
130665130866
if( pObjTab && pObjTab!=pTab ) continue;
130666130867
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
130667130868
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
130668130869
1, 0, &iDataCur, &iIdxCur);
130669130870
/* reg[7] counts the number of entries in the table.
@@ -131254,16 +131455,16 @@
131254131455
** in each index that it looks at. Return the new limit.
131255131456
*/
131256131457
case PragTyp_ANALYSIS_LIMIT: {
131257131458
sqlite3_int64 N;
131258131459
if( zRight
131259
- && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
131460
+ && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */
131260131461
&& N>=0
131261131462
){
131262131463
db->nAnalysisLimit = (int)(N&0x7fffffff);
131263131464
}
131264
- returnSingleInt(v, db->nAnalysisLimit);
131465
+ returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */
131265131466
break;
131266131467
}
131267131468
131268131469
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
131269131470
/*
@@ -133046,14 +133247,17 @@
133046133247
while( p ){
133047133248
ExprSetProperty(p, EP_FromJoin);
133048133249
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
133049133250
ExprSetVVAProperty(p, EP_NoReduce);
133050133251
p->iRightJoinTable = iTable;
133051
- if( p->op==TK_FUNCTION && p->x.pList ){
133052
- int i;
133053
- for(i=0; i<p->x.pList->nExpr; i++){
133054
- sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133252
+ if( p->op==TK_FUNCTION ){
133253
+ assert( ExprUseXList(p) );
133254
+ if( p->x.pList ){
133255
+ int i;
133256
+ for(i=0; i<p->x.pList->nExpr; i++){
133257
+ sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133258
+ }
133055133259
}
133056133260
}
133057133261
sqlite3SetJoinExpr(p->pLeft, iTable);
133058133262
p = p->pRight;
133059133263
}
@@ -133072,14 +133276,17 @@
133072133276
ExprClearProperty(p, EP_FromJoin);
133073133277
}
133074133278
if( p->op==TK_COLUMN && p->iTable==iTable ){
133075133279
ExprClearProperty(p, EP_CanBeNull);
133076133280
}
133077
- if( p->op==TK_FUNCTION && p->x.pList ){
133078
- int i;
133079
- for(i=0; i<p->x.pList->nExpr; i++){
133080
- unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133281
+ if( p->op==TK_FUNCTION ){
133282
+ assert( ExprUseXList(p) );
133283
+ if( p->x.pList ){
133284
+ int i;
133285
+ for(i=0; i<p->x.pList->nExpr; i++){
133286
+ unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133287
+ }
133081133288
}
133082133289
}
133083133290
unsetJoinExpr(p->pLeft, iTable);
133084133291
p = p->pRight;
133085133292
}
@@ -133590,13 +133797,17 @@
133590133797
ExprList *pExtra = 0;
133591133798
for(i=0; i<pEList->nExpr; i++){
133592133799
struct ExprList_item *pItem = &pEList->a[i];
133593133800
if( pItem->u.x.iOrderByCol==0 ){
133594133801
Expr *pExpr = pItem->pExpr;
133595
- Table *pTab = pExpr->y.pTab;
133596
- if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 && pTab && !IsVirtual(pTab)
133597
- && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)
133802
+ Table *pTab;
133803
+ if( pExpr->op==TK_COLUMN
133804
+ && pExpr->iColumn>=0
133805
+ && ALWAYS( ExprUseYTab(pExpr) )
133806
+ && (pTab = pExpr->y.pTab)!=0
133807
+ && IsOrdinaryTable(pTab)
133808
+ && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0
133598133809
){
133599133810
int j;
133600133811
for(j=0; j<nDefer; j++){
133601133812
if( pSort->aDefer[j].iCsr==pExpr->iTable ) break;
133602133813
}
@@ -133613,10 +133824,11 @@
133613133824
}
133614133825
for(k=0; k<nKey; k++){
133615133826
Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
133616133827
if( pNew ){
133617133828
pNew->iTable = pExpr->iTable;
133829
+ assert( ExprUseYTab(pNew) );
133618133830
pNew->y.pTab = pExpr->y.pTab;
133619133831
pNew->iColumn = pPk ? pPk->aiColumn[k] : -1;
133620133832
pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew);
133621133833
}
133622133834
}
@@ -134461,11 +134673,11 @@
134461134673
** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
134462134674
** branch below. */
134463134675
break;
134464134676
}
134465134677
134466
- assert( pTab && pExpr->y.pTab==pTab );
134678
+ assert( pTab && ExprUseYTab(pExpr) && pExpr->y.pTab==pTab );
134467134679
if( pS ){
134468134680
/* The "table" is actually a sub-select or a view in the FROM clause
134469134681
** of the SELECT statement. Return the declaration type and origin
134470134682
** data for the result-set column of the sub-select.
134471134683
*/
@@ -134521,13 +134733,15 @@
134521134733
/* The expression is a sub-select. Return the declaration type and
134522134734
** origin info for the single column in the result set of the SELECT
134523134735
** statement.
134524134736
*/
134525134737
NameContext sNC;
134526
- Select *pS = pExpr->x.pSelect;
134527
- Expr *p = pS->pEList->a[0].pExpr;
134528
- assert( ExprHasProperty(pExpr, EP_xIsSelect) );
134738
+ Select *pS;
134739
+ Expr *p;
134740
+ assert( ExprUseXSelect(pExpr) );
134741
+ pS = pExpr->x.pSelect;
134742
+ p = pS->pEList->a[0].pExpr;
134529134743
sNC.pSrcList = pS->pSrc;
134530134744
sNC.pNext = pNC;
134531134745
sNC.pParse = pNC->pParse;
134532134746
zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
134533134747
break;
@@ -134652,11 +134866,12 @@
134652134866
for(i=0; i<pEList->nExpr; i++){
134653134867
Expr *p = pEList->a[i].pExpr;
134654134868
134655134869
assert( p!=0 );
134656134870
assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
134657
- assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */
134871
+ assert( p->op!=TK_COLUMN
134872
+ || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
134658134873
if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
134659134874
/* An AS clause always takes first priority */
134660134875
char *zName = pEList->a[i].zEName;
134661134876
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
134662134877
}else if( srcName && p->op==TK_COLUMN ){
@@ -134748,11 +134963,14 @@
134748134963
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
134749134964
while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
134750134965
pColExpr = pColExpr->pRight;
134751134966
assert( pColExpr!=0 );
134752134967
}
134753
- if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
134968
+ if( pColExpr->op==TK_COLUMN
134969
+ && ALWAYS( ExprUseYTab(pColExpr) )
134970
+ && (pTab = pColExpr->y.pTab)!=0
134971
+ ){
134754134972
/* For columns use the column name name */
134755134973
int iCol = pColExpr->iColumn;
134756134974
if( iCol<0 ) iCol = pTab->iPKey;
134757134975
zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
134758134976
}else if( pColExpr->op==TK_ID ){
@@ -136330,11 +136548,11 @@
136330136548
if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
136331136549
pExpr->iTable = pSubst->iNewTable;
136332136550
}
136333136551
pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
136334136552
pExpr->pRight = substExpr(pSubst, pExpr->pRight);
136335
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
136553
+ if( ExprUseXSelect(pExpr) ){
136336136554
substSelect(pSubst, pExpr->x.pSelect, 1);
136337136555
}else{
136338136556
substExprList(pSubst, pExpr->x.pList);
136339136557
}
136340136558
#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -137541,25 +137759,28 @@
137541137759
** located but before their arguments have been subjected to aggregate
137542137760
** analysis.
137543137761
*/
137544137762
static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
137545137763
int eRet = WHERE_ORDERBY_NORMAL; /* Return value */
137546
- ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */
137764
+ ExprList *pEList; /* Arguments to agg function */
137547137765
const char *zFunc; /* Name of aggregate function pFunc */
137548137766
ExprList *pOrderBy;
137549137767
u8 sortFlags = 0;
137550137768
137551137769
assert( *ppMinMax==0 );
137552137770
assert( pFunc->op==TK_AGG_FUNCTION );
137553137771
assert( !IsWindowFunc(pFunc) );
137772
+ assert( ExprUseXList(pFunc) );
137773
+ pEList = pFunc->x.pList;
137554137774
if( pEList==0
137555137775
|| pEList->nExpr!=1
137556137776
|| ExprHasProperty(pFunc, EP_WinFunc)
137557137777
|| OptimizationDisabled(db, SQLITE_MinMaxOpt)
137558137778
){
137559137779
return eRet;
137560137780
}
137781
+ assert( !ExprHasProperty(pFunc, EP_IntValue) );
137561137782
zFunc = pFunc->u.zToken;
137562137783
if( sqlite3StrICmp(zFunc, "min")==0 ){
137563137784
eRet = WHERE_ORDERBY_MIN;
137564137785
if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
137565137786
sortFlags = KEYINFO_ORDER_BIGNULL;
@@ -137632,10 +137853,11 @@
137632137853
if( !pIdx ){
137633137854
sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
137634137855
pParse->checkSchema = 1;
137635137856
return SQLITE_ERROR;
137636137857
}
137858
+ assert( pFrom->fg.isCte==0 );
137637137859
pFrom->u2.pIBIndex = pIdx;
137638137860
return SQLITE_OK;
137639137861
}
137640137862
137641137863
/*
@@ -137889,10 +138111,14 @@
137889138111
pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
137890138112
pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
137891138113
if( db->mallocFailed ) return 2;
137892138114
pFrom->pSelect->selFlags |= SF_CopyCte;
137893138115
assert( pFrom->pSelect );
138116
+ if( pFrom->fg.isIndexedBy ){
138117
+ sqlite3ErrorMsg(pParse, "no such index: \"%s\"", pFrom->u1.zIndexedBy);
138118
+ return 2;
138119
+ }
137894138120
pFrom->fg.isCte = 1;
137895138121
pFrom->u2.pCteUse = pCteUse;
137896138122
pCteUse->nUse++;
137897138123
if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){
137898138124
pCteUse->eM10d = M10d_Yes;
@@ -138524,11 +138750,11 @@
138524138750
#endif
138525138751
sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
138526138752
for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
138527138753
if( pFunc->iDistinct>=0 ){
138528138754
Expr *pE = pFunc->pFExpr;
138529
- assert( !ExprHasProperty(pE, EP_xIsSelect) );
138755
+ assert( ExprUseXList(pE) );
138530138756
if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
138531138757
sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
138532138758
"argument");
138533138759
pFunc->iDistinct = -1;
138534138760
}else{
@@ -138549,12 +138775,13 @@
138549138775
static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
138550138776
Vdbe *v = pParse->pVdbe;
138551138777
int i;
138552138778
struct AggInfo_func *pF;
138553138779
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138554
- ExprList *pList = pF->pFExpr->x.pList;
138555
- assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
138780
+ ExprList *pList;
138781
+ assert( ExprUseXList(pF->pFExpr) );
138782
+ pList = pF->pFExpr->x.pList;
138556138783
sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
138557138784
sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
138558138785
}
138559138786
}
138560138787
@@ -138584,13 +138811,14 @@
138584138811
pAggInfo->directMode = 1;
138585138812
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138586138813
int nArg;
138587138814
int addrNext = 0;
138588138815
int regAgg;
138589
- ExprList *pList = pF->pFExpr->x.pList;
138590
- assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
138816
+ ExprList *pList;
138817
+ assert( ExprUseXList(pF->pFExpr) );
138591138818
assert( !IsWindowFunc(pF->pFExpr) );
138819
+ pList = pF->pFExpr->x.pList;
138592138820
if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
138593138821
Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
138594138822
if( pAggInfo->nAccumulator
138595138823
&& (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
138596138824
&& regAcc
@@ -138832,11 +139060,13 @@
138832139060
if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
138833139061
if( p->pWhere ) return 0;
138834139062
if( p->pGroupBy ) return 0;
138835139063
pExpr = p->pEList->a[0].pExpr;
138836139064
if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
139065
+ assert( ExprUseUToken(pExpr) );
138837139066
if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
139067
+ assert( ExprUseXList(pExpr) );
138838139068
if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
138839139069
if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
138840139070
pSub = p->pSrc->a[0].pSelect;
138841139071
if( pSub==0 ) return 0; /* The FROM is a subquery */
138842139072
if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */
@@ -139647,11 +139877,11 @@
139647139877
}else{
139648139878
minMaxFlag = WHERE_ORDERBY_NORMAL;
139649139879
}
139650139880
for(i=0; i<pAggInfo->nFunc; i++){
139651139881
Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
139652
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
139882
+ assert( ExprUseXList(pExpr) );
139653139883
sNC.ncFlags |= NC_InAggFunc;
139654139884
sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
139655139885
#ifndef SQLITE_OMIT_WINDOWFUNC
139656139886
assert( !IsWindowFunc(pExpr) );
139657139887
if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -139702,11 +139932,13 @@
139702139932
u16 distFlag = 0;
139703139933
int eDist = WHERE_DISTINCT_NOOP;
139704139934
139705139935
if( pAggInfo->nFunc==1
139706139936
&& pAggInfo->aFunc[0].iDistinct>=0
139707
- && pAggInfo->aFunc[0].pFExpr->x.pList
139937
+ && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0)
139938
+ && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr))
139939
+ && pAggInfo->aFunc[0].pFExpr->x.pList!=0
139708139940
){
139709139941
Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
139710139942
pExpr = sqlite3ExprDup(db, pExpr, 0);
139711139943
pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
139712139944
pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr);
@@ -140023,10 +140255,11 @@
140023140255
if( i==pAggInfo->nFunc ){
140024140256
regAcc = ++pParse->nMem;
140025140257
sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
140026140258
}
140027140259
}else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
140260
+ assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) );
140028140261
pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
140029140262
distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
140030140263
}
140031140264
140032140265
/* This case runs if the aggregate has no GROUP BY clause. The
@@ -144048,11 +144281,14 @@
144048144281
** Except, if argument db is not NULL, then the entry associated with
144049144282
** connection db is left in the p->u.vtab.p list.
144050144283
*/
144051144284
static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
144052144285
VTable *pRet = 0;
144053
- VTable *pVTable = p->u.vtab.p;
144286
+ VTable *pVTable;
144287
+
144288
+ assert( IsVirtual(p) );
144289
+ pVTable = p->u.vtab.p;
144054144290
p->u.vtab.p = 0;
144055144291
144056144292
/* Assert that the mutex (if any) associated with the BtShared database
144057144293
** that contains table p is held by the caller. See header comments
144058144294
** above function sqlite3VtabUnlockList() for an explanation of why
@@ -144156,10 +144392,11 @@
144156144392
** structure being xDisconnected and free). Any other VTable structures
144157144393
** in the list are moved to the sqlite3.pDisconnect list of the associated
144158144394
** database connection.
144159144395
*/
144160144396
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
144397
+ assert( IsVirtual(p) );
144161144398
if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
144162144399
if( p->u.vtab.azArg ){
144163144400
int i;
144164144401
for(i=0; i<p->u.vtab.nArg; i++){
144165144402
if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
@@ -144173,13 +144410,16 @@
144173144410
** The string is not copied - the pointer is stored. The
144174144411
** string will be freed automatically when the table is
144175144412
** deleted.
144176144413
*/
144177144414
static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
144178
- sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
144415
+ sqlite3_int64 nBytes;
144179144416
char **azModuleArg;
144180144417
sqlite3 *db = pParse->db;
144418
+
144419
+ assert( IsVirtual(pTable) );
144420
+ nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
144181144421
if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
144182144422
sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
144183144423
}
144184144424
azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes);
144185144425
if( azModuleArg==0 ){
@@ -144262,10 +144502,11 @@
144262144502
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
144263144503
Table *pTab = pParse->pNewTable; /* The table being constructed */
144264144504
sqlite3 *db = pParse->db; /* The database connection */
144265144505
144266144506
if( pTab==0 ) return;
144507
+ assert( IsVirtual(pTab) );
144267144508
addArgumentToVtab(pParse);
144268144509
pParse->sArg.z = 0;
144269144510
if( pTab->u.vtab.nArg<1 ) return;
144270144511
144271144512
/* If the CREATE VIRTUAL TABLE statement is being entered for the
@@ -144379,17 +144620,20 @@
144379144620
char **pzErr
144380144621
){
144381144622
VtabCtx sCtx;
144382144623
VTable *pVTable;
144383144624
int rc;
144384
- const char *const*azArg = (const char *const*)pTab->u.vtab.azArg;
144625
+ const char *const*azArg;
144385144626
int nArg = pTab->u.vtab.nArg;
144386144627
char *zErr = 0;
144387144628
char *zModuleName;
144388144629
int iDb;
144389144630
VtabCtx *pCtx;
144390144631
144632
+ assert( IsVirtual(pTab) );
144633
+ azArg = (const char *const*)pTab->u.vtab.azArg;
144634
+
144391144635
/* Check that the virtual-table is not already being initialized */
144392144636
for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
144393144637
if( pCtx->pTab==pTab ){
144394144638
*pzErr = sqlite3MPrintf(db,
144395144639
"vtable constructor called recursively: %s", pTab->zName
@@ -144713,11 +144957,11 @@
144713144957
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144714144958
int rc = SQLITE_OK;
144715144959
Table *pTab;
144716144960
144717144961
pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144718
- if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){
144962
+ if( pTab!=0 && ALWAYS(IsVirtual(pTab)) && ALWAYS(pTab->u.vtab.p!=0) ){
144719144963
VTable *p;
144720144964
int (*xDestroy)(sqlite3_vtab *);
144721144965
for(p=pTab->u.vtab.p; p; p=p->pNext){
144722144966
assert( p->pVtab );
144723144967
if( p->pVtab->nRef>0 ){
@@ -144946,10 +145190,11 @@
144946145190
int rc = 0;
144947145191
144948145192
/* Check to see the left operand is a column in a virtual table */
144949145193
if( NEVER(pExpr==0) ) return pDef;
144950145194
if( pExpr->op!=TK_COLUMN ) return pDef;
145195
+ assert( ExprUseYTab(pExpr) );
144951145196
pTab = pExpr->y.pTab;
144952145197
if( pTab==0 ) return pDef;
144953145198
if( !IsVirtual(pTab) ) return pDef;
144954145199
pVtab = sqlite3GetVTable(db, pTab)->pVtab;
144955145200
assert( pVtab!=0 );
@@ -145254,11 +145499,11 @@
145254145499
int iBase; /* Base register of multi-key index record */
145255145500
int nPrefix; /* Number of prior entires in the key */
145256145501
u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
145257145502
} *aInLoop; /* Information about each nested IN operator */
145258145503
} in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
145259
- Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
145504
+ Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */
145260145505
} u;
145261145506
struct WhereLoop *pWLoop; /* The selected WhereLoop object */
145262145507
Bitmask notReady; /* FROM entries not usable at this level */
145263145508
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
145264145509
int addrVisit; /* Address at which row is visited */
@@ -146182,20 +146427,27 @@
146182146427
){
146183146428
sqlite3 *db = pParse->db;
146184146429
Expr *pNew;
146185146430
pNew = sqlite3ExprDup(db, pX, 0);
146186146431
if( db->mallocFailed==0 ){
146187
- ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
146188
- ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
146432
+ ExprList *pOrigRhs; /* Original unmodified RHS */
146433
+ ExprList *pOrigLhs; /* Original unmodified LHS */
146189146434
ExprList *pRhs = 0; /* New RHS after modifications */
146190146435
ExprList *pLhs = 0; /* New LHS after mods */
146191146436
int i; /* Loop counter */
146192146437
Select *pSelect; /* Pointer to the SELECT on the RHS */
146193146438
146439
+ assert( ExprUseXSelect(pNew) );
146440
+ pOrigRhs = pNew->x.pSelect->pEList;
146441
+ assert( pNew->pLeft!=0 );
146442
+ assert( ExprUseXList(pNew->pLeft) );
146443
+ pOrigLhs = pNew->pLeft->x.pList;
146194146444
for(i=iEq; i<pLoop->nLTerm; i++){
146195146445
if( pLoop->aLTerm[i]->pExpr==pX ){
146196
- int iField = pLoop->aLTerm[i]->u.x.iField - 1;
146446
+ int iField;
146447
+ assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
146448
+ iField = pLoop->aLTerm[i]->u.x.iField - 1;
146197146449
if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
146198146450
pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
146199146451
pOrigRhs->a[iField].pExpr = 0;
146200146452
assert( pOrigLhs->a[iField].pExpr!=0 );
146201146453
pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
@@ -146306,11 +146558,11 @@
146306146558
assert( pLoop->aLTerm[i]!=0 );
146307146559
if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
146308146560
}
146309146561
146310146562
iTab = 0;
146311
- if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
146563
+ if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
146312146564
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
146313146565
}else{
146314146566
sqlite3 *db = pParse->db;
146315146567
pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
146316146568
@@ -146328,12 +146580,12 @@
146328146580
bRev = !bRev;
146329146581
}
146330146582
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
146331146583
VdbeCoverageIf(v, bRev);
146332146584
VdbeCoverageIf(v, !bRev);
146585
+
146333146586
assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
146334
-
146335146587
pLoop->wsFlags |= WHERE_IN_ABLE;
146336146588
if( pLevel->u.in.nIn==0 ){
146337146589
pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
146338146590
}
146339146591
if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
@@ -146871,21 +147123,23 @@
146871147123
*/
146872147124
static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
146873147125
assert( nReg>0 );
146874147126
if( p && sqlite3ExprIsVector(p) ){
146875147127
#ifndef SQLITE_OMIT_SUBQUERY
146876
- if( (p->flags & EP_xIsSelect) ){
147128
+ if( ExprUseXSelect(p) ){
146877147129
Vdbe *v = pParse->pVdbe;
146878147130
int iSelect;
146879147131
assert( p->op==TK_SELECT );
146880147132
iSelect = sqlite3CodeSubselect(pParse, p);
146881147133
sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
146882147134
}else
146883147135
#endif
146884147136
{
146885147137
int i;
146886
- ExprList *pList = p->x.pList;
147138
+ const ExprList *pList;
147139
+ assert( ExprUseXList(p) );
147140
+ pList = p->x.pList;
146887147141
assert( nReg<=pList->nExpr );
146888147142
for(i=0; i<nReg; i++){
146889147143
sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i);
146890147144
}
146891147145
}
@@ -146934,14 +147188,14 @@
146934147188
preserveExpr(pX, pExpr);
146935147189
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
146936147190
pExpr->op = TK_COLUMN;
146937147191
pExpr->iTable = pX->iIdxCur;
146938147192
pExpr->iColumn = pX->iIdxCol;
146939
- pExpr->y.pTab = 0;
146940147193
testcase( ExprHasProperty(pExpr, EP_Skip) );
146941147194
testcase( ExprHasProperty(pExpr, EP_Unlikely) );
146942
- ExprClearProperty(pExpr, EP_Skip|EP_Unlikely);
147195
+ ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
147196
+ pExpr->y.pTab = 0;
146943147197
return WRC_Prune;
146944147198
}else{
146945147199
return WRC_Continue;
146946147200
}
146947147201
}
@@ -146952,11 +147206,11 @@
146952147206
*/
146953147207
static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
146954147208
if( pExpr->op==TK_COLUMN ){
146955147209
IdxExprTrans *pX = p->u.pIdxTrans;
146956147210
if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
146957
- assert( pExpr->y.pTab!=0 );
147211
+ assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 );
146958147212
preserveExpr(pX, pExpr);
146959147213
pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
146960147214
pExpr->iTable = pX->iIdxCur;
146961147215
pExpr->iColumn = pX->iIdxCol;
146962147216
pExpr->y.pTab = 0;
@@ -147189,11 +147443,16 @@
147189147443
** the u.vtab.idxStr. NULL it out to prevent a use-after-free */
147190147444
if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
147191147445
pLevel->p1 = iCur;
147192147446
pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
147193147447
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
147194
- iIn = pLevel->u.in.nIn;
147448
+ assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
147449
+ if( pLoop->wsFlags & WHERE_IN_ABLE ){
147450
+ iIn = pLevel->u.in.nIn;
147451
+ }else{
147452
+ iIn = 0;
147453
+ }
147195147454
for(j=nConstraint-1; j>=0; j--){
147196147455
pTerm = pLoop->aLTerm[j];
147197147456
if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
147198147457
if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
147199147458
disableTerm(pLevel, pTerm);
@@ -148078,11 +148337,14 @@
148078148337
}
148079148338
sqlite3ExprDelete(db, pDelete);
148080148339
}
148081148340
}
148082148341
ExplainQueryPlanPop(pParse);
148083
- pLevel->u.pCovidx = pCov;
148342
+ assert( pLevel->pWLoop==pLoop );
148343
+ assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 );
148344
+ assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 );
148345
+ pLevel->u.pCoveringIdx = pCov;
148084148346
if( pCov ) pLevel->iIdxCur = iCovCur;
148085148347
if( pAndExpr ){
148086148348
pAndExpr->pLeft = 0;
148087148349
sqlite3ExprDelete(db, pAndExpr);
148088148350
}
@@ -148222,16 +148484,17 @@
148222148484
sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
148223148485
}
148224148486
#endif
148225148487
assert( !ExprHasProperty(pE, EP_FromJoin) );
148226148488
assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
148489
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
148227148490
pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
148228148491
WO_EQ|WO_IN|WO_IS, 0);
148229148492
if( pAlt==0 ) continue;
148230148493
if( pAlt->wtFlags & (TERM_CODED) ) continue;
148231148494
if( (pAlt->eOperator & WO_IN)
148232
- && (pAlt->pExpr->flags & EP_xIsSelect)
148495
+ && ExprUseXSelect(pAlt->pExpr)
148233148496
&& (pAlt->pExpr->x.pSelect->pEList->nExpr>1)
148234148497
){
148235148498
continue;
148236148499
}
148237148500
testcase( pAlt->eOperator & WO_EQ );
@@ -148476,10 +148739,11 @@
148476148739
return 0;
148477148740
}
148478148741
#ifdef SQLITE_EBCDIC
148479148742
if( *pnoCase ) return 0;
148480148743
#endif
148744
+ assert( ExprUseXList(pExpr) );
148481148745
pList = pExpr->x.pList;
148482148746
pLeft = pList->a[1].pExpr;
148483148747
148484148748
pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
148485148749
op = pRight->op;
@@ -148491,11 +148755,12 @@
148491148755
z = sqlite3_value_text(pVal);
148492148756
}
148493148757
sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
148494148758
assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
148495148759
}else if( op==TK_STRING ){
148496
- z = (u8*)pRight->u.zToken;
148760
+ assert( !ExprHasProperty(pRight, EP_IntValue) );
148761
+ z = (u8*)pRight->u.zToken;
148497148762
}
148498148763
if( z ){
148499148764
148500148765
/* Count the number of prefix characters prior to the first wildcard */
148501148766
cnt = 0;
@@ -148520,11 +148785,13 @@
148520148785
148521148786
/* Get the pattern prefix. Remove all escapes from the prefix. */
148522148787
pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
148523148788
if( pPrefix ){
148524148789
int iFrom, iTo;
148525
- char *zNew = pPrefix->u.zToken;
148790
+ char *zNew;
148791
+ assert( !ExprHasProperty(pPrefix, EP_IntValue) );
148792
+ zNew = pPrefix->u.zToken;
148526148793
zNew[cnt] = 0;
148527148794
for(iFrom=iTo=0; iFrom<cnt; iFrom++){
148528148795
if( zNew[iFrom]==wc[3] ) iFrom++;
148529148796
zNew[iTo++] = zNew[iFrom];
148530148797
}
@@ -148544,11 +148811,13 @@
148544148811
** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148545148812
** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148546148813
*/
148547148814
if( pLeft->op!=TK_COLUMN
148548148815
|| sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148549
- || (pLeft->y.pTab && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148816
+ || (ALWAYS( ExprUseYTab(pLeft) )
148817
+ && pLeft->y.pTab
148818
+ && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148550148819
){
148551148820
int isNum;
148552148821
double rDummy;
148553148822
isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148554148823
if( isNum<=0 ){
@@ -148572,10 +148841,11 @@
148572148841
/* If the RHS pattern is a bound parameter, make arrangements to
148573148842
** reprepare the statement when that parameter is rebound */
148574148843
if( op==TK_VARIABLE ){
148575148844
Vdbe *v = pParse->pVdbe;
148576148845
sqlite3VdbeSetVarmask(v, pRight->iColumn);
148846
+ assert( !ExprHasProperty(pRight, EP_IntValue) );
148577148847
if( *pisComplete && pRight->u.zToken[1] ){
148578148848
/* If the rhs of the LIKE expression is a variable, and the current
148579148849
** value of the variable means there is no need to invoke the LIKE
148580148850
** function, then no OP_Variable will be added to the program.
148581148851
** This causes problems for the sqlite3_bind_parameter_name()
@@ -148645,10 +148915,11 @@
148645148915
};
148646148916
ExprList *pList;
148647148917
Expr *pCol; /* Column reference */
148648148918
int i;
148649148919
148920
+ assert( ExprUseXList(pExpr) );
148650148921
pList = pExpr->x.pList;
148651148922
if( pList==0 || pList->nExpr!=2 ){
148652148923
return 0;
148653148924
}
148654148925
@@ -148658,13 +148929,15 @@
148658148929
**
148659148930
** vtab_column MATCH expression
148660148931
** MATCH(expression,vtab_column)
148661148932
*/
148662148933
pCol = pList->a[1].pExpr;
148934
+ assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148663148935
testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148664148936
if( ExprIsVtab(pCol) ){
148665148937
for(i=0; i<ArraySize(aOp); i++){
148938
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
148666148939
if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
148667148940
*peOp2 = aOp[i].eOp2;
148668148941
*ppRight = pList->a[0].pExpr;
148669148942
*ppLeft = pCol;
148670148943
return 1;
@@ -148681,20 +148954,22 @@
148681148954
** Historically, xFindFunction expected to see lower-case function
148682148955
** names. But for this use case, xFindFunction is expected to deal
148683148956
** with function names in an arbitrary case.
148684148957
*/
148685148958
pCol = pList->a[0].pExpr;
148959
+ assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148686148960
testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148687148961
if( ExprIsVtab(pCol) ){
148688148962
sqlite3_vtab *pVtab;
148689148963
sqlite3_module *pMod;
148690148964
void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
148691148965
void *pNotUsed;
148692148966
pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
148693148967
assert( pVtab!=0 );
148694148968
assert( pVtab->pModule!=0 );
148695
- pMod = (sqlite3_module *)pVtab->pModule;
148969
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
148970
+ pMod = (sqlite3_module *)pVtab->pModule;
148696148971
if( pMod->xFindFunction!=0 ){
148697148972
i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
148698148973
if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
148699148974
*peOp2 = i;
148700148975
*ppRight = pList->a[1].pExpr;
@@ -148705,14 +148980,16 @@
148705148980
}
148706148981
}else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
148707148982
int res = 0;
148708148983
Expr *pLeft = pExpr->pLeft;
148709148984
Expr *pRight = pExpr->pRight;
148985
+ assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
148710148986
testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
148711148987
if( ExprIsVtab(pLeft) ){
148712148988
res++;
148713148989
}
148990
+ assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
148714148991
testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
148715148992
if( pRight && ExprIsVtab(pRight) ){
148716148993
res++;
148717148994
SWAP(Expr*, pLeft, pRight);
148718148995
}
@@ -148961,10 +149238,11 @@
148961149238
int j;
148962149239
Bitmask b = 0;
148963149240
pOrTerm->u.pAndInfo = pAndInfo;
148964149241
pOrTerm->wtFlags |= TERM_ANDINFO;
148965149242
pOrTerm->eOperator = WO_AND;
149243
+ pOrTerm->leftCursor = -1;
148966149244
pAndWC = &pAndInfo->wc;
148967149245
memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
148968149246
sqlite3WhereClauseInit(pAndWC, pWC->pWInfo);
148969149247
sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
148970149248
sqlite3WhereExprAnalyze(pSrc, pAndWC);
@@ -149003,15 +149281,14 @@
149003149281
/*
149004149282
** Record the set of tables that satisfy case 3. The set might be
149005149283
** empty.
149006149284
*/
149007149285
pOrInfo->indexable = indexable;
149286
+ pTerm->eOperator = WO_OR;
149287
+ pTerm->leftCursor = -1;
149008149288
if( indexable ){
149009
- pTerm->eOperator = WO_OR;
149010149289
pWC->hasOr = 1;
149011
- }else{
149012
- pTerm->eOperator = WO_OR;
149013149290
}
149014149291
149015149292
/* For a two-way OR, attempt to implementation case 2.
149016149293
*/
149017149294
if( indexable && pOrWc->nTerm==2 ){
@@ -149080,10 +149357,11 @@
149080149357
testcase( pOrTerm->wtFlags & TERM_COPIED );
149081149358
testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
149082149359
assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
149083149360
continue;
149084149361
}
149362
+ assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149085149363
iColumn = pOrTerm->u.x.leftColumn;
149086149364
iCursor = pOrTerm->leftCursor;
149087149365
pLeft = pOrTerm->pExpr->pLeft;
149088149366
break;
149089149367
}
@@ -149100,10 +149378,11 @@
149100149378
/* We have found a candidate table and column. Check to see if that
149101149379
** table and column is common to every term in the OR clause */
149102149380
okToChngToIN = 1;
149103149381
for(; i>=0 && okToChngToIN; i--, pOrTerm++){
149104149382
assert( pOrTerm->eOperator & WO_EQ );
149383
+ assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149105149384
if( pOrTerm->leftCursor!=iCursor ){
149106149385
pOrTerm->wtFlags &= ~TERM_OR_OK;
149107149386
}else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR
149108149387
&& sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1)
149109149388
)){
@@ -149136,10 +149415,11 @@
149136149415
Expr *pNew; /* The complete IN operator */
149137149416
149138149417
for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
149139149418
if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
149140149419
assert( pOrTerm->eOperator & WO_EQ );
149420
+ assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149141149421
assert( pOrTerm->leftCursor==iCursor );
149142149422
assert( pOrTerm->u.x.leftColumn==iColumn );
149143149423
pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
149144149424
pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
149145149425
pLeft = pOrTerm->pExpr->pLeft;
@@ -149148,11 +149428,11 @@
149148149428
pDup = sqlite3ExprDup(db, pLeft, 0);
149149149429
pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
149150149430
if( pNew ){
149151149431
int idxNew;
149152149432
transferJoinMarkings(pNew, pExpr);
149153
- assert( !ExprHasProperty(pNew, EP_xIsSelect) );
149433
+ assert( ExprUseXList(pNew) );
149154149434
pNew->x.pList = pList;
149155149435
idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
149156149436
testcase( idxNew==0 );
149157149437
exprAnalyze(pSrc, pWC, idxNew);
149158149438
/* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
@@ -149276,10 +149556,11 @@
149276149556
** on the first element of the vector. */
149277149557
assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
149278149558
assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
149279149559
assert( op<=TK_GE );
149280149560
if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
149561
+ assert( ExprUseXList(pExpr) );
149281149562
pExpr = pExpr->x.pList->a[0].pExpr;
149282149563
149283149564
}
149284149565
149285149566
if( pExpr->op==TK_COLUMN ){
@@ -149342,11 +149623,11 @@
149342149623
prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft);
149343149624
op = pExpr->op;
149344149625
if( op==TK_IN ){
149345149626
assert( pExpr->pRight==0 );
149346149627
if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
149347
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
149628
+ if( ExprUseXSelect(pExpr) ){
149348149629
pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect);
149349149630
}else{
149350149631
pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList);
149351149632
}
149352149633
}else if( op==TK_ISNULL ){
@@ -149378,15 +149659,17 @@
149378149659
u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
149379149660
149380149661
if( pTerm->u.x.iField>0 ){
149381149662
assert( op==TK_IN );
149382149663
assert( pLeft->op==TK_VECTOR );
149664
+ assert( ExprUseXList(pLeft) );
149383149665
pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr;
149384149666
}
149385149667
149386149668
if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
149387149669
pTerm->leftCursor = aiCurCol[0];
149670
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149388149671
pTerm->u.x.leftColumn = aiCurCol[1];
149389149672
pTerm->eOperator = operatorMask(op) & opMask;
149390149673
}
149391149674
if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
149392149675
if( pRight
@@ -149420,10 +149703,11 @@
149420149703
pDup = pExpr;
149421149704
pNew = pTerm;
149422149705
}
149423149706
pNew->wtFlags |= exprCommute(pParse, pDup);
149424149707
pNew->leftCursor = aiCurCol[0];
149708
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149425149709
pNew->u.x.leftColumn = aiCurCol[1];
149426149710
testcase( (prereqLeft | extraRight) != prereqLeft );
149427149711
pNew->prereqRight = prereqLeft | extraRight;
149428149712
pNew->prereqAll = prereqAll;
149429149713
pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
@@ -149430,10 +149714,11 @@
149430149714
}else
149431149715
if( op==TK_ISNULL
149432149716
&& !ExprHasProperty(pExpr,EP_FromJoin)
149433149717
&& 0==sqlite3ExprCanBeNull(pLeft)
149434149718
){
149719
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
149435149720
pExpr->op = TK_TRUEFALSE;
149436149721
pExpr->u.zToken = "false";
149437149722
ExprSetProperty(pExpr, EP_IsFalse);
149438149723
pTerm->prereqAll = 0;
149439149724
pTerm->eOperator = 0;
@@ -149455,13 +149740,15 @@
149455149740
** term. That means that if the BETWEEN term is coded, the children are
149456149741
** skipped. Or, if the children are satisfied by an index, the original
149457149742
** BETWEEN term is skipped.
149458149743
*/
149459149744
else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
149460
- ExprList *pList = pExpr->x.pList;
149745
+ ExprList *pList;
149461149746
int i;
149462149747
static const u8 ops[] = {TK_GE, TK_LE};
149748
+ assert( ExprUseXList(pExpr) );
149749
+ pList = pExpr->x.pList;
149463149750
assert( pList!=0 );
149464149751
assert( pList->nExpr==2 );
149465149752
for(i=0; i<2; i++){
149466149753
Expr *pNewExpr;
149467149754
int idxNew;
@@ -149550,12 +149837,16 @@
149550149837
int idxNew1;
149551149838
int idxNew2;
149552149839
const char *zCollSeqName; /* Name of collating sequence */
149553149840
const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
149554149841
149842
+ assert( ExprUseXList(pExpr) );
149555149843
pLeft = pExpr->x.pList->a[1].pExpr;
149556149844
pStr2 = sqlite3ExprDup(db, pStr1, 0);
149845
+ assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) );
149846
+ assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) );
149847
+
149557149848
149558149849
/* Convert the lower bound to upper-case and the upper bound to
149559149850
** lower-case (upper-case is less than lower-case in ASCII) so that
149560149851
** the range constraints also work for BLOBs
149561149852
*/
@@ -149651,10 +149942,11 @@
149651149942
** not use window functions.
149652149943
*/
149653149944
else if( pExpr->op==TK_IN
149654149945
&& pTerm->u.x.iField==0
149655149946
&& pExpr->pLeft->op==TK_VECTOR
149947
+ && ALWAYS( ExprUseXSelect(pExpr) )
149656149948
&& pExpr->x.pSelect->pPrior==0
149657149949
#ifndef SQLITE_OMIT_WINDOWFUNC
149658149950
&& pExpr->x.pSelect->pWin==0
149659149951
#endif
149660149952
&& pWC->op==TK_AND
@@ -149814,18 +150106,19 @@
149814150106
mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
149815150107
if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft);
149816150108
if( p->pRight ){
149817150109
mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight);
149818150110
assert( p->x.pList==0 );
149819
- }else if( ExprHasProperty(p, EP_xIsSelect) ){
150111
+ }else if( ExprUseXSelect(p) ){
149820150112
if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
149821150113
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
149822150114
}else if( p->x.pList ){
149823150115
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
149824150116
}
149825150117
#ifndef SQLITE_OMIT_WINDOWFUNC
149826
- if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){
150118
+ if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && ExprUseYWin(p) ){
150119
+ assert( p->y.pWin!=0 );
149827150120
mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
149828150121
mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
149829150122
mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter);
149830150123
}
149831150124
#endif
@@ -149896,10 +150189,11 @@
149896150189
}
149897150190
pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
149898150191
if( pColRef==0 ) return;
149899150192
pColRef->iTable = pItem->iCursor;
149900150193
pColRef->iColumn = k++;
150194
+ assert( ExprUseYTab(pColRef) );
149901150195
pColRef->y.pTab = pTab;
149902150196
pRhs = sqlite3PExpr(pParse, TK_UPLUS,
149903150197
sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
149904150198
pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
149905150199
if( pItem->fg.jointype & JT_LEFT ){
@@ -150197,12 +150491,14 @@
150197150491
pWC = pScan->pWC;
150198150492
while(1){
150199150493
iColumn = pScan->aiColumn[pScan->iEquiv-1];
150200150494
iCur = pScan->aiCur[pScan->iEquiv-1];
150201150495
assert( pWC!=0 );
150496
+ assert( iCur>=0 );
150202150497
do{
150203150498
for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
150499
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 );
150204150500
if( pTerm->leftCursor==iCur
150205150501
&& pTerm->u.x.leftColumn==iColumn
150206150502
&& (iColumn!=XN_EXPR
150207150503
|| sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
150208150504
pScan->pIdxExpr,iCur)==0)
@@ -150638,10 +150934,11 @@
150638150934
** the RHS of a LEFT JOIN. Such a term can only be used if it is from
150639150935
** the ON clause. */
150640150936
return 0;
150641150937
}
150642150938
if( (pTerm->prereqRight & notReady)!=0 ) return 0;
150939
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150643150940
if( pTerm->u.x.leftColumn<0 ) return 0;
150644150941
aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
150645150942
if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
150646150943
testcase( pTerm->pExpr->op==TK_IS );
150647150944
return 1;
@@ -150710,12 +151007,15 @@
150710151007
&& sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
150711151008
pPartial = sqlite3ExprAnd(pParse, pPartial,
150712151009
sqlite3ExprDup(pParse->db, pExpr, 0));
150713151010
}
150714151011
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
150715
- int iCol = pTerm->u.x.leftColumn;
150716
- Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151012
+ int iCol;
151013
+ Bitmask cMask;
151014
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151015
+ iCol = pTerm->u.x.leftColumn;
151016
+ cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
150717151017
testcase( iCol==BMS );
150718151018
testcase( iCol==BMS-1 );
150719151019
if( !sentWarning ){
150720151020
sqlite3_log(SQLITE_WARNING_AUTOINDEX,
150721151021
"automatic index on %s(%s)", pTable->zName,
@@ -150763,12 +151063,15 @@
150763151063
pIdx->pTable = pTable;
150764151064
n = 0;
150765151065
idxCols = 0;
150766151066
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
150767151067
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
150768
- int iCol = pTerm->u.x.leftColumn;
150769
- Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151068
+ int iCol;
151069
+ Bitmask cMask;
151070
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151071
+ iCol = pTerm->u.x.leftColumn;
151072
+ cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
150770151073
testcase( iCol==BMS-1 );
150771151074
testcase( iCol==BMS );
150772151075
if( (idxCols & cMask)==0 ){
150773151076
Expr *pX = pTerm->pExpr;
150774151077
idxCols |= cMask;
@@ -150891,10 +151194,11 @@
150891151194
testcase( pTerm->eOperator & WO_ISNULL );
150892151195
testcase( pTerm->eOperator & WO_IS );
150893151196
testcase( pTerm->eOperator & WO_ALL );
150894151197
if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
150895151198
if( pTerm->wtFlags & TERM_VNULL ) continue;
151199
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150896151200
assert( pTerm->u.x.leftColumn>=(-1) );
150897151201
nTerm++;
150898151202
}
150899151203
150900151204
/* If the ORDER BY clause contains only columns in the current
@@ -150951,10 +151255,11 @@
150951151255
if( (pSrc->fg.jointype & JT_LEFT)!=0
150952151256
&& !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
150953151257
){
150954151258
continue;
150955151259
}
151260
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150956151261
assert( pTerm->u.x.leftColumn>=(-1) );
150957151262
pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
150958151263
pIdxCons[j].iTermOffset = i;
150959151264
op = pTerm->eOperator & WO_ALL;
150960151265
if( op==WO_IN ) op = WO_EQ;
@@ -151714,10 +152019,11 @@
151714152019
if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
151715152020
if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
151716152021
if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
151717152022
if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
151718152023
if( pTerm->eOperator & WO_SINGLE ){
152024
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151719152025
sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
151720152026
pTerm->leftCursor, pTerm->u.x.leftColumn);
151721152027
}else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
151722152028
sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
151723152029
pTerm->u.pOrInfo->indexable);
@@ -151731,11 +152037,11 @@
151731152037
** shown about each Term */
151732152038
if( sqlite3WhereTrace & 0x10000 ){
151733152039
sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx",
151734152040
pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight);
151735152041
}
151736
- if( pTerm->u.x.iField ){
152042
+ if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){
151737152043
sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField);
151738152044
}
151739152045
if( pTerm->iParent>=0 ){
151740152046
sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
151741152047
}
@@ -151895,11 +152201,12 @@
151895152201
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
151896152202
int i;
151897152203
assert( pWInfo!=0 );
151898152204
for(i=0; i<pWInfo->nLevel; i++){
151899152205
WhereLevel *pLevel = &pWInfo->a[i];
151900
- if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
152206
+ if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){
152207
+ assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 );
151901152208
sqlite3DbFree(db, pLevel->u.in.aInLoop);
151902152209
}
151903152210
}
151904152211
sqlite3WhereClauseClear(&pWInfo->sWC);
151905152212
while( pWInfo->pLoops ){
@@ -152330,13 +152637,16 @@
152330152637
/* Test if comparison i of pTerm is compatible with column (i+nEq)
152331152638
** of the index. If not, exit the loop. */
152332152639
char aff; /* Comparison affinity */
152333152640
char idxaff = 0; /* Indexed columns affinity */
152334152641
CollSeq *pColl; /* Comparison collation sequence */
152335
- Expr *pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr;
152336
- Expr *pRhs = pTerm->pExpr->pRight;
152337
- if( pRhs->flags & EP_xIsSelect ){
152642
+ Expr *pLhs, *pRhs;
152643
+
152644
+ assert( ExprUseXList(pTerm->pExpr->pLeft) );
152645
+ pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr;
152646
+ pRhs = pTerm->pExpr->pRight;
152647
+ if( ExprUseXSelect(pRhs) ){
152338152648
pRhs = pRhs->x.pSelect->pEList->a[i].pExpr;
152339152649
}else{
152340152650
pRhs = pRhs->x.pList->a[i].pExpr;
152341152651
}
152342152652
@@ -152493,11 +152803,11 @@
152493152803
|| (pNew->wsFlags & WHERE_SKIPSCAN)!=0
152494152804
);
152495152805
152496152806
if( eOp & WO_IN ){
152497152807
Expr *pExpr = pTerm->pExpr;
152498
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
152808
+ if( ExprUseXSelect(pExpr) ){
152499152809
/* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
152500152810
int i;
152501152811
nIn = 46; assert( 46==sqlite3LogEst(25) );
152502152812
152503152813
/* The expression may actually be of the form (x, y) IN (SELECT...).
@@ -152634,11 +152944,11 @@
152634152944
#ifdef SQLITE_ENABLE_STAT4
152635152945
tRowcnt nOut = 0;
152636152946
if( nInMul==0
152637152947
&& pProbe->nSample
152638152948
&& ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol)
152639
- && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
152949
+ && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr))
152640152950
&& OptimizationEnabled(db, SQLITE_Stat4)
152641152951
){
152642152952
Expr *pExpr = pTerm->pExpr;
152643152953
if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
152644152954
testcase( eOp & WO_EQ );
@@ -152910,10 +153220,11 @@
152910153220
pTab = pSrc->pTab;
152911153221
pWC = pBuilder->pWC;
152912153222
assert( !IsVirtual(pSrc->pTab) );
152913153223
152914153224
if( pSrc->fg.isIndexedBy ){
153225
+ assert( pSrc->fg.isCte==0 );
152915153226
/* An INDEXED BY clause specifies a particular index to use */
152916153227
pProbe = pSrc->u2.pIBIndex;
152917153228
}else if( !HasRowid(pTab) ){
152918153229
pProbe = pTab->pIndex;
152919153230
}else{
@@ -155380,11 +155691,11 @@
155380155691
if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
155381155692
#endif
155382155693
}else{
155383155694
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
155384155695
}
155385
- if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
155696
+ if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
155386155697
struct InLoop *pIn;
155387155698
int j;
155388155699
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
155389155700
for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
155390155701
assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
@@ -155449,14 +155760,14 @@
155449155760
if( (ws & WHERE_IDX_ONLY)==0 ){
155450155761
assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
155451155762
sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
155452155763
}
155453155764
if( (ws & WHERE_INDEXED)
155454
- || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx)
155765
+ || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx)
155455155766
){
155456155767
if( ws & WHERE_MULTI_OR ){
155457
- Index *pIx = pLevel->u.pCovidx;
155768
+ Index *pIx = pLevel->u.pCoveringIdx;
155458155769
int iDb = sqlite3SchemaToIndex(db, pIx->pSchema);
155459155770
sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb);
155460155771
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
155461155772
}
155462155773
sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -155533,11 +155844,11 @@
155533155844
** reference the index.
155534155845
*/
155535155846
if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){
155536155847
pIdx = pLoop->u.btree.pIndex;
155537155848
}else if( pLoop->wsFlags & WHERE_MULTI_OR ){
155538
- pIdx = pLevel->u.pCovidx;
155849
+ pIdx = pLevel->u.pCoveringIdx;
155539155850
}
155540155851
if( pIdx
155541155852
&& !db->mallocFailed
155542155853
){
155543155854
if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){
@@ -156194,28 +156505,28 @@
156194156505
static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ }
156195156506
156196156507
/* Window functions that use all window interfaces: xStep, xFinal,
156197156508
** xValue, and xInverse */
156198156509
#define WINDOWFUNCALL(name,nArg,extra) { \
156199
- nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156510
+ nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156200156511
name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \
156201156512
name ## InvFunc, name ## Name, {0} \
156202156513
}
156203156514
156204156515
/* Window functions that are implemented using bytecode and thus have
156205156516
** no-op routines for their methods */
156206156517
#define WINDOWFUNCNOOP(name,nArg,extra) { \
156207
- nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156518
+ nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156208156519
noopStepFunc, noopValueFunc, noopValueFunc, \
156209156520
noopStepFunc, name ## Name, {0} \
156210156521
}
156211156522
156212156523
/* Window functions that use all window interfaces: xStep, the
156213156524
** same routine for xFinalize and xValue and which never call
156214156525
** xInverse. */
156215156526
#define WINDOWFUNCX(name,nArg,extra) { \
156216
- nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156527
+ nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156217156528
name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \
156218156529
noopStepFunc, name ## Name, {0} \
156219156530
}
156220156531
156221156532
@@ -156554,11 +156865,12 @@
156554156865
return WRC_Continue;
156555156866
}
156556156867
156557156868
static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
156558156869
if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
156559
- sqlite3ErrorMsg(pWalker->pParse,
156870
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
156871
+ sqlite3ErrorMsg(pWalker->pParse,
156560156872
"misuse of aggregate: %s()", pExpr->u.zToken);
156561156873
}
156562156874
return WRC_Continue;
156563156875
}
156564156876
@@ -156642,11 +156954,13 @@
156642156954
/* Append the arguments passed to each window function to the
156643156955
** sub-select expression list. Also allocate two registers for each
156644156956
** window function - one for the accumulator, another for interim
156645156957
** results. */
156646156958
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
156647
- ExprList *pArgs = pWin->pOwner->x.pList;
156959
+ ExprList *pArgs;
156960
+ assert( ExprUseXList(pWin->pOwner) );
156961
+ pArgs = pWin->pOwner->x.pList;
156648156962
if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
156649156963
selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
156650156964
pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
156651156965
pWin->bExprArgs = 1;
156652156966
}else{
@@ -157035,12 +157349,15 @@
157035157349
**
157036157350
** regApp+0: slot to copy min()/max() argument to for MakeRecord
157037157351
** regApp+1: integer value used to ensure keys are unique
157038157352
** regApp+2: output of MakeRecord
157039157353
*/
157040
- ExprList *pList = pWin->pOwner->x.pList;
157041
- KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
157354
+ ExprList *pList;
157355
+ KeyInfo *pKeyInfo;
157356
+ assert( ExprUseXList(pWin->pOwner) );
157357
+ pList = pWin->pOwner->x.pList;
157358
+ pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
157042157359
pWin->csrApp = pParse->nTab++;
157043157360
pWin->regApp = pParse->nMem+1;
157044157361
pParse->nMem += 3;
157045157362
if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
157046157363
assert( pKeyInfo->aSortFlags[0]==0 );
@@ -157124,11 +157441,13 @@
157124157441
/*
157125157442
** Return the number of arguments passed to the window-function associated
157126157443
** with the object passed as the only argument to this function.
157127157444
*/
157128157445
static int windowArgCount(Window *pWin){
157129
- ExprList *pList = pWin->pOwner->x.pList;
157446
+ const ExprList *pList;
157447
+ assert( ExprUseXList(pWin->pOwner) );
157448
+ pList = pWin->pOwner->x.pList;
157130157449
return (pList ? pList->nExpr : 0);
157131157450
}
157132157451
157133157452
typedef struct WindowCodeArg WindowCodeArg;
157134157453
typedef struct WindowCsrAndReg WindowCsrAndReg;
@@ -157309,10 +157628,11 @@
157309157628
sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
157310157629
}else if( pFunc->xSFunc!=noopStepFunc ){
157311157630
int addrIf = 0;
157312157631
if( pWin->pFilter ){
157313157632
int regTmp;
157633
+ assert( ExprUseXList(pWin->pOwner) );
157314157634
assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
157315157635
assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
157316157636
regTmp = sqlite3GetTempReg(pParse);
157317157637
sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
157318157638
addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
@@ -157322,10 +157642,11 @@
157322157642
157323157643
if( pWin->bExprArgs ){
157324157644
int iOp = sqlite3VdbeCurrentAddr(v);
157325157645
int iEnd;
157326157646
157647
+ assert( ExprUseXList(pWin->pOwner) );
157327157648
nArg = pWin->pOwner->x.pList->nExpr;
157328157649
regArg = sqlite3GetTempRange(pParse, nArg);
157329157650
sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
157330157651
157331157652
for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
@@ -157336,10 +157657,11 @@
157336157657
}
157337157658
}
157338157659
if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
157339157660
CollSeq *pColl;
157340157661
assert( nArg>0 );
157662
+ assert( ExprUseXList(pWin->pOwner) );
157341157663
pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
157342157664
sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
157343157665
}
157344157666
sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
157345157667
bInverse, regArg, pWin->regAccum);
@@ -157521,10 +157843,11 @@
157521157843
Parse *pParse = p->pParse;
157522157844
Window *pWin;
157523157845
157524157846
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
157525157847
FuncDef *pFunc = pWin->pFunc;
157848
+ assert( ExprUseXList(pWin->pOwner) );
157526157849
if( pFunc->zName==nth_valueName
157527157850
|| pFunc->zName==first_valueName
157528157851
){
157529157852
int csr = pWin->csrApp;
157530157853
int lbl = sqlite3VdbeMakeLabel(pParse);
@@ -158870,13 +159193,13 @@
158870159193
p->affExpr = 0;
158871159194
p->flags = EP_Leaf;
158872159195
ExprClearVVAProperties(p);
158873159196
p->iAgg = -1;
158874159197
p->pLeft = p->pRight = 0;
158875
- p->x.pList = 0;
158876159198
p->pAggInfo = 0;
158877
- p->y.pTab = 0;
159199
+ memset(&p->x, 0, sizeof(p->x));
159200
+ memset(&p->y, 0, sizeof(p->y));
158878159201
p->op2 = 0;
158879159202
p->iTable = 0;
158880159203
p->iColumn = 0;
158881159204
p->u.zToken = (char*)&p[1];
158882159205
memcpy(p->u.zToken, t.z, t.n);
@@ -166966,11 +167289,13 @@
166966167289
** if this is not the last copy of the function, do not invoke it. Multiple
166967167290
** copies of a single function are created when create_function() is called
166968167291
** with SQLITE_ANY as the encoding.
166969167292
*/
166970167293
static void functionDestroy(sqlite3 *db, FuncDef *p){
166971
- FuncDestructor *pDestructor = p->u.pDestructor;
167294
+ FuncDestructor *pDestructor;
167295
+ assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
167296
+ pDestructor = p->u.pDestructor;
166972167297
if( pDestructor ){
166973167298
pDestructor->nRef--;
166974167299
if( pDestructor->nRef==0 ){
166975167300
pDestructor->xDestroy(pDestructor->pUserData);
166976167301
sqlite3DbFree(db, pDestructor);
@@ -168987,10 +169312,11 @@
168987169312
** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
168988169313
** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
168989169314
** off all other flags.
168990169315
*/
168991169316
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
169317
+ SQLITE_OPEN_EXCLUSIVE |
168992169318
SQLITE_OPEN_MAIN_DB |
168993169319
SQLITE_OPEN_TEMP_DB |
168994169320
SQLITE_OPEN_TRANSIENT_DB |
168995169321
SQLITE_OPEN_MAIN_JOURNAL |
168996169322
SQLITE_OPEN_TEMP_JOURNAL |
@@ -172095,10 +172421,11 @@
172095172421
SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
172096172422
#ifdef SQLITE_TEST
172097172423
SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*);
172098172424
SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
172099172425
#endif
172426
+SQLITE_PRIVATE void *sqlite3Fts3MallocZero(i64 nByte);
172100172427
172101172428
SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
172102172429
sqlite3_tokenizer_cursor **
172103172430
);
172104172431
@@ -177176,12 +177503,12 @@
177176177503
case FTSQUERY_OR: {
177177177504
Fts3Expr *pLeft = pExpr->pLeft;
177178177505
Fts3Expr *pRight = pExpr->pRight;
177179177506
sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
177180177507
177181
- assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
177182
- assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
177508
+ assert_fts3_nc( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
177509
+ assert_fts3_nc( pRight->bStart || pLeft->iDocid==pRight->iDocid );
177183177510
177184177511
if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
177185177512
fts3EvalNextRow(pCsr, pLeft, pRc);
177186177513
}else if( pLeft->bEof || iCmp>0 ){
177187177514
fts3EvalNextRow(pCsr, pRight, pRc);
@@ -178617,11 +178944,11 @@
178617178944
/*
178618178945
** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
178619178946
** zero the memory before returning a pointer to it. If unsuccessful,
178620178947
** return NULL.
178621178948
*/
178622
-static void *fts3MallocZero(sqlite3_int64 nByte){
178949
+SQLITE_PRIVATE void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){
178623178950
void *pRet = sqlite3_malloc64(nByte);
178624178951
if( pRet ) memset(pRet, 0, nByte);
178625178952
return pRet;
178626178953
}
178627178954
@@ -178698,11 +179025,11 @@
178698179025
sqlite3_int64 nByte; /* total space to allocate */
178699179026
178700179027
rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
178701179028
if( rc==SQLITE_OK ){
178702179029
nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
178703
- pRet = (Fts3Expr *)fts3MallocZero(nByte);
179030
+ pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte);
178704179031
if( !pRet ){
178705179032
rc = SQLITE_NOMEM;
178706179033
}else{
178707179034
pRet->eType = FTSQUERY_PHRASE;
178708179035
pRet->pPhrase = (Fts3Phrase *)&pRet[1];
@@ -178953,11 +179280,11 @@
178953179280
*/
178954179281
cNext = zInput[nKey];
178955179282
if( fts3isspace(cNext)
178956179283
|| cNext=='"' || cNext=='(' || cNext==')' || cNext==0
178957179284
){
178958
- pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr));
179285
+ pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr));
178959179286
if( !pRet ){
178960179287
return SQLITE_NOMEM;
178961179288
}
178962179289
pRet->eType = pKey->eType;
178963179290
pRet->nNear = nNear;
@@ -179132,11 +179459,11 @@
179132179459
179133179460
if( !sqlite3_fts3_enable_parentheses
179134179461
&& p->eType==FTSQUERY_PHRASE && pParse->isNot
179135179462
){
179136179463
/* Create an implicit NOT operator. */
179137
- Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr));
179464
+ Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179138179465
if( !pNot ){
179139179466
sqlite3Fts3ExprFree(p);
179140179467
rc = SQLITE_NOMEM;
179141179468
goto exprparse_out;
179142179469
}
@@ -179166,11 +179493,11 @@
179166179493
179167179494
if( isPhrase && !isRequirePhrase ){
179168179495
/* Insert an implicit AND operator. */
179169179496
Fts3Expr *pAnd;
179170179497
assert( pRet && pPrev );
179171
- pAnd = fts3MallocZero(sizeof(Fts3Expr));
179498
+ pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179172179499
if( !pAnd ){
179173179500
sqlite3Fts3ExprFree(p);
179174179501
rc = SQLITE_NOMEM;
179175179502
goto exprparse_out;
179176179503
}
@@ -183396,12 +183723,22 @@
183396183723
pReader->aNode = 0;
183397183724
if( pElem ){
183398183725
char *aCopy;
183399183726
PendingList *pList = (PendingList *)fts3HashData(pElem);
183400183727
int nCopy = pList->nData+1;
183401
- pReader->zTerm = (char *)fts3HashKey(pElem);
183402
- pReader->nTerm = fts3HashKeysize(pElem);
183728
+
183729
+ int nTerm = fts3HashKeysize(pElem);
183730
+ if( (nTerm+1)>pReader->nTermAlloc ){
183731
+ sqlite3_free(pReader->zTerm);
183732
+ pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2);
183733
+ if( !pReader->zTerm ) return SQLITE_NOMEM;
183734
+ pReader->nTermAlloc = (nTerm+1)*2;
183735
+ }
183736
+ memcpy(pReader->zTerm, fts3HashKey(pElem), nTerm);
183737
+ pReader->zTerm[nTerm] = '\0';
183738
+ pReader->nTerm = nTerm;
183739
+
183403183740
aCopy = (char*)sqlite3_malloc(nCopy);
183404183741
if( !aCopy ) return SQLITE_NOMEM;
183405183742
memcpy(aCopy, pList->aData, nCopy);
183406183743
pReader->nNode = pReader->nDoclist = nCopy;
183407183744
pReader->aNode = pReader->aDoclist = aCopy;
@@ -183650,13 +183987,11 @@
183650183987
** Free all allocations associated with the iterator passed as the
183651183988
** second argument.
183652183989
*/
183653183990
SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){
183654183991
if( pReader ){
183655
- if( !fts3SegReaderIsPending(pReader) ){
183656
- sqlite3_free(pReader->zTerm);
183657
- }
183992
+ sqlite3_free(pReader->zTerm);
183658183993
if( !fts3SegReaderIsRootOnly(pReader) ){
183659183994
sqlite3_free(pReader->aNode);
183660183995
}
183661183996
sqlite3_blob_close(pReader->pBlob);
183662183997
}
@@ -188003,13 +188338,12 @@
188003188338
MatchinfoBuffer *pRet;
188004188339
sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
188005188340
+ sizeof(MatchinfoBuffer);
188006188341
sqlite3_int64 nStr = strlen(zMatchinfo);
188007188342
188008
- pRet = sqlite3_malloc64(nByte + nStr+1);
188343
+ pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
188009188344
if( pRet ){
188010
- memset(pRet, 0, nByte);
188011188345
pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
188012188346
pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
188013188347
+ sizeof(u32)*((int)nElem+1);
188014188348
pRet->nElem = (int)nElem;
188015188349
pRet->zMatchinfo = ((char*)pRet) + nByte;
@@ -188409,15 +188743,14 @@
188409188743
188410188744
/* Now that it is known how many phrases there are, allocate and zero
188411188745
** the required space using malloc().
188412188746
*/
188413188747
nByte = sizeof(SnippetPhrase) * nList;
188414
- sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte);
188748
+ sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte);
188415188749
if( !sIter.aPhrase ){
188416188750
return SQLITE_NOMEM;
188417188751
}
188418
- memset(sIter.aPhrase, 0, nByte);
188419188752
188420188753
/* Initialize the contents of the SnippetIter object. Then iterate through
188421188754
** the set of phrases in the expression to populate the aPhrase[] array.
188422188755
*/
188423188756
sIter.pCsr = pCsr;
@@ -189016,13 +189349,12 @@
189016189349
int rc = SQLITE_OK;
189017189350
189018189351
/* Allocate and populate the array of LcsIterator objects. The array
189019189352
** contains one element for each matchable phrase in the query.
189020189353
**/
189021
- aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase);
189354
+ aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase);
189022189355
if( !aIter ) return SQLITE_NOMEM;
189023
- memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase);
189024189356
(void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
189025189357
189026189358
for(i=0; i<pInfo->nPhrase; i++){
189027189359
LcsIterator *pIter = &aIter[i];
189028189360
nToken -= pIter->pExpr->pPhrase->nToken;
@@ -189479,11 +189811,11 @@
189479189811
/* Count the number of terms in the query */
189480189812
rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
189481189813
if( rc!=SQLITE_OK ) goto offsets_out;
189482189814
189483189815
/* Allocate the array of TermOffset iterators. */
189484
- sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken);
189816
+ sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken);
189485189817
if( 0==sCtx.aTerm ){
189486189818
rc = SQLITE_NOMEM;
189487189819
goto offsets_out;
189488189820
}
189489189821
sCtx.iDocid = pCsr->iPrevId;
@@ -190517,11 +190849,25 @@
190517190849
# define NEVER(X) ((X)?(assert(0),1):0)
190518190850
# else
190519190851
# define ALWAYS(X) (X)
190520190852
# define NEVER(X) (X)
190521190853
# endif
190854
+# define testcase(X)
190522190855
#endif
190856
+#if defined(NDEBUG)
190857
+# define VVA(X)
190858
+#else
190859
+# define VVA(X) X
190860
+#endif
190861
+
190862
+/*
190863
+** Some of the testcase() macros in this file are problematic for gcov
190864
+** in that they generate false-miss errors randomly. This is a gcov problem,
190865
+** not a problem in this case. But to work around it, we disable the
190866
+** problematic test cases for production builds.
190867
+*/
190868
+#define json_testcase(X)
190523190869
190524190870
/* Objects */
190525190871
typedef struct JsonString JsonString;
190526190872
typedef struct JsonNode JsonNode;
190527190873
typedef struct JsonParse JsonParse;
@@ -190575,17 +190921,18 @@
190575190921
/* A single node of parsed JSON
190576190922
*/
190577190923
struct JsonNode {
190578190924
u8 eType; /* One of the JSON_ type values */
190579190925
u8 jnFlags; /* JNODE flags */
190926
+ u8 eU; /* Which union element to use */
190580190927
u32 n; /* Bytes of content, or number of sub-nodes */
190581190928
union {
190582
- const char *zJContent; /* Content for INT, REAL, and STRING */
190583
- u32 iAppend; /* More terms for ARRAY and OBJECT */
190584
- u32 iKey; /* Key for ARRAY objects in json_tree() */
190585
- u32 iReplace; /* Replacement content for JNODE_REPLACE */
190586
- JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */
190929
+ const char *zJContent; /* 1: Content for INT, REAL, and STRING */
190930
+ u32 iAppend; /* 2: More terms for ARRAY and OBJECT */
190931
+ u32 iKey; /* 3: Key for ARRAY objects in json_tree() */
190932
+ u32 iReplace; /* 4: Replacement content for JNODE_REPLACE */
190933
+ JsonNode *pPatch; /* 5: Node chain of patch for JNODE_PATCH */
190587190934
} u;
190588190935
};
190589190936
190590190937
/* A completely parsed JSON string
190591190938
*/
@@ -190862,13 +191209,15 @@
190862191209
sqlite3_value **aReplace /* Replacement values */
190863191210
){
190864191211
assert( pNode!=0 );
190865191212
if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
190866191213
if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){
191214
+ assert( pNode->eU==4 );
190867191215
jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
190868191216
return;
190869191217
}
191218
+ assert( pNode->eU==5 );
190870191219
pNode = pNode->u.pPatch;
190871191220
}
190872191221
switch( pNode->eType ){
190873191222
default: {
190874191223
assert( pNode->eType==JSON_NULL );
@@ -190883,17 +191232,19 @@
190883191232
jsonAppendRaw(pOut, "false", 5);
190884191233
break;
190885191234
}
190886191235
case JSON_STRING: {
190887191236
if( pNode->jnFlags & JNODE_RAW ){
191237
+ assert( pNode->eU==1 );
190888191238
jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
190889191239
break;
190890191240
}
190891191241
/* no break */ deliberate_fall_through
190892191242
}
190893191243
case JSON_REAL:
190894191244
case JSON_INT: {
191245
+ assert( pNode->eU==1 );
190895191246
jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
190896191247
break;
190897191248
}
190898191249
case JSON_ARRAY: {
190899191250
u32 j = 1;
@@ -190905,10 +191256,11 @@
190905191256
jsonRenderNode(&pNode[j], pOut, aReplace);
190906191257
}
190907191258
j += jsonNodeSize(&pNode[j]);
190908191259
}
190909191260
if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191261
+ assert( pNode->eU==2 );
190910191262
pNode = &pNode[pNode->u.iAppend];
190911191263
j = 1;
190912191264
}
190913191265
jsonAppendChar(pOut, ']');
190914191266
break;
@@ -190925,10 +191277,11 @@
190925191277
jsonRenderNode(&pNode[j+1], pOut, aReplace);
190926191278
}
190927191279
j += 1 + jsonNodeSize(&pNode[j+1]);
190928191280
}
190929191281
if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191282
+ assert( pNode->eU==2 );
190930191283
pNode = &pNode[pNode->u.iAppend];
190931191284
j = 1;
190932191285
}
190933191286
jsonAppendChar(pOut, '}');
190934191287
break;
@@ -191004,11 +191357,13 @@
191004191357
sqlite3_result_int(pCtx, 0);
191005191358
break;
191006191359
}
191007191360
case JSON_INT: {
191008191361
sqlite3_int64 i = 0;
191009
- const char *z = pNode->u.zJContent;
191362
+ const char *z;
191363
+ assert( pNode->eU==1 );
191364
+ z = pNode->u.zJContent;
191010191365
if( z[0]=='-' ){ z++; }
191011191366
while( z[0]>='0' && z[0]<='9' ){
191012191367
unsigned v = *(z++) - '0';
191013191368
if( i>=LARGEST_INT64/10 ){
191014191369
if( i>LARGEST_INT64/10 ) goto int_as_real;
@@ -191032,13 +191387,16 @@
191032191387
int_as_real: ; /* no break */ deliberate_fall_through
191033191388
}
191034191389
case JSON_REAL: {
191035191390
double r;
191036191391
#ifdef SQLITE_AMALGAMATION
191037
- const char *z = pNode->u.zJContent;
191392
+ const char *z;
191393
+ assert( pNode->eU==1 );
191394
+ z = pNode->u.zJContent;
191038191395
sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
191039191396
#else
191397
+ assert( pNode->eU==1 );
191040191398
r = strtod(pNode->u.zJContent, 0);
191041191399
#endif
191042191400
sqlite3_result_double(pCtx, r);
191043191401
break;
191044191402
}
@@ -191045,26 +191403,30 @@
191045191403
case JSON_STRING: {
191046191404
#if 0 /* Never happens because JNODE_RAW is only set by json_set(),
191047191405
** json_insert() and json_replace() and those routines do not
191048191406
** call jsonReturn() */
191049191407
if( pNode->jnFlags & JNODE_RAW ){
191408
+ assert( pNode->eU==1 );
191050191409
sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
191051191410
SQLITE_TRANSIENT);
191052191411
}else
191053191412
#endif
191054191413
assert( (pNode->jnFlags & JNODE_RAW)==0 );
191055191414
if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
191056191415
/* JSON formatted without any backslash-escapes */
191416
+ assert( pNode->eU==1 );
191057191417
sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
191058191418
SQLITE_TRANSIENT);
191059191419
}else{
191060191420
/* Translate JSON formatted string into raw text */
191061191421
u32 i;
191062191422
u32 n = pNode->n;
191063
- const char *z = pNode->u.zJContent;
191423
+ const char *z;
191064191424
char *zOut;
191065191425
u32 j;
191426
+ assert( pNode->eU==1 );
191427
+ z = pNode->u.zJContent;
191066191428
zOut = sqlite3_malloc( n+1 );
191067191429
if( zOut==0 ){
191068191430
sqlite3_result_error_nomem(pCtx);
191069191431
break;
191070191432
}
@@ -191187,10 +191549,11 @@
191187191549
return jsonParseAddNodeExpand(pParse, eType, n, zContent);
191188191550
}
191189191551
p = &pParse->aNode[pParse->nNode];
191190191552
p->eType = (u8)eType;
191191191553
p->jnFlags = 0;
191554
+ VVA( p->eU = zContent ? 1 : 0 );
191192191555
p->n = n;
191193191556
p->u.zJContent = zContent;
191194191557
return pParse->nNode++;
191195191558
}
191196191559
@@ -191254,10 +191617,11 @@
191254191617
return j+1;
191255191618
}else if( c=='[' ){
191256191619
/* Parse array */
191257191620
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
191258191621
if( iThis<0 ) return -1;
191622
+ memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
191259191623
for(j=i+1;;j++){
191260191624
while( safe_isspace(z[j]) ){ j++; }
191261191625
if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
191262191626
x = jsonParseValue(pParse, j);
191263191627
pParse->iDepth--;
@@ -191518,10 +191882,11 @@
191518191882
/*
191519191883
** Compare the OBJECT label at pNode against zKey,nKey. Return true on
191520191884
** a match.
191521191885
*/
191522191886
static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
191887
+ assert( pNode->eU==1 );
191523191888
if( pNode->jnFlags & JNODE_RAW ){
191524191889
if( pNode->n!=nKey ) return 0;
191525191890
return strncmp(pNode->u.zJContent, zKey, nKey)==0;
191526191891
}else{
191527191892
if( pNode->n!=nKey+2 ) return 0;
@@ -191583,10 +191948,11 @@
191583191948
}
191584191949
j++;
191585191950
j += jsonNodeSize(&pRoot[j]);
191586191951
}
191587191952
if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
191953
+ assert( pRoot->eU==2 );
191588191954
iRoot += pRoot->u.iAppend;
191589191955
pRoot = &pParse->aNode[iRoot];
191590191956
j = 1;
191591191957
}
191592191958
if( pApnd ){
@@ -191597,12 +191963,14 @@
191597191963
zPath += i;
191598191964
pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191599191965
if( pParse->oom ) return 0;
191600191966
if( pNode ){
191601191967
pRoot = &pParse->aNode[iRoot];
191968
+ assert( pRoot->eU==0 );
191602191969
pRoot->u.iAppend = iStart - iRoot;
191603191970
pRoot->jnFlags |= JNODE_APPEND;
191971
+ VVA( pRoot->eU = 2 );
191604191972
pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
191605191973
}
191606191974
return pNode;
191607191975
}
191608191976
}else if( zPath[0]=='[' ){
@@ -191621,10 +191989,11 @@
191621191989
while( j<=pBase->n ){
191622191990
if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
191623191991
j += jsonNodeSize(&pBase[j]);
191624191992
}
191625191993
if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
191994
+ assert( pBase->eU==2 );
191626191995
iBase += pBase->u.iAppend;
191627191996
pBase = &pParse->aNode[iBase];
191628191997
j = 1;
191629191998
}
191630191999
j = 2;
@@ -191654,10 +192023,11 @@
191654192023
while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
191655192024
if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
191656192025
j += jsonNodeSize(&pRoot[j]);
191657192026
}
191658192027
if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
192028
+ assert( pRoot->eU==2 );
191659192029
iRoot += pRoot->u.iAppend;
191660192030
pRoot = &pParse->aNode[iRoot];
191661192031
j = 1;
191662192032
}
191663192033
if( j<=pRoot->n ){
@@ -191669,12 +192039,14 @@
191669192039
iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0);
191670192040
pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191671192041
if( pParse->oom ) return 0;
191672192042
if( pNode ){
191673192043
pRoot = &pParse->aNode[iRoot];
192044
+ assert( pRoot->eU==0 );
191674192045
pRoot->u.iAppend = iStart - iRoot;
191675192046
pRoot->jnFlags |= JNODE_APPEND;
192047
+ VVA( pRoot->eU = 2 );
191676192048
}
191677192049
return pNode;
191678192050
}
191679192051
}else{
191680192052
*pzErr = zPath;
@@ -191824,13 +192196,17 @@
191824192196
}else{
191825192197
zType = jsonType[x.aNode[i].eType];
191826192198
}
191827192199
jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d",
191828192200
i, zType, x.aNode[i].n, x.aUp[i]);
192201
+ assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 );
191829192202
if( x.aNode[i].u.zJContent!=0 ){
192203
+ assert( x.aNode[i].eU==1 );
191830192204
jsonAppendRaw(&s, " ", 1);
191831192205
jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n);
192206
+ }else{
192207
+ assert( x.aNode[i].eU==0 );
191832192208
}
191833192209
jsonAppendRaw(&s, "\n", 1);
191834192210
}
191835192211
jsonParseReset(&x);
191836192212
jsonResult(&s);
@@ -192009,10 +192385,11 @@
192009192385
for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){
192010192386
u32 nKey;
192011192387
const char *zKey;
192012192388
assert( pPatch[i].eType==JSON_STRING );
192013192389
assert( pPatch[i].jnFlags & JNODE_LABEL );
192390
+ assert( pPatch[i].eU==1 );
192014192391
nKey = pPatch[i].n;
192015192392
zKey = pPatch[i].u.zJContent;
192016192393
assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
192017192394
for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
192018192395
assert( pTarget[j].eType==JSON_STRING );
@@ -192025,10 +192402,13 @@
192025192402
}else{
192026192403
JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
192027192404
if( pNew==0 ) return 0;
192028192405
pTarget = &pParse->aNode[iTarget];
192029192406
if( pNew!=&pTarget[j+1] ){
192407
+ assert( pTarget[j+1].eU==0 || pTarget[j+1].eU==1 );
192408
+ testcase( pTarget[j+1].eU==1 );
192409
+ VVA( pTarget[j+1].eU = 5 );
192030192410
pTarget[j+1].u.pPatch = pNew;
192031192411
pTarget[j+1].jnFlags |= JNODE_PATCH;
192032192412
}
192033192413
}
192034192414
break;
@@ -192040,13 +192420,18 @@
192040192420
jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
192041192421
iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
192042192422
if( pParse->oom ) return 0;
192043192423
jsonRemoveAllNulls(pPatch);
192044192424
pTarget = &pParse->aNode[iTarget];
192425
+ assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 );
192426
+ testcase( pParse->aNode[iRoot].eU==2 );
192045192427
pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
192428
+ VVA( pParse->aNode[iRoot].eU = 2 );
192046192429
pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
192047192430
iRoot = iStart;
192431
+ assert( pParse->aNode[iPatch].eU==0 );
192432
+ VVA( pParse->aNode[iPatch].eU = 5 );
192048192433
pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
192049192434
pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
192050192435
}
192051192436
}
192052192437
return pTarget;
@@ -192184,15 +192569,19 @@
192184192569
for(i=1; i<(u32)argc; i+=2){
192185192570
zPath = (const char*)sqlite3_value_text(argv[i]);
192186192571
pNode = jsonLookup(&x, zPath, 0, ctx);
192187192572
if( x.nErr ) goto replace_err;
192188192573
if( pNode ){
192574
+ assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 );
192575
+ json_testcase( pNode->eU!=0 && pNode->eU!=1 );
192189192576
pNode->jnFlags |= (u8)JNODE_REPLACE;
192577
+ VVA( pNode->eU = 4 );
192190192578
pNode->u.iReplace = i + 1;
192191192579
}
192192192580
}
192193192581
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192582
+ assert( x.aNode[0].eU==4 );
192194192583
sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192195192584
}else{
192196192585
jsonReturnJson(x.aNode, ctx, argv);
192197192586
}
192198192587
replace_err:
@@ -192238,15 +192627,19 @@
192238192627
sqlite3_result_error_nomem(ctx);
192239192628
goto jsonSetDone;
192240192629
}else if( x.nErr ){
192241192630
goto jsonSetDone;
192242192631
}else if( pNode && (bApnd || bIsSet) ){
192632
+ json_testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
192633
+ assert( pNode->eU!=3 || pNode->eU!=5 );
192634
+ VVA( pNode->eU = 4 );
192243192635
pNode->jnFlags |= (u8)JNODE_REPLACE;
192244192636
pNode->u.iReplace = i + 1;
192245192637
}
192246192638
}
192247192639
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192640
+ assert( x.aNode[0].eU==4 );
192248192641
sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192249192642
}else{
192250192643
jsonReturnJson(x.aNode, ctx, argv);
192251192644
}
192252192645
jsonSetDone:
@@ -192593,10 +192986,13 @@
192593192986
if( p->i<p->iEnd ){
192594192987
u32 iUp = p->sParse.aUp[p->i];
192595192988
JsonNode *pUp = &p->sParse.aNode[iUp];
192596192989
p->eType = pUp->eType;
192597192990
if( pUp->eType==JSON_ARRAY ){
192991
+ assert( pUp->eU==0 || pUp->eU==3 );
192992
+ json_testcase( pUp->eU==3 );
192993
+ VVA( pUp->eU = 3 );
192598192994
if( iUp==p->i-1 ){
192599192995
pUp->u.iKey = 0;
192600192996
}else{
192601192997
pUp->u.iKey++;
192602192998
}
@@ -192639,16 +193035,19 @@
192639193035
iUp = p->sParse.aUp[i];
192640193036
jsonEachComputePath(p, pStr, iUp);
192641193037
pNode = &p->sParse.aNode[i];
192642193038
pUp = &p->sParse.aNode[iUp];
192643193039
if( pUp->eType==JSON_ARRAY ){
193040
+ assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) );
193041
+ testcase( pUp->eU==0 );
192644193042
jsonPrintf(30, pStr, "[%d]", pUp->u.iKey);
192645193043
}else{
192646193044
assert( pUp->eType==JSON_OBJECT );
192647193045
if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
192648193046
assert( pNode->eType==JSON_STRING );
192649193047
assert( pNode->jnFlags & JNODE_LABEL );
193048
+ assert( pNode->eU==1 );
192650193049
jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
192651193050
}
192652193051
}
192653193052
192654193053
/* Return the value of a column */
@@ -192666,10 +193065,11 @@
192666193065
jsonReturn(pThis, ctx, 0);
192667193066
}else if( p->eType==JSON_ARRAY ){
192668193067
u32 iKey;
192669193068
if( p->bRecursive ){
192670193069
if( p->iRowid==0 ) break;
193070
+ assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 );
192671193071
iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey;
192672193072
}else{
192673193073
iKey = p->iRowid;
192674193074
}
192675193075
sqlite3_result_int64(ctx, (sqlite3_int64)iKey);
@@ -192715,10 +193115,11 @@
192715193115
jsonAppendChar(&x, '$');
192716193116
}
192717193117
if( p->eType==JSON_ARRAY ){
192718193118
jsonPrintf(30, &x, "[%d]", p->iRowid);
192719193119
}else if( p->eType==JSON_OBJECT ){
193120
+ assert( pThis->eU==1 );
192720193121
jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
192721193122
}
192722193123
}
192723193124
jsonResult(&x);
192724193125
break;
@@ -192782,10 +193183,11 @@
192782193183
int iCol;
192783193184
int iMask;
192784193185
if( pConstraint->iColumn < JEACH_JSON ) continue;
192785193186
iCol = pConstraint->iColumn - JEACH_JSON;
192786193187
assert( iCol==0 || iCol==1 );
193188
+ testcase( iCol==0 );
192787193189
iMask = 1 << iCol;
192788193190
if( pConstraint->usable==0 ){
192789193191
unusableMask |= iMask;
192790193192
}else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
192791193193
aIdx[iCol] = i;
@@ -192879,10 +193281,12 @@
192879193281
pNode = p->sParse.aNode;
192880193282
}
192881193283
p->iBegin = p->i = (int)(pNode - p->sParse.aNode);
192882193284
p->eType = pNode->eType;
192883193285
if( p->eType>=JSON_ARRAY ){
193286
+ assert( pNode->eU==0 );
193287
+ VVA( pNode->eU = 3 );
192884193288
pNode->u.iKey = 0;
192885193289
p->iEnd = p->i + pNode->n + 1;
192886193290
if( p->bRecursive ){
192887193291
p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType;
192888193292
if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){
@@ -193493,11 +193897,11 @@
193493193897
193494193898
/* The testcase() macro should already be defined in the amalgamation. If
193495193899
** it is not, make it a no-op.
193496193900
*/
193497193901
#ifndef SQLITE_AMALGAMATION
193498
-# ifdef SQLITE_COVERAGE_TEST
193902
+# if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
193499193903
unsigned int sqlite3RtreeTestcase = 0;
193500193904
# define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; }
193501193905
# else
193502193906
# define testcase(X)
193503193907
# endif
@@ -214008,11 +214412,11 @@
214008214412
214009214413
/*
214010214414
** A version of memcmp() that does not cause asan errors if one of the pointer
214011214415
** parameters is NULL and the number of bytes to compare is zero.
214012214416
*/
214013
-#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
214417
+#define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
214014214418
214015214419
/* Mark a function parameter as unused, to suppress nuisance compiler
214016214420
** warnings. */
214017214421
#ifndef UNUSED_PARAM
214018214422
# define UNUSED_PARAM(X) (void)(X)
@@ -217034,11 +217438,10 @@
217034217438
int *pRc,
217035217439
Fts5Buffer *pBuf,
217036217440
u32 nData,
217037217441
const u8 *pData
217038217442
){
217039
- assert_nc( *pRc || nData>=0 );
217040217443
if( nData ){
217041217444
if( fts5BufferGrow(pRc, pBuf, nData) ) return;
217042217445
memcpy(&pBuf->p[pBuf->n], pData, nData);
217043217446
pBuf->n += nData;
217044217447
}
@@ -217146,11 +217549,10 @@
217146217549
return 1;
217147217550
}else{
217148217551
i64 iOff = *piOff;
217149217552
u32 iVal;
217150217553
fts5FastGetVarint32(a, i, iVal);
217151
- assert( iVal>=0 );
217152217554
if( iVal<=1 ){
217153217555
if( iVal==0 ){
217154217556
*pi = i;
217155217557
return 0;
217156217558
}
@@ -221761,11 +222163,11 @@
221761222163
if( iCol>=0 ){
221762222164
if( pHash->eDetail==FTS5_DETAIL_NONE ){
221763222165
p->bContent = 1;
221764222166
}else{
221765222167
/* Append a new column value, if necessary */
221766
- assert( iCol>=p->iCol );
222168
+ assert_nc( iCol>=p->iCol );
221767222169
if( iCol!=p->iCol ){
221768222170
if( pHash->eDetail==FTS5_DETAIL_FULL ){
221769222171
pPtr[p->nData++] = 0x01;
221770222172
p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
221771222173
p->iCol = (i16)iCol;
@@ -222566,12 +222968,15 @@
222566222968
** +ve if pRight is smaller than pLeft. In other words:
222567222969
**
222568222970
** res = *pLeft - *pRight
222569222971
*/
222570222972
static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
222571
- int nCmp = MIN(pLeft->n, pRight->n);
222572
- int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
222973
+ int nCmp, res;
222974
+ nCmp = MIN(pLeft->n, pRight->n);
222975
+ assert( nCmp<=0 || pLeft->p!=0 );
222976
+ assert( nCmp<=0 || pRight->p!=0 );
222977
+ res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
222573222978
return (res==0 ? (pLeft->n - pRight->n) : res);
222574222979
}
222575222980
222576222981
static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
222577222982
int ret;
@@ -224244,25 +224649,24 @@
224244224649
Fts5Index *p, /* Leave any error code here */
224245224650
int bGe, /* True for a >= search */
224246224651
Fts5SegIter *pIter, /* Iterator to seek */
224247224652
const u8 *pTerm, int nTerm /* Term to search for */
224248224653
){
224249
- int iOff;
224654
+ u32 iOff;
224250224655
const u8 *a = pIter->pLeaf->p;
224251
- int szLeaf = pIter->pLeaf->szLeaf;
224252
- int n = pIter->pLeaf->nn;
224656
+ u32 n = (u32)pIter->pLeaf->nn;
224253224657
224254224658
u32 nMatch = 0;
224255224659
u32 nKeep = 0;
224256224660
u32 nNew = 0;
224257224661
u32 iTermOff;
224258
- int iPgidx; /* Current offset in pgidx */
224662
+ u32 iPgidx; /* Current offset in pgidx */
224259224663
int bEndOfPage = 0;
224260224664
224261224665
assert( p->rc==SQLITE_OK );
224262224666
224263
- iPgidx = szLeaf;
224667
+ iPgidx = (u32)pIter->pLeaf->szLeaf;
224264224668
iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
224265224669
iOff = iTermOff;
224266224670
if( iOff>n ){
224267224671
p->rc = FTS5_CORRUPT;
224268224672
return;
@@ -224324,19 +224728,19 @@
224324224728
do {
224325224729
fts5SegIterNextPage(p, pIter);
224326224730
if( pIter->pLeaf==0 ) return;
224327224731
a = pIter->pLeaf->p;
224328224732
if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
224329
- iPgidx = pIter->pLeaf->szLeaf;
224733
+ iPgidx = (u32)pIter->pLeaf->szLeaf;
224330224734
iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
224331
- if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
224735
+ if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
224332224736
p->rc = FTS5_CORRUPT;
224333224737
return;
224334224738
}else{
224335224739
nKeep = 0;
224336224740
iTermOff = iOff;
224337
- n = pIter->pLeaf->nn;
224741
+ n = (u32)pIter->pLeaf->nn;
224338224742
iOff += fts5GetVarint32(&a[iOff], nNew);
224339224743
break;
224340224744
}
224341224745
}
224342224746
}while( 1 );
@@ -231573,11 +231977,11 @@
231573231977
int nArg, /* Number of args */
231574231978
sqlite3_value **apUnused /* Function arguments */
231575231979
){
231576231980
assert( nArg==0 );
231577231981
UNUSED_PARAM2(nArg, apUnused);
231578
- sqlite3_result_text(pCtx, "fts5: 2021-10-05 18:33:38 a7835bead85b1b18a8affd9835240b0baf9c7af887196bbdcc3f5d58055042fc", -1, SQLITE_TRANSIENT);
231982
+ sqlite3_result_text(pCtx, "fts5: 2021-10-04 12:16:27 71b102942cf46e307b123afbc51be06ebf48af9c364c0e7e0b9763f6963d3fb9", -1, SQLITE_TRANSIENT);
231579231983
}
231580231984
231581231985
/*
231582231986
** Return true if zName is the extension on one of the shadow tables used
231583231987
** by this module.
231584231988
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-10-06 10:36:56 566e6974892ebd3d3de8d77b24655257a5efe14434c553e1a25fc680b201b336"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -843,11 +843,10 @@
843 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
844 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
845 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
846 #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
847 #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
848 #define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8))
849 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
850 #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
851 #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
852 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
853 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
@@ -879,10 +878,23 @@
879 ** CAPI3REF: Flags For File Open Operations
880 **
881 ** These bit values are intended for use in the
882 ** 3rd parameter to the [sqlite3_open_v2()] interface and
883 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
 
 
 
 
 
 
 
 
 
 
 
 
 
884 */
885 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
886 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
887 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
888 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
@@ -3723,22 +3735,24 @@
3723 ** the default shared cache setting provided by
3724 ** [sqlite3_enable_shared_cache()].)^
3725 **
3726 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3727 ** <dd>The database filename is not allowed to be a symbolic link</dd>
3728 **
3729 ** [[OPEN_EXCLUSIVE]] ^(<dt>[SQLITE_OPEN_EXCLUSIVE]</dt>
3730 ** <dd>This flag causes the open to fail if the database file already
3731 ** exists. The open will only be success if this flag is used in combination
3732 ** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if
3733 ** the file does not previously exist.</dd>
3734 ** </dl>)^
3735 **
3736 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3737 ** required combinations shown above optionally combined with other
3738 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3739 ** then the behavior is undefined.
 
 
 
 
 
 
 
 
3740 **
3741 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3742 ** [sqlite3_vfs] object that defines the operating system interface that
3743 ** the new database connection should use. ^If the fourth parameter is
3744 ** a NULL pointer then the default [sqlite3_vfs] object is used.
@@ -13162,13 +13176,15 @@
13162 ** is significant and used at least once. On switch statements
13163 ** where multiple cases go to the same block of code, testcase()
13164 ** can insure that all cases are evaluated.
13165 **
13166 */
13167 #ifdef SQLITE_COVERAGE_TEST
13168 SQLITE_PRIVATE void sqlite3Coverage(int);
13169 # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
 
 
13170 #else
13171 # define testcase(X)
13172 #endif
13173
13174 /*
@@ -13228,30 +13244,10 @@
13228 #else
13229 # define ALWAYS(X) (X)
13230 # define NEVER(X) (X)
13231 #endif
13232
13233 /*
13234 ** The harmless(X) macro indicates that expression X is usually false
13235 ** but can be true without causing any problems, but we don't know of
13236 ** any way to cause X to be true.
13237 **
13238 ** In debugging and testing builds, this macro will abort if X is ever
13239 ** true. In this way, developers are alerted to a possible test case
13240 ** that causes X to be true. If a harmless macro ever fails, that is
13241 ** an opportunity to change the macro into a testcase() and add a new
13242 ** test case to the test suite.
13243 **
13244 ** For normal production builds, harmless(X) is a no-op, since it does
13245 ** not matter whether expression X is true or false.
13246 */
13247 #ifdef SQLITE_DEBUG
13248 # define harmless(X) assert(!(X));
13249 #else
13250 # define harmless(X)
13251 #endif
13252
13253 /*
13254 ** Some conditionals are optimizations only. In other words, if the
13255 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
13256 ** the correct answer is still obtained, though perhaps not as quickly.
13257 **
@@ -13430,11 +13426,11 @@
13430 /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */
13431
13432 /*
13433 ** Number of entries in a hash table
13434 */
13435 /* #define sqliteHashCount(H) ((H)->count) // NOT USED */
13436
13437 #endif /* SQLITE_HASH_H */
13438
13439 /************** End of hash.h ************************************************/
13440 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -16428,14 +16424,14 @@
16428 int nVdbeExec; /* Number of nested calls to VdbeExec() */
16429 int nVDestroy; /* Number of active OP_VDestroy operations */
16430 int nExtension; /* Number of loaded extensions */
16431 void **aExtension; /* Array of shared library handles */
16432 union {
16433 void (*xLegacy)(void*,const char*); /* Legacy trace function */
16434 int (*xV2)(u32,void*,void*,void*); /* V2 Trace function */
16435 } trace;
16436 void *pTraceArg; /* Argument to the trace function */
16437 #ifndef SQLITE_OMIT_DEPRECATED
16438 void (*xProfile)(void*,const char*,u64); /* Profiling function */
16439 void *pProfileArg; /* Argument to profile function */
16440 #endif
16441 void *pCommitArg; /* Argument to xCommitCallback() */
@@ -16667,11 +16663,11 @@
16667 void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */
16668 const char *zName; /* SQL name of the function. */
16669 union {
16670 FuncDef *pHash; /* Next with a different name but the same hash */
16671 FuncDestructor *pDestructor; /* Reference counted destructor function */
16672 } u;
16673 };
16674
16675 /*
16676 ** This structure encapsulates a user-function destructor callback (as
16677 ** configured using create_function_v2()) and a reference counter. When
@@ -16728,10 +16724,11 @@
16728 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
16729 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
16730 #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
16731 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
16732 #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
 
16733 #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */
16734
16735 /* Identifier numbers for each in-line function */
16736 #define INLINEFUNC_coalesce 0
16737 #define INLINEFUNC_implies_nonnull_row 1
@@ -16806,48 +16803,55 @@
16806 ** available as the function user-data (sqlite3_user_data()). The
16807 ** FuncDef.flags variable is set to the value passed as the flags
16808 ** parameter.
16809 */
16810 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
16811 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
 
16812 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16813 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16814 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16815 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16816 #define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16817 {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
16818 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16819 #define MFUNCTION(zName, nArg, xPtr, xFunc) \
16820 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
16821 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
16822 #define INLINE_FUNC(zName, nArg, iArg, mFlags) \
16823 {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
 
16824 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16825 #define TEST_FUNC(zName, nArg, iArg, mFlags) \
16826 {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
 
16827 SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16828 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16829 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16830 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
16831 0, 0, xFunc, 0, 0, 0, #zName, {0} }
16832 #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
16833 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
 
16834 (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
16835 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
16836 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
 
16837 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16838 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
16839 {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
 
16840 pArg, 0, xFunc, 0, 0, 0, #zName, }
16841 #define LIKEFUNC(zName, nArg, arg, flags) \
16842 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
16843 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
16844 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
16845 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
16846 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
16847 #define INTERNAL_FUNCTION(zName, nArg, xFunc) \
16848 {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
 
16849 0, 0, xFunc, 0, 0, 0, #zName, {0} }
16850
16851
16852 /*
16853 ** All current savepoints are stored in a linked list starting at
@@ -17566,14 +17570,14 @@
17566 ** code representing the ">=" operator. This same integer code is reused
17567 ** to represent the greater-than-or-equal-to operator in the expression
17568 ** tree.
17569 **
17570 ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
17571 ** or TK_STRING), then Expr.token contains the text of the SQL literal. If
17572 ** the expression is a variable (TK_VARIABLE), then Expr.token contains the
17573 ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
17574 ** then Expr.token contains the name of the function.
17575 **
17576 ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
17577 ** binary operator. Either or both may be NULL.
17578 **
17579 ** Expr.x.pList is a list of arguments if the expression is an SQL function,
@@ -17609,11 +17613,11 @@
17609 **
17610 ** Expr objects can use a lot of memory space in database schema. To
17611 ** help reduce memory requirements, sometimes an Expr object will be
17612 ** truncated. And to reduce the number of memory allocations, sometimes
17613 ** two or more Expr objects will be stored in a single memory allocation,
17614 ** together with Expr.zToken strings.
17615 **
17616 ** If the EP_Reduced and EP_TokenOnly flags are set when
17617 ** an Expr object is truncated. When EP_Reduced is set, then all
17618 ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
17619 ** are contained within the same memory allocation. Note, however, that
@@ -17678,12 +17682,11 @@
17678 int regReturn; /* Register used to hold return address */
17679 } sub;
17680 } y;
17681 };
17682
17683 /*
17684 ** The following are the meanings of bits in the Expr.flags field.
17685 ** Value restrictions:
17686 **
17687 ** EP_Agg == NC_HasAgg == SF_HasAgg
17688 ** EP_Win == NC_HasWin
17689 */
@@ -17718,27 +17721,35 @@
17718 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
17719 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
17720 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
17721 /* 0x80000000 // Available */
17722
17723 /*
17724 ** The EP_Propagate mask is a set of properties that automatically propagate
17725 ** upwards into parent nodes.
17726 */
17727 #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
17728
17729 /*
17730 ** These macros can be used to test, set, or clear bits in the
17731 ** Expr.flags field.
17732 */
17733 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
17734 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
17735 #define ExprSetProperty(E,P) (E)->flags|=(P)
17736 #define ExprClearProperty(E,P) (E)->flags&=~(P)
17737 #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
17738 #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
17739
 
 
 
 
 
 
 
 
 
 
17740
17741 /* Flags for use with Expr.vvaFlags
17742 */
17743 #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */
17744 #define EP_Immutable 0x02 /* Do not change this Expr node */
@@ -17817,15 +17828,16 @@
17817 unsigned done :1; /* A flag to indicate when processing is finished */
17818 unsigned reusable :1; /* Constant expression is reusable */
17819 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
17820 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
17821 union {
17822 struct {
17823 u16 iOrderByCol; /* For ORDER BY, column number in result set */
17824 u16 iAlias; /* Index into Parse.aAlias[] for zName */
17825 } x;
17826 int iConstExprReg; /* Register in which Expr value is cached */
 
17827 } u;
17828 } a[1]; /* One slot for each expression in the list */
17829 };
17830
17831 /*
@@ -17859,10 +17871,17 @@
17859 };
17860
17861 /*
17862 ** The SrcItem object represents a single term in the FROM clause of a query.
17863 ** The SrcList object is mostly an array of SrcItems.
 
 
 
 
 
 
 
17864 */
17865 struct SrcItem {
17866 Schema *pSchema; /* Schema to which this item is fixed */
17867 char *zDatabase; /* Name of database holding this table */
17868 char *zName; /* Name of the table */
@@ -18453,10 +18472,12 @@
18453 #ifndef SQLITE_OMIT_ALTERTABLE
18454 RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
18455 #endif
18456 };
18457
 
 
18458 #define PARSE_MODE_NORMAL 0
18459 #define PARSE_MODE_DECLARE_VTAB 1
18460 #define PARSE_MODE_RENAME 2
18461 #define PARSE_MODE_UNMAP 3
18462
@@ -20109,12 +20130,12 @@
20109 ** All of this is no-op for a production build. It only comes into
20110 ** play when the SQLITE_MEMDEBUG compile-time option is used.
20111 */
20112 #ifdef SQLITE_MEMDEBUG
20113 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
20114 SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
20115 SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8);
20116 #else
20117 # define sqlite3MemdebugSetType(X,Y) /* no-op */
20118 # define sqlite3MemdebugHasType(X,Y) 1
20119 # define sqlite3MemdebugNoType(X,Y) 1
20120 #endif
@@ -21433,10 +21454,16 @@
21433 ** database connections. After initialization, this table is
21434 ** read-only.
21435 */
21436 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
21437
 
 
 
 
 
 
21438 #ifdef VDBE_PROFILE
21439 /*
21440 ** The following performance counter can be used in place of
21441 ** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
21442 */
@@ -24817,11 +24844,11 @@
24817 ** Given an allocation, find the MemBlockHdr for that allocation.
24818 **
24819 ** This routine checks the guards at either end of the allocation and
24820 ** if they are incorrect it asserts.
24821 */
24822 static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){
24823 struct MemBlockHdr *p;
24824 int *pInt;
24825 u8 *pU8;
24826 int nReserve;
24827
@@ -25064,11 +25091,11 @@
25064 ** This routine is designed for use within an assert() statement, to
25065 ** verify the type of an allocation. For example:
25066 **
25067 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
25068 */
25069 SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
25070 int rc = 1;
25071 if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
25072 struct MemBlockHdr *pHdr;
25073 pHdr = sqlite3MemsysGetHeader(p);
25074 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -25086,11 +25113,11 @@
25086 ** This routine is designed for use within an assert() statement, to
25087 ** verify the type of an allocation. For example:
25088 **
25089 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
25090 */
25091 SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
25092 int rc = 1;
25093 if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
25094 struct MemBlockHdr *pHdr;
25095 pHdr = sqlite3MemsysGetHeader(p);
25096 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -30551,10 +30578,11 @@
30551 zOp2[0] = 0;
30552 }
30553 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
30554 pExpr->iColumn, zFlgs, zOp2);
30555 }else{
 
30556 sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
30557 pExpr->iTable, pExpr->iColumn,
30558 pExpr->y.pTab, zFlgs);
30559 }
30560 if( ExprHasProperty(pExpr, EP_FixedCol) ){
@@ -30570,15 +30598,17 @@
30570 }
30571 break;
30572 }
30573 #ifndef SQLITE_OMIT_FLOATING_POINT
30574 case TK_FLOAT: {
 
30575 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
30576 break;
30577 }
30578 #endif
30579 case TK_STRING: {
 
30580 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
30581 break;
30582 }
30583 case TK_NULL: {
30584 sqlite3TreeViewLine(pView,"NULL");
@@ -30589,30 +30619,34 @@
30589 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
30590 break;
30591 }
30592 #ifndef SQLITE_OMIT_BLOB_LITERAL
30593 case TK_BLOB: {
 
30594 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
30595 break;
30596 }
30597 #endif
30598 case TK_VARIABLE: {
 
30599 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
30600 pExpr->u.zToken, pExpr->iColumn);
30601 break;
30602 }
30603 case TK_REGISTER: {
30604 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
30605 break;
30606 }
30607 case TK_ID: {
 
30608 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
30609 break;
30610 }
30611 #ifndef SQLITE_OMIT_CAST
30612 case TK_CAST: {
30613 /* Expressions of the form: CAST(pLeft AS token) */
 
30614 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
30615 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30616 break;
30617 }
30618 #endif /* SQLITE_OMIT_CAST */
@@ -30658,10 +30692,11 @@
30658 zUniOp = azOp[x];
30659 break;
30660 }
30661
30662 case TK_SPAN: {
 
30663 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
30664 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30665 break;
30666 }
30667
@@ -30669,10 +30704,11 @@
30669 /* COLLATE operators without the EP_Collate flag are intended to
30670 ** emulate collation associated with a table column. These show
30671 ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE
30672 ** operators that appear in the original SQL always have the
30673 ** EP_Collate bit set and appear in treeview output as just "COLLATE" */
 
30674 sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s",
30675 !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "",
30676 pExpr->u.zToken, zFlgs);
30677 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30678 break;
@@ -30684,17 +30720,19 @@
30684 Window *pWin;
30685 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
30686 pFarg = 0;
30687 pWin = 0;
30688 }else{
 
30689 pFarg = pExpr->x.pList;
30690 #ifndef SQLITE_OMIT_WINDOWFUNC
30691 pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
30692 #else
30693 pWin = 0;
30694 #endif
30695 }
 
30696 if( pExpr->op==TK_AGG_FUNCTION ){
30697 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
30698 pExpr->op2, pExpr->u.zToken, zFlgs,
30699 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
30700 pExpr->iAgg, pExpr->pAggInfo);
@@ -30722,23 +30760,25 @@
30722 #endif
30723 break;
30724 }
30725 #ifndef SQLITE_OMIT_SUBQUERY
30726 case TK_EXISTS: {
 
30727 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
30728 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30729 break;
30730 }
30731 case TK_SELECT: {
 
30732 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
30733 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30734 break;
30735 }
30736 case TK_IN: {
30737 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
30738 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30739 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
30740 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30741 }else{
30742 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
30743 }
30744 break;
@@ -30755,13 +30795,16 @@
30755 ** X is stored in pExpr->pLeft.
30756 ** Y is stored in pExpr->pList->a[0].pExpr.
30757 ** Z is stored in pExpr->pList->a[1].pExpr.
30758 */
30759 case TK_BETWEEN: {
30760 Expr *pX = pExpr->pLeft;
30761 Expr *pY = pExpr->x.pList->a[0].pExpr;
30762 Expr *pZ = pExpr->x.pList->a[1].pExpr;
 
 
 
30763 sqlite3TreeViewLine(pView, "BETWEEN");
30764 sqlite3TreeViewExpr(pView, pX, 1);
30765 sqlite3TreeViewExpr(pView, pY, 1);
30766 sqlite3TreeViewExpr(pView, pZ, 0);
30767 break;
@@ -30779,10 +30822,11 @@
30779 break;
30780 }
30781 case TK_CASE: {
30782 sqlite3TreeViewLine(pView, "CASE");
30783 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
 
30784 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
30785 break;
30786 }
30787 #ifndef SQLITE_OMIT_TRIGGER
30788 case TK_RAISE: {
@@ -30791,10 +30835,11 @@
30791 case OE_Rollback: zType = "rollback"; break;
30792 case OE_Abort: zType = "abort"; break;
30793 case OE_Fail: zType = "fail"; break;
30794 case OE_Ignore: zType = "ignore"; break;
30795 }
 
30796 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
30797 break;
30798 }
30799 #endif
30800 case TK_MATCH: {
@@ -30803,18 +30848,20 @@
30803 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
30804 break;
30805 }
30806 case TK_VECTOR: {
30807 char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
 
30808 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
30809 sqlite3_free(z);
30810 break;
30811 }
30812 case TK_SELECT_COLUMN: {
30813 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s",
30814 pExpr->iColumn, pExpr->iTable-1,
30815 pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : "");
 
30816 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
30817 break;
30818 }
30819 case TK_IF_NULL_ROW: {
30820 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
@@ -31887,20 +31934,10 @@
31887 /* #include <stdarg.h> */
31888 #ifndef SQLITE_OMIT_FLOATING_POINT
31889 #include <math.h>
31890 #endif
31891
31892 /*
31893 ** Routine needed to support the testcase() macro.
31894 */
31895 #ifdef SQLITE_COVERAGE_TEST
31896 SQLITE_PRIVATE void sqlite3Coverage(int x){
31897 static unsigned dummy = 0;
31898 dummy += (unsigned)x;
31899 }
31900 #endif
31901
31902 /*
31903 ** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
31904 ** or to bypass normal error detection during testing in order to let
31905 ** execute proceed futher downstream.
31906 **
@@ -32143,10 +32180,11 @@
32143 }
32144 }
32145 z[j] = 0;
32146 }
32147 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
 
32148 assert( sqlite3Isquote(p->u.zToken[0]) );
32149 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
32150 sqlite3Dequote(p->u.zToken);
32151 }
32152
@@ -40270,12 +40308,10 @@
40270 if( fd<0 ){
40271 if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
40272 /* If unable to create a journal because the directory is not
40273 ** writable, change the error code to indicate that. */
40274 rc = SQLITE_READONLY_DIRECTORY;
40275 }else if( errno==EEXIST ){
40276 rc = SQLITE_CANTOPEN_EXISTS;
40277 }else if( errno!=EISDIR && isReadWrite ){
40278 /* Failed to open the file for read/write access. Try read-only. */
40279 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
40280 openFlags &= ~(O_RDWR|O_CREAT);
40281 flags |= SQLITE_OPEN_READONLY;
@@ -59613,11 +59649,11 @@
59613 */
59614 pPg->flags &= ~PGHDR_NEED_SYNC;
59615 pPgOld = sqlite3PagerLookup(pPager, pgno);
59616 assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
59617 if( pPgOld ){
59618 if( pPgOld->nRef>1 ){
59619 sqlite3PagerUnrefNotNull(pPgOld);
59620 return SQLITE_CORRUPT_BKPT;
59621 }
59622 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
59623 if( pPager->tempFile ){
@@ -64637,11 +64673,10 @@
64637 ** Access to all fields of this structure is controlled by the mutex
64638 ** stored in MemPage.pBt->mutex.
64639 */
64640 struct MemPage {
64641 u8 isInit; /* True if previously initialized. MUST BE FIRST! */
64642 u8 bBusy; /* Prevent endless loops on corrupt database files */
64643 u8 intKey; /* True if table b-trees. False for index b-trees */
64644 u8 intKeyLeaf; /* True if the leaf of an intKey table */
64645 Pgno pgno; /* Page number for this page */
64646 /* Only the first 8 bytes (above) are zeroed by pager.c when a new page
64647 ** is allocated. All fields that follow must be initialized before use */
@@ -70227,11 +70262,13 @@
70227 #endif
70228
70229 assert( pPage );
70230 assert( eOp==0 || eOp==1 );
70231 assert( pCur->eState==CURSOR_VALID );
70232 assert( pCur->ix<pPage->nCell );
 
 
70233 assert( cursorHoldsMutex(pCur) );
70234
70235 getCellInfo(pCur);
70236 aPayload = pCur->info.pPayload;
70237 assert( offset+amt <= pCur->info.nPayload );
@@ -70414,11 +70451,10 @@
70414 */
70415 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
70416 assert( cursorHoldsMutex(pCur) );
70417 assert( pCur->eState==CURSOR_VALID );
70418 assert( pCur->iPage>=0 && pCur->pPage );
70419 assert( pCur->ix<pCur->pPage->nCell );
70420 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
70421 }
70422
70423 /*
70424 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -70476,11 +70512,11 @@
70476 int amt;
70477 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
70478 assert( pCur->eState==CURSOR_VALID );
70479 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
70480 assert( cursorOwnsBtShared(pCur) );
70481 assert( pCur->ix<pCur->pPage->nCell );
70482 assert( pCur->info.nSize>0 );
70483 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
70484 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
70485 amt = pCur->info.nLocal;
70486 if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
@@ -71262,20 +71298,10 @@
71262 ** module cov1/btree78.test testcase 220 (2018-06-08) for an
71263 ** example. */
71264 return SQLITE_CORRUPT_BKPT;
71265 }
71266
71267 /* If the database file is corrupt, it is possible for the value of idx
71268 ** to be invalid here. This can only occur if a second cursor modifies
71269 ** the page while cursor pCur is holding a reference to it. Which can
71270 ** only happen if the database is corrupt in such a way as to link the
71271 ** page into more than one b-tree structure.
71272 **
71273 ** Update 2019-12-23: appears to long longer be possible after the
71274 ** addition of anotherValidCursor() condition on balance_deeper(). */
71275 harmless( idx>pPage->nCell );
71276
71277 if( idx>=pPage->nCell ){
71278 if( !pPage->leaf ){
71279 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
71280 if( rc ) return rc;
71281 return moveToLeftmost(pCur);
@@ -71759,11 +71785,11 @@
71759
71760 assert( sqlite3_mutex_held(pBt->mutex) );
71761 assert( CORRUPT_DB || iPage>1 );
71762 assert( !pMemPage || pMemPage->pgno==iPage );
71763
71764 if( iPage<2 || iPage>pBt->nPage ){
71765 return SQLITE_CORRUPT_BKPT;
71766 }
71767 if( pMemPage ){
71768 pPage = pMemPage;
71769 sqlite3PagerRef(pPage->pDbPage);
@@ -74360,11 +74386,14 @@
74360 assert( szNew==pPage->xCellSize(pPage, newCell) );
74361 assert( szNew <= MX_CELL_SIZE(pBt) );
74362 idx = pCur->ix;
74363 if( loc==0 ){
74364 CellInfo info;
74365 assert( idx<pPage->nCell );
 
 
 
74366 rc = sqlite3PagerWrite(pPage->pDbPage);
74367 if( rc ){
74368 goto end_insert;
74369 }
74370 oldCell = findCell(pPage, idx);
@@ -74946,15 +74975,16 @@
74946 if( pgno>btreePagecount(pBt) ){
74947 return SQLITE_CORRUPT_BKPT;
74948 }
74949 rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
74950 if( rc ) return rc;
74951 if( pPage->bBusy ){
 
 
74952 rc = SQLITE_CORRUPT_BKPT;
74953 goto cleardatabasepage_out;
74954 }
74955 pPage->bBusy = 1;
74956 hdr = pPage->hdrOffset;
74957 for(i=0; i<pPage->nCell; i++){
74958 pCell = findCell(pPage, i);
74959 if( !pPage->leaf ){
74960 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
@@ -74977,11 +75007,10 @@
74977 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
74978 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
74979 }
74980
74981 cleardatabasepage_out:
74982 pPage->bBusy = 0;
74983 releasePage(pPage);
74984 return rc;
74985 }
74986
74987 /*
@@ -75056,14 +75085,14 @@
75056 assert( iTable>=2 );
75057 if( iTable>btreePagecount(pBt) ){
75058 return SQLITE_CORRUPT_BKPT;
75059 }
75060
75061 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
75062 if( rc ) return rc;
75063 rc = sqlite3BtreeClearTable(p, iTable, 0);
75064 if( rc ){
 
 
75065 releasePage(pPage);
75066 return rc;
75067 }
75068
75069 *piMoved = 0;
@@ -78434,12 +78463,14 @@
78434 ExprList *pList = 0; /* Function arguments */
78435 int i; /* Iterator variable */
78436
78437 assert( pCtx!=0 );
78438 assert( (p->flags & EP_TokenOnly)==0 );
 
78439 pList = p->x.pList;
78440 if( pList ) nVal = pList->nExpr;
 
78441 pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
78442 assert( pFunc );
78443 if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
78444 || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
78445 ){
@@ -78539,11 +78570,13 @@
78539 ** check ensures that an EP_TokenOnly expression is never passed down
78540 ** into valueFromFunction(). */
78541 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
78542
78543 if( op==TK_CAST ){
78544 u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
 
 
78545 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
78546 testcase( rc!=SQLITE_OK );
78547 if( *ppVal ){
78548 sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
78549 sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
@@ -78612,10 +78645,11 @@
78612 sqlite3VdbeMemSetNull(pVal);
78613 }
78614 #ifndef SQLITE_OMIT_BLOB_LITERAL
78615 else if( op==TK_BLOB ){
78616 int nVal;
 
78617 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
78618 assert( pExpr->u.zToken[1]=='\'' );
78619 pVal = valueNew(db, pCtx);
78620 if( !pVal ) goto no_mem;
78621 zVal = &pExpr->u.zToken[2];
@@ -78629,10 +78663,11 @@
78629 else if( op==TK_FUNCTION && pCtx!=0 ){
78630 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
78631 }
78632 #endif
78633 else if( op==TK_TRUEFALSE ){
 
78634 pVal = valueNew(db, pCtx);
78635 if( pVal ){
78636 pVal->flags = MEM_Int;
78637 pVal->u.i = pExpr->u.zToken[4]==0;
78638 }
@@ -80501,10 +80536,11 @@
80501 */
80502 static void displayP4Expr(StrAccum *p, Expr *pExpr){
80503 const char *zOp = 0;
80504 switch( pExpr->op ){
80505 case TK_STRING:
 
80506 sqlite3_str_appendf(p, "%Q", pExpr->u.zToken);
80507 break;
80508 case TK_INTEGER:
80509 sqlite3_str_appendf(p, "%d", pExpr->u.iValue);
80510 break;
@@ -80847,12 +80883,12 @@
80847 ** with no indexes using a single prepared INSERT statement, bind()
80848 ** and reset(). Inserts are grouped into a transaction.
80849 */
80850 testcase( p->flags & MEM_Agg );
80851 testcase( p->flags & MEM_Dyn );
80852 testcase( p->xDel==sqlite3VdbeFrameMemDel );
80853 if( p->flags&(MEM_Agg|MEM_Dyn) ){
 
80854 sqlite3VdbeMemRelease(p);
80855 }else if( p->szMalloc ){
80856 sqlite3DbFreeNN(db, p->zMalloc);
80857 p->szMalloc = 0;
80858 }
@@ -84553,12 +84589,12 @@
84553 /**************************** sqlite3_result_ *******************************
84554 ** The following routines are used by user-defined functions to specify
84555 ** the function result.
84556 **
84557 ** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
84558 ** result as a string or blob but if the string or blob is too large, it
84559 ** then sets the error code to SQLITE_TOOBIG
84560 **
84561 ** The invokeValueDestructor(P,X) routine invokes destructor function X()
84562 ** on value P is not going to be used and need to be destroyed.
84563 */
84564 static void setResultStrOrError(
@@ -84566,12 +84602,20 @@
84566 const char *z, /* String pointer */
84567 int n, /* Bytes in string, or negative */
84568 u8 enc, /* Encoding of z. 0 for BLOBs */
84569 void (*xDel)(void*) /* Destructor function */
84570 ){
84571 if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){
84572 sqlite3_result_error_toobig(pCtx);
 
 
 
 
 
 
 
 
84573 }
84574 }
84575 static int invokeValueDestructor(
84576 const void *p, /* Value to destroy */
84577 void (*xDel)(void*), /* The destructor */
@@ -90536,11 +90580,11 @@
90536 assert( aMem[pOp->p3].flags & MEM_Null );
90537 aMem[pOp->p3].n = 0;
90538 aMem[pOp->p3].z = "";
90539 }
90540 pCx = p->apCsr[pOp->p1];
90541 if( pCx && !pCx->hasBeenDuped ){
90542 /* If the ephermeral table is already open and has no duplicates from
90543 ** OP_OpenDup, then erase all existing content so that the table is
90544 ** empty again, rather than creating a new table. */
90545 assert( pCx->isEphemeral );
90546 pCx->seqCount = 0;
@@ -95092,11 +95136,11 @@
95092 /* Check that the column is not part of an FK child key definition. It
95093 ** is not necessary to check if it is part of a parent key, as parent
95094 ** key columns must be indexed. The check below will pick up this
95095 ** case. */
95096 FKey *pFKey;
95097 assert( !IsVirtual(pTab) );
95098 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
95099 int j;
95100 for(j=0; j<pFKey->nCol; j++){
95101 if( pFKey->aCol[j].iFrom==iCol ){
95102 zFault = "foreign key";
@@ -99101,11 +99145,11 @@
99101 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
99102 if( pExpr->pRight ){
99103 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
99104 pExpr = pExpr->pRight;
99105 continue;
99106 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
99107 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
99108 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
99109 }else{
99110 if( pExpr->x.pList ){
99111 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
@@ -99373,10 +99417,11 @@
99373 sqlite3ExprDelete(db, pDup);
99374 pDup = 0;
99375 }else{
99376 incrAggFunctionDepth(pDup, nSubquery);
99377 if( pExpr->op==TK_COLLATE ){
 
99378 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
99379 }
99380
99381 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
99382 ** prevents ExprDelete() from deleting the Expr structure itself,
@@ -99476,10 +99521,11 @@
99476 SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){
99477 int n;
99478 Table *pExTab;
99479
99480 n = pExpr->iColumn;
 
99481 pExTab = pExpr->y.pTab;
99482 assert( pExTab!=0 );
99483 if( (pExTab->tabFlags & TF_HasGenerated)!=0
99484 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
99485 ){
@@ -99613,10 +99659,11 @@
99613 const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
99614 assert( zTabName!=0 );
99615 if( sqlite3StrICmp(zTabName, zTab)!=0 ){
99616 continue;
99617 }
 
99618 if( IN_RENAME_OBJECT && pItem->zAlias ){
99619 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
99620 }
99621 }
99622 hCol = sqlite3StrIHash(zCol);
@@ -99644,10 +99691,11 @@
99644 pMatch = pItem;
99645 }
99646 }
99647 if( pMatch ){
99648 pExpr->iTable = pMatch->iCursor;
 
99649 pExpr->y.pTab = pMatch->pTab;
99650 /* RIGHT JOIN not (yet) supported */
99651 assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
99652 if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
99653 ExprSetProperty(pExpr, EP_CanBeNull);
@@ -99717,10 +99765,11 @@
99717 cnt++;
99718 pMatch = 0;
99719 #ifndef SQLITE_OMIT_UPSERT
99720 if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
99721 testcase( iCol==(-1) );
 
99722 if( IN_RENAME_OBJECT ){
99723 pExpr->iColumn = iCol;
99724 pExpr->y.pTab = pTab;
99725 eNewExprOp = TK_COLUMN;
99726 }else{
@@ -99729,10 +99778,11 @@
99729 eNewExprOp = TK_REGISTER;
99730 }
99731 }else
99732 #endif /* SQLITE_OMIT_UPSERT */
99733 {
 
99734 pExpr->y.pTab = pTab;
99735 if( pParse->bReturning ){
99736 eNewExprOp = TK_REGISTER;
99737 pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
99738 sqlite3TableColumnToStorage(pTab, iCol) + 1;
@@ -99803,12 +99853,12 @@
99803 if( pEList->a[j].eEName==ENAME_NAME
99804 && sqlite3_stricmp(zAs, zCol)==0
99805 ){
99806 Expr *pOrig;
99807 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
99808 assert( pExpr->x.pList==0 );
99809 assert( pExpr->x.pSelect==0 );
99810 pOrig = pEList->a[j].pExpr;
99811 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
99812 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
99813 return WRC_Abort;
99814 }
@@ -99876,11 +99926,11 @@
99876 "double-quoted string literal: \"%w\"", zCol);
99877 #ifdef SQLITE_ENABLE_NORMALIZE
99878 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
99879 #endif
99880 pExpr->op = TK_STRING;
99881 pExpr->y.pTab = 0;
99882 return WRC_Prune;
99883 }
99884 if( sqlite3ExprIdToTrueFalse(pExpr) ){
99885 return WRC_Prune;
99886 }
@@ -99962,11 +100012,13 @@
99962 */
99963 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
99964 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
99965 if( p ){
99966 SrcItem *pItem = &pSrc->a[iSrc];
99967 Table *pTab = p->y.pTab = pItem->pTab;
 
 
99968 p->iTable = pItem->iCursor;
99969 if( p->y.pTab->iPKey==iCol ){
99970 p->iColumn = -1;
99971 }else{
99972 p->iColumn = (ynVar)iCol;
@@ -100029,10 +100081,11 @@
100029 ** value between 1.0 and 0.0.
100030 */
100031 static int exprProbability(Expr *p){
100032 double r = -1.0;
100033 if( p->op!=TK_FLOAT ) return -1;
 
100034 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
100035 assert( r>=0.0 );
100036 if( r>1.0 ) return -1;
100037 return (int)(r*134217728.0);
100038 }
@@ -100077,10 +100130,11 @@
100077 SrcList *pSrcList = pNC->pSrcList;
100078 SrcItem *pItem;
100079 assert( pSrcList && pSrcList->nSrc>=1 );
100080 pItem = pSrcList->a;
100081 pExpr->op = TK_COLUMN;
 
100082 pExpr->y.pTab = pItem->pTab;
100083 pExpr->iTable = pItem->iCursor;
100084 pExpr->iColumn--;
100085 pExpr->affExpr = SQLITE_AFF_INTEGER;
100086 break;
@@ -100109,10 +100163,11 @@
100109 anRef[i] = p->nRef;
100110 }
100111 sqlite3WalkExpr(pWalker, pExpr->pLeft);
100112 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
100113 testcase( ExprHasProperty(pExpr, EP_FromJoin) );
 
100114 if( pExpr->op==TK_NOTNULL ){
100115 pExpr->u.zToken = "true";
100116 ExprSetProperty(pExpr, EP_IsTrue);
100117 }else{
100118 pExpr->u.zToken = "false";
@@ -100144,10 +100199,11 @@
100144 Expr *pRight;
100145
100146 if( pExpr->op==TK_ID ){
100147 zDb = 0;
100148 zTable = 0;
 
100149 zColumn = pExpr->u.zToken;
100150 }else{
100151 Expr *pLeft = pExpr->pLeft;
100152 testcase( pNC->ncFlags & NC_IdxExpr );
100153 testcase( pNC->ncFlags & NC_GenCol );
@@ -100156,16 +100212,19 @@
100156 pRight = pExpr->pRight;
100157 if( pRight->op==TK_ID ){
100158 zDb = 0;
100159 }else{
100160 assert( pRight->op==TK_DOT );
 
100161 zDb = pLeft->u.zToken;
100162 pLeft = pRight->pLeft;
100163 pRight = pRight->pRight;
100164 }
 
100165 zTable = pLeft->u.zToken;
100166 zColumn = pRight->u.zToken;
 
100167 if( IN_RENAME_OBJECT ){
100168 sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
100169 sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
100170 }
100171 }
@@ -100186,11 +100245,11 @@
100186 u8 enc = ENC(pParse->db); /* The database encoding */
100187 int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
100188 #ifndef SQLITE_OMIT_WINDOWFUNC
100189 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
100190 #endif
100191 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
100192 zId = pExpr->u.zToken;
100193 nId = sqlite3Strlen30(zId);
100194 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
100195 if( pDef==0 ){
100196 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
@@ -100350,11 +100409,11 @@
100350 sqlite3WalkExprList(pWalker, pList);
100351 if( is_agg ){
100352 #ifndef SQLITE_OMIT_WINDOWFUNC
100353 if( pWin ){
100354 Select *pSel = pNC->pWinSelect;
100355 assert( pWin==pExpr->y.pWin );
100356 if( IN_RENAME_OBJECT==0 ){
100357 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
100358 if( pParse->db->mallocFailed ) break;
100359 }
100360 sqlite3WalkExprList(pWalker, pWin->pPartition);
@@ -100399,11 +100458,11 @@
100399 case TK_SELECT:
100400 case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
100401 #endif
100402 case TK_IN: {
100403 testcase( pExpr->op==TK_IN );
100404 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
100405 int nRef = pNC->nRef;
100406 testcase( pNC->ncFlags & NC_IsCheck );
100407 testcase( pNC->ncFlags & NC_PartIdx );
100408 testcase( pNC->ncFlags & NC_IdxExpr );
100409 testcase( pNC->ncFlags & NC_GenCol );
@@ -100456,10 +100515,11 @@
100456 int nLeft, nRight;
100457 if( pParse->db->mallocFailed ) break;
100458 assert( pExpr->pLeft!=0 );
100459 nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
100460 if( pExpr->op==TK_BETWEEN ){
 
100461 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
100462 if( nRight==nLeft ){
100463 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
100464 }
100465 }else{
@@ -100504,11 +100564,13 @@
100504 int i; /* Loop counter */
100505
100506 UNUSED_PARAMETER(pParse);
100507
100508 if( pE->op==TK_ID ){
100509 char *zCol = pE->u.zToken;
 
 
100510 for(i=0; i<pEList->nExpr; i++){
100511 if( pEList->a[i].eEName==ENAME_NAME
100512 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
100513 ){
100514 return i+1;
@@ -101369,15 +101431,18 @@
101369 pExpr = pExpr->pLeft;
101370 assert( pExpr!=0 );
101371 }
101372 op = pExpr->op;
101373 if( op==TK_REGISTER ) op = pExpr->op2;
101374 if( (op==TK_COLUMN || op==TK_AGG_COLUMN) && pExpr->y.pTab ){
101375 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
 
 
 
101376 }
101377 if( op==TK_SELECT ){
101378 assert( pExpr->flags&EP_xIsSelect );
101379 assert( pExpr->x.pSelect!=0 );
101380 assert( pExpr->x.pSelect->pEList!=0 );
101381 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
101382 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
101383 }
@@ -101386,18 +101451,19 @@
101386 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101387 return sqlite3AffinityType(pExpr->u.zToken, 0);
101388 }
101389 #endif
101390 if( op==TK_SELECT_COLUMN ){
101391 assert( pExpr->pLeft->flags&EP_xIsSelect );
101392 assert( pExpr->iColumn < pExpr->iTable );
101393 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
101394 return sqlite3ExprAffinity(
101395 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
101396 );
101397 }
101398 if( op==TK_VECTOR ){
 
101399 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
101400 }
101401 return pExpr->affExpr;
101402 }
101403
@@ -101453,11 +101519,11 @@
101453 ** expression.
101454 */
101455 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
101456 while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){
101457 if( ExprHasProperty(pExpr, EP_Unlikely) ){
101458 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
101459 assert( pExpr->x.pList->nExpr>0 );
101460 assert( pExpr->op==TK_FUNCTION );
101461 pExpr = pExpr->x.pList->a[0].pExpr;
101462 }else{
101463 assert( pExpr->op==TK_COLLATE );
@@ -101486,45 +101552,46 @@
101486 CollSeq *pColl = 0;
101487 const Expr *p = pExpr;
101488 while( p ){
101489 int op = p->op;
101490 if( op==TK_REGISTER ) op = p->op2;
101491 if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER)
101492 && p->y.pTab!=0
101493 ){
101494 /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101495 ** a TK_COLUMN but was previously evaluated and cached in a register */
101496 int j = p->iColumn;
101497 if( j>=0 ){
101498 const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101499 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101500 }
101501 break;
 
101502 }
101503 if( op==TK_CAST || op==TK_UPLUS ){
101504 p = p->pLeft;
101505 continue;
101506 }
101507 if( op==TK_VECTOR ){
 
101508 p = p->x.pList->a[0].pExpr;
101509 continue;
101510 }
101511 if( op==TK_COLLATE ){
 
101512 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
101513 break;
101514 }
101515 if( p->flags & EP_Collate ){
101516 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
101517 p = p->pLeft;
101518 }else{
101519 Expr *pNext = p->pRight;
101520 /* The Expr.x union is never used at the same time as Expr.pRight */
 
101521 assert( p->x.pList==0 || p->pRight==0 );
101522 if( p->x.pList!=0
101523 && !db->mallocFailed
101524 && ALWAYS(!ExprHasProperty(p, EP_xIsSelect))
101525 ){
101526 int i;
101527 for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
101528 if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
101529 pNext = p->x.pList->a[i].pExpr;
101530 break;
@@ -101603,11 +101670,11 @@
101603 pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
101604 assert( pExpr->pLeft );
101605 aff = sqlite3ExprAffinity(pExpr->pLeft);
101606 if( pExpr->pRight ){
101607 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
101608 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
101609 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
101610 }else if( aff==0 ){
101611 aff = SQLITE_AFF_BLOB;
101612 }
101613 return aff;
@@ -101743,12 +101810,14 @@
101743 */
101744 SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){
101745 u8 op = pExpr->op;
101746 if( op==TK_REGISTER ) op = pExpr->op2;
101747 if( op==TK_VECTOR ){
 
101748 return pExpr->x.pList->nExpr;
101749 }else if( op==TK_SELECT ){
 
101750 return pExpr->x.pSelect->pEList->nExpr;
101751 }else{
101752 return 1;
101753 }
101754 }
@@ -101771,12 +101840,14 @@
101771 SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
101772 assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR );
101773 if( sqlite3ExprIsVector(pVector) ){
101774 assert( pVector->op2==0 || pVector->op==TK_REGISTER );
101775 if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){
 
101776 return pVector->x.pSelect->pEList->a[i].pExpr;
101777 }else{
 
101778 return pVector->x.pList->a[i].pExpr;
101779 }
101780 }
101781 return pVector;
101782 }
@@ -101808,11 +101879,11 @@
101808 int iField, /* Which column of the vector to return */
101809 int nField /* Total number of columns in the vector */
101810 ){
101811 Expr *pRet;
101812 if( pVector->op==TK_SELECT ){
101813 assert( pVector->flags & EP_xIsSelect );
101814 /* The TK_SELECT_COLUMN Expr node:
101815 **
101816 ** pLeft: pVector containing TK_SELECT. Not deleted.
101817 ** pRight: not used. But recursively deleted.
101818 ** iColumn: Index of a column in pVector
@@ -101833,11 +101904,13 @@
101833 pRet->iColumn = iField;
101834 pRet->pLeft = pVector;
101835 }
101836 }else{
101837 if( pVector->op==TK_VECTOR ){
101838 Expr **ppVector = &pVector->x.pList->a[iField].pExpr;
 
 
101839 pVector = *ppVector;
101840 if( IN_RENAME_OBJECT ){
101841 /* This must be a vector UPDATE inside a trigger */
101842 *ppVector = 0;
101843 return pVector;
@@ -101897,14 +101970,16 @@
101897 if( op==TK_REGISTER ){
101898 *ppExpr = sqlite3VectorFieldSubexpr(pVector, iField);
101899 return pVector->iTable+iField;
101900 }
101901 if( op==TK_SELECT ){
 
101902 *ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr;
101903 return regSelect+iField;
101904 }
101905 if( op==TK_VECTOR ){
 
101906 *ppExpr = pVector->x.pList->a[iField].pExpr;
101907 return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree);
101908 }
101909 return 0;
101910 }
@@ -102075,11 +102150,11 @@
102075 */
102076 static void exprSetHeight(Expr *p){
102077 int nHeight = 0;
102078 heightOfExpr(p->pLeft, &nHeight);
102079 heightOfExpr(p->pRight, &nHeight);
102080 if( ExprHasProperty(p, EP_xIsSelect) ){
102081 heightOfSelect(p->x.pSelect, &nHeight);
102082 }else if( p->x.pList ){
102083 heightOfExprList(p->x.pList, &nHeight);
102084 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102085 }
@@ -102114,11 +102189,11 @@
102114 ** Propagate all EP_Propagate flags from the Expr.x.pList into
102115 ** Expr.flags.
102116 */
102117 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
102118 if( pParse->nErr ) return;
102119 if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
102120 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102121 }
102122 }
102123 #define exprSetHeight(y)
102124 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
@@ -102298,17 +102373,24 @@
102298 Select *pRet = 0;
102299 assert( nElem>1 );
102300 for(ii=0; ii<pEList->nExpr; ii++){
102301 Select *pSel;
102302 Expr *pExpr = pEList->a[ii].pExpr;
102303 int nExprElem = (pExpr->op==TK_VECTOR ? pExpr->x.pList->nExpr : 1);
 
 
 
 
 
 
102304 if( nExprElem!=nElem ){
102305 sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d",
102306 nExprElem, nExprElem>1?"s":"", nElem
102307 );
102308 break;
102309 }
 
102310 pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
102311 pExpr->x.pList = 0;
102312 if( pSel ){
102313 if( pRet ){
102314 pSel->op = TK_ALL;
@@ -102374,11 +102456,11 @@
102374 ){
102375 sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
102376 }
102377 pNew->x.pList = pList;
102378 ExprSetProperty(pNew, EP_HasFunc);
102379 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
102380 sqlite3ExprSetHeightAndFlags(pParse, pNew);
102381 if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
102382 return pNew;
102383 }
102384
@@ -102500,31 +102582,30 @@
102500 /*
102501 ** Recursively delete an expression tree.
102502 */
102503 static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
102504 assert( p!=0 );
102505 /* Sanity check: Assert that the IntValue is non-negative if it exists */
102506 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
102507
102508 assert( !ExprHasProperty(p, EP_WinFunc) || p->y.pWin!=0 || db->mallocFailed );
102509 assert( p->op!=TK_FUNCTION || ExprHasProperty(p, EP_TokenOnly|EP_Reduced)
102510 || p->y.pWin==0 || ExprHasProperty(p, EP_WinFunc) );
102511 #ifdef SQLITE_DEBUG
102512 if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){
102513 assert( p->pLeft==0 );
102514 assert( p->pRight==0 );
102515 assert( p->x.pSelect==0 );
 
102516 }
102517 #endif
102518 if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){
102519 /* The Expr.x union is never used at the same time as Expr.pRight */
102520 assert( p->x.pList==0 || p->pRight==0 );
102521 if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft);
102522 if( p->pRight ){
102523 assert( !ExprHasProperty(p, EP_WinFunc) );
102524 sqlite3ExprDeleteNN(db, p->pRight);
102525 }else if( ExprHasProperty(p, EP_xIsSelect) ){
102526 assert( !ExprHasProperty(p, EP_WinFunc) );
102527 sqlite3SelectDelete(db, p->x.pSelect);
102528 }else{
102529 sqlite3ExprListDelete(db, p->x.pList);
102530 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -102532,11 +102613,14 @@
102532 sqlite3WindowDelete(db, p->y.pWin);
102533 }
102534 #endif
102535 }
102536 }
102537 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
 
 
 
102538 if( !ExprHasProperty(p, EP_Static) ){
102539 sqlite3DbFreeNN(db, p);
102540 }
102541 }
102542 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
@@ -102748,11 +102832,11 @@
102748 memcpy(zToken, p->u.zToken, nToken);
102749 }
102750
102751 if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){
102752 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
102753 if( ExprHasProperty(p, EP_xIsSelect) ){
102754 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
102755 }else{
102756 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
102757 }
102758 }
@@ -103375,11 +103459,11 @@
103375 ** the conversion happened, and zero if the expression is unaltered.
103376 */
103377 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
103378 u32 v;
103379 assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
103380 if( !ExprHasProperty(pExpr, EP_Quoted)
103381 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
103382 ){
103383 pExpr->op = TK_TRUEFALSE;
103384 ExprSetProperty(pExpr, v);
103385 return 1;
@@ -103392,10 +103476,11 @@
103392 ** and 0 if it is FALSE.
103393 */
103394 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
103395 pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
103396 assert( pExpr->op==TK_TRUEFALSE );
 
103397 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
103398 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
103399 return pExpr->u.zToken[4]==0;
103400 }
103401
@@ -103596,11 +103681,11 @@
103596 }
103597 }
103598 }
103599
103600 /* Check if pExpr is a sub-select. If so, consider it variable. */
103601 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
103602 pWalker->eCode = 0;
103603 return WRC_Abort;
103604 }
103605
103606 return exprNodeIsConstant(pWalker, pExpr);
@@ -103746,10 +103831,11 @@
103746 case TK_STRING:
103747 case TK_FLOAT:
103748 case TK_BLOB:
103749 return 0;
103750 case TK_COLUMN:
 
103751 return ExprHasProperty(p, EP_CanBeNull) ||
103752 p->y.pTab==0 || /* Reference to column of index on expression */
103753 (p->iColumn>=0
103754 && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
103755 && p->y.pTab->aCol[p->iColumn].notNull==0);
@@ -103823,11 +103909,11 @@
103823 Select *p;
103824 SrcList *pSrc;
103825 ExprList *pEList;
103826 Table *pTab;
103827 int i;
103828 if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */
103829 if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
103830 p = pX->x.pSelect;
103831 if( p->pPrior ) return 0; /* Not a compound SELECT */
103832 if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
103833 testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -103994,11 +104080,11 @@
103994 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
103995 ** whether or not the SELECT result contains NULL values, check whether
103996 ** or not NULL is actually possible (it may not be, for example, due
103997 ** to NOT NULL constraints in the schema). If no NULL values are possible,
103998 ** set prRhsHasNull to 0 before continuing. */
103999 if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){
104000 int i;
104001 ExprList *pEList = pX->x.pSelect->pEList;
104002 for(i=0; i<pEList->nExpr; i++){
104003 if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break;
104004 }
@@ -104150,11 +104236,11 @@
104150 ** then it is not worth creating an ephemeral table to evaluate
104151 ** the IN operator so return IN_INDEX_NOOP.
104152 */
104153 if( eType==0
104154 && (inFlags & IN_INDEX_NOOP_OK)
104155 && !ExprHasProperty(pX, EP_xIsSelect)
104156 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
104157 ){
104158 eType = IN_INDEX_NOOP;
104159 }
104160
@@ -104198,11 +104284,11 @@
104198 ** string is eventually freed using sqlite3DbFree().
104199 */
104200 static char *exprINAffinity(Parse *pParse, const Expr *pExpr){
104201 Expr *pLeft = pExpr->pLeft;
104202 int nVal = sqlite3ExprVectorSize(pLeft);
104203 Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0;
104204 char *zRet;
104205
104206 assert( pExpr->op==TK_IN );
104207 zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
104208 if( zRet ){
@@ -104248,11 +104334,11 @@
104248 **
104249 ** "row value misused"
104250 */
104251 SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
104252 #ifndef SQLITE_OMIT_SUBQUERY
104253 if( pExpr->flags & EP_xIsSelect ){
104254 sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
104255 }else
104256 #endif
104257 {
104258 sqlite3ErrorMsg(pParse, "row value misused");
@@ -104312,22 +104398,24 @@
104312 /* If this routine has already been coded, but the previous code
104313 ** might not have been invoked yet, so invoke it now as a subroutine.
104314 */
104315 if( ExprHasProperty(pExpr, EP_Subrtn) ){
104316 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
104317 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104318 ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
104319 pExpr->x.pSelect->selId));
104320 }
 
104321 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104322 pExpr->y.sub.iAddr);
104323 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
104324 sqlite3VdbeJumpHere(v, addrOnce);
104325 return;
104326 }
104327
104328 /* Begin coding the subroutine */
 
104329 ExprSetProperty(pExpr, EP_Subrtn);
104330 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
104331 pExpr->y.sub.regReturn = ++pParse->nMem;
104332 pExpr->y.sub.iAddr =
104333 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
@@ -104344,19 +104432,19 @@
104344 ** RHS of the IN operator.
104345 */
104346 pExpr->iTable = iTab;
104347 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
104348 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
104349 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104350 VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
104351 }else{
104352 VdbeComment((v, "RHS of IN operator"));
104353 }
104354 #endif
104355 pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
104356
104357 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104358 /* Case 1: expr IN (SELECT ...)
104359 **
104360 ** Generate code to write the results of the select into the temporary
104361 ** table allocated and opened above.
104362 */
@@ -104450,10 +104538,11 @@
104450 sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
104451 }
104452 if( addrOnce ){
104453 sqlite3VdbeJumpHere(v, addrOnce);
104454 /* Subroutine return */
 
104455 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104456 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104457 sqlite3ClearTempRegCache(pParse);
104458 }
104459 }
@@ -104486,23 +104575,26 @@
104486 assert( v!=0 );
104487 if( pParse->nErr ) return 0;
104488 testcase( pExpr->op==TK_EXISTS );
104489 testcase( pExpr->op==TK_SELECT );
104490 assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
104491 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
104492 pSel = pExpr->x.pSelect;
104493
104494 /* If this routine has already been coded, then invoke it as a
104495 ** subroutine. */
104496 if( ExprHasProperty(pExpr, EP_Subrtn) ){
104497 ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
 
104498 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104499 pExpr->y.sub.iAddr);
104500 return pExpr->iTable;
104501 }
104502
104503 /* Begin coding the subroutine */
 
 
104504 ExprSetProperty(pExpr, EP_Subrtn);
104505 pExpr->y.sub.regReturn = ++pParse->nMem;
104506 pExpr->y.sub.iAddr =
104507 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
104508 VdbeComment((v, "return address"));
@@ -104578,10 +104670,11 @@
104578 if( addrOnce ){
104579 sqlite3VdbeJumpHere(v, addrOnce);
104580 }
104581
104582 /* Subroutine return */
 
104583 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104584 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104585 sqlite3ClearTempRegCache(pParse);
104586 return rReg;
104587 }
@@ -104594,11 +104687,11 @@
104594 ** columns as the vector on the LHS. Or, if the RHS of the IN() is not
104595 ** a sub-query, that the LHS is a vector of size 1.
104596 */
104597 SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
104598 int nVector = sqlite3ExprVectorSize(pIn->pLeft);
104599 if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){
104600 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
104601 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
104602 return 1;
104603 }
104604 }else if( nVector!=1 ){
@@ -104728,17 +104821,19 @@
104728 ** sequence of comparisons.
104729 **
104730 ** This is step (1) in the in-operator.md optimized algorithm.
104731 */
104732 if( eType==IN_INDEX_NOOP ){
104733 ExprList *pList = pExpr->x.pList;
104734 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
104735 int labelOk = sqlite3VdbeMakeLabel(pParse);
104736 int r2, regToFree;
104737 int regCkNull = 0;
104738 int ii;
104739 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
 
 
104740 if( destIfNull!=destIfFalse ){
104741 regCkNull = sqlite3GetTempReg(pParse);
104742 sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
104743 }
104744 for(ii=0; ii<pList->nExpr; ii++){
@@ -105120,10 +105215,11 @@
105120 #endif
105121 }else{
105122 int i;
105123 iResult = pParse->nMem+1;
105124 pParse->nMem += nResult;
 
105125 for(i=0; i<nResult; i++){
105126 sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
105127 }
105128 }
105129 }
@@ -105318,10 +105414,11 @@
105318 ** datatype by applying the Affinity of the table column to the
105319 ** constant.
105320 */
105321 int aff;
105322 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
 
105323 if( pExpr->y.pTab ){
105324 aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105325 }else{
105326 aff = pExpr->affExpr;
105327 }
@@ -105341,13 +105438,15 @@
105341 ** The row is unpacked into registers beginning at
105342 ** 0-(pParse->iSelfTab). The rowid (if any) is in a register
105343 ** immediately prior to the first column.
105344 */
105345 Column *pCol;
105346 Table *pTab = pExpr->y.pTab;
105347 int iSrc;
105348 int iCol = pExpr->iColumn;
 
 
105349 assert( pTab!=0 );
105350 assert( iCol>=XN_ROWID );
105351 assert( iCol<pTab->nCol );
105352 if( iCol<0 ){
105353 return -1-pParse->iSelfTab;
@@ -105381,10 +105480,11 @@
105381 /* Coding an expression that is part of an index where column names
105382 ** in the index refer to the table to which the index belongs */
105383 iTab = pParse->iSelfTab - 1;
105384 }
105385 }
 
105386 iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
105387 pExpr->iColumn, iTab, target,
105388 pExpr->op2);
105389 if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
105390 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
@@ -105458,10 +105558,11 @@
105458 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
105459 if( inReg!=target ){
105460 sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
105461 inReg = target;
105462 }
 
105463 sqlite3VdbeAddOp2(v, OP_Cast, target,
105464 sqlite3AffinityType(pExpr->u.zToken, 0));
105465 return inReg;
105466 }
105467 #endif /* SQLITE_OMIT_CAST */
@@ -105625,12 +105726,12 @@
105625 if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
105626 /* SQL functions can be expensive. So try to avoid running them
105627 ** multiple times if we know they always give the same result */
105628 return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
105629 }
105630 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
105631 assert( !ExprHasProperty(pExpr, EP_TokenOnly) );
 
105632 pFarg = pExpr->x.pList;
105633 nFarg = pFarg ? pFarg->nExpr : 0;
105634 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105635 zId = pExpr->u.zToken;
105636 pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
@@ -105745,11 +105846,14 @@
105745 int nCol;
105746 testcase( op==TK_EXISTS );
105747 testcase( op==TK_SELECT );
105748 if( pParse->db->mallocFailed ){
105749 return 0;
105750 }else if( op==TK_SELECT && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 ){
 
 
 
105751 sqlite3SubselectError(pParse, nCol, 1);
105752 }else{
105753 return sqlite3CodeSubselect(pParse, pExpr);
105754 }
105755 break;
@@ -105827,13 +105931,18 @@
105827 **
105828 ** p1==0 -> old.rowid p1==3 -> new.rowid
105829 ** p1==1 -> old.a p1==4 -> new.a
105830 ** p1==2 -> old.b p1==5 -> new.b
105831 */
105832 Table *pTab = pExpr->y.pTab;
105833 int iCol = pExpr->iColumn;
105834 int p1 = pExpr->iTable * (pTab->nCol+1) + 1
 
 
 
 
 
105835 + sqlite3TableColumnToStorage(pTab, iCol);
105836
105837 assert( pExpr->iTable==0 || pExpr->iTable==1 );
105838 assert( iCol>=-1 && iCol<pTab->nCol );
105839 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
@@ -105917,11 +106026,11 @@
105917 Expr *pX; /* The X expression */
105918 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
105919 Expr *pDel = 0;
105920 sqlite3 *db = pParse->db;
105921
105922 assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
105923 assert(pExpr->x.pList->nExpr > 0);
105924 pEList = pExpr->x.pList;
105925 aListelem = pEList->a;
105926 nExpr = pEList->nExpr;
105927 endLabel = sqlite3VdbeMakeLabel(pParse);
@@ -106262,11 +106371,11 @@
106262
106263 memset(&compLeft, 0, sizeof(Expr));
106264 memset(&compRight, 0, sizeof(Expr));
106265 memset(&exprAnd, 0, sizeof(Expr));
106266
106267 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
106268 pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
106269 if( db->mallocFailed==0 ){
106270 exprAnd.op = TK_AND;
106271 exprAnd.pLeft = &compLeft;
106272 exprAnd.pRight = &compRight;
@@ -106737,11 +106846,16 @@
106737 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
106738 return 1;
106739 }
106740 return 2;
106741 }
106742 if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){
 
 
 
 
 
106743 if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){
106744 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
106745 #ifndef SQLITE_OMIT_WINDOWFUNC
106746 assert( pA->op==pB->op );
106747 if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){
@@ -106844,16 +106958,17 @@
106844 return pNN->op!=TK_NULL;
106845 }
106846 switch( p->op ){
106847 case TK_IN: {
106848 if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
106849 assert( ExprHasProperty(p,EP_xIsSelect)
106850 || (p->x.pList!=0 && p->x.pList->nExpr>0) );
106851 return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
106852 }
106853 case TK_BETWEEN: {
106854 ExprList *pList = p->x.pList;
 
 
106855 assert( pList!=0 );
106856 assert( pList->nExpr==2 );
106857 if( seenNot ) return 0;
106858 if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
106859 || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1)
@@ -107026,14 +107141,18 @@
107026 testcase( pExpr->op==TK_LE );
107027 testcase( pExpr->op==TK_GT );
107028 testcase( pExpr->op==TK_GE );
107029 /* The y.pTab=0 assignment in wherecode.c always happens after the
107030 ** impliesNotNullRow() test */
107031 if( (pLeft->op==TK_COLUMN && pLeft->y.pTab!=0
107032 && IsVirtual(pLeft->y.pTab))
107033 || (pRight->op==TK_COLUMN && pRight->y.pTab!=0
107034 && IsVirtual(pRight->y.pTab))
 
 
 
 
107035 ){
107036 return WRC_Prune;
107037 }
107038 /* no break */ deliberate_fall_through
107039 }
@@ -107213,10 +107332,11 @@
107213 w.u.pSrcCount = &cnt;
107214 cnt.pSrc = pSrcList;
107215 cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
107216 cnt.nThis = 0;
107217 cnt.nOther = 0;
 
107218 sqlite3WalkExprList(&w, pExpr->x.pList);
107219 #ifndef SQLITE_OMIT_WINDOWFUNC
107220 if( ExprHasProperty(pExpr, EP_WinFunc) ){
107221 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
107222 }
@@ -107354,10 +107474,11 @@
107354 }
107355 if( (k>=pAggInfo->nColumn)
107356 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
107357 ){
107358 pCol = &pAggInfo->aCol[k];
 
107359 pCol->pTab = pExpr->y.pTab;
107360 pCol->iTable = pExpr->iTable;
107361 pCol->iColumn = pExpr->iColumn;
107362 pCol->iMem = ++pParse->nMem;
107363 pCol->iSorterColumn = -1;
@@ -107417,11 +107538,11 @@
107417 if( i>=0 ){
107418 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
107419 pItem = &pAggInfo->aFunc[i];
107420 pItem->pFExpr = pExpr;
107421 pItem->iMem = ++pParse->nMem;
107422 assert( !ExprHasProperty(pExpr, EP_IntValue) );
107423 pItem->pFunc = sqlite3FindFunction(pParse->db,
107424 pExpr->u.zToken,
107425 pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
107426 if( pExpr->flags & EP_Distinct ){
107427 pItem->iDistinct = pParse->nTab++;
@@ -107939,10 +108060,11 @@
107939 */
107940 assert( pDflt==0 || pDflt->op==TK_SPAN );
107941 if( pDflt && pDflt->pLeft->op==TK_NULL ){
107942 pDflt = 0;
107943 }
 
107944 if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
107945 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
107946 "Cannot add a REFERENCES column with non-NULL default value");
107947 }
107948 if( pCol->notNull && !pDflt ){
@@ -107981,11 +108103,12 @@
107981 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
107982 *zEnd-- = '\0';
107983 }
107984 /* substr() operations on characters, but addColOffset is in bytes. So we
107985 ** have to use printf() to translate between these units: */
107986 assert( !IsVirtual(pTab) );
 
107987 sqlite3NestedParse(pParse,
107988 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
107989 "sql = printf('%%.%ds, ',sql) || %Q"
107990 " || substr(sql,1+length(printf('%%.%ds',sql))) "
107991 "WHERE type = 'table' AND name = %Q",
@@ -108075,10 +108198,11 @@
108075 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
108076 goto exit_begin_add_column;
108077 }
108078
108079 sqlite3MayAbort(pParse);
 
108080 assert( pTab->u.tab.addColOffset>0 );
108081 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108082
108083 /* Put a copy of the Table struct in Parse.pNewTable for the
108084 ** sqlite3AddColumn() function and friends to modify. But modify
@@ -108105,11 +108229,11 @@
108105 for(i=0; i<pNew->nCol; i++){
108106 Column *pCol = &pNew->aCol[i];
108107 pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
108108 pCol->hName = sqlite3StrIHash(pCol->zCnName);
108109 }
108110 assert( !IsVirtual(pNew) );
108111 pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
108112 pNew->pSchema = db->aDb[iDb].pSchema;
108113 pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
108114 pNew->nTabRef = 1;
108115
@@ -108374,11 +108498,13 @@
108374 ** Walker callback used by sqlite3RenameExprUnmap().
108375 */
108376 static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
108377 Parse *pParse = pWalker->pParse;
108378 sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
108379 sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
 
 
108380 return WRC_Continue;
108381 }
108382
108383 /*
108384 ** Iterate through the Select objects that are part of WITH clauses attached
@@ -108436,11 +108562,13 @@
108436 */
108437 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
108438 Parse *pParse = pWalker->pParse;
108439 int i;
108440 if( pParse->nErr ) return WRC_Abort;
108441 if( NEVER(p->selFlags & (SF_View|SF_CopyCte)) ){
 
 
108442 return WRC_Prune;
108443 }
108444 if( ALWAYS(p->pEList) ){
108445 ExprList *pList = p->pEList;
108446 for(i=0; i<pList->nExpr; i++){
@@ -108573,10 +108701,11 @@
108573 && pWalker->pParse->pTriggerTab==p->pTab
108574 ){
108575 renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108576 }else if( pExpr->op==TK_COLUMN
108577 && pExpr->iColumn==p->iCol
 
108578 && p->pTab==pExpr->y.pTab
108579 ){
108580 renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108581 }
108582 return WRC_Continue;
@@ -109103,11 +109232,11 @@
109103 sqlite3WalkExpr(&sWalker, pExpr);
109104 }
109105 #endif
109106 }
109107
109108 assert( !IsVirtual(sParse.pNewTable) );
109109 for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109110 for(i=0; i<pFKey->nCol; i++){
109111 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
109112 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
109113 }
@@ -109175,11 +109304,14 @@
109175 /*
109176 ** Walker expression callback used by "RENAME TABLE".
109177 */
109178 static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
109179 RenameCtx *p = pWalker->u.pRename;
109180 if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){
 
 
 
109181 renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab);
109182 }
109183 return WRC_Continue;
109184 }
109185
@@ -109293,11 +109425,11 @@
109293 #ifndef SQLITE_OMIT_FOREIGN_KEY
109294 if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
109295 && !IsVirtual(pTab)
109296 ){
109297 FKey *pFKey;
109298 assert( !IsVirtual(pTab) );
109299 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109300 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109301 renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109302 }
109303 }
@@ -109614,11 +109746,11 @@
109614 if( iCol<pTab->nCol-1 ){
109615 RenameToken *pEnd;
109616 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
109617 zEnd = (const char*)pEnd->t.z;
109618 }else{
109619 assert( !IsVirtual(pTab) );
109620 zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
109621 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109622 }
109623
109624 zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
@@ -110789,11 +110921,11 @@
110789 pParse->nMem = MAX(pParse->nMem, iMem);
110790 v = sqlite3GetVdbe(pParse);
110791 if( v==0 || NEVER(pTab==0) ){
110792 return;
110793 }
110794 if( pTab->tnum==0 ){
110795 /* Do not gather statistics on views or virtual tables */
110796 return;
110797 }
110798 if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
110799 /* Do not gather statistics on system tables */
@@ -112083,10 +112215,11 @@
112083
112084 #ifndef SQLITE_OMIT_AUTHORIZATION
112085 if( pAuthArg ){
112086 char *zAuthArg;
112087 if( pAuthArg->op==TK_STRING ){
 
112088 zAuthArg = pAuthArg->u.zToken;
112089 }else{
112090 zAuthArg = 0;
112091 }
112092 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
@@ -112767,21 +112900,25 @@
112767 Returning *pReturning = pParse->u1.pReturning;
112768 int addrRewind;
112769 int i;
112770 int reg;
112771
112772 addrRewind =
112773 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
112774 VdbeCoverage(v);
112775 reg = pReturning->iRetReg;
112776 for(i=0; i<pReturning->nRetCol; i++){
112777 sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i);
112778 }
112779 sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i);
112780 sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1);
112781 VdbeCoverage(v);
112782 sqlite3VdbeJumpHere(v, addrRewind);
 
 
 
 
112783 }
112784 sqlite3VdbeAddOp0(v, OP_Halt);
112785
112786 #if SQLITE_USER_AUTHENTICATION
112787 if( pParse->nTableLock>0 && db->init.busy==0 ){
@@ -112858,11 +112995,15 @@
112858 }
112859 }
112860
112861 if( pParse->bReturning ){
112862 Returning *pRet = pParse->u1.pReturning;
112863 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
 
 
 
 
112864 }
112865
112866 /* Finally, jump back to the beginning of the executable code. */
112867 sqlite3VdbeGoto(v, 1);
112868 }
@@ -113280,11 +113421,11 @@
113280 Table *pTab, /* The table containing the column */
113281 Column *pCol, /* The column to receive the new DEFAULT expression */
113282 Expr *pExpr /* The new default expression */
113283 ){
113284 ExprList *pList;
113285 assert( !IsVirtual(pTab) );
113286 pList = pTab->u.tab.pDfltList;
113287 if( pCol->iDflt==0
113288 || NEVER(pList==0)
113289 || NEVER(pList->nExpr<pCol->iDflt)
113290 ){
@@ -113301,11 +113442,11 @@
113301 ** the DEFAULT clause or the AS clause of a generated column.
113302 ** Return NULL if the column has no associated expression.
113303 */
113304 SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){
113305 if( pCol->iDflt==0 ) return 0;
113306 if( NEVER(IsVirtual(pTab)) ) return 0;
113307 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
113308 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
113309 return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
113310 }
113311
@@ -113360,17 +113501,17 @@
113360 for(i=0; i<pTable->nCol; i++, pCol++){
113361 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
113362 sqlite3DbFree(db, pCol->zCnName);
113363 }
113364 sqlite3DbFree(db, pTable->aCol);
113365 if( !IsVirtual(pTable) ){
113366 sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
113367 }
113368 if( db==0 || db->pnBytesFreed==0 ){
113369 pTable->aCol = 0;
113370 pTable->nCol = 0;
113371 if( !IsVirtual(pTable) ){
113372 pTable->u.tab.pDfltList = 0;
113373 }
113374 }
113375 }
113376 }
@@ -114433,11 +114574,13 @@
114433 for(i=0; i<nTerm; i++){
114434 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
114435 assert( pCExpr!=0 );
114436 sqlite3StringToId(pCExpr);
114437 if( pCExpr->op==TK_ID ){
114438 const char *zCName = pCExpr->u.zToken;
 
 
114439 for(iCol=0; iCol<pTab->nCol; iCol++){
114440 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
114441 pCol = &pTab->aCol[iCol];
114442 makeColumnPartOfPrimaryKey(pParse, pCol);
114443 break;
@@ -114805,11 +114948,10 @@
114805 ** This is used to determine if the column number x appears in any of the
114806 ** first nCol entries of an index.
114807 */
114808 static int hasColumn(const i16 *aiCol, int nCol, int x){
114809 while( nCol-- > 0 ){
114810 assert( aiCol[0]>=0 );
114811 if( x==*(aiCol++) ){
114812 return 1;
114813 }
114814 }
114815 return 0;
@@ -115181,11 +115323,11 @@
115181 **
115182 ** If the root page number is 1, that means this is the sqlite_schema
115183 ** table itself. So mark it read-only.
115184 */
115185 if( db->init.busy ){
115186 if( pSelect ){
115187 sqlite3ErrorMsg(pParse, "");
115188 return;
115189 }
115190 p->tnum = db->init.newTnum;
115191 if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
@@ -116146,10 +116288,11 @@
116146 pFKey = sqlite3DbMallocZero(db, nByte );
116147 if( pFKey==0 ){
116148 goto fk_end;
116149 }
116150 pFKey->pFrom = p;
 
116151 pFKey->pNextFrom = p->u.tab.pFKey;
116152 z = (char*)&pFKey->aCol[nCol];
116153 pFKey->zTo = z;
116154 if( IN_RENAME_OBJECT ){
116155 sqlite3RenameTokenMap(pParse, (void*)z, pTo);
@@ -116211,11 +116354,11 @@
116211 pNextTo->pPrevTo = pFKey;
116212 }
116213
116214 /* Link the foreign key to the table as the last step.
116215 */
116216 assert( !IsVirtual(p) );
116217 p->u.tab.pFKey = pFKey;
116218 pFKey = 0;
116219
116220 fk_end:
116221 sqlite3DbFree(db, pFKey);
@@ -116234,11 +116377,11 @@
116234 SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
116235 #ifndef SQLITE_OMIT_FOREIGN_KEY
116236 Table *pTab;
116237 FKey *pFKey;
116238 if( (pTab = pParse->pNewTable)==0 ) return;
116239 if( NEVER(IsVirtual(pTab)) ) return;
116240 if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
116241 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
116242 pFKey->isDeferred = (u8)isDeferred;
116243 #endif
116244 }
@@ -116636,10 +116779,11 @@
116636 */
116637 for(i=0; i<pList->nExpr; i++){
116638 Expr *pExpr = pList->a[i].pExpr;
116639 assert( pExpr!=0 );
116640 if( pExpr->op==TK_COLLATE ){
 
116641 nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
116642 }
116643 }
116644
116645 /*
@@ -116731,10 +116875,11 @@
116731 pIndex->aiColumn[i] = (i16)j;
116732 }
116733 zColl = 0;
116734 if( pListItem->pExpr->op==TK_COLLATE ){
116735 int nColl;
 
116736 zColl = pListItem->pExpr->u.zToken;
116737 nColl = sqlite3Strlen30(zColl) + 1;
116738 assert( nExtra>=nColl );
116739 memcpy(zExtra, zColl, nColl);
116740 zColl = zExtra;
@@ -117519,10 +117664,11 @@
117519 ** construct "indexed_opt" for details. */
117520 pItem->fg.notIndexed = 1;
117521 }else{
117522 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
117523 pItem->fg.isIndexedBy = 1;
 
117524 }
117525 }
117526 }
117527
117528 /*
@@ -118499,10 +118645,11 @@
118499 int h, /* Hash of the name */
118500 const char *zFunc /* Name of function */
118501 ){
118502 FuncDef *p;
118503 for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){
 
118504 if( sqlite3StrICmp(p->zName, zFunc)==0 ){
118505 return p;
118506 }
118507 }
118508 return 0;
@@ -118520,10 +118667,11 @@
118520 FuncDef *pOther;
118521 const char *zName = aDef[i].zName;
118522 int nName = sqlite3Strlen30(zName);
118523 int h = SQLITE_FUNC_HASH(zName[0], nName);
118524 assert( zName[0]>='a' && zName[0]<='z' );
 
118525 pOther = sqlite3FunctionSearch(h, zName);
118526 if( pOther ){
118527 assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] );
118528 aDef[i].pNext = pOther->pNext;
118529 pOther->pNext = &aDef[i];
@@ -118911,10 +119059,11 @@
118911 ** and the SELECT subtree. */
118912 pSrc->a[0].pTab = 0;
118913 pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
118914 pSrc->a[0].pTab = pTab;
118915 if( pSrc->a[0].fg.isIndexedBy ){
 
118916 pSrc->a[0].u2.pIBIndex = 0;
118917 pSrc->a[0].fg.isIndexedBy = 0;
118918 sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
118919 }else if( pSrc->a[0].fg.isCte ){
118920 pSrc->a[0].u2.pCteUse->nUse++;
@@ -121495,11 +121644,15 @@
121495 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
121496 pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
121497 /* pGCC is always non-NULL since groupConcatStep() will have always
121498 ** run frist to initialize it */
121499 if( ALWAYS(pGCC) ){
121500 int nVS = sqlite3_value_bytes(argv[0]);
 
 
 
 
121501 pGCC->nAccum -= 1;
121502 if( pGCC->pnSepLengths!=0 ){
121503 assert(pGCC->nAccum >= 0);
121504 if( pGCC->nAccum>0 ){
121505 nVS += *pGCC->pnSepLengths;
@@ -121610,15 +121763,16 @@
121610 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
121611 FuncDef *pDef;
121612 int nExpr;
121613 assert( pExpr!=0 );
121614 assert( pExpr->op==TK_FUNCTION );
 
121615 if( !pExpr->x.pList ){
121616 return 0;
121617 }
121618 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
121619 nExpr = pExpr->x.pList->nExpr;
 
121620 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
121621 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
121622 if( pDef==0 ) return 0;
121623 #endif
121624 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
@@ -121638,10 +121792,11 @@
121638 aWc[3] = 0;
121639 }else{
121640 Expr *pEscape = pExpr->x.pList->a[2].pExpr;
121641 char *zEscape;
121642 if( pEscape->op!=TK_STRING ) return 0;
 
121643 zEscape = pEscape->u.zToken;
121644 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
121645 if( zEscape[0]==aWc[0] ) return 0;
121646 if( zEscape[0]==aWc[1] ) return 0;
121647 aWc[3] = zEscape[0];
@@ -122019,10 +122174,11 @@
122019 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
122020 printf("FUNC-HASH %02d:", i);
122021 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){
122022 int n = sqlite3Strlen30(p->zName);
122023 int h = p->zName[0] + n;
 
122024 printf(" %s(%d)", p->zName, h);
122025 }
122026 printf("\n");
122027 }
122028 }
@@ -122541,10 +122697,11 @@
122541 int iCursor, /* The open cursor on the table */
122542 i16 iCol /* The column that is wanted */
122543 ){
122544 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
122545 if( pExpr ){
 
122546 pExpr->y.pTab = pTab;
122547 pExpr->iTable = iCursor;
122548 pExpr->iColumn = iCol;
122549 }
122550 return pExpr;
@@ -122751,17 +122908,16 @@
122751 ** the table from the database. Triggers are disabled while running this
122752 ** DELETE, but foreign key actions are not.
122753 */
122754 SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
122755 sqlite3 *db = pParse->db;
122756 if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
122757 int iSkip = 0;
122758 Vdbe *v = sqlite3GetVdbe(pParse);
122759
122760 assert( v ); /* VDBE has already been allocated */
122761 assert( !IsView(pTab) ); /* Not a view */
122762 assert( !IsVirtual(pTab) );
122763 if( sqlite3FkReferences(pTab)==0 ){
122764 /* Search for a deferred foreign key constraint for which this table
122765 ** is the child table. If one cannot be found, return without
122766 ** generating any VDBE code. If one can be found, then jump over
122767 ** the entire DELETE if there are no outstanding deferred constraints
@@ -122921,17 +123077,17 @@
122921 /* Exactly one of regOld and regNew should be non-zero. */
122922 assert( (regOld==0)!=(regNew==0) );
122923
122924 /* If foreign-keys are disabled, this function is a no-op. */
122925 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
 
122926
122927 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122928 zDb = db->aDb[iDb].zDbSName;
122929
122930 /* Loop through all the foreign key constraints for which pTab is the
122931 ** child table (the table that the foreign key definition is part of). */
122932 assert( !IsVirtual(pTab) );
122933 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
122934 Table *pTo; /* Parent table of foreign key pFKey */
122935 Index *pIdx = 0; /* Index on key columns in pTo */
122936 int *aiFree = 0;
122937 int *aiCol;
@@ -123110,14 +123266,13 @@
123110 SQLITE_PRIVATE u32 sqlite3FkOldmask(
123111 Parse *pParse, /* Parse context */
123112 Table *pTab /* Table being modified */
123113 ){
123114 u32 mask = 0;
123115 if( pParse->db->flags&SQLITE_ForeignKeys ){
123116 FKey *p;
123117 int i;
123118 assert( !IsVirtual(pTab) );
123119 for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
123120 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
123121 }
123122 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
123123 Index *pIdx = 0;
@@ -123164,11 +123319,11 @@
123164 int *aChange, /* Non-NULL for UPDATE operations */
123165 int chngRowid /* True for UPDATE that affects rowid */
123166 ){
123167 int eRet = 1; /* Value to return if bHaveFK is true */
123168 int bHaveFK = 0; /* If FK processing is required */
123169 if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){
123170 if( !aChange ){
123171 /* A DELETE operation. Foreign key processing is required if the
123172 ** table in question is either the child or parent table for any
123173 ** foreign key constraint. */
123174 bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
@@ -123452,11 +123607,11 @@
123452 */
123453 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123454 FKey *pFKey; /* Iterator variable */
123455 FKey *pNext; /* Copy of pFKey->pNextFrom */
123456
123457 assert( !IsVirtual(pTab) );
123458 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
123459 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123460
123461 /* Remove the FK from the fkeyHash hash table. */
123462 if( !db || db->pnBytesFreed==0 ){
@@ -125711,10 +125866,11 @@
125711 ** (5) No FK constraint counters need to be updated if a conflict occurs.
125712 **
125713 ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
125714 ** must be explicitly deleted in order to ensure any pre-update hook
125715 ** is invoked. */
 
125716 #ifndef SQLITE_ENABLE_PREUPDATE_HOOK
125717 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
125718 && pPk==pIdx /* Condition 2 */
125719 && onError==OE_Replace /* Condition 1 */
125720 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
@@ -126391,11 +126547,13 @@
126391 /* Default values for second and subsequent columns need to match. */
126392 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126393 Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
126394 Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
126395 assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
 
126396 assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
 
126397 if( (pDestExpr==0)!=(pSrcExpr==0)
126398 || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
126399 pSrcExpr->u.zToken)!=0)
126400 ){
126401 return 0; /* Default values must be the same for all columns */
@@ -126431,10 +126589,11 @@
126431 ** But the main beneficiary of the transfer optimization is the VACUUM
126432 ** command, and the VACUUM command disables foreign key constraints. So
126433 ** the extra complication to make this rule less restrictive is probably
126434 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126435 */
 
126436 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
126437 return 0;
126438 }
126439 #endif
126440 if( (db->flags & SQLITE_CountRows)!=0 ){
@@ -129423,11 +129582,15 @@
129423 goto pragma_out;
129424 }
129425
129426 /* Locate the pragma in the lookup table */
129427 pPragma = pragmaLocate(zLeft);
129428 if( pPragma==0 ) goto pragma_out;
 
 
 
 
129429
129430 /* Make sure the database schema is loaded if the pragma requires that */
129431 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
129432 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
129433 }
@@ -130073,10 +130236,18 @@
130073 if( sqlite3GetBoolean(zRight, 0) ){
130074 db->flags |= mask;
130075 }else{
130076 db->flags &= ~mask;
130077 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
 
 
 
 
 
 
 
 
130078 }
130079
130080 /* Many of the flag-pragmas modify the code generated by the SQL
130081 ** compiler (eg. count_changes). So add an opcode to expire all
130082 ** compiled SQL statements after modifying a pragma value.
@@ -130113,10 +130284,11 @@
130113 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
130114 pParse->nMem = 7;
130115 sqlite3ViewGetColumnNames(pParse, pTab);
130116 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
130117 int isHidden = 0;
 
130118 if( pCol->colFlags & COLFLAG_NOINSERT ){
130119 if( pPragma->iArg==0 ){
130120 nHidden++;
130121 continue;
130122 }
@@ -130133,20 +130305,20 @@
130133 }else if( pPk==0 ){
130134 k = 1;
130135 }else{
130136 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
130137 }
130138 assert( sqlite3ColumnExpr(pTab,pCol)==0
130139 || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN
130140 || isHidden>=2 );
 
130141 sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
130142 i-nHidden,
130143 pCol->zCnName,
130144 sqlite3ColumnType(pCol,""),
130145 pCol->notNull ? 1 : 0,
130146 isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 :
130147 sqlite3ColumnExpr(pTab,pCol)->u.zToken,
130148 k,
130149 isHidden);
130150 }
130151 }
130152 }
@@ -130170,12 +130342,39 @@
130170 pParse->nMem = 6;
130171 sqlite3CodeVerifyNamedSchema(pParse, zDb);
130172 for(ii=0; ii<db->nDb; ii++){
130173 HashElem *k;
130174 Hash *pHash;
 
130175 if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
 
 
 
 
 
 
130176 pHash = &db->aDb[ii].pSchema->tblHash;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130177 for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){
130178 Table *pTab = sqliteHashData(k);
130179 const char *zType;
130180 if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
130181 if( IsView(pTab) ){
@@ -130326,15 +130525,17 @@
130326 FuncDef *p;
130327 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
130328 pParse->nMem = 6;
130329 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
130330 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
 
130331 pragmaFunclistLine(v, p, 1, showInternFunc);
130332 }
130333 }
130334 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
130335 p = (FuncDef*)sqliteHashData(j);
 
130336 pragmaFunclistLine(v, p, 0, showInternFunc);
130337 }
130338 }
130339 break;
130340
@@ -130364,11 +130565,11 @@
130364 #ifndef SQLITE_OMIT_FOREIGN_KEY
130365 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
130366 FKey *pFK;
130367 Table *pTab;
130368 pTab = sqlite3FindTable(db, zRight, zDb);
130369 if( pTab && !IsVirtual(pTab) ){
130370 pFK = pTab->u.tab.pFKey;
130371 if( pFK ){
130372 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130373 int i = 0;
130374 pParse->nMem = 8;
@@ -130424,19 +130625,19 @@
130424 k = 0;
130425 }else{
130426 pTab = (Table*)sqliteHashData(k);
130427 k = sqliteHashNext(k);
130428 }
130429 if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue;
130430 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130431 zDb = db->aDb[iDb].zDbSName;
130432 sqlite3CodeVerifySchema(pParse, iDb);
130433 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130434 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130435 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130436 sqlite3VdbeLoadString(v, regResult, pTab->zName);
130437 assert( !IsVirtual(pTab) );
130438 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130439 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130440 if( pParent==0 ) continue;
130441 pIdx = 0;
130442 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -130455,11 +130656,11 @@
130455 }
130456 assert( pParse->nErr>0 || pFK==0 );
130457 if( pFK ) break;
130458 if( pParse->nTab<i ) pParse->nTab = i;
130459 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130460 assert( !IsVirtual(pTab) );
130461 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130462 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130463 pIdx = 0;
130464 aiCols = 0;
130465 if( pParent ){
@@ -130659,11 +130860,11 @@
130659 int loopTop;
130660 int iDataCur, iIdxCur;
130661 int r1 = -1;
130662 int bStrict;
130663
130664 if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
130665 if( pObjTab && pObjTab!=pTab ) continue;
130666 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
130667 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
130668 1, 0, &iDataCur, &iIdxCur);
130669 /* reg[7] counts the number of entries in the table.
@@ -131254,16 +131455,16 @@
131254 ** in each index that it looks at. Return the new limit.
131255 */
131256 case PragTyp_ANALYSIS_LIMIT: {
131257 sqlite3_int64 N;
131258 if( zRight
131259 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
131260 && N>=0
131261 ){
131262 db->nAnalysisLimit = (int)(N&0x7fffffff);
131263 }
131264 returnSingleInt(v, db->nAnalysisLimit);
131265 break;
131266 }
131267
131268 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
131269 /*
@@ -133046,14 +133247,17 @@
133046 while( p ){
133047 ExprSetProperty(p, EP_FromJoin);
133048 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
133049 ExprSetVVAProperty(p, EP_NoReduce);
133050 p->iRightJoinTable = iTable;
133051 if( p->op==TK_FUNCTION && p->x.pList ){
133052 int i;
133053 for(i=0; i<p->x.pList->nExpr; i++){
133054 sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable);
 
 
 
133055 }
133056 }
133057 sqlite3SetJoinExpr(p->pLeft, iTable);
133058 p = p->pRight;
133059 }
@@ -133072,14 +133276,17 @@
133072 ExprClearProperty(p, EP_FromJoin);
133073 }
133074 if( p->op==TK_COLUMN && p->iTable==iTable ){
133075 ExprClearProperty(p, EP_CanBeNull);
133076 }
133077 if( p->op==TK_FUNCTION && p->x.pList ){
133078 int i;
133079 for(i=0; i<p->x.pList->nExpr; i++){
133080 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
 
 
 
133081 }
133082 }
133083 unsetJoinExpr(p->pLeft, iTable);
133084 p = p->pRight;
133085 }
@@ -133590,13 +133797,17 @@
133590 ExprList *pExtra = 0;
133591 for(i=0; i<pEList->nExpr; i++){
133592 struct ExprList_item *pItem = &pEList->a[i];
133593 if( pItem->u.x.iOrderByCol==0 ){
133594 Expr *pExpr = pItem->pExpr;
133595 Table *pTab = pExpr->y.pTab;
133596 if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 && pTab && !IsVirtual(pTab)
133597 && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)
 
 
 
 
133598 ){
133599 int j;
133600 for(j=0; j<nDefer; j++){
133601 if( pSort->aDefer[j].iCsr==pExpr->iTable ) break;
133602 }
@@ -133613,10 +133824,11 @@
133613 }
133614 for(k=0; k<nKey; k++){
133615 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
133616 if( pNew ){
133617 pNew->iTable = pExpr->iTable;
 
133618 pNew->y.pTab = pExpr->y.pTab;
133619 pNew->iColumn = pPk ? pPk->aiColumn[k] : -1;
133620 pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew);
133621 }
133622 }
@@ -134461,11 +134673,11 @@
134461 ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
134462 ** branch below. */
134463 break;
134464 }
134465
134466 assert( pTab && pExpr->y.pTab==pTab );
134467 if( pS ){
134468 /* The "table" is actually a sub-select or a view in the FROM clause
134469 ** of the SELECT statement. Return the declaration type and origin
134470 ** data for the result-set column of the sub-select.
134471 */
@@ -134521,13 +134733,15 @@
134521 /* The expression is a sub-select. Return the declaration type and
134522 ** origin info for the single column in the result set of the SELECT
134523 ** statement.
134524 */
134525 NameContext sNC;
134526 Select *pS = pExpr->x.pSelect;
134527 Expr *p = pS->pEList->a[0].pExpr;
134528 assert( ExprHasProperty(pExpr, EP_xIsSelect) );
 
 
134529 sNC.pSrcList = pS->pSrc;
134530 sNC.pNext = pNC;
134531 sNC.pParse = pNC->pParse;
134532 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
134533 break;
@@ -134652,11 +134866,12 @@
134652 for(i=0; i<pEList->nExpr; i++){
134653 Expr *p = pEList->a[i].pExpr;
134654
134655 assert( p!=0 );
134656 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
134657 assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */
 
134658 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
134659 /* An AS clause always takes first priority */
134660 char *zName = pEList->a[i].zEName;
134661 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
134662 }else if( srcName && p->op==TK_COLUMN ){
@@ -134748,11 +134963,14 @@
134748 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
134749 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
134750 pColExpr = pColExpr->pRight;
134751 assert( pColExpr!=0 );
134752 }
134753 if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
 
 
 
134754 /* For columns use the column name name */
134755 int iCol = pColExpr->iColumn;
134756 if( iCol<0 ) iCol = pTab->iPKey;
134757 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
134758 }else if( pColExpr->op==TK_ID ){
@@ -136330,11 +136548,11 @@
136330 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
136331 pExpr->iTable = pSubst->iNewTable;
136332 }
136333 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
136334 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
136335 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
136336 substSelect(pSubst, pExpr->x.pSelect, 1);
136337 }else{
136338 substExprList(pSubst, pExpr->x.pList);
136339 }
136340 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -137541,25 +137759,28 @@
137541 ** located but before their arguments have been subjected to aggregate
137542 ** analysis.
137543 */
137544 static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
137545 int eRet = WHERE_ORDERBY_NORMAL; /* Return value */
137546 ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */
137547 const char *zFunc; /* Name of aggregate function pFunc */
137548 ExprList *pOrderBy;
137549 u8 sortFlags = 0;
137550
137551 assert( *ppMinMax==0 );
137552 assert( pFunc->op==TK_AGG_FUNCTION );
137553 assert( !IsWindowFunc(pFunc) );
 
 
137554 if( pEList==0
137555 || pEList->nExpr!=1
137556 || ExprHasProperty(pFunc, EP_WinFunc)
137557 || OptimizationDisabled(db, SQLITE_MinMaxOpt)
137558 ){
137559 return eRet;
137560 }
 
137561 zFunc = pFunc->u.zToken;
137562 if( sqlite3StrICmp(zFunc, "min")==0 ){
137563 eRet = WHERE_ORDERBY_MIN;
137564 if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
137565 sortFlags = KEYINFO_ORDER_BIGNULL;
@@ -137632,10 +137853,11 @@
137632 if( !pIdx ){
137633 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
137634 pParse->checkSchema = 1;
137635 return SQLITE_ERROR;
137636 }
 
137637 pFrom->u2.pIBIndex = pIdx;
137638 return SQLITE_OK;
137639 }
137640
137641 /*
@@ -137889,10 +138111,14 @@
137889 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
137890 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
137891 if( db->mallocFailed ) return 2;
137892 pFrom->pSelect->selFlags |= SF_CopyCte;
137893 assert( pFrom->pSelect );
 
 
 
 
137894 pFrom->fg.isCte = 1;
137895 pFrom->u2.pCteUse = pCteUse;
137896 pCteUse->nUse++;
137897 if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){
137898 pCteUse->eM10d = M10d_Yes;
@@ -138524,11 +138750,11 @@
138524 #endif
138525 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
138526 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
138527 if( pFunc->iDistinct>=0 ){
138528 Expr *pE = pFunc->pFExpr;
138529 assert( !ExprHasProperty(pE, EP_xIsSelect) );
138530 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
138531 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
138532 "argument");
138533 pFunc->iDistinct = -1;
138534 }else{
@@ -138549,12 +138775,13 @@
138549 static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
138550 Vdbe *v = pParse->pVdbe;
138551 int i;
138552 struct AggInfo_func *pF;
138553 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138554 ExprList *pList = pF->pFExpr->x.pList;
138555 assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
 
138556 sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
138557 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
138558 }
138559 }
138560
@@ -138584,13 +138811,14 @@
138584 pAggInfo->directMode = 1;
138585 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138586 int nArg;
138587 int addrNext = 0;
138588 int regAgg;
138589 ExprList *pList = pF->pFExpr->x.pList;
138590 assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
138591 assert( !IsWindowFunc(pF->pFExpr) );
 
138592 if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
138593 Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
138594 if( pAggInfo->nAccumulator
138595 && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
138596 && regAcc
@@ -138832,11 +139060,13 @@
138832 if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
138833 if( p->pWhere ) return 0;
138834 if( p->pGroupBy ) return 0;
138835 pExpr = p->pEList->a[0].pExpr;
138836 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
 
138837 if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
 
138838 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
138839 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
138840 pSub = p->pSrc->a[0].pSelect;
138841 if( pSub==0 ) return 0; /* The FROM is a subquery */
138842 if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */
@@ -139647,11 +139877,11 @@
139647 }else{
139648 minMaxFlag = WHERE_ORDERBY_NORMAL;
139649 }
139650 for(i=0; i<pAggInfo->nFunc; i++){
139651 Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
139652 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
139653 sNC.ncFlags |= NC_InAggFunc;
139654 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
139655 #ifndef SQLITE_OMIT_WINDOWFUNC
139656 assert( !IsWindowFunc(pExpr) );
139657 if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -139702,11 +139932,13 @@
139702 u16 distFlag = 0;
139703 int eDist = WHERE_DISTINCT_NOOP;
139704
139705 if( pAggInfo->nFunc==1
139706 && pAggInfo->aFunc[0].iDistinct>=0
139707 && pAggInfo->aFunc[0].pFExpr->x.pList
 
 
139708 ){
139709 Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
139710 pExpr = sqlite3ExprDup(db, pExpr, 0);
139711 pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
139712 pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr);
@@ -140023,10 +140255,11 @@
140023 if( i==pAggInfo->nFunc ){
140024 regAcc = ++pParse->nMem;
140025 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
140026 }
140027 }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
 
140028 pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
140029 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
140030 }
140031
140032 /* This case runs if the aggregate has no GROUP BY clause. The
@@ -144048,11 +144281,14 @@
144048 ** Except, if argument db is not NULL, then the entry associated with
144049 ** connection db is left in the p->u.vtab.p list.
144050 */
144051 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
144052 VTable *pRet = 0;
144053 VTable *pVTable = p->u.vtab.p;
 
 
 
144054 p->u.vtab.p = 0;
144055
144056 /* Assert that the mutex (if any) associated with the BtShared database
144057 ** that contains table p is held by the caller. See header comments
144058 ** above function sqlite3VtabUnlockList() for an explanation of why
@@ -144156,10 +144392,11 @@
144156 ** structure being xDisconnected and free). Any other VTable structures
144157 ** in the list are moved to the sqlite3.pDisconnect list of the associated
144158 ** database connection.
144159 */
144160 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
 
144161 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
144162 if( p->u.vtab.azArg ){
144163 int i;
144164 for(i=0; i<p->u.vtab.nArg; i++){
144165 if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
@@ -144173,13 +144410,16 @@
144173 ** The string is not copied - the pointer is stored. The
144174 ** string will be freed automatically when the table is
144175 ** deleted.
144176 */
144177 static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
144178 sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
144179 char **azModuleArg;
144180 sqlite3 *db = pParse->db;
 
 
 
144181 if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
144182 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
144183 }
144184 azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes);
144185 if( azModuleArg==0 ){
@@ -144262,10 +144502,11 @@
144262 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
144263 Table *pTab = pParse->pNewTable; /* The table being constructed */
144264 sqlite3 *db = pParse->db; /* The database connection */
144265
144266 if( pTab==0 ) return;
 
144267 addArgumentToVtab(pParse);
144268 pParse->sArg.z = 0;
144269 if( pTab->u.vtab.nArg<1 ) return;
144270
144271 /* If the CREATE VIRTUAL TABLE statement is being entered for the
@@ -144379,17 +144620,20 @@
144379 char **pzErr
144380 ){
144381 VtabCtx sCtx;
144382 VTable *pVTable;
144383 int rc;
144384 const char *const*azArg = (const char *const*)pTab->u.vtab.azArg;
144385 int nArg = pTab->u.vtab.nArg;
144386 char *zErr = 0;
144387 char *zModuleName;
144388 int iDb;
144389 VtabCtx *pCtx;
144390
 
 
 
144391 /* Check that the virtual-table is not already being initialized */
144392 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
144393 if( pCtx->pTab==pTab ){
144394 *pzErr = sqlite3MPrintf(db,
144395 "vtable constructor called recursively: %s", pTab->zName
@@ -144713,11 +144957,11 @@
144713 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144714 int rc = SQLITE_OK;
144715 Table *pTab;
144716
144717 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144718 if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){
144719 VTable *p;
144720 int (*xDestroy)(sqlite3_vtab *);
144721 for(p=pTab->u.vtab.p; p; p=p->pNext){
144722 assert( p->pVtab );
144723 if( p->pVtab->nRef>0 ){
@@ -144946,10 +145190,11 @@
144946 int rc = 0;
144947
144948 /* Check to see the left operand is a column in a virtual table */
144949 if( NEVER(pExpr==0) ) return pDef;
144950 if( pExpr->op!=TK_COLUMN ) return pDef;
 
144951 pTab = pExpr->y.pTab;
144952 if( pTab==0 ) return pDef;
144953 if( !IsVirtual(pTab) ) return pDef;
144954 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
144955 assert( pVtab!=0 );
@@ -145254,11 +145499,11 @@
145254 int iBase; /* Base register of multi-key index record */
145255 int nPrefix; /* Number of prior entires in the key */
145256 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
145257 } *aInLoop; /* Information about each nested IN operator */
145258 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
145259 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
145260 } u;
145261 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
145262 Bitmask notReady; /* FROM entries not usable at this level */
145263 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
145264 int addrVisit; /* Address at which row is visited */
@@ -146182,20 +146427,27 @@
146182 ){
146183 sqlite3 *db = pParse->db;
146184 Expr *pNew;
146185 pNew = sqlite3ExprDup(db, pX, 0);
146186 if( db->mallocFailed==0 ){
146187 ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
146188 ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
146189 ExprList *pRhs = 0; /* New RHS after modifications */
146190 ExprList *pLhs = 0; /* New LHS after mods */
146191 int i; /* Loop counter */
146192 Select *pSelect; /* Pointer to the SELECT on the RHS */
146193
 
 
 
 
 
146194 for(i=iEq; i<pLoop->nLTerm; i++){
146195 if( pLoop->aLTerm[i]->pExpr==pX ){
146196 int iField = pLoop->aLTerm[i]->u.x.iField - 1;
 
 
146197 if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
146198 pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
146199 pOrigRhs->a[iField].pExpr = 0;
146200 assert( pOrigLhs->a[iField].pExpr!=0 );
146201 pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
@@ -146306,11 +146558,11 @@
146306 assert( pLoop->aLTerm[i]!=0 );
146307 if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
146308 }
146309
146310 iTab = 0;
146311 if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
146312 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
146313 }else{
146314 sqlite3 *db = pParse->db;
146315 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
146316
@@ -146328,12 +146580,12 @@
146328 bRev = !bRev;
146329 }
146330 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
146331 VdbeCoverageIf(v, bRev);
146332 VdbeCoverageIf(v, !bRev);
 
146333 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
146334
146335 pLoop->wsFlags |= WHERE_IN_ABLE;
146336 if( pLevel->u.in.nIn==0 ){
146337 pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
146338 }
146339 if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
@@ -146871,21 +147123,23 @@
146871 */
146872 static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
146873 assert( nReg>0 );
146874 if( p && sqlite3ExprIsVector(p) ){
146875 #ifndef SQLITE_OMIT_SUBQUERY
146876 if( (p->flags & EP_xIsSelect) ){
146877 Vdbe *v = pParse->pVdbe;
146878 int iSelect;
146879 assert( p->op==TK_SELECT );
146880 iSelect = sqlite3CodeSubselect(pParse, p);
146881 sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
146882 }else
146883 #endif
146884 {
146885 int i;
146886 ExprList *pList = p->x.pList;
 
 
146887 assert( nReg<=pList->nExpr );
146888 for(i=0; i<nReg; i++){
146889 sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i);
146890 }
146891 }
@@ -146934,14 +147188,14 @@
146934 preserveExpr(pX, pExpr);
146935 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
146936 pExpr->op = TK_COLUMN;
146937 pExpr->iTable = pX->iIdxCur;
146938 pExpr->iColumn = pX->iIdxCol;
146939 pExpr->y.pTab = 0;
146940 testcase( ExprHasProperty(pExpr, EP_Skip) );
146941 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
146942 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely);
 
146943 return WRC_Prune;
146944 }else{
146945 return WRC_Continue;
146946 }
146947 }
@@ -146952,11 +147206,11 @@
146952 */
146953 static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
146954 if( pExpr->op==TK_COLUMN ){
146955 IdxExprTrans *pX = p->u.pIdxTrans;
146956 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
146957 assert( pExpr->y.pTab!=0 );
146958 preserveExpr(pX, pExpr);
146959 pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
146960 pExpr->iTable = pX->iIdxCur;
146961 pExpr->iColumn = pX->iIdxCol;
146962 pExpr->y.pTab = 0;
@@ -147189,11 +147443,16 @@
147189 ** the u.vtab.idxStr. NULL it out to prevent a use-after-free */
147190 if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
147191 pLevel->p1 = iCur;
147192 pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
147193 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
147194 iIn = pLevel->u.in.nIn;
 
 
 
 
 
147195 for(j=nConstraint-1; j>=0; j--){
147196 pTerm = pLoop->aLTerm[j];
147197 if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
147198 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
147199 disableTerm(pLevel, pTerm);
@@ -148078,11 +148337,14 @@
148078 }
148079 sqlite3ExprDelete(db, pDelete);
148080 }
148081 }
148082 ExplainQueryPlanPop(pParse);
148083 pLevel->u.pCovidx = pCov;
 
 
 
148084 if( pCov ) pLevel->iIdxCur = iCovCur;
148085 if( pAndExpr ){
148086 pAndExpr->pLeft = 0;
148087 sqlite3ExprDelete(db, pAndExpr);
148088 }
@@ -148222,16 +148484,17 @@
148222 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
148223 }
148224 #endif
148225 assert( !ExprHasProperty(pE, EP_FromJoin) );
148226 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
 
148227 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
148228 WO_EQ|WO_IN|WO_IS, 0);
148229 if( pAlt==0 ) continue;
148230 if( pAlt->wtFlags & (TERM_CODED) ) continue;
148231 if( (pAlt->eOperator & WO_IN)
148232 && (pAlt->pExpr->flags & EP_xIsSelect)
148233 && (pAlt->pExpr->x.pSelect->pEList->nExpr>1)
148234 ){
148235 continue;
148236 }
148237 testcase( pAlt->eOperator & WO_EQ );
@@ -148476,10 +148739,11 @@
148476 return 0;
148477 }
148478 #ifdef SQLITE_EBCDIC
148479 if( *pnoCase ) return 0;
148480 #endif
 
148481 pList = pExpr->x.pList;
148482 pLeft = pList->a[1].pExpr;
148483
148484 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
148485 op = pRight->op;
@@ -148491,11 +148755,12 @@
148491 z = sqlite3_value_text(pVal);
148492 }
148493 sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
148494 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
148495 }else if( op==TK_STRING ){
148496 z = (u8*)pRight->u.zToken;
 
148497 }
148498 if( z ){
148499
148500 /* Count the number of prefix characters prior to the first wildcard */
148501 cnt = 0;
@@ -148520,11 +148785,13 @@
148520
148521 /* Get the pattern prefix. Remove all escapes from the prefix. */
148522 pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
148523 if( pPrefix ){
148524 int iFrom, iTo;
148525 char *zNew = pPrefix->u.zToken;
 
 
148526 zNew[cnt] = 0;
148527 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
148528 if( zNew[iFrom]==wc[3] ) iFrom++;
148529 zNew[iTo++] = zNew[iFrom];
148530 }
@@ -148544,11 +148811,13 @@
148544 ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148545 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148546 */
148547 if( pLeft->op!=TK_COLUMN
148548 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148549 || (pLeft->y.pTab && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
 
 
148550 ){
148551 int isNum;
148552 double rDummy;
148553 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148554 if( isNum<=0 ){
@@ -148572,10 +148841,11 @@
148572 /* If the RHS pattern is a bound parameter, make arrangements to
148573 ** reprepare the statement when that parameter is rebound */
148574 if( op==TK_VARIABLE ){
148575 Vdbe *v = pParse->pVdbe;
148576 sqlite3VdbeSetVarmask(v, pRight->iColumn);
 
148577 if( *pisComplete && pRight->u.zToken[1] ){
148578 /* If the rhs of the LIKE expression is a variable, and the current
148579 ** value of the variable means there is no need to invoke the LIKE
148580 ** function, then no OP_Variable will be added to the program.
148581 ** This causes problems for the sqlite3_bind_parameter_name()
@@ -148645,10 +148915,11 @@
148645 };
148646 ExprList *pList;
148647 Expr *pCol; /* Column reference */
148648 int i;
148649
 
148650 pList = pExpr->x.pList;
148651 if( pList==0 || pList->nExpr!=2 ){
148652 return 0;
148653 }
148654
@@ -148658,13 +148929,15 @@
148658 **
148659 ** vtab_column MATCH expression
148660 ** MATCH(expression,vtab_column)
148661 */
148662 pCol = pList->a[1].pExpr;
 
148663 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148664 if( ExprIsVtab(pCol) ){
148665 for(i=0; i<ArraySize(aOp); i++){
 
148666 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
148667 *peOp2 = aOp[i].eOp2;
148668 *ppRight = pList->a[0].pExpr;
148669 *ppLeft = pCol;
148670 return 1;
@@ -148681,20 +148954,22 @@
148681 ** Historically, xFindFunction expected to see lower-case function
148682 ** names. But for this use case, xFindFunction is expected to deal
148683 ** with function names in an arbitrary case.
148684 */
148685 pCol = pList->a[0].pExpr;
 
148686 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148687 if( ExprIsVtab(pCol) ){
148688 sqlite3_vtab *pVtab;
148689 sqlite3_module *pMod;
148690 void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
148691 void *pNotUsed;
148692 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
148693 assert( pVtab!=0 );
148694 assert( pVtab->pModule!=0 );
148695 pMod = (sqlite3_module *)pVtab->pModule;
 
148696 if( pMod->xFindFunction!=0 ){
148697 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
148698 if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
148699 *peOp2 = i;
148700 *ppRight = pList->a[1].pExpr;
@@ -148705,14 +148980,16 @@
148705 }
148706 }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
148707 int res = 0;
148708 Expr *pLeft = pExpr->pLeft;
148709 Expr *pRight = pExpr->pRight;
 
148710 testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
148711 if( ExprIsVtab(pLeft) ){
148712 res++;
148713 }
 
148714 testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
148715 if( pRight && ExprIsVtab(pRight) ){
148716 res++;
148717 SWAP(Expr*, pLeft, pRight);
148718 }
@@ -148961,10 +149238,11 @@
148961 int j;
148962 Bitmask b = 0;
148963 pOrTerm->u.pAndInfo = pAndInfo;
148964 pOrTerm->wtFlags |= TERM_ANDINFO;
148965 pOrTerm->eOperator = WO_AND;
 
148966 pAndWC = &pAndInfo->wc;
148967 memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
148968 sqlite3WhereClauseInit(pAndWC, pWC->pWInfo);
148969 sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
148970 sqlite3WhereExprAnalyze(pSrc, pAndWC);
@@ -149003,15 +149281,14 @@
149003 /*
149004 ** Record the set of tables that satisfy case 3. The set might be
149005 ** empty.
149006 */
149007 pOrInfo->indexable = indexable;
 
 
149008 if( indexable ){
149009 pTerm->eOperator = WO_OR;
149010 pWC->hasOr = 1;
149011 }else{
149012 pTerm->eOperator = WO_OR;
149013 }
149014
149015 /* For a two-way OR, attempt to implementation case 2.
149016 */
149017 if( indexable && pOrWc->nTerm==2 ){
@@ -149080,10 +149357,11 @@
149080 testcase( pOrTerm->wtFlags & TERM_COPIED );
149081 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
149082 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
149083 continue;
149084 }
 
149085 iColumn = pOrTerm->u.x.leftColumn;
149086 iCursor = pOrTerm->leftCursor;
149087 pLeft = pOrTerm->pExpr->pLeft;
149088 break;
149089 }
@@ -149100,10 +149378,11 @@
149100 /* We have found a candidate table and column. Check to see if that
149101 ** table and column is common to every term in the OR clause */
149102 okToChngToIN = 1;
149103 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
149104 assert( pOrTerm->eOperator & WO_EQ );
 
149105 if( pOrTerm->leftCursor!=iCursor ){
149106 pOrTerm->wtFlags &= ~TERM_OR_OK;
149107 }else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR
149108 && sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1)
149109 )){
@@ -149136,10 +149415,11 @@
149136 Expr *pNew; /* The complete IN operator */
149137
149138 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
149139 if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
149140 assert( pOrTerm->eOperator & WO_EQ );
 
149141 assert( pOrTerm->leftCursor==iCursor );
149142 assert( pOrTerm->u.x.leftColumn==iColumn );
149143 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
149144 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
149145 pLeft = pOrTerm->pExpr->pLeft;
@@ -149148,11 +149428,11 @@
149148 pDup = sqlite3ExprDup(db, pLeft, 0);
149149 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
149150 if( pNew ){
149151 int idxNew;
149152 transferJoinMarkings(pNew, pExpr);
149153 assert( !ExprHasProperty(pNew, EP_xIsSelect) );
149154 pNew->x.pList = pList;
149155 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
149156 testcase( idxNew==0 );
149157 exprAnalyze(pSrc, pWC, idxNew);
149158 /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
@@ -149276,10 +149556,11 @@
149276 ** on the first element of the vector. */
149277 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
149278 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
149279 assert( op<=TK_GE );
149280 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
 
149281 pExpr = pExpr->x.pList->a[0].pExpr;
149282
149283 }
149284
149285 if( pExpr->op==TK_COLUMN ){
@@ -149342,11 +149623,11 @@
149342 prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft);
149343 op = pExpr->op;
149344 if( op==TK_IN ){
149345 assert( pExpr->pRight==0 );
149346 if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
149347 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
149348 pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect);
149349 }else{
149350 pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList);
149351 }
149352 }else if( op==TK_ISNULL ){
@@ -149378,15 +149659,17 @@
149378 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
149379
149380 if( pTerm->u.x.iField>0 ){
149381 assert( op==TK_IN );
149382 assert( pLeft->op==TK_VECTOR );
 
149383 pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr;
149384 }
149385
149386 if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
149387 pTerm->leftCursor = aiCurCol[0];
 
149388 pTerm->u.x.leftColumn = aiCurCol[1];
149389 pTerm->eOperator = operatorMask(op) & opMask;
149390 }
149391 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
149392 if( pRight
@@ -149420,10 +149703,11 @@
149420 pDup = pExpr;
149421 pNew = pTerm;
149422 }
149423 pNew->wtFlags |= exprCommute(pParse, pDup);
149424 pNew->leftCursor = aiCurCol[0];
 
149425 pNew->u.x.leftColumn = aiCurCol[1];
149426 testcase( (prereqLeft | extraRight) != prereqLeft );
149427 pNew->prereqRight = prereqLeft | extraRight;
149428 pNew->prereqAll = prereqAll;
149429 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
@@ -149430,10 +149714,11 @@
149430 }else
149431 if( op==TK_ISNULL
149432 && !ExprHasProperty(pExpr,EP_FromJoin)
149433 && 0==sqlite3ExprCanBeNull(pLeft)
149434 ){
 
149435 pExpr->op = TK_TRUEFALSE;
149436 pExpr->u.zToken = "false";
149437 ExprSetProperty(pExpr, EP_IsFalse);
149438 pTerm->prereqAll = 0;
149439 pTerm->eOperator = 0;
@@ -149455,13 +149740,15 @@
149455 ** term. That means that if the BETWEEN term is coded, the children are
149456 ** skipped. Or, if the children are satisfied by an index, the original
149457 ** BETWEEN term is skipped.
149458 */
149459 else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
149460 ExprList *pList = pExpr->x.pList;
149461 int i;
149462 static const u8 ops[] = {TK_GE, TK_LE};
 
 
149463 assert( pList!=0 );
149464 assert( pList->nExpr==2 );
149465 for(i=0; i<2; i++){
149466 Expr *pNewExpr;
149467 int idxNew;
@@ -149550,12 +149837,16 @@
149550 int idxNew1;
149551 int idxNew2;
149552 const char *zCollSeqName; /* Name of collating sequence */
149553 const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
149554
 
149555 pLeft = pExpr->x.pList->a[1].pExpr;
149556 pStr2 = sqlite3ExprDup(db, pStr1, 0);
 
 
 
149557
149558 /* Convert the lower bound to upper-case and the upper bound to
149559 ** lower-case (upper-case is less than lower-case in ASCII) so that
149560 ** the range constraints also work for BLOBs
149561 */
@@ -149651,10 +149942,11 @@
149651 ** not use window functions.
149652 */
149653 else if( pExpr->op==TK_IN
149654 && pTerm->u.x.iField==0
149655 && pExpr->pLeft->op==TK_VECTOR
 
149656 && pExpr->x.pSelect->pPrior==0
149657 #ifndef SQLITE_OMIT_WINDOWFUNC
149658 && pExpr->x.pSelect->pWin==0
149659 #endif
149660 && pWC->op==TK_AND
@@ -149814,18 +150106,19 @@
149814 mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
149815 if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft);
149816 if( p->pRight ){
149817 mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight);
149818 assert( p->x.pList==0 );
149819 }else if( ExprHasProperty(p, EP_xIsSelect) ){
149820 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
149821 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
149822 }else if( p->x.pList ){
149823 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
149824 }
149825 #ifndef SQLITE_OMIT_WINDOWFUNC
149826 if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){
 
149827 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
149828 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
149829 mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter);
149830 }
149831 #endif
@@ -149896,10 +150189,11 @@
149896 }
149897 pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
149898 if( pColRef==0 ) return;
149899 pColRef->iTable = pItem->iCursor;
149900 pColRef->iColumn = k++;
 
149901 pColRef->y.pTab = pTab;
149902 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
149903 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
149904 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
149905 if( pItem->fg.jointype & JT_LEFT ){
@@ -150197,12 +150491,14 @@
150197 pWC = pScan->pWC;
150198 while(1){
150199 iColumn = pScan->aiColumn[pScan->iEquiv-1];
150200 iCur = pScan->aiCur[pScan->iEquiv-1];
150201 assert( pWC!=0 );
 
150202 do{
150203 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
 
150204 if( pTerm->leftCursor==iCur
150205 && pTerm->u.x.leftColumn==iColumn
150206 && (iColumn!=XN_EXPR
150207 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
150208 pScan->pIdxExpr,iCur)==0)
@@ -150638,10 +150934,11 @@
150638 ** the RHS of a LEFT JOIN. Such a term can only be used if it is from
150639 ** the ON clause. */
150640 return 0;
150641 }
150642 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
 
150643 if( pTerm->u.x.leftColumn<0 ) return 0;
150644 aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
150645 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
150646 testcase( pTerm->pExpr->op==TK_IS );
150647 return 1;
@@ -150710,12 +151007,15 @@
150710 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
150711 pPartial = sqlite3ExprAnd(pParse, pPartial,
150712 sqlite3ExprDup(pParse->db, pExpr, 0));
150713 }
150714 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
150715 int iCol = pTerm->u.x.leftColumn;
150716 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
 
 
 
150717 testcase( iCol==BMS );
150718 testcase( iCol==BMS-1 );
150719 if( !sentWarning ){
150720 sqlite3_log(SQLITE_WARNING_AUTOINDEX,
150721 "automatic index on %s(%s)", pTable->zName,
@@ -150763,12 +151063,15 @@
150763 pIdx->pTable = pTable;
150764 n = 0;
150765 idxCols = 0;
150766 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
150767 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
150768 int iCol = pTerm->u.x.leftColumn;
150769 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
 
 
 
150770 testcase( iCol==BMS-1 );
150771 testcase( iCol==BMS );
150772 if( (idxCols & cMask)==0 ){
150773 Expr *pX = pTerm->pExpr;
150774 idxCols |= cMask;
@@ -150891,10 +151194,11 @@
150891 testcase( pTerm->eOperator & WO_ISNULL );
150892 testcase( pTerm->eOperator & WO_IS );
150893 testcase( pTerm->eOperator & WO_ALL );
150894 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
150895 if( pTerm->wtFlags & TERM_VNULL ) continue;
 
150896 assert( pTerm->u.x.leftColumn>=(-1) );
150897 nTerm++;
150898 }
150899
150900 /* If the ORDER BY clause contains only columns in the current
@@ -150951,10 +151255,11 @@
150951 if( (pSrc->fg.jointype & JT_LEFT)!=0
150952 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
150953 ){
150954 continue;
150955 }
 
150956 assert( pTerm->u.x.leftColumn>=(-1) );
150957 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
150958 pIdxCons[j].iTermOffset = i;
150959 op = pTerm->eOperator & WO_ALL;
150960 if( op==WO_IN ) op = WO_EQ;
@@ -151714,10 +152019,11 @@
151714 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
151715 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
151716 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
151717 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
151718 if( pTerm->eOperator & WO_SINGLE ){
 
151719 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
151720 pTerm->leftCursor, pTerm->u.x.leftColumn);
151721 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
151722 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
151723 pTerm->u.pOrInfo->indexable);
@@ -151731,11 +152037,11 @@
151731 ** shown about each Term */
151732 if( sqlite3WhereTrace & 0x10000 ){
151733 sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx",
151734 pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight);
151735 }
151736 if( pTerm->u.x.iField ){
151737 sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField);
151738 }
151739 if( pTerm->iParent>=0 ){
151740 sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
151741 }
@@ -151895,11 +152201,12 @@
151895 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
151896 int i;
151897 assert( pWInfo!=0 );
151898 for(i=0; i<pWInfo->nLevel; i++){
151899 WhereLevel *pLevel = &pWInfo->a[i];
151900 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
 
151901 sqlite3DbFree(db, pLevel->u.in.aInLoop);
151902 }
151903 }
151904 sqlite3WhereClauseClear(&pWInfo->sWC);
151905 while( pWInfo->pLoops ){
@@ -152330,13 +152637,16 @@
152330 /* Test if comparison i of pTerm is compatible with column (i+nEq)
152331 ** of the index. If not, exit the loop. */
152332 char aff; /* Comparison affinity */
152333 char idxaff = 0; /* Indexed columns affinity */
152334 CollSeq *pColl; /* Comparison collation sequence */
152335 Expr *pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr;
152336 Expr *pRhs = pTerm->pExpr->pRight;
152337 if( pRhs->flags & EP_xIsSelect ){
 
 
 
152338 pRhs = pRhs->x.pSelect->pEList->a[i].pExpr;
152339 }else{
152340 pRhs = pRhs->x.pList->a[i].pExpr;
152341 }
152342
@@ -152493,11 +152803,11 @@
152493 || (pNew->wsFlags & WHERE_SKIPSCAN)!=0
152494 );
152495
152496 if( eOp & WO_IN ){
152497 Expr *pExpr = pTerm->pExpr;
152498 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
152499 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
152500 int i;
152501 nIn = 46; assert( 46==sqlite3LogEst(25) );
152502
152503 /* The expression may actually be of the form (x, y) IN (SELECT...).
@@ -152634,11 +152944,11 @@
152634 #ifdef SQLITE_ENABLE_STAT4
152635 tRowcnt nOut = 0;
152636 if( nInMul==0
152637 && pProbe->nSample
152638 && ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol)
152639 && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
152640 && OptimizationEnabled(db, SQLITE_Stat4)
152641 ){
152642 Expr *pExpr = pTerm->pExpr;
152643 if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
152644 testcase( eOp & WO_EQ );
@@ -152910,10 +153220,11 @@
152910 pTab = pSrc->pTab;
152911 pWC = pBuilder->pWC;
152912 assert( !IsVirtual(pSrc->pTab) );
152913
152914 if( pSrc->fg.isIndexedBy ){
 
152915 /* An INDEXED BY clause specifies a particular index to use */
152916 pProbe = pSrc->u2.pIBIndex;
152917 }else if( !HasRowid(pTab) ){
152918 pProbe = pTab->pIndex;
152919 }else{
@@ -155380,11 +155691,11 @@
155380 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
155381 #endif
155382 }else{
155383 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
155384 }
155385 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
155386 struct InLoop *pIn;
155387 int j;
155388 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
155389 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
155390 assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
@@ -155449,14 +155760,14 @@
155449 if( (ws & WHERE_IDX_ONLY)==0 ){
155450 assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
155451 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
155452 }
155453 if( (ws & WHERE_INDEXED)
155454 || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx)
155455 ){
155456 if( ws & WHERE_MULTI_OR ){
155457 Index *pIx = pLevel->u.pCovidx;
155458 int iDb = sqlite3SchemaToIndex(db, pIx->pSchema);
155459 sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb);
155460 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
155461 }
155462 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -155533,11 +155844,11 @@
155533 ** reference the index.
155534 */
155535 if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){
155536 pIdx = pLoop->u.btree.pIndex;
155537 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
155538 pIdx = pLevel->u.pCovidx;
155539 }
155540 if( pIdx
155541 && !db->mallocFailed
155542 ){
155543 if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){
@@ -156194,28 +156505,28 @@
156194 static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ }
156195
156196 /* Window functions that use all window interfaces: xStep, xFinal,
156197 ** xValue, and xInverse */
156198 #define WINDOWFUNCALL(name,nArg,extra) { \
156199 nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156200 name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \
156201 name ## InvFunc, name ## Name, {0} \
156202 }
156203
156204 /* Window functions that are implemented using bytecode and thus have
156205 ** no-op routines for their methods */
156206 #define WINDOWFUNCNOOP(name,nArg,extra) { \
156207 nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156208 noopStepFunc, noopValueFunc, noopValueFunc, \
156209 noopStepFunc, name ## Name, {0} \
156210 }
156211
156212 /* Window functions that use all window interfaces: xStep, the
156213 ** same routine for xFinalize and xValue and which never call
156214 ** xInverse. */
156215 #define WINDOWFUNCX(name,nArg,extra) { \
156216 nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156217 name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \
156218 noopStepFunc, name ## Name, {0} \
156219 }
156220
156221
@@ -156554,11 +156865,12 @@
156554 return WRC_Continue;
156555 }
156556
156557 static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
156558 if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
156559 sqlite3ErrorMsg(pWalker->pParse,
 
156560 "misuse of aggregate: %s()", pExpr->u.zToken);
156561 }
156562 return WRC_Continue;
156563 }
156564
@@ -156642,11 +156954,13 @@
156642 /* Append the arguments passed to each window function to the
156643 ** sub-select expression list. Also allocate two registers for each
156644 ** window function - one for the accumulator, another for interim
156645 ** results. */
156646 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
156647 ExprList *pArgs = pWin->pOwner->x.pList;
 
 
156648 if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
156649 selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
156650 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
156651 pWin->bExprArgs = 1;
156652 }else{
@@ -157035,12 +157349,15 @@
157035 **
157036 ** regApp+0: slot to copy min()/max() argument to for MakeRecord
157037 ** regApp+1: integer value used to ensure keys are unique
157038 ** regApp+2: output of MakeRecord
157039 */
157040 ExprList *pList = pWin->pOwner->x.pList;
157041 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
 
 
 
157042 pWin->csrApp = pParse->nTab++;
157043 pWin->regApp = pParse->nMem+1;
157044 pParse->nMem += 3;
157045 if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
157046 assert( pKeyInfo->aSortFlags[0]==0 );
@@ -157124,11 +157441,13 @@
157124 /*
157125 ** Return the number of arguments passed to the window-function associated
157126 ** with the object passed as the only argument to this function.
157127 */
157128 static int windowArgCount(Window *pWin){
157129 ExprList *pList = pWin->pOwner->x.pList;
 
 
157130 return (pList ? pList->nExpr : 0);
157131 }
157132
157133 typedef struct WindowCodeArg WindowCodeArg;
157134 typedef struct WindowCsrAndReg WindowCsrAndReg;
@@ -157309,10 +157628,11 @@
157309 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
157310 }else if( pFunc->xSFunc!=noopStepFunc ){
157311 int addrIf = 0;
157312 if( pWin->pFilter ){
157313 int regTmp;
 
157314 assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
157315 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
157316 regTmp = sqlite3GetTempReg(pParse);
157317 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
157318 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
@@ -157322,10 +157642,11 @@
157322
157323 if( pWin->bExprArgs ){
157324 int iOp = sqlite3VdbeCurrentAddr(v);
157325 int iEnd;
157326
 
157327 nArg = pWin->pOwner->x.pList->nExpr;
157328 regArg = sqlite3GetTempRange(pParse, nArg);
157329 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
157330
157331 for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
@@ -157336,10 +157657,11 @@
157336 }
157337 }
157338 if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
157339 CollSeq *pColl;
157340 assert( nArg>0 );
 
157341 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
157342 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
157343 }
157344 sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
157345 bInverse, regArg, pWin->regAccum);
@@ -157521,10 +157843,11 @@
157521 Parse *pParse = p->pParse;
157522 Window *pWin;
157523
157524 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
157525 FuncDef *pFunc = pWin->pFunc;
 
157526 if( pFunc->zName==nth_valueName
157527 || pFunc->zName==first_valueName
157528 ){
157529 int csr = pWin->csrApp;
157530 int lbl = sqlite3VdbeMakeLabel(pParse);
@@ -158870,13 +159193,13 @@
158870 p->affExpr = 0;
158871 p->flags = EP_Leaf;
158872 ExprClearVVAProperties(p);
158873 p->iAgg = -1;
158874 p->pLeft = p->pRight = 0;
158875 p->x.pList = 0;
158876 p->pAggInfo = 0;
158877 p->y.pTab = 0;
 
158878 p->op2 = 0;
158879 p->iTable = 0;
158880 p->iColumn = 0;
158881 p->u.zToken = (char*)&p[1];
158882 memcpy(p->u.zToken, t.z, t.n);
@@ -166966,11 +167289,13 @@
166966 ** if this is not the last copy of the function, do not invoke it. Multiple
166967 ** copies of a single function are created when create_function() is called
166968 ** with SQLITE_ANY as the encoding.
166969 */
166970 static void functionDestroy(sqlite3 *db, FuncDef *p){
166971 FuncDestructor *pDestructor = p->u.pDestructor;
 
 
166972 if( pDestructor ){
166973 pDestructor->nRef--;
166974 if( pDestructor->nRef==0 ){
166975 pDestructor->xDestroy(pDestructor->pUserData);
166976 sqlite3DbFree(db, pDestructor);
@@ -168987,10 +169312,11 @@
168987 ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
168988 ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
168989 ** off all other flags.
168990 */
168991 flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
 
168992 SQLITE_OPEN_MAIN_DB |
168993 SQLITE_OPEN_TEMP_DB |
168994 SQLITE_OPEN_TRANSIENT_DB |
168995 SQLITE_OPEN_MAIN_JOURNAL |
168996 SQLITE_OPEN_TEMP_JOURNAL |
@@ -172095,10 +172421,11 @@
172095 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
172096 #ifdef SQLITE_TEST
172097 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*);
172098 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
172099 #endif
 
172100
172101 SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
172102 sqlite3_tokenizer_cursor **
172103 );
172104
@@ -177176,12 +177503,12 @@
177176 case FTSQUERY_OR: {
177177 Fts3Expr *pLeft = pExpr->pLeft;
177178 Fts3Expr *pRight = pExpr->pRight;
177179 sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
177180
177181 assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
177182 assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
177183
177184 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
177185 fts3EvalNextRow(pCsr, pLeft, pRc);
177186 }else if( pLeft->bEof || iCmp>0 ){
177187 fts3EvalNextRow(pCsr, pRight, pRc);
@@ -178617,11 +178944,11 @@
178617 /*
178618 ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
178619 ** zero the memory before returning a pointer to it. If unsuccessful,
178620 ** return NULL.
178621 */
178622 static void *fts3MallocZero(sqlite3_int64 nByte){
178623 void *pRet = sqlite3_malloc64(nByte);
178624 if( pRet ) memset(pRet, 0, nByte);
178625 return pRet;
178626 }
178627
@@ -178698,11 +179025,11 @@
178698 sqlite3_int64 nByte; /* total space to allocate */
178699
178700 rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
178701 if( rc==SQLITE_OK ){
178702 nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
178703 pRet = (Fts3Expr *)fts3MallocZero(nByte);
178704 if( !pRet ){
178705 rc = SQLITE_NOMEM;
178706 }else{
178707 pRet->eType = FTSQUERY_PHRASE;
178708 pRet->pPhrase = (Fts3Phrase *)&pRet[1];
@@ -178953,11 +179280,11 @@
178953 */
178954 cNext = zInput[nKey];
178955 if( fts3isspace(cNext)
178956 || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
178957 ){
178958 pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr));
178959 if( !pRet ){
178960 return SQLITE_NOMEM;
178961 }
178962 pRet->eType = pKey->eType;
178963 pRet->nNear = nNear;
@@ -179132,11 +179459,11 @@
179132
179133 if( !sqlite3_fts3_enable_parentheses
179134 && p->eType==FTSQUERY_PHRASE && pParse->isNot
179135 ){
179136 /* Create an implicit NOT operator. */
179137 Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr));
179138 if( !pNot ){
179139 sqlite3Fts3ExprFree(p);
179140 rc = SQLITE_NOMEM;
179141 goto exprparse_out;
179142 }
@@ -179166,11 +179493,11 @@
179166
179167 if( isPhrase && !isRequirePhrase ){
179168 /* Insert an implicit AND operator. */
179169 Fts3Expr *pAnd;
179170 assert( pRet && pPrev );
179171 pAnd = fts3MallocZero(sizeof(Fts3Expr));
179172 if( !pAnd ){
179173 sqlite3Fts3ExprFree(p);
179174 rc = SQLITE_NOMEM;
179175 goto exprparse_out;
179176 }
@@ -183396,12 +183723,22 @@
183396 pReader->aNode = 0;
183397 if( pElem ){
183398 char *aCopy;
183399 PendingList *pList = (PendingList *)fts3HashData(pElem);
183400 int nCopy = pList->nData+1;
183401 pReader->zTerm = (char *)fts3HashKey(pElem);
183402 pReader->nTerm = fts3HashKeysize(pElem);
 
 
 
 
 
 
 
 
 
 
183403 aCopy = (char*)sqlite3_malloc(nCopy);
183404 if( !aCopy ) return SQLITE_NOMEM;
183405 memcpy(aCopy, pList->aData, nCopy);
183406 pReader->nNode = pReader->nDoclist = nCopy;
183407 pReader->aNode = pReader->aDoclist = aCopy;
@@ -183650,13 +183987,11 @@
183650 ** Free all allocations associated with the iterator passed as the
183651 ** second argument.
183652 */
183653 SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){
183654 if( pReader ){
183655 if( !fts3SegReaderIsPending(pReader) ){
183656 sqlite3_free(pReader->zTerm);
183657 }
183658 if( !fts3SegReaderIsRootOnly(pReader) ){
183659 sqlite3_free(pReader->aNode);
183660 }
183661 sqlite3_blob_close(pReader->pBlob);
183662 }
@@ -188003,13 +188338,12 @@
188003 MatchinfoBuffer *pRet;
188004 sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
188005 + sizeof(MatchinfoBuffer);
188006 sqlite3_int64 nStr = strlen(zMatchinfo);
188007
188008 pRet = sqlite3_malloc64(nByte + nStr+1);
188009 if( pRet ){
188010 memset(pRet, 0, nByte);
188011 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
188012 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
188013 + sizeof(u32)*((int)nElem+1);
188014 pRet->nElem = (int)nElem;
188015 pRet->zMatchinfo = ((char*)pRet) + nByte;
@@ -188409,15 +188743,14 @@
188409
188410 /* Now that it is known how many phrases there are, allocate and zero
188411 ** the required space using malloc().
188412 */
188413 nByte = sizeof(SnippetPhrase) * nList;
188414 sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte);
188415 if( !sIter.aPhrase ){
188416 return SQLITE_NOMEM;
188417 }
188418 memset(sIter.aPhrase, 0, nByte);
188419
188420 /* Initialize the contents of the SnippetIter object. Then iterate through
188421 ** the set of phrases in the expression to populate the aPhrase[] array.
188422 */
188423 sIter.pCsr = pCsr;
@@ -189016,13 +189349,12 @@
189016 int rc = SQLITE_OK;
189017
189018 /* Allocate and populate the array of LcsIterator objects. The array
189019 ** contains one element for each matchable phrase in the query.
189020 **/
189021 aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase);
189022 if( !aIter ) return SQLITE_NOMEM;
189023 memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase);
189024 (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
189025
189026 for(i=0; i<pInfo->nPhrase; i++){
189027 LcsIterator *pIter = &aIter[i];
189028 nToken -= pIter->pExpr->pPhrase->nToken;
@@ -189479,11 +189811,11 @@
189479 /* Count the number of terms in the query */
189480 rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
189481 if( rc!=SQLITE_OK ) goto offsets_out;
189482
189483 /* Allocate the array of TermOffset iterators. */
189484 sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken);
189485 if( 0==sCtx.aTerm ){
189486 rc = SQLITE_NOMEM;
189487 goto offsets_out;
189488 }
189489 sCtx.iDocid = pCsr->iPrevId;
@@ -190517,11 +190849,25 @@
190517 # define NEVER(X) ((X)?(assert(0),1):0)
190518 # else
190519 # define ALWAYS(X) (X)
190520 # define NEVER(X) (X)
190521 # endif
 
190522 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
190523
190524 /* Objects */
190525 typedef struct JsonString JsonString;
190526 typedef struct JsonNode JsonNode;
190527 typedef struct JsonParse JsonParse;
@@ -190575,17 +190921,18 @@
190575 /* A single node of parsed JSON
190576 */
190577 struct JsonNode {
190578 u8 eType; /* One of the JSON_ type values */
190579 u8 jnFlags; /* JNODE flags */
 
190580 u32 n; /* Bytes of content, or number of sub-nodes */
190581 union {
190582 const char *zJContent; /* Content for INT, REAL, and STRING */
190583 u32 iAppend; /* More terms for ARRAY and OBJECT */
190584 u32 iKey; /* Key for ARRAY objects in json_tree() */
190585 u32 iReplace; /* Replacement content for JNODE_REPLACE */
190586 JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */
190587 } u;
190588 };
190589
190590 /* A completely parsed JSON string
190591 */
@@ -190862,13 +191209,15 @@
190862 sqlite3_value **aReplace /* Replacement values */
190863 ){
190864 assert( pNode!=0 );
190865 if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
190866 if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){
 
190867 jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
190868 return;
190869 }
 
190870 pNode = pNode->u.pPatch;
190871 }
190872 switch( pNode->eType ){
190873 default: {
190874 assert( pNode->eType==JSON_NULL );
@@ -190883,17 +191232,19 @@
190883 jsonAppendRaw(pOut, "false", 5);
190884 break;
190885 }
190886 case JSON_STRING: {
190887 if( pNode->jnFlags & JNODE_RAW ){
 
190888 jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
190889 break;
190890 }
190891 /* no break */ deliberate_fall_through
190892 }
190893 case JSON_REAL:
190894 case JSON_INT: {
 
190895 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
190896 break;
190897 }
190898 case JSON_ARRAY: {
190899 u32 j = 1;
@@ -190905,10 +191256,11 @@
190905 jsonRenderNode(&pNode[j], pOut, aReplace);
190906 }
190907 j += jsonNodeSize(&pNode[j]);
190908 }
190909 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
 
190910 pNode = &pNode[pNode->u.iAppend];
190911 j = 1;
190912 }
190913 jsonAppendChar(pOut, ']');
190914 break;
@@ -190925,10 +191277,11 @@
190925 jsonRenderNode(&pNode[j+1], pOut, aReplace);
190926 }
190927 j += 1 + jsonNodeSize(&pNode[j+1]);
190928 }
190929 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
 
190930 pNode = &pNode[pNode->u.iAppend];
190931 j = 1;
190932 }
190933 jsonAppendChar(pOut, '}');
190934 break;
@@ -191004,11 +191357,13 @@
191004 sqlite3_result_int(pCtx, 0);
191005 break;
191006 }
191007 case JSON_INT: {
191008 sqlite3_int64 i = 0;
191009 const char *z = pNode->u.zJContent;
 
 
191010 if( z[0]=='-' ){ z++; }
191011 while( z[0]>='0' && z[0]<='9' ){
191012 unsigned v = *(z++) - '0';
191013 if( i>=LARGEST_INT64/10 ){
191014 if( i>LARGEST_INT64/10 ) goto int_as_real;
@@ -191032,13 +191387,16 @@
191032 int_as_real: ; /* no break */ deliberate_fall_through
191033 }
191034 case JSON_REAL: {
191035 double r;
191036 #ifdef SQLITE_AMALGAMATION
191037 const char *z = pNode->u.zJContent;
 
 
191038 sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
191039 #else
 
191040 r = strtod(pNode->u.zJContent, 0);
191041 #endif
191042 sqlite3_result_double(pCtx, r);
191043 break;
191044 }
@@ -191045,26 +191403,30 @@
191045 case JSON_STRING: {
191046 #if 0 /* Never happens because JNODE_RAW is only set by json_set(),
191047 ** json_insert() and json_replace() and those routines do not
191048 ** call jsonReturn() */
191049 if( pNode->jnFlags & JNODE_RAW ){
 
191050 sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
191051 SQLITE_TRANSIENT);
191052 }else
191053 #endif
191054 assert( (pNode->jnFlags & JNODE_RAW)==0 );
191055 if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
191056 /* JSON formatted without any backslash-escapes */
 
191057 sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
191058 SQLITE_TRANSIENT);
191059 }else{
191060 /* Translate JSON formatted string into raw text */
191061 u32 i;
191062 u32 n = pNode->n;
191063 const char *z = pNode->u.zJContent;
191064 char *zOut;
191065 u32 j;
 
 
191066 zOut = sqlite3_malloc( n+1 );
191067 if( zOut==0 ){
191068 sqlite3_result_error_nomem(pCtx);
191069 break;
191070 }
@@ -191187,10 +191549,11 @@
191187 return jsonParseAddNodeExpand(pParse, eType, n, zContent);
191188 }
191189 p = &pParse->aNode[pParse->nNode];
191190 p->eType = (u8)eType;
191191 p->jnFlags = 0;
 
191192 p->n = n;
191193 p->u.zJContent = zContent;
191194 return pParse->nNode++;
191195 }
191196
@@ -191254,10 +191617,11 @@
191254 return j+1;
191255 }else if( c=='[' ){
191256 /* Parse array */
191257 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
191258 if( iThis<0 ) return -1;
 
191259 for(j=i+1;;j++){
191260 while( safe_isspace(z[j]) ){ j++; }
191261 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
191262 x = jsonParseValue(pParse, j);
191263 pParse->iDepth--;
@@ -191518,10 +191882,11 @@
191518 /*
191519 ** Compare the OBJECT label at pNode against zKey,nKey. Return true on
191520 ** a match.
191521 */
191522 static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
 
191523 if( pNode->jnFlags & JNODE_RAW ){
191524 if( pNode->n!=nKey ) return 0;
191525 return strncmp(pNode->u.zJContent, zKey, nKey)==0;
191526 }else{
191527 if( pNode->n!=nKey+2 ) return 0;
@@ -191583,10 +191948,11 @@
191583 }
191584 j++;
191585 j += jsonNodeSize(&pRoot[j]);
191586 }
191587 if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
 
191588 iRoot += pRoot->u.iAppend;
191589 pRoot = &pParse->aNode[iRoot];
191590 j = 1;
191591 }
191592 if( pApnd ){
@@ -191597,12 +191963,14 @@
191597 zPath += i;
191598 pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191599 if( pParse->oom ) return 0;
191600 if( pNode ){
191601 pRoot = &pParse->aNode[iRoot];
 
191602 pRoot->u.iAppend = iStart - iRoot;
191603 pRoot->jnFlags |= JNODE_APPEND;
 
191604 pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
191605 }
191606 return pNode;
191607 }
191608 }else if( zPath[0]=='[' ){
@@ -191621,10 +191989,11 @@
191621 while( j<=pBase->n ){
191622 if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
191623 j += jsonNodeSize(&pBase[j]);
191624 }
191625 if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
 
191626 iBase += pBase->u.iAppend;
191627 pBase = &pParse->aNode[iBase];
191628 j = 1;
191629 }
191630 j = 2;
@@ -191654,10 +192023,11 @@
191654 while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
191655 if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
191656 j += jsonNodeSize(&pRoot[j]);
191657 }
191658 if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
 
191659 iRoot += pRoot->u.iAppend;
191660 pRoot = &pParse->aNode[iRoot];
191661 j = 1;
191662 }
191663 if( j<=pRoot->n ){
@@ -191669,12 +192039,14 @@
191669 iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0);
191670 pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191671 if( pParse->oom ) return 0;
191672 if( pNode ){
191673 pRoot = &pParse->aNode[iRoot];
 
191674 pRoot->u.iAppend = iStart - iRoot;
191675 pRoot->jnFlags |= JNODE_APPEND;
 
191676 }
191677 return pNode;
191678 }
191679 }else{
191680 *pzErr = zPath;
@@ -191824,13 +192196,17 @@
191824 }else{
191825 zType = jsonType[x.aNode[i].eType];
191826 }
191827 jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d",
191828 i, zType, x.aNode[i].n, x.aUp[i]);
 
191829 if( x.aNode[i].u.zJContent!=0 ){
 
191830 jsonAppendRaw(&s, " ", 1);
191831 jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n);
 
 
191832 }
191833 jsonAppendRaw(&s, "\n", 1);
191834 }
191835 jsonParseReset(&x);
191836 jsonResult(&s);
@@ -192009,10 +192385,11 @@
192009 for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){
192010 u32 nKey;
192011 const char *zKey;
192012 assert( pPatch[i].eType==JSON_STRING );
192013 assert( pPatch[i].jnFlags & JNODE_LABEL );
 
192014 nKey = pPatch[i].n;
192015 zKey = pPatch[i].u.zJContent;
192016 assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
192017 for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
192018 assert( pTarget[j].eType==JSON_STRING );
@@ -192025,10 +192402,13 @@
192025 }else{
192026 JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
192027 if( pNew==0 ) return 0;
192028 pTarget = &pParse->aNode[iTarget];
192029 if( pNew!=&pTarget[j+1] ){
 
 
 
192030 pTarget[j+1].u.pPatch = pNew;
192031 pTarget[j+1].jnFlags |= JNODE_PATCH;
192032 }
192033 }
192034 break;
@@ -192040,13 +192420,18 @@
192040 jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
192041 iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
192042 if( pParse->oom ) return 0;
192043 jsonRemoveAllNulls(pPatch);
192044 pTarget = &pParse->aNode[iTarget];
 
 
192045 pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
 
192046 pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
192047 iRoot = iStart;
 
 
192048 pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
192049 pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
192050 }
192051 }
192052 return pTarget;
@@ -192184,15 +192569,19 @@
192184 for(i=1; i<(u32)argc; i+=2){
192185 zPath = (const char*)sqlite3_value_text(argv[i]);
192186 pNode = jsonLookup(&x, zPath, 0, ctx);
192187 if( x.nErr ) goto replace_err;
192188 if( pNode ){
 
 
192189 pNode->jnFlags |= (u8)JNODE_REPLACE;
 
192190 pNode->u.iReplace = i + 1;
192191 }
192192 }
192193 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
 
192194 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192195 }else{
192196 jsonReturnJson(x.aNode, ctx, argv);
192197 }
192198 replace_err:
@@ -192238,15 +192627,19 @@
192238 sqlite3_result_error_nomem(ctx);
192239 goto jsonSetDone;
192240 }else if( x.nErr ){
192241 goto jsonSetDone;
192242 }else if( pNode && (bApnd || bIsSet) ){
 
 
 
192243 pNode->jnFlags |= (u8)JNODE_REPLACE;
192244 pNode->u.iReplace = i + 1;
192245 }
192246 }
192247 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
 
192248 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192249 }else{
192250 jsonReturnJson(x.aNode, ctx, argv);
192251 }
192252 jsonSetDone:
@@ -192593,10 +192986,13 @@
192593 if( p->i<p->iEnd ){
192594 u32 iUp = p->sParse.aUp[p->i];
192595 JsonNode *pUp = &p->sParse.aNode[iUp];
192596 p->eType = pUp->eType;
192597 if( pUp->eType==JSON_ARRAY ){
 
 
 
192598 if( iUp==p->i-1 ){
192599 pUp->u.iKey = 0;
192600 }else{
192601 pUp->u.iKey++;
192602 }
@@ -192639,16 +193035,19 @@
192639 iUp = p->sParse.aUp[i];
192640 jsonEachComputePath(p, pStr, iUp);
192641 pNode = &p->sParse.aNode[i];
192642 pUp = &p->sParse.aNode[iUp];
192643 if( pUp->eType==JSON_ARRAY ){
 
 
192644 jsonPrintf(30, pStr, "[%d]", pUp->u.iKey);
192645 }else{
192646 assert( pUp->eType==JSON_OBJECT );
192647 if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
192648 assert( pNode->eType==JSON_STRING );
192649 assert( pNode->jnFlags & JNODE_LABEL );
 
192650 jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
192651 }
192652 }
192653
192654 /* Return the value of a column */
@@ -192666,10 +193065,11 @@
192666 jsonReturn(pThis, ctx, 0);
192667 }else if( p->eType==JSON_ARRAY ){
192668 u32 iKey;
192669 if( p->bRecursive ){
192670 if( p->iRowid==0 ) break;
 
192671 iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey;
192672 }else{
192673 iKey = p->iRowid;
192674 }
192675 sqlite3_result_int64(ctx, (sqlite3_int64)iKey);
@@ -192715,10 +193115,11 @@
192715 jsonAppendChar(&x, '$');
192716 }
192717 if( p->eType==JSON_ARRAY ){
192718 jsonPrintf(30, &x, "[%d]", p->iRowid);
192719 }else if( p->eType==JSON_OBJECT ){
 
192720 jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
192721 }
192722 }
192723 jsonResult(&x);
192724 break;
@@ -192782,10 +193183,11 @@
192782 int iCol;
192783 int iMask;
192784 if( pConstraint->iColumn < JEACH_JSON ) continue;
192785 iCol = pConstraint->iColumn - JEACH_JSON;
192786 assert( iCol==0 || iCol==1 );
 
192787 iMask = 1 << iCol;
192788 if( pConstraint->usable==0 ){
192789 unusableMask |= iMask;
192790 }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
192791 aIdx[iCol] = i;
@@ -192879,10 +193281,12 @@
192879 pNode = p->sParse.aNode;
192880 }
192881 p->iBegin = p->i = (int)(pNode - p->sParse.aNode);
192882 p->eType = pNode->eType;
192883 if( p->eType>=JSON_ARRAY ){
 
 
192884 pNode->u.iKey = 0;
192885 p->iEnd = p->i + pNode->n + 1;
192886 if( p->bRecursive ){
192887 p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType;
192888 if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){
@@ -193493,11 +193897,11 @@
193493
193494 /* The testcase() macro should already be defined in the amalgamation. If
193495 ** it is not, make it a no-op.
193496 */
193497 #ifndef SQLITE_AMALGAMATION
193498 # ifdef SQLITE_COVERAGE_TEST
193499 unsigned int sqlite3RtreeTestcase = 0;
193500 # define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; }
193501 # else
193502 # define testcase(X)
193503 # endif
@@ -214008,11 +214412,11 @@
214008
214009 /*
214010 ** A version of memcmp() that does not cause asan errors if one of the pointer
214011 ** parameters is NULL and the number of bytes to compare is zero.
214012 */
214013 #define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
214014
214015 /* Mark a function parameter as unused, to suppress nuisance compiler
214016 ** warnings. */
214017 #ifndef UNUSED_PARAM
214018 # define UNUSED_PARAM(X) (void)(X)
@@ -217034,11 +217438,10 @@
217034 int *pRc,
217035 Fts5Buffer *pBuf,
217036 u32 nData,
217037 const u8 *pData
217038 ){
217039 assert_nc( *pRc || nData>=0 );
217040 if( nData ){
217041 if( fts5BufferGrow(pRc, pBuf, nData) ) return;
217042 memcpy(&pBuf->p[pBuf->n], pData, nData);
217043 pBuf->n += nData;
217044 }
@@ -217146,11 +217549,10 @@
217146 return 1;
217147 }else{
217148 i64 iOff = *piOff;
217149 u32 iVal;
217150 fts5FastGetVarint32(a, i, iVal);
217151 assert( iVal>=0 );
217152 if( iVal<=1 ){
217153 if( iVal==0 ){
217154 *pi = i;
217155 return 0;
217156 }
@@ -221761,11 +222163,11 @@
221761 if( iCol>=0 ){
221762 if( pHash->eDetail==FTS5_DETAIL_NONE ){
221763 p->bContent = 1;
221764 }else{
221765 /* Append a new column value, if necessary */
221766 assert( iCol>=p->iCol );
221767 if( iCol!=p->iCol ){
221768 if( pHash->eDetail==FTS5_DETAIL_FULL ){
221769 pPtr[p->nData++] = 0x01;
221770 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
221771 p->iCol = (i16)iCol;
@@ -222566,12 +222968,15 @@
222566 ** +ve if pRight is smaller than pLeft. In other words:
222567 **
222568 ** res = *pLeft - *pRight
222569 */
222570 static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
222571 int nCmp = MIN(pLeft->n, pRight->n);
222572 int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
 
 
 
222573 return (res==0 ? (pLeft->n - pRight->n) : res);
222574 }
222575
222576 static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
222577 int ret;
@@ -224244,25 +224649,24 @@
224244 Fts5Index *p, /* Leave any error code here */
224245 int bGe, /* True for a >= search */
224246 Fts5SegIter *pIter, /* Iterator to seek */
224247 const u8 *pTerm, int nTerm /* Term to search for */
224248 ){
224249 int iOff;
224250 const u8 *a = pIter->pLeaf->p;
224251 int szLeaf = pIter->pLeaf->szLeaf;
224252 int n = pIter->pLeaf->nn;
224253
224254 u32 nMatch = 0;
224255 u32 nKeep = 0;
224256 u32 nNew = 0;
224257 u32 iTermOff;
224258 int iPgidx; /* Current offset in pgidx */
224259 int bEndOfPage = 0;
224260
224261 assert( p->rc==SQLITE_OK );
224262
224263 iPgidx = szLeaf;
224264 iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
224265 iOff = iTermOff;
224266 if( iOff>n ){
224267 p->rc = FTS5_CORRUPT;
224268 return;
@@ -224324,19 +224728,19 @@
224324 do {
224325 fts5SegIterNextPage(p, pIter);
224326 if( pIter->pLeaf==0 ) return;
224327 a = pIter->pLeaf->p;
224328 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
224329 iPgidx = pIter->pLeaf->szLeaf;
224330 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
224331 if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
224332 p->rc = FTS5_CORRUPT;
224333 return;
224334 }else{
224335 nKeep = 0;
224336 iTermOff = iOff;
224337 n = pIter->pLeaf->nn;
224338 iOff += fts5GetVarint32(&a[iOff], nNew);
224339 break;
224340 }
224341 }
224342 }while( 1 );
@@ -231573,11 +231977,11 @@
231573 int nArg, /* Number of args */
231574 sqlite3_value **apUnused /* Function arguments */
231575 ){
231576 assert( nArg==0 );
231577 UNUSED_PARAM2(nArg, apUnused);
231578 sqlite3_result_text(pCtx, "fts5: 2021-10-05 18:33:38 a7835bead85b1b18a8affd9835240b0baf9c7af887196bbdcc3f5d58055042fc", -1, SQLITE_TRANSIENT);
231579 }
231580
231581 /*
231582 ** Return true if zName is the extension on one of the shadow tables used
231583 ** by this module.
231584
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.37.0"
456 #define SQLITE_VERSION_NUMBER 3037000
457 #define SQLITE_SOURCE_ID "2021-10-21 20:08:00 559ba38b8a0f7795d781838ec78969874fd678f749b26cd49cf6112afc838732"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -843,11 +843,10 @@
843 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
844 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
845 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
846 #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
847 #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
 
848 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
849 #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
850 #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
851 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
852 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
@@ -879,10 +878,23 @@
878 ** CAPI3REF: Flags For File Open Operations
879 **
880 ** These bit values are intended for use in the
881 ** 3rd parameter to the [sqlite3_open_v2()] interface and
882 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
883 **
884 ** Only those flags marked as "Ok for sqlite3_open_v2()" may be
885 ** used as the third argument to the [sqlite3_open_v2()] interface.
886 ** The other flags have historically been ignored by sqlite3_open_v2(),
887 ** though future versions of SQLite might change so that an error is
888 ** raised if any of the disallowed bits are passed into sqlite3_open_v2().
889 ** Applications should not depend on the historical behavior.
890 **
891 ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
892 ** [sqlite3_open_v2()] does *not* cause the underlying database file
893 ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
894 ** [sqlite3_open_v2()] has historically be a no-op and might become an
895 ** error in future versions of SQLite.
896 */
897 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
898 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
899 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
900 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
@@ -3723,22 +3735,24 @@
3735 ** the default shared cache setting provided by
3736 ** [sqlite3_enable_shared_cache()].)^
3737 **
3738 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3739 ** <dd>The database filename is not allowed to be a symbolic link</dd>
 
 
 
 
 
 
3740 ** </dl>)^
3741 **
3742 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3743 ** required combinations shown above optionally combined with other
3744 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3745 ** then the behavior is undefined. Historic versions of SQLite
3746 ** have silently ignored surplus bits in the flags parameter to
3747 ** sqlite3_open_v2(), however that behavior might not be carried through
3748 ** into future versions of SQLite and so applications should not rely
3749 ** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3750 ** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
3751 ** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
3752 ** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3753 ** by sqlite3_open_v2().
3754 **
3755 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3756 ** [sqlite3_vfs] object that defines the operating system interface that
3757 ** the new database connection should use. ^If the fourth parameter is
3758 ** a NULL pointer then the default [sqlite3_vfs] object is used.
@@ -13162,13 +13176,15 @@
13176 ** is significant and used at least once. On switch statements
13177 ** where multiple cases go to the same block of code, testcase()
13178 ** can insure that all cases are evaluated.
13179 **
13180 */
13181 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
13182 # ifndef SQLITE_AMALGAMATION
13183 extern unsigned int sqlite3CoverageCounter;
13184 # endif
13185 # define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; }
13186 #else
13187 # define testcase(X)
13188 #endif
13189
13190 /*
@@ -13228,30 +13244,10 @@
13244 #else
13245 # define ALWAYS(X) (X)
13246 # define NEVER(X) (X)
13247 #endif
13248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13249 /*
13250 ** Some conditionals are optimizations only. In other words, if the
13251 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
13252 ** the correct answer is still obtained, though perhaps not as quickly.
13253 **
@@ -13430,11 +13426,11 @@
13426 /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */
13427
13428 /*
13429 ** Number of entries in a hash table
13430 */
13431 #define sqliteHashCount(H) ((H)->count)
13432
13433 #endif /* SQLITE_HASH_H */
13434
13435 /************** End of hash.h ************************************************/
13436 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -16428,14 +16424,14 @@
16424 int nVdbeExec; /* Number of nested calls to VdbeExec() */
16425 int nVDestroy; /* Number of active OP_VDestroy operations */
16426 int nExtension; /* Number of loaded extensions */
16427 void **aExtension; /* Array of shared library handles */
16428 union {
16429 void (*xLegacy)(void*,const char*); /* mTrace==SQLITE_TRACE_LEGACY */
16430 int (*xV2)(u32,void*,void*,void*); /* All other mTrace values */
16431 } trace;
16432 void *pTraceArg; /* Argument to the trace function */
16433 #ifndef SQLITE_OMIT_DEPRECATED
16434 void (*xProfile)(void*,const char*,u64); /* Profiling function */
16435 void *pProfileArg; /* Argument to profile function */
16436 #endif
16437 void *pCommitArg; /* Argument to xCommitCallback() */
@@ -16667,11 +16663,11 @@
16663 void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */
16664 const char *zName; /* SQL name of the function. */
16665 union {
16666 FuncDef *pHash; /* Next with a different name but the same hash */
16667 FuncDestructor *pDestructor; /* Reference counted destructor function */
16668 } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */
16669 };
16670
16671 /*
16672 ** This structure encapsulates a user-function destructor callback (as
16673 ** configured using create_function_v2()) and a reference counter. When
@@ -16728,10 +16724,11 @@
16724 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
16725 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
16726 #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
16727 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
16728 #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
16729 #define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */
16730 #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */
16731
16732 /* Identifier numbers for each in-line function */
16733 #define INLINEFUNC_coalesce 0
16734 #define INLINEFUNC_implies_nonnull_row 1
@@ -16806,48 +16803,55 @@
16803 ** available as the function user-data (sqlite3_user_data()). The
16804 ** FuncDef.flags variable is set to the value passed as the flags
16805 ** parameter.
16806 */
16807 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
16808 {nArg, SQLITE_FUNC_BUILTIN|\
16809 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16810 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16811 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16812 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16813 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16814 #define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16815 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
16816 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16817 #define MFUNCTION(zName, nArg, xPtr, xFunc) \
16818 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
16819 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
16820 #define INLINE_FUNC(zName, nArg, iArg, mFlags) \
16821 {nArg, SQLITE_FUNC_BUILTIN|\
16822 SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16823 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16824 #define TEST_FUNC(zName, nArg, iArg, mFlags) \
16825 {nArg, SQLITE_FUNC_BUILTIN|\
16826 SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
16827 SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16828 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16829 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16830 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
16831 0, 0, xFunc, 0, 0, 0, #zName, {0} }
16832 #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
16833 {nArg, SQLITE_FUNC_BUILTIN|\
16834 SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
16835 (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
16836 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
16837 {nArg, SQLITE_FUNC_BUILTIN|\
16838 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
16839 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16840 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
16841 {nArg, SQLITE_FUNC_BUILTIN|\
16842 SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16843 pArg, 0, xFunc, 0, 0, 0, #zName, }
16844 #define LIKEFUNC(zName, nArg, arg, flags) \
16845 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
16846 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
16847 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
16848 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
16849 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
16850 #define INTERNAL_FUNCTION(zName, nArg, xFunc) \
16851 {nArg, SQLITE_FUNC_BUILTIN|\
16852 SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
16853 0, 0, xFunc, 0, 0, 0, #zName, {0} }
16854
16855
16856 /*
16857 ** All current savepoints are stored in a linked list starting at
@@ -17566,14 +17570,14 @@
17570 ** code representing the ">=" operator. This same integer code is reused
17571 ** to represent the greater-than-or-equal-to operator in the expression
17572 ** tree.
17573 **
17574 ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
17575 ** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If
17576 ** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the
17577 ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
17578 ** then Expr.u.zToken contains the name of the function.
17579 **
17580 ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
17581 ** binary operator. Either or both may be NULL.
17582 **
17583 ** Expr.x.pList is a list of arguments if the expression is an SQL function,
@@ -17609,11 +17613,11 @@
17613 **
17614 ** Expr objects can use a lot of memory space in database schema. To
17615 ** help reduce memory requirements, sometimes an Expr object will be
17616 ** truncated. And to reduce the number of memory allocations, sometimes
17617 ** two or more Expr objects will be stored in a single memory allocation,
17618 ** together with Expr.u.zToken strings.
17619 **
17620 ** If the EP_Reduced and EP_TokenOnly flags are set when
17621 ** an Expr object is truncated. When EP_Reduced is set, then all
17622 ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
17623 ** are contained within the same memory allocation. Note, however, that
@@ -17678,12 +17682,11 @@
17682 int regReturn; /* Register used to hold return address */
17683 } sub;
17684 } y;
17685 };
17686
17687 /* The following are the meanings of bits in the Expr.flags field.
 
17688 ** Value restrictions:
17689 **
17690 ** EP_Agg == NC_HasAgg == SF_HasAgg
17691 ** EP_Win == NC_HasWin
17692 */
@@ -17718,27 +17721,35 @@
17721 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
17722 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
17723 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
17724 /* 0x80000000 // Available */
17725
17726 /* The EP_Propagate mask is a set of properties that automatically propagate
 
17727 ** upwards into parent nodes.
17728 */
17729 #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
17730
17731 /* Macros can be used to test, set, or clear bits in the
 
17732 ** Expr.flags field.
17733 */
17734 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
17735 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
17736 #define ExprSetProperty(E,P) (E)->flags|=(P)
17737 #define ExprClearProperty(E,P) (E)->flags&=~(P)
17738 #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
17739 #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
17740
17741 /* Macros used to ensure that the correct members of unions are accessed
17742 ** in Expr.
17743 */
17744 #define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
17745 #define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0)
17746 #define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0)
17747 #define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0)
17748 #define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0)
17749 #define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0)
17750 #define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0)
17751
17752 /* Flags for use with Expr.vvaFlags
17753 */
17754 #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */
17755 #define EP_Immutable 0x02 /* Do not change this Expr node */
@@ -17817,15 +17828,16 @@
17828 unsigned done :1; /* A flag to indicate when processing is finished */
17829 unsigned reusable :1; /* Constant expression is reusable */
17830 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
17831 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
17832 union {
17833 struct { /* Used by any ExprList other than Parse.pConsExpr */
17834 u16 iOrderByCol; /* For ORDER BY, column number in result set */
17835 u16 iAlias; /* Index into Parse.aAlias[] for zName */
17836 } x;
17837 int iConstExprReg; /* Register in which Expr value is cached. Used only
17838 ** by Parse.pConstExpr */
17839 } u;
17840 } a[1]; /* One slot for each expression in the list */
17841 };
17842
17843 /*
@@ -17859,10 +17871,17 @@
17871 };
17872
17873 /*
17874 ** The SrcItem object represents a single term in the FROM clause of a query.
17875 ** The SrcList object is mostly an array of SrcItems.
17876 **
17877 ** Union member validity:
17878 **
17879 ** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc
17880 ** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy
17881 ** u2.pIBIndex fg.isIndexedBy && !fg.isCte
17882 ** u2.pCteUse fg.isCte && !fg.isIndexedBy
17883 */
17884 struct SrcItem {
17885 Schema *pSchema; /* Schema to which this item is fixed */
17886 char *zDatabase; /* Name of database holding this table */
17887 char *zName; /* Name of the table */
@@ -18453,10 +18472,12 @@
18472 #ifndef SQLITE_OMIT_ALTERTABLE
18473 RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
18474 #endif
18475 };
18476
18477 /* Allowed values for Parse.eParseMode
18478 */
18479 #define PARSE_MODE_NORMAL 0
18480 #define PARSE_MODE_DECLARE_VTAB 1
18481 #define PARSE_MODE_RENAME 2
18482 #define PARSE_MODE_UNMAP 3
18483
@@ -20109,12 +20130,12 @@
20130 ** All of this is no-op for a production build. It only comes into
20131 ** play when the SQLITE_MEMDEBUG compile-time option is used.
20132 */
20133 #ifdef SQLITE_MEMDEBUG
20134 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
20135 SQLITE_PRIVATE int sqlite3MemdebugHasType(const void*,u8);
20136 SQLITE_PRIVATE int sqlite3MemdebugNoType(const void*,u8);
20137 #else
20138 # define sqlite3MemdebugSetType(X,Y) /* no-op */
20139 # define sqlite3MemdebugHasType(X,Y) 1
20140 # define sqlite3MemdebugNoType(X,Y) 1
20141 #endif
@@ -21433,10 +21454,16 @@
21454 ** database connections. After initialization, this table is
21455 ** read-only.
21456 */
21457 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
21458
21459 /*
21460 ** Counter used for coverage testing. Does not come into play for
21461 ** release builds.
21462 */
21463 SQLITE_PRIVATE unsigned int sqlite3CoverageCounter;
21464
21465 #ifdef VDBE_PROFILE
21466 /*
21467 ** The following performance counter can be used in place of
21468 ** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
21469 */
@@ -24817,11 +24844,11 @@
24844 ** Given an allocation, find the MemBlockHdr for that allocation.
24845 **
24846 ** This routine checks the guards at either end of the allocation and
24847 ** if they are incorrect it asserts.
24848 */
24849 static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){
24850 struct MemBlockHdr *p;
24851 int *pInt;
24852 u8 *pU8;
24853 int nReserve;
24854
@@ -25064,11 +25091,11 @@
25091 ** This routine is designed for use within an assert() statement, to
25092 ** verify the type of an allocation. For example:
25093 **
25094 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
25095 */
25096 SQLITE_PRIVATE int sqlite3MemdebugHasType(const void *p, u8 eType){
25097 int rc = 1;
25098 if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
25099 struct MemBlockHdr *pHdr;
25100 pHdr = sqlite3MemsysGetHeader(p);
25101 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -25086,11 +25113,11 @@
25113 ** This routine is designed for use within an assert() statement, to
25114 ** verify the type of an allocation. For example:
25115 **
25116 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
25117 */
25118 SQLITE_PRIVATE int sqlite3MemdebugNoType(const void *p, u8 eType){
25119 int rc = 1;
25120 if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
25121 struct MemBlockHdr *pHdr;
25122 pHdr = sqlite3MemsysGetHeader(p);
25123 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -30551,10 +30578,11 @@
30578 zOp2[0] = 0;
30579 }
30580 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
30581 pExpr->iColumn, zFlgs, zOp2);
30582 }else{
30583 assert( ExprUseYTab(pExpr) );
30584 sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
30585 pExpr->iTable, pExpr->iColumn,
30586 pExpr->y.pTab, zFlgs);
30587 }
30588 if( ExprHasProperty(pExpr, EP_FixedCol) ){
@@ -30570,15 +30598,17 @@
30598 }
30599 break;
30600 }
30601 #ifndef SQLITE_OMIT_FLOATING_POINT
30602 case TK_FLOAT: {
30603 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30604 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
30605 break;
30606 }
30607 #endif
30608 case TK_STRING: {
30609 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30610 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
30611 break;
30612 }
30613 case TK_NULL: {
30614 sqlite3TreeViewLine(pView,"NULL");
@@ -30589,30 +30619,34 @@
30619 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
30620 break;
30621 }
30622 #ifndef SQLITE_OMIT_BLOB_LITERAL
30623 case TK_BLOB: {
30624 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30625 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
30626 break;
30627 }
30628 #endif
30629 case TK_VARIABLE: {
30630 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30631 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
30632 pExpr->u.zToken, pExpr->iColumn);
30633 break;
30634 }
30635 case TK_REGISTER: {
30636 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
30637 break;
30638 }
30639 case TK_ID: {
30640 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30641 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
30642 break;
30643 }
30644 #ifndef SQLITE_OMIT_CAST
30645 case TK_CAST: {
30646 /* Expressions of the form: CAST(pLeft AS token) */
30647 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30648 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
30649 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30650 break;
30651 }
30652 #endif /* SQLITE_OMIT_CAST */
@@ -30658,10 +30692,11 @@
30692 zUniOp = azOp[x];
30693 break;
30694 }
30695
30696 case TK_SPAN: {
30697 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30698 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
30699 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30700 break;
30701 }
30702
@@ -30669,10 +30704,11 @@
30704 /* COLLATE operators without the EP_Collate flag are intended to
30705 ** emulate collation associated with a table column. These show
30706 ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE
30707 ** operators that appear in the original SQL always have the
30708 ** EP_Collate bit set and appear in treeview output as just "COLLATE" */
30709 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30710 sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s",
30711 !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "",
30712 pExpr->u.zToken, zFlgs);
30713 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30714 break;
@@ -30684,17 +30720,19 @@
30720 Window *pWin;
30721 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
30722 pFarg = 0;
30723 pWin = 0;
30724 }else{
30725 assert( ExprUseXList(pExpr) );
30726 pFarg = pExpr->x.pList;
30727 #ifndef SQLITE_OMIT_WINDOWFUNC
30728 pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
30729 #else
30730 pWin = 0;
30731 #endif
30732 }
30733 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30734 if( pExpr->op==TK_AGG_FUNCTION ){
30735 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
30736 pExpr->op2, pExpr->u.zToken, zFlgs,
30737 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
30738 pExpr->iAgg, pExpr->pAggInfo);
@@ -30722,23 +30760,25 @@
30760 #endif
30761 break;
30762 }
30763 #ifndef SQLITE_OMIT_SUBQUERY
30764 case TK_EXISTS: {
30765 assert( ExprUseXSelect(pExpr) );
30766 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
30767 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30768 break;
30769 }
30770 case TK_SELECT: {
30771 assert( ExprUseXSelect(pExpr) );
30772 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
30773 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30774 break;
30775 }
30776 case TK_IN: {
30777 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
30778 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30779 if( ExprUseXSelect(pExpr) ){
30780 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30781 }else{
30782 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
30783 }
30784 break;
@@ -30755,13 +30795,16 @@
30795 ** X is stored in pExpr->pLeft.
30796 ** Y is stored in pExpr->pList->a[0].pExpr.
30797 ** Z is stored in pExpr->pList->a[1].pExpr.
30798 */
30799 case TK_BETWEEN: {
30800 const Expr *pX, *pY, *pZ;
30801 pX = pExpr->pLeft;
30802 assert( ExprUseXList(pExpr) );
30803 assert( pExpr->x.pList->nExpr==2 );
30804 pY = pExpr->x.pList->a[0].pExpr;
30805 pZ = pExpr->x.pList->a[1].pExpr;
30806 sqlite3TreeViewLine(pView, "BETWEEN");
30807 sqlite3TreeViewExpr(pView, pX, 1);
30808 sqlite3TreeViewExpr(pView, pY, 1);
30809 sqlite3TreeViewExpr(pView, pZ, 0);
30810 break;
@@ -30779,10 +30822,11 @@
30822 break;
30823 }
30824 case TK_CASE: {
30825 sqlite3TreeViewLine(pView, "CASE");
30826 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30827 assert( ExprUseXList(pExpr) );
30828 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
30829 break;
30830 }
30831 #ifndef SQLITE_OMIT_TRIGGER
30832 case TK_RAISE: {
@@ -30791,10 +30835,11 @@
30835 case OE_Rollback: zType = "rollback"; break;
30836 case OE_Abort: zType = "abort"; break;
30837 case OE_Fail: zType = "fail"; break;
30838 case OE_Ignore: zType = "ignore"; break;
30839 }
30840 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30841 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
30842 break;
30843 }
30844 #endif
30845 case TK_MATCH: {
@@ -30803,18 +30848,20 @@
30848 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
30849 break;
30850 }
30851 case TK_VECTOR: {
30852 char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
30853 assert( ExprUseXList(pExpr) );
30854 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
30855 sqlite3_free(z);
30856 break;
30857 }
30858 case TK_SELECT_COLUMN: {
30859 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s",
30860 pExpr->iColumn, pExpr->iTable-1,
30861 pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : "");
30862 assert( ExprUseXSelect(pExpr->pLeft) );
30863 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
30864 break;
30865 }
30866 case TK_IF_NULL_ROW: {
30867 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
@@ -31887,20 +31934,10 @@
31934 /* #include <stdarg.h> */
31935 #ifndef SQLITE_OMIT_FLOATING_POINT
31936 #include <math.h>
31937 #endif
31938
 
 
 
 
 
 
 
 
 
 
31939 /*
31940 ** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
31941 ** or to bypass normal error detection during testing in order to let
31942 ** execute proceed futher downstream.
31943 **
@@ -32143,10 +32180,11 @@
32180 }
32181 }
32182 z[j] = 0;
32183 }
32184 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
32185 assert( !ExprHasProperty(p, EP_IntValue) );
32186 assert( sqlite3Isquote(p->u.zToken[0]) );
32187 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
32188 sqlite3Dequote(p->u.zToken);
32189 }
32190
@@ -40270,12 +40308,10 @@
40308 if( fd<0 ){
40309 if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
40310 /* If unable to create a journal because the directory is not
40311 ** writable, change the error code to indicate that. */
40312 rc = SQLITE_READONLY_DIRECTORY;
 
 
40313 }else if( errno!=EISDIR && isReadWrite ){
40314 /* Failed to open the file for read/write access. Try read-only. */
40315 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
40316 openFlags &= ~(O_RDWR|O_CREAT);
40317 flags |= SQLITE_OPEN_READONLY;
@@ -59613,11 +59649,11 @@
59649 */
59650 pPg->flags &= ~PGHDR_NEED_SYNC;
59651 pPgOld = sqlite3PagerLookup(pPager, pgno);
59652 assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
59653 if( pPgOld ){
59654 if( NEVER(pPgOld->nRef>1) ){
59655 sqlite3PagerUnrefNotNull(pPgOld);
59656 return SQLITE_CORRUPT_BKPT;
59657 }
59658 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
59659 if( pPager->tempFile ){
@@ -64637,11 +64673,10 @@
64673 ** Access to all fields of this structure is controlled by the mutex
64674 ** stored in MemPage.pBt->mutex.
64675 */
64676 struct MemPage {
64677 u8 isInit; /* True if previously initialized. MUST BE FIRST! */
 
64678 u8 intKey; /* True if table b-trees. False for index b-trees */
64679 u8 intKeyLeaf; /* True if the leaf of an intKey table */
64680 Pgno pgno; /* Page number for this page */
64681 /* Only the first 8 bytes (above) are zeroed by pager.c when a new page
64682 ** is allocated. All fields that follow must be initialized before use */
@@ -70227,11 +70262,13 @@
70262 #endif
70263
70264 assert( pPage );
70265 assert( eOp==0 || eOp==1 );
70266 assert( pCur->eState==CURSOR_VALID );
70267 if( pCur->ix>=pPage->nCell ){
70268 return SQLITE_CORRUPT_PAGE(pPage);
70269 }
70270 assert( cursorHoldsMutex(pCur) );
70271
70272 getCellInfo(pCur);
70273 aPayload = pCur->info.pPayload;
70274 assert( offset+amt <= pCur->info.nPayload );
@@ -70414,11 +70451,10 @@
70451 */
70452 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
70453 assert( cursorHoldsMutex(pCur) );
70454 assert( pCur->eState==CURSOR_VALID );
70455 assert( pCur->iPage>=0 && pCur->pPage );
 
70456 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
70457 }
70458
70459 /*
70460 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -70476,11 +70512,11 @@
70512 int amt;
70513 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
70514 assert( pCur->eState==CURSOR_VALID );
70515 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
70516 assert( cursorOwnsBtShared(pCur) );
70517 assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
70518 assert( pCur->info.nSize>0 );
70519 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
70520 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
70521 amt = pCur->info.nLocal;
70522 if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
@@ -71262,20 +71298,10 @@
71298 ** module cov1/btree78.test testcase 220 (2018-06-08) for an
71299 ** example. */
71300 return SQLITE_CORRUPT_BKPT;
71301 }
71302
 
 
 
 
 
 
 
 
 
 
71303 if( idx>=pPage->nCell ){
71304 if( !pPage->leaf ){
71305 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
71306 if( rc ) return rc;
71307 return moveToLeftmost(pCur);
@@ -71759,11 +71785,11 @@
71785
71786 assert( sqlite3_mutex_held(pBt->mutex) );
71787 assert( CORRUPT_DB || iPage>1 );
71788 assert( !pMemPage || pMemPage->pgno==iPage );
71789
71790 if( NEVER(iPage<2) || iPage>pBt->nPage ){
71791 return SQLITE_CORRUPT_BKPT;
71792 }
71793 if( pMemPage ){
71794 pPage = pMemPage;
71795 sqlite3PagerRef(pPage->pDbPage);
@@ -74360,11 +74386,14 @@
74386 assert( szNew==pPage->xCellSize(pPage, newCell) );
74387 assert( szNew <= MX_CELL_SIZE(pBt) );
74388 idx = pCur->ix;
74389 if( loc==0 ){
74390 CellInfo info;
74391 assert( idx>=0 );
74392 if( idx>=pPage->nCell ){
74393 return SQLITE_CORRUPT_BKPT;
74394 }
74395 rc = sqlite3PagerWrite(pPage->pDbPage);
74396 if( rc ){
74397 goto end_insert;
74398 }
74399 oldCell = findCell(pPage, idx);
@@ -74946,15 +74975,16 @@
74975 if( pgno>btreePagecount(pBt) ){
74976 return SQLITE_CORRUPT_BKPT;
74977 }
74978 rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
74979 if( rc ) return rc;
74980 if( (pBt->openFlags & BTREE_SINGLE)==0
74981 && sqlite3PagerPageRefcount(pPage->pDbPage)!=1
74982 ){
74983 rc = SQLITE_CORRUPT_BKPT;
74984 goto cleardatabasepage_out;
74985 }
 
74986 hdr = pPage->hdrOffset;
74987 for(i=0; i<pPage->nCell; i++){
74988 pCell = findCell(pPage, i);
74989 if( !pPage->leaf ){
74990 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
@@ -74977,11 +75007,10 @@
75007 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
75008 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
75009 }
75010
75011 cleardatabasepage_out:
 
75012 releasePage(pPage);
75013 return rc;
75014 }
75015
75016 /*
@@ -75056,14 +75085,14 @@
75085 assert( iTable>=2 );
75086 if( iTable>btreePagecount(pBt) ){
75087 return SQLITE_CORRUPT_BKPT;
75088 }
75089
 
 
75090 rc = sqlite3BtreeClearTable(p, iTable, 0);
75091 if( rc ) return rc;
75092 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
75093 if( NEVER(rc) ){
75094 releasePage(pPage);
75095 return rc;
75096 }
75097
75098 *piMoved = 0;
@@ -78434,12 +78463,14 @@
78463 ExprList *pList = 0; /* Function arguments */
78464 int i; /* Iterator variable */
78465
78466 assert( pCtx!=0 );
78467 assert( (p->flags & EP_TokenOnly)==0 );
78468 assert( ExprUseXList(p) );
78469 pList = p->x.pList;
78470 if( pList ) nVal = pList->nExpr;
78471 assert( !ExprHasProperty(p, EP_IntValue) );
78472 pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
78473 assert( pFunc );
78474 if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
78475 || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
78476 ){
@@ -78539,11 +78570,13 @@
78570 ** check ensures that an EP_TokenOnly expression is never passed down
78571 ** into valueFromFunction(). */
78572 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
78573
78574 if( op==TK_CAST ){
78575 u8 aff;
78576 assert( !ExprHasProperty(pExpr, EP_IntValue) );
78577 aff = sqlite3AffinityType(pExpr->u.zToken,0);
78578 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
78579 testcase( rc!=SQLITE_OK );
78580 if( *ppVal ){
78581 sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
78582 sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
@@ -78612,10 +78645,11 @@
78645 sqlite3VdbeMemSetNull(pVal);
78646 }
78647 #ifndef SQLITE_OMIT_BLOB_LITERAL
78648 else if( op==TK_BLOB ){
78649 int nVal;
78650 assert( !ExprHasProperty(pExpr, EP_IntValue) );
78651 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
78652 assert( pExpr->u.zToken[1]=='\'' );
78653 pVal = valueNew(db, pCtx);
78654 if( !pVal ) goto no_mem;
78655 zVal = &pExpr->u.zToken[2];
@@ -78629,10 +78663,11 @@
78663 else if( op==TK_FUNCTION && pCtx!=0 ){
78664 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
78665 }
78666 #endif
78667 else if( op==TK_TRUEFALSE ){
78668 assert( !ExprHasProperty(pExpr, EP_IntValue) );
78669 pVal = valueNew(db, pCtx);
78670 if( pVal ){
78671 pVal->flags = MEM_Int;
78672 pVal->u.i = pExpr->u.zToken[4]==0;
78673 }
@@ -80501,10 +80536,11 @@
80536 */
80537 static void displayP4Expr(StrAccum *p, Expr *pExpr){
80538 const char *zOp = 0;
80539 switch( pExpr->op ){
80540 case TK_STRING:
80541 assert( !ExprHasProperty(pExpr, EP_IntValue) );
80542 sqlite3_str_appendf(p, "%Q", pExpr->u.zToken);
80543 break;
80544 case TK_INTEGER:
80545 sqlite3_str_appendf(p, "%d", pExpr->u.iValue);
80546 break;
@@ -80847,12 +80883,12 @@
80883 ** with no indexes using a single prepared INSERT statement, bind()
80884 ** and reset(). Inserts are grouped into a transaction.
80885 */
80886 testcase( p->flags & MEM_Agg );
80887 testcase( p->flags & MEM_Dyn );
 
80888 if( p->flags&(MEM_Agg|MEM_Dyn) ){
80889 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
80890 sqlite3VdbeMemRelease(p);
80891 }else if( p->szMalloc ){
80892 sqlite3DbFreeNN(db, p->zMalloc);
80893 p->szMalloc = 0;
80894 }
@@ -84553,12 +84589,12 @@
84589 /**************************** sqlite3_result_ *******************************
84590 ** The following routines are used by user-defined functions to specify
84591 ** the function result.
84592 **
84593 ** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
84594 ** result as a string or blob. Appropriate errors are set if the string/blob
84595 ** is too big or if an OOM occurs.
84596 **
84597 ** The invokeValueDestructor(P,X) routine invokes destructor function X()
84598 ** on value P is not going to be used and need to be destroyed.
84599 */
84600 static void setResultStrOrError(
@@ -84566,12 +84602,20 @@
84602 const char *z, /* String pointer */
84603 int n, /* Bytes in string, or negative */
84604 u8 enc, /* Encoding of z. 0 for BLOBs */
84605 void (*xDel)(void*) /* Destructor function */
84606 ){
84607 int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel);
84608 if( rc ){
84609 if( rc==SQLITE_TOOBIG ){
84610 sqlite3_result_error_toobig(pCtx);
84611 }else{
84612 /* The only errors possible from sqlite3VdbeMemSetStr are
84613 ** SQLITE_TOOBIG and SQLITE_NOMEM */
84614 assert( rc==SQLITE_NOMEM );
84615 sqlite3_result_error_nomem(pCtx);
84616 }
84617 }
84618 }
84619 static int invokeValueDestructor(
84620 const void *p, /* Value to destroy */
84621 void (*xDel)(void*), /* The destructor */
@@ -90536,11 +90580,11 @@
90580 assert( aMem[pOp->p3].flags & MEM_Null );
90581 aMem[pOp->p3].n = 0;
90582 aMem[pOp->p3].z = "";
90583 }
90584 pCx = p->apCsr[pOp->p1];
90585 if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){
90586 /* If the ephermeral table is already open and has no duplicates from
90587 ** OP_OpenDup, then erase all existing content so that the table is
90588 ** empty again, rather than creating a new table. */
90589 assert( pCx->isEphemeral );
90590 pCx->seqCount = 0;
@@ -95092,11 +95136,11 @@
95136 /* Check that the column is not part of an FK child key definition. It
95137 ** is not necessary to check if it is part of a parent key, as parent
95138 ** key columns must be indexed. The check below will pick up this
95139 ** case. */
95140 FKey *pFKey;
95141 assert( IsOrdinaryTable(pTab) );
95142 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
95143 int j;
95144 for(j=0; j<pFKey->nCol; j++){
95145 if( pFKey->aCol[j].iFrom==iCol ){
95146 zFault = "foreign key";
@@ -99101,11 +99145,11 @@
99145 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
99146 if( pExpr->pRight ){
99147 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
99148 pExpr = pExpr->pRight;
99149 continue;
99150 }else if( ExprUseXSelect(pExpr) ){
99151 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
99152 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
99153 }else{
99154 if( pExpr->x.pList ){
99155 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
@@ -99373,10 +99417,11 @@
99417 sqlite3ExprDelete(db, pDup);
99418 pDup = 0;
99419 }else{
99420 incrAggFunctionDepth(pDup, nSubquery);
99421 if( pExpr->op==TK_COLLATE ){
99422 assert( !ExprHasProperty(pExpr, EP_IntValue) );
99423 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
99424 }
99425
99426 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
99427 ** prevents ExprDelete() from deleting the Expr structure itself,
@@ -99476,10 +99521,11 @@
99521 SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){
99522 int n;
99523 Table *pExTab;
99524
99525 n = pExpr->iColumn;
99526 assert( ExprUseYTab(pExpr) );
99527 pExTab = pExpr->y.pTab;
99528 assert( pExTab!=0 );
99529 if( (pExTab->tabFlags & TF_HasGenerated)!=0
99530 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
99531 ){
@@ -99613,10 +99659,11 @@
99659 const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
99660 assert( zTabName!=0 );
99661 if( sqlite3StrICmp(zTabName, zTab)!=0 ){
99662 continue;
99663 }
99664 assert( ExprUseYTab(pExpr) );
99665 if( IN_RENAME_OBJECT && pItem->zAlias ){
99666 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
99667 }
99668 }
99669 hCol = sqlite3StrIHash(zCol);
@@ -99644,10 +99691,11 @@
99691 pMatch = pItem;
99692 }
99693 }
99694 if( pMatch ){
99695 pExpr->iTable = pMatch->iCursor;
99696 assert( ExprUseYTab(pExpr) );
99697 pExpr->y.pTab = pMatch->pTab;
99698 /* RIGHT JOIN not (yet) supported */
99699 assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
99700 if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
99701 ExprSetProperty(pExpr, EP_CanBeNull);
@@ -99717,10 +99765,11 @@
99765 cnt++;
99766 pMatch = 0;
99767 #ifndef SQLITE_OMIT_UPSERT
99768 if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
99769 testcase( iCol==(-1) );
99770 assert( ExprUseYTab(pExpr) );
99771 if( IN_RENAME_OBJECT ){
99772 pExpr->iColumn = iCol;
99773 pExpr->y.pTab = pTab;
99774 eNewExprOp = TK_COLUMN;
99775 }else{
@@ -99729,10 +99778,11 @@
99778 eNewExprOp = TK_REGISTER;
99779 }
99780 }else
99781 #endif /* SQLITE_OMIT_UPSERT */
99782 {
99783 assert( ExprUseYTab(pExpr) );
99784 pExpr->y.pTab = pTab;
99785 if( pParse->bReturning ){
99786 eNewExprOp = TK_REGISTER;
99787 pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
99788 sqlite3TableColumnToStorage(pTab, iCol) + 1;
@@ -99803,12 +99853,12 @@
99853 if( pEList->a[j].eEName==ENAME_NAME
99854 && sqlite3_stricmp(zAs, zCol)==0
99855 ){
99856 Expr *pOrig;
99857 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
99858 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
99859 assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 );
99860 pOrig = pEList->a[j].pExpr;
99861 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
99862 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
99863 return WRC_Abort;
99864 }
@@ -99876,11 +99926,11 @@
99926 "double-quoted string literal: \"%w\"", zCol);
99927 #ifdef SQLITE_ENABLE_NORMALIZE
99928 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
99929 #endif
99930 pExpr->op = TK_STRING;
99931 memset(&pExpr->y, 0, sizeof(pExpr->y));
99932 return WRC_Prune;
99933 }
99934 if( sqlite3ExprIdToTrueFalse(pExpr) ){
99935 return WRC_Prune;
99936 }
@@ -99962,11 +100012,13 @@
100012 */
100013 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
100014 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
100015 if( p ){
100016 SrcItem *pItem = &pSrc->a[iSrc];
100017 Table *pTab;
100018 assert( ExprUseYTab(p) );
100019 pTab = p->y.pTab = pItem->pTab;
100020 p->iTable = pItem->iCursor;
100021 if( p->y.pTab->iPKey==iCol ){
100022 p->iColumn = -1;
100023 }else{
100024 p->iColumn = (ynVar)iCol;
@@ -100029,10 +100081,11 @@
100081 ** value between 1.0 and 0.0.
100082 */
100083 static int exprProbability(Expr *p){
100084 double r = -1.0;
100085 if( p->op!=TK_FLOAT ) return -1;
100086 assert( !ExprHasProperty(p, EP_IntValue) );
100087 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
100088 assert( r>=0.0 );
100089 if( r>1.0 ) return -1;
100090 return (int)(r*134217728.0);
100091 }
@@ -100077,10 +100130,11 @@
100130 SrcList *pSrcList = pNC->pSrcList;
100131 SrcItem *pItem;
100132 assert( pSrcList && pSrcList->nSrc>=1 );
100133 pItem = pSrcList->a;
100134 pExpr->op = TK_COLUMN;
100135 assert( ExprUseYTab(pExpr) );
100136 pExpr->y.pTab = pItem->pTab;
100137 pExpr->iTable = pItem->iCursor;
100138 pExpr->iColumn--;
100139 pExpr->affExpr = SQLITE_AFF_INTEGER;
100140 break;
@@ -100109,10 +100163,11 @@
100163 anRef[i] = p->nRef;
100164 }
100165 sqlite3WalkExpr(pWalker, pExpr->pLeft);
100166 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
100167 testcase( ExprHasProperty(pExpr, EP_FromJoin) );
100168 assert( !ExprHasProperty(pExpr, EP_IntValue) );
100169 if( pExpr->op==TK_NOTNULL ){
100170 pExpr->u.zToken = "true";
100171 ExprSetProperty(pExpr, EP_IsTrue);
100172 }else{
100173 pExpr->u.zToken = "false";
@@ -100144,10 +100199,11 @@
100199 Expr *pRight;
100200
100201 if( pExpr->op==TK_ID ){
100202 zDb = 0;
100203 zTable = 0;
100204 assert( !ExprHasProperty(pExpr, EP_IntValue) );
100205 zColumn = pExpr->u.zToken;
100206 }else{
100207 Expr *pLeft = pExpr->pLeft;
100208 testcase( pNC->ncFlags & NC_IdxExpr );
100209 testcase( pNC->ncFlags & NC_GenCol );
@@ -100156,16 +100212,19 @@
100212 pRight = pExpr->pRight;
100213 if( pRight->op==TK_ID ){
100214 zDb = 0;
100215 }else{
100216 assert( pRight->op==TK_DOT );
100217 assert( !ExprHasProperty(pRight, EP_IntValue) );
100218 zDb = pLeft->u.zToken;
100219 pLeft = pRight->pLeft;
100220 pRight = pRight->pRight;
100221 }
100222 assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) );
100223 zTable = pLeft->u.zToken;
100224 zColumn = pRight->u.zToken;
100225 assert( ExprUseYTab(pExpr) );
100226 if( IN_RENAME_OBJECT ){
100227 sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
100228 sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
100229 }
100230 }
@@ -100186,11 +100245,11 @@
100245 u8 enc = ENC(pParse->db); /* The database encoding */
100246 int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
100247 #ifndef SQLITE_OMIT_WINDOWFUNC
100248 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
100249 #endif
100250 assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
100251 zId = pExpr->u.zToken;
100252 nId = sqlite3Strlen30(zId);
100253 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
100254 if( pDef==0 ){
100255 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
@@ -100350,11 +100409,11 @@
100409 sqlite3WalkExprList(pWalker, pList);
100410 if( is_agg ){
100411 #ifndef SQLITE_OMIT_WINDOWFUNC
100412 if( pWin ){
100413 Select *pSel = pNC->pWinSelect;
100414 assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) );
100415 if( IN_RENAME_OBJECT==0 ){
100416 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
100417 if( pParse->db->mallocFailed ) break;
100418 }
100419 sqlite3WalkExprList(pWalker, pWin->pPartition);
@@ -100399,11 +100458,11 @@
100458 case TK_SELECT:
100459 case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
100460 #endif
100461 case TK_IN: {
100462 testcase( pExpr->op==TK_IN );
100463 if( ExprUseXSelect(pExpr) ){
100464 int nRef = pNC->nRef;
100465 testcase( pNC->ncFlags & NC_IsCheck );
100466 testcase( pNC->ncFlags & NC_PartIdx );
100467 testcase( pNC->ncFlags & NC_IdxExpr );
100468 testcase( pNC->ncFlags & NC_GenCol );
@@ -100456,10 +100515,11 @@
100515 int nLeft, nRight;
100516 if( pParse->db->mallocFailed ) break;
100517 assert( pExpr->pLeft!=0 );
100518 nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
100519 if( pExpr->op==TK_BETWEEN ){
100520 assert( ExprUseXList(pExpr) );
100521 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
100522 if( nRight==nLeft ){
100523 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
100524 }
100525 }else{
@@ -100504,11 +100564,13 @@
100564 int i; /* Loop counter */
100565
100566 UNUSED_PARAMETER(pParse);
100567
100568 if( pE->op==TK_ID ){
100569 const char *zCol;
100570 assert( !ExprHasProperty(pE, EP_IntValue) );
100571 zCol = pE->u.zToken;
100572 for(i=0; i<pEList->nExpr; i++){
100573 if( pEList->a[i].eEName==ENAME_NAME
100574 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
100575 ){
100576 return i+1;
@@ -101369,15 +101431,18 @@
101431 pExpr = pExpr->pLeft;
101432 assert( pExpr!=0 );
101433 }
101434 op = pExpr->op;
101435 if( op==TK_REGISTER ) op = pExpr->op2;
101436 if( op==TK_COLUMN || op==TK_AGG_COLUMN ){
101437 assert( ExprUseYTab(pExpr) );
101438 if( pExpr->y.pTab ){
101439 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101440 }
101441 }
101442 if( op==TK_SELECT ){
101443 assert( ExprUseXSelect(pExpr) );
101444 assert( pExpr->x.pSelect!=0 );
101445 assert( pExpr->x.pSelect->pEList!=0 );
101446 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
101447 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
101448 }
@@ -101386,18 +101451,19 @@
101451 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101452 return sqlite3AffinityType(pExpr->u.zToken, 0);
101453 }
101454 #endif
101455 if( op==TK_SELECT_COLUMN ){
101456 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
101457 assert( pExpr->iColumn < pExpr->iTable );
101458 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
101459 return sqlite3ExprAffinity(
101460 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
101461 );
101462 }
101463 if( op==TK_VECTOR ){
101464 assert( ExprUseXList(pExpr) );
101465 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
101466 }
101467 return pExpr->affExpr;
101468 }
101469
@@ -101453,11 +101519,11 @@
101519 ** expression.
101520 */
101521 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
101522 while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){
101523 if( ExprHasProperty(pExpr, EP_Unlikely) ){
101524 assert( ExprUseXList(pExpr) );
101525 assert( pExpr->x.pList->nExpr>0 );
101526 assert( pExpr->op==TK_FUNCTION );
101527 pExpr = pExpr->x.pList->a[0].pExpr;
101528 }else{
101529 assert( pExpr->op==TK_COLLATE );
@@ -101486,45 +101552,46 @@
101552 CollSeq *pColl = 0;
101553 const Expr *p = pExpr;
101554 while( p ){
101555 int op = p->op;
101556 if( op==TK_REGISTER ) op = p->op2;
101557 if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){
101558 assert( ExprUseYTab(p) );
101559 if( p->y.pTab!=0 ){
101560 /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101561 ** a TK_COLUMN but was previously evaluated and cached in a register */
101562 int j = p->iColumn;
101563 if( j>=0 ){
101564 const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101565 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101566 }
101567 break;
101568 }
101569 }
101570 if( op==TK_CAST || op==TK_UPLUS ){
101571 p = p->pLeft;
101572 continue;
101573 }
101574 if( op==TK_VECTOR ){
101575 assert( ExprUseXList(p) );
101576 p = p->x.pList->a[0].pExpr;
101577 continue;
101578 }
101579 if( op==TK_COLLATE ){
101580 assert( !ExprHasProperty(p, EP_IntValue) );
101581 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
101582 break;
101583 }
101584 if( p->flags & EP_Collate ){
101585 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
101586 p = p->pLeft;
101587 }else{
101588 Expr *pNext = p->pRight;
101589 /* The Expr.x union is never used at the same time as Expr.pRight */
101590 assert( ExprUseXList(p) );
101591 assert( p->x.pList==0 || p->pRight==0 );
101592 if( p->x.pList!=0 && !db->mallocFailed ){
 
 
 
101593 int i;
101594 for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
101595 if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
101596 pNext = p->x.pList->a[i].pExpr;
101597 break;
@@ -101603,11 +101670,11 @@
101670 pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
101671 assert( pExpr->pLeft );
101672 aff = sqlite3ExprAffinity(pExpr->pLeft);
101673 if( pExpr->pRight ){
101674 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
101675 }else if( ExprUseXSelect(pExpr) ){
101676 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
101677 }else if( aff==0 ){
101678 aff = SQLITE_AFF_BLOB;
101679 }
101680 return aff;
@@ -101743,12 +101810,14 @@
101810 */
101811 SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){
101812 u8 op = pExpr->op;
101813 if( op==TK_REGISTER ) op = pExpr->op2;
101814 if( op==TK_VECTOR ){
101815 assert( ExprUseXList(pExpr) );
101816 return pExpr->x.pList->nExpr;
101817 }else if( op==TK_SELECT ){
101818 assert( ExprUseXSelect(pExpr) );
101819 return pExpr->x.pSelect->pEList->nExpr;
101820 }else{
101821 return 1;
101822 }
101823 }
@@ -101771,12 +101840,14 @@
101840 SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
101841 assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR );
101842 if( sqlite3ExprIsVector(pVector) ){
101843 assert( pVector->op2==0 || pVector->op==TK_REGISTER );
101844 if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){
101845 assert( ExprUseXSelect(pVector) );
101846 return pVector->x.pSelect->pEList->a[i].pExpr;
101847 }else{
101848 assert( ExprUseXList(pVector) );
101849 return pVector->x.pList->a[i].pExpr;
101850 }
101851 }
101852 return pVector;
101853 }
@@ -101808,11 +101879,11 @@
101879 int iField, /* Which column of the vector to return */
101880 int nField /* Total number of columns in the vector */
101881 ){
101882 Expr *pRet;
101883 if( pVector->op==TK_SELECT ){
101884 assert( ExprUseXSelect(pVector) );
101885 /* The TK_SELECT_COLUMN Expr node:
101886 **
101887 ** pLeft: pVector containing TK_SELECT. Not deleted.
101888 ** pRight: not used. But recursively deleted.
101889 ** iColumn: Index of a column in pVector
@@ -101833,11 +101904,13 @@
101904 pRet->iColumn = iField;
101905 pRet->pLeft = pVector;
101906 }
101907 }else{
101908 if( pVector->op==TK_VECTOR ){
101909 Expr **ppVector;
101910 assert( ExprUseXList(pVector) );
101911 ppVector = &pVector->x.pList->a[iField].pExpr;
101912 pVector = *ppVector;
101913 if( IN_RENAME_OBJECT ){
101914 /* This must be a vector UPDATE inside a trigger */
101915 *ppVector = 0;
101916 return pVector;
@@ -101897,14 +101970,16 @@
101970 if( op==TK_REGISTER ){
101971 *ppExpr = sqlite3VectorFieldSubexpr(pVector, iField);
101972 return pVector->iTable+iField;
101973 }
101974 if( op==TK_SELECT ){
101975 assert( ExprUseXSelect(pVector) );
101976 *ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr;
101977 return regSelect+iField;
101978 }
101979 if( op==TK_VECTOR ){
101980 assert( ExprUseXList(pVector) );
101981 *ppExpr = pVector->x.pList->a[iField].pExpr;
101982 return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree);
101983 }
101984 return 0;
101985 }
@@ -102075,11 +102150,11 @@
102150 */
102151 static void exprSetHeight(Expr *p){
102152 int nHeight = 0;
102153 heightOfExpr(p->pLeft, &nHeight);
102154 heightOfExpr(p->pRight, &nHeight);
102155 if( ExprUseXSelect(p) ){
102156 heightOfSelect(p->x.pSelect, &nHeight);
102157 }else if( p->x.pList ){
102158 heightOfExprList(p->x.pList, &nHeight);
102159 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102160 }
@@ -102114,11 +102189,11 @@
102189 ** Propagate all EP_Propagate flags from the Expr.x.pList into
102190 ** Expr.flags.
102191 */
102192 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
102193 if( pParse->nErr ) return;
102194 if( p && ExprUseXList(p) && p->x.pList ){
102195 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102196 }
102197 }
102198 #define exprSetHeight(y)
102199 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
@@ -102298,17 +102373,24 @@
102373 Select *pRet = 0;
102374 assert( nElem>1 );
102375 for(ii=0; ii<pEList->nExpr; ii++){
102376 Select *pSel;
102377 Expr *pExpr = pEList->a[ii].pExpr;
102378 int nExprElem;
102379 if( pExpr->op==TK_VECTOR ){
102380 assert( ExprUseXList(pExpr) );
102381 nExprElem = pExpr->x.pList->nExpr;
102382 }else{
102383 nExprElem = 1;
102384 }
102385 if( nExprElem!=nElem ){
102386 sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d",
102387 nExprElem, nExprElem>1?"s":"", nElem
102388 );
102389 break;
102390 }
102391 assert( ExprUseXList(pExpr) );
102392 pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
102393 pExpr->x.pList = 0;
102394 if( pSel ){
102395 if( pRet ){
102396 pSel->op = TK_ALL;
@@ -102374,11 +102456,11 @@
102456 ){
102457 sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
102458 }
102459 pNew->x.pList = pList;
102460 ExprSetProperty(pNew, EP_HasFunc);
102461 assert( ExprUseXList(pNew) );
102462 sqlite3ExprSetHeightAndFlags(pParse, pNew);
102463 if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
102464 return pNew;
102465 }
102466
@@ -102500,31 +102582,30 @@
102582 /*
102583 ** Recursively delete an expression tree.
102584 */
102585 static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
102586 assert( p!=0 );
102587 assert( !ExprUseUValue(p) || p->u.iValue>=0 );
102588 assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
102589 assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
102590 assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) );
 
 
102591 #ifdef SQLITE_DEBUG
102592 if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){
102593 assert( p->pLeft==0 );
102594 assert( p->pRight==0 );
102595 assert( !ExprUseXSelect(p) || p->x.pSelect==0 );
102596 assert( !ExprUseXList(p) || p->x.pList==0 );
102597 }
102598 #endif
102599 if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){
102600 /* The Expr.x union is never used at the same time as Expr.pRight */
102601 assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 );
102602 if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft);
102603 if( p->pRight ){
102604 assert( !ExprHasProperty(p, EP_WinFunc) );
102605 sqlite3ExprDeleteNN(db, p->pRight);
102606 }else if( ExprUseXSelect(p) ){
102607 assert( !ExprHasProperty(p, EP_WinFunc) );
102608 sqlite3SelectDelete(db, p->x.pSelect);
102609 }else{
102610 sqlite3ExprListDelete(db, p->x.pList);
102611 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -102532,11 +102613,14 @@
102613 sqlite3WindowDelete(db, p->y.pWin);
102614 }
102615 #endif
102616 }
102617 }
102618 if( ExprHasProperty(p, EP_MemToken) ){
102619 assert( !ExprHasProperty(p, EP_IntValue) );
102620 sqlite3DbFree(db, p->u.zToken);
102621 }
102622 if( !ExprHasProperty(p, EP_Static) ){
102623 sqlite3DbFreeNN(db, p);
102624 }
102625 }
102626 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
@@ -102748,11 +102832,11 @@
102832 memcpy(zToken, p->u.zToken, nToken);
102833 }
102834
102835 if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){
102836 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
102837 if( ExprUseXSelect(p) ){
102838 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
102839 }else{
102840 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
102841 }
102842 }
@@ -103375,11 +103459,11 @@
103459 ** the conversion happened, and zero if the expression is unaltered.
103460 */
103461 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
103462 u32 v;
103463 assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
103464 if( !ExprHasProperty(pExpr, EP_Quoted|EP_IntValue)
103465 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
103466 ){
103467 pExpr->op = TK_TRUEFALSE;
103468 ExprSetProperty(pExpr, v);
103469 return 1;
@@ -103392,10 +103476,11 @@
103476 ** and 0 if it is FALSE.
103477 */
103478 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
103479 pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
103480 assert( pExpr->op==TK_TRUEFALSE );
103481 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103482 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
103483 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
103484 return pExpr->u.zToken[4]==0;
103485 }
103486
@@ -103596,11 +103681,11 @@
103681 }
103682 }
103683 }
103684
103685 /* Check if pExpr is a sub-select. If so, consider it variable. */
103686 if( ExprUseXSelect(pExpr) ){
103687 pWalker->eCode = 0;
103688 return WRC_Abort;
103689 }
103690
103691 return exprNodeIsConstant(pWalker, pExpr);
@@ -103746,10 +103831,11 @@
103831 case TK_STRING:
103832 case TK_FLOAT:
103833 case TK_BLOB:
103834 return 0;
103835 case TK_COLUMN:
103836 assert( ExprUseYTab(p) );
103837 return ExprHasProperty(p, EP_CanBeNull) ||
103838 p->y.pTab==0 || /* Reference to column of index on expression */
103839 (p->iColumn>=0
103840 && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
103841 && p->y.pTab->aCol[p->iColumn].notNull==0);
@@ -103823,11 +103909,11 @@
103909 Select *p;
103910 SrcList *pSrc;
103911 ExprList *pEList;
103912 Table *pTab;
103913 int i;
103914 if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */
103915 if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
103916 p = pX->x.pSelect;
103917 if( p->pPrior ) return 0; /* Not a compound SELECT */
103918 if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
103919 testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -103994,11 +104080,11 @@
104080 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
104081 ** whether or not the SELECT result contains NULL values, check whether
104082 ** or not NULL is actually possible (it may not be, for example, due
104083 ** to NOT NULL constraints in the schema). If no NULL values are possible,
104084 ** set prRhsHasNull to 0 before continuing. */
104085 if( prRhsHasNull && ExprUseXSelect(pX) ){
104086 int i;
104087 ExprList *pEList = pX->x.pSelect->pEList;
104088 for(i=0; i<pEList->nExpr; i++){
104089 if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break;
104090 }
@@ -104150,11 +104236,11 @@
104236 ** then it is not worth creating an ephemeral table to evaluate
104237 ** the IN operator so return IN_INDEX_NOOP.
104238 */
104239 if( eType==0
104240 && (inFlags & IN_INDEX_NOOP_OK)
104241 && ExprUseXList(pX)
104242 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
104243 ){
104244 eType = IN_INDEX_NOOP;
104245 }
104246
@@ -104198,11 +104284,11 @@
104284 ** string is eventually freed using sqlite3DbFree().
104285 */
104286 static char *exprINAffinity(Parse *pParse, const Expr *pExpr){
104287 Expr *pLeft = pExpr->pLeft;
104288 int nVal = sqlite3ExprVectorSize(pLeft);
104289 Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
104290 char *zRet;
104291
104292 assert( pExpr->op==TK_IN );
104293 zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
104294 if( zRet ){
@@ -104248,11 +104334,11 @@
104334 **
104335 ** "row value misused"
104336 */
104337 SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
104338 #ifndef SQLITE_OMIT_SUBQUERY
104339 if( ExprUseXSelect(pExpr) ){
104340 sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
104341 }else
104342 #endif
104343 {
104344 sqlite3ErrorMsg(pParse, "row value misused");
@@ -104312,22 +104398,24 @@
104398 /* If this routine has already been coded, but the previous code
104399 ** might not have been invoked yet, so invoke it now as a subroutine.
104400 */
104401 if( ExprHasProperty(pExpr, EP_Subrtn) ){
104402 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
104403 if( ExprUseXSelect(pExpr) ){
104404 ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
104405 pExpr->x.pSelect->selId));
104406 }
104407 assert( ExprUseYSub(pExpr) );
104408 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104409 pExpr->y.sub.iAddr);
104410 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
104411 sqlite3VdbeJumpHere(v, addrOnce);
104412 return;
104413 }
104414
104415 /* Begin coding the subroutine */
104416 assert( !ExprUseYWin(pExpr) );
104417 ExprSetProperty(pExpr, EP_Subrtn);
104418 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
104419 pExpr->y.sub.regReturn = ++pParse->nMem;
104420 pExpr->y.sub.iAddr =
104421 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
@@ -104344,19 +104432,19 @@
104432 ** RHS of the IN operator.
104433 */
104434 pExpr->iTable = iTab;
104435 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
104436 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
104437 if( ExprUseXSelect(pExpr) ){
104438 VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
104439 }else{
104440 VdbeComment((v, "RHS of IN operator"));
104441 }
104442 #endif
104443 pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
104444
104445 if( ExprUseXSelect(pExpr) ){
104446 /* Case 1: expr IN (SELECT ...)
104447 **
104448 ** Generate code to write the results of the select into the temporary
104449 ** table allocated and opened above.
104450 */
@@ -104450,10 +104538,11 @@
104538 sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
104539 }
104540 if( addrOnce ){
104541 sqlite3VdbeJumpHere(v, addrOnce);
104542 /* Subroutine return */
104543 assert( ExprUseYSub(pExpr) );
104544 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104545 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104546 sqlite3ClearTempRegCache(pParse);
104547 }
104548 }
@@ -104486,23 +104575,26 @@
104575 assert( v!=0 );
104576 if( pParse->nErr ) return 0;
104577 testcase( pExpr->op==TK_EXISTS );
104578 testcase( pExpr->op==TK_SELECT );
104579 assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
104580 assert( ExprUseXSelect(pExpr) );
104581 pSel = pExpr->x.pSelect;
104582
104583 /* If this routine has already been coded, then invoke it as a
104584 ** subroutine. */
104585 if( ExprHasProperty(pExpr, EP_Subrtn) ){
104586 ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
104587 assert( ExprUseYSub(pExpr) );
104588 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104589 pExpr->y.sub.iAddr);
104590 return pExpr->iTable;
104591 }
104592
104593 /* Begin coding the subroutine */
104594 assert( !ExprUseYWin(pExpr) );
104595 assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) );
104596 ExprSetProperty(pExpr, EP_Subrtn);
104597 pExpr->y.sub.regReturn = ++pParse->nMem;
104598 pExpr->y.sub.iAddr =
104599 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
104600 VdbeComment((v, "return address"));
@@ -104578,10 +104670,11 @@
104670 if( addrOnce ){
104671 sqlite3VdbeJumpHere(v, addrOnce);
104672 }
104673
104674 /* Subroutine return */
104675 assert( ExprUseYSub(pExpr) );
104676 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104677 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104678 sqlite3ClearTempRegCache(pParse);
104679 return rReg;
104680 }
@@ -104594,11 +104687,11 @@
104687 ** columns as the vector on the LHS. Or, if the RHS of the IN() is not
104688 ** a sub-query, that the LHS is a vector of size 1.
104689 */
104690 SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
104691 int nVector = sqlite3ExprVectorSize(pIn->pLeft);
104692 if( ExprUseXSelect(pIn) && !pParse->db->mallocFailed ){
104693 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
104694 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
104695 return 1;
104696 }
104697 }else if( nVector!=1 ){
@@ -104728,17 +104821,19 @@
104821 ** sequence of comparisons.
104822 **
104823 ** This is step (1) in the in-operator.md optimized algorithm.
104824 */
104825 if( eType==IN_INDEX_NOOP ){
104826 ExprList *pList;
104827 CollSeq *pColl;
104828 int labelOk = sqlite3VdbeMakeLabel(pParse);
104829 int r2, regToFree;
104830 int regCkNull = 0;
104831 int ii;
104832 assert( ExprUseXList(pExpr) );
104833 pList = pExpr->x.pList;
104834 pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
104835 if( destIfNull!=destIfFalse ){
104836 regCkNull = sqlite3GetTempReg(pParse);
104837 sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
104838 }
104839 for(ii=0; ii<pList->nExpr; ii++){
@@ -105120,10 +105215,11 @@
105215 #endif
105216 }else{
105217 int i;
105218 iResult = pParse->nMem+1;
105219 pParse->nMem += nResult;
105220 assert( ExprUseXList(p) );
105221 for(i=0; i<nResult; i++){
105222 sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
105223 }
105224 }
105225 }
@@ -105318,10 +105414,11 @@
105414 ** datatype by applying the Affinity of the table column to the
105415 ** constant.
105416 */
105417 int aff;
105418 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
105419 assert( ExprUseYTab(pExpr) );
105420 if( pExpr->y.pTab ){
105421 aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105422 }else{
105423 aff = pExpr->affExpr;
105424 }
@@ -105341,13 +105438,15 @@
105438 ** The row is unpacked into registers beginning at
105439 ** 0-(pParse->iSelfTab). The rowid (if any) is in a register
105440 ** immediately prior to the first column.
105441 */
105442 Column *pCol;
105443 Table *pTab;
105444 int iSrc;
105445 int iCol = pExpr->iColumn;
105446 assert( ExprUseYTab(pExpr) );
105447 pTab = pExpr->y.pTab;
105448 assert( pTab!=0 );
105449 assert( iCol>=XN_ROWID );
105450 assert( iCol<pTab->nCol );
105451 if( iCol<0 ){
105452 return -1-pParse->iSelfTab;
@@ -105381,10 +105480,11 @@
105480 /* Coding an expression that is part of an index where column names
105481 ** in the index refer to the table to which the index belongs */
105482 iTab = pParse->iSelfTab - 1;
105483 }
105484 }
105485 assert( ExprUseYTab(pExpr) );
105486 iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
105487 pExpr->iColumn, iTab, target,
105488 pExpr->op2);
105489 if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
105490 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
@@ -105458,10 +105558,11 @@
105558 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
105559 if( inReg!=target ){
105560 sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
105561 inReg = target;
105562 }
105563 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105564 sqlite3VdbeAddOp2(v, OP_Cast, target,
105565 sqlite3AffinityType(pExpr->u.zToken, 0));
105566 return inReg;
105567 }
105568 #endif /* SQLITE_OMIT_CAST */
@@ -105625,12 +105726,12 @@
105726 if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
105727 /* SQL functions can be expensive. So try to avoid running them
105728 ** multiple times if we know they always give the same result */
105729 return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
105730 }
 
105731 assert( !ExprHasProperty(pExpr, EP_TokenOnly) );
105732 assert( ExprUseXList(pExpr) );
105733 pFarg = pExpr->x.pList;
105734 nFarg = pFarg ? pFarg->nExpr : 0;
105735 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105736 zId = pExpr->u.zToken;
105737 pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
@@ -105745,11 +105846,14 @@
105846 int nCol;
105847 testcase( op==TK_EXISTS );
105848 testcase( op==TK_SELECT );
105849 if( pParse->db->mallocFailed ){
105850 return 0;
105851 }else if( op==TK_SELECT
105852 && ALWAYS( ExprUseXSelect(pExpr) )
105853 && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1
105854 ){
105855 sqlite3SubselectError(pParse, nCol, 1);
105856 }else{
105857 return sqlite3CodeSubselect(pParse, pExpr);
105858 }
105859 break;
@@ -105827,13 +105931,18 @@
105931 **
105932 ** p1==0 -> old.rowid p1==3 -> new.rowid
105933 ** p1==1 -> old.a p1==4 -> new.a
105934 ** p1==2 -> old.b p1==5 -> new.b
105935 */
105936 Table *pTab;
105937 int iCol;
105938 int p1;
105939
105940 assert( ExprUseYTab(pExpr) );
105941 pTab = pExpr->y.pTab;
105942 iCol = pExpr->iColumn;
105943 p1 = pExpr->iTable * (pTab->nCol+1) + 1
105944 + sqlite3TableColumnToStorage(pTab, iCol);
105945
105946 assert( pExpr->iTable==0 || pExpr->iTable==1 );
105947 assert( iCol>=-1 && iCol<pTab->nCol );
105948 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
@@ -105917,11 +106026,11 @@
106026 Expr *pX; /* The X expression */
106027 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
106028 Expr *pDel = 0;
106029 sqlite3 *db = pParse->db;
106030
106031 assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 );
106032 assert(pExpr->x.pList->nExpr > 0);
106033 pEList = pExpr->x.pList;
106034 aListelem = pEList->a;
106035 nExpr = pEList->nExpr;
106036 endLabel = sqlite3VdbeMakeLabel(pParse);
@@ -106262,11 +106371,11 @@
106371
106372 memset(&compLeft, 0, sizeof(Expr));
106373 memset(&compRight, 0, sizeof(Expr));
106374 memset(&exprAnd, 0, sizeof(Expr));
106375
106376 assert( ExprUseXList(pExpr) );
106377 pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
106378 if( db->mallocFailed==0 ){
106379 exprAnd.op = TK_AND;
106380 exprAnd.pLeft = &compLeft;
106381 exprAnd.pRight = &compRight;
@@ -106737,11 +106846,16 @@
106846 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
106847 return 1;
106848 }
106849 return 2;
106850 }
106851 if( pA->op!=TK_COLUMN
106852 && pA->op!=TK_AGG_COLUMN
106853 && ALWAYS(!ExprHasProperty(pA, EP_IntValue))
106854 && pA->u.zToken
106855 ){
106856 assert( !ExprHasProperty(pB, EP_IntValue) );
106857 if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){
106858 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
106859 #ifndef SQLITE_OMIT_WINDOWFUNC
106860 assert( pA->op==pB->op );
106861 if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){
@@ -106844,16 +106958,17 @@
106958 return pNN->op!=TK_NULL;
106959 }
106960 switch( p->op ){
106961 case TK_IN: {
106962 if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
106963 assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) );
 
106964 return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
106965 }
106966 case TK_BETWEEN: {
106967 ExprList *pList;
106968 assert( ExprUseXList(p) );
106969 pList = p->x.pList;
106970 assert( pList!=0 );
106971 assert( pList->nExpr==2 );
106972 if( seenNot ) return 0;
106973 if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
106974 || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1)
@@ -107026,14 +107141,18 @@
107141 testcase( pExpr->op==TK_LE );
107142 testcase( pExpr->op==TK_GT );
107143 testcase( pExpr->op==TK_GE );
107144 /* The y.pTab=0 assignment in wherecode.c always happens after the
107145 ** impliesNotNullRow() test */
107146 assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
107147 assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
107148 if( (pLeft->op==TK_COLUMN
107149 && pLeft->y.pTab!=0
107150 && IsVirtual(pLeft->y.pTab))
107151 || (pRight->op==TK_COLUMN
107152 && pRight->y.pTab!=0
107153 && IsVirtual(pRight->y.pTab))
107154 ){
107155 return WRC_Prune;
107156 }
107157 /* no break */ deliberate_fall_through
107158 }
@@ -107213,10 +107332,11 @@
107332 w.u.pSrcCount = &cnt;
107333 cnt.pSrc = pSrcList;
107334 cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
107335 cnt.nThis = 0;
107336 cnt.nOther = 0;
107337 assert( ExprUseXList(pExpr) );
107338 sqlite3WalkExprList(&w, pExpr->x.pList);
107339 #ifndef SQLITE_OMIT_WINDOWFUNC
107340 if( ExprHasProperty(pExpr, EP_WinFunc) ){
107341 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
107342 }
@@ -107354,10 +107474,11 @@
107474 }
107475 if( (k>=pAggInfo->nColumn)
107476 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
107477 ){
107478 pCol = &pAggInfo->aCol[k];
107479 assert( ExprUseYTab(pExpr) );
107480 pCol->pTab = pExpr->y.pTab;
107481 pCol->iTable = pExpr->iTable;
107482 pCol->iColumn = pExpr->iColumn;
107483 pCol->iMem = ++pParse->nMem;
107484 pCol->iSorterColumn = -1;
@@ -107417,11 +107538,11 @@
107538 if( i>=0 ){
107539 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
107540 pItem = &pAggInfo->aFunc[i];
107541 pItem->pFExpr = pExpr;
107542 pItem->iMem = ++pParse->nMem;
107543 assert( ExprUseUToken(pExpr) );
107544 pItem->pFunc = sqlite3FindFunction(pParse->db,
107545 pExpr->u.zToken,
107546 pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
107547 if( pExpr->flags & EP_Distinct ){
107548 pItem->iDistinct = pParse->nTab++;
@@ -107939,10 +108060,11 @@
108060 */
108061 assert( pDflt==0 || pDflt->op==TK_SPAN );
108062 if( pDflt && pDflt->pLeft->op==TK_NULL ){
108063 pDflt = 0;
108064 }
108065 assert( IsOrdinaryTable(pNew) );
108066 if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
108067 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
108068 "Cannot add a REFERENCES column with non-NULL default value");
108069 }
108070 if( pCol->notNull && !pDflt ){
@@ -107981,11 +108103,12 @@
108103 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
108104 *zEnd-- = '\0';
108105 }
108106 /* substr() operations on characters, but addColOffset is in bytes. So we
108107 ** have to use printf() to translate between these units: */
108108 assert( IsOrdinaryTable(pTab) );
108109 assert( IsOrdinaryTable(pNew) );
108110 sqlite3NestedParse(pParse,
108111 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108112 "sql = printf('%%.%ds, ',sql) || %Q"
108113 " || substr(sql,1+length(printf('%%.%ds',sql))) "
108114 "WHERE type = 'table' AND name = %Q",
@@ -108075,10 +108198,11 @@
108198 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
108199 goto exit_begin_add_column;
108200 }
108201
108202 sqlite3MayAbort(pParse);
108203 assert( IsOrdinaryTable(pTab) );
108204 assert( pTab->u.tab.addColOffset>0 );
108205 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108206
108207 /* Put a copy of the Table struct in Parse.pNewTable for the
108208 ** sqlite3AddColumn() function and friends to modify. But modify
@@ -108105,11 +108229,11 @@
108229 for(i=0; i<pNew->nCol; i++){
108230 Column *pCol = &pNew->aCol[i];
108231 pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
108232 pCol->hName = sqlite3StrIHash(pCol->zCnName);
108233 }
108234 assert( IsOrdinaryTable(pNew) );
108235 pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
108236 pNew->pSchema = db->aDb[iDb].pSchema;
108237 pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
108238 pNew->nTabRef = 1;
108239
@@ -108374,11 +108498,13 @@
108498 ** Walker callback used by sqlite3RenameExprUnmap().
108499 */
108500 static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
108501 Parse *pParse = pWalker->pParse;
108502 sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
108503 if( ExprUseYTab(pExpr) ){
108504 sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
108505 }
108506 return WRC_Continue;
108507 }
108508
108509 /*
108510 ** Iterate through the Select objects that are part of WITH clauses attached
@@ -108436,11 +108562,13 @@
108562 */
108563 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
108564 Parse *pParse = pWalker->pParse;
108565 int i;
108566 if( pParse->nErr ) return WRC_Abort;
108567 testcase( p->selFlags & SF_View );
108568 testcase( p->selFlags & SF_CopyCte );
108569 if( p->selFlags & (SF_View|SF_CopyCte) ){
108570 return WRC_Prune;
108571 }
108572 if( ALWAYS(p->pEList) ){
108573 ExprList *pList = p->pEList;
108574 for(i=0; i<pList->nExpr; i++){
@@ -108573,10 +108701,11 @@
108701 && pWalker->pParse->pTriggerTab==p->pTab
108702 ){
108703 renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108704 }else if( pExpr->op==TK_COLUMN
108705 && pExpr->iColumn==p->iCol
108706 && ALWAYS(ExprUseYTab(pExpr))
108707 && p->pTab==pExpr->y.pTab
108708 ){
108709 renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108710 }
108711 return WRC_Continue;
@@ -109103,11 +109232,11 @@
109232 sqlite3WalkExpr(&sWalker, pExpr);
109233 }
109234 #endif
109235 }
109236
109237 assert( IsOrdinaryTable(sParse.pNewTable) );
109238 for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109239 for(i=0; i<pFKey->nCol; i++){
109240 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
109241 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
109242 }
@@ -109175,11 +109304,14 @@
109304 /*
109305 ** Walker expression callback used by "RENAME TABLE".
109306 */
109307 static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
109308 RenameCtx *p = pWalker->u.pRename;
109309 if( pExpr->op==TK_COLUMN
109310 && ALWAYS(ExprUseYTab(pExpr))
109311 && p->pTab==pExpr->y.pTab
109312 ){
109313 renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab);
109314 }
109315 return WRC_Continue;
109316 }
109317
@@ -109293,11 +109425,11 @@
109425 #ifndef SQLITE_OMIT_FOREIGN_KEY
109426 if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
109427 && !IsVirtual(pTab)
109428 ){
109429 FKey *pFKey;
109430 assert( IsOrdinaryTable(pTab) );
109431 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109432 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109433 renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109434 }
109435 }
@@ -109614,11 +109746,11 @@
109746 if( iCol<pTab->nCol-1 ){
109747 RenameToken *pEnd;
109748 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
109749 zEnd = (const char*)pEnd->t.z;
109750 }else{
109751 assert( IsOrdinaryTable(pTab) );
109752 zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
109753 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109754 }
109755
109756 zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
@@ -110789,11 +110921,11 @@
110921 pParse->nMem = MAX(pParse->nMem, iMem);
110922 v = sqlite3GetVdbe(pParse);
110923 if( v==0 || NEVER(pTab==0) ){
110924 return;
110925 }
110926 if( !IsOrdinaryTable(pTab) ){
110927 /* Do not gather statistics on views or virtual tables */
110928 return;
110929 }
110930 if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
110931 /* Do not gather statistics on system tables */
@@ -112083,10 +112215,11 @@
112215
112216 #ifndef SQLITE_OMIT_AUTHORIZATION
112217 if( pAuthArg ){
112218 char *zAuthArg;
112219 if( pAuthArg->op==TK_STRING ){
112220 assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112221 zAuthArg = pAuthArg->u.zToken;
112222 }else{
112223 zAuthArg = 0;
112224 }
112225 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
@@ -112767,21 +112900,25 @@
112900 Returning *pReturning = pParse->u1.pReturning;
112901 int addrRewind;
112902 int i;
112903 int reg;
112904
112905 if( pReturning->nRetCol==0 ){
112906 assert( CORRUPT_DB );
112907 }else{
112908 addrRewind =
112909 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
112910 VdbeCoverage(v);
112911 reg = pReturning->iRetReg;
112912 for(i=0; i<pReturning->nRetCol; i++){
112913 sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i);
112914 }
112915 sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i);
112916 sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1);
112917 VdbeCoverage(v);
112918 sqlite3VdbeJumpHere(v, addrRewind);
112919 }
112920 }
112921 sqlite3VdbeAddOp0(v, OP_Halt);
112922
112923 #if SQLITE_USER_AUTHENTICATION
112924 if( pParse->nTableLock>0 && db->init.busy==0 ){
@@ -112858,11 +112995,15 @@
112995 }
112996 }
112997
112998 if( pParse->bReturning ){
112999 Returning *pRet = pParse->u1.pReturning;
113000 if( pRet->nRetCol==0 ){
113001 assert( CORRUPT_DB );
113002 }else{
113003 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
113004 }
113005 }
113006
113007 /* Finally, jump back to the beginning of the executable code. */
113008 sqlite3VdbeGoto(v, 1);
113009 }
@@ -113280,11 +113421,11 @@
113421 Table *pTab, /* The table containing the column */
113422 Column *pCol, /* The column to receive the new DEFAULT expression */
113423 Expr *pExpr /* The new default expression */
113424 ){
113425 ExprList *pList;
113426 assert( IsOrdinaryTable(pTab) );
113427 pList = pTab->u.tab.pDfltList;
113428 if( pCol->iDflt==0
113429 || NEVER(pList==0)
113430 || NEVER(pList->nExpr<pCol->iDflt)
113431 ){
@@ -113301,11 +113442,11 @@
113442 ** the DEFAULT clause or the AS clause of a generated column.
113443 ** Return NULL if the column has no associated expression.
113444 */
113445 SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){
113446 if( pCol->iDflt==0 ) return 0;
113447 if( NEVER(!IsOrdinaryTable(pTab)) ) return 0;
113448 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
113449 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
113450 return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
113451 }
113452
@@ -113360,17 +113501,17 @@
113501 for(i=0; i<pTable->nCol; i++, pCol++){
113502 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
113503 sqlite3DbFree(db, pCol->zCnName);
113504 }
113505 sqlite3DbFree(db, pTable->aCol);
113506 if( IsOrdinaryTable(pTable) ){
113507 sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
113508 }
113509 if( db==0 || db->pnBytesFreed==0 ){
113510 pTable->aCol = 0;
113511 pTable->nCol = 0;
113512 if( IsOrdinaryTable(pTable) ){
113513 pTable->u.tab.pDfltList = 0;
113514 }
113515 }
113516 }
113517 }
@@ -114433,11 +114574,13 @@
114574 for(i=0; i<nTerm; i++){
114575 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
114576 assert( pCExpr!=0 );
114577 sqlite3StringToId(pCExpr);
114578 if( pCExpr->op==TK_ID ){
114579 const char *zCName;
114580 assert( !ExprHasProperty(pCExpr, EP_IntValue) );
114581 zCName = pCExpr->u.zToken;
114582 for(iCol=0; iCol<pTab->nCol; iCol++){
114583 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
114584 pCol = &pTab->aCol[iCol];
114585 makeColumnPartOfPrimaryKey(pParse, pCol);
114586 break;
@@ -114805,11 +114948,10 @@
114948 ** This is used to determine if the column number x appears in any of the
114949 ** first nCol entries of an index.
114950 */
114951 static int hasColumn(const i16 *aiCol, int nCol, int x){
114952 while( nCol-- > 0 ){
 
114953 if( x==*(aiCol++) ){
114954 return 1;
114955 }
114956 }
114957 return 0;
@@ -115181,11 +115323,11 @@
115323 **
115324 ** If the root page number is 1, that means this is the sqlite_schema
115325 ** table itself. So mark it read-only.
115326 */
115327 if( db->init.busy ){
115328 if( pSelect || (!IsOrdinaryTable(p) && db->init.newTnum) ){
115329 sqlite3ErrorMsg(pParse, "");
115330 return;
115331 }
115332 p->tnum = db->init.newTnum;
115333 if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
@@ -116146,10 +116288,11 @@
116288 pFKey = sqlite3DbMallocZero(db, nByte );
116289 if( pFKey==0 ){
116290 goto fk_end;
116291 }
116292 pFKey->pFrom = p;
116293 assert( IsOrdinaryTable(p) );
116294 pFKey->pNextFrom = p->u.tab.pFKey;
116295 z = (char*)&pFKey->aCol[nCol];
116296 pFKey->zTo = z;
116297 if( IN_RENAME_OBJECT ){
116298 sqlite3RenameTokenMap(pParse, (void*)z, pTo);
@@ -116211,11 +116354,11 @@
116354 pNextTo->pPrevTo = pFKey;
116355 }
116356
116357 /* Link the foreign key to the table as the last step.
116358 */
116359 assert( IsOrdinaryTable(p) );
116360 p->u.tab.pFKey = pFKey;
116361 pFKey = 0;
116362
116363 fk_end:
116364 sqlite3DbFree(db, pFKey);
@@ -116234,11 +116377,11 @@
116377 SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
116378 #ifndef SQLITE_OMIT_FOREIGN_KEY
116379 Table *pTab;
116380 FKey *pFKey;
116381 if( (pTab = pParse->pNewTable)==0 ) return;
116382 if( NEVER(!IsOrdinaryTable(pTab)) ) return;
116383 if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
116384 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
116385 pFKey->isDeferred = (u8)isDeferred;
116386 #endif
116387 }
@@ -116636,10 +116779,11 @@
116779 */
116780 for(i=0; i<pList->nExpr; i++){
116781 Expr *pExpr = pList->a[i].pExpr;
116782 assert( pExpr!=0 );
116783 if( pExpr->op==TK_COLLATE ){
116784 assert( !ExprHasProperty(pExpr, EP_IntValue) );
116785 nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
116786 }
116787 }
116788
116789 /*
@@ -116731,10 +116875,11 @@
116875 pIndex->aiColumn[i] = (i16)j;
116876 }
116877 zColl = 0;
116878 if( pListItem->pExpr->op==TK_COLLATE ){
116879 int nColl;
116880 assert( !ExprHasProperty(pListItem->pExpr, EP_IntValue) );
116881 zColl = pListItem->pExpr->u.zToken;
116882 nColl = sqlite3Strlen30(zColl) + 1;
116883 assert( nExtra>=nColl );
116884 memcpy(zExtra, zColl, nColl);
116885 zColl = zExtra;
@@ -117519,10 +117664,11 @@
117664 ** construct "indexed_opt" for details. */
117665 pItem->fg.notIndexed = 1;
117666 }else{
117667 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
117668 pItem->fg.isIndexedBy = 1;
117669 assert( pItem->fg.isCte==0 ); /* No collision on union u2 */
117670 }
117671 }
117672 }
117673
117674 /*
@@ -118499,10 +118645,11 @@
118645 int h, /* Hash of the name */
118646 const char *zFunc /* Name of function */
118647 ){
118648 FuncDef *p;
118649 for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){
118650 assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
118651 if( sqlite3StrICmp(p->zName, zFunc)==0 ){
118652 return p;
118653 }
118654 }
118655 return 0;
@@ -118520,10 +118667,11 @@
118667 FuncDef *pOther;
118668 const char *zName = aDef[i].zName;
118669 int nName = sqlite3Strlen30(zName);
118670 int h = SQLITE_FUNC_HASH(zName[0], nName);
118671 assert( zName[0]>='a' && zName[0]<='z' );
118672 assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN );
118673 pOther = sqlite3FunctionSearch(h, zName);
118674 if( pOther ){
118675 assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] );
118676 aDef[i].pNext = pOther->pNext;
118677 pOther->pNext = &aDef[i];
@@ -118911,10 +119059,11 @@
119059 ** and the SELECT subtree. */
119060 pSrc->a[0].pTab = 0;
119061 pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
119062 pSrc->a[0].pTab = pTab;
119063 if( pSrc->a[0].fg.isIndexedBy ){
119064 assert( pSrc->a[0].fg.isCte==0 );
119065 pSrc->a[0].u2.pIBIndex = 0;
119066 pSrc->a[0].fg.isIndexedBy = 0;
119067 sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
119068 }else if( pSrc->a[0].fg.isCte ){
119069 pSrc->a[0].u2.pCteUse->nUse++;
@@ -121495,11 +121644,15 @@
121644 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
121645 pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
121646 /* pGCC is always non-NULL since groupConcatStep() will have always
121647 ** run frist to initialize it */
121648 if( ALWAYS(pGCC) ){
121649 int nVS;
121650 /* Must call sqlite3_value_text() to convert the argument into text prior
121651 ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
121652 (void)sqlite3_value_text(argv[0]);
121653 nVS = sqlite3_value_bytes(argv[0]);
121654 pGCC->nAccum -= 1;
121655 if( pGCC->pnSepLengths!=0 ){
121656 assert(pGCC->nAccum >= 0);
121657 if( pGCC->nAccum>0 ){
121658 nVS += *pGCC->pnSepLengths;
@@ -121610,15 +121763,16 @@
121763 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
121764 FuncDef *pDef;
121765 int nExpr;
121766 assert( pExpr!=0 );
121767 assert( pExpr->op==TK_FUNCTION );
121768 assert( ExprUseXList(pExpr) );
121769 if( !pExpr->x.pList ){
121770 return 0;
121771 }
 
121772 nExpr = pExpr->x.pList->nExpr;
121773 assert( !ExprHasProperty(pExpr, EP_IntValue) );
121774 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
121775 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
121776 if( pDef==0 ) return 0;
121777 #endif
121778 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
@@ -121638,10 +121792,11 @@
121792 aWc[3] = 0;
121793 }else{
121794 Expr *pEscape = pExpr->x.pList->a[2].pExpr;
121795 char *zEscape;
121796 if( pEscape->op!=TK_STRING ) return 0;
121797 assert( !ExprHasProperty(pEscape, EP_IntValue) );
121798 zEscape = pEscape->u.zToken;
121799 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
121800 if( zEscape[0]==aWc[0] ) return 0;
121801 if( zEscape[0]==aWc[1] ) return 0;
121802 aWc[3] = zEscape[0];
@@ -122019,10 +122174,11 @@
122174 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
122175 printf("FUNC-HASH %02d:", i);
122176 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){
122177 int n = sqlite3Strlen30(p->zName);
122178 int h = p->zName[0] + n;
122179 assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
122180 printf(" %s(%d)", p->zName, h);
122181 }
122182 printf("\n");
122183 }
122184 }
@@ -122541,10 +122697,11 @@
122697 int iCursor, /* The open cursor on the table */
122698 i16 iCol /* The column that is wanted */
122699 ){
122700 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
122701 if( pExpr ){
122702 assert( ExprUseYTab(pExpr) );
122703 pExpr->y.pTab = pTab;
122704 pExpr->iTable = iCursor;
122705 pExpr->iColumn = iCol;
122706 }
122707 return pExpr;
@@ -122751,17 +122908,16 @@
122908 ** the table from the database. Triggers are disabled while running this
122909 ** DELETE, but foreign key actions are not.
122910 */
122911 SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
122912 sqlite3 *db = pParse->db;
122913 if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){
122914 int iSkip = 0;
122915 Vdbe *v = sqlite3GetVdbe(pParse);
122916
122917 assert( v ); /* VDBE has already been allocated */
122918 assert( IsOrdinaryTable(pTab) );
 
122919 if( sqlite3FkReferences(pTab)==0 ){
122920 /* Search for a deferred foreign key constraint for which this table
122921 ** is the child table. If one cannot be found, return without
122922 ** generating any VDBE code. If one can be found, then jump over
122923 ** the entire DELETE if there are no outstanding deferred constraints
@@ -122921,17 +123077,17 @@
123077 /* Exactly one of regOld and regNew should be non-zero. */
123078 assert( (regOld==0)!=(regNew==0) );
123079
123080 /* If foreign-keys are disabled, this function is a no-op. */
123081 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
123082 if( !IsOrdinaryTable(pTab) ) return;
123083
123084 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
123085 zDb = db->aDb[iDb].zDbSName;
123086
123087 /* Loop through all the foreign key constraints for which pTab is the
123088 ** child table (the table that the foreign key definition is part of). */
 
123089 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
123090 Table *pTo; /* Parent table of foreign key pFKey */
123091 Index *pIdx = 0; /* Index on key columns in pTo */
123092 int *aiFree = 0;
123093 int *aiCol;
@@ -123110,14 +123266,13 @@
123266 SQLITE_PRIVATE u32 sqlite3FkOldmask(
123267 Parse *pParse, /* Parse context */
123268 Table *pTab /* Table being modified */
123269 ){
123270 u32 mask = 0;
123271 if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123272 FKey *p;
123273 int i;
 
123274 for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
123275 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
123276 }
123277 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
123278 Index *pIdx = 0;
@@ -123164,11 +123319,11 @@
123319 int *aChange, /* Non-NULL for UPDATE operations */
123320 int chngRowid /* True for UPDATE that affects rowid */
123321 ){
123322 int eRet = 1; /* Value to return if bHaveFK is true */
123323 int bHaveFK = 0; /* If FK processing is required */
123324 if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123325 if( !aChange ){
123326 /* A DELETE operation. Foreign key processing is required if the
123327 ** table in question is either the child or parent table for any
123328 ** foreign key constraint. */
123329 bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
@@ -123452,11 +123607,11 @@
123607 */
123608 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123609 FKey *pFKey; /* Iterator variable */
123610 FKey *pNext; /* Copy of pFKey->pNextFrom */
123611
123612 assert( IsOrdinaryTable(pTab) );
123613 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
123614 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123615
123616 /* Remove the FK from the fkeyHash hash table. */
123617 if( !db || db->pnBytesFreed==0 ){
@@ -125711,10 +125866,11 @@
125866 ** (5) No FK constraint counters need to be updated if a conflict occurs.
125867 **
125868 ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
125869 ** must be explicitly deleted in order to ensure any pre-update hook
125870 ** is invoked. */
125871 assert( IsOrdinaryTable(pTab) );
125872 #ifndef SQLITE_ENABLE_PREUPDATE_HOOK
125873 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
125874 && pPk==pIdx /* Condition 2 */
125875 && onError==OE_Replace /* Condition 1 */
125876 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
@@ -126391,11 +126547,13 @@
126547 /* Default values for second and subsequent columns need to match. */
126548 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126549 Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
126550 Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
126551 assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
126552 assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
126553 assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
126554 assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
126555 if( (pDestExpr==0)!=(pSrcExpr==0)
126556 || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
126557 pSrcExpr->u.zToken)!=0)
126558 ){
126559 return 0; /* Default values must be the same for all columns */
@@ -126431,10 +126589,11 @@
126589 ** But the main beneficiary of the transfer optimization is the VACUUM
126590 ** command, and the VACUUM command disables foreign key constraints. So
126591 ** the extra complication to make this rule less restrictive is probably
126592 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126593 */
126594 assert( IsOrdinaryTable(pDest) );
126595 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
126596 return 0;
126597 }
126598 #endif
126599 if( (db->flags & SQLITE_CountRows)!=0 ){
@@ -129423,11 +129582,15 @@
129582 goto pragma_out;
129583 }
129584
129585 /* Locate the pragma in the lookup table */
129586 pPragma = pragmaLocate(zLeft);
129587 if( pPragma==0 ){
129588 /* IMP: R-43042-22504 No error messages are generated if an
129589 ** unknown pragma is issued. */
129590 goto pragma_out;
129591 }
129592
129593 /* Make sure the database schema is loaded if the pragma requires that */
129594 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
129595 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
129596 }
@@ -130073,10 +130236,18 @@
130236 if( sqlite3GetBoolean(zRight, 0) ){
130237 db->flags |= mask;
130238 }else{
130239 db->flags &= ~mask;
130240 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
130241 if( (mask & SQLITE_WriteSchema)!=0
130242 && sqlite3_stricmp(zRight, "reset")==0
130243 ){
130244 /* IMP: R-60817-01178 If the argument is "RESET" then schema
130245 ** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
130246 ** in addition, the schema is reloaded. */
130247 sqlite3ResetAllSchemasOfConnection(db);
130248 }
130249 }
130250
130251 /* Many of the flag-pragmas modify the code generated by the SQL
130252 ** compiler (eg. count_changes). So add an opcode to expire all
130253 ** compiled SQL statements after modifying a pragma value.
@@ -130113,10 +130284,11 @@
130284 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
130285 pParse->nMem = 7;
130286 sqlite3ViewGetColumnNames(pParse, pTab);
130287 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
130288 int isHidden = 0;
130289 const Expr *pColExpr;
130290 if( pCol->colFlags & COLFLAG_NOINSERT ){
130291 if( pPragma->iArg==0 ){
130292 nHidden++;
130293 continue;
130294 }
@@ -130133,20 +130305,20 @@
130305 }else if( pPk==0 ){
130306 k = 1;
130307 }else{
130308 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
130309 }
130310 pColExpr = sqlite3ColumnExpr(pTab,pCol);
130311 assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 );
130312 assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue)
130313 || isHidden>=2 );
130314 sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
130315 i-nHidden,
130316 pCol->zCnName,
130317 sqlite3ColumnType(pCol,""),
130318 pCol->notNull ? 1 : 0,
130319 (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken,
 
130320 k,
130321 isHidden);
130322 }
130323 }
130324 }
@@ -130170,12 +130342,39 @@
130342 pParse->nMem = 6;
130343 sqlite3CodeVerifyNamedSchema(pParse, zDb);
130344 for(ii=0; ii<db->nDb; ii++){
130345 HashElem *k;
130346 Hash *pHash;
130347 int initNCol;
130348 if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
130349
130350 /* Ensure that the Table.nCol field is initialized for all views
130351 ** and virtual tables. Each time we initialize a Table.nCol value
130352 ** for a table, that can potentially disrupt the hash table, so restart
130353 ** the initialization scan.
130354 */
130355 pHash = &db->aDb[ii].pSchema->tblHash;
130356 initNCol = sqliteHashCount(pHash);
130357 while( initNCol-- ){
130358 for(k=sqliteHashFirst(pHash); 1; k=sqliteHashNext(k) ){
130359 Table *pTab;
130360 if( k==0 ){ initNCol = 0; break; }
130361 pTab = sqliteHashData(k);
130362 if( pTab->nCol==0 ){
130363 char *zSql = sqlite3MPrintf(db, "SELECT*FROM\"%w\"", pTab->zName);
130364 if( zSql ){
130365 sqlite3_stmt *pDummy = 0;
130366 (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
130367 (void)sqlite3_finalize(pDummy);
130368 sqlite3DbFree(db, zSql);
130369 }
130370 pHash = &db->aDb[ii].pSchema->tblHash;
130371 break;
130372 }
130373 }
130374 }
130375
130376 for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){
130377 Table *pTab = sqliteHashData(k);
130378 const char *zType;
130379 if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
130380 if( IsView(pTab) ){
@@ -130326,15 +130525,17 @@
130525 FuncDef *p;
130526 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
130527 pParse->nMem = 6;
130528 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
130529 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
130530 assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
130531 pragmaFunclistLine(v, p, 1, showInternFunc);
130532 }
130533 }
130534 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
130535 p = (FuncDef*)sqliteHashData(j);
130536 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
130537 pragmaFunclistLine(v, p, 0, showInternFunc);
130538 }
130539 }
130540 break;
130541
@@ -130364,11 +130565,11 @@
130565 #ifndef SQLITE_OMIT_FOREIGN_KEY
130566 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
130567 FKey *pFK;
130568 Table *pTab;
130569 pTab = sqlite3FindTable(db, zRight, zDb);
130570 if( pTab && IsOrdinaryTable(pTab) ){
130571 pFK = pTab->u.tab.pFKey;
130572 if( pFK ){
130573 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130574 int i = 0;
130575 pParse->nMem = 8;
@@ -130424,19 +130625,19 @@
130625 k = 0;
130626 }else{
130627 pTab = (Table*)sqliteHashData(k);
130628 k = sqliteHashNext(k);
130629 }
130630 if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue;
130631 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130632 zDb = db->aDb[iDb].zDbSName;
130633 sqlite3CodeVerifySchema(pParse, iDb);
130634 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130635 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130636 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130637 sqlite3VdbeLoadString(v, regResult, pTab->zName);
130638 assert( IsOrdinaryTable(pTab) );
130639 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130640 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130641 if( pParent==0 ) continue;
130642 pIdx = 0;
130643 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -130455,11 +130656,11 @@
130656 }
130657 assert( pParse->nErr>0 || pFK==0 );
130658 if( pFK ) break;
130659 if( pParse->nTab<i ) pParse->nTab = i;
130660 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130661 assert( IsOrdinaryTable(pTab) );
130662 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130663 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130664 pIdx = 0;
130665 aiCols = 0;
130666 if( pParent ){
@@ -130659,11 +130860,11 @@
130860 int loopTop;
130861 int iDataCur, iIdxCur;
130862 int r1 = -1;
130863 int bStrict;
130864
130865 if( !IsOrdinaryTable(pTab) ) continue;
130866 if( pObjTab && pObjTab!=pTab ) continue;
130867 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
130868 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
130869 1, 0, &iDataCur, &iIdxCur);
130870 /* reg[7] counts the number of entries in the table.
@@ -131254,16 +131455,16 @@
131455 ** in each index that it looks at. Return the new limit.
131456 */
131457 case PragTyp_ANALYSIS_LIMIT: {
131458 sqlite3_int64 N;
131459 if( zRight
131460 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */
131461 && N>=0
131462 ){
131463 db->nAnalysisLimit = (int)(N&0x7fffffff);
131464 }
131465 returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */
131466 break;
131467 }
131468
131469 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
131470 /*
@@ -133046,14 +133247,17 @@
133247 while( p ){
133248 ExprSetProperty(p, EP_FromJoin);
133249 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
133250 ExprSetVVAProperty(p, EP_NoReduce);
133251 p->iRightJoinTable = iTable;
133252 if( p->op==TK_FUNCTION ){
133253 assert( ExprUseXList(p) );
133254 if( p->x.pList ){
133255 int i;
133256 for(i=0; i<p->x.pList->nExpr; i++){
133257 sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133258 }
133259 }
133260 }
133261 sqlite3SetJoinExpr(p->pLeft, iTable);
133262 p = p->pRight;
133263 }
@@ -133072,14 +133276,17 @@
133276 ExprClearProperty(p, EP_FromJoin);
133277 }
133278 if( p->op==TK_COLUMN && p->iTable==iTable ){
133279 ExprClearProperty(p, EP_CanBeNull);
133280 }
133281 if( p->op==TK_FUNCTION ){
133282 assert( ExprUseXList(p) );
133283 if( p->x.pList ){
133284 int i;
133285 for(i=0; i<p->x.pList->nExpr; i++){
133286 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133287 }
133288 }
133289 }
133290 unsetJoinExpr(p->pLeft, iTable);
133291 p = p->pRight;
133292 }
@@ -133590,13 +133797,17 @@
133797 ExprList *pExtra = 0;
133798 for(i=0; i<pEList->nExpr; i++){
133799 struct ExprList_item *pItem = &pEList->a[i];
133800 if( pItem->u.x.iOrderByCol==0 ){
133801 Expr *pExpr = pItem->pExpr;
133802 Table *pTab;
133803 if( pExpr->op==TK_COLUMN
133804 && pExpr->iColumn>=0
133805 && ALWAYS( ExprUseYTab(pExpr) )
133806 && (pTab = pExpr->y.pTab)!=0
133807 && IsOrdinaryTable(pTab)
133808 && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0
133809 ){
133810 int j;
133811 for(j=0; j<nDefer; j++){
133812 if( pSort->aDefer[j].iCsr==pExpr->iTable ) break;
133813 }
@@ -133613,10 +133824,11 @@
133824 }
133825 for(k=0; k<nKey; k++){
133826 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
133827 if( pNew ){
133828 pNew->iTable = pExpr->iTable;
133829 assert( ExprUseYTab(pNew) );
133830 pNew->y.pTab = pExpr->y.pTab;
133831 pNew->iColumn = pPk ? pPk->aiColumn[k] : -1;
133832 pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew);
133833 }
133834 }
@@ -134461,11 +134673,11 @@
134673 ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
134674 ** branch below. */
134675 break;
134676 }
134677
134678 assert( pTab && ExprUseYTab(pExpr) && pExpr->y.pTab==pTab );
134679 if( pS ){
134680 /* The "table" is actually a sub-select or a view in the FROM clause
134681 ** of the SELECT statement. Return the declaration type and origin
134682 ** data for the result-set column of the sub-select.
134683 */
@@ -134521,13 +134733,15 @@
134733 /* The expression is a sub-select. Return the declaration type and
134734 ** origin info for the single column in the result set of the SELECT
134735 ** statement.
134736 */
134737 NameContext sNC;
134738 Select *pS;
134739 Expr *p;
134740 assert( ExprUseXSelect(pExpr) );
134741 pS = pExpr->x.pSelect;
134742 p = pS->pEList->a[0].pExpr;
134743 sNC.pSrcList = pS->pSrc;
134744 sNC.pNext = pNC;
134745 sNC.pParse = pNC->pParse;
134746 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
134747 break;
@@ -134652,11 +134866,12 @@
134866 for(i=0; i<pEList->nExpr; i++){
134867 Expr *p = pEList->a[i].pExpr;
134868
134869 assert( p!=0 );
134870 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
134871 assert( p->op!=TK_COLUMN
134872 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
134873 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
134874 /* An AS clause always takes first priority */
134875 char *zName = pEList->a[i].zEName;
134876 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
134877 }else if( srcName && p->op==TK_COLUMN ){
@@ -134748,11 +134963,14 @@
134963 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
134964 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
134965 pColExpr = pColExpr->pRight;
134966 assert( pColExpr!=0 );
134967 }
134968 if( pColExpr->op==TK_COLUMN
134969 && ALWAYS( ExprUseYTab(pColExpr) )
134970 && (pTab = pColExpr->y.pTab)!=0
134971 ){
134972 /* For columns use the column name name */
134973 int iCol = pColExpr->iColumn;
134974 if( iCol<0 ) iCol = pTab->iPKey;
134975 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
134976 }else if( pColExpr->op==TK_ID ){
@@ -136330,11 +136548,11 @@
136548 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
136549 pExpr->iTable = pSubst->iNewTable;
136550 }
136551 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
136552 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
136553 if( ExprUseXSelect(pExpr) ){
136554 substSelect(pSubst, pExpr->x.pSelect, 1);
136555 }else{
136556 substExprList(pSubst, pExpr->x.pList);
136557 }
136558 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -137541,25 +137759,28 @@
137759 ** located but before their arguments have been subjected to aggregate
137760 ** analysis.
137761 */
137762 static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
137763 int eRet = WHERE_ORDERBY_NORMAL; /* Return value */
137764 ExprList *pEList; /* Arguments to agg function */
137765 const char *zFunc; /* Name of aggregate function pFunc */
137766 ExprList *pOrderBy;
137767 u8 sortFlags = 0;
137768
137769 assert( *ppMinMax==0 );
137770 assert( pFunc->op==TK_AGG_FUNCTION );
137771 assert( !IsWindowFunc(pFunc) );
137772 assert( ExprUseXList(pFunc) );
137773 pEList = pFunc->x.pList;
137774 if( pEList==0
137775 || pEList->nExpr!=1
137776 || ExprHasProperty(pFunc, EP_WinFunc)
137777 || OptimizationDisabled(db, SQLITE_MinMaxOpt)
137778 ){
137779 return eRet;
137780 }
137781 assert( !ExprHasProperty(pFunc, EP_IntValue) );
137782 zFunc = pFunc->u.zToken;
137783 if( sqlite3StrICmp(zFunc, "min")==0 ){
137784 eRet = WHERE_ORDERBY_MIN;
137785 if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
137786 sortFlags = KEYINFO_ORDER_BIGNULL;
@@ -137632,10 +137853,11 @@
137853 if( !pIdx ){
137854 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
137855 pParse->checkSchema = 1;
137856 return SQLITE_ERROR;
137857 }
137858 assert( pFrom->fg.isCte==0 );
137859 pFrom->u2.pIBIndex = pIdx;
137860 return SQLITE_OK;
137861 }
137862
137863 /*
@@ -137889,10 +138111,14 @@
138111 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
138112 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
138113 if( db->mallocFailed ) return 2;
138114 pFrom->pSelect->selFlags |= SF_CopyCte;
138115 assert( pFrom->pSelect );
138116 if( pFrom->fg.isIndexedBy ){
138117 sqlite3ErrorMsg(pParse, "no such index: \"%s\"", pFrom->u1.zIndexedBy);
138118 return 2;
138119 }
138120 pFrom->fg.isCte = 1;
138121 pFrom->u2.pCteUse = pCteUse;
138122 pCteUse->nUse++;
138123 if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){
138124 pCteUse->eM10d = M10d_Yes;
@@ -138524,11 +138750,11 @@
138750 #endif
138751 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
138752 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
138753 if( pFunc->iDistinct>=0 ){
138754 Expr *pE = pFunc->pFExpr;
138755 assert( ExprUseXList(pE) );
138756 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
138757 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
138758 "argument");
138759 pFunc->iDistinct = -1;
138760 }else{
@@ -138549,12 +138775,13 @@
138775 static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
138776 Vdbe *v = pParse->pVdbe;
138777 int i;
138778 struct AggInfo_func *pF;
138779 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138780 ExprList *pList;
138781 assert( ExprUseXList(pF->pFExpr) );
138782 pList = pF->pFExpr->x.pList;
138783 sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
138784 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
138785 }
138786 }
138787
@@ -138584,13 +138811,14 @@
138811 pAggInfo->directMode = 1;
138812 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138813 int nArg;
138814 int addrNext = 0;
138815 int regAgg;
138816 ExprList *pList;
138817 assert( ExprUseXList(pF->pFExpr) );
138818 assert( !IsWindowFunc(pF->pFExpr) );
138819 pList = pF->pFExpr->x.pList;
138820 if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
138821 Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
138822 if( pAggInfo->nAccumulator
138823 && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
138824 && regAcc
@@ -138832,11 +139060,13 @@
139060 if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
139061 if( p->pWhere ) return 0;
139062 if( p->pGroupBy ) return 0;
139063 pExpr = p->pEList->a[0].pExpr;
139064 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
139065 assert( ExprUseUToken(pExpr) );
139066 if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
139067 assert( ExprUseXList(pExpr) );
139068 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
139069 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
139070 pSub = p->pSrc->a[0].pSelect;
139071 if( pSub==0 ) return 0; /* The FROM is a subquery */
139072 if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */
@@ -139647,11 +139877,11 @@
139877 }else{
139878 minMaxFlag = WHERE_ORDERBY_NORMAL;
139879 }
139880 for(i=0; i<pAggInfo->nFunc; i++){
139881 Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
139882 assert( ExprUseXList(pExpr) );
139883 sNC.ncFlags |= NC_InAggFunc;
139884 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
139885 #ifndef SQLITE_OMIT_WINDOWFUNC
139886 assert( !IsWindowFunc(pExpr) );
139887 if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -139702,11 +139932,13 @@
139932 u16 distFlag = 0;
139933 int eDist = WHERE_DISTINCT_NOOP;
139934
139935 if( pAggInfo->nFunc==1
139936 && pAggInfo->aFunc[0].iDistinct>=0
139937 && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0)
139938 && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr))
139939 && pAggInfo->aFunc[0].pFExpr->x.pList!=0
139940 ){
139941 Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
139942 pExpr = sqlite3ExprDup(db, pExpr, 0);
139943 pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
139944 pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr);
@@ -140023,10 +140255,11 @@
140255 if( i==pAggInfo->nFunc ){
140256 regAcc = ++pParse->nMem;
140257 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
140258 }
140259 }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
140260 assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) );
140261 pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
140262 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
140263 }
140264
140265 /* This case runs if the aggregate has no GROUP BY clause. The
@@ -144048,11 +144281,14 @@
144281 ** Except, if argument db is not NULL, then the entry associated with
144282 ** connection db is left in the p->u.vtab.p list.
144283 */
144284 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
144285 VTable *pRet = 0;
144286 VTable *pVTable;
144287
144288 assert( IsVirtual(p) );
144289 pVTable = p->u.vtab.p;
144290 p->u.vtab.p = 0;
144291
144292 /* Assert that the mutex (if any) associated with the BtShared database
144293 ** that contains table p is held by the caller. See header comments
144294 ** above function sqlite3VtabUnlockList() for an explanation of why
@@ -144156,10 +144392,11 @@
144392 ** structure being xDisconnected and free). Any other VTable structures
144393 ** in the list are moved to the sqlite3.pDisconnect list of the associated
144394 ** database connection.
144395 */
144396 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
144397 assert( IsVirtual(p) );
144398 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
144399 if( p->u.vtab.azArg ){
144400 int i;
144401 for(i=0; i<p->u.vtab.nArg; i++){
144402 if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
@@ -144173,13 +144410,16 @@
144410 ** The string is not copied - the pointer is stored. The
144411 ** string will be freed automatically when the table is
144412 ** deleted.
144413 */
144414 static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
144415 sqlite3_int64 nBytes;
144416 char **azModuleArg;
144417 sqlite3 *db = pParse->db;
144418
144419 assert( IsVirtual(pTable) );
144420 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
144421 if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
144422 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
144423 }
144424 azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes);
144425 if( azModuleArg==0 ){
@@ -144262,10 +144502,11 @@
144502 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
144503 Table *pTab = pParse->pNewTable; /* The table being constructed */
144504 sqlite3 *db = pParse->db; /* The database connection */
144505
144506 if( pTab==0 ) return;
144507 assert( IsVirtual(pTab) );
144508 addArgumentToVtab(pParse);
144509 pParse->sArg.z = 0;
144510 if( pTab->u.vtab.nArg<1 ) return;
144511
144512 /* If the CREATE VIRTUAL TABLE statement is being entered for the
@@ -144379,17 +144620,20 @@
144620 char **pzErr
144621 ){
144622 VtabCtx sCtx;
144623 VTable *pVTable;
144624 int rc;
144625 const char *const*azArg;
144626 int nArg = pTab->u.vtab.nArg;
144627 char *zErr = 0;
144628 char *zModuleName;
144629 int iDb;
144630 VtabCtx *pCtx;
144631
144632 assert( IsVirtual(pTab) );
144633 azArg = (const char *const*)pTab->u.vtab.azArg;
144634
144635 /* Check that the virtual-table is not already being initialized */
144636 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
144637 if( pCtx->pTab==pTab ){
144638 *pzErr = sqlite3MPrintf(db,
144639 "vtable constructor called recursively: %s", pTab->zName
@@ -144713,11 +144957,11 @@
144957 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144958 int rc = SQLITE_OK;
144959 Table *pTab;
144960
144961 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144962 if( pTab!=0 && ALWAYS(IsVirtual(pTab)) && ALWAYS(pTab->u.vtab.p!=0) ){
144963 VTable *p;
144964 int (*xDestroy)(sqlite3_vtab *);
144965 for(p=pTab->u.vtab.p; p; p=p->pNext){
144966 assert( p->pVtab );
144967 if( p->pVtab->nRef>0 ){
@@ -144946,10 +145190,11 @@
145190 int rc = 0;
145191
145192 /* Check to see the left operand is a column in a virtual table */
145193 if( NEVER(pExpr==0) ) return pDef;
145194 if( pExpr->op!=TK_COLUMN ) return pDef;
145195 assert( ExprUseYTab(pExpr) );
145196 pTab = pExpr->y.pTab;
145197 if( pTab==0 ) return pDef;
145198 if( !IsVirtual(pTab) ) return pDef;
145199 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
145200 assert( pVtab!=0 );
@@ -145254,11 +145499,11 @@
145499 int iBase; /* Base register of multi-key index record */
145500 int nPrefix; /* Number of prior entires in the key */
145501 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
145502 } *aInLoop; /* Information about each nested IN operator */
145503 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
145504 Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */
145505 } u;
145506 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
145507 Bitmask notReady; /* FROM entries not usable at this level */
145508 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
145509 int addrVisit; /* Address at which row is visited */
@@ -146182,20 +146427,27 @@
146427 ){
146428 sqlite3 *db = pParse->db;
146429 Expr *pNew;
146430 pNew = sqlite3ExprDup(db, pX, 0);
146431 if( db->mallocFailed==0 ){
146432 ExprList *pOrigRhs; /* Original unmodified RHS */
146433 ExprList *pOrigLhs; /* Original unmodified LHS */
146434 ExprList *pRhs = 0; /* New RHS after modifications */
146435 ExprList *pLhs = 0; /* New LHS after mods */
146436 int i; /* Loop counter */
146437 Select *pSelect; /* Pointer to the SELECT on the RHS */
146438
146439 assert( ExprUseXSelect(pNew) );
146440 pOrigRhs = pNew->x.pSelect->pEList;
146441 assert( pNew->pLeft!=0 );
146442 assert( ExprUseXList(pNew->pLeft) );
146443 pOrigLhs = pNew->pLeft->x.pList;
146444 for(i=iEq; i<pLoop->nLTerm; i++){
146445 if( pLoop->aLTerm[i]->pExpr==pX ){
146446 int iField;
146447 assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
146448 iField = pLoop->aLTerm[i]->u.x.iField - 1;
146449 if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
146450 pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
146451 pOrigRhs->a[iField].pExpr = 0;
146452 assert( pOrigLhs->a[iField].pExpr!=0 );
146453 pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
@@ -146306,11 +146558,11 @@
146558 assert( pLoop->aLTerm[i]!=0 );
146559 if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
146560 }
146561
146562 iTab = 0;
146563 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
146564 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
146565 }else{
146566 sqlite3 *db = pParse->db;
146567 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
146568
@@ -146328,12 +146580,12 @@
146580 bRev = !bRev;
146581 }
146582 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
146583 VdbeCoverageIf(v, bRev);
146584 VdbeCoverageIf(v, !bRev);
146585
146586 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
 
146587 pLoop->wsFlags |= WHERE_IN_ABLE;
146588 if( pLevel->u.in.nIn==0 ){
146589 pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
146590 }
146591 if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
@@ -146871,21 +147123,23 @@
147123 */
147124 static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
147125 assert( nReg>0 );
147126 if( p && sqlite3ExprIsVector(p) ){
147127 #ifndef SQLITE_OMIT_SUBQUERY
147128 if( ExprUseXSelect(p) ){
147129 Vdbe *v = pParse->pVdbe;
147130 int iSelect;
147131 assert( p->op==TK_SELECT );
147132 iSelect = sqlite3CodeSubselect(pParse, p);
147133 sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
147134 }else
147135 #endif
147136 {
147137 int i;
147138 const ExprList *pList;
147139 assert( ExprUseXList(p) );
147140 pList = p->x.pList;
147141 assert( nReg<=pList->nExpr );
147142 for(i=0; i<nReg; i++){
147143 sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i);
147144 }
147145 }
@@ -146934,14 +147188,14 @@
147188 preserveExpr(pX, pExpr);
147189 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
147190 pExpr->op = TK_COLUMN;
147191 pExpr->iTable = pX->iIdxCur;
147192 pExpr->iColumn = pX->iIdxCol;
 
147193 testcase( ExprHasProperty(pExpr, EP_Skip) );
147194 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
147195 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
147196 pExpr->y.pTab = 0;
147197 return WRC_Prune;
147198 }else{
147199 return WRC_Continue;
147200 }
147201 }
@@ -146952,11 +147206,11 @@
147206 */
147207 static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
147208 if( pExpr->op==TK_COLUMN ){
147209 IdxExprTrans *pX = p->u.pIdxTrans;
147210 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
147211 assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 );
147212 preserveExpr(pX, pExpr);
147213 pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
147214 pExpr->iTable = pX->iIdxCur;
147215 pExpr->iColumn = pX->iIdxCol;
147216 pExpr->y.pTab = 0;
@@ -147189,11 +147443,16 @@
147443 ** the u.vtab.idxStr. NULL it out to prevent a use-after-free */
147444 if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
147445 pLevel->p1 = iCur;
147446 pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
147447 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
147448 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
147449 if( pLoop->wsFlags & WHERE_IN_ABLE ){
147450 iIn = pLevel->u.in.nIn;
147451 }else{
147452 iIn = 0;
147453 }
147454 for(j=nConstraint-1; j>=0; j--){
147455 pTerm = pLoop->aLTerm[j];
147456 if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
147457 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
147458 disableTerm(pLevel, pTerm);
@@ -148078,11 +148337,14 @@
148337 }
148338 sqlite3ExprDelete(db, pDelete);
148339 }
148340 }
148341 ExplainQueryPlanPop(pParse);
148342 assert( pLevel->pWLoop==pLoop );
148343 assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 );
148344 assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 );
148345 pLevel->u.pCoveringIdx = pCov;
148346 if( pCov ) pLevel->iIdxCur = iCovCur;
148347 if( pAndExpr ){
148348 pAndExpr->pLeft = 0;
148349 sqlite3ExprDelete(db, pAndExpr);
148350 }
@@ -148222,16 +148484,17 @@
148484 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
148485 }
148486 #endif
148487 assert( !ExprHasProperty(pE, EP_FromJoin) );
148488 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
148489 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
148490 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
148491 WO_EQ|WO_IN|WO_IS, 0);
148492 if( pAlt==0 ) continue;
148493 if( pAlt->wtFlags & (TERM_CODED) ) continue;
148494 if( (pAlt->eOperator & WO_IN)
148495 && ExprUseXSelect(pAlt->pExpr)
148496 && (pAlt->pExpr->x.pSelect->pEList->nExpr>1)
148497 ){
148498 continue;
148499 }
148500 testcase( pAlt->eOperator & WO_EQ );
@@ -148476,10 +148739,11 @@
148739 return 0;
148740 }
148741 #ifdef SQLITE_EBCDIC
148742 if( *pnoCase ) return 0;
148743 #endif
148744 assert( ExprUseXList(pExpr) );
148745 pList = pExpr->x.pList;
148746 pLeft = pList->a[1].pExpr;
148747
148748 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
148749 op = pRight->op;
@@ -148491,11 +148755,12 @@
148755 z = sqlite3_value_text(pVal);
148756 }
148757 sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
148758 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
148759 }else if( op==TK_STRING ){
148760 assert( !ExprHasProperty(pRight, EP_IntValue) );
148761 z = (u8*)pRight->u.zToken;
148762 }
148763 if( z ){
148764
148765 /* Count the number of prefix characters prior to the first wildcard */
148766 cnt = 0;
@@ -148520,11 +148785,13 @@
148785
148786 /* Get the pattern prefix. Remove all escapes from the prefix. */
148787 pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
148788 if( pPrefix ){
148789 int iFrom, iTo;
148790 char *zNew;
148791 assert( !ExprHasProperty(pPrefix, EP_IntValue) );
148792 zNew = pPrefix->u.zToken;
148793 zNew[cnt] = 0;
148794 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
148795 if( zNew[iFrom]==wc[3] ) iFrom++;
148796 zNew[iTo++] = zNew[iFrom];
148797 }
@@ -148544,11 +148811,13 @@
148811 ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148812 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148813 */
148814 if( pLeft->op!=TK_COLUMN
148815 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148816 || (ALWAYS( ExprUseYTab(pLeft) )
148817 && pLeft->y.pTab
148818 && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148819 ){
148820 int isNum;
148821 double rDummy;
148822 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148823 if( isNum<=0 ){
@@ -148572,10 +148841,11 @@
148841 /* If the RHS pattern is a bound parameter, make arrangements to
148842 ** reprepare the statement when that parameter is rebound */
148843 if( op==TK_VARIABLE ){
148844 Vdbe *v = pParse->pVdbe;
148845 sqlite3VdbeSetVarmask(v, pRight->iColumn);
148846 assert( !ExprHasProperty(pRight, EP_IntValue) );
148847 if( *pisComplete && pRight->u.zToken[1] ){
148848 /* If the rhs of the LIKE expression is a variable, and the current
148849 ** value of the variable means there is no need to invoke the LIKE
148850 ** function, then no OP_Variable will be added to the program.
148851 ** This causes problems for the sqlite3_bind_parameter_name()
@@ -148645,10 +148915,11 @@
148915 };
148916 ExprList *pList;
148917 Expr *pCol; /* Column reference */
148918 int i;
148919
148920 assert( ExprUseXList(pExpr) );
148921 pList = pExpr->x.pList;
148922 if( pList==0 || pList->nExpr!=2 ){
148923 return 0;
148924 }
148925
@@ -148658,13 +148929,15 @@
148929 **
148930 ** vtab_column MATCH expression
148931 ** MATCH(expression,vtab_column)
148932 */
148933 pCol = pList->a[1].pExpr;
148934 assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148935 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148936 if( ExprIsVtab(pCol) ){
148937 for(i=0; i<ArraySize(aOp); i++){
148938 assert( !ExprHasProperty(pExpr, EP_IntValue) );
148939 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
148940 *peOp2 = aOp[i].eOp2;
148941 *ppRight = pList->a[0].pExpr;
148942 *ppLeft = pCol;
148943 return 1;
@@ -148681,20 +148954,22 @@
148954 ** Historically, xFindFunction expected to see lower-case function
148955 ** names. But for this use case, xFindFunction is expected to deal
148956 ** with function names in an arbitrary case.
148957 */
148958 pCol = pList->a[0].pExpr;
148959 assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148960 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148961 if( ExprIsVtab(pCol) ){
148962 sqlite3_vtab *pVtab;
148963 sqlite3_module *pMod;
148964 void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
148965 void *pNotUsed;
148966 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
148967 assert( pVtab!=0 );
148968 assert( pVtab->pModule!=0 );
148969 assert( !ExprHasProperty(pExpr, EP_IntValue) );
148970 pMod = (sqlite3_module *)pVtab->pModule;
148971 if( pMod->xFindFunction!=0 ){
148972 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
148973 if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
148974 *peOp2 = i;
148975 *ppRight = pList->a[1].pExpr;
@@ -148705,14 +148980,16 @@
148980 }
148981 }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
148982 int res = 0;
148983 Expr *pLeft = pExpr->pLeft;
148984 Expr *pRight = pExpr->pRight;
148985 assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
148986 testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
148987 if( ExprIsVtab(pLeft) ){
148988 res++;
148989 }
148990 assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
148991 testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
148992 if( pRight && ExprIsVtab(pRight) ){
148993 res++;
148994 SWAP(Expr*, pLeft, pRight);
148995 }
@@ -148961,10 +149238,11 @@
149238 int j;
149239 Bitmask b = 0;
149240 pOrTerm->u.pAndInfo = pAndInfo;
149241 pOrTerm->wtFlags |= TERM_ANDINFO;
149242 pOrTerm->eOperator = WO_AND;
149243 pOrTerm->leftCursor = -1;
149244 pAndWC = &pAndInfo->wc;
149245 memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
149246 sqlite3WhereClauseInit(pAndWC, pWC->pWInfo);
149247 sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
149248 sqlite3WhereExprAnalyze(pSrc, pAndWC);
@@ -149003,15 +149281,14 @@
149281 /*
149282 ** Record the set of tables that satisfy case 3. The set might be
149283 ** empty.
149284 */
149285 pOrInfo->indexable = indexable;
149286 pTerm->eOperator = WO_OR;
149287 pTerm->leftCursor = -1;
149288 if( indexable ){
 
149289 pWC->hasOr = 1;
 
 
149290 }
149291
149292 /* For a two-way OR, attempt to implementation case 2.
149293 */
149294 if( indexable && pOrWc->nTerm==2 ){
@@ -149080,10 +149357,11 @@
149357 testcase( pOrTerm->wtFlags & TERM_COPIED );
149358 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
149359 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
149360 continue;
149361 }
149362 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149363 iColumn = pOrTerm->u.x.leftColumn;
149364 iCursor = pOrTerm->leftCursor;
149365 pLeft = pOrTerm->pExpr->pLeft;
149366 break;
149367 }
@@ -149100,10 +149378,11 @@
149378 /* We have found a candidate table and column. Check to see if that
149379 ** table and column is common to every term in the OR clause */
149380 okToChngToIN = 1;
149381 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
149382 assert( pOrTerm->eOperator & WO_EQ );
149383 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149384 if( pOrTerm->leftCursor!=iCursor ){
149385 pOrTerm->wtFlags &= ~TERM_OR_OK;
149386 }else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR
149387 && sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1)
149388 )){
@@ -149136,10 +149415,11 @@
149415 Expr *pNew; /* The complete IN operator */
149416
149417 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
149418 if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
149419 assert( pOrTerm->eOperator & WO_EQ );
149420 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149421 assert( pOrTerm->leftCursor==iCursor );
149422 assert( pOrTerm->u.x.leftColumn==iColumn );
149423 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
149424 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
149425 pLeft = pOrTerm->pExpr->pLeft;
@@ -149148,11 +149428,11 @@
149428 pDup = sqlite3ExprDup(db, pLeft, 0);
149429 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
149430 if( pNew ){
149431 int idxNew;
149432 transferJoinMarkings(pNew, pExpr);
149433 assert( ExprUseXList(pNew) );
149434 pNew->x.pList = pList;
149435 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
149436 testcase( idxNew==0 );
149437 exprAnalyze(pSrc, pWC, idxNew);
149438 /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
@@ -149276,10 +149556,11 @@
149556 ** on the first element of the vector. */
149557 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
149558 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
149559 assert( op<=TK_GE );
149560 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
149561 assert( ExprUseXList(pExpr) );
149562 pExpr = pExpr->x.pList->a[0].pExpr;
149563
149564 }
149565
149566 if( pExpr->op==TK_COLUMN ){
@@ -149342,11 +149623,11 @@
149623 prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft);
149624 op = pExpr->op;
149625 if( op==TK_IN ){
149626 assert( pExpr->pRight==0 );
149627 if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
149628 if( ExprUseXSelect(pExpr) ){
149629 pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect);
149630 }else{
149631 pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList);
149632 }
149633 }else if( op==TK_ISNULL ){
@@ -149378,15 +149659,17 @@
149659 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
149660
149661 if( pTerm->u.x.iField>0 ){
149662 assert( op==TK_IN );
149663 assert( pLeft->op==TK_VECTOR );
149664 assert( ExprUseXList(pLeft) );
149665 pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr;
149666 }
149667
149668 if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
149669 pTerm->leftCursor = aiCurCol[0];
149670 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149671 pTerm->u.x.leftColumn = aiCurCol[1];
149672 pTerm->eOperator = operatorMask(op) & opMask;
149673 }
149674 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
149675 if( pRight
@@ -149420,10 +149703,11 @@
149703 pDup = pExpr;
149704 pNew = pTerm;
149705 }
149706 pNew->wtFlags |= exprCommute(pParse, pDup);
149707 pNew->leftCursor = aiCurCol[0];
149708 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149709 pNew->u.x.leftColumn = aiCurCol[1];
149710 testcase( (prereqLeft | extraRight) != prereqLeft );
149711 pNew->prereqRight = prereqLeft | extraRight;
149712 pNew->prereqAll = prereqAll;
149713 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
@@ -149430,10 +149714,11 @@
149714 }else
149715 if( op==TK_ISNULL
149716 && !ExprHasProperty(pExpr,EP_FromJoin)
149717 && 0==sqlite3ExprCanBeNull(pLeft)
149718 ){
149719 assert( !ExprHasProperty(pExpr, EP_IntValue) );
149720 pExpr->op = TK_TRUEFALSE;
149721 pExpr->u.zToken = "false";
149722 ExprSetProperty(pExpr, EP_IsFalse);
149723 pTerm->prereqAll = 0;
149724 pTerm->eOperator = 0;
@@ -149455,13 +149740,15 @@
149740 ** term. That means that if the BETWEEN term is coded, the children are
149741 ** skipped. Or, if the children are satisfied by an index, the original
149742 ** BETWEEN term is skipped.
149743 */
149744 else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
149745 ExprList *pList;
149746 int i;
149747 static const u8 ops[] = {TK_GE, TK_LE};
149748 assert( ExprUseXList(pExpr) );
149749 pList = pExpr->x.pList;
149750 assert( pList!=0 );
149751 assert( pList->nExpr==2 );
149752 for(i=0; i<2; i++){
149753 Expr *pNewExpr;
149754 int idxNew;
@@ -149550,12 +149837,16 @@
149837 int idxNew1;
149838 int idxNew2;
149839 const char *zCollSeqName; /* Name of collating sequence */
149840 const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
149841
149842 assert( ExprUseXList(pExpr) );
149843 pLeft = pExpr->x.pList->a[1].pExpr;
149844 pStr2 = sqlite3ExprDup(db, pStr1, 0);
149845 assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) );
149846 assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) );
149847
149848
149849 /* Convert the lower bound to upper-case and the upper bound to
149850 ** lower-case (upper-case is less than lower-case in ASCII) so that
149851 ** the range constraints also work for BLOBs
149852 */
@@ -149651,10 +149942,11 @@
149942 ** not use window functions.
149943 */
149944 else if( pExpr->op==TK_IN
149945 && pTerm->u.x.iField==0
149946 && pExpr->pLeft->op==TK_VECTOR
149947 && ALWAYS( ExprUseXSelect(pExpr) )
149948 && pExpr->x.pSelect->pPrior==0
149949 #ifndef SQLITE_OMIT_WINDOWFUNC
149950 && pExpr->x.pSelect->pWin==0
149951 #endif
149952 && pWC->op==TK_AND
@@ -149814,18 +150106,19 @@
150106 mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
150107 if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft);
150108 if( p->pRight ){
150109 mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight);
150110 assert( p->x.pList==0 );
150111 }else if( ExprUseXSelect(p) ){
150112 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
150113 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
150114 }else if( p->x.pList ){
150115 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
150116 }
150117 #ifndef SQLITE_OMIT_WINDOWFUNC
150118 if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && ExprUseYWin(p) ){
150119 assert( p->y.pWin!=0 );
150120 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
150121 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
150122 mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter);
150123 }
150124 #endif
@@ -149896,10 +150189,11 @@
150189 }
150190 pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
150191 if( pColRef==0 ) return;
150192 pColRef->iTable = pItem->iCursor;
150193 pColRef->iColumn = k++;
150194 assert( ExprUseYTab(pColRef) );
150195 pColRef->y.pTab = pTab;
150196 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
150197 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
150198 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
150199 if( pItem->fg.jointype & JT_LEFT ){
@@ -150197,12 +150491,14 @@
150491 pWC = pScan->pWC;
150492 while(1){
150493 iColumn = pScan->aiColumn[pScan->iEquiv-1];
150494 iCur = pScan->aiCur[pScan->iEquiv-1];
150495 assert( pWC!=0 );
150496 assert( iCur>=0 );
150497 do{
150498 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
150499 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 );
150500 if( pTerm->leftCursor==iCur
150501 && pTerm->u.x.leftColumn==iColumn
150502 && (iColumn!=XN_EXPR
150503 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
150504 pScan->pIdxExpr,iCur)==0)
@@ -150638,10 +150934,11 @@
150934 ** the RHS of a LEFT JOIN. Such a term can only be used if it is from
150935 ** the ON clause. */
150936 return 0;
150937 }
150938 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
150939 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150940 if( pTerm->u.x.leftColumn<0 ) return 0;
150941 aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
150942 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
150943 testcase( pTerm->pExpr->op==TK_IS );
150944 return 1;
@@ -150710,12 +151007,15 @@
151007 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
151008 pPartial = sqlite3ExprAnd(pParse, pPartial,
151009 sqlite3ExprDup(pParse->db, pExpr, 0));
151010 }
151011 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
151012 int iCol;
151013 Bitmask cMask;
151014 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151015 iCol = pTerm->u.x.leftColumn;
151016 cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151017 testcase( iCol==BMS );
151018 testcase( iCol==BMS-1 );
151019 if( !sentWarning ){
151020 sqlite3_log(SQLITE_WARNING_AUTOINDEX,
151021 "automatic index on %s(%s)", pTable->zName,
@@ -150763,12 +151063,15 @@
151063 pIdx->pTable = pTable;
151064 n = 0;
151065 idxCols = 0;
151066 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
151067 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
151068 int iCol;
151069 Bitmask cMask;
151070 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151071 iCol = pTerm->u.x.leftColumn;
151072 cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151073 testcase( iCol==BMS-1 );
151074 testcase( iCol==BMS );
151075 if( (idxCols & cMask)==0 ){
151076 Expr *pX = pTerm->pExpr;
151077 idxCols |= cMask;
@@ -150891,10 +151194,11 @@
151194 testcase( pTerm->eOperator & WO_ISNULL );
151195 testcase( pTerm->eOperator & WO_IS );
151196 testcase( pTerm->eOperator & WO_ALL );
151197 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
151198 if( pTerm->wtFlags & TERM_VNULL ) continue;
151199 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151200 assert( pTerm->u.x.leftColumn>=(-1) );
151201 nTerm++;
151202 }
151203
151204 /* If the ORDER BY clause contains only columns in the current
@@ -150951,10 +151255,11 @@
151255 if( (pSrc->fg.jointype & JT_LEFT)!=0
151256 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
151257 ){
151258 continue;
151259 }
151260 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151261 assert( pTerm->u.x.leftColumn>=(-1) );
151262 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
151263 pIdxCons[j].iTermOffset = i;
151264 op = pTerm->eOperator & WO_ALL;
151265 if( op==WO_IN ) op = WO_EQ;
@@ -151714,10 +152019,11 @@
152019 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
152020 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
152021 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
152022 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
152023 if( pTerm->eOperator & WO_SINGLE ){
152024 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152025 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
152026 pTerm->leftCursor, pTerm->u.x.leftColumn);
152027 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
152028 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
152029 pTerm->u.pOrInfo->indexable);
@@ -151731,11 +152037,11 @@
152037 ** shown about each Term */
152038 if( sqlite3WhereTrace & 0x10000 ){
152039 sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx",
152040 pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight);
152041 }
152042 if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){
152043 sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField);
152044 }
152045 if( pTerm->iParent>=0 ){
152046 sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
152047 }
@@ -151895,11 +152201,12 @@
152201 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
152202 int i;
152203 assert( pWInfo!=0 );
152204 for(i=0; i<pWInfo->nLevel; i++){
152205 WhereLevel *pLevel = &pWInfo->a[i];
152206 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){
152207 assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 );
152208 sqlite3DbFree(db, pLevel->u.in.aInLoop);
152209 }
152210 }
152211 sqlite3WhereClauseClear(&pWInfo->sWC);
152212 while( pWInfo->pLoops ){
@@ -152330,13 +152637,16 @@
152637 /* Test if comparison i of pTerm is compatible with column (i+nEq)
152638 ** of the index. If not, exit the loop. */
152639 char aff; /* Comparison affinity */
152640 char idxaff = 0; /* Indexed columns affinity */
152641 CollSeq *pColl; /* Comparison collation sequence */
152642 Expr *pLhs, *pRhs;
152643
152644 assert( ExprUseXList(pTerm->pExpr->pLeft) );
152645 pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr;
152646 pRhs = pTerm->pExpr->pRight;
152647 if( ExprUseXSelect(pRhs) ){
152648 pRhs = pRhs->x.pSelect->pEList->a[i].pExpr;
152649 }else{
152650 pRhs = pRhs->x.pList->a[i].pExpr;
152651 }
152652
@@ -152493,11 +152803,11 @@
152803 || (pNew->wsFlags & WHERE_SKIPSCAN)!=0
152804 );
152805
152806 if( eOp & WO_IN ){
152807 Expr *pExpr = pTerm->pExpr;
152808 if( ExprUseXSelect(pExpr) ){
152809 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
152810 int i;
152811 nIn = 46; assert( 46==sqlite3LogEst(25) );
152812
152813 /* The expression may actually be of the form (x, y) IN (SELECT...).
@@ -152634,11 +152944,11 @@
152944 #ifdef SQLITE_ENABLE_STAT4
152945 tRowcnt nOut = 0;
152946 if( nInMul==0
152947 && pProbe->nSample
152948 && ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol)
152949 && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr))
152950 && OptimizationEnabled(db, SQLITE_Stat4)
152951 ){
152952 Expr *pExpr = pTerm->pExpr;
152953 if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
152954 testcase( eOp & WO_EQ );
@@ -152910,10 +153220,11 @@
153220 pTab = pSrc->pTab;
153221 pWC = pBuilder->pWC;
153222 assert( !IsVirtual(pSrc->pTab) );
153223
153224 if( pSrc->fg.isIndexedBy ){
153225 assert( pSrc->fg.isCte==0 );
153226 /* An INDEXED BY clause specifies a particular index to use */
153227 pProbe = pSrc->u2.pIBIndex;
153228 }else if( !HasRowid(pTab) ){
153229 pProbe = pTab->pIndex;
153230 }else{
@@ -155380,11 +155691,11 @@
155691 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
155692 #endif
155693 }else{
155694 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
155695 }
155696 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
155697 struct InLoop *pIn;
155698 int j;
155699 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
155700 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
155701 assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
@@ -155449,14 +155760,14 @@
155760 if( (ws & WHERE_IDX_ONLY)==0 ){
155761 assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
155762 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
155763 }
155764 if( (ws & WHERE_INDEXED)
155765 || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx)
155766 ){
155767 if( ws & WHERE_MULTI_OR ){
155768 Index *pIx = pLevel->u.pCoveringIdx;
155769 int iDb = sqlite3SchemaToIndex(db, pIx->pSchema);
155770 sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb);
155771 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
155772 }
155773 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -155533,11 +155844,11 @@
155844 ** reference the index.
155845 */
155846 if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){
155847 pIdx = pLoop->u.btree.pIndex;
155848 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
155849 pIdx = pLevel->u.pCoveringIdx;
155850 }
155851 if( pIdx
155852 && !db->mallocFailed
155853 ){
155854 if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){
@@ -156194,28 +156505,28 @@
156505 static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ }
156506
156507 /* Window functions that use all window interfaces: xStep, xFinal,
156508 ** xValue, and xInverse */
156509 #define WINDOWFUNCALL(name,nArg,extra) { \
156510 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156511 name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \
156512 name ## InvFunc, name ## Name, {0} \
156513 }
156514
156515 /* Window functions that are implemented using bytecode and thus have
156516 ** no-op routines for their methods */
156517 #define WINDOWFUNCNOOP(name,nArg,extra) { \
156518 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156519 noopStepFunc, noopValueFunc, noopValueFunc, \
156520 noopStepFunc, name ## Name, {0} \
156521 }
156522
156523 /* Window functions that use all window interfaces: xStep, the
156524 ** same routine for xFinalize and xValue and which never call
156525 ** xInverse. */
156526 #define WINDOWFUNCX(name,nArg,extra) { \
156527 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156528 name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \
156529 noopStepFunc, name ## Name, {0} \
156530 }
156531
156532
@@ -156554,11 +156865,12 @@
156865 return WRC_Continue;
156866 }
156867
156868 static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
156869 if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
156870 assert( !ExprHasProperty(pExpr, EP_IntValue) );
156871 sqlite3ErrorMsg(pWalker->pParse,
156872 "misuse of aggregate: %s()", pExpr->u.zToken);
156873 }
156874 return WRC_Continue;
156875 }
156876
@@ -156642,11 +156954,13 @@
156954 /* Append the arguments passed to each window function to the
156955 ** sub-select expression list. Also allocate two registers for each
156956 ** window function - one for the accumulator, another for interim
156957 ** results. */
156958 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
156959 ExprList *pArgs;
156960 assert( ExprUseXList(pWin->pOwner) );
156961 pArgs = pWin->pOwner->x.pList;
156962 if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
156963 selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
156964 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
156965 pWin->bExprArgs = 1;
156966 }else{
@@ -157035,12 +157349,15 @@
157349 **
157350 ** regApp+0: slot to copy min()/max() argument to for MakeRecord
157351 ** regApp+1: integer value used to ensure keys are unique
157352 ** regApp+2: output of MakeRecord
157353 */
157354 ExprList *pList;
157355 KeyInfo *pKeyInfo;
157356 assert( ExprUseXList(pWin->pOwner) );
157357 pList = pWin->pOwner->x.pList;
157358 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
157359 pWin->csrApp = pParse->nTab++;
157360 pWin->regApp = pParse->nMem+1;
157361 pParse->nMem += 3;
157362 if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
157363 assert( pKeyInfo->aSortFlags[0]==0 );
@@ -157124,11 +157441,13 @@
157441 /*
157442 ** Return the number of arguments passed to the window-function associated
157443 ** with the object passed as the only argument to this function.
157444 */
157445 static int windowArgCount(Window *pWin){
157446 const ExprList *pList;
157447 assert( ExprUseXList(pWin->pOwner) );
157448 pList = pWin->pOwner->x.pList;
157449 return (pList ? pList->nExpr : 0);
157450 }
157451
157452 typedef struct WindowCodeArg WindowCodeArg;
157453 typedef struct WindowCsrAndReg WindowCsrAndReg;
@@ -157309,10 +157628,11 @@
157628 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
157629 }else if( pFunc->xSFunc!=noopStepFunc ){
157630 int addrIf = 0;
157631 if( pWin->pFilter ){
157632 int regTmp;
157633 assert( ExprUseXList(pWin->pOwner) );
157634 assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
157635 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
157636 regTmp = sqlite3GetTempReg(pParse);
157637 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
157638 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
@@ -157322,10 +157642,11 @@
157642
157643 if( pWin->bExprArgs ){
157644 int iOp = sqlite3VdbeCurrentAddr(v);
157645 int iEnd;
157646
157647 assert( ExprUseXList(pWin->pOwner) );
157648 nArg = pWin->pOwner->x.pList->nExpr;
157649 regArg = sqlite3GetTempRange(pParse, nArg);
157650 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
157651
157652 for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
@@ -157336,10 +157657,11 @@
157657 }
157658 }
157659 if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
157660 CollSeq *pColl;
157661 assert( nArg>0 );
157662 assert( ExprUseXList(pWin->pOwner) );
157663 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
157664 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
157665 }
157666 sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
157667 bInverse, regArg, pWin->regAccum);
@@ -157521,10 +157843,11 @@
157843 Parse *pParse = p->pParse;
157844 Window *pWin;
157845
157846 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
157847 FuncDef *pFunc = pWin->pFunc;
157848 assert( ExprUseXList(pWin->pOwner) );
157849 if( pFunc->zName==nth_valueName
157850 || pFunc->zName==first_valueName
157851 ){
157852 int csr = pWin->csrApp;
157853 int lbl = sqlite3VdbeMakeLabel(pParse);
@@ -158870,13 +159193,13 @@
159193 p->affExpr = 0;
159194 p->flags = EP_Leaf;
159195 ExprClearVVAProperties(p);
159196 p->iAgg = -1;
159197 p->pLeft = p->pRight = 0;
 
159198 p->pAggInfo = 0;
159199 memset(&p->x, 0, sizeof(p->x));
159200 memset(&p->y, 0, sizeof(p->y));
159201 p->op2 = 0;
159202 p->iTable = 0;
159203 p->iColumn = 0;
159204 p->u.zToken = (char*)&p[1];
159205 memcpy(p->u.zToken, t.z, t.n);
@@ -166966,11 +167289,13 @@
167289 ** if this is not the last copy of the function, do not invoke it. Multiple
167290 ** copies of a single function are created when create_function() is called
167291 ** with SQLITE_ANY as the encoding.
167292 */
167293 static void functionDestroy(sqlite3 *db, FuncDef *p){
167294 FuncDestructor *pDestructor;
167295 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
167296 pDestructor = p->u.pDestructor;
167297 if( pDestructor ){
167298 pDestructor->nRef--;
167299 if( pDestructor->nRef==0 ){
167300 pDestructor->xDestroy(pDestructor->pUserData);
167301 sqlite3DbFree(db, pDestructor);
@@ -168987,10 +169312,11 @@
169312 ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
169313 ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
169314 ** off all other flags.
169315 */
169316 flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
169317 SQLITE_OPEN_EXCLUSIVE |
169318 SQLITE_OPEN_MAIN_DB |
169319 SQLITE_OPEN_TEMP_DB |
169320 SQLITE_OPEN_TRANSIENT_DB |
169321 SQLITE_OPEN_MAIN_JOURNAL |
169322 SQLITE_OPEN_TEMP_JOURNAL |
@@ -172095,10 +172421,11 @@
172421 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
172422 #ifdef SQLITE_TEST
172423 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*);
172424 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
172425 #endif
172426 SQLITE_PRIVATE void *sqlite3Fts3MallocZero(i64 nByte);
172427
172428 SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
172429 sqlite3_tokenizer_cursor **
172430 );
172431
@@ -177176,12 +177503,12 @@
177503 case FTSQUERY_OR: {
177504 Fts3Expr *pLeft = pExpr->pLeft;
177505 Fts3Expr *pRight = pExpr->pRight;
177506 sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
177507
177508 assert_fts3_nc( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
177509 assert_fts3_nc( pRight->bStart || pLeft->iDocid==pRight->iDocid );
177510
177511 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
177512 fts3EvalNextRow(pCsr, pLeft, pRc);
177513 }else if( pLeft->bEof || iCmp>0 ){
177514 fts3EvalNextRow(pCsr, pRight, pRc);
@@ -178617,11 +178944,11 @@
178944 /*
178945 ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
178946 ** zero the memory before returning a pointer to it. If unsuccessful,
178947 ** return NULL.
178948 */
178949 SQLITE_PRIVATE void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){
178950 void *pRet = sqlite3_malloc64(nByte);
178951 if( pRet ) memset(pRet, 0, nByte);
178952 return pRet;
178953 }
178954
@@ -178698,11 +179025,11 @@
179025 sqlite3_int64 nByte; /* total space to allocate */
179026
179027 rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
179028 if( rc==SQLITE_OK ){
179029 nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
179030 pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte);
179031 if( !pRet ){
179032 rc = SQLITE_NOMEM;
179033 }else{
179034 pRet->eType = FTSQUERY_PHRASE;
179035 pRet->pPhrase = (Fts3Phrase *)&pRet[1];
@@ -178953,11 +179280,11 @@
179280 */
179281 cNext = zInput[nKey];
179282 if( fts3isspace(cNext)
179283 || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
179284 ){
179285 pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179286 if( !pRet ){
179287 return SQLITE_NOMEM;
179288 }
179289 pRet->eType = pKey->eType;
179290 pRet->nNear = nNear;
@@ -179132,11 +179459,11 @@
179459
179460 if( !sqlite3_fts3_enable_parentheses
179461 && p->eType==FTSQUERY_PHRASE && pParse->isNot
179462 ){
179463 /* Create an implicit NOT operator. */
179464 Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179465 if( !pNot ){
179466 sqlite3Fts3ExprFree(p);
179467 rc = SQLITE_NOMEM;
179468 goto exprparse_out;
179469 }
@@ -179166,11 +179493,11 @@
179493
179494 if( isPhrase && !isRequirePhrase ){
179495 /* Insert an implicit AND operator. */
179496 Fts3Expr *pAnd;
179497 assert( pRet && pPrev );
179498 pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179499 if( !pAnd ){
179500 sqlite3Fts3ExprFree(p);
179501 rc = SQLITE_NOMEM;
179502 goto exprparse_out;
179503 }
@@ -183396,12 +183723,22 @@
183723 pReader->aNode = 0;
183724 if( pElem ){
183725 char *aCopy;
183726 PendingList *pList = (PendingList *)fts3HashData(pElem);
183727 int nCopy = pList->nData+1;
183728
183729 int nTerm = fts3HashKeysize(pElem);
183730 if( (nTerm+1)>pReader->nTermAlloc ){
183731 sqlite3_free(pReader->zTerm);
183732 pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2);
183733 if( !pReader->zTerm ) return SQLITE_NOMEM;
183734 pReader->nTermAlloc = (nTerm+1)*2;
183735 }
183736 memcpy(pReader->zTerm, fts3HashKey(pElem), nTerm);
183737 pReader->zTerm[nTerm] = '\0';
183738 pReader->nTerm = nTerm;
183739
183740 aCopy = (char*)sqlite3_malloc(nCopy);
183741 if( !aCopy ) return SQLITE_NOMEM;
183742 memcpy(aCopy, pList->aData, nCopy);
183743 pReader->nNode = pReader->nDoclist = nCopy;
183744 pReader->aNode = pReader->aDoclist = aCopy;
@@ -183650,13 +183987,11 @@
183987 ** Free all allocations associated with the iterator passed as the
183988 ** second argument.
183989 */
183990 SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){
183991 if( pReader ){
183992 sqlite3_free(pReader->zTerm);
 
 
183993 if( !fts3SegReaderIsRootOnly(pReader) ){
183994 sqlite3_free(pReader->aNode);
183995 }
183996 sqlite3_blob_close(pReader->pBlob);
183997 }
@@ -188003,13 +188338,12 @@
188338 MatchinfoBuffer *pRet;
188339 sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
188340 + sizeof(MatchinfoBuffer);
188341 sqlite3_int64 nStr = strlen(zMatchinfo);
188342
188343 pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
188344 if( pRet ){
 
188345 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
188346 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
188347 + sizeof(u32)*((int)nElem+1);
188348 pRet->nElem = (int)nElem;
188349 pRet->zMatchinfo = ((char*)pRet) + nByte;
@@ -188409,15 +188743,14 @@
188743
188744 /* Now that it is known how many phrases there are, allocate and zero
188745 ** the required space using malloc().
188746 */
188747 nByte = sizeof(SnippetPhrase) * nList;
188748 sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte);
188749 if( !sIter.aPhrase ){
188750 return SQLITE_NOMEM;
188751 }
 
188752
188753 /* Initialize the contents of the SnippetIter object. Then iterate through
188754 ** the set of phrases in the expression to populate the aPhrase[] array.
188755 */
188756 sIter.pCsr = pCsr;
@@ -189016,13 +189349,12 @@
189349 int rc = SQLITE_OK;
189350
189351 /* Allocate and populate the array of LcsIterator objects. The array
189352 ** contains one element for each matchable phrase in the query.
189353 **/
189354 aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase);
189355 if( !aIter ) return SQLITE_NOMEM;
 
189356 (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
189357
189358 for(i=0; i<pInfo->nPhrase; i++){
189359 LcsIterator *pIter = &aIter[i];
189360 nToken -= pIter->pExpr->pPhrase->nToken;
@@ -189479,11 +189811,11 @@
189811 /* Count the number of terms in the query */
189812 rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
189813 if( rc!=SQLITE_OK ) goto offsets_out;
189814
189815 /* Allocate the array of TermOffset iterators. */
189816 sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken);
189817 if( 0==sCtx.aTerm ){
189818 rc = SQLITE_NOMEM;
189819 goto offsets_out;
189820 }
189821 sCtx.iDocid = pCsr->iPrevId;
@@ -190517,11 +190849,25 @@
190849 # define NEVER(X) ((X)?(assert(0),1):0)
190850 # else
190851 # define ALWAYS(X) (X)
190852 # define NEVER(X) (X)
190853 # endif
190854 # define testcase(X)
190855 #endif
190856 #if defined(NDEBUG)
190857 # define VVA(X)
190858 #else
190859 # define VVA(X) X
190860 #endif
190861
190862 /*
190863 ** Some of the testcase() macros in this file are problematic for gcov
190864 ** in that they generate false-miss errors randomly. This is a gcov problem,
190865 ** not a problem in this case. But to work around it, we disable the
190866 ** problematic test cases for production builds.
190867 */
190868 #define json_testcase(X)
190869
190870 /* Objects */
190871 typedef struct JsonString JsonString;
190872 typedef struct JsonNode JsonNode;
190873 typedef struct JsonParse JsonParse;
@@ -190575,17 +190921,18 @@
190921 /* A single node of parsed JSON
190922 */
190923 struct JsonNode {
190924 u8 eType; /* One of the JSON_ type values */
190925 u8 jnFlags; /* JNODE flags */
190926 u8 eU; /* Which union element to use */
190927 u32 n; /* Bytes of content, or number of sub-nodes */
190928 union {
190929 const char *zJContent; /* 1: Content for INT, REAL, and STRING */
190930 u32 iAppend; /* 2: More terms for ARRAY and OBJECT */
190931 u32 iKey; /* 3: Key for ARRAY objects in json_tree() */
190932 u32 iReplace; /* 4: Replacement content for JNODE_REPLACE */
190933 JsonNode *pPatch; /* 5: Node chain of patch for JNODE_PATCH */
190934 } u;
190935 };
190936
190937 /* A completely parsed JSON string
190938 */
@@ -190862,13 +191209,15 @@
191209 sqlite3_value **aReplace /* Replacement values */
191210 ){
191211 assert( pNode!=0 );
191212 if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
191213 if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){
191214 assert( pNode->eU==4 );
191215 jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
191216 return;
191217 }
191218 assert( pNode->eU==5 );
191219 pNode = pNode->u.pPatch;
191220 }
191221 switch( pNode->eType ){
191222 default: {
191223 assert( pNode->eType==JSON_NULL );
@@ -190883,17 +191232,19 @@
191232 jsonAppendRaw(pOut, "false", 5);
191233 break;
191234 }
191235 case JSON_STRING: {
191236 if( pNode->jnFlags & JNODE_RAW ){
191237 assert( pNode->eU==1 );
191238 jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
191239 break;
191240 }
191241 /* no break */ deliberate_fall_through
191242 }
191243 case JSON_REAL:
191244 case JSON_INT: {
191245 assert( pNode->eU==1 );
191246 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
191247 break;
191248 }
191249 case JSON_ARRAY: {
191250 u32 j = 1;
@@ -190905,10 +191256,11 @@
191256 jsonRenderNode(&pNode[j], pOut, aReplace);
191257 }
191258 j += jsonNodeSize(&pNode[j]);
191259 }
191260 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191261 assert( pNode->eU==2 );
191262 pNode = &pNode[pNode->u.iAppend];
191263 j = 1;
191264 }
191265 jsonAppendChar(pOut, ']');
191266 break;
@@ -190925,10 +191277,11 @@
191277 jsonRenderNode(&pNode[j+1], pOut, aReplace);
191278 }
191279 j += 1 + jsonNodeSize(&pNode[j+1]);
191280 }
191281 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191282 assert( pNode->eU==2 );
191283 pNode = &pNode[pNode->u.iAppend];
191284 j = 1;
191285 }
191286 jsonAppendChar(pOut, '}');
191287 break;
@@ -191004,11 +191357,13 @@
191357 sqlite3_result_int(pCtx, 0);
191358 break;
191359 }
191360 case JSON_INT: {
191361 sqlite3_int64 i = 0;
191362 const char *z;
191363 assert( pNode->eU==1 );
191364 z = pNode->u.zJContent;
191365 if( z[0]=='-' ){ z++; }
191366 while( z[0]>='0' && z[0]<='9' ){
191367 unsigned v = *(z++) - '0';
191368 if( i>=LARGEST_INT64/10 ){
191369 if( i>LARGEST_INT64/10 ) goto int_as_real;
@@ -191032,13 +191387,16 @@
191387 int_as_real: ; /* no break */ deliberate_fall_through
191388 }
191389 case JSON_REAL: {
191390 double r;
191391 #ifdef SQLITE_AMALGAMATION
191392 const char *z;
191393 assert( pNode->eU==1 );
191394 z = pNode->u.zJContent;
191395 sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
191396 #else
191397 assert( pNode->eU==1 );
191398 r = strtod(pNode->u.zJContent, 0);
191399 #endif
191400 sqlite3_result_double(pCtx, r);
191401 break;
191402 }
@@ -191045,26 +191403,30 @@
191403 case JSON_STRING: {
191404 #if 0 /* Never happens because JNODE_RAW is only set by json_set(),
191405 ** json_insert() and json_replace() and those routines do not
191406 ** call jsonReturn() */
191407 if( pNode->jnFlags & JNODE_RAW ){
191408 assert( pNode->eU==1 );
191409 sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
191410 SQLITE_TRANSIENT);
191411 }else
191412 #endif
191413 assert( (pNode->jnFlags & JNODE_RAW)==0 );
191414 if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
191415 /* JSON formatted without any backslash-escapes */
191416 assert( pNode->eU==1 );
191417 sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
191418 SQLITE_TRANSIENT);
191419 }else{
191420 /* Translate JSON formatted string into raw text */
191421 u32 i;
191422 u32 n = pNode->n;
191423 const char *z;
191424 char *zOut;
191425 u32 j;
191426 assert( pNode->eU==1 );
191427 z = pNode->u.zJContent;
191428 zOut = sqlite3_malloc( n+1 );
191429 if( zOut==0 ){
191430 sqlite3_result_error_nomem(pCtx);
191431 break;
191432 }
@@ -191187,10 +191549,11 @@
191549 return jsonParseAddNodeExpand(pParse, eType, n, zContent);
191550 }
191551 p = &pParse->aNode[pParse->nNode];
191552 p->eType = (u8)eType;
191553 p->jnFlags = 0;
191554 VVA( p->eU = zContent ? 1 : 0 );
191555 p->n = n;
191556 p->u.zJContent = zContent;
191557 return pParse->nNode++;
191558 }
191559
@@ -191254,10 +191617,11 @@
191617 return j+1;
191618 }else if( c=='[' ){
191619 /* Parse array */
191620 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
191621 if( iThis<0 ) return -1;
191622 memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
191623 for(j=i+1;;j++){
191624 while( safe_isspace(z[j]) ){ j++; }
191625 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
191626 x = jsonParseValue(pParse, j);
191627 pParse->iDepth--;
@@ -191518,10 +191882,11 @@
191882 /*
191883 ** Compare the OBJECT label at pNode against zKey,nKey. Return true on
191884 ** a match.
191885 */
191886 static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
191887 assert( pNode->eU==1 );
191888 if( pNode->jnFlags & JNODE_RAW ){
191889 if( pNode->n!=nKey ) return 0;
191890 return strncmp(pNode->u.zJContent, zKey, nKey)==0;
191891 }else{
191892 if( pNode->n!=nKey+2 ) return 0;
@@ -191583,10 +191948,11 @@
191948 }
191949 j++;
191950 j += jsonNodeSize(&pRoot[j]);
191951 }
191952 if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
191953 assert( pRoot->eU==2 );
191954 iRoot += pRoot->u.iAppend;
191955 pRoot = &pParse->aNode[iRoot];
191956 j = 1;
191957 }
191958 if( pApnd ){
@@ -191597,12 +191963,14 @@
191963 zPath += i;
191964 pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191965 if( pParse->oom ) return 0;
191966 if( pNode ){
191967 pRoot = &pParse->aNode[iRoot];
191968 assert( pRoot->eU==0 );
191969 pRoot->u.iAppend = iStart - iRoot;
191970 pRoot->jnFlags |= JNODE_APPEND;
191971 VVA( pRoot->eU = 2 );
191972 pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
191973 }
191974 return pNode;
191975 }
191976 }else if( zPath[0]=='[' ){
@@ -191621,10 +191989,11 @@
191989 while( j<=pBase->n ){
191990 if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
191991 j += jsonNodeSize(&pBase[j]);
191992 }
191993 if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
191994 assert( pBase->eU==2 );
191995 iBase += pBase->u.iAppend;
191996 pBase = &pParse->aNode[iBase];
191997 j = 1;
191998 }
191999 j = 2;
@@ -191654,10 +192023,11 @@
192023 while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
192024 if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
192025 j += jsonNodeSize(&pRoot[j]);
192026 }
192027 if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
192028 assert( pRoot->eU==2 );
192029 iRoot += pRoot->u.iAppend;
192030 pRoot = &pParse->aNode[iRoot];
192031 j = 1;
192032 }
192033 if( j<=pRoot->n ){
@@ -191669,12 +192039,14 @@
192039 iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0);
192040 pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
192041 if( pParse->oom ) return 0;
192042 if( pNode ){
192043 pRoot = &pParse->aNode[iRoot];
192044 assert( pRoot->eU==0 );
192045 pRoot->u.iAppend = iStart - iRoot;
192046 pRoot->jnFlags |= JNODE_APPEND;
192047 VVA( pRoot->eU = 2 );
192048 }
192049 return pNode;
192050 }
192051 }else{
192052 *pzErr = zPath;
@@ -191824,13 +192196,17 @@
192196 }else{
192197 zType = jsonType[x.aNode[i].eType];
192198 }
192199 jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d",
192200 i, zType, x.aNode[i].n, x.aUp[i]);
192201 assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 );
192202 if( x.aNode[i].u.zJContent!=0 ){
192203 assert( x.aNode[i].eU==1 );
192204 jsonAppendRaw(&s, " ", 1);
192205 jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n);
192206 }else{
192207 assert( x.aNode[i].eU==0 );
192208 }
192209 jsonAppendRaw(&s, "\n", 1);
192210 }
192211 jsonParseReset(&x);
192212 jsonResult(&s);
@@ -192009,10 +192385,11 @@
192385 for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){
192386 u32 nKey;
192387 const char *zKey;
192388 assert( pPatch[i].eType==JSON_STRING );
192389 assert( pPatch[i].jnFlags & JNODE_LABEL );
192390 assert( pPatch[i].eU==1 );
192391 nKey = pPatch[i].n;
192392 zKey = pPatch[i].u.zJContent;
192393 assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
192394 for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
192395 assert( pTarget[j].eType==JSON_STRING );
@@ -192025,10 +192402,13 @@
192402 }else{
192403 JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
192404 if( pNew==0 ) return 0;
192405 pTarget = &pParse->aNode[iTarget];
192406 if( pNew!=&pTarget[j+1] ){
192407 assert( pTarget[j+1].eU==0 || pTarget[j+1].eU==1 );
192408 testcase( pTarget[j+1].eU==1 );
192409 VVA( pTarget[j+1].eU = 5 );
192410 pTarget[j+1].u.pPatch = pNew;
192411 pTarget[j+1].jnFlags |= JNODE_PATCH;
192412 }
192413 }
192414 break;
@@ -192040,13 +192420,18 @@
192420 jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
192421 iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
192422 if( pParse->oom ) return 0;
192423 jsonRemoveAllNulls(pPatch);
192424 pTarget = &pParse->aNode[iTarget];
192425 assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 );
192426 testcase( pParse->aNode[iRoot].eU==2 );
192427 pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
192428 VVA( pParse->aNode[iRoot].eU = 2 );
192429 pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
192430 iRoot = iStart;
192431 assert( pParse->aNode[iPatch].eU==0 );
192432 VVA( pParse->aNode[iPatch].eU = 5 );
192433 pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
192434 pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
192435 }
192436 }
192437 return pTarget;
@@ -192184,15 +192569,19 @@
192569 for(i=1; i<(u32)argc; i+=2){
192570 zPath = (const char*)sqlite3_value_text(argv[i]);
192571 pNode = jsonLookup(&x, zPath, 0, ctx);
192572 if( x.nErr ) goto replace_err;
192573 if( pNode ){
192574 assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 );
192575 json_testcase( pNode->eU!=0 && pNode->eU!=1 );
192576 pNode->jnFlags |= (u8)JNODE_REPLACE;
192577 VVA( pNode->eU = 4 );
192578 pNode->u.iReplace = i + 1;
192579 }
192580 }
192581 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192582 assert( x.aNode[0].eU==4 );
192583 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192584 }else{
192585 jsonReturnJson(x.aNode, ctx, argv);
192586 }
192587 replace_err:
@@ -192238,15 +192627,19 @@
192627 sqlite3_result_error_nomem(ctx);
192628 goto jsonSetDone;
192629 }else if( x.nErr ){
192630 goto jsonSetDone;
192631 }else if( pNode && (bApnd || bIsSet) ){
192632 json_testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
192633 assert( pNode->eU!=3 || pNode->eU!=5 );
192634 VVA( pNode->eU = 4 );
192635 pNode->jnFlags |= (u8)JNODE_REPLACE;
192636 pNode->u.iReplace = i + 1;
192637 }
192638 }
192639 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192640 assert( x.aNode[0].eU==4 );
192641 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192642 }else{
192643 jsonReturnJson(x.aNode, ctx, argv);
192644 }
192645 jsonSetDone:
@@ -192593,10 +192986,13 @@
192986 if( p->i<p->iEnd ){
192987 u32 iUp = p->sParse.aUp[p->i];
192988 JsonNode *pUp = &p->sParse.aNode[iUp];
192989 p->eType = pUp->eType;
192990 if( pUp->eType==JSON_ARRAY ){
192991 assert( pUp->eU==0 || pUp->eU==3 );
192992 json_testcase( pUp->eU==3 );
192993 VVA( pUp->eU = 3 );
192994 if( iUp==p->i-1 ){
192995 pUp->u.iKey = 0;
192996 }else{
192997 pUp->u.iKey++;
192998 }
@@ -192639,16 +193035,19 @@
193035 iUp = p->sParse.aUp[i];
193036 jsonEachComputePath(p, pStr, iUp);
193037 pNode = &p->sParse.aNode[i];
193038 pUp = &p->sParse.aNode[iUp];
193039 if( pUp->eType==JSON_ARRAY ){
193040 assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) );
193041 testcase( pUp->eU==0 );
193042 jsonPrintf(30, pStr, "[%d]", pUp->u.iKey);
193043 }else{
193044 assert( pUp->eType==JSON_OBJECT );
193045 if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
193046 assert( pNode->eType==JSON_STRING );
193047 assert( pNode->jnFlags & JNODE_LABEL );
193048 assert( pNode->eU==1 );
193049 jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
193050 }
193051 }
193052
193053 /* Return the value of a column */
@@ -192666,10 +193065,11 @@
193065 jsonReturn(pThis, ctx, 0);
193066 }else if( p->eType==JSON_ARRAY ){
193067 u32 iKey;
193068 if( p->bRecursive ){
193069 if( p->iRowid==0 ) break;
193070 assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 );
193071 iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey;
193072 }else{
193073 iKey = p->iRowid;
193074 }
193075 sqlite3_result_int64(ctx, (sqlite3_int64)iKey);
@@ -192715,10 +193115,11 @@
193115 jsonAppendChar(&x, '$');
193116 }
193117 if( p->eType==JSON_ARRAY ){
193118 jsonPrintf(30, &x, "[%d]", p->iRowid);
193119 }else if( p->eType==JSON_OBJECT ){
193120 assert( pThis->eU==1 );
193121 jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
193122 }
193123 }
193124 jsonResult(&x);
193125 break;
@@ -192782,10 +193183,11 @@
193183 int iCol;
193184 int iMask;
193185 if( pConstraint->iColumn < JEACH_JSON ) continue;
193186 iCol = pConstraint->iColumn - JEACH_JSON;
193187 assert( iCol==0 || iCol==1 );
193188 testcase( iCol==0 );
193189 iMask = 1 << iCol;
193190 if( pConstraint->usable==0 ){
193191 unusableMask |= iMask;
193192 }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
193193 aIdx[iCol] = i;
@@ -192879,10 +193281,12 @@
193281 pNode = p->sParse.aNode;
193282 }
193283 p->iBegin = p->i = (int)(pNode - p->sParse.aNode);
193284 p->eType = pNode->eType;
193285 if( p->eType>=JSON_ARRAY ){
193286 assert( pNode->eU==0 );
193287 VVA( pNode->eU = 3 );
193288 pNode->u.iKey = 0;
193289 p->iEnd = p->i + pNode->n + 1;
193290 if( p->bRecursive ){
193291 p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType;
193292 if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){
@@ -193493,11 +193897,11 @@
193897
193898 /* The testcase() macro should already be defined in the amalgamation. If
193899 ** it is not, make it a no-op.
193900 */
193901 #ifndef SQLITE_AMALGAMATION
193902 # if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
193903 unsigned int sqlite3RtreeTestcase = 0;
193904 # define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; }
193905 # else
193906 # define testcase(X)
193907 # endif
@@ -214008,11 +214412,11 @@
214412
214413 /*
214414 ** A version of memcmp() that does not cause asan errors if one of the pointer
214415 ** parameters is NULL and the number of bytes to compare is zero.
214416 */
214417 #define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
214418
214419 /* Mark a function parameter as unused, to suppress nuisance compiler
214420 ** warnings. */
214421 #ifndef UNUSED_PARAM
214422 # define UNUSED_PARAM(X) (void)(X)
@@ -217034,11 +217438,10 @@
217438 int *pRc,
217439 Fts5Buffer *pBuf,
217440 u32 nData,
217441 const u8 *pData
217442 ){
 
217443 if( nData ){
217444 if( fts5BufferGrow(pRc, pBuf, nData) ) return;
217445 memcpy(&pBuf->p[pBuf->n], pData, nData);
217446 pBuf->n += nData;
217447 }
@@ -217146,11 +217549,10 @@
217549 return 1;
217550 }else{
217551 i64 iOff = *piOff;
217552 u32 iVal;
217553 fts5FastGetVarint32(a, i, iVal);
 
217554 if( iVal<=1 ){
217555 if( iVal==0 ){
217556 *pi = i;
217557 return 0;
217558 }
@@ -221761,11 +222163,11 @@
222163 if( iCol>=0 ){
222164 if( pHash->eDetail==FTS5_DETAIL_NONE ){
222165 p->bContent = 1;
222166 }else{
222167 /* Append a new column value, if necessary */
222168 assert_nc( iCol>=p->iCol );
222169 if( iCol!=p->iCol ){
222170 if( pHash->eDetail==FTS5_DETAIL_FULL ){
222171 pPtr[p->nData++] = 0x01;
222172 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
222173 p->iCol = (i16)iCol;
@@ -222566,12 +222968,15 @@
222968 ** +ve if pRight is smaller than pLeft. In other words:
222969 **
222970 ** res = *pLeft - *pRight
222971 */
222972 static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
222973 int nCmp, res;
222974 nCmp = MIN(pLeft->n, pRight->n);
222975 assert( nCmp<=0 || pLeft->p!=0 );
222976 assert( nCmp<=0 || pRight->p!=0 );
222977 res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
222978 return (res==0 ? (pLeft->n - pRight->n) : res);
222979 }
222980
222981 static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
222982 int ret;
@@ -224244,25 +224649,24 @@
224649 Fts5Index *p, /* Leave any error code here */
224650 int bGe, /* True for a >= search */
224651 Fts5SegIter *pIter, /* Iterator to seek */
224652 const u8 *pTerm, int nTerm /* Term to search for */
224653 ){
224654 u32 iOff;
224655 const u8 *a = pIter->pLeaf->p;
224656 u32 n = (u32)pIter->pLeaf->nn;
 
224657
224658 u32 nMatch = 0;
224659 u32 nKeep = 0;
224660 u32 nNew = 0;
224661 u32 iTermOff;
224662 u32 iPgidx; /* Current offset in pgidx */
224663 int bEndOfPage = 0;
224664
224665 assert( p->rc==SQLITE_OK );
224666
224667 iPgidx = (u32)pIter->pLeaf->szLeaf;
224668 iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
224669 iOff = iTermOff;
224670 if( iOff>n ){
224671 p->rc = FTS5_CORRUPT;
224672 return;
@@ -224324,19 +224728,19 @@
224728 do {
224729 fts5SegIterNextPage(p, pIter);
224730 if( pIter->pLeaf==0 ) return;
224731 a = pIter->pLeaf->p;
224732 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
224733 iPgidx = (u32)pIter->pLeaf->szLeaf;
224734 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
224735 if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
224736 p->rc = FTS5_CORRUPT;
224737 return;
224738 }else{
224739 nKeep = 0;
224740 iTermOff = iOff;
224741 n = (u32)pIter->pLeaf->nn;
224742 iOff += fts5GetVarint32(&a[iOff], nNew);
224743 break;
224744 }
224745 }
224746 }while( 1 );
@@ -231573,11 +231977,11 @@
231977 int nArg, /* Number of args */
231978 sqlite3_value **apUnused /* Function arguments */
231979 ){
231980 assert( nArg==0 );
231981 UNUSED_PARAM2(nArg, apUnused);
231982 sqlite3_result_text(pCtx, "fts5: 2021-10-04 12:16:27 71b102942cf46e307b123afbc51be06ebf48af9c364c0e7e0b9763f6963d3fb9", -1, SQLITE_TRANSIENT);
231983 }
231984
231985 /*
231986 ** Return true if zName is the extension on one of the shadow tables used
231987 ** by this module.
231988
+23 -9
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.37.0"
150150
#define SQLITE_VERSION_NUMBER 3037000
151
-#define SQLITE_SOURCE_ID "2021-10-06 10:36:56 566e6974892ebd3d3de8d77b24655257a5efe14434c553e1a25fc680b201b336"
151
+#define SQLITE_SOURCE_ID "2021-10-21 20:08:00 559ba38b8a0f7795d781838ec78969874fd678f749b26cd49cf6112afc838732"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -537,11 +537,10 @@
537537
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
538538
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
539539
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
540540
#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
541541
#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
542
-#define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8))
543542
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
544543
#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
545544
#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
546545
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
547546
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
@@ -573,10 +572,23 @@
573572
** CAPI3REF: Flags For File Open Operations
574573
**
575574
** These bit values are intended for use in the
576575
** 3rd parameter to the [sqlite3_open_v2()] interface and
577576
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
577
+**
578
+** Only those flags marked as "Ok for sqlite3_open_v2()" may be
579
+** used as the third argument to the [sqlite3_open_v2()] interface.
580
+** The other flags have historically been ignored by sqlite3_open_v2(),
581
+** though future versions of SQLite might change so that an error is
582
+** raised if any of the disallowed bits are passed into sqlite3_open_v2().
583
+** Applications should not depend on the historical behavior.
584
+**
585
+** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
586
+** [sqlite3_open_v2()] does *not* cause the underlying database file
587
+** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
588
+** [sqlite3_open_v2()] has historically be a no-op and might become an
589
+** error in future versions of SQLite.
578590
*/
579591
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
580592
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
581593
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
582594
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
@@ -3417,22 +3429,24 @@
34173429
** the default shared cache setting provided by
34183430
** [sqlite3_enable_shared_cache()].)^
34193431
**
34203432
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
34213433
** <dd>The database filename is not allowed to be a symbolic link</dd>
3422
-**
3423
-** [[OPEN_EXCLUSIVE]] ^(<dt>[SQLITE_OPEN_EXCLUSIVE]</dt>
3424
-** <dd>This flag causes the open to fail if the database file already
3425
-** exists. The open will only be success if this flag is used in combination
3426
-** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if
3427
-** the file does not previously exist.</dd>
34283434
** </dl>)^
34293435
**
34303436
** If the 3rd parameter to sqlite3_open_v2() is not one of the
34313437
** required combinations shown above optionally combined with other
34323438
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3433
-** then the behavior is undefined.
3439
+** then the behavior is undefined. Historic versions of SQLite
3440
+** have silently ignored surplus bits in the flags parameter to
3441
+** sqlite3_open_v2(), however that behavior might not be carried through
3442
+** into future versions of SQLite and so applications should not rely
3443
+** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3444
+** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
3445
+** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
3446
+** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3447
+** by sqlite3_open_v2().
34343448
**
34353449
** ^The fourth parameter to sqlite3_open_v2() is the name of the
34363450
** [sqlite3_vfs] object that defines the operating system interface that
34373451
** the new database connection should use. ^If the fourth parameter is
34383452
** a NULL pointer then the default [sqlite3_vfs] object is used.
34393453
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-10-06 10:36:56 566e6974892ebd3d3de8d77b24655257a5efe14434c553e1a25fc680b201b336"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -537,11 +537,10 @@
537 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
538 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
539 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
540 #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
541 #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
542 #define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8))
543 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
544 #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
545 #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
546 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
547 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
@@ -573,10 +572,23 @@
573 ** CAPI3REF: Flags For File Open Operations
574 **
575 ** These bit values are intended for use in the
576 ** 3rd parameter to the [sqlite3_open_v2()] interface and
577 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
 
 
 
 
 
 
 
 
 
 
 
 
 
578 */
579 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
580 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
581 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
582 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
@@ -3417,22 +3429,24 @@
3417 ** the default shared cache setting provided by
3418 ** [sqlite3_enable_shared_cache()].)^
3419 **
3420 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3421 ** <dd>The database filename is not allowed to be a symbolic link</dd>
3422 **
3423 ** [[OPEN_EXCLUSIVE]] ^(<dt>[SQLITE_OPEN_EXCLUSIVE]</dt>
3424 ** <dd>This flag causes the open to fail if the database file already
3425 ** exists. The open will only be success if this flag is used in combination
3426 ** with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags and if
3427 ** the file does not previously exist.</dd>
3428 ** </dl>)^
3429 **
3430 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3431 ** required combinations shown above optionally combined with other
3432 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3433 ** then the behavior is undefined.
 
 
 
 
 
 
 
 
3434 **
3435 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3436 ** [sqlite3_vfs] object that defines the operating system interface that
3437 ** the new database connection should use. ^If the fourth parameter is
3438 ** a NULL pointer then the default [sqlite3_vfs] object is used.
3439
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.37.0"
150 #define SQLITE_VERSION_NUMBER 3037000
151 #define SQLITE_SOURCE_ID "2021-10-21 20:08:00 559ba38b8a0f7795d781838ec78969874fd678f749b26cd49cf6112afc838732"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -537,11 +537,10 @@
537 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
538 #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
539 #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
540 #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
541 #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
 
542 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
543 #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
544 #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
545 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
546 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
@@ -573,10 +572,23 @@
572 ** CAPI3REF: Flags For File Open Operations
573 **
574 ** These bit values are intended for use in the
575 ** 3rd parameter to the [sqlite3_open_v2()] interface and
576 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
577 **
578 ** Only those flags marked as "Ok for sqlite3_open_v2()" may be
579 ** used as the third argument to the [sqlite3_open_v2()] interface.
580 ** The other flags have historically been ignored by sqlite3_open_v2(),
581 ** though future versions of SQLite might change so that an error is
582 ** raised if any of the disallowed bits are passed into sqlite3_open_v2().
583 ** Applications should not depend on the historical behavior.
584 **
585 ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
586 ** [sqlite3_open_v2()] does *not* cause the underlying database file
587 ** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
588 ** [sqlite3_open_v2()] has historically be a no-op and might become an
589 ** error in future versions of SQLite.
590 */
591 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
592 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
593 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
594 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
@@ -3417,22 +3429,24 @@
3429 ** the default shared cache setting provided by
3430 ** [sqlite3_enable_shared_cache()].)^
3431 **
3432 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3433 ** <dd>The database filename is not allowed to be a symbolic link</dd>
 
 
 
 
 
 
3434 ** </dl>)^
3435 **
3436 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3437 ** required combinations shown above optionally combined with other
3438 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3439 ** then the behavior is undefined. Historic versions of SQLite
3440 ** have silently ignored surplus bits in the flags parameter to
3441 ** sqlite3_open_v2(), however that behavior might not be carried through
3442 ** into future versions of SQLite and so applications should not rely
3443 ** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3444 ** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
3445 ** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
3446 ** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3447 ** by sqlite3_open_v2().
3448 **
3449 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3450 ** [sqlite3_vfs] object that defines the operating system interface that
3451 ** the new database connection should use. ^If the fourth parameter is
3452 ** a NULL pointer then the default [sqlite3_vfs] object is used.
3453

Keyboard Shortcuts

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