Fossil SCM

Update the built-in SQLite to the latest 3.37.0 alpha for testing.

drh 2021-10-26 17:21 trunk
Commit ed3dc66de0063e4b350323f58c96c97f3219909b69c9c47a26ff29764f1934a9
3 files changed -2 +797 -383 +23 -9
--- 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
+797 -383
--- 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-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
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.
@@ -13160,15 +13174,16 @@
1316013174
** can be used to make sure boundary values are tested. For
1316113175
** bitmask tests, testcase() can be used to make sure each bit
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.
13165
-**
1316613179
*/
13167
-#ifdef SQLITE_COVERAGE_TEST
13168
-SQLITE_PRIVATE void sqlite3Coverage(int);
13169
-# define testcase(X) if( X ){ sqlite3Coverage(__LINE__); }
13180
+#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
13181
+# ifndef SQLITE_AMALGAMATION
13182
+ extern unsigned int sqlite3CoverageCounter;
13183
+# endif
13184
+# define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; }
1317013185
#else
1317113186
# define testcase(X)
1317213187
#endif
1317313188
1317413189
/*
@@ -13228,30 +13243,10 @@
1322813243
#else
1322913244
# define ALWAYS(X) (X)
1323013245
# define NEVER(X) (X)
1323113246
#endif
1323213247
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
-
1325313248
/*
1325413249
** Some conditionals are optimizations only. In other words, if the
1325513250
** conditionals are replaced with a constant 1 (true) or 0 (false) then
1325613251
** the correct answer is still obtained, though perhaps not as quickly.
1325713252
**
@@ -13430,11 +13425,11 @@
1343013425
/* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */
1343113426
1343213427
/*
1343313428
** Number of entries in a hash table
1343413429
*/
13435
-/* #define sqliteHashCount(H) ((H)->count) // NOT USED */
13430
+#define sqliteHashCount(H) ((H)->count)
1343613431
1343713432
#endif /* SQLITE_HASH_H */
1343813433
1343913434
/************** End of hash.h ************************************************/
1344013435
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -16428,14 +16423,14 @@
1642816423
int nVdbeExec; /* Number of nested calls to VdbeExec() */
1642916424
int nVDestroy; /* Number of active OP_VDestroy operations */
1643016425
int nExtension; /* Number of loaded extensions */
1643116426
void **aExtension; /* Array of shared library handles */
1643216427
union {
16433
- void (*xLegacy)(void*,const char*); /* Legacy trace function */
16434
- int (*xV2)(u32,void*,void*,void*); /* V2 Trace function */
16428
+ void (*xLegacy)(void*,const char*); /* mTrace==SQLITE_TRACE_LEGACY */
16429
+ int (*xV2)(u32,void*,void*,void*); /* All other mTrace values */
1643516430
} trace;
16436
- void *pTraceArg; /* Argument to the trace function */
16431
+ void *pTraceArg; /* Argument to the trace function */
1643716432
#ifndef SQLITE_OMIT_DEPRECATED
1643816433
void (*xProfile)(void*,const char*,u64); /* Profiling function */
1643916434
void *pProfileArg; /* Argument to profile function */
1644016435
#endif
1644116436
void *pCommitArg; /* Argument to xCommitCallback() */
@@ -16667,11 +16662,11 @@
1666716662
void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */
1666816663
const char *zName; /* SQL name of the function. */
1666916664
union {
1667016665
FuncDef *pHash; /* Next with a different name but the same hash */
1667116666
FuncDestructor *pDestructor; /* Reference counted destructor function */
16672
- } u;
16667
+ } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */
1667316668
};
1667416669
1667516670
/*
1667616671
** This structure encapsulates a user-function destructor callback (as
1667716672
** configured using create_function_v2()) and a reference counter. When
@@ -16728,10 +16723,11 @@
1672816723
#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
1672916724
#define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
1673016725
#define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
1673116726
#define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
1673216727
#define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
16728
+#define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */
1673316729
#define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */
1673416730
1673516731
/* Identifier numbers for each in-line function */
1673616732
#define INLINEFUNC_coalesce 0
1673716733
#define INLINEFUNC_implies_nonnull_row 1
@@ -16806,48 +16802,55 @@
1680616802
** available as the function user-data (sqlite3_user_data()). The
1680716803
** FuncDef.flags variable is set to the value passed as the flags
1680816804
** parameter.
1680916805
*/
1681016806
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
16811
- {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16807
+ {nArg, SQLITE_FUNC_BUILTIN|\
16808
+ SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1681216809
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1681316810
#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16814
- {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16811
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1681516812
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1681616813
#define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16817
- {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
16814
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
1681816815
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1681916816
#define MFUNCTION(zName, nArg, xPtr, xFunc) \
16820
- {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
16817
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
1682116818
xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
1682216819
#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
16823
- {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16820
+ {nArg, SQLITE_FUNC_BUILTIN|\
16821
+ SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
1682416822
SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
1682516823
#define TEST_FUNC(zName, nArg, iArg, mFlags) \
16826
- {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
16824
+ {nArg, SQLITE_FUNC_BUILTIN|\
16825
+ SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
1682716826
SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
1682816827
SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
1682916828
#define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16830
- {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
16829
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
1683116830
0, 0, xFunc, 0, 0, 0, #zName, {0} }
1683216831
#define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
16833
- {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
16832
+ {nArg, SQLITE_FUNC_BUILTIN|\
16833
+ SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
1683416834
(void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} }
1683516835
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
16836
- {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
16836
+ {nArg, SQLITE_FUNC_BUILTIN|\
16837
+ SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
1683716838
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
1683816839
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
16839
- {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16840
+ {nArg, SQLITE_FUNC_BUILTIN|\
16841
+ SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1684016842
pArg, 0, xFunc, 0, 0, 0, #zName, }
1684116843
#define LIKEFUNC(zName, nArg, arg, flags) \
16842
- {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
16844
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
1684316845
(void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
1684416846
#define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
16845
- {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
16847
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
1684616848
SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
1684716849
#define INTERNAL_FUNCTION(zName, nArg, xFunc) \
16848
- {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
16850
+ {nArg, SQLITE_FUNC_BUILTIN|\
16851
+ SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
1684916852
0, 0, xFunc, 0, 0, 0, #zName, {0} }
1685016853
1685116854
1685216855
/*
1685316856
** All current savepoints are stored in a linked list starting at
@@ -17566,14 +17569,14 @@
1756617569
** code representing the ">=" operator. This same integer code is reused
1756717570
** to represent the greater-than-or-equal-to operator in the expression
1756817571
** tree.
1756917572
**
1757017573
** 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
17574
+** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If
17575
+** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the
1757317576
** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
17574
-** then Expr.token contains the name of the function.
17577
+** then Expr.u.zToken contains the name of the function.
1757517578
**
1757617579
** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
1757717580
** binary operator. Either or both may be NULL.
1757817581
**
1757917582
** Expr.x.pList is a list of arguments if the expression is an SQL function,
@@ -17609,11 +17612,11 @@
1760917612
**
1761017613
** Expr objects can use a lot of memory space in database schema. To
1761117614
** help reduce memory requirements, sometimes an Expr object will be
1761217615
** truncated. And to reduce the number of memory allocations, sometimes
1761317616
** two or more Expr objects will be stored in a single memory allocation,
17614
-** together with Expr.zToken strings.
17617
+** together with Expr.u.zToken strings.
1761517618
**
1761617619
** If the EP_Reduced and EP_TokenOnly flags are set when
1761717620
** an Expr object is truncated. When EP_Reduced is set, then all
1761817621
** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
1761917622
** are contained within the same memory allocation. Note, however, that
@@ -17678,12 +17681,11 @@
1767817681
int regReturn; /* Register used to hold return address */
1767917682
} sub;
1768017683
} y;
1768117684
};
1768217685
17683
-/*
17684
-** The following are the meanings of bits in the Expr.flags field.
17686
+/* The following are the meanings of bits in the Expr.flags field.
1768517687
** Value restrictions:
1768617688
**
1768717689
** EP_Agg == NC_HasAgg == SF_HasAgg
1768817690
** EP_Win == NC_HasWin
1768917691
*/
@@ -17718,27 +17720,35 @@
1771817720
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
1771917721
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
1772017722
#define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
1772117723
/* 0x80000000 // Available */
1772217724
17723
-/*
17724
-** The EP_Propagate mask is a set of properties that automatically propagate
17725
+/* The EP_Propagate mask is a set of properties that automatically propagate
1772517726
** upwards into parent nodes.
1772617727
*/
1772717728
#define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
1772817729
17729
-/*
17730
-** These macros can be used to test, set, or clear bits in the
17730
+/* Macros can be used to test, set, or clear bits in the
1773117731
** Expr.flags field.
1773217732
*/
1773317733
#define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
1773417734
#define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
1773517735
#define ExprSetProperty(E,P) (E)->flags|=(P)
1773617736
#define ExprClearProperty(E,P) (E)->flags&=~(P)
1773717737
#define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
1773817738
#define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
1773917739
17740
+/* Macros used to ensure that the correct members of unions are accessed
17741
+** in Expr.
17742
+*/
17743
+#define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
17744
+#define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0)
17745
+#define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0)
17746
+#define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0)
17747
+#define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0)
17748
+#define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0)
17749
+#define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0)
1774017750
1774117751
/* Flags for use with Expr.vvaFlags
1774217752
*/
1774317753
#define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */
1774417754
#define EP_Immutable 0x02 /* Do not change this Expr node */
@@ -17817,15 +17827,16 @@
1781717827
unsigned done :1; /* A flag to indicate when processing is finished */
1781817828
unsigned reusable :1; /* Constant expression is reusable */
1781917829
unsigned bSorterRef :1; /* Defer evaluation until after sorting */
1782017830
unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
1782117831
union {
17822
- struct {
17832
+ struct { /* Used by any ExprList other than Parse.pConsExpr */
1782317833
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1782417834
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1782517835
} x;
17826
- int iConstExprReg; /* Register in which Expr value is cached */
17836
+ int iConstExprReg; /* Register in which Expr value is cached. Used only
17837
+ ** by Parse.pConstExpr */
1782717838
} u;
1782817839
} a[1]; /* One slot for each expression in the list */
1782917840
};
1783017841
1783117842
/*
@@ -17859,10 +17870,17 @@
1785917870
};
1786017871
1786117872
/*
1786217873
** The SrcItem object represents a single term in the FROM clause of a query.
1786317874
** The SrcList object is mostly an array of SrcItems.
17875
+**
17876
+** Union member validity:
17877
+**
17878
+** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc
17879
+** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy
17880
+** u2.pIBIndex fg.isIndexedBy && !fg.isCte
17881
+** u2.pCteUse fg.isCte && !fg.isIndexedBy
1786417882
*/
1786517883
struct SrcItem {
1786617884
Schema *pSchema; /* Schema to which this item is fixed */
1786717885
char *zDatabase; /* Name of database holding this table */
1786817886
char *zName; /* Name of the table */
@@ -18453,10 +18471,12 @@
1845318471
#ifndef SQLITE_OMIT_ALTERTABLE
1845418472
RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
1845518473
#endif
1845618474
};
1845718475
18476
+/* Allowed values for Parse.eParseMode
18477
+*/
1845818478
#define PARSE_MODE_NORMAL 0
1845918479
#define PARSE_MODE_DECLARE_VTAB 1
1846018480
#define PARSE_MODE_RENAME 2
1846118481
#define PARSE_MODE_UNMAP 3
1846218482
@@ -20109,12 +20129,12 @@
2010920129
** All of this is no-op for a production build. It only comes into
2011020130
** play when the SQLITE_MEMDEBUG compile-time option is used.
2011120131
*/
2011220132
#ifdef SQLITE_MEMDEBUG
2011320133
SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
20114
-SQLITE_PRIVATE int sqlite3MemdebugHasType(void*,u8);
20115
-SQLITE_PRIVATE int sqlite3MemdebugNoType(void*,u8);
20134
+SQLITE_PRIVATE int sqlite3MemdebugHasType(const void*,u8);
20135
+SQLITE_PRIVATE int sqlite3MemdebugNoType(const void*,u8);
2011620136
#else
2011720137
# define sqlite3MemdebugSetType(X,Y) /* no-op */
2011820138
# define sqlite3MemdebugHasType(X,Y) 1
2011920139
# define sqlite3MemdebugNoType(X,Y) 1
2012020140
#endif
@@ -21432,10 +21452,22 @@
2143221452
** Hash table for global functions - functions common to all
2143321453
** database connections. After initialization, this table is
2143421454
** read-only.
2143521455
*/
2143621456
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
21457
+
21458
+#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
21459
+/*
21460
+** Counter used for coverage testing. Does not come into play for
21461
+** release builds.
21462
+**
21463
+** Access to this global variable is not mutex protected. This might
21464
+** result in TSAN warnings. But as the variable does not exist in
21465
+** release builds, that should not be a concern.
21466
+*/
21467
+SQLITE_PRIVATE unsigned int sqlite3CoverageCounter;
21468
+#endif /* SQLITE_COVERAGE_TEST || SQLITE_DEBUG */
2143721469
2143821470
#ifdef VDBE_PROFILE
2143921471
/*
2144021472
** The following performance counter can be used in place of
2144121473
** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
@@ -24817,11 +24849,11 @@
2481724849
** Given an allocation, find the MemBlockHdr for that allocation.
2481824850
**
2481924851
** This routine checks the guards at either end of the allocation and
2482024852
** if they are incorrect it asserts.
2482124853
*/
24822
-static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){
24854
+static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){
2482324855
struct MemBlockHdr *p;
2482424856
int *pInt;
2482524857
u8 *pU8;
2482624858
int nReserve;
2482724859
@@ -25064,11 +25096,11 @@
2506425096
** This routine is designed for use within an assert() statement, to
2506525097
** verify the type of an allocation. For example:
2506625098
**
2506725099
** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2506825100
*/
25069
-SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){
25101
+SQLITE_PRIVATE int sqlite3MemdebugHasType(const void *p, u8 eType){
2507025102
int rc = 1;
2507125103
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
2507225104
struct MemBlockHdr *pHdr;
2507325105
pHdr = sqlite3MemsysGetHeader(p);
2507425106
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -25086,11 +25118,11 @@
2508625118
** This routine is designed for use within an assert() statement, to
2508725119
** verify the type of an allocation. For example:
2508825120
**
2508925121
** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2509025122
*/
25091
-SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){
25123
+SQLITE_PRIVATE int sqlite3MemdebugNoType(const void *p, u8 eType){
2509225124
int rc = 1;
2509325125
if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
2509425126
struct MemBlockHdr *pHdr;
2509525127
pHdr = sqlite3MemsysGetHeader(p);
2509625128
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -30551,10 +30583,11 @@
3055130583
zOp2[0] = 0;
3055230584
}
3055330585
sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
3055430586
pExpr->iColumn, zFlgs, zOp2);
3055530587
}else{
30588
+ assert( ExprUseYTab(pExpr) );
3055630589
sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
3055730590
pExpr->iTable, pExpr->iColumn,
3055830591
pExpr->y.pTab, zFlgs);
3055930592
}
3056030593
if( ExprHasProperty(pExpr, EP_FixedCol) ){
@@ -30570,15 +30603,17 @@
3057030603
}
3057130604
break;
3057230605
}
3057330606
#ifndef SQLITE_OMIT_FLOATING_POINT
3057430607
case TK_FLOAT: {
30608
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3057530609
sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
3057630610
break;
3057730611
}
3057830612
#endif
3057930613
case TK_STRING: {
30614
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3058030615
sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
3058130616
break;
3058230617
}
3058330618
case TK_NULL: {
3058430619
sqlite3TreeViewLine(pView,"NULL");
@@ -30589,30 +30624,34 @@
3058930624
sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
3059030625
break;
3059130626
}
3059230627
#ifndef SQLITE_OMIT_BLOB_LITERAL
3059330628
case TK_BLOB: {
30629
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3059430630
sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
3059530631
break;
3059630632
}
3059730633
#endif
3059830634
case TK_VARIABLE: {
30635
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3059930636
sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
3060030637
pExpr->u.zToken, pExpr->iColumn);
3060130638
break;
3060230639
}
3060330640
case TK_REGISTER: {
3060430641
sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
3060530642
break;
3060630643
}
3060730644
case TK_ID: {
30645
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3060830646
sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
3060930647
break;
3061030648
}
3061130649
#ifndef SQLITE_OMIT_CAST
3061230650
case TK_CAST: {
3061330651
/* Expressions of the form: CAST(pLeft AS token) */
30652
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3061430653
sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
3061530654
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
3061630655
break;
3061730656
}
3061830657
#endif /* SQLITE_OMIT_CAST */
@@ -30658,10 +30697,11 @@
3065830697
zUniOp = azOp[x];
3065930698
break;
3066030699
}
3066130700
3066230701
case TK_SPAN: {
30702
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3066330703
sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
3066430704
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
3066530705
break;
3066630706
}
3066730707
@@ -30669,10 +30709,11 @@
3066930709
/* COLLATE operators without the EP_Collate flag are intended to
3067030710
** emulate collation associated with a table column. These show
3067130711
** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE
3067230712
** operators that appear in the original SQL always have the
3067330713
** EP_Collate bit set and appear in treeview output as just "COLLATE" */
30714
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3067430715
sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s",
3067530716
!ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "",
3067630717
pExpr->u.zToken, zFlgs);
3067730718
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
3067830719
break;
@@ -30684,17 +30725,19 @@
3068430725
Window *pWin;
3068530726
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
3068630727
pFarg = 0;
3068730728
pWin = 0;
3068830729
}else{
30730
+ assert( ExprUseXList(pExpr) );
3068930731
pFarg = pExpr->x.pList;
3069030732
#ifndef SQLITE_OMIT_WINDOWFUNC
3069130733
pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
3069230734
#else
3069330735
pWin = 0;
3069430736
#endif
3069530737
}
30738
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3069630739
if( pExpr->op==TK_AGG_FUNCTION ){
3069730740
sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
3069830741
pExpr->op2, pExpr->u.zToken, zFlgs,
3069930742
pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
3070030743
pExpr->iAgg, pExpr->pAggInfo);
@@ -30722,23 +30765,25 @@
3072230765
#endif
3072330766
break;
3072430767
}
3072530768
#ifndef SQLITE_OMIT_SUBQUERY
3072630769
case TK_EXISTS: {
30770
+ assert( ExprUseXSelect(pExpr) );
3072730771
sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
3072830772
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3072930773
break;
3073030774
}
3073130775
case TK_SELECT: {
30776
+ assert( ExprUseXSelect(pExpr) );
3073230777
sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
3073330778
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3073430779
break;
3073530780
}
3073630781
case TK_IN: {
3073730782
sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
3073830783
sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30739
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
30784
+ if( ExprUseXSelect(pExpr) ){
3074030785
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3074130786
}else{
3074230787
sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
3074330788
}
3074430789
break;
@@ -30755,13 +30800,16 @@
3075530800
** X is stored in pExpr->pLeft.
3075630801
** Y is stored in pExpr->pList->a[0].pExpr.
3075730802
** Z is stored in pExpr->pList->a[1].pExpr.
3075830803
*/
3075930804
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;
30805
+ const Expr *pX, *pY, *pZ;
30806
+ pX = pExpr->pLeft;
30807
+ assert( ExprUseXList(pExpr) );
30808
+ assert( pExpr->x.pList->nExpr==2 );
30809
+ pY = pExpr->x.pList->a[0].pExpr;
30810
+ pZ = pExpr->x.pList->a[1].pExpr;
3076330811
sqlite3TreeViewLine(pView, "BETWEEN");
3076430812
sqlite3TreeViewExpr(pView, pX, 1);
3076530813
sqlite3TreeViewExpr(pView, pY, 1);
3076630814
sqlite3TreeViewExpr(pView, pZ, 0);
3076730815
break;
@@ -30779,10 +30827,11 @@
3077930827
break;
3078030828
}
3078130829
case TK_CASE: {
3078230830
sqlite3TreeViewLine(pView, "CASE");
3078330831
sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30832
+ assert( ExprUseXList(pExpr) );
3078430833
sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
3078530834
break;
3078630835
}
3078730836
#ifndef SQLITE_OMIT_TRIGGER
3078830837
case TK_RAISE: {
@@ -30791,10 +30840,11 @@
3079130840
case OE_Rollback: zType = "rollback"; break;
3079230841
case OE_Abort: zType = "abort"; break;
3079330842
case OE_Fail: zType = "fail"; break;
3079430843
case OE_Ignore: zType = "ignore"; break;
3079530844
}
30845
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
3079630846
sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
3079730847
break;
3079830848
}
3079930849
#endif
3080030850
case TK_MATCH: {
@@ -30803,18 +30853,20 @@
3080330853
sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
3080430854
break;
3080530855
}
3080630856
case TK_VECTOR: {
3080730857
char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
30858
+ assert( ExprUseXList(pExpr) );
3080830859
sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
3080930860
sqlite3_free(z);
3081030861
break;
3081130862
}
3081230863
case TK_SELECT_COLUMN: {
3081330864
sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s",
3081430865
pExpr->iColumn, pExpr->iTable-1,
3081530866
pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : "");
30867
+ assert( ExprUseXSelect(pExpr->pLeft) );
3081630868
sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
3081730869
break;
3081830870
}
3081930871
case TK_IF_NULL_ROW: {
3082030872
sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
@@ -31887,20 +31939,10 @@
3188731939
/* #include <stdarg.h> */
3188831940
#ifndef SQLITE_OMIT_FLOATING_POINT
3188931941
#include <math.h>
3189031942
#endif
3189131943
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
-
3190231944
/*
3190331945
** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
3190431946
** or to bypass normal error detection during testing in order to let
3190531947
** execute proceed futher downstream.
3190631948
**
@@ -32143,10 +32185,11 @@
3214332185
}
3214432186
}
3214532187
z[j] = 0;
3214632188
}
3214732189
SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
32190
+ assert( !ExprHasProperty(p, EP_IntValue) );
3214832191
assert( sqlite3Isquote(p->u.zToken[0]) );
3214932192
p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
3215032193
sqlite3Dequote(p->u.zToken);
3215132194
}
3215232195
@@ -40209,10 +40252,15 @@
4020940252
if( randomnessPid!=osGetpid(0) ){
4021040253
randomnessPid = osGetpid(0);
4021140254
sqlite3_randomness(0,0);
4021240255
}
4021340256
memset(p, 0, sizeof(unixFile));
40257
+
40258
+#ifdef SQLITE_ASSERT_NO_FILES
40259
+ /* Applications that never read or write a persistent disk files */
40260
+ assert( zName==0 );
40261
+#endif
4021440262
4021540263
if( eType==SQLITE_OPEN_MAIN_DB ){
4021640264
UnixUnusedFd *pUnused;
4021740265
pUnused = findReusableFd(zName, flags);
4021840266
if( pUnused ){
@@ -40270,12 +40318,10 @@
4027040318
if( fd<0 ){
4027140319
if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
4027240320
/* If unable to create a journal because the directory is not
4027340321
** writable, change the error code to indicate that. */
4027440322
rc = SQLITE_READONLY_DIRECTORY;
40275
- }else if( errno==EEXIST ){
40276
- rc = SQLITE_CANTOPEN_EXISTS;
4027740323
}else if( errno!=EISDIR && isReadWrite ){
4027840324
/* Failed to open the file for read/write access. Try read-only. */
4027940325
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
4028040326
openFlags &= ~(O_RDWR|O_CREAT);
4028140327
flags |= SQLITE_OPEN_READONLY;
@@ -48623,11 +48669,11 @@
4862348669
/*
4862448670
** Try to enlarge the memory allocation to hold at least sz bytes
4862548671
*/
4862648672
static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
4862748673
unsigned char *pNew;
48628
- if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
48674
+ if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){
4862948675
return SQLITE_FULL;
4863048676
}
4863148677
if( newSz>p->szMax ){
4863248678
return SQLITE_FULL;
4863348679
}
@@ -48822,11 +48868,11 @@
4882248868
int iAmt,
4882348869
void **pp
4882448870
){
4882548871
MemStore *p = ((MemFile*)pFile)->pStore;
4882648872
memdbEnter(p);
48827
- if( iOfst+iAmt>p->sz ){
48873
+ if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){
4882848874
*pp = 0;
4882948875
}else{
4883048876
p->nMmap++;
4883148877
*pp = (void*)(p->aData + iOfst);
4883248878
}
@@ -48856,13 +48902,11 @@
4885648902
int *pOutFlags
4885748903
){
4885848904
MemFile *pFile = (MemFile*)pFd;
4885948905
MemStore *p = 0;
4886048906
int szName;
48861
- if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48862
- return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
48863
- }
48907
+
4886448908
memset(pFile, 0, sizeof(*pFile));
4886548909
szName = sqlite3Strlen30(zName);
4886648910
if( szName>1 && zName[0]=='/' ){
4886748911
int i;
4886848912
#ifndef SQLITE_MUTEX_OMIT
@@ -48918,12 +48962,13 @@
4891848962
memset(p, 0, sizeof(*p));
4891948963
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
4892048964
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
4892148965
}
4892248966
pFile->pStore = p;
48923
- assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
48924
- *pOutFlags = flags | SQLITE_OPEN_MEMORY;
48967
+ if( pOutFlags!=0 ){
48968
+ *pOutFlags = flags | SQLITE_OPEN_MEMORY;
48969
+ }
4892548970
pFd->pMethods = &memdb_io_methods;
4892648971
memdbLeave(p);
4892748972
return SQLITE_OK;
4892848973
}
4892948974
@@ -53114,10 +53159,11 @@
5311453159
u8 walSyncFlags; /* See description above */
5311553160
u8 tempFile; /* zFilename is a temporary or immutable file */
5311653161
u8 noLock; /* Do not lock (except in WAL mode) */
5311753162
u8 readOnly; /* True for a read-only database */
5311853163
u8 memDb; /* True to inhibit all file I/O */
53164
+ u8 memVfs; /* VFS-implemented memory database */
5311953165
5312053166
/**************************************************************************
5312153167
** The following block contains those class members that change during
5312253168
** routine operation. Class members not in this block are either fixed
5312353169
** when the pager is first created or else only change when there is a
@@ -57356,11 +57402,11 @@
5735657402
if( zFilename && zFilename[0] ){
5735757403
int fout = 0; /* VFS flags returned by xOpen() */
5735857404
rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
5735957405
assert( !memDb );
5736057406
#ifndef SQLITE_OMIT_DESERIALIZE
57361
- memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
57407
+ pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
5736257408
#endif
5736357409
readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
5736457410
5736557411
/* If the file was successfully opened for read/write access,
5736657412
** choose a default page size in case we have to create the
@@ -59293,11 +59339,11 @@
5929359339
5929459340
/*
5929559341
** Return true if this is an in-memory or temp-file backed pager.
5929659342
*/
5929759343
SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
59298
- return pPager->tempFile;
59344
+ return pPager->tempFile || pPager->memVfs;
5929959345
}
5930059346
5930159347
/*
5930259348
** Check that there are at least nSavepoint savepoints open. If there are
5930359349
** currently less than nSavepoints open, then open one or more savepoints
@@ -59613,11 +59659,11 @@
5961359659
*/
5961459660
pPg->flags &= ~PGHDR_NEED_SYNC;
5961559661
pPgOld = sqlite3PagerLookup(pPager, pgno);
5961659662
assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
5961759663
if( pPgOld ){
59618
- if( pPgOld->nRef>1 ){
59664
+ if( NEVER(pPgOld->nRef>1) ){
5961959665
sqlite3PagerUnrefNotNull(pPgOld);
5962059666
return SQLITE_CORRUPT_BKPT;
5962159667
}
5962259668
pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
5962359669
if( pPager->tempFile ){
@@ -64637,11 +64683,10 @@
6463764683
** Access to all fields of this structure is controlled by the mutex
6463864684
** stored in MemPage.pBt->mutex.
6463964685
*/
6464064686
struct MemPage {
6464164687
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
64642
- u8 bBusy; /* Prevent endless loops on corrupt database files */
6464364688
u8 intKey; /* True if table b-trees. False for index b-trees */
6464464689
u8 intKeyLeaf; /* True if the leaf of an intKey table */
6464564690
Pgno pgno; /* Page number for this page */
6464664691
/* Only the first 8 bytes (above) are zeroed by pager.c when a new page
6464764692
** is allocated. All fields that follow must be initialized before use */
@@ -70227,11 +70272,13 @@
7022770272
#endif
7022870273
7022970274
assert( pPage );
7023070275
assert( eOp==0 || eOp==1 );
7023170276
assert( pCur->eState==CURSOR_VALID );
70232
- assert( pCur->ix<pPage->nCell );
70277
+ if( pCur->ix>=pPage->nCell ){
70278
+ return SQLITE_CORRUPT_PAGE(pPage);
70279
+ }
7023370280
assert( cursorHoldsMutex(pCur) );
7023470281
7023570282
getCellInfo(pCur);
7023670283
aPayload = pCur->info.pPayload;
7023770284
assert( offset+amt <= pCur->info.nPayload );
@@ -70414,11 +70461,10 @@
7041470461
*/
7041570462
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
7041670463
assert( cursorHoldsMutex(pCur) );
7041770464
assert( pCur->eState==CURSOR_VALID );
7041870465
assert( pCur->iPage>=0 && pCur->pPage );
70419
- assert( pCur->ix<pCur->pPage->nCell );
7042070466
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
7042170467
}
7042270468
7042370469
/*
7042470470
** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -70476,11 +70522,11 @@
7047670522
int amt;
7047770523
assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
7047870524
assert( pCur->eState==CURSOR_VALID );
7047970525
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
7048070526
assert( cursorOwnsBtShared(pCur) );
70481
- assert( pCur->ix<pCur->pPage->nCell );
70527
+ assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
7048270528
assert( pCur->info.nSize>0 );
7048370529
assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
7048470530
assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
7048570531
amt = pCur->info.nLocal;
7048670532
if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
@@ -71262,20 +71308,10 @@
7126271308
** module cov1/btree78.test testcase 220 (2018-06-08) for an
7126371309
** example. */
7126471310
return SQLITE_CORRUPT_BKPT;
7126571311
}
7126671312
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
-
7127771313
if( idx>=pPage->nCell ){
7127871314
if( !pPage->leaf ){
7127971315
rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
7128071316
if( rc ) return rc;
7128171317
return moveToLeftmost(pCur);
@@ -71759,11 +71795,11 @@
7175971795
7176071796
assert( sqlite3_mutex_held(pBt->mutex) );
7176171797
assert( CORRUPT_DB || iPage>1 );
7176271798
assert( !pMemPage || pMemPage->pgno==iPage );
7176371799
71764
- if( iPage<2 || iPage>pBt->nPage ){
71800
+ if( NEVER(iPage<2) || iPage>pBt->nPage ){
7176571801
return SQLITE_CORRUPT_BKPT;
7176671802
}
7176771803
if( pMemPage ){
7176871804
pPage = pMemPage;
7176971805
sqlite3PagerRef(pPage->pDbPage);
@@ -72484,11 +72520,11 @@
7248472520
int k; /* Current slot in pCArray->apEnd[] */
7248572521
u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
7248672522
7248772523
assert( i<iEnd );
7248872524
j = get2byte(&aData[hdr+5]);
72489
- if( NEVER(j>(u32)usableSize) ){ j = 0; }
72525
+ if( j>(u32)usableSize ){ j = 0; }
7249072526
memcpy(&pTmp[j], &aData[j], usableSize - j);
7249172527
7249272528
for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
7249372529
pSrcEnd = pCArray->apEnd[k];
7249472530
@@ -74360,11 +74396,14 @@
7436074396
assert( szNew==pPage->xCellSize(pPage, newCell) );
7436174397
assert( szNew <= MX_CELL_SIZE(pBt) );
7436274398
idx = pCur->ix;
7436374399
if( loc==0 ){
7436474400
CellInfo info;
74365
- assert( idx<pPage->nCell );
74401
+ assert( idx>=0 );
74402
+ if( idx>=pPage->nCell ){
74403
+ return SQLITE_CORRUPT_BKPT;
74404
+ }
7436674405
rc = sqlite3PagerWrite(pPage->pDbPage);
7436774406
if( rc ){
7436874407
goto end_insert;
7436974408
}
7437074409
oldCell = findCell(pPage, idx);
@@ -74946,15 +74985,16 @@
7494674985
if( pgno>btreePagecount(pBt) ){
7494774986
return SQLITE_CORRUPT_BKPT;
7494874987
}
7494974988
rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
7495074989
if( rc ) return rc;
74951
- if( pPage->bBusy ){
74990
+ if( (pBt->openFlags & BTREE_SINGLE)==0
74991
+ && sqlite3PagerPageRefcount(pPage->pDbPage)!=1
74992
+ ){
7495274993
rc = SQLITE_CORRUPT_BKPT;
7495374994
goto cleardatabasepage_out;
7495474995
}
74955
- pPage->bBusy = 1;
7495674996
hdr = pPage->hdrOffset;
7495774997
for(i=0; i<pPage->nCell; i++){
7495874998
pCell = findCell(pPage, i);
7495974999
if( !pPage->leaf ){
7496075000
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
@@ -74977,11 +75017,10 @@
7497775017
}else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
7497875018
zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
7497975019
}
7498075020
7498175021
cleardatabasepage_out:
74982
- pPage->bBusy = 0;
7498375022
releasePage(pPage);
7498475023
return rc;
7498575024
}
7498675025
7498775026
/*
@@ -75056,14 +75095,14 @@
7505675095
assert( iTable>=2 );
7505775096
if( iTable>btreePagecount(pBt) ){
7505875097
return SQLITE_CORRUPT_BKPT;
7505975098
}
7506075099
75061
- rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
75062
- if( rc ) return rc;
7506375100
rc = sqlite3BtreeClearTable(p, iTable, 0);
75064
- if( rc ){
75101
+ if( rc ) return rc;
75102
+ rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
75103
+ if( NEVER(rc) ){
7506575104
releasePage(pPage);
7506675105
return rc;
7506775106
}
7506875107
7506975108
*piMoved = 0;
@@ -78434,12 +78473,14 @@
7843478473
ExprList *pList = 0; /* Function arguments */
7843578474
int i; /* Iterator variable */
7843678475
7843778476
assert( pCtx!=0 );
7843878477
assert( (p->flags & EP_TokenOnly)==0 );
78478
+ assert( ExprUseXList(p) );
7843978479
pList = p->x.pList;
7844078480
if( pList ) nVal = pList->nExpr;
78481
+ assert( !ExprHasProperty(p, EP_IntValue) );
7844178482
pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
7844278483
assert( pFunc );
7844378484
if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
7844478485
|| (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
7844578486
){
@@ -78539,11 +78580,13 @@
7853978580
** check ensures that an EP_TokenOnly expression is never passed down
7854078581
** into valueFromFunction(). */
7854178582
assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
7854278583
7854378584
if( op==TK_CAST ){
78544
- u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
78585
+ u8 aff;
78586
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
78587
+ aff = sqlite3AffinityType(pExpr->u.zToken,0);
7854578588
rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
7854678589
testcase( rc!=SQLITE_OK );
7854778590
if( *ppVal ){
7854878591
sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
7854978592
sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
@@ -78612,10 +78655,11 @@
7861278655
sqlite3VdbeMemSetNull(pVal);
7861378656
}
7861478657
#ifndef SQLITE_OMIT_BLOB_LITERAL
7861578658
else if( op==TK_BLOB ){
7861678659
int nVal;
78660
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
7861778661
assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
7861878662
assert( pExpr->u.zToken[1]=='\'' );
7861978663
pVal = valueNew(db, pCtx);
7862078664
if( !pVal ) goto no_mem;
7862178665
zVal = &pExpr->u.zToken[2];
@@ -78629,10 +78673,11 @@
7862978673
else if( op==TK_FUNCTION && pCtx!=0 ){
7863078674
rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
7863178675
}
7863278676
#endif
7863378677
else if( op==TK_TRUEFALSE ){
78678
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
7863478679
pVal = valueNew(db, pCtx);
7863578680
if( pVal ){
7863678681
pVal->flags = MEM_Int;
7863778682
pVal->u.i = pExpr->u.zToken[4]==0;
7863878683
}
@@ -80501,10 +80546,11 @@
8050180546
*/
8050280547
static void displayP4Expr(StrAccum *p, Expr *pExpr){
8050380548
const char *zOp = 0;
8050480549
switch( pExpr->op ){
8050580550
case TK_STRING:
80551
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
8050680552
sqlite3_str_appendf(p, "%Q", pExpr->u.zToken);
8050780553
break;
8050880554
case TK_INTEGER:
8050980555
sqlite3_str_appendf(p, "%d", pExpr->u.iValue);
8051080556
break;
@@ -80847,12 +80893,12 @@
8084780893
** with no indexes using a single prepared INSERT statement, bind()
8084880894
** and reset(). Inserts are grouped into a transaction.
8084980895
*/
8085080896
testcase( p->flags & MEM_Agg );
8085180897
testcase( p->flags & MEM_Dyn );
80852
- testcase( p->xDel==sqlite3VdbeFrameMemDel );
8085380898
if( p->flags&(MEM_Agg|MEM_Dyn) ){
80899
+ testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
8085480900
sqlite3VdbeMemRelease(p);
8085580901
}else if( p->szMalloc ){
8085680902
sqlite3DbFreeNN(db, p->zMalloc);
8085780903
p->szMalloc = 0;
8085880904
}
@@ -84553,12 +84599,12 @@
8455384599
/**************************** sqlite3_result_ *******************************
8455484600
** The following routines are used by user-defined functions to specify
8455584601
** the function result.
8455684602
**
8455784603
** 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
84604
+** result as a string or blob. Appropriate errors are set if the string/blob
84605
+** is too big or if an OOM occurs.
8456084606
**
8456184607
** The invokeValueDestructor(P,X) routine invokes destructor function X()
8456284608
** on value P is not going to be used and need to be destroyed.
8456384609
*/
8456484610
static void setResultStrOrError(
@@ -84566,12 +84612,20 @@
8456684612
const char *z, /* String pointer */
8456784613
int n, /* Bytes in string, or negative */
8456884614
u8 enc, /* Encoding of z. 0 for BLOBs */
8456984615
void (*xDel)(void*) /* Destructor function */
8457084616
){
84571
- if( sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel)==SQLITE_TOOBIG ){
84572
- sqlite3_result_error_toobig(pCtx);
84617
+ int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel);
84618
+ if( rc ){
84619
+ if( rc==SQLITE_TOOBIG ){
84620
+ sqlite3_result_error_toobig(pCtx);
84621
+ }else{
84622
+ /* The only errors possible from sqlite3VdbeMemSetStr are
84623
+ ** SQLITE_TOOBIG and SQLITE_NOMEM */
84624
+ assert( rc==SQLITE_NOMEM );
84625
+ sqlite3_result_error_nomem(pCtx);
84626
+ }
8457384627
}
8457484628
}
8457584629
static int invokeValueDestructor(
8457684630
const void *p, /* Value to destroy */
8457784631
void (*xDel)(void*), /* The destructor */
@@ -90536,11 +90590,11 @@
9053690590
assert( aMem[pOp->p3].flags & MEM_Null );
9053790591
aMem[pOp->p3].n = 0;
9053890592
aMem[pOp->p3].z = "";
9053990593
}
9054090594
pCx = p->apCsr[pOp->p1];
90541
- if( pCx && !pCx->hasBeenDuped ){
90595
+ if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){
9054290596
/* If the ephermeral table is already open and has no duplicates from
9054390597
** OP_OpenDup, then erase all existing content so that the table is
9054490598
** empty again, rather than creating a new table. */
9054590599
assert( pCx->isEphemeral );
9054690600
pCx->seqCount = 0;
@@ -95092,11 +95146,11 @@
9509295146
/* Check that the column is not part of an FK child key definition. It
9509395147
** is not necessary to check if it is part of a parent key, as parent
9509495148
** key columns must be indexed. The check below will pick up this
9509595149
** case. */
9509695150
FKey *pFKey;
95097
- assert( !IsVirtual(pTab) );
95151
+ assert( IsOrdinaryTable(pTab) );
9509895152
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
9509995153
int j;
9510095154
for(j=0; j<pFKey->nCol; j++){
9510195155
if( pFKey->aCol[j].iFrom==iCol ){
9510295156
zFault = "foreign key";
@@ -96682,11 +96736,11 @@
9668296736
void *p = 0;
9668396737
int chunksize = 4*1024;
9668496738
sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
9668596739
sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
9668696740
sqlite3OsFetch(pFd, 0, (int)nByte, &p);
96687
- sqlite3OsUnfetch(pFd, 0, p);
96741
+ if( p ) sqlite3OsUnfetch(pFd, 0, p);
9668896742
}
9668996743
}
9669096744
#else
9669196745
# define vdbeSorterExtendFile(x,y,z)
9669296746
#endif
@@ -99101,11 +99155,11 @@
9910199155
if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
9910299156
if( pExpr->pRight ){
9910399157
assert( !ExprHasProperty(pExpr, EP_WinFunc) );
9910499158
pExpr = pExpr->pRight;
9910599159
continue;
99106
- }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
99160
+ }else if( ExprUseXSelect(pExpr) ){
9910799161
assert( !ExprHasProperty(pExpr, EP_WinFunc) );
9910899162
if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
9910999163
}else{
9911099164
if( pExpr->x.pList ){
9911199165
if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
@@ -99373,10 +99427,11 @@
9937399427
sqlite3ExprDelete(db, pDup);
9937499428
pDup = 0;
9937599429
}else{
9937699430
incrAggFunctionDepth(pDup, nSubquery);
9937799431
if( pExpr->op==TK_COLLATE ){
99432
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
9937899433
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
9937999434
}
9938099435
9938199436
/* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
9938299437
** prevents ExprDelete() from deleting the Expr structure itself,
@@ -99476,10 +99531,11 @@
9947699531
SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){
9947799532
int n;
9947899533
Table *pExTab;
9947999534
9948099535
n = pExpr->iColumn;
99536
+ assert( ExprUseYTab(pExpr) );
9948199537
pExTab = pExpr->y.pTab;
9948299538
assert( pExTab!=0 );
9948399539
if( (pExTab->tabFlags & TF_HasGenerated)!=0
9948499540
&& (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
9948599541
){
@@ -99613,10 +99669,11 @@
9961399669
const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
9961499670
assert( zTabName!=0 );
9961599671
if( sqlite3StrICmp(zTabName, zTab)!=0 ){
9961699672
continue;
9961799673
}
99674
+ assert( ExprUseYTab(pExpr) );
9961899675
if( IN_RENAME_OBJECT && pItem->zAlias ){
9961999676
sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
9962099677
}
9962199678
}
9962299679
hCol = sqlite3StrIHash(zCol);
@@ -99644,10 +99701,11 @@
9964499701
pMatch = pItem;
9964599702
}
9964699703
}
9964799704
if( pMatch ){
9964899705
pExpr->iTable = pMatch->iCursor;
99706
+ assert( ExprUseYTab(pExpr) );
9964999707
pExpr->y.pTab = pMatch->pTab;
9965099708
/* RIGHT JOIN not (yet) supported */
9965199709
assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
9965299710
if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
9965399711
ExprSetProperty(pExpr, EP_CanBeNull);
@@ -99717,10 +99775,11 @@
9971799775
cnt++;
9971899776
pMatch = 0;
9971999777
#ifndef SQLITE_OMIT_UPSERT
9972099778
if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
9972199779
testcase( iCol==(-1) );
99780
+ assert( ExprUseYTab(pExpr) );
9972299781
if( IN_RENAME_OBJECT ){
9972399782
pExpr->iColumn = iCol;
9972499783
pExpr->y.pTab = pTab;
9972599784
eNewExprOp = TK_COLUMN;
9972699785
}else{
@@ -99729,10 +99788,11 @@
9972999788
eNewExprOp = TK_REGISTER;
9973099789
}
9973199790
}else
9973299791
#endif /* SQLITE_OMIT_UPSERT */
9973399792
{
99793
+ assert( ExprUseYTab(pExpr) );
9973499794
pExpr->y.pTab = pTab;
9973599795
if( pParse->bReturning ){
9973699796
eNewExprOp = TK_REGISTER;
9973799797
pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
9973899798
sqlite3TableColumnToStorage(pTab, iCol) + 1;
@@ -99803,12 +99863,12 @@
9980399863
if( pEList->a[j].eEName==ENAME_NAME
9980499864
&& sqlite3_stricmp(zAs, zCol)==0
9980599865
){
9980699866
Expr *pOrig;
9980799867
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
99808
- assert( pExpr->x.pList==0 );
99809
- assert( pExpr->x.pSelect==0 );
99868
+ assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
99869
+ assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 );
9981099870
pOrig = pEList->a[j].pExpr;
9981199871
if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
9981299872
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
9981399873
return WRC_Abort;
9981499874
}
@@ -99876,11 +99936,11 @@
9987699936
"double-quoted string literal: \"%w\"", zCol);
9987799937
#ifdef SQLITE_ENABLE_NORMALIZE
9987899938
sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
9987999939
#endif
9988099940
pExpr->op = TK_STRING;
99881
- pExpr->y.pTab = 0;
99941
+ memset(&pExpr->y, 0, sizeof(pExpr->y));
9988299942
return WRC_Prune;
9988399943
}
9988499944
if( sqlite3ExprIdToTrueFalse(pExpr) ){
9988599945
return WRC_Prune;
9988699946
}
@@ -99962,11 +100022,13 @@
99962100022
*/
99963100023
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
99964100024
Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
99965100025
if( p ){
99966100026
SrcItem *pItem = &pSrc->a[iSrc];
99967
- Table *pTab = p->y.pTab = pItem->pTab;
100027
+ Table *pTab;
100028
+ assert( ExprUseYTab(p) );
100029
+ pTab = p->y.pTab = pItem->pTab;
99968100030
p->iTable = pItem->iCursor;
99969100031
if( p->y.pTab->iPKey==iCol ){
99970100032
p->iColumn = -1;
99971100033
}else{
99972100034
p->iColumn = (ynVar)iCol;
@@ -100029,10 +100091,11 @@
100029100091
** value between 1.0 and 0.0.
100030100092
*/
100031100093
static int exprProbability(Expr *p){
100032100094
double r = -1.0;
100033100095
if( p->op!=TK_FLOAT ) return -1;
100096
+ assert( !ExprHasProperty(p, EP_IntValue) );
100034100097
sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
100035100098
assert( r>=0.0 );
100036100099
if( r>1.0 ) return -1;
100037100100
return (int)(r*134217728.0);
100038100101
}
@@ -100077,10 +100140,11 @@
100077100140
SrcList *pSrcList = pNC->pSrcList;
100078100141
SrcItem *pItem;
100079100142
assert( pSrcList && pSrcList->nSrc>=1 );
100080100143
pItem = pSrcList->a;
100081100144
pExpr->op = TK_COLUMN;
100145
+ assert( ExprUseYTab(pExpr) );
100082100146
pExpr->y.pTab = pItem->pTab;
100083100147
pExpr->iTable = pItem->iCursor;
100084100148
pExpr->iColumn--;
100085100149
pExpr->affExpr = SQLITE_AFF_INTEGER;
100086100150
break;
@@ -100109,10 +100173,11 @@
100109100173
anRef[i] = p->nRef;
100110100174
}
100111100175
sqlite3WalkExpr(pWalker, pExpr->pLeft);
100112100176
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
100113100177
testcase( ExprHasProperty(pExpr, EP_FromJoin) );
100178
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
100114100179
if( pExpr->op==TK_NOTNULL ){
100115100180
pExpr->u.zToken = "true";
100116100181
ExprSetProperty(pExpr, EP_IsTrue);
100117100182
}else{
100118100183
pExpr->u.zToken = "false";
@@ -100144,10 +100209,11 @@
100144100209
Expr *pRight;
100145100210
100146100211
if( pExpr->op==TK_ID ){
100147100212
zDb = 0;
100148100213
zTable = 0;
100214
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
100149100215
zColumn = pExpr->u.zToken;
100150100216
}else{
100151100217
Expr *pLeft = pExpr->pLeft;
100152100218
testcase( pNC->ncFlags & NC_IdxExpr );
100153100219
testcase( pNC->ncFlags & NC_GenCol );
@@ -100156,16 +100222,19 @@
100156100222
pRight = pExpr->pRight;
100157100223
if( pRight->op==TK_ID ){
100158100224
zDb = 0;
100159100225
}else{
100160100226
assert( pRight->op==TK_DOT );
100227
+ assert( !ExprHasProperty(pRight, EP_IntValue) );
100161100228
zDb = pLeft->u.zToken;
100162100229
pLeft = pRight->pLeft;
100163100230
pRight = pRight->pRight;
100164100231
}
100232
+ assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) );
100165100233
zTable = pLeft->u.zToken;
100166100234
zColumn = pRight->u.zToken;
100235
+ assert( ExprUseYTab(pExpr) );
100167100236
if( IN_RENAME_OBJECT ){
100168100237
sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
100169100238
sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
100170100239
}
100171100240
}
@@ -100186,11 +100255,11 @@
100186100255
u8 enc = ENC(pParse->db); /* The database encoding */
100187100256
int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
100188100257
#ifndef SQLITE_OMIT_WINDOWFUNC
100189100258
Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
100190100259
#endif
100191
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
100260
+ assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
100192100261
zId = pExpr->u.zToken;
100193100262
nId = sqlite3Strlen30(zId);
100194100263
pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
100195100264
if( pDef==0 ){
100196100265
pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
@@ -100350,11 +100419,11 @@
100350100419
sqlite3WalkExprList(pWalker, pList);
100351100420
if( is_agg ){
100352100421
#ifndef SQLITE_OMIT_WINDOWFUNC
100353100422
if( pWin ){
100354100423
Select *pSel = pNC->pWinSelect;
100355
- assert( pWin==pExpr->y.pWin );
100424
+ assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) );
100356100425
if( IN_RENAME_OBJECT==0 ){
100357100426
sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
100358100427
if( pParse->db->mallocFailed ) break;
100359100428
}
100360100429
sqlite3WalkExprList(pWalker, pWin->pPartition);
@@ -100399,11 +100468,11 @@
100399100468
case TK_SELECT:
100400100469
case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
100401100470
#endif
100402100471
case TK_IN: {
100403100472
testcase( pExpr->op==TK_IN );
100404
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
100473
+ if( ExprUseXSelect(pExpr) ){
100405100474
int nRef = pNC->nRef;
100406100475
testcase( pNC->ncFlags & NC_IsCheck );
100407100476
testcase( pNC->ncFlags & NC_PartIdx );
100408100477
testcase( pNC->ncFlags & NC_IdxExpr );
100409100478
testcase( pNC->ncFlags & NC_GenCol );
@@ -100456,10 +100525,11 @@
100456100525
int nLeft, nRight;
100457100526
if( pParse->db->mallocFailed ) break;
100458100527
assert( pExpr->pLeft!=0 );
100459100528
nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
100460100529
if( pExpr->op==TK_BETWEEN ){
100530
+ assert( ExprUseXList(pExpr) );
100461100531
nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
100462100532
if( nRight==nLeft ){
100463100533
nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
100464100534
}
100465100535
}else{
@@ -100504,11 +100574,13 @@
100504100574
int i; /* Loop counter */
100505100575
100506100576
UNUSED_PARAMETER(pParse);
100507100577
100508100578
if( pE->op==TK_ID ){
100509
- char *zCol = pE->u.zToken;
100579
+ const char *zCol;
100580
+ assert( !ExprHasProperty(pE, EP_IntValue) );
100581
+ zCol = pE->u.zToken;
100510100582
for(i=0; i<pEList->nExpr; i++){
100511100583
if( pEList->a[i].eEName==ENAME_NAME
100512100584
&& sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
100513100585
){
100514100586
return i+1;
@@ -101369,15 +101441,18 @@
101369101441
pExpr = pExpr->pLeft;
101370101442
assert( pExpr!=0 );
101371101443
}
101372101444
op = pExpr->op;
101373101445
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);
101446
+ if( op==TK_COLUMN || op==TK_AGG_COLUMN ){
101447
+ assert( ExprUseYTab(pExpr) );
101448
+ if( pExpr->y.pTab ){
101449
+ return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101450
+ }
101376101451
}
101377101452
if( op==TK_SELECT ){
101378
- assert( pExpr->flags&EP_xIsSelect );
101453
+ assert( ExprUseXSelect(pExpr) );
101379101454
assert( pExpr->x.pSelect!=0 );
101380101455
assert( pExpr->x.pSelect->pEList!=0 );
101381101456
assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
101382101457
return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
101383101458
}
@@ -101386,18 +101461,19 @@
101386101461
assert( !ExprHasProperty(pExpr, EP_IntValue) );
101387101462
return sqlite3AffinityType(pExpr->u.zToken, 0);
101388101463
}
101389101464
#endif
101390101465
if( op==TK_SELECT_COLUMN ){
101391
- assert( pExpr->pLeft->flags&EP_xIsSelect );
101466
+ assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
101392101467
assert( pExpr->iColumn < pExpr->iTable );
101393101468
assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
101394101469
return sqlite3ExprAffinity(
101395101470
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
101396101471
);
101397101472
}
101398101473
if( op==TK_VECTOR ){
101474
+ assert( ExprUseXList(pExpr) );
101399101475
return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
101400101476
}
101401101477
return pExpr->affExpr;
101402101478
}
101403101479
@@ -101453,11 +101529,11 @@
101453101529
** expression.
101454101530
*/
101455101531
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
101456101532
while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){
101457101533
if( ExprHasProperty(pExpr, EP_Unlikely) ){
101458
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
101534
+ assert( ExprUseXList(pExpr) );
101459101535
assert( pExpr->x.pList->nExpr>0 );
101460101536
assert( pExpr->op==TK_FUNCTION );
101461101537
pExpr = pExpr->x.pList->a[0].pExpr;
101462101538
}else{
101463101539
assert( pExpr->op==TK_COLLATE );
@@ -101486,45 +101562,46 @@
101486101562
CollSeq *pColl = 0;
101487101563
const Expr *p = pExpr;
101488101564
while( p ){
101489101565
int op = p->op;
101490101566
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;
101567
+ if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){
101568
+ assert( ExprUseYTab(p) );
101569
+ if( p->y.pTab!=0 ){
101570
+ /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101571
+ ** a TK_COLUMN but was previously evaluated and cached in a register */
101572
+ int j = p->iColumn;
101573
+ if( j>=0 ){
101574
+ const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101575
+ pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101576
+ }
101577
+ break;
101578
+ }
101502101579
}
101503101580
if( op==TK_CAST || op==TK_UPLUS ){
101504101581
p = p->pLeft;
101505101582
continue;
101506101583
}
101507101584
if( op==TK_VECTOR ){
101585
+ assert( ExprUseXList(p) );
101508101586
p = p->x.pList->a[0].pExpr;
101509101587
continue;
101510101588
}
101511101589
if( op==TK_COLLATE ){
101590
+ assert( !ExprHasProperty(p, EP_IntValue) );
101512101591
pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
101513101592
break;
101514101593
}
101515101594
if( p->flags & EP_Collate ){
101516101595
if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
101517101596
p = p->pLeft;
101518101597
}else{
101519101598
Expr *pNext = p->pRight;
101520101599
/* The Expr.x union is never used at the same time as Expr.pRight */
101600
+ assert( ExprUseXList(p) );
101521101601
assert( p->x.pList==0 || p->pRight==0 );
101522
- if( p->x.pList!=0
101523
- && !db->mallocFailed
101524
- && ALWAYS(!ExprHasProperty(p, EP_xIsSelect))
101525
- ){
101602
+ if( p->x.pList!=0 && !db->mallocFailed ){
101526101603
int i;
101527101604
for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
101528101605
if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
101529101606
pNext = p->x.pList->a[i].pExpr;
101530101607
break;
@@ -101603,11 +101680,11 @@
101603101680
pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
101604101681
assert( pExpr->pLeft );
101605101682
aff = sqlite3ExprAffinity(pExpr->pLeft);
101606101683
if( pExpr->pRight ){
101607101684
aff = sqlite3CompareAffinity(pExpr->pRight, aff);
101608
- }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
101685
+ }else if( ExprUseXSelect(pExpr) ){
101609101686
aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
101610101687
}else if( aff==0 ){
101611101688
aff = SQLITE_AFF_BLOB;
101612101689
}
101613101690
return aff;
@@ -101743,12 +101820,14 @@
101743101820
*/
101744101821
SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){
101745101822
u8 op = pExpr->op;
101746101823
if( op==TK_REGISTER ) op = pExpr->op2;
101747101824
if( op==TK_VECTOR ){
101825
+ assert( ExprUseXList(pExpr) );
101748101826
return pExpr->x.pList->nExpr;
101749101827
}else if( op==TK_SELECT ){
101828
+ assert( ExprUseXSelect(pExpr) );
101750101829
return pExpr->x.pSelect->pEList->nExpr;
101751101830
}else{
101752101831
return 1;
101753101832
}
101754101833
}
@@ -101771,12 +101850,14 @@
101771101850
SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
101772101851
assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR );
101773101852
if( sqlite3ExprIsVector(pVector) ){
101774101853
assert( pVector->op2==0 || pVector->op==TK_REGISTER );
101775101854
if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){
101855
+ assert( ExprUseXSelect(pVector) );
101776101856
return pVector->x.pSelect->pEList->a[i].pExpr;
101777101857
}else{
101858
+ assert( ExprUseXList(pVector) );
101778101859
return pVector->x.pList->a[i].pExpr;
101779101860
}
101780101861
}
101781101862
return pVector;
101782101863
}
@@ -101808,11 +101889,11 @@
101808101889
int iField, /* Which column of the vector to return */
101809101890
int nField /* Total number of columns in the vector */
101810101891
){
101811101892
Expr *pRet;
101812101893
if( pVector->op==TK_SELECT ){
101813
- assert( pVector->flags & EP_xIsSelect );
101894
+ assert( ExprUseXSelect(pVector) );
101814101895
/* The TK_SELECT_COLUMN Expr node:
101815101896
**
101816101897
** pLeft: pVector containing TK_SELECT. Not deleted.
101817101898
** pRight: not used. But recursively deleted.
101818101899
** iColumn: Index of a column in pVector
@@ -101833,11 +101914,13 @@
101833101914
pRet->iColumn = iField;
101834101915
pRet->pLeft = pVector;
101835101916
}
101836101917
}else{
101837101918
if( pVector->op==TK_VECTOR ){
101838
- Expr **ppVector = &pVector->x.pList->a[iField].pExpr;
101919
+ Expr **ppVector;
101920
+ assert( ExprUseXList(pVector) );
101921
+ ppVector = &pVector->x.pList->a[iField].pExpr;
101839101922
pVector = *ppVector;
101840101923
if( IN_RENAME_OBJECT ){
101841101924
/* This must be a vector UPDATE inside a trigger */
101842101925
*ppVector = 0;
101843101926
return pVector;
@@ -101897,14 +101980,16 @@
101897101980
if( op==TK_REGISTER ){
101898101981
*ppExpr = sqlite3VectorFieldSubexpr(pVector, iField);
101899101982
return pVector->iTable+iField;
101900101983
}
101901101984
if( op==TK_SELECT ){
101985
+ assert( ExprUseXSelect(pVector) );
101902101986
*ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr;
101903101987
return regSelect+iField;
101904101988
}
101905101989
if( op==TK_VECTOR ){
101990
+ assert( ExprUseXList(pVector) );
101906101991
*ppExpr = pVector->x.pList->a[iField].pExpr;
101907101992
return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree);
101908101993
}
101909101994
return 0;
101910101995
}
@@ -102075,11 +102160,11 @@
102075102160
*/
102076102161
static void exprSetHeight(Expr *p){
102077102162
int nHeight = 0;
102078102163
heightOfExpr(p->pLeft, &nHeight);
102079102164
heightOfExpr(p->pRight, &nHeight);
102080
- if( ExprHasProperty(p, EP_xIsSelect) ){
102165
+ if( ExprUseXSelect(p) ){
102081102166
heightOfSelect(p->x.pSelect, &nHeight);
102082102167
}else if( p->x.pList ){
102083102168
heightOfExprList(p->x.pList, &nHeight);
102084102169
p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102085102170
}
@@ -102114,11 +102199,11 @@
102114102199
** Propagate all EP_Propagate flags from the Expr.x.pList into
102115102200
** Expr.flags.
102116102201
*/
102117102202
SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
102118102203
if( pParse->nErr ) return;
102119
- if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){
102204
+ if( p && ExprUseXList(p) && p->x.pList ){
102120102205
p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102121102206
}
102122102207
}
102123102208
#define exprSetHeight(y)
102124102209
#endif /* SQLITE_MAX_EXPR_DEPTH>0 */
@@ -102298,17 +102383,24 @@
102298102383
Select *pRet = 0;
102299102384
assert( nElem>1 );
102300102385
for(ii=0; ii<pEList->nExpr; ii++){
102301102386
Select *pSel;
102302102387
Expr *pExpr = pEList->a[ii].pExpr;
102303
- int nExprElem = (pExpr->op==TK_VECTOR ? pExpr->x.pList->nExpr : 1);
102388
+ int nExprElem;
102389
+ if( pExpr->op==TK_VECTOR ){
102390
+ assert( ExprUseXList(pExpr) );
102391
+ nExprElem = pExpr->x.pList->nExpr;
102392
+ }else{
102393
+ nExprElem = 1;
102394
+ }
102304102395
if( nExprElem!=nElem ){
102305102396
sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d",
102306102397
nExprElem, nExprElem>1?"s":"", nElem
102307102398
);
102308102399
break;
102309102400
}
102401
+ assert( ExprUseXList(pExpr) );
102310102402
pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
102311102403
pExpr->x.pList = 0;
102312102404
if( pSel ){
102313102405
if( pRet ){
102314102406
pSel->op = TK_ALL;
@@ -102374,11 +102466,11 @@
102374102466
){
102375102467
sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
102376102468
}
102377102469
pNew->x.pList = pList;
102378102470
ExprSetProperty(pNew, EP_HasFunc);
102379
- assert( !ExprHasProperty(pNew, EP_xIsSelect) );
102471
+ assert( ExprUseXList(pNew) );
102380102472
sqlite3ExprSetHeightAndFlags(pParse, pNew);
102381102473
if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
102382102474
return pNew;
102383102475
}
102384102476
@@ -102500,31 +102592,30 @@
102500102592
/*
102501102593
** Recursively delete an expression tree.
102502102594
*/
102503102595
static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
102504102596
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) );
102597
+ assert( !ExprUseUValue(p) || p->u.iValue>=0 );
102598
+ assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
102599
+ assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
102600
+ assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) );
102511102601
#ifdef SQLITE_DEBUG
102512102602
if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){
102513102603
assert( p->pLeft==0 );
102514102604
assert( p->pRight==0 );
102515
- assert( p->x.pSelect==0 );
102605
+ assert( !ExprUseXSelect(p) || p->x.pSelect==0 );
102606
+ assert( !ExprUseXList(p) || p->x.pList==0 );
102516102607
}
102517102608
#endif
102518102609
if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){
102519102610
/* The Expr.x union is never used at the same time as Expr.pRight */
102520
- assert( p->x.pList==0 || p->pRight==0 );
102611
+ assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 );
102521102612
if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft);
102522102613
if( p->pRight ){
102523102614
assert( !ExprHasProperty(p, EP_WinFunc) );
102524102615
sqlite3ExprDeleteNN(db, p->pRight);
102525
- }else if( ExprHasProperty(p, EP_xIsSelect) ){
102616
+ }else if( ExprUseXSelect(p) ){
102526102617
assert( !ExprHasProperty(p, EP_WinFunc) );
102527102618
sqlite3SelectDelete(db, p->x.pSelect);
102528102619
}else{
102529102620
sqlite3ExprListDelete(db, p->x.pList);
102530102621
#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -102532,11 +102623,14 @@
102532102623
sqlite3WindowDelete(db, p->y.pWin);
102533102624
}
102534102625
#endif
102535102626
}
102536102627
}
102537
- if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
102628
+ if( ExprHasProperty(p, EP_MemToken) ){
102629
+ assert( !ExprHasProperty(p, EP_IntValue) );
102630
+ sqlite3DbFree(db, p->u.zToken);
102631
+ }
102538102632
if( !ExprHasProperty(p, EP_Static) ){
102539102633
sqlite3DbFreeNN(db, p);
102540102634
}
102541102635
}
102542102636
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
@@ -102748,11 +102842,11 @@
102748102842
memcpy(zToken, p->u.zToken, nToken);
102749102843
}
102750102844
102751102845
if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){
102752102846
/* Fill in the pNew->x.pSelect or pNew->x.pList member. */
102753
- if( ExprHasProperty(p, EP_xIsSelect) ){
102847
+ if( ExprUseXSelect(p) ){
102754102848
pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
102755102849
}else{
102756102850
pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
102757102851
}
102758102852
}
@@ -103375,11 +103469,11 @@
103375103469
** the conversion happened, and zero if the expression is unaltered.
103376103470
*/
103377103471
SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
103378103472
u32 v;
103379103473
assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
103380
- if( !ExprHasProperty(pExpr, EP_Quoted)
103474
+ if( !ExprHasProperty(pExpr, EP_Quoted|EP_IntValue)
103381103475
&& (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
103382103476
){
103383103477
pExpr->op = TK_TRUEFALSE;
103384103478
ExprSetProperty(pExpr, v);
103385103479
return 1;
@@ -103392,10 +103486,11 @@
103392103486
** and 0 if it is FALSE.
103393103487
*/
103394103488
SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
103395103489
pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
103396103490
assert( pExpr->op==TK_TRUEFALSE );
103491
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
103397103492
assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
103398103493
|| sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
103399103494
return pExpr->u.zToken[4]==0;
103400103495
}
103401103496
@@ -103596,11 +103691,11 @@
103596103691
}
103597103692
}
103598103693
}
103599103694
103600103695
/* Check if pExpr is a sub-select. If so, consider it variable. */
103601
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
103696
+ if( ExprUseXSelect(pExpr) ){
103602103697
pWalker->eCode = 0;
103603103698
return WRC_Abort;
103604103699
}
103605103700
103606103701
return exprNodeIsConstant(pWalker, pExpr);
@@ -103746,10 +103841,11 @@
103746103841
case TK_STRING:
103747103842
case TK_FLOAT:
103748103843
case TK_BLOB:
103749103844
return 0;
103750103845
case TK_COLUMN:
103846
+ assert( ExprUseYTab(p) );
103751103847
return ExprHasProperty(p, EP_CanBeNull) ||
103752103848
p->y.pTab==0 || /* Reference to column of index on expression */
103753103849
(p->iColumn>=0
103754103850
&& ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
103755103851
&& p->y.pTab->aCol[p->iColumn].notNull==0);
@@ -103823,11 +103919,11 @@
103823103919
Select *p;
103824103920
SrcList *pSrc;
103825103921
ExprList *pEList;
103826103922
Table *pTab;
103827103923
int i;
103828
- if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */
103924
+ if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */
103829103925
if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
103830103926
p = pX->x.pSelect;
103831103927
if( p->pPrior ) return 0; /* Not a compound SELECT */
103832103928
if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
103833103929
testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -103994,11 +104090,11 @@
103994104090
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
103995104091
** whether or not the SELECT result contains NULL values, check whether
103996104092
** or not NULL is actually possible (it may not be, for example, due
103997104093
** to NOT NULL constraints in the schema). If no NULL values are possible,
103998104094
** set prRhsHasNull to 0 before continuing. */
103999
- if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){
104095
+ if( prRhsHasNull && ExprUseXSelect(pX) ){
104000104096
int i;
104001104097
ExprList *pEList = pX->x.pSelect->pEList;
104002104098
for(i=0; i<pEList->nExpr; i++){
104003104099
if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break;
104004104100
}
@@ -104150,11 +104246,11 @@
104150104246
** then it is not worth creating an ephemeral table to evaluate
104151104247
** the IN operator so return IN_INDEX_NOOP.
104152104248
*/
104153104249
if( eType==0
104154104250
&& (inFlags & IN_INDEX_NOOP_OK)
104155
- && !ExprHasProperty(pX, EP_xIsSelect)
104251
+ && ExprUseXList(pX)
104156104252
&& (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
104157104253
){
104158104254
eType = IN_INDEX_NOOP;
104159104255
}
104160104256
@@ -104198,11 +104294,11 @@
104198104294
** string is eventually freed using sqlite3DbFree().
104199104295
*/
104200104296
static char *exprINAffinity(Parse *pParse, const Expr *pExpr){
104201104297
Expr *pLeft = pExpr->pLeft;
104202104298
int nVal = sqlite3ExprVectorSize(pLeft);
104203
- Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0;
104299
+ Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
104204104300
char *zRet;
104205104301
104206104302
assert( pExpr->op==TK_IN );
104207104303
zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
104208104304
if( zRet ){
@@ -104248,11 +104344,11 @@
104248104344
**
104249104345
** "row value misused"
104250104346
*/
104251104347
SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
104252104348
#ifndef SQLITE_OMIT_SUBQUERY
104253
- if( pExpr->flags & EP_xIsSelect ){
104349
+ if( ExprUseXSelect(pExpr) ){
104254104350
sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
104255104351
}else
104256104352
#endif
104257104353
{
104258104354
sqlite3ErrorMsg(pParse, "row value misused");
@@ -104312,22 +104408,24 @@
104312104408
/* If this routine has already been coded, but the previous code
104313104409
** might not have been invoked yet, so invoke it now as a subroutine.
104314104410
*/
104315104411
if( ExprHasProperty(pExpr, EP_Subrtn) ){
104316104412
addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
104317
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104413
+ if( ExprUseXSelect(pExpr) ){
104318104414
ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
104319104415
pExpr->x.pSelect->selId));
104320104416
}
104417
+ assert( ExprUseYSub(pExpr) );
104321104418
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104322104419
pExpr->y.sub.iAddr);
104323104420
sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
104324104421
sqlite3VdbeJumpHere(v, addrOnce);
104325104422
return;
104326104423
}
104327104424
104328104425
/* Begin coding the subroutine */
104426
+ assert( !ExprUseYWin(pExpr) );
104329104427
ExprSetProperty(pExpr, EP_Subrtn);
104330104428
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
104331104429
pExpr->y.sub.regReturn = ++pParse->nMem;
104332104430
pExpr->y.sub.iAddr =
104333104431
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
@@ -104344,19 +104442,19 @@
104344104442
** RHS of the IN operator.
104345104443
*/
104346104444
pExpr->iTable = iTab;
104347104445
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
104348104446
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
104349
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104447
+ if( ExprUseXSelect(pExpr) ){
104350104448
VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
104351104449
}else{
104352104450
VdbeComment((v, "RHS of IN operator"));
104353104451
}
104354104452
#endif
104355104453
pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
104356104454
104357
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
104455
+ if( ExprUseXSelect(pExpr) ){
104358104456
/* Case 1: expr IN (SELECT ...)
104359104457
**
104360104458
** Generate code to write the results of the select into the temporary
104361104459
** table allocated and opened above.
104362104460
*/
@@ -104450,10 +104548,11 @@
104450104548
sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
104451104549
}
104452104550
if( addrOnce ){
104453104551
sqlite3VdbeJumpHere(v, addrOnce);
104454104552
/* Subroutine return */
104553
+ assert( ExprUseYSub(pExpr) );
104455104554
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104456104555
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104457104556
sqlite3ClearTempRegCache(pParse);
104458104557
}
104459104558
}
@@ -104486,23 +104585,26 @@
104486104585
assert( v!=0 );
104487104586
if( pParse->nErr ) return 0;
104488104587
testcase( pExpr->op==TK_EXISTS );
104489104588
testcase( pExpr->op==TK_SELECT );
104490104589
assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
104491
- assert( ExprHasProperty(pExpr, EP_xIsSelect) );
104590
+ assert( ExprUseXSelect(pExpr) );
104492104591
pSel = pExpr->x.pSelect;
104493104592
104494104593
/* If this routine has already been coded, then invoke it as a
104495104594
** subroutine. */
104496104595
if( ExprHasProperty(pExpr, EP_Subrtn) ){
104497104596
ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
104597
+ assert( ExprUseYSub(pExpr) );
104498104598
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104499104599
pExpr->y.sub.iAddr);
104500104600
return pExpr->iTable;
104501104601
}
104502104602
104503104603
/* Begin coding the subroutine */
104604
+ assert( !ExprUseYWin(pExpr) );
104605
+ assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) );
104504104606
ExprSetProperty(pExpr, EP_Subrtn);
104505104607
pExpr->y.sub.regReturn = ++pParse->nMem;
104506104608
pExpr->y.sub.iAddr =
104507104609
sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
104508104610
VdbeComment((v, "return address"));
@@ -104578,10 +104680,11 @@
104578104680
if( addrOnce ){
104579104681
sqlite3VdbeJumpHere(v, addrOnce);
104580104682
}
104581104683
104582104684
/* Subroutine return */
104685
+ assert( ExprUseYSub(pExpr) );
104583104686
sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104584104687
sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104585104688
sqlite3ClearTempRegCache(pParse);
104586104689
return rReg;
104587104690
}
@@ -104594,11 +104697,11 @@
104594104697
** columns as the vector on the LHS. Or, if the RHS of the IN() is not
104595104698
** a sub-query, that the LHS is a vector of size 1.
104596104699
*/
104597104700
SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
104598104701
int nVector = sqlite3ExprVectorSize(pIn->pLeft);
104599
- if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){
104702
+ if( ExprUseXSelect(pIn) && !pParse->db->mallocFailed ){
104600104703
if( nVector!=pIn->x.pSelect->pEList->nExpr ){
104601104704
sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
104602104705
return 1;
104603104706
}
104604104707
}else if( nVector!=1 ){
@@ -104728,17 +104831,19 @@
104728104831
** sequence of comparisons.
104729104832
**
104730104833
** This is step (1) in the in-operator.md optimized algorithm.
104731104834
*/
104732104835
if( eType==IN_INDEX_NOOP ){
104733
- ExprList *pList = pExpr->x.pList;
104734
- CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
104836
+ ExprList *pList;
104837
+ CollSeq *pColl;
104735104838
int labelOk = sqlite3VdbeMakeLabel(pParse);
104736104839
int r2, regToFree;
104737104840
int regCkNull = 0;
104738104841
int ii;
104739
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
104842
+ assert( ExprUseXList(pExpr) );
104843
+ pList = pExpr->x.pList;
104844
+ pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
104740104845
if( destIfNull!=destIfFalse ){
104741104846
regCkNull = sqlite3GetTempReg(pParse);
104742104847
sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
104743104848
}
104744104849
for(ii=0; ii<pList->nExpr; ii++){
@@ -105120,10 +105225,11 @@
105120105225
#endif
105121105226
}else{
105122105227
int i;
105123105228
iResult = pParse->nMem+1;
105124105229
pParse->nMem += nResult;
105230
+ assert( ExprUseXList(p) );
105125105231
for(i=0; i<nResult; i++){
105126105232
sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
105127105233
}
105128105234
}
105129105235
}
@@ -105318,10 +105424,11 @@
105318105424
** datatype by applying the Affinity of the table column to the
105319105425
** constant.
105320105426
*/
105321105427
int aff;
105322105428
iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
105429
+ assert( ExprUseYTab(pExpr) );
105323105430
if( pExpr->y.pTab ){
105324105431
aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105325105432
}else{
105326105433
aff = pExpr->affExpr;
105327105434
}
@@ -105341,13 +105448,15 @@
105341105448
** The row is unpacked into registers beginning at
105342105449
** 0-(pParse->iSelfTab). The rowid (if any) is in a register
105343105450
** immediately prior to the first column.
105344105451
*/
105345105452
Column *pCol;
105346
- Table *pTab = pExpr->y.pTab;
105453
+ Table *pTab;
105347105454
int iSrc;
105348105455
int iCol = pExpr->iColumn;
105456
+ assert( ExprUseYTab(pExpr) );
105457
+ pTab = pExpr->y.pTab;
105349105458
assert( pTab!=0 );
105350105459
assert( iCol>=XN_ROWID );
105351105460
assert( iCol<pTab->nCol );
105352105461
if( iCol<0 ){
105353105462
return -1-pParse->iSelfTab;
@@ -105381,10 +105490,11 @@
105381105490
/* Coding an expression that is part of an index where column names
105382105491
** in the index refer to the table to which the index belongs */
105383105492
iTab = pParse->iSelfTab - 1;
105384105493
}
105385105494
}
105495
+ assert( ExprUseYTab(pExpr) );
105386105496
iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
105387105497
pExpr->iColumn, iTab, target,
105388105498
pExpr->op2);
105389105499
if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
105390105500
sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
@@ -105458,10 +105568,11 @@
105458105568
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
105459105569
if( inReg!=target ){
105460105570
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
105461105571
inReg = target;
105462105572
}
105573
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
105463105574
sqlite3VdbeAddOp2(v, OP_Cast, target,
105464105575
sqlite3AffinityType(pExpr->u.zToken, 0));
105465105576
return inReg;
105466105577
}
105467105578
#endif /* SQLITE_OMIT_CAST */
@@ -105625,12 +105736,12 @@
105625105736
if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
105626105737
/* SQL functions can be expensive. So try to avoid running them
105627105738
** multiple times if we know they always give the same result */
105628105739
return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
105629105740
}
105630
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
105631105741
assert( !ExprHasProperty(pExpr, EP_TokenOnly) );
105742
+ assert( ExprUseXList(pExpr) );
105632105743
pFarg = pExpr->x.pList;
105633105744
nFarg = pFarg ? pFarg->nExpr : 0;
105634105745
assert( !ExprHasProperty(pExpr, EP_IntValue) );
105635105746
zId = pExpr->u.zToken;
105636105747
pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
@@ -105745,11 +105856,14 @@
105745105856
int nCol;
105746105857
testcase( op==TK_EXISTS );
105747105858
testcase( op==TK_SELECT );
105748105859
if( pParse->db->mallocFailed ){
105749105860
return 0;
105750
- }else if( op==TK_SELECT && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1 ){
105861
+ }else if( op==TK_SELECT
105862
+ && ALWAYS( ExprUseXSelect(pExpr) )
105863
+ && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1
105864
+ ){
105751105865
sqlite3SubselectError(pParse, nCol, 1);
105752105866
}else{
105753105867
return sqlite3CodeSubselect(pParse, pExpr);
105754105868
}
105755105869
break;
@@ -105827,13 +105941,18 @@
105827105941
**
105828105942
** p1==0 -> old.rowid p1==3 -> new.rowid
105829105943
** p1==1 -> old.a p1==4 -> new.a
105830105944
** p1==2 -> old.b p1==5 -> new.b
105831105945
*/
105832
- Table *pTab = pExpr->y.pTab;
105833
- int iCol = pExpr->iColumn;
105834
- int p1 = pExpr->iTable * (pTab->nCol+1) + 1
105946
+ Table *pTab;
105947
+ int iCol;
105948
+ int p1;
105949
+
105950
+ assert( ExprUseYTab(pExpr) );
105951
+ pTab = pExpr->y.pTab;
105952
+ iCol = pExpr->iColumn;
105953
+ p1 = pExpr->iTable * (pTab->nCol+1) + 1
105835105954
+ sqlite3TableColumnToStorage(pTab, iCol);
105836105955
105837105956
assert( pExpr->iTable==0 || pExpr->iTable==1 );
105838105957
assert( iCol>=-1 && iCol<pTab->nCol );
105839105958
assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
@@ -105917,11 +106036,11 @@
105917106036
Expr *pX; /* The X expression */
105918106037
Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
105919106038
Expr *pDel = 0;
105920106039
sqlite3 *db = pParse->db;
105921106040
105922
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
106041
+ assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 );
105923106042
assert(pExpr->x.pList->nExpr > 0);
105924106043
pEList = pExpr->x.pList;
105925106044
aListelem = pEList->a;
105926106045
nExpr = pEList->nExpr;
105927106046
endLabel = sqlite3VdbeMakeLabel(pParse);
@@ -106262,11 +106381,11 @@
106262106381
106263106382
memset(&compLeft, 0, sizeof(Expr));
106264106383
memset(&compRight, 0, sizeof(Expr));
106265106384
memset(&exprAnd, 0, sizeof(Expr));
106266106385
106267
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
106386
+ assert( ExprUseXList(pExpr) );
106268106387
pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
106269106388
if( db->mallocFailed==0 ){
106270106389
exprAnd.op = TK_AND;
106271106390
exprAnd.pLeft = &compLeft;
106272106391
exprAnd.pRight = &compRight;
@@ -106737,11 +106856,16 @@
106737106856
if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
106738106857
return 1;
106739106858
}
106740106859
return 2;
106741106860
}
106742
- if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){
106861
+ if( pA->op!=TK_COLUMN
106862
+ && pA->op!=TK_AGG_COLUMN
106863
+ && ALWAYS(!ExprHasProperty(pA, EP_IntValue))
106864
+ && pA->u.zToken
106865
+ ){
106866
+ assert( !ExprHasProperty(pB, EP_IntValue) );
106743106867
if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){
106744106868
if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
106745106869
#ifndef SQLITE_OMIT_WINDOWFUNC
106746106870
assert( pA->op==pB->op );
106747106871
if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){
@@ -106844,16 +106968,17 @@
106844106968
return pNN->op!=TK_NULL;
106845106969
}
106846106970
switch( p->op ){
106847106971
case TK_IN: {
106848106972
if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
106849
- assert( ExprHasProperty(p,EP_xIsSelect)
106850
- || (p->x.pList!=0 && p->x.pList->nExpr>0) );
106973
+ assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) );
106851106974
return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
106852106975
}
106853106976
case TK_BETWEEN: {
106854
- ExprList *pList = p->x.pList;
106977
+ ExprList *pList;
106978
+ assert( ExprUseXList(p) );
106979
+ pList = p->x.pList;
106855106980
assert( pList!=0 );
106856106981
assert( pList->nExpr==2 );
106857106982
if( seenNot ) return 0;
106858106983
if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
106859106984
|| exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1)
@@ -107026,14 +107151,18 @@
107026107151
testcase( pExpr->op==TK_LE );
107027107152
testcase( pExpr->op==TK_GT );
107028107153
testcase( pExpr->op==TK_GE );
107029107154
/* The y.pTab=0 assignment in wherecode.c always happens after the
107030107155
** 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))
107156
+ assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
107157
+ assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
107158
+ if( (pLeft->op==TK_COLUMN
107159
+ && pLeft->y.pTab!=0
107160
+ && IsVirtual(pLeft->y.pTab))
107161
+ || (pRight->op==TK_COLUMN
107162
+ && pRight->y.pTab!=0
107163
+ && IsVirtual(pRight->y.pTab))
107035107164
){
107036107165
return WRC_Prune;
107037107166
}
107038107167
/* no break */ deliberate_fall_through
107039107168
}
@@ -107213,10 +107342,11 @@
107213107342
w.u.pSrcCount = &cnt;
107214107343
cnt.pSrc = pSrcList;
107215107344
cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
107216107345
cnt.nThis = 0;
107217107346
cnt.nOther = 0;
107347
+ assert( ExprUseXList(pExpr) );
107218107348
sqlite3WalkExprList(&w, pExpr->x.pList);
107219107349
#ifndef SQLITE_OMIT_WINDOWFUNC
107220107350
if( ExprHasProperty(pExpr, EP_WinFunc) ){
107221107351
sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
107222107352
}
@@ -107354,10 +107484,11 @@
107354107484
}
107355107485
if( (k>=pAggInfo->nColumn)
107356107486
&& (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
107357107487
){
107358107488
pCol = &pAggInfo->aCol[k];
107489
+ assert( ExprUseYTab(pExpr) );
107359107490
pCol->pTab = pExpr->y.pTab;
107360107491
pCol->iTable = pExpr->iTable;
107361107492
pCol->iColumn = pExpr->iColumn;
107362107493
pCol->iMem = ++pParse->nMem;
107363107494
pCol->iSorterColumn = -1;
@@ -107417,11 +107548,11 @@
107417107548
if( i>=0 ){
107418107549
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
107419107550
pItem = &pAggInfo->aFunc[i];
107420107551
pItem->pFExpr = pExpr;
107421107552
pItem->iMem = ++pParse->nMem;
107422
- assert( !ExprHasProperty(pExpr, EP_IntValue) );
107553
+ assert( ExprUseUToken(pExpr) );
107423107554
pItem->pFunc = sqlite3FindFunction(pParse->db,
107424107555
pExpr->u.zToken,
107425107556
pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
107426107557
if( pExpr->flags & EP_Distinct ){
107427107558
pItem->iDistinct = pParse->nTab++;
@@ -107939,10 +108070,11 @@
107939108070
*/
107940108071
assert( pDflt==0 || pDflt->op==TK_SPAN );
107941108072
if( pDflt && pDflt->pLeft->op==TK_NULL ){
107942108073
pDflt = 0;
107943108074
}
108075
+ assert( IsOrdinaryTable(pNew) );
107944108076
if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
107945108077
sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
107946108078
"Cannot add a REFERENCES column with non-NULL default value");
107947108079
}
107948108080
if( pCol->notNull && !pDflt ){
@@ -107981,11 +108113,12 @@
107981108113
while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
107982108114
*zEnd-- = '\0';
107983108115
}
107984108116
/* substr() operations on characters, but addColOffset is in bytes. So we
107985108117
** have to use printf() to translate between these units: */
107986
- assert( !IsVirtual(pTab) );
108118
+ assert( IsOrdinaryTable(pTab) );
108119
+ assert( IsOrdinaryTable(pNew) );
107987108120
sqlite3NestedParse(pParse,
107988108121
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
107989108122
"sql = printf('%%.%ds, ',sql) || %Q"
107990108123
" || substr(sql,1+length(printf('%%.%ds',sql))) "
107991108124
"WHERE type = 'table' AND name = %Q",
@@ -108075,10 +108208,11 @@
108075108208
if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
108076108209
goto exit_begin_add_column;
108077108210
}
108078108211
108079108212
sqlite3MayAbort(pParse);
108213
+ assert( IsOrdinaryTable(pTab) );
108080108214
assert( pTab->u.tab.addColOffset>0 );
108081108215
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108082108216
108083108217
/* Put a copy of the Table struct in Parse.pNewTable for the
108084108218
** sqlite3AddColumn() function and friends to modify. But modify
@@ -108105,11 +108239,11 @@
108105108239
for(i=0; i<pNew->nCol; i++){
108106108240
Column *pCol = &pNew->aCol[i];
108107108241
pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
108108108242
pCol->hName = sqlite3StrIHash(pCol->zCnName);
108109108243
}
108110
- assert( !IsVirtual(pNew) );
108244
+ assert( IsOrdinaryTable(pNew) );
108111108245
pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
108112108246
pNew->pSchema = db->aDb[iDb].pSchema;
108113108247
pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
108114108248
pNew->nTabRef = 1;
108115108249
@@ -108374,11 +108508,13 @@
108374108508
** Walker callback used by sqlite3RenameExprUnmap().
108375108509
*/
108376108510
static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
108377108511
Parse *pParse = pWalker->pParse;
108378108512
sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
108379
- sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
108513
+ if( ExprUseYTab(pExpr) ){
108514
+ sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
108515
+ }
108380108516
return WRC_Continue;
108381108517
}
108382108518
108383108519
/*
108384108520
** Iterate through the Select objects that are part of WITH clauses attached
@@ -108436,11 +108572,13 @@
108436108572
*/
108437108573
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
108438108574
Parse *pParse = pWalker->pParse;
108439108575
int i;
108440108576
if( pParse->nErr ) return WRC_Abort;
108441
- if( NEVER(p->selFlags & (SF_View|SF_CopyCte)) ){
108577
+ testcase( p->selFlags & SF_View );
108578
+ testcase( p->selFlags & SF_CopyCte );
108579
+ if( p->selFlags & (SF_View|SF_CopyCte) ){
108442108580
return WRC_Prune;
108443108581
}
108444108582
if( ALWAYS(p->pEList) ){
108445108583
ExprList *pList = p->pEList;
108446108584
for(i=0; i<pList->nExpr; i++){
@@ -108573,10 +108711,11 @@
108573108711
&& pWalker->pParse->pTriggerTab==p->pTab
108574108712
){
108575108713
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108576108714
}else if( pExpr->op==TK_COLUMN
108577108715
&& pExpr->iColumn==p->iCol
108716
+ && ALWAYS(ExprUseYTab(pExpr))
108578108717
&& p->pTab==pExpr->y.pTab
108579108718
){
108580108719
renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108581108720
}
108582108721
return WRC_Continue;
@@ -109103,11 +109242,11 @@
109103109242
sqlite3WalkExpr(&sWalker, pExpr);
109104109243
}
109105109244
#endif
109106109245
}
109107109246
109108
- assert( !IsVirtual(sParse.pNewTable) );
109247
+ assert( IsOrdinaryTable(sParse.pNewTable) );
109109109248
for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109110109249
for(i=0; i<pFKey->nCol; i++){
109111109250
if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
109112109251
renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
109113109252
}
@@ -109175,11 +109314,14 @@
109175109314
/*
109176109315
** Walker expression callback used by "RENAME TABLE".
109177109316
*/
109178109317
static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
109179109318
RenameCtx *p = pWalker->u.pRename;
109180
- if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){
109319
+ if( pExpr->op==TK_COLUMN
109320
+ && ALWAYS(ExprUseYTab(pExpr))
109321
+ && p->pTab==pExpr->y.pTab
109322
+ ){
109181109323
renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab);
109182109324
}
109183109325
return WRC_Continue;
109184109326
}
109185109327
@@ -109293,11 +109435,11 @@
109293109435
#ifndef SQLITE_OMIT_FOREIGN_KEY
109294109436
if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
109295109437
&& !IsVirtual(pTab)
109296109438
){
109297109439
FKey *pFKey;
109298
- assert( !IsVirtual(pTab) );
109440
+ assert( IsOrdinaryTable(pTab) );
109299109441
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109300109442
if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109301109443
renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109302109444
}
109303109445
}
@@ -109614,11 +109756,11 @@
109614109756
if( iCol<pTab->nCol-1 ){
109615109757
RenameToken *pEnd;
109616109758
pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
109617109759
zEnd = (const char*)pEnd->t.z;
109618109760
}else{
109619
- assert( !IsVirtual(pTab) );
109761
+ assert( IsOrdinaryTable(pTab) );
109620109762
zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
109621109763
while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109622109764
}
109623109765
109624109766
zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
@@ -110789,11 +110931,11 @@
110789110931
pParse->nMem = MAX(pParse->nMem, iMem);
110790110932
v = sqlite3GetVdbe(pParse);
110791110933
if( v==0 || NEVER(pTab==0) ){
110792110934
return;
110793110935
}
110794
- if( pTab->tnum==0 ){
110936
+ if( !IsOrdinaryTable(pTab) ){
110795110937
/* Do not gather statistics on views or virtual tables */
110796110938
return;
110797110939
}
110798110940
if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
110799110941
/* Do not gather statistics on system tables */
@@ -112083,10 +112225,11 @@
112083112225
112084112226
#ifndef SQLITE_OMIT_AUTHORIZATION
112085112227
if( pAuthArg ){
112086112228
char *zAuthArg;
112087112229
if( pAuthArg->op==TK_STRING ){
112230
+ assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112088112231
zAuthArg = pAuthArg->u.zToken;
112089112232
}else{
112090112233
zAuthArg = 0;
112091112234
}
112092112235
rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
@@ -112767,21 +112910,25 @@
112767112910
Returning *pReturning = pParse->u1.pReturning;
112768112911
int addrRewind;
112769112912
int i;
112770112913
int reg;
112771112914
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);
112915
+ if( pReturning->nRetCol==0 ){
112916
+ assert( CORRUPT_DB );
112917
+ }else{
112918
+ addrRewind =
112919
+ sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
112920
+ VdbeCoverage(v);
112921
+ reg = pReturning->iRetReg;
112922
+ for(i=0; i<pReturning->nRetCol; i++){
112923
+ sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i);
112924
+ }
112925
+ sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i);
112926
+ sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1);
112927
+ VdbeCoverage(v);
112928
+ sqlite3VdbeJumpHere(v, addrRewind);
112929
+ }
112783112930
}
112784112931
sqlite3VdbeAddOp0(v, OP_Halt);
112785112932
112786112933
#if SQLITE_USER_AUTHENTICATION
112787112934
if( pParse->nTableLock>0 && db->init.busy==0 ){
@@ -112858,11 +113005,15 @@
112858113005
}
112859113006
}
112860113007
112861113008
if( pParse->bReturning ){
112862113009
Returning *pRet = pParse->u1.pReturning;
112863
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
113010
+ if( pRet->nRetCol==0 ){
113011
+ assert( CORRUPT_DB );
113012
+ }else{
113013
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
113014
+ }
112864113015
}
112865113016
112866113017
/* Finally, jump back to the beginning of the executable code. */
112867113018
sqlite3VdbeGoto(v, 1);
112868113019
}
@@ -113280,11 +113431,11 @@
113280113431
Table *pTab, /* The table containing the column */
113281113432
Column *pCol, /* The column to receive the new DEFAULT expression */
113282113433
Expr *pExpr /* The new default expression */
113283113434
){
113284113435
ExprList *pList;
113285
- assert( !IsVirtual(pTab) );
113436
+ assert( IsOrdinaryTable(pTab) );
113286113437
pList = pTab->u.tab.pDfltList;
113287113438
if( pCol->iDflt==0
113288113439
|| NEVER(pList==0)
113289113440
|| NEVER(pList->nExpr<pCol->iDflt)
113290113441
){
@@ -113301,11 +113452,11 @@
113301113452
** the DEFAULT clause or the AS clause of a generated column.
113302113453
** Return NULL if the column has no associated expression.
113303113454
*/
113304113455
SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){
113305113456
if( pCol->iDflt==0 ) return 0;
113306
- if( NEVER(IsVirtual(pTab)) ) return 0;
113457
+ if( NEVER(!IsOrdinaryTable(pTab)) ) return 0;
113307113458
if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
113308113459
if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
113309113460
return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
113310113461
}
113311113462
@@ -113360,17 +113511,17 @@
113360113511
for(i=0; i<pTable->nCol; i++, pCol++){
113361113512
assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
113362113513
sqlite3DbFree(db, pCol->zCnName);
113363113514
}
113364113515
sqlite3DbFree(db, pTable->aCol);
113365
- if( !IsVirtual(pTable) ){
113516
+ if( IsOrdinaryTable(pTable) ){
113366113517
sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
113367113518
}
113368113519
if( db==0 || db->pnBytesFreed==0 ){
113369113520
pTable->aCol = 0;
113370113521
pTable->nCol = 0;
113371
- if( !IsVirtual(pTable) ){
113522
+ if( IsOrdinaryTable(pTable) ){
113372113523
pTable->u.tab.pDfltList = 0;
113373113524
}
113374113525
}
113375113526
}
113376113527
}
@@ -114433,11 +114584,13 @@
114433114584
for(i=0; i<nTerm; i++){
114434114585
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
114435114586
assert( pCExpr!=0 );
114436114587
sqlite3StringToId(pCExpr);
114437114588
if( pCExpr->op==TK_ID ){
114438
- const char *zCName = pCExpr->u.zToken;
114589
+ const char *zCName;
114590
+ assert( !ExprHasProperty(pCExpr, EP_IntValue) );
114591
+ zCName = pCExpr->u.zToken;
114439114592
for(iCol=0; iCol<pTab->nCol; iCol++){
114440114593
if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
114441114594
pCol = &pTab->aCol[iCol];
114442114595
makeColumnPartOfPrimaryKey(pParse, pCol);
114443114596
break;
@@ -114805,11 +114958,10 @@
114805114958
** This is used to determine if the column number x appears in any of the
114806114959
** first nCol entries of an index.
114807114960
*/
114808114961
static int hasColumn(const i16 *aiCol, int nCol, int x){
114809114962
while( nCol-- > 0 ){
114810
- assert( aiCol[0]>=0 );
114811114963
if( x==*(aiCol++) ){
114812114964
return 1;
114813114965
}
114814114966
}
114815114967
return 0;
@@ -115181,11 +115333,11 @@
115181115333
**
115182115334
** If the root page number is 1, that means this is the sqlite_schema
115183115335
** table itself. So mark it read-only.
115184115336
*/
115185115337
if( db->init.busy ){
115186
- if( pSelect ){
115338
+ if( pSelect || (!IsOrdinaryTable(p) && db->init.newTnum) ){
115187115339
sqlite3ErrorMsg(pParse, "");
115188115340
return;
115189115341
}
115190115342
p->tnum = db->init.newTnum;
115191115343
if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
@@ -116146,10 +116298,11 @@
116146116298
pFKey = sqlite3DbMallocZero(db, nByte );
116147116299
if( pFKey==0 ){
116148116300
goto fk_end;
116149116301
}
116150116302
pFKey->pFrom = p;
116303
+ assert( IsOrdinaryTable(p) );
116151116304
pFKey->pNextFrom = p->u.tab.pFKey;
116152116305
z = (char*)&pFKey->aCol[nCol];
116153116306
pFKey->zTo = z;
116154116307
if( IN_RENAME_OBJECT ){
116155116308
sqlite3RenameTokenMap(pParse, (void*)z, pTo);
@@ -116211,11 +116364,11 @@
116211116364
pNextTo->pPrevTo = pFKey;
116212116365
}
116213116366
116214116367
/* Link the foreign key to the table as the last step.
116215116368
*/
116216
- assert( !IsVirtual(p) );
116369
+ assert( IsOrdinaryTable(p) );
116217116370
p->u.tab.pFKey = pFKey;
116218116371
pFKey = 0;
116219116372
116220116373
fk_end:
116221116374
sqlite3DbFree(db, pFKey);
@@ -116234,11 +116387,11 @@
116234116387
SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
116235116388
#ifndef SQLITE_OMIT_FOREIGN_KEY
116236116389
Table *pTab;
116237116390
FKey *pFKey;
116238116391
if( (pTab = pParse->pNewTable)==0 ) return;
116239
- if( NEVER(IsVirtual(pTab)) ) return;
116392
+ if( NEVER(!IsOrdinaryTable(pTab)) ) return;
116240116393
if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
116241116394
assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
116242116395
pFKey->isDeferred = (u8)isDeferred;
116243116396
#endif
116244116397
}
@@ -116636,10 +116789,11 @@
116636116789
*/
116637116790
for(i=0; i<pList->nExpr; i++){
116638116791
Expr *pExpr = pList->a[i].pExpr;
116639116792
assert( pExpr!=0 );
116640116793
if( pExpr->op==TK_COLLATE ){
116794
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
116641116795
nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
116642116796
}
116643116797
}
116644116798
116645116799
/*
@@ -116731,10 +116885,11 @@
116731116885
pIndex->aiColumn[i] = (i16)j;
116732116886
}
116733116887
zColl = 0;
116734116888
if( pListItem->pExpr->op==TK_COLLATE ){
116735116889
int nColl;
116890
+ assert( !ExprHasProperty(pListItem->pExpr, EP_IntValue) );
116736116891
zColl = pListItem->pExpr->u.zToken;
116737116892
nColl = sqlite3Strlen30(zColl) + 1;
116738116893
assert( nExtra>=nColl );
116739116894
memcpy(zExtra, zColl, nColl);
116740116895
zColl = zExtra;
@@ -117519,10 +117674,11 @@
117519117674
** construct "indexed_opt" for details. */
117520117675
pItem->fg.notIndexed = 1;
117521117676
}else{
117522117677
pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
117523117678
pItem->fg.isIndexedBy = 1;
117679
+ assert( pItem->fg.isCte==0 ); /* No collision on union u2 */
117524117680
}
117525117681
}
117526117682
}
117527117683
117528117684
/*
@@ -118499,10 +118655,11 @@
118499118655
int h, /* Hash of the name */
118500118656
const char *zFunc /* Name of function */
118501118657
){
118502118658
FuncDef *p;
118503118659
for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){
118660
+ assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
118504118661
if( sqlite3StrICmp(p->zName, zFunc)==0 ){
118505118662
return p;
118506118663
}
118507118664
}
118508118665
return 0;
@@ -118520,10 +118677,11 @@
118520118677
FuncDef *pOther;
118521118678
const char *zName = aDef[i].zName;
118522118679
int nName = sqlite3Strlen30(zName);
118523118680
int h = SQLITE_FUNC_HASH(zName[0], nName);
118524118681
assert( zName[0]>='a' && zName[0]<='z' );
118682
+ assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN );
118525118683
pOther = sqlite3FunctionSearch(h, zName);
118526118684
if( pOther ){
118527118685
assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] );
118528118686
aDef[i].pNext = pOther->pNext;
118529118687
pOther->pNext = &aDef[i];
@@ -118911,10 +119069,11 @@
118911119069
** and the SELECT subtree. */
118912119070
pSrc->a[0].pTab = 0;
118913119071
pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
118914119072
pSrc->a[0].pTab = pTab;
118915119073
if( pSrc->a[0].fg.isIndexedBy ){
119074
+ assert( pSrc->a[0].fg.isCte==0 );
118916119075
pSrc->a[0].u2.pIBIndex = 0;
118917119076
pSrc->a[0].fg.isIndexedBy = 0;
118918119077
sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
118919119078
}else if( pSrc->a[0].fg.isCte ){
118920119079
pSrc->a[0].u2.pCteUse->nUse++;
@@ -121495,11 +121654,15 @@
121495121654
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
121496121655
pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
121497121656
/* pGCC is always non-NULL since groupConcatStep() will have always
121498121657
** run frist to initialize it */
121499121658
if( ALWAYS(pGCC) ){
121500
- int nVS = sqlite3_value_bytes(argv[0]);
121659
+ int nVS;
121660
+ /* Must call sqlite3_value_text() to convert the argument into text prior
121661
+ ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
121662
+ (void)sqlite3_value_text(argv[0]);
121663
+ nVS = sqlite3_value_bytes(argv[0]);
121501121664
pGCC->nAccum -= 1;
121502121665
if( pGCC->pnSepLengths!=0 ){
121503121666
assert(pGCC->nAccum >= 0);
121504121667
if( pGCC->nAccum>0 ){
121505121668
nVS += *pGCC->pnSepLengths;
@@ -121610,15 +121773,16 @@
121610121773
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
121611121774
FuncDef *pDef;
121612121775
int nExpr;
121613121776
assert( pExpr!=0 );
121614121777
assert( pExpr->op==TK_FUNCTION );
121778
+ assert( ExprUseXList(pExpr) );
121615121779
if( !pExpr->x.pList ){
121616121780
return 0;
121617121781
}
121618
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
121619121782
nExpr = pExpr->x.pList->nExpr;
121783
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
121620121784
pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
121621121785
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
121622121786
if( pDef==0 ) return 0;
121623121787
#endif
121624121788
if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
@@ -121638,10 +121802,11 @@
121638121802
aWc[3] = 0;
121639121803
}else{
121640121804
Expr *pEscape = pExpr->x.pList->a[2].pExpr;
121641121805
char *zEscape;
121642121806
if( pEscape->op!=TK_STRING ) return 0;
121807
+ assert( !ExprHasProperty(pEscape, EP_IntValue) );
121643121808
zEscape = pEscape->u.zToken;
121644121809
if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
121645121810
if( zEscape[0]==aWc[0] ) return 0;
121646121811
if( zEscape[0]==aWc[1] ) return 0;
121647121812
aWc[3] = zEscape[0];
@@ -122019,10 +122184,11 @@
122019122184
for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
122020122185
printf("FUNC-HASH %02d:", i);
122021122186
for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){
122022122187
int n = sqlite3Strlen30(p->zName);
122023122188
int h = p->zName[0] + n;
122189
+ assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
122024122190
printf(" %s(%d)", p->zName, h);
122025122191
}
122026122192
printf("\n");
122027122193
}
122028122194
}
@@ -122541,10 +122707,11 @@
122541122707
int iCursor, /* The open cursor on the table */
122542122708
i16 iCol /* The column that is wanted */
122543122709
){
122544122710
Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
122545122711
if( pExpr ){
122712
+ assert( ExprUseYTab(pExpr) );
122546122713
pExpr->y.pTab = pTab;
122547122714
pExpr->iTable = iCursor;
122548122715
pExpr->iColumn = iCol;
122549122716
}
122550122717
return pExpr;
@@ -122751,17 +122918,16 @@
122751122918
** the table from the database. Triggers are disabled while running this
122752122919
** DELETE, but foreign key actions are not.
122753122920
*/
122754122921
SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
122755122922
sqlite3 *db = pParse->db;
122756
- if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){
122923
+ if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){
122757122924
int iSkip = 0;
122758122925
Vdbe *v = sqlite3GetVdbe(pParse);
122759122926
122760122927
assert( v ); /* VDBE has already been allocated */
122761
- assert( !IsView(pTab) ); /* Not a view */
122762
- assert( !IsVirtual(pTab) );
122928
+ assert( IsOrdinaryTable(pTab) );
122763122929
if( sqlite3FkReferences(pTab)==0 ){
122764122930
/* Search for a deferred foreign key constraint for which this table
122765122931
** is the child table. If one cannot be found, return without
122766122932
** generating any VDBE code. If one can be found, then jump over
122767122933
** the entire DELETE if there are no outstanding deferred constraints
@@ -122921,17 +123087,17 @@
122921123087
/* Exactly one of regOld and regNew should be non-zero. */
122922123088
assert( (regOld==0)!=(regNew==0) );
122923123089
122924123090
/* If foreign-keys are disabled, this function is a no-op. */
122925123091
if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
123092
+ if( !IsOrdinaryTable(pTab) ) return;
122926123093
122927123094
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
122928123095
zDb = db->aDb[iDb].zDbSName;
122929123096
122930123097
/* Loop through all the foreign key constraints for which pTab is the
122931123098
** child table (the table that the foreign key definition is part of). */
122932
- assert( !IsVirtual(pTab) );
122933123099
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
122934123100
Table *pTo; /* Parent table of foreign key pFKey */
122935123101
Index *pIdx = 0; /* Index on key columns in pTo */
122936123102
int *aiFree = 0;
122937123103
int *aiCol;
@@ -123110,14 +123276,13 @@
123110123276
SQLITE_PRIVATE u32 sqlite3FkOldmask(
123111123277
Parse *pParse, /* Parse context */
123112123278
Table *pTab /* Table being modified */
123113123279
){
123114123280
u32 mask = 0;
123115
- if( pParse->db->flags&SQLITE_ForeignKeys ){
123281
+ if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123116123282
FKey *p;
123117123283
int i;
123118
- assert( !IsVirtual(pTab) );
123119123284
for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
123120123285
for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
123121123286
}
123122123287
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
123123123288
Index *pIdx = 0;
@@ -123164,11 +123329,11 @@
123164123329
int *aChange, /* Non-NULL for UPDATE operations */
123165123330
int chngRowid /* True for UPDATE that affects rowid */
123166123331
){
123167123332
int eRet = 1; /* Value to return if bHaveFK is true */
123168123333
int bHaveFK = 0; /* If FK processing is required */
123169
- if( pParse->db->flags&SQLITE_ForeignKeys && !IsVirtual(pTab) ){
123334
+ if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123170123335
if( !aChange ){
123171123336
/* A DELETE operation. Foreign key processing is required if the
123172123337
** table in question is either the child or parent table for any
123173123338
** foreign key constraint. */
123174123339
bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
@@ -123452,11 +123617,11 @@
123452123617
*/
123453123618
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123454123619
FKey *pFKey; /* Iterator variable */
123455123620
FKey *pNext; /* Copy of pFKey->pNextFrom */
123456123621
123457
- assert( !IsVirtual(pTab) );
123622
+ assert( IsOrdinaryTable(pTab) );
123458123623
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
123459123624
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123460123625
123461123626
/* Remove the FK from the fkeyHash hash table. */
123462123627
if( !db || db->pnBytesFreed==0 ){
@@ -125711,10 +125876,11 @@
125711125876
** (5) No FK constraint counters need to be updated if a conflict occurs.
125712125877
**
125713125878
** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
125714125879
** must be explicitly deleted in order to ensure any pre-update hook
125715125880
** is invoked. */
125881
+ assert( IsOrdinaryTable(pTab) );
125716125882
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
125717125883
if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
125718125884
&& pPk==pIdx /* Condition 2 */
125719125885
&& onError==OE_Replace /* Condition 1 */
125720125886
&& ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
@@ -126391,11 +126557,13 @@
126391126557
/* Default values for second and subsequent columns need to match. */
126392126558
if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126393126559
Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
126394126560
Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
126395126561
assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
126562
+ assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
126396126563
assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
126564
+ assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
126397126565
if( (pDestExpr==0)!=(pSrcExpr==0)
126398126566
|| (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
126399126567
pSrcExpr->u.zToken)!=0)
126400126568
){
126401126569
return 0; /* Default values must be the same for all columns */
@@ -126431,10 +126599,11 @@
126431126599
** But the main beneficiary of the transfer optimization is the VACUUM
126432126600
** command, and the VACUUM command disables foreign key constraints. So
126433126601
** the extra complication to make this rule less restrictive is probably
126434126602
** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126435126603
*/
126604
+ assert( IsOrdinaryTable(pDest) );
126436126605
if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
126437126606
return 0;
126438126607
}
126439126608
#endif
126440126609
if( (db->flags & SQLITE_CountRows)!=0 ){
@@ -129423,11 +129592,15 @@
129423129592
goto pragma_out;
129424129593
}
129425129594
129426129595
/* Locate the pragma in the lookup table */
129427129596
pPragma = pragmaLocate(zLeft);
129428
- if( pPragma==0 ) goto pragma_out;
129597
+ if( pPragma==0 ){
129598
+ /* IMP: R-43042-22504 No error messages are generated if an
129599
+ ** unknown pragma is issued. */
129600
+ goto pragma_out;
129601
+ }
129429129602
129430129603
/* Make sure the database schema is loaded if the pragma requires that */
129431129604
if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
129432129605
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
129433129606
}
@@ -130073,10 +130246,18 @@
130073130246
if( sqlite3GetBoolean(zRight, 0) ){
130074130247
db->flags |= mask;
130075130248
}else{
130076130249
db->flags &= ~mask;
130077130250
if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
130251
+ if( (mask & SQLITE_WriteSchema)!=0
130252
+ && sqlite3_stricmp(zRight, "reset")==0
130253
+ ){
130254
+ /* IMP: R-60817-01178 If the argument is "RESET" then schema
130255
+ ** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
130256
+ ** in addition, the schema is reloaded. */
130257
+ sqlite3ResetAllSchemasOfConnection(db);
130258
+ }
130078130259
}
130079130260
130080130261
/* Many of the flag-pragmas modify the code generated by the SQL
130081130262
** compiler (eg. count_changes). So add an opcode to expire all
130082130263
** compiled SQL statements after modifying a pragma value.
@@ -130113,10 +130294,11 @@
130113130294
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
130114130295
pParse->nMem = 7;
130115130296
sqlite3ViewGetColumnNames(pParse, pTab);
130116130297
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
130117130298
int isHidden = 0;
130299
+ const Expr *pColExpr;
130118130300
if( pCol->colFlags & COLFLAG_NOINSERT ){
130119130301
if( pPragma->iArg==0 ){
130120130302
nHidden++;
130121130303
continue;
130122130304
}
@@ -130133,20 +130315,20 @@
130133130315
}else if( pPk==0 ){
130134130316
k = 1;
130135130317
}else{
130136130318
for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
130137130319
}
130138
- assert( sqlite3ColumnExpr(pTab,pCol)==0
130139
- || sqlite3ColumnExpr(pTab,pCol)->op==TK_SPAN
130140
- || isHidden>=2 );
130320
+ pColExpr = sqlite3ColumnExpr(pTab,pCol);
130321
+ assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 );
130322
+ assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue)
130323
+ || isHidden>=2 );
130141130324
sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
130142130325
i-nHidden,
130143130326
pCol->zCnName,
130144130327
sqlite3ColumnType(pCol,""),
130145130328
pCol->notNull ? 1 : 0,
130146
- isHidden>=2 || sqlite3ColumnExpr(pTab,pCol)==0 ? 0 :
130147
- sqlite3ColumnExpr(pTab,pCol)->u.zToken,
130329
+ (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken,
130148130330
k,
130149130331
isHidden);
130150130332
}
130151130333
}
130152130334
}
@@ -130170,12 +130352,39 @@
130170130352
pParse->nMem = 6;
130171130353
sqlite3CodeVerifyNamedSchema(pParse, zDb);
130172130354
for(ii=0; ii<db->nDb; ii++){
130173130355
HashElem *k;
130174130356
Hash *pHash;
130357
+ int initNCol;
130175130358
if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
130359
+
130360
+ /* Ensure that the Table.nCol field is initialized for all views
130361
+ ** and virtual tables. Each time we initialize a Table.nCol value
130362
+ ** for a table, that can potentially disrupt the hash table, so restart
130363
+ ** the initialization scan.
130364
+ */
130176130365
pHash = &db->aDb[ii].pSchema->tblHash;
130366
+ initNCol = sqliteHashCount(pHash);
130367
+ while( initNCol-- ){
130368
+ for(k=sqliteHashFirst(pHash); 1; k=sqliteHashNext(k) ){
130369
+ Table *pTab;
130370
+ if( k==0 ){ initNCol = 0; break; }
130371
+ pTab = sqliteHashData(k);
130372
+ if( pTab->nCol==0 ){
130373
+ char *zSql = sqlite3MPrintf(db, "SELECT*FROM\"%w\"", pTab->zName);
130374
+ if( zSql ){
130375
+ sqlite3_stmt *pDummy = 0;
130376
+ (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
130377
+ (void)sqlite3_finalize(pDummy);
130378
+ sqlite3DbFree(db, zSql);
130379
+ }
130380
+ pHash = &db->aDb[ii].pSchema->tblHash;
130381
+ break;
130382
+ }
130383
+ }
130384
+ }
130385
+
130177130386
for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){
130178130387
Table *pTab = sqliteHashData(k);
130179130388
const char *zType;
130180130389
if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
130181130390
if( IsView(pTab) ){
@@ -130326,15 +130535,17 @@
130326130535
FuncDef *p;
130327130536
int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
130328130537
pParse->nMem = 6;
130329130538
for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
130330130539
for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
130540
+ assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
130331130541
pragmaFunclistLine(v, p, 1, showInternFunc);
130332130542
}
130333130543
}
130334130544
for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
130335130545
p = (FuncDef*)sqliteHashData(j);
130546
+ assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
130336130547
pragmaFunclistLine(v, p, 0, showInternFunc);
130337130548
}
130338130549
}
130339130550
break;
130340130551
@@ -130364,11 +130575,11 @@
130364130575
#ifndef SQLITE_OMIT_FOREIGN_KEY
130365130576
case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
130366130577
FKey *pFK;
130367130578
Table *pTab;
130368130579
pTab = sqlite3FindTable(db, zRight, zDb);
130369
- if( pTab && !IsVirtual(pTab) ){
130580
+ if( pTab && IsOrdinaryTable(pTab) ){
130370130581
pFK = pTab->u.tab.pFKey;
130371130582
if( pFK ){
130372130583
int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130373130584
int i = 0;
130374130585
pParse->nMem = 8;
@@ -130424,19 +130635,19 @@
130424130635
k = 0;
130425130636
}else{
130426130637
pTab = (Table*)sqliteHashData(k);
130427130638
k = sqliteHashNext(k);
130428130639
}
130429
- if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue;
130640
+ if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue;
130430130641
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130431130642
zDb = db->aDb[iDb].zDbSName;
130432130643
sqlite3CodeVerifySchema(pParse, iDb);
130433130644
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130434130645
if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130435130646
sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130436130647
sqlite3VdbeLoadString(v, regResult, pTab->zName);
130437
- assert( !IsVirtual(pTab) );
130648
+ assert( IsOrdinaryTable(pTab) );
130438130649
for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130439130650
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130440130651
if( pParent==0 ) continue;
130441130652
pIdx = 0;
130442130653
sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -130455,11 +130666,11 @@
130455130666
}
130456130667
assert( pParse->nErr>0 || pFK==0 );
130457130668
if( pFK ) break;
130458130669
if( pParse->nTab<i ) pParse->nTab = i;
130459130670
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130460
- assert( !IsVirtual(pTab) );
130671
+ assert( IsOrdinaryTable(pTab) );
130461130672
for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130462130673
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130463130674
pIdx = 0;
130464130675
aiCols = 0;
130465130676
if( pParent ){
@@ -130659,11 +130870,11 @@
130659130870
int loopTop;
130660130871
int iDataCur, iIdxCur;
130661130872
int r1 = -1;
130662130873
int bStrict;
130663130874
130664
- if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
130875
+ if( !IsOrdinaryTable(pTab) ) continue;
130665130876
if( pObjTab && pObjTab!=pTab ) continue;
130666130877
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
130667130878
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
130668130879
1, 0, &iDataCur, &iIdxCur);
130669130880
/* reg[7] counts the number of entries in the table.
@@ -131254,16 +131465,16 @@
131254131465
** in each index that it looks at. Return the new limit.
131255131466
*/
131256131467
case PragTyp_ANALYSIS_LIMIT: {
131257131468
sqlite3_int64 N;
131258131469
if( zRight
131259
- && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
131470
+ && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */
131260131471
&& N>=0
131261131472
){
131262131473
db->nAnalysisLimit = (int)(N&0x7fffffff);
131263131474
}
131264
- returnSingleInt(v, db->nAnalysisLimit);
131475
+ returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */
131265131476
break;
131266131477
}
131267131478
131268131479
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
131269131480
/*
@@ -133046,14 +133257,17 @@
133046133257
while( p ){
133047133258
ExprSetProperty(p, EP_FromJoin);
133048133259
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
133049133260
ExprSetVVAProperty(p, EP_NoReduce);
133050133261
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);
133262
+ if( p->op==TK_FUNCTION ){
133263
+ assert( ExprUseXList(p) );
133264
+ if( p->x.pList ){
133265
+ int i;
133266
+ for(i=0; i<p->x.pList->nExpr; i++){
133267
+ sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133268
+ }
133055133269
}
133056133270
}
133057133271
sqlite3SetJoinExpr(p->pLeft, iTable);
133058133272
p = p->pRight;
133059133273
}
@@ -133072,14 +133286,17 @@
133072133286
ExprClearProperty(p, EP_FromJoin);
133073133287
}
133074133288
if( p->op==TK_COLUMN && p->iTable==iTable ){
133075133289
ExprClearProperty(p, EP_CanBeNull);
133076133290
}
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);
133291
+ if( p->op==TK_FUNCTION ){
133292
+ assert( ExprUseXList(p) );
133293
+ if( p->x.pList ){
133294
+ int i;
133295
+ for(i=0; i<p->x.pList->nExpr; i++){
133296
+ unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133297
+ }
133081133298
}
133082133299
}
133083133300
unsetJoinExpr(p->pLeft, iTable);
133084133301
p = p->pRight;
133085133302
}
@@ -133590,13 +133807,17 @@
133590133807
ExprList *pExtra = 0;
133591133808
for(i=0; i<pEList->nExpr; i++){
133592133809
struct ExprList_item *pItem = &pEList->a[i];
133593133810
if( pItem->u.x.iOrderByCol==0 ){
133594133811
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)
133812
+ Table *pTab;
133813
+ if( pExpr->op==TK_COLUMN
133814
+ && pExpr->iColumn>=0
133815
+ && ALWAYS( ExprUseYTab(pExpr) )
133816
+ && (pTab = pExpr->y.pTab)!=0
133817
+ && IsOrdinaryTable(pTab)
133818
+ && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0
133598133819
){
133599133820
int j;
133600133821
for(j=0; j<nDefer; j++){
133601133822
if( pSort->aDefer[j].iCsr==pExpr->iTable ) break;
133602133823
}
@@ -133613,10 +133834,11 @@
133613133834
}
133614133835
for(k=0; k<nKey; k++){
133615133836
Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
133616133837
if( pNew ){
133617133838
pNew->iTable = pExpr->iTable;
133839
+ assert( ExprUseYTab(pNew) );
133618133840
pNew->y.pTab = pExpr->y.pTab;
133619133841
pNew->iColumn = pPk ? pPk->aiColumn[k] : -1;
133620133842
pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew);
133621133843
}
133622133844
}
@@ -134461,11 +134683,11 @@
134461134683
** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
134462134684
** branch below. */
134463134685
break;
134464134686
}
134465134687
134466
- assert( pTab && pExpr->y.pTab==pTab );
134688
+ assert( pTab && ExprUseYTab(pExpr) && pExpr->y.pTab==pTab );
134467134689
if( pS ){
134468134690
/* The "table" is actually a sub-select or a view in the FROM clause
134469134691
** of the SELECT statement. Return the declaration type and origin
134470134692
** data for the result-set column of the sub-select.
134471134693
*/
@@ -134521,13 +134743,15 @@
134521134743
/* The expression is a sub-select. Return the declaration type and
134522134744
** origin info for the single column in the result set of the SELECT
134523134745
** statement.
134524134746
*/
134525134747
NameContext sNC;
134526
- Select *pS = pExpr->x.pSelect;
134527
- Expr *p = pS->pEList->a[0].pExpr;
134528
- assert( ExprHasProperty(pExpr, EP_xIsSelect) );
134748
+ Select *pS;
134749
+ Expr *p;
134750
+ assert( ExprUseXSelect(pExpr) );
134751
+ pS = pExpr->x.pSelect;
134752
+ p = pS->pEList->a[0].pExpr;
134529134753
sNC.pSrcList = pS->pSrc;
134530134754
sNC.pNext = pNC;
134531134755
sNC.pParse = pNC->pParse;
134532134756
zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
134533134757
break;
@@ -134652,11 +134876,12 @@
134652134876
for(i=0; i<pEList->nExpr; i++){
134653134877
Expr *p = pEList->a[i].pExpr;
134654134878
134655134879
assert( p!=0 );
134656134880
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 */
134881
+ assert( p->op!=TK_COLUMN
134882
+ || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
134658134883
if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
134659134884
/* An AS clause always takes first priority */
134660134885
char *zName = pEList->a[i].zEName;
134661134886
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
134662134887
}else if( srcName && p->op==TK_COLUMN ){
@@ -134748,11 +134973,14 @@
134748134973
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
134749134974
while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
134750134975
pColExpr = pColExpr->pRight;
134751134976
assert( pColExpr!=0 );
134752134977
}
134753
- if( pColExpr->op==TK_COLUMN && (pTab = pColExpr->y.pTab)!=0 ){
134978
+ if( pColExpr->op==TK_COLUMN
134979
+ && ALWAYS( ExprUseYTab(pColExpr) )
134980
+ && (pTab = pColExpr->y.pTab)!=0
134981
+ ){
134754134982
/* For columns use the column name name */
134755134983
int iCol = pColExpr->iColumn;
134756134984
if( iCol<0 ) iCol = pTab->iPKey;
134757134985
zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
134758134986
}else if( pColExpr->op==TK_ID ){
@@ -136330,11 +136558,11 @@
136330136558
if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
136331136559
pExpr->iTable = pSubst->iNewTable;
136332136560
}
136333136561
pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
136334136562
pExpr->pRight = substExpr(pSubst, pExpr->pRight);
136335
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
136563
+ if( ExprUseXSelect(pExpr) ){
136336136564
substSelect(pSubst, pExpr->x.pSelect, 1);
136337136565
}else{
136338136566
substExprList(pSubst, pExpr->x.pList);
136339136567
}
136340136568
#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -137541,25 +137769,28 @@
137541137769
** located but before their arguments have been subjected to aggregate
137542137770
** analysis.
137543137771
*/
137544137772
static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
137545137773
int eRet = WHERE_ORDERBY_NORMAL; /* Return value */
137546
- ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */
137774
+ ExprList *pEList; /* Arguments to agg function */
137547137775
const char *zFunc; /* Name of aggregate function pFunc */
137548137776
ExprList *pOrderBy;
137549137777
u8 sortFlags = 0;
137550137778
137551137779
assert( *ppMinMax==0 );
137552137780
assert( pFunc->op==TK_AGG_FUNCTION );
137553137781
assert( !IsWindowFunc(pFunc) );
137782
+ assert( ExprUseXList(pFunc) );
137783
+ pEList = pFunc->x.pList;
137554137784
if( pEList==0
137555137785
|| pEList->nExpr!=1
137556137786
|| ExprHasProperty(pFunc, EP_WinFunc)
137557137787
|| OptimizationDisabled(db, SQLITE_MinMaxOpt)
137558137788
){
137559137789
return eRet;
137560137790
}
137791
+ assert( !ExprHasProperty(pFunc, EP_IntValue) );
137561137792
zFunc = pFunc->u.zToken;
137562137793
if( sqlite3StrICmp(zFunc, "min")==0 ){
137563137794
eRet = WHERE_ORDERBY_MIN;
137564137795
if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
137565137796
sortFlags = KEYINFO_ORDER_BIGNULL;
@@ -137632,10 +137863,11 @@
137632137863
if( !pIdx ){
137633137864
sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
137634137865
pParse->checkSchema = 1;
137635137866
return SQLITE_ERROR;
137636137867
}
137868
+ assert( pFrom->fg.isCte==0 );
137637137869
pFrom->u2.pIBIndex = pIdx;
137638137870
return SQLITE_OK;
137639137871
}
137640137872
137641137873
/*
@@ -137889,10 +138121,14 @@
137889138121
pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
137890138122
pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
137891138123
if( db->mallocFailed ) return 2;
137892138124
pFrom->pSelect->selFlags |= SF_CopyCte;
137893138125
assert( pFrom->pSelect );
138126
+ if( pFrom->fg.isIndexedBy ){
138127
+ sqlite3ErrorMsg(pParse, "no such index: \"%s\"", pFrom->u1.zIndexedBy);
138128
+ return 2;
138129
+ }
137894138130
pFrom->fg.isCte = 1;
137895138131
pFrom->u2.pCteUse = pCteUse;
137896138132
pCteUse->nUse++;
137897138133
if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){
137898138134
pCteUse->eM10d = M10d_Yes;
@@ -138524,11 +138760,11 @@
138524138760
#endif
138525138761
sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
138526138762
for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
138527138763
if( pFunc->iDistinct>=0 ){
138528138764
Expr *pE = pFunc->pFExpr;
138529
- assert( !ExprHasProperty(pE, EP_xIsSelect) );
138765
+ assert( ExprUseXList(pE) );
138530138766
if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
138531138767
sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
138532138768
"argument");
138533138769
pFunc->iDistinct = -1;
138534138770
}else{
@@ -138549,12 +138785,13 @@
138549138785
static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
138550138786
Vdbe *v = pParse->pVdbe;
138551138787
int i;
138552138788
struct AggInfo_func *pF;
138553138789
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) );
138790
+ ExprList *pList;
138791
+ assert( ExprUseXList(pF->pFExpr) );
138792
+ pList = pF->pFExpr->x.pList;
138556138793
sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
138557138794
sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
138558138795
}
138559138796
}
138560138797
@@ -138584,13 +138821,14 @@
138584138821
pAggInfo->directMode = 1;
138585138822
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138586138823
int nArg;
138587138824
int addrNext = 0;
138588138825
int regAgg;
138589
- ExprList *pList = pF->pFExpr->x.pList;
138590
- assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
138826
+ ExprList *pList;
138827
+ assert( ExprUseXList(pF->pFExpr) );
138591138828
assert( !IsWindowFunc(pF->pFExpr) );
138829
+ pList = pF->pFExpr->x.pList;
138592138830
if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
138593138831
Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
138594138832
if( pAggInfo->nAccumulator
138595138833
&& (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
138596138834
&& regAcc
@@ -138832,11 +139070,13 @@
138832139070
if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
138833139071
if( p->pWhere ) return 0;
138834139072
if( p->pGroupBy ) return 0;
138835139073
pExpr = p->pEList->a[0].pExpr;
138836139074
if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
139075
+ assert( ExprUseUToken(pExpr) );
138837139076
if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
139077
+ assert( ExprUseXList(pExpr) );
138838139078
if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
138839139079
if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
138840139080
pSub = p->pSrc->a[0].pSelect;
138841139081
if( pSub==0 ) return 0; /* The FROM is a subquery */
138842139082
if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */
@@ -139647,11 +139887,11 @@
139647139887
}else{
139648139888
minMaxFlag = WHERE_ORDERBY_NORMAL;
139649139889
}
139650139890
for(i=0; i<pAggInfo->nFunc; i++){
139651139891
Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
139652
- assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
139892
+ assert( ExprUseXList(pExpr) );
139653139893
sNC.ncFlags |= NC_InAggFunc;
139654139894
sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
139655139895
#ifndef SQLITE_OMIT_WINDOWFUNC
139656139896
assert( !IsWindowFunc(pExpr) );
139657139897
if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -139702,11 +139942,13 @@
139702139942
u16 distFlag = 0;
139703139943
int eDist = WHERE_DISTINCT_NOOP;
139704139944
139705139945
if( pAggInfo->nFunc==1
139706139946
&& pAggInfo->aFunc[0].iDistinct>=0
139707
- && pAggInfo->aFunc[0].pFExpr->x.pList
139947
+ && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0)
139948
+ && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr))
139949
+ && pAggInfo->aFunc[0].pFExpr->x.pList!=0
139708139950
){
139709139951
Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
139710139952
pExpr = sqlite3ExprDup(db, pExpr, 0);
139711139953
pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
139712139954
pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr);
@@ -140023,10 +140265,11 @@
140023140265
if( i==pAggInfo->nFunc ){
140024140266
regAcc = ++pParse->nMem;
140025140267
sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
140026140268
}
140027140269
}else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
140270
+ assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) );
140028140271
pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
140029140272
distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
140030140273
}
140031140274
140032140275
/* This case runs if the aggregate has no GROUP BY clause. The
@@ -144048,11 +144291,14 @@
144048144291
** Except, if argument db is not NULL, then the entry associated with
144049144292
** connection db is left in the p->u.vtab.p list.
144050144293
*/
144051144294
static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
144052144295
VTable *pRet = 0;
144053
- VTable *pVTable = p->u.vtab.p;
144296
+ VTable *pVTable;
144297
+
144298
+ assert( IsVirtual(p) );
144299
+ pVTable = p->u.vtab.p;
144054144300
p->u.vtab.p = 0;
144055144301
144056144302
/* Assert that the mutex (if any) associated with the BtShared database
144057144303
** that contains table p is held by the caller. See header comments
144058144304
** above function sqlite3VtabUnlockList() for an explanation of why
@@ -144156,10 +144402,11 @@
144156144402
** structure being xDisconnected and free). Any other VTable structures
144157144403
** in the list are moved to the sqlite3.pDisconnect list of the associated
144158144404
** database connection.
144159144405
*/
144160144406
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
144407
+ assert( IsVirtual(p) );
144161144408
if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
144162144409
if( p->u.vtab.azArg ){
144163144410
int i;
144164144411
for(i=0; i<p->u.vtab.nArg; i++){
144165144412
if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
@@ -144173,13 +144420,16 @@
144173144420
** The string is not copied - the pointer is stored. The
144174144421
** string will be freed automatically when the table is
144175144422
** deleted.
144176144423
*/
144177144424
static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
144178
- sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
144425
+ sqlite3_int64 nBytes;
144179144426
char **azModuleArg;
144180144427
sqlite3 *db = pParse->db;
144428
+
144429
+ assert( IsVirtual(pTable) );
144430
+ nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
144181144431
if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
144182144432
sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
144183144433
}
144184144434
azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes);
144185144435
if( azModuleArg==0 ){
@@ -144262,10 +144512,11 @@
144262144512
SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
144263144513
Table *pTab = pParse->pNewTable; /* The table being constructed */
144264144514
sqlite3 *db = pParse->db; /* The database connection */
144265144515
144266144516
if( pTab==0 ) return;
144517
+ assert( IsVirtual(pTab) );
144267144518
addArgumentToVtab(pParse);
144268144519
pParse->sArg.z = 0;
144269144520
if( pTab->u.vtab.nArg<1 ) return;
144270144521
144271144522
/* If the CREATE VIRTUAL TABLE statement is being entered for the
@@ -144379,17 +144630,20 @@
144379144630
char **pzErr
144380144631
){
144381144632
VtabCtx sCtx;
144382144633
VTable *pVTable;
144383144634
int rc;
144384
- const char *const*azArg = (const char *const*)pTab->u.vtab.azArg;
144635
+ const char *const*azArg;
144385144636
int nArg = pTab->u.vtab.nArg;
144386144637
char *zErr = 0;
144387144638
char *zModuleName;
144388144639
int iDb;
144389144640
VtabCtx *pCtx;
144390144641
144642
+ assert( IsVirtual(pTab) );
144643
+ azArg = (const char *const*)pTab->u.vtab.azArg;
144644
+
144391144645
/* Check that the virtual-table is not already being initialized */
144392144646
for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
144393144647
if( pCtx->pTab==pTab ){
144394144648
*pzErr = sqlite3MPrintf(db,
144395144649
"vtable constructor called recursively: %s", pTab->zName
@@ -144713,11 +144967,11 @@
144713144967
SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144714144968
int rc = SQLITE_OK;
144715144969
Table *pTab;
144716144970
144717144971
pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144718
- if( pTab!=0 && ALWAYS(pTab->u.vtab.p!=0) ){
144972
+ if( pTab!=0 && ALWAYS(IsVirtual(pTab)) && ALWAYS(pTab->u.vtab.p!=0) ){
144719144973
VTable *p;
144720144974
int (*xDestroy)(sqlite3_vtab *);
144721144975
for(p=pTab->u.vtab.p; p; p=p->pNext){
144722144976
assert( p->pVtab );
144723144977
if( p->pVtab->nRef>0 ){
@@ -144946,10 +145200,11 @@
144946145200
int rc = 0;
144947145201
144948145202
/* Check to see the left operand is a column in a virtual table */
144949145203
if( NEVER(pExpr==0) ) return pDef;
144950145204
if( pExpr->op!=TK_COLUMN ) return pDef;
145205
+ assert( ExprUseYTab(pExpr) );
144951145206
pTab = pExpr->y.pTab;
144952145207
if( pTab==0 ) return pDef;
144953145208
if( !IsVirtual(pTab) ) return pDef;
144954145209
pVtab = sqlite3GetVTable(db, pTab)->pVtab;
144955145210
assert( pVtab!=0 );
@@ -145254,11 +145509,11 @@
145254145509
int iBase; /* Base register of multi-key index record */
145255145510
int nPrefix; /* Number of prior entires in the key */
145256145511
u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
145257145512
} *aInLoop; /* Information about each nested IN operator */
145258145513
} in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
145259
- Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
145514
+ Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */
145260145515
} u;
145261145516
struct WhereLoop *pWLoop; /* The selected WhereLoop object */
145262145517
Bitmask notReady; /* FROM entries not usable at this level */
145263145518
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
145264145519
int addrVisit; /* Address at which row is visited */
@@ -146182,20 +146437,27 @@
146182146437
){
146183146438
sqlite3 *db = pParse->db;
146184146439
Expr *pNew;
146185146440
pNew = sqlite3ExprDup(db, pX, 0);
146186146441
if( db->mallocFailed==0 ){
146187
- ExprList *pOrigRhs = pNew->x.pSelect->pEList; /* Original unmodified RHS */
146188
- ExprList *pOrigLhs = pNew->pLeft->x.pList; /* Original unmodified LHS */
146442
+ ExprList *pOrigRhs; /* Original unmodified RHS */
146443
+ ExprList *pOrigLhs; /* Original unmodified LHS */
146189146444
ExprList *pRhs = 0; /* New RHS after modifications */
146190146445
ExprList *pLhs = 0; /* New LHS after mods */
146191146446
int i; /* Loop counter */
146192146447
Select *pSelect; /* Pointer to the SELECT on the RHS */
146193146448
146449
+ assert( ExprUseXSelect(pNew) );
146450
+ pOrigRhs = pNew->x.pSelect->pEList;
146451
+ assert( pNew->pLeft!=0 );
146452
+ assert( ExprUseXList(pNew->pLeft) );
146453
+ pOrigLhs = pNew->pLeft->x.pList;
146194146454
for(i=iEq; i<pLoop->nLTerm; i++){
146195146455
if( pLoop->aLTerm[i]->pExpr==pX ){
146196
- int iField = pLoop->aLTerm[i]->u.x.iField - 1;
146456
+ int iField;
146457
+ assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
146458
+ iField = pLoop->aLTerm[i]->u.x.iField - 1;
146197146459
if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
146198146460
pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
146199146461
pOrigRhs->a[iField].pExpr = 0;
146200146462
assert( pOrigLhs->a[iField].pExpr!=0 );
146201146463
pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
@@ -146306,11 +146568,11 @@
146306146568
assert( pLoop->aLTerm[i]!=0 );
146307146569
if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
146308146570
}
146309146571
146310146572
iTab = 0;
146311
- if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
146573
+ if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
146312146574
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
146313146575
}else{
146314146576
sqlite3 *db = pParse->db;
146315146577
pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
146316146578
@@ -146328,12 +146590,12 @@
146328146590
bRev = !bRev;
146329146591
}
146330146592
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
146331146593
VdbeCoverageIf(v, bRev);
146332146594
VdbeCoverageIf(v, !bRev);
146595
+
146333146596
assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
146334
-
146335146597
pLoop->wsFlags |= WHERE_IN_ABLE;
146336146598
if( pLevel->u.in.nIn==0 ){
146337146599
pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
146338146600
}
146339146601
if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
@@ -146871,21 +147133,23 @@
146871147133
*/
146872147134
static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
146873147135
assert( nReg>0 );
146874147136
if( p && sqlite3ExprIsVector(p) ){
146875147137
#ifndef SQLITE_OMIT_SUBQUERY
146876
- if( (p->flags & EP_xIsSelect) ){
147138
+ if( ExprUseXSelect(p) ){
146877147139
Vdbe *v = pParse->pVdbe;
146878147140
int iSelect;
146879147141
assert( p->op==TK_SELECT );
146880147142
iSelect = sqlite3CodeSubselect(pParse, p);
146881147143
sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
146882147144
}else
146883147145
#endif
146884147146
{
146885147147
int i;
146886
- ExprList *pList = p->x.pList;
147148
+ const ExprList *pList;
147149
+ assert( ExprUseXList(p) );
147150
+ pList = p->x.pList;
146887147151
assert( nReg<=pList->nExpr );
146888147152
for(i=0; i<nReg; i++){
146889147153
sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i);
146890147154
}
146891147155
}
@@ -146934,14 +147198,14 @@
146934147198
preserveExpr(pX, pExpr);
146935147199
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
146936147200
pExpr->op = TK_COLUMN;
146937147201
pExpr->iTable = pX->iIdxCur;
146938147202
pExpr->iColumn = pX->iIdxCol;
146939
- pExpr->y.pTab = 0;
146940147203
testcase( ExprHasProperty(pExpr, EP_Skip) );
146941147204
testcase( ExprHasProperty(pExpr, EP_Unlikely) );
146942
- ExprClearProperty(pExpr, EP_Skip|EP_Unlikely);
147205
+ ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
147206
+ pExpr->y.pTab = 0;
146943147207
return WRC_Prune;
146944147208
}else{
146945147209
return WRC_Continue;
146946147210
}
146947147211
}
@@ -146952,11 +147216,11 @@
146952147216
*/
146953147217
static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
146954147218
if( pExpr->op==TK_COLUMN ){
146955147219
IdxExprTrans *pX = p->u.pIdxTrans;
146956147220
if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
146957
- assert( pExpr->y.pTab!=0 );
147221
+ assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 );
146958147222
preserveExpr(pX, pExpr);
146959147223
pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
146960147224
pExpr->iTable = pX->iIdxCur;
146961147225
pExpr->iColumn = pX->iIdxCol;
146962147226
pExpr->y.pTab = 0;
@@ -147189,11 +147453,16 @@
147189147453
** the u.vtab.idxStr. NULL it out to prevent a use-after-free */
147190147454
if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
147191147455
pLevel->p1 = iCur;
147192147456
pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
147193147457
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
147194
- iIn = pLevel->u.in.nIn;
147458
+ assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
147459
+ if( pLoop->wsFlags & WHERE_IN_ABLE ){
147460
+ iIn = pLevel->u.in.nIn;
147461
+ }else{
147462
+ iIn = 0;
147463
+ }
147195147464
for(j=nConstraint-1; j>=0; j--){
147196147465
pTerm = pLoop->aLTerm[j];
147197147466
if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
147198147467
if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
147199147468
disableTerm(pLevel, pTerm);
@@ -148078,11 +148347,14 @@
148078148347
}
148079148348
sqlite3ExprDelete(db, pDelete);
148080148349
}
148081148350
}
148082148351
ExplainQueryPlanPop(pParse);
148083
- pLevel->u.pCovidx = pCov;
148352
+ assert( pLevel->pWLoop==pLoop );
148353
+ assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 );
148354
+ assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 );
148355
+ pLevel->u.pCoveringIdx = pCov;
148084148356
if( pCov ) pLevel->iIdxCur = iCovCur;
148085148357
if( pAndExpr ){
148086148358
pAndExpr->pLeft = 0;
148087148359
sqlite3ExprDelete(db, pAndExpr);
148088148360
}
@@ -148222,16 +148494,17 @@
148222148494
sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
148223148495
}
148224148496
#endif
148225148497
assert( !ExprHasProperty(pE, EP_FromJoin) );
148226148498
assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
148499
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
148227148500
pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
148228148501
WO_EQ|WO_IN|WO_IS, 0);
148229148502
if( pAlt==0 ) continue;
148230148503
if( pAlt->wtFlags & (TERM_CODED) ) continue;
148231148504
if( (pAlt->eOperator & WO_IN)
148232
- && (pAlt->pExpr->flags & EP_xIsSelect)
148505
+ && ExprUseXSelect(pAlt->pExpr)
148233148506
&& (pAlt->pExpr->x.pSelect->pEList->nExpr>1)
148234148507
){
148235148508
continue;
148236148509
}
148237148510
testcase( pAlt->eOperator & WO_EQ );
@@ -148476,10 +148749,11 @@
148476148749
return 0;
148477148750
}
148478148751
#ifdef SQLITE_EBCDIC
148479148752
if( *pnoCase ) return 0;
148480148753
#endif
148754
+ assert( ExprUseXList(pExpr) );
148481148755
pList = pExpr->x.pList;
148482148756
pLeft = pList->a[1].pExpr;
148483148757
148484148758
pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
148485148759
op = pRight->op;
@@ -148491,11 +148765,12 @@
148491148765
z = sqlite3_value_text(pVal);
148492148766
}
148493148767
sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
148494148768
assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
148495148769
}else if( op==TK_STRING ){
148496
- z = (u8*)pRight->u.zToken;
148770
+ assert( !ExprHasProperty(pRight, EP_IntValue) );
148771
+ z = (u8*)pRight->u.zToken;
148497148772
}
148498148773
if( z ){
148499148774
148500148775
/* Count the number of prefix characters prior to the first wildcard */
148501148776
cnt = 0;
@@ -148520,11 +148795,13 @@
148520148795
148521148796
/* Get the pattern prefix. Remove all escapes from the prefix. */
148522148797
pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
148523148798
if( pPrefix ){
148524148799
int iFrom, iTo;
148525
- char *zNew = pPrefix->u.zToken;
148800
+ char *zNew;
148801
+ assert( !ExprHasProperty(pPrefix, EP_IntValue) );
148802
+ zNew = pPrefix->u.zToken;
148526148803
zNew[cnt] = 0;
148527148804
for(iFrom=iTo=0; iFrom<cnt; iFrom++){
148528148805
if( zNew[iFrom]==wc[3] ) iFrom++;
148529148806
zNew[iTo++] = zNew[iFrom];
148530148807
}
@@ -148544,11 +148821,13 @@
148544148821
** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148545148822
** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148546148823
*/
148547148824
if( pLeft->op!=TK_COLUMN
148548148825
|| sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148549
- || (pLeft->y.pTab && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148826
+ || (ALWAYS( ExprUseYTab(pLeft) )
148827
+ && pLeft->y.pTab
148828
+ && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148550148829
){
148551148830
int isNum;
148552148831
double rDummy;
148553148832
isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148554148833
if( isNum<=0 ){
@@ -148572,10 +148851,11 @@
148572148851
/* If the RHS pattern is a bound parameter, make arrangements to
148573148852
** reprepare the statement when that parameter is rebound */
148574148853
if( op==TK_VARIABLE ){
148575148854
Vdbe *v = pParse->pVdbe;
148576148855
sqlite3VdbeSetVarmask(v, pRight->iColumn);
148856
+ assert( !ExprHasProperty(pRight, EP_IntValue) );
148577148857
if( *pisComplete && pRight->u.zToken[1] ){
148578148858
/* If the rhs of the LIKE expression is a variable, and the current
148579148859
** value of the variable means there is no need to invoke the LIKE
148580148860
** function, then no OP_Variable will be added to the program.
148581148861
** This causes problems for the sqlite3_bind_parameter_name()
@@ -148645,10 +148925,11 @@
148645148925
};
148646148926
ExprList *pList;
148647148927
Expr *pCol; /* Column reference */
148648148928
int i;
148649148929
148930
+ assert( ExprUseXList(pExpr) );
148650148931
pList = pExpr->x.pList;
148651148932
if( pList==0 || pList->nExpr!=2 ){
148652148933
return 0;
148653148934
}
148654148935
@@ -148658,13 +148939,15 @@
148658148939
**
148659148940
** vtab_column MATCH expression
148660148941
** MATCH(expression,vtab_column)
148661148942
*/
148662148943
pCol = pList->a[1].pExpr;
148944
+ assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148663148945
testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148664148946
if( ExprIsVtab(pCol) ){
148665148947
for(i=0; i<ArraySize(aOp); i++){
148948
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
148666148949
if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
148667148950
*peOp2 = aOp[i].eOp2;
148668148951
*ppRight = pList->a[0].pExpr;
148669148952
*ppLeft = pCol;
148670148953
return 1;
@@ -148681,20 +148964,22 @@
148681148964
** Historically, xFindFunction expected to see lower-case function
148682148965
** names. But for this use case, xFindFunction is expected to deal
148683148966
** with function names in an arbitrary case.
148684148967
*/
148685148968
pCol = pList->a[0].pExpr;
148969
+ assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148686148970
testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148687148971
if( ExprIsVtab(pCol) ){
148688148972
sqlite3_vtab *pVtab;
148689148973
sqlite3_module *pMod;
148690148974
void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
148691148975
void *pNotUsed;
148692148976
pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
148693148977
assert( pVtab!=0 );
148694148978
assert( pVtab->pModule!=0 );
148695
- pMod = (sqlite3_module *)pVtab->pModule;
148979
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
148980
+ pMod = (sqlite3_module *)pVtab->pModule;
148696148981
if( pMod->xFindFunction!=0 ){
148697148982
i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
148698148983
if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
148699148984
*peOp2 = i;
148700148985
*ppRight = pList->a[1].pExpr;
@@ -148705,14 +148990,16 @@
148705148990
}
148706148991
}else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
148707148992
int res = 0;
148708148993
Expr *pLeft = pExpr->pLeft;
148709148994
Expr *pRight = pExpr->pRight;
148995
+ assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
148710148996
testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
148711148997
if( ExprIsVtab(pLeft) ){
148712148998
res++;
148713148999
}
149000
+ assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
148714149001
testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
148715149002
if( pRight && ExprIsVtab(pRight) ){
148716149003
res++;
148717149004
SWAP(Expr*, pLeft, pRight);
148718149005
}
@@ -148961,10 +149248,11 @@
148961149248
int j;
148962149249
Bitmask b = 0;
148963149250
pOrTerm->u.pAndInfo = pAndInfo;
148964149251
pOrTerm->wtFlags |= TERM_ANDINFO;
148965149252
pOrTerm->eOperator = WO_AND;
149253
+ pOrTerm->leftCursor = -1;
148966149254
pAndWC = &pAndInfo->wc;
148967149255
memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
148968149256
sqlite3WhereClauseInit(pAndWC, pWC->pWInfo);
148969149257
sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
148970149258
sqlite3WhereExprAnalyze(pSrc, pAndWC);
@@ -149003,15 +149291,14 @@
149003149291
/*
149004149292
** Record the set of tables that satisfy case 3. The set might be
149005149293
** empty.
149006149294
*/
149007149295
pOrInfo->indexable = indexable;
149296
+ pTerm->eOperator = WO_OR;
149297
+ pTerm->leftCursor = -1;
149008149298
if( indexable ){
149009
- pTerm->eOperator = WO_OR;
149010149299
pWC->hasOr = 1;
149011
- }else{
149012
- pTerm->eOperator = WO_OR;
149013149300
}
149014149301
149015149302
/* For a two-way OR, attempt to implementation case 2.
149016149303
*/
149017149304
if( indexable && pOrWc->nTerm==2 ){
@@ -149080,10 +149367,11 @@
149080149367
testcase( pOrTerm->wtFlags & TERM_COPIED );
149081149368
testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
149082149369
assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
149083149370
continue;
149084149371
}
149372
+ assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149085149373
iColumn = pOrTerm->u.x.leftColumn;
149086149374
iCursor = pOrTerm->leftCursor;
149087149375
pLeft = pOrTerm->pExpr->pLeft;
149088149376
break;
149089149377
}
@@ -149100,10 +149388,11 @@
149100149388
/* We have found a candidate table and column. Check to see if that
149101149389
** table and column is common to every term in the OR clause */
149102149390
okToChngToIN = 1;
149103149391
for(; i>=0 && okToChngToIN; i--, pOrTerm++){
149104149392
assert( pOrTerm->eOperator & WO_EQ );
149393
+ assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149105149394
if( pOrTerm->leftCursor!=iCursor ){
149106149395
pOrTerm->wtFlags &= ~TERM_OR_OK;
149107149396
}else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR
149108149397
&& sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1)
149109149398
)){
@@ -149136,10 +149425,11 @@
149136149425
Expr *pNew; /* The complete IN operator */
149137149426
149138149427
for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
149139149428
if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
149140149429
assert( pOrTerm->eOperator & WO_EQ );
149430
+ assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149141149431
assert( pOrTerm->leftCursor==iCursor );
149142149432
assert( pOrTerm->u.x.leftColumn==iColumn );
149143149433
pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
149144149434
pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
149145149435
pLeft = pOrTerm->pExpr->pLeft;
@@ -149148,11 +149438,11 @@
149148149438
pDup = sqlite3ExprDup(db, pLeft, 0);
149149149439
pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
149150149440
if( pNew ){
149151149441
int idxNew;
149152149442
transferJoinMarkings(pNew, pExpr);
149153
- assert( !ExprHasProperty(pNew, EP_xIsSelect) );
149443
+ assert( ExprUseXList(pNew) );
149154149444
pNew->x.pList = pList;
149155149445
idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
149156149446
testcase( idxNew==0 );
149157149447
exprAnalyze(pSrc, pWC, idxNew);
149158149448
/* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
@@ -149276,10 +149566,11 @@
149276149566
** on the first element of the vector. */
149277149567
assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
149278149568
assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
149279149569
assert( op<=TK_GE );
149280149570
if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
149571
+ assert( ExprUseXList(pExpr) );
149281149572
pExpr = pExpr->x.pList->a[0].pExpr;
149282149573
149283149574
}
149284149575
149285149576
if( pExpr->op==TK_COLUMN ){
@@ -149342,11 +149633,11 @@
149342149633
prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft);
149343149634
op = pExpr->op;
149344149635
if( op==TK_IN ){
149345149636
assert( pExpr->pRight==0 );
149346149637
if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
149347
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
149638
+ if( ExprUseXSelect(pExpr) ){
149348149639
pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect);
149349149640
}else{
149350149641
pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList);
149351149642
}
149352149643
}else if( op==TK_ISNULL ){
@@ -149378,15 +149669,17 @@
149378149669
u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
149379149670
149380149671
if( pTerm->u.x.iField>0 ){
149381149672
assert( op==TK_IN );
149382149673
assert( pLeft->op==TK_VECTOR );
149674
+ assert( ExprUseXList(pLeft) );
149383149675
pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr;
149384149676
}
149385149677
149386149678
if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
149387149679
pTerm->leftCursor = aiCurCol[0];
149680
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149388149681
pTerm->u.x.leftColumn = aiCurCol[1];
149389149682
pTerm->eOperator = operatorMask(op) & opMask;
149390149683
}
149391149684
if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
149392149685
if( pRight
@@ -149420,10 +149713,11 @@
149420149713
pDup = pExpr;
149421149714
pNew = pTerm;
149422149715
}
149423149716
pNew->wtFlags |= exprCommute(pParse, pDup);
149424149717
pNew->leftCursor = aiCurCol[0];
149718
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149425149719
pNew->u.x.leftColumn = aiCurCol[1];
149426149720
testcase( (prereqLeft | extraRight) != prereqLeft );
149427149721
pNew->prereqRight = prereqLeft | extraRight;
149428149722
pNew->prereqAll = prereqAll;
149429149723
pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
@@ -149430,10 +149724,11 @@
149430149724
}else
149431149725
if( op==TK_ISNULL
149432149726
&& !ExprHasProperty(pExpr,EP_FromJoin)
149433149727
&& 0==sqlite3ExprCanBeNull(pLeft)
149434149728
){
149729
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
149435149730
pExpr->op = TK_TRUEFALSE;
149436149731
pExpr->u.zToken = "false";
149437149732
ExprSetProperty(pExpr, EP_IsFalse);
149438149733
pTerm->prereqAll = 0;
149439149734
pTerm->eOperator = 0;
@@ -149455,13 +149750,15 @@
149455149750
** term. That means that if the BETWEEN term is coded, the children are
149456149751
** skipped. Or, if the children are satisfied by an index, the original
149457149752
** BETWEEN term is skipped.
149458149753
*/
149459149754
else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
149460
- ExprList *pList = pExpr->x.pList;
149755
+ ExprList *pList;
149461149756
int i;
149462149757
static const u8 ops[] = {TK_GE, TK_LE};
149758
+ assert( ExprUseXList(pExpr) );
149759
+ pList = pExpr->x.pList;
149463149760
assert( pList!=0 );
149464149761
assert( pList->nExpr==2 );
149465149762
for(i=0; i<2; i++){
149466149763
Expr *pNewExpr;
149467149764
int idxNew;
@@ -149550,12 +149847,16 @@
149550149847
int idxNew1;
149551149848
int idxNew2;
149552149849
const char *zCollSeqName; /* Name of collating sequence */
149553149850
const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
149554149851
149852
+ assert( ExprUseXList(pExpr) );
149555149853
pLeft = pExpr->x.pList->a[1].pExpr;
149556149854
pStr2 = sqlite3ExprDup(db, pStr1, 0);
149855
+ assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) );
149856
+ assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) );
149857
+
149557149858
149558149859
/* Convert the lower bound to upper-case and the upper bound to
149559149860
** lower-case (upper-case is less than lower-case in ASCII) so that
149560149861
** the range constraints also work for BLOBs
149561149862
*/
@@ -149651,10 +149952,11 @@
149651149952
** not use window functions.
149652149953
*/
149653149954
else if( pExpr->op==TK_IN
149654149955
&& pTerm->u.x.iField==0
149655149956
&& pExpr->pLeft->op==TK_VECTOR
149957
+ && ALWAYS( ExprUseXSelect(pExpr) )
149656149958
&& pExpr->x.pSelect->pPrior==0
149657149959
#ifndef SQLITE_OMIT_WINDOWFUNC
149658149960
&& pExpr->x.pSelect->pWin==0
149659149961
#endif
149660149962
&& pWC->op==TK_AND
@@ -149814,18 +150116,19 @@
149814150116
mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
149815150117
if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft);
149816150118
if( p->pRight ){
149817150119
mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight);
149818150120
assert( p->x.pList==0 );
149819
- }else if( ExprHasProperty(p, EP_xIsSelect) ){
150121
+ }else if( ExprUseXSelect(p) ){
149820150122
if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
149821150123
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
149822150124
}else if( p->x.pList ){
149823150125
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
149824150126
}
149825150127
#ifndef SQLITE_OMIT_WINDOWFUNC
149826
- if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && p->y.pWin ){
150128
+ if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && ExprUseYWin(p) ){
150129
+ assert( p->y.pWin!=0 );
149827150130
mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
149828150131
mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
149829150132
mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter);
149830150133
}
149831150134
#endif
@@ -149896,10 +150199,11 @@
149896150199
}
149897150200
pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
149898150201
if( pColRef==0 ) return;
149899150202
pColRef->iTable = pItem->iCursor;
149900150203
pColRef->iColumn = k++;
150204
+ assert( ExprUseYTab(pColRef) );
149901150205
pColRef->y.pTab = pTab;
149902150206
pRhs = sqlite3PExpr(pParse, TK_UPLUS,
149903150207
sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
149904150208
pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
149905150209
if( pItem->fg.jointype & JT_LEFT ){
@@ -150197,12 +150501,14 @@
150197150501
pWC = pScan->pWC;
150198150502
while(1){
150199150503
iColumn = pScan->aiColumn[pScan->iEquiv-1];
150200150504
iCur = pScan->aiCur[pScan->iEquiv-1];
150201150505
assert( pWC!=0 );
150506
+ assert( iCur>=0 );
150202150507
do{
150203150508
for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
150509
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 );
150204150510
if( pTerm->leftCursor==iCur
150205150511
&& pTerm->u.x.leftColumn==iColumn
150206150512
&& (iColumn!=XN_EXPR
150207150513
|| sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
150208150514
pScan->pIdxExpr,iCur)==0)
@@ -150638,10 +150944,11 @@
150638150944
** the RHS of a LEFT JOIN. Such a term can only be used if it is from
150639150945
** the ON clause. */
150640150946
return 0;
150641150947
}
150642150948
if( (pTerm->prereqRight & notReady)!=0 ) return 0;
150949
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150643150950
if( pTerm->u.x.leftColumn<0 ) return 0;
150644150951
aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
150645150952
if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
150646150953
testcase( pTerm->pExpr->op==TK_IS );
150647150954
return 1;
@@ -150710,12 +151017,15 @@
150710151017
&& sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
150711151018
pPartial = sqlite3ExprAnd(pParse, pPartial,
150712151019
sqlite3ExprDup(pParse->db, pExpr, 0));
150713151020
}
150714151021
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
150715
- int iCol = pTerm->u.x.leftColumn;
150716
- Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151022
+ int iCol;
151023
+ Bitmask cMask;
151024
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151025
+ iCol = pTerm->u.x.leftColumn;
151026
+ cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
150717151027
testcase( iCol==BMS );
150718151028
testcase( iCol==BMS-1 );
150719151029
if( !sentWarning ){
150720151030
sqlite3_log(SQLITE_WARNING_AUTOINDEX,
150721151031
"automatic index on %s(%s)", pTable->zName,
@@ -150763,12 +151073,15 @@
150763151073
pIdx->pTable = pTable;
150764151074
n = 0;
150765151075
idxCols = 0;
150766151076
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
150767151077
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
150768
- int iCol = pTerm->u.x.leftColumn;
150769
- Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151078
+ int iCol;
151079
+ Bitmask cMask;
151080
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151081
+ iCol = pTerm->u.x.leftColumn;
151082
+ cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
150770151083
testcase( iCol==BMS-1 );
150771151084
testcase( iCol==BMS );
150772151085
if( (idxCols & cMask)==0 ){
150773151086
Expr *pX = pTerm->pExpr;
150774151087
idxCols |= cMask;
@@ -150891,10 +151204,11 @@
150891151204
testcase( pTerm->eOperator & WO_ISNULL );
150892151205
testcase( pTerm->eOperator & WO_IS );
150893151206
testcase( pTerm->eOperator & WO_ALL );
150894151207
if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
150895151208
if( pTerm->wtFlags & TERM_VNULL ) continue;
151209
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150896151210
assert( pTerm->u.x.leftColumn>=(-1) );
150897151211
nTerm++;
150898151212
}
150899151213
150900151214
/* If the ORDER BY clause contains only columns in the current
@@ -150951,10 +151265,11 @@
150951151265
if( (pSrc->fg.jointype & JT_LEFT)!=0
150952151266
&& !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
150953151267
){
150954151268
continue;
150955151269
}
151270
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150956151271
assert( pTerm->u.x.leftColumn>=(-1) );
150957151272
pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
150958151273
pIdxCons[j].iTermOffset = i;
150959151274
op = pTerm->eOperator & WO_ALL;
150960151275
if( op==WO_IN ) op = WO_EQ;
@@ -151714,10 +152029,11 @@
151714152029
if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
151715152030
if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
151716152031
if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
151717152032
if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
151718152033
if( pTerm->eOperator & WO_SINGLE ){
152034
+ assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151719152035
sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
151720152036
pTerm->leftCursor, pTerm->u.x.leftColumn);
151721152037
}else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
151722152038
sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
151723152039
pTerm->u.pOrInfo->indexable);
@@ -151731,11 +152047,11 @@
151731152047
** shown about each Term */
151732152048
if( sqlite3WhereTrace & 0x10000 ){
151733152049
sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx",
151734152050
pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight);
151735152051
}
151736
- if( pTerm->u.x.iField ){
152052
+ if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){
151737152053
sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField);
151738152054
}
151739152055
if( pTerm->iParent>=0 ){
151740152056
sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
151741152057
}
@@ -151895,11 +152211,12 @@
151895152211
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
151896152212
int i;
151897152213
assert( pWInfo!=0 );
151898152214
for(i=0; i<pWInfo->nLevel; i++){
151899152215
WhereLevel *pLevel = &pWInfo->a[i];
151900
- if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
152216
+ if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){
152217
+ assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 );
151901152218
sqlite3DbFree(db, pLevel->u.in.aInLoop);
151902152219
}
151903152220
}
151904152221
sqlite3WhereClauseClear(&pWInfo->sWC);
151905152222
while( pWInfo->pLoops ){
@@ -152330,13 +152647,16 @@
152330152647
/* Test if comparison i of pTerm is compatible with column (i+nEq)
152331152648
** of the index. If not, exit the loop. */
152332152649
char aff; /* Comparison affinity */
152333152650
char idxaff = 0; /* Indexed columns affinity */
152334152651
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 ){
152652
+ Expr *pLhs, *pRhs;
152653
+
152654
+ assert( ExprUseXList(pTerm->pExpr->pLeft) );
152655
+ pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr;
152656
+ pRhs = pTerm->pExpr->pRight;
152657
+ if( ExprUseXSelect(pRhs) ){
152338152658
pRhs = pRhs->x.pSelect->pEList->a[i].pExpr;
152339152659
}else{
152340152660
pRhs = pRhs->x.pList->a[i].pExpr;
152341152661
}
152342152662
@@ -152493,11 +152813,11 @@
152493152813
|| (pNew->wsFlags & WHERE_SKIPSCAN)!=0
152494152814
);
152495152815
152496152816
if( eOp & WO_IN ){
152497152817
Expr *pExpr = pTerm->pExpr;
152498
- if( ExprHasProperty(pExpr, EP_xIsSelect) ){
152818
+ if( ExprUseXSelect(pExpr) ){
152499152819
/* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
152500152820
int i;
152501152821
nIn = 46; assert( 46==sqlite3LogEst(25) );
152502152822
152503152823
/* The expression may actually be of the form (x, y) IN (SELECT...).
@@ -152634,11 +152954,11 @@
152634152954
#ifdef SQLITE_ENABLE_STAT4
152635152955
tRowcnt nOut = 0;
152636152956
if( nInMul==0
152637152957
&& pProbe->nSample
152638152958
&& ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol)
152639
- && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
152959
+ && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr))
152640152960
&& OptimizationEnabled(db, SQLITE_Stat4)
152641152961
){
152642152962
Expr *pExpr = pTerm->pExpr;
152643152963
if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
152644152964
testcase( eOp & WO_EQ );
@@ -152910,10 +153230,11 @@
152910153230
pTab = pSrc->pTab;
152911153231
pWC = pBuilder->pWC;
152912153232
assert( !IsVirtual(pSrc->pTab) );
152913153233
152914153234
if( pSrc->fg.isIndexedBy ){
153235
+ assert( pSrc->fg.isCte==0 );
152915153236
/* An INDEXED BY clause specifies a particular index to use */
152916153237
pProbe = pSrc->u2.pIBIndex;
152917153238
}else if( !HasRowid(pTab) ){
152918153239
pProbe = pTab->pIndex;
152919153240
}else{
@@ -155380,11 +155701,11 @@
155380155701
if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
155381155702
#endif
155382155703
}else{
155383155704
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
155384155705
}
155385
- if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
155706
+ if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
155386155707
struct InLoop *pIn;
155387155708
int j;
155388155709
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
155389155710
for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
155390155711
assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
@@ -155449,14 +155770,14 @@
155449155770
if( (ws & WHERE_IDX_ONLY)==0 ){
155450155771
assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
155451155772
sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
155452155773
}
155453155774
if( (ws & WHERE_INDEXED)
155454
- || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx)
155775
+ || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx)
155455155776
){
155456155777
if( ws & WHERE_MULTI_OR ){
155457
- Index *pIx = pLevel->u.pCovidx;
155778
+ Index *pIx = pLevel->u.pCoveringIdx;
155458155779
int iDb = sqlite3SchemaToIndex(db, pIx->pSchema);
155459155780
sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb);
155460155781
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
155461155782
}
155462155783
sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -155533,11 +155854,11 @@
155533155854
** reference the index.
155534155855
*/
155535155856
if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){
155536155857
pIdx = pLoop->u.btree.pIndex;
155537155858
}else if( pLoop->wsFlags & WHERE_MULTI_OR ){
155538
- pIdx = pLevel->u.pCovidx;
155859
+ pIdx = pLevel->u.pCoveringIdx;
155539155860
}
155540155861
if( pIdx
155541155862
&& !db->mallocFailed
155542155863
){
155543155864
if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){
@@ -156194,28 +156515,28 @@
156194156515
static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ }
156195156516
156196156517
/* Window functions that use all window interfaces: xStep, xFinal,
156197156518
** xValue, and xInverse */
156198156519
#define WINDOWFUNCALL(name,nArg,extra) { \
156199
- nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156520
+ nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156200156521
name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \
156201156522
name ## InvFunc, name ## Name, {0} \
156202156523
}
156203156524
156204156525
/* Window functions that are implemented using bytecode and thus have
156205156526
** no-op routines for their methods */
156206156527
#define WINDOWFUNCNOOP(name,nArg,extra) { \
156207
- nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156528
+ nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156208156529
noopStepFunc, noopValueFunc, noopValueFunc, \
156209156530
noopStepFunc, name ## Name, {0} \
156210156531
}
156211156532
156212156533
/* Window functions that use all window interfaces: xStep, the
156213156534
** same routine for xFinalize and xValue and which never call
156214156535
** xInverse. */
156215156536
#define WINDOWFUNCX(name,nArg,extra) { \
156216
- nArg, (SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156537
+ nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156217156538
name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \
156218156539
noopStepFunc, name ## Name, {0} \
156219156540
}
156220156541
156221156542
@@ -156554,11 +156875,12 @@
156554156875
return WRC_Continue;
156555156876
}
156556156877
156557156878
static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
156558156879
if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
156559
- sqlite3ErrorMsg(pWalker->pParse,
156880
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
156881
+ sqlite3ErrorMsg(pWalker->pParse,
156560156882
"misuse of aggregate: %s()", pExpr->u.zToken);
156561156883
}
156562156884
return WRC_Continue;
156563156885
}
156564156886
@@ -156642,11 +156964,13 @@
156642156964
/* Append the arguments passed to each window function to the
156643156965
** sub-select expression list. Also allocate two registers for each
156644156966
** window function - one for the accumulator, another for interim
156645156967
** results. */
156646156968
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
156647
- ExprList *pArgs = pWin->pOwner->x.pList;
156969
+ ExprList *pArgs;
156970
+ assert( ExprUseXList(pWin->pOwner) );
156971
+ pArgs = pWin->pOwner->x.pList;
156648156972
if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
156649156973
selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
156650156974
pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
156651156975
pWin->bExprArgs = 1;
156652156976
}else{
@@ -157035,12 +157359,15 @@
157035157359
**
157036157360
** regApp+0: slot to copy min()/max() argument to for MakeRecord
157037157361
** regApp+1: integer value used to ensure keys are unique
157038157362
** regApp+2: output of MakeRecord
157039157363
*/
157040
- ExprList *pList = pWin->pOwner->x.pList;
157041
- KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
157364
+ ExprList *pList;
157365
+ KeyInfo *pKeyInfo;
157366
+ assert( ExprUseXList(pWin->pOwner) );
157367
+ pList = pWin->pOwner->x.pList;
157368
+ pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
157042157369
pWin->csrApp = pParse->nTab++;
157043157370
pWin->regApp = pParse->nMem+1;
157044157371
pParse->nMem += 3;
157045157372
if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
157046157373
assert( pKeyInfo->aSortFlags[0]==0 );
@@ -157124,11 +157451,13 @@
157124157451
/*
157125157452
** Return the number of arguments passed to the window-function associated
157126157453
** with the object passed as the only argument to this function.
157127157454
*/
157128157455
static int windowArgCount(Window *pWin){
157129
- ExprList *pList = pWin->pOwner->x.pList;
157456
+ const ExprList *pList;
157457
+ assert( ExprUseXList(pWin->pOwner) );
157458
+ pList = pWin->pOwner->x.pList;
157130157459
return (pList ? pList->nExpr : 0);
157131157460
}
157132157461
157133157462
typedef struct WindowCodeArg WindowCodeArg;
157134157463
typedef struct WindowCsrAndReg WindowCsrAndReg;
@@ -157309,10 +157638,11 @@
157309157638
sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
157310157639
}else if( pFunc->xSFunc!=noopStepFunc ){
157311157640
int addrIf = 0;
157312157641
if( pWin->pFilter ){
157313157642
int regTmp;
157643
+ assert( ExprUseXList(pWin->pOwner) );
157314157644
assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
157315157645
assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
157316157646
regTmp = sqlite3GetTempReg(pParse);
157317157647
sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
157318157648
addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
@@ -157322,10 +157652,11 @@
157322157652
157323157653
if( pWin->bExprArgs ){
157324157654
int iOp = sqlite3VdbeCurrentAddr(v);
157325157655
int iEnd;
157326157656
157657
+ assert( ExprUseXList(pWin->pOwner) );
157327157658
nArg = pWin->pOwner->x.pList->nExpr;
157328157659
regArg = sqlite3GetTempRange(pParse, nArg);
157329157660
sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
157330157661
157331157662
for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
@@ -157336,10 +157667,11 @@
157336157667
}
157337157668
}
157338157669
if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
157339157670
CollSeq *pColl;
157340157671
assert( nArg>0 );
157672
+ assert( ExprUseXList(pWin->pOwner) );
157341157673
pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
157342157674
sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
157343157675
}
157344157676
sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
157345157677
bInverse, regArg, pWin->regAccum);
@@ -157521,10 +157853,11 @@
157521157853
Parse *pParse = p->pParse;
157522157854
Window *pWin;
157523157855
157524157856
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
157525157857
FuncDef *pFunc = pWin->pFunc;
157858
+ assert( ExprUseXList(pWin->pOwner) );
157526157859
if( pFunc->zName==nth_valueName
157527157860
|| pFunc->zName==first_valueName
157528157861
){
157529157862
int csr = pWin->csrApp;
157530157863
int lbl = sqlite3VdbeMakeLabel(pParse);
@@ -158870,13 +159203,13 @@
158870159203
p->affExpr = 0;
158871159204
p->flags = EP_Leaf;
158872159205
ExprClearVVAProperties(p);
158873159206
p->iAgg = -1;
158874159207
p->pLeft = p->pRight = 0;
158875
- p->x.pList = 0;
158876159208
p->pAggInfo = 0;
158877
- p->y.pTab = 0;
159209
+ memset(&p->x, 0, sizeof(p->x));
159210
+ memset(&p->y, 0, sizeof(p->y));
158878159211
p->op2 = 0;
158879159212
p->iTable = 0;
158880159213
p->iColumn = 0;
158881159214
p->u.zToken = (char*)&p[1];
158882159215
memcpy(p->u.zToken, t.z, t.n);
@@ -166966,11 +167299,13 @@
166966167299
** if this is not the last copy of the function, do not invoke it. Multiple
166967167300
** copies of a single function are created when create_function() is called
166968167301
** with SQLITE_ANY as the encoding.
166969167302
*/
166970167303
static void functionDestroy(sqlite3 *db, FuncDef *p){
166971
- FuncDestructor *pDestructor = p->u.pDestructor;
167304
+ FuncDestructor *pDestructor;
167305
+ assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
167306
+ pDestructor = p->u.pDestructor;
166972167307
if( pDestructor ){
166973167308
pDestructor->nRef--;
166974167309
if( pDestructor->nRef==0 ){
166975167310
pDestructor->xDestroy(pDestructor->pUserData);
166976167311
sqlite3DbFree(db, pDestructor);
@@ -168987,10 +169322,11 @@
168987169322
** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
168988169323
** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
168989169324
** off all other flags.
168990169325
*/
168991169326
flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
169327
+ SQLITE_OPEN_EXCLUSIVE |
168992169328
SQLITE_OPEN_MAIN_DB |
168993169329
SQLITE_OPEN_TEMP_DB |
168994169330
SQLITE_OPEN_TRANSIENT_DB |
168995169331
SQLITE_OPEN_MAIN_JOURNAL |
168996169332
SQLITE_OPEN_TEMP_JOURNAL |
@@ -172095,10 +172431,11 @@
172095172431
SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
172096172432
#ifdef SQLITE_TEST
172097172433
SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*);
172098172434
SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
172099172435
#endif
172436
+SQLITE_PRIVATE void *sqlite3Fts3MallocZero(i64 nByte);
172100172437
172101172438
SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
172102172439
sqlite3_tokenizer_cursor **
172103172440
);
172104172441
@@ -177176,12 +177513,12 @@
177176177513
case FTSQUERY_OR: {
177177177514
Fts3Expr *pLeft = pExpr->pLeft;
177178177515
Fts3Expr *pRight = pExpr->pRight;
177179177516
sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
177180177517
177181
- assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
177182
- assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
177518
+ assert_fts3_nc( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
177519
+ assert_fts3_nc( pRight->bStart || pLeft->iDocid==pRight->iDocid );
177183177520
177184177521
if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
177185177522
fts3EvalNextRow(pCsr, pLeft, pRc);
177186177523
}else if( pLeft->bEof || iCmp>0 ){
177187177524
fts3EvalNextRow(pCsr, pRight, pRc);
@@ -178617,11 +178954,11 @@
178617178954
/*
178618178955
** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
178619178956
** zero the memory before returning a pointer to it. If unsuccessful,
178620178957
** return NULL.
178621178958
*/
178622
-static void *fts3MallocZero(sqlite3_int64 nByte){
178959
+SQLITE_PRIVATE void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){
178623178960
void *pRet = sqlite3_malloc64(nByte);
178624178961
if( pRet ) memset(pRet, 0, nByte);
178625178962
return pRet;
178626178963
}
178627178964
@@ -178698,11 +179035,11 @@
178698179035
sqlite3_int64 nByte; /* total space to allocate */
178699179036
178700179037
rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
178701179038
if( rc==SQLITE_OK ){
178702179039
nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
178703
- pRet = (Fts3Expr *)fts3MallocZero(nByte);
179040
+ pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte);
178704179041
if( !pRet ){
178705179042
rc = SQLITE_NOMEM;
178706179043
}else{
178707179044
pRet->eType = FTSQUERY_PHRASE;
178708179045
pRet->pPhrase = (Fts3Phrase *)&pRet[1];
@@ -178953,11 +179290,11 @@
178953179290
*/
178954179291
cNext = zInput[nKey];
178955179292
if( fts3isspace(cNext)
178956179293
|| cNext=='"' || cNext=='(' || cNext==')' || cNext==0
178957179294
){
178958
- pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr));
179295
+ pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr));
178959179296
if( !pRet ){
178960179297
return SQLITE_NOMEM;
178961179298
}
178962179299
pRet->eType = pKey->eType;
178963179300
pRet->nNear = nNear;
@@ -179132,11 +179469,11 @@
179132179469
179133179470
if( !sqlite3_fts3_enable_parentheses
179134179471
&& p->eType==FTSQUERY_PHRASE && pParse->isNot
179135179472
){
179136179473
/* Create an implicit NOT operator. */
179137
- Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr));
179474
+ Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179138179475
if( !pNot ){
179139179476
sqlite3Fts3ExprFree(p);
179140179477
rc = SQLITE_NOMEM;
179141179478
goto exprparse_out;
179142179479
}
@@ -179166,11 +179503,11 @@
179166179503
179167179504
if( isPhrase && !isRequirePhrase ){
179168179505
/* Insert an implicit AND operator. */
179169179506
Fts3Expr *pAnd;
179170179507
assert( pRet && pPrev );
179171
- pAnd = fts3MallocZero(sizeof(Fts3Expr));
179508
+ pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179172179509
if( !pAnd ){
179173179510
sqlite3Fts3ExprFree(p);
179174179511
rc = SQLITE_NOMEM;
179175179512
goto exprparse_out;
179176179513
}
@@ -183396,12 +183733,22 @@
183396183733
pReader->aNode = 0;
183397183734
if( pElem ){
183398183735
char *aCopy;
183399183736
PendingList *pList = (PendingList *)fts3HashData(pElem);
183400183737
int nCopy = pList->nData+1;
183401
- pReader->zTerm = (char *)fts3HashKey(pElem);
183402
- pReader->nTerm = fts3HashKeysize(pElem);
183738
+
183739
+ int nTerm = fts3HashKeysize(pElem);
183740
+ if( (nTerm+1)>pReader->nTermAlloc ){
183741
+ sqlite3_free(pReader->zTerm);
183742
+ pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2);
183743
+ if( !pReader->zTerm ) return SQLITE_NOMEM;
183744
+ pReader->nTermAlloc = (nTerm+1)*2;
183745
+ }
183746
+ memcpy(pReader->zTerm, fts3HashKey(pElem), nTerm);
183747
+ pReader->zTerm[nTerm] = '\0';
183748
+ pReader->nTerm = nTerm;
183749
+
183403183750
aCopy = (char*)sqlite3_malloc(nCopy);
183404183751
if( !aCopy ) return SQLITE_NOMEM;
183405183752
memcpy(aCopy, pList->aData, nCopy);
183406183753
pReader->nNode = pReader->nDoclist = nCopy;
183407183754
pReader->aNode = pReader->aDoclist = aCopy;
@@ -183650,13 +183997,11 @@
183650183997
** Free all allocations associated with the iterator passed as the
183651183998
** second argument.
183652183999
*/
183653184000
SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){
183654184001
if( pReader ){
183655
- if( !fts3SegReaderIsPending(pReader) ){
183656
- sqlite3_free(pReader->zTerm);
183657
- }
184002
+ sqlite3_free(pReader->zTerm);
183658184003
if( !fts3SegReaderIsRootOnly(pReader) ){
183659184004
sqlite3_free(pReader->aNode);
183660184005
}
183661184006
sqlite3_blob_close(pReader->pBlob);
183662184007
}
@@ -188003,13 +188348,12 @@
188003188348
MatchinfoBuffer *pRet;
188004188349
sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
188005188350
+ sizeof(MatchinfoBuffer);
188006188351
sqlite3_int64 nStr = strlen(zMatchinfo);
188007188352
188008
- pRet = sqlite3_malloc64(nByte + nStr+1);
188353
+ pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
188009188354
if( pRet ){
188010
- memset(pRet, 0, nByte);
188011188355
pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
188012188356
pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
188013188357
+ sizeof(u32)*((int)nElem+1);
188014188358
pRet->nElem = (int)nElem;
188015188359
pRet->zMatchinfo = ((char*)pRet) + nByte;
@@ -188409,15 +188753,14 @@
188409188753
188410188754
/* Now that it is known how many phrases there are, allocate and zero
188411188755
** the required space using malloc().
188412188756
*/
188413188757
nByte = sizeof(SnippetPhrase) * nList;
188414
- sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte);
188758
+ sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte);
188415188759
if( !sIter.aPhrase ){
188416188760
return SQLITE_NOMEM;
188417188761
}
188418
- memset(sIter.aPhrase, 0, nByte);
188419188762
188420188763
/* Initialize the contents of the SnippetIter object. Then iterate through
188421188764
** the set of phrases in the expression to populate the aPhrase[] array.
188422188765
*/
188423188766
sIter.pCsr = pCsr;
@@ -189016,13 +189359,12 @@
189016189359
int rc = SQLITE_OK;
189017189360
189018189361
/* Allocate and populate the array of LcsIterator objects. The array
189019189362
** contains one element for each matchable phrase in the query.
189020189363
**/
189021
- aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase);
189364
+ aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase);
189022189365
if( !aIter ) return SQLITE_NOMEM;
189023
- memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase);
189024189366
(void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
189025189367
189026189368
for(i=0; i<pInfo->nPhrase; i++){
189027189369
LcsIterator *pIter = &aIter[i];
189028189370
nToken -= pIter->pExpr->pPhrase->nToken;
@@ -189479,11 +189821,11 @@
189479189821
/* Count the number of terms in the query */
189480189822
rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
189481189823
if( rc!=SQLITE_OK ) goto offsets_out;
189482189824
189483189825
/* Allocate the array of TermOffset iterators. */
189484
- sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken);
189826
+ sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken);
189485189827
if( 0==sCtx.aTerm ){
189486189828
rc = SQLITE_NOMEM;
189487189829
goto offsets_out;
189488189830
}
189489189831
sCtx.iDocid = pCsr->iPrevId;
@@ -190517,11 +190859,25 @@
190517190859
# define NEVER(X) ((X)?(assert(0),1):0)
190518190860
# else
190519190861
# define ALWAYS(X) (X)
190520190862
# define NEVER(X) (X)
190521190863
# endif
190864
+# define testcase(X)
190522190865
#endif
190866
+#if defined(NDEBUG)
190867
+# define VVA(X)
190868
+#else
190869
+# define VVA(X) X
190870
+#endif
190871
+
190872
+/*
190873
+** Some of the testcase() macros in this file are problematic for gcov
190874
+** in that they generate false-miss errors randomly. This is a gcov problem,
190875
+** not a problem in this case. But to work around it, we disable the
190876
+** problematic test cases for production builds.
190877
+*/
190878
+#define json_testcase(X)
190523190879
190524190880
/* Objects */
190525190881
typedef struct JsonString JsonString;
190526190882
typedef struct JsonNode JsonNode;
190527190883
typedef struct JsonParse JsonParse;
@@ -190575,17 +190931,18 @@
190575190931
/* A single node of parsed JSON
190576190932
*/
190577190933
struct JsonNode {
190578190934
u8 eType; /* One of the JSON_ type values */
190579190935
u8 jnFlags; /* JNODE flags */
190936
+ u8 eU; /* Which union element to use */
190580190937
u32 n; /* Bytes of content, or number of sub-nodes */
190581190938
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 */
190939
+ const char *zJContent; /* 1: Content for INT, REAL, and STRING */
190940
+ u32 iAppend; /* 2: More terms for ARRAY and OBJECT */
190941
+ u32 iKey; /* 3: Key for ARRAY objects in json_tree() */
190942
+ u32 iReplace; /* 4: Replacement content for JNODE_REPLACE */
190943
+ JsonNode *pPatch; /* 5: Node chain of patch for JNODE_PATCH */
190587190944
} u;
190588190945
};
190589190946
190590190947
/* A completely parsed JSON string
190591190948
*/
@@ -190862,13 +191219,15 @@
190862191219
sqlite3_value **aReplace /* Replacement values */
190863191220
){
190864191221
assert( pNode!=0 );
190865191222
if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
190866191223
if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){
191224
+ assert( pNode->eU==4 );
190867191225
jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
190868191226
return;
190869191227
}
191228
+ assert( pNode->eU==5 );
190870191229
pNode = pNode->u.pPatch;
190871191230
}
190872191231
switch( pNode->eType ){
190873191232
default: {
190874191233
assert( pNode->eType==JSON_NULL );
@@ -190883,17 +191242,19 @@
190883191242
jsonAppendRaw(pOut, "false", 5);
190884191243
break;
190885191244
}
190886191245
case JSON_STRING: {
190887191246
if( pNode->jnFlags & JNODE_RAW ){
191247
+ assert( pNode->eU==1 );
190888191248
jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
190889191249
break;
190890191250
}
190891191251
/* no break */ deliberate_fall_through
190892191252
}
190893191253
case JSON_REAL:
190894191254
case JSON_INT: {
191255
+ assert( pNode->eU==1 );
190895191256
jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
190896191257
break;
190897191258
}
190898191259
case JSON_ARRAY: {
190899191260
u32 j = 1;
@@ -190905,10 +191266,11 @@
190905191266
jsonRenderNode(&pNode[j], pOut, aReplace);
190906191267
}
190907191268
j += jsonNodeSize(&pNode[j]);
190908191269
}
190909191270
if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191271
+ assert( pNode->eU==2 );
190910191272
pNode = &pNode[pNode->u.iAppend];
190911191273
j = 1;
190912191274
}
190913191275
jsonAppendChar(pOut, ']');
190914191276
break;
@@ -190925,10 +191287,11 @@
190925191287
jsonRenderNode(&pNode[j+1], pOut, aReplace);
190926191288
}
190927191289
j += 1 + jsonNodeSize(&pNode[j+1]);
190928191290
}
190929191291
if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191292
+ assert( pNode->eU==2 );
190930191293
pNode = &pNode[pNode->u.iAppend];
190931191294
j = 1;
190932191295
}
190933191296
jsonAppendChar(pOut, '}');
190934191297
break;
@@ -191004,11 +191367,13 @@
191004191367
sqlite3_result_int(pCtx, 0);
191005191368
break;
191006191369
}
191007191370
case JSON_INT: {
191008191371
sqlite3_int64 i = 0;
191009
- const char *z = pNode->u.zJContent;
191372
+ const char *z;
191373
+ assert( pNode->eU==1 );
191374
+ z = pNode->u.zJContent;
191010191375
if( z[0]=='-' ){ z++; }
191011191376
while( z[0]>='0' && z[0]<='9' ){
191012191377
unsigned v = *(z++) - '0';
191013191378
if( i>=LARGEST_INT64/10 ){
191014191379
if( i>LARGEST_INT64/10 ) goto int_as_real;
@@ -191032,13 +191397,16 @@
191032191397
int_as_real: ; /* no break */ deliberate_fall_through
191033191398
}
191034191399
case JSON_REAL: {
191035191400
double r;
191036191401
#ifdef SQLITE_AMALGAMATION
191037
- const char *z = pNode->u.zJContent;
191402
+ const char *z;
191403
+ assert( pNode->eU==1 );
191404
+ z = pNode->u.zJContent;
191038191405
sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
191039191406
#else
191407
+ assert( pNode->eU==1 );
191040191408
r = strtod(pNode->u.zJContent, 0);
191041191409
#endif
191042191410
sqlite3_result_double(pCtx, r);
191043191411
break;
191044191412
}
@@ -191045,26 +191413,30 @@
191045191413
case JSON_STRING: {
191046191414
#if 0 /* Never happens because JNODE_RAW is only set by json_set(),
191047191415
** json_insert() and json_replace() and those routines do not
191048191416
** call jsonReturn() */
191049191417
if( pNode->jnFlags & JNODE_RAW ){
191418
+ assert( pNode->eU==1 );
191050191419
sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
191051191420
SQLITE_TRANSIENT);
191052191421
}else
191053191422
#endif
191054191423
assert( (pNode->jnFlags & JNODE_RAW)==0 );
191055191424
if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
191056191425
/* JSON formatted without any backslash-escapes */
191426
+ assert( pNode->eU==1 );
191057191427
sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
191058191428
SQLITE_TRANSIENT);
191059191429
}else{
191060191430
/* Translate JSON formatted string into raw text */
191061191431
u32 i;
191062191432
u32 n = pNode->n;
191063
- const char *z = pNode->u.zJContent;
191433
+ const char *z;
191064191434
char *zOut;
191065191435
u32 j;
191436
+ assert( pNode->eU==1 );
191437
+ z = pNode->u.zJContent;
191066191438
zOut = sqlite3_malloc( n+1 );
191067191439
if( zOut==0 ){
191068191440
sqlite3_result_error_nomem(pCtx);
191069191441
break;
191070191442
}
@@ -191187,10 +191559,11 @@
191187191559
return jsonParseAddNodeExpand(pParse, eType, n, zContent);
191188191560
}
191189191561
p = &pParse->aNode[pParse->nNode];
191190191562
p->eType = (u8)eType;
191191191563
p->jnFlags = 0;
191564
+ VVA( p->eU = zContent ? 1 : 0 );
191192191565
p->n = n;
191193191566
p->u.zJContent = zContent;
191194191567
return pParse->nNode++;
191195191568
}
191196191569
@@ -191254,10 +191627,11 @@
191254191627
return j+1;
191255191628
}else if( c=='[' ){
191256191629
/* Parse array */
191257191630
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
191258191631
if( iThis<0 ) return -1;
191632
+ memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
191259191633
for(j=i+1;;j++){
191260191634
while( safe_isspace(z[j]) ){ j++; }
191261191635
if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
191262191636
x = jsonParseValue(pParse, j);
191263191637
pParse->iDepth--;
@@ -191518,10 +191892,11 @@
191518191892
/*
191519191893
** Compare the OBJECT label at pNode against zKey,nKey. Return true on
191520191894
** a match.
191521191895
*/
191522191896
static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
191897
+ assert( pNode->eU==1 );
191523191898
if( pNode->jnFlags & JNODE_RAW ){
191524191899
if( pNode->n!=nKey ) return 0;
191525191900
return strncmp(pNode->u.zJContent, zKey, nKey)==0;
191526191901
}else{
191527191902
if( pNode->n!=nKey+2 ) return 0;
@@ -191583,10 +191958,11 @@
191583191958
}
191584191959
j++;
191585191960
j += jsonNodeSize(&pRoot[j]);
191586191961
}
191587191962
if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
191963
+ assert( pRoot->eU==2 );
191588191964
iRoot += pRoot->u.iAppend;
191589191965
pRoot = &pParse->aNode[iRoot];
191590191966
j = 1;
191591191967
}
191592191968
if( pApnd ){
@@ -191597,12 +191973,14 @@
191597191973
zPath += i;
191598191974
pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191599191975
if( pParse->oom ) return 0;
191600191976
if( pNode ){
191601191977
pRoot = &pParse->aNode[iRoot];
191978
+ assert( pRoot->eU==0 );
191602191979
pRoot->u.iAppend = iStart - iRoot;
191603191980
pRoot->jnFlags |= JNODE_APPEND;
191981
+ VVA( pRoot->eU = 2 );
191604191982
pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
191605191983
}
191606191984
return pNode;
191607191985
}
191608191986
}else if( zPath[0]=='[' ){
@@ -191621,10 +191999,11 @@
191621191999
while( j<=pBase->n ){
191622192000
if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
191623192001
j += jsonNodeSize(&pBase[j]);
191624192002
}
191625192003
if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
192004
+ assert( pBase->eU==2 );
191626192005
iBase += pBase->u.iAppend;
191627192006
pBase = &pParse->aNode[iBase];
191628192007
j = 1;
191629192008
}
191630192009
j = 2;
@@ -191654,10 +192033,11 @@
191654192033
while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
191655192034
if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
191656192035
j += jsonNodeSize(&pRoot[j]);
191657192036
}
191658192037
if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
192038
+ assert( pRoot->eU==2 );
191659192039
iRoot += pRoot->u.iAppend;
191660192040
pRoot = &pParse->aNode[iRoot];
191661192041
j = 1;
191662192042
}
191663192043
if( j<=pRoot->n ){
@@ -191669,12 +192049,14 @@
191669192049
iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0);
191670192050
pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191671192051
if( pParse->oom ) return 0;
191672192052
if( pNode ){
191673192053
pRoot = &pParse->aNode[iRoot];
192054
+ assert( pRoot->eU==0 );
191674192055
pRoot->u.iAppend = iStart - iRoot;
191675192056
pRoot->jnFlags |= JNODE_APPEND;
192057
+ VVA( pRoot->eU = 2 );
191676192058
}
191677192059
return pNode;
191678192060
}
191679192061
}else{
191680192062
*pzErr = zPath;
@@ -191824,13 +192206,17 @@
191824192206
}else{
191825192207
zType = jsonType[x.aNode[i].eType];
191826192208
}
191827192209
jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d",
191828192210
i, zType, x.aNode[i].n, x.aUp[i]);
192211
+ assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 );
191829192212
if( x.aNode[i].u.zJContent!=0 ){
192213
+ assert( x.aNode[i].eU==1 );
191830192214
jsonAppendRaw(&s, " ", 1);
191831192215
jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n);
192216
+ }else{
192217
+ assert( x.aNode[i].eU==0 );
191832192218
}
191833192219
jsonAppendRaw(&s, "\n", 1);
191834192220
}
191835192221
jsonParseReset(&x);
191836192222
jsonResult(&s);
@@ -192009,10 +192395,11 @@
192009192395
for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){
192010192396
u32 nKey;
192011192397
const char *zKey;
192012192398
assert( pPatch[i].eType==JSON_STRING );
192013192399
assert( pPatch[i].jnFlags & JNODE_LABEL );
192400
+ assert( pPatch[i].eU==1 );
192014192401
nKey = pPatch[i].n;
192015192402
zKey = pPatch[i].u.zJContent;
192016192403
assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
192017192404
for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
192018192405
assert( pTarget[j].eType==JSON_STRING );
@@ -192025,10 +192412,13 @@
192025192412
}else{
192026192413
JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
192027192414
if( pNew==0 ) return 0;
192028192415
pTarget = &pParse->aNode[iTarget];
192029192416
if( pNew!=&pTarget[j+1] ){
192417
+ assert( pTarget[j+1].eU==0 || pTarget[j+1].eU==1 );
192418
+ testcase( pTarget[j+1].eU==1 );
192419
+ VVA( pTarget[j+1].eU = 5 );
192030192420
pTarget[j+1].u.pPatch = pNew;
192031192421
pTarget[j+1].jnFlags |= JNODE_PATCH;
192032192422
}
192033192423
}
192034192424
break;
@@ -192040,13 +192430,18 @@
192040192430
jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
192041192431
iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
192042192432
if( pParse->oom ) return 0;
192043192433
jsonRemoveAllNulls(pPatch);
192044192434
pTarget = &pParse->aNode[iTarget];
192435
+ assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 );
192436
+ testcase( pParse->aNode[iRoot].eU==2 );
192045192437
pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
192438
+ VVA( pParse->aNode[iRoot].eU = 2 );
192046192439
pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
192047192440
iRoot = iStart;
192441
+ assert( pParse->aNode[iPatch].eU==0 );
192442
+ VVA( pParse->aNode[iPatch].eU = 5 );
192048192443
pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
192049192444
pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
192050192445
}
192051192446
}
192052192447
return pTarget;
@@ -192184,15 +192579,19 @@
192184192579
for(i=1; i<(u32)argc; i+=2){
192185192580
zPath = (const char*)sqlite3_value_text(argv[i]);
192186192581
pNode = jsonLookup(&x, zPath, 0, ctx);
192187192582
if( x.nErr ) goto replace_err;
192188192583
if( pNode ){
192584
+ assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 );
192585
+ json_testcase( pNode->eU!=0 && pNode->eU!=1 );
192189192586
pNode->jnFlags |= (u8)JNODE_REPLACE;
192587
+ VVA( pNode->eU = 4 );
192190192588
pNode->u.iReplace = i + 1;
192191192589
}
192192192590
}
192193192591
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192592
+ assert( x.aNode[0].eU==4 );
192194192593
sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192195192594
}else{
192196192595
jsonReturnJson(x.aNode, ctx, argv);
192197192596
}
192198192597
replace_err:
@@ -192238,15 +192637,19 @@
192238192637
sqlite3_result_error_nomem(ctx);
192239192638
goto jsonSetDone;
192240192639
}else if( x.nErr ){
192241192640
goto jsonSetDone;
192242192641
}else if( pNode && (bApnd || bIsSet) ){
192642
+ json_testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
192643
+ assert( pNode->eU!=3 || pNode->eU!=5 );
192644
+ VVA( pNode->eU = 4 );
192243192645
pNode->jnFlags |= (u8)JNODE_REPLACE;
192244192646
pNode->u.iReplace = i + 1;
192245192647
}
192246192648
}
192247192649
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192650
+ assert( x.aNode[0].eU==4 );
192248192651
sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192249192652
}else{
192250192653
jsonReturnJson(x.aNode, ctx, argv);
192251192654
}
192252192655
jsonSetDone:
@@ -192593,10 +192996,13 @@
192593192996
if( p->i<p->iEnd ){
192594192997
u32 iUp = p->sParse.aUp[p->i];
192595192998
JsonNode *pUp = &p->sParse.aNode[iUp];
192596192999
p->eType = pUp->eType;
192597193000
if( pUp->eType==JSON_ARRAY ){
193001
+ assert( pUp->eU==0 || pUp->eU==3 );
193002
+ json_testcase( pUp->eU==3 );
193003
+ VVA( pUp->eU = 3 );
192598193004
if( iUp==p->i-1 ){
192599193005
pUp->u.iKey = 0;
192600193006
}else{
192601193007
pUp->u.iKey++;
192602193008
}
@@ -192639,16 +193045,19 @@
192639193045
iUp = p->sParse.aUp[i];
192640193046
jsonEachComputePath(p, pStr, iUp);
192641193047
pNode = &p->sParse.aNode[i];
192642193048
pUp = &p->sParse.aNode[iUp];
192643193049
if( pUp->eType==JSON_ARRAY ){
193050
+ assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) );
193051
+ testcase( pUp->eU==0 );
192644193052
jsonPrintf(30, pStr, "[%d]", pUp->u.iKey);
192645193053
}else{
192646193054
assert( pUp->eType==JSON_OBJECT );
192647193055
if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
192648193056
assert( pNode->eType==JSON_STRING );
192649193057
assert( pNode->jnFlags & JNODE_LABEL );
193058
+ assert( pNode->eU==1 );
192650193059
jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
192651193060
}
192652193061
}
192653193062
192654193063
/* Return the value of a column */
@@ -192666,10 +193075,11 @@
192666193075
jsonReturn(pThis, ctx, 0);
192667193076
}else if( p->eType==JSON_ARRAY ){
192668193077
u32 iKey;
192669193078
if( p->bRecursive ){
192670193079
if( p->iRowid==0 ) break;
193080
+ assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 );
192671193081
iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey;
192672193082
}else{
192673193083
iKey = p->iRowid;
192674193084
}
192675193085
sqlite3_result_int64(ctx, (sqlite3_int64)iKey);
@@ -192715,10 +193125,11 @@
192715193125
jsonAppendChar(&x, '$');
192716193126
}
192717193127
if( p->eType==JSON_ARRAY ){
192718193128
jsonPrintf(30, &x, "[%d]", p->iRowid);
192719193129
}else if( p->eType==JSON_OBJECT ){
193130
+ assert( pThis->eU==1 );
192720193131
jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
192721193132
}
192722193133
}
192723193134
jsonResult(&x);
192724193135
break;
@@ -192782,10 +193193,11 @@
192782193193
int iCol;
192783193194
int iMask;
192784193195
if( pConstraint->iColumn < JEACH_JSON ) continue;
192785193196
iCol = pConstraint->iColumn - JEACH_JSON;
192786193197
assert( iCol==0 || iCol==1 );
193198
+ testcase( iCol==0 );
192787193199
iMask = 1 << iCol;
192788193200
if( pConstraint->usable==0 ){
192789193201
unusableMask |= iMask;
192790193202
}else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
192791193203
aIdx[iCol] = i;
@@ -192879,10 +193291,12 @@
192879193291
pNode = p->sParse.aNode;
192880193292
}
192881193293
p->iBegin = p->i = (int)(pNode - p->sParse.aNode);
192882193294
p->eType = pNode->eType;
192883193295
if( p->eType>=JSON_ARRAY ){
193296
+ assert( pNode->eU==0 );
193297
+ VVA( pNode->eU = 3 );
192884193298
pNode->u.iKey = 0;
192885193299
p->iEnd = p->i + pNode->n + 1;
192886193300
if( p->bRecursive ){
192887193301
p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType;
192888193302
if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){
@@ -193493,11 +193907,11 @@
193493193907
193494193908
/* The testcase() macro should already be defined in the amalgamation. If
193495193909
** it is not, make it a no-op.
193496193910
*/
193497193911
#ifndef SQLITE_AMALGAMATION
193498
-# ifdef SQLITE_COVERAGE_TEST
193912
+# if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
193499193913
unsigned int sqlite3RtreeTestcase = 0;
193500193914
# define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; }
193501193915
# else
193502193916
# define testcase(X)
193503193917
# endif
@@ -214008,11 +214422,11 @@
214008214422
214009214423
/*
214010214424
** A version of memcmp() that does not cause asan errors if one of the pointer
214011214425
** parameters is NULL and the number of bytes to compare is zero.
214012214426
*/
214013
-#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
214427
+#define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
214014214428
214015214429
/* Mark a function parameter as unused, to suppress nuisance compiler
214016214430
** warnings. */
214017214431
#ifndef UNUSED_PARAM
214018214432
# define UNUSED_PARAM(X) (void)(X)
@@ -217034,11 +217448,10 @@
217034217448
int *pRc,
217035217449
Fts5Buffer *pBuf,
217036217450
u32 nData,
217037217451
const u8 *pData
217038217452
){
217039
- assert_nc( *pRc || nData>=0 );
217040217453
if( nData ){
217041217454
if( fts5BufferGrow(pRc, pBuf, nData) ) return;
217042217455
memcpy(&pBuf->p[pBuf->n], pData, nData);
217043217456
pBuf->n += nData;
217044217457
}
@@ -217146,11 +217559,10 @@
217146217559
return 1;
217147217560
}else{
217148217561
i64 iOff = *piOff;
217149217562
u32 iVal;
217150217563
fts5FastGetVarint32(a, i, iVal);
217151
- assert( iVal>=0 );
217152217564
if( iVal<=1 ){
217153217565
if( iVal==0 ){
217154217566
*pi = i;
217155217567
return 0;
217156217568
}
@@ -221761,11 +222173,11 @@
221761222173
if( iCol>=0 ){
221762222174
if( pHash->eDetail==FTS5_DETAIL_NONE ){
221763222175
p->bContent = 1;
221764222176
}else{
221765222177
/* Append a new column value, if necessary */
221766
- assert( iCol>=p->iCol );
222178
+ assert_nc( iCol>=p->iCol );
221767222179
if( iCol!=p->iCol ){
221768222180
if( pHash->eDetail==FTS5_DETAIL_FULL ){
221769222181
pPtr[p->nData++] = 0x01;
221770222182
p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
221771222183
p->iCol = (i16)iCol;
@@ -222566,12 +222978,15 @@
222566222978
** +ve if pRight is smaller than pLeft. In other words:
222567222979
**
222568222980
** res = *pLeft - *pRight
222569222981
*/
222570222982
static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
222571
- int nCmp = MIN(pLeft->n, pRight->n);
222572
- int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
222983
+ int nCmp, res;
222984
+ nCmp = MIN(pLeft->n, pRight->n);
222985
+ assert( nCmp<=0 || pLeft->p!=0 );
222986
+ assert( nCmp<=0 || pRight->p!=0 );
222987
+ res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
222573222988
return (res==0 ? (pLeft->n - pRight->n) : res);
222574222989
}
222575222990
222576222991
static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
222577222992
int ret;
@@ -224244,25 +224659,24 @@
224244224659
Fts5Index *p, /* Leave any error code here */
224245224660
int bGe, /* True for a >= search */
224246224661
Fts5SegIter *pIter, /* Iterator to seek */
224247224662
const u8 *pTerm, int nTerm /* Term to search for */
224248224663
){
224249
- int iOff;
224664
+ u32 iOff;
224250224665
const u8 *a = pIter->pLeaf->p;
224251
- int szLeaf = pIter->pLeaf->szLeaf;
224252
- int n = pIter->pLeaf->nn;
224666
+ u32 n = (u32)pIter->pLeaf->nn;
224253224667
224254224668
u32 nMatch = 0;
224255224669
u32 nKeep = 0;
224256224670
u32 nNew = 0;
224257224671
u32 iTermOff;
224258
- int iPgidx; /* Current offset in pgidx */
224672
+ u32 iPgidx; /* Current offset in pgidx */
224259224673
int bEndOfPage = 0;
224260224674
224261224675
assert( p->rc==SQLITE_OK );
224262224676
224263
- iPgidx = szLeaf;
224677
+ iPgidx = (u32)pIter->pLeaf->szLeaf;
224264224678
iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
224265224679
iOff = iTermOff;
224266224680
if( iOff>n ){
224267224681
p->rc = FTS5_CORRUPT;
224268224682
return;
@@ -224324,19 +224738,19 @@
224324224738
do {
224325224739
fts5SegIterNextPage(p, pIter);
224326224740
if( pIter->pLeaf==0 ) return;
224327224741
a = pIter->pLeaf->p;
224328224742
if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
224329
- iPgidx = pIter->pLeaf->szLeaf;
224743
+ iPgidx = (u32)pIter->pLeaf->szLeaf;
224330224744
iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
224331
- if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
224745
+ if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
224332224746
p->rc = FTS5_CORRUPT;
224333224747
return;
224334224748
}else{
224335224749
nKeep = 0;
224336224750
iTermOff = iOff;
224337
- n = pIter->pLeaf->nn;
224751
+ n = (u32)pIter->pLeaf->nn;
224338224752
iOff += fts5GetVarint32(&a[iOff], nNew);
224339224753
break;
224340224754
}
224341224755
}
224342224756
}while( 1 );
@@ -231573,11 +231987,11 @@
231573231987
int nArg, /* Number of args */
231574231988
sqlite3_value **apUnused /* Function arguments */
231575231989
){
231576231990
assert( nArg==0 );
231577231991
UNUSED_PARAM2(nArg, apUnused);
231578
- sqlite3_result_text(pCtx, "fts5: 2021-10-05 18:33:38 a7835bead85b1b18a8affd9835240b0baf9c7af887196bbdcc3f5d58055042fc", -1, SQLITE_TRANSIENT);
231992
+ sqlite3_result_text(pCtx, "fts5: 2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a", -1, SQLITE_TRANSIENT);
231579231993
}
231580231994
231581231995
/*
231582231996
** Return true if zName is the extension on one of the shadow tables used
231583231997
** by this module.
231584231998
--- 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.
@@ -13160,15 +13174,16 @@
13160 ** can be used to make sure boundary values are tested. For
13161 ** bitmask tests, testcase() can be used to make sure each bit
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 +13243,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 +13425,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 +16423,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 +16662,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 +16723,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 +16802,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 +17569,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 +17612,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 +17681,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 +17720,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 +17827,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 +17870,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 +18471,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 +20129,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
@@ -21432,10 +21452,22 @@
21432 ** Hash table for global functions - functions common to all
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.
@@ -24817,11 +24849,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 +25096,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 +25118,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 +30583,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 +30603,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 +30624,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 +30697,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 +30709,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 +30725,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 +30765,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 +30800,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 +30827,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 +30840,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 +30853,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 +31939,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 +32185,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
@@ -40209,10 +40252,15 @@
40209 if( randomnessPid!=osGetpid(0) ){
40210 randomnessPid = osGetpid(0);
40211 sqlite3_randomness(0,0);
40212 }
40213 memset(p, 0, sizeof(unixFile));
 
 
 
 
 
40214
40215 if( eType==SQLITE_OPEN_MAIN_DB ){
40216 UnixUnusedFd *pUnused;
40217 pUnused = findReusableFd(zName, flags);
40218 if( pUnused ){
@@ -40270,12 +40318,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;
@@ -48623,11 +48669,11 @@
48623 /*
48624 ** Try to enlarge the memory allocation to hold at least sz bytes
48625 */
48626 static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
48627 unsigned char *pNew;
48628 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
48629 return SQLITE_FULL;
48630 }
48631 if( newSz>p->szMax ){
48632 return SQLITE_FULL;
48633 }
@@ -48822,11 +48868,11 @@
48822 int iAmt,
48823 void **pp
48824 ){
48825 MemStore *p = ((MemFile*)pFile)->pStore;
48826 memdbEnter(p);
48827 if( iOfst+iAmt>p->sz ){
48828 *pp = 0;
48829 }else{
48830 p->nMmap++;
48831 *pp = (void*)(p->aData + iOfst);
48832 }
@@ -48856,13 +48902,11 @@
48856 int *pOutFlags
48857 ){
48858 MemFile *pFile = (MemFile*)pFd;
48859 MemStore *p = 0;
48860 int szName;
48861 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48862 return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
48863 }
48864 memset(pFile, 0, sizeof(*pFile));
48865 szName = sqlite3Strlen30(zName);
48866 if( szName>1 && zName[0]=='/' ){
48867 int i;
48868 #ifndef SQLITE_MUTEX_OMIT
@@ -48918,12 +48962,13 @@
48918 memset(p, 0, sizeof(*p));
48919 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
48920 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48921 }
48922 pFile->pStore = p;
48923 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
48924 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
 
48925 pFd->pMethods = &memdb_io_methods;
48926 memdbLeave(p);
48927 return SQLITE_OK;
48928 }
48929
@@ -53114,10 +53159,11 @@
53114 u8 walSyncFlags; /* See description above */
53115 u8 tempFile; /* zFilename is a temporary or immutable file */
53116 u8 noLock; /* Do not lock (except in WAL mode) */
53117 u8 readOnly; /* True for a read-only database */
53118 u8 memDb; /* True to inhibit all file I/O */
 
53119
53120 /**************************************************************************
53121 ** The following block contains those class members that change during
53122 ** routine operation. Class members not in this block are either fixed
53123 ** when the pager is first created or else only change when there is a
@@ -57356,11 +57402,11 @@
57356 if( zFilename && zFilename[0] ){
57357 int fout = 0; /* VFS flags returned by xOpen() */
57358 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
57359 assert( !memDb );
57360 #ifndef SQLITE_OMIT_DESERIALIZE
57361 memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
57362 #endif
57363 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
57364
57365 /* If the file was successfully opened for read/write access,
57366 ** choose a default page size in case we have to create the
@@ -59293,11 +59339,11 @@
59293
59294 /*
59295 ** Return true if this is an in-memory or temp-file backed pager.
59296 */
59297 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
59298 return pPager->tempFile;
59299 }
59300
59301 /*
59302 ** Check that there are at least nSavepoint savepoints open. If there are
59303 ** currently less than nSavepoints open, then open one or more savepoints
@@ -59613,11 +59659,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 +64683,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 +70272,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 +70461,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 +70522,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 +71308,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 +71795,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);
@@ -72484,11 +72520,11 @@
72484 int k; /* Current slot in pCArray->apEnd[] */
72485 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
72486
72487 assert( i<iEnd );
72488 j = get2byte(&aData[hdr+5]);
72489 if( NEVER(j>(u32)usableSize) ){ j = 0; }
72490 memcpy(&pTmp[j], &aData[j], usableSize - j);
72491
72492 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
72493 pSrcEnd = pCArray->apEnd[k];
72494
@@ -74360,11 +74396,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 +74985,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 +75017,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 +75095,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 +78473,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 +78580,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 +78655,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 +78673,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 +80546,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 +80893,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 +84599,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 +84612,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 +90590,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 +95146,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";
@@ -96682,11 +96736,11 @@
96682 void *p = 0;
96683 int chunksize = 4*1024;
96684 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
96685 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
96686 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
96687 sqlite3OsUnfetch(pFd, 0, p);
96688 }
96689 }
96690 #else
96691 # define vdbeSorterExtendFile(x,y,z)
96692 #endif
@@ -99101,11 +99155,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 +99427,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 +99531,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 +99669,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 +99701,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 +99775,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 +99788,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 +99863,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 +99936,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 +100022,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 +100091,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 +100140,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 +100173,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 +100209,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 +100222,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 +100255,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 +100419,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 +100468,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 +100525,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 +100574,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 +101441,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 +101461,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 +101529,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 +101562,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 +101680,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 +101820,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 +101850,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 +101889,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 +101914,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 +101980,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 +102160,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 +102199,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 +102383,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 +102466,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 +102592,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 +102623,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 +102842,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 +103469,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 +103486,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 +103691,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 +103841,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 +103919,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 +104090,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 +104246,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 +104294,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 +104344,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 +104408,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 +104442,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 +104548,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 +104585,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 +104680,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 +104697,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 +104831,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 +105225,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 +105424,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 +105448,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 +105490,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 +105568,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 +105736,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 +105856,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 +105941,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 +106036,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 +106381,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 +106856,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 +106968,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 +107151,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 +107342,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 +107484,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 +107548,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 +108070,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 +108113,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 +108208,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 +108239,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 +108508,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 +108572,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 +108711,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 +109242,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 +109314,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 +109435,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 +109756,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 +110931,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 +112225,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 +112910,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 +113005,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 +113431,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 +113452,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 +113511,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 +114584,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 +114958,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 +115333,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 +116298,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 +116364,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 +116387,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 +116789,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 +116885,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 +117674,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 +118655,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 +118677,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 +119069,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 +121654,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 +121773,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 +121802,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 +122184,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 +122707,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 +122918,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 +123087,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 +123276,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 +123329,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 +123617,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 +125876,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 +126557,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 +126599,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 +129592,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 +130246,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 +130294,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 +130315,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 +130352,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 +130535,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 +130575,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 +130635,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 +130666,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 +130870,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 +131465,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 +133257,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 +133286,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 +133807,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 +133834,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 +134683,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 +134743,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 +134876,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 +134973,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 +136558,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 +137769,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 +137863,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 +138121,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 +138760,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 +138785,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 +138821,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 +139070,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 +139887,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 +139942,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 +140265,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 +144291,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 +144402,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 +144420,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 +144512,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 +144630,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 +144967,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 +145200,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 +145509,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 +146437,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 +146568,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 +146590,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 +147133,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 +147198,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 +147216,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 +147453,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 +148347,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 +148494,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 +148749,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 +148765,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 +148795,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 +148821,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 +148851,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 +148925,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 +148939,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 +148964,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 +148990,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 +149248,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 +149291,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 +149367,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 +149388,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 +149425,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 +149438,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 +149566,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 +149633,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 +149669,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 +149713,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 +149724,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 +149750,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 +149847,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 +149952,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 +150116,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 +150199,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 +150501,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 +150944,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 +151017,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 +151073,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 +151204,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 +151265,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 +152029,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 +152047,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 +152211,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 +152647,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 +152813,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 +152954,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 +153230,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 +155701,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 +155770,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 +155854,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 +156515,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 +156875,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 +156964,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 +157359,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 +157451,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 +157638,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 +157652,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 +157667,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 +157853,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 +159203,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 +167299,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 +169322,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 +172431,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 +177513,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 +178954,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 +179035,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 +179290,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 +179469,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 +179503,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 +183733,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 +183997,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 +188348,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 +188753,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 +189359,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 +189821,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 +190859,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 +190931,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 +191219,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 +191242,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 +191266,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 +191287,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 +191367,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 +191397,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 +191413,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 +191559,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 +191627,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 +191892,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 +191958,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 +191973,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 +191999,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 +192033,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 +192049,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 +192206,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 +192395,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 +192412,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 +192430,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 +192579,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 +192637,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 +192996,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 +193045,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 +193075,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 +193125,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 +193193,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 +193291,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 +193907,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 +214422,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 +217448,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 +217559,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 +222173,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 +222978,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 +224659,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 +224738,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 +231987,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-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
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.
@@ -13160,15 +13174,16 @@
13174 ** can be used to make sure boundary values are tested. For
13175 ** bitmask tests, testcase() can be used to make sure each bit
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 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
13181 # ifndef SQLITE_AMALGAMATION
13182 extern unsigned int sqlite3CoverageCounter;
13183 # endif
13184 # define testcase(X) if( X ){ sqlite3CoverageCounter += (unsigned)__LINE__; }
13185 #else
13186 # define testcase(X)
13187 #endif
13188
13189 /*
@@ -13228,30 +13243,10 @@
13243 #else
13244 # define ALWAYS(X) (X)
13245 # define NEVER(X) (X)
13246 #endif
13247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13248 /*
13249 ** Some conditionals are optimizations only. In other words, if the
13250 ** conditionals are replaced with a constant 1 (true) or 0 (false) then
13251 ** the correct answer is still obtained, though perhaps not as quickly.
13252 **
@@ -13430,11 +13425,11 @@
13425 /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */
13426
13427 /*
13428 ** Number of entries in a hash table
13429 */
13430 #define sqliteHashCount(H) ((H)->count)
13431
13432 #endif /* SQLITE_HASH_H */
13433
13434 /************** End of hash.h ************************************************/
13435 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -16428,14 +16423,14 @@
16423 int nVdbeExec; /* Number of nested calls to VdbeExec() */
16424 int nVDestroy; /* Number of active OP_VDestroy operations */
16425 int nExtension; /* Number of loaded extensions */
16426 void **aExtension; /* Array of shared library handles */
16427 union {
16428 void (*xLegacy)(void*,const char*); /* mTrace==SQLITE_TRACE_LEGACY */
16429 int (*xV2)(u32,void*,void*,void*); /* All other mTrace values */
16430 } trace;
16431 void *pTraceArg; /* Argument to the trace function */
16432 #ifndef SQLITE_OMIT_DEPRECATED
16433 void (*xProfile)(void*,const char*,u64); /* Profiling function */
16434 void *pProfileArg; /* Argument to profile function */
16435 #endif
16436 void *pCommitArg; /* Argument to xCommitCallback() */
@@ -16667,11 +16662,11 @@
16662 void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */
16663 const char *zName; /* SQL name of the function. */
16664 union {
16665 FuncDef *pHash; /* Next with a different name but the same hash */
16666 FuncDestructor *pDestructor; /* Reference counted destructor function */
16667 } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */
16668 };
16669
16670 /*
16671 ** This structure encapsulates a user-function destructor callback (as
16672 ** configured using create_function_v2()) and a reference counter. When
@@ -16728,10 +16723,11 @@
16723 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
16724 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
16725 #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
16726 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
16727 #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */
16728 #define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */
16729 #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */
16730
16731 /* Identifier numbers for each in-line function */
16732 #define INLINEFUNC_coalesce 0
16733 #define INLINEFUNC_implies_nonnull_row 1
@@ -16806,48 +16802,55 @@
16802 ** available as the function user-data (sqlite3_user_data()). The
16803 ** FuncDef.flags variable is set to the value passed as the flags
16804 ** parameter.
16805 */
16806 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
16807 {nArg, SQLITE_FUNC_BUILTIN|\
16808 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16809 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16810 #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16811 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16812 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16813 #define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16814 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
16815 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16816 #define MFUNCTION(zName, nArg, xPtr, xFunc) \
16817 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
16818 xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
16819 #define INLINE_FUNC(zName, nArg, iArg, mFlags) \
16820 {nArg, SQLITE_FUNC_BUILTIN|\
16821 SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16822 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16823 #define TEST_FUNC(zName, nArg, iArg, mFlags) \
16824 {nArg, SQLITE_FUNC_BUILTIN|\
16825 SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \
16826 SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
16827 SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
16828 #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \
16829 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \
16830 0, 0, xFunc, 0, 0, 0, #zName, {0} }
16831 #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \
16832 {nArg, SQLITE_FUNC_BUILTIN|\
16833 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_BUILTIN|\
16837 SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
16838 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
16839 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
16840 {nArg, SQLITE_FUNC_BUILTIN|\
16841 SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
16842 pArg, 0, xFunc, 0, 0, 0, #zName, }
16843 #define LIKEFUNC(zName, nArg, arg, flags) \
16844 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
16845 (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
16846 #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
16847 {nArg, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
16848 SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
16849 #define INTERNAL_FUNCTION(zName, nArg, xFunc) \
16850 {nArg, SQLITE_FUNC_BUILTIN|\
16851 SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
16852 0, 0, xFunc, 0, 0, 0, #zName, {0} }
16853
16854
16855 /*
16856 ** All current savepoints are stored in a linked list starting at
@@ -17566,14 +17569,14 @@
17569 ** code representing the ">=" operator. This same integer code is reused
17570 ** to represent the greater-than-or-equal-to operator in the expression
17571 ** tree.
17572 **
17573 ** If the expression is an SQL literal (TK_INTEGER, TK_FLOAT, TK_BLOB,
17574 ** or TK_STRING), then Expr.u.zToken contains the text of the SQL literal. If
17575 ** the expression is a variable (TK_VARIABLE), then Expr.u.zToken contains the
17576 ** variable name. Finally, if the expression is an SQL function (TK_FUNCTION),
17577 ** then Expr.u.zToken contains the name of the function.
17578 **
17579 ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a
17580 ** binary operator. Either or both may be NULL.
17581 **
17582 ** Expr.x.pList is a list of arguments if the expression is an SQL function,
@@ -17609,11 +17612,11 @@
17612 **
17613 ** Expr objects can use a lot of memory space in database schema. To
17614 ** help reduce memory requirements, sometimes an Expr object will be
17615 ** truncated. And to reduce the number of memory allocations, sometimes
17616 ** two or more Expr objects will be stored in a single memory allocation,
17617 ** together with Expr.u.zToken strings.
17618 **
17619 ** If the EP_Reduced and EP_TokenOnly flags are set when
17620 ** an Expr object is truncated. When EP_Reduced is set, then all
17621 ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees
17622 ** are contained within the same memory allocation. Note, however, that
@@ -17678,12 +17681,11 @@
17681 int regReturn; /* Register used to hold return address */
17682 } sub;
17683 } y;
17684 };
17685
17686 /* The following are the meanings of bits in the Expr.flags field.
 
17687 ** Value restrictions:
17688 **
17689 ** EP_Agg == NC_HasAgg == SF_HasAgg
17690 ** EP_Win == NC_HasWin
17691 */
@@ -17718,27 +17720,35 @@
17720 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
17721 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
17722 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
17723 /* 0x80000000 // Available */
17724
17725 /* The EP_Propagate mask is a set of properties that automatically propagate
 
17726 ** upwards into parent nodes.
17727 */
17728 #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
17729
17730 /* 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 /* Macros used to ensure that the correct members of unions are accessed
17741 ** in Expr.
17742 */
17743 #define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
17744 #define ExprUseUValue(E) (((E)->flags&EP_IntValue)!=0)
17745 #define ExprUseXList(E) (((E)->flags&EP_xIsSelect)==0)
17746 #define ExprUseXSelect(E) (((E)->flags&EP_xIsSelect)!=0)
17747 #define ExprUseYTab(E) (((E)->flags&(EP_WinFunc|EP_Subrtn))==0)
17748 #define ExprUseYWin(E) (((E)->flags&EP_WinFunc)!=0)
17749 #define ExprUseYSub(E) (((E)->flags&EP_Subrtn)!=0)
17750
17751 /* Flags for use with Expr.vvaFlags
17752 */
17753 #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */
17754 #define EP_Immutable 0x02 /* Do not change this Expr node */
@@ -17817,15 +17827,16 @@
17827 unsigned done :1; /* A flag to indicate when processing is finished */
17828 unsigned reusable :1; /* Constant expression is reusable */
17829 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
17830 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
17831 union {
17832 struct { /* Used by any ExprList other than Parse.pConsExpr */
17833 u16 iOrderByCol; /* For ORDER BY, column number in result set */
17834 u16 iAlias; /* Index into Parse.aAlias[] for zName */
17835 } x;
17836 int iConstExprReg; /* Register in which Expr value is cached. Used only
17837 ** by Parse.pConstExpr */
17838 } u;
17839 } a[1]; /* One slot for each expression in the list */
17840 };
17841
17842 /*
@@ -17859,10 +17870,17 @@
17870 };
17871
17872 /*
17873 ** The SrcItem object represents a single term in the FROM clause of a query.
17874 ** The SrcList object is mostly an array of SrcItems.
17875 **
17876 ** Union member validity:
17877 **
17878 ** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc
17879 ** u1.pFuncArg fg.isTabFunc && !fg.isIndexedBy
17880 ** u2.pIBIndex fg.isIndexedBy && !fg.isCte
17881 ** u2.pCteUse fg.isCte && !fg.isIndexedBy
17882 */
17883 struct SrcItem {
17884 Schema *pSchema; /* Schema to which this item is fixed */
17885 char *zDatabase; /* Name of database holding this table */
17886 char *zName; /* Name of the table */
@@ -18453,10 +18471,12 @@
18471 #ifndef SQLITE_OMIT_ALTERTABLE
18472 RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
18473 #endif
18474 };
18475
18476 /* Allowed values for Parse.eParseMode
18477 */
18478 #define PARSE_MODE_NORMAL 0
18479 #define PARSE_MODE_DECLARE_VTAB 1
18480 #define PARSE_MODE_RENAME 2
18481 #define PARSE_MODE_UNMAP 3
18482
@@ -20109,12 +20129,12 @@
20129 ** All of this is no-op for a production build. It only comes into
20130 ** play when the SQLITE_MEMDEBUG compile-time option is used.
20131 */
20132 #ifdef SQLITE_MEMDEBUG
20133 SQLITE_PRIVATE void sqlite3MemdebugSetType(void*,u8);
20134 SQLITE_PRIVATE int sqlite3MemdebugHasType(const void*,u8);
20135 SQLITE_PRIVATE int sqlite3MemdebugNoType(const void*,u8);
20136 #else
20137 # define sqlite3MemdebugSetType(X,Y) /* no-op */
20138 # define sqlite3MemdebugHasType(X,Y) 1
20139 # define sqlite3MemdebugNoType(X,Y) 1
20140 #endif
@@ -21432,10 +21452,22 @@
21452 ** Hash table for global functions - functions common to all
21453 ** database connections. After initialization, this table is
21454 ** read-only.
21455 */
21456 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
21457
21458 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
21459 /*
21460 ** Counter used for coverage testing. Does not come into play for
21461 ** release builds.
21462 **
21463 ** Access to this global variable is not mutex protected. This might
21464 ** result in TSAN warnings. But as the variable does not exist in
21465 ** release builds, that should not be a concern.
21466 */
21467 SQLITE_PRIVATE unsigned int sqlite3CoverageCounter;
21468 #endif /* SQLITE_COVERAGE_TEST || SQLITE_DEBUG */
21469
21470 #ifdef VDBE_PROFILE
21471 /*
21472 ** The following performance counter can be used in place of
21473 ** sqlite3Hwtime() for profiling. This is a no-op on standard builds.
@@ -24817,11 +24849,11 @@
24849 ** Given an allocation, find the MemBlockHdr for that allocation.
24850 **
24851 ** This routine checks the guards at either end of the allocation and
24852 ** if they are incorrect it asserts.
24853 */
24854 static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){
24855 struct MemBlockHdr *p;
24856 int *pInt;
24857 u8 *pU8;
24858 int nReserve;
24859
@@ -25064,11 +25096,11 @@
25096 ** This routine is designed for use within an assert() statement, to
25097 ** verify the type of an allocation. For example:
25098 **
25099 ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
25100 */
25101 SQLITE_PRIVATE int sqlite3MemdebugHasType(const void *p, u8 eType){
25102 int rc = 1;
25103 if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
25104 struct MemBlockHdr *pHdr;
25105 pHdr = sqlite3MemsysGetHeader(p);
25106 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -25086,11 +25118,11 @@
25118 ** This routine is designed for use within an assert() statement, to
25119 ** verify the type of an allocation. For example:
25120 **
25121 ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
25122 */
25123 SQLITE_PRIVATE int sqlite3MemdebugNoType(const void *p, u8 eType){
25124 int rc = 1;
25125 if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){
25126 struct MemBlockHdr *pHdr;
25127 pHdr = sqlite3MemsysGetHeader(p);
25128 assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
@@ -30551,10 +30583,11 @@
30583 zOp2[0] = 0;
30584 }
30585 sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s",
30586 pExpr->iColumn, zFlgs, zOp2);
30587 }else{
30588 assert( ExprUseYTab(pExpr) );
30589 sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s",
30590 pExpr->iTable, pExpr->iColumn,
30591 pExpr->y.pTab, zFlgs);
30592 }
30593 if( ExprHasProperty(pExpr, EP_FixedCol) ){
@@ -30570,15 +30603,17 @@
30603 }
30604 break;
30605 }
30606 #ifndef SQLITE_OMIT_FLOATING_POINT
30607 case TK_FLOAT: {
30608 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30609 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
30610 break;
30611 }
30612 #endif
30613 case TK_STRING: {
30614 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30615 sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken);
30616 break;
30617 }
30618 case TK_NULL: {
30619 sqlite3TreeViewLine(pView,"NULL");
@@ -30589,30 +30624,34 @@
30624 sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs);
30625 break;
30626 }
30627 #ifndef SQLITE_OMIT_BLOB_LITERAL
30628 case TK_BLOB: {
30629 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30630 sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken);
30631 break;
30632 }
30633 #endif
30634 case TK_VARIABLE: {
30635 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30636 sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)",
30637 pExpr->u.zToken, pExpr->iColumn);
30638 break;
30639 }
30640 case TK_REGISTER: {
30641 sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable);
30642 break;
30643 }
30644 case TK_ID: {
30645 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30646 sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken);
30647 break;
30648 }
30649 #ifndef SQLITE_OMIT_CAST
30650 case TK_CAST: {
30651 /* Expressions of the form: CAST(pLeft AS token) */
30652 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30653 sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken);
30654 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30655 break;
30656 }
30657 #endif /* SQLITE_OMIT_CAST */
@@ -30658,10 +30697,11 @@
30697 zUniOp = azOp[x];
30698 break;
30699 }
30700
30701 case TK_SPAN: {
30702 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30703 sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken);
30704 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30705 break;
30706 }
30707
@@ -30669,10 +30709,11 @@
30709 /* COLLATE operators without the EP_Collate flag are intended to
30710 ** emulate collation associated with a table column. These show
30711 ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE
30712 ** operators that appear in the original SQL always have the
30713 ** EP_Collate bit set and appear in treeview output as just "COLLATE" */
30714 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30715 sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s",
30716 !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "",
30717 pExpr->u.zToken, zFlgs);
30718 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30719 break;
@@ -30684,17 +30725,19 @@
30725 Window *pWin;
30726 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
30727 pFarg = 0;
30728 pWin = 0;
30729 }else{
30730 assert( ExprUseXList(pExpr) );
30731 pFarg = pExpr->x.pList;
30732 #ifndef SQLITE_OMIT_WINDOWFUNC
30733 pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0;
30734 #else
30735 pWin = 0;
30736 #endif
30737 }
30738 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30739 if( pExpr->op==TK_AGG_FUNCTION ){
30740 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
30741 pExpr->op2, pExpr->u.zToken, zFlgs,
30742 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
30743 pExpr->iAgg, pExpr->pAggInfo);
@@ -30722,23 +30765,25 @@
30765 #endif
30766 break;
30767 }
30768 #ifndef SQLITE_OMIT_SUBQUERY
30769 case TK_EXISTS: {
30770 assert( ExprUseXSelect(pExpr) );
30771 sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags);
30772 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30773 break;
30774 }
30775 case TK_SELECT: {
30776 assert( ExprUseXSelect(pExpr) );
30777 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
30778 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30779 break;
30780 }
30781 case TK_IN: {
30782 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
30783 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30784 if( ExprUseXSelect(pExpr) ){
30785 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
30786 }else{
30787 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
30788 }
30789 break;
@@ -30755,13 +30800,16 @@
30800 ** X is stored in pExpr->pLeft.
30801 ** Y is stored in pExpr->pList->a[0].pExpr.
30802 ** Z is stored in pExpr->pList->a[1].pExpr.
30803 */
30804 case TK_BETWEEN: {
30805 const Expr *pX, *pY, *pZ;
30806 pX = pExpr->pLeft;
30807 assert( ExprUseXList(pExpr) );
30808 assert( pExpr->x.pList->nExpr==2 );
30809 pY = pExpr->x.pList->a[0].pExpr;
30810 pZ = pExpr->x.pList->a[1].pExpr;
30811 sqlite3TreeViewLine(pView, "BETWEEN");
30812 sqlite3TreeViewExpr(pView, pX, 1);
30813 sqlite3TreeViewExpr(pView, pY, 1);
30814 sqlite3TreeViewExpr(pView, pZ, 0);
30815 break;
@@ -30779,10 +30827,11 @@
30827 break;
30828 }
30829 case TK_CASE: {
30830 sqlite3TreeViewLine(pView, "CASE");
30831 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
30832 assert( ExprUseXList(pExpr) );
30833 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
30834 break;
30835 }
30836 #ifndef SQLITE_OMIT_TRIGGER
30837 case TK_RAISE: {
@@ -30791,10 +30840,11 @@
30840 case OE_Rollback: zType = "rollback"; break;
30841 case OE_Abort: zType = "abort"; break;
30842 case OE_Fail: zType = "fail"; break;
30843 case OE_Ignore: zType = "ignore"; break;
30844 }
30845 assert( !ExprHasProperty(pExpr, EP_IntValue) );
30846 sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken);
30847 break;
30848 }
30849 #endif
30850 case TK_MATCH: {
@@ -30803,18 +30853,20 @@
30853 sqlite3TreeViewExpr(pView, pExpr->pRight, 0);
30854 break;
30855 }
30856 case TK_VECTOR: {
30857 char *z = sqlite3_mprintf("VECTOR%s",zFlgs);
30858 assert( ExprUseXList(pExpr) );
30859 sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z);
30860 sqlite3_free(z);
30861 break;
30862 }
30863 case TK_SELECT_COLUMN: {
30864 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s",
30865 pExpr->iColumn, pExpr->iTable-1,
30866 pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : "");
30867 assert( ExprUseXSelect(pExpr->pLeft) );
30868 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
30869 break;
30870 }
30871 case TK_IF_NULL_ROW: {
30872 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
@@ -31887,20 +31939,10 @@
31939 /* #include <stdarg.h> */
31940 #ifndef SQLITE_OMIT_FLOATING_POINT
31941 #include <math.h>
31942 #endif
31943
 
 
 
 
 
 
 
 
 
 
31944 /*
31945 ** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
31946 ** or to bypass normal error detection during testing in order to let
31947 ** execute proceed futher downstream.
31948 **
@@ -32143,10 +32185,11 @@
32185 }
32186 }
32187 z[j] = 0;
32188 }
32189 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){
32190 assert( !ExprHasProperty(p, EP_IntValue) );
32191 assert( sqlite3Isquote(p->u.zToken[0]) );
32192 p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted;
32193 sqlite3Dequote(p->u.zToken);
32194 }
32195
@@ -40209,10 +40252,15 @@
40252 if( randomnessPid!=osGetpid(0) ){
40253 randomnessPid = osGetpid(0);
40254 sqlite3_randomness(0,0);
40255 }
40256 memset(p, 0, sizeof(unixFile));
40257
40258 #ifdef SQLITE_ASSERT_NO_FILES
40259 /* Applications that never read or write a persistent disk files */
40260 assert( zName==0 );
40261 #endif
40262
40263 if( eType==SQLITE_OPEN_MAIN_DB ){
40264 UnixUnusedFd *pUnused;
40265 pUnused = findReusableFd(zName, flags);
40266 if( pUnused ){
@@ -40270,12 +40318,10 @@
40318 if( fd<0 ){
40319 if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){
40320 /* If unable to create a journal because the directory is not
40321 ** writable, change the error code to indicate that. */
40322 rc = SQLITE_READONLY_DIRECTORY;
 
 
40323 }else if( errno!=EISDIR && isReadWrite ){
40324 /* Failed to open the file for read/write access. Try read-only. */
40325 flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
40326 openFlags &= ~(O_RDWR|O_CREAT);
40327 flags |= SQLITE_OPEN_READONLY;
@@ -48623,11 +48669,11 @@
48669 /*
48670 ** Try to enlarge the memory allocation to hold at least sz bytes
48671 */
48672 static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
48673 unsigned char *pNew;
48674 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || NEVER(p->nMmap>0) ){
48675 return SQLITE_FULL;
48676 }
48677 if( newSz>p->szMax ){
48678 return SQLITE_FULL;
48679 }
@@ -48822,11 +48868,11 @@
48868 int iAmt,
48869 void **pp
48870 ){
48871 MemStore *p = ((MemFile*)pFile)->pStore;
48872 memdbEnter(p);
48873 if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){
48874 *pp = 0;
48875 }else{
48876 p->nMmap++;
48877 *pp = (void*)(p->aData + iOfst);
48878 }
@@ -48856,13 +48902,11 @@
48902 int *pOutFlags
48903 ){
48904 MemFile *pFile = (MemFile*)pFd;
48905 MemStore *p = 0;
48906 int szName;
48907
 
 
48908 memset(pFile, 0, sizeof(*pFile));
48909 szName = sqlite3Strlen30(zName);
48910 if( szName>1 && zName[0]=='/' ){
48911 int i;
48912 #ifndef SQLITE_MUTEX_OMIT
@@ -48918,12 +48962,13 @@
48962 memset(p, 0, sizeof(*p));
48963 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
48964 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48965 }
48966 pFile->pStore = p;
48967 if( pOutFlags!=0 ){
48968 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
48969 }
48970 pFd->pMethods = &memdb_io_methods;
48971 memdbLeave(p);
48972 return SQLITE_OK;
48973 }
48974
@@ -53114,10 +53159,11 @@
53159 u8 walSyncFlags; /* See description above */
53160 u8 tempFile; /* zFilename is a temporary or immutable file */
53161 u8 noLock; /* Do not lock (except in WAL mode) */
53162 u8 readOnly; /* True for a read-only database */
53163 u8 memDb; /* True to inhibit all file I/O */
53164 u8 memVfs; /* VFS-implemented memory database */
53165
53166 /**************************************************************************
53167 ** The following block contains those class members that change during
53168 ** routine operation. Class members not in this block are either fixed
53169 ** when the pager is first created or else only change when there is a
@@ -57356,11 +57402,11 @@
57402 if( zFilename && zFilename[0] ){
57403 int fout = 0; /* VFS flags returned by xOpen() */
57404 rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
57405 assert( !memDb );
57406 #ifndef SQLITE_OMIT_DESERIALIZE
57407 pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
57408 #endif
57409 readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
57410
57411 /* If the file was successfully opened for read/write access,
57412 ** choose a default page size in case we have to create the
@@ -59293,11 +59339,11 @@
59339
59340 /*
59341 ** Return true if this is an in-memory or temp-file backed pager.
59342 */
59343 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
59344 return pPager->tempFile || pPager->memVfs;
59345 }
59346
59347 /*
59348 ** Check that there are at least nSavepoint savepoints open. If there are
59349 ** currently less than nSavepoints open, then open one or more savepoints
@@ -59613,11 +59659,11 @@
59659 */
59660 pPg->flags &= ~PGHDR_NEED_SYNC;
59661 pPgOld = sqlite3PagerLookup(pPager, pgno);
59662 assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
59663 if( pPgOld ){
59664 if( NEVER(pPgOld->nRef>1) ){
59665 sqlite3PagerUnrefNotNull(pPgOld);
59666 return SQLITE_CORRUPT_BKPT;
59667 }
59668 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
59669 if( pPager->tempFile ){
@@ -64637,11 +64683,10 @@
64683 ** Access to all fields of this structure is controlled by the mutex
64684 ** stored in MemPage.pBt->mutex.
64685 */
64686 struct MemPage {
64687 u8 isInit; /* True if previously initialized. MUST BE FIRST! */
 
64688 u8 intKey; /* True if table b-trees. False for index b-trees */
64689 u8 intKeyLeaf; /* True if the leaf of an intKey table */
64690 Pgno pgno; /* Page number for this page */
64691 /* Only the first 8 bytes (above) are zeroed by pager.c when a new page
64692 ** is allocated. All fields that follow must be initialized before use */
@@ -70227,11 +70272,13 @@
70272 #endif
70273
70274 assert( pPage );
70275 assert( eOp==0 || eOp==1 );
70276 assert( pCur->eState==CURSOR_VALID );
70277 if( pCur->ix>=pPage->nCell ){
70278 return SQLITE_CORRUPT_PAGE(pPage);
70279 }
70280 assert( cursorHoldsMutex(pCur) );
70281
70282 getCellInfo(pCur);
70283 aPayload = pCur->info.pPayload;
70284 assert( offset+amt <= pCur->info.nPayload );
@@ -70414,11 +70461,10 @@
70461 */
70462 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
70463 assert( cursorHoldsMutex(pCur) );
70464 assert( pCur->eState==CURSOR_VALID );
70465 assert( pCur->iPage>=0 && pCur->pPage );
 
70466 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
70467 }
70468
70469 /*
70470 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -70476,11 +70522,11 @@
70522 int amt;
70523 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
70524 assert( pCur->eState==CURSOR_VALID );
70525 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
70526 assert( cursorOwnsBtShared(pCur) );
70527 assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
70528 assert( pCur->info.nSize>0 );
70529 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
70530 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
70531 amt = pCur->info.nLocal;
70532 if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){
@@ -71262,20 +71308,10 @@
71308 ** module cov1/btree78.test testcase 220 (2018-06-08) for an
71309 ** example. */
71310 return SQLITE_CORRUPT_BKPT;
71311 }
71312
 
 
 
 
 
 
 
 
 
 
71313 if( idx>=pPage->nCell ){
71314 if( !pPage->leaf ){
71315 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
71316 if( rc ) return rc;
71317 return moveToLeftmost(pCur);
@@ -71759,11 +71795,11 @@
71795
71796 assert( sqlite3_mutex_held(pBt->mutex) );
71797 assert( CORRUPT_DB || iPage>1 );
71798 assert( !pMemPage || pMemPage->pgno==iPage );
71799
71800 if( NEVER(iPage<2) || iPage>pBt->nPage ){
71801 return SQLITE_CORRUPT_BKPT;
71802 }
71803 if( pMemPage ){
71804 pPage = pMemPage;
71805 sqlite3PagerRef(pPage->pDbPage);
@@ -72484,11 +72520,11 @@
72520 int k; /* Current slot in pCArray->apEnd[] */
72521 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
72522
72523 assert( i<iEnd );
72524 j = get2byte(&aData[hdr+5]);
72525 if( j>(u32)usableSize ){ j = 0; }
72526 memcpy(&pTmp[j], &aData[j], usableSize - j);
72527
72528 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
72529 pSrcEnd = pCArray->apEnd[k];
72530
@@ -74360,11 +74396,14 @@
74396 assert( szNew==pPage->xCellSize(pPage, newCell) );
74397 assert( szNew <= MX_CELL_SIZE(pBt) );
74398 idx = pCur->ix;
74399 if( loc==0 ){
74400 CellInfo info;
74401 assert( idx>=0 );
74402 if( idx>=pPage->nCell ){
74403 return SQLITE_CORRUPT_BKPT;
74404 }
74405 rc = sqlite3PagerWrite(pPage->pDbPage);
74406 if( rc ){
74407 goto end_insert;
74408 }
74409 oldCell = findCell(pPage, idx);
@@ -74946,15 +74985,16 @@
74985 if( pgno>btreePagecount(pBt) ){
74986 return SQLITE_CORRUPT_BKPT;
74987 }
74988 rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
74989 if( rc ) return rc;
74990 if( (pBt->openFlags & BTREE_SINGLE)==0
74991 && sqlite3PagerPageRefcount(pPage->pDbPage)!=1
74992 ){
74993 rc = SQLITE_CORRUPT_BKPT;
74994 goto cleardatabasepage_out;
74995 }
 
74996 hdr = pPage->hdrOffset;
74997 for(i=0; i<pPage->nCell; i++){
74998 pCell = findCell(pPage, i);
74999 if( !pPage->leaf ){
75000 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
@@ -74977,11 +75017,10 @@
75017 }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){
75018 zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF);
75019 }
75020
75021 cleardatabasepage_out:
 
75022 releasePage(pPage);
75023 return rc;
75024 }
75025
75026 /*
@@ -75056,14 +75095,14 @@
75095 assert( iTable>=2 );
75096 if( iTable>btreePagecount(pBt) ){
75097 return SQLITE_CORRUPT_BKPT;
75098 }
75099
 
 
75100 rc = sqlite3BtreeClearTable(p, iTable, 0);
75101 if( rc ) return rc;
75102 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
75103 if( NEVER(rc) ){
75104 releasePage(pPage);
75105 return rc;
75106 }
75107
75108 *piMoved = 0;
@@ -78434,12 +78473,14 @@
78473 ExprList *pList = 0; /* Function arguments */
78474 int i; /* Iterator variable */
78475
78476 assert( pCtx!=0 );
78477 assert( (p->flags & EP_TokenOnly)==0 );
78478 assert( ExprUseXList(p) );
78479 pList = p->x.pList;
78480 if( pList ) nVal = pList->nExpr;
78481 assert( !ExprHasProperty(p, EP_IntValue) );
78482 pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0);
78483 assert( pFunc );
78484 if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0
78485 || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
78486 ){
@@ -78539,11 +78580,13 @@
78580 ** check ensures that an EP_TokenOnly expression is never passed down
78581 ** into valueFromFunction(). */
78582 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
78583
78584 if( op==TK_CAST ){
78585 u8 aff;
78586 assert( !ExprHasProperty(pExpr, EP_IntValue) );
78587 aff = sqlite3AffinityType(pExpr->u.zToken,0);
78588 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
78589 testcase( rc!=SQLITE_OK );
78590 if( *ppVal ){
78591 sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8);
78592 sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8);
@@ -78612,10 +78655,11 @@
78655 sqlite3VdbeMemSetNull(pVal);
78656 }
78657 #ifndef SQLITE_OMIT_BLOB_LITERAL
78658 else if( op==TK_BLOB ){
78659 int nVal;
78660 assert( !ExprHasProperty(pExpr, EP_IntValue) );
78661 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
78662 assert( pExpr->u.zToken[1]=='\'' );
78663 pVal = valueNew(db, pCtx);
78664 if( !pVal ) goto no_mem;
78665 zVal = &pExpr->u.zToken[2];
@@ -78629,10 +78673,11 @@
78673 else if( op==TK_FUNCTION && pCtx!=0 ){
78674 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
78675 }
78676 #endif
78677 else if( op==TK_TRUEFALSE ){
78678 assert( !ExprHasProperty(pExpr, EP_IntValue) );
78679 pVal = valueNew(db, pCtx);
78680 if( pVal ){
78681 pVal->flags = MEM_Int;
78682 pVal->u.i = pExpr->u.zToken[4]==0;
78683 }
@@ -80501,10 +80546,11 @@
80546 */
80547 static void displayP4Expr(StrAccum *p, Expr *pExpr){
80548 const char *zOp = 0;
80549 switch( pExpr->op ){
80550 case TK_STRING:
80551 assert( !ExprHasProperty(pExpr, EP_IntValue) );
80552 sqlite3_str_appendf(p, "%Q", pExpr->u.zToken);
80553 break;
80554 case TK_INTEGER:
80555 sqlite3_str_appendf(p, "%d", pExpr->u.iValue);
80556 break;
@@ -80847,12 +80893,12 @@
80893 ** with no indexes using a single prepared INSERT statement, bind()
80894 ** and reset(). Inserts are grouped into a transaction.
80895 */
80896 testcase( p->flags & MEM_Agg );
80897 testcase( p->flags & MEM_Dyn );
 
80898 if( p->flags&(MEM_Agg|MEM_Dyn) ){
80899 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
80900 sqlite3VdbeMemRelease(p);
80901 }else if( p->szMalloc ){
80902 sqlite3DbFreeNN(db, p->zMalloc);
80903 p->szMalloc = 0;
80904 }
@@ -84553,12 +84599,12 @@
84599 /**************************** sqlite3_result_ *******************************
84600 ** The following routines are used by user-defined functions to specify
84601 ** the function result.
84602 **
84603 ** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
84604 ** result as a string or blob. Appropriate errors are set if the string/blob
84605 ** is too big or if an OOM occurs.
84606 **
84607 ** The invokeValueDestructor(P,X) routine invokes destructor function X()
84608 ** on value P is not going to be used and need to be destroyed.
84609 */
84610 static void setResultStrOrError(
@@ -84566,12 +84612,20 @@
84612 const char *z, /* String pointer */
84613 int n, /* Bytes in string, or negative */
84614 u8 enc, /* Encoding of z. 0 for BLOBs */
84615 void (*xDel)(void*) /* Destructor function */
84616 ){
84617 int rc = sqlite3VdbeMemSetStr(pCtx->pOut, z, n, enc, xDel);
84618 if( rc ){
84619 if( rc==SQLITE_TOOBIG ){
84620 sqlite3_result_error_toobig(pCtx);
84621 }else{
84622 /* The only errors possible from sqlite3VdbeMemSetStr are
84623 ** SQLITE_TOOBIG and SQLITE_NOMEM */
84624 assert( rc==SQLITE_NOMEM );
84625 sqlite3_result_error_nomem(pCtx);
84626 }
84627 }
84628 }
84629 static int invokeValueDestructor(
84630 const void *p, /* Value to destroy */
84631 void (*xDel)(void*), /* The destructor */
@@ -90536,11 +90590,11 @@
90590 assert( aMem[pOp->p3].flags & MEM_Null );
90591 aMem[pOp->p3].n = 0;
90592 aMem[pOp->p3].z = "";
90593 }
90594 pCx = p->apCsr[pOp->p1];
90595 if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){
90596 /* If the ephermeral table is already open and has no duplicates from
90597 ** OP_OpenDup, then erase all existing content so that the table is
90598 ** empty again, rather than creating a new table. */
90599 assert( pCx->isEphemeral );
90600 pCx->seqCount = 0;
@@ -95092,11 +95146,11 @@
95146 /* Check that the column is not part of an FK child key definition. It
95147 ** is not necessary to check if it is part of a parent key, as parent
95148 ** key columns must be indexed. The check below will pick up this
95149 ** case. */
95150 FKey *pFKey;
95151 assert( IsOrdinaryTable(pTab) );
95152 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
95153 int j;
95154 for(j=0; j<pFKey->nCol; j++){
95155 if( pFKey->aCol[j].iFrom==iCol ){
95156 zFault = "foreign key";
@@ -96682,11 +96736,11 @@
96736 void *p = 0;
96737 int chunksize = 4*1024;
96738 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
96739 sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
96740 sqlite3OsFetch(pFd, 0, (int)nByte, &p);
96741 if( p ) sqlite3OsUnfetch(pFd, 0, p);
96742 }
96743 }
96744 #else
96745 # define vdbeSorterExtendFile(x,y,z)
96746 #endif
@@ -99101,11 +99155,11 @@
99155 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
99156 if( pExpr->pRight ){
99157 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
99158 pExpr = pExpr->pRight;
99159 continue;
99160 }else if( ExprUseXSelect(pExpr) ){
99161 assert( !ExprHasProperty(pExpr, EP_WinFunc) );
99162 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
99163 }else{
99164 if( pExpr->x.pList ){
99165 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
@@ -99373,10 +99427,11 @@
99427 sqlite3ExprDelete(db, pDup);
99428 pDup = 0;
99429 }else{
99430 incrAggFunctionDepth(pDup, nSubquery);
99431 if( pExpr->op==TK_COLLATE ){
99432 assert( !ExprHasProperty(pExpr, EP_IntValue) );
99433 pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
99434 }
99435
99436 /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This
99437 ** prevents ExprDelete() from deleting the Expr structure itself,
@@ -99476,10 +99531,11 @@
99531 SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){
99532 int n;
99533 Table *pExTab;
99534
99535 n = pExpr->iColumn;
99536 assert( ExprUseYTab(pExpr) );
99537 pExTab = pExpr->y.pTab;
99538 assert( pExTab!=0 );
99539 if( (pExTab->tabFlags & TF_HasGenerated)!=0
99540 && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0
99541 ){
@@ -99613,10 +99669,11 @@
99669 const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
99670 assert( zTabName!=0 );
99671 if( sqlite3StrICmp(zTabName, zTab)!=0 ){
99672 continue;
99673 }
99674 assert( ExprUseYTab(pExpr) );
99675 if( IN_RENAME_OBJECT && pItem->zAlias ){
99676 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
99677 }
99678 }
99679 hCol = sqlite3StrIHash(zCol);
@@ -99644,10 +99701,11 @@
99701 pMatch = pItem;
99702 }
99703 }
99704 if( pMatch ){
99705 pExpr->iTable = pMatch->iCursor;
99706 assert( ExprUseYTab(pExpr) );
99707 pExpr->y.pTab = pMatch->pTab;
99708 /* RIGHT JOIN not (yet) supported */
99709 assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
99710 if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
99711 ExprSetProperty(pExpr, EP_CanBeNull);
@@ -99717,10 +99775,11 @@
99775 cnt++;
99776 pMatch = 0;
99777 #ifndef SQLITE_OMIT_UPSERT
99778 if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){
99779 testcase( iCol==(-1) );
99780 assert( ExprUseYTab(pExpr) );
99781 if( IN_RENAME_OBJECT ){
99782 pExpr->iColumn = iCol;
99783 pExpr->y.pTab = pTab;
99784 eNewExprOp = TK_COLUMN;
99785 }else{
@@ -99729,10 +99788,11 @@
99788 eNewExprOp = TK_REGISTER;
99789 }
99790 }else
99791 #endif /* SQLITE_OMIT_UPSERT */
99792 {
99793 assert( ExprUseYTab(pExpr) );
99794 pExpr->y.pTab = pTab;
99795 if( pParse->bReturning ){
99796 eNewExprOp = TK_REGISTER;
99797 pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
99798 sqlite3TableColumnToStorage(pTab, iCol) + 1;
@@ -99803,12 +99863,12 @@
99863 if( pEList->a[j].eEName==ENAME_NAME
99864 && sqlite3_stricmp(zAs, zCol)==0
99865 ){
99866 Expr *pOrig;
99867 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
99868 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
99869 assert( ExprUseXSelect(pExpr)==0 || pExpr->x.pSelect==0 );
99870 pOrig = pEList->a[j].pExpr;
99871 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
99872 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
99873 return WRC_Abort;
99874 }
@@ -99876,11 +99936,11 @@
99936 "double-quoted string literal: \"%w\"", zCol);
99937 #ifdef SQLITE_ENABLE_NORMALIZE
99938 sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol);
99939 #endif
99940 pExpr->op = TK_STRING;
99941 memset(&pExpr->y, 0, sizeof(pExpr->y));
99942 return WRC_Prune;
99943 }
99944 if( sqlite3ExprIdToTrueFalse(pExpr) ){
99945 return WRC_Prune;
99946 }
@@ -99962,11 +100022,13 @@
100022 */
100023 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
100024 Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
100025 if( p ){
100026 SrcItem *pItem = &pSrc->a[iSrc];
100027 Table *pTab;
100028 assert( ExprUseYTab(p) );
100029 pTab = p->y.pTab = pItem->pTab;
100030 p->iTable = pItem->iCursor;
100031 if( p->y.pTab->iPKey==iCol ){
100032 p->iColumn = -1;
100033 }else{
100034 p->iColumn = (ynVar)iCol;
@@ -100029,10 +100091,11 @@
100091 ** value between 1.0 and 0.0.
100092 */
100093 static int exprProbability(Expr *p){
100094 double r = -1.0;
100095 if( p->op!=TK_FLOAT ) return -1;
100096 assert( !ExprHasProperty(p, EP_IntValue) );
100097 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
100098 assert( r>=0.0 );
100099 if( r>1.0 ) return -1;
100100 return (int)(r*134217728.0);
100101 }
@@ -100077,10 +100140,11 @@
100140 SrcList *pSrcList = pNC->pSrcList;
100141 SrcItem *pItem;
100142 assert( pSrcList && pSrcList->nSrc>=1 );
100143 pItem = pSrcList->a;
100144 pExpr->op = TK_COLUMN;
100145 assert( ExprUseYTab(pExpr) );
100146 pExpr->y.pTab = pItem->pTab;
100147 pExpr->iTable = pItem->iCursor;
100148 pExpr->iColumn--;
100149 pExpr->affExpr = SQLITE_AFF_INTEGER;
100150 break;
@@ -100109,10 +100173,11 @@
100173 anRef[i] = p->nRef;
100174 }
100175 sqlite3WalkExpr(pWalker, pExpr->pLeft);
100176 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
100177 testcase( ExprHasProperty(pExpr, EP_FromJoin) );
100178 assert( !ExprHasProperty(pExpr, EP_IntValue) );
100179 if( pExpr->op==TK_NOTNULL ){
100180 pExpr->u.zToken = "true";
100181 ExprSetProperty(pExpr, EP_IsTrue);
100182 }else{
100183 pExpr->u.zToken = "false";
@@ -100144,10 +100209,11 @@
100209 Expr *pRight;
100210
100211 if( pExpr->op==TK_ID ){
100212 zDb = 0;
100213 zTable = 0;
100214 assert( !ExprHasProperty(pExpr, EP_IntValue) );
100215 zColumn = pExpr->u.zToken;
100216 }else{
100217 Expr *pLeft = pExpr->pLeft;
100218 testcase( pNC->ncFlags & NC_IdxExpr );
100219 testcase( pNC->ncFlags & NC_GenCol );
@@ -100156,16 +100222,19 @@
100222 pRight = pExpr->pRight;
100223 if( pRight->op==TK_ID ){
100224 zDb = 0;
100225 }else{
100226 assert( pRight->op==TK_DOT );
100227 assert( !ExprHasProperty(pRight, EP_IntValue) );
100228 zDb = pLeft->u.zToken;
100229 pLeft = pRight->pLeft;
100230 pRight = pRight->pRight;
100231 }
100232 assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) );
100233 zTable = pLeft->u.zToken;
100234 zColumn = pRight->u.zToken;
100235 assert( ExprUseYTab(pExpr) );
100236 if( IN_RENAME_OBJECT ){
100237 sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
100238 sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
100239 }
100240 }
@@ -100186,11 +100255,11 @@
100255 u8 enc = ENC(pParse->db); /* The database encoding */
100256 int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
100257 #ifndef SQLITE_OMIT_WINDOWFUNC
100258 Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0);
100259 #endif
100260 assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) );
100261 zId = pExpr->u.zToken;
100262 nId = sqlite3Strlen30(zId);
100263 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
100264 if( pDef==0 ){
100265 pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0);
@@ -100350,11 +100419,11 @@
100419 sqlite3WalkExprList(pWalker, pList);
100420 if( is_agg ){
100421 #ifndef SQLITE_OMIT_WINDOWFUNC
100422 if( pWin ){
100423 Select *pSel = pNC->pWinSelect;
100424 assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) );
100425 if( IN_RENAME_OBJECT==0 ){
100426 sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef);
100427 if( pParse->db->mallocFailed ) break;
100428 }
100429 sqlite3WalkExprList(pWalker, pWin->pPartition);
@@ -100399,11 +100468,11 @@
100468 case TK_SELECT:
100469 case TK_EXISTS: testcase( pExpr->op==TK_EXISTS );
100470 #endif
100471 case TK_IN: {
100472 testcase( pExpr->op==TK_IN );
100473 if( ExprUseXSelect(pExpr) ){
100474 int nRef = pNC->nRef;
100475 testcase( pNC->ncFlags & NC_IsCheck );
100476 testcase( pNC->ncFlags & NC_PartIdx );
100477 testcase( pNC->ncFlags & NC_IdxExpr );
100478 testcase( pNC->ncFlags & NC_GenCol );
@@ -100456,10 +100525,11 @@
100525 int nLeft, nRight;
100526 if( pParse->db->mallocFailed ) break;
100527 assert( pExpr->pLeft!=0 );
100528 nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
100529 if( pExpr->op==TK_BETWEEN ){
100530 assert( ExprUseXList(pExpr) );
100531 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
100532 if( nRight==nLeft ){
100533 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
100534 }
100535 }else{
@@ -100504,11 +100574,13 @@
100574 int i; /* Loop counter */
100575
100576 UNUSED_PARAMETER(pParse);
100577
100578 if( pE->op==TK_ID ){
100579 const char *zCol;
100580 assert( !ExprHasProperty(pE, EP_IntValue) );
100581 zCol = pE->u.zToken;
100582 for(i=0; i<pEList->nExpr; i++){
100583 if( pEList->a[i].eEName==ENAME_NAME
100584 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
100585 ){
100586 return i+1;
@@ -101369,15 +101441,18 @@
101441 pExpr = pExpr->pLeft;
101442 assert( pExpr!=0 );
101443 }
101444 op = pExpr->op;
101445 if( op==TK_REGISTER ) op = pExpr->op2;
101446 if( op==TK_COLUMN || op==TK_AGG_COLUMN ){
101447 assert( ExprUseYTab(pExpr) );
101448 if( pExpr->y.pTab ){
101449 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
101450 }
101451 }
101452 if( op==TK_SELECT ){
101453 assert( ExprUseXSelect(pExpr) );
101454 assert( pExpr->x.pSelect!=0 );
101455 assert( pExpr->x.pSelect->pEList!=0 );
101456 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
101457 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
101458 }
@@ -101386,18 +101461,19 @@
101461 assert( !ExprHasProperty(pExpr, EP_IntValue) );
101462 return sqlite3AffinityType(pExpr->u.zToken, 0);
101463 }
101464 #endif
101465 if( op==TK_SELECT_COLUMN ){
101466 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
101467 assert( pExpr->iColumn < pExpr->iTable );
101468 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
101469 return sqlite3ExprAffinity(
101470 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
101471 );
101472 }
101473 if( op==TK_VECTOR ){
101474 assert( ExprUseXList(pExpr) );
101475 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
101476 }
101477 return pExpr->affExpr;
101478 }
101479
@@ -101453,11 +101529,11 @@
101529 ** expression.
101530 */
101531 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
101532 while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){
101533 if( ExprHasProperty(pExpr, EP_Unlikely) ){
101534 assert( ExprUseXList(pExpr) );
101535 assert( pExpr->x.pList->nExpr>0 );
101536 assert( pExpr->op==TK_FUNCTION );
101537 pExpr = pExpr->x.pList->a[0].pExpr;
101538 }else{
101539 assert( pExpr->op==TK_COLLATE );
@@ -101486,45 +101562,46 @@
101562 CollSeq *pColl = 0;
101563 const Expr *p = pExpr;
101564 while( p ){
101565 int op = p->op;
101566 if( op==TK_REGISTER ) op = p->op2;
101567 if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){
101568 assert( ExprUseYTab(p) );
101569 if( p->y.pTab!=0 ){
101570 /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
101571 ** a TK_COLUMN but was previously evaluated and cached in a register */
101572 int j = p->iColumn;
101573 if( j>=0 ){
101574 const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
101575 pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
101576 }
101577 break;
101578 }
101579 }
101580 if( op==TK_CAST || op==TK_UPLUS ){
101581 p = p->pLeft;
101582 continue;
101583 }
101584 if( op==TK_VECTOR ){
101585 assert( ExprUseXList(p) );
101586 p = p->x.pList->a[0].pExpr;
101587 continue;
101588 }
101589 if( op==TK_COLLATE ){
101590 assert( !ExprHasProperty(p, EP_IntValue) );
101591 pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken);
101592 break;
101593 }
101594 if( p->flags & EP_Collate ){
101595 if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
101596 p = p->pLeft;
101597 }else{
101598 Expr *pNext = p->pRight;
101599 /* The Expr.x union is never used at the same time as Expr.pRight */
101600 assert( ExprUseXList(p) );
101601 assert( p->x.pList==0 || p->pRight==0 );
101602 if( p->x.pList!=0 && !db->mallocFailed ){
 
 
 
101603 int i;
101604 for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){
101605 if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){
101606 pNext = p->x.pList->a[i].pExpr;
101607 break;
@@ -101603,11 +101680,11 @@
101680 pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT );
101681 assert( pExpr->pLeft );
101682 aff = sqlite3ExprAffinity(pExpr->pLeft);
101683 if( pExpr->pRight ){
101684 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
101685 }else if( ExprUseXSelect(pExpr) ){
101686 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
101687 }else if( aff==0 ){
101688 aff = SQLITE_AFF_BLOB;
101689 }
101690 return aff;
@@ -101743,12 +101820,14 @@
101820 */
101821 SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){
101822 u8 op = pExpr->op;
101823 if( op==TK_REGISTER ) op = pExpr->op2;
101824 if( op==TK_VECTOR ){
101825 assert( ExprUseXList(pExpr) );
101826 return pExpr->x.pList->nExpr;
101827 }else if( op==TK_SELECT ){
101828 assert( ExprUseXSelect(pExpr) );
101829 return pExpr->x.pSelect->pEList->nExpr;
101830 }else{
101831 return 1;
101832 }
101833 }
@@ -101771,12 +101850,14 @@
101850 SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
101851 assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR );
101852 if( sqlite3ExprIsVector(pVector) ){
101853 assert( pVector->op2==0 || pVector->op==TK_REGISTER );
101854 if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){
101855 assert( ExprUseXSelect(pVector) );
101856 return pVector->x.pSelect->pEList->a[i].pExpr;
101857 }else{
101858 assert( ExprUseXList(pVector) );
101859 return pVector->x.pList->a[i].pExpr;
101860 }
101861 }
101862 return pVector;
101863 }
@@ -101808,11 +101889,11 @@
101889 int iField, /* Which column of the vector to return */
101890 int nField /* Total number of columns in the vector */
101891 ){
101892 Expr *pRet;
101893 if( pVector->op==TK_SELECT ){
101894 assert( ExprUseXSelect(pVector) );
101895 /* The TK_SELECT_COLUMN Expr node:
101896 **
101897 ** pLeft: pVector containing TK_SELECT. Not deleted.
101898 ** pRight: not used. But recursively deleted.
101899 ** iColumn: Index of a column in pVector
@@ -101833,11 +101914,13 @@
101914 pRet->iColumn = iField;
101915 pRet->pLeft = pVector;
101916 }
101917 }else{
101918 if( pVector->op==TK_VECTOR ){
101919 Expr **ppVector;
101920 assert( ExprUseXList(pVector) );
101921 ppVector = &pVector->x.pList->a[iField].pExpr;
101922 pVector = *ppVector;
101923 if( IN_RENAME_OBJECT ){
101924 /* This must be a vector UPDATE inside a trigger */
101925 *ppVector = 0;
101926 return pVector;
@@ -101897,14 +101980,16 @@
101980 if( op==TK_REGISTER ){
101981 *ppExpr = sqlite3VectorFieldSubexpr(pVector, iField);
101982 return pVector->iTable+iField;
101983 }
101984 if( op==TK_SELECT ){
101985 assert( ExprUseXSelect(pVector) );
101986 *ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr;
101987 return regSelect+iField;
101988 }
101989 if( op==TK_VECTOR ){
101990 assert( ExprUseXList(pVector) );
101991 *ppExpr = pVector->x.pList->a[iField].pExpr;
101992 return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree);
101993 }
101994 return 0;
101995 }
@@ -102075,11 +102160,11 @@
102160 */
102161 static void exprSetHeight(Expr *p){
102162 int nHeight = 0;
102163 heightOfExpr(p->pLeft, &nHeight);
102164 heightOfExpr(p->pRight, &nHeight);
102165 if( ExprUseXSelect(p) ){
102166 heightOfSelect(p->x.pSelect, &nHeight);
102167 }else if( p->x.pList ){
102168 heightOfExprList(p->x.pList, &nHeight);
102169 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102170 }
@@ -102114,11 +102199,11 @@
102199 ** Propagate all EP_Propagate flags from the Expr.x.pList into
102200 ** Expr.flags.
102201 */
102202 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
102203 if( pParse->nErr ) return;
102204 if( p && ExprUseXList(p) && p->x.pList ){
102205 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
102206 }
102207 }
102208 #define exprSetHeight(y)
102209 #endif /* SQLITE_MAX_EXPR_DEPTH>0 */
@@ -102298,17 +102383,24 @@
102383 Select *pRet = 0;
102384 assert( nElem>1 );
102385 for(ii=0; ii<pEList->nExpr; ii++){
102386 Select *pSel;
102387 Expr *pExpr = pEList->a[ii].pExpr;
102388 int nExprElem;
102389 if( pExpr->op==TK_VECTOR ){
102390 assert( ExprUseXList(pExpr) );
102391 nExprElem = pExpr->x.pList->nExpr;
102392 }else{
102393 nExprElem = 1;
102394 }
102395 if( nExprElem!=nElem ){
102396 sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d",
102397 nExprElem, nExprElem>1?"s":"", nElem
102398 );
102399 break;
102400 }
102401 assert( ExprUseXList(pExpr) );
102402 pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0);
102403 pExpr->x.pList = 0;
102404 if( pSel ){
102405 if( pRet ){
102406 pSel->op = TK_ALL;
@@ -102374,11 +102466,11 @@
102466 ){
102467 sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
102468 }
102469 pNew->x.pList = pList;
102470 ExprSetProperty(pNew, EP_HasFunc);
102471 assert( ExprUseXList(pNew) );
102472 sqlite3ExprSetHeightAndFlags(pParse, pNew);
102473 if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
102474 return pNew;
102475 }
102476
@@ -102500,31 +102592,30 @@
102592 /*
102593 ** Recursively delete an expression tree.
102594 */
102595 static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
102596 assert( p!=0 );
102597 assert( !ExprUseUValue(p) || p->u.iValue>=0 );
102598 assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
102599 assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
102600 assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) );
 
 
102601 #ifdef SQLITE_DEBUG
102602 if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){
102603 assert( p->pLeft==0 );
102604 assert( p->pRight==0 );
102605 assert( !ExprUseXSelect(p) || p->x.pSelect==0 );
102606 assert( !ExprUseXList(p) || p->x.pList==0 );
102607 }
102608 #endif
102609 if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){
102610 /* The Expr.x union is never used at the same time as Expr.pRight */
102611 assert( (ExprUseXList(p) && p->x.pList==0) || p->pRight==0 );
102612 if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft);
102613 if( p->pRight ){
102614 assert( !ExprHasProperty(p, EP_WinFunc) );
102615 sqlite3ExprDeleteNN(db, p->pRight);
102616 }else if( ExprUseXSelect(p) ){
102617 assert( !ExprHasProperty(p, EP_WinFunc) );
102618 sqlite3SelectDelete(db, p->x.pSelect);
102619 }else{
102620 sqlite3ExprListDelete(db, p->x.pList);
102621 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -102532,11 +102623,14 @@
102623 sqlite3WindowDelete(db, p->y.pWin);
102624 }
102625 #endif
102626 }
102627 }
102628 if( ExprHasProperty(p, EP_MemToken) ){
102629 assert( !ExprHasProperty(p, EP_IntValue) );
102630 sqlite3DbFree(db, p->u.zToken);
102631 }
102632 if( !ExprHasProperty(p, EP_Static) ){
102633 sqlite3DbFreeNN(db, p);
102634 }
102635 }
102636 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
@@ -102748,11 +102842,11 @@
102842 memcpy(zToken, p->u.zToken, nToken);
102843 }
102844
102845 if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){
102846 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
102847 if( ExprUseXSelect(p) ){
102848 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
102849 }else{
102850 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
102851 }
102852 }
@@ -103375,11 +103469,11 @@
103469 ** the conversion happened, and zero if the expression is unaltered.
103470 */
103471 SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){
103472 u32 v;
103473 assert( pExpr->op==TK_ID || pExpr->op==TK_STRING );
103474 if( !ExprHasProperty(pExpr, EP_Quoted|EP_IntValue)
103475 && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0
103476 ){
103477 pExpr->op = TK_TRUEFALSE;
103478 ExprSetProperty(pExpr, v);
103479 return 1;
@@ -103392,10 +103486,11 @@
103486 ** and 0 if it is FALSE.
103487 */
103488 SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){
103489 pExpr = sqlite3ExprSkipCollate((Expr*)pExpr);
103490 assert( pExpr->op==TK_TRUEFALSE );
103491 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103492 assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0
103493 || sqlite3StrICmp(pExpr->u.zToken,"false")==0 );
103494 return pExpr->u.zToken[4]==0;
103495 }
103496
@@ -103596,11 +103691,11 @@
103691 }
103692 }
103693 }
103694
103695 /* Check if pExpr is a sub-select. If so, consider it variable. */
103696 if( ExprUseXSelect(pExpr) ){
103697 pWalker->eCode = 0;
103698 return WRC_Abort;
103699 }
103700
103701 return exprNodeIsConstant(pWalker, pExpr);
@@ -103746,10 +103841,11 @@
103841 case TK_STRING:
103842 case TK_FLOAT:
103843 case TK_BLOB:
103844 return 0;
103845 case TK_COLUMN:
103846 assert( ExprUseYTab(p) );
103847 return ExprHasProperty(p, EP_CanBeNull) ||
103848 p->y.pTab==0 || /* Reference to column of index on expression */
103849 (p->iColumn>=0
103850 && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */
103851 && p->y.pTab->aCol[p->iColumn].notNull==0);
@@ -103823,11 +103919,11 @@
103919 Select *p;
103920 SrcList *pSrc;
103921 ExprList *pEList;
103922 Table *pTab;
103923 int i;
103924 if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */
103925 if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */
103926 p = pX->x.pSelect;
103927 if( p->pPrior ) return 0; /* Not a compound SELECT */
103928 if( p->selFlags & (SF_Distinct|SF_Aggregate) ){
103929 testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
@@ -103994,11 +104090,11 @@
104090 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
104091 ** whether or not the SELECT result contains NULL values, check whether
104092 ** or not NULL is actually possible (it may not be, for example, due
104093 ** to NOT NULL constraints in the schema). If no NULL values are possible,
104094 ** set prRhsHasNull to 0 before continuing. */
104095 if( prRhsHasNull && ExprUseXSelect(pX) ){
104096 int i;
104097 ExprList *pEList = pX->x.pSelect->pEList;
104098 for(i=0; i<pEList->nExpr; i++){
104099 if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break;
104100 }
@@ -104150,11 +104246,11 @@
104246 ** then it is not worth creating an ephemeral table to evaluate
104247 ** the IN operator so return IN_INDEX_NOOP.
104248 */
104249 if( eType==0
104250 && (inFlags & IN_INDEX_NOOP_OK)
104251 && ExprUseXList(pX)
104252 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
104253 ){
104254 eType = IN_INDEX_NOOP;
104255 }
104256
@@ -104198,11 +104294,11 @@
104294 ** string is eventually freed using sqlite3DbFree().
104295 */
104296 static char *exprINAffinity(Parse *pParse, const Expr *pExpr){
104297 Expr *pLeft = pExpr->pLeft;
104298 int nVal = sqlite3ExprVectorSize(pLeft);
104299 Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
104300 char *zRet;
104301
104302 assert( pExpr->op==TK_IN );
104303 zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
104304 if( zRet ){
@@ -104248,11 +104344,11 @@
104344 **
104345 ** "row value misused"
104346 */
104347 SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){
104348 #ifndef SQLITE_OMIT_SUBQUERY
104349 if( ExprUseXSelect(pExpr) ){
104350 sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1);
104351 }else
104352 #endif
104353 {
104354 sqlite3ErrorMsg(pParse, "row value misused");
@@ -104312,22 +104408,24 @@
104408 /* If this routine has already been coded, but the previous code
104409 ** might not have been invoked yet, so invoke it now as a subroutine.
104410 */
104411 if( ExprHasProperty(pExpr, EP_Subrtn) ){
104412 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
104413 if( ExprUseXSelect(pExpr) ){
104414 ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d",
104415 pExpr->x.pSelect->selId));
104416 }
104417 assert( ExprUseYSub(pExpr) );
104418 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104419 pExpr->y.sub.iAddr);
104420 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
104421 sqlite3VdbeJumpHere(v, addrOnce);
104422 return;
104423 }
104424
104425 /* Begin coding the subroutine */
104426 assert( !ExprUseYWin(pExpr) );
104427 ExprSetProperty(pExpr, EP_Subrtn);
104428 assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
104429 pExpr->y.sub.regReturn = ++pParse->nMem;
104430 pExpr->y.sub.iAddr =
104431 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
@@ -104344,19 +104442,19 @@
104442 ** RHS of the IN operator.
104443 */
104444 pExpr->iTable = iTab;
104445 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
104446 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
104447 if( ExprUseXSelect(pExpr) ){
104448 VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
104449 }else{
104450 VdbeComment((v, "RHS of IN operator"));
104451 }
104452 #endif
104453 pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
104454
104455 if( ExprUseXSelect(pExpr) ){
104456 /* Case 1: expr IN (SELECT ...)
104457 **
104458 ** Generate code to write the results of the select into the temporary
104459 ** table allocated and opened above.
104460 */
@@ -104450,10 +104548,11 @@
104548 sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
104549 }
104550 if( addrOnce ){
104551 sqlite3VdbeJumpHere(v, addrOnce);
104552 /* Subroutine return */
104553 assert( ExprUseYSub(pExpr) );
104554 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104555 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104556 sqlite3ClearTempRegCache(pParse);
104557 }
104558 }
@@ -104486,23 +104585,26 @@
104585 assert( v!=0 );
104586 if( pParse->nErr ) return 0;
104587 testcase( pExpr->op==TK_EXISTS );
104588 testcase( pExpr->op==TK_SELECT );
104589 assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT );
104590 assert( ExprUseXSelect(pExpr) );
104591 pSel = pExpr->x.pSelect;
104592
104593 /* If this routine has already been coded, then invoke it as a
104594 ** subroutine. */
104595 if( ExprHasProperty(pExpr, EP_Subrtn) ){
104596 ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId));
104597 assert( ExprUseYSub(pExpr) );
104598 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
104599 pExpr->y.sub.iAddr);
104600 return pExpr->iTable;
104601 }
104602
104603 /* Begin coding the subroutine */
104604 assert( !ExprUseYWin(pExpr) );
104605 assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) );
104606 ExprSetProperty(pExpr, EP_Subrtn);
104607 pExpr->y.sub.regReturn = ++pParse->nMem;
104608 pExpr->y.sub.iAddr =
104609 sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1;
104610 VdbeComment((v, "return address"));
@@ -104578,10 +104680,11 @@
104680 if( addrOnce ){
104681 sqlite3VdbeJumpHere(v, addrOnce);
104682 }
104683
104684 /* Subroutine return */
104685 assert( ExprUseYSub(pExpr) );
104686 sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn);
104687 sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1);
104688 sqlite3ClearTempRegCache(pParse);
104689 return rReg;
104690 }
@@ -104594,11 +104697,11 @@
104697 ** columns as the vector on the LHS. Or, if the RHS of the IN() is not
104698 ** a sub-query, that the LHS is a vector of size 1.
104699 */
104700 SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){
104701 int nVector = sqlite3ExprVectorSize(pIn->pLeft);
104702 if( ExprUseXSelect(pIn) && !pParse->db->mallocFailed ){
104703 if( nVector!=pIn->x.pSelect->pEList->nExpr ){
104704 sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector);
104705 return 1;
104706 }
104707 }else if( nVector!=1 ){
@@ -104728,17 +104831,19 @@
104831 ** sequence of comparisons.
104832 **
104833 ** This is step (1) in the in-operator.md optimized algorithm.
104834 */
104835 if( eType==IN_INDEX_NOOP ){
104836 ExprList *pList;
104837 CollSeq *pColl;
104838 int labelOk = sqlite3VdbeMakeLabel(pParse);
104839 int r2, regToFree;
104840 int regCkNull = 0;
104841 int ii;
104842 assert( ExprUseXList(pExpr) );
104843 pList = pExpr->x.pList;
104844 pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
104845 if( destIfNull!=destIfFalse ){
104846 regCkNull = sqlite3GetTempReg(pParse);
104847 sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull);
104848 }
104849 for(ii=0; ii<pList->nExpr; ii++){
@@ -105120,10 +105225,11 @@
105225 #endif
105226 }else{
105227 int i;
105228 iResult = pParse->nMem+1;
105229 pParse->nMem += nResult;
105230 assert( ExprUseXList(p) );
105231 for(i=0; i<nResult; i++){
105232 sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult);
105233 }
105234 }
105235 }
@@ -105318,10 +105424,11 @@
105424 ** datatype by applying the Affinity of the table column to the
105425 ** constant.
105426 */
105427 int aff;
105428 iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
105429 assert( ExprUseYTab(pExpr) );
105430 if( pExpr->y.pTab ){
105431 aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105432 }else{
105433 aff = pExpr->affExpr;
105434 }
@@ -105341,13 +105448,15 @@
105448 ** The row is unpacked into registers beginning at
105449 ** 0-(pParse->iSelfTab). The rowid (if any) is in a register
105450 ** immediately prior to the first column.
105451 */
105452 Column *pCol;
105453 Table *pTab;
105454 int iSrc;
105455 int iCol = pExpr->iColumn;
105456 assert( ExprUseYTab(pExpr) );
105457 pTab = pExpr->y.pTab;
105458 assert( pTab!=0 );
105459 assert( iCol>=XN_ROWID );
105460 assert( iCol<pTab->nCol );
105461 if( iCol<0 ){
105462 return -1-pParse->iSelfTab;
@@ -105381,10 +105490,11 @@
105490 /* Coding an expression that is part of an index where column names
105491 ** in the index refer to the table to which the index belongs */
105492 iTab = pParse->iSelfTab - 1;
105493 }
105494 }
105495 assert( ExprUseYTab(pExpr) );
105496 iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
105497 pExpr->iColumn, iTab, target,
105498 pExpr->op2);
105499 if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
105500 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
@@ -105458,10 +105568,11 @@
105568 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
105569 if( inReg!=target ){
105570 sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
105571 inReg = target;
105572 }
105573 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105574 sqlite3VdbeAddOp2(v, OP_Cast, target,
105575 sqlite3AffinityType(pExpr->u.zToken, 0));
105576 return inReg;
105577 }
105578 #endif /* SQLITE_OMIT_CAST */
@@ -105625,12 +105736,12 @@
105736 if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
105737 /* SQL functions can be expensive. So try to avoid running them
105738 ** multiple times if we know they always give the same result */
105739 return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1);
105740 }
 
105741 assert( !ExprHasProperty(pExpr, EP_TokenOnly) );
105742 assert( ExprUseXList(pExpr) );
105743 pFarg = pExpr->x.pList;
105744 nFarg = pFarg ? pFarg->nExpr : 0;
105745 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105746 zId = pExpr->u.zToken;
105747 pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0);
@@ -105745,11 +105856,14 @@
105856 int nCol;
105857 testcase( op==TK_EXISTS );
105858 testcase( op==TK_SELECT );
105859 if( pParse->db->mallocFailed ){
105860 return 0;
105861 }else if( op==TK_SELECT
105862 && ALWAYS( ExprUseXSelect(pExpr) )
105863 && (nCol = pExpr->x.pSelect->pEList->nExpr)!=1
105864 ){
105865 sqlite3SubselectError(pParse, nCol, 1);
105866 }else{
105867 return sqlite3CodeSubselect(pParse, pExpr);
105868 }
105869 break;
@@ -105827,13 +105941,18 @@
105941 **
105942 ** p1==0 -> old.rowid p1==3 -> new.rowid
105943 ** p1==1 -> old.a p1==4 -> new.a
105944 ** p1==2 -> old.b p1==5 -> new.b
105945 */
105946 Table *pTab;
105947 int iCol;
105948 int p1;
105949
105950 assert( ExprUseYTab(pExpr) );
105951 pTab = pExpr->y.pTab;
105952 iCol = pExpr->iColumn;
105953 p1 = pExpr->iTable * (pTab->nCol+1) + 1
105954 + sqlite3TableColumnToStorage(pTab, iCol);
105955
105956 assert( pExpr->iTable==0 || pExpr->iTable==1 );
105957 assert( iCol>=-1 && iCol<pTab->nCol );
105958 assert( pTab->iPKey<0 || iCol!=pTab->iPKey );
@@ -105917,11 +106036,11 @@
106036 Expr *pX; /* The X expression */
106037 Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */
106038 Expr *pDel = 0;
106039 sqlite3 *db = pParse->db;
106040
106041 assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 );
106042 assert(pExpr->x.pList->nExpr > 0);
106043 pEList = pExpr->x.pList;
106044 aListelem = pEList->a;
106045 nExpr = pEList->nExpr;
106046 endLabel = sqlite3VdbeMakeLabel(pParse);
@@ -106262,11 +106381,11 @@
106381
106382 memset(&compLeft, 0, sizeof(Expr));
106383 memset(&compRight, 0, sizeof(Expr));
106384 memset(&exprAnd, 0, sizeof(Expr));
106385
106386 assert( ExprUseXList(pExpr) );
106387 pDel = sqlite3ExprDup(db, pExpr->pLeft, 0);
106388 if( db->mallocFailed==0 ){
106389 exprAnd.op = TK_AND;
106390 exprAnd.pLeft = &compLeft;
106391 exprAnd.pRight = &compRight;
@@ -106737,11 +106856,16 @@
106856 if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
106857 return 1;
106858 }
106859 return 2;
106860 }
106861 if( pA->op!=TK_COLUMN
106862 && pA->op!=TK_AGG_COLUMN
106863 && ALWAYS(!ExprHasProperty(pA, EP_IntValue))
106864 && pA->u.zToken
106865 ){
106866 assert( !ExprHasProperty(pB, EP_IntValue) );
106867 if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){
106868 if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
106869 #ifndef SQLITE_OMIT_WINDOWFUNC
106870 assert( pA->op==pB->op );
106871 if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){
@@ -106844,16 +106968,17 @@
106968 return pNN->op!=TK_NULL;
106969 }
106970 switch( p->op ){
106971 case TK_IN: {
106972 if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0;
106973 assert( ExprUseXSelect(p) || (p->x.pList!=0 && p->x.pList->nExpr>0) );
 
106974 return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1);
106975 }
106976 case TK_BETWEEN: {
106977 ExprList *pList;
106978 assert( ExprUseXList(p) );
106979 pList = p->x.pList;
106980 assert( pList!=0 );
106981 assert( pList->nExpr==2 );
106982 if( seenNot ) return 0;
106983 if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1)
106984 || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1)
@@ -107026,14 +107151,18 @@
107151 testcase( pExpr->op==TK_LE );
107152 testcase( pExpr->op==TK_GT );
107153 testcase( pExpr->op==TK_GE );
107154 /* The y.pTab=0 assignment in wherecode.c always happens after the
107155 ** impliesNotNullRow() test */
107156 assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
107157 assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
107158 if( (pLeft->op==TK_COLUMN
107159 && pLeft->y.pTab!=0
107160 && IsVirtual(pLeft->y.pTab))
107161 || (pRight->op==TK_COLUMN
107162 && pRight->y.pTab!=0
107163 && IsVirtual(pRight->y.pTab))
107164 ){
107165 return WRC_Prune;
107166 }
107167 /* no break */ deliberate_fall_through
107168 }
@@ -107213,10 +107342,11 @@
107342 w.u.pSrcCount = &cnt;
107343 cnt.pSrc = pSrcList;
107344 cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
107345 cnt.nThis = 0;
107346 cnt.nOther = 0;
107347 assert( ExprUseXList(pExpr) );
107348 sqlite3WalkExprList(&w, pExpr->x.pList);
107349 #ifndef SQLITE_OMIT_WINDOWFUNC
107350 if( ExprHasProperty(pExpr, EP_WinFunc) ){
107351 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
107352 }
@@ -107354,10 +107484,11 @@
107484 }
107485 if( (k>=pAggInfo->nColumn)
107486 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
107487 ){
107488 pCol = &pAggInfo->aCol[k];
107489 assert( ExprUseYTab(pExpr) );
107490 pCol->pTab = pExpr->y.pTab;
107491 pCol->iTable = pExpr->iTable;
107492 pCol->iColumn = pExpr->iColumn;
107493 pCol->iMem = ++pParse->nMem;
107494 pCol->iSorterColumn = -1;
@@ -107417,11 +107548,11 @@
107548 if( i>=0 ){
107549 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
107550 pItem = &pAggInfo->aFunc[i];
107551 pItem->pFExpr = pExpr;
107552 pItem->iMem = ++pParse->nMem;
107553 assert( ExprUseUToken(pExpr) );
107554 pItem->pFunc = sqlite3FindFunction(pParse->db,
107555 pExpr->u.zToken,
107556 pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
107557 if( pExpr->flags & EP_Distinct ){
107558 pItem->iDistinct = pParse->nTab++;
@@ -107939,10 +108070,11 @@
108070 */
108071 assert( pDflt==0 || pDflt->op==TK_SPAN );
108072 if( pDflt && pDflt->pLeft->op==TK_NULL ){
108073 pDflt = 0;
108074 }
108075 assert( IsOrdinaryTable(pNew) );
108076 if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){
108077 sqlite3ErrorIfNotEmpty(pParse, zDb, zTab,
108078 "Cannot add a REFERENCES column with non-NULL default value");
108079 }
108080 if( pCol->notNull && !pDflt ){
@@ -107981,11 +108113,12 @@
108113 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
108114 *zEnd-- = '\0';
108115 }
108116 /* substr() operations on characters, but addColOffset is in bytes. So we
108117 ** have to use printf() to translate between these units: */
108118 assert( IsOrdinaryTable(pTab) );
108119 assert( IsOrdinaryTable(pNew) );
108120 sqlite3NestedParse(pParse,
108121 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
108122 "sql = printf('%%.%ds, ',sql) || %Q"
108123 " || substr(sql,1+length(printf('%%.%ds',sql))) "
108124 "WHERE type = 'table' AND name = %Q",
@@ -108075,10 +108208,11 @@
108208 if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
108209 goto exit_begin_add_column;
108210 }
108211
108212 sqlite3MayAbort(pParse);
108213 assert( IsOrdinaryTable(pTab) );
108214 assert( pTab->u.tab.addColOffset>0 );
108215 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
108216
108217 /* Put a copy of the Table struct in Parse.pNewTable for the
108218 ** sqlite3AddColumn() function and friends to modify. But modify
@@ -108105,11 +108239,11 @@
108239 for(i=0; i<pNew->nCol; i++){
108240 Column *pCol = &pNew->aCol[i];
108241 pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName);
108242 pCol->hName = sqlite3StrIHash(pCol->zCnName);
108243 }
108244 assert( IsOrdinaryTable(pNew) );
108245 pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0);
108246 pNew->pSchema = db->aDb[iDb].pSchema;
108247 pNew->u.tab.addColOffset = pTab->u.tab.addColOffset;
108248 pNew->nTabRef = 1;
108249
@@ -108374,11 +108508,13 @@
108508 ** Walker callback used by sqlite3RenameExprUnmap().
108509 */
108510 static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){
108511 Parse *pParse = pWalker->pParse;
108512 sqlite3RenameTokenRemap(pParse, 0, (const void*)pExpr);
108513 if( ExprUseYTab(pExpr) ){
108514 sqlite3RenameTokenRemap(pParse, 0, (const void*)&pExpr->y.pTab);
108515 }
108516 return WRC_Continue;
108517 }
108518
108519 /*
108520 ** Iterate through the Select objects that are part of WITH clauses attached
@@ -108436,11 +108572,13 @@
108572 */
108573 static int renameUnmapSelectCb(Walker *pWalker, Select *p){
108574 Parse *pParse = pWalker->pParse;
108575 int i;
108576 if( pParse->nErr ) return WRC_Abort;
108577 testcase( p->selFlags & SF_View );
108578 testcase( p->selFlags & SF_CopyCte );
108579 if( p->selFlags & (SF_View|SF_CopyCte) ){
108580 return WRC_Prune;
108581 }
108582 if( ALWAYS(p->pEList) ){
108583 ExprList *pList = p->pEList;
108584 for(i=0; i<pList->nExpr; i++){
@@ -108573,10 +108711,11 @@
108711 && pWalker->pParse->pTriggerTab==p->pTab
108712 ){
108713 renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108714 }else if( pExpr->op==TK_COLUMN
108715 && pExpr->iColumn==p->iCol
108716 && ALWAYS(ExprUseYTab(pExpr))
108717 && p->pTab==pExpr->y.pTab
108718 ){
108719 renameTokenFind(pWalker->pParse, p, (void*)pExpr);
108720 }
108721 return WRC_Continue;
@@ -109103,11 +109242,11 @@
109242 sqlite3WalkExpr(&sWalker, pExpr);
109243 }
109244 #endif
109245 }
109246
109247 assert( IsOrdinaryTable(sParse.pNewTable) );
109248 for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109249 for(i=0; i<pFKey->nCol; i++){
109250 if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){
109251 renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]);
109252 }
@@ -109175,11 +109314,14 @@
109314 /*
109315 ** Walker expression callback used by "RENAME TABLE".
109316 */
109317 static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
109318 RenameCtx *p = pWalker->u.pRename;
109319 if( pExpr->op==TK_COLUMN
109320 && ALWAYS(ExprUseYTab(pExpr))
109321 && p->pTab==pExpr->y.pTab
109322 ){
109323 renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab);
109324 }
109325 return WRC_Continue;
109326 }
109327
@@ -109293,11 +109435,11 @@
109435 #ifndef SQLITE_OMIT_FOREIGN_KEY
109436 if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys))
109437 && !IsVirtual(pTab)
109438 ){
109439 FKey *pFKey;
109440 assert( IsOrdinaryTable(pTab) );
109441 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
109442 if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){
109443 renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo);
109444 }
109445 }
@@ -109614,11 +109756,11 @@
109756 if( iCol<pTab->nCol-1 ){
109757 RenameToken *pEnd;
109758 pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName);
109759 zEnd = (const char*)pEnd->t.z;
109760 }else{
109761 assert( IsOrdinaryTable(pTab) );
109762 zEnd = (const char*)&zSql[pTab->u.tab.addColOffset];
109763 while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--;
109764 }
109765
109766 zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd);
@@ -110789,11 +110931,11 @@
110931 pParse->nMem = MAX(pParse->nMem, iMem);
110932 v = sqlite3GetVdbe(pParse);
110933 if( v==0 || NEVER(pTab==0) ){
110934 return;
110935 }
110936 if( !IsOrdinaryTable(pTab) ){
110937 /* Do not gather statistics on views or virtual tables */
110938 return;
110939 }
110940 if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
110941 /* Do not gather statistics on system tables */
@@ -112083,10 +112225,11 @@
112225
112226 #ifndef SQLITE_OMIT_AUTHORIZATION
112227 if( pAuthArg ){
112228 char *zAuthArg;
112229 if( pAuthArg->op==TK_STRING ){
112230 assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112231 zAuthArg = pAuthArg->u.zToken;
112232 }else{
112233 zAuthArg = 0;
112234 }
112235 rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
@@ -112767,21 +112910,25 @@
112910 Returning *pReturning = pParse->u1.pReturning;
112911 int addrRewind;
112912 int i;
112913 int reg;
112914
112915 if( pReturning->nRetCol==0 ){
112916 assert( CORRUPT_DB );
112917 }else{
112918 addrRewind =
112919 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
112920 VdbeCoverage(v);
112921 reg = pReturning->iRetReg;
112922 for(i=0; i<pReturning->nRetCol; i++){
112923 sqlite3VdbeAddOp3(v, OP_Column, pReturning->iRetCur, i, reg+i);
112924 }
112925 sqlite3VdbeAddOp2(v, OP_ResultRow, reg, i);
112926 sqlite3VdbeAddOp2(v, OP_Next, pReturning->iRetCur, addrRewind+1);
112927 VdbeCoverage(v);
112928 sqlite3VdbeJumpHere(v, addrRewind);
112929 }
112930 }
112931 sqlite3VdbeAddOp0(v, OP_Halt);
112932
112933 #if SQLITE_USER_AUTHENTICATION
112934 if( pParse->nTableLock>0 && db->init.busy==0 ){
@@ -112858,11 +113005,15 @@
113005 }
113006 }
113007
113008 if( pParse->bReturning ){
113009 Returning *pRet = pParse->u1.pReturning;
113010 if( pRet->nRetCol==0 ){
113011 assert( CORRUPT_DB );
113012 }else{
113013 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
113014 }
113015 }
113016
113017 /* Finally, jump back to the beginning of the executable code. */
113018 sqlite3VdbeGoto(v, 1);
113019 }
@@ -113280,11 +113431,11 @@
113431 Table *pTab, /* The table containing the column */
113432 Column *pCol, /* The column to receive the new DEFAULT expression */
113433 Expr *pExpr /* The new default expression */
113434 ){
113435 ExprList *pList;
113436 assert( IsOrdinaryTable(pTab) );
113437 pList = pTab->u.tab.pDfltList;
113438 if( pCol->iDflt==0
113439 || NEVER(pList==0)
113440 || NEVER(pList->nExpr<pCol->iDflt)
113441 ){
@@ -113301,11 +113452,11 @@
113452 ** the DEFAULT clause or the AS clause of a generated column.
113453 ** Return NULL if the column has no associated expression.
113454 */
113455 SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){
113456 if( pCol->iDflt==0 ) return 0;
113457 if( NEVER(!IsOrdinaryTable(pTab)) ) return 0;
113458 if( NEVER(pTab->u.tab.pDfltList==0) ) return 0;
113459 if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0;
113460 return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr;
113461 }
113462
@@ -113360,17 +113511,17 @@
113511 for(i=0; i<pTable->nCol; i++, pCol++){
113512 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
113513 sqlite3DbFree(db, pCol->zCnName);
113514 }
113515 sqlite3DbFree(db, pTable->aCol);
113516 if( IsOrdinaryTable(pTable) ){
113517 sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
113518 }
113519 if( db==0 || db->pnBytesFreed==0 ){
113520 pTable->aCol = 0;
113521 pTable->nCol = 0;
113522 if( IsOrdinaryTable(pTable) ){
113523 pTable->u.tab.pDfltList = 0;
113524 }
113525 }
113526 }
113527 }
@@ -114433,11 +114584,13 @@
114584 for(i=0; i<nTerm; i++){
114585 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
114586 assert( pCExpr!=0 );
114587 sqlite3StringToId(pCExpr);
114588 if( pCExpr->op==TK_ID ){
114589 const char *zCName;
114590 assert( !ExprHasProperty(pCExpr, EP_IntValue) );
114591 zCName = pCExpr->u.zToken;
114592 for(iCol=0; iCol<pTab->nCol; iCol++){
114593 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
114594 pCol = &pTab->aCol[iCol];
114595 makeColumnPartOfPrimaryKey(pParse, pCol);
114596 break;
@@ -114805,11 +114958,10 @@
114958 ** This is used to determine if the column number x appears in any of the
114959 ** first nCol entries of an index.
114960 */
114961 static int hasColumn(const i16 *aiCol, int nCol, int x){
114962 while( nCol-- > 0 ){
 
114963 if( x==*(aiCol++) ){
114964 return 1;
114965 }
114966 }
114967 return 0;
@@ -115181,11 +115333,11 @@
115333 **
115334 ** If the root page number is 1, that means this is the sqlite_schema
115335 ** table itself. So mark it read-only.
115336 */
115337 if( db->init.busy ){
115338 if( pSelect || (!IsOrdinaryTable(p) && db->init.newTnum) ){
115339 sqlite3ErrorMsg(pParse, "");
115340 return;
115341 }
115342 p->tnum = db->init.newTnum;
115343 if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
@@ -116146,10 +116298,11 @@
116298 pFKey = sqlite3DbMallocZero(db, nByte );
116299 if( pFKey==0 ){
116300 goto fk_end;
116301 }
116302 pFKey->pFrom = p;
116303 assert( IsOrdinaryTable(p) );
116304 pFKey->pNextFrom = p->u.tab.pFKey;
116305 z = (char*)&pFKey->aCol[nCol];
116306 pFKey->zTo = z;
116307 if( IN_RENAME_OBJECT ){
116308 sqlite3RenameTokenMap(pParse, (void*)z, pTo);
@@ -116211,11 +116364,11 @@
116364 pNextTo->pPrevTo = pFKey;
116365 }
116366
116367 /* Link the foreign key to the table as the last step.
116368 */
116369 assert( IsOrdinaryTable(p) );
116370 p->u.tab.pFKey = pFKey;
116371 pFKey = 0;
116372
116373 fk_end:
116374 sqlite3DbFree(db, pFKey);
@@ -116234,11 +116387,11 @@
116387 SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
116388 #ifndef SQLITE_OMIT_FOREIGN_KEY
116389 Table *pTab;
116390 FKey *pFKey;
116391 if( (pTab = pParse->pNewTable)==0 ) return;
116392 if( NEVER(!IsOrdinaryTable(pTab)) ) return;
116393 if( (pFKey = pTab->u.tab.pFKey)==0 ) return;
116394 assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
116395 pFKey->isDeferred = (u8)isDeferred;
116396 #endif
116397 }
@@ -116636,10 +116789,11 @@
116789 */
116790 for(i=0; i<pList->nExpr; i++){
116791 Expr *pExpr = pList->a[i].pExpr;
116792 assert( pExpr!=0 );
116793 if( pExpr->op==TK_COLLATE ){
116794 assert( !ExprHasProperty(pExpr, EP_IntValue) );
116795 nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
116796 }
116797 }
116798
116799 /*
@@ -116731,10 +116885,11 @@
116885 pIndex->aiColumn[i] = (i16)j;
116886 }
116887 zColl = 0;
116888 if( pListItem->pExpr->op==TK_COLLATE ){
116889 int nColl;
116890 assert( !ExprHasProperty(pListItem->pExpr, EP_IntValue) );
116891 zColl = pListItem->pExpr->u.zToken;
116892 nColl = sqlite3Strlen30(zColl) + 1;
116893 assert( nExtra>=nColl );
116894 memcpy(zExtra, zColl, nColl);
116895 zColl = zExtra;
@@ -117519,10 +117674,11 @@
117674 ** construct "indexed_opt" for details. */
117675 pItem->fg.notIndexed = 1;
117676 }else{
117677 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
117678 pItem->fg.isIndexedBy = 1;
117679 assert( pItem->fg.isCte==0 ); /* No collision on union u2 */
117680 }
117681 }
117682 }
117683
117684 /*
@@ -118499,10 +118655,11 @@
118655 int h, /* Hash of the name */
118656 const char *zFunc /* Name of function */
118657 ){
118658 FuncDef *p;
118659 for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){
118660 assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
118661 if( sqlite3StrICmp(p->zName, zFunc)==0 ){
118662 return p;
118663 }
118664 }
118665 return 0;
@@ -118520,10 +118677,11 @@
118677 FuncDef *pOther;
118678 const char *zName = aDef[i].zName;
118679 int nName = sqlite3Strlen30(zName);
118680 int h = SQLITE_FUNC_HASH(zName[0], nName);
118681 assert( zName[0]>='a' && zName[0]<='z' );
118682 assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN );
118683 pOther = sqlite3FunctionSearch(h, zName);
118684 if( pOther ){
118685 assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] );
118686 aDef[i].pNext = pOther->pNext;
118687 pOther->pNext = &aDef[i];
@@ -118911,10 +119069,11 @@
119069 ** and the SELECT subtree. */
119070 pSrc->a[0].pTab = 0;
119071 pSelectSrc = sqlite3SrcListDup(db, pSrc, 0);
119072 pSrc->a[0].pTab = pTab;
119073 if( pSrc->a[0].fg.isIndexedBy ){
119074 assert( pSrc->a[0].fg.isCte==0 );
119075 pSrc->a[0].u2.pIBIndex = 0;
119076 pSrc->a[0].fg.isIndexedBy = 0;
119077 sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy);
119078 }else if( pSrc->a[0].fg.isCte ){
119079 pSrc->a[0].u2.pCteUse->nUse++;
@@ -121495,11 +121654,15 @@
121654 if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
121655 pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC));
121656 /* pGCC is always non-NULL since groupConcatStep() will have always
121657 ** run frist to initialize it */
121658 if( ALWAYS(pGCC) ){
121659 int nVS;
121660 /* Must call sqlite3_value_text() to convert the argument into text prior
121661 ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */
121662 (void)sqlite3_value_text(argv[0]);
121663 nVS = sqlite3_value_bytes(argv[0]);
121664 pGCC->nAccum -= 1;
121665 if( pGCC->pnSepLengths!=0 ){
121666 assert(pGCC->nAccum >= 0);
121667 if( pGCC->nAccum>0 ){
121668 nVS += *pGCC->pnSepLengths;
@@ -121610,15 +121773,16 @@
121773 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
121774 FuncDef *pDef;
121775 int nExpr;
121776 assert( pExpr!=0 );
121777 assert( pExpr->op==TK_FUNCTION );
121778 assert( ExprUseXList(pExpr) );
121779 if( !pExpr->x.pList ){
121780 return 0;
121781 }
 
121782 nExpr = pExpr->x.pList->nExpr;
121783 assert( !ExprHasProperty(pExpr, EP_IntValue) );
121784 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
121785 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
121786 if( pDef==0 ) return 0;
121787 #endif
121788 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
@@ -121638,10 +121802,11 @@
121802 aWc[3] = 0;
121803 }else{
121804 Expr *pEscape = pExpr->x.pList->a[2].pExpr;
121805 char *zEscape;
121806 if( pEscape->op!=TK_STRING ) return 0;
121807 assert( !ExprHasProperty(pEscape, EP_IntValue) );
121808 zEscape = pEscape->u.zToken;
121809 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
121810 if( zEscape[0]==aWc[0] ) return 0;
121811 if( zEscape[0]==aWc[1] ) return 0;
121812 aWc[3] = zEscape[0];
@@ -122019,10 +122184,11 @@
122184 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
122185 printf("FUNC-HASH %02d:", i);
122186 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){
122187 int n = sqlite3Strlen30(p->zName);
122188 int h = p->zName[0] + n;
122189 assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
122190 printf(" %s(%d)", p->zName, h);
122191 }
122192 printf("\n");
122193 }
122194 }
@@ -122541,10 +122707,11 @@
122707 int iCursor, /* The open cursor on the table */
122708 i16 iCol /* The column that is wanted */
122709 ){
122710 Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
122711 if( pExpr ){
122712 assert( ExprUseYTab(pExpr) );
122713 pExpr->y.pTab = pTab;
122714 pExpr->iTable = iCursor;
122715 pExpr->iColumn = iCol;
122716 }
122717 return pExpr;
@@ -122751,17 +122918,16 @@
122918 ** the table from the database. Triggers are disabled while running this
122919 ** DELETE, but foreign key actions are not.
122920 */
122921 SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
122922 sqlite3 *db = pParse->db;
122923 if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){
122924 int iSkip = 0;
122925 Vdbe *v = sqlite3GetVdbe(pParse);
122926
122927 assert( v ); /* VDBE has already been allocated */
122928 assert( IsOrdinaryTable(pTab) );
 
122929 if( sqlite3FkReferences(pTab)==0 ){
122930 /* Search for a deferred foreign key constraint for which this table
122931 ** is the child table. If one cannot be found, return without
122932 ** generating any VDBE code. If one can be found, then jump over
122933 ** the entire DELETE if there are no outstanding deferred constraints
@@ -122921,17 +123087,17 @@
123087 /* Exactly one of regOld and regNew should be non-zero. */
123088 assert( (regOld==0)!=(regNew==0) );
123089
123090 /* If foreign-keys are disabled, this function is a no-op. */
123091 if( (db->flags&SQLITE_ForeignKeys)==0 ) return;
123092 if( !IsOrdinaryTable(pTab) ) return;
123093
123094 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
123095 zDb = db->aDb[iDb].zDbSName;
123096
123097 /* Loop through all the foreign key constraints for which pTab is the
123098 ** child table (the table that the foreign key definition is part of). */
 
123099 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){
123100 Table *pTo; /* Parent table of foreign key pFKey */
123101 Index *pIdx = 0; /* Index on key columns in pTo */
123102 int *aiFree = 0;
123103 int *aiCol;
@@ -123110,14 +123276,13 @@
123276 SQLITE_PRIVATE u32 sqlite3FkOldmask(
123277 Parse *pParse, /* Parse context */
123278 Table *pTab /* Table being modified */
123279 ){
123280 u32 mask = 0;
123281 if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123282 FKey *p;
123283 int i;
 
123284 for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){
123285 for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom);
123286 }
123287 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
123288 Index *pIdx = 0;
@@ -123164,11 +123329,11 @@
123329 int *aChange, /* Non-NULL for UPDATE operations */
123330 int chngRowid /* True for UPDATE that affects rowid */
123331 ){
123332 int eRet = 1; /* Value to return if bHaveFK is true */
123333 int bHaveFK = 0; /* If FK processing is required */
123334 if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){
123335 if( !aChange ){
123336 /* A DELETE operation. Foreign key processing is required if the
123337 ** table in question is either the child or parent table for any
123338 ** foreign key constraint. */
123339 bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey);
@@ -123452,11 +123617,11 @@
123617 */
123618 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
123619 FKey *pFKey; /* Iterator variable */
123620 FKey *pNext; /* Copy of pFKey->pNextFrom */
123621
123622 assert( IsOrdinaryTable(pTab) );
123623 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
123624 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
123625
123626 /* Remove the FK from the fkeyHash hash table. */
123627 if( !db || db->pnBytesFreed==0 ){
@@ -125711,10 +125876,11 @@
125876 ** (5) No FK constraint counters need to be updated if a conflict occurs.
125877 **
125878 ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row
125879 ** must be explicitly deleted in order to ensure any pre-update hook
125880 ** is invoked. */
125881 assert( IsOrdinaryTable(pTab) );
125882 #ifndef SQLITE_ENABLE_PREUPDATE_HOOK
125883 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
125884 && pPk==pIdx /* Condition 2 */
125885 && onError==OE_Replace /* Condition 1 */
125886 && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */
@@ -126391,11 +126557,13 @@
126557 /* Default values for second and subsequent columns need to match. */
126558 if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){
126559 Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol);
126560 Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol);
126561 assert( pDestExpr==0 || pDestExpr->op==TK_SPAN );
126562 assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) );
126563 assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN );
126564 assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) );
126565 if( (pDestExpr==0)!=(pSrcExpr==0)
126566 || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken,
126567 pSrcExpr->u.zToken)!=0)
126568 ){
126569 return 0; /* Default values must be the same for all columns */
@@ -126431,10 +126599,11 @@
126599 ** But the main beneficiary of the transfer optimization is the VACUUM
126600 ** command, and the VACUUM command disables foreign key constraints. So
126601 ** the extra complication to make this rule less restrictive is probably
126602 ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
126603 */
126604 assert( IsOrdinaryTable(pDest) );
126605 if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){
126606 return 0;
126607 }
126608 #endif
126609 if( (db->flags & SQLITE_CountRows)!=0 ){
@@ -129423,11 +129592,15 @@
129592 goto pragma_out;
129593 }
129594
129595 /* Locate the pragma in the lookup table */
129596 pPragma = pragmaLocate(zLeft);
129597 if( pPragma==0 ){
129598 /* IMP: R-43042-22504 No error messages are generated if an
129599 ** unknown pragma is issued. */
129600 goto pragma_out;
129601 }
129602
129603 /* Make sure the database schema is loaded if the pragma requires that */
129604 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
129605 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
129606 }
@@ -130073,10 +130246,18 @@
130246 if( sqlite3GetBoolean(zRight, 0) ){
130247 db->flags |= mask;
130248 }else{
130249 db->flags &= ~mask;
130250 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
130251 if( (mask & SQLITE_WriteSchema)!=0
130252 && sqlite3_stricmp(zRight, "reset")==0
130253 ){
130254 /* IMP: R-60817-01178 If the argument is "RESET" then schema
130255 ** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
130256 ** in addition, the schema is reloaded. */
130257 sqlite3ResetAllSchemasOfConnection(db);
130258 }
130259 }
130260
130261 /* Many of the flag-pragmas modify the code generated by the SQL
130262 ** compiler (eg. count_changes). So add an opcode to expire all
130263 ** compiled SQL statements after modifying a pragma value.
@@ -130113,10 +130294,11 @@
130294 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
130295 pParse->nMem = 7;
130296 sqlite3ViewGetColumnNames(pParse, pTab);
130297 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
130298 int isHidden = 0;
130299 const Expr *pColExpr;
130300 if( pCol->colFlags & COLFLAG_NOINSERT ){
130301 if( pPragma->iArg==0 ){
130302 nHidden++;
130303 continue;
130304 }
@@ -130133,20 +130315,20 @@
130315 }else if( pPk==0 ){
130316 k = 1;
130317 }else{
130318 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
130319 }
130320 pColExpr = sqlite3ColumnExpr(pTab,pCol);
130321 assert( pColExpr==0 || pColExpr->op==TK_SPAN || isHidden>=2 );
130322 assert( pColExpr==0 || !ExprHasProperty(pColExpr, EP_IntValue)
130323 || isHidden>=2 );
130324 sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi",
130325 i-nHidden,
130326 pCol->zCnName,
130327 sqlite3ColumnType(pCol,""),
130328 pCol->notNull ? 1 : 0,
130329 (isHidden>=2 || pColExpr==0) ? 0 : pColExpr->u.zToken,
 
130330 k,
130331 isHidden);
130332 }
130333 }
130334 }
@@ -130170,12 +130352,39 @@
130352 pParse->nMem = 6;
130353 sqlite3CodeVerifyNamedSchema(pParse, zDb);
130354 for(ii=0; ii<db->nDb; ii++){
130355 HashElem *k;
130356 Hash *pHash;
130357 int initNCol;
130358 if( zDb && sqlite3_stricmp(zDb, db->aDb[ii].zDbSName)!=0 ) continue;
130359
130360 /* Ensure that the Table.nCol field is initialized for all views
130361 ** and virtual tables. Each time we initialize a Table.nCol value
130362 ** for a table, that can potentially disrupt the hash table, so restart
130363 ** the initialization scan.
130364 */
130365 pHash = &db->aDb[ii].pSchema->tblHash;
130366 initNCol = sqliteHashCount(pHash);
130367 while( initNCol-- ){
130368 for(k=sqliteHashFirst(pHash); 1; k=sqliteHashNext(k) ){
130369 Table *pTab;
130370 if( k==0 ){ initNCol = 0; break; }
130371 pTab = sqliteHashData(k);
130372 if( pTab->nCol==0 ){
130373 char *zSql = sqlite3MPrintf(db, "SELECT*FROM\"%w\"", pTab->zName);
130374 if( zSql ){
130375 sqlite3_stmt *pDummy = 0;
130376 (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
130377 (void)sqlite3_finalize(pDummy);
130378 sqlite3DbFree(db, zSql);
130379 }
130380 pHash = &db->aDb[ii].pSchema->tblHash;
130381 break;
130382 }
130383 }
130384 }
130385
130386 for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){
130387 Table *pTab = sqliteHashData(k);
130388 const char *zType;
130389 if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue;
130390 if( IsView(pTab) ){
@@ -130326,15 +130535,17 @@
130535 FuncDef *p;
130536 int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0;
130537 pParse->nMem = 6;
130538 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
130539 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
130540 assert( p->funcFlags & SQLITE_FUNC_BUILTIN );
130541 pragmaFunclistLine(v, p, 1, showInternFunc);
130542 }
130543 }
130544 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
130545 p = (FuncDef*)sqliteHashData(j);
130546 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
130547 pragmaFunclistLine(v, p, 0, showInternFunc);
130548 }
130549 }
130550 break;
130551
@@ -130364,11 +130575,11 @@
130575 #ifndef SQLITE_OMIT_FOREIGN_KEY
130576 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
130577 FKey *pFK;
130578 Table *pTab;
130579 pTab = sqlite3FindTable(db, zRight, zDb);
130580 if( pTab && IsOrdinaryTable(pTab) ){
130581 pFK = pTab->u.tab.pFKey;
130582 if( pFK ){
130583 int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130584 int i = 0;
130585 pParse->nMem = 8;
@@ -130424,19 +130635,19 @@
130635 k = 0;
130636 }else{
130637 pTab = (Table*)sqliteHashData(k);
130638 k = sqliteHashNext(k);
130639 }
130640 if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue;
130641 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
130642 zDb = db->aDb[iDb].zDbSName;
130643 sqlite3CodeVerifySchema(pParse, iDb);
130644 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
130645 if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
130646 sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
130647 sqlite3VdbeLoadString(v, regResult, pTab->zName);
130648 assert( IsOrdinaryTable(pTab) );
130649 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130650 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130651 if( pParent==0 ) continue;
130652 pIdx = 0;
130653 sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
@@ -130455,11 +130666,11 @@
130666 }
130667 assert( pParse->nErr>0 || pFK==0 );
130668 if( pFK ) break;
130669 if( pParse->nTab<i ) pParse->nTab = i;
130670 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
130671 assert( IsOrdinaryTable(pTab) );
130672 for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){
130673 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
130674 pIdx = 0;
130675 aiCols = 0;
130676 if( pParent ){
@@ -130659,11 +130870,11 @@
130870 int loopTop;
130871 int iDataCur, iIdxCur;
130872 int r1 = -1;
130873 int bStrict;
130874
130875 if( !IsOrdinaryTable(pTab) ) continue;
130876 if( pObjTab && pObjTab!=pTab ) continue;
130877 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
130878 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
130879 1, 0, &iDataCur, &iIdxCur);
130880 /* reg[7] counts the number of entries in the table.
@@ -131254,16 +131465,16 @@
131465 ** in each index that it looks at. Return the new limit.
131466 */
131467 case PragTyp_ANALYSIS_LIMIT: {
131468 sqlite3_int64 N;
131469 if( zRight
131470 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */
131471 && N>=0
131472 ){
131473 db->nAnalysisLimit = (int)(N&0x7fffffff);
131474 }
131475 returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */
131476 break;
131477 }
131478
131479 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
131480 /*
@@ -133046,14 +133257,17 @@
133257 while( p ){
133258 ExprSetProperty(p, EP_FromJoin);
133259 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
133260 ExprSetVVAProperty(p, EP_NoReduce);
133261 p->iRightJoinTable = iTable;
133262 if( p->op==TK_FUNCTION ){
133263 assert( ExprUseXList(p) );
133264 if( p->x.pList ){
133265 int i;
133266 for(i=0; i<p->x.pList->nExpr; i++){
133267 sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133268 }
133269 }
133270 }
133271 sqlite3SetJoinExpr(p->pLeft, iTable);
133272 p = p->pRight;
133273 }
@@ -133072,14 +133286,17 @@
133286 ExprClearProperty(p, EP_FromJoin);
133287 }
133288 if( p->op==TK_COLUMN && p->iTable==iTable ){
133289 ExprClearProperty(p, EP_CanBeNull);
133290 }
133291 if( p->op==TK_FUNCTION ){
133292 assert( ExprUseXList(p) );
133293 if( p->x.pList ){
133294 int i;
133295 for(i=0; i<p->x.pList->nExpr; i++){
133296 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
133297 }
133298 }
133299 }
133300 unsetJoinExpr(p->pLeft, iTable);
133301 p = p->pRight;
133302 }
@@ -133590,13 +133807,17 @@
133807 ExprList *pExtra = 0;
133808 for(i=0; i<pEList->nExpr; i++){
133809 struct ExprList_item *pItem = &pEList->a[i];
133810 if( pItem->u.x.iOrderByCol==0 ){
133811 Expr *pExpr = pItem->pExpr;
133812 Table *pTab;
133813 if( pExpr->op==TK_COLUMN
133814 && pExpr->iColumn>=0
133815 && ALWAYS( ExprUseYTab(pExpr) )
133816 && (pTab = pExpr->y.pTab)!=0
133817 && IsOrdinaryTable(pTab)
133818 && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)!=0
133819 ){
133820 int j;
133821 for(j=0; j<nDefer; j++){
133822 if( pSort->aDefer[j].iCsr==pExpr->iTable ) break;
133823 }
@@ -133613,10 +133834,11 @@
133834 }
133835 for(k=0; k<nKey; k++){
133836 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
133837 if( pNew ){
133838 pNew->iTable = pExpr->iTable;
133839 assert( ExprUseYTab(pNew) );
133840 pNew->y.pTab = pExpr->y.pTab;
133841 pNew->iColumn = pPk ? pPk->aiColumn[k] : -1;
133842 pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew);
133843 }
133844 }
@@ -134461,11 +134683,11 @@
134683 ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
134684 ** branch below. */
134685 break;
134686 }
134687
134688 assert( pTab && ExprUseYTab(pExpr) && pExpr->y.pTab==pTab );
134689 if( pS ){
134690 /* The "table" is actually a sub-select or a view in the FROM clause
134691 ** of the SELECT statement. Return the declaration type and origin
134692 ** data for the result-set column of the sub-select.
134693 */
@@ -134521,13 +134743,15 @@
134743 /* The expression is a sub-select. Return the declaration type and
134744 ** origin info for the single column in the result set of the SELECT
134745 ** statement.
134746 */
134747 NameContext sNC;
134748 Select *pS;
134749 Expr *p;
134750 assert( ExprUseXSelect(pExpr) );
134751 pS = pExpr->x.pSelect;
134752 p = pS->pEList->a[0].pExpr;
134753 sNC.pSrcList = pS->pSrc;
134754 sNC.pNext = pNC;
134755 sNC.pParse = pNC->pParse;
134756 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);
134757 break;
@@ -134652,11 +134876,12 @@
134876 for(i=0; i<pEList->nExpr; i++){
134877 Expr *p = pEList->a[i].pExpr;
134878
134879 assert( p!=0 );
134880 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
134881 assert( p->op!=TK_COLUMN
134882 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
134883 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
134884 /* An AS clause always takes first priority */
134885 char *zName = pEList->a[i].zEName;
134886 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
134887 }else if( srcName && p->op==TK_COLUMN ){
@@ -134748,11 +134973,14 @@
134973 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
134974 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
134975 pColExpr = pColExpr->pRight;
134976 assert( pColExpr!=0 );
134977 }
134978 if( pColExpr->op==TK_COLUMN
134979 && ALWAYS( ExprUseYTab(pColExpr) )
134980 && (pTab = pColExpr->y.pTab)!=0
134981 ){
134982 /* For columns use the column name name */
134983 int iCol = pColExpr->iColumn;
134984 if( iCol<0 ) iCol = pTab->iPKey;
134985 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
134986 }else if( pColExpr->op==TK_ID ){
@@ -136330,11 +136558,11 @@
136558 if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){
136559 pExpr->iTable = pSubst->iNewTable;
136560 }
136561 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
136562 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
136563 if( ExprUseXSelect(pExpr) ){
136564 substSelect(pSubst, pExpr->x.pSelect, 1);
136565 }else{
136566 substExprList(pSubst, pExpr->x.pList);
136567 }
136568 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -137541,25 +137769,28 @@
137769 ** located but before their arguments have been subjected to aggregate
137770 ** analysis.
137771 */
137772 static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
137773 int eRet = WHERE_ORDERBY_NORMAL; /* Return value */
137774 ExprList *pEList; /* Arguments to agg function */
137775 const char *zFunc; /* Name of aggregate function pFunc */
137776 ExprList *pOrderBy;
137777 u8 sortFlags = 0;
137778
137779 assert( *ppMinMax==0 );
137780 assert( pFunc->op==TK_AGG_FUNCTION );
137781 assert( !IsWindowFunc(pFunc) );
137782 assert( ExprUseXList(pFunc) );
137783 pEList = pFunc->x.pList;
137784 if( pEList==0
137785 || pEList->nExpr!=1
137786 || ExprHasProperty(pFunc, EP_WinFunc)
137787 || OptimizationDisabled(db, SQLITE_MinMaxOpt)
137788 ){
137789 return eRet;
137790 }
137791 assert( !ExprHasProperty(pFunc, EP_IntValue) );
137792 zFunc = pFunc->u.zToken;
137793 if( sqlite3StrICmp(zFunc, "min")==0 ){
137794 eRet = WHERE_ORDERBY_MIN;
137795 if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){
137796 sortFlags = KEYINFO_ORDER_BIGNULL;
@@ -137632,10 +137863,11 @@
137863 if( !pIdx ){
137864 sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0);
137865 pParse->checkSchema = 1;
137866 return SQLITE_ERROR;
137867 }
137868 assert( pFrom->fg.isCte==0 );
137869 pFrom->u2.pIBIndex = pIdx;
137870 return SQLITE_OK;
137871 }
137872
137873 /*
@@ -137889,10 +138121,14 @@
138121 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
138122 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
138123 if( db->mallocFailed ) return 2;
138124 pFrom->pSelect->selFlags |= SF_CopyCte;
138125 assert( pFrom->pSelect );
138126 if( pFrom->fg.isIndexedBy ){
138127 sqlite3ErrorMsg(pParse, "no such index: \"%s\"", pFrom->u1.zIndexedBy);
138128 return 2;
138129 }
138130 pFrom->fg.isCte = 1;
138131 pFrom->u2.pCteUse = pCteUse;
138132 pCteUse->nUse++;
138133 if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){
138134 pCteUse->eM10d = M10d_Yes;
@@ -138524,11 +138760,11 @@
138760 #endif
138761 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
138762 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
138763 if( pFunc->iDistinct>=0 ){
138764 Expr *pE = pFunc->pFExpr;
138765 assert( ExprUseXList(pE) );
138766 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
138767 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
138768 "argument");
138769 pFunc->iDistinct = -1;
138770 }else{
@@ -138549,12 +138785,13 @@
138785 static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
138786 Vdbe *v = pParse->pVdbe;
138787 int i;
138788 struct AggInfo_func *pF;
138789 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138790 ExprList *pList;
138791 assert( ExprUseXList(pF->pFExpr) );
138792 pList = pF->pFExpr->x.pList;
138793 sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
138794 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
138795 }
138796 }
138797
@@ -138584,13 +138821,14 @@
138821 pAggInfo->directMode = 1;
138822 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
138823 int nArg;
138824 int addrNext = 0;
138825 int regAgg;
138826 ExprList *pList;
138827 assert( ExprUseXList(pF->pFExpr) );
138828 assert( !IsWindowFunc(pF->pFExpr) );
138829 pList = pF->pFExpr->x.pList;
138830 if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
138831 Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
138832 if( pAggInfo->nAccumulator
138833 && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
138834 && regAcc
@@ -138832,11 +139070,13 @@
139070 if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
139071 if( p->pWhere ) return 0;
139072 if( p->pGroupBy ) return 0;
139073 pExpr = p->pEList->a[0].pExpr;
139074 if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
139075 assert( ExprUseUToken(pExpr) );
139076 if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
139077 assert( ExprUseXList(pExpr) );
139078 if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */
139079 if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */
139080 pSub = p->pSrc->a[0].pSelect;
139081 if( pSub==0 ) return 0; /* The FROM is a subquery */
139082 if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */
@@ -139647,11 +139887,11 @@
139887 }else{
139888 minMaxFlag = WHERE_ORDERBY_NORMAL;
139889 }
139890 for(i=0; i<pAggInfo->nFunc; i++){
139891 Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
139892 assert( ExprUseXList(pExpr) );
139893 sNC.ncFlags |= NC_InAggFunc;
139894 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
139895 #ifndef SQLITE_OMIT_WINDOWFUNC
139896 assert( !IsWindowFunc(pExpr) );
139897 if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -139702,11 +139942,13 @@
139942 u16 distFlag = 0;
139943 int eDist = WHERE_DISTINCT_NOOP;
139944
139945 if( pAggInfo->nFunc==1
139946 && pAggInfo->aFunc[0].iDistinct>=0
139947 && ALWAYS(pAggInfo->aFunc[0].pFExpr!=0)
139948 && ALWAYS(ExprUseXList(pAggInfo->aFunc[0].pFExpr))
139949 && pAggInfo->aFunc[0].pFExpr->x.pList!=0
139950 ){
139951 Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr;
139952 pExpr = sqlite3ExprDup(db, pExpr, 0);
139953 pDistinct = sqlite3ExprListDup(db, pGroupBy, 0);
139954 pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr);
@@ -140023,10 +140265,11 @@
140265 if( i==pAggInfo->nFunc ){
140266 regAcc = ++pParse->nMem;
140267 sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc);
140268 }
140269 }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){
140270 assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) );
140271 pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList;
140272 distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0;
140273 }
140274
140275 /* This case runs if the aggregate has no GROUP BY clause. The
@@ -144048,11 +144291,14 @@
144291 ** Except, if argument db is not NULL, then the entry associated with
144292 ** connection db is left in the p->u.vtab.p list.
144293 */
144294 static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){
144295 VTable *pRet = 0;
144296 VTable *pVTable;
144297
144298 assert( IsVirtual(p) );
144299 pVTable = p->u.vtab.p;
144300 p->u.vtab.p = 0;
144301
144302 /* Assert that the mutex (if any) associated with the BtShared database
144303 ** that contains table p is held by the caller. See header comments
144304 ** above function sqlite3VtabUnlockList() for an explanation of why
@@ -144156,10 +144402,11 @@
144402 ** structure being xDisconnected and free). Any other VTable structures
144403 ** in the list are moved to the sqlite3.pDisconnect list of the associated
144404 ** database connection.
144405 */
144406 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
144407 assert( IsVirtual(p) );
144408 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
144409 if( p->u.vtab.azArg ){
144410 int i;
144411 for(i=0; i<p->u.vtab.nArg; i++){
144412 if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
@@ -144173,13 +144420,16 @@
144420 ** The string is not copied - the pointer is stored. The
144421 ** string will be freed automatically when the table is
144422 ** deleted.
144423 */
144424 static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
144425 sqlite3_int64 nBytes;
144426 char **azModuleArg;
144427 sqlite3 *db = pParse->db;
144428
144429 assert( IsVirtual(pTable) );
144430 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg);
144431 if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
144432 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
144433 }
144434 azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes);
144435 if( azModuleArg==0 ){
@@ -144262,10 +144512,11 @@
144512 SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
144513 Table *pTab = pParse->pNewTable; /* The table being constructed */
144514 sqlite3 *db = pParse->db; /* The database connection */
144515
144516 if( pTab==0 ) return;
144517 assert( IsVirtual(pTab) );
144518 addArgumentToVtab(pParse);
144519 pParse->sArg.z = 0;
144520 if( pTab->u.vtab.nArg<1 ) return;
144521
144522 /* If the CREATE VIRTUAL TABLE statement is being entered for the
@@ -144379,17 +144630,20 @@
144630 char **pzErr
144631 ){
144632 VtabCtx sCtx;
144633 VTable *pVTable;
144634 int rc;
144635 const char *const*azArg;
144636 int nArg = pTab->u.vtab.nArg;
144637 char *zErr = 0;
144638 char *zModuleName;
144639 int iDb;
144640 VtabCtx *pCtx;
144641
144642 assert( IsVirtual(pTab) );
144643 azArg = (const char *const*)pTab->u.vtab.azArg;
144644
144645 /* Check that the virtual-table is not already being initialized */
144646 for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){
144647 if( pCtx->pTab==pTab ){
144648 *pzErr = sqlite3MPrintf(db,
144649 "vtable constructor called recursively: %s", pTab->zName
@@ -144713,11 +144967,11 @@
144967 SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){
144968 int rc = SQLITE_OK;
144969 Table *pTab;
144970
144971 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName);
144972 if( pTab!=0 && ALWAYS(IsVirtual(pTab)) && ALWAYS(pTab->u.vtab.p!=0) ){
144973 VTable *p;
144974 int (*xDestroy)(sqlite3_vtab *);
144975 for(p=pTab->u.vtab.p; p; p=p->pNext){
144976 assert( p->pVtab );
144977 if( p->pVtab->nRef>0 ){
@@ -144946,10 +145200,11 @@
145200 int rc = 0;
145201
145202 /* Check to see the left operand is a column in a virtual table */
145203 if( NEVER(pExpr==0) ) return pDef;
145204 if( pExpr->op!=TK_COLUMN ) return pDef;
145205 assert( ExprUseYTab(pExpr) );
145206 pTab = pExpr->y.pTab;
145207 if( pTab==0 ) return pDef;
145208 if( !IsVirtual(pTab) ) return pDef;
145209 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
145210 assert( pVtab!=0 );
@@ -145254,11 +145509,11 @@
145509 int iBase; /* Base register of multi-key index record */
145510 int nPrefix; /* Number of prior entires in the key */
145511 u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */
145512 } *aInLoop; /* Information about each nested IN operator */
145513 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
145514 Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */
145515 } u;
145516 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
145517 Bitmask notReady; /* FROM entries not usable at this level */
145518 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
145519 int addrVisit; /* Address at which row is visited */
@@ -146182,20 +146437,27 @@
146437 ){
146438 sqlite3 *db = pParse->db;
146439 Expr *pNew;
146440 pNew = sqlite3ExprDup(db, pX, 0);
146441 if( db->mallocFailed==0 ){
146442 ExprList *pOrigRhs; /* Original unmodified RHS */
146443 ExprList *pOrigLhs; /* Original unmodified LHS */
146444 ExprList *pRhs = 0; /* New RHS after modifications */
146445 ExprList *pLhs = 0; /* New LHS after mods */
146446 int i; /* Loop counter */
146447 Select *pSelect; /* Pointer to the SELECT on the RHS */
146448
146449 assert( ExprUseXSelect(pNew) );
146450 pOrigRhs = pNew->x.pSelect->pEList;
146451 assert( pNew->pLeft!=0 );
146452 assert( ExprUseXList(pNew->pLeft) );
146453 pOrigLhs = pNew->pLeft->x.pList;
146454 for(i=iEq; i<pLoop->nLTerm; i++){
146455 if( pLoop->aLTerm[i]->pExpr==pX ){
146456 int iField;
146457 assert( (pLoop->aLTerm[i]->eOperator & (WO_OR|WO_AND))==0 );
146458 iField = pLoop->aLTerm[i]->u.x.iField - 1;
146459 if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */
146460 pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr);
146461 pOrigRhs->a[iField].pExpr = 0;
146462 assert( pOrigLhs->a[iField].pExpr!=0 );
146463 pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr);
@@ -146306,11 +146568,11 @@
146568 assert( pLoop->aLTerm[i]!=0 );
146569 if( pLoop->aLTerm[i]->pExpr==pX ) nEq++;
146570 }
146571
146572 iTab = 0;
146573 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
146574 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
146575 }else{
146576 sqlite3 *db = pParse->db;
146577 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
146578
@@ -146328,12 +146590,12 @@
146590 bRev = !bRev;
146591 }
146592 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
146593 VdbeCoverageIf(v, bRev);
146594 VdbeCoverageIf(v, !bRev);
146595
146596 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
 
146597 pLoop->wsFlags |= WHERE_IN_ABLE;
146598 if( pLevel->u.in.nIn==0 ){
146599 pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse);
146600 }
146601 if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){
@@ -146871,21 +147133,23 @@
147133 */
147134 static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
147135 assert( nReg>0 );
147136 if( p && sqlite3ExprIsVector(p) ){
147137 #ifndef SQLITE_OMIT_SUBQUERY
147138 if( ExprUseXSelect(p) ){
147139 Vdbe *v = pParse->pVdbe;
147140 int iSelect;
147141 assert( p->op==TK_SELECT );
147142 iSelect = sqlite3CodeSubselect(pParse, p);
147143 sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
147144 }else
147145 #endif
147146 {
147147 int i;
147148 const ExprList *pList;
147149 assert( ExprUseXList(p) );
147150 pList = p->x.pList;
147151 assert( nReg<=pList->nExpr );
147152 for(i=0; i<nReg; i++){
147153 sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i);
147154 }
147155 }
@@ -146934,14 +147198,14 @@
147198 preserveExpr(pX, pExpr);
147199 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
147200 pExpr->op = TK_COLUMN;
147201 pExpr->iTable = pX->iIdxCur;
147202 pExpr->iColumn = pX->iIdxCol;
 
147203 testcase( ExprHasProperty(pExpr, EP_Skip) );
147204 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
147205 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
147206 pExpr->y.pTab = 0;
147207 return WRC_Prune;
147208 }else{
147209 return WRC_Continue;
147210 }
147211 }
@@ -146952,11 +147216,11 @@
147216 */
147217 static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
147218 if( pExpr->op==TK_COLUMN ){
147219 IdxExprTrans *pX = p->u.pIdxTrans;
147220 if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
147221 assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 );
147222 preserveExpr(pX, pExpr);
147223 pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
147224 pExpr->iTable = pX->iIdxCur;
147225 pExpr->iColumn = pX->iIdxCol;
147226 pExpr->y.pTab = 0;
@@ -147189,11 +147453,16 @@
147453 ** the u.vtab.idxStr. NULL it out to prevent a use-after-free */
147454 if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0;
147455 pLevel->p1 = iCur;
147456 pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext;
147457 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
147458 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
147459 if( pLoop->wsFlags & WHERE_IN_ABLE ){
147460 iIn = pLevel->u.in.nIn;
147461 }else{
147462 iIn = 0;
147463 }
147464 for(j=nConstraint-1; j>=0; j--){
147465 pTerm = pLoop->aLTerm[j];
147466 if( (pTerm->eOperator & WO_IN)!=0 ) iIn--;
147467 if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){
147468 disableTerm(pLevel, pTerm);
@@ -148078,11 +148347,14 @@
148347 }
148348 sqlite3ExprDelete(db, pDelete);
148349 }
148350 }
148351 ExplainQueryPlanPop(pParse);
148352 assert( pLevel->pWLoop==pLoop );
148353 assert( (pLoop->wsFlags & WHERE_MULTI_OR)!=0 );
148354 assert( (pLoop->wsFlags & WHERE_IN_ABLE)==0 );
148355 pLevel->u.pCoveringIdx = pCov;
148356 if( pCov ) pLevel->iIdxCur = iCovCur;
148357 if( pAndExpr ){
148358 pAndExpr->pLeft = 0;
148359 sqlite3ExprDelete(db, pAndExpr);
148360 }
@@ -148222,16 +148494,17 @@
148494 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
148495 }
148496 #endif
148497 assert( !ExprHasProperty(pE, EP_FromJoin) );
148498 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
148499 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
148500 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
148501 WO_EQ|WO_IN|WO_IS, 0);
148502 if( pAlt==0 ) continue;
148503 if( pAlt->wtFlags & (TERM_CODED) ) continue;
148504 if( (pAlt->eOperator & WO_IN)
148505 && ExprUseXSelect(pAlt->pExpr)
148506 && (pAlt->pExpr->x.pSelect->pEList->nExpr>1)
148507 ){
148508 continue;
148509 }
148510 testcase( pAlt->eOperator & WO_EQ );
@@ -148476,10 +148749,11 @@
148749 return 0;
148750 }
148751 #ifdef SQLITE_EBCDIC
148752 if( *pnoCase ) return 0;
148753 #endif
148754 assert( ExprUseXList(pExpr) );
148755 pList = pExpr->x.pList;
148756 pLeft = pList->a[1].pExpr;
148757
148758 pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr);
148759 op = pRight->op;
@@ -148491,11 +148765,12 @@
148765 z = sqlite3_value_text(pVal);
148766 }
148767 sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
148768 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
148769 }else if( op==TK_STRING ){
148770 assert( !ExprHasProperty(pRight, EP_IntValue) );
148771 z = (u8*)pRight->u.zToken;
148772 }
148773 if( z ){
148774
148775 /* Count the number of prefix characters prior to the first wildcard */
148776 cnt = 0;
@@ -148520,11 +148795,13 @@
148795
148796 /* Get the pattern prefix. Remove all escapes from the prefix. */
148797 pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
148798 if( pPrefix ){
148799 int iFrom, iTo;
148800 char *zNew;
148801 assert( !ExprHasProperty(pPrefix, EP_IntValue) );
148802 zNew = pPrefix->u.zToken;
148803 zNew[cnt] = 0;
148804 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
148805 if( zNew[iFrom]==wc[3] ) iFrom++;
148806 zNew[iTo++] = zNew[iFrom];
148807 }
@@ -148544,11 +148821,13 @@
148821 ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975
148822 ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a
148823 */
148824 if( pLeft->op!=TK_COLUMN
148825 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
148826 || (ALWAYS( ExprUseYTab(pLeft) )
148827 && pLeft->y.pTab
148828 && IsVirtual(pLeft->y.pTab)) /* Might be numeric */
148829 ){
148830 int isNum;
148831 double rDummy;
148832 isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8);
148833 if( isNum<=0 ){
@@ -148572,10 +148851,11 @@
148851 /* If the RHS pattern is a bound parameter, make arrangements to
148852 ** reprepare the statement when that parameter is rebound */
148853 if( op==TK_VARIABLE ){
148854 Vdbe *v = pParse->pVdbe;
148855 sqlite3VdbeSetVarmask(v, pRight->iColumn);
148856 assert( !ExprHasProperty(pRight, EP_IntValue) );
148857 if( *pisComplete && pRight->u.zToken[1] ){
148858 /* If the rhs of the LIKE expression is a variable, and the current
148859 ** value of the variable means there is no need to invoke the LIKE
148860 ** function, then no OP_Variable will be added to the program.
148861 ** This causes problems for the sqlite3_bind_parameter_name()
@@ -148645,10 +148925,11 @@
148925 };
148926 ExprList *pList;
148927 Expr *pCol; /* Column reference */
148928 int i;
148929
148930 assert( ExprUseXList(pExpr) );
148931 pList = pExpr->x.pList;
148932 if( pList==0 || pList->nExpr!=2 ){
148933 return 0;
148934 }
148935
@@ -148658,13 +148939,15 @@
148939 **
148940 ** vtab_column MATCH expression
148941 ** MATCH(expression,vtab_column)
148942 */
148943 pCol = pList->a[1].pExpr;
148944 assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148945 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148946 if( ExprIsVtab(pCol) ){
148947 for(i=0; i<ArraySize(aOp); i++){
148948 assert( !ExprHasProperty(pExpr, EP_IntValue) );
148949 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
148950 *peOp2 = aOp[i].eOp2;
148951 *ppRight = pList->a[0].pExpr;
148952 *ppLeft = pCol;
148953 return 1;
@@ -148681,20 +148964,22 @@
148964 ** Historically, xFindFunction expected to see lower-case function
148965 ** names. But for this use case, xFindFunction is expected to deal
148966 ** with function names in an arbitrary case.
148967 */
148968 pCol = pList->a[0].pExpr;
148969 assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
148970 testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
148971 if( ExprIsVtab(pCol) ){
148972 sqlite3_vtab *pVtab;
148973 sqlite3_module *pMod;
148974 void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
148975 void *pNotUsed;
148976 pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
148977 assert( pVtab!=0 );
148978 assert( pVtab->pModule!=0 );
148979 assert( !ExprHasProperty(pExpr, EP_IntValue) );
148980 pMod = (sqlite3_module *)pVtab->pModule;
148981 if( pMod->xFindFunction!=0 ){
148982 i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
148983 if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
148984 *peOp2 = i;
148985 *ppRight = pList->a[1].pExpr;
@@ -148705,14 +148990,16 @@
148990 }
148991 }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
148992 int res = 0;
148993 Expr *pLeft = pExpr->pLeft;
148994 Expr *pRight = pExpr->pRight;
148995 assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
148996 testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
148997 if( ExprIsVtab(pLeft) ){
148998 res++;
148999 }
149000 assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
149001 testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
149002 if( pRight && ExprIsVtab(pRight) ){
149003 res++;
149004 SWAP(Expr*, pLeft, pRight);
149005 }
@@ -148961,10 +149248,11 @@
149248 int j;
149249 Bitmask b = 0;
149250 pOrTerm->u.pAndInfo = pAndInfo;
149251 pOrTerm->wtFlags |= TERM_ANDINFO;
149252 pOrTerm->eOperator = WO_AND;
149253 pOrTerm->leftCursor = -1;
149254 pAndWC = &pAndInfo->wc;
149255 memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic));
149256 sqlite3WhereClauseInit(pAndWC, pWC->pWInfo);
149257 sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND);
149258 sqlite3WhereExprAnalyze(pSrc, pAndWC);
@@ -149003,15 +149291,14 @@
149291 /*
149292 ** Record the set of tables that satisfy case 3. The set might be
149293 ** empty.
149294 */
149295 pOrInfo->indexable = indexable;
149296 pTerm->eOperator = WO_OR;
149297 pTerm->leftCursor = -1;
149298 if( indexable ){
 
149299 pWC->hasOr = 1;
 
 
149300 }
149301
149302 /* For a two-way OR, attempt to implementation case 2.
149303 */
149304 if( indexable && pOrWc->nTerm==2 ){
@@ -149080,10 +149367,11 @@
149367 testcase( pOrTerm->wtFlags & TERM_COPIED );
149368 testcase( pOrTerm->wtFlags & TERM_VIRTUAL );
149369 assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) );
149370 continue;
149371 }
149372 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149373 iColumn = pOrTerm->u.x.leftColumn;
149374 iCursor = pOrTerm->leftCursor;
149375 pLeft = pOrTerm->pExpr->pLeft;
149376 break;
149377 }
@@ -149100,10 +149388,11 @@
149388 /* We have found a candidate table and column. Check to see if that
149389 ** table and column is common to every term in the OR clause */
149390 okToChngToIN = 1;
149391 for(; i>=0 && okToChngToIN; i--, pOrTerm++){
149392 assert( pOrTerm->eOperator & WO_EQ );
149393 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149394 if( pOrTerm->leftCursor!=iCursor ){
149395 pOrTerm->wtFlags &= ~TERM_OR_OK;
149396 }else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR
149397 && sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1)
149398 )){
@@ -149136,10 +149425,11 @@
149425 Expr *pNew; /* The complete IN operator */
149426
149427 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
149428 if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue;
149429 assert( pOrTerm->eOperator & WO_EQ );
149430 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
149431 assert( pOrTerm->leftCursor==iCursor );
149432 assert( pOrTerm->u.x.leftColumn==iColumn );
149433 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
149434 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
149435 pLeft = pOrTerm->pExpr->pLeft;
@@ -149148,11 +149438,11 @@
149438 pDup = sqlite3ExprDup(db, pLeft, 0);
149439 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
149440 if( pNew ){
149441 int idxNew;
149442 transferJoinMarkings(pNew, pExpr);
149443 assert( ExprUseXList(pNew) );
149444 pNew->x.pList = pList;
149445 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
149446 testcase( idxNew==0 );
149447 exprAnalyze(pSrc, pWC, idxNew);
149448 /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */
@@ -149276,10 +149566,11 @@
149566 ** on the first element of the vector. */
149567 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
149568 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
149569 assert( op<=TK_GE );
149570 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
149571 assert( ExprUseXList(pExpr) );
149572 pExpr = pExpr->x.pList->a[0].pExpr;
149573
149574 }
149575
149576 if( pExpr->op==TK_COLUMN ){
@@ -149342,11 +149633,11 @@
149633 prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft);
149634 op = pExpr->op;
149635 if( op==TK_IN ){
149636 assert( pExpr->pRight==0 );
149637 if( sqlite3ExprCheckIN(pParse, pExpr) ) return;
149638 if( ExprUseXSelect(pExpr) ){
149639 pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect);
149640 }else{
149641 pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList);
149642 }
149643 }else if( op==TK_ISNULL ){
@@ -149378,15 +149669,17 @@
149669 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
149670
149671 if( pTerm->u.x.iField>0 ){
149672 assert( op==TK_IN );
149673 assert( pLeft->op==TK_VECTOR );
149674 assert( ExprUseXList(pLeft) );
149675 pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr;
149676 }
149677
149678 if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
149679 pTerm->leftCursor = aiCurCol[0];
149680 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149681 pTerm->u.x.leftColumn = aiCurCol[1];
149682 pTerm->eOperator = operatorMask(op) & opMask;
149683 }
149684 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
149685 if( pRight
@@ -149420,10 +149713,11 @@
149713 pDup = pExpr;
149714 pNew = pTerm;
149715 }
149716 pNew->wtFlags |= exprCommute(pParse, pDup);
149717 pNew->leftCursor = aiCurCol[0];
149718 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
149719 pNew->u.x.leftColumn = aiCurCol[1];
149720 testcase( (prereqLeft | extraRight) != prereqLeft );
149721 pNew->prereqRight = prereqLeft | extraRight;
149722 pNew->prereqAll = prereqAll;
149723 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
@@ -149430,10 +149724,11 @@
149724 }else
149725 if( op==TK_ISNULL
149726 && !ExprHasProperty(pExpr,EP_FromJoin)
149727 && 0==sqlite3ExprCanBeNull(pLeft)
149728 ){
149729 assert( !ExprHasProperty(pExpr, EP_IntValue) );
149730 pExpr->op = TK_TRUEFALSE;
149731 pExpr->u.zToken = "false";
149732 ExprSetProperty(pExpr, EP_IsFalse);
149733 pTerm->prereqAll = 0;
149734 pTerm->eOperator = 0;
@@ -149455,13 +149750,15 @@
149750 ** term. That means that if the BETWEEN term is coded, the children are
149751 ** skipped. Or, if the children are satisfied by an index, the original
149752 ** BETWEEN term is skipped.
149753 */
149754 else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){
149755 ExprList *pList;
149756 int i;
149757 static const u8 ops[] = {TK_GE, TK_LE};
149758 assert( ExprUseXList(pExpr) );
149759 pList = pExpr->x.pList;
149760 assert( pList!=0 );
149761 assert( pList->nExpr==2 );
149762 for(i=0; i<2; i++){
149763 Expr *pNewExpr;
149764 int idxNew;
@@ -149550,12 +149847,16 @@
149847 int idxNew1;
149848 int idxNew2;
149849 const char *zCollSeqName; /* Name of collating sequence */
149850 const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
149851
149852 assert( ExprUseXList(pExpr) );
149853 pLeft = pExpr->x.pList->a[1].pExpr;
149854 pStr2 = sqlite3ExprDup(db, pStr1, 0);
149855 assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) );
149856 assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) );
149857
149858
149859 /* Convert the lower bound to upper-case and the upper bound to
149860 ** lower-case (upper-case is less than lower-case in ASCII) so that
149861 ** the range constraints also work for BLOBs
149862 */
@@ -149651,10 +149952,11 @@
149952 ** not use window functions.
149953 */
149954 else if( pExpr->op==TK_IN
149955 && pTerm->u.x.iField==0
149956 && pExpr->pLeft->op==TK_VECTOR
149957 && ALWAYS( ExprUseXSelect(pExpr) )
149958 && pExpr->x.pSelect->pPrior==0
149959 #ifndef SQLITE_OMIT_WINDOWFUNC
149960 && pExpr->x.pSelect->pWin==0
149961 #endif
149962 && pWC->op==TK_AND
@@ -149814,18 +150116,19 @@
150116 mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0;
150117 if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft);
150118 if( p->pRight ){
150119 mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight);
150120 assert( p->x.pList==0 );
150121 }else if( ExprUseXSelect(p) ){
150122 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
150123 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
150124 }else if( p->x.pList ){
150125 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
150126 }
150127 #ifndef SQLITE_OMIT_WINDOWFUNC
150128 if( (p->op==TK_FUNCTION || p->op==TK_AGG_FUNCTION) && ExprUseYWin(p) ){
150129 assert( p->y.pWin!=0 );
150130 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
150131 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
150132 mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter);
150133 }
150134 #endif
@@ -149896,10 +150199,11 @@
150199 }
150200 pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
150201 if( pColRef==0 ) return;
150202 pColRef->iTable = pItem->iCursor;
150203 pColRef->iColumn = k++;
150204 assert( ExprUseYTab(pColRef) );
150205 pColRef->y.pTab = pTab;
150206 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
150207 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
150208 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
150209 if( pItem->fg.jointype & JT_LEFT ){
@@ -150197,12 +150501,14 @@
150501 pWC = pScan->pWC;
150502 while(1){
150503 iColumn = pScan->aiColumn[pScan->iEquiv-1];
150504 iCur = pScan->aiCur[pScan->iEquiv-1];
150505 assert( pWC!=0 );
150506 assert( iCur>=0 );
150507 do{
150508 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
150509 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 );
150510 if( pTerm->leftCursor==iCur
150511 && pTerm->u.x.leftColumn==iColumn
150512 && (iColumn!=XN_EXPR
150513 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
150514 pScan->pIdxExpr,iCur)==0)
@@ -150638,10 +150944,11 @@
150944 ** the RHS of a LEFT JOIN. Such a term can only be used if it is from
150945 ** the ON clause. */
150946 return 0;
150947 }
150948 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
150949 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
150950 if( pTerm->u.x.leftColumn<0 ) return 0;
150951 aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity;
150952 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
150953 testcase( pTerm->pExpr->op==TK_IS );
150954 return 1;
@@ -150710,12 +151017,15 @@
151017 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
151018 pPartial = sqlite3ExprAnd(pParse, pPartial,
151019 sqlite3ExprDup(pParse->db, pExpr, 0));
151020 }
151021 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
151022 int iCol;
151023 Bitmask cMask;
151024 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151025 iCol = pTerm->u.x.leftColumn;
151026 cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151027 testcase( iCol==BMS );
151028 testcase( iCol==BMS-1 );
151029 if( !sentWarning ){
151030 sqlite3_log(SQLITE_WARNING_AUTOINDEX,
151031 "automatic index on %s(%s)", pTable->zName,
@@ -150763,12 +151073,15 @@
151073 pIdx->pTable = pTable;
151074 n = 0;
151075 idxCols = 0;
151076 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
151077 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
151078 int iCol;
151079 Bitmask cMask;
151080 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151081 iCol = pTerm->u.x.leftColumn;
151082 cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
151083 testcase( iCol==BMS-1 );
151084 testcase( iCol==BMS );
151085 if( (idxCols & cMask)==0 ){
151086 Expr *pX = pTerm->pExpr;
151087 idxCols |= cMask;
@@ -150891,10 +151204,11 @@
151204 testcase( pTerm->eOperator & WO_ISNULL );
151205 testcase( pTerm->eOperator & WO_IS );
151206 testcase( pTerm->eOperator & WO_ALL );
151207 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
151208 if( pTerm->wtFlags & TERM_VNULL ) continue;
151209 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151210 assert( pTerm->u.x.leftColumn>=(-1) );
151211 nTerm++;
151212 }
151213
151214 /* If the ORDER BY clause contains only columns in the current
@@ -150951,10 +151265,11 @@
151265 if( (pSrc->fg.jointype & JT_LEFT)!=0
151266 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
151267 ){
151268 continue;
151269 }
151270 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151271 assert( pTerm->u.x.leftColumn>=(-1) );
151272 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
151273 pIdxCons[j].iTermOffset = i;
151274 op = pTerm->eOperator & WO_ALL;
151275 if( op==WO_IN ) op = WO_EQ;
@@ -151714,10 +152029,11 @@
152029 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
152030 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
152031 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
152032 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
152033 if( pTerm->eOperator & WO_SINGLE ){
152034 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
152035 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
152036 pTerm->leftCursor, pTerm->u.x.leftColumn);
152037 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){
152038 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx",
152039 pTerm->u.pOrInfo->indexable);
@@ -151731,11 +152047,11 @@
152047 ** shown about each Term */
152048 if( sqlite3WhereTrace & 0x10000 ){
152049 sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx",
152050 pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight);
152051 }
152052 if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){
152053 sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField);
152054 }
152055 if( pTerm->iParent>=0 ){
152056 sqlite3DebugPrintf(" iParent=%d", pTerm->iParent);
152057 }
@@ -151895,11 +152211,12 @@
152211 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
152212 int i;
152213 assert( pWInfo!=0 );
152214 for(i=0; i<pWInfo->nLevel; i++){
152215 WhereLevel *pLevel = &pWInfo->a[i];
152216 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE)!=0 ){
152217 assert( (pLevel->pWLoop->wsFlags & WHERE_MULTI_OR)==0 );
152218 sqlite3DbFree(db, pLevel->u.in.aInLoop);
152219 }
152220 }
152221 sqlite3WhereClauseClear(&pWInfo->sWC);
152222 while( pWInfo->pLoops ){
@@ -152330,13 +152647,16 @@
152647 /* Test if comparison i of pTerm is compatible with column (i+nEq)
152648 ** of the index. If not, exit the loop. */
152649 char aff; /* Comparison affinity */
152650 char idxaff = 0; /* Indexed columns affinity */
152651 CollSeq *pColl; /* Comparison collation sequence */
152652 Expr *pLhs, *pRhs;
152653
152654 assert( ExprUseXList(pTerm->pExpr->pLeft) );
152655 pLhs = pTerm->pExpr->pLeft->x.pList->a[i].pExpr;
152656 pRhs = pTerm->pExpr->pRight;
152657 if( ExprUseXSelect(pRhs) ){
152658 pRhs = pRhs->x.pSelect->pEList->a[i].pExpr;
152659 }else{
152660 pRhs = pRhs->x.pList->a[i].pExpr;
152661 }
152662
@@ -152493,11 +152813,11 @@
152813 || (pNew->wsFlags & WHERE_SKIPSCAN)!=0
152814 );
152815
152816 if( eOp & WO_IN ){
152817 Expr *pExpr = pTerm->pExpr;
152818 if( ExprUseXSelect(pExpr) ){
152819 /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
152820 int i;
152821 nIn = 46; assert( 46==sqlite3LogEst(25) );
152822
152823 /* The expression may actually be of the form (x, y) IN (SELECT...).
@@ -152634,11 +152954,11 @@
152954 #ifdef SQLITE_ENABLE_STAT4
152955 tRowcnt nOut = 0;
152956 if( nInMul==0
152957 && pProbe->nSample
152958 && ALWAYS(pNew->u.btree.nEq<=pProbe->nSampleCol)
152959 && ((eOp & WO_IN)==0 || ExprUseXList(pTerm->pExpr))
152960 && OptimizationEnabled(db, SQLITE_Stat4)
152961 ){
152962 Expr *pExpr = pTerm->pExpr;
152963 if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){
152964 testcase( eOp & WO_EQ );
@@ -152910,10 +153230,11 @@
153230 pTab = pSrc->pTab;
153231 pWC = pBuilder->pWC;
153232 assert( !IsVirtual(pSrc->pTab) );
153233
153234 if( pSrc->fg.isIndexedBy ){
153235 assert( pSrc->fg.isCte==0 );
153236 /* An INDEXED BY clause specifies a particular index to use */
153237 pProbe = pSrc->u2.pIBIndex;
153238 }else if( !HasRowid(pTab) ){
153239 pProbe = pTab->pIndex;
153240 }else{
@@ -155380,11 +155701,11 @@
155701 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
155702 #endif
155703 }else{
155704 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
155705 }
155706 if( (pLoop->wsFlags & WHERE_IN_ABLE)!=0 && pLevel->u.in.nIn>0 ){
155707 struct InLoop *pIn;
155708 int j;
155709 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
155710 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
155711 assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull
@@ -155449,14 +155770,14 @@
155770 if( (ws & WHERE_IDX_ONLY)==0 ){
155771 assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
155772 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
155773 }
155774 if( (ws & WHERE_INDEXED)
155775 || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx)
155776 ){
155777 if( ws & WHERE_MULTI_OR ){
155778 Index *pIx = pLevel->u.pCoveringIdx;
155779 int iDb = sqlite3SchemaToIndex(db, pIx->pSchema);
155780 sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb);
155781 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
155782 }
155783 sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
@@ -155533,11 +155854,11 @@
155854 ** reference the index.
155855 */
155856 if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){
155857 pIdx = pLoop->u.btree.pIndex;
155858 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
155859 pIdx = pLevel->u.pCoveringIdx;
155860 }
155861 if( pIdx
155862 && !db->mallocFailed
155863 ){
155864 if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){
@@ -156194,28 +156515,28 @@
156515 static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ }
156516
156517 /* Window functions that use all window interfaces: xStep, xFinal,
156518 ** xValue, and xInverse */
156519 #define WINDOWFUNCALL(name,nArg,extra) { \
156520 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156521 name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \
156522 name ## InvFunc, name ## Name, {0} \
156523 }
156524
156525 /* Window functions that are implemented using bytecode and thus have
156526 ** no-op routines for their methods */
156527 #define WINDOWFUNCNOOP(name,nArg,extra) { \
156528 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156529 noopStepFunc, noopValueFunc, noopValueFunc, \
156530 noopStepFunc, name ## Name, {0} \
156531 }
156532
156533 /* Window functions that use all window interfaces: xStep, the
156534 ** same routine for xFinalize and xValue and which never call
156535 ** xInverse. */
156536 #define WINDOWFUNCX(name,nArg,extra) { \
156537 nArg, (SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_WINDOW|extra), 0, 0, \
156538 name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \
156539 noopStepFunc, name ## Name, {0} \
156540 }
156541
156542
@@ -156554,11 +156875,12 @@
156875 return WRC_Continue;
156876 }
156877
156878 static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
156879 if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
156880 assert( !ExprHasProperty(pExpr, EP_IntValue) );
156881 sqlite3ErrorMsg(pWalker->pParse,
156882 "misuse of aggregate: %s()", pExpr->u.zToken);
156883 }
156884 return WRC_Continue;
156885 }
156886
@@ -156642,11 +156964,13 @@
156964 /* Append the arguments passed to each window function to the
156965 ** sub-select expression list. Also allocate two registers for each
156966 ** window function - one for the accumulator, another for interim
156967 ** results. */
156968 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
156969 ExprList *pArgs;
156970 assert( ExprUseXList(pWin->pOwner) );
156971 pArgs = pWin->pOwner->x.pList;
156972 if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){
156973 selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist);
156974 pWin->iArgCol = (pSublist ? pSublist->nExpr : 0);
156975 pWin->bExprArgs = 1;
156976 }else{
@@ -157035,12 +157359,15 @@
157359 **
157360 ** regApp+0: slot to copy min()/max() argument to for MakeRecord
157361 ** regApp+1: integer value used to ensure keys are unique
157362 ** regApp+2: output of MakeRecord
157363 */
157364 ExprList *pList;
157365 KeyInfo *pKeyInfo;
157366 assert( ExprUseXList(pWin->pOwner) );
157367 pList = pWin->pOwner->x.pList;
157368 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0);
157369 pWin->csrApp = pParse->nTab++;
157370 pWin->regApp = pParse->nMem+1;
157371 pParse->nMem += 3;
157372 if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){
157373 assert( pKeyInfo->aSortFlags[0]==0 );
@@ -157124,11 +157451,13 @@
157451 /*
157452 ** Return the number of arguments passed to the window-function associated
157453 ** with the object passed as the only argument to this function.
157454 */
157455 static int windowArgCount(Window *pWin){
157456 const ExprList *pList;
157457 assert( ExprUseXList(pWin->pOwner) );
157458 pList = pWin->pOwner->x.pList;
157459 return (pList ? pList->nExpr : 0);
157460 }
157461
157462 typedef struct WindowCodeArg WindowCodeArg;
157463 typedef struct WindowCsrAndReg WindowCsrAndReg;
@@ -157309,10 +157638,11 @@
157638 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
157639 }else if( pFunc->xSFunc!=noopStepFunc ){
157640 int addrIf = 0;
157641 if( pWin->pFilter ){
157642 int regTmp;
157643 assert( ExprUseXList(pWin->pOwner) );
157644 assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr );
157645 assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 );
157646 regTmp = sqlite3GetTempReg(pParse);
157647 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
157648 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
@@ -157322,10 +157652,11 @@
157652
157653 if( pWin->bExprArgs ){
157654 int iOp = sqlite3VdbeCurrentAddr(v);
157655 int iEnd;
157656
157657 assert( ExprUseXList(pWin->pOwner) );
157658 nArg = pWin->pOwner->x.pList->nExpr;
157659 regArg = sqlite3GetTempRange(pParse, nArg);
157660 sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0);
157661
157662 for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
@@ -157336,10 +157667,11 @@
157667 }
157668 }
157669 if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
157670 CollSeq *pColl;
157671 assert( nArg>0 );
157672 assert( ExprUseXList(pWin->pOwner) );
157673 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
157674 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
157675 }
157676 sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
157677 bInverse, regArg, pWin->regAccum);
@@ -157521,10 +157853,11 @@
157853 Parse *pParse = p->pParse;
157854 Window *pWin;
157855
157856 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
157857 FuncDef *pFunc = pWin->pFunc;
157858 assert( ExprUseXList(pWin->pOwner) );
157859 if( pFunc->zName==nth_valueName
157860 || pFunc->zName==first_valueName
157861 ){
157862 int csr = pWin->csrApp;
157863 int lbl = sqlite3VdbeMakeLabel(pParse);
@@ -158870,13 +159203,13 @@
159203 p->affExpr = 0;
159204 p->flags = EP_Leaf;
159205 ExprClearVVAProperties(p);
159206 p->iAgg = -1;
159207 p->pLeft = p->pRight = 0;
 
159208 p->pAggInfo = 0;
159209 memset(&p->x, 0, sizeof(p->x));
159210 memset(&p->y, 0, sizeof(p->y));
159211 p->op2 = 0;
159212 p->iTable = 0;
159213 p->iColumn = 0;
159214 p->u.zToken = (char*)&p[1];
159215 memcpy(p->u.zToken, t.z, t.n);
@@ -166966,11 +167299,13 @@
167299 ** if this is not the last copy of the function, do not invoke it. Multiple
167300 ** copies of a single function are created when create_function() is called
167301 ** with SQLITE_ANY as the encoding.
167302 */
167303 static void functionDestroy(sqlite3 *db, FuncDef *p){
167304 FuncDestructor *pDestructor;
167305 assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 );
167306 pDestructor = p->u.pDestructor;
167307 if( pDestructor ){
167308 pDestructor->nRef--;
167309 if( pDestructor->nRef==0 ){
167310 pDestructor->xDestroy(pDestructor->pUserData);
167311 sqlite3DbFree(db, pDestructor);
@@ -168987,10 +169322,11 @@
169322 ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE,
169323 ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask
169324 ** off all other flags.
169325 */
169326 flags &= ~( SQLITE_OPEN_DELETEONCLOSE |
169327 SQLITE_OPEN_EXCLUSIVE |
169328 SQLITE_OPEN_MAIN_DB |
169329 SQLITE_OPEN_TEMP_DB |
169330 SQLITE_OPEN_TRANSIENT_DB |
169331 SQLITE_OPEN_MAIN_JOURNAL |
169332 SQLITE_OPEN_TEMP_JOURNAL |
@@ -172095,10 +172431,11 @@
172431 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
172432 #ifdef SQLITE_TEST
172433 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*);
172434 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
172435 #endif
172436 SQLITE_PRIVATE void *sqlite3Fts3MallocZero(i64 nByte);
172437
172438 SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int,
172439 sqlite3_tokenizer_cursor **
172440 );
172441
@@ -177176,12 +177513,12 @@
177513 case FTSQUERY_OR: {
177514 Fts3Expr *pLeft = pExpr->pLeft;
177515 Fts3Expr *pRight = pExpr->pRight;
177516 sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid);
177517
177518 assert_fts3_nc( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
177519 assert_fts3_nc( pRight->bStart || pLeft->iDocid==pRight->iDocid );
177520
177521 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
177522 fts3EvalNextRow(pCsr, pLeft, pRc);
177523 }else if( pLeft->bEof || iCmp>0 ){
177524 fts3EvalNextRow(pCsr, pRight, pRc);
@@ -178617,11 +178954,11 @@
178954 /*
178955 ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
178956 ** zero the memory before returning a pointer to it. If unsuccessful,
178957 ** return NULL.
178958 */
178959 SQLITE_PRIVATE void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){
178960 void *pRet = sqlite3_malloc64(nByte);
178961 if( pRet ) memset(pRet, 0, nByte);
178962 return pRet;
178963 }
178964
@@ -178698,11 +179035,11 @@
179035 sqlite3_int64 nByte; /* total space to allocate */
179036
179037 rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
179038 if( rc==SQLITE_OK ){
179039 nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
179040 pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte);
179041 if( !pRet ){
179042 rc = SQLITE_NOMEM;
179043 }else{
179044 pRet->eType = FTSQUERY_PHRASE;
179045 pRet->pPhrase = (Fts3Phrase *)&pRet[1];
@@ -178953,11 +179290,11 @@
179290 */
179291 cNext = zInput[nKey];
179292 if( fts3isspace(cNext)
179293 || cNext=='"' || cNext=='(' || cNext==')' || cNext==0
179294 ){
179295 pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179296 if( !pRet ){
179297 return SQLITE_NOMEM;
179298 }
179299 pRet->eType = pKey->eType;
179300 pRet->nNear = nNear;
@@ -179132,11 +179469,11 @@
179469
179470 if( !sqlite3_fts3_enable_parentheses
179471 && p->eType==FTSQUERY_PHRASE && pParse->isNot
179472 ){
179473 /* Create an implicit NOT operator. */
179474 Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179475 if( !pNot ){
179476 sqlite3Fts3ExprFree(p);
179477 rc = SQLITE_NOMEM;
179478 goto exprparse_out;
179479 }
@@ -179166,11 +179503,11 @@
179503
179504 if( isPhrase && !isRequirePhrase ){
179505 /* Insert an implicit AND operator. */
179506 Fts3Expr *pAnd;
179507 assert( pRet && pPrev );
179508 pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr));
179509 if( !pAnd ){
179510 sqlite3Fts3ExprFree(p);
179511 rc = SQLITE_NOMEM;
179512 goto exprparse_out;
179513 }
@@ -183396,12 +183733,22 @@
183733 pReader->aNode = 0;
183734 if( pElem ){
183735 char *aCopy;
183736 PendingList *pList = (PendingList *)fts3HashData(pElem);
183737 int nCopy = pList->nData+1;
183738
183739 int nTerm = fts3HashKeysize(pElem);
183740 if( (nTerm+1)>pReader->nTermAlloc ){
183741 sqlite3_free(pReader->zTerm);
183742 pReader->zTerm = (char*)sqlite3_malloc((nTerm+1)*2);
183743 if( !pReader->zTerm ) return SQLITE_NOMEM;
183744 pReader->nTermAlloc = (nTerm+1)*2;
183745 }
183746 memcpy(pReader->zTerm, fts3HashKey(pElem), nTerm);
183747 pReader->zTerm[nTerm] = '\0';
183748 pReader->nTerm = nTerm;
183749
183750 aCopy = (char*)sqlite3_malloc(nCopy);
183751 if( !aCopy ) return SQLITE_NOMEM;
183752 memcpy(aCopy, pList->aData, nCopy);
183753 pReader->nNode = pReader->nDoclist = nCopy;
183754 pReader->aNode = pReader->aDoclist = aCopy;
@@ -183650,13 +183997,11 @@
183997 ** Free all allocations associated with the iterator passed as the
183998 ** second argument.
183999 */
184000 SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){
184001 if( pReader ){
184002 sqlite3_free(pReader->zTerm);
 
 
184003 if( !fts3SegReaderIsRootOnly(pReader) ){
184004 sqlite3_free(pReader->aNode);
184005 }
184006 sqlite3_blob_close(pReader->pBlob);
184007 }
@@ -188003,13 +188348,12 @@
188348 MatchinfoBuffer *pRet;
188349 sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
188350 + sizeof(MatchinfoBuffer);
188351 sqlite3_int64 nStr = strlen(zMatchinfo);
188352
188353 pRet = sqlite3Fts3MallocZero(nByte + nStr+1);
188354 if( pRet ){
 
188355 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
188356 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
188357 + sizeof(u32)*((int)nElem+1);
188358 pRet->nElem = (int)nElem;
188359 pRet->zMatchinfo = ((char*)pRet) + nByte;
@@ -188409,15 +188753,14 @@
188753
188754 /* Now that it is known how many phrases there are, allocate and zero
188755 ** the required space using malloc().
188756 */
188757 nByte = sizeof(SnippetPhrase) * nList;
188758 sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte);
188759 if( !sIter.aPhrase ){
188760 return SQLITE_NOMEM;
188761 }
 
188762
188763 /* Initialize the contents of the SnippetIter object. Then iterate through
188764 ** the set of phrases in the expression to populate the aPhrase[] array.
188765 */
188766 sIter.pCsr = pCsr;
@@ -189016,13 +189359,12 @@
189359 int rc = SQLITE_OK;
189360
189361 /* Allocate and populate the array of LcsIterator objects. The array
189362 ** contains one element for each matchable phrase in the query.
189363 **/
189364 aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase);
189365 if( !aIter ) return SQLITE_NOMEM;
 
189366 (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
189367
189368 for(i=0; i<pInfo->nPhrase; i++){
189369 LcsIterator *pIter = &aIter[i];
189370 nToken -= pIter->pExpr->pPhrase->nToken;
@@ -189479,11 +189821,11 @@
189821 /* Count the number of terms in the query */
189822 rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
189823 if( rc!=SQLITE_OK ) goto offsets_out;
189824
189825 /* Allocate the array of TermOffset iterators. */
189826 sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken);
189827 if( 0==sCtx.aTerm ){
189828 rc = SQLITE_NOMEM;
189829 goto offsets_out;
189830 }
189831 sCtx.iDocid = pCsr->iPrevId;
@@ -190517,11 +190859,25 @@
190859 # define NEVER(X) ((X)?(assert(0),1):0)
190860 # else
190861 # define ALWAYS(X) (X)
190862 # define NEVER(X) (X)
190863 # endif
190864 # define testcase(X)
190865 #endif
190866 #if defined(NDEBUG)
190867 # define VVA(X)
190868 #else
190869 # define VVA(X) X
190870 #endif
190871
190872 /*
190873 ** Some of the testcase() macros in this file are problematic for gcov
190874 ** in that they generate false-miss errors randomly. This is a gcov problem,
190875 ** not a problem in this case. But to work around it, we disable the
190876 ** problematic test cases for production builds.
190877 */
190878 #define json_testcase(X)
190879
190880 /* Objects */
190881 typedef struct JsonString JsonString;
190882 typedef struct JsonNode JsonNode;
190883 typedef struct JsonParse JsonParse;
@@ -190575,17 +190931,18 @@
190931 /* A single node of parsed JSON
190932 */
190933 struct JsonNode {
190934 u8 eType; /* One of the JSON_ type values */
190935 u8 jnFlags; /* JNODE flags */
190936 u8 eU; /* Which union element to use */
190937 u32 n; /* Bytes of content, or number of sub-nodes */
190938 union {
190939 const char *zJContent; /* 1: Content for INT, REAL, and STRING */
190940 u32 iAppend; /* 2: More terms for ARRAY and OBJECT */
190941 u32 iKey; /* 3: Key for ARRAY objects in json_tree() */
190942 u32 iReplace; /* 4: Replacement content for JNODE_REPLACE */
190943 JsonNode *pPatch; /* 5: Node chain of patch for JNODE_PATCH */
190944 } u;
190945 };
190946
190947 /* A completely parsed JSON string
190948 */
@@ -190862,13 +191219,15 @@
191219 sqlite3_value **aReplace /* Replacement values */
191220 ){
191221 assert( pNode!=0 );
191222 if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){
191223 if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){
191224 assert( pNode->eU==4 );
191225 jsonAppendValue(pOut, aReplace[pNode->u.iReplace]);
191226 return;
191227 }
191228 assert( pNode->eU==5 );
191229 pNode = pNode->u.pPatch;
191230 }
191231 switch( pNode->eType ){
191232 default: {
191233 assert( pNode->eType==JSON_NULL );
@@ -190883,17 +191242,19 @@
191242 jsonAppendRaw(pOut, "false", 5);
191243 break;
191244 }
191245 case JSON_STRING: {
191246 if( pNode->jnFlags & JNODE_RAW ){
191247 assert( pNode->eU==1 );
191248 jsonAppendString(pOut, pNode->u.zJContent, pNode->n);
191249 break;
191250 }
191251 /* no break */ deliberate_fall_through
191252 }
191253 case JSON_REAL:
191254 case JSON_INT: {
191255 assert( pNode->eU==1 );
191256 jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n);
191257 break;
191258 }
191259 case JSON_ARRAY: {
191260 u32 j = 1;
@@ -190905,10 +191266,11 @@
191266 jsonRenderNode(&pNode[j], pOut, aReplace);
191267 }
191268 j += jsonNodeSize(&pNode[j]);
191269 }
191270 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191271 assert( pNode->eU==2 );
191272 pNode = &pNode[pNode->u.iAppend];
191273 j = 1;
191274 }
191275 jsonAppendChar(pOut, ']');
191276 break;
@@ -190925,10 +191287,11 @@
191287 jsonRenderNode(&pNode[j+1], pOut, aReplace);
191288 }
191289 j += 1 + jsonNodeSize(&pNode[j+1]);
191290 }
191291 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
191292 assert( pNode->eU==2 );
191293 pNode = &pNode[pNode->u.iAppend];
191294 j = 1;
191295 }
191296 jsonAppendChar(pOut, '}');
191297 break;
@@ -191004,11 +191367,13 @@
191367 sqlite3_result_int(pCtx, 0);
191368 break;
191369 }
191370 case JSON_INT: {
191371 sqlite3_int64 i = 0;
191372 const char *z;
191373 assert( pNode->eU==1 );
191374 z = pNode->u.zJContent;
191375 if( z[0]=='-' ){ z++; }
191376 while( z[0]>='0' && z[0]<='9' ){
191377 unsigned v = *(z++) - '0';
191378 if( i>=LARGEST_INT64/10 ){
191379 if( i>LARGEST_INT64/10 ) goto int_as_real;
@@ -191032,13 +191397,16 @@
191397 int_as_real: ; /* no break */ deliberate_fall_through
191398 }
191399 case JSON_REAL: {
191400 double r;
191401 #ifdef SQLITE_AMALGAMATION
191402 const char *z;
191403 assert( pNode->eU==1 );
191404 z = pNode->u.zJContent;
191405 sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8);
191406 #else
191407 assert( pNode->eU==1 );
191408 r = strtod(pNode->u.zJContent, 0);
191409 #endif
191410 sqlite3_result_double(pCtx, r);
191411 break;
191412 }
@@ -191045,26 +191413,30 @@
191413 case JSON_STRING: {
191414 #if 0 /* Never happens because JNODE_RAW is only set by json_set(),
191415 ** json_insert() and json_replace() and those routines do not
191416 ** call jsonReturn() */
191417 if( pNode->jnFlags & JNODE_RAW ){
191418 assert( pNode->eU==1 );
191419 sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n,
191420 SQLITE_TRANSIENT);
191421 }else
191422 #endif
191423 assert( (pNode->jnFlags & JNODE_RAW)==0 );
191424 if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){
191425 /* JSON formatted without any backslash-escapes */
191426 assert( pNode->eU==1 );
191427 sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2,
191428 SQLITE_TRANSIENT);
191429 }else{
191430 /* Translate JSON formatted string into raw text */
191431 u32 i;
191432 u32 n = pNode->n;
191433 const char *z;
191434 char *zOut;
191435 u32 j;
191436 assert( pNode->eU==1 );
191437 z = pNode->u.zJContent;
191438 zOut = sqlite3_malloc( n+1 );
191439 if( zOut==0 ){
191440 sqlite3_result_error_nomem(pCtx);
191441 break;
191442 }
@@ -191187,10 +191559,11 @@
191559 return jsonParseAddNodeExpand(pParse, eType, n, zContent);
191560 }
191561 p = &pParse->aNode[pParse->nNode];
191562 p->eType = (u8)eType;
191563 p->jnFlags = 0;
191564 VVA( p->eU = zContent ? 1 : 0 );
191565 p->n = n;
191566 p->u.zJContent = zContent;
191567 return pParse->nNode++;
191568 }
191569
@@ -191254,10 +191627,11 @@
191627 return j+1;
191628 }else if( c=='[' ){
191629 /* Parse array */
191630 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
191631 if( iThis<0 ) return -1;
191632 memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
191633 for(j=i+1;;j++){
191634 while( safe_isspace(z[j]) ){ j++; }
191635 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
191636 x = jsonParseValue(pParse, j);
191637 pParse->iDepth--;
@@ -191518,10 +191892,11 @@
191892 /*
191893 ** Compare the OBJECT label at pNode against zKey,nKey. Return true on
191894 ** a match.
191895 */
191896 static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){
191897 assert( pNode->eU==1 );
191898 if( pNode->jnFlags & JNODE_RAW ){
191899 if( pNode->n!=nKey ) return 0;
191900 return strncmp(pNode->u.zJContent, zKey, nKey)==0;
191901 }else{
191902 if( pNode->n!=nKey+2 ) return 0;
@@ -191583,10 +191958,11 @@
191958 }
191959 j++;
191960 j += jsonNodeSize(&pRoot[j]);
191961 }
191962 if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
191963 assert( pRoot->eU==2 );
191964 iRoot += pRoot->u.iAppend;
191965 pRoot = &pParse->aNode[iRoot];
191966 j = 1;
191967 }
191968 if( pApnd ){
@@ -191597,12 +191973,14 @@
191973 zPath += i;
191974 pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
191975 if( pParse->oom ) return 0;
191976 if( pNode ){
191977 pRoot = &pParse->aNode[iRoot];
191978 assert( pRoot->eU==0 );
191979 pRoot->u.iAppend = iStart - iRoot;
191980 pRoot->jnFlags |= JNODE_APPEND;
191981 VVA( pRoot->eU = 2 );
191982 pParse->aNode[iLabel].jnFlags |= JNODE_RAW;
191983 }
191984 return pNode;
191985 }
191986 }else if( zPath[0]=='[' ){
@@ -191621,10 +191999,11 @@
191999 while( j<=pBase->n ){
192000 if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
192001 j += jsonNodeSize(&pBase[j]);
192002 }
192003 if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
192004 assert( pBase->eU==2 );
192005 iBase += pBase->u.iAppend;
192006 pBase = &pParse->aNode[iBase];
192007 j = 1;
192008 }
192009 j = 2;
@@ -191654,10 +192033,11 @@
192033 while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
192034 if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
192035 j += jsonNodeSize(&pRoot[j]);
192036 }
192037 if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
192038 assert( pRoot->eU==2 );
192039 iRoot += pRoot->u.iAppend;
192040 pRoot = &pParse->aNode[iRoot];
192041 j = 1;
192042 }
192043 if( j<=pRoot->n ){
@@ -191669,12 +192049,14 @@
192049 iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0);
192050 pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
192051 if( pParse->oom ) return 0;
192052 if( pNode ){
192053 pRoot = &pParse->aNode[iRoot];
192054 assert( pRoot->eU==0 );
192055 pRoot->u.iAppend = iStart - iRoot;
192056 pRoot->jnFlags |= JNODE_APPEND;
192057 VVA( pRoot->eU = 2 );
192058 }
192059 return pNode;
192060 }
192061 }else{
192062 *pzErr = zPath;
@@ -191824,13 +192206,17 @@
192206 }else{
192207 zType = jsonType[x.aNode[i].eType];
192208 }
192209 jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d",
192210 i, zType, x.aNode[i].n, x.aUp[i]);
192211 assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 );
192212 if( x.aNode[i].u.zJContent!=0 ){
192213 assert( x.aNode[i].eU==1 );
192214 jsonAppendRaw(&s, " ", 1);
192215 jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n);
192216 }else{
192217 assert( x.aNode[i].eU==0 );
192218 }
192219 jsonAppendRaw(&s, "\n", 1);
192220 }
192221 jsonParseReset(&x);
192222 jsonResult(&s);
@@ -192009,10 +192395,11 @@
192395 for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){
192396 u32 nKey;
192397 const char *zKey;
192398 assert( pPatch[i].eType==JSON_STRING );
192399 assert( pPatch[i].jnFlags & JNODE_LABEL );
192400 assert( pPatch[i].eU==1 );
192401 nKey = pPatch[i].n;
192402 zKey = pPatch[i].u.zJContent;
192403 assert( (pPatch[i].jnFlags & JNODE_RAW)==0 );
192404 for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){
192405 assert( pTarget[j].eType==JSON_STRING );
@@ -192025,10 +192412,13 @@
192412 }else{
192413 JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]);
192414 if( pNew==0 ) return 0;
192415 pTarget = &pParse->aNode[iTarget];
192416 if( pNew!=&pTarget[j+1] ){
192417 assert( pTarget[j+1].eU==0 || pTarget[j+1].eU==1 );
192418 testcase( pTarget[j+1].eU==1 );
192419 VVA( pTarget[j+1].eU = 5 );
192420 pTarget[j+1].u.pPatch = pNew;
192421 pTarget[j+1].jnFlags |= JNODE_PATCH;
192422 }
192423 }
192424 break;
@@ -192040,13 +192430,18 @@
192430 jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
192431 iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
192432 if( pParse->oom ) return 0;
192433 jsonRemoveAllNulls(pPatch);
192434 pTarget = &pParse->aNode[iTarget];
192435 assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 );
192436 testcase( pParse->aNode[iRoot].eU==2 );
192437 pParse->aNode[iRoot].jnFlags |= JNODE_APPEND;
192438 VVA( pParse->aNode[iRoot].eU = 2 );
192439 pParse->aNode[iRoot].u.iAppend = iStart - iRoot;
192440 iRoot = iStart;
192441 assert( pParse->aNode[iPatch].eU==0 );
192442 VVA( pParse->aNode[iPatch].eU = 5 );
192443 pParse->aNode[iPatch].jnFlags |= JNODE_PATCH;
192444 pParse->aNode[iPatch].u.pPatch = &pPatch[i+1];
192445 }
192446 }
192447 return pTarget;
@@ -192184,15 +192579,19 @@
192579 for(i=1; i<(u32)argc; i+=2){
192580 zPath = (const char*)sqlite3_value_text(argv[i]);
192581 pNode = jsonLookup(&x, zPath, 0, ctx);
192582 if( x.nErr ) goto replace_err;
192583 if( pNode ){
192584 assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 );
192585 json_testcase( pNode->eU!=0 && pNode->eU!=1 );
192586 pNode->jnFlags |= (u8)JNODE_REPLACE;
192587 VVA( pNode->eU = 4 );
192588 pNode->u.iReplace = i + 1;
192589 }
192590 }
192591 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192592 assert( x.aNode[0].eU==4 );
192593 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192594 }else{
192595 jsonReturnJson(x.aNode, ctx, argv);
192596 }
192597 replace_err:
@@ -192238,15 +192637,19 @@
192637 sqlite3_result_error_nomem(ctx);
192638 goto jsonSetDone;
192639 }else if( x.nErr ){
192640 goto jsonSetDone;
192641 }else if( pNode && (bApnd || bIsSet) ){
192642 json_testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
192643 assert( pNode->eU!=3 || pNode->eU!=5 );
192644 VVA( pNode->eU = 4 );
192645 pNode->jnFlags |= (u8)JNODE_REPLACE;
192646 pNode->u.iReplace = i + 1;
192647 }
192648 }
192649 if( x.aNode[0].jnFlags & JNODE_REPLACE ){
192650 assert( x.aNode[0].eU==4 );
192651 sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]);
192652 }else{
192653 jsonReturnJson(x.aNode, ctx, argv);
192654 }
192655 jsonSetDone:
@@ -192593,10 +192996,13 @@
192996 if( p->i<p->iEnd ){
192997 u32 iUp = p->sParse.aUp[p->i];
192998 JsonNode *pUp = &p->sParse.aNode[iUp];
192999 p->eType = pUp->eType;
193000 if( pUp->eType==JSON_ARRAY ){
193001 assert( pUp->eU==0 || pUp->eU==3 );
193002 json_testcase( pUp->eU==3 );
193003 VVA( pUp->eU = 3 );
193004 if( iUp==p->i-1 ){
193005 pUp->u.iKey = 0;
193006 }else{
193007 pUp->u.iKey++;
193008 }
@@ -192639,16 +193045,19 @@
193045 iUp = p->sParse.aUp[i];
193046 jsonEachComputePath(p, pStr, iUp);
193047 pNode = &p->sParse.aNode[i];
193048 pUp = &p->sParse.aNode[iUp];
193049 if( pUp->eType==JSON_ARRAY ){
193050 assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) );
193051 testcase( pUp->eU==0 );
193052 jsonPrintf(30, pStr, "[%d]", pUp->u.iKey);
193053 }else{
193054 assert( pUp->eType==JSON_OBJECT );
193055 if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
193056 assert( pNode->eType==JSON_STRING );
193057 assert( pNode->jnFlags & JNODE_LABEL );
193058 assert( pNode->eU==1 );
193059 jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
193060 }
193061 }
193062
193063 /* Return the value of a column */
@@ -192666,10 +193075,11 @@
193075 jsonReturn(pThis, ctx, 0);
193076 }else if( p->eType==JSON_ARRAY ){
193077 u32 iKey;
193078 if( p->bRecursive ){
193079 if( p->iRowid==0 ) break;
193080 assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 );
193081 iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey;
193082 }else{
193083 iKey = p->iRowid;
193084 }
193085 sqlite3_result_int64(ctx, (sqlite3_int64)iKey);
@@ -192715,10 +193125,11 @@
193125 jsonAppendChar(&x, '$');
193126 }
193127 if( p->eType==JSON_ARRAY ){
193128 jsonPrintf(30, &x, "[%d]", p->iRowid);
193129 }else if( p->eType==JSON_OBJECT ){
193130 assert( pThis->eU==1 );
193131 jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
193132 }
193133 }
193134 jsonResult(&x);
193135 break;
@@ -192782,10 +193193,11 @@
193193 int iCol;
193194 int iMask;
193195 if( pConstraint->iColumn < JEACH_JSON ) continue;
193196 iCol = pConstraint->iColumn - JEACH_JSON;
193197 assert( iCol==0 || iCol==1 );
193198 testcase( iCol==0 );
193199 iMask = 1 << iCol;
193200 if( pConstraint->usable==0 ){
193201 unusableMask |= iMask;
193202 }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
193203 aIdx[iCol] = i;
@@ -192879,10 +193291,12 @@
193291 pNode = p->sParse.aNode;
193292 }
193293 p->iBegin = p->i = (int)(pNode - p->sParse.aNode);
193294 p->eType = pNode->eType;
193295 if( p->eType>=JSON_ARRAY ){
193296 assert( pNode->eU==0 );
193297 VVA( pNode->eU = 3 );
193298 pNode->u.iKey = 0;
193299 p->iEnd = p->i + pNode->n + 1;
193300 if( p->bRecursive ){
193301 p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType;
193302 if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){
@@ -193493,11 +193907,11 @@
193907
193908 /* The testcase() macro should already be defined in the amalgamation. If
193909 ** it is not, make it a no-op.
193910 */
193911 #ifndef SQLITE_AMALGAMATION
193912 # if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
193913 unsigned int sqlite3RtreeTestcase = 0;
193914 # define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; }
193915 # else
193916 # define testcase(X)
193917 # endif
@@ -214008,11 +214422,11 @@
214422
214423 /*
214424 ** A version of memcmp() that does not cause asan errors if one of the pointer
214425 ** parameters is NULL and the number of bytes to compare is zero.
214426 */
214427 #define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
214428
214429 /* Mark a function parameter as unused, to suppress nuisance compiler
214430 ** warnings. */
214431 #ifndef UNUSED_PARAM
214432 # define UNUSED_PARAM(X) (void)(X)
@@ -217034,11 +217448,10 @@
217448 int *pRc,
217449 Fts5Buffer *pBuf,
217450 u32 nData,
217451 const u8 *pData
217452 ){
 
217453 if( nData ){
217454 if( fts5BufferGrow(pRc, pBuf, nData) ) return;
217455 memcpy(&pBuf->p[pBuf->n], pData, nData);
217456 pBuf->n += nData;
217457 }
@@ -217146,11 +217559,10 @@
217559 return 1;
217560 }else{
217561 i64 iOff = *piOff;
217562 u32 iVal;
217563 fts5FastGetVarint32(a, i, iVal);
 
217564 if( iVal<=1 ){
217565 if( iVal==0 ){
217566 *pi = i;
217567 return 0;
217568 }
@@ -221761,11 +222173,11 @@
222173 if( iCol>=0 ){
222174 if( pHash->eDetail==FTS5_DETAIL_NONE ){
222175 p->bContent = 1;
222176 }else{
222177 /* Append a new column value, if necessary */
222178 assert_nc( iCol>=p->iCol );
222179 if( iCol!=p->iCol ){
222180 if( pHash->eDetail==FTS5_DETAIL_FULL ){
222181 pPtr[p->nData++] = 0x01;
222182 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
222183 p->iCol = (i16)iCol;
@@ -222566,12 +222978,15 @@
222978 ** +ve if pRight is smaller than pLeft. In other words:
222979 **
222980 ** res = *pLeft - *pRight
222981 */
222982 static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
222983 int nCmp, res;
222984 nCmp = MIN(pLeft->n, pRight->n);
222985 assert( nCmp<=0 || pLeft->p!=0 );
222986 assert( nCmp<=0 || pRight->p!=0 );
222987 res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
222988 return (res==0 ? (pLeft->n - pRight->n) : res);
222989 }
222990
222991 static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
222992 int ret;
@@ -224244,25 +224659,24 @@
224659 Fts5Index *p, /* Leave any error code here */
224660 int bGe, /* True for a >= search */
224661 Fts5SegIter *pIter, /* Iterator to seek */
224662 const u8 *pTerm, int nTerm /* Term to search for */
224663 ){
224664 u32 iOff;
224665 const u8 *a = pIter->pLeaf->p;
224666 u32 n = (u32)pIter->pLeaf->nn;
 
224667
224668 u32 nMatch = 0;
224669 u32 nKeep = 0;
224670 u32 nNew = 0;
224671 u32 iTermOff;
224672 u32 iPgidx; /* Current offset in pgidx */
224673 int bEndOfPage = 0;
224674
224675 assert( p->rc==SQLITE_OK );
224676
224677 iPgidx = (u32)pIter->pLeaf->szLeaf;
224678 iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
224679 iOff = iTermOff;
224680 if( iOff>n ){
224681 p->rc = FTS5_CORRUPT;
224682 return;
@@ -224324,19 +224738,19 @@
224738 do {
224739 fts5SegIterNextPage(p, pIter);
224740 if( pIter->pLeaf==0 ) return;
224741 a = pIter->pLeaf->p;
224742 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
224743 iPgidx = (u32)pIter->pLeaf->szLeaf;
224744 iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
224745 if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){
224746 p->rc = FTS5_CORRUPT;
224747 return;
224748 }else{
224749 nKeep = 0;
224750 iTermOff = iOff;
224751 n = (u32)pIter->pLeaf->nn;
224752 iOff += fts5GetVarint32(&a[iOff], nNew);
224753 break;
224754 }
224755 }
224756 }while( 1 );
@@ -231573,11 +231987,11 @@
231987 int nArg, /* Number of args */
231988 sqlite3_value **apUnused /* Function arguments */
231989 ){
231990 assert( nArg==0 );
231991 UNUSED_PARAM2(nArg, apUnused);
231992 sqlite3_result_text(pCtx, "fts5: 2021-10-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a", -1, SQLITE_TRANSIENT);
231993 }
231994
231995 /*
231996 ** Return true if zName is the extension on one of the shadow tables used
231997 ** by this module.
231998
+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-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
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-26 09:53:51 4b41535b096dec4b15a85e657102a72d4288728da6103f3fdcbe0e6f244c673a"
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