| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.37.0" |
| 456 | 456 | #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" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -843,11 +843,10 @@ |
| 843 | 843 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 844 | 844 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 845 | 845 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 846 | 846 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 847 | 847 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 848 | | -#define SQLITE_CANTOPEN_EXISTS (SQLITE_CANTOPEN | (7<<8)) |
| 849 | 848 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 850 | 849 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 851 | 850 | #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) |
| 852 | 851 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 853 | 852 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| | @@ -879,10 +878,23 @@ |
| 879 | 878 | ** CAPI3REF: Flags For File Open Operations |
| 880 | 879 | ** |
| 881 | 880 | ** These bit values are intended for use in the |
| 882 | 881 | ** 3rd parameter to the [sqlite3_open_v2()] interface and |
| 883 | 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. |
| 884 | 896 | */ |
| 885 | 897 | #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ |
| 886 | 898 | #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ |
| 887 | 899 | #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ |
| 888 | 900 | #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ |
| | @@ -3723,22 +3735,24 @@ |
| 3723 | 3735 | ** the default shared cache setting provided by |
| 3724 | 3736 | ** [sqlite3_enable_shared_cache()].)^ |
| 3725 | 3737 | ** |
| 3726 | 3738 | ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt> |
| 3727 | 3739 | ** <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 | 3740 | ** </dl>)^ |
| 3735 | 3741 | ** |
| 3736 | 3742 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 3737 | 3743 | ** required combinations shown above optionally combined with other |
| 3738 | 3744 | ** [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(). |
| 3740 | 3754 | ** |
| 3741 | 3755 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 3742 | 3756 | ** [sqlite3_vfs] object that defines the operating system interface that |
| 3743 | 3757 | ** the new database connection should use. ^If the fourth parameter is |
| 3744 | 3758 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| | @@ -13160,15 +13174,16 @@ |
| 13160 | 13174 | ** can be used to make sure boundary values are tested. For |
| 13161 | 13175 | ** bitmask tests, testcase() can be used to make sure each bit |
| 13162 | 13176 | ** is significant and used at least once. On switch statements |
| 13163 | 13177 | ** where multiple cases go to the same block of code, testcase() |
| 13164 | 13178 | ** can insure that all cases are evaluated. |
| 13165 | | -** |
| 13166 | 13179 | */ |
| 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__; } |
| 13170 | 13185 | #else |
| 13171 | 13186 | # define testcase(X) |
| 13172 | 13187 | #endif |
| 13173 | 13188 | |
| 13174 | 13189 | /* |
| | @@ -13228,30 +13243,10 @@ |
| 13228 | 13243 | #else |
| 13229 | 13244 | # define ALWAYS(X) (X) |
| 13230 | 13245 | # define NEVER(X) (X) |
| 13231 | 13246 | #endif |
| 13232 | 13247 | |
| 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 | 13248 | /* |
| 13254 | 13249 | ** Some conditionals are optimizations only. In other words, if the |
| 13255 | 13250 | ** conditionals are replaced with a constant 1 (true) or 0 (false) then |
| 13256 | 13251 | ** the correct answer is still obtained, though perhaps not as quickly. |
| 13257 | 13252 | ** |
| | @@ -13430,11 +13425,11 @@ |
| 13430 | 13425 | /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ |
| 13431 | 13426 | |
| 13432 | 13427 | /* |
| 13433 | 13428 | ** Number of entries in a hash table |
| 13434 | 13429 | */ |
| 13435 | | -/* #define sqliteHashCount(H) ((H)->count) // NOT USED */ |
| 13430 | +#define sqliteHashCount(H) ((H)->count) |
| 13436 | 13431 | |
| 13437 | 13432 | #endif /* SQLITE_HASH_H */ |
| 13438 | 13433 | |
| 13439 | 13434 | /************** End of hash.h ************************************************/ |
| 13440 | 13435 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| | @@ -16428,14 +16423,14 @@ |
| 16428 | 16423 | int nVdbeExec; /* Number of nested calls to VdbeExec() */ |
| 16429 | 16424 | int nVDestroy; /* Number of active OP_VDestroy operations */ |
| 16430 | 16425 | int nExtension; /* Number of loaded extensions */ |
| 16431 | 16426 | void **aExtension; /* Array of shared library handles */ |
| 16432 | 16427 | 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 */ |
| 16435 | 16430 | } trace; |
| 16436 | | - void *pTraceArg; /* Argument to the trace function */ |
| 16431 | + void *pTraceArg; /* Argument to the trace function */ |
| 16437 | 16432 | #ifndef SQLITE_OMIT_DEPRECATED |
| 16438 | 16433 | void (*xProfile)(void*,const char*,u64); /* Profiling function */ |
| 16439 | 16434 | void *pProfileArg; /* Argument to profile function */ |
| 16440 | 16435 | #endif |
| 16441 | 16436 | void *pCommitArg; /* Argument to xCommitCallback() */ |
| | @@ -16667,11 +16662,11 @@ |
| 16667 | 16662 | void (*xInverse)(sqlite3_context*,int,sqlite3_value**); /* inverse agg-step */ |
| 16668 | 16663 | const char *zName; /* SQL name of the function. */ |
| 16669 | 16664 | union { |
| 16670 | 16665 | FuncDef *pHash; /* Next with a different name but the same hash */ |
| 16671 | 16666 | FuncDestructor *pDestructor; /* Reference counted destructor function */ |
| 16672 | | - } u; |
| 16667 | + } u; /* pHash if SQLITE_FUNC_BUILTIN, pDestructor otherwise */ |
| 16673 | 16668 | }; |
| 16674 | 16669 | |
| 16675 | 16670 | /* |
| 16676 | 16671 | ** This structure encapsulates a user-function destructor callback (as |
| 16677 | 16672 | ** configured using create_function_v2()) and a reference counter. When |
| | @@ -16728,10 +16723,11 @@ |
| 16728 | 16723 | #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */ |
| 16729 | 16724 | #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */ |
| 16730 | 16725 | #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */ |
| 16731 | 16726 | #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */ |
| 16732 | 16727 | #define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */ |
| 16728 | +#define SQLITE_FUNC_BUILTIN 0x00800000 /* This is a built-in function */ |
| 16733 | 16729 | #define SQLITE_FUNC_ANYORDER 0x08000000 /* count/min/max aggregate */ |
| 16734 | 16730 | |
| 16735 | 16731 | /* Identifier numbers for each in-line function */ |
| 16736 | 16732 | #define INLINEFUNC_coalesce 0 |
| 16737 | 16733 | #define INLINEFUNC_implies_nonnull_row 1 |
| | @@ -16806,48 +16802,55 @@ |
| 16806 | 16802 | ** available as the function user-data (sqlite3_user_data()). The |
| 16807 | 16803 | ** FuncDef.flags variable is set to the value passed as the flags |
| 16808 | 16804 | ** parameter. |
| 16809 | 16805 | */ |
| 16810 | 16806 | #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), \ |
| 16812 | 16809 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16813 | 16810 | #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), \ |
| 16815 | 16812 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16816 | 16813 | #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, \ |
| 16818 | 16815 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16819 | 16816 | #define MFUNCTION(zName, nArg, xPtr, xFunc) \ |
| 16820 | | - {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ |
| 16817 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ |
| 16821 | 16818 | xPtr, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16822 | 16819 | #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), \ |
| 16824 | 16822 | SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } |
| 16825 | 16823 | #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| \ |
| 16827 | 16826 | SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ |
| 16828 | 16827 | SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } |
| 16829 | 16828 | #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16830 | | - {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ |
| 16829 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ |
| 16831 | 16830 | 0, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16832 | 16831 | #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, \ |
| 16834 | 16834 | (void*)&sqlite3Config, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16835 | 16835 | #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,\ |
| 16837 | 16838 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16838 | 16839 | #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), \ |
| 16840 | 16842 | pArg, 0, xFunc, 0, 0, 0, #zName, } |
| 16841 | 16843 | #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, \ |
| 16843 | 16845 | (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} } |
| 16844 | 16846 | #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, \ |
| 16846 | 16848 | SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}} |
| 16847 | 16849 | #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, \ |
| 16849 | 16852 | 0, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16850 | 16853 | |
| 16851 | 16854 | |
| 16852 | 16855 | /* |
| 16853 | 16856 | ** All current savepoints are stored in a linked list starting at |
| | @@ -17566,14 +17569,14 @@ |
| 17566 | 17569 | ** code representing the ">=" operator. This same integer code is reused |
| 17567 | 17570 | ** to represent the greater-than-or-equal-to operator in the expression |
| 17568 | 17571 | ** tree. |
| 17569 | 17572 | ** |
| 17570 | 17573 | ** 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 |
| 17573 | 17576 | ** 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. |
| 17575 | 17578 | ** |
| 17576 | 17579 | ** Expr.pRight and Expr.pLeft are the left and right subexpressions of a |
| 17577 | 17580 | ** binary operator. Either or both may be NULL. |
| 17578 | 17581 | ** |
| 17579 | 17582 | ** Expr.x.pList is a list of arguments if the expression is an SQL function, |
| | @@ -17609,11 +17612,11 @@ |
| 17609 | 17612 | ** |
| 17610 | 17613 | ** Expr objects can use a lot of memory space in database schema. To |
| 17611 | 17614 | ** help reduce memory requirements, sometimes an Expr object will be |
| 17612 | 17615 | ** truncated. And to reduce the number of memory allocations, sometimes |
| 17613 | 17616 | ** 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. |
| 17615 | 17618 | ** |
| 17616 | 17619 | ** If the EP_Reduced and EP_TokenOnly flags are set when |
| 17617 | 17620 | ** an Expr object is truncated. When EP_Reduced is set, then all |
| 17618 | 17621 | ** the child Expr objects in the Expr.pLeft and Expr.pRight subtrees |
| 17619 | 17622 | ** are contained within the same memory allocation. Note, however, that |
| | @@ -17678,12 +17681,11 @@ |
| 17678 | 17681 | int regReturn; /* Register used to hold return address */ |
| 17679 | 17682 | } sub; |
| 17680 | 17683 | } y; |
| 17681 | 17684 | }; |
| 17682 | 17685 | |
| 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. |
| 17685 | 17687 | ** Value restrictions: |
| 17686 | 17688 | ** |
| 17687 | 17689 | ** EP_Agg == NC_HasAgg == SF_HasAgg |
| 17688 | 17690 | ** EP_Win == NC_HasWin |
| 17689 | 17691 | */ |
| | @@ -17718,27 +17720,35 @@ |
| 17718 | 17720 | #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ |
| 17719 | 17721 | #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ |
| 17720 | 17722 | #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */ |
| 17721 | 17723 | /* 0x80000000 // Available */ |
| 17722 | 17724 | |
| 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 |
| 17725 | 17726 | ** upwards into parent nodes. |
| 17726 | 17727 | */ |
| 17727 | 17728 | #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc) |
| 17728 | 17729 | |
| 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 |
| 17731 | 17731 | ** Expr.flags field. |
| 17732 | 17732 | */ |
| 17733 | 17733 | #define ExprHasProperty(E,P) (((E)->flags&(P))!=0) |
| 17734 | 17734 | #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P)) |
| 17735 | 17735 | #define ExprSetProperty(E,P) (E)->flags|=(P) |
| 17736 | 17736 | #define ExprClearProperty(E,P) (E)->flags&=~(P) |
| 17737 | 17737 | #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue) |
| 17738 | 17738 | #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse) |
| 17739 | 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) |
| 17740 | 17750 | |
| 17741 | 17751 | /* Flags for use with Expr.vvaFlags |
| 17742 | 17752 | */ |
| 17743 | 17753 | #define EP_NoReduce 0x01 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 17744 | 17754 | #define EP_Immutable 0x02 /* Do not change this Expr node */ |
| | @@ -17817,15 +17827,16 @@ |
| 17817 | 17827 | unsigned done :1; /* A flag to indicate when processing is finished */ |
| 17818 | 17828 | unsigned reusable :1; /* Constant expression is reusable */ |
| 17819 | 17829 | unsigned bSorterRef :1; /* Defer evaluation until after sorting */ |
| 17820 | 17830 | unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */ |
| 17821 | 17831 | union { |
| 17822 | | - struct { |
| 17832 | + struct { /* Used by any ExprList other than Parse.pConsExpr */ |
| 17823 | 17833 | u16 iOrderByCol; /* For ORDER BY, column number in result set */ |
| 17824 | 17834 | u16 iAlias; /* Index into Parse.aAlias[] for zName */ |
| 17825 | 17835 | } 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 */ |
| 17827 | 17838 | } u; |
| 17828 | 17839 | } a[1]; /* One slot for each expression in the list */ |
| 17829 | 17840 | }; |
| 17830 | 17841 | |
| 17831 | 17842 | /* |
| | @@ -17859,10 +17870,17 @@ |
| 17859 | 17870 | }; |
| 17860 | 17871 | |
| 17861 | 17872 | /* |
| 17862 | 17873 | ** The SrcItem object represents a single term in the FROM clause of a query. |
| 17863 | 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 |
| 17864 | 17882 | */ |
| 17865 | 17883 | struct SrcItem { |
| 17866 | 17884 | Schema *pSchema; /* Schema to which this item is fixed */ |
| 17867 | 17885 | char *zDatabase; /* Name of database holding this table */ |
| 17868 | 17886 | char *zName; /* Name of the table */ |
| | @@ -18453,10 +18471,12 @@ |
| 18453 | 18471 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 18454 | 18472 | RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */ |
| 18455 | 18473 | #endif |
| 18456 | 18474 | }; |
| 18457 | 18475 | |
| 18476 | +/* Allowed values for Parse.eParseMode |
| 18477 | +*/ |
| 18458 | 18478 | #define PARSE_MODE_NORMAL 0 |
| 18459 | 18479 | #define PARSE_MODE_DECLARE_VTAB 1 |
| 18460 | 18480 | #define PARSE_MODE_RENAME 2 |
| 18461 | 18481 | #define PARSE_MODE_UNMAP 3 |
| 18462 | 18482 | |
| | @@ -20109,12 +20129,12 @@ |
| 20109 | 20129 | ** All of this is no-op for a production build. It only comes into |
| 20110 | 20130 | ** play when the SQLITE_MEMDEBUG compile-time option is used. |
| 20111 | 20131 | */ |
| 20112 | 20132 | #ifdef SQLITE_MEMDEBUG |
| 20113 | 20133 | 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); |
| 20116 | 20136 | #else |
| 20117 | 20137 | # define sqlite3MemdebugSetType(X,Y) /* no-op */ |
| 20118 | 20138 | # define sqlite3MemdebugHasType(X,Y) 1 |
| 20119 | 20139 | # define sqlite3MemdebugNoType(X,Y) 1 |
| 20120 | 20140 | #endif |
| | @@ -21432,10 +21452,22 @@ |
| 21432 | 21452 | ** Hash table for global functions - functions common to all |
| 21433 | 21453 | ** database connections. After initialization, this table is |
| 21434 | 21454 | ** read-only. |
| 21435 | 21455 | */ |
| 21436 | 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 */ |
| 21437 | 21469 | |
| 21438 | 21470 | #ifdef VDBE_PROFILE |
| 21439 | 21471 | /* |
| 21440 | 21472 | ** The following performance counter can be used in place of |
| 21441 | 21473 | ** sqlite3Hwtime() for profiling. This is a no-op on standard builds. |
| | @@ -24817,11 +24849,11 @@ |
| 24817 | 24849 | ** Given an allocation, find the MemBlockHdr for that allocation. |
| 24818 | 24850 | ** |
| 24819 | 24851 | ** This routine checks the guards at either end of the allocation and |
| 24820 | 24852 | ** if they are incorrect it asserts. |
| 24821 | 24853 | */ |
| 24822 | | -static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){ |
| 24854 | +static struct MemBlockHdr *sqlite3MemsysGetHeader(const void *pAllocation){ |
| 24823 | 24855 | struct MemBlockHdr *p; |
| 24824 | 24856 | int *pInt; |
| 24825 | 24857 | u8 *pU8; |
| 24826 | 24858 | int nReserve; |
| 24827 | 24859 | |
| | @@ -25064,11 +25096,11 @@ |
| 25064 | 25096 | ** This routine is designed for use within an assert() statement, to |
| 25065 | 25097 | ** verify the type of an allocation. For example: |
| 25066 | 25098 | ** |
| 25067 | 25099 | ** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 25068 | 25100 | */ |
| 25069 | | -SQLITE_PRIVATE int sqlite3MemdebugHasType(void *p, u8 eType){ |
| 25101 | +SQLITE_PRIVATE int sqlite3MemdebugHasType(const void *p, u8 eType){ |
| 25070 | 25102 | int rc = 1; |
| 25071 | 25103 | if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){ |
| 25072 | 25104 | struct MemBlockHdr *pHdr; |
| 25073 | 25105 | pHdr = sqlite3MemsysGetHeader(p); |
| 25074 | 25106 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| | @@ -25086,11 +25118,11 @@ |
| 25086 | 25118 | ** This routine is designed for use within an assert() statement, to |
| 25087 | 25119 | ** verify the type of an allocation. For example: |
| 25088 | 25120 | ** |
| 25089 | 25121 | ** assert( sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| 25090 | 25122 | */ |
| 25091 | | -SQLITE_PRIVATE int sqlite3MemdebugNoType(void *p, u8 eType){ |
| 25123 | +SQLITE_PRIVATE int sqlite3MemdebugNoType(const void *p, u8 eType){ |
| 25092 | 25124 | int rc = 1; |
| 25093 | 25125 | if( p && sqlite3GlobalConfig.m.xFree==sqlite3MemFree ){ |
| 25094 | 25126 | struct MemBlockHdr *pHdr; |
| 25095 | 25127 | pHdr = sqlite3MemsysGetHeader(p); |
| 25096 | 25128 | assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */ |
| | @@ -30551,10 +30583,11 @@ |
| 30551 | 30583 | zOp2[0] = 0; |
| 30552 | 30584 | } |
| 30553 | 30585 | sqlite3TreeViewLine(pView, "COLUMN(%d)%s%s", |
| 30554 | 30586 | pExpr->iColumn, zFlgs, zOp2); |
| 30555 | 30587 | }else{ |
| 30588 | + assert( ExprUseYTab(pExpr) ); |
| 30556 | 30589 | sqlite3TreeViewLine(pView, "{%d:%d} pTab=%p%s", |
| 30557 | 30590 | pExpr->iTable, pExpr->iColumn, |
| 30558 | 30591 | pExpr->y.pTab, zFlgs); |
| 30559 | 30592 | } |
| 30560 | 30593 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| | @@ -30570,15 +30603,17 @@ |
| 30570 | 30603 | } |
| 30571 | 30604 | break; |
| 30572 | 30605 | } |
| 30573 | 30606 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 30574 | 30607 | case TK_FLOAT: { |
| 30608 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30575 | 30609 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 30576 | 30610 | break; |
| 30577 | 30611 | } |
| 30578 | 30612 | #endif |
| 30579 | 30613 | case TK_STRING: { |
| 30614 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30580 | 30615 | sqlite3TreeViewLine(pView,"%Q", pExpr->u.zToken); |
| 30581 | 30616 | break; |
| 30582 | 30617 | } |
| 30583 | 30618 | case TK_NULL: { |
| 30584 | 30619 | sqlite3TreeViewLine(pView,"NULL"); |
| | @@ -30589,30 +30624,34 @@ |
| 30589 | 30624 | sqlite3ExprTruthValue(pExpr) ? "TRUE" : "FALSE", zFlgs); |
| 30590 | 30625 | break; |
| 30591 | 30626 | } |
| 30592 | 30627 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 30593 | 30628 | case TK_BLOB: { |
| 30629 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30594 | 30630 | sqlite3TreeViewLine(pView,"%s", pExpr->u.zToken); |
| 30595 | 30631 | break; |
| 30596 | 30632 | } |
| 30597 | 30633 | #endif |
| 30598 | 30634 | case TK_VARIABLE: { |
| 30635 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30599 | 30636 | sqlite3TreeViewLine(pView,"VARIABLE(%s,%d)", |
| 30600 | 30637 | pExpr->u.zToken, pExpr->iColumn); |
| 30601 | 30638 | break; |
| 30602 | 30639 | } |
| 30603 | 30640 | case TK_REGISTER: { |
| 30604 | 30641 | sqlite3TreeViewLine(pView,"REGISTER(%d)", pExpr->iTable); |
| 30605 | 30642 | break; |
| 30606 | 30643 | } |
| 30607 | 30644 | case TK_ID: { |
| 30645 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30608 | 30646 | sqlite3TreeViewLine(pView,"ID \"%w\"", pExpr->u.zToken); |
| 30609 | 30647 | break; |
| 30610 | 30648 | } |
| 30611 | 30649 | #ifndef SQLITE_OMIT_CAST |
| 30612 | 30650 | case TK_CAST: { |
| 30613 | 30651 | /* Expressions of the form: CAST(pLeft AS token) */ |
| 30652 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30614 | 30653 | sqlite3TreeViewLine(pView,"CAST %Q", pExpr->u.zToken); |
| 30615 | 30654 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 30616 | 30655 | break; |
| 30617 | 30656 | } |
| 30618 | 30657 | #endif /* SQLITE_OMIT_CAST */ |
| | @@ -30658,10 +30697,11 @@ |
| 30658 | 30697 | zUniOp = azOp[x]; |
| 30659 | 30698 | break; |
| 30660 | 30699 | } |
| 30661 | 30700 | |
| 30662 | 30701 | case TK_SPAN: { |
| 30702 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30663 | 30703 | sqlite3TreeViewLine(pView, "SPAN %Q", pExpr->u.zToken); |
| 30664 | 30704 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 30665 | 30705 | break; |
| 30666 | 30706 | } |
| 30667 | 30707 | |
| | @@ -30669,10 +30709,11 @@ |
| 30669 | 30709 | /* COLLATE operators without the EP_Collate flag are intended to |
| 30670 | 30710 | ** emulate collation associated with a table column. These show |
| 30671 | 30711 | ** up in the treeview output as "SOFT-COLLATE". Explicit COLLATE |
| 30672 | 30712 | ** operators that appear in the original SQL always have the |
| 30673 | 30713 | ** EP_Collate bit set and appear in treeview output as just "COLLATE" */ |
| 30714 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30674 | 30715 | sqlite3TreeViewLine(pView, "%sCOLLATE %Q%s", |
| 30675 | 30716 | !ExprHasProperty(pExpr, EP_Collate) ? "SOFT-" : "", |
| 30676 | 30717 | pExpr->u.zToken, zFlgs); |
| 30677 | 30718 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 0); |
| 30678 | 30719 | break; |
| | @@ -30684,17 +30725,19 @@ |
| 30684 | 30725 | Window *pWin; |
| 30685 | 30726 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 30686 | 30727 | pFarg = 0; |
| 30687 | 30728 | pWin = 0; |
| 30688 | 30729 | }else{ |
| 30730 | + assert( ExprUseXList(pExpr) ); |
| 30689 | 30731 | pFarg = pExpr->x.pList; |
| 30690 | 30732 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 30691 | 30733 | pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; |
| 30692 | 30734 | #else |
| 30693 | 30735 | pWin = 0; |
| 30694 | 30736 | #endif |
| 30695 | 30737 | } |
| 30738 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30696 | 30739 | if( pExpr->op==TK_AGG_FUNCTION ){ |
| 30697 | 30740 | sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p", |
| 30698 | 30741 | pExpr->op2, pExpr->u.zToken, zFlgs, |
| 30699 | 30742 | pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0, |
| 30700 | 30743 | pExpr->iAgg, pExpr->pAggInfo); |
| | @@ -30722,23 +30765,25 @@ |
| 30722 | 30765 | #endif |
| 30723 | 30766 | break; |
| 30724 | 30767 | } |
| 30725 | 30768 | #ifndef SQLITE_OMIT_SUBQUERY |
| 30726 | 30769 | case TK_EXISTS: { |
| 30770 | + assert( ExprUseXSelect(pExpr) ); |
| 30727 | 30771 | sqlite3TreeViewLine(pView, "EXISTS-expr flags=0x%x", pExpr->flags); |
| 30728 | 30772 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 30729 | 30773 | break; |
| 30730 | 30774 | } |
| 30731 | 30775 | case TK_SELECT: { |
| 30776 | + assert( ExprUseXSelect(pExpr) ); |
| 30732 | 30777 | sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); |
| 30733 | 30778 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 30734 | 30779 | break; |
| 30735 | 30780 | } |
| 30736 | 30781 | case TK_IN: { |
| 30737 | 30782 | sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); |
| 30738 | 30783 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 30739 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 30784 | + if( ExprUseXSelect(pExpr) ){ |
| 30740 | 30785 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 30741 | 30786 | }else{ |
| 30742 | 30787 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 30743 | 30788 | } |
| 30744 | 30789 | break; |
| | @@ -30755,13 +30800,16 @@ |
| 30755 | 30800 | ** X is stored in pExpr->pLeft. |
| 30756 | 30801 | ** Y is stored in pExpr->pList->a[0].pExpr. |
| 30757 | 30802 | ** Z is stored in pExpr->pList->a[1].pExpr. |
| 30758 | 30803 | */ |
| 30759 | 30804 | 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; |
| 30763 | 30811 | sqlite3TreeViewLine(pView, "BETWEEN"); |
| 30764 | 30812 | sqlite3TreeViewExpr(pView, pX, 1); |
| 30765 | 30813 | sqlite3TreeViewExpr(pView, pY, 1); |
| 30766 | 30814 | sqlite3TreeViewExpr(pView, pZ, 0); |
| 30767 | 30815 | break; |
| | @@ -30779,10 +30827,11 @@ |
| 30779 | 30827 | break; |
| 30780 | 30828 | } |
| 30781 | 30829 | case TK_CASE: { |
| 30782 | 30830 | sqlite3TreeViewLine(pView, "CASE"); |
| 30783 | 30831 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 30832 | + assert( ExprUseXList(pExpr) ); |
| 30784 | 30833 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| 30785 | 30834 | break; |
| 30786 | 30835 | } |
| 30787 | 30836 | #ifndef SQLITE_OMIT_TRIGGER |
| 30788 | 30837 | case TK_RAISE: { |
| | @@ -30791,10 +30840,11 @@ |
| 30791 | 30840 | case OE_Rollback: zType = "rollback"; break; |
| 30792 | 30841 | case OE_Abort: zType = "abort"; break; |
| 30793 | 30842 | case OE_Fail: zType = "fail"; break; |
| 30794 | 30843 | case OE_Ignore: zType = "ignore"; break; |
| 30795 | 30844 | } |
| 30845 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 30796 | 30846 | sqlite3TreeViewLine(pView, "RAISE %s(%Q)", zType, pExpr->u.zToken); |
| 30797 | 30847 | break; |
| 30798 | 30848 | } |
| 30799 | 30849 | #endif |
| 30800 | 30850 | case TK_MATCH: { |
| | @@ -30803,18 +30853,20 @@ |
| 30803 | 30853 | sqlite3TreeViewExpr(pView, pExpr->pRight, 0); |
| 30804 | 30854 | break; |
| 30805 | 30855 | } |
| 30806 | 30856 | case TK_VECTOR: { |
| 30807 | 30857 | char *z = sqlite3_mprintf("VECTOR%s",zFlgs); |
| 30858 | + assert( ExprUseXList(pExpr) ); |
| 30808 | 30859 | sqlite3TreeViewBareExprList(pView, pExpr->x.pList, z); |
| 30809 | 30860 | sqlite3_free(z); |
| 30810 | 30861 | break; |
| 30811 | 30862 | } |
| 30812 | 30863 | case TK_SELECT_COLUMN: { |
| 30813 | 30864 | sqlite3TreeViewLine(pView, "SELECT-COLUMN %d of [0..%d]%s", |
| 30814 | 30865 | pExpr->iColumn, pExpr->iTable-1, |
| 30815 | 30866 | pExpr->pRight==pExpr->pLeft ? " (SELECT-owner)" : ""); |
| 30867 | + assert( ExprUseXSelect(pExpr->pLeft) ); |
| 30816 | 30868 | sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0); |
| 30817 | 30869 | break; |
| 30818 | 30870 | } |
| 30819 | 30871 | case TK_IF_NULL_ROW: { |
| 30820 | 30872 | sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable); |
| | @@ -31887,20 +31939,10 @@ |
| 31887 | 31939 | /* #include <stdarg.h> */ |
| 31888 | 31940 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 31889 | 31941 | #include <math.h> |
| 31890 | 31942 | #endif |
| 31891 | 31943 | |
| 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 | 31944 | /* |
| 31903 | 31945 | ** Calls to sqlite3FaultSim() are used to simulate a failure during testing, |
| 31904 | 31946 | ** or to bypass normal error detection during testing in order to let |
| 31905 | 31947 | ** execute proceed futher downstream. |
| 31906 | 31948 | ** |
| | @@ -32143,10 +32185,11 @@ |
| 32143 | 32185 | } |
| 32144 | 32186 | } |
| 32145 | 32187 | z[j] = 0; |
| 32146 | 32188 | } |
| 32147 | 32189 | SQLITE_PRIVATE void sqlite3DequoteExpr(Expr *p){ |
| 32190 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 32148 | 32191 | assert( sqlite3Isquote(p->u.zToken[0]) ); |
| 32149 | 32192 | p->flags |= p->u.zToken[0]=='"' ? EP_Quoted|EP_DblQuoted : EP_Quoted; |
| 32150 | 32193 | sqlite3Dequote(p->u.zToken); |
| 32151 | 32194 | } |
| 32152 | 32195 | |
| | @@ -40209,10 +40252,15 @@ |
| 40209 | 40252 | if( randomnessPid!=osGetpid(0) ){ |
| 40210 | 40253 | randomnessPid = osGetpid(0); |
| 40211 | 40254 | sqlite3_randomness(0,0); |
| 40212 | 40255 | } |
| 40213 | 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 |
| 40214 | 40262 | |
| 40215 | 40263 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 40216 | 40264 | UnixUnusedFd *pUnused; |
| 40217 | 40265 | pUnused = findReusableFd(zName, flags); |
| 40218 | 40266 | if( pUnused ){ |
| | @@ -40270,12 +40318,10 @@ |
| 40270 | 40318 | if( fd<0 ){ |
| 40271 | 40319 | if( isNewJrnl && errno==EACCES && osAccess(zName, F_OK) ){ |
| 40272 | 40320 | /* If unable to create a journal because the directory is not |
| 40273 | 40321 | ** writable, change the error code to indicate that. */ |
| 40274 | 40322 | rc = SQLITE_READONLY_DIRECTORY; |
| 40275 | | - }else if( errno==EEXIST ){ |
| 40276 | | - rc = SQLITE_CANTOPEN_EXISTS; |
| 40277 | 40323 | }else if( errno!=EISDIR && isReadWrite ){ |
| 40278 | 40324 | /* Failed to open the file for read/write access. Try read-only. */ |
| 40279 | 40325 | flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); |
| 40280 | 40326 | openFlags &= ~(O_RDWR|O_CREAT); |
| 40281 | 40327 | flags |= SQLITE_OPEN_READONLY; |
| | @@ -48623,11 +48669,11 @@ |
| 48623 | 48669 | /* |
| 48624 | 48670 | ** Try to enlarge the memory allocation to hold at least sz bytes |
| 48625 | 48671 | */ |
| 48626 | 48672 | static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){ |
| 48627 | 48673 | 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) ){ |
| 48629 | 48675 | return SQLITE_FULL; |
| 48630 | 48676 | } |
| 48631 | 48677 | if( newSz>p->szMax ){ |
| 48632 | 48678 | return SQLITE_FULL; |
| 48633 | 48679 | } |
| | @@ -48822,11 +48868,11 @@ |
| 48822 | 48868 | int iAmt, |
| 48823 | 48869 | void **pp |
| 48824 | 48870 | ){ |
| 48825 | 48871 | MemStore *p = ((MemFile*)pFile)->pStore; |
| 48826 | 48872 | memdbEnter(p); |
| 48827 | | - if( iOfst+iAmt>p->sz ){ |
| 48873 | + if( iOfst+iAmt>p->sz || (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)!=0 ){ |
| 48828 | 48874 | *pp = 0; |
| 48829 | 48875 | }else{ |
| 48830 | 48876 | p->nMmap++; |
| 48831 | 48877 | *pp = (void*)(p->aData + iOfst); |
| 48832 | 48878 | } |
| | @@ -48856,13 +48902,11 @@ |
| 48856 | 48902 | int *pOutFlags |
| 48857 | 48903 | ){ |
| 48858 | 48904 | MemFile *pFile = (MemFile*)pFd; |
| 48859 | 48905 | MemStore *p = 0; |
| 48860 | 48906 | int szName; |
| 48861 | | - if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){ |
| 48862 | | - return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags); |
| 48863 | | - } |
| 48907 | + |
| 48864 | 48908 | memset(pFile, 0, sizeof(*pFile)); |
| 48865 | 48909 | szName = sqlite3Strlen30(zName); |
| 48866 | 48910 | if( szName>1 && zName[0]=='/' ){ |
| 48867 | 48911 | int i; |
| 48868 | 48912 | #ifndef SQLITE_MUTEX_OMIT |
| | @@ -48918,12 +48962,13 @@ |
| 48918 | 48962 | memset(p, 0, sizeof(*p)); |
| 48919 | 48963 | p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE; |
| 48920 | 48964 | p->szMax = sqlite3GlobalConfig.mxMemdbSize; |
| 48921 | 48965 | } |
| 48922 | 48966 | 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 | + } |
| 48925 | 48970 | pFd->pMethods = &memdb_io_methods; |
| 48926 | 48971 | memdbLeave(p); |
| 48927 | 48972 | return SQLITE_OK; |
| 48928 | 48973 | } |
| 48929 | 48974 | |
| | @@ -53114,10 +53159,11 @@ |
| 53114 | 53159 | u8 walSyncFlags; /* See description above */ |
| 53115 | 53160 | u8 tempFile; /* zFilename is a temporary or immutable file */ |
| 53116 | 53161 | u8 noLock; /* Do not lock (except in WAL mode) */ |
| 53117 | 53162 | u8 readOnly; /* True for a read-only database */ |
| 53118 | 53163 | u8 memDb; /* True to inhibit all file I/O */ |
| 53164 | + u8 memVfs; /* VFS-implemented memory database */ |
| 53119 | 53165 | |
| 53120 | 53166 | /************************************************************************** |
| 53121 | 53167 | ** The following block contains those class members that change during |
| 53122 | 53168 | ** routine operation. Class members not in this block are either fixed |
| 53123 | 53169 | ** when the pager is first created or else only change when there is a |
| | @@ -57356,11 +57402,11 @@ |
| 57356 | 57402 | if( zFilename && zFilename[0] ){ |
| 57357 | 57403 | int fout = 0; /* VFS flags returned by xOpen() */ |
| 57358 | 57404 | rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout); |
| 57359 | 57405 | assert( !memDb ); |
| 57360 | 57406 | #ifndef SQLITE_OMIT_DESERIALIZE |
| 57361 | | - memJM = (fout&SQLITE_OPEN_MEMORY)!=0; |
| 57407 | + pPager->memVfs = memJM = (fout&SQLITE_OPEN_MEMORY)!=0; |
| 57362 | 57408 | #endif |
| 57363 | 57409 | readOnly = (fout&SQLITE_OPEN_READONLY)!=0; |
| 57364 | 57410 | |
| 57365 | 57411 | /* If the file was successfully opened for read/write access, |
| 57366 | 57412 | ** choose a default page size in case we have to create the |
| | @@ -59293,11 +59339,11 @@ |
| 59293 | 59339 | |
| 59294 | 59340 | /* |
| 59295 | 59341 | ** Return true if this is an in-memory or temp-file backed pager. |
| 59296 | 59342 | */ |
| 59297 | 59343 | SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){ |
| 59298 | | - return pPager->tempFile; |
| 59344 | + return pPager->tempFile || pPager->memVfs; |
| 59299 | 59345 | } |
| 59300 | 59346 | |
| 59301 | 59347 | /* |
| 59302 | 59348 | ** Check that there are at least nSavepoint savepoints open. If there are |
| 59303 | 59349 | ** currently less than nSavepoints open, then open one or more savepoints |
| | @@ -59613,11 +59659,11 @@ |
| 59613 | 59659 | */ |
| 59614 | 59660 | pPg->flags &= ~PGHDR_NEED_SYNC; |
| 59615 | 59661 | pPgOld = sqlite3PagerLookup(pPager, pgno); |
| 59616 | 59662 | assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB ); |
| 59617 | 59663 | if( pPgOld ){ |
| 59618 | | - if( pPgOld->nRef>1 ){ |
| 59664 | + if( NEVER(pPgOld->nRef>1) ){ |
| 59619 | 59665 | sqlite3PagerUnrefNotNull(pPgOld); |
| 59620 | 59666 | return SQLITE_CORRUPT_BKPT; |
| 59621 | 59667 | } |
| 59622 | 59668 | pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC); |
| 59623 | 59669 | if( pPager->tempFile ){ |
| | @@ -64637,11 +64683,10 @@ |
| 64637 | 64683 | ** Access to all fields of this structure is controlled by the mutex |
| 64638 | 64684 | ** stored in MemPage.pBt->mutex. |
| 64639 | 64685 | */ |
| 64640 | 64686 | struct MemPage { |
| 64641 | 64687 | u8 isInit; /* True if previously initialized. MUST BE FIRST! */ |
| 64642 | | - u8 bBusy; /* Prevent endless loops on corrupt database files */ |
| 64643 | 64688 | u8 intKey; /* True if table b-trees. False for index b-trees */ |
| 64644 | 64689 | u8 intKeyLeaf; /* True if the leaf of an intKey table */ |
| 64645 | 64690 | Pgno pgno; /* Page number for this page */ |
| 64646 | 64691 | /* Only the first 8 bytes (above) are zeroed by pager.c when a new page |
| 64647 | 64692 | ** is allocated. All fields that follow must be initialized before use */ |
| | @@ -70227,11 +70272,13 @@ |
| 70227 | 70272 | #endif |
| 70228 | 70273 | |
| 70229 | 70274 | assert( pPage ); |
| 70230 | 70275 | assert( eOp==0 || eOp==1 ); |
| 70231 | 70276 | assert( pCur->eState==CURSOR_VALID ); |
| 70232 | | - assert( pCur->ix<pPage->nCell ); |
| 70277 | + if( pCur->ix>=pPage->nCell ){ |
| 70278 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 70279 | + } |
| 70233 | 70280 | assert( cursorHoldsMutex(pCur) ); |
| 70234 | 70281 | |
| 70235 | 70282 | getCellInfo(pCur); |
| 70236 | 70283 | aPayload = pCur->info.pPayload; |
| 70237 | 70284 | assert( offset+amt <= pCur->info.nPayload ); |
| | @@ -70414,11 +70461,10 @@ |
| 70414 | 70461 | */ |
| 70415 | 70462 | SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 70416 | 70463 | assert( cursorHoldsMutex(pCur) ); |
| 70417 | 70464 | assert( pCur->eState==CURSOR_VALID ); |
| 70418 | 70465 | assert( pCur->iPage>=0 && pCur->pPage ); |
| 70419 | | - assert( pCur->ix<pCur->pPage->nCell ); |
| 70420 | 70466 | return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); |
| 70421 | 70467 | } |
| 70422 | 70468 | |
| 70423 | 70469 | /* |
| 70424 | 70470 | ** This variant of sqlite3BtreePayload() works even if the cursor has not |
| | @@ -70476,11 +70522,11 @@ |
| 70476 | 70522 | int amt; |
| 70477 | 70523 | assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage); |
| 70478 | 70524 | assert( pCur->eState==CURSOR_VALID ); |
| 70479 | 70525 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 70480 | 70526 | assert( cursorOwnsBtShared(pCur) ); |
| 70481 | | - assert( pCur->ix<pCur->pPage->nCell ); |
| 70527 | + assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB ); |
| 70482 | 70528 | assert( pCur->info.nSize>0 ); |
| 70483 | 70529 | assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB ); |
| 70484 | 70530 | assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB); |
| 70485 | 70531 | amt = pCur->info.nLocal; |
| 70486 | 70532 | if( amt>(int)(pCur->pPage->aDataEnd - pCur->info.pPayload) ){ |
| | @@ -71262,20 +71308,10 @@ |
| 71262 | 71308 | ** module cov1/btree78.test testcase 220 (2018-06-08) for an |
| 71263 | 71309 | ** example. */ |
| 71264 | 71310 | return SQLITE_CORRUPT_BKPT; |
| 71265 | 71311 | } |
| 71266 | 71312 | |
| 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 | 71313 | if( idx>=pPage->nCell ){ |
| 71278 | 71314 | if( !pPage->leaf ){ |
| 71279 | 71315 | rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); |
| 71280 | 71316 | if( rc ) return rc; |
| 71281 | 71317 | return moveToLeftmost(pCur); |
| | @@ -71759,11 +71795,11 @@ |
| 71759 | 71795 | |
| 71760 | 71796 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 71761 | 71797 | assert( CORRUPT_DB || iPage>1 ); |
| 71762 | 71798 | assert( !pMemPage || pMemPage->pgno==iPage ); |
| 71763 | 71799 | |
| 71764 | | - if( iPage<2 || iPage>pBt->nPage ){ |
| 71800 | + if( NEVER(iPage<2) || iPage>pBt->nPage ){ |
| 71765 | 71801 | return SQLITE_CORRUPT_BKPT; |
| 71766 | 71802 | } |
| 71767 | 71803 | if( pMemPage ){ |
| 71768 | 71804 | pPage = pMemPage; |
| 71769 | 71805 | sqlite3PagerRef(pPage->pDbPage); |
| | @@ -72484,11 +72520,11 @@ |
| 72484 | 72520 | int k; /* Current slot in pCArray->apEnd[] */ |
| 72485 | 72521 | u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ |
| 72486 | 72522 | |
| 72487 | 72523 | assert( i<iEnd ); |
| 72488 | 72524 | j = get2byte(&aData[hdr+5]); |
| 72489 | | - if( NEVER(j>(u32)usableSize) ){ j = 0; } |
| 72525 | + if( j>(u32)usableSize ){ j = 0; } |
| 72490 | 72526 | memcpy(&pTmp[j], &aData[j], usableSize - j); |
| 72491 | 72527 | |
| 72492 | 72528 | for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){} |
| 72493 | 72529 | pSrcEnd = pCArray->apEnd[k]; |
| 72494 | 72530 | |
| | @@ -74360,11 +74396,14 @@ |
| 74360 | 74396 | assert( szNew==pPage->xCellSize(pPage, newCell) ); |
| 74361 | 74397 | assert( szNew <= MX_CELL_SIZE(pBt) ); |
| 74362 | 74398 | idx = pCur->ix; |
| 74363 | 74399 | if( loc==0 ){ |
| 74364 | 74400 | CellInfo info; |
| 74365 | | - assert( idx<pPage->nCell ); |
| 74401 | + assert( idx>=0 ); |
| 74402 | + if( idx>=pPage->nCell ){ |
| 74403 | + return SQLITE_CORRUPT_BKPT; |
| 74404 | + } |
| 74366 | 74405 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 74367 | 74406 | if( rc ){ |
| 74368 | 74407 | goto end_insert; |
| 74369 | 74408 | } |
| 74370 | 74409 | oldCell = findCell(pPage, idx); |
| | @@ -74946,15 +74985,16 @@ |
| 74946 | 74985 | if( pgno>btreePagecount(pBt) ){ |
| 74947 | 74986 | return SQLITE_CORRUPT_BKPT; |
| 74948 | 74987 | } |
| 74949 | 74988 | rc = getAndInitPage(pBt, pgno, &pPage, 0, 0); |
| 74950 | 74989 | if( rc ) return rc; |
| 74951 | | - if( pPage->bBusy ){ |
| 74990 | + if( (pBt->openFlags & BTREE_SINGLE)==0 |
| 74991 | + && sqlite3PagerPageRefcount(pPage->pDbPage)!=1 |
| 74992 | + ){ |
| 74952 | 74993 | rc = SQLITE_CORRUPT_BKPT; |
| 74953 | 74994 | goto cleardatabasepage_out; |
| 74954 | 74995 | } |
| 74955 | | - pPage->bBusy = 1; |
| 74956 | 74996 | hdr = pPage->hdrOffset; |
| 74957 | 74997 | for(i=0; i<pPage->nCell; i++){ |
| 74958 | 74998 | pCell = findCell(pPage, i); |
| 74959 | 74999 | if( !pPage->leaf ){ |
| 74960 | 75000 | rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange); |
| | @@ -74977,11 +75017,10 @@ |
| 74977 | 75017 | }else if( (rc = sqlite3PagerWrite(pPage->pDbPage))==0 ){ |
| 74978 | 75018 | zeroPage(pPage, pPage->aData[hdr] | PTF_LEAF); |
| 74979 | 75019 | } |
| 74980 | 75020 | |
| 74981 | 75021 | cleardatabasepage_out: |
| 74982 | | - pPage->bBusy = 0; |
| 74983 | 75022 | releasePage(pPage); |
| 74984 | 75023 | return rc; |
| 74985 | 75024 | } |
| 74986 | 75025 | |
| 74987 | 75026 | /* |
| | @@ -75056,14 +75095,14 @@ |
| 75056 | 75095 | assert( iTable>=2 ); |
| 75057 | 75096 | if( iTable>btreePagecount(pBt) ){ |
| 75058 | 75097 | return SQLITE_CORRUPT_BKPT; |
| 75059 | 75098 | } |
| 75060 | 75099 | |
| 75061 | | - rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0); |
| 75062 | | - if( rc ) return rc; |
| 75063 | 75100 | 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) ){ |
| 75065 | 75104 | releasePage(pPage); |
| 75066 | 75105 | return rc; |
| 75067 | 75106 | } |
| 75068 | 75107 | |
| 75069 | 75108 | *piMoved = 0; |
| | @@ -78434,12 +78473,14 @@ |
| 78434 | 78473 | ExprList *pList = 0; /* Function arguments */ |
| 78435 | 78474 | int i; /* Iterator variable */ |
| 78436 | 78475 | |
| 78437 | 78476 | assert( pCtx!=0 ); |
| 78438 | 78477 | assert( (p->flags & EP_TokenOnly)==0 ); |
| 78478 | + assert( ExprUseXList(p) ); |
| 78439 | 78479 | pList = p->x.pList; |
| 78440 | 78480 | if( pList ) nVal = pList->nExpr; |
| 78481 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 78441 | 78482 | pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0); |
| 78442 | 78483 | assert( pFunc ); |
| 78443 | 78484 | if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 |
| 78444 | 78485 | || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) |
| 78445 | 78486 | ){ |
| | @@ -78539,11 +78580,13 @@ |
| 78539 | 78580 | ** check ensures that an EP_TokenOnly expression is never passed down |
| 78540 | 78581 | ** into valueFromFunction(). */ |
| 78541 | 78582 | assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 ); |
| 78542 | 78583 | |
| 78543 | 78584 | 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); |
| 78545 | 78588 | rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx); |
| 78546 | 78589 | testcase( rc!=SQLITE_OK ); |
| 78547 | 78590 | if( *ppVal ){ |
| 78548 | 78591 | sqlite3VdbeMemCast(*ppVal, aff, SQLITE_UTF8); |
| 78549 | 78592 | sqlite3ValueApplyAffinity(*ppVal, affinity, SQLITE_UTF8); |
| | @@ -78612,10 +78655,11 @@ |
| 78612 | 78655 | sqlite3VdbeMemSetNull(pVal); |
| 78613 | 78656 | } |
| 78614 | 78657 | #ifndef SQLITE_OMIT_BLOB_LITERAL |
| 78615 | 78658 | else if( op==TK_BLOB ){ |
| 78616 | 78659 | int nVal; |
| 78660 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 78617 | 78661 | assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' ); |
| 78618 | 78662 | assert( pExpr->u.zToken[1]=='\'' ); |
| 78619 | 78663 | pVal = valueNew(db, pCtx); |
| 78620 | 78664 | if( !pVal ) goto no_mem; |
| 78621 | 78665 | zVal = &pExpr->u.zToken[2]; |
| | @@ -78629,10 +78673,11 @@ |
| 78629 | 78673 | else if( op==TK_FUNCTION && pCtx!=0 ){ |
| 78630 | 78674 | rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx); |
| 78631 | 78675 | } |
| 78632 | 78676 | #endif |
| 78633 | 78677 | else if( op==TK_TRUEFALSE ){ |
| 78678 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 78634 | 78679 | pVal = valueNew(db, pCtx); |
| 78635 | 78680 | if( pVal ){ |
| 78636 | 78681 | pVal->flags = MEM_Int; |
| 78637 | 78682 | pVal->u.i = pExpr->u.zToken[4]==0; |
| 78638 | 78683 | } |
| | @@ -80501,10 +80546,11 @@ |
| 80501 | 80546 | */ |
| 80502 | 80547 | static void displayP4Expr(StrAccum *p, Expr *pExpr){ |
| 80503 | 80548 | const char *zOp = 0; |
| 80504 | 80549 | switch( pExpr->op ){ |
| 80505 | 80550 | case TK_STRING: |
| 80551 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 80506 | 80552 | sqlite3_str_appendf(p, "%Q", pExpr->u.zToken); |
| 80507 | 80553 | break; |
| 80508 | 80554 | case TK_INTEGER: |
| 80509 | 80555 | sqlite3_str_appendf(p, "%d", pExpr->u.iValue); |
| 80510 | 80556 | break; |
| | @@ -80847,12 +80893,12 @@ |
| 80847 | 80893 | ** with no indexes using a single prepared INSERT statement, bind() |
| 80848 | 80894 | ** and reset(). Inserts are grouped into a transaction. |
| 80849 | 80895 | */ |
| 80850 | 80896 | testcase( p->flags & MEM_Agg ); |
| 80851 | 80897 | testcase( p->flags & MEM_Dyn ); |
| 80852 | | - testcase( p->xDel==sqlite3VdbeFrameMemDel ); |
| 80853 | 80898 | if( p->flags&(MEM_Agg|MEM_Dyn) ){ |
| 80899 | + testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel ); |
| 80854 | 80900 | sqlite3VdbeMemRelease(p); |
| 80855 | 80901 | }else if( p->szMalloc ){ |
| 80856 | 80902 | sqlite3DbFreeNN(db, p->zMalloc); |
| 80857 | 80903 | p->szMalloc = 0; |
| 80858 | 80904 | } |
| | @@ -84553,12 +84599,12 @@ |
| 84553 | 84599 | /**************************** sqlite3_result_ ******************************* |
| 84554 | 84600 | ** The following routines are used by user-defined functions to specify |
| 84555 | 84601 | ** the function result. |
| 84556 | 84602 | ** |
| 84557 | 84603 | ** 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. |
| 84560 | 84606 | ** |
| 84561 | 84607 | ** The invokeValueDestructor(P,X) routine invokes destructor function X() |
| 84562 | 84608 | ** on value P is not going to be used and need to be destroyed. |
| 84563 | 84609 | */ |
| 84564 | 84610 | static void setResultStrOrError( |
| | @@ -84566,12 +84612,20 @@ |
| 84566 | 84612 | const char *z, /* String pointer */ |
| 84567 | 84613 | int n, /* Bytes in string, or negative */ |
| 84568 | 84614 | u8 enc, /* Encoding of z. 0 for BLOBs */ |
| 84569 | 84615 | void (*xDel)(void*) /* Destructor function */ |
| 84570 | 84616 | ){ |
| 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 | + } |
| 84573 | 84627 | } |
| 84574 | 84628 | } |
| 84575 | 84629 | static int invokeValueDestructor( |
| 84576 | 84630 | const void *p, /* Value to destroy */ |
| 84577 | 84631 | void (*xDel)(void*), /* The destructor */ |
| | @@ -90536,11 +90590,11 @@ |
| 90536 | 90590 | assert( aMem[pOp->p3].flags & MEM_Null ); |
| 90537 | 90591 | aMem[pOp->p3].n = 0; |
| 90538 | 90592 | aMem[pOp->p3].z = ""; |
| 90539 | 90593 | } |
| 90540 | 90594 | pCx = p->apCsr[pOp->p1]; |
| 90541 | | - if( pCx && !pCx->hasBeenDuped ){ |
| 90595 | + if( pCx && !pCx->hasBeenDuped && ALWAYS(pOp->p2<=pCx->nField) ){ |
| 90542 | 90596 | /* If the ephermeral table is already open and has no duplicates from |
| 90543 | 90597 | ** OP_OpenDup, then erase all existing content so that the table is |
| 90544 | 90598 | ** empty again, rather than creating a new table. */ |
| 90545 | 90599 | assert( pCx->isEphemeral ); |
| 90546 | 90600 | pCx->seqCount = 0; |
| | @@ -95092,11 +95146,11 @@ |
| 95092 | 95146 | /* Check that the column is not part of an FK child key definition. It |
| 95093 | 95147 | ** is not necessary to check if it is part of a parent key, as parent |
| 95094 | 95148 | ** key columns must be indexed. The check below will pick up this |
| 95095 | 95149 | ** case. */ |
| 95096 | 95150 | FKey *pFKey; |
| 95097 | | - assert( !IsVirtual(pTab) ); |
| 95151 | + assert( IsOrdinaryTable(pTab) ); |
| 95098 | 95152 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 95099 | 95153 | int j; |
| 95100 | 95154 | for(j=0; j<pFKey->nCol; j++){ |
| 95101 | 95155 | if( pFKey->aCol[j].iFrom==iCol ){ |
| 95102 | 95156 | zFault = "foreign key"; |
| | @@ -96682,11 +96736,11 @@ |
| 96682 | 96736 | void *p = 0; |
| 96683 | 96737 | int chunksize = 4*1024; |
| 96684 | 96738 | sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize); |
| 96685 | 96739 | sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte); |
| 96686 | 96740 | sqlite3OsFetch(pFd, 0, (int)nByte, &p); |
| 96687 | | - sqlite3OsUnfetch(pFd, 0, p); |
| 96741 | + if( p ) sqlite3OsUnfetch(pFd, 0, p); |
| 96688 | 96742 | } |
| 96689 | 96743 | } |
| 96690 | 96744 | #else |
| 96691 | 96745 | # define vdbeSorterExtendFile(x,y,z) |
| 96692 | 96746 | #endif |
| | @@ -99101,11 +99155,11 @@ |
| 99101 | 99155 | if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort; |
| 99102 | 99156 | if( pExpr->pRight ){ |
| 99103 | 99157 | assert( !ExprHasProperty(pExpr, EP_WinFunc) ); |
| 99104 | 99158 | pExpr = pExpr->pRight; |
| 99105 | 99159 | continue; |
| 99106 | | - }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 99160 | + }else if( ExprUseXSelect(pExpr) ){ |
| 99107 | 99161 | assert( !ExprHasProperty(pExpr, EP_WinFunc) ); |
| 99108 | 99162 | if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort; |
| 99109 | 99163 | }else{ |
| 99110 | 99164 | if( pExpr->x.pList ){ |
| 99111 | 99165 | if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort; |
| | @@ -99373,10 +99427,11 @@ |
| 99373 | 99427 | sqlite3ExprDelete(db, pDup); |
| 99374 | 99428 | pDup = 0; |
| 99375 | 99429 | }else{ |
| 99376 | 99430 | incrAggFunctionDepth(pDup, nSubquery); |
| 99377 | 99431 | if( pExpr->op==TK_COLLATE ){ |
| 99432 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 99378 | 99433 | pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); |
| 99379 | 99434 | } |
| 99380 | 99435 | |
| 99381 | 99436 | /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This |
| 99382 | 99437 | ** prevents ExprDelete() from deleting the Expr structure itself, |
| | @@ -99476,10 +99531,11 @@ |
| 99476 | 99531 | SQLITE_PRIVATE Bitmask sqlite3ExprColUsed(Expr *pExpr){ |
| 99477 | 99532 | int n; |
| 99478 | 99533 | Table *pExTab; |
| 99479 | 99534 | |
| 99480 | 99535 | n = pExpr->iColumn; |
| 99536 | + assert( ExprUseYTab(pExpr) ); |
| 99481 | 99537 | pExTab = pExpr->y.pTab; |
| 99482 | 99538 | assert( pExTab!=0 ); |
| 99483 | 99539 | if( (pExTab->tabFlags & TF_HasGenerated)!=0 |
| 99484 | 99540 | && (pExTab->aCol[n].colFlags & COLFLAG_GENERATED)!=0 |
| 99485 | 99541 | ){ |
| | @@ -99613,10 +99669,11 @@ |
| 99613 | 99669 | const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName; |
| 99614 | 99670 | assert( zTabName!=0 ); |
| 99615 | 99671 | if( sqlite3StrICmp(zTabName, zTab)!=0 ){ |
| 99616 | 99672 | continue; |
| 99617 | 99673 | } |
| 99674 | + assert( ExprUseYTab(pExpr) ); |
| 99618 | 99675 | if( IN_RENAME_OBJECT && pItem->zAlias ){ |
| 99619 | 99676 | sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); |
| 99620 | 99677 | } |
| 99621 | 99678 | } |
| 99622 | 99679 | hCol = sqlite3StrIHash(zCol); |
| | @@ -99644,10 +99701,11 @@ |
| 99644 | 99701 | pMatch = pItem; |
| 99645 | 99702 | } |
| 99646 | 99703 | } |
| 99647 | 99704 | if( pMatch ){ |
| 99648 | 99705 | pExpr->iTable = pMatch->iCursor; |
| 99706 | + assert( ExprUseYTab(pExpr) ); |
| 99649 | 99707 | pExpr->y.pTab = pMatch->pTab; |
| 99650 | 99708 | /* RIGHT JOIN not (yet) supported */ |
| 99651 | 99709 | assert( (pMatch->fg.jointype & JT_RIGHT)==0 ); |
| 99652 | 99710 | if( (pMatch->fg.jointype & JT_LEFT)!=0 ){ |
| 99653 | 99711 | ExprSetProperty(pExpr, EP_CanBeNull); |
| | @@ -99717,10 +99775,11 @@ |
| 99717 | 99775 | cnt++; |
| 99718 | 99776 | pMatch = 0; |
| 99719 | 99777 | #ifndef SQLITE_OMIT_UPSERT |
| 99720 | 99778 | if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){ |
| 99721 | 99779 | testcase( iCol==(-1) ); |
| 99780 | + assert( ExprUseYTab(pExpr) ); |
| 99722 | 99781 | if( IN_RENAME_OBJECT ){ |
| 99723 | 99782 | pExpr->iColumn = iCol; |
| 99724 | 99783 | pExpr->y.pTab = pTab; |
| 99725 | 99784 | eNewExprOp = TK_COLUMN; |
| 99726 | 99785 | }else{ |
| | @@ -99729,10 +99788,11 @@ |
| 99729 | 99788 | eNewExprOp = TK_REGISTER; |
| 99730 | 99789 | } |
| 99731 | 99790 | }else |
| 99732 | 99791 | #endif /* SQLITE_OMIT_UPSERT */ |
| 99733 | 99792 | { |
| 99793 | + assert( ExprUseYTab(pExpr) ); |
| 99734 | 99794 | pExpr->y.pTab = pTab; |
| 99735 | 99795 | if( pParse->bReturning ){ |
| 99736 | 99796 | eNewExprOp = TK_REGISTER; |
| 99737 | 99797 | pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable + |
| 99738 | 99798 | sqlite3TableColumnToStorage(pTab, iCol) + 1; |
| | @@ -99803,12 +99863,12 @@ |
| 99803 | 99863 | if( pEList->a[j].eEName==ENAME_NAME |
| 99804 | 99864 | && sqlite3_stricmp(zAs, zCol)==0 |
| 99805 | 99865 | ){ |
| 99806 | 99866 | Expr *pOrig; |
| 99807 | 99867 | 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 ); |
| 99810 | 99870 | pOrig = pEList->a[j].pExpr; |
| 99811 | 99871 | if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){ |
| 99812 | 99872 | sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); |
| 99813 | 99873 | return WRC_Abort; |
| 99814 | 99874 | } |
| | @@ -99876,11 +99936,11 @@ |
| 99876 | 99936 | "double-quoted string literal: \"%w\"", zCol); |
| 99877 | 99937 | #ifdef SQLITE_ENABLE_NORMALIZE |
| 99878 | 99938 | sqlite3VdbeAddDblquoteStr(db, pParse->pVdbe, zCol); |
| 99879 | 99939 | #endif |
| 99880 | 99940 | pExpr->op = TK_STRING; |
| 99881 | | - pExpr->y.pTab = 0; |
| 99941 | + memset(&pExpr->y, 0, sizeof(pExpr->y)); |
| 99882 | 99942 | return WRC_Prune; |
| 99883 | 99943 | } |
| 99884 | 99944 | if( sqlite3ExprIdToTrueFalse(pExpr) ){ |
| 99885 | 99945 | return WRC_Prune; |
| 99886 | 99946 | } |
| | @@ -99962,11 +100022,13 @@ |
| 99962 | 100022 | */ |
| 99963 | 100023 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){ |
| 99964 | 100024 | Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0); |
| 99965 | 100025 | if( p ){ |
| 99966 | 100026 | 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; |
| 99968 | 100030 | p->iTable = pItem->iCursor; |
| 99969 | 100031 | if( p->y.pTab->iPKey==iCol ){ |
| 99970 | 100032 | p->iColumn = -1; |
| 99971 | 100033 | }else{ |
| 99972 | 100034 | p->iColumn = (ynVar)iCol; |
| | @@ -100029,10 +100091,11 @@ |
| 100029 | 100091 | ** value between 1.0 and 0.0. |
| 100030 | 100092 | */ |
| 100031 | 100093 | static int exprProbability(Expr *p){ |
| 100032 | 100094 | double r = -1.0; |
| 100033 | 100095 | if( p->op!=TK_FLOAT ) return -1; |
| 100096 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 100034 | 100097 | sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8); |
| 100035 | 100098 | assert( r>=0.0 ); |
| 100036 | 100099 | if( r>1.0 ) return -1; |
| 100037 | 100100 | return (int)(r*134217728.0); |
| 100038 | 100101 | } |
| | @@ -100077,10 +100140,11 @@ |
| 100077 | 100140 | SrcList *pSrcList = pNC->pSrcList; |
| 100078 | 100141 | SrcItem *pItem; |
| 100079 | 100142 | assert( pSrcList && pSrcList->nSrc>=1 ); |
| 100080 | 100143 | pItem = pSrcList->a; |
| 100081 | 100144 | pExpr->op = TK_COLUMN; |
| 100145 | + assert( ExprUseYTab(pExpr) ); |
| 100082 | 100146 | pExpr->y.pTab = pItem->pTab; |
| 100083 | 100147 | pExpr->iTable = pItem->iCursor; |
| 100084 | 100148 | pExpr->iColumn--; |
| 100085 | 100149 | pExpr->affExpr = SQLITE_AFF_INTEGER; |
| 100086 | 100150 | break; |
| | @@ -100109,10 +100173,11 @@ |
| 100109 | 100173 | anRef[i] = p->nRef; |
| 100110 | 100174 | } |
| 100111 | 100175 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 100112 | 100176 | if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){ |
| 100113 | 100177 | testcase( ExprHasProperty(pExpr, EP_FromJoin) ); |
| 100178 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 100114 | 100179 | if( pExpr->op==TK_NOTNULL ){ |
| 100115 | 100180 | pExpr->u.zToken = "true"; |
| 100116 | 100181 | ExprSetProperty(pExpr, EP_IsTrue); |
| 100117 | 100182 | }else{ |
| 100118 | 100183 | pExpr->u.zToken = "false"; |
| | @@ -100144,10 +100209,11 @@ |
| 100144 | 100209 | Expr *pRight; |
| 100145 | 100210 | |
| 100146 | 100211 | if( pExpr->op==TK_ID ){ |
| 100147 | 100212 | zDb = 0; |
| 100148 | 100213 | zTable = 0; |
| 100214 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 100149 | 100215 | zColumn = pExpr->u.zToken; |
| 100150 | 100216 | }else{ |
| 100151 | 100217 | Expr *pLeft = pExpr->pLeft; |
| 100152 | 100218 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 100153 | 100219 | testcase( pNC->ncFlags & NC_GenCol ); |
| | @@ -100156,16 +100222,19 @@ |
| 100156 | 100222 | pRight = pExpr->pRight; |
| 100157 | 100223 | if( pRight->op==TK_ID ){ |
| 100158 | 100224 | zDb = 0; |
| 100159 | 100225 | }else{ |
| 100160 | 100226 | assert( pRight->op==TK_DOT ); |
| 100227 | + assert( !ExprHasProperty(pRight, EP_IntValue) ); |
| 100161 | 100228 | zDb = pLeft->u.zToken; |
| 100162 | 100229 | pLeft = pRight->pLeft; |
| 100163 | 100230 | pRight = pRight->pRight; |
| 100164 | 100231 | } |
| 100232 | + assert( ExprUseUToken(pLeft) && ExprUseUToken(pRight) ); |
| 100165 | 100233 | zTable = pLeft->u.zToken; |
| 100166 | 100234 | zColumn = pRight->u.zToken; |
| 100235 | + assert( ExprUseYTab(pExpr) ); |
| 100167 | 100236 | if( IN_RENAME_OBJECT ){ |
| 100168 | 100237 | sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight); |
| 100169 | 100238 | sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft); |
| 100170 | 100239 | } |
| 100171 | 100240 | } |
| | @@ -100186,11 +100255,11 @@ |
| 100186 | 100255 | u8 enc = ENC(pParse->db); /* The database encoding */ |
| 100187 | 100256 | int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin)); |
| 100188 | 100257 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100189 | 100258 | Window *pWin = (IsWindowFunc(pExpr) ? pExpr->y.pWin : 0); |
| 100190 | 100259 | #endif |
| 100191 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 100260 | + assert( !ExprHasProperty(pExpr, EP_xIsSelect|EP_IntValue) ); |
| 100192 | 100261 | zId = pExpr->u.zToken; |
| 100193 | 100262 | nId = sqlite3Strlen30(zId); |
| 100194 | 100263 | pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0); |
| 100195 | 100264 | if( pDef==0 ){ |
| 100196 | 100265 | pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0); |
| | @@ -100350,11 +100419,11 @@ |
| 100350 | 100419 | sqlite3WalkExprList(pWalker, pList); |
| 100351 | 100420 | if( is_agg ){ |
| 100352 | 100421 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 100353 | 100422 | if( pWin ){ |
| 100354 | 100423 | Select *pSel = pNC->pWinSelect; |
| 100355 | | - assert( pWin==pExpr->y.pWin ); |
| 100424 | + assert( pWin==0 || (ExprUseYWin(pExpr) && pWin==pExpr->y.pWin) ); |
| 100356 | 100425 | if( IN_RENAME_OBJECT==0 ){ |
| 100357 | 100426 | sqlite3WindowUpdate(pParse, pSel ? pSel->pWinDefn : 0, pWin, pDef); |
| 100358 | 100427 | if( pParse->db->mallocFailed ) break; |
| 100359 | 100428 | } |
| 100360 | 100429 | sqlite3WalkExprList(pWalker, pWin->pPartition); |
| | @@ -100399,11 +100468,11 @@ |
| 100399 | 100468 | case TK_SELECT: |
| 100400 | 100469 | case TK_EXISTS: testcase( pExpr->op==TK_EXISTS ); |
| 100401 | 100470 | #endif |
| 100402 | 100471 | case TK_IN: { |
| 100403 | 100472 | testcase( pExpr->op==TK_IN ); |
| 100404 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 100473 | + if( ExprUseXSelect(pExpr) ){ |
| 100405 | 100474 | int nRef = pNC->nRef; |
| 100406 | 100475 | testcase( pNC->ncFlags & NC_IsCheck ); |
| 100407 | 100476 | testcase( pNC->ncFlags & NC_PartIdx ); |
| 100408 | 100477 | testcase( pNC->ncFlags & NC_IdxExpr ); |
| 100409 | 100478 | testcase( pNC->ncFlags & NC_GenCol ); |
| | @@ -100456,10 +100525,11 @@ |
| 100456 | 100525 | int nLeft, nRight; |
| 100457 | 100526 | if( pParse->db->mallocFailed ) break; |
| 100458 | 100527 | assert( pExpr->pLeft!=0 ); |
| 100459 | 100528 | nLeft = sqlite3ExprVectorSize(pExpr->pLeft); |
| 100460 | 100529 | if( pExpr->op==TK_BETWEEN ){ |
| 100530 | + assert( ExprUseXList(pExpr) ); |
| 100461 | 100531 | nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr); |
| 100462 | 100532 | if( nRight==nLeft ){ |
| 100463 | 100533 | nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr); |
| 100464 | 100534 | } |
| 100465 | 100535 | }else{ |
| | @@ -100504,11 +100574,13 @@ |
| 100504 | 100574 | int i; /* Loop counter */ |
| 100505 | 100575 | |
| 100506 | 100576 | UNUSED_PARAMETER(pParse); |
| 100507 | 100577 | |
| 100508 | 100578 | 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; |
| 100510 | 100582 | for(i=0; i<pEList->nExpr; i++){ |
| 100511 | 100583 | if( pEList->a[i].eEName==ENAME_NAME |
| 100512 | 100584 | && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0 |
| 100513 | 100585 | ){ |
| 100514 | 100586 | return i+1; |
| | @@ -101369,15 +101441,18 @@ |
| 101369 | 101441 | pExpr = pExpr->pLeft; |
| 101370 | 101442 | assert( pExpr!=0 ); |
| 101371 | 101443 | } |
| 101372 | 101444 | op = pExpr->op; |
| 101373 | 101445 | 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 | + } |
| 101376 | 101451 | } |
| 101377 | 101452 | if( op==TK_SELECT ){ |
| 101378 | | - assert( pExpr->flags&EP_xIsSelect ); |
| 101453 | + assert( ExprUseXSelect(pExpr) ); |
| 101379 | 101454 | assert( pExpr->x.pSelect!=0 ); |
| 101380 | 101455 | assert( pExpr->x.pSelect->pEList!=0 ); |
| 101381 | 101456 | assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 ); |
| 101382 | 101457 | return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr); |
| 101383 | 101458 | } |
| | @@ -101386,18 +101461,19 @@ |
| 101386 | 101461 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 101387 | 101462 | return sqlite3AffinityType(pExpr->u.zToken, 0); |
| 101388 | 101463 | } |
| 101389 | 101464 | #endif |
| 101390 | 101465 | if( op==TK_SELECT_COLUMN ){ |
| 101391 | | - assert( pExpr->pLeft->flags&EP_xIsSelect ); |
| 101466 | + assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) ); |
| 101392 | 101467 | assert( pExpr->iColumn < pExpr->iTable ); |
| 101393 | 101468 | assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); |
| 101394 | 101469 | return sqlite3ExprAffinity( |
| 101395 | 101470 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 101396 | 101471 | ); |
| 101397 | 101472 | } |
| 101398 | 101473 | if( op==TK_VECTOR ){ |
| 101474 | + assert( ExprUseXList(pExpr) ); |
| 101399 | 101475 | return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr); |
| 101400 | 101476 | } |
| 101401 | 101477 | return pExpr->affExpr; |
| 101402 | 101478 | } |
| 101403 | 101479 | |
| | @@ -101453,11 +101529,11 @@ |
| 101453 | 101529 | ** expression. |
| 101454 | 101530 | */ |
| 101455 | 101531 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){ |
| 101456 | 101532 | while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){ |
| 101457 | 101533 | if( ExprHasProperty(pExpr, EP_Unlikely) ){ |
| 101458 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 101534 | + assert( ExprUseXList(pExpr) ); |
| 101459 | 101535 | assert( pExpr->x.pList->nExpr>0 ); |
| 101460 | 101536 | assert( pExpr->op==TK_FUNCTION ); |
| 101461 | 101537 | pExpr = pExpr->x.pList->a[0].pExpr; |
| 101462 | 101538 | }else{ |
| 101463 | 101539 | assert( pExpr->op==TK_COLLATE ); |
| | @@ -101486,45 +101562,46 @@ |
| 101486 | 101562 | CollSeq *pColl = 0; |
| 101487 | 101563 | const Expr *p = pExpr; |
| 101488 | 101564 | while( p ){ |
| 101489 | 101565 | int op = p->op; |
| 101490 | 101566 | 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 | + } |
| 101502 | 101579 | } |
| 101503 | 101580 | if( op==TK_CAST || op==TK_UPLUS ){ |
| 101504 | 101581 | p = p->pLeft; |
| 101505 | 101582 | continue; |
| 101506 | 101583 | } |
| 101507 | 101584 | if( op==TK_VECTOR ){ |
| 101585 | + assert( ExprUseXList(p) ); |
| 101508 | 101586 | p = p->x.pList->a[0].pExpr; |
| 101509 | 101587 | continue; |
| 101510 | 101588 | } |
| 101511 | 101589 | if( op==TK_COLLATE ){ |
| 101590 | + assert( !ExprHasProperty(p, EP_IntValue) ); |
| 101512 | 101591 | pColl = sqlite3GetCollSeq(pParse, ENC(db), 0, p->u.zToken); |
| 101513 | 101592 | break; |
| 101514 | 101593 | } |
| 101515 | 101594 | if( p->flags & EP_Collate ){ |
| 101516 | 101595 | if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){ |
| 101517 | 101596 | p = p->pLeft; |
| 101518 | 101597 | }else{ |
| 101519 | 101598 | Expr *pNext = p->pRight; |
| 101520 | 101599 | /* The Expr.x union is never used at the same time as Expr.pRight */ |
| 101600 | + assert( ExprUseXList(p) ); |
| 101521 | 101601 | 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 ){ |
| 101526 | 101603 | int i; |
| 101527 | 101604 | for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){ |
| 101528 | 101605 | if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){ |
| 101529 | 101606 | pNext = p->x.pList->a[i].pExpr; |
| 101530 | 101607 | break; |
| | @@ -101603,11 +101680,11 @@ |
| 101603 | 101680 | pExpr->op==TK_NE || pExpr->op==TK_IS || pExpr->op==TK_ISNOT ); |
| 101604 | 101681 | assert( pExpr->pLeft ); |
| 101605 | 101682 | aff = sqlite3ExprAffinity(pExpr->pLeft); |
| 101606 | 101683 | if( pExpr->pRight ){ |
| 101607 | 101684 | aff = sqlite3CompareAffinity(pExpr->pRight, aff); |
| 101608 | | - }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 101685 | + }else if( ExprUseXSelect(pExpr) ){ |
| 101609 | 101686 | aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff); |
| 101610 | 101687 | }else if( aff==0 ){ |
| 101611 | 101688 | aff = SQLITE_AFF_BLOB; |
| 101612 | 101689 | } |
| 101613 | 101690 | return aff; |
| | @@ -101743,12 +101820,14 @@ |
| 101743 | 101820 | */ |
| 101744 | 101821 | SQLITE_PRIVATE int sqlite3ExprVectorSize(const Expr *pExpr){ |
| 101745 | 101822 | u8 op = pExpr->op; |
| 101746 | 101823 | if( op==TK_REGISTER ) op = pExpr->op2; |
| 101747 | 101824 | if( op==TK_VECTOR ){ |
| 101825 | + assert( ExprUseXList(pExpr) ); |
| 101748 | 101826 | return pExpr->x.pList->nExpr; |
| 101749 | 101827 | }else if( op==TK_SELECT ){ |
| 101828 | + assert( ExprUseXSelect(pExpr) ); |
| 101750 | 101829 | return pExpr->x.pSelect->pEList->nExpr; |
| 101751 | 101830 | }else{ |
| 101752 | 101831 | return 1; |
| 101753 | 101832 | } |
| 101754 | 101833 | } |
| | @@ -101771,12 +101850,14 @@ |
| 101771 | 101850 | SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){ |
| 101772 | 101851 | assert( i<sqlite3ExprVectorSize(pVector) || pVector->op==TK_ERROR ); |
| 101773 | 101852 | if( sqlite3ExprIsVector(pVector) ){ |
| 101774 | 101853 | assert( pVector->op2==0 || pVector->op==TK_REGISTER ); |
| 101775 | 101854 | if( pVector->op==TK_SELECT || pVector->op2==TK_SELECT ){ |
| 101855 | + assert( ExprUseXSelect(pVector) ); |
| 101776 | 101856 | return pVector->x.pSelect->pEList->a[i].pExpr; |
| 101777 | 101857 | }else{ |
| 101858 | + assert( ExprUseXList(pVector) ); |
| 101778 | 101859 | return pVector->x.pList->a[i].pExpr; |
| 101779 | 101860 | } |
| 101780 | 101861 | } |
| 101781 | 101862 | return pVector; |
| 101782 | 101863 | } |
| | @@ -101808,11 +101889,11 @@ |
| 101808 | 101889 | int iField, /* Which column of the vector to return */ |
| 101809 | 101890 | int nField /* Total number of columns in the vector */ |
| 101810 | 101891 | ){ |
| 101811 | 101892 | Expr *pRet; |
| 101812 | 101893 | if( pVector->op==TK_SELECT ){ |
| 101813 | | - assert( pVector->flags & EP_xIsSelect ); |
| 101894 | + assert( ExprUseXSelect(pVector) ); |
| 101814 | 101895 | /* The TK_SELECT_COLUMN Expr node: |
| 101815 | 101896 | ** |
| 101816 | 101897 | ** pLeft: pVector containing TK_SELECT. Not deleted. |
| 101817 | 101898 | ** pRight: not used. But recursively deleted. |
| 101818 | 101899 | ** iColumn: Index of a column in pVector |
| | @@ -101833,11 +101914,13 @@ |
| 101833 | 101914 | pRet->iColumn = iField; |
| 101834 | 101915 | pRet->pLeft = pVector; |
| 101835 | 101916 | } |
| 101836 | 101917 | }else{ |
| 101837 | 101918 | 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; |
| 101839 | 101922 | pVector = *ppVector; |
| 101840 | 101923 | if( IN_RENAME_OBJECT ){ |
| 101841 | 101924 | /* This must be a vector UPDATE inside a trigger */ |
| 101842 | 101925 | *ppVector = 0; |
| 101843 | 101926 | return pVector; |
| | @@ -101897,14 +101980,16 @@ |
| 101897 | 101980 | if( op==TK_REGISTER ){ |
| 101898 | 101981 | *ppExpr = sqlite3VectorFieldSubexpr(pVector, iField); |
| 101899 | 101982 | return pVector->iTable+iField; |
| 101900 | 101983 | } |
| 101901 | 101984 | if( op==TK_SELECT ){ |
| 101985 | + assert( ExprUseXSelect(pVector) ); |
| 101902 | 101986 | *ppExpr = pVector->x.pSelect->pEList->a[iField].pExpr; |
| 101903 | 101987 | return regSelect+iField; |
| 101904 | 101988 | } |
| 101905 | 101989 | if( op==TK_VECTOR ){ |
| 101990 | + assert( ExprUseXList(pVector) ); |
| 101906 | 101991 | *ppExpr = pVector->x.pList->a[iField].pExpr; |
| 101907 | 101992 | return sqlite3ExprCodeTemp(pParse, *ppExpr, pRegFree); |
| 101908 | 101993 | } |
| 101909 | 101994 | return 0; |
| 101910 | 101995 | } |
| | @@ -102075,11 +102160,11 @@ |
| 102075 | 102160 | */ |
| 102076 | 102161 | static void exprSetHeight(Expr *p){ |
| 102077 | 102162 | int nHeight = 0; |
| 102078 | 102163 | heightOfExpr(p->pLeft, &nHeight); |
| 102079 | 102164 | heightOfExpr(p->pRight, &nHeight); |
| 102080 | | - if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 102165 | + if( ExprUseXSelect(p) ){ |
| 102081 | 102166 | heightOfSelect(p->x.pSelect, &nHeight); |
| 102082 | 102167 | }else if( p->x.pList ){ |
| 102083 | 102168 | heightOfExprList(p->x.pList, &nHeight); |
| 102084 | 102169 | p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); |
| 102085 | 102170 | } |
| | @@ -102114,11 +102199,11 @@ |
| 102114 | 102199 | ** Propagate all EP_Propagate flags from the Expr.x.pList into |
| 102115 | 102200 | ** Expr.flags. |
| 102116 | 102201 | */ |
| 102117 | 102202 | SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ |
| 102118 | 102203 | if( pParse->nErr ) return; |
| 102119 | | - if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){ |
| 102204 | + if( p && ExprUseXList(p) && p->x.pList ){ |
| 102120 | 102205 | p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); |
| 102121 | 102206 | } |
| 102122 | 102207 | } |
| 102123 | 102208 | #define exprSetHeight(y) |
| 102124 | 102209 | #endif /* SQLITE_MAX_EXPR_DEPTH>0 */ |
| | @@ -102298,17 +102383,24 @@ |
| 102298 | 102383 | Select *pRet = 0; |
| 102299 | 102384 | assert( nElem>1 ); |
| 102300 | 102385 | for(ii=0; ii<pEList->nExpr; ii++){ |
| 102301 | 102386 | Select *pSel; |
| 102302 | 102387 | 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 | + } |
| 102304 | 102395 | if( nExprElem!=nElem ){ |
| 102305 | 102396 | sqlite3ErrorMsg(pParse, "IN(...) element has %d term%s - expected %d", |
| 102306 | 102397 | nExprElem, nExprElem>1?"s":"", nElem |
| 102307 | 102398 | ); |
| 102308 | 102399 | break; |
| 102309 | 102400 | } |
| 102401 | + assert( ExprUseXList(pExpr) ); |
| 102310 | 102402 | pSel = sqlite3SelectNew(pParse, pExpr->x.pList, 0, 0, 0, 0, 0, SF_Values,0); |
| 102311 | 102403 | pExpr->x.pList = 0; |
| 102312 | 102404 | if( pSel ){ |
| 102313 | 102405 | if( pRet ){ |
| 102314 | 102406 | pSel->op = TK_ALL; |
| | @@ -102374,11 +102466,11 @@ |
| 102374 | 102466 | ){ |
| 102375 | 102467 | sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken); |
| 102376 | 102468 | } |
| 102377 | 102469 | pNew->x.pList = pList; |
| 102378 | 102470 | ExprSetProperty(pNew, EP_HasFunc); |
| 102379 | | - assert( !ExprHasProperty(pNew, EP_xIsSelect) ); |
| 102471 | + assert( ExprUseXList(pNew) ); |
| 102380 | 102472 | sqlite3ExprSetHeightAndFlags(pParse, pNew); |
| 102381 | 102473 | if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct); |
| 102382 | 102474 | return pNew; |
| 102383 | 102475 | } |
| 102384 | 102476 | |
| | @@ -102500,31 +102592,30 @@ |
| 102500 | 102592 | /* |
| 102501 | 102593 | ** Recursively delete an expression tree. |
| 102502 | 102594 | */ |
| 102503 | 102595 | static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ |
| 102504 | 102596 | 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) ); |
| 102511 | 102601 | #ifdef SQLITE_DEBUG |
| 102512 | 102602 | if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){ |
| 102513 | 102603 | assert( p->pLeft==0 ); |
| 102514 | 102604 | 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 ); |
| 102516 | 102607 | } |
| 102517 | 102608 | #endif |
| 102518 | 102609 | if( !ExprHasProperty(p, (EP_TokenOnly|EP_Leaf)) ){ |
| 102519 | 102610 | /* 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 ); |
| 102521 | 102612 | if( p->pLeft && p->op!=TK_SELECT_COLUMN ) sqlite3ExprDeleteNN(db, p->pLeft); |
| 102522 | 102613 | if( p->pRight ){ |
| 102523 | 102614 | assert( !ExprHasProperty(p, EP_WinFunc) ); |
| 102524 | 102615 | sqlite3ExprDeleteNN(db, p->pRight); |
| 102525 | | - }else if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 102616 | + }else if( ExprUseXSelect(p) ){ |
| 102526 | 102617 | assert( !ExprHasProperty(p, EP_WinFunc) ); |
| 102527 | 102618 | sqlite3SelectDelete(db, p->x.pSelect); |
| 102528 | 102619 | }else{ |
| 102529 | 102620 | sqlite3ExprListDelete(db, p->x.pList); |
| 102530 | 102621 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| | @@ -102532,11 +102623,14 @@ |
| 102532 | 102623 | sqlite3WindowDelete(db, p->y.pWin); |
| 102533 | 102624 | } |
| 102534 | 102625 | #endif |
| 102535 | 102626 | } |
| 102536 | 102627 | } |
| 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 | + } |
| 102538 | 102632 | if( !ExprHasProperty(p, EP_Static) ){ |
| 102539 | 102633 | sqlite3DbFreeNN(db, p); |
| 102540 | 102634 | } |
| 102541 | 102635 | } |
| 102542 | 102636 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){ |
| | @@ -102748,11 +102842,11 @@ |
| 102748 | 102842 | memcpy(zToken, p->u.zToken, nToken); |
| 102749 | 102843 | } |
| 102750 | 102844 | |
| 102751 | 102845 | if( 0==((p->flags|pNew->flags) & (EP_TokenOnly|EP_Leaf)) ){ |
| 102752 | 102846 | /* Fill in the pNew->x.pSelect or pNew->x.pList member. */ |
| 102753 | | - if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 102847 | + if( ExprUseXSelect(p) ){ |
| 102754 | 102848 | pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags); |
| 102755 | 102849 | }else{ |
| 102756 | 102850 | pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags); |
| 102757 | 102851 | } |
| 102758 | 102852 | } |
| | @@ -103375,11 +103469,11 @@ |
| 103375 | 103469 | ** the conversion happened, and zero if the expression is unaltered. |
| 103376 | 103470 | */ |
| 103377 | 103471 | SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){ |
| 103378 | 103472 | u32 v; |
| 103379 | 103473 | assert( pExpr->op==TK_ID || pExpr->op==TK_STRING ); |
| 103380 | | - if( !ExprHasProperty(pExpr, EP_Quoted) |
| 103474 | + if( !ExprHasProperty(pExpr, EP_Quoted|EP_IntValue) |
| 103381 | 103475 | && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0 |
| 103382 | 103476 | ){ |
| 103383 | 103477 | pExpr->op = TK_TRUEFALSE; |
| 103384 | 103478 | ExprSetProperty(pExpr, v); |
| 103385 | 103479 | return 1; |
| | @@ -103392,10 +103486,11 @@ |
| 103392 | 103486 | ** and 0 if it is FALSE. |
| 103393 | 103487 | */ |
| 103394 | 103488 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ |
| 103395 | 103489 | pExpr = sqlite3ExprSkipCollate((Expr*)pExpr); |
| 103396 | 103490 | assert( pExpr->op==TK_TRUEFALSE ); |
| 103491 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 103397 | 103492 | assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 |
| 103398 | 103493 | || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); |
| 103399 | 103494 | return pExpr->u.zToken[4]==0; |
| 103400 | 103495 | } |
| 103401 | 103496 | |
| | @@ -103596,11 +103691,11 @@ |
| 103596 | 103691 | } |
| 103597 | 103692 | } |
| 103598 | 103693 | } |
| 103599 | 103694 | |
| 103600 | 103695 | /* Check if pExpr is a sub-select. If so, consider it variable. */ |
| 103601 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 103696 | + if( ExprUseXSelect(pExpr) ){ |
| 103602 | 103697 | pWalker->eCode = 0; |
| 103603 | 103698 | return WRC_Abort; |
| 103604 | 103699 | } |
| 103605 | 103700 | |
| 103606 | 103701 | return exprNodeIsConstant(pWalker, pExpr); |
| | @@ -103746,10 +103841,11 @@ |
| 103746 | 103841 | case TK_STRING: |
| 103747 | 103842 | case TK_FLOAT: |
| 103748 | 103843 | case TK_BLOB: |
| 103749 | 103844 | return 0; |
| 103750 | 103845 | case TK_COLUMN: |
| 103846 | + assert( ExprUseYTab(p) ); |
| 103751 | 103847 | return ExprHasProperty(p, EP_CanBeNull) || |
| 103752 | 103848 | p->y.pTab==0 || /* Reference to column of index on expression */ |
| 103753 | 103849 | (p->iColumn>=0 |
| 103754 | 103850 | && ALWAYS(p->y.pTab->aCol!=0) /* Defense against OOM problems */ |
| 103755 | 103851 | && p->y.pTab->aCol[p->iColumn].notNull==0); |
| | @@ -103823,11 +103919,11 @@ |
| 103823 | 103919 | Select *p; |
| 103824 | 103920 | SrcList *pSrc; |
| 103825 | 103921 | ExprList *pEList; |
| 103826 | 103922 | Table *pTab; |
| 103827 | 103923 | int i; |
| 103828 | | - if( !ExprHasProperty(pX, EP_xIsSelect) ) return 0; /* Not a subquery */ |
| 103924 | + if( !ExprUseXSelect(pX) ) return 0; /* Not a subquery */ |
| 103829 | 103925 | if( ExprHasProperty(pX, EP_VarSelect) ) return 0; /* Correlated subq */ |
| 103830 | 103926 | p = pX->x.pSelect; |
| 103831 | 103927 | if( p->pPrior ) return 0; /* Not a compound SELECT */ |
| 103832 | 103928 | if( p->selFlags & (SF_Distinct|SF_Aggregate) ){ |
| 103833 | 103929 | testcase( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct ); |
| | @@ -103994,11 +104090,11 @@ |
| 103994 | 104090 | /* If the RHS of this IN(...) operator is a SELECT, and if it matters |
| 103995 | 104091 | ** whether or not the SELECT result contains NULL values, check whether |
| 103996 | 104092 | ** or not NULL is actually possible (it may not be, for example, due |
| 103997 | 104093 | ** to NOT NULL constraints in the schema). If no NULL values are possible, |
| 103998 | 104094 | ** set prRhsHasNull to 0 before continuing. */ |
| 103999 | | - if( prRhsHasNull && (pX->flags & EP_xIsSelect) ){ |
| 104095 | + if( prRhsHasNull && ExprUseXSelect(pX) ){ |
| 104000 | 104096 | int i; |
| 104001 | 104097 | ExprList *pEList = pX->x.pSelect->pEList; |
| 104002 | 104098 | for(i=0; i<pEList->nExpr; i++){ |
| 104003 | 104099 | if( sqlite3ExprCanBeNull(pEList->a[i].pExpr) ) break; |
| 104004 | 104100 | } |
| | @@ -104150,11 +104246,11 @@ |
| 104150 | 104246 | ** then it is not worth creating an ephemeral table to evaluate |
| 104151 | 104247 | ** the IN operator so return IN_INDEX_NOOP. |
| 104152 | 104248 | */ |
| 104153 | 104249 | if( eType==0 |
| 104154 | 104250 | && (inFlags & IN_INDEX_NOOP_OK) |
| 104155 | | - && !ExprHasProperty(pX, EP_xIsSelect) |
| 104251 | + && ExprUseXList(pX) |
| 104156 | 104252 | && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2) |
| 104157 | 104253 | ){ |
| 104158 | 104254 | eType = IN_INDEX_NOOP; |
| 104159 | 104255 | } |
| 104160 | 104256 | |
| | @@ -104198,11 +104294,11 @@ |
| 104198 | 104294 | ** string is eventually freed using sqlite3DbFree(). |
| 104199 | 104295 | */ |
| 104200 | 104296 | static char *exprINAffinity(Parse *pParse, const Expr *pExpr){ |
| 104201 | 104297 | Expr *pLeft = pExpr->pLeft; |
| 104202 | 104298 | int nVal = sqlite3ExprVectorSize(pLeft); |
| 104203 | | - Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0; |
| 104299 | + Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0; |
| 104204 | 104300 | char *zRet; |
| 104205 | 104301 | |
| 104206 | 104302 | assert( pExpr->op==TK_IN ); |
| 104207 | 104303 | zRet = sqlite3DbMallocRaw(pParse->db, nVal+1); |
| 104208 | 104304 | if( zRet ){ |
| | @@ -104248,11 +104344,11 @@ |
| 104248 | 104344 | ** |
| 104249 | 104345 | ** "row value misused" |
| 104250 | 104346 | */ |
| 104251 | 104347 | SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){ |
| 104252 | 104348 | #ifndef SQLITE_OMIT_SUBQUERY |
| 104253 | | - if( pExpr->flags & EP_xIsSelect ){ |
| 104349 | + if( ExprUseXSelect(pExpr) ){ |
| 104254 | 104350 | sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1); |
| 104255 | 104351 | }else |
| 104256 | 104352 | #endif |
| 104257 | 104353 | { |
| 104258 | 104354 | sqlite3ErrorMsg(pParse, "row value misused"); |
| | @@ -104312,22 +104408,24 @@ |
| 104312 | 104408 | /* If this routine has already been coded, but the previous code |
| 104313 | 104409 | ** might not have been invoked yet, so invoke it now as a subroutine. |
| 104314 | 104410 | */ |
| 104315 | 104411 | if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 104316 | 104412 | addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 104317 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 104413 | + if( ExprUseXSelect(pExpr) ){ |
| 104318 | 104414 | ExplainQueryPlan((pParse, 0, "REUSE LIST SUBQUERY %d", |
| 104319 | 104415 | pExpr->x.pSelect->selId)); |
| 104320 | 104416 | } |
| 104417 | + assert( ExprUseYSub(pExpr) ); |
| 104321 | 104418 | sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, |
| 104322 | 104419 | pExpr->y.sub.iAddr); |
| 104323 | 104420 | sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable); |
| 104324 | 104421 | sqlite3VdbeJumpHere(v, addrOnce); |
| 104325 | 104422 | return; |
| 104326 | 104423 | } |
| 104327 | 104424 | |
| 104328 | 104425 | /* Begin coding the subroutine */ |
| 104426 | + assert( !ExprUseYWin(pExpr) ); |
| 104329 | 104427 | ExprSetProperty(pExpr, EP_Subrtn); |
| 104330 | 104428 | assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 104331 | 104429 | pExpr->y.sub.regReturn = ++pParse->nMem; |
| 104332 | 104430 | pExpr->y.sub.iAddr = |
| 104333 | 104431 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; |
| | @@ -104344,19 +104442,19 @@ |
| 104344 | 104442 | ** RHS of the IN operator. |
| 104345 | 104443 | */ |
| 104346 | 104444 | pExpr->iTable = iTab; |
| 104347 | 104445 | addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal); |
| 104348 | 104446 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 104349 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 104447 | + if( ExprUseXSelect(pExpr) ){ |
| 104350 | 104448 | VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId)); |
| 104351 | 104449 | }else{ |
| 104352 | 104450 | VdbeComment((v, "RHS of IN operator")); |
| 104353 | 104451 | } |
| 104354 | 104452 | #endif |
| 104355 | 104453 | pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1); |
| 104356 | 104454 | |
| 104357 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 104455 | + if( ExprUseXSelect(pExpr) ){ |
| 104358 | 104456 | /* Case 1: expr IN (SELECT ...) |
| 104359 | 104457 | ** |
| 104360 | 104458 | ** Generate code to write the results of the select into the temporary |
| 104361 | 104459 | ** table allocated and opened above. |
| 104362 | 104460 | */ |
| | @@ -104450,10 +104548,11 @@ |
| 104450 | 104548 | sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO); |
| 104451 | 104549 | } |
| 104452 | 104550 | if( addrOnce ){ |
| 104453 | 104551 | sqlite3VdbeJumpHere(v, addrOnce); |
| 104454 | 104552 | /* Subroutine return */ |
| 104553 | + assert( ExprUseYSub(pExpr) ); |
| 104455 | 104554 | sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); |
| 104456 | 104555 | sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); |
| 104457 | 104556 | sqlite3ClearTempRegCache(pParse); |
| 104458 | 104557 | } |
| 104459 | 104558 | } |
| | @@ -104486,23 +104585,26 @@ |
| 104486 | 104585 | assert( v!=0 ); |
| 104487 | 104586 | if( pParse->nErr ) return 0; |
| 104488 | 104587 | testcase( pExpr->op==TK_EXISTS ); |
| 104489 | 104588 | testcase( pExpr->op==TK_SELECT ); |
| 104490 | 104589 | assert( pExpr->op==TK_EXISTS || pExpr->op==TK_SELECT ); |
| 104491 | | - assert( ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 104590 | + assert( ExprUseXSelect(pExpr) ); |
| 104492 | 104591 | pSel = pExpr->x.pSelect; |
| 104493 | 104592 | |
| 104494 | 104593 | /* If this routine has already been coded, then invoke it as a |
| 104495 | 104594 | ** subroutine. */ |
| 104496 | 104595 | if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 104497 | 104596 | ExplainQueryPlan((pParse, 0, "REUSE SUBQUERY %d", pSel->selId)); |
| 104597 | + assert( ExprUseYSub(pExpr) ); |
| 104498 | 104598 | sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, |
| 104499 | 104599 | pExpr->y.sub.iAddr); |
| 104500 | 104600 | return pExpr->iTable; |
| 104501 | 104601 | } |
| 104502 | 104602 | |
| 104503 | 104603 | /* Begin coding the subroutine */ |
| 104604 | + assert( !ExprUseYWin(pExpr) ); |
| 104605 | + assert( !ExprHasProperty(pExpr, EP_Reduced|EP_TokenOnly) ); |
| 104504 | 104606 | ExprSetProperty(pExpr, EP_Subrtn); |
| 104505 | 104607 | pExpr->y.sub.regReturn = ++pParse->nMem; |
| 104506 | 104608 | pExpr->y.sub.iAddr = |
| 104507 | 104609 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pExpr->y.sub.regReturn) + 1; |
| 104508 | 104610 | VdbeComment((v, "return address")); |
| | @@ -104578,10 +104680,11 @@ |
| 104578 | 104680 | if( addrOnce ){ |
| 104579 | 104681 | sqlite3VdbeJumpHere(v, addrOnce); |
| 104580 | 104682 | } |
| 104581 | 104683 | |
| 104582 | 104684 | /* Subroutine return */ |
| 104685 | + assert( ExprUseYSub(pExpr) ); |
| 104583 | 104686 | sqlite3VdbeAddOp1(v, OP_Return, pExpr->y.sub.regReturn); |
| 104584 | 104687 | sqlite3VdbeChangeP1(v, pExpr->y.sub.iAddr-1, sqlite3VdbeCurrentAddr(v)-1); |
| 104585 | 104688 | sqlite3ClearTempRegCache(pParse); |
| 104586 | 104689 | return rReg; |
| 104587 | 104690 | } |
| | @@ -104594,11 +104697,11 @@ |
| 104594 | 104697 | ** columns as the vector on the LHS. Or, if the RHS of the IN() is not |
| 104595 | 104698 | ** a sub-query, that the LHS is a vector of size 1. |
| 104596 | 104699 | */ |
| 104597 | 104700 | SQLITE_PRIVATE int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){ |
| 104598 | 104701 | int nVector = sqlite3ExprVectorSize(pIn->pLeft); |
| 104599 | | - if( (pIn->flags & EP_xIsSelect)!=0 && !pParse->db->mallocFailed ){ |
| 104702 | + if( ExprUseXSelect(pIn) && !pParse->db->mallocFailed ){ |
| 104600 | 104703 | if( nVector!=pIn->x.pSelect->pEList->nExpr ){ |
| 104601 | 104704 | sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector); |
| 104602 | 104705 | return 1; |
| 104603 | 104706 | } |
| 104604 | 104707 | }else if( nVector!=1 ){ |
| | @@ -104728,17 +104831,19 @@ |
| 104728 | 104831 | ** sequence of comparisons. |
| 104729 | 104832 | ** |
| 104730 | 104833 | ** This is step (1) in the in-operator.md optimized algorithm. |
| 104731 | 104834 | */ |
| 104732 | 104835 | if( eType==IN_INDEX_NOOP ){ |
| 104733 | | - ExprList *pList = pExpr->x.pList; |
| 104734 | | - CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 104836 | + ExprList *pList; |
| 104837 | + CollSeq *pColl; |
| 104735 | 104838 | int labelOk = sqlite3VdbeMakeLabel(pParse); |
| 104736 | 104839 | int r2, regToFree; |
| 104737 | 104840 | int regCkNull = 0; |
| 104738 | 104841 | int ii; |
| 104739 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 104842 | + assert( ExprUseXList(pExpr) ); |
| 104843 | + pList = pExpr->x.pList; |
| 104844 | + pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 104740 | 104845 | if( destIfNull!=destIfFalse ){ |
| 104741 | 104846 | regCkNull = sqlite3GetTempReg(pParse); |
| 104742 | 104847 | sqlite3VdbeAddOp3(v, OP_BitAnd, rLhs, rLhs, regCkNull); |
| 104743 | 104848 | } |
| 104744 | 104849 | for(ii=0; ii<pList->nExpr; ii++){ |
| | @@ -105120,10 +105225,11 @@ |
| 105120 | 105225 | #endif |
| 105121 | 105226 | }else{ |
| 105122 | 105227 | int i; |
| 105123 | 105228 | iResult = pParse->nMem+1; |
| 105124 | 105229 | pParse->nMem += nResult; |
| 105230 | + assert( ExprUseXList(p) ); |
| 105125 | 105231 | for(i=0; i<nResult; i++){ |
| 105126 | 105232 | sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult); |
| 105127 | 105233 | } |
| 105128 | 105234 | } |
| 105129 | 105235 | } |
| | @@ -105318,10 +105424,11 @@ |
| 105318 | 105424 | ** datatype by applying the Affinity of the table column to the |
| 105319 | 105425 | ** constant. |
| 105320 | 105426 | */ |
| 105321 | 105427 | int aff; |
| 105322 | 105428 | iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); |
| 105429 | + assert( ExprUseYTab(pExpr) ); |
| 105323 | 105430 | if( pExpr->y.pTab ){ |
| 105324 | 105431 | aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 105325 | 105432 | }else{ |
| 105326 | 105433 | aff = pExpr->affExpr; |
| 105327 | 105434 | } |
| | @@ -105341,13 +105448,15 @@ |
| 105341 | 105448 | ** The row is unpacked into registers beginning at |
| 105342 | 105449 | ** 0-(pParse->iSelfTab). The rowid (if any) is in a register |
| 105343 | 105450 | ** immediately prior to the first column. |
| 105344 | 105451 | */ |
| 105345 | 105452 | Column *pCol; |
| 105346 | | - Table *pTab = pExpr->y.pTab; |
| 105453 | + Table *pTab; |
| 105347 | 105454 | int iSrc; |
| 105348 | 105455 | int iCol = pExpr->iColumn; |
| 105456 | + assert( ExprUseYTab(pExpr) ); |
| 105457 | + pTab = pExpr->y.pTab; |
| 105349 | 105458 | assert( pTab!=0 ); |
| 105350 | 105459 | assert( iCol>=XN_ROWID ); |
| 105351 | 105460 | assert( iCol<pTab->nCol ); |
| 105352 | 105461 | if( iCol<0 ){ |
| 105353 | 105462 | return -1-pParse->iSelfTab; |
| | @@ -105381,10 +105490,11 @@ |
| 105381 | 105490 | /* Coding an expression that is part of an index where column names |
| 105382 | 105491 | ** in the index refer to the table to which the index belongs */ |
| 105383 | 105492 | iTab = pParse->iSelfTab - 1; |
| 105384 | 105493 | } |
| 105385 | 105494 | } |
| 105495 | + assert( ExprUseYTab(pExpr) ); |
| 105386 | 105496 | iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab, |
| 105387 | 105497 | pExpr->iColumn, iTab, target, |
| 105388 | 105498 | pExpr->op2); |
| 105389 | 105499 | if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){ |
| 105390 | 105500 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| | @@ -105458,10 +105568,11 @@ |
| 105458 | 105568 | inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target); |
| 105459 | 105569 | if( inReg!=target ){ |
| 105460 | 105570 | sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target); |
| 105461 | 105571 | inReg = target; |
| 105462 | 105572 | } |
| 105573 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 105463 | 105574 | sqlite3VdbeAddOp2(v, OP_Cast, target, |
| 105464 | 105575 | sqlite3AffinityType(pExpr->u.zToken, 0)); |
| 105465 | 105576 | return inReg; |
| 105466 | 105577 | } |
| 105467 | 105578 | #endif /* SQLITE_OMIT_CAST */ |
| | @@ -105625,12 +105736,12 @@ |
| 105625 | 105736 | if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ |
| 105626 | 105737 | /* SQL functions can be expensive. So try to avoid running them |
| 105627 | 105738 | ** multiple times if we know they always give the same result */ |
| 105628 | 105739 | return sqlite3ExprCodeRunJustOnce(pParse, pExpr, -1); |
| 105629 | 105740 | } |
| 105630 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 105631 | 105741 | assert( !ExprHasProperty(pExpr, EP_TokenOnly) ); |
| 105742 | + assert( ExprUseXList(pExpr) ); |
| 105632 | 105743 | pFarg = pExpr->x.pList; |
| 105633 | 105744 | nFarg = pFarg ? pFarg->nExpr : 0; |
| 105634 | 105745 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 105635 | 105746 | zId = pExpr->u.zToken; |
| 105636 | 105747 | pDef = sqlite3FindFunction(db, zId, nFarg, enc, 0); |
| | @@ -105745,11 +105856,14 @@ |
| 105745 | 105856 | int nCol; |
| 105746 | 105857 | testcase( op==TK_EXISTS ); |
| 105747 | 105858 | testcase( op==TK_SELECT ); |
| 105748 | 105859 | if( pParse->db->mallocFailed ){ |
| 105749 | 105860 | 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 | + ){ |
| 105751 | 105865 | sqlite3SubselectError(pParse, nCol, 1); |
| 105752 | 105866 | }else{ |
| 105753 | 105867 | return sqlite3CodeSubselect(pParse, pExpr); |
| 105754 | 105868 | } |
| 105755 | 105869 | break; |
| | @@ -105827,13 +105941,18 @@ |
| 105827 | 105941 | ** |
| 105828 | 105942 | ** p1==0 -> old.rowid p1==3 -> new.rowid |
| 105829 | 105943 | ** p1==1 -> old.a p1==4 -> new.a |
| 105830 | 105944 | ** p1==2 -> old.b p1==5 -> new.b |
| 105831 | 105945 | */ |
| 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 |
| 105835 | 105954 | + sqlite3TableColumnToStorage(pTab, iCol); |
| 105836 | 105955 | |
| 105837 | 105956 | assert( pExpr->iTable==0 || pExpr->iTable==1 ); |
| 105838 | 105957 | assert( iCol>=-1 && iCol<pTab->nCol ); |
| 105839 | 105958 | assert( pTab->iPKey<0 || iCol!=pTab->iPKey ); |
| | @@ -105917,11 +106036,11 @@ |
| 105917 | 106036 | Expr *pX; /* The X expression */ |
| 105918 | 106037 | Expr *pTest = 0; /* X==Ei (form A) or just Ei (form B) */ |
| 105919 | 106038 | Expr *pDel = 0; |
| 105920 | 106039 | sqlite3 *db = pParse->db; |
| 105921 | 106040 | |
| 105922 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList ); |
| 106041 | + assert( ExprUseXList(pExpr) && pExpr->x.pList!=0 ); |
| 105923 | 106042 | assert(pExpr->x.pList->nExpr > 0); |
| 105924 | 106043 | pEList = pExpr->x.pList; |
| 105925 | 106044 | aListelem = pEList->a; |
| 105926 | 106045 | nExpr = pEList->nExpr; |
| 105927 | 106046 | endLabel = sqlite3VdbeMakeLabel(pParse); |
| | @@ -106262,11 +106381,11 @@ |
| 106262 | 106381 | |
| 106263 | 106382 | memset(&compLeft, 0, sizeof(Expr)); |
| 106264 | 106383 | memset(&compRight, 0, sizeof(Expr)); |
| 106265 | 106384 | memset(&exprAnd, 0, sizeof(Expr)); |
| 106266 | 106385 | |
| 106267 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 106386 | + assert( ExprUseXList(pExpr) ); |
| 106268 | 106387 | pDel = sqlite3ExprDup(db, pExpr->pLeft, 0); |
| 106269 | 106388 | if( db->mallocFailed==0 ){ |
| 106270 | 106389 | exprAnd.op = TK_AND; |
| 106271 | 106390 | exprAnd.pLeft = &compLeft; |
| 106272 | 106391 | exprAnd.pRight = &compRight; |
| | @@ -106737,11 +106856,16 @@ |
| 106737 | 106856 | if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){ |
| 106738 | 106857 | return 1; |
| 106739 | 106858 | } |
| 106740 | 106859 | return 2; |
| 106741 | 106860 | } |
| 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) ); |
| 106743 | 106867 | if( pA->op==TK_FUNCTION || pA->op==TK_AGG_FUNCTION ){ |
| 106744 | 106868 | if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; |
| 106745 | 106869 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 106746 | 106870 | assert( pA->op==pB->op ); |
| 106747 | 106871 | if( ExprHasProperty(pA,EP_WinFunc)!=ExprHasProperty(pB,EP_WinFunc) ){ |
| | @@ -106844,16 +106968,17 @@ |
| 106844 | 106968 | return pNN->op!=TK_NULL; |
| 106845 | 106969 | } |
| 106846 | 106970 | switch( p->op ){ |
| 106847 | 106971 | case TK_IN: { |
| 106848 | 106972 | 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) ); |
| 106851 | 106974 | return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1); |
| 106852 | 106975 | } |
| 106853 | 106976 | case TK_BETWEEN: { |
| 106854 | | - ExprList *pList = p->x.pList; |
| 106977 | + ExprList *pList; |
| 106978 | + assert( ExprUseXList(p) ); |
| 106979 | + pList = p->x.pList; |
| 106855 | 106980 | assert( pList!=0 ); |
| 106856 | 106981 | assert( pList->nExpr==2 ); |
| 106857 | 106982 | if( seenNot ) return 0; |
| 106858 | 106983 | if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, 1) |
| 106859 | 106984 | || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, 1) |
| | @@ -107026,14 +107151,18 @@ |
| 107026 | 107151 | testcase( pExpr->op==TK_LE ); |
| 107027 | 107152 | testcase( pExpr->op==TK_GT ); |
| 107028 | 107153 | testcase( pExpr->op==TK_GE ); |
| 107029 | 107154 | /* The y.pTab=0 assignment in wherecode.c always happens after the |
| 107030 | 107155 | ** 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)) |
| 107035 | 107164 | ){ |
| 107036 | 107165 | return WRC_Prune; |
| 107037 | 107166 | } |
| 107038 | 107167 | /* no break */ deliberate_fall_through |
| 107039 | 107168 | } |
| | @@ -107213,10 +107342,11 @@ |
| 107213 | 107342 | w.u.pSrcCount = &cnt; |
| 107214 | 107343 | cnt.pSrc = pSrcList; |
| 107215 | 107344 | cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF; |
| 107216 | 107345 | cnt.nThis = 0; |
| 107217 | 107346 | cnt.nOther = 0; |
| 107347 | + assert( ExprUseXList(pExpr) ); |
| 107218 | 107348 | sqlite3WalkExprList(&w, pExpr->x.pList); |
| 107219 | 107349 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 107220 | 107350 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 107221 | 107351 | sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter); |
| 107222 | 107352 | } |
| | @@ -107354,10 +107484,11 @@ |
| 107354 | 107484 | } |
| 107355 | 107485 | if( (k>=pAggInfo->nColumn) |
| 107356 | 107486 | && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0 |
| 107357 | 107487 | ){ |
| 107358 | 107488 | pCol = &pAggInfo->aCol[k]; |
| 107489 | + assert( ExprUseYTab(pExpr) ); |
| 107359 | 107490 | pCol->pTab = pExpr->y.pTab; |
| 107360 | 107491 | pCol->iTable = pExpr->iTable; |
| 107361 | 107492 | pCol->iColumn = pExpr->iColumn; |
| 107362 | 107493 | pCol->iMem = ++pParse->nMem; |
| 107363 | 107494 | pCol->iSorterColumn = -1; |
| | @@ -107417,11 +107548,11 @@ |
| 107417 | 107548 | if( i>=0 ){ |
| 107418 | 107549 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 107419 | 107550 | pItem = &pAggInfo->aFunc[i]; |
| 107420 | 107551 | pItem->pFExpr = pExpr; |
| 107421 | 107552 | pItem->iMem = ++pParse->nMem; |
| 107422 | | - assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 107553 | + assert( ExprUseUToken(pExpr) ); |
| 107423 | 107554 | pItem->pFunc = sqlite3FindFunction(pParse->db, |
| 107424 | 107555 | pExpr->u.zToken, |
| 107425 | 107556 | pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0); |
| 107426 | 107557 | if( pExpr->flags & EP_Distinct ){ |
| 107427 | 107558 | pItem->iDistinct = pParse->nTab++; |
| | @@ -107939,10 +108070,11 @@ |
| 107939 | 108070 | */ |
| 107940 | 108071 | assert( pDflt==0 || pDflt->op==TK_SPAN ); |
| 107941 | 108072 | if( pDflt && pDflt->pLeft->op==TK_NULL ){ |
| 107942 | 108073 | pDflt = 0; |
| 107943 | 108074 | } |
| 108075 | + assert( IsOrdinaryTable(pNew) ); |
| 107944 | 108076 | if( (db->flags&SQLITE_ForeignKeys) && pNew->u.tab.pFKey && pDflt ){ |
| 107945 | 108077 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| 107946 | 108078 | "Cannot add a REFERENCES column with non-NULL default value"); |
| 107947 | 108079 | } |
| 107948 | 108080 | if( pCol->notNull && !pDflt ){ |
| | @@ -107981,11 +108113,12 @@ |
| 107981 | 108113 | while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){ |
| 107982 | 108114 | *zEnd-- = '\0'; |
| 107983 | 108115 | } |
| 107984 | 108116 | /* substr() operations on characters, but addColOffset is in bytes. So we |
| 107985 | 108117 | ** have to use printf() to translate between these units: */ |
| 107986 | | - assert( !IsVirtual(pTab) ); |
| 108118 | + assert( IsOrdinaryTable(pTab) ); |
| 108119 | + assert( IsOrdinaryTable(pNew) ); |
| 107987 | 108120 | sqlite3NestedParse(pParse, |
| 107988 | 108121 | "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET " |
| 107989 | 108122 | "sql = printf('%%.%ds, ',sql) || %Q" |
| 107990 | 108123 | " || substr(sql,1+length(printf('%%.%ds',sql))) " |
| 107991 | 108124 | "WHERE type = 'table' AND name = %Q", |
| | @@ -108075,10 +108208,11 @@ |
| 108075 | 108208 | if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){ |
| 108076 | 108209 | goto exit_begin_add_column; |
| 108077 | 108210 | } |
| 108078 | 108211 | |
| 108079 | 108212 | sqlite3MayAbort(pParse); |
| 108213 | + assert( IsOrdinaryTable(pTab) ); |
| 108080 | 108214 | assert( pTab->u.tab.addColOffset>0 ); |
| 108081 | 108215 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 108082 | 108216 | |
| 108083 | 108217 | /* Put a copy of the Table struct in Parse.pNewTable for the |
| 108084 | 108218 | ** sqlite3AddColumn() function and friends to modify. But modify |
| | @@ -108105,11 +108239,11 @@ |
| 108105 | 108239 | for(i=0; i<pNew->nCol; i++){ |
| 108106 | 108240 | Column *pCol = &pNew->aCol[i]; |
| 108107 | 108241 | pCol->zCnName = sqlite3DbStrDup(db, pCol->zCnName); |
| 108108 | 108242 | pCol->hName = sqlite3StrIHash(pCol->zCnName); |
| 108109 | 108243 | } |
| 108110 | | - assert( !IsVirtual(pNew) ); |
| 108244 | + assert( IsOrdinaryTable(pNew) ); |
| 108111 | 108245 | pNew->u.tab.pDfltList = sqlite3ExprListDup(db, pTab->u.tab.pDfltList, 0); |
| 108112 | 108246 | pNew->pSchema = db->aDb[iDb].pSchema; |
| 108113 | 108247 | pNew->u.tab.addColOffset = pTab->u.tab.addColOffset; |
| 108114 | 108248 | pNew->nTabRef = 1; |
| 108115 | 108249 | |
| | @@ -108374,11 +108508,13 @@ |
| 108374 | 108508 | ** Walker callback used by sqlite3RenameExprUnmap(). |
| 108375 | 108509 | */ |
| 108376 | 108510 | static int renameUnmapExprCb(Walker *pWalker, Expr *pExpr){ |
| 108377 | 108511 | Parse *pParse = pWalker->pParse; |
| 108378 | 108512 | 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 | + } |
| 108380 | 108516 | return WRC_Continue; |
| 108381 | 108517 | } |
| 108382 | 108518 | |
| 108383 | 108519 | /* |
| 108384 | 108520 | ** Iterate through the Select objects that are part of WITH clauses attached |
| | @@ -108436,11 +108572,13 @@ |
| 108436 | 108572 | */ |
| 108437 | 108573 | static int renameUnmapSelectCb(Walker *pWalker, Select *p){ |
| 108438 | 108574 | Parse *pParse = pWalker->pParse; |
| 108439 | 108575 | int i; |
| 108440 | 108576 | 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) ){ |
| 108442 | 108580 | return WRC_Prune; |
| 108443 | 108581 | } |
| 108444 | 108582 | if( ALWAYS(p->pEList) ){ |
| 108445 | 108583 | ExprList *pList = p->pEList; |
| 108446 | 108584 | for(i=0; i<pList->nExpr; i++){ |
| | @@ -108573,10 +108711,11 @@ |
| 108573 | 108711 | && pWalker->pParse->pTriggerTab==p->pTab |
| 108574 | 108712 | ){ |
| 108575 | 108713 | renameTokenFind(pWalker->pParse, p, (void*)pExpr); |
| 108576 | 108714 | }else if( pExpr->op==TK_COLUMN |
| 108577 | 108715 | && pExpr->iColumn==p->iCol |
| 108716 | + && ALWAYS(ExprUseYTab(pExpr)) |
| 108578 | 108717 | && p->pTab==pExpr->y.pTab |
| 108579 | 108718 | ){ |
| 108580 | 108719 | renameTokenFind(pWalker->pParse, p, (void*)pExpr); |
| 108581 | 108720 | } |
| 108582 | 108721 | return WRC_Continue; |
| | @@ -109103,11 +109242,11 @@ |
| 109103 | 109242 | sqlite3WalkExpr(&sWalker, pExpr); |
| 109104 | 109243 | } |
| 109105 | 109244 | #endif |
| 109106 | 109245 | } |
| 109107 | 109246 | |
| 109108 | | - assert( !IsVirtual(sParse.pNewTable) ); |
| 109247 | + assert( IsOrdinaryTable(sParse.pNewTable) ); |
| 109109 | 109248 | for(pFKey=sParse.pNewTable->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109110 | 109249 | for(i=0; i<pFKey->nCol; i++){ |
| 109111 | 109250 | if( bFKOnly==0 && pFKey->aCol[i].iFrom==iCol ){ |
| 109112 | 109251 | renameTokenFind(&sParse, &sCtx, (void*)&pFKey->aCol[i]); |
| 109113 | 109252 | } |
| | @@ -109175,11 +109314,14 @@ |
| 109175 | 109314 | /* |
| 109176 | 109315 | ** Walker expression callback used by "RENAME TABLE". |
| 109177 | 109316 | */ |
| 109178 | 109317 | static int renameTableExprCb(Walker *pWalker, Expr *pExpr){ |
| 109179 | 109318 | 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 | + ){ |
| 109181 | 109323 | renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab); |
| 109182 | 109324 | } |
| 109183 | 109325 | return WRC_Continue; |
| 109184 | 109326 | } |
| 109185 | 109327 | |
| | @@ -109293,11 +109435,11 @@ |
| 109293 | 109435 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 109294 | 109436 | if( (isLegacy==0 || (db->flags & SQLITE_ForeignKeys)) |
| 109295 | 109437 | && !IsVirtual(pTab) |
| 109296 | 109438 | ){ |
| 109297 | 109439 | FKey *pFKey; |
| 109298 | | - assert( !IsVirtual(pTab) ); |
| 109440 | + assert( IsOrdinaryTable(pTab) ); |
| 109299 | 109441 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 109300 | 109442 | if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ |
| 109301 | 109443 | renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); |
| 109302 | 109444 | } |
| 109303 | 109445 | } |
| | @@ -109614,11 +109756,11 @@ |
| 109614 | 109756 | if( iCol<pTab->nCol-1 ){ |
| 109615 | 109757 | RenameToken *pEnd; |
| 109616 | 109758 | pEnd = renameTokenFind(&sParse, 0, (void*)pTab->aCol[iCol+1].zCnName); |
| 109617 | 109759 | zEnd = (const char*)pEnd->t.z; |
| 109618 | 109760 | }else{ |
| 109619 | | - assert( !IsVirtual(pTab) ); |
| 109761 | + assert( IsOrdinaryTable(pTab) ); |
| 109620 | 109762 | zEnd = (const char*)&zSql[pTab->u.tab.addColOffset]; |
| 109621 | 109763 | while( ALWAYS(pCol->t.z[0]!=0) && pCol->t.z[0]!=',' ) pCol->t.z--; |
| 109622 | 109764 | } |
| 109623 | 109765 | |
| 109624 | 109766 | zNew = sqlite3MPrintf(db, "%.*s%s", pCol->t.z-zSql, zSql, zEnd); |
| | @@ -110789,11 +110931,11 @@ |
| 110789 | 110931 | pParse->nMem = MAX(pParse->nMem, iMem); |
| 110790 | 110932 | v = sqlite3GetVdbe(pParse); |
| 110791 | 110933 | if( v==0 || NEVER(pTab==0) ){ |
| 110792 | 110934 | return; |
| 110793 | 110935 | } |
| 110794 | | - if( pTab->tnum==0 ){ |
| 110936 | + if( !IsOrdinaryTable(pTab) ){ |
| 110795 | 110937 | /* Do not gather statistics on views or virtual tables */ |
| 110796 | 110938 | return; |
| 110797 | 110939 | } |
| 110798 | 110940 | if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){ |
| 110799 | 110941 | /* Do not gather statistics on system tables */ |
| | @@ -112083,10 +112225,11 @@ |
| 112083 | 112225 | |
| 112084 | 112226 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 112085 | 112227 | if( pAuthArg ){ |
| 112086 | 112228 | char *zAuthArg; |
| 112087 | 112229 | if( pAuthArg->op==TK_STRING ){ |
| 112230 | + assert( !ExprHasProperty(pAuthArg, EP_IntValue) ); |
| 112088 | 112231 | zAuthArg = pAuthArg->u.zToken; |
| 112089 | 112232 | }else{ |
| 112090 | 112233 | zAuthArg = 0; |
| 112091 | 112234 | } |
| 112092 | 112235 | rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0); |
| | @@ -112767,21 +112910,25 @@ |
| 112767 | 112910 | Returning *pReturning = pParse->u1.pReturning; |
| 112768 | 112911 | int addrRewind; |
| 112769 | 112912 | int i; |
| 112770 | 112913 | int reg; |
| 112771 | 112914 | |
| 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 | + } |
| 112783 | 112930 | } |
| 112784 | 112931 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 112785 | 112932 | |
| 112786 | 112933 | #if SQLITE_USER_AUTHENTICATION |
| 112787 | 112934 | if( pParse->nTableLock>0 && db->init.busy==0 ){ |
| | @@ -112858,11 +113005,15 @@ |
| 112858 | 113005 | } |
| 112859 | 113006 | } |
| 112860 | 113007 | |
| 112861 | 113008 | if( pParse->bReturning ){ |
| 112862 | 113009 | 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 | + } |
| 112864 | 113015 | } |
| 112865 | 113016 | |
| 112866 | 113017 | /* Finally, jump back to the beginning of the executable code. */ |
| 112867 | 113018 | sqlite3VdbeGoto(v, 1); |
| 112868 | 113019 | } |
| | @@ -113280,11 +113431,11 @@ |
| 113280 | 113431 | Table *pTab, /* The table containing the column */ |
| 113281 | 113432 | Column *pCol, /* The column to receive the new DEFAULT expression */ |
| 113282 | 113433 | Expr *pExpr /* The new default expression */ |
| 113283 | 113434 | ){ |
| 113284 | 113435 | ExprList *pList; |
| 113285 | | - assert( !IsVirtual(pTab) ); |
| 113436 | + assert( IsOrdinaryTable(pTab) ); |
| 113286 | 113437 | pList = pTab->u.tab.pDfltList; |
| 113287 | 113438 | if( pCol->iDflt==0 |
| 113288 | 113439 | || NEVER(pList==0) |
| 113289 | 113440 | || NEVER(pList->nExpr<pCol->iDflt) |
| 113290 | 113441 | ){ |
| | @@ -113301,11 +113452,11 @@ |
| 113301 | 113452 | ** the DEFAULT clause or the AS clause of a generated column. |
| 113302 | 113453 | ** Return NULL if the column has no associated expression. |
| 113303 | 113454 | */ |
| 113304 | 113455 | SQLITE_PRIVATE Expr *sqlite3ColumnExpr(Table *pTab, Column *pCol){ |
| 113305 | 113456 | if( pCol->iDflt==0 ) return 0; |
| 113306 | | - if( NEVER(IsVirtual(pTab)) ) return 0; |
| 113457 | + if( NEVER(!IsOrdinaryTable(pTab)) ) return 0; |
| 113307 | 113458 | if( NEVER(pTab->u.tab.pDfltList==0) ) return 0; |
| 113308 | 113459 | if( NEVER(pTab->u.tab.pDfltList->nExpr<pCol->iDflt) ) return 0; |
| 113309 | 113460 | return pTab->u.tab.pDfltList->a[pCol->iDflt-1].pExpr; |
| 113310 | 113461 | } |
| 113311 | 113462 | |
| | @@ -113360,17 +113511,17 @@ |
| 113360 | 113511 | for(i=0; i<pTable->nCol; i++, pCol++){ |
| 113361 | 113512 | assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) ); |
| 113362 | 113513 | sqlite3DbFree(db, pCol->zCnName); |
| 113363 | 113514 | } |
| 113364 | 113515 | sqlite3DbFree(db, pTable->aCol); |
| 113365 | | - if( !IsVirtual(pTable) ){ |
| 113516 | + if( IsOrdinaryTable(pTable) ){ |
| 113366 | 113517 | sqlite3ExprListDelete(db, pTable->u.tab.pDfltList); |
| 113367 | 113518 | } |
| 113368 | 113519 | if( db==0 || db->pnBytesFreed==0 ){ |
| 113369 | 113520 | pTable->aCol = 0; |
| 113370 | 113521 | pTable->nCol = 0; |
| 113371 | | - if( !IsVirtual(pTable) ){ |
| 113522 | + if( IsOrdinaryTable(pTable) ){ |
| 113372 | 113523 | pTable->u.tab.pDfltList = 0; |
| 113373 | 113524 | } |
| 113374 | 113525 | } |
| 113375 | 113526 | } |
| 113376 | 113527 | } |
| | @@ -114433,11 +114584,13 @@ |
| 114433 | 114584 | for(i=0; i<nTerm; i++){ |
| 114434 | 114585 | Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr); |
| 114435 | 114586 | assert( pCExpr!=0 ); |
| 114436 | 114587 | sqlite3StringToId(pCExpr); |
| 114437 | 114588 | 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; |
| 114439 | 114592 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 114440 | 114593 | if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){ |
| 114441 | 114594 | pCol = &pTab->aCol[iCol]; |
| 114442 | 114595 | makeColumnPartOfPrimaryKey(pParse, pCol); |
| 114443 | 114596 | break; |
| | @@ -114805,11 +114958,10 @@ |
| 114805 | 114958 | ** This is used to determine if the column number x appears in any of the |
| 114806 | 114959 | ** first nCol entries of an index. |
| 114807 | 114960 | */ |
| 114808 | 114961 | static int hasColumn(const i16 *aiCol, int nCol, int x){ |
| 114809 | 114962 | while( nCol-- > 0 ){ |
| 114810 | | - assert( aiCol[0]>=0 ); |
| 114811 | 114963 | if( x==*(aiCol++) ){ |
| 114812 | 114964 | return 1; |
| 114813 | 114965 | } |
| 114814 | 114966 | } |
| 114815 | 114967 | return 0; |
| | @@ -115181,11 +115333,11 @@ |
| 115181 | 115333 | ** |
| 115182 | 115334 | ** If the root page number is 1, that means this is the sqlite_schema |
| 115183 | 115335 | ** table itself. So mark it read-only. |
| 115184 | 115336 | */ |
| 115185 | 115337 | if( db->init.busy ){ |
| 115186 | | - if( pSelect ){ |
| 115338 | + if( pSelect || (!IsOrdinaryTable(p) && db->init.newTnum) ){ |
| 115187 | 115339 | sqlite3ErrorMsg(pParse, ""); |
| 115188 | 115340 | return; |
| 115189 | 115341 | } |
| 115190 | 115342 | p->tnum = db->init.newTnum; |
| 115191 | 115343 | if( p->tnum==1 ) p->tabFlags |= TF_Readonly; |
| | @@ -116146,10 +116298,11 @@ |
| 116146 | 116298 | pFKey = sqlite3DbMallocZero(db, nByte ); |
| 116147 | 116299 | if( pFKey==0 ){ |
| 116148 | 116300 | goto fk_end; |
| 116149 | 116301 | } |
| 116150 | 116302 | pFKey->pFrom = p; |
| 116303 | + assert( IsOrdinaryTable(p) ); |
| 116151 | 116304 | pFKey->pNextFrom = p->u.tab.pFKey; |
| 116152 | 116305 | z = (char*)&pFKey->aCol[nCol]; |
| 116153 | 116306 | pFKey->zTo = z; |
| 116154 | 116307 | if( IN_RENAME_OBJECT ){ |
| 116155 | 116308 | sqlite3RenameTokenMap(pParse, (void*)z, pTo); |
| | @@ -116211,11 +116364,11 @@ |
| 116211 | 116364 | pNextTo->pPrevTo = pFKey; |
| 116212 | 116365 | } |
| 116213 | 116366 | |
| 116214 | 116367 | /* Link the foreign key to the table as the last step. |
| 116215 | 116368 | */ |
| 116216 | | - assert( !IsVirtual(p) ); |
| 116369 | + assert( IsOrdinaryTable(p) ); |
| 116217 | 116370 | p->u.tab.pFKey = pFKey; |
| 116218 | 116371 | pFKey = 0; |
| 116219 | 116372 | |
| 116220 | 116373 | fk_end: |
| 116221 | 116374 | sqlite3DbFree(db, pFKey); |
| | @@ -116234,11 +116387,11 @@ |
| 116234 | 116387 | SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){ |
| 116235 | 116388 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 116236 | 116389 | Table *pTab; |
| 116237 | 116390 | FKey *pFKey; |
| 116238 | 116391 | if( (pTab = pParse->pNewTable)==0 ) return; |
| 116239 | | - if( NEVER(IsVirtual(pTab)) ) return; |
| 116392 | + if( NEVER(!IsOrdinaryTable(pTab)) ) return; |
| 116240 | 116393 | if( (pFKey = pTab->u.tab.pFKey)==0 ) return; |
| 116241 | 116394 | assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */ |
| 116242 | 116395 | pFKey->isDeferred = (u8)isDeferred; |
| 116243 | 116396 | #endif |
| 116244 | 116397 | } |
| | @@ -116636,10 +116789,11 @@ |
| 116636 | 116789 | */ |
| 116637 | 116790 | for(i=0; i<pList->nExpr; i++){ |
| 116638 | 116791 | Expr *pExpr = pList->a[i].pExpr; |
| 116639 | 116792 | assert( pExpr!=0 ); |
| 116640 | 116793 | if( pExpr->op==TK_COLLATE ){ |
| 116794 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 116641 | 116795 | nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken)); |
| 116642 | 116796 | } |
| 116643 | 116797 | } |
| 116644 | 116798 | |
| 116645 | 116799 | /* |
| | @@ -116731,10 +116885,11 @@ |
| 116731 | 116885 | pIndex->aiColumn[i] = (i16)j; |
| 116732 | 116886 | } |
| 116733 | 116887 | zColl = 0; |
| 116734 | 116888 | if( pListItem->pExpr->op==TK_COLLATE ){ |
| 116735 | 116889 | int nColl; |
| 116890 | + assert( !ExprHasProperty(pListItem->pExpr, EP_IntValue) ); |
| 116736 | 116891 | zColl = pListItem->pExpr->u.zToken; |
| 116737 | 116892 | nColl = sqlite3Strlen30(zColl) + 1; |
| 116738 | 116893 | assert( nExtra>=nColl ); |
| 116739 | 116894 | memcpy(zExtra, zColl, nColl); |
| 116740 | 116895 | zColl = zExtra; |
| | @@ -117519,10 +117674,11 @@ |
| 117519 | 117674 | ** construct "indexed_opt" for details. */ |
| 117520 | 117675 | pItem->fg.notIndexed = 1; |
| 117521 | 117676 | }else{ |
| 117522 | 117677 | pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy); |
| 117523 | 117678 | pItem->fg.isIndexedBy = 1; |
| 117679 | + assert( pItem->fg.isCte==0 ); /* No collision on union u2 */ |
| 117524 | 117680 | } |
| 117525 | 117681 | } |
| 117526 | 117682 | } |
| 117527 | 117683 | |
| 117528 | 117684 | /* |
| | @@ -118499,10 +118655,11 @@ |
| 118499 | 118655 | int h, /* Hash of the name */ |
| 118500 | 118656 | const char *zFunc /* Name of function */ |
| 118501 | 118657 | ){ |
| 118502 | 118658 | FuncDef *p; |
| 118503 | 118659 | for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){ |
| 118660 | + assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); |
| 118504 | 118661 | if( sqlite3StrICmp(p->zName, zFunc)==0 ){ |
| 118505 | 118662 | return p; |
| 118506 | 118663 | } |
| 118507 | 118664 | } |
| 118508 | 118665 | return 0; |
| | @@ -118520,10 +118677,11 @@ |
| 118520 | 118677 | FuncDef *pOther; |
| 118521 | 118678 | const char *zName = aDef[i].zName; |
| 118522 | 118679 | int nName = sqlite3Strlen30(zName); |
| 118523 | 118680 | int h = SQLITE_FUNC_HASH(zName[0], nName); |
| 118524 | 118681 | assert( zName[0]>='a' && zName[0]<='z' ); |
| 118682 | + assert( aDef[i].funcFlags & SQLITE_FUNC_BUILTIN ); |
| 118525 | 118683 | pOther = sqlite3FunctionSearch(h, zName); |
| 118526 | 118684 | if( pOther ){ |
| 118527 | 118685 | assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] ); |
| 118528 | 118686 | aDef[i].pNext = pOther->pNext; |
| 118529 | 118687 | pOther->pNext = &aDef[i]; |
| | @@ -118911,10 +119069,11 @@ |
| 118911 | 119069 | ** and the SELECT subtree. */ |
| 118912 | 119070 | pSrc->a[0].pTab = 0; |
| 118913 | 119071 | pSelectSrc = sqlite3SrcListDup(db, pSrc, 0); |
| 118914 | 119072 | pSrc->a[0].pTab = pTab; |
| 118915 | 119073 | if( pSrc->a[0].fg.isIndexedBy ){ |
| 119074 | + assert( pSrc->a[0].fg.isCte==0 ); |
| 118916 | 119075 | pSrc->a[0].u2.pIBIndex = 0; |
| 118917 | 119076 | pSrc->a[0].fg.isIndexedBy = 0; |
| 118918 | 119077 | sqlite3DbFree(db, pSrc->a[0].u1.zIndexedBy); |
| 118919 | 119078 | }else if( pSrc->a[0].fg.isCte ){ |
| 118920 | 119079 | pSrc->a[0].u2.pCteUse->nUse++; |
| | @@ -121495,11 +121654,15 @@ |
| 121495 | 121654 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 121496 | 121655 | pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); |
| 121497 | 121656 | /* pGCC is always non-NULL since groupConcatStep() will have always |
| 121498 | 121657 | ** run frist to initialize it */ |
| 121499 | 121658 | 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]); |
| 121501 | 121664 | pGCC->nAccum -= 1; |
| 121502 | 121665 | if( pGCC->pnSepLengths!=0 ){ |
| 121503 | 121666 | assert(pGCC->nAccum >= 0); |
| 121504 | 121667 | if( pGCC->nAccum>0 ){ |
| 121505 | 121668 | nVS += *pGCC->pnSepLengths; |
| | @@ -121610,15 +121773,16 @@ |
| 121610 | 121773 | SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ |
| 121611 | 121774 | FuncDef *pDef; |
| 121612 | 121775 | int nExpr; |
| 121613 | 121776 | assert( pExpr!=0 ); |
| 121614 | 121777 | assert( pExpr->op==TK_FUNCTION ); |
| 121778 | + assert( ExprUseXList(pExpr) ); |
| 121615 | 121779 | if( !pExpr->x.pList ){ |
| 121616 | 121780 | return 0; |
| 121617 | 121781 | } |
| 121618 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 121619 | 121782 | nExpr = pExpr->x.pList->nExpr; |
| 121783 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 121620 | 121784 | pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0); |
| 121621 | 121785 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 121622 | 121786 | if( pDef==0 ) return 0; |
| 121623 | 121787 | #endif |
| 121624 | 121788 | if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){ |
| | @@ -121638,10 +121802,11 @@ |
| 121638 | 121802 | aWc[3] = 0; |
| 121639 | 121803 | }else{ |
| 121640 | 121804 | Expr *pEscape = pExpr->x.pList->a[2].pExpr; |
| 121641 | 121805 | char *zEscape; |
| 121642 | 121806 | if( pEscape->op!=TK_STRING ) return 0; |
| 121807 | + assert( !ExprHasProperty(pEscape, EP_IntValue) ); |
| 121643 | 121808 | zEscape = pEscape->u.zToken; |
| 121644 | 121809 | if( zEscape[0]==0 || zEscape[1]!=0 ) return 0; |
| 121645 | 121810 | if( zEscape[0]==aWc[0] ) return 0; |
| 121646 | 121811 | if( zEscape[0]==aWc[1] ) return 0; |
| 121647 | 121812 | aWc[3] = zEscape[0]; |
| | @@ -122019,10 +122184,11 @@ |
| 122019 | 122184 | for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 122020 | 122185 | printf("FUNC-HASH %02d:", i); |
| 122021 | 122186 | for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash){ |
| 122022 | 122187 | int n = sqlite3Strlen30(p->zName); |
| 122023 | 122188 | int h = p->zName[0] + n; |
| 122189 | + assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); |
| 122024 | 122190 | printf(" %s(%d)", p->zName, h); |
| 122025 | 122191 | } |
| 122026 | 122192 | printf("\n"); |
| 122027 | 122193 | } |
| 122028 | 122194 | } |
| | @@ -122541,10 +122707,11 @@ |
| 122541 | 122707 | int iCursor, /* The open cursor on the table */ |
| 122542 | 122708 | i16 iCol /* The column that is wanted */ |
| 122543 | 122709 | ){ |
| 122544 | 122710 | Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0); |
| 122545 | 122711 | if( pExpr ){ |
| 122712 | + assert( ExprUseYTab(pExpr) ); |
| 122546 | 122713 | pExpr->y.pTab = pTab; |
| 122547 | 122714 | pExpr->iTable = iCursor; |
| 122548 | 122715 | pExpr->iColumn = iCol; |
| 122549 | 122716 | } |
| 122550 | 122717 | return pExpr; |
| | @@ -122751,17 +122918,16 @@ |
| 122751 | 122918 | ** the table from the database. Triggers are disabled while running this |
| 122752 | 122919 | ** DELETE, but foreign key actions are not. |
| 122753 | 122920 | */ |
| 122754 | 122921 | SQLITE_PRIVATE void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){ |
| 122755 | 122922 | sqlite3 *db = pParse->db; |
| 122756 | | - if( (db->flags&SQLITE_ForeignKeys) && !IsVirtual(pTab) ){ |
| 122923 | + if( (db->flags&SQLITE_ForeignKeys) && IsOrdinaryTable(pTab) ){ |
| 122757 | 122924 | int iSkip = 0; |
| 122758 | 122925 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 122759 | 122926 | |
| 122760 | 122927 | assert( v ); /* VDBE has already been allocated */ |
| 122761 | | - assert( !IsView(pTab) ); /* Not a view */ |
| 122762 | | - assert( !IsVirtual(pTab) ); |
| 122928 | + assert( IsOrdinaryTable(pTab) ); |
| 122763 | 122929 | if( sqlite3FkReferences(pTab)==0 ){ |
| 122764 | 122930 | /* Search for a deferred foreign key constraint for which this table |
| 122765 | 122931 | ** is the child table. If one cannot be found, return without |
| 122766 | 122932 | ** generating any VDBE code. If one can be found, then jump over |
| 122767 | 122933 | ** the entire DELETE if there are no outstanding deferred constraints |
| | @@ -122921,17 +123087,17 @@ |
| 122921 | 123087 | /* Exactly one of regOld and regNew should be non-zero. */ |
| 122922 | 123088 | assert( (regOld==0)!=(regNew==0) ); |
| 122923 | 123089 | |
| 122924 | 123090 | /* If foreign-keys are disabled, this function is a no-op. */ |
| 122925 | 123091 | if( (db->flags&SQLITE_ForeignKeys)==0 ) return; |
| 123092 | + if( !IsOrdinaryTable(pTab) ) return; |
| 122926 | 123093 | |
| 122927 | 123094 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 122928 | 123095 | zDb = db->aDb[iDb].zDbSName; |
| 122929 | 123096 | |
| 122930 | 123097 | /* Loop through all the foreign key constraints for which pTab is the |
| 122931 | 123098 | ** child table (the table that the foreign key definition is part of). */ |
| 122932 | | - assert( !IsVirtual(pTab) ); |
| 122933 | 123099 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 122934 | 123100 | Table *pTo; /* Parent table of foreign key pFKey */ |
| 122935 | 123101 | Index *pIdx = 0; /* Index on key columns in pTo */ |
| 122936 | 123102 | int *aiFree = 0; |
| 122937 | 123103 | int *aiCol; |
| | @@ -123110,14 +123276,13 @@ |
| 123110 | 123276 | SQLITE_PRIVATE u32 sqlite3FkOldmask( |
| 123111 | 123277 | Parse *pParse, /* Parse context */ |
| 123112 | 123278 | Table *pTab /* Table being modified */ |
| 123113 | 123279 | ){ |
| 123114 | 123280 | u32 mask = 0; |
| 123115 | | - if( pParse->db->flags&SQLITE_ForeignKeys ){ |
| 123281 | + if( pParse->db->flags&SQLITE_ForeignKeys && IsOrdinaryTable(pTab) ){ |
| 123116 | 123282 | FKey *p; |
| 123117 | 123283 | int i; |
| 123118 | | - assert( !IsVirtual(pTab) ); |
| 123119 | 123284 | for(p=pTab->u.tab.pFKey; p; p=p->pNextFrom){ |
| 123120 | 123285 | for(i=0; i<p->nCol; i++) mask |= COLUMN_MASK(p->aCol[i].iFrom); |
| 123121 | 123286 | } |
| 123122 | 123287 | for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){ |
| 123123 | 123288 | Index *pIdx = 0; |
| | @@ -123164,11 +123329,11 @@ |
| 123164 | 123329 | int *aChange, /* Non-NULL for UPDATE operations */ |
| 123165 | 123330 | int chngRowid /* True for UPDATE that affects rowid */ |
| 123166 | 123331 | ){ |
| 123167 | 123332 | int eRet = 1; /* Value to return if bHaveFK is true */ |
| 123168 | 123333 | 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) ){ |
| 123170 | 123335 | if( !aChange ){ |
| 123171 | 123336 | /* A DELETE operation. Foreign key processing is required if the |
| 123172 | 123337 | ** table in question is either the child or parent table for any |
| 123173 | 123338 | ** foreign key constraint. */ |
| 123174 | 123339 | bHaveFK = (sqlite3FkReferences(pTab) || pTab->u.tab.pFKey); |
| | @@ -123452,11 +123617,11 @@ |
| 123452 | 123617 | */ |
| 123453 | 123618 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ |
| 123454 | 123619 | FKey *pFKey; /* Iterator variable */ |
| 123455 | 123620 | FKey *pNext; /* Copy of pFKey->pNextFrom */ |
| 123456 | 123621 | |
| 123457 | | - assert( !IsVirtual(pTab) ); |
| 123622 | + assert( IsOrdinaryTable(pTab) ); |
| 123458 | 123623 | for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){ |
| 123459 | 123624 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); |
| 123460 | 123625 | |
| 123461 | 123626 | /* Remove the FK from the fkeyHash hash table. */ |
| 123462 | 123627 | if( !db || db->pnBytesFreed==0 ){ |
| | @@ -125711,10 +125876,11 @@ |
| 125711 | 125876 | ** (5) No FK constraint counters need to be updated if a conflict occurs. |
| 125712 | 125877 | ** |
| 125713 | 125878 | ** This is not possible for ENABLE_PREUPDATE_HOOK builds, as the row |
| 125714 | 125879 | ** must be explicitly deleted in order to ensure any pre-update hook |
| 125715 | 125880 | ** is invoked. */ |
| 125881 | + assert( IsOrdinaryTable(pTab) ); |
| 125716 | 125882 | #ifndef SQLITE_ENABLE_PREUPDATE_HOOK |
| 125717 | 125883 | if( (ix==0 && pIdx->pNext==0) /* Condition 3 */ |
| 125718 | 125884 | && pPk==pIdx /* Condition 2 */ |
| 125719 | 125885 | && onError==OE_Replace /* Condition 1 */ |
| 125720 | 125886 | && ( 0==(db->flags&SQLITE_RecTriggers) || /* Condition 4 */ |
| | @@ -126391,11 +126557,13 @@ |
| 126391 | 126557 | /* Default values for second and subsequent columns need to match. */ |
| 126392 | 126558 | if( (pDestCol->colFlags & COLFLAG_GENERATED)==0 && i>0 ){ |
| 126393 | 126559 | Expr *pDestExpr = sqlite3ColumnExpr(pDest, pDestCol); |
| 126394 | 126560 | Expr *pSrcExpr = sqlite3ColumnExpr(pSrc, pSrcCol); |
| 126395 | 126561 | assert( pDestExpr==0 || pDestExpr->op==TK_SPAN ); |
| 126562 | + assert( pDestExpr==0 || !ExprHasProperty(pDestExpr, EP_IntValue) ); |
| 126396 | 126563 | assert( pSrcExpr==0 || pSrcExpr->op==TK_SPAN ); |
| 126564 | + assert( pSrcExpr==0 || !ExprHasProperty(pSrcExpr, EP_IntValue) ); |
| 126397 | 126565 | if( (pDestExpr==0)!=(pSrcExpr==0) |
| 126398 | 126566 | || (pDestExpr!=0 && strcmp(pDestExpr->u.zToken, |
| 126399 | 126567 | pSrcExpr->u.zToken)!=0) |
| 126400 | 126568 | ){ |
| 126401 | 126569 | return 0; /* Default values must be the same for all columns */ |
| | @@ -126431,10 +126599,11 @@ |
| 126431 | 126599 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 126432 | 126600 | ** command, and the VACUUM command disables foreign key constraints. So |
| 126433 | 126601 | ** the extra complication to make this rule less restrictive is probably |
| 126434 | 126602 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| 126435 | 126603 | */ |
| 126604 | + assert( IsOrdinaryTable(pDest) ); |
| 126436 | 126605 | if( (db->flags & SQLITE_ForeignKeys)!=0 && pDest->u.tab.pFKey!=0 ){ |
| 126437 | 126606 | return 0; |
| 126438 | 126607 | } |
| 126439 | 126608 | #endif |
| 126440 | 126609 | if( (db->flags & SQLITE_CountRows)!=0 ){ |
| | @@ -129423,11 +129592,15 @@ |
| 129423 | 129592 | goto pragma_out; |
| 129424 | 129593 | } |
| 129425 | 129594 | |
| 129426 | 129595 | /* Locate the pragma in the lookup table */ |
| 129427 | 129596 | 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 | + } |
| 129429 | 129602 | |
| 129430 | 129603 | /* Make sure the database schema is loaded if the pragma requires that */ |
| 129431 | 129604 | if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){ |
| 129432 | 129605 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 129433 | 129606 | } |
| | @@ -130073,10 +130246,18 @@ |
| 130073 | 130246 | if( sqlite3GetBoolean(zRight, 0) ){ |
| 130074 | 130247 | db->flags |= mask; |
| 130075 | 130248 | }else{ |
| 130076 | 130249 | db->flags &= ~mask; |
| 130077 | 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 | + } |
| 130078 | 130259 | } |
| 130079 | 130260 | |
| 130080 | 130261 | /* Many of the flag-pragmas modify the code generated by the SQL |
| 130081 | 130262 | ** compiler (eg. count_changes). So add an opcode to expire all |
| 130082 | 130263 | ** compiled SQL statements after modifying a pragma value. |
| | @@ -130113,10 +130294,11 @@ |
| 130113 | 130294 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 130114 | 130295 | pParse->nMem = 7; |
| 130115 | 130296 | sqlite3ViewGetColumnNames(pParse, pTab); |
| 130116 | 130297 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 130117 | 130298 | int isHidden = 0; |
| 130299 | + const Expr *pColExpr; |
| 130118 | 130300 | if( pCol->colFlags & COLFLAG_NOINSERT ){ |
| 130119 | 130301 | if( pPragma->iArg==0 ){ |
| 130120 | 130302 | nHidden++; |
| 130121 | 130303 | continue; |
| 130122 | 130304 | } |
| | @@ -130133,20 +130315,20 @@ |
| 130133 | 130315 | }else if( pPk==0 ){ |
| 130134 | 130316 | k = 1; |
| 130135 | 130317 | }else{ |
| 130136 | 130318 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
| 130137 | 130319 | } |
| 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 ); |
| 130141 | 130324 | sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi", |
| 130142 | 130325 | i-nHidden, |
| 130143 | 130326 | pCol->zCnName, |
| 130144 | 130327 | sqlite3ColumnType(pCol,""), |
| 130145 | 130328 | 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, |
| 130148 | 130330 | k, |
| 130149 | 130331 | isHidden); |
| 130150 | 130332 | } |
| 130151 | 130333 | } |
| 130152 | 130334 | } |
| | @@ -130170,12 +130352,39 @@ |
| 130170 | 130352 | pParse->nMem = 6; |
| 130171 | 130353 | sqlite3CodeVerifyNamedSchema(pParse, zDb); |
| 130172 | 130354 | for(ii=0; ii<db->nDb; ii++){ |
| 130173 | 130355 | HashElem *k; |
| 130174 | 130356 | Hash *pHash; |
| 130357 | + int initNCol; |
| 130175 | 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 | + */ |
| 130176 | 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 | + |
| 130177 | 130386 | for(k=sqliteHashFirst(pHash); k; k=sqliteHashNext(k) ){ |
| 130178 | 130387 | Table *pTab = sqliteHashData(k); |
| 130179 | 130388 | const char *zType; |
| 130180 | 130389 | if( zRight && sqlite3_stricmp(zRight, pTab->zName)!=0 ) continue; |
| 130181 | 130390 | if( IsView(pTab) ){ |
| | @@ -130326,15 +130535,17 @@ |
| 130326 | 130535 | FuncDef *p; |
| 130327 | 130536 | int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0; |
| 130328 | 130537 | pParse->nMem = 6; |
| 130329 | 130538 | for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 130330 | 130539 | for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){ |
| 130540 | + assert( p->funcFlags & SQLITE_FUNC_BUILTIN ); |
| 130331 | 130541 | pragmaFunclistLine(v, p, 1, showInternFunc); |
| 130332 | 130542 | } |
| 130333 | 130543 | } |
| 130334 | 130544 | for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){ |
| 130335 | 130545 | p = (FuncDef*)sqliteHashData(j); |
| 130546 | + assert( (p->funcFlags & SQLITE_FUNC_BUILTIN)==0 ); |
| 130336 | 130547 | pragmaFunclistLine(v, p, 0, showInternFunc); |
| 130337 | 130548 | } |
| 130338 | 130549 | } |
| 130339 | 130550 | break; |
| 130340 | 130551 | |
| | @@ -130364,11 +130575,11 @@ |
| 130364 | 130575 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 130365 | 130576 | case PragTyp_FOREIGN_KEY_LIST: if( zRight ){ |
| 130366 | 130577 | FKey *pFK; |
| 130367 | 130578 | Table *pTab; |
| 130368 | 130579 | pTab = sqlite3FindTable(db, zRight, zDb); |
| 130369 | | - if( pTab && !IsVirtual(pTab) ){ |
| 130580 | + if( pTab && IsOrdinaryTable(pTab) ){ |
| 130370 | 130581 | pFK = pTab->u.tab.pFKey; |
| 130371 | 130582 | if( pFK ){ |
| 130372 | 130583 | int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 130373 | 130584 | int i = 0; |
| 130374 | 130585 | pParse->nMem = 8; |
| | @@ -130424,19 +130635,19 @@ |
| 130424 | 130635 | k = 0; |
| 130425 | 130636 | }else{ |
| 130426 | 130637 | pTab = (Table*)sqliteHashData(k); |
| 130427 | 130638 | k = sqliteHashNext(k); |
| 130428 | 130639 | } |
| 130429 | | - if( pTab==0 || IsVirtual(pTab) || pTab->u.tab.pFKey==0 ) continue; |
| 130640 | + if( pTab==0 || !IsOrdinaryTable(pTab) || pTab->u.tab.pFKey==0 ) continue; |
| 130430 | 130641 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 130431 | 130642 | zDb = db->aDb[iDb].zDbSName; |
| 130432 | 130643 | sqlite3CodeVerifySchema(pParse, iDb); |
| 130433 | 130644 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 130434 | 130645 | if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow; |
| 130435 | 130646 | sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead); |
| 130436 | 130647 | sqlite3VdbeLoadString(v, regResult, pTab->zName); |
| 130437 | | - assert( !IsVirtual(pTab) ); |
| 130648 | + assert( IsOrdinaryTable(pTab) ); |
| 130438 | 130649 | for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130439 | 130650 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 130440 | 130651 | if( pParent==0 ) continue; |
| 130441 | 130652 | pIdx = 0; |
| 130442 | 130653 | sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName); |
| | @@ -130455,11 +130666,11 @@ |
| 130455 | 130666 | } |
| 130456 | 130667 | assert( pParse->nErr>0 || pFK==0 ); |
| 130457 | 130668 | if( pFK ) break; |
| 130458 | 130669 | if( pParse->nTab<i ) pParse->nTab = i; |
| 130459 | 130670 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v); |
| 130460 | | - assert( !IsVirtual(pTab) ); |
| 130671 | + assert( IsOrdinaryTable(pTab) ); |
| 130461 | 130672 | for(i=1, pFK=pTab->u.tab.pFKey; pFK; i++, pFK=pFK->pNextFrom){ |
| 130462 | 130673 | pParent = sqlite3FindTable(db, pFK->zTo, zDb); |
| 130463 | 130674 | pIdx = 0; |
| 130464 | 130675 | aiCols = 0; |
| 130465 | 130676 | if( pParent ){ |
| | @@ -130659,11 +130870,11 @@ |
| 130659 | 130870 | int loopTop; |
| 130660 | 130871 | int iDataCur, iIdxCur; |
| 130661 | 130872 | int r1 = -1; |
| 130662 | 130873 | int bStrict; |
| 130663 | 130874 | |
| 130664 | | - if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */ |
| 130875 | + if( !IsOrdinaryTable(pTab) ) continue; |
| 130665 | 130876 | if( pObjTab && pObjTab!=pTab ) continue; |
| 130666 | 130877 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 130667 | 130878 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, |
| 130668 | 130879 | 1, 0, &iDataCur, &iIdxCur); |
| 130669 | 130880 | /* reg[7] counts the number of entries in the table. |
| | @@ -131254,16 +131465,16 @@ |
| 131254 | 131465 | ** in each index that it looks at. Return the new limit. |
| 131255 | 131466 | */ |
| 131256 | 131467 | case PragTyp_ANALYSIS_LIMIT: { |
| 131257 | 131468 | sqlite3_int64 N; |
| 131258 | 131469 | if( zRight |
| 131259 | | - && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK |
| 131470 | + && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK /* IMP: R-40975-20399 */ |
| 131260 | 131471 | && N>=0 |
| 131261 | 131472 | ){ |
| 131262 | 131473 | db->nAnalysisLimit = (int)(N&0x7fffffff); |
| 131263 | 131474 | } |
| 131264 | | - returnSingleInt(v, db->nAnalysisLimit); |
| 131475 | + returnSingleInt(v, db->nAnalysisLimit); /* IMP: R-57594-65522 */ |
| 131265 | 131476 | break; |
| 131266 | 131477 | } |
| 131267 | 131478 | |
| 131268 | 131479 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 131269 | 131480 | /* |
| | @@ -133046,14 +133257,17 @@ |
| 133046 | 133257 | while( p ){ |
| 133047 | 133258 | ExprSetProperty(p, EP_FromJoin); |
| 133048 | 133259 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 133049 | 133260 | ExprSetVVAProperty(p, EP_NoReduce); |
| 133050 | 133261 | 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 | + } |
| 133055 | 133269 | } |
| 133056 | 133270 | } |
| 133057 | 133271 | sqlite3SetJoinExpr(p->pLeft, iTable); |
| 133058 | 133272 | p = p->pRight; |
| 133059 | 133273 | } |
| | @@ -133072,14 +133286,17 @@ |
| 133072 | 133286 | ExprClearProperty(p, EP_FromJoin); |
| 133073 | 133287 | } |
| 133074 | 133288 | if( p->op==TK_COLUMN && p->iTable==iTable ){ |
| 133075 | 133289 | ExprClearProperty(p, EP_CanBeNull); |
| 133076 | 133290 | } |
| 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 | + } |
| 133081 | 133298 | } |
| 133082 | 133299 | } |
| 133083 | 133300 | unsetJoinExpr(p->pLeft, iTable); |
| 133084 | 133301 | p = p->pRight; |
| 133085 | 133302 | } |
| | @@ -133590,13 +133807,17 @@ |
| 133590 | 133807 | ExprList *pExtra = 0; |
| 133591 | 133808 | for(i=0; i<pEList->nExpr; i++){ |
| 133592 | 133809 | struct ExprList_item *pItem = &pEList->a[i]; |
| 133593 | 133810 | if( pItem->u.x.iOrderByCol==0 ){ |
| 133594 | 133811 | 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 |
| 133598 | 133819 | ){ |
| 133599 | 133820 | int j; |
| 133600 | 133821 | for(j=0; j<nDefer; j++){ |
| 133601 | 133822 | if( pSort->aDefer[j].iCsr==pExpr->iTable ) break; |
| 133602 | 133823 | } |
| | @@ -133613,10 +133834,11 @@ |
| 133613 | 133834 | } |
| 133614 | 133835 | for(k=0; k<nKey; k++){ |
| 133615 | 133836 | Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0); |
| 133616 | 133837 | if( pNew ){ |
| 133617 | 133838 | pNew->iTable = pExpr->iTable; |
| 133839 | + assert( ExprUseYTab(pNew) ); |
| 133618 | 133840 | pNew->y.pTab = pExpr->y.pTab; |
| 133619 | 133841 | pNew->iColumn = pPk ? pPk->aiColumn[k] : -1; |
| 133620 | 133842 | pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew); |
| 133621 | 133843 | } |
| 133622 | 133844 | } |
| | @@ -134461,11 +134683,11 @@ |
| 134461 | 134683 | ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT |
| 134462 | 134684 | ** branch below. */ |
| 134463 | 134685 | break; |
| 134464 | 134686 | } |
| 134465 | 134687 | |
| 134466 | | - assert( pTab && pExpr->y.pTab==pTab ); |
| 134688 | + assert( pTab && ExprUseYTab(pExpr) && pExpr->y.pTab==pTab ); |
| 134467 | 134689 | if( pS ){ |
| 134468 | 134690 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 134469 | 134691 | ** of the SELECT statement. Return the declaration type and origin |
| 134470 | 134692 | ** data for the result-set column of the sub-select. |
| 134471 | 134693 | */ |
| | @@ -134521,13 +134743,15 @@ |
| 134521 | 134743 | /* The expression is a sub-select. Return the declaration type and |
| 134522 | 134744 | ** origin info for the single column in the result set of the SELECT |
| 134523 | 134745 | ** statement. |
| 134524 | 134746 | */ |
| 134525 | 134747 | 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; |
| 134529 | 134753 | sNC.pSrcList = pS->pSrc; |
| 134530 | 134754 | sNC.pNext = pNC; |
| 134531 | 134755 | sNC.pParse = pNC->pParse; |
| 134532 | 134756 | zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol); |
| 134533 | 134757 | break; |
| | @@ -134652,11 +134876,12 @@ |
| 134652 | 134876 | for(i=0; i<pEList->nExpr; i++){ |
| 134653 | 134877 | Expr *p = pEList->a[i].pExpr; |
| 134654 | 134878 | |
| 134655 | 134879 | assert( p!=0 ); |
| 134656 | 134880 | 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 */ |
| 134658 | 134883 | if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){ |
| 134659 | 134884 | /* An AS clause always takes first priority */ |
| 134660 | 134885 | char *zName = pEList->a[i].zEName; |
| 134661 | 134886 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); |
| 134662 | 134887 | }else if( srcName && p->op==TK_COLUMN ){ |
| | @@ -134748,11 +134973,14 @@ |
| 134748 | 134973 | Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr); |
| 134749 | 134974 | while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){ |
| 134750 | 134975 | pColExpr = pColExpr->pRight; |
| 134751 | 134976 | assert( pColExpr!=0 ); |
| 134752 | 134977 | } |
| 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 | + ){ |
| 134754 | 134982 | /* For columns use the column name name */ |
| 134755 | 134983 | int iCol = pColExpr->iColumn; |
| 134756 | 134984 | if( iCol<0 ) iCol = pTab->iPKey; |
| 134757 | 134985 | zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid"; |
| 134758 | 134986 | }else if( pColExpr->op==TK_ID ){ |
| | @@ -136330,11 +136558,11 @@ |
| 136330 | 136558 | if( pExpr->op==TK_IF_NULL_ROW && pExpr->iTable==pSubst->iTable ){ |
| 136331 | 136559 | pExpr->iTable = pSubst->iNewTable; |
| 136332 | 136560 | } |
| 136333 | 136561 | pExpr->pLeft = substExpr(pSubst, pExpr->pLeft); |
| 136334 | 136562 | pExpr->pRight = substExpr(pSubst, pExpr->pRight); |
| 136335 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 136563 | + if( ExprUseXSelect(pExpr) ){ |
| 136336 | 136564 | substSelect(pSubst, pExpr->x.pSelect, 1); |
| 136337 | 136565 | }else{ |
| 136338 | 136566 | substExprList(pSubst, pExpr->x.pList); |
| 136339 | 136567 | } |
| 136340 | 136568 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| | @@ -137541,25 +137769,28 @@ |
| 137541 | 137769 | ** located but before their arguments have been subjected to aggregate |
| 137542 | 137770 | ** analysis. |
| 137543 | 137771 | */ |
| 137544 | 137772 | static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){ |
| 137545 | 137773 | int eRet = WHERE_ORDERBY_NORMAL; /* Return value */ |
| 137546 | | - ExprList *pEList = pFunc->x.pList; /* Arguments to agg function */ |
| 137774 | + ExprList *pEList; /* Arguments to agg function */ |
| 137547 | 137775 | const char *zFunc; /* Name of aggregate function pFunc */ |
| 137548 | 137776 | ExprList *pOrderBy; |
| 137549 | 137777 | u8 sortFlags = 0; |
| 137550 | 137778 | |
| 137551 | 137779 | assert( *ppMinMax==0 ); |
| 137552 | 137780 | assert( pFunc->op==TK_AGG_FUNCTION ); |
| 137553 | 137781 | assert( !IsWindowFunc(pFunc) ); |
| 137782 | + assert( ExprUseXList(pFunc) ); |
| 137783 | + pEList = pFunc->x.pList; |
| 137554 | 137784 | if( pEList==0 |
| 137555 | 137785 | || pEList->nExpr!=1 |
| 137556 | 137786 | || ExprHasProperty(pFunc, EP_WinFunc) |
| 137557 | 137787 | || OptimizationDisabled(db, SQLITE_MinMaxOpt) |
| 137558 | 137788 | ){ |
| 137559 | 137789 | return eRet; |
| 137560 | 137790 | } |
| 137791 | + assert( !ExprHasProperty(pFunc, EP_IntValue) ); |
| 137561 | 137792 | zFunc = pFunc->u.zToken; |
| 137562 | 137793 | if( sqlite3StrICmp(zFunc, "min")==0 ){ |
| 137563 | 137794 | eRet = WHERE_ORDERBY_MIN; |
| 137564 | 137795 | if( sqlite3ExprCanBeNull(pEList->a[0].pExpr) ){ |
| 137565 | 137796 | sortFlags = KEYINFO_ORDER_BIGNULL; |
| | @@ -137632,10 +137863,11 @@ |
| 137632 | 137863 | if( !pIdx ){ |
| 137633 | 137864 | sqlite3ErrorMsg(pParse, "no such index: %s", zIndexedBy, 0); |
| 137634 | 137865 | pParse->checkSchema = 1; |
| 137635 | 137866 | return SQLITE_ERROR; |
| 137636 | 137867 | } |
| 137868 | + assert( pFrom->fg.isCte==0 ); |
| 137637 | 137869 | pFrom->u2.pIBIndex = pIdx; |
| 137638 | 137870 | return SQLITE_OK; |
| 137639 | 137871 | } |
| 137640 | 137872 | |
| 137641 | 137873 | /* |
| | @@ -137889,10 +138121,14 @@ |
| 137889 | 138121 | pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid; |
| 137890 | 138122 | pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0); |
| 137891 | 138123 | if( db->mallocFailed ) return 2; |
| 137892 | 138124 | pFrom->pSelect->selFlags |= SF_CopyCte; |
| 137893 | 138125 | assert( pFrom->pSelect ); |
| 138126 | + if( pFrom->fg.isIndexedBy ){ |
| 138127 | + sqlite3ErrorMsg(pParse, "no such index: \"%s\"", pFrom->u1.zIndexedBy); |
| 138128 | + return 2; |
| 138129 | + } |
| 137894 | 138130 | pFrom->fg.isCte = 1; |
| 137895 | 138131 | pFrom->u2.pCteUse = pCteUse; |
| 137896 | 138132 | pCteUse->nUse++; |
| 137897 | 138133 | if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){ |
| 137898 | 138134 | pCteUse->eM10d = M10d_Yes; |
| | @@ -138524,11 +138760,11 @@ |
| 138524 | 138760 | #endif |
| 138525 | 138761 | sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg); |
| 138526 | 138762 | for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){ |
| 138527 | 138763 | if( pFunc->iDistinct>=0 ){ |
| 138528 | 138764 | Expr *pE = pFunc->pFExpr; |
| 138529 | | - assert( !ExprHasProperty(pE, EP_xIsSelect) ); |
| 138765 | + assert( ExprUseXList(pE) ); |
| 138530 | 138766 | if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){ |
| 138531 | 138767 | sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " |
| 138532 | 138768 | "argument"); |
| 138533 | 138769 | pFunc->iDistinct = -1; |
| 138534 | 138770 | }else{ |
| | @@ -138549,12 +138785,13 @@ |
| 138549 | 138785 | static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){ |
| 138550 | 138786 | Vdbe *v = pParse->pVdbe; |
| 138551 | 138787 | int i; |
| 138552 | 138788 | struct AggInfo_func *pF; |
| 138553 | 138789 | 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; |
| 138556 | 138793 | sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0); |
| 138557 | 138794 | sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF); |
| 138558 | 138795 | } |
| 138559 | 138796 | } |
| 138560 | 138797 | |
| | @@ -138584,13 +138821,14 @@ |
| 138584 | 138821 | pAggInfo->directMode = 1; |
| 138585 | 138822 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 138586 | 138823 | int nArg; |
| 138587 | 138824 | int addrNext = 0; |
| 138588 | 138825 | int regAgg; |
| 138589 | | - ExprList *pList = pF->pFExpr->x.pList; |
| 138590 | | - assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) ); |
| 138826 | + ExprList *pList; |
| 138827 | + assert( ExprUseXList(pF->pFExpr) ); |
| 138591 | 138828 | assert( !IsWindowFunc(pF->pFExpr) ); |
| 138829 | + pList = pF->pFExpr->x.pList; |
| 138592 | 138830 | if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){ |
| 138593 | 138831 | Expr *pFilter = pF->pFExpr->y.pWin->pFilter; |
| 138594 | 138832 | if( pAggInfo->nAccumulator |
| 138595 | 138833 | && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) |
| 138596 | 138834 | && regAcc |
| | @@ -138832,11 +139070,13 @@ |
| 138832 | 139070 | if( p->pEList->nExpr!=1 ) return 0; /* Single result column */ |
| 138833 | 139071 | if( p->pWhere ) return 0; |
| 138834 | 139072 | if( p->pGroupBy ) return 0; |
| 138835 | 139073 | pExpr = p->pEList->a[0].pExpr; |
| 138836 | 139074 | if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */ |
| 139075 | + assert( ExprUseUToken(pExpr) ); |
| 138837 | 139076 | if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */ |
| 139077 | + assert( ExprUseXList(pExpr) ); |
| 138838 | 139078 | if( pExpr->x.pList!=0 ) return 0; /* Must be count(*) */ |
| 138839 | 139079 | if( p->pSrc->nSrc!=1 ) return 0; /* One table in FROM */ |
| 138840 | 139080 | pSub = p->pSrc->a[0].pSelect; |
| 138841 | 139081 | if( pSub==0 ) return 0; /* The FROM is a subquery */ |
| 138842 | 139082 | if( pSub->pPrior==0 ) return 0; /* Must be a compound ry */ |
| | @@ -139647,11 +139887,11 @@ |
| 139647 | 139887 | }else{ |
| 139648 | 139888 | minMaxFlag = WHERE_ORDERBY_NORMAL; |
| 139649 | 139889 | } |
| 139650 | 139890 | for(i=0; i<pAggInfo->nFunc; i++){ |
| 139651 | 139891 | Expr *pExpr = pAggInfo->aFunc[i].pFExpr; |
| 139652 | | - assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 139892 | + assert( ExprUseXList(pExpr) ); |
| 139653 | 139893 | sNC.ncFlags |= NC_InAggFunc; |
| 139654 | 139894 | sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList); |
| 139655 | 139895 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 139656 | 139896 | assert( !IsWindowFunc(pExpr) ); |
| 139657 | 139897 | if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| | @@ -139702,11 +139942,13 @@ |
| 139702 | 139942 | u16 distFlag = 0; |
| 139703 | 139943 | int eDist = WHERE_DISTINCT_NOOP; |
| 139704 | 139944 | |
| 139705 | 139945 | if( pAggInfo->nFunc==1 |
| 139706 | 139946 | && 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 |
| 139708 | 139950 | ){ |
| 139709 | 139951 | Expr *pExpr = pAggInfo->aFunc[0].pFExpr->x.pList->a[0].pExpr; |
| 139710 | 139952 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 139711 | 139953 | pDistinct = sqlite3ExprListDup(db, pGroupBy, 0); |
| 139712 | 139954 | pDistinct = sqlite3ExprListAppend(pParse, pDistinct, pExpr); |
| | @@ -140023,10 +140265,11 @@ |
| 140023 | 140265 | if( i==pAggInfo->nFunc ){ |
| 140024 | 140266 | regAcc = ++pParse->nMem; |
| 140025 | 140267 | sqlite3VdbeAddOp2(v, OP_Integer, 0, regAcc); |
| 140026 | 140268 | } |
| 140027 | 140269 | }else if( pAggInfo->nFunc==1 && pAggInfo->aFunc[0].iDistinct>=0 ){ |
| 140270 | + assert( ExprUseXList(pAggInfo->aFunc[0].pFExpr) ); |
| 140028 | 140271 | pDistinct = pAggInfo->aFunc[0].pFExpr->x.pList; |
| 140029 | 140272 | distFlag = pDistinct ? (WHERE_WANT_DISTINCT|WHERE_AGG_DISTINCT) : 0; |
| 140030 | 140273 | } |
| 140031 | 140274 | |
| 140032 | 140275 | /* This case runs if the aggregate has no GROUP BY clause. The |
| | @@ -144048,11 +144291,14 @@ |
| 144048 | 144291 | ** Except, if argument db is not NULL, then the entry associated with |
| 144049 | 144292 | ** connection db is left in the p->u.vtab.p list. |
| 144050 | 144293 | */ |
| 144051 | 144294 | static VTable *vtabDisconnectAll(sqlite3 *db, Table *p){ |
| 144052 | 144295 | VTable *pRet = 0; |
| 144053 | | - VTable *pVTable = p->u.vtab.p; |
| 144296 | + VTable *pVTable; |
| 144297 | + |
| 144298 | + assert( IsVirtual(p) ); |
| 144299 | + pVTable = p->u.vtab.p; |
| 144054 | 144300 | p->u.vtab.p = 0; |
| 144055 | 144301 | |
| 144056 | 144302 | /* Assert that the mutex (if any) associated with the BtShared database |
| 144057 | 144303 | ** that contains table p is held by the caller. See header comments |
| 144058 | 144304 | ** above function sqlite3VtabUnlockList() for an explanation of why |
| | @@ -144156,10 +144402,11 @@ |
| 144156 | 144402 | ** structure being xDisconnected and free). Any other VTable structures |
| 144157 | 144403 | ** in the list are moved to the sqlite3.pDisconnect list of the associated |
| 144158 | 144404 | ** database connection. |
| 144159 | 144405 | */ |
| 144160 | 144406 | SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){ |
| 144407 | + assert( IsVirtual(p) ); |
| 144161 | 144408 | if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p); |
| 144162 | 144409 | if( p->u.vtab.azArg ){ |
| 144163 | 144410 | int i; |
| 144164 | 144411 | for(i=0; i<p->u.vtab.nArg; i++){ |
| 144165 | 144412 | if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]); |
| | @@ -144173,13 +144420,16 @@ |
| 144173 | 144420 | ** The string is not copied - the pointer is stored. The |
| 144174 | 144421 | ** string will be freed automatically when the table is |
| 144175 | 144422 | ** deleted. |
| 144176 | 144423 | */ |
| 144177 | 144424 | static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){ |
| 144178 | | - sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); |
| 144425 | + sqlite3_int64 nBytes; |
| 144179 | 144426 | char **azModuleArg; |
| 144180 | 144427 | sqlite3 *db = pParse->db; |
| 144428 | + |
| 144429 | + assert( IsVirtual(pTable) ); |
| 144430 | + nBytes = sizeof(char *)*(2+pTable->u.vtab.nArg); |
| 144181 | 144431 | if( pTable->u.vtab.nArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 144182 | 144432 | sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName); |
| 144183 | 144433 | } |
| 144184 | 144434 | azModuleArg = sqlite3DbRealloc(db, pTable->u.vtab.azArg, nBytes); |
| 144185 | 144435 | if( azModuleArg==0 ){ |
| | @@ -144262,10 +144512,11 @@ |
| 144262 | 144512 | SQLITE_PRIVATE void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){ |
| 144263 | 144513 | Table *pTab = pParse->pNewTable; /* The table being constructed */ |
| 144264 | 144514 | sqlite3 *db = pParse->db; /* The database connection */ |
| 144265 | 144515 | |
| 144266 | 144516 | if( pTab==0 ) return; |
| 144517 | + assert( IsVirtual(pTab) ); |
| 144267 | 144518 | addArgumentToVtab(pParse); |
| 144268 | 144519 | pParse->sArg.z = 0; |
| 144269 | 144520 | if( pTab->u.vtab.nArg<1 ) return; |
| 144270 | 144521 | |
| 144271 | 144522 | /* If the CREATE VIRTUAL TABLE statement is being entered for the |
| | @@ -144379,17 +144630,20 @@ |
| 144379 | 144630 | char **pzErr |
| 144380 | 144631 | ){ |
| 144381 | 144632 | VtabCtx sCtx; |
| 144382 | 144633 | VTable *pVTable; |
| 144383 | 144634 | int rc; |
| 144384 | | - const char *const*azArg = (const char *const*)pTab->u.vtab.azArg; |
| 144635 | + const char *const*azArg; |
| 144385 | 144636 | int nArg = pTab->u.vtab.nArg; |
| 144386 | 144637 | char *zErr = 0; |
| 144387 | 144638 | char *zModuleName; |
| 144388 | 144639 | int iDb; |
| 144389 | 144640 | VtabCtx *pCtx; |
| 144390 | 144641 | |
| 144642 | + assert( IsVirtual(pTab) ); |
| 144643 | + azArg = (const char *const*)pTab->u.vtab.azArg; |
| 144644 | + |
| 144391 | 144645 | /* Check that the virtual-table is not already being initialized */ |
| 144392 | 144646 | for(pCtx=db->pVtabCtx; pCtx; pCtx=pCtx->pPrior){ |
| 144393 | 144647 | if( pCtx->pTab==pTab ){ |
| 144394 | 144648 | *pzErr = sqlite3MPrintf(db, |
| 144395 | 144649 | "vtable constructor called recursively: %s", pTab->zName |
| | @@ -144713,11 +144967,11 @@ |
| 144713 | 144967 | SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ |
| 144714 | 144968 | int rc = SQLITE_OK; |
| 144715 | 144969 | Table *pTab; |
| 144716 | 144970 | |
| 144717 | 144971 | 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) ){ |
| 144719 | 144973 | VTable *p; |
| 144720 | 144974 | int (*xDestroy)(sqlite3_vtab *); |
| 144721 | 144975 | for(p=pTab->u.vtab.p; p; p=p->pNext){ |
| 144722 | 144976 | assert( p->pVtab ); |
| 144723 | 144977 | if( p->pVtab->nRef>0 ){ |
| | @@ -144946,10 +145200,11 @@ |
| 144946 | 145200 | int rc = 0; |
| 144947 | 145201 | |
| 144948 | 145202 | /* Check to see the left operand is a column in a virtual table */ |
| 144949 | 145203 | if( NEVER(pExpr==0) ) return pDef; |
| 144950 | 145204 | if( pExpr->op!=TK_COLUMN ) return pDef; |
| 145205 | + assert( ExprUseYTab(pExpr) ); |
| 144951 | 145206 | pTab = pExpr->y.pTab; |
| 144952 | 145207 | if( pTab==0 ) return pDef; |
| 144953 | 145208 | if( !IsVirtual(pTab) ) return pDef; |
| 144954 | 145209 | pVtab = sqlite3GetVTable(db, pTab)->pVtab; |
| 144955 | 145210 | assert( pVtab!=0 ); |
| | @@ -145254,11 +145509,11 @@ |
| 145254 | 145509 | int iBase; /* Base register of multi-key index record */ |
| 145255 | 145510 | int nPrefix; /* Number of prior entires in the key */ |
| 145256 | 145511 | u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */ |
| 145257 | 145512 | } *aInLoop; /* Information about each nested IN operator */ |
| 145258 | 145513 | } 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 */ |
| 145260 | 145515 | } u; |
| 145261 | 145516 | struct WhereLoop *pWLoop; /* The selected WhereLoop object */ |
| 145262 | 145517 | Bitmask notReady; /* FROM entries not usable at this level */ |
| 145263 | 145518 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 145264 | 145519 | int addrVisit; /* Address at which row is visited */ |
| | @@ -146182,20 +146437,27 @@ |
| 146182 | 146437 | ){ |
| 146183 | 146438 | sqlite3 *db = pParse->db; |
| 146184 | 146439 | Expr *pNew; |
| 146185 | 146440 | pNew = sqlite3ExprDup(db, pX, 0); |
| 146186 | 146441 | 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 */ |
| 146189 | 146444 | ExprList *pRhs = 0; /* New RHS after modifications */ |
| 146190 | 146445 | ExprList *pLhs = 0; /* New LHS after mods */ |
| 146191 | 146446 | int i; /* Loop counter */ |
| 146192 | 146447 | Select *pSelect; /* Pointer to the SELECT on the RHS */ |
| 146193 | 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; |
| 146194 | 146454 | for(i=iEq; i<pLoop->nLTerm; i++){ |
| 146195 | 146455 | 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; |
| 146197 | 146459 | if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */ |
| 146198 | 146460 | pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr); |
| 146199 | 146461 | pOrigRhs->a[iField].pExpr = 0; |
| 146200 | 146462 | assert( pOrigLhs->a[iField].pExpr!=0 ); |
| 146201 | 146463 | pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr); |
| | @@ -146306,11 +146568,11 @@ |
| 146306 | 146568 | assert( pLoop->aLTerm[i]!=0 ); |
| 146307 | 146569 | if( pLoop->aLTerm[i]->pExpr==pX ) nEq++; |
| 146308 | 146570 | } |
| 146309 | 146571 | |
| 146310 | 146572 | 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 ){ |
| 146312 | 146574 | eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab); |
| 146313 | 146575 | }else{ |
| 146314 | 146576 | sqlite3 *db = pParse->db; |
| 146315 | 146577 | pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX); |
| 146316 | 146578 | |
| | @@ -146328,12 +146590,12 @@ |
| 146328 | 146590 | bRev = !bRev; |
| 146329 | 146591 | } |
| 146330 | 146592 | sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0); |
| 146331 | 146593 | VdbeCoverageIf(v, bRev); |
| 146332 | 146594 | VdbeCoverageIf(v, !bRev); |
| 146595 | + |
| 146333 | 146596 | assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 ); |
| 146334 | | - |
| 146335 | 146597 | pLoop->wsFlags |= WHERE_IN_ABLE; |
| 146336 | 146598 | if( pLevel->u.in.nIn==0 ){ |
| 146337 | 146599 | pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse); |
| 146338 | 146600 | } |
| 146339 | 146601 | if( iEq>0 && (pLoop->wsFlags & WHERE_IN_SEEKSCAN)==0 ){ |
| | @@ -146871,21 +147133,23 @@ |
| 146871 | 147133 | */ |
| 146872 | 147134 | static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){ |
| 146873 | 147135 | assert( nReg>0 ); |
| 146874 | 147136 | if( p && sqlite3ExprIsVector(p) ){ |
| 146875 | 147137 | #ifndef SQLITE_OMIT_SUBQUERY |
| 146876 | | - if( (p->flags & EP_xIsSelect) ){ |
| 147138 | + if( ExprUseXSelect(p) ){ |
| 146877 | 147139 | Vdbe *v = pParse->pVdbe; |
| 146878 | 147140 | int iSelect; |
| 146879 | 147141 | assert( p->op==TK_SELECT ); |
| 146880 | 147142 | iSelect = sqlite3CodeSubselect(pParse, p); |
| 146881 | 147143 | sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1); |
| 146882 | 147144 | }else |
| 146883 | 147145 | #endif |
| 146884 | 147146 | { |
| 146885 | 147147 | int i; |
| 146886 | | - ExprList *pList = p->x.pList; |
| 147148 | + const ExprList *pList; |
| 147149 | + assert( ExprUseXList(p) ); |
| 147150 | + pList = p->x.pList; |
| 146887 | 147151 | assert( nReg<=pList->nExpr ); |
| 146888 | 147152 | for(i=0; i<nReg; i++){ |
| 146889 | 147153 | sqlite3ExprCode(pParse, pList->a[i].pExpr, iReg+i); |
| 146890 | 147154 | } |
| 146891 | 147155 | } |
| | @@ -146934,14 +147198,14 @@ |
| 146934 | 147198 | preserveExpr(pX, pExpr); |
| 146935 | 147199 | pExpr->affExpr = sqlite3ExprAffinity(pExpr); |
| 146936 | 147200 | pExpr->op = TK_COLUMN; |
| 146937 | 147201 | pExpr->iTable = pX->iIdxCur; |
| 146938 | 147202 | pExpr->iColumn = pX->iIdxCol; |
| 146939 | | - pExpr->y.pTab = 0; |
| 146940 | 147203 | testcase( ExprHasProperty(pExpr, EP_Skip) ); |
| 146941 | 147204 | 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; |
| 146943 | 147207 | return WRC_Prune; |
| 146944 | 147208 | }else{ |
| 146945 | 147209 | return WRC_Continue; |
| 146946 | 147210 | } |
| 146947 | 147211 | } |
| | @@ -146952,11 +147216,11 @@ |
| 146952 | 147216 | */ |
| 146953 | 147217 | static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){ |
| 146954 | 147218 | if( pExpr->op==TK_COLUMN ){ |
| 146955 | 147219 | IdxExprTrans *pX = p->u.pIdxTrans; |
| 146956 | 147220 | if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){ |
| 146957 | | - assert( pExpr->y.pTab!=0 ); |
| 147221 | + assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 ); |
| 146958 | 147222 | preserveExpr(pX, pExpr); |
| 146959 | 147223 | pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn); |
| 146960 | 147224 | pExpr->iTable = pX->iIdxCur; |
| 146961 | 147225 | pExpr->iColumn = pX->iIdxCol; |
| 146962 | 147226 | pExpr->y.pTab = 0; |
| | @@ -147189,11 +147453,16 @@ |
| 147189 | 147453 | ** the u.vtab.idxStr. NULL it out to prevent a use-after-free */ |
| 147190 | 147454 | if( db->mallocFailed ) pLoop->u.vtab.idxStr = 0; |
| 147191 | 147455 | pLevel->p1 = iCur; |
| 147192 | 147456 | pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext; |
| 147193 | 147457 | 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 | + } |
| 147195 | 147464 | for(j=nConstraint-1; j>=0; j--){ |
| 147196 | 147465 | pTerm = pLoop->aLTerm[j]; |
| 147197 | 147466 | if( (pTerm->eOperator & WO_IN)!=0 ) iIn--; |
| 147198 | 147467 | if( j<16 && (pLoop->u.vtab.omitMask>>j)&1 ){ |
| 147199 | 147468 | disableTerm(pLevel, pTerm); |
| | @@ -148078,11 +148347,14 @@ |
| 148078 | 148347 | } |
| 148079 | 148348 | sqlite3ExprDelete(db, pDelete); |
| 148080 | 148349 | } |
| 148081 | 148350 | } |
| 148082 | 148351 | 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; |
| 148084 | 148356 | if( pCov ) pLevel->iIdxCur = iCovCur; |
| 148085 | 148357 | if( pAndExpr ){ |
| 148086 | 148358 | pAndExpr->pLeft = 0; |
| 148087 | 148359 | sqlite3ExprDelete(db, pAndExpr); |
| 148088 | 148360 | } |
| | @@ -148222,16 +148494,17 @@ |
| 148222 | 148494 | sqlite3WhereTermPrint(pTerm, pWC->nTerm-j); |
| 148223 | 148495 | } |
| 148224 | 148496 | #endif |
| 148225 | 148497 | assert( !ExprHasProperty(pE, EP_FromJoin) ); |
| 148226 | 148498 | assert( (pTerm->prereqRight & pLevel->notReady)!=0 ); |
| 148499 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 148227 | 148500 | pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady, |
| 148228 | 148501 | WO_EQ|WO_IN|WO_IS, 0); |
| 148229 | 148502 | if( pAlt==0 ) continue; |
| 148230 | 148503 | if( pAlt->wtFlags & (TERM_CODED) ) continue; |
| 148231 | 148504 | if( (pAlt->eOperator & WO_IN) |
| 148232 | | - && (pAlt->pExpr->flags & EP_xIsSelect) |
| 148505 | + && ExprUseXSelect(pAlt->pExpr) |
| 148233 | 148506 | && (pAlt->pExpr->x.pSelect->pEList->nExpr>1) |
| 148234 | 148507 | ){ |
| 148235 | 148508 | continue; |
| 148236 | 148509 | } |
| 148237 | 148510 | testcase( pAlt->eOperator & WO_EQ ); |
| | @@ -148476,10 +148749,11 @@ |
| 148476 | 148749 | return 0; |
| 148477 | 148750 | } |
| 148478 | 148751 | #ifdef SQLITE_EBCDIC |
| 148479 | 148752 | if( *pnoCase ) return 0; |
| 148480 | 148753 | #endif |
| 148754 | + assert( ExprUseXList(pExpr) ); |
| 148481 | 148755 | pList = pExpr->x.pList; |
| 148482 | 148756 | pLeft = pList->a[1].pExpr; |
| 148483 | 148757 | |
| 148484 | 148758 | pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr); |
| 148485 | 148759 | op = pRight->op; |
| | @@ -148491,11 +148765,12 @@ |
| 148491 | 148765 | z = sqlite3_value_text(pVal); |
| 148492 | 148766 | } |
| 148493 | 148767 | sqlite3VdbeSetVarmask(pParse->pVdbe, iCol); |
| 148494 | 148768 | assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER ); |
| 148495 | 148769 | }else if( op==TK_STRING ){ |
| 148496 | | - z = (u8*)pRight->u.zToken; |
| 148770 | + assert( !ExprHasProperty(pRight, EP_IntValue) ); |
| 148771 | + z = (u8*)pRight->u.zToken; |
| 148497 | 148772 | } |
| 148498 | 148773 | if( z ){ |
| 148499 | 148774 | |
| 148500 | 148775 | /* Count the number of prefix characters prior to the first wildcard */ |
| 148501 | 148776 | cnt = 0; |
| | @@ -148520,11 +148795,13 @@ |
| 148520 | 148795 | |
| 148521 | 148796 | /* Get the pattern prefix. Remove all escapes from the prefix. */ |
| 148522 | 148797 | pPrefix = sqlite3Expr(db, TK_STRING, (char*)z); |
| 148523 | 148798 | if( pPrefix ){ |
| 148524 | 148799 | int iFrom, iTo; |
| 148525 | | - char *zNew = pPrefix->u.zToken; |
| 148800 | + char *zNew; |
| 148801 | + assert( !ExprHasProperty(pPrefix, EP_IntValue) ); |
| 148802 | + zNew = pPrefix->u.zToken; |
| 148526 | 148803 | zNew[cnt] = 0; |
| 148527 | 148804 | for(iFrom=iTo=0; iFrom<cnt; iFrom++){ |
| 148528 | 148805 | if( zNew[iFrom]==wc[3] ) iFrom++; |
| 148529 | 148806 | zNew[iTo++] = zNew[iFrom]; |
| 148530 | 148807 | } |
| | @@ -148544,11 +148821,13 @@ |
| 148544 | 148821 | ** 2019-06-14 https://sqlite.org/src/info/ce8717f0885af975 |
| 148545 | 148822 | ** 2019-09-03 https://sqlite.org/src/info/0f0428096f17252a |
| 148546 | 148823 | */ |
| 148547 | 148824 | if( pLeft->op!=TK_COLUMN |
| 148548 | 148825 | || 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 */ |
| 148550 | 148829 | ){ |
| 148551 | 148830 | int isNum; |
| 148552 | 148831 | double rDummy; |
| 148553 | 148832 | isNum = sqlite3AtoF(zNew, &rDummy, iTo, SQLITE_UTF8); |
| 148554 | 148833 | if( isNum<=0 ){ |
| | @@ -148572,10 +148851,11 @@ |
| 148572 | 148851 | /* If the RHS pattern is a bound parameter, make arrangements to |
| 148573 | 148852 | ** reprepare the statement when that parameter is rebound */ |
| 148574 | 148853 | if( op==TK_VARIABLE ){ |
| 148575 | 148854 | Vdbe *v = pParse->pVdbe; |
| 148576 | 148855 | sqlite3VdbeSetVarmask(v, pRight->iColumn); |
| 148856 | + assert( !ExprHasProperty(pRight, EP_IntValue) ); |
| 148577 | 148857 | if( *pisComplete && pRight->u.zToken[1] ){ |
| 148578 | 148858 | /* If the rhs of the LIKE expression is a variable, and the current |
| 148579 | 148859 | ** value of the variable means there is no need to invoke the LIKE |
| 148580 | 148860 | ** function, then no OP_Variable will be added to the program. |
| 148581 | 148861 | ** This causes problems for the sqlite3_bind_parameter_name() |
| | @@ -148645,10 +148925,11 @@ |
| 148645 | 148925 | }; |
| 148646 | 148926 | ExprList *pList; |
| 148647 | 148927 | Expr *pCol; /* Column reference */ |
| 148648 | 148928 | int i; |
| 148649 | 148929 | |
| 148930 | + assert( ExprUseXList(pExpr) ); |
| 148650 | 148931 | pList = pExpr->x.pList; |
| 148651 | 148932 | if( pList==0 || pList->nExpr!=2 ){ |
| 148652 | 148933 | return 0; |
| 148653 | 148934 | } |
| 148654 | 148935 | |
| | @@ -148658,13 +148939,15 @@ |
| 148658 | 148939 | ** |
| 148659 | 148940 | ** vtab_column MATCH expression |
| 148660 | 148941 | ** MATCH(expression,vtab_column) |
| 148661 | 148942 | */ |
| 148662 | 148943 | pCol = pList->a[1].pExpr; |
| 148944 | + assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); |
| 148663 | 148945 | testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 148664 | 148946 | if( ExprIsVtab(pCol) ){ |
| 148665 | 148947 | for(i=0; i<ArraySize(aOp); i++){ |
| 148948 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 148666 | 148949 | if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 148667 | 148950 | *peOp2 = aOp[i].eOp2; |
| 148668 | 148951 | *ppRight = pList->a[0].pExpr; |
| 148669 | 148952 | *ppLeft = pCol; |
| 148670 | 148953 | return 1; |
| | @@ -148681,20 +148964,22 @@ |
| 148681 | 148964 | ** Historically, xFindFunction expected to see lower-case function |
| 148682 | 148965 | ** names. But for this use case, xFindFunction is expected to deal |
| 148683 | 148966 | ** with function names in an arbitrary case. |
| 148684 | 148967 | */ |
| 148685 | 148968 | pCol = pList->a[0].pExpr; |
| 148969 | + assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) ); |
| 148686 | 148970 | testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 ); |
| 148687 | 148971 | if( ExprIsVtab(pCol) ){ |
| 148688 | 148972 | sqlite3_vtab *pVtab; |
| 148689 | 148973 | sqlite3_module *pMod; |
| 148690 | 148974 | void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); |
| 148691 | 148975 | void *pNotUsed; |
| 148692 | 148976 | pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| 148693 | 148977 | assert( pVtab!=0 ); |
| 148694 | 148978 | assert( pVtab->pModule!=0 ); |
| 148695 | | - pMod = (sqlite3_module *)pVtab->pModule; |
| 148979 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 148980 | + pMod = (sqlite3_module *)pVtab->pModule; |
| 148696 | 148981 | if( pMod->xFindFunction!=0 ){ |
| 148697 | 148982 | i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed); |
| 148698 | 148983 | if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){ |
| 148699 | 148984 | *peOp2 = i; |
| 148700 | 148985 | *ppRight = pList->a[1].pExpr; |
| | @@ -148705,14 +148990,16 @@ |
| 148705 | 148990 | } |
| 148706 | 148991 | }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 148707 | 148992 | int res = 0; |
| 148708 | 148993 | Expr *pLeft = pExpr->pLeft; |
| 148709 | 148994 | Expr *pRight = pExpr->pRight; |
| 148995 | + assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) ); |
| 148710 | 148996 | testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 ); |
| 148711 | 148997 | if( ExprIsVtab(pLeft) ){ |
| 148712 | 148998 | res++; |
| 148713 | 148999 | } |
| 149000 | + assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) ); |
| 148714 | 149001 | testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 ); |
| 148715 | 149002 | if( pRight && ExprIsVtab(pRight) ){ |
| 148716 | 149003 | res++; |
| 148717 | 149004 | SWAP(Expr*, pLeft, pRight); |
| 148718 | 149005 | } |
| | @@ -148961,10 +149248,11 @@ |
| 148961 | 149248 | int j; |
| 148962 | 149249 | Bitmask b = 0; |
| 148963 | 149250 | pOrTerm->u.pAndInfo = pAndInfo; |
| 148964 | 149251 | pOrTerm->wtFlags |= TERM_ANDINFO; |
| 148965 | 149252 | pOrTerm->eOperator = WO_AND; |
| 149253 | + pOrTerm->leftCursor = -1; |
| 148966 | 149254 | pAndWC = &pAndInfo->wc; |
| 148967 | 149255 | memset(pAndWC->aStatic, 0, sizeof(pAndWC->aStatic)); |
| 148968 | 149256 | sqlite3WhereClauseInit(pAndWC, pWC->pWInfo); |
| 148969 | 149257 | sqlite3WhereSplit(pAndWC, pOrTerm->pExpr, TK_AND); |
| 148970 | 149258 | sqlite3WhereExprAnalyze(pSrc, pAndWC); |
| | @@ -149003,15 +149291,14 @@ |
| 149003 | 149291 | /* |
| 149004 | 149292 | ** Record the set of tables that satisfy case 3. The set might be |
| 149005 | 149293 | ** empty. |
| 149006 | 149294 | */ |
| 149007 | 149295 | pOrInfo->indexable = indexable; |
| 149296 | + pTerm->eOperator = WO_OR; |
| 149297 | + pTerm->leftCursor = -1; |
| 149008 | 149298 | if( indexable ){ |
| 149009 | | - pTerm->eOperator = WO_OR; |
| 149010 | 149299 | pWC->hasOr = 1; |
| 149011 | | - }else{ |
| 149012 | | - pTerm->eOperator = WO_OR; |
| 149013 | 149300 | } |
| 149014 | 149301 | |
| 149015 | 149302 | /* For a two-way OR, attempt to implementation case 2. |
| 149016 | 149303 | */ |
| 149017 | 149304 | if( indexable && pOrWc->nTerm==2 ){ |
| | @@ -149080,10 +149367,11 @@ |
| 149080 | 149367 | testcase( pOrTerm->wtFlags & TERM_COPIED ); |
| 149081 | 149368 | testcase( pOrTerm->wtFlags & TERM_VIRTUAL ); |
| 149082 | 149369 | assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) ); |
| 149083 | 149370 | continue; |
| 149084 | 149371 | } |
| 149372 | + assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149085 | 149373 | iColumn = pOrTerm->u.x.leftColumn; |
| 149086 | 149374 | iCursor = pOrTerm->leftCursor; |
| 149087 | 149375 | pLeft = pOrTerm->pExpr->pLeft; |
| 149088 | 149376 | break; |
| 149089 | 149377 | } |
| | @@ -149100,10 +149388,11 @@ |
| 149100 | 149388 | /* We have found a candidate table and column. Check to see if that |
| 149101 | 149389 | ** table and column is common to every term in the OR clause */ |
| 149102 | 149390 | okToChngToIN = 1; |
| 149103 | 149391 | for(; i>=0 && okToChngToIN; i--, pOrTerm++){ |
| 149104 | 149392 | assert( pOrTerm->eOperator & WO_EQ ); |
| 149393 | + assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149105 | 149394 | if( pOrTerm->leftCursor!=iCursor ){ |
| 149106 | 149395 | pOrTerm->wtFlags &= ~TERM_OR_OK; |
| 149107 | 149396 | }else if( pOrTerm->u.x.leftColumn!=iColumn || (iColumn==XN_EXPR |
| 149108 | 149397 | && sqlite3ExprCompare(pParse, pOrTerm->pExpr->pLeft, pLeft, -1) |
| 149109 | 149398 | )){ |
| | @@ -149136,10 +149425,11 @@ |
| 149136 | 149425 | Expr *pNew; /* The complete IN operator */ |
| 149137 | 149426 | |
| 149138 | 149427 | for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){ |
| 149139 | 149428 | if( (pOrTerm->wtFlags & TERM_OR_OK)==0 ) continue; |
| 149140 | 149429 | assert( pOrTerm->eOperator & WO_EQ ); |
| 149430 | + assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149141 | 149431 | assert( pOrTerm->leftCursor==iCursor ); |
| 149142 | 149432 | assert( pOrTerm->u.x.leftColumn==iColumn ); |
| 149143 | 149433 | pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0); |
| 149144 | 149434 | pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup); |
| 149145 | 149435 | pLeft = pOrTerm->pExpr->pLeft; |
| | @@ -149148,11 +149438,11 @@ |
| 149148 | 149438 | pDup = sqlite3ExprDup(db, pLeft, 0); |
| 149149 | 149439 | pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0); |
| 149150 | 149440 | if( pNew ){ |
| 149151 | 149441 | int idxNew; |
| 149152 | 149442 | transferJoinMarkings(pNew, pExpr); |
| 149153 | | - assert( !ExprHasProperty(pNew, EP_xIsSelect) ); |
| 149443 | + assert( ExprUseXList(pNew) ); |
| 149154 | 149444 | pNew->x.pList = pList; |
| 149155 | 149445 | idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC); |
| 149156 | 149446 | testcase( idxNew==0 ); |
| 149157 | 149447 | exprAnalyze(pSrc, pWC, idxNew); |
| 149158 | 149448 | /* pTerm = &pWC->a[idxTerm]; // would be needed if pTerm where reused */ |
| | @@ -149276,10 +149566,11 @@ |
| 149276 | 149566 | ** on the first element of the vector. */ |
| 149277 | 149567 | assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE ); |
| 149278 | 149568 | assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE ); |
| 149279 | 149569 | assert( op<=TK_GE ); |
| 149280 | 149570 | if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){ |
| 149571 | + assert( ExprUseXList(pExpr) ); |
| 149281 | 149572 | pExpr = pExpr->x.pList->a[0].pExpr; |
| 149282 | 149573 | |
| 149283 | 149574 | } |
| 149284 | 149575 | |
| 149285 | 149576 | if( pExpr->op==TK_COLUMN ){ |
| | @@ -149342,11 +149633,11 @@ |
| 149342 | 149633 | prereqLeft = sqlite3WhereExprUsage(pMaskSet, pExpr->pLeft); |
| 149343 | 149634 | op = pExpr->op; |
| 149344 | 149635 | if( op==TK_IN ){ |
| 149345 | 149636 | assert( pExpr->pRight==0 ); |
| 149346 | 149637 | if( sqlite3ExprCheckIN(pParse, pExpr) ) return; |
| 149347 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 149638 | + if( ExprUseXSelect(pExpr) ){ |
| 149348 | 149639 | pTerm->prereqRight = exprSelectUsage(pMaskSet, pExpr->x.pSelect); |
| 149349 | 149640 | }else{ |
| 149350 | 149641 | pTerm->prereqRight = sqlite3WhereExprListUsage(pMaskSet, pExpr->x.pList); |
| 149351 | 149642 | } |
| 149352 | 149643 | }else if( op==TK_ISNULL ){ |
| | @@ -149378,15 +149669,17 @@ |
| 149378 | 149669 | u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV; |
| 149379 | 149670 | |
| 149380 | 149671 | if( pTerm->u.x.iField>0 ){ |
| 149381 | 149672 | assert( op==TK_IN ); |
| 149382 | 149673 | assert( pLeft->op==TK_VECTOR ); |
| 149674 | + assert( ExprUseXList(pLeft) ); |
| 149383 | 149675 | pLeft = pLeft->x.pList->a[pTerm->u.x.iField-1].pExpr; |
| 149384 | 149676 | } |
| 149385 | 149677 | |
| 149386 | 149678 | if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){ |
| 149387 | 149679 | pTerm->leftCursor = aiCurCol[0]; |
| 149680 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149388 | 149681 | pTerm->u.x.leftColumn = aiCurCol[1]; |
| 149389 | 149682 | pTerm->eOperator = operatorMask(op) & opMask; |
| 149390 | 149683 | } |
| 149391 | 149684 | if( op==TK_IS ) pTerm->wtFlags |= TERM_IS; |
| 149392 | 149685 | if( pRight |
| | @@ -149420,10 +149713,11 @@ |
| 149420 | 149713 | pDup = pExpr; |
| 149421 | 149714 | pNew = pTerm; |
| 149422 | 149715 | } |
| 149423 | 149716 | pNew->wtFlags |= exprCommute(pParse, pDup); |
| 149424 | 149717 | pNew->leftCursor = aiCurCol[0]; |
| 149718 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 149425 | 149719 | pNew->u.x.leftColumn = aiCurCol[1]; |
| 149426 | 149720 | testcase( (prereqLeft | extraRight) != prereqLeft ); |
| 149427 | 149721 | pNew->prereqRight = prereqLeft | extraRight; |
| 149428 | 149722 | pNew->prereqAll = prereqAll; |
| 149429 | 149723 | pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask; |
| | @@ -149430,10 +149724,11 @@ |
| 149430 | 149724 | }else |
| 149431 | 149725 | if( op==TK_ISNULL |
| 149432 | 149726 | && !ExprHasProperty(pExpr,EP_FromJoin) |
| 149433 | 149727 | && 0==sqlite3ExprCanBeNull(pLeft) |
| 149434 | 149728 | ){ |
| 149729 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 149435 | 149730 | pExpr->op = TK_TRUEFALSE; |
| 149436 | 149731 | pExpr->u.zToken = "false"; |
| 149437 | 149732 | ExprSetProperty(pExpr, EP_IsFalse); |
| 149438 | 149733 | pTerm->prereqAll = 0; |
| 149439 | 149734 | pTerm->eOperator = 0; |
| | @@ -149455,13 +149750,15 @@ |
| 149455 | 149750 | ** term. That means that if the BETWEEN term is coded, the children are |
| 149456 | 149751 | ** skipped. Or, if the children are satisfied by an index, the original |
| 149457 | 149752 | ** BETWEEN term is skipped. |
| 149458 | 149753 | */ |
| 149459 | 149754 | else if( pExpr->op==TK_BETWEEN && pWC->op==TK_AND ){ |
| 149460 | | - ExprList *pList = pExpr->x.pList; |
| 149755 | + ExprList *pList; |
| 149461 | 149756 | int i; |
| 149462 | 149757 | static const u8 ops[] = {TK_GE, TK_LE}; |
| 149758 | + assert( ExprUseXList(pExpr) ); |
| 149759 | + pList = pExpr->x.pList; |
| 149463 | 149760 | assert( pList!=0 ); |
| 149464 | 149761 | assert( pList->nExpr==2 ); |
| 149465 | 149762 | for(i=0; i<2; i++){ |
| 149466 | 149763 | Expr *pNewExpr; |
| 149467 | 149764 | int idxNew; |
| | @@ -149550,12 +149847,16 @@ |
| 149550 | 149847 | int idxNew1; |
| 149551 | 149848 | int idxNew2; |
| 149552 | 149849 | const char *zCollSeqName; /* Name of collating sequence */ |
| 149553 | 149850 | const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC; |
| 149554 | 149851 | |
| 149852 | + assert( ExprUseXList(pExpr) ); |
| 149555 | 149853 | pLeft = pExpr->x.pList->a[1].pExpr; |
| 149556 | 149854 | pStr2 = sqlite3ExprDup(db, pStr1, 0); |
| 149855 | + assert( pStr1==0 || !ExprHasProperty(pStr1, EP_IntValue) ); |
| 149856 | + assert( pStr2==0 || !ExprHasProperty(pStr2, EP_IntValue) ); |
| 149857 | + |
| 149557 | 149858 | |
| 149558 | 149859 | /* Convert the lower bound to upper-case and the upper bound to |
| 149559 | 149860 | ** lower-case (upper-case is less than lower-case in ASCII) so that |
| 149560 | 149861 | ** the range constraints also work for BLOBs |
| 149561 | 149862 | */ |
| | @@ -149651,10 +149952,11 @@ |
| 149651 | 149952 | ** not use window functions. |
| 149652 | 149953 | */ |
| 149653 | 149954 | else if( pExpr->op==TK_IN |
| 149654 | 149955 | && pTerm->u.x.iField==0 |
| 149655 | 149956 | && pExpr->pLeft->op==TK_VECTOR |
| 149957 | + && ALWAYS( ExprUseXSelect(pExpr) ) |
| 149656 | 149958 | && pExpr->x.pSelect->pPrior==0 |
| 149657 | 149959 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 149658 | 149960 | && pExpr->x.pSelect->pWin==0 |
| 149659 | 149961 | #endif |
| 149660 | 149962 | && pWC->op==TK_AND |
| | @@ -149814,18 +150116,19 @@ |
| 149814 | 150116 | mask = (p->op==TK_IF_NULL_ROW) ? sqlite3WhereGetMask(pMaskSet, p->iTable) : 0; |
| 149815 | 150117 | if( p->pLeft ) mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pLeft); |
| 149816 | 150118 | if( p->pRight ){ |
| 149817 | 150119 | mask |= sqlite3WhereExprUsageNN(pMaskSet, p->pRight); |
| 149818 | 150120 | assert( p->x.pList==0 ); |
| 149819 | | - }else if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 150121 | + }else if( ExprUseXSelect(p) ){ |
| 149820 | 150122 | if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1; |
| 149821 | 150123 | mask |= exprSelectUsage(pMaskSet, p->x.pSelect); |
| 149822 | 150124 | }else if( p->x.pList ){ |
| 149823 | 150125 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList); |
| 149824 | 150126 | } |
| 149825 | 150127 | #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 ); |
| 149827 | 150130 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition); |
| 149828 | 150131 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy); |
| 149829 | 150132 | mask |= sqlite3WhereExprUsage(pMaskSet, p->y.pWin->pFilter); |
| 149830 | 150133 | } |
| 149831 | 150134 | #endif |
| | @@ -149896,10 +150199,11 @@ |
| 149896 | 150199 | } |
| 149897 | 150200 | pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0); |
| 149898 | 150201 | if( pColRef==0 ) return; |
| 149899 | 150202 | pColRef->iTable = pItem->iCursor; |
| 149900 | 150203 | pColRef->iColumn = k++; |
| 150204 | + assert( ExprUseYTab(pColRef) ); |
| 149901 | 150205 | pColRef->y.pTab = pTab; |
| 149902 | 150206 | pRhs = sqlite3PExpr(pParse, TK_UPLUS, |
| 149903 | 150207 | sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); |
| 149904 | 150208 | pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs); |
| 149905 | 150209 | if( pItem->fg.jointype & JT_LEFT ){ |
| | @@ -150197,12 +150501,14 @@ |
| 150197 | 150501 | pWC = pScan->pWC; |
| 150198 | 150502 | while(1){ |
| 150199 | 150503 | iColumn = pScan->aiColumn[pScan->iEquiv-1]; |
| 150200 | 150504 | iCur = pScan->aiCur[pScan->iEquiv-1]; |
| 150201 | 150505 | assert( pWC!=0 ); |
| 150506 | + assert( iCur>=0 ); |
| 150202 | 150507 | do{ |
| 150203 | 150508 | for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){ |
| 150509 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 || pTerm->leftCursor<0 ); |
| 150204 | 150510 | if( pTerm->leftCursor==iCur |
| 150205 | 150511 | && pTerm->u.x.leftColumn==iColumn |
| 150206 | 150512 | && (iColumn!=XN_EXPR |
| 150207 | 150513 | || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft, |
| 150208 | 150514 | pScan->pIdxExpr,iCur)==0) |
| | @@ -150638,10 +150944,11 @@ |
| 150638 | 150944 | ** the RHS of a LEFT JOIN. Such a term can only be used if it is from |
| 150639 | 150945 | ** the ON clause. */ |
| 150640 | 150946 | return 0; |
| 150641 | 150947 | } |
| 150642 | 150948 | if( (pTerm->prereqRight & notReady)!=0 ) return 0; |
| 150949 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 150643 | 150950 | if( pTerm->u.x.leftColumn<0 ) return 0; |
| 150644 | 150951 | aff = pSrc->pTab->aCol[pTerm->u.x.leftColumn].affinity; |
| 150645 | 150952 | if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0; |
| 150646 | 150953 | testcase( pTerm->pExpr->op==TK_IS ); |
| 150647 | 150954 | return 1; |
| | @@ -150710,12 +151017,15 @@ |
| 150710 | 151017 | && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){ |
| 150711 | 151018 | pPartial = sqlite3ExprAnd(pParse, pPartial, |
| 150712 | 151019 | sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 150713 | 151020 | } |
| 150714 | 151021 | 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); |
| 150717 | 151027 | testcase( iCol==BMS ); |
| 150718 | 151028 | testcase( iCol==BMS-1 ); |
| 150719 | 151029 | if( !sentWarning ){ |
| 150720 | 151030 | sqlite3_log(SQLITE_WARNING_AUTOINDEX, |
| 150721 | 151031 | "automatic index on %s(%s)", pTable->zName, |
| | @@ -150763,12 +151073,15 @@ |
| 150763 | 151073 | pIdx->pTable = pTable; |
| 150764 | 151074 | n = 0; |
| 150765 | 151075 | idxCols = 0; |
| 150766 | 151076 | for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){ |
| 150767 | 151077 | 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); |
| 150770 | 151083 | testcase( iCol==BMS-1 ); |
| 150771 | 151084 | testcase( iCol==BMS ); |
| 150772 | 151085 | if( (idxCols & cMask)==0 ){ |
| 150773 | 151086 | Expr *pX = pTerm->pExpr; |
| 150774 | 151087 | idxCols |= cMask; |
| | @@ -150891,10 +151204,11 @@ |
| 150891 | 151204 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 150892 | 151205 | testcase( pTerm->eOperator & WO_IS ); |
| 150893 | 151206 | testcase( pTerm->eOperator & WO_ALL ); |
| 150894 | 151207 | if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue; |
| 150895 | 151208 | if( pTerm->wtFlags & TERM_VNULL ) continue; |
| 151209 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 150896 | 151210 | assert( pTerm->u.x.leftColumn>=(-1) ); |
| 150897 | 151211 | nTerm++; |
| 150898 | 151212 | } |
| 150899 | 151213 | |
| 150900 | 151214 | /* If the ORDER BY clause contains only columns in the current |
| | @@ -150951,10 +151265,11 @@ |
| 150951 | 151265 | if( (pSrc->fg.jointype & JT_LEFT)!=0 |
| 150952 | 151266 | && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 150953 | 151267 | ){ |
| 150954 | 151268 | continue; |
| 150955 | 151269 | } |
| 151270 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 150956 | 151271 | assert( pTerm->u.x.leftColumn>=(-1) ); |
| 150957 | 151272 | pIdxCons[j].iColumn = pTerm->u.x.leftColumn; |
| 150958 | 151273 | pIdxCons[j].iTermOffset = i; |
| 150959 | 151274 | op = pTerm->eOperator & WO_ALL; |
| 150960 | 151275 | if( op==WO_IN ) op = WO_EQ; |
| | @@ -151714,10 +152029,11 @@ |
| 151714 | 152029 | if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V'; |
| 151715 | 152030 | if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E'; |
| 151716 | 152031 | if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L'; |
| 151717 | 152032 | if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C'; |
| 151718 | 152033 | if( pTerm->eOperator & WO_SINGLE ){ |
| 152034 | + assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 ); |
| 151719 | 152035 | sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}", |
| 151720 | 152036 | pTerm->leftCursor, pTerm->u.x.leftColumn); |
| 151721 | 152037 | }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){ |
| 151722 | 152038 | sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx", |
| 151723 | 152039 | pTerm->u.pOrInfo->indexable); |
| | @@ -151731,11 +152047,11 @@ |
| 151731 | 152047 | ** shown about each Term */ |
| 151732 | 152048 | if( sqlite3WhereTrace & 0x10000 ){ |
| 151733 | 152049 | sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx", |
| 151734 | 152050 | pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight); |
| 151735 | 152051 | } |
| 151736 | | - if( pTerm->u.x.iField ){ |
| 152052 | + if( (pTerm->eOperator & (WO_OR|WO_AND))==0 && pTerm->u.x.iField ){ |
| 151737 | 152053 | sqlite3DebugPrintf(" iField=%d", pTerm->u.x.iField); |
| 151738 | 152054 | } |
| 151739 | 152055 | if( pTerm->iParent>=0 ){ |
| 151740 | 152056 | sqlite3DebugPrintf(" iParent=%d", pTerm->iParent); |
| 151741 | 152057 | } |
| | @@ -151895,11 +152211,12 @@ |
| 151895 | 152211 | static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ |
| 151896 | 152212 | int i; |
| 151897 | 152213 | assert( pWInfo!=0 ); |
| 151898 | 152214 | for(i=0; i<pWInfo->nLevel; i++){ |
| 151899 | 152215 | 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 ); |
| 151901 | 152218 | sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 151902 | 152219 | } |
| 151903 | 152220 | } |
| 151904 | 152221 | sqlite3WhereClauseClear(&pWInfo->sWC); |
| 151905 | 152222 | while( pWInfo->pLoops ){ |
| | @@ -152330,13 +152647,16 @@ |
| 152330 | 152647 | /* Test if comparison i of pTerm is compatible with column (i+nEq) |
| 152331 | 152648 | ** of the index. If not, exit the loop. */ |
| 152332 | 152649 | char aff; /* Comparison affinity */ |
| 152333 | 152650 | char idxaff = 0; /* Indexed columns affinity */ |
| 152334 | 152651 | 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) ){ |
| 152338 | 152658 | pRhs = pRhs->x.pSelect->pEList->a[i].pExpr; |
| 152339 | 152659 | }else{ |
| 152340 | 152660 | pRhs = pRhs->x.pList->a[i].pExpr; |
| 152341 | 152661 | } |
| 152342 | 152662 | |
| | @@ -152493,11 +152813,11 @@ |
| 152493 | 152813 | || (pNew->wsFlags & WHERE_SKIPSCAN)!=0 |
| 152494 | 152814 | ); |
| 152495 | 152815 | |
| 152496 | 152816 | if( eOp & WO_IN ){ |
| 152497 | 152817 | Expr *pExpr = pTerm->pExpr; |
| 152498 | | - if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 152818 | + if( ExprUseXSelect(pExpr) ){ |
| 152499 | 152819 | /* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */ |
| 152500 | 152820 | int i; |
| 152501 | 152821 | nIn = 46; assert( 46==sqlite3LogEst(25) ); |
| 152502 | 152822 | |
| 152503 | 152823 | /* The expression may actually be of the form (x, y) IN (SELECT...). |
| | @@ -152634,11 +152954,11 @@ |
| 152634 | 152954 | #ifdef SQLITE_ENABLE_STAT4 |
| 152635 | 152955 | tRowcnt nOut = 0; |
| 152636 | 152956 | if( nInMul==0 |
| 152637 | 152957 | && pProbe->nSample |
| 152638 | 152958 | && 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)) |
| 152640 | 152960 | && OptimizationEnabled(db, SQLITE_Stat4) |
| 152641 | 152961 | ){ |
| 152642 | 152962 | Expr *pExpr = pTerm->pExpr; |
| 152643 | 152963 | if( (eOp & (WO_EQ|WO_ISNULL|WO_IS))!=0 ){ |
| 152644 | 152964 | testcase( eOp & WO_EQ ); |
| | @@ -152910,10 +153230,11 @@ |
| 152910 | 153230 | pTab = pSrc->pTab; |
| 152911 | 153231 | pWC = pBuilder->pWC; |
| 152912 | 153232 | assert( !IsVirtual(pSrc->pTab) ); |
| 152913 | 153233 | |
| 152914 | 153234 | if( pSrc->fg.isIndexedBy ){ |
| 153235 | + assert( pSrc->fg.isCte==0 ); |
| 152915 | 153236 | /* An INDEXED BY clause specifies a particular index to use */ |
| 152916 | 153237 | pProbe = pSrc->u2.pIBIndex; |
| 152917 | 153238 | }else if( !HasRowid(pTab) ){ |
| 152918 | 153239 | pProbe = pTab->pIndex; |
| 152919 | 153240 | }else{ |
| | @@ -155380,11 +155701,11 @@ |
| 155380 | 155701 | if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek); |
| 155381 | 155702 | #endif |
| 155382 | 155703 | }else{ |
| 155383 | 155704 | sqlite3VdbeResolveLabel(v, pLevel->addrCont); |
| 155384 | 155705 | } |
| 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 ){ |
| 155386 | 155707 | struct InLoop *pIn; |
| 155387 | 155708 | int j; |
| 155388 | 155709 | sqlite3VdbeResolveLabel(v, pLevel->addrNxt); |
| 155389 | 155710 | for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){ |
| 155390 | 155711 | assert( sqlite3VdbeGetOp(v, pIn->addrInTop+1)->opcode==OP_IsNull |
| | @@ -155449,14 +155770,14 @@ |
| 155449 | 155770 | if( (ws & WHERE_IDX_ONLY)==0 ){ |
| 155450 | 155771 | assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor ); |
| 155451 | 155772 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur); |
| 155452 | 155773 | } |
| 155453 | 155774 | if( (ws & WHERE_INDEXED) |
| 155454 | | - || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) |
| 155775 | + || ((ws & WHERE_MULTI_OR) && pLevel->u.pCoveringIdx) |
| 155455 | 155776 | ){ |
| 155456 | 155777 | if( ws & WHERE_MULTI_OR ){ |
| 155457 | | - Index *pIx = pLevel->u.pCovidx; |
| 155778 | + Index *pIx = pLevel->u.pCoveringIdx; |
| 155458 | 155779 | int iDb = sqlite3SchemaToIndex(db, pIx->pSchema); |
| 155459 | 155780 | sqlite3VdbeAddOp3(v, OP_ReopenIdx, pLevel->iIdxCur, pIx->tnum, iDb); |
| 155460 | 155781 | sqlite3VdbeSetP4KeyInfo(pParse, pIx); |
| 155461 | 155782 | } |
| 155462 | 155783 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur); |
| | @@ -155533,11 +155854,11 @@ |
| 155533 | 155854 | ** reference the index. |
| 155534 | 155855 | */ |
| 155535 | 155856 | if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){ |
| 155536 | 155857 | pIdx = pLoop->u.btree.pIndex; |
| 155537 | 155858 | }else if( pLoop->wsFlags & WHERE_MULTI_OR ){ |
| 155538 | | - pIdx = pLevel->u.pCovidx; |
| 155859 | + pIdx = pLevel->u.pCoveringIdx; |
| 155539 | 155860 | } |
| 155540 | 155861 | if( pIdx |
| 155541 | 155862 | && !db->mallocFailed |
| 155542 | 155863 | ){ |
| 155543 | 155864 | if( pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable) ){ |
| | @@ -156194,28 +156515,28 @@ |
| 156194 | 156515 | static void noopValueFunc(sqlite3_context *p){ UNUSED_PARAMETER(p); /*no-op*/ } |
| 156195 | 156516 | |
| 156196 | 156517 | /* Window functions that use all window interfaces: xStep, xFinal, |
| 156197 | 156518 | ** xValue, and xInverse */ |
| 156198 | 156519 | #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, \ |
| 156200 | 156521 | name ## StepFunc, name ## FinalizeFunc, name ## ValueFunc, \ |
| 156201 | 156522 | name ## InvFunc, name ## Name, {0} \ |
| 156202 | 156523 | } |
| 156203 | 156524 | |
| 156204 | 156525 | /* Window functions that are implemented using bytecode and thus have |
| 156205 | 156526 | ** no-op routines for their methods */ |
| 156206 | 156527 | #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, \ |
| 156208 | 156529 | noopStepFunc, noopValueFunc, noopValueFunc, \ |
| 156209 | 156530 | noopStepFunc, name ## Name, {0} \ |
| 156210 | 156531 | } |
| 156211 | 156532 | |
| 156212 | 156533 | /* Window functions that use all window interfaces: xStep, the |
| 156213 | 156534 | ** same routine for xFinalize and xValue and which never call |
| 156214 | 156535 | ** xInverse. */ |
| 156215 | 156536 | #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, \ |
| 156217 | 156538 | name ## StepFunc, name ## ValueFunc, name ## ValueFunc, \ |
| 156218 | 156539 | noopStepFunc, name ## Name, {0} \ |
| 156219 | 156540 | } |
| 156220 | 156541 | |
| 156221 | 156542 | |
| | @@ -156554,11 +156875,12 @@ |
| 156554 | 156875 | return WRC_Continue; |
| 156555 | 156876 | } |
| 156556 | 156877 | |
| 156557 | 156878 | static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){ |
| 156558 | 156879 | if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){ |
| 156559 | | - sqlite3ErrorMsg(pWalker->pParse, |
| 156880 | + assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 156881 | + sqlite3ErrorMsg(pWalker->pParse, |
| 156560 | 156882 | "misuse of aggregate: %s()", pExpr->u.zToken); |
| 156561 | 156883 | } |
| 156562 | 156884 | return WRC_Continue; |
| 156563 | 156885 | } |
| 156564 | 156886 | |
| | @@ -156642,11 +156964,13 @@ |
| 156642 | 156964 | /* Append the arguments passed to each window function to the |
| 156643 | 156965 | ** sub-select expression list. Also allocate two registers for each |
| 156644 | 156966 | ** window function - one for the accumulator, another for interim |
| 156645 | 156967 | ** results. */ |
| 156646 | 156968 | 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; |
| 156648 | 156972 | if( pWin->pFunc->funcFlags & SQLITE_FUNC_SUBTYPE ){ |
| 156649 | 156973 | selectWindowRewriteEList(pParse, pMWin, pSrc, pArgs, pTab, &pSublist); |
| 156650 | 156974 | pWin->iArgCol = (pSublist ? pSublist->nExpr : 0); |
| 156651 | 156975 | pWin->bExprArgs = 1; |
| 156652 | 156976 | }else{ |
| | @@ -157035,12 +157359,15 @@ |
| 157035 | 157359 | ** |
| 157036 | 157360 | ** regApp+0: slot to copy min()/max() argument to for MakeRecord |
| 157037 | 157361 | ** regApp+1: integer value used to ensure keys are unique |
| 157038 | 157362 | ** regApp+2: output of MakeRecord |
| 157039 | 157363 | */ |
| 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); |
| 157042 | 157369 | pWin->csrApp = pParse->nTab++; |
| 157043 | 157370 | pWin->regApp = pParse->nMem+1; |
| 157044 | 157371 | pParse->nMem += 3; |
| 157045 | 157372 | if( pKeyInfo && pWin->pFunc->zName[1]=='i' ){ |
| 157046 | 157373 | assert( pKeyInfo->aSortFlags[0]==0 ); |
| | @@ -157124,11 +157451,13 @@ |
| 157124 | 157451 | /* |
| 157125 | 157452 | ** Return the number of arguments passed to the window-function associated |
| 157126 | 157453 | ** with the object passed as the only argument to this function. |
| 157127 | 157454 | */ |
| 157128 | 157455 | 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; |
| 157130 | 157459 | return (pList ? pList->nExpr : 0); |
| 157131 | 157460 | } |
| 157132 | 157461 | |
| 157133 | 157462 | typedef struct WindowCodeArg WindowCodeArg; |
| 157134 | 157463 | typedef struct WindowCsrAndReg WindowCsrAndReg; |
| | @@ -157309,10 +157638,11 @@ |
| 157309 | 157638 | sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1); |
| 157310 | 157639 | }else if( pFunc->xSFunc!=noopStepFunc ){ |
| 157311 | 157640 | int addrIf = 0; |
| 157312 | 157641 | if( pWin->pFilter ){ |
| 157313 | 157642 | int regTmp; |
| 157643 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157314 | 157644 | assert( pWin->bExprArgs || !nArg ||nArg==pWin->pOwner->x.pList->nExpr ); |
| 157315 | 157645 | assert( pWin->bExprArgs || nArg ||pWin->pOwner->x.pList==0 ); |
| 157316 | 157646 | regTmp = sqlite3GetTempReg(pParse); |
| 157317 | 157647 | sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp); |
| 157318 | 157648 | addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1); |
| | @@ -157322,10 +157652,11 @@ |
| 157322 | 157652 | |
| 157323 | 157653 | if( pWin->bExprArgs ){ |
| 157324 | 157654 | int iOp = sqlite3VdbeCurrentAddr(v); |
| 157325 | 157655 | int iEnd; |
| 157326 | 157656 | |
| 157657 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157327 | 157658 | nArg = pWin->pOwner->x.pList->nExpr; |
| 157328 | 157659 | regArg = sqlite3GetTempRange(pParse, nArg); |
| 157329 | 157660 | sqlite3ExprCodeExprList(pParse, pWin->pOwner->x.pList, regArg, 0, 0); |
| 157330 | 157661 | |
| 157331 | 157662 | for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){ |
| | @@ -157336,10 +157667,11 @@ |
| 157336 | 157667 | } |
| 157337 | 157668 | } |
| 157338 | 157669 | if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 157339 | 157670 | CollSeq *pColl; |
| 157340 | 157671 | assert( nArg>0 ); |
| 157672 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157341 | 157673 | pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr); |
| 157342 | 157674 | sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ); |
| 157343 | 157675 | } |
| 157344 | 157676 | sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep, |
| 157345 | 157677 | bInverse, regArg, pWin->regAccum); |
| | @@ -157521,10 +157853,11 @@ |
| 157521 | 157853 | Parse *pParse = p->pParse; |
| 157522 | 157854 | Window *pWin; |
| 157523 | 157855 | |
| 157524 | 157856 | for(pWin=pMWin; pWin; pWin=pWin->pNextWin){ |
| 157525 | 157857 | FuncDef *pFunc = pWin->pFunc; |
| 157858 | + assert( ExprUseXList(pWin->pOwner) ); |
| 157526 | 157859 | if( pFunc->zName==nth_valueName |
| 157527 | 157860 | || pFunc->zName==first_valueName |
| 157528 | 157861 | ){ |
| 157529 | 157862 | int csr = pWin->csrApp; |
| 157530 | 157863 | int lbl = sqlite3VdbeMakeLabel(pParse); |
| | @@ -158870,13 +159203,13 @@ |
| 158870 | 159203 | p->affExpr = 0; |
| 158871 | 159204 | p->flags = EP_Leaf; |
| 158872 | 159205 | ExprClearVVAProperties(p); |
| 158873 | 159206 | p->iAgg = -1; |
| 158874 | 159207 | p->pLeft = p->pRight = 0; |
| 158875 | | - p->x.pList = 0; |
| 158876 | 159208 | p->pAggInfo = 0; |
| 158877 | | - p->y.pTab = 0; |
| 159209 | + memset(&p->x, 0, sizeof(p->x)); |
| 159210 | + memset(&p->y, 0, sizeof(p->y)); |
| 158878 | 159211 | p->op2 = 0; |
| 158879 | 159212 | p->iTable = 0; |
| 158880 | 159213 | p->iColumn = 0; |
| 158881 | 159214 | p->u.zToken = (char*)&p[1]; |
| 158882 | 159215 | memcpy(p->u.zToken, t.z, t.n); |
| | @@ -166966,11 +167299,13 @@ |
| 166966 | 167299 | ** if this is not the last copy of the function, do not invoke it. Multiple |
| 166967 | 167300 | ** copies of a single function are created when create_function() is called |
| 166968 | 167301 | ** with SQLITE_ANY as the encoding. |
| 166969 | 167302 | */ |
| 166970 | 167303 | 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; |
| 166972 | 167307 | if( pDestructor ){ |
| 166973 | 167308 | pDestructor->nRef--; |
| 166974 | 167309 | if( pDestructor->nRef==0 ){ |
| 166975 | 167310 | pDestructor->xDestroy(pDestructor->pUserData); |
| 166976 | 167311 | sqlite3DbFree(db, pDestructor); |
| | @@ -168987,10 +169322,11 @@ |
| 168987 | 169322 | ** SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE, SQLITE_OPEN_SHAREDCACHE, |
| 168988 | 169323 | ** SQLITE_OPEN_PRIVATECACHE, and some reserved bits. Silently mask |
| 168989 | 169324 | ** off all other flags. |
| 168990 | 169325 | */ |
| 168991 | 169326 | flags &= ~( SQLITE_OPEN_DELETEONCLOSE | |
| 169327 | + SQLITE_OPEN_EXCLUSIVE | |
| 168992 | 169328 | SQLITE_OPEN_MAIN_DB | |
| 168993 | 169329 | SQLITE_OPEN_TEMP_DB | |
| 168994 | 169330 | SQLITE_OPEN_TRANSIENT_DB | |
| 168995 | 169331 | SQLITE_OPEN_MAIN_JOURNAL | |
| 168996 | 169332 | SQLITE_OPEN_TEMP_JOURNAL | |
| | @@ -172095,10 +172431,11 @@ |
| 172095 | 172431 | SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *); |
| 172096 | 172432 | #ifdef SQLITE_TEST |
| 172097 | 172433 | SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db, Fts3Hash*); |
| 172098 | 172434 | SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db); |
| 172099 | 172435 | #endif |
| 172436 | +SQLITE_PRIVATE void *sqlite3Fts3MallocZero(i64 nByte); |
| 172100 | 172437 | |
| 172101 | 172438 | SQLITE_PRIVATE int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int, |
| 172102 | 172439 | sqlite3_tokenizer_cursor ** |
| 172103 | 172440 | ); |
| 172104 | 172441 | |
| | @@ -177176,12 +177513,12 @@ |
| 177176 | 177513 | case FTSQUERY_OR: { |
| 177177 | 177514 | Fts3Expr *pLeft = pExpr->pLeft; |
| 177178 | 177515 | Fts3Expr *pRight = pExpr->pRight; |
| 177179 | 177516 | sqlite3_int64 iCmp = DOCID_CMP(pLeft->iDocid, pRight->iDocid); |
| 177180 | 177517 | |
| 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 ); |
| 177183 | 177520 | |
| 177184 | 177521 | if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){ |
| 177185 | 177522 | fts3EvalNextRow(pCsr, pLeft, pRc); |
| 177186 | 177523 | }else if( pLeft->bEof || iCmp>0 ){ |
| 177187 | 177524 | fts3EvalNextRow(pCsr, pRight, pRc); |
| | @@ -178617,11 +178954,11 @@ |
| 178617 | 178954 | /* |
| 178618 | 178955 | ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful, |
| 178619 | 178956 | ** zero the memory before returning a pointer to it. If unsuccessful, |
| 178620 | 178957 | ** return NULL. |
| 178621 | 178958 | */ |
| 178622 | | -static void *fts3MallocZero(sqlite3_int64 nByte){ |
| 178959 | +SQLITE_PRIVATE void *sqlite3Fts3MallocZero(sqlite3_int64 nByte){ |
| 178623 | 178960 | void *pRet = sqlite3_malloc64(nByte); |
| 178624 | 178961 | if( pRet ) memset(pRet, 0, nByte); |
| 178625 | 178962 | return pRet; |
| 178626 | 178963 | } |
| 178627 | 178964 | |
| | @@ -178698,11 +179035,11 @@ |
| 178698 | 179035 | sqlite3_int64 nByte; /* total space to allocate */ |
| 178699 | 179036 | |
| 178700 | 179037 | rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition); |
| 178701 | 179038 | if( rc==SQLITE_OK ){ |
| 178702 | 179039 | nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken; |
| 178703 | | - pRet = (Fts3Expr *)fts3MallocZero(nByte); |
| 179040 | + pRet = (Fts3Expr *)sqlite3Fts3MallocZero(nByte); |
| 178704 | 179041 | if( !pRet ){ |
| 178705 | 179042 | rc = SQLITE_NOMEM; |
| 178706 | 179043 | }else{ |
| 178707 | 179044 | pRet->eType = FTSQUERY_PHRASE; |
| 178708 | 179045 | pRet->pPhrase = (Fts3Phrase *)&pRet[1]; |
| | @@ -178953,11 +179290,11 @@ |
| 178953 | 179290 | */ |
| 178954 | 179291 | cNext = zInput[nKey]; |
| 178955 | 179292 | if( fts3isspace(cNext) |
| 178956 | 179293 | || cNext=='"' || cNext=='(' || cNext==')' || cNext==0 |
| 178957 | 179294 | ){ |
| 178958 | | - pRet = (Fts3Expr *)fts3MallocZero(sizeof(Fts3Expr)); |
| 179295 | + pRet = (Fts3Expr *)sqlite3Fts3MallocZero(sizeof(Fts3Expr)); |
| 178959 | 179296 | if( !pRet ){ |
| 178960 | 179297 | return SQLITE_NOMEM; |
| 178961 | 179298 | } |
| 178962 | 179299 | pRet->eType = pKey->eType; |
| 178963 | 179300 | pRet->nNear = nNear; |
| | @@ -179132,11 +179469,11 @@ |
| 179132 | 179469 | |
| 179133 | 179470 | if( !sqlite3_fts3_enable_parentheses |
| 179134 | 179471 | && p->eType==FTSQUERY_PHRASE && pParse->isNot |
| 179135 | 179472 | ){ |
| 179136 | 179473 | /* Create an implicit NOT operator. */ |
| 179137 | | - Fts3Expr *pNot = fts3MallocZero(sizeof(Fts3Expr)); |
| 179474 | + Fts3Expr *pNot = sqlite3Fts3MallocZero(sizeof(Fts3Expr)); |
| 179138 | 179475 | if( !pNot ){ |
| 179139 | 179476 | sqlite3Fts3ExprFree(p); |
| 179140 | 179477 | rc = SQLITE_NOMEM; |
| 179141 | 179478 | goto exprparse_out; |
| 179142 | 179479 | } |
| | @@ -179166,11 +179503,11 @@ |
| 179166 | 179503 | |
| 179167 | 179504 | if( isPhrase && !isRequirePhrase ){ |
| 179168 | 179505 | /* Insert an implicit AND operator. */ |
| 179169 | 179506 | Fts3Expr *pAnd; |
| 179170 | 179507 | assert( pRet && pPrev ); |
| 179171 | | - pAnd = fts3MallocZero(sizeof(Fts3Expr)); |
| 179508 | + pAnd = sqlite3Fts3MallocZero(sizeof(Fts3Expr)); |
| 179172 | 179509 | if( !pAnd ){ |
| 179173 | 179510 | sqlite3Fts3ExprFree(p); |
| 179174 | 179511 | rc = SQLITE_NOMEM; |
| 179175 | 179512 | goto exprparse_out; |
| 179176 | 179513 | } |
| | @@ -183396,12 +183733,22 @@ |
| 183396 | 183733 | pReader->aNode = 0; |
| 183397 | 183734 | if( pElem ){ |
| 183398 | 183735 | char *aCopy; |
| 183399 | 183736 | PendingList *pList = (PendingList *)fts3HashData(pElem); |
| 183400 | 183737 | 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 | + |
| 183403 | 183750 | aCopy = (char*)sqlite3_malloc(nCopy); |
| 183404 | 183751 | if( !aCopy ) return SQLITE_NOMEM; |
| 183405 | 183752 | memcpy(aCopy, pList->aData, nCopy); |
| 183406 | 183753 | pReader->nNode = pReader->nDoclist = nCopy; |
| 183407 | 183754 | pReader->aNode = pReader->aDoclist = aCopy; |
| | @@ -183650,13 +183997,11 @@ |
| 183650 | 183997 | ** Free all allocations associated with the iterator passed as the |
| 183651 | 183998 | ** second argument. |
| 183652 | 183999 | */ |
| 183653 | 184000 | SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *pReader){ |
| 183654 | 184001 | if( pReader ){ |
| 183655 | | - if( !fts3SegReaderIsPending(pReader) ){ |
| 183656 | | - sqlite3_free(pReader->zTerm); |
| 183657 | | - } |
| 184002 | + sqlite3_free(pReader->zTerm); |
| 183658 | 184003 | if( !fts3SegReaderIsRootOnly(pReader) ){ |
| 183659 | 184004 | sqlite3_free(pReader->aNode); |
| 183660 | 184005 | } |
| 183661 | 184006 | sqlite3_blob_close(pReader->pBlob); |
| 183662 | 184007 | } |
| | @@ -188003,13 +188348,12 @@ |
| 188003 | 188348 | MatchinfoBuffer *pRet; |
| 188004 | 188349 | sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1) |
| 188005 | 188350 | + sizeof(MatchinfoBuffer); |
| 188006 | 188351 | sqlite3_int64 nStr = strlen(zMatchinfo); |
| 188007 | 188352 | |
| 188008 | | - pRet = sqlite3_malloc64(nByte + nStr+1); |
| 188353 | + pRet = sqlite3Fts3MallocZero(nByte + nStr+1); |
| 188009 | 188354 | if( pRet ){ |
| 188010 | | - memset(pRet, 0, nByte); |
| 188011 | 188355 | pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet; |
| 188012 | 188356 | pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] |
| 188013 | 188357 | + sizeof(u32)*((int)nElem+1); |
| 188014 | 188358 | pRet->nElem = (int)nElem; |
| 188015 | 188359 | pRet->zMatchinfo = ((char*)pRet) + nByte; |
| | @@ -188409,15 +188753,14 @@ |
| 188409 | 188753 | |
| 188410 | 188754 | /* Now that it is known how many phrases there are, allocate and zero |
| 188411 | 188755 | ** the required space using malloc(). |
| 188412 | 188756 | */ |
| 188413 | 188757 | nByte = sizeof(SnippetPhrase) * nList; |
| 188414 | | - sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte); |
| 188758 | + sIter.aPhrase = (SnippetPhrase *)sqlite3Fts3MallocZero(nByte); |
| 188415 | 188759 | if( !sIter.aPhrase ){ |
| 188416 | 188760 | return SQLITE_NOMEM; |
| 188417 | 188761 | } |
| 188418 | | - memset(sIter.aPhrase, 0, nByte); |
| 188419 | 188762 | |
| 188420 | 188763 | /* Initialize the contents of the SnippetIter object. Then iterate through |
| 188421 | 188764 | ** the set of phrases in the expression to populate the aPhrase[] array. |
| 188422 | 188765 | */ |
| 188423 | 188766 | sIter.pCsr = pCsr; |
| | @@ -189016,13 +189359,12 @@ |
| 189016 | 189359 | int rc = SQLITE_OK; |
| 189017 | 189360 | |
| 189018 | 189361 | /* Allocate and populate the array of LcsIterator objects. The array |
| 189019 | 189362 | ** contains one element for each matchable phrase in the query. |
| 189020 | 189363 | **/ |
| 189021 | | - aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase); |
| 189364 | + aIter = sqlite3Fts3MallocZero(sizeof(LcsIterator) * pCsr->nPhrase); |
| 189022 | 189365 | if( !aIter ) return SQLITE_NOMEM; |
| 189023 | | - memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase); |
| 189024 | 189366 | (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter); |
| 189025 | 189367 | |
| 189026 | 189368 | for(i=0; i<pInfo->nPhrase; i++){ |
| 189027 | 189369 | LcsIterator *pIter = &aIter[i]; |
| 189028 | 189370 | nToken -= pIter->pExpr->pPhrase->nToken; |
| | @@ -189479,11 +189821,11 @@ |
| 189479 | 189821 | /* Count the number of terms in the query */ |
| 189480 | 189822 | rc = fts3ExprLoadDoclists(pCsr, 0, &nToken); |
| 189481 | 189823 | if( rc!=SQLITE_OK ) goto offsets_out; |
| 189482 | 189824 | |
| 189483 | 189825 | /* Allocate the array of TermOffset iterators. */ |
| 189484 | | - sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken); |
| 189826 | + sCtx.aTerm = (TermOffset *)sqlite3Fts3MallocZero(sizeof(TermOffset)*nToken); |
| 189485 | 189827 | if( 0==sCtx.aTerm ){ |
| 189486 | 189828 | rc = SQLITE_NOMEM; |
| 189487 | 189829 | goto offsets_out; |
| 189488 | 189830 | } |
| 189489 | 189831 | sCtx.iDocid = pCsr->iPrevId; |
| | @@ -190517,11 +190859,25 @@ |
| 190517 | 190859 | # define NEVER(X) ((X)?(assert(0),1):0) |
| 190518 | 190860 | # else |
| 190519 | 190861 | # define ALWAYS(X) (X) |
| 190520 | 190862 | # define NEVER(X) (X) |
| 190521 | 190863 | # endif |
| 190864 | +# define testcase(X) |
| 190522 | 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) |
| 190523 | 190879 | |
| 190524 | 190880 | /* Objects */ |
| 190525 | 190881 | typedef struct JsonString JsonString; |
| 190526 | 190882 | typedef struct JsonNode JsonNode; |
| 190527 | 190883 | typedef struct JsonParse JsonParse; |
| | @@ -190575,17 +190931,18 @@ |
| 190575 | 190931 | /* A single node of parsed JSON |
| 190576 | 190932 | */ |
| 190577 | 190933 | struct JsonNode { |
| 190578 | 190934 | u8 eType; /* One of the JSON_ type values */ |
| 190579 | 190935 | u8 jnFlags; /* JNODE flags */ |
| 190936 | + u8 eU; /* Which union element to use */ |
| 190580 | 190937 | u32 n; /* Bytes of content, or number of sub-nodes */ |
| 190581 | 190938 | 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 */ |
| 190587 | 190944 | } u; |
| 190588 | 190945 | }; |
| 190589 | 190946 | |
| 190590 | 190947 | /* A completely parsed JSON string |
| 190591 | 190948 | */ |
| | @@ -190862,13 +191219,15 @@ |
| 190862 | 191219 | sqlite3_value **aReplace /* Replacement values */ |
| 190863 | 191220 | ){ |
| 190864 | 191221 | assert( pNode!=0 ); |
| 190865 | 191222 | if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){ |
| 190866 | 191223 | if( (pNode->jnFlags & JNODE_REPLACE)!=0 && ALWAYS(aReplace!=0) ){ |
| 191224 | + assert( pNode->eU==4 ); |
| 190867 | 191225 | jsonAppendValue(pOut, aReplace[pNode->u.iReplace]); |
| 190868 | 191226 | return; |
| 190869 | 191227 | } |
| 191228 | + assert( pNode->eU==5 ); |
| 190870 | 191229 | pNode = pNode->u.pPatch; |
| 190871 | 191230 | } |
| 190872 | 191231 | switch( pNode->eType ){ |
| 190873 | 191232 | default: { |
| 190874 | 191233 | assert( pNode->eType==JSON_NULL ); |
| | @@ -190883,17 +191242,19 @@ |
| 190883 | 191242 | jsonAppendRaw(pOut, "false", 5); |
| 190884 | 191243 | break; |
| 190885 | 191244 | } |
| 190886 | 191245 | case JSON_STRING: { |
| 190887 | 191246 | if( pNode->jnFlags & JNODE_RAW ){ |
| 191247 | + assert( pNode->eU==1 ); |
| 190888 | 191248 | jsonAppendString(pOut, pNode->u.zJContent, pNode->n); |
| 190889 | 191249 | break; |
| 190890 | 191250 | } |
| 190891 | 191251 | /* no break */ deliberate_fall_through |
| 190892 | 191252 | } |
| 190893 | 191253 | case JSON_REAL: |
| 190894 | 191254 | case JSON_INT: { |
| 191255 | + assert( pNode->eU==1 ); |
| 190895 | 191256 | jsonAppendRaw(pOut, pNode->u.zJContent, pNode->n); |
| 190896 | 191257 | break; |
| 190897 | 191258 | } |
| 190898 | 191259 | case JSON_ARRAY: { |
| 190899 | 191260 | u32 j = 1; |
| | @@ -190905,10 +191266,11 @@ |
| 190905 | 191266 | jsonRenderNode(&pNode[j], pOut, aReplace); |
| 190906 | 191267 | } |
| 190907 | 191268 | j += jsonNodeSize(&pNode[j]); |
| 190908 | 191269 | } |
| 190909 | 191270 | if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; |
| 191271 | + assert( pNode->eU==2 ); |
| 190910 | 191272 | pNode = &pNode[pNode->u.iAppend]; |
| 190911 | 191273 | j = 1; |
| 190912 | 191274 | } |
| 190913 | 191275 | jsonAppendChar(pOut, ']'); |
| 190914 | 191276 | break; |
| | @@ -190925,10 +191287,11 @@ |
| 190925 | 191287 | jsonRenderNode(&pNode[j+1], pOut, aReplace); |
| 190926 | 191288 | } |
| 190927 | 191289 | j += 1 + jsonNodeSize(&pNode[j+1]); |
| 190928 | 191290 | } |
| 190929 | 191291 | if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; |
| 191292 | + assert( pNode->eU==2 ); |
| 190930 | 191293 | pNode = &pNode[pNode->u.iAppend]; |
| 190931 | 191294 | j = 1; |
| 190932 | 191295 | } |
| 190933 | 191296 | jsonAppendChar(pOut, '}'); |
| 190934 | 191297 | break; |
| | @@ -191004,11 +191367,13 @@ |
| 191004 | 191367 | sqlite3_result_int(pCtx, 0); |
| 191005 | 191368 | break; |
| 191006 | 191369 | } |
| 191007 | 191370 | case JSON_INT: { |
| 191008 | 191371 | 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; |
| 191010 | 191375 | if( z[0]=='-' ){ z++; } |
| 191011 | 191376 | while( z[0]>='0' && z[0]<='9' ){ |
| 191012 | 191377 | unsigned v = *(z++) - '0'; |
| 191013 | 191378 | if( i>=LARGEST_INT64/10 ){ |
| 191014 | 191379 | if( i>LARGEST_INT64/10 ) goto int_as_real; |
| | @@ -191032,13 +191397,16 @@ |
| 191032 | 191397 | int_as_real: ; /* no break */ deliberate_fall_through |
| 191033 | 191398 | } |
| 191034 | 191399 | case JSON_REAL: { |
| 191035 | 191400 | double r; |
| 191036 | 191401 | #ifdef SQLITE_AMALGAMATION |
| 191037 | | - const char *z = pNode->u.zJContent; |
| 191402 | + const char *z; |
| 191403 | + assert( pNode->eU==1 ); |
| 191404 | + z = pNode->u.zJContent; |
| 191038 | 191405 | sqlite3AtoF(z, &r, sqlite3Strlen30(z), SQLITE_UTF8); |
| 191039 | 191406 | #else |
| 191407 | + assert( pNode->eU==1 ); |
| 191040 | 191408 | r = strtod(pNode->u.zJContent, 0); |
| 191041 | 191409 | #endif |
| 191042 | 191410 | sqlite3_result_double(pCtx, r); |
| 191043 | 191411 | break; |
| 191044 | 191412 | } |
| | @@ -191045,26 +191413,30 @@ |
| 191045 | 191413 | case JSON_STRING: { |
| 191046 | 191414 | #if 0 /* Never happens because JNODE_RAW is only set by json_set(), |
| 191047 | 191415 | ** json_insert() and json_replace() and those routines do not |
| 191048 | 191416 | ** call jsonReturn() */ |
| 191049 | 191417 | if( pNode->jnFlags & JNODE_RAW ){ |
| 191418 | + assert( pNode->eU==1 ); |
| 191050 | 191419 | sqlite3_result_text(pCtx, pNode->u.zJContent, pNode->n, |
| 191051 | 191420 | SQLITE_TRANSIENT); |
| 191052 | 191421 | }else |
| 191053 | 191422 | #endif |
| 191054 | 191423 | assert( (pNode->jnFlags & JNODE_RAW)==0 ); |
| 191055 | 191424 | if( (pNode->jnFlags & JNODE_ESCAPE)==0 ){ |
| 191056 | 191425 | /* JSON formatted without any backslash-escapes */ |
| 191426 | + assert( pNode->eU==1 ); |
| 191057 | 191427 | sqlite3_result_text(pCtx, pNode->u.zJContent+1, pNode->n-2, |
| 191058 | 191428 | SQLITE_TRANSIENT); |
| 191059 | 191429 | }else{ |
| 191060 | 191430 | /* Translate JSON formatted string into raw text */ |
| 191061 | 191431 | u32 i; |
| 191062 | 191432 | u32 n = pNode->n; |
| 191063 | | - const char *z = pNode->u.zJContent; |
| 191433 | + const char *z; |
| 191064 | 191434 | char *zOut; |
| 191065 | 191435 | u32 j; |
| 191436 | + assert( pNode->eU==1 ); |
| 191437 | + z = pNode->u.zJContent; |
| 191066 | 191438 | zOut = sqlite3_malloc( n+1 ); |
| 191067 | 191439 | if( zOut==0 ){ |
| 191068 | 191440 | sqlite3_result_error_nomem(pCtx); |
| 191069 | 191441 | break; |
| 191070 | 191442 | } |
| | @@ -191187,10 +191559,11 @@ |
| 191187 | 191559 | return jsonParseAddNodeExpand(pParse, eType, n, zContent); |
| 191188 | 191560 | } |
| 191189 | 191561 | p = &pParse->aNode[pParse->nNode]; |
| 191190 | 191562 | p->eType = (u8)eType; |
| 191191 | 191563 | p->jnFlags = 0; |
| 191564 | + VVA( p->eU = zContent ? 1 : 0 ); |
| 191192 | 191565 | p->n = n; |
| 191193 | 191566 | p->u.zJContent = zContent; |
| 191194 | 191567 | return pParse->nNode++; |
| 191195 | 191568 | } |
| 191196 | 191569 | |
| | @@ -191254,10 +191627,11 @@ |
| 191254 | 191627 | return j+1; |
| 191255 | 191628 | }else if( c=='[' ){ |
| 191256 | 191629 | /* Parse array */ |
| 191257 | 191630 | iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0); |
| 191258 | 191631 | if( iThis<0 ) return -1; |
| 191632 | + memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u)); |
| 191259 | 191633 | for(j=i+1;;j++){ |
| 191260 | 191634 | while( safe_isspace(z[j]) ){ j++; } |
| 191261 | 191635 | if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1; |
| 191262 | 191636 | x = jsonParseValue(pParse, j); |
| 191263 | 191637 | pParse->iDepth--; |
| | @@ -191518,10 +191892,11 @@ |
| 191518 | 191892 | /* |
| 191519 | 191893 | ** Compare the OBJECT label at pNode against zKey,nKey. Return true on |
| 191520 | 191894 | ** a match. |
| 191521 | 191895 | */ |
| 191522 | 191896 | static int jsonLabelCompare(JsonNode *pNode, const char *zKey, u32 nKey){ |
| 191897 | + assert( pNode->eU==1 ); |
| 191523 | 191898 | if( pNode->jnFlags & JNODE_RAW ){ |
| 191524 | 191899 | if( pNode->n!=nKey ) return 0; |
| 191525 | 191900 | return strncmp(pNode->u.zJContent, zKey, nKey)==0; |
| 191526 | 191901 | }else{ |
| 191527 | 191902 | if( pNode->n!=nKey+2 ) return 0; |
| | @@ -191583,10 +191958,11 @@ |
| 191583 | 191958 | } |
| 191584 | 191959 | j++; |
| 191585 | 191960 | j += jsonNodeSize(&pRoot[j]); |
| 191586 | 191961 | } |
| 191587 | 191962 | if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break; |
| 191963 | + assert( pRoot->eU==2 ); |
| 191588 | 191964 | iRoot += pRoot->u.iAppend; |
| 191589 | 191965 | pRoot = &pParse->aNode[iRoot]; |
| 191590 | 191966 | j = 1; |
| 191591 | 191967 | } |
| 191592 | 191968 | if( pApnd ){ |
| | @@ -191597,12 +191973,14 @@ |
| 191597 | 191973 | zPath += i; |
| 191598 | 191974 | pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr); |
| 191599 | 191975 | if( pParse->oom ) return 0; |
| 191600 | 191976 | if( pNode ){ |
| 191601 | 191977 | pRoot = &pParse->aNode[iRoot]; |
| 191978 | + assert( pRoot->eU==0 ); |
| 191602 | 191979 | pRoot->u.iAppend = iStart - iRoot; |
| 191603 | 191980 | pRoot->jnFlags |= JNODE_APPEND; |
| 191981 | + VVA( pRoot->eU = 2 ); |
| 191604 | 191982 | pParse->aNode[iLabel].jnFlags |= JNODE_RAW; |
| 191605 | 191983 | } |
| 191606 | 191984 | return pNode; |
| 191607 | 191985 | } |
| 191608 | 191986 | }else if( zPath[0]=='[' ){ |
| | @@ -191621,10 +191999,11 @@ |
| 191621 | 191999 | while( j<=pBase->n ){ |
| 191622 | 192000 | if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++; |
| 191623 | 192001 | j += jsonNodeSize(&pBase[j]); |
| 191624 | 192002 | } |
| 191625 | 192003 | if( (pBase->jnFlags & JNODE_APPEND)==0 ) break; |
| 192004 | + assert( pBase->eU==2 ); |
| 191626 | 192005 | iBase += pBase->u.iAppend; |
| 191627 | 192006 | pBase = &pParse->aNode[iBase]; |
| 191628 | 192007 | j = 1; |
| 191629 | 192008 | } |
| 191630 | 192009 | j = 2; |
| | @@ -191654,10 +192033,11 @@ |
| 191654 | 192033 | while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){ |
| 191655 | 192034 | if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--; |
| 191656 | 192035 | j += jsonNodeSize(&pRoot[j]); |
| 191657 | 192036 | } |
| 191658 | 192037 | if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break; |
| 192038 | + assert( pRoot->eU==2 ); |
| 191659 | 192039 | iRoot += pRoot->u.iAppend; |
| 191660 | 192040 | pRoot = &pParse->aNode[iRoot]; |
| 191661 | 192041 | j = 1; |
| 191662 | 192042 | } |
| 191663 | 192043 | if( j<=pRoot->n ){ |
| | @@ -191669,12 +192049,14 @@ |
| 191669 | 192049 | iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0); |
| 191670 | 192050 | pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr); |
| 191671 | 192051 | if( pParse->oom ) return 0; |
| 191672 | 192052 | if( pNode ){ |
| 191673 | 192053 | pRoot = &pParse->aNode[iRoot]; |
| 192054 | + assert( pRoot->eU==0 ); |
| 191674 | 192055 | pRoot->u.iAppend = iStart - iRoot; |
| 191675 | 192056 | pRoot->jnFlags |= JNODE_APPEND; |
| 192057 | + VVA( pRoot->eU = 2 ); |
| 191676 | 192058 | } |
| 191677 | 192059 | return pNode; |
| 191678 | 192060 | } |
| 191679 | 192061 | }else{ |
| 191680 | 192062 | *pzErr = zPath; |
| | @@ -191824,13 +192206,17 @@ |
| 191824 | 192206 | }else{ |
| 191825 | 192207 | zType = jsonType[x.aNode[i].eType]; |
| 191826 | 192208 | } |
| 191827 | 192209 | jsonPrintf(100, &s,"node %3u: %7s n=%-4d up=%-4d", |
| 191828 | 192210 | i, zType, x.aNode[i].n, x.aUp[i]); |
| 192211 | + assert( x.aNode[i].eU==0 || x.aNode[i].eU==1 ); |
| 191829 | 192212 | if( x.aNode[i].u.zJContent!=0 ){ |
| 192213 | + assert( x.aNode[i].eU==1 ); |
| 191830 | 192214 | jsonAppendRaw(&s, " ", 1); |
| 191831 | 192215 | jsonAppendRaw(&s, x.aNode[i].u.zJContent, x.aNode[i].n); |
| 192216 | + }else{ |
| 192217 | + assert( x.aNode[i].eU==0 ); |
| 191832 | 192218 | } |
| 191833 | 192219 | jsonAppendRaw(&s, "\n", 1); |
| 191834 | 192220 | } |
| 191835 | 192221 | jsonParseReset(&x); |
| 191836 | 192222 | jsonResult(&s); |
| | @@ -192009,10 +192395,11 @@ |
| 192009 | 192395 | for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){ |
| 192010 | 192396 | u32 nKey; |
| 192011 | 192397 | const char *zKey; |
| 192012 | 192398 | assert( pPatch[i].eType==JSON_STRING ); |
| 192013 | 192399 | assert( pPatch[i].jnFlags & JNODE_LABEL ); |
| 192400 | + assert( pPatch[i].eU==1 ); |
| 192014 | 192401 | nKey = pPatch[i].n; |
| 192015 | 192402 | zKey = pPatch[i].u.zJContent; |
| 192016 | 192403 | assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); |
| 192017 | 192404 | for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){ |
| 192018 | 192405 | assert( pTarget[j].eType==JSON_STRING ); |
| | @@ -192025,10 +192412,13 @@ |
| 192025 | 192412 | }else{ |
| 192026 | 192413 | JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]); |
| 192027 | 192414 | if( pNew==0 ) return 0; |
| 192028 | 192415 | pTarget = &pParse->aNode[iTarget]; |
| 192029 | 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 ); |
| 192030 | 192420 | pTarget[j+1].u.pPatch = pNew; |
| 192031 | 192421 | pTarget[j+1].jnFlags |= JNODE_PATCH; |
| 192032 | 192422 | } |
| 192033 | 192423 | } |
| 192034 | 192424 | break; |
| | @@ -192040,13 +192430,18 @@ |
| 192040 | 192430 | jsonParseAddNode(pParse, JSON_STRING, nKey, zKey); |
| 192041 | 192431 | iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0); |
| 192042 | 192432 | if( pParse->oom ) return 0; |
| 192043 | 192433 | jsonRemoveAllNulls(pPatch); |
| 192044 | 192434 | pTarget = &pParse->aNode[iTarget]; |
| 192435 | + assert( pParse->aNode[iRoot].eU==0 || pParse->aNode[iRoot].eU==2 ); |
| 192436 | + testcase( pParse->aNode[iRoot].eU==2 ); |
| 192045 | 192437 | pParse->aNode[iRoot].jnFlags |= JNODE_APPEND; |
| 192438 | + VVA( pParse->aNode[iRoot].eU = 2 ); |
| 192046 | 192439 | pParse->aNode[iRoot].u.iAppend = iStart - iRoot; |
| 192047 | 192440 | iRoot = iStart; |
| 192441 | + assert( pParse->aNode[iPatch].eU==0 ); |
| 192442 | + VVA( pParse->aNode[iPatch].eU = 5 ); |
| 192048 | 192443 | pParse->aNode[iPatch].jnFlags |= JNODE_PATCH; |
| 192049 | 192444 | pParse->aNode[iPatch].u.pPatch = &pPatch[i+1]; |
| 192050 | 192445 | } |
| 192051 | 192446 | } |
| 192052 | 192447 | return pTarget; |
| | @@ -192184,15 +192579,19 @@ |
| 192184 | 192579 | for(i=1; i<(u32)argc; i+=2){ |
| 192185 | 192580 | zPath = (const char*)sqlite3_value_text(argv[i]); |
| 192186 | 192581 | pNode = jsonLookup(&x, zPath, 0, ctx); |
| 192187 | 192582 | if( x.nErr ) goto replace_err; |
| 192188 | 192583 | if( pNode ){ |
| 192584 | + assert( pNode->eU==0 || pNode->eU==1 || pNode->eU==4 ); |
| 192585 | + json_testcase( pNode->eU!=0 && pNode->eU!=1 ); |
| 192189 | 192586 | pNode->jnFlags |= (u8)JNODE_REPLACE; |
| 192587 | + VVA( pNode->eU = 4 ); |
| 192190 | 192588 | pNode->u.iReplace = i + 1; |
| 192191 | 192589 | } |
| 192192 | 192590 | } |
| 192193 | 192591 | if( x.aNode[0].jnFlags & JNODE_REPLACE ){ |
| 192592 | + assert( x.aNode[0].eU==4 ); |
| 192194 | 192593 | sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); |
| 192195 | 192594 | }else{ |
| 192196 | 192595 | jsonReturnJson(x.aNode, ctx, argv); |
| 192197 | 192596 | } |
| 192198 | 192597 | replace_err: |
| | @@ -192238,15 +192637,19 @@ |
| 192238 | 192637 | sqlite3_result_error_nomem(ctx); |
| 192239 | 192638 | goto jsonSetDone; |
| 192240 | 192639 | }else if( x.nErr ){ |
| 192241 | 192640 | goto jsonSetDone; |
| 192242 | 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 ); |
| 192243 | 192645 | pNode->jnFlags |= (u8)JNODE_REPLACE; |
| 192244 | 192646 | pNode->u.iReplace = i + 1; |
| 192245 | 192647 | } |
| 192246 | 192648 | } |
| 192247 | 192649 | if( x.aNode[0].jnFlags & JNODE_REPLACE ){ |
| 192650 | + assert( x.aNode[0].eU==4 ); |
| 192248 | 192651 | sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); |
| 192249 | 192652 | }else{ |
| 192250 | 192653 | jsonReturnJson(x.aNode, ctx, argv); |
| 192251 | 192654 | } |
| 192252 | 192655 | jsonSetDone: |
| | @@ -192593,10 +192996,13 @@ |
| 192593 | 192996 | if( p->i<p->iEnd ){ |
| 192594 | 192997 | u32 iUp = p->sParse.aUp[p->i]; |
| 192595 | 192998 | JsonNode *pUp = &p->sParse.aNode[iUp]; |
| 192596 | 192999 | p->eType = pUp->eType; |
| 192597 | 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 ); |
| 192598 | 193004 | if( iUp==p->i-1 ){ |
| 192599 | 193005 | pUp->u.iKey = 0; |
| 192600 | 193006 | }else{ |
| 192601 | 193007 | pUp->u.iKey++; |
| 192602 | 193008 | } |
| | @@ -192639,16 +193045,19 @@ |
| 192639 | 193045 | iUp = p->sParse.aUp[i]; |
| 192640 | 193046 | jsonEachComputePath(p, pStr, iUp); |
| 192641 | 193047 | pNode = &p->sParse.aNode[i]; |
| 192642 | 193048 | pUp = &p->sParse.aNode[iUp]; |
| 192643 | 193049 | if( pUp->eType==JSON_ARRAY ){ |
| 193050 | + assert( pUp->eU==3 || (pUp->eU==0 && pUp->u.iKey==0) ); |
| 193051 | + testcase( pUp->eU==0 ); |
| 192644 | 193052 | jsonPrintf(30, pStr, "[%d]", pUp->u.iKey); |
| 192645 | 193053 | }else{ |
| 192646 | 193054 | assert( pUp->eType==JSON_OBJECT ); |
| 192647 | 193055 | if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--; |
| 192648 | 193056 | assert( pNode->eType==JSON_STRING ); |
| 192649 | 193057 | assert( pNode->jnFlags & JNODE_LABEL ); |
| 193058 | + assert( pNode->eU==1 ); |
| 192650 | 193059 | jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1); |
| 192651 | 193060 | } |
| 192652 | 193061 | } |
| 192653 | 193062 | |
| 192654 | 193063 | /* Return the value of a column */ |
| | @@ -192666,10 +193075,11 @@ |
| 192666 | 193075 | jsonReturn(pThis, ctx, 0); |
| 192667 | 193076 | }else if( p->eType==JSON_ARRAY ){ |
| 192668 | 193077 | u32 iKey; |
| 192669 | 193078 | if( p->bRecursive ){ |
| 192670 | 193079 | if( p->iRowid==0 ) break; |
| 193080 | + assert( p->sParse.aNode[p->sParse.aUp[p->i]].eU==3 ); |
| 192671 | 193081 | iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey; |
| 192672 | 193082 | }else{ |
| 192673 | 193083 | iKey = p->iRowid; |
| 192674 | 193084 | } |
| 192675 | 193085 | sqlite3_result_int64(ctx, (sqlite3_int64)iKey); |
| | @@ -192715,10 +193125,11 @@ |
| 192715 | 193125 | jsonAppendChar(&x, '$'); |
| 192716 | 193126 | } |
| 192717 | 193127 | if( p->eType==JSON_ARRAY ){ |
| 192718 | 193128 | jsonPrintf(30, &x, "[%d]", p->iRowid); |
| 192719 | 193129 | }else if( p->eType==JSON_OBJECT ){ |
| 193130 | + assert( pThis->eU==1 ); |
| 192720 | 193131 | jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1); |
| 192721 | 193132 | } |
| 192722 | 193133 | } |
| 192723 | 193134 | jsonResult(&x); |
| 192724 | 193135 | break; |
| | @@ -192782,10 +193193,11 @@ |
| 192782 | 193193 | int iCol; |
| 192783 | 193194 | int iMask; |
| 192784 | 193195 | if( pConstraint->iColumn < JEACH_JSON ) continue; |
| 192785 | 193196 | iCol = pConstraint->iColumn - JEACH_JSON; |
| 192786 | 193197 | assert( iCol==0 || iCol==1 ); |
| 193198 | + testcase( iCol==0 ); |
| 192787 | 193199 | iMask = 1 << iCol; |
| 192788 | 193200 | if( pConstraint->usable==0 ){ |
| 192789 | 193201 | unusableMask |= iMask; |
| 192790 | 193202 | }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){ |
| 192791 | 193203 | aIdx[iCol] = i; |
| | @@ -192879,10 +193291,12 @@ |
| 192879 | 193291 | pNode = p->sParse.aNode; |
| 192880 | 193292 | } |
| 192881 | 193293 | p->iBegin = p->i = (int)(pNode - p->sParse.aNode); |
| 192882 | 193294 | p->eType = pNode->eType; |
| 192883 | 193295 | if( p->eType>=JSON_ARRAY ){ |
| 193296 | + assert( pNode->eU==0 ); |
| 193297 | + VVA( pNode->eU = 3 ); |
| 192884 | 193298 | pNode->u.iKey = 0; |
| 192885 | 193299 | p->iEnd = p->i + pNode->n + 1; |
| 192886 | 193300 | if( p->bRecursive ){ |
| 192887 | 193301 | p->eType = p->sParse.aNode[p->sParse.aUp[p->i]].eType; |
| 192888 | 193302 | if( p->i>0 && (p->sParse.aNode[p->i-1].jnFlags & JNODE_LABEL)!=0 ){ |
| | @@ -193493,11 +193907,11 @@ |
| 193493 | 193907 | |
| 193494 | 193908 | /* The testcase() macro should already be defined in the amalgamation. If |
| 193495 | 193909 | ** it is not, make it a no-op. |
| 193496 | 193910 | */ |
| 193497 | 193911 | #ifndef SQLITE_AMALGAMATION |
| 193498 | | -# ifdef SQLITE_COVERAGE_TEST |
| 193912 | +# if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) |
| 193499 | 193913 | unsigned int sqlite3RtreeTestcase = 0; |
| 193500 | 193914 | # define testcase(X) if( X ){ sqlite3RtreeTestcase += __LINE__; } |
| 193501 | 193915 | # else |
| 193502 | 193916 | # define testcase(X) |
| 193503 | 193917 | # endif |
| | @@ -214008,11 +214422,11 @@ |
| 214008 | 214422 | |
| 214009 | 214423 | /* |
| 214010 | 214424 | ** A version of memcmp() that does not cause asan errors if one of the pointer |
| 214011 | 214425 | ** parameters is NULL and the number of bytes to compare is zero. |
| 214012 | 214426 | */ |
| 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))) |
| 214014 | 214428 | |
| 214015 | 214429 | /* Mark a function parameter as unused, to suppress nuisance compiler |
| 214016 | 214430 | ** warnings. */ |
| 214017 | 214431 | #ifndef UNUSED_PARAM |
| 214018 | 214432 | # define UNUSED_PARAM(X) (void)(X) |
| | @@ -217034,11 +217448,10 @@ |
| 217034 | 217448 | int *pRc, |
| 217035 | 217449 | Fts5Buffer *pBuf, |
| 217036 | 217450 | u32 nData, |
| 217037 | 217451 | const u8 *pData |
| 217038 | 217452 | ){ |
| 217039 | | - assert_nc( *pRc || nData>=0 ); |
| 217040 | 217453 | if( nData ){ |
| 217041 | 217454 | if( fts5BufferGrow(pRc, pBuf, nData) ) return; |
| 217042 | 217455 | memcpy(&pBuf->p[pBuf->n], pData, nData); |
| 217043 | 217456 | pBuf->n += nData; |
| 217044 | 217457 | } |
| | @@ -217146,11 +217559,10 @@ |
| 217146 | 217559 | return 1; |
| 217147 | 217560 | }else{ |
| 217148 | 217561 | i64 iOff = *piOff; |
| 217149 | 217562 | u32 iVal; |
| 217150 | 217563 | fts5FastGetVarint32(a, i, iVal); |
| 217151 | | - assert( iVal>=0 ); |
| 217152 | 217564 | if( iVal<=1 ){ |
| 217153 | 217565 | if( iVal==0 ){ |
| 217154 | 217566 | *pi = i; |
| 217155 | 217567 | return 0; |
| 217156 | 217568 | } |
| | @@ -221761,11 +222173,11 @@ |
| 221761 | 222173 | if( iCol>=0 ){ |
| 221762 | 222174 | if( pHash->eDetail==FTS5_DETAIL_NONE ){ |
| 221763 | 222175 | p->bContent = 1; |
| 221764 | 222176 | }else{ |
| 221765 | 222177 | /* Append a new column value, if necessary */ |
| 221766 | | - assert( iCol>=p->iCol ); |
| 222178 | + assert_nc( iCol>=p->iCol ); |
| 221767 | 222179 | if( iCol!=p->iCol ){ |
| 221768 | 222180 | if( pHash->eDetail==FTS5_DETAIL_FULL ){ |
| 221769 | 222181 | pPtr[p->nData++] = 0x01; |
| 221770 | 222182 | p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol); |
| 221771 | 222183 | p->iCol = (i16)iCol; |
| | @@ -222566,12 +222978,15 @@ |
| 222566 | 222978 | ** +ve if pRight is smaller than pLeft. In other words: |
| 222567 | 222979 | ** |
| 222568 | 222980 | ** res = *pLeft - *pRight |
| 222569 | 222981 | */ |
| 222570 | 222982 | 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); |
| 222573 | 222988 | return (res==0 ? (pLeft->n - pRight->n) : res); |
| 222574 | 222989 | } |
| 222575 | 222990 | |
| 222576 | 222991 | static int fts5LeafFirstTermOff(Fts5Data *pLeaf){ |
| 222577 | 222992 | int ret; |
| | @@ -224244,25 +224659,24 @@ |
| 224244 | 224659 | Fts5Index *p, /* Leave any error code here */ |
| 224245 | 224660 | int bGe, /* True for a >= search */ |
| 224246 | 224661 | Fts5SegIter *pIter, /* Iterator to seek */ |
| 224247 | 224662 | const u8 *pTerm, int nTerm /* Term to search for */ |
| 224248 | 224663 | ){ |
| 224249 | | - int iOff; |
| 224664 | + u32 iOff; |
| 224250 | 224665 | 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; |
| 224253 | 224667 | |
| 224254 | 224668 | u32 nMatch = 0; |
| 224255 | 224669 | u32 nKeep = 0; |
| 224256 | 224670 | u32 nNew = 0; |
| 224257 | 224671 | u32 iTermOff; |
| 224258 | | - int iPgidx; /* Current offset in pgidx */ |
| 224672 | + u32 iPgidx; /* Current offset in pgidx */ |
| 224259 | 224673 | int bEndOfPage = 0; |
| 224260 | 224674 | |
| 224261 | 224675 | assert( p->rc==SQLITE_OK ); |
| 224262 | 224676 | |
| 224263 | | - iPgidx = szLeaf; |
| 224677 | + iPgidx = (u32)pIter->pLeaf->szLeaf; |
| 224264 | 224678 | iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff); |
| 224265 | 224679 | iOff = iTermOff; |
| 224266 | 224680 | if( iOff>n ){ |
| 224267 | 224681 | p->rc = FTS5_CORRUPT; |
| 224268 | 224682 | return; |
| | @@ -224324,19 +224738,19 @@ |
| 224324 | 224738 | do { |
| 224325 | 224739 | fts5SegIterNextPage(p, pIter); |
| 224326 | 224740 | if( pIter->pLeaf==0 ) return; |
| 224327 | 224741 | a = pIter->pLeaf->p; |
| 224328 | 224742 | if( fts5LeafIsTermless(pIter->pLeaf)==0 ){ |
| 224329 | | - iPgidx = pIter->pLeaf->szLeaf; |
| 224743 | + iPgidx = (u32)pIter->pLeaf->szLeaf; |
| 224330 | 224744 | iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff); |
| 224331 | | - if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){ |
| 224745 | + if( iOff<4 || (i64)iOff>=pIter->pLeaf->szLeaf ){ |
| 224332 | 224746 | p->rc = FTS5_CORRUPT; |
| 224333 | 224747 | return; |
| 224334 | 224748 | }else{ |
| 224335 | 224749 | nKeep = 0; |
| 224336 | 224750 | iTermOff = iOff; |
| 224337 | | - n = pIter->pLeaf->nn; |
| 224751 | + n = (u32)pIter->pLeaf->nn; |
| 224338 | 224752 | iOff += fts5GetVarint32(&a[iOff], nNew); |
| 224339 | 224753 | break; |
| 224340 | 224754 | } |
| 224341 | 224755 | } |
| 224342 | 224756 | }while( 1 ); |
| | @@ -231573,11 +231987,11 @@ |
| 231573 | 231987 | int nArg, /* Number of args */ |
| 231574 | 231988 | sqlite3_value **apUnused /* Function arguments */ |
| 231575 | 231989 | ){ |
| 231576 | 231990 | assert( nArg==0 ); |
| 231577 | 231991 | 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); |
| 231579 | 231993 | } |
| 231580 | 231994 | |
| 231581 | 231995 | /* |
| 231582 | 231996 | ** Return true if zName is the extension on one of the shadow tables used |
| 231583 | 231997 | ** by this module. |
| 231584 | 231998 | |