| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.17.0. By combining all the individual C code files into this |
| 3 | +** version 3.18.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -389,20 +389,20 @@ |
| 389 | 389 | ** SQLite source code has been stored in the |
| 390 | 390 | ** <a href="http://www.fossil-scm.org/">Fossil configuration management |
| 391 | 391 | ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to |
| 392 | 392 | ** a string which identifies a particular check-in of SQLite |
| 393 | 393 | ** within its configuration management system. ^The SQLITE_SOURCE_ID |
| 394 | | -** string contains the date and time of the check-in (UTC) and an SHA1 |
| 395 | | -** hash of the entire source tree. |
| 394 | +** string contains the date and time of the check-in (UTC) and a SHA1 |
| 395 | +** or SHA3-256 hash of the entire source tree. |
| 396 | 396 | ** |
| 397 | 397 | ** See also: [sqlite3_libversion()], |
| 398 | 398 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 399 | 399 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 400 | 400 | */ |
| 401 | | -#define SQLITE_VERSION "3.17.0" |
| 402 | | -#define SQLITE_VERSION_NUMBER 3017000 |
| 403 | | -#define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c" |
| 401 | +#define SQLITE_VERSION "3.18.0" |
| 402 | +#define SQLITE_VERSION_NUMBER 3018000 |
| 403 | +#define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37" |
| 404 | 404 | |
| 405 | 405 | /* |
| 406 | 406 | ** CAPI3REF: Run-Time Library Version Numbers |
| 407 | 407 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 408 | 408 | ** |
| | @@ -2315,24 +2315,34 @@ |
| 2315 | 2315 | ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those |
| 2316 | 2316 | ** names are not also used by explicitly declared columns. ^If |
| 2317 | 2317 | ** the table has a column of type [INTEGER PRIMARY KEY] then that column |
| 2318 | 2318 | ** is another alias for the rowid. |
| 2319 | 2319 | ** |
| 2320 | | -** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the |
| 2321 | | -** most recent successful [INSERT] into a rowid table or [virtual table] |
| 2322 | | -** on database connection D. |
| 2323 | | -** ^Inserts into [WITHOUT ROWID] tables are not recorded. |
| 2324 | | -** ^If no successful [INSERT]s into rowid tables |
| 2325 | | -** have ever occurred on the database connection D, |
| 2326 | | -** then sqlite3_last_insert_rowid(D) returns zero. |
| 2320 | +** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of |
| 2321 | +** the most recent successful [INSERT] into a rowid table or [virtual table] |
| 2322 | +** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not |
| 2323 | +** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred |
| 2324 | +** on the database connection D, then sqlite3_last_insert_rowid(D) returns |
| 2325 | +** zero. |
| 2327 | 2326 | ** |
| 2328 | | -** ^(If an [INSERT] occurs within a trigger or within a [virtual table] |
| 2329 | | -** method, then this routine will return the [rowid] of the inserted |
| 2330 | | -** row as long as the trigger or virtual table method is running. |
| 2331 | | -** But once the trigger or virtual table method ends, the value returned |
| 2332 | | -** by this routine reverts to what it was before the trigger or virtual |
| 2333 | | -** table method began.)^ |
| 2327 | +** As well as being set automatically as rows are inserted into database |
| 2328 | +** tables, the value returned by this function may be set explicitly by |
| 2329 | +** [sqlite3_set_last_insert_rowid()] |
| 2330 | +** |
| 2331 | +** Some virtual table implementations may INSERT rows into rowid tables as |
| 2332 | +** part of committing a transaction (e.g. to flush data accumulated in memory |
| 2333 | +** to disk). In this case subsequent calls to this function return the rowid |
| 2334 | +** associated with these internal INSERT operations, which leads to |
| 2335 | +** unintuitive results. Virtual table implementations that do write to rowid |
| 2336 | +** tables in this way can avoid this problem by restoring the original |
| 2337 | +** rowid value using [sqlite3_set_last_insert_rowid()] before returning |
| 2338 | +** control to the user. |
| 2339 | +** |
| 2340 | +** ^(If an [INSERT] occurs within a trigger then this routine will |
| 2341 | +** return the [rowid] of the inserted row as long as the trigger is |
| 2342 | +** running. Once the trigger program ends, the value returned |
| 2343 | +** by this routine reverts to what it was before the trigger was fired.)^ |
| 2334 | 2344 | ** |
| 2335 | 2345 | ** ^An [INSERT] that fails due to a constraint violation is not a |
| 2336 | 2346 | ** successful [INSERT] and does not change the value returned by this |
| 2337 | 2347 | ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, |
| 2338 | 2348 | ** and INSERT OR ABORT make no changes to the return value of this |
| | @@ -2355,10 +2365,20 @@ |
| 2355 | 2365 | ** unpredictable and might not equal either the old or the new |
| 2356 | 2366 | ** last insert [rowid]. |
| 2357 | 2367 | */ |
| 2358 | 2368 | SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); |
| 2359 | 2369 | |
| 2370 | +/* |
| 2371 | +** CAPI3REF: Set the Last Insert Rowid value. |
| 2372 | +** METHOD: sqlite3 |
| 2373 | +** |
| 2374 | +** The sqlite3_set_last_insert_rowid(D, R) method allows the application to |
| 2375 | +** set the value returned by calling sqlite3_last_insert_rowid(D) to R |
| 2376 | +** without inserting a row into the database. |
| 2377 | +*/ |
| 2378 | +SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64); |
| 2379 | + |
| 2360 | 2380 | /* |
| 2361 | 2381 | ** CAPI3REF: Count The Number Of Rows Modified |
| 2362 | 2382 | ** METHOD: sqlite3 |
| 2363 | 2383 | ** |
| 2364 | 2384 | ** ^This function returns the number of rows modified, inserted or |
| | @@ -3679,13 +3699,13 @@ |
| 3679 | 3699 | ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> |
| 3680 | 3700 | ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ |
| 3681 | 3701 | ** |
| 3682 | 3702 | ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> |
| 3683 | 3703 | ** <dd>The maximum number of instructions in a virtual machine program |
| 3684 | | -** used to implement an SQL statement. This limit is not currently |
| 3685 | | -** enforced, though that might be added in some future release of |
| 3686 | | -** SQLite.</dd>)^ |
| 3704 | +** used to implement an SQL statement. If [sqlite3_prepare_v2()] or |
| 3705 | +** the equivalent tries to allocate space for more than this many opcodes |
| 3706 | +** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^ |
| 3687 | 3707 | ** |
| 3688 | 3708 | ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> |
| 3689 | 3709 | ** <dd>The maximum number of arguments on a function.</dd>)^ |
| 3690 | 3710 | ** |
| 3691 | 3711 | ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> |
| | @@ -3718,10 +3738,11 @@ |
| 3718 | 3738 | #define SQLITE_LIMIT_ATTACHED 7 |
| 3719 | 3739 | #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 |
| 3720 | 3740 | #define SQLITE_LIMIT_VARIABLE_NUMBER 9 |
| 3721 | 3741 | #define SQLITE_LIMIT_TRIGGER_DEPTH 10 |
| 3722 | 3742 | #define SQLITE_LIMIT_WORKER_THREADS 11 |
| 3743 | + |
| 3723 | 3744 | |
| 3724 | 3745 | /* |
| 3725 | 3746 | ** CAPI3REF: Compiling An SQL Statement |
| 3726 | 3747 | ** KEYWORDS: {SQL statement compiler} |
| 3727 | 3748 | ** METHOD: sqlite3 |
| | @@ -10846,11 +10867,11 @@ |
| 10846 | 10867 | /* |
| 10847 | 10868 | ** The maximum number of opcodes in a VDBE program. |
| 10848 | 10869 | ** Not currently enforced. |
| 10849 | 10870 | */ |
| 10850 | 10871 | #ifndef SQLITE_MAX_VDBE_OP |
| 10851 | | -# define SQLITE_MAX_VDBE_OP 25000 |
| 10872 | +# define SQLITE_MAX_VDBE_OP 250000000 |
| 10852 | 10873 | #endif |
| 10853 | 10874 | |
| 10854 | 10875 | /* |
| 10855 | 10876 | ** The maximum number of arguments to an SQL function. |
| 10856 | 10877 | */ |
| | @@ -12457,10 +12478,11 @@ |
| 12457 | 12478 | SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); |
| 12458 | 12479 | SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*); |
| 12459 | 12480 | |
| 12460 | 12481 | SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); |
| 12461 | 12482 | SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); |
| 12483 | +SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*); |
| 12462 | 12484 | |
| 12463 | 12485 | #ifndef SQLITE_OMIT_INCRBLOB |
| 12464 | 12486 | SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*); |
| 12465 | 12487 | SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); |
| 12466 | 12488 | SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); |
| | @@ -12623,10 +12645,11 @@ |
| 12623 | 12645 | struct SubProgram { |
| 12624 | 12646 | VdbeOp *aOp; /* Array of opcodes for sub-program */ |
| 12625 | 12647 | int nOp; /* Elements in aOp[] */ |
| 12626 | 12648 | int nMem; /* Number of memory cells required */ |
| 12627 | 12649 | int nCsr; /* Number of cursors required */ |
| 12650 | + u8 *aOnce; /* Array of OP_Once flags */ |
| 12628 | 12651 | void *token; /* id that may be used to recursive triggers */ |
| 12629 | 12652 | SubProgram *pNext; /* Next sub-program already visited */ |
| 12630 | 12653 | }; |
| 12631 | 12654 | |
| 12632 | 12655 | /* |
| | @@ -12757,117 +12780,119 @@ |
| 12757 | 12780 | #define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 12758 | 12781 | #define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 12759 | 12782 | #define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 12760 | 12783 | #define OP_Last 53 |
| 12761 | 12784 | #define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 12762 | | -#define OP_SorterSort 55 |
| 12763 | | -#define OP_Sort 56 |
| 12764 | | -#define OP_Rewind 57 |
| 12765 | | -#define OP_IdxLE 58 /* synopsis: key=r[P3@P4] */ |
| 12766 | | -#define OP_IdxGT 59 /* synopsis: key=r[P3@P4] */ |
| 12767 | | -#define OP_IdxLT 60 /* synopsis: key=r[P3@P4] */ |
| 12768 | | -#define OP_IdxGE 61 /* synopsis: key=r[P3@P4] */ |
| 12769 | | -#define OP_RowSetRead 62 /* synopsis: r[P3]=rowset(P1) */ |
| 12770 | | -#define OP_RowSetTest 63 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 12771 | | -#define OP_Program 64 |
| 12772 | | -#define OP_FkIfZero 65 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 12773 | | -#define OP_IfPos 66 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 12774 | | -#define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 12775 | | -#define OP_DecrJumpZero 68 /* synopsis: if (--r[P1])==0 goto P2 */ |
| 12776 | | -#define OP_IncrVacuum 69 |
| 12777 | | -#define OP_VNext 70 |
| 12778 | | -#define OP_Init 71 /* synopsis: Start at P2 */ |
| 12779 | | -#define OP_Return 72 |
| 12780 | | -#define OP_EndCoroutine 73 |
| 12781 | | -#define OP_HaltIfNull 74 /* synopsis: if r[P3]=null halt */ |
| 12782 | | -#define OP_Halt 75 |
| 12783 | | -#define OP_Integer 76 /* synopsis: r[P2]=P1 */ |
| 12784 | | -#define OP_Int64 77 /* synopsis: r[P2]=P4 */ |
| 12785 | | -#define OP_String 78 /* synopsis: r[P2]='P4' (len=P1) */ |
| 12786 | | -#define OP_Null 79 /* synopsis: r[P2..P3]=NULL */ |
| 12787 | | -#define OP_SoftNull 80 /* synopsis: r[P1]=NULL */ |
| 12788 | | -#define OP_Blob 81 /* synopsis: r[P2]=P4 (len=P1) */ |
| 12789 | | -#define OP_Variable 82 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 12790 | | -#define OP_Move 83 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 12791 | | -#define OP_Copy 84 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 12792 | | -#define OP_SCopy 85 /* synopsis: r[P2]=r[P1] */ |
| 12793 | | -#define OP_IntCopy 86 /* synopsis: r[P2]=r[P1] */ |
| 12794 | | -#define OP_ResultRow 87 /* synopsis: output=r[P1@P2] */ |
| 12795 | | -#define OP_CollSeq 88 |
| 12796 | | -#define OP_Function0 89 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12797 | | -#define OP_Function 90 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12798 | | -#define OP_AddImm 91 /* synopsis: r[P1]=r[P1]+P2 */ |
| 12799 | | -#define OP_RealAffinity 92 |
| 12800 | | -#define OP_Cast 93 /* synopsis: affinity(r[P1]) */ |
| 12801 | | -#define OP_Permutation 94 |
| 12802 | | -#define OP_Compare 95 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 12803 | | -#define OP_Column 96 /* synopsis: r[P3]=PX */ |
| 12785 | +#define OP_IfSmaller 55 |
| 12786 | +#define OP_SorterSort 56 |
| 12787 | +#define OP_Sort 57 |
| 12788 | +#define OP_Rewind 58 |
| 12789 | +#define OP_IdxLE 59 /* synopsis: key=r[P3@P4] */ |
| 12790 | +#define OP_IdxGT 60 /* synopsis: key=r[P3@P4] */ |
| 12791 | +#define OP_IdxLT 61 /* synopsis: key=r[P3@P4] */ |
| 12792 | +#define OP_IdxGE 62 /* synopsis: key=r[P3@P4] */ |
| 12793 | +#define OP_RowSetRead 63 /* synopsis: r[P3]=rowset(P1) */ |
| 12794 | +#define OP_RowSetTest 64 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 12795 | +#define OP_Program 65 |
| 12796 | +#define OP_FkIfZero 66 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 12797 | +#define OP_IfPos 67 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 12798 | +#define OP_IfNotZero 68 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 12799 | +#define OP_DecrJumpZero 69 /* synopsis: if (--r[P1])==0 goto P2 */ |
| 12800 | +#define OP_IncrVacuum 70 |
| 12801 | +#define OP_VNext 71 |
| 12802 | +#define OP_Init 72 /* synopsis: Start at P2 */ |
| 12803 | +#define OP_Return 73 |
| 12804 | +#define OP_EndCoroutine 74 |
| 12805 | +#define OP_HaltIfNull 75 /* synopsis: if r[P3]=null halt */ |
| 12806 | +#define OP_Halt 76 |
| 12807 | +#define OP_Integer 77 /* synopsis: r[P2]=P1 */ |
| 12808 | +#define OP_Int64 78 /* synopsis: r[P2]=P4 */ |
| 12809 | +#define OP_String 79 /* synopsis: r[P2]='P4' (len=P1) */ |
| 12810 | +#define OP_Null 80 /* synopsis: r[P2..P3]=NULL */ |
| 12811 | +#define OP_SoftNull 81 /* synopsis: r[P1]=NULL */ |
| 12812 | +#define OP_Blob 82 /* synopsis: r[P2]=P4 (len=P1) */ |
| 12813 | +#define OP_Variable 83 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 12814 | +#define OP_Move 84 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 12815 | +#define OP_Copy 85 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 12816 | +#define OP_SCopy 86 /* synopsis: r[P2]=r[P1] */ |
| 12817 | +#define OP_IntCopy 87 /* synopsis: r[P2]=r[P1] */ |
| 12818 | +#define OP_ResultRow 88 /* synopsis: output=r[P1@P2] */ |
| 12819 | +#define OP_CollSeq 89 |
| 12820 | +#define OP_Function0 90 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12821 | +#define OP_Function 91 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12822 | +#define OP_AddImm 92 /* synopsis: r[P1]=r[P1]+P2 */ |
| 12823 | +#define OP_RealAffinity 93 |
| 12824 | +#define OP_Cast 94 /* synopsis: affinity(r[P1]) */ |
| 12825 | +#define OP_Permutation 95 |
| 12826 | +#define OP_Compare 96 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 12804 | 12827 | #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 12805 | | -#define OP_Affinity 98 /* synopsis: affinity(r[P1@P2]) */ |
| 12806 | | -#define OP_MakeRecord 99 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 12807 | | -#define OP_Count 100 /* synopsis: r[P2]=count() */ |
| 12808 | | -#define OP_ReadCookie 101 |
| 12809 | | -#define OP_SetCookie 102 |
| 12810 | | -#define OP_ReopenIdx 103 /* synopsis: root=P2 iDb=P3 */ |
| 12811 | | -#define OP_OpenRead 104 /* synopsis: root=P2 iDb=P3 */ |
| 12812 | | -#define OP_OpenWrite 105 /* synopsis: root=P2 iDb=P3 */ |
| 12813 | | -#define OP_OpenAutoindex 106 /* synopsis: nColumn=P2 */ |
| 12814 | | -#define OP_OpenEphemeral 107 /* synopsis: nColumn=P2 */ |
| 12815 | | -#define OP_SorterOpen 108 |
| 12816 | | -#define OP_SequenceTest 109 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 12817 | | -#define OP_OpenPseudo 110 /* synopsis: P3 columns in r[P2] */ |
| 12818 | | -#define OP_Close 111 |
| 12819 | | -#define OP_ColumnsUsed 112 |
| 12820 | | -#define OP_Sequence 113 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 12821 | | -#define OP_NewRowid 114 /* synopsis: r[P2]=rowid */ |
| 12822 | | -#define OP_Insert 115 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 12823 | | -#define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */ |
| 12824 | | -#define OP_Delete 117 |
| 12825 | | -#define OP_ResetCount 118 |
| 12826 | | -#define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 12827 | | -#define OP_SorterData 120 /* synopsis: r[P2]=data */ |
| 12828 | | -#define OP_RowData 121 /* synopsis: r[P2]=data */ |
| 12829 | | -#define OP_Rowid 122 /* synopsis: r[P2]=rowid */ |
| 12830 | | -#define OP_NullRow 123 |
| 12831 | | -#define OP_SorterInsert 124 /* synopsis: key=r[P2] */ |
| 12832 | | -#define OP_IdxInsert 125 /* synopsis: key=r[P2] */ |
| 12833 | | -#define OP_IdxDelete 126 /* synopsis: key=r[P2@P3] */ |
| 12834 | | -#define OP_Seek 127 /* synopsis: Move P3 to P1.rowid */ |
| 12835 | | -#define OP_IdxRowid 128 /* synopsis: r[P2]=rowid */ |
| 12836 | | -#define OP_Destroy 129 |
| 12837 | | -#define OP_Clear 130 |
| 12838 | | -#define OP_ResetSorter 131 |
| 12828 | +#define OP_Column 98 /* synopsis: r[P3]=PX */ |
| 12829 | +#define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */ |
| 12830 | +#define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 12831 | +#define OP_Count 101 /* synopsis: r[P2]=count() */ |
| 12832 | +#define OP_ReadCookie 102 |
| 12833 | +#define OP_SetCookie 103 |
| 12834 | +#define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */ |
| 12835 | +#define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */ |
| 12836 | +#define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */ |
| 12837 | +#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */ |
| 12838 | +#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */ |
| 12839 | +#define OP_SorterOpen 109 |
| 12840 | +#define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 12841 | +#define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */ |
| 12842 | +#define OP_Close 112 |
| 12843 | +#define OP_ColumnsUsed 113 |
| 12844 | +#define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 12845 | +#define OP_NewRowid 115 /* synopsis: r[P2]=rowid */ |
| 12846 | +#define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 12847 | +#define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */ |
| 12848 | +#define OP_Delete 118 |
| 12849 | +#define OP_ResetCount 119 |
| 12850 | +#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 12851 | +#define OP_SorterData 121 /* synopsis: r[P2]=data */ |
| 12852 | +#define OP_RowData 122 /* synopsis: r[P2]=data */ |
| 12853 | +#define OP_Rowid 123 /* synopsis: r[P2]=rowid */ |
| 12854 | +#define OP_NullRow 124 |
| 12855 | +#define OP_SorterInsert 125 /* synopsis: key=r[P2] */ |
| 12856 | +#define OP_IdxInsert 126 /* synopsis: key=r[P2] */ |
| 12857 | +#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */ |
| 12858 | +#define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */ |
| 12859 | +#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */ |
| 12860 | +#define OP_Destroy 130 |
| 12861 | +#define OP_Clear 131 |
| 12839 | 12862 | #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 12840 | | -#define OP_CreateIndex 133 /* synopsis: r[P2]=root iDb=P1 */ |
| 12841 | | -#define OP_CreateTable 134 /* synopsis: r[P2]=root iDb=P1 */ |
| 12842 | | -#define OP_ParseSchema 135 |
| 12843 | | -#define OP_LoadAnalysis 136 |
| 12844 | | -#define OP_DropTable 137 |
| 12845 | | -#define OP_DropIndex 138 |
| 12846 | | -#define OP_DropTrigger 139 |
| 12847 | | -#define OP_IntegrityCk 140 |
| 12848 | | -#define OP_RowSetAdd 141 /* synopsis: rowset(P1)=r[P2] */ |
| 12849 | | -#define OP_Param 142 |
| 12850 | | -#define OP_FkCounter 143 /* synopsis: fkctr[P1]+=P2 */ |
| 12851 | | -#define OP_MemMax 144 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 12852 | | -#define OP_OffsetLimit 145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 12853 | | -#define OP_AggStep0 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12854 | | -#define OP_AggStep 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12855 | | -#define OP_AggFinal 148 /* synopsis: accum=r[P1] N=P2 */ |
| 12856 | | -#define OP_Expire 149 |
| 12857 | | -#define OP_TableLock 150 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 12858 | | -#define OP_VBegin 151 |
| 12859 | | -#define OP_VCreate 152 |
| 12860 | | -#define OP_VDestroy 153 |
| 12861 | | -#define OP_VOpen 154 |
| 12862 | | -#define OP_VColumn 155 /* synopsis: r[P3]=vcolumn(P2) */ |
| 12863 | | -#define OP_VRename 156 |
| 12864 | | -#define OP_Pagecount 157 |
| 12865 | | -#define OP_MaxPgcnt 158 |
| 12866 | | -#define OP_CursorHint 159 |
| 12867 | | -#define OP_Noop 160 |
| 12868 | | -#define OP_Explain 161 |
| 12863 | +#define OP_ResetSorter 133 |
| 12864 | +#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */ |
| 12865 | +#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */ |
| 12866 | +#define OP_SqlExec 136 |
| 12867 | +#define OP_ParseSchema 137 |
| 12868 | +#define OP_LoadAnalysis 138 |
| 12869 | +#define OP_DropTable 139 |
| 12870 | +#define OP_DropIndex 140 |
| 12871 | +#define OP_DropTrigger 141 |
| 12872 | +#define OP_IntegrityCk 142 |
| 12873 | +#define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */ |
| 12874 | +#define OP_Param 144 |
| 12875 | +#define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */ |
| 12876 | +#define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 12877 | +#define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 12878 | +#define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12879 | +#define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12880 | +#define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */ |
| 12881 | +#define OP_Expire 151 |
| 12882 | +#define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 12883 | +#define OP_VBegin 153 |
| 12884 | +#define OP_VCreate 154 |
| 12885 | +#define OP_VDestroy 155 |
| 12886 | +#define OP_VOpen 156 |
| 12887 | +#define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */ |
| 12888 | +#define OP_VRename 158 |
| 12889 | +#define OP_Pagecount 159 |
| 12890 | +#define OP_MaxPgcnt 160 |
| 12891 | +#define OP_CursorHint 161 |
| 12892 | +#define OP_Noop 162 |
| 12893 | +#define OP_Explain 163 |
| 12869 | 12894 | |
| 12870 | 12895 | /* Properties such as "out2" or "jump" that are specified in |
| 12871 | 12896 | ** comments following the "case" for each opcode in the vdbe.c |
| 12872 | 12897 | ** are encoded into bitvectors as follows: |
| 12873 | 12898 | */ |
| | @@ -12883,32 +12908,32 @@ |
| 12883 | 12908 | /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\ |
| 12884 | 12909 | /* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\ |
| 12885 | 12910 | /* 32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 12886 | 12911 | /* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\ |
| 12887 | 12912 | /* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\ |
| 12888 | | -/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b,\ |
| 12889 | | -/* 64 */ 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01,\ |
| 12890 | | -/* 72 */ 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10,\ |
| 12891 | | -/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 12892 | | -/* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\ |
| 12893 | | -/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 12913 | +/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23,\ |
| 12914 | +/* 64 */ 0x0b, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\ |
| 12915 | +/* 72 */ 0x01, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\ |
| 12916 | +/* 80 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\ |
| 12917 | +/* 88 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\ |
| 12918 | +/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 12894 | 12919 | /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12895 | | -/* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12896 | | -/* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\ |
| 12897 | | -/* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\ |
| 12898 | | -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\ |
| 12899 | | -/* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12900 | | -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 12901 | | -/* 160 */ 0x00, 0x00,} |
| 12920 | +/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 12921 | +/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\ |
| 12922 | +/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\ |
| 12923 | +/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\ |
| 12924 | +/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\ |
| 12925 | +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 12926 | +/* 160 */ 0x10, 0x00, 0x00, 0x00,} |
| 12902 | 12927 | |
| 12903 | 12928 | /* The sqlite3P2Values() routine is able to run faster if it knows |
| 12904 | 12929 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 12905 | 12930 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 12906 | 12931 | ** generated this include file strives to group all JUMP opcodes |
| 12907 | 12932 | ** together near the beginning of the list. |
| 12908 | 12933 | */ |
| 12909 | | -#define SQLITE_MX_JUMP_OPCODE 71 /* Maximum JUMP opcode */ |
| 12934 | +#define SQLITE_MX_JUMP_OPCODE 72 /* Maximum JUMP opcode */ |
| 12910 | 12935 | |
| 12911 | 12936 | /************** End of opcodes.h *********************************************/ |
| 12912 | 12937 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 12913 | 12938 | |
| 12914 | 12939 | /* |
| | @@ -13868,11 +13893,11 @@ |
| 13868 | 13893 | ** The "PRAGMA synchronous" statement also uses the zero-based numbers. |
| 13869 | 13894 | ** In other words, the zero-based numbers are used for all external interfaces |
| 13870 | 13895 | ** and the one-based values are used internally. |
| 13871 | 13896 | */ |
| 13872 | 13897 | #ifndef SQLITE_DEFAULT_SYNCHRONOUS |
| 13873 | | -# define SQLITE_DEFAULT_SYNCHRONOUS (PAGER_SYNCHRONOUS_FULL-1) |
| 13898 | +# define SQLITE_DEFAULT_SYNCHRONOUS 2 |
| 13874 | 13899 | #endif |
| 13875 | 13900 | #ifndef SQLITE_DEFAULT_WAL_SYNCHRONOUS |
| 13876 | 13901 | # define SQLITE_DEFAULT_WAL_SYNCHRONOUS SQLITE_DEFAULT_SYNCHRONOUS |
| 13877 | 13902 | #endif |
| 13878 | 13903 | |
| | @@ -14074,10 +14099,11 @@ |
| 14074 | 14099 | u8 suppressErr; /* Do not issue error messages if true */ |
| 14075 | 14100 | u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ |
| 14076 | 14101 | u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */ |
| 14077 | 14102 | u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 14078 | 14103 | u8 skipBtreeMutex; /* True if no shared-cache backends */ |
| 14104 | + u8 nSqlExec; /* Number of pending OP_SqlExec opcodes */ |
| 14079 | 14105 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 14080 | 14106 | u32 magic; /* Magic number for detect library misuse */ |
| 14081 | 14107 | int nChange; /* Value returned by sqlite3_changes() */ |
| 14082 | 14108 | int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 14083 | 14109 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| | @@ -14589,18 +14615,18 @@ |
| 14589 | 14615 | char *zColAff; /* String defining the affinity of each column */ |
| 14590 | 14616 | ExprList *pCheck; /* All CHECK constraints */ |
| 14591 | 14617 | /* ... also used as column name list in a VIEW */ |
| 14592 | 14618 | int tnum; /* Root BTree page for this table */ |
| 14593 | 14619 | u32 nTabRef; /* Number of pointers to this Table */ |
| 14620 | + u32 tabFlags; /* Mask of TF_* values */ |
| 14594 | 14621 | i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */ |
| 14595 | 14622 | i16 nCol; /* Number of columns in this table */ |
| 14596 | 14623 | LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */ |
| 14597 | 14624 | LogEst szTabRow; /* Estimated size of each table row in bytes */ |
| 14598 | 14625 | #ifdef SQLITE_ENABLE_COSTMULT |
| 14599 | 14626 | LogEst costMult; /* Cost multiplier for using this table */ |
| 14600 | 14627 | #endif |
| 14601 | | - u8 tabFlags; /* Mask of TF_* values */ |
| 14602 | 14628 | u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */ |
| 14603 | 14629 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 14604 | 14630 | int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */ |
| 14605 | 14631 | #endif |
| 14606 | 14632 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -14620,27 +14646,29 @@ |
| 14620 | 14646 | ** followed by non-hidden columns. Example: "CREATE VIRTUAL TABLE x USING |
| 14621 | 14647 | ** vtab1(a HIDDEN, b);". Since "b" is a non-hidden column but "a" is hidden, |
| 14622 | 14648 | ** the TF_OOOHidden attribute would apply in this case. Such tables require |
| 14623 | 14649 | ** special handling during INSERT processing. |
| 14624 | 14650 | */ |
| 14625 | | -#define TF_Readonly 0x01 /* Read-only system table */ |
| 14626 | | -#define TF_Ephemeral 0x02 /* An ephemeral table */ |
| 14627 | | -#define TF_HasPrimaryKey 0x04 /* Table has a primary key */ |
| 14628 | | -#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ |
| 14629 | | -#define TF_Virtual 0x10 /* Is a virtual table */ |
| 14630 | | -#define TF_WithoutRowid 0x20 /* No rowid. PRIMARY KEY is the key */ |
| 14631 | | -#define TF_NoVisibleRowid 0x40 /* No user-visible "rowid" column */ |
| 14632 | | -#define TF_OOOHidden 0x80 /* Out-of-Order hidden columns */ |
| 14633 | | - |
| 14651 | +#define TF_Readonly 0x0001 /* Read-only system table */ |
| 14652 | +#define TF_Ephemeral 0x0002 /* An ephemeral table */ |
| 14653 | +#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */ |
| 14654 | +#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */ |
| 14655 | +#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */ |
| 14656 | +#define TF_WithoutRowid 0x0020 /* No rowid. PRIMARY KEY is the key */ |
| 14657 | +#define TF_NoVisibleRowid 0x0040 /* No user-visible "rowid" column */ |
| 14658 | +#define TF_OOOHidden 0x0080 /* Out-of-Order hidden columns */ |
| 14659 | +#define TF_StatsUsed 0x0100 /* Query planner decisions affected by |
| 14660 | + ** Index.aiRowLogEst[] values */ |
| 14661 | +#define TF_HasNotNull 0x0200 /* Contains NOT NULL constraints */ |
| 14634 | 14662 | |
| 14635 | 14663 | /* |
| 14636 | 14664 | ** Test to see whether or not a table is a virtual table. This is |
| 14637 | 14665 | ** done as a macro so that it will be optimized out when virtual |
| 14638 | 14666 | ** table support is omitted from the build. |
| 14639 | 14667 | */ |
| 14640 | 14668 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 14641 | | -# define IsVirtual(X) (((X)->tabFlags & TF_Virtual)!=0) |
| 14669 | +# define IsVirtual(X) ((X)->nModuleArg) |
| 14642 | 14670 | #else |
| 14643 | 14671 | # define IsVirtual(X) 0 |
| 14644 | 14672 | #endif |
| 14645 | 14673 | |
| 14646 | 14674 | /* |
| | @@ -14871,10 +14899,11 @@ |
| 14871 | 14899 | unsigned bUnordered:1; /* Use this index for == or IN queries only */ |
| 14872 | 14900 | unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ |
| 14873 | 14901 | unsigned isResized:1; /* True if resizeIndexObject() has been called */ |
| 14874 | 14902 | unsigned isCovering:1; /* True if this is a covering index */ |
| 14875 | 14903 | unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ |
| 14904 | + unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */ |
| 14876 | 14905 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 14877 | 14906 | int nSample; /* Number of elements in aSample[] */ |
| 14878 | 14907 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 14879 | 14908 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 14880 | 14909 | IndexSample *aSample; /* Samples of the left-most key */ |
| | @@ -15181,11 +15210,11 @@ |
| 15181 | 15210 | ** form is used for name resolution with nested FROM clauses. |
| 15182 | 15211 | */ |
| 15183 | 15212 | struct ExprList { |
| 15184 | 15213 | int nExpr; /* Number of expressions on the list */ |
| 15185 | 15214 | struct ExprList_item { /* For each expression in the list */ |
| 15186 | | - Expr *pExpr; /* The list of expressions */ |
| 15215 | + Expr *pExpr; /* The parse tree for this expression */ |
| 15187 | 15216 | char *zName; /* Token associated with this expression */ |
| 15188 | 15217 | char *zSpan; /* Original text of the expression */ |
| 15189 | 15218 | u8 sortOrder; /* 1 for DESC or 0 for ASC */ |
| 15190 | 15219 | unsigned done :1; /* A flag to indicate when processing is finished */ |
| 15191 | 15220 | unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */ |
| | @@ -16504,10 +16533,11 @@ |
| 16504 | 16533 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*); |
| 16505 | 16534 | SQLITE_PRIVATE void sqlite3Vacuum(Parse*,Token*); |
| 16506 | 16535 | SQLITE_PRIVATE int sqlite3RunVacuum(char**, sqlite3*, int); |
| 16507 | 16536 | SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*); |
| 16508 | 16537 | SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*, int); |
| 16538 | +SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int); |
| 16509 | 16539 | SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int); |
| 16510 | 16540 | SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Expr*, Expr*, int); |
| 16511 | 16541 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 16512 | 16542 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 16513 | 16543 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| | @@ -17450,19 +17480,25 @@ |
| 17450 | 17480 | "COMPILER=gcc-" __VERSION__, |
| 17451 | 17481 | #endif |
| 17452 | 17482 | #if SQLITE_COVERAGE_TEST |
| 17453 | 17483 | "COVERAGE_TEST", |
| 17454 | 17484 | #endif |
| 17455 | | -#if SQLITE_DEBUG |
| 17485 | +#ifdef SQLITE_DEBUG |
| 17456 | 17486 | "DEBUG", |
| 17457 | 17487 | #endif |
| 17458 | 17488 | #if SQLITE_DEFAULT_LOCKING_MODE |
| 17459 | 17489 | "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), |
| 17460 | 17490 | #endif |
| 17461 | 17491 | #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc) |
| 17462 | 17492 | "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), |
| 17463 | 17493 | #endif |
| 17494 | +#if SQLITE_DEFAULT_SYNCHRONOUS |
| 17495 | + "DEFAULT_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_SYNCHRONOUS), |
| 17496 | +#endif |
| 17497 | +#if SQLITE_DEFAULT_WAL_SYNCHRONOUS |
| 17498 | + "DEFAULT_WAL_SYNCHRONOUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_WAL_SYNCHRONOUS), |
| 17499 | +#endif |
| 17464 | 17500 | #if SQLITE_DIRECT_OVERFLOW_READ |
| 17465 | 17501 | "DIRECT_OVERFLOW_READ", |
| 17466 | 17502 | #endif |
| 17467 | 17503 | #if SQLITE_DISABLE_DIRSYNC |
| 17468 | 17504 | "DISABLE_DIRSYNC", |
| | @@ -18035,10 +18071,11 @@ |
| 18035 | 18071 | VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */ |
| 18036 | 18072 | Op *aOp; /* Program instructions for parent frame */ |
| 18037 | 18073 | i64 *anExec; /* Event counters from parent frame */ |
| 18038 | 18074 | Mem *aMem; /* Array of memory cells for parent frame */ |
| 18039 | 18075 | VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ |
| 18076 | + u8 *aOnce; /* Bitmask used by OP_Once */ |
| 18040 | 18077 | void *token; /* Copy of SubProgram.token */ |
| 18041 | 18078 | i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ |
| 18042 | 18079 | AuxData *pAuxData; /* Linked list of auxdata allocations */ |
| 18043 | 18080 | int nCursor; /* Number of entries in apCsr */ |
| 18044 | 18081 | int pc; /* Program Counter in parent (calling) frame */ |
| | @@ -19505,22 +19542,23 @@ |
| 19505 | 19542 | ** |
| 19506 | 19543 | ** Move the date backwards to the beginning of the current day, |
| 19507 | 19544 | ** or month or year. |
| 19508 | 19545 | */ |
| 19509 | 19546 | if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break; |
| 19547 | + if( !p->validJD && !p->validYMD && !p->validHMS ) break; |
| 19510 | 19548 | z += 9; |
| 19511 | 19549 | computeYMD(p); |
| 19512 | 19550 | p->validHMS = 1; |
| 19513 | 19551 | p->h = p->m = 0; |
| 19514 | 19552 | p->s = 0.0; |
| 19553 | + p->rawS = 0; |
| 19515 | 19554 | p->validTZ = 0; |
| 19516 | 19555 | p->validJD = 0; |
| 19517 | 19556 | if( sqlite3_stricmp(z,"month")==0 ){ |
| 19518 | 19557 | p->D = 1; |
| 19519 | 19558 | rc = 0; |
| 19520 | 19559 | }else if( sqlite3_stricmp(z,"year")==0 ){ |
| 19521 | | - computeYMD(p); |
| 19522 | 19560 | p->M = 1; |
| 19523 | 19561 | p->D = 1; |
| 19524 | 19562 | rc = 0; |
| 19525 | 19563 | }else if( sqlite3_stricmp(z,"day")==0 ){ |
| 19526 | 19564 | rc = 0; |
| | @@ -20638,11 +20676,13 @@ |
| 20638 | 20676 | ** Use the zone allocator available on apple products unless the |
| 20639 | 20677 | ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined. |
| 20640 | 20678 | */ |
| 20641 | 20679 | #include <sys/sysctl.h> |
| 20642 | 20680 | #include <malloc/malloc.h> |
| 20681 | +#ifdef SQLITE_MIGHT_BE_SINGLE_CORE |
| 20643 | 20682 | #include <libkern/OSAtomic.h> |
| 20683 | +#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */ |
| 20644 | 20684 | static malloc_zone_t* _sqliteZone_; |
| 20645 | 20685 | #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x)) |
| 20646 | 20686 | #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x)); |
| 20647 | 20687 | #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y)) |
| 20648 | 20688 | #define SQLITE_MALLOCSIZE(x) \ |
| | @@ -20831,23 +20871,14 @@ |
| 20831 | 20871 | /* defer MT decisions to system malloc */ |
| 20832 | 20872 | _sqliteZone_ = malloc_default_zone(); |
| 20833 | 20873 | }else{ |
| 20834 | 20874 | /* only 1 core, use our own zone to contention over global locks, |
| 20835 | 20875 | ** e.g. we have our own dedicated locks */ |
| 20836 | | - bool success; |
| 20837 | | - malloc_zone_t* newzone = malloc_create_zone(4096, 0); |
| 20838 | | - malloc_set_zone_name(newzone, "Sqlite_Heap"); |
| 20839 | | - do{ |
| 20840 | | - success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, |
| 20841 | | - (void * volatile *)&_sqliteZone_); |
| 20842 | | - }while(!_sqliteZone_); |
| 20843 | | - if( !success ){ |
| 20844 | | - /* somebody registered a zone first */ |
| 20845 | | - malloc_destroy_zone(newzone); |
| 20846 | | - } |
| 20847 | | - } |
| 20848 | | -#endif |
| 20876 | + _sqliteZone_ = malloc_create_zone(4096, 0); |
| 20877 | + malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap"); |
| 20878 | + } |
| 20879 | +#endif /* defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */ |
| 20849 | 20880 | UNUSED_PARAMETER(NotUsed); |
| 20850 | 20881 | return SQLITE_OK; |
| 20851 | 20882 | } |
| 20852 | 20883 | |
| 20853 | 20884 | /* |
| | @@ -24050,12 +24081,12 @@ |
| 24050 | 24081 | #ifdef SQLITE_DEBUG |
| 24051 | 24082 | assert( p->nRef>0 || p->owner==0 ); |
| 24052 | 24083 | p->owner = tid; |
| 24053 | 24084 | p->nRef++; |
| 24054 | 24085 | if( p->trace ){ |
| 24055 | | - OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n", |
| 24056 | | - tid, p, p->trace, p->nRef)); |
| 24086 | + OSTRACE(("ENTER-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n", |
| 24087 | + tid, p->id, p, p->trace, p->nRef)); |
| 24057 | 24088 | } |
| 24058 | 24089 | #endif |
| 24059 | 24090 | } |
| 24060 | 24091 | |
| 24061 | 24092 | static int winMutexTry(sqlite3_mutex *p){ |
| | @@ -24093,12 +24124,12 @@ |
| 24093 | 24124 | #else |
| 24094 | 24125 | UNUSED_PARAMETER(p); |
| 24095 | 24126 | #endif |
| 24096 | 24127 | #ifdef SQLITE_DEBUG |
| 24097 | 24128 | if( p->trace ){ |
| 24098 | | - OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n", |
| 24099 | | - tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc))); |
| 24129 | + OSTRACE(("TRY-MUTEX tid=%lu, mutex(%d)=%p (%d), owner=%lu, nRef=%d, rc=%s\n", |
| 24130 | + tid, p->id, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc))); |
| 24100 | 24131 | } |
| 24101 | 24132 | #endif |
| 24102 | 24133 | return rc; |
| 24103 | 24134 | } |
| 24104 | 24135 | |
| | @@ -24122,12 +24153,12 @@ |
| 24122 | 24153 | #endif |
| 24123 | 24154 | assert( winMutex_isInit==1 ); |
| 24124 | 24155 | LeaveCriticalSection(&p->mutex); |
| 24125 | 24156 | #ifdef SQLITE_DEBUG |
| 24126 | 24157 | if( p->trace ){ |
| 24127 | | - OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n", |
| 24128 | | - tid, p, p->trace, p->nRef)); |
| 24158 | + OSTRACE(("LEAVE-MUTEX tid=%lu, mutex(%d)=%p (%d), nRef=%d\n", |
| 24159 | + tid, p->id, p, p->trace, p->nRef)); |
| 24129 | 24160 | } |
| 24130 | 24161 | #endif |
| 24131 | 24162 | } |
| 24132 | 24163 | |
| 24133 | 24164 | SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3DefaultMutex(void){ |
| | @@ -24383,10 +24414,17 @@ |
| 24383 | 24414 | ** implementation of malloc_good_size(), which must be called in debug |
| 24384 | 24415 | ** mode and specifically when the DMD "Dark Matter Detector" is enabled |
| 24385 | 24416 | ** or else a crash results. Hence, do not attempt to optimize out the |
| 24386 | 24417 | ** following xRoundup() call. */ |
| 24387 | 24418 | nFull = sqlite3GlobalConfig.m.xRoundup(n); |
| 24419 | + |
| 24420 | +#ifdef SQLITE_MAX_MEMORY |
| 24421 | + if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){ |
| 24422 | + *pp = 0; |
| 24423 | + return; |
| 24424 | + } |
| 24425 | +#endif |
| 24388 | 24426 | |
| 24389 | 24427 | sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n); |
| 24390 | 24428 | if( mem0.alarmThreshold>0 ){ |
| 24391 | 24429 | sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 24392 | 24430 | if( nUsed >= mem0.alarmThreshold - nFull ){ |
| | @@ -24572,11 +24610,11 @@ |
| 24572 | 24610 | return sqlite3GlobalConfig.m.xSize(p); |
| 24573 | 24611 | } |
| 24574 | 24612 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 24575 | 24613 | assert( p!=0 ); |
| 24576 | 24614 | if( db==0 || !isLookaside(db,p) ){ |
| 24577 | | -#if SQLITE_DEBUG |
| 24615 | +#ifdef SQLITE_DEBUG |
| 24578 | 24616 | if( db==0 ){ |
| 24579 | 24617 | assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); |
| 24580 | 24618 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 24581 | 24619 | }else{ |
| 24582 | 24620 | assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| | @@ -24633,11 +24671,11 @@ |
| 24633 | 24671 | measureAllocationSize(db, p); |
| 24634 | 24672 | return; |
| 24635 | 24673 | } |
| 24636 | 24674 | if( isLookaside(db, p) ){ |
| 24637 | 24675 | LookasideSlot *pBuf = (LookasideSlot*)p; |
| 24638 | | -#if SQLITE_DEBUG |
| 24676 | +#ifdef SQLITE_DEBUG |
| 24639 | 24677 | /* Trash all content in the buffer being freed */ |
| 24640 | 24678 | memset(p, 0xaa, db->lookaside.sz); |
| 24641 | 24679 | #endif |
| 24642 | 24680 | pBuf->pNext = db->lookaside.pFree; |
| 24643 | 24681 | db->lookaside.pFree = pBuf; |
| | @@ -25002,11 +25040,11 @@ |
| 25002 | 25040 | |
| 25003 | 25041 | /* |
| 25004 | 25042 | ** Conversion types fall into various categories as defined by the |
| 25005 | 25043 | ** following enumeration. |
| 25006 | 25044 | */ |
| 25007 | | -#define etRADIX 0 /* Integer types. %d, %x, %o, and so forth */ |
| 25045 | +#define etRADIX 0 /* non-decimal integer types. %x %o */ |
| 25008 | 25046 | #define etFLOAT 1 /* Floating point. %f */ |
| 25009 | 25047 | #define etEXP 2 /* Exponentional notation. %e and %E */ |
| 25010 | 25048 | #define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */ |
| 25011 | 25049 | #define etSIZE 4 /* Return number of characters processed so far. %n */ |
| 25012 | 25050 | #define etSTRING 5 /* Strings. %s */ |
| | @@ -25020,12 +25058,13 @@ |
| 25020 | 25058 | #define etTOKEN 11 /* a pointer to a Token structure */ |
| 25021 | 25059 | #define etSRCLIST 12 /* a pointer to a SrcList */ |
| 25022 | 25060 | #define etPOINTER 13 /* The %p conversion */ |
| 25023 | 25061 | #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */ |
| 25024 | 25062 | #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
| 25063 | +#define etDECIMAL 16 /* %d or %u, but not %x, %o */ |
| 25025 | 25064 | |
| 25026 | | -#define etINVALID 16 /* Any unrecognized conversion type */ |
| 25065 | +#define etINVALID 17 /* Any unrecognized conversion type */ |
| 25027 | 25066 | |
| 25028 | 25067 | |
| 25029 | 25068 | /* |
| 25030 | 25069 | ** An "etByte" is an 8-bit unsigned value. |
| 25031 | 25070 | */ |
| | @@ -25045,40 +25084,40 @@ |
| 25045 | 25084 | } et_info; |
| 25046 | 25085 | |
| 25047 | 25086 | /* |
| 25048 | 25087 | ** Allowed values for et_info.flags |
| 25049 | 25088 | */ |
| 25050 | | -#define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 25051 | | -#define FLAG_STRING 4 /* Allow infinity precision */ |
| 25089 | +#define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 25090 | +#define FLAG_STRING 4 /* Allow infinite precision */ |
| 25052 | 25091 | |
| 25053 | 25092 | |
| 25054 | 25093 | /* |
| 25055 | 25094 | ** The following table is searched linearly, so it is good to put the |
| 25056 | 25095 | ** most frequently used conversion types first. |
| 25057 | 25096 | */ |
| 25058 | 25097 | static const char aDigits[] = "0123456789ABCDEF0123456789abcdef"; |
| 25059 | 25098 | static const char aPrefix[] = "-x0\000X0"; |
| 25060 | 25099 | static const et_info fmtinfo[] = { |
| 25061 | | - { 'd', 10, 1, etRADIX, 0, 0 }, |
| 25100 | + { 'd', 10, 1, etDECIMAL, 0, 0 }, |
| 25062 | 25101 | { 's', 0, 4, etSTRING, 0, 0 }, |
| 25063 | 25102 | { 'g', 0, 1, etGENERIC, 30, 0 }, |
| 25064 | 25103 | { 'z', 0, 4, etDYNSTRING, 0, 0 }, |
| 25065 | 25104 | { 'q', 0, 4, etSQLESCAPE, 0, 0 }, |
| 25066 | 25105 | { 'Q', 0, 4, etSQLESCAPE2, 0, 0 }, |
| 25067 | 25106 | { 'w', 0, 4, etSQLESCAPE3, 0, 0 }, |
| 25068 | 25107 | { 'c', 0, 0, etCHARX, 0, 0 }, |
| 25069 | 25108 | { 'o', 8, 0, etRADIX, 0, 2 }, |
| 25070 | | - { 'u', 10, 0, etRADIX, 0, 0 }, |
| 25109 | + { 'u', 10, 0, etDECIMAL, 0, 0 }, |
| 25071 | 25110 | { 'x', 16, 0, etRADIX, 16, 1 }, |
| 25072 | 25111 | { 'X', 16, 0, etRADIX, 0, 4 }, |
| 25073 | 25112 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 25074 | 25113 | { 'f', 0, 1, etFLOAT, 0, 0 }, |
| 25075 | 25114 | { 'e', 0, 1, etEXP, 30, 0 }, |
| 25076 | 25115 | { 'E', 0, 1, etEXP, 14, 0 }, |
| 25077 | 25116 | { 'G', 0, 1, etGENERIC, 14, 0 }, |
| 25078 | 25117 | #endif |
| 25079 | | - { 'i', 10, 1, etRADIX, 0, 0 }, |
| 25118 | + { 'i', 10, 1, etDECIMAL, 0, 0 }, |
| 25080 | 25119 | { 'n', 0, 0, etSIZE, 0, 0 }, |
| 25081 | 25120 | { '%', 0, 0, etPERCENT, 0, 0 }, |
| 25082 | 25121 | { 'p', 16, 0, etPOINTER, 0, 1 }, |
| 25083 | 25122 | |
| 25084 | 25123 | /* All the rest are undocumented and are for internal use only */ |
| | @@ -25166,18 +25205,17 @@ |
| 25166 | 25205 | int precision; /* Precision of the current field */ |
| 25167 | 25206 | int length; /* Length of the field */ |
| 25168 | 25207 | int idx; /* A general purpose loop counter */ |
| 25169 | 25208 | int width; /* Width of the current field */ |
| 25170 | 25209 | etByte flag_leftjustify; /* True if "-" flag is present */ |
| 25171 | | - etByte flag_plussign; /* True if "+" flag is present */ |
| 25172 | | - etByte flag_blanksign; /* True if " " flag is present */ |
| 25210 | + etByte flag_prefix; /* '+' or ' ' or 0 for prefix */ |
| 25173 | 25211 | etByte flag_alternateform; /* True if "#" flag is present */ |
| 25174 | 25212 | etByte flag_altform2; /* True if "!" flag is present */ |
| 25175 | 25213 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 25176 | | - etByte flag_long; /* True if "l" flag is present */ |
| 25177 | | - etByte flag_longlong; /* True if the "ll" flag is present */ |
| 25214 | + etByte flag_long; /* 1 for the "l" flag, 2 for "ll", 0 by default */ |
| 25178 | 25215 | etByte done; /* Loop termination flag */ |
| 25216 | + etByte cThousand; /* Thousands separator for %d and %u */ |
| 25179 | 25217 | etByte xtype = etINVALID; /* Conversion paradigm */ |
| 25180 | 25218 | u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
| 25181 | 25219 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 25182 | 25220 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 25183 | 25221 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| | @@ -25216,21 +25254,22 @@ |
| 25216 | 25254 | if( (c=(*++fmt))==0 ){ |
| 25217 | 25255 | sqlite3StrAccumAppend(pAccum, "%", 1); |
| 25218 | 25256 | break; |
| 25219 | 25257 | } |
| 25220 | 25258 | /* Find out what flags are present */ |
| 25221 | | - flag_leftjustify = flag_plussign = flag_blanksign = |
| 25259 | + flag_leftjustify = flag_prefix = cThousand = |
| 25222 | 25260 | flag_alternateform = flag_altform2 = flag_zeropad = 0; |
| 25223 | 25261 | done = 0; |
| 25224 | 25262 | do{ |
| 25225 | 25263 | switch( c ){ |
| 25226 | 25264 | case '-': flag_leftjustify = 1; break; |
| 25227 | | - case '+': flag_plussign = 1; break; |
| 25228 | | - case ' ': flag_blanksign = 1; break; |
| 25265 | + case '+': flag_prefix = '+'; break; |
| 25266 | + case ' ': flag_prefix = ' '; break; |
| 25229 | 25267 | case '#': flag_alternateform = 1; break; |
| 25230 | 25268 | case '!': flag_altform2 = 1; break; |
| 25231 | 25269 | case '0': flag_zeropad = 1; break; |
| 25270 | + case ',': cThousand = ','; break; |
| 25232 | 25271 | default: done = 1; break; |
| 25233 | 25272 | } |
| 25234 | 25273 | }while( !done && (c=(*++fmt))!=0 ); |
| 25235 | 25274 | /* Get the field width */ |
| 25236 | 25275 | if( c=='*' ){ |
| | @@ -25296,17 +25335,15 @@ |
| 25296 | 25335 | /* Get the conversion type modifier */ |
| 25297 | 25336 | if( c=='l' ){ |
| 25298 | 25337 | flag_long = 1; |
| 25299 | 25338 | c = *++fmt; |
| 25300 | 25339 | if( c=='l' ){ |
| 25301 | | - flag_longlong = 1; |
| 25340 | + flag_long = 2; |
| 25302 | 25341 | c = *++fmt; |
| 25303 | | - }else{ |
| 25304 | | - flag_longlong = 0; |
| 25305 | 25342 | } |
| 25306 | 25343 | }else{ |
| 25307 | | - flag_long = flag_longlong = 0; |
| 25344 | + flag_long = 0; |
| 25308 | 25345 | } |
| 25309 | 25346 | /* Fetch the info entry for the field */ |
| 25310 | 25347 | infop = &fmtinfo[0]; |
| 25311 | 25348 | xtype = etINVALID; |
| 25312 | 25349 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| | @@ -25320,41 +25357,42 @@ |
| 25320 | 25357 | /* |
| 25321 | 25358 | ** At this point, variables are initialized as follows: |
| 25322 | 25359 | ** |
| 25323 | 25360 | ** flag_alternateform TRUE if a '#' is present. |
| 25324 | 25361 | ** flag_altform2 TRUE if a '!' is present. |
| 25325 | | - ** flag_plussign TRUE if a '+' is present. |
| 25362 | + ** flag_prefix '+' or ' ' or zero |
| 25326 | 25363 | ** flag_leftjustify TRUE if a '-' is present or if the |
| 25327 | 25364 | ** field width was negative. |
| 25328 | 25365 | ** flag_zeropad TRUE if the width began with 0. |
| 25329 | | - ** flag_long TRUE if the letter 'l' (ell) prefixed |
| 25330 | | - ** the conversion character. |
| 25331 | | - ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed |
| 25332 | | - ** the conversion character. |
| 25333 | | - ** flag_blanksign TRUE if a ' ' is present. |
| 25366 | + ** flag_long 1 for "l", 2 for "ll" |
| 25334 | 25367 | ** width The specified field width. This is |
| 25335 | 25368 | ** always non-negative. Zero is the default. |
| 25336 | 25369 | ** precision The specified precision. The default |
| 25337 | 25370 | ** is -1. |
| 25338 | 25371 | ** xtype The class of the conversion. |
| 25339 | 25372 | ** infop Pointer to the appropriate info struct. |
| 25340 | 25373 | */ |
| 25341 | 25374 | switch( xtype ){ |
| 25342 | 25375 | case etPOINTER: |
| 25343 | | - flag_longlong = sizeof(char*)==sizeof(i64); |
| 25344 | | - flag_long = sizeof(char*)==sizeof(long int); |
| 25376 | + flag_long = sizeof(char*)==sizeof(i64) ? 2 : |
| 25377 | + sizeof(char*)==sizeof(long int) ? 1 : 0; |
| 25345 | 25378 | /* Fall through into the next case */ |
| 25346 | 25379 | case etORDINAL: |
| 25347 | | - case etRADIX: |
| 25380 | + case etRADIX: |
| 25381 | + cThousand = 0; |
| 25382 | + /* Fall through into the next case */ |
| 25383 | + case etDECIMAL: |
| 25348 | 25384 | if( infop->flags & FLAG_SIGNED ){ |
| 25349 | 25385 | i64 v; |
| 25350 | 25386 | if( bArgList ){ |
| 25351 | 25387 | v = getIntArg(pArgList); |
| 25352 | | - }else if( flag_longlong ){ |
| 25353 | | - v = va_arg(ap,i64); |
| 25354 | 25388 | }else if( flag_long ){ |
| 25355 | | - v = va_arg(ap,long int); |
| 25389 | + if( flag_long==2 ){ |
| 25390 | + v = va_arg(ap,i64) ; |
| 25391 | + }else{ |
| 25392 | + v = va_arg(ap,long int); |
| 25393 | + } |
| 25356 | 25394 | }else{ |
| 25357 | 25395 | v = va_arg(ap,int); |
| 25358 | 25396 | } |
| 25359 | 25397 | if( v<0 ){ |
| 25360 | 25398 | if( v==SMALLEST_INT64 ){ |
| | @@ -25363,40 +25401,41 @@ |
| 25363 | 25401 | longvalue = -v; |
| 25364 | 25402 | } |
| 25365 | 25403 | prefix = '-'; |
| 25366 | 25404 | }else{ |
| 25367 | 25405 | longvalue = v; |
| 25368 | | - if( flag_plussign ) prefix = '+'; |
| 25369 | | - else if( flag_blanksign ) prefix = ' '; |
| 25370 | | - else prefix = 0; |
| 25406 | + prefix = flag_prefix; |
| 25371 | 25407 | } |
| 25372 | 25408 | }else{ |
| 25373 | 25409 | if( bArgList ){ |
| 25374 | 25410 | longvalue = (u64)getIntArg(pArgList); |
| 25375 | | - }else if( flag_longlong ){ |
| 25376 | | - longvalue = va_arg(ap,u64); |
| 25377 | 25411 | }else if( flag_long ){ |
| 25378 | | - longvalue = va_arg(ap,unsigned long int); |
| 25412 | + if( flag_long==2 ){ |
| 25413 | + longvalue = va_arg(ap,u64); |
| 25414 | + }else{ |
| 25415 | + longvalue = va_arg(ap,unsigned long int); |
| 25416 | + } |
| 25379 | 25417 | }else{ |
| 25380 | 25418 | longvalue = va_arg(ap,unsigned int); |
| 25381 | 25419 | } |
| 25382 | 25420 | prefix = 0; |
| 25383 | 25421 | } |
| 25384 | 25422 | if( longvalue==0 ) flag_alternateform = 0; |
| 25385 | 25423 | if( flag_zeropad && precision<width-(prefix!=0) ){ |
| 25386 | 25424 | precision = width-(prefix!=0); |
| 25387 | 25425 | } |
| 25388 | | - if( precision<etBUFSIZE-10 ){ |
| 25426 | + if( precision<etBUFSIZE-10-etBUFSIZE/3 ){ |
| 25389 | 25427 | nOut = etBUFSIZE; |
| 25390 | 25428 | zOut = buf; |
| 25391 | 25429 | }else{ |
| 25392 | | - nOut = precision + 10; |
| 25393 | | - zOut = zExtra = sqlite3Malloc( nOut ); |
| 25430 | + u64 n = (u64)precision + 10 + precision/3; |
| 25431 | + zOut = zExtra = sqlite3Malloc( n ); |
| 25394 | 25432 | if( zOut==0 ){ |
| 25395 | 25433 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 25396 | 25434 | return; |
| 25397 | 25435 | } |
| 25436 | + nOut = (int)n; |
| 25398 | 25437 | } |
| 25399 | 25438 | bufpt = &zOut[nOut-1]; |
| 25400 | 25439 | if( xtype==etORDINAL ){ |
| 25401 | 25440 | static const char zOrd[] = "thstndrd"; |
| 25402 | 25441 | int x = (int)(longvalue % 10); |
| | @@ -25413,12 +25452,27 @@ |
| 25413 | 25452 | *(--bufpt) = cset[longvalue%base]; |
| 25414 | 25453 | longvalue = longvalue/base; |
| 25415 | 25454 | }while( longvalue>0 ); |
| 25416 | 25455 | } |
| 25417 | 25456 | length = (int)(&zOut[nOut-1]-bufpt); |
| 25418 | | - for(idx=precision-length; idx>0; idx--){ |
| 25457 | + while( precision>length ){ |
| 25419 | 25458 | *(--bufpt) = '0'; /* Zero pad */ |
| 25459 | + length++; |
| 25460 | + } |
| 25461 | + if( cThousand ){ |
| 25462 | + int nn = (length - 1)/3; /* Number of "," to insert */ |
| 25463 | + int ix = (length - 1)%3 + 1; |
| 25464 | + bufpt -= nn; |
| 25465 | + for(idx=0; nn>0; idx++){ |
| 25466 | + bufpt[idx] = bufpt[idx+nn]; |
| 25467 | + ix--; |
| 25468 | + if( ix==0 ){ |
| 25469 | + bufpt[++idx] = cThousand; |
| 25470 | + nn--; |
| 25471 | + ix = 3; |
| 25472 | + } |
| 25473 | + } |
| 25420 | 25474 | } |
| 25421 | 25475 | if( prefix ) *(--bufpt) = prefix; /* Add sign */ |
| 25422 | 25476 | if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */ |
| 25423 | 25477 | const char *pre; |
| 25424 | 25478 | char x; |
| | @@ -25441,13 +25495,11 @@ |
| 25441 | 25495 | if( precision<0 ) precision = 6; /* Set default precision */ |
| 25442 | 25496 | if( realvalue<0.0 ){ |
| 25443 | 25497 | realvalue = -realvalue; |
| 25444 | 25498 | prefix = '-'; |
| 25445 | 25499 | }else{ |
| 25446 | | - if( flag_plussign ) prefix = '+'; |
| 25447 | | - else if( flag_blanksign ) prefix = ' '; |
| 25448 | | - else prefix = 0; |
| 25500 | + prefix = flag_prefix; |
| 25449 | 25501 | } |
| 25450 | 25502 | if( xtype==etGENERIC && precision>0 ) precision--; |
| 25451 | 25503 | testcase( precision>0xfff ); |
| 25452 | 25504 | for(idx=precision&0xfff, rounder=0.5; idx>0; idx--, rounder*=0.1){} |
| 25453 | 25505 | if( xtype==etFLOAT ) realvalue += rounder; |
| | @@ -26215,10 +26267,14 @@ |
| 26215 | 26267 | ** Generate a human-readable description of a Select object. |
| 26216 | 26268 | */ |
| 26217 | 26269 | SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ |
| 26218 | 26270 | int n = 0; |
| 26219 | 26271 | int cnt = 0; |
| 26272 | + if( p==0 ){ |
| 26273 | + sqlite3TreeViewLine(pView, "nil-SELECT"); |
| 26274 | + return; |
| 26275 | + } |
| 26220 | 26276 | pView = sqlite3TreeViewPush(pView, moreToFollow); |
| 26221 | 26277 | if( p->pWith ){ |
| 26222 | 26278 | sqlite3TreeViewWith(pView, p->pWith, 1); |
| 26223 | 26279 | cnt = 1; |
| 26224 | 26280 | sqlite3TreeViewPush(pView, 1); |
| | @@ -29464,117 +29520,119 @@ |
| 29464 | 29520 | /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 29465 | 29521 | /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 29466 | 29522 | /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 29467 | 29523 | /* 53 */ "Last" OpHelp(""), |
| 29468 | 29524 | /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), |
| 29469 | | - /* 55 */ "SorterSort" OpHelp(""), |
| 29470 | | - /* 56 */ "Sort" OpHelp(""), |
| 29471 | | - /* 57 */ "Rewind" OpHelp(""), |
| 29472 | | - /* 58 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 29473 | | - /* 59 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 29474 | | - /* 60 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 29475 | | - /* 61 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 29476 | | - /* 62 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 29477 | | - /* 63 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 29478 | | - /* 64 */ "Program" OpHelp(""), |
| 29479 | | - /* 65 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 29480 | | - /* 66 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 29481 | | - /* 67 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), |
| 29482 | | - /* 68 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 29483 | | - /* 69 */ "IncrVacuum" OpHelp(""), |
| 29484 | | - /* 70 */ "VNext" OpHelp(""), |
| 29485 | | - /* 71 */ "Init" OpHelp("Start at P2"), |
| 29486 | | - /* 72 */ "Return" OpHelp(""), |
| 29487 | | - /* 73 */ "EndCoroutine" OpHelp(""), |
| 29488 | | - /* 74 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 29489 | | - /* 75 */ "Halt" OpHelp(""), |
| 29490 | | - /* 76 */ "Integer" OpHelp("r[P2]=P1"), |
| 29491 | | - /* 77 */ "Int64" OpHelp("r[P2]=P4"), |
| 29492 | | - /* 78 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 29493 | | - /* 79 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 29494 | | - /* 80 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 29495 | | - /* 81 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 29496 | | - /* 82 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 29497 | | - /* 83 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 29498 | | - /* 84 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 29499 | | - /* 85 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 29500 | | - /* 86 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 29501 | | - /* 87 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 29502 | | - /* 88 */ "CollSeq" OpHelp(""), |
| 29503 | | - /* 89 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), |
| 29504 | | - /* 90 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 29505 | | - /* 91 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 29506 | | - /* 92 */ "RealAffinity" OpHelp(""), |
| 29507 | | - /* 93 */ "Cast" OpHelp("affinity(r[P1])"), |
| 29508 | | - /* 94 */ "Permutation" OpHelp(""), |
| 29509 | | - /* 95 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 29510 | | - /* 96 */ "Column" OpHelp("r[P3]=PX"), |
| 29525 | + /* 55 */ "IfSmaller" OpHelp(""), |
| 29526 | + /* 56 */ "SorterSort" OpHelp(""), |
| 29527 | + /* 57 */ "Sort" OpHelp(""), |
| 29528 | + /* 58 */ "Rewind" OpHelp(""), |
| 29529 | + /* 59 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 29530 | + /* 60 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 29531 | + /* 61 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 29532 | + /* 62 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 29533 | + /* 63 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 29534 | + /* 64 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 29535 | + /* 65 */ "Program" OpHelp(""), |
| 29536 | + /* 66 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 29537 | + /* 67 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 29538 | + /* 68 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), |
| 29539 | + /* 69 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 29540 | + /* 70 */ "IncrVacuum" OpHelp(""), |
| 29541 | + /* 71 */ "VNext" OpHelp(""), |
| 29542 | + /* 72 */ "Init" OpHelp("Start at P2"), |
| 29543 | + /* 73 */ "Return" OpHelp(""), |
| 29544 | + /* 74 */ "EndCoroutine" OpHelp(""), |
| 29545 | + /* 75 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 29546 | + /* 76 */ "Halt" OpHelp(""), |
| 29547 | + /* 77 */ "Integer" OpHelp("r[P2]=P1"), |
| 29548 | + /* 78 */ "Int64" OpHelp("r[P2]=P4"), |
| 29549 | + /* 79 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 29550 | + /* 80 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 29551 | + /* 81 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 29552 | + /* 82 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 29553 | + /* 83 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 29554 | + /* 84 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 29555 | + /* 85 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 29556 | + /* 86 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 29557 | + /* 87 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 29558 | + /* 88 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 29559 | + /* 89 */ "CollSeq" OpHelp(""), |
| 29560 | + /* 90 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), |
| 29561 | + /* 91 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 29562 | + /* 92 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 29563 | + /* 93 */ "RealAffinity" OpHelp(""), |
| 29564 | + /* 94 */ "Cast" OpHelp("affinity(r[P1])"), |
| 29565 | + /* 95 */ "Permutation" OpHelp(""), |
| 29566 | + /* 96 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 29511 | 29567 | /* 97 */ "String8" OpHelp("r[P2]='P4'"), |
| 29512 | | - /* 98 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 29513 | | - /* 99 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 29514 | | - /* 100 */ "Count" OpHelp("r[P2]=count()"), |
| 29515 | | - /* 101 */ "ReadCookie" OpHelp(""), |
| 29516 | | - /* 102 */ "SetCookie" OpHelp(""), |
| 29517 | | - /* 103 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 29518 | | - /* 104 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 29519 | | - /* 105 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 29520 | | - /* 106 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 29521 | | - /* 107 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 29522 | | - /* 108 */ "SorterOpen" OpHelp(""), |
| 29523 | | - /* 109 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 29524 | | - /* 110 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 29525 | | - /* 111 */ "Close" OpHelp(""), |
| 29526 | | - /* 112 */ "ColumnsUsed" OpHelp(""), |
| 29527 | | - /* 113 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 29528 | | - /* 114 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 29529 | | - /* 115 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 29530 | | - /* 116 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 29531 | | - /* 117 */ "Delete" OpHelp(""), |
| 29532 | | - /* 118 */ "ResetCount" OpHelp(""), |
| 29533 | | - /* 119 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 29534 | | - /* 120 */ "SorterData" OpHelp("r[P2]=data"), |
| 29535 | | - /* 121 */ "RowData" OpHelp("r[P2]=data"), |
| 29536 | | - /* 122 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 29537 | | - /* 123 */ "NullRow" OpHelp(""), |
| 29538 | | - /* 124 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 29539 | | - /* 125 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 29540 | | - /* 126 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 29541 | | - /* 127 */ "Seek" OpHelp("Move P3 to P1.rowid"), |
| 29542 | | - /* 128 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 29543 | | - /* 129 */ "Destroy" OpHelp(""), |
| 29544 | | - /* 130 */ "Clear" OpHelp(""), |
| 29545 | | - /* 131 */ "ResetSorter" OpHelp(""), |
| 29568 | + /* 98 */ "Column" OpHelp("r[P3]=PX"), |
| 29569 | + /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 29570 | + /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 29571 | + /* 101 */ "Count" OpHelp("r[P2]=count()"), |
| 29572 | + /* 102 */ "ReadCookie" OpHelp(""), |
| 29573 | + /* 103 */ "SetCookie" OpHelp(""), |
| 29574 | + /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 29575 | + /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 29576 | + /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 29577 | + /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 29578 | + /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 29579 | + /* 109 */ "SorterOpen" OpHelp(""), |
| 29580 | + /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 29581 | + /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 29582 | + /* 112 */ "Close" OpHelp(""), |
| 29583 | + /* 113 */ "ColumnsUsed" OpHelp(""), |
| 29584 | + /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 29585 | + /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 29586 | + /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 29587 | + /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 29588 | + /* 118 */ "Delete" OpHelp(""), |
| 29589 | + /* 119 */ "ResetCount" OpHelp(""), |
| 29590 | + /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 29591 | + /* 121 */ "SorterData" OpHelp("r[P2]=data"), |
| 29592 | + /* 122 */ "RowData" OpHelp("r[P2]=data"), |
| 29593 | + /* 123 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 29594 | + /* 124 */ "NullRow" OpHelp(""), |
| 29595 | + /* 125 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 29596 | + /* 126 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 29597 | + /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 29598 | + /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"), |
| 29599 | + /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 29600 | + /* 130 */ "Destroy" OpHelp(""), |
| 29601 | + /* 131 */ "Clear" OpHelp(""), |
| 29546 | 29602 | /* 132 */ "Real" OpHelp("r[P2]=P4"), |
| 29547 | | - /* 133 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 29548 | | - /* 134 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 29549 | | - /* 135 */ "ParseSchema" OpHelp(""), |
| 29550 | | - /* 136 */ "LoadAnalysis" OpHelp(""), |
| 29551 | | - /* 137 */ "DropTable" OpHelp(""), |
| 29552 | | - /* 138 */ "DropIndex" OpHelp(""), |
| 29553 | | - /* 139 */ "DropTrigger" OpHelp(""), |
| 29554 | | - /* 140 */ "IntegrityCk" OpHelp(""), |
| 29555 | | - /* 141 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 29556 | | - /* 142 */ "Param" OpHelp(""), |
| 29557 | | - /* 143 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 29558 | | - /* 144 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 29559 | | - /* 145 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 29560 | | - /* 146 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29561 | | - /* 147 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29562 | | - /* 148 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 29563 | | - /* 149 */ "Expire" OpHelp(""), |
| 29564 | | - /* 150 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 29565 | | - /* 151 */ "VBegin" OpHelp(""), |
| 29566 | | - /* 152 */ "VCreate" OpHelp(""), |
| 29567 | | - /* 153 */ "VDestroy" OpHelp(""), |
| 29568 | | - /* 154 */ "VOpen" OpHelp(""), |
| 29569 | | - /* 155 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 29570 | | - /* 156 */ "VRename" OpHelp(""), |
| 29571 | | - /* 157 */ "Pagecount" OpHelp(""), |
| 29572 | | - /* 158 */ "MaxPgcnt" OpHelp(""), |
| 29573 | | - /* 159 */ "CursorHint" OpHelp(""), |
| 29574 | | - /* 160 */ "Noop" OpHelp(""), |
| 29575 | | - /* 161 */ "Explain" OpHelp(""), |
| 29603 | + /* 133 */ "ResetSorter" OpHelp(""), |
| 29604 | + /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 29605 | + /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 29606 | + /* 136 */ "SqlExec" OpHelp(""), |
| 29607 | + /* 137 */ "ParseSchema" OpHelp(""), |
| 29608 | + /* 138 */ "LoadAnalysis" OpHelp(""), |
| 29609 | + /* 139 */ "DropTable" OpHelp(""), |
| 29610 | + /* 140 */ "DropIndex" OpHelp(""), |
| 29611 | + /* 141 */ "DropTrigger" OpHelp(""), |
| 29612 | + /* 142 */ "IntegrityCk" OpHelp(""), |
| 29613 | + /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 29614 | + /* 144 */ "Param" OpHelp(""), |
| 29615 | + /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 29616 | + /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 29617 | + /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 29618 | + /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29619 | + /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29620 | + /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 29621 | + /* 151 */ "Expire" OpHelp(""), |
| 29622 | + /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 29623 | + /* 153 */ "VBegin" OpHelp(""), |
| 29624 | + /* 154 */ "VCreate" OpHelp(""), |
| 29625 | + /* 155 */ "VDestroy" OpHelp(""), |
| 29626 | + /* 156 */ "VOpen" OpHelp(""), |
| 29627 | + /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 29628 | + /* 158 */ "VRename" OpHelp(""), |
| 29629 | + /* 159 */ "Pagecount" OpHelp(""), |
| 29630 | + /* 160 */ "MaxPgcnt" OpHelp(""), |
| 29631 | + /* 161 */ "CursorHint" OpHelp(""), |
| 29632 | + /* 162 */ "Noop" OpHelp(""), |
| 29633 | + /* 163 */ "Explain" OpHelp(""), |
| 29576 | 29634 | }; |
| 29577 | 29635 | return azName[i]; |
| 29578 | 29636 | } |
| 29579 | 29637 | #endif |
| 29580 | 29638 | |
| | @@ -37952,46 +38010,84 @@ |
| 37952 | 38010 | * be freed immediately and any attempt to access any of that freed |
| 37953 | 38011 | * data will almost certainly result in an immediate access violation. |
| 37954 | 38012 | ****************************************************************************** |
| 37955 | 38013 | */ |
| 37956 | 38014 | #ifndef SQLITE_WIN32_HEAP_CREATE |
| 37957 | | -# define SQLITE_WIN32_HEAP_CREATE (TRUE) |
| 38015 | +# define SQLITE_WIN32_HEAP_CREATE (TRUE) |
| 38016 | +#endif |
| 38017 | + |
| 38018 | +/* |
| 38019 | + * This is the maximum possible initial size of the Win32-specific heap, in |
| 38020 | + * bytes. |
| 38021 | + */ |
| 38022 | +#ifndef SQLITE_WIN32_HEAP_MAX_INIT_SIZE |
| 38023 | +# define SQLITE_WIN32_HEAP_MAX_INIT_SIZE (4294967295U) |
| 38024 | +#endif |
| 38025 | + |
| 38026 | +/* |
| 38027 | + * This is the extra space for the initial size of the Win32-specific heap, |
| 38028 | + * in bytes. This value may be zero. |
| 38029 | + */ |
| 38030 | +#ifndef SQLITE_WIN32_HEAP_INIT_EXTRA |
| 38031 | +# define SQLITE_WIN32_HEAP_INIT_EXTRA (4194304) |
| 38032 | +#endif |
| 38033 | + |
| 38034 | +/* |
| 38035 | + * Calculate the maximum legal cache size, in pages, based on the maximum |
| 38036 | + * possible initial heap size and the default page size, setting aside the |
| 38037 | + * needed extra space. |
| 38038 | + */ |
| 38039 | +#ifndef SQLITE_WIN32_MAX_CACHE_SIZE |
| 38040 | +# define SQLITE_WIN32_MAX_CACHE_SIZE (((SQLITE_WIN32_HEAP_MAX_INIT_SIZE) - \ |
| 38041 | + (SQLITE_WIN32_HEAP_INIT_EXTRA)) / \ |
| 38042 | + (SQLITE_DEFAULT_PAGE_SIZE)) |
| 37958 | 38043 | #endif |
| 37959 | 38044 | |
| 37960 | 38045 | /* |
| 37961 | 38046 | * This is cache size used in the calculation of the initial size of the |
| 37962 | 38047 | * Win32-specific heap. It cannot be negative. |
| 37963 | 38048 | */ |
| 37964 | 38049 | #ifndef SQLITE_WIN32_CACHE_SIZE |
| 37965 | 38050 | # if SQLITE_DEFAULT_CACHE_SIZE>=0 |
| 37966 | | -# define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE) |
| 38051 | +# define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE) |
| 37967 | 38052 | # else |
| 37968 | | -# define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE)) |
| 38053 | +# define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE)) |
| 37969 | 38054 | # endif |
| 37970 | 38055 | #endif |
| 37971 | 38056 | |
| 38057 | +/* |
| 38058 | + * Make sure that the calculated cache size, in pages, cannot cause the |
| 38059 | + * initial size of the Win32-specific heap to exceed the maximum amount |
| 38060 | + * of memory that can be specified in the call to HeapCreate. |
| 38061 | + */ |
| 38062 | +#if SQLITE_WIN32_CACHE_SIZE>SQLITE_WIN32_MAX_CACHE_SIZE |
| 38063 | +# undef SQLITE_WIN32_CACHE_SIZE |
| 38064 | +# define SQLITE_WIN32_CACHE_SIZE (2000) |
| 38065 | +#endif |
| 38066 | + |
| 37972 | 38067 | /* |
| 37973 | 38068 | * The initial size of the Win32-specific heap. This value may be zero. |
| 37974 | 38069 | */ |
| 37975 | 38070 | #ifndef SQLITE_WIN32_HEAP_INIT_SIZE |
| 37976 | | -# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \ |
| 37977 | | - (SQLITE_DEFAULT_PAGE_SIZE) + 4194304) |
| 38071 | +# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \ |
| 38072 | + (SQLITE_DEFAULT_PAGE_SIZE) + \ |
| 38073 | + (SQLITE_WIN32_HEAP_INIT_EXTRA)) |
| 37978 | 38074 | #endif |
| 37979 | 38075 | |
| 37980 | 38076 | /* |
| 37981 | 38077 | * The maximum size of the Win32-specific heap. This value may be zero. |
| 37982 | 38078 | */ |
| 37983 | 38079 | #ifndef SQLITE_WIN32_HEAP_MAX_SIZE |
| 37984 | | -# define SQLITE_WIN32_HEAP_MAX_SIZE (0) |
| 38080 | +# define SQLITE_WIN32_HEAP_MAX_SIZE (0) |
| 37985 | 38081 | #endif |
| 37986 | 38082 | |
| 37987 | 38083 | /* |
| 37988 | 38084 | * The extra flags to use in calls to the Win32 heap APIs. This value may be |
| 37989 | 38085 | * zero for the default behavior. |
| 37990 | 38086 | */ |
| 37991 | 38087 | #ifndef SQLITE_WIN32_HEAP_FLAGS |
| 37992 | | -# define SQLITE_WIN32_HEAP_FLAGS (0) |
| 38088 | +# define SQLITE_WIN32_HEAP_FLAGS (0) |
| 37993 | 38089 | #endif |
| 37994 | 38090 | |
| 37995 | 38091 | |
| 37996 | 38092 | /* |
| 37997 | 38093 | ** The winMemData structure stores information required by the Win32-specific |
| | @@ -44084,11 +44180,11 @@ |
| 44084 | 44180 | ** This routine is for use inside of assert() statements only. For |
| 44085 | 44181 | ** example: |
| 44086 | 44182 | ** |
| 44087 | 44183 | ** assert( sqlite3PcachePageSanity(pPg) ); |
| 44088 | 44184 | */ |
| 44089 | | -#if SQLITE_DEBUG |
| 44185 | +#ifdef SQLITE_DEBUG |
| 44090 | 44186 | SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){ |
| 44091 | 44187 | PCache *pCache; |
| 44092 | 44188 | assert( pPg!=0 ); |
| 44093 | 44189 | assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */ |
| 44094 | 44190 | pCache = pPg->pCache; |
| | @@ -60177,21 +60273,22 @@ |
| 60177 | 60273 | } |
| 60178 | 60274 | #endif |
| 60179 | 60275 | |
| 60180 | 60276 | |
| 60181 | 60277 | /* |
| 60182 | | -** Defragment the page given. All Cells are moved to the |
| 60183 | | -** end of the page and all free space is collected into one |
| 60184 | | -** big FreeBlk that occurs in between the header and cell |
| 60185 | | -** pointer array and the cell content area. |
| 60278 | +** Defragment the page given. This routine reorganizes cells within the |
| 60279 | +** page so that there are no free-blocks on the free-block list. |
| 60280 | +** |
| 60281 | +** Parameter nMaxFrag is the maximum amount of fragmented space that may be |
| 60282 | +** present in the page after this routine returns. |
| 60186 | 60283 | ** |
| 60187 | 60284 | ** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a |
| 60188 | 60285 | ** b-tree page so that there are no freeblocks or fragment bytes, all |
| 60189 | 60286 | ** unused bytes are contained in the unallocated space region, and all |
| 60190 | 60287 | ** cells are packed tightly at the end of the page. |
| 60191 | 60288 | */ |
| 60192 | | -static int defragmentPage(MemPage *pPage){ |
| 60289 | +static int defragmentPage(MemPage *pPage, int nMaxFrag){ |
| 60193 | 60290 | int i; /* Loop counter */ |
| 60194 | 60291 | int pc; /* Address of the i-th cell */ |
| 60195 | 60292 | int hdr; /* Offset to the page header */ |
| 60196 | 60293 | int size; /* Size of a cell */ |
| 60197 | 60294 | int usableSize; /* Number of usable bytes on a page */ |
| | @@ -60202,11 +60299,10 @@ |
| 60202 | 60299 | unsigned char *temp; /* Temp area for cell content */ |
| 60203 | 60300 | unsigned char *src; /* Source of content */ |
| 60204 | 60301 | int iCellFirst; /* First allowable cell index */ |
| 60205 | 60302 | int iCellLast; /* Last possible cell index */ |
| 60206 | 60303 | |
| 60207 | | - |
| 60208 | 60304 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 60209 | 60305 | assert( pPage->pBt!=0 ); |
| 60210 | 60306 | assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE ); |
| 60211 | 60307 | assert( pPage->nOverflow==0 ); |
| 60212 | 60308 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| | @@ -60214,13 +60310,60 @@ |
| 60214 | 60310 | src = data = pPage->aData; |
| 60215 | 60311 | hdr = pPage->hdrOffset; |
| 60216 | 60312 | cellOffset = pPage->cellOffset; |
| 60217 | 60313 | nCell = pPage->nCell; |
| 60218 | 60314 | assert( nCell==get2byte(&data[hdr+3]) ); |
| 60315 | + iCellFirst = cellOffset + 2*nCell; |
| 60219 | 60316 | usableSize = pPage->pBt->usableSize; |
| 60317 | + |
| 60318 | + /* This block handles pages with two or fewer free blocks and nMaxFrag |
| 60319 | + ** or fewer fragmented bytes. In this case it is faster to move the |
| 60320 | + ** two (or one) blocks of cells using memmove() and add the required |
| 60321 | + ** offsets to each pointer in the cell-pointer array than it is to |
| 60322 | + ** reconstruct the entire page. */ |
| 60323 | + if( (int)data[hdr+7]<=nMaxFrag ){ |
| 60324 | + int iFree = get2byte(&data[hdr+1]); |
| 60325 | + if( iFree ){ |
| 60326 | + int iFree2 = get2byte(&data[iFree]); |
| 60327 | + |
| 60328 | + /* pageFindSlot() has already verified that free blocks are sorted |
| 60329 | + ** in order of offset within the page, and that no block extends |
| 60330 | + ** past the end of the page. Provided the two free slots do not |
| 60331 | + ** overlap, this guarantees that the memmove() calls below will not |
| 60332 | + ** overwrite the usableSize byte buffer, even if the database page |
| 60333 | + ** is corrupt. */ |
| 60334 | + assert( iFree2==0 || iFree2>iFree ); |
| 60335 | + assert( iFree+get2byte(&data[iFree+2]) <= usableSize ); |
| 60336 | + assert( iFree2==0 || iFree2+get2byte(&data[iFree2+2]) <= usableSize ); |
| 60337 | + |
| 60338 | + if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){ |
| 60339 | + u8 *pEnd = &data[cellOffset + nCell*2]; |
| 60340 | + u8 *pAddr; |
| 60341 | + int sz2 = 0; |
| 60342 | + int sz = get2byte(&data[iFree+2]); |
| 60343 | + int top = get2byte(&data[hdr+5]); |
| 60344 | + if( iFree2 ){ |
| 60345 | + if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_BKPT; |
| 60346 | + sz2 = get2byte(&data[iFree2+2]); |
| 60347 | + assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize ); |
| 60348 | + memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); |
| 60349 | + sz += sz2; |
| 60350 | + } |
| 60351 | + cbrk = top+sz; |
| 60352 | + assert( cbrk+(iFree-top) <= usableSize ); |
| 60353 | + memmove(&data[cbrk], &data[top], iFree-top); |
| 60354 | + for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){ |
| 60355 | + pc = get2byte(pAddr); |
| 60356 | + if( pc<iFree ){ put2byte(pAddr, pc+sz); } |
| 60357 | + else if( pc<iFree2 ){ put2byte(pAddr, pc+sz2); } |
| 60358 | + } |
| 60359 | + goto defragment_out; |
| 60360 | + } |
| 60361 | + } |
| 60362 | + } |
| 60363 | + |
| 60220 | 60364 | cbrk = usableSize; |
| 60221 | | - iCellFirst = cellOffset + 2*nCell; |
| 60222 | 60365 | iCellLast = usableSize - 4; |
| 60223 | 60366 | for(i=0; i<nCell; i++){ |
| 60224 | 60367 | u8 *pAddr; /* The i-th cell pointer */ |
| 60225 | 60368 | pAddr = &data[cellOffset + i*2]; |
| 60226 | 60369 | pc = get2byte(pAddr); |
| | @@ -60250,20 +60393,22 @@ |
| 60250 | 60393 | memcpy(&temp[x], &data[x], (cbrk+size) - x); |
| 60251 | 60394 | src = temp; |
| 60252 | 60395 | } |
| 60253 | 60396 | memcpy(&data[cbrk], &src[pc], size); |
| 60254 | 60397 | } |
| 60398 | + data[hdr+7] = 0; |
| 60399 | + |
| 60400 | + defragment_out: |
| 60401 | + if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){ |
| 60402 | + return SQLITE_CORRUPT_BKPT; |
| 60403 | + } |
| 60255 | 60404 | assert( cbrk>=iCellFirst ); |
| 60256 | 60405 | put2byte(&data[hdr+5], cbrk); |
| 60257 | 60406 | data[hdr+1] = 0; |
| 60258 | 60407 | data[hdr+2] = 0; |
| 60259 | | - data[hdr+7] = 0; |
| 60260 | 60408 | memset(&data[iCellFirst], 0, cbrk-iCellFirst); |
| 60261 | 60409 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 60262 | | - if( cbrk-iCellFirst!=pPage->nFree ){ |
| 60263 | | - return SQLITE_CORRUPT_BKPT; |
| 60264 | | - } |
| 60265 | 60410 | return SQLITE_OK; |
| 60266 | 60411 | } |
| 60267 | 60412 | |
| 60268 | 60413 | /* |
| 60269 | 60414 | ** Search the free-list on page pPg for space to store a cell nByte bytes in |
| | @@ -60397,14 +60542,14 @@ |
| 60397 | 60542 | ** to see if defragmentation is necessary. |
| 60398 | 60543 | */ |
| 60399 | 60544 | testcase( gap+2+nByte==top ); |
| 60400 | 60545 | if( gap+2+nByte>top ){ |
| 60401 | 60546 | assert( pPage->nCell>0 || CORRUPT_DB ); |
| 60402 | | - rc = defragmentPage(pPage); |
| 60547 | + rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte))); |
| 60403 | 60548 | if( rc ) return rc; |
| 60404 | 60549 | top = get2byteNotZero(&data[hdr+5]); |
| 60405 | | - assert( gap+nByte<=top ); |
| 60550 | + assert( gap+2+nByte<=top ); |
| 60406 | 60551 | } |
| 60407 | 60552 | |
| 60408 | 60553 | |
| 60409 | 60554 | /* Allocate memory from the gap in between the cell pointer array |
| 60410 | 60555 | ** and the cell content area. The btreeInitPage() call has already |
| | @@ -61672,10 +61817,35 @@ |
| 61672 | 61817 | sqlite3BtreeLeave(p); |
| 61673 | 61818 | return rc; |
| 61674 | 61819 | #endif |
| 61675 | 61820 | } |
| 61676 | 61821 | |
| 61822 | +/* |
| 61823 | +** If the user has not set the safety-level for this database connection |
| 61824 | +** using "PRAGMA synchronous", and if the safety-level is not already |
| 61825 | +** set to the value passed to this function as the second parameter, |
| 61826 | +** set it so. |
| 61827 | +*/ |
| 61828 | +#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS |
| 61829 | +static void setDefaultSyncFlag(BtShared *pBt, u8 safety_level){ |
| 61830 | + sqlite3 *db; |
| 61831 | + Db *pDb; |
| 61832 | + if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){ |
| 61833 | + while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; } |
| 61834 | + if( pDb->bSyncSet==0 |
| 61835 | + && pDb->safety_level!=safety_level |
| 61836 | + && pDb!=&db->aDb[1] |
| 61837 | + ){ |
| 61838 | + pDb->safety_level = safety_level; |
| 61839 | + sqlite3PagerSetFlags(pBt->pPager, |
| 61840 | + pDb->safety_level | (db->flags & PAGER_FLAGS_MASK)); |
| 61841 | + } |
| 61842 | + } |
| 61843 | +} |
| 61844 | +#else |
| 61845 | +# define setDefaultSyncFlag(pBt,safety_level) |
| 61846 | +#endif |
| 61677 | 61847 | |
| 61678 | 61848 | /* |
| 61679 | 61849 | ** Get a reference to pPage1 of the database file. This will |
| 61680 | 61850 | ** also acquire a readlock on that file. |
| 61681 | 61851 | ** |
| | @@ -61745,30 +61915,19 @@ |
| 61745 | 61915 | int isOpen = 0; |
| 61746 | 61916 | rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen); |
| 61747 | 61917 | if( rc!=SQLITE_OK ){ |
| 61748 | 61918 | goto page1_init_failed; |
| 61749 | 61919 | }else{ |
| 61750 | | -#if SQLITE_DEFAULT_SYNCHRONOUS!=SQLITE_DEFAULT_WAL_SYNCHRONOUS |
| 61751 | | - sqlite3 *db; |
| 61752 | | - Db *pDb; |
| 61753 | | - if( (db=pBt->db)!=0 && (pDb=db->aDb)!=0 ){ |
| 61754 | | - while( pDb->pBt==0 || pDb->pBt->pBt!=pBt ){ pDb++; } |
| 61755 | | - if( pDb->bSyncSet==0 |
| 61756 | | - && pDb->safety_level==SQLITE_DEFAULT_SYNCHRONOUS+1 |
| 61757 | | - ){ |
| 61758 | | - pDb->safety_level = SQLITE_DEFAULT_WAL_SYNCHRONOUS+1; |
| 61759 | | - sqlite3PagerSetFlags(pBt->pPager, |
| 61760 | | - pDb->safety_level | (db->flags & PAGER_FLAGS_MASK)); |
| 61761 | | - } |
| 61762 | | - } |
| 61763 | | -#endif |
| 61920 | + setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1); |
| 61764 | 61921 | if( isOpen==0 ){ |
| 61765 | 61922 | releasePage(pPage1); |
| 61766 | 61923 | return SQLITE_OK; |
| 61767 | 61924 | } |
| 61768 | 61925 | } |
| 61769 | 61926 | rc = SQLITE_NOTADB; |
| 61927 | + }else{ |
| 61928 | + setDefaultSyncFlag(pBt, SQLITE_DEFAULT_SYNCHRONOUS+1); |
| 61770 | 61929 | } |
| 61771 | 61930 | #endif |
| 61772 | 61931 | |
| 61773 | 61932 | /* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload |
| 61774 | 61933 | ** fractions and the leaf payload fraction values must be 64, 32, and 32. |
| | @@ -63636,11 +63795,11 @@ |
| 63636 | 63795 | pCur->aiIdx[pCur->iPage] = 0; |
| 63637 | 63796 | return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage], |
| 63638 | 63797 | pCur, pCur->curPagerFlags); |
| 63639 | 63798 | } |
| 63640 | 63799 | |
| 63641 | | -#if SQLITE_DEBUG |
| 63800 | +#ifdef SQLITE_DEBUG |
| 63642 | 63801 | /* |
| 63643 | 63802 | ** Page pParent is an internal (non-leaf) tree page. This function |
| 63644 | 63803 | ** asserts that page number iChild is the left-child if the iIdx'th |
| 63645 | 63804 | ** cell in page pParent. Or, if iIdx is equal to the total number of |
| 63646 | 63805 | ** cells in pParent, that page number iChild is the right-child of |
| | @@ -64178,10 +64337,34 @@ |
| 64178 | 64337 | ** have been deleted? This API will need to change to return an error code |
| 64179 | 64338 | ** as well as the boolean result value. |
| 64180 | 64339 | */ |
| 64181 | 64340 | return (CURSOR_VALID!=pCur->eState); |
| 64182 | 64341 | } |
| 64342 | + |
| 64343 | +/* |
| 64344 | +** Return an estimate for the number of rows in the table that pCur is |
| 64345 | +** pointing to. Return a negative number if no estimate is currently |
| 64346 | +** available. |
| 64347 | +*/ |
| 64348 | +SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor *pCur){ |
| 64349 | + i64 n; |
| 64350 | + u8 i; |
| 64351 | + |
| 64352 | + assert( cursorOwnsBtShared(pCur) ); |
| 64353 | + assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 64354 | + |
| 64355 | + /* Currently this interface is only called by the OP_IfSmaller |
| 64356 | + ** opcode, and it that case the cursor will always be valid and |
| 64357 | + ** will always point to a leaf node. */ |
| 64358 | + if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1; |
| 64359 | + if( NEVER(pCur->apPage[pCur->iPage]->leaf==0) ) return -1; |
| 64360 | + |
| 64361 | + for(n=1, i=0; i<=pCur->iPage; i++){ |
| 64362 | + n *= pCur->apPage[i]->nCell; |
| 64363 | + } |
| 64364 | + return n; |
| 64365 | +} |
| 64183 | 64366 | |
| 64184 | 64367 | /* |
| 64185 | 64368 | ** Advance the cursor to the next entry in the database. If |
| 64186 | 64369 | ** successful then set *pRes=0. If the cursor |
| 64187 | 64370 | ** was already pointing to the last entry in the database before |
| | @@ -65023,11 +65206,11 @@ |
| 65023 | 65206 | ** pPrior Where to write the pgno of the first overflow page |
| 65024 | 65207 | ** |
| 65025 | 65208 | ** Use a call to btreeParseCellPtr() to verify that the values above |
| 65026 | 65209 | ** were computed correctly. |
| 65027 | 65210 | */ |
| 65028 | | -#if SQLITE_DEBUG |
| 65211 | +#ifdef SQLITE_DEBUG |
| 65029 | 65212 | { |
| 65030 | 65213 | CellInfo info; |
| 65031 | 65214 | pPage->xParseCell(pPage, pCell, &info); |
| 65032 | 65215 | assert( nHeader==(int)(info.pPayload - pCell) ); |
| 65033 | 65216 | assert( info.nKey==pX->nKey ); |
| | @@ -66549,11 +66732,11 @@ |
| 66549 | 66732 | ** copied into the parent, because if the parent is page 1 then it will |
| 66550 | 66733 | ** by smaller than the child due to the database header, and so all the |
| 66551 | 66734 | ** free space needs to be up front. |
| 66552 | 66735 | */ |
| 66553 | 66736 | assert( nNew==1 || CORRUPT_DB ); |
| 66554 | | - rc = defragmentPage(apNew[0]); |
| 66737 | + rc = defragmentPage(apNew[0], -1); |
| 66555 | 66738 | testcase( rc!=SQLITE_OK ); |
| 66556 | 66739 | assert( apNew[0]->nFree == |
| 66557 | 66740 | (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2) |
| 66558 | 66741 | || rc!=SQLITE_OK |
| 66559 | 66742 | ); |
| | @@ -71201,10 +71384,11 @@ |
| 71201 | 71384 | ** Remember the SQL string for a prepared statement. |
| 71202 | 71385 | */ |
| 71203 | 71386 | SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){ |
| 71204 | 71387 | assert( isPrepareV2==1 || isPrepareV2==0 ); |
| 71205 | 71388 | if( p==0 ) return; |
| 71389 | + if( !isPrepareV2 ) p->expmask = 0; |
| 71206 | 71390 | #if defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_ENABLE_SQLLOG) |
| 71207 | 71391 | if( !isPrepareV2 ) return; |
| 71208 | 71392 | #endif |
| 71209 | 71393 | assert( p->zSql==0 ); |
| 71210 | 71394 | p->zSql = sqlite3DbStrNDup(p->db, z, n); |
| | @@ -71229,10 +71413,11 @@ |
| 71229 | 71413 | pB->pPrev = pTmp; |
| 71230 | 71414 | zTmp = pA->zSql; |
| 71231 | 71415 | pA->zSql = pB->zSql; |
| 71232 | 71416 | pB->zSql = zTmp; |
| 71233 | 71417 | pB->isPrepareV2 = pA->isPrepareV2; |
| 71418 | + pB->expmask = pA->expmask; |
| 71234 | 71419 | } |
| 71235 | 71420 | |
| 71236 | 71421 | /* |
| 71237 | 71422 | ** Resize the Vdbe.aOp array so that it is at least nOp elements larger |
| 71238 | 71423 | ** than its current size. nOp is guaranteed to be less than or equal |
| | @@ -71258,10 +71443,16 @@ |
| 71258 | 71443 | int nNew = (p->nOpAlloc>=512 ? p->nOpAlloc*2 : p->nOpAlloc+nOp); |
| 71259 | 71444 | #else |
| 71260 | 71445 | int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 71261 | 71446 | UNUSED_PARAMETER(nOp); |
| 71262 | 71447 | #endif |
| 71448 | + |
| 71449 | + /* Ensure that the size of a VDBE does not grow too large */ |
| 71450 | + if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){ |
| 71451 | + sqlite3OomFault(p->db); |
| 71452 | + return SQLITE_NOMEM; |
| 71453 | + } |
| 71263 | 71454 | |
| 71264 | 71455 | assert( nOp<=(1024/sizeof(Op)) ); |
| 71265 | 71456 | assert( nNew>=(p->nOpAlloc+nOp) ); |
| 71266 | 71457 | pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); |
| 71267 | 71458 | if( pNew ){ |
| | @@ -73753,17 +73944,17 @@ |
| 73753 | 73944 | ** Then the internal cache might have been left in an inconsistent |
| 73754 | 73945 | ** state. We need to rollback the statement transaction, if there is |
| 73755 | 73946 | ** one, or the complete transaction if there is no statement transaction. |
| 73756 | 73947 | */ |
| 73757 | 73948 | |
| 73949 | + if( p->magic!=VDBE_MAGIC_RUN ){ |
| 73950 | + return SQLITE_OK; |
| 73951 | + } |
| 73758 | 73952 | if( db->mallocFailed ){ |
| 73759 | 73953 | p->rc = SQLITE_NOMEM_BKPT; |
| 73760 | 73954 | } |
| 73761 | 73955 | closeAllCursors(p); |
| 73762 | | - if( p->magic!=VDBE_MAGIC_RUN ){ |
| 73763 | | - return SQLITE_OK; |
| 73764 | | - } |
| 73765 | 73956 | checkActiveVdbeCnt(db); |
| 73766 | 73957 | |
| 73767 | 73958 | /* No commit or rollback needed if the program never started or if the |
| 73768 | 73959 | ** SQL statement does not read or write a database file. */ |
| 73769 | 73960 | if( p->pc>=0 && p->bIsReader ){ |
| | @@ -74706,11 +74897,11 @@ |
| 74706 | 74897 | } |
| 74707 | 74898 | assert( u<=pKeyInfo->nField + 1 ); |
| 74708 | 74899 | p->nField = u; |
| 74709 | 74900 | } |
| 74710 | 74901 | |
| 74711 | | -#if SQLITE_DEBUG |
| 74902 | +#ifdef SQLITE_DEBUG |
| 74712 | 74903 | /* |
| 74713 | 74904 | ** This function compares two index or table record keys in the same way |
| 74714 | 74905 | ** as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(), |
| 74715 | 74906 | ** this function deserializes and compares values using the |
| 74716 | 74907 | ** sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used |
| | @@ -74811,11 +75002,11 @@ |
| 74811 | 75002 | if( pKeyInfo->db->mallocFailed ) return 1; |
| 74812 | 75003 | return 0; |
| 74813 | 75004 | } |
| 74814 | 75005 | #endif |
| 74815 | 75006 | |
| 74816 | | -#if SQLITE_DEBUG |
| 75007 | +#ifdef SQLITE_DEBUG |
| 74817 | 75008 | /* |
| 74818 | 75009 | ** Count the number of fields (a.k.a. columns) in the record given by |
| 74819 | 75010 | ** pKey,nKey. The verify that this count is less than or equal to the |
| 74820 | 75011 | ** limit given by pKeyInfo->nField + pKeyInfo->nXField. |
| 74821 | 75012 | ** |
| | @@ -75694,12 +75885,12 @@ |
| 75694 | 75885 | ** to sqlite3_reoptimize() that re-preparing the statement may result |
| 75695 | 75886 | ** in a better query plan. |
| 75696 | 75887 | */ |
| 75697 | 75888 | SQLITE_PRIVATE void sqlite3VdbeSetVarmask(Vdbe *v, int iVar){ |
| 75698 | 75889 | assert( iVar>0 ); |
| 75699 | | - if( iVar>32 ){ |
| 75700 | | - v->expmask = 0xffffffff; |
| 75890 | + if( iVar>=32 ){ |
| 75891 | + v->expmask |= 0x80000000; |
| 75701 | 75892 | }else{ |
| 75702 | 75893 | v->expmask |= ((u32)1 << (iVar-1)); |
| 75703 | 75894 | } |
| 75704 | 75895 | } |
| 75705 | 75896 | |
| | @@ -75965,11 +76156,12 @@ |
| 75965 | 76156 | sqlite3_mutex_enter(mutex); |
| 75966 | 76157 | for(i=0; i<p->nVar; i++){ |
| 75967 | 76158 | sqlite3VdbeMemRelease(&p->aVar[i]); |
| 75968 | 76159 | p->aVar[i].flags = MEM_Null; |
| 75969 | 76160 | } |
| 75970 | | - if( p->isPrepareV2 && p->expmask ){ |
| 76161 | + assert( p->isPrepareV2 || p->expmask==0 ); |
| 76162 | + if( p->expmask ){ |
| 75971 | 76163 | p->expired = 1; |
| 75972 | 76164 | } |
| 75973 | 76165 | sqlite3_mutex_leave(mutex); |
| 75974 | 76166 | return rc; |
| 75975 | 76167 | } |
| | @@ -77069,13 +77261,12 @@ |
| 77069 | 77261 | ** parameter in the WHERE clause might influence the choice of query plan |
| 77070 | 77262 | ** for a statement, then the statement will be automatically recompiled, |
| 77071 | 77263 | ** as if there had been a schema change, on the first sqlite3_step() call |
| 77072 | 77264 | ** following any change to the bindings of that parameter. |
| 77073 | 77265 | */ |
| 77074 | | - if( p->isPrepareV2 && |
| 77075 | | - ((i<32 && p->expmask & ((u32)1 << i)) || p->expmask==0xffffffff) |
| 77076 | | - ){ |
| 77266 | + assert( p->isPrepareV2 || p->expmask==0 ); |
| 77267 | + if( p->expmask!=0 && (p->expmask & (i>=31 ? 0x80000000 : (u32)1<<i))!=0 ){ |
| 77077 | 77268 | p->expired = 1; |
| 77078 | 77269 | } |
| 77079 | 77270 | return SQLITE_OK; |
| 77080 | 77271 | } |
| 77081 | 77272 | |
| | @@ -77334,14 +77525,16 @@ |
| 77334 | 77525 | Vdbe *pFrom = (Vdbe*)pFromStmt; |
| 77335 | 77526 | Vdbe *pTo = (Vdbe*)pToStmt; |
| 77336 | 77527 | if( pFrom->nVar!=pTo->nVar ){ |
| 77337 | 77528 | return SQLITE_ERROR; |
| 77338 | 77529 | } |
| 77339 | | - if( pTo->isPrepareV2 && pTo->expmask ){ |
| 77530 | + assert( pTo->isPrepareV2 || pTo->expmask==0 ); |
| 77531 | + if( pTo->expmask ){ |
| 77340 | 77532 | pTo->expired = 1; |
| 77341 | 77533 | } |
| 77342 | | - if( pFrom->isPrepareV2 && pFrom->expmask ){ |
| 77534 | + assert( pFrom->isPrepareV2 || pFrom->expmask==0 ); |
| 77535 | + if( pFrom->expmask ){ |
| 77343 | 77536 | pFrom->expired = 1; |
| 77344 | 77537 | } |
| 77345 | 77538 | return sqlite3TransferBindings(pFromStmt, pToStmt); |
| 77346 | 77539 | } |
| 77347 | 77540 | #endif |
| | @@ -78303,13 +78496,11 @@ |
| 78303 | 78496 | c = 'e'; |
| 78304 | 78497 | assert( (f & (MEM_Static|MEM_Dyn))==0 ); |
| 78305 | 78498 | }else{ |
| 78306 | 78499 | c = 's'; |
| 78307 | 78500 | } |
| 78308 | | - |
| 78309 | | - sqlite3_snprintf(100, zCsr, "%c", c); |
| 78310 | | - zCsr += sqlite3Strlen30(zCsr); |
| 78501 | + *(zCsr++) = c; |
| 78311 | 78502 | sqlite3_snprintf(100, zCsr, "%d[", pMem->n); |
| 78312 | 78503 | zCsr += sqlite3Strlen30(zCsr); |
| 78313 | 78504 | for(i=0; i<16 && i<pMem->n; i++){ |
| 78314 | 78505 | sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF)); |
| 78315 | 78506 | zCsr += sqlite3Strlen30(zCsr); |
| | @@ -78317,13 +78508,11 @@ |
| 78317 | 78508 | for(i=0; i<16 && i<pMem->n; i++){ |
| 78318 | 78509 | char z = pMem->z[i]; |
| 78319 | 78510 | if( z<32 || z>126 ) *zCsr++ = '.'; |
| 78320 | 78511 | else *zCsr++ = z; |
| 78321 | 78512 | } |
| 78322 | | - |
| 78323 | | - sqlite3_snprintf(100, zCsr, "]%s", encnames[pMem->enc]); |
| 78324 | | - zCsr += sqlite3Strlen30(zCsr); |
| 78513 | + *(zCsr++) = ']'; |
| 78325 | 78514 | if( f & MEM_Zero ){ |
| 78326 | 78515 | sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero); |
| 78327 | 78516 | zCsr += sqlite3Strlen30(zCsr); |
| 78328 | 78517 | } |
| 78329 | 78518 | *zCsr = '\0'; |
| | @@ -79658,39 +79847,39 @@ |
| 79658 | 79847 | if( pCtx->pOut != pOut ){ |
| 79659 | 79848 | pCtx->pOut = pOut; |
| 79660 | 79849 | for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; |
| 79661 | 79850 | } |
| 79662 | 79851 | |
| 79663 | | - memAboutToChange(p, pCtx->pOut); |
| 79852 | + memAboutToChange(p, pOut); |
| 79664 | 79853 | #ifdef SQLITE_DEBUG |
| 79665 | 79854 | for(i=0; i<pCtx->argc; i++){ |
| 79666 | 79855 | assert( memIsValid(pCtx->argv[i]) ); |
| 79667 | 79856 | REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 79668 | 79857 | } |
| 79669 | 79858 | #endif |
| 79670 | | - MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 79859 | + MemSetTypeFlag(pOut, MEM_Null); |
| 79671 | 79860 | pCtx->fErrorOrAux = 0; |
| 79672 | 79861 | (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ |
| 79673 | 79862 | |
| 79674 | 79863 | /* If the function returned an error, throw an exception */ |
| 79675 | 79864 | if( pCtx->fErrorOrAux ){ |
| 79676 | 79865 | if( pCtx->isError ){ |
| 79677 | | - sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| 79866 | + sqlite3VdbeError(p, "%s", sqlite3_value_text(pOut)); |
| 79678 | 79867 | rc = pCtx->isError; |
| 79679 | 79868 | } |
| 79680 | 79869 | sqlite3VdbeDeleteAuxData(db, &p->pAuxData, pCtx->iOp, pOp->p1); |
| 79681 | 79870 | if( rc ) goto abort_due_to_error; |
| 79682 | 79871 | } |
| 79683 | 79872 | |
| 79684 | 79873 | /* Copy the result of the function into register P3 */ |
| 79685 | 79874 | if( pOut->flags & (MEM_Str|MEM_Blob) ){ |
| 79686 | | - sqlite3VdbeChangeEncoding(pCtx->pOut, encoding); |
| 79687 | | - if( sqlite3VdbeMemTooBig(pCtx->pOut) ) goto too_big; |
| 79875 | + sqlite3VdbeChangeEncoding(pOut, encoding); |
| 79876 | + if( sqlite3VdbeMemTooBig(pOut) ) goto too_big; |
| 79688 | 79877 | } |
| 79689 | 79878 | |
| 79690 | | - REGISTER_TRACE(pOp->p3, pCtx->pOut); |
| 79691 | | - UPDATE_MAX_BLOBSIZE(pCtx->pOut); |
| 79879 | + REGISTER_TRACE(pOp->p3, pOut); |
| 79880 | + UPDATE_MAX_BLOBSIZE(pOut); |
| 79692 | 79881 | break; |
| 79693 | 79882 | } |
| 79694 | 79883 | |
| 79695 | 79884 | /* Opcode: BitAnd P1 P2 P3 * * |
| 79696 | 79885 | ** Synopsis: r[P3]=r[P1]&r[P2] |
| | @@ -80187,11 +80376,11 @@ |
| 80187 | 80376 | pKeyInfo = pOp->p4.pKeyInfo; |
| 80188 | 80377 | assert( n>0 ); |
| 80189 | 80378 | assert( pKeyInfo!=0 ); |
| 80190 | 80379 | p1 = pOp->p1; |
| 80191 | 80380 | p2 = pOp->p2; |
| 80192 | | -#if SQLITE_DEBUG |
| 80381 | +#ifdef SQLITE_DEBUG |
| 80193 | 80382 | if( aPermute ){ |
| 80194 | 80383 | int k, mx = 0; |
| 80195 | 80384 | for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k]; |
| 80196 | 80385 | assert( p1>0 && p1+mx<=(p->nMem+1 - p->nCursor)+1 ); |
| 80197 | 80386 | assert( p2>0 && p2+mx<=(p->nMem+1 - p->nCursor)+1 ); |
| | @@ -80325,23 +80514,43 @@ |
| 80325 | 80514 | break; |
| 80326 | 80515 | } |
| 80327 | 80516 | |
| 80328 | 80517 | /* Opcode: Once P1 P2 * * * |
| 80329 | 80518 | ** |
| 80330 | | -** If the P1 value is equal to the P1 value on the OP_Init opcode at |
| 80331 | | -** instruction 0, then jump to P2. If the two P1 values differ, then |
| 80332 | | -** set the P1 value on this opcode to equal the P1 value on the OP_Init |
| 80333 | | -** and fall through. |
| 80519 | +** Fall through to the next instruction the first time this opcode is |
| 80520 | +** encountered on each invocation of the byte-code program. Jump to P2 |
| 80521 | +** on the second and all subsequent encounters during the same invocation. |
| 80522 | +** |
| 80523 | +** Top-level programs determine first invocation by comparing the P1 |
| 80524 | +** operand against the P1 operand on the OP_Init opcode at the beginning |
| 80525 | +** of the program. If the P1 values differ, then fall through and make |
| 80526 | +** the P1 of this opcode equal to the P1 of OP_Init. If P1 values are |
| 80527 | +** the same then take the jump. |
| 80528 | +** |
| 80529 | +** For subprograms, there is a bitmask in the VdbeFrame that determines |
| 80530 | +** whether or not the jump should be taken. The bitmask is necessary |
| 80531 | +** because the self-altering code trick does not work for recursive |
| 80532 | +** triggers. |
| 80334 | 80533 | */ |
| 80335 | 80534 | case OP_Once: { /* jump */ |
| 80535 | + u32 iAddr; /* Address of this instruction */ |
| 80336 | 80536 | assert( p->aOp[0].opcode==OP_Init ); |
| 80337 | | - VdbeBranchTaken(p->aOp[0].p1==pOp->p1, 2); |
| 80338 | | - if( p->aOp[0].p1==pOp->p1 ){ |
| 80339 | | - goto jump_to_p2; |
| 80537 | + if( p->pFrame ){ |
| 80538 | + iAddr = (int)(pOp - p->aOp); |
| 80539 | + if( (p->pFrame->aOnce[iAddr/8] & (1<<(iAddr & 7)))!=0 ){ |
| 80540 | + VdbeBranchTaken(1, 2); |
| 80541 | + goto jump_to_p2; |
| 80542 | + } |
| 80543 | + p->pFrame->aOnce[iAddr/8] |= 1<<(iAddr & 7); |
| 80340 | 80544 | }else{ |
| 80341 | | - pOp->p1 = p->aOp[0].p1; |
| 80545 | + if( p->aOp[0].p1==pOp->p1 ){ |
| 80546 | + VdbeBranchTaken(1, 2); |
| 80547 | + goto jump_to_p2; |
| 80548 | + } |
| 80342 | 80549 | } |
| 80550 | + VdbeBranchTaken(0, 2); |
| 80551 | + pOp->p1 = p->aOp[0].p1; |
| 80343 | 80552 | break; |
| 80344 | 80553 | } |
| 80345 | 80554 | |
| 80346 | 80555 | /* Opcode: If P1 P2 P3 * * |
| 80347 | 80556 | ** |
| | @@ -80650,12 +80859,17 @@ |
| 80650 | 80859 | /* Content is irrelevant for |
| 80651 | 80860 | ** 1. the typeof() function, |
| 80652 | 80861 | ** 2. the length(X) function if X is a blob, and |
| 80653 | 80862 | ** 3. if the content length is zero. |
| 80654 | 80863 | ** So we might as well use bogus content rather than reading |
| 80655 | | - ** content from disk. */ |
| 80656 | | - static u8 aZero[8]; /* This is the bogus content */ |
| 80864 | + ** content from disk. |
| 80865 | + ** |
| 80866 | + ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the |
| 80867 | + ** buffer passed to it, debugging function VdbeMemPrettyPrint() may |
| 80868 | + ** read up to 16. So 16 bytes of bogus content is supplied. |
| 80869 | + */ |
| 80870 | + static u8 aZero[16]; /* This is the bogus content */ |
| 80657 | 80871 | sqlite3VdbeSerialGet(aZero, t, pDest); |
| 80658 | 80872 | }else{ |
| 80659 | 80873 | rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); |
| 80660 | 80874 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 80661 | 80875 | sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| | @@ -82836,10 +83050,37 @@ |
| 82836 | 83050 | assert( pOp->p2==0 ); |
| 82837 | 83051 | } |
| 82838 | 83052 | break; |
| 82839 | 83053 | } |
| 82840 | 83054 | |
| 83055 | +/* Opcode: IfSmaller P1 P2 P3 * * |
| 83056 | +** |
| 83057 | +** Estimate the number of rows in the table P1. Jump to P2 if that |
| 83058 | +** estimate is less than approximately 2**(0.1*P3). |
| 83059 | +*/ |
| 83060 | +case OP_IfSmaller: { /* jump */ |
| 83061 | + VdbeCursor *pC; |
| 83062 | + BtCursor *pCrsr; |
| 83063 | + int res; |
| 83064 | + i64 sz; |
| 83065 | + |
| 83066 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 83067 | + pC = p->apCsr[pOp->p1]; |
| 83068 | + assert( pC!=0 ); |
| 83069 | + pCrsr = pC->uc.pCursor; |
| 83070 | + assert( pCrsr ); |
| 83071 | + rc = sqlite3BtreeFirst(pCrsr, &res); |
| 83072 | + if( rc ) goto abort_due_to_error; |
| 83073 | + if( res==0 ){ |
| 83074 | + sz = sqlite3BtreeRowCountEst(pCrsr); |
| 83075 | + if( ALWAYS(sz>=0) && sqlite3LogEst((u64)sz)<pOp->p3 ) res = 1; |
| 83076 | + } |
| 83077 | + VdbeBranchTaken(res!=0,2); |
| 83078 | + if( res ) goto jump_to_p2; |
| 83079 | + break; |
| 83080 | +} |
| 83081 | + |
| 82841 | 83082 | |
| 82842 | 83083 | /* Opcode: SorterSort P1 P2 * * * |
| 82843 | 83084 | ** |
| 82844 | 83085 | ** After all records have been inserted into the Sorter object |
| 82845 | 83086 | ** identified by P1, invoke this opcode to actually do the sorting. |
| | @@ -83479,10 +83720,22 @@ |
| 83479 | 83720 | rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags); |
| 83480 | 83721 | if( rc ) goto abort_due_to_error; |
| 83481 | 83722 | pOut->u.i = pgno; |
| 83482 | 83723 | break; |
| 83483 | 83724 | } |
| 83725 | + |
| 83726 | +/* Opcode: SqlExec * * * P4 * |
| 83727 | +** |
| 83728 | +** Run the SQL statement or statements specified in the P4 string. |
| 83729 | +*/ |
| 83730 | +case OP_SqlExec: { |
| 83731 | + db->nSqlExec++; |
| 83732 | + rc = sqlite3_exec(db, pOp->p4.z, 0, 0, 0); |
| 83733 | + db->nSqlExec--; |
| 83734 | + if( rc ) goto abort_due_to_error; |
| 83735 | + break; |
| 83736 | +} |
| 83484 | 83737 | |
| 83485 | 83738 | /* Opcode: ParseSchema P1 * * P4 * |
| 83486 | 83739 | ** |
| 83487 | 83740 | ** Read and parse all entries from the SQLITE_MASTER table of database P1 |
| 83488 | 83741 | ** that match the WHERE clause P4. |
| | @@ -83600,11 +83853,11 @@ |
| 83600 | 83853 | ** |
| 83601 | 83854 | ** Do an analysis of the currently open database. Store in |
| 83602 | 83855 | ** register P1 the text of an error message describing any problems. |
| 83603 | 83856 | ** If no problems are found, store a NULL in register P1. |
| 83604 | 83857 | ** |
| 83605 | | -** The register P3 contains the maximum number of allowed errors. |
| 83858 | +** The register P3 contains one less than the maximum number of allowed errors. |
| 83606 | 83859 | ** At most reg(P3) errors will be reported. |
| 83607 | 83860 | ** In other words, the analysis stops as soon as reg(P1) errors are |
| 83608 | 83861 | ** seen. Reg(P1) is updated with the number of errors remaining. |
| 83609 | 83862 | ** |
| 83610 | 83863 | ** The root page numbers of all tables in the database are integers |
| | @@ -83633,18 +83886,18 @@ |
| 83633 | 83886 | assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); |
| 83634 | 83887 | pIn1 = &aMem[pOp->p1]; |
| 83635 | 83888 | assert( pOp->p5<db->nDb ); |
| 83636 | 83889 | assert( DbMaskTest(p->btreeMask, pOp->p5) ); |
| 83637 | 83890 | z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot, |
| 83638 | | - (int)pnErr->u.i, &nErr); |
| 83639 | | - pnErr->u.i -= nErr; |
| 83891 | + (int)pnErr->u.i+1, &nErr); |
| 83640 | 83892 | sqlite3VdbeMemSetNull(pIn1); |
| 83641 | 83893 | if( nErr==0 ){ |
| 83642 | 83894 | assert( z==0 ); |
| 83643 | 83895 | }else if( z==0 ){ |
| 83644 | 83896 | goto no_mem; |
| 83645 | 83897 | }else{ |
| 83898 | + pnErr->u.i -= nErr-1; |
| 83646 | 83899 | sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free); |
| 83647 | 83900 | } |
| 83648 | 83901 | UPDATE_MAX_BLOBSIZE(pIn1); |
| 83649 | 83902 | sqlite3VdbeChangeEncoding(pIn1, encoding); |
| 83650 | 83903 | break; |
| | @@ -83819,11 +84072,12 @@ |
| 83819 | 84072 | nMem = pProgram->nMem + pProgram->nCsr; |
| 83820 | 84073 | assert( nMem>0 ); |
| 83821 | 84074 | if( pProgram->nCsr==0 ) nMem++; |
| 83822 | 84075 | nByte = ROUND8(sizeof(VdbeFrame)) |
| 83823 | 84076 | + nMem * sizeof(Mem) |
| 83824 | | - + pProgram->nCsr * sizeof(VdbeCursor *); |
| 84077 | + + pProgram->nCsr * sizeof(VdbeCursor*) |
| 84078 | + + (pProgram->nOp + 7)/8; |
| 83825 | 84079 | pFrame = sqlite3DbMallocZero(db, nByte); |
| 83826 | 84080 | if( !pFrame ){ |
| 83827 | 84081 | goto no_mem; |
| 83828 | 84082 | } |
| 83829 | 84083 | sqlite3VdbeMemRelease(pRt); |
| | @@ -83870,10 +84124,12 @@ |
| 83870 | 84124 | p->pFrame = pFrame; |
| 83871 | 84125 | p->aMem = aMem = VdbeFrameMem(pFrame); |
| 83872 | 84126 | p->nMem = pFrame->nChildMem; |
| 83873 | 84127 | p->nCursor = (u16)pFrame->nChildCsr; |
| 83874 | 84128 | p->apCsr = (VdbeCursor **)&aMem[p->nMem]; |
| 84129 | + pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr]; |
| 84130 | + memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8); |
| 83875 | 84131 | p->aOp = aOp = pProgram->aOp; |
| 83876 | 84132 | p->nOp = pProgram->nOp; |
| 83877 | 84133 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 83878 | 84134 | p->anExec = 0; |
| 83879 | 84135 | #endif |
| | @@ -84899,11 +85155,15 @@ |
| 84899 | 85155 | char *z = sqlite3VdbeExpandSql(p, zTrace); |
| 84900 | 85156 | x(db->pTraceArg, z); |
| 84901 | 85157 | sqlite3_free(z); |
| 84902 | 85158 | }else |
| 84903 | 85159 | #endif |
| 84904 | | - { |
| 85160 | + if( db->nVdbeExec>1 ){ |
| 85161 | + char *z = sqlite3MPrintf(db, "-- %s", zTrace); |
| 85162 | + (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, z); |
| 85163 | + sqlite3DbFree(db, z); |
| 85164 | + }else{ |
| 84905 | 85165 | (void)db->xTrace(SQLITE_TRACE_STMT, db->pTraceArg, p, zTrace); |
| 84906 | 85166 | } |
| 84907 | 85167 | } |
| 84908 | 85168 | #ifdef SQLITE_USE_FCNTL_TRACE |
| 84909 | 85169 | zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); |
| | @@ -88787,15 +89047,15 @@ |
| 88787 | 89047 | ** The return value from the callback should be one of the WRC_* |
| 88788 | 89048 | ** constants to specify how to proceed with the walk. |
| 88789 | 89049 | ** |
| 88790 | 89050 | ** WRC_Continue Continue descending down the tree. |
| 88791 | 89051 | ** |
| 88792 | | -** WRC_Prune Do not descend into child nodes. But allow |
| 89052 | +** WRC_Prune Do not descend into child nodes, but allow |
| 88793 | 89053 | ** the walk to continue with sibling nodes. |
| 88794 | 89054 | ** |
| 88795 | 89055 | ** WRC_Abort Do no more callbacks. Unwind the stack and |
| 88796 | | -** return the top-level walk call. |
| 89056 | +** return from the top-level walk call. |
| 88797 | 89057 | ** |
| 88798 | 89058 | ** The return value from this routine is WRC_Abort to abandon the tree walk |
| 88799 | 89059 | ** and WRC_Continue to continue. |
| 88800 | 89060 | */ |
| 88801 | 89061 | static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){ |
| | @@ -89153,11 +89413,12 @@ |
| 89153 | 89413 | } |
| 89154 | 89414 | } |
| 89155 | 89415 | } |
| 89156 | 89416 | |
| 89157 | 89417 | /* Start at the inner-most context and move outward until a match is found */ |
| 89158 | | - while( pNC && cnt==0 ){ |
| 89418 | + assert( pNC && cnt==0 ); |
| 89419 | + do{ |
| 89159 | 89420 | ExprList *pEList; |
| 89160 | 89421 | SrcList *pSrcList = pNC->pSrcList; |
| 89161 | 89422 | |
| 89162 | 89423 | if( pSrcList ){ |
| 89163 | 89424 | for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){ |
| | @@ -89338,15 +89599,15 @@ |
| 89338 | 89599 | } |
| 89339 | 89600 | |
| 89340 | 89601 | /* Advance to the next name context. The loop will exit when either |
| 89341 | 89602 | ** we have a match (cnt>0) or when we run out of name contexts. |
| 89342 | 89603 | */ |
| 89343 | | - if( cnt==0 ){ |
| 89344 | | - pNC = pNC->pNext; |
| 89345 | | - nSubquery++; |
| 89346 | | - } |
| 89347 | | - } |
| 89604 | + if( cnt ) break; |
| 89605 | + pNC = pNC->pNext; |
| 89606 | + nSubquery++; |
| 89607 | + }while( pNC ); |
| 89608 | + |
| 89348 | 89609 | |
| 89349 | 89610 | /* |
| 89350 | 89611 | ** If X and Y are NULL (in other words if only the column name Z is |
| 89351 | 89612 | ** supplied) and the value of Z is enclosed in double-quotes, then |
| 89352 | 89613 | ** Z is a string literal if it doesn't match any column names. In that |
| | @@ -89532,37 +89793,42 @@ |
| 89532 | 89793 | break; |
| 89533 | 89794 | } |
| 89534 | 89795 | #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) |
| 89535 | 89796 | && !defined(SQLITE_OMIT_SUBQUERY) */ |
| 89536 | 89797 | |
| 89537 | | - /* A lone identifier is the name of a column. |
| 89538 | | - */ |
| 89539 | | - case TK_ID: { |
| 89540 | | - return lookupName(pParse, 0, 0, pExpr->u.zToken, pNC, pExpr); |
| 89541 | | - } |
| 89542 | | - |
| 89543 | | - /* A table name and column name: ID.ID |
| 89798 | + /* A column name: ID |
| 89799 | + ** Or table name and column name: ID.ID |
| 89544 | 89800 | ** Or a database, table and column: ID.ID.ID |
| 89801 | + ** |
| 89802 | + ** The TK_ID and TK_OUT cases are combined so that there will only |
| 89803 | + ** be one call to lookupName(). Then the compiler will in-line |
| 89804 | + ** lookupName() for a size reduction and performance increase. |
| 89545 | 89805 | */ |
| 89806 | + case TK_ID: |
| 89546 | 89807 | case TK_DOT: { |
| 89547 | 89808 | const char *zColumn; |
| 89548 | 89809 | const char *zTable; |
| 89549 | 89810 | const char *zDb; |
| 89550 | 89811 | Expr *pRight; |
| 89551 | 89812 | |
| 89552 | | - /* if( pSrcList==0 ) break; */ |
| 89553 | | - notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr); |
| 89554 | | - pRight = pExpr->pRight; |
| 89555 | | - if( pRight->op==TK_ID ){ |
| 89813 | + if( pExpr->op==TK_ID ){ |
| 89556 | 89814 | zDb = 0; |
| 89557 | | - zTable = pExpr->pLeft->u.zToken; |
| 89558 | | - zColumn = pRight->u.zToken; |
| 89815 | + zTable = 0; |
| 89816 | + zColumn = pExpr->u.zToken; |
| 89559 | 89817 | }else{ |
| 89560 | | - assert( pRight->op==TK_DOT ); |
| 89561 | | - zDb = pExpr->pLeft->u.zToken; |
| 89562 | | - zTable = pRight->pLeft->u.zToken; |
| 89563 | | - zColumn = pRight->pRight->u.zToken; |
| 89818 | + notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr); |
| 89819 | + pRight = pExpr->pRight; |
| 89820 | + if( pRight->op==TK_ID ){ |
| 89821 | + zDb = 0; |
| 89822 | + zTable = pExpr->pLeft->u.zToken; |
| 89823 | + zColumn = pRight->u.zToken; |
| 89824 | + }else{ |
| 89825 | + assert( pRight->op==TK_DOT ); |
| 89826 | + zDb = pExpr->pLeft->u.zToken; |
| 89827 | + zTable = pRight->pLeft->u.zToken; |
| 89828 | + zColumn = pRight->pRight->u.zToken; |
| 89829 | + } |
| 89564 | 89830 | } |
| 89565 | 89831 | return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr); |
| 89566 | 89832 | } |
| 89567 | 89833 | |
| 89568 | 89834 | /* Resolve function names |
| | @@ -92326,10 +92592,11 @@ |
| 92326 | 92592 | ** in *pValue. If the expression is not an integer or if it is too big |
| 92327 | 92593 | ** to fit in a signed 32-bit integer, return 0 and leave *pValue unchanged. |
| 92328 | 92594 | */ |
| 92329 | 92595 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr *p, int *pValue){ |
| 92330 | 92596 | int rc = 0; |
| 92597 | + if( p==0 ) return 0; /* Can only happen following on OOM */ |
| 92331 | 92598 | |
| 92332 | 92599 | /* If an expression is an integer literal that fits in a signed 32-bit |
| 92333 | 92600 | ** integer, then the EP_IntValue flag will have already been set */ |
| 92334 | 92601 | assert( p->op!=TK_INTEGER || (p->flags & EP_IntValue)!=0 |
| 92335 | 92602 | || sqlite3GetInt32(p->u.zToken, &rc)==0 ); |
| | @@ -92833,11 +93100,11 @@ |
| 92833 | 93100 | int nVal = sqlite3ExprVectorSize(pLeft); |
| 92834 | 93101 | Select *pSelect = (pExpr->flags & EP_xIsSelect) ? pExpr->x.pSelect : 0; |
| 92835 | 93102 | char *zRet; |
| 92836 | 93103 | |
| 92837 | 93104 | assert( pExpr->op==TK_IN ); |
| 92838 | | - zRet = sqlite3DbMallocZero(pParse->db, nVal+1); |
| 93105 | + zRet = sqlite3DbMallocRaw(pParse->db, nVal+1); |
| 92839 | 93106 | if( zRet ){ |
| 92840 | 93107 | int i; |
| 92841 | 93108 | for(i=0; i<nVal; i++){ |
| 92842 | 93109 | Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i); |
| 92843 | 93110 | char a = sqlite3ExprAffinity(pA); |
| | @@ -92998,11 +93265,10 @@ |
| 92998 | 93265 | if( ALWAYS(pEList->nExpr==nVal) ){ |
| 92999 | 93266 | SelectDest dest; |
| 93000 | 93267 | int i; |
| 93001 | 93268 | sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable); |
| 93002 | 93269 | dest.zAffSdst = exprINAffinity(pParse, pExpr); |
| 93003 | | - assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable ); |
| 93004 | 93270 | pSelect->iLimit = 0; |
| 93005 | 93271 | testcase( pSelect->selFlags & SF_Distinct ); |
| 93006 | 93272 | testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */ |
| 93007 | 93273 | if( sqlite3Select(pParse, pSelect, &dest) ){ |
| 93008 | 93274 | sqlite3DbFree(pParse->db, dest.zAffSdst); |
| | @@ -93738,11 +94004,11 @@ |
| 93738 | 94004 | ** Clear all column cache entries. |
| 93739 | 94005 | */ |
| 93740 | 94006 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){ |
| 93741 | 94007 | int i; |
| 93742 | 94008 | |
| 93743 | | -#if SQLITE_DEBUG |
| 94009 | +#ifdef SQLITE_DEBUG |
| 93744 | 94010 | if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ |
| 93745 | 94011 | printf("CLEAR\n"); |
| 93746 | 94012 | } |
| 93747 | 94013 | #endif |
| 93748 | 94014 | for(i=0; i<pParse->nColCache; i++){ |
| | @@ -95145,10 +95411,21 @@ |
| 95145 | 95411 | if( pA->a[i].sortOrder!=pB->a[i].sortOrder ) return 1; |
| 95146 | 95412 | if( sqlite3ExprCompare(pExprA, pExprB, iTab) ) return 1; |
| 95147 | 95413 | } |
| 95148 | 95414 | return 0; |
| 95149 | 95415 | } |
| 95416 | + |
| 95417 | +/* |
| 95418 | +** Like sqlite3ExprCompare() except COLLATE operators at the top-level |
| 95419 | +** are ignored. |
| 95420 | +*/ |
| 95421 | +SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr *pA, Expr *pB, int iTab){ |
| 95422 | + return sqlite3ExprCompare( |
| 95423 | + sqlite3ExprSkipCollate(pA), |
| 95424 | + sqlite3ExprSkipCollate(pB), |
| 95425 | + iTab); |
| 95426 | +} |
| 95150 | 95427 | |
| 95151 | 95428 | /* |
| 95152 | 95429 | ** Return true if we can prove the pE2 will always be true if pE1 is |
| 95153 | 95430 | ** true. Return false if we cannot complete the proof or if pE2 might |
| 95154 | 95431 | ** be false. Examples: |
| | @@ -96698,10 +96975,11 @@ |
| 96698 | 96975 | Stat4Sample current; /* Current row as a Stat4Sample */ |
| 96699 | 96976 | u32 iPrn; /* Pseudo-random number used for sampling */ |
| 96700 | 96977 | Stat4Sample *aBest; /* Array of nCol best samples */ |
| 96701 | 96978 | int iMin; /* Index in a[] of entry with minimum score */ |
| 96702 | 96979 | int nSample; /* Current number of samples */ |
| 96980 | + int nMaxEqZero; /* Max leading 0 in anEq[] for any a[] entry */ |
| 96703 | 96981 | int iGet; /* Index of current sample accessed by stat_get() */ |
| 96704 | 96982 | Stat4Sample *a; /* Array of mxSample Stat4Sample objects */ |
| 96705 | 96983 | sqlite3 *db; /* Database connection, for malloc() */ |
| 96706 | 96984 | }; |
| 96707 | 96985 | |
| | @@ -96962,10 +97240,17 @@ |
| 96962 | 97240 | int i; |
| 96963 | 97241 | |
| 96964 | 97242 | assert( IsStat4 || nEqZero==0 ); |
| 96965 | 97243 | |
| 96966 | 97244 | #ifdef SQLITE_ENABLE_STAT4 |
| 97245 | + /* Stat4Accum.nMaxEqZero is set to the maximum number of leading 0 |
| 97246 | + ** values in the anEq[] array of any sample in Stat4Accum.a[]. In |
| 97247 | + ** other words, if nMaxEqZero is n, then it is guaranteed that there |
| 97248 | + ** are no samples with Stat4Sample.anEq[m]==0 for (m>=n). */ |
| 97249 | + if( nEqZero>p->nMaxEqZero ){ |
| 97250 | + p->nMaxEqZero = nEqZero; |
| 97251 | + } |
| 96967 | 97252 | if( pNew->isPSample==0 ){ |
| 96968 | 97253 | Stat4Sample *pUpgrade = 0; |
| 96969 | 97254 | assert( pNew->anEq[pNew->iCol]>0 ); |
| 96970 | 97255 | |
| 96971 | 97256 | /* This sample is being added because the prefix that ends in column |
| | @@ -97059,16 +97344,26 @@ |
| 97059 | 97344 | if( p->nSample<p->mxSample || sampleIsBetter(p, pBest, &p->a[p->iMin]) ){ |
| 97060 | 97345 | sampleInsert(p, pBest, i); |
| 97061 | 97346 | } |
| 97062 | 97347 | } |
| 97063 | 97348 | |
| 97064 | | - /* Update the anEq[] fields of any samples already collected. */ |
| 97349 | + /* Check that no sample contains an anEq[] entry with an index of |
| 97350 | + ** p->nMaxEqZero or greater set to zero. */ |
| 97065 | 97351 | for(i=p->nSample-1; i>=0; i--){ |
| 97066 | 97352 | int j; |
| 97067 | | - for(j=iChng; j<p->nCol; j++){ |
| 97068 | | - if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j]; |
| 97353 | + for(j=p->nMaxEqZero; j<p->nCol; j++) assert( p->a[i].anEq[j]>0 ); |
| 97354 | + } |
| 97355 | + |
| 97356 | + /* Update the anEq[] fields of any samples already collected. */ |
| 97357 | + if( iChng<p->nMaxEqZero ){ |
| 97358 | + for(i=p->nSample-1; i>=0; i--){ |
| 97359 | + int j; |
| 97360 | + for(j=iChng; j<p->nCol; j++){ |
| 97361 | + if( p->a[i].anEq[j]==0 ) p->a[i].anEq[j] = p->current.anEq[j]; |
| 97362 | + } |
| 97069 | 97363 | } |
| 97364 | + p->nMaxEqZero = iChng; |
| 97070 | 97365 | } |
| 97071 | 97366 | #endif |
| 97072 | 97367 | |
| 97073 | 97368 | #if defined(SQLITE_ENABLE_STAT3) && !defined(SQLITE_ENABLE_STAT4) |
| 97074 | 97369 | if( iChng==0 ){ |
| | @@ -97594,11 +97889,11 @@ |
| 97594 | 97889 | Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); |
| 97595 | 97890 | int j, k, regKey; |
| 97596 | 97891 | regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol); |
| 97597 | 97892 | for(j=0; j<pPk->nKeyCol; j++){ |
| 97598 | 97893 | k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]); |
| 97599 | | - assert( k>=0 && k<pTab->nCol ); |
| 97894 | + assert( k>=0 && k<pIdx->nColumn ); |
| 97600 | 97895 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j); |
| 97601 | 97896 | VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName)); |
| 97602 | 97897 | } |
| 97603 | 97898 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid); |
| 97604 | 97899 | sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol); |
| | @@ -97778,44 +98073,32 @@ |
| 97778 | 98073 | /* Form 1: Analyze everything */ |
| 97779 | 98074 | for(i=0; i<db->nDb; i++){ |
| 97780 | 98075 | if( i==1 ) continue; /* Do not analyze the TEMP database */ |
| 97781 | 98076 | analyzeDatabase(pParse, i); |
| 97782 | 98077 | } |
| 97783 | | - }else if( pName2->n==0 ){ |
| 97784 | | - /* Form 2: Analyze the database or table named */ |
| 97785 | | - iDb = sqlite3FindDb(db, pName1); |
| 97786 | | - if( iDb>=0 ){ |
| 97787 | | - analyzeDatabase(pParse, iDb); |
| 97788 | | - }else{ |
| 97789 | | - z = sqlite3NameFromToken(db, pName1); |
| 97790 | | - if( z ){ |
| 97791 | | - if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){ |
| 97792 | | - analyzeTable(pParse, pIdx->pTable, pIdx); |
| 97793 | | - }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){ |
| 97794 | | - analyzeTable(pParse, pTab, 0); |
| 97795 | | - } |
| 97796 | | - sqlite3DbFree(db, z); |
| 97797 | | - } |
| 97798 | | - } |
| 97799 | | - }else{ |
| 97800 | | - /* Form 3: Analyze the fully qualified table name */ |
| 98078 | + }else if( pName2->n==0 && (iDb = sqlite3FindDb(db, pName1))>=0 ){ |
| 98079 | + /* Analyze the schema named as the argument */ |
| 98080 | + analyzeDatabase(pParse, iDb); |
| 98081 | + }else{ |
| 98082 | + /* Form 3: Analyze the table or index named as an argument */ |
| 97801 | 98083 | iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName); |
| 97802 | 98084 | if( iDb>=0 ){ |
| 97803 | | - zDb = db->aDb[iDb].zDbSName; |
| 98085 | + zDb = pName2->n ? db->aDb[iDb].zDbSName : 0; |
| 97804 | 98086 | z = sqlite3NameFromToken(db, pTableName); |
| 97805 | 98087 | if( z ){ |
| 97806 | 98088 | if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){ |
| 97807 | 98089 | analyzeTable(pParse, pIdx->pTable, pIdx); |
| 97808 | 98090 | }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){ |
| 97809 | 98091 | analyzeTable(pParse, pTab, 0); |
| 97810 | 98092 | } |
| 97811 | 98093 | sqlite3DbFree(db, z); |
| 97812 | 98094 | } |
| 97813 | | - } |
| 98095 | + } |
| 97814 | 98096 | } |
| 97815 | | - v = sqlite3GetVdbe(pParse); |
| 97816 | | - if( v ) sqlite3VdbeAddOp0(v, OP_Expire); |
| 98097 | + if( db->nSqlExec==0 && (v = sqlite3GetVdbe(pParse))!=0 ){ |
| 98098 | + sqlite3VdbeAddOp0(v, OP_Expire); |
| 98099 | + } |
| 97817 | 98100 | } |
| 97818 | 98101 | |
| 97819 | 98102 | /* |
| 97820 | 98103 | ** Used to pass information from the analyzer reader through to the |
| 97821 | 98104 | ** callback routine. |
| | @@ -97940,19 +98223,24 @@ |
| 97940 | 98223 | } |
| 97941 | 98224 | aiRowEst = pIndex->aiRowEst; |
| 97942 | 98225 | #endif |
| 97943 | 98226 | pIndex->bUnordered = 0; |
| 97944 | 98227 | decodeIntArray((char*)z, nCol, aiRowEst, pIndex->aiRowLogEst, pIndex); |
| 97945 | | - if( pIndex->pPartIdxWhere==0 ) pTable->nRowLogEst = pIndex->aiRowLogEst[0]; |
| 98228 | + pIndex->hasStat1 = 1; |
| 98229 | + if( pIndex->pPartIdxWhere==0 ){ |
| 98230 | + pTable->nRowLogEst = pIndex->aiRowLogEst[0]; |
| 98231 | + pTable->tabFlags |= TF_HasStat1; |
| 98232 | + } |
| 97946 | 98233 | }else{ |
| 97947 | 98234 | Index fakeIdx; |
| 97948 | 98235 | fakeIdx.szIdxRow = pTable->szTabRow; |
| 97949 | 98236 | #ifdef SQLITE_ENABLE_COSTMULT |
| 97950 | 98237 | fakeIdx.pTable = pTable; |
| 97951 | 98238 | #endif |
| 97952 | 98239 | decodeIntArray((char*)z, 1, 0, &pTable->nRowLogEst, &fakeIdx); |
| 97953 | 98240 | pTable->szTabRow = fakeIdx.szIdxRow; |
| 98241 | + pTable->tabFlags |= TF_HasStat1; |
| 97954 | 98242 | } |
| 97955 | 98243 | |
| 97956 | 98244 | return 0; |
| 97957 | 98245 | } |
| 97958 | 98246 | |
| | @@ -98243,19 +98531,24 @@ |
| 98243 | 98531 | SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ |
| 98244 | 98532 | analysisInfo sInfo; |
| 98245 | 98533 | HashElem *i; |
| 98246 | 98534 | char *zSql; |
| 98247 | 98535 | int rc = SQLITE_OK; |
| 98536 | + Schema *pSchema = db->aDb[iDb].pSchema; |
| 98248 | 98537 | |
| 98249 | 98538 | assert( iDb>=0 && iDb<db->nDb ); |
| 98250 | 98539 | assert( db->aDb[iDb].pBt!=0 ); |
| 98251 | 98540 | |
| 98252 | 98541 | /* Clear any prior statistics */ |
| 98253 | 98542 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 98254 | | - for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ |
| 98543 | + for(i=sqliteHashFirst(&pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 98544 | + Table *pTab = sqliteHashData(i); |
| 98545 | + pTab->tabFlags &= ~TF_HasStat1; |
| 98546 | + } |
| 98547 | + for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){ |
| 98255 | 98548 | Index *pIdx = sqliteHashData(i); |
| 98256 | | - pIdx->aiRowLogEst[0] = 0; |
| 98549 | + pIdx->hasStat1 = 0; |
| 98257 | 98550 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 98258 | 98551 | sqlite3DeleteIndexSamples(db, pIdx); |
| 98259 | 98552 | pIdx->aSample = 0; |
| 98260 | 98553 | #endif |
| 98261 | 98554 | } |
| | @@ -98274,23 +98567,23 @@ |
| 98274 | 98567 | } |
| 98275 | 98568 | } |
| 98276 | 98569 | |
| 98277 | 98570 | /* Set appropriate defaults on all indexes not in the sqlite_stat1 table */ |
| 98278 | 98571 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 98279 | | - for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ |
| 98572 | + for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){ |
| 98280 | 98573 | Index *pIdx = sqliteHashData(i); |
| 98281 | | - if( pIdx->aiRowLogEst[0]==0 ) sqlite3DefaultRowEst(pIdx); |
| 98574 | + if( !pIdx->hasStat1 ) sqlite3DefaultRowEst(pIdx); |
| 98282 | 98575 | } |
| 98283 | 98576 | |
| 98284 | 98577 | /* Load the statistics from the sqlite_stat4 table. */ |
| 98285 | 98578 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 98286 | 98579 | if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){ |
| 98287 | 98580 | db->lookaside.bDisable++; |
| 98288 | 98581 | rc = loadStat4(db, sInfo.zDatabase); |
| 98289 | 98582 | db->lookaside.bDisable--; |
| 98290 | 98583 | } |
| 98291 | | - for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ |
| 98584 | + for(i=sqliteHashFirst(&pSchema->idxHash); i; i=sqliteHashNext(i)){ |
| 98292 | 98585 | Index *pIdx = sqliteHashData(i); |
| 98293 | 98586 | sqlite3_free(pIdx->aiRowEst); |
| 98294 | 98587 | pIdx->aiRowEst = 0; |
| 98295 | 98588 | } |
| 98296 | 98589 | #endif |
| | @@ -100271,10 +100564,11 @@ |
| 100271 | 100564 | SQLITE_PRIVATE void sqlite3AddNotNull(Parse *pParse, int onError){ |
| 100272 | 100565 | Table *p; |
| 100273 | 100566 | p = pParse->pNewTable; |
| 100274 | 100567 | if( p==0 || NEVER(p->nCol<1) ) return; |
| 100275 | 100568 | p->aCol[p->nCol-1].notNull = (u8)onError; |
| 100569 | + p->tabFlags |= TF_HasNotNull; |
| 100276 | 100570 | } |
| 100277 | 100571 | |
| 100278 | 100572 | /* |
| 100279 | 100573 | ** Scan the column type name zType (length nType) and return the |
| 100280 | 100574 | ** associated affinity type. |
| | @@ -102609,10 +102903,13 @@ |
| 102609 | 102903 | /* 10, 9, 8, 7, 6 */ |
| 102610 | 102904 | LogEst aVal[] = { 33, 32, 30, 28, 26 }; |
| 102611 | 102905 | LogEst *a = pIdx->aiRowLogEst; |
| 102612 | 102906 | int nCopy = MIN(ArraySize(aVal), pIdx->nKeyCol); |
| 102613 | 102907 | int i; |
| 102908 | + |
| 102909 | + /* Indexes with default row estimates should not have stat1 data */ |
| 102910 | + assert( !pIdx->hasStat1 ); |
| 102614 | 102911 | |
| 102615 | 102912 | /* Set the first entry (number of rows in the index) to the estimated |
| 102616 | 102913 | ** number of rows in the table, or half the number of rows in the table |
| 102617 | 102914 | ** for a partial index. But do not let the estimate drop below 10. */ |
| 102618 | 102915 | a[0] = pIdx->pTable->nRowLogEst; |
| | @@ -105193,19 +105490,17 @@ |
| 105193 | 105490 | nNeedle = sqlite3_value_bytes(argv[1]); |
| 105194 | 105491 | if( nNeedle>0 ){ |
| 105195 | 105492 | if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){ |
| 105196 | 105493 | zHaystack = sqlite3_value_blob(argv[0]); |
| 105197 | 105494 | zNeedle = sqlite3_value_blob(argv[1]); |
| 105198 | | - assert( zNeedle!=0 ); |
| 105199 | | - assert( zHaystack!=0 || nHaystack==0 ); |
| 105200 | 105495 | isText = 0; |
| 105201 | 105496 | }else{ |
| 105202 | 105497 | zHaystack = sqlite3_value_text(argv[0]); |
| 105203 | 105498 | zNeedle = sqlite3_value_text(argv[1]); |
| 105204 | 105499 | isText = 1; |
| 105205 | | - if( zHaystack==0 || zNeedle==0 ) return; |
| 105206 | 105500 | } |
| 105501 | + if( zNeedle==0 || (nHaystack && zHaystack==0) ) return; |
| 105207 | 105502 | while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){ |
| 105208 | 105503 | N++; |
| 105209 | 105504 | do{ |
| 105210 | 105505 | nHaystack--; |
| 105211 | 105506 | zHaystack++; |
| | @@ -109798,10 +110093,13 @@ |
| 109798 | 110093 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| 109799 | 110094 | } |
| 109800 | 110095 | } |
| 109801 | 110096 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]); |
| 109802 | 110097 | VdbeComment((v, "for %s", pIdx->zName)); |
| 110098 | +#ifdef SQLITE_ENABLE_NULL_TRIM |
| 110099 | + if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable); |
| 110100 | +#endif |
| 109803 | 110101 | |
| 109804 | 110102 | /* In an UPDATE operation, if this index is the PRIMARY KEY index |
| 109805 | 110103 | ** of a WITHOUT ROWID table and there has been no change the |
| 109806 | 110104 | ** primary key, then no collision is possible. The collision detection |
| 109807 | 110105 | ** logic below can all be skipped. */ |
| | @@ -109953,12 +110251,15 @@ |
| 109953 | 110251 | |
| 109954 | 110252 | /* Records with omitted columns are only allowed for schema format |
| 109955 | 110253 | ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */ |
| 109956 | 110254 | if( pTab->pSchema->file_format<2 ) return; |
| 109957 | 110255 | |
| 109958 | | - for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){} |
| 109959 | | - sqlite3VdbeChangeP5(v, i); |
| 110256 | + for(i=pTab->nCol-1; i>0; i--){ |
| 110257 | + if( pTab->aCol[i].pDflt!=0 ) break; |
| 110258 | + if( pTab->aCol[i].colFlags & COLFLAG_PRIMKEY ) break; |
| 110259 | + } |
| 110260 | + sqlite3VdbeChangeP5(v, i+1); |
| 109960 | 110261 | } |
| 109961 | 110262 | #endif |
| 109962 | 110263 | |
| 109963 | 110264 | /* |
| 109964 | 110265 | ** This routine generates code to finish the INSERT or UPDATE operation |
| | @@ -110244,11 +110545,11 @@ |
| 110244 | 110545 | } |
| 110245 | 110546 | if( sqlite3TriggerList(pParse, pDest) ){ |
| 110246 | 110547 | return 0; /* tab1 must not have triggers */ |
| 110247 | 110548 | } |
| 110248 | 110549 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 110249 | | - if( pDest->tabFlags & TF_Virtual ){ |
| 110550 | + if( IsVirtual(pDest) ){ |
| 110250 | 110551 | return 0; /* tab1 must not be a virtual table */ |
| 110251 | 110552 | } |
| 110252 | 110553 | #endif |
| 110253 | 110554 | if( onError==OE_Default ){ |
| 110254 | 110555 | if( pDest->iPKey>=0 ) onError = pDest->keyConf; |
| | @@ -110306,11 +110607,11 @@ |
| 110306 | 110607 | } |
| 110307 | 110608 | if( HasRowid(pDest)!=HasRowid(pSrc) ){ |
| 110308 | 110609 | return 0; /* source and destination must both be WITHOUT ROWID or not */ |
| 110309 | 110610 | } |
| 110310 | 110611 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 110311 | | - if( pSrc->tabFlags & TF_Virtual ){ |
| 110612 | + if( IsVirtual(pSrc) ){ |
| 110312 | 110613 | return 0; /* tab2 must not be a virtual table */ |
| 110313 | 110614 | } |
| 110314 | 110615 | #endif |
| 110315 | 110616 | if( pSrc->pSelect ){ |
| 110316 | 110617 | return 0; /* tab2 may not be a view */ |
| | @@ -110492,12 +110793,10 @@ |
| 110492 | 110793 | ** might change the definition of a collation sequence and then run |
| 110493 | 110794 | ** a VACUUM command. In that case keys may not be written in strictly |
| 110494 | 110795 | ** sorted order. */ |
| 110495 | 110796 | for(i=0; i<pSrcIdx->nColumn; i++){ |
| 110496 | 110797 | const char *zColl = pSrcIdx->azColl[i]; |
| 110497 | | - assert( sqlite3_stricmp(sqlite3StrBINARY, zColl)!=0 |
| 110498 | | - || sqlite3StrBINARY==zColl ); |
| 110499 | 110798 | if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break; |
| 110500 | 110799 | } |
| 110501 | 110800 | if( i==pSrcIdx->nColumn ){ |
| 110502 | 110801 | idxInsFlags = OPFLAG_USESEEKRESULT; |
| 110503 | 110802 | sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| | @@ -110603,11 +110902,11 @@ |
| 110603 | 110902 | /* Invoke the callback function if required */ |
| 110604 | 110903 | if( xCallback && (SQLITE_ROW==rc || |
| 110605 | 110904 | (SQLITE_DONE==rc && !callbackIsInit |
| 110606 | 110905 | && db->flags&SQLITE_NullCallback)) ){ |
| 110607 | 110906 | if( !callbackIsInit ){ |
| 110608 | | - azCols = sqlite3DbMallocZero(db, 2*nCol*sizeof(const char*) + 1); |
| 110907 | + azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*)); |
| 110609 | 110908 | if( azCols==0 ){ |
| 110610 | 110909 | goto exec_out; |
| 110611 | 110910 | } |
| 110612 | 110911 | for(i=0; i<nCol; i++){ |
| 110613 | 110912 | azCols[i] = (char *)sqlite3_column_name(pStmt, i); |
| | @@ -110624,10 +110923,11 @@ |
| 110624 | 110923 | if( !azVals[i] && sqlite3_column_type(pStmt, i)!=SQLITE_NULL ){ |
| 110625 | 110924 | sqlite3OomFault(db); |
| 110626 | 110925 | goto exec_out; |
| 110627 | 110926 | } |
| 110628 | 110927 | } |
| 110928 | + azVals[i] = 0; |
| 110629 | 110929 | } |
| 110630 | 110930 | if( xCallback(pArg, nCol, azVals, azCols) ){ |
| 110631 | 110931 | /* EVIDENCE-OF: R-38229-40159 If the callback function to |
| 110632 | 110932 | ** sqlite3_exec() returns non-zero, then sqlite3_exec() will |
| 110633 | 110933 | ** return SQLITE_ABORT. */ |
| | @@ -110979,10 +111279,12 @@ |
| 110979 | 111279 | /* Version 3.12.0 and later */ |
| 110980 | 111280 | int (*system_errno)(sqlite3*); |
| 110981 | 111281 | /* Version 3.14.0 and later */ |
| 110982 | 111282 | int (*trace_v2)(sqlite3*,unsigned,int(*)(unsigned,void*,void*,void*),void*); |
| 110983 | 111283 | char *(*expanded_sql)(sqlite3_stmt*); |
| 111284 | + /* Version 3.18.0 and later */ |
| 111285 | + void (*set_last_insert_rowid)(sqlite3*,sqlite3_int64); |
| 110984 | 111286 | }; |
| 110985 | 111287 | |
| 110986 | 111288 | /* |
| 110987 | 111289 | ** This is the function signature used for all extension entry points. It |
| 110988 | 111290 | ** is also defined in the file "loadext.c". |
| | @@ -111237,10 +111539,12 @@ |
| 111237 | 111539 | /* Version 3.12.0 and later */ |
| 111238 | 111540 | #define sqlite3_system_errno sqlite3_api->system_errno |
| 111239 | 111541 | /* Version 3.14.0 and later */ |
| 111240 | 111542 | #define sqlite3_trace_v2 sqlite3_api->trace_v2 |
| 111241 | 111543 | #define sqlite3_expanded_sql sqlite3_api->expanded_sql |
| 111544 | +/* Version 3.18.0 and later */ |
| 111545 | +#define sqlite3_set_last_insert_rowid sqlite3_api->set_last_insert_rowid |
| 111242 | 111546 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 111243 | 111547 | |
| 111244 | 111548 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 111245 | 111549 | /* This case when the file really is being compiled as a loadable |
| 111246 | 111550 | ** extension */ |
| | @@ -111662,11 +111966,13 @@ |
| 111662 | 111966 | sqlite3_db_cacheflush, |
| 111663 | 111967 | /* Version 3.12.0 and later */ |
| 111664 | 111968 | sqlite3_system_errno, |
| 111665 | 111969 | /* Version 3.14.0 and later */ |
| 111666 | 111970 | sqlite3_trace_v2, |
| 111667 | | - sqlite3_expanded_sql |
| 111971 | + sqlite3_expanded_sql, |
| 111972 | + /* Version 3.18.0 and later */ |
| 111973 | + sqlite3_set_last_insert_rowid |
| 111668 | 111974 | }; |
| 111669 | 111975 | |
| 111670 | 111976 | /* |
| 111671 | 111977 | ** Attempt to load an SQLite extension library contained in the file |
| 111672 | 111978 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| | @@ -112094,15 +112400,15 @@ |
| 112094 | 112400 | #define PragTyp_JOURNAL_SIZE_LIMIT 20 |
| 112095 | 112401 | #define PragTyp_LOCK_PROXY_FILE 21 |
| 112096 | 112402 | #define PragTyp_LOCKING_MODE 22 |
| 112097 | 112403 | #define PragTyp_PAGE_COUNT 23 |
| 112098 | 112404 | #define PragTyp_MMAP_SIZE 24 |
| 112099 | | -#define PragTyp_PAGE_SIZE 25 |
| 112100 | | -#define PragTyp_SECURE_DELETE 26 |
| 112101 | | -#define PragTyp_SHRINK_MEMORY 27 |
| 112102 | | -#define PragTyp_SOFT_HEAP_LIMIT 28 |
| 112103 | | -#define PragTyp_STATS 29 |
| 112405 | +#define PragTyp_OPTIMIZE 25 |
| 112406 | +#define PragTyp_PAGE_SIZE 26 |
| 112407 | +#define PragTyp_SECURE_DELETE 27 |
| 112408 | +#define PragTyp_SHRINK_MEMORY 28 |
| 112409 | +#define PragTyp_SOFT_HEAP_LIMIT 29 |
| 112104 | 112410 | #define PragTyp_SYNCHRONOUS 30 |
| 112105 | 112411 | #define PragTyp_TABLE_INFO 31 |
| 112106 | 112412 | #define PragTyp_TEMP_STORE 32 |
| 112107 | 112413 | #define PragTyp_TEMP_STORE_DIRECTORY 33 |
| 112108 | 112414 | #define PragTyp_THREADS 34 |
| | @@ -112112,10 +112418,11 @@ |
| 112112 | 112418 | #define PragTyp_HEXKEY 38 |
| 112113 | 112419 | #define PragTyp_KEY 39 |
| 112114 | 112420 | #define PragTyp_REKEY 40 |
| 112115 | 112421 | #define PragTyp_LOCK_STATUS 41 |
| 112116 | 112422 | #define PragTyp_PARSER_TRACE 42 |
| 112423 | +#define PragTyp_STATS 43 |
| 112117 | 112424 | |
| 112118 | 112425 | /* Property flags associated with various pragma. */ |
| 112119 | 112426 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 112120 | 112427 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 112121 | 112428 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| | @@ -112135,51 +112442,52 @@ |
| 112135 | 112442 | /* 2 */ "name", |
| 112136 | 112443 | /* 3 */ "type", |
| 112137 | 112444 | /* 4 */ "notnull", |
| 112138 | 112445 | /* 5 */ "dflt_value", |
| 112139 | 112446 | /* 6 */ "pk", |
| 112140 | | - /* 7 */ "table", /* Used by: stats */ |
| 112141 | | - /* 8 */ "index", |
| 112142 | | - /* 9 */ "width", |
| 112143 | | - /* 10 */ "height", |
| 112144 | | - /* 11 */ "seqno", /* Used by: index_info */ |
| 112145 | | - /* 12 */ "cid", |
| 112146 | | - /* 13 */ "name", |
| 112147 | | - /* 14 */ "seqno", /* Used by: index_xinfo */ |
| 112148 | | - /* 15 */ "cid", |
| 112149 | | - /* 16 */ "name", |
| 112150 | | - /* 17 */ "desc", |
| 112151 | | - /* 18 */ "coll", |
| 112152 | | - /* 19 */ "key", |
| 112153 | | - /* 20 */ "seq", /* Used by: index_list */ |
| 112154 | | - /* 21 */ "name", |
| 112155 | | - /* 22 */ "unique", |
| 112156 | | - /* 23 */ "origin", |
| 112157 | | - /* 24 */ "partial", |
| 112158 | | - /* 25 */ "seq", /* Used by: database_list */ |
| 112159 | | - /* 26 */ "name", |
| 112160 | | - /* 27 */ "file", |
| 112161 | | - /* 28 */ "seq", /* Used by: collation_list */ |
| 112162 | | - /* 29 */ "name", |
| 112163 | | - /* 30 */ "id", /* Used by: foreign_key_list */ |
| 112164 | | - /* 31 */ "seq", |
| 112165 | | - /* 32 */ "table", |
| 112166 | | - /* 33 */ "from", |
| 112167 | | - /* 34 */ "to", |
| 112168 | | - /* 35 */ "on_update", |
| 112169 | | - /* 36 */ "on_delete", |
| 112170 | | - /* 37 */ "match", |
| 112171 | | - /* 38 */ "table", /* Used by: foreign_key_check */ |
| 112172 | | - /* 39 */ "rowid", |
| 112173 | | - /* 40 */ "parent", |
| 112174 | | - /* 41 */ "fkid", |
| 112175 | | - /* 42 */ "busy", /* Used by: wal_checkpoint */ |
| 112176 | | - /* 43 */ "log", |
| 112177 | | - /* 44 */ "checkpointed", |
| 112178 | | - /* 45 */ "timeout", /* Used by: busy_timeout */ |
| 112179 | | - /* 46 */ "database", /* Used by: lock_status */ |
| 112180 | | - /* 47 */ "status", |
| 112447 | + /* 7 */ "tbl", /* Used by: stats */ |
| 112448 | + /* 8 */ "idx", |
| 112449 | + /* 9 */ "wdth", |
| 112450 | + /* 10 */ "hght", |
| 112451 | + /* 11 */ "flgs", |
| 112452 | + /* 12 */ "seqno", /* Used by: index_info */ |
| 112453 | + /* 13 */ "cid", |
| 112454 | + /* 14 */ "name", |
| 112455 | + /* 15 */ "seqno", /* Used by: index_xinfo */ |
| 112456 | + /* 16 */ "cid", |
| 112457 | + /* 17 */ "name", |
| 112458 | + /* 18 */ "desc", |
| 112459 | + /* 19 */ "coll", |
| 112460 | + /* 20 */ "key", |
| 112461 | + /* 21 */ "seq", /* Used by: index_list */ |
| 112462 | + /* 22 */ "name", |
| 112463 | + /* 23 */ "unique", |
| 112464 | + /* 24 */ "origin", |
| 112465 | + /* 25 */ "partial", |
| 112466 | + /* 26 */ "seq", /* Used by: database_list */ |
| 112467 | + /* 27 */ "name", |
| 112468 | + /* 28 */ "file", |
| 112469 | + /* 29 */ "seq", /* Used by: collation_list */ |
| 112470 | + /* 30 */ "name", |
| 112471 | + /* 31 */ "id", /* Used by: foreign_key_list */ |
| 112472 | + /* 32 */ "seq", |
| 112473 | + /* 33 */ "table", |
| 112474 | + /* 34 */ "from", |
| 112475 | + /* 35 */ "to", |
| 112476 | + /* 36 */ "on_update", |
| 112477 | + /* 37 */ "on_delete", |
| 112478 | + /* 38 */ "match", |
| 112479 | + /* 39 */ "table", /* Used by: foreign_key_check */ |
| 112480 | + /* 40 */ "rowid", |
| 112481 | + /* 41 */ "parent", |
| 112482 | + /* 42 */ "fkid", |
| 112483 | + /* 43 */ "busy", /* Used by: wal_checkpoint */ |
| 112484 | + /* 44 */ "log", |
| 112485 | + /* 45 */ "checkpointed", |
| 112486 | + /* 46 */ "timeout", /* Used by: busy_timeout */ |
| 112487 | + /* 47 */ "database", /* Used by: lock_status */ |
| 112488 | + /* 48 */ "status", |
| 112181 | 112489 | }; |
| 112182 | 112490 | |
| 112183 | 112491 | /* Definitions of all built-in pragmas */ |
| 112184 | 112492 | typedef struct PragmaName { |
| 112185 | 112493 | const char *const zName; /* Name of pragma */ |
| | @@ -112221,11 +112529,11 @@ |
| 112221 | 112529 | #endif |
| 112222 | 112530 | #endif |
| 112223 | 112531 | {/* zName: */ "busy_timeout", |
| 112224 | 112532 | /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, |
| 112225 | 112533 | /* ePragFlg: */ PragFlg_Result0, |
| 112226 | | - /* ColNames: */ 45, 1, |
| 112534 | + /* ColNames: */ 46, 1, |
| 112227 | 112535 | /* iArg: */ 0 }, |
| 112228 | 112536 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 112229 | 112537 | {/* zName: */ "cache_size", |
| 112230 | 112538 | /* ePragTyp: */ PragTyp_CACHE_SIZE, |
| 112231 | 112539 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| | @@ -112258,11 +112566,11 @@ |
| 112258 | 112566 | #endif |
| 112259 | 112567 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 112260 | 112568 | {/* zName: */ "collation_list", |
| 112261 | 112569 | /* ePragTyp: */ PragTyp_COLLATION_LIST, |
| 112262 | 112570 | /* ePragFlg: */ PragFlg_Result0, |
| 112263 | | - /* ColNames: */ 28, 2, |
| 112571 | + /* ColNames: */ 29, 2, |
| 112264 | 112572 | /* iArg: */ 0 }, |
| 112265 | 112573 | #endif |
| 112266 | 112574 | #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) |
| 112267 | 112575 | {/* zName: */ "compile_options", |
| 112268 | 112576 | /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, |
| | @@ -112293,11 +112601,11 @@ |
| 112293 | 112601 | #endif |
| 112294 | 112602 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 112295 | 112603 | {/* zName: */ "database_list", |
| 112296 | 112604 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 112297 | 112605 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, |
| 112298 | | - /* ColNames: */ 25, 3, |
| 112606 | + /* ColNames: */ 26, 3, |
| 112299 | 112607 | /* iArg: */ 0 }, |
| 112300 | 112608 | #endif |
| 112301 | 112609 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 112302 | 112610 | {/* zName: */ "default_cache_size", |
| 112303 | 112611 | /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, |
| | @@ -112330,18 +112638,18 @@ |
| 112330 | 112638 | #endif |
| 112331 | 112639 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 112332 | 112640 | {/* zName: */ "foreign_key_check", |
| 112333 | 112641 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, |
| 112334 | 112642 | /* ePragFlg: */ PragFlg_NeedSchema, |
| 112335 | | - /* ColNames: */ 38, 4, |
| 112643 | + /* ColNames: */ 39, 4, |
| 112336 | 112644 | /* iArg: */ 0 }, |
| 112337 | 112645 | #endif |
| 112338 | 112646 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) |
| 112339 | 112647 | {/* zName: */ "foreign_key_list", |
| 112340 | 112648 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, |
| 112341 | 112649 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 112342 | | - /* ColNames: */ 30, 8, |
| 112650 | + /* ColNames: */ 31, 8, |
| 112343 | 112651 | /* iArg: */ 0 }, |
| 112344 | 112652 | #endif |
| 112345 | 112653 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 112346 | 112654 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 112347 | 112655 | {/* zName: */ "foreign_keys", |
| | @@ -112400,21 +112708,21 @@ |
| 112400 | 112708 | #endif |
| 112401 | 112709 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 112402 | 112710 | {/* zName: */ "index_info", |
| 112403 | 112711 | /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 112404 | 112712 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 112405 | | - /* ColNames: */ 11, 3, |
| 112713 | + /* ColNames: */ 12, 3, |
| 112406 | 112714 | /* iArg: */ 0 }, |
| 112407 | 112715 | {/* zName: */ "index_list", |
| 112408 | 112716 | /* ePragTyp: */ PragTyp_INDEX_LIST, |
| 112409 | 112717 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 112410 | | - /* ColNames: */ 20, 5, |
| 112718 | + /* ColNames: */ 21, 5, |
| 112411 | 112719 | /* iArg: */ 0 }, |
| 112412 | 112720 | {/* zName: */ "index_xinfo", |
| 112413 | 112721 | /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 112414 | 112722 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 112415 | | - /* ColNames: */ 14, 6, |
| 112723 | + /* ColNames: */ 15, 6, |
| 112416 | 112724 | /* iArg: */ 1 }, |
| 112417 | 112725 | #endif |
| 112418 | 112726 | #if !defined(SQLITE_OMIT_INTEGRITY_CHECK) |
| 112419 | 112727 | {/* zName: */ "integrity_check", |
| 112420 | 112728 | /* ePragTyp: */ PragTyp_INTEGRITY_CHECK, |
| | @@ -112457,11 +112765,11 @@ |
| 112457 | 112765 | #endif |
| 112458 | 112766 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 112459 | 112767 | {/* zName: */ "lock_status", |
| 112460 | 112768 | /* ePragTyp: */ PragTyp_LOCK_STATUS, |
| 112461 | 112769 | /* ePragFlg: */ PragFlg_Result0, |
| 112462 | | - /* ColNames: */ 46, 2, |
| 112770 | + /* ColNames: */ 47, 2, |
| 112463 | 112771 | /* iArg: */ 0 }, |
| 112464 | 112772 | #endif |
| 112465 | 112773 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 112466 | 112774 | {/* zName: */ "locking_mode", |
| 112467 | 112775 | /* ePragTyp: */ PragTyp_LOCKING_MODE, |
| | @@ -112476,10 +112784,17 @@ |
| 112476 | 112784 | {/* zName: */ "mmap_size", |
| 112477 | 112785 | /* ePragTyp: */ PragTyp_MMAP_SIZE, |
| 112478 | 112786 | /* ePragFlg: */ 0, |
| 112479 | 112787 | /* ColNames: */ 0, 0, |
| 112480 | 112788 | /* iArg: */ 0 }, |
| 112789 | +#endif |
| 112790 | + {/* zName: */ "optimize", |
| 112791 | + /* ePragTyp: */ PragTyp_OPTIMIZE, |
| 112792 | + /* ePragFlg: */ PragFlg_Result1, |
| 112793 | + /* ColNames: */ 0, 0, |
| 112794 | + /* iArg: */ 0 }, |
| 112795 | +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 112481 | 112796 | {/* zName: */ "page_count", |
| 112482 | 112797 | /* ePragTyp: */ PragTyp_PAGE_COUNT, |
| 112483 | 112798 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq, |
| 112484 | 112799 | /* ColNames: */ 0, 0, |
| 112485 | 112800 | /* iArg: */ 0 }, |
| | @@ -112574,15 +112889,15 @@ |
| 112574 | 112889 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 112575 | 112890 | /* ColNames: */ 0, 0, |
| 112576 | 112891 | /* iArg: */ SQLITE_SqlTrace }, |
| 112577 | 112892 | #endif |
| 112578 | 112893 | #endif |
| 112579 | | -#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 112894 | +#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG) |
| 112580 | 112895 | {/* zName: */ "stats", |
| 112581 | 112896 | /* ePragTyp: */ PragTyp_STATS, |
| 112582 | 112897 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq, |
| 112583 | | - /* ColNames: */ 7, 4, |
| 112898 | + /* ColNames: */ 7, 5, |
| 112584 | 112899 | /* iArg: */ 0 }, |
| 112585 | 112900 | #endif |
| 112586 | 112901 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 112587 | 112902 | {/* zName: */ "synchronous", |
| 112588 | 112903 | /* ePragTyp: */ PragTyp_SYNCHRONOUS, |
| | @@ -112657,11 +112972,11 @@ |
| 112657 | 112972 | /* ColNames: */ 0, 0, |
| 112658 | 112973 | /* iArg: */ 0 }, |
| 112659 | 112974 | {/* zName: */ "wal_checkpoint", |
| 112660 | 112975 | /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, |
| 112661 | 112976 | /* ePragFlg: */ PragFlg_NeedSchema, |
| 112662 | | - /* ColNames: */ 42, 3, |
| 112977 | + /* ColNames: */ 43, 3, |
| 112663 | 112978 | /* iArg: */ 0 }, |
| 112664 | 112979 | #endif |
| 112665 | 112980 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 112666 | 112981 | {/* zName: */ "writable_schema", |
| 112667 | 112982 | /* ePragTyp: */ PragTyp_FLAG, |
| | @@ -112668,11 +112983,11 @@ |
| 112668 | 112983 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 112669 | 112984 | /* ColNames: */ 0, 0, |
| 112670 | 112985 | /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode }, |
| 112671 | 112986 | #endif |
| 112672 | 112987 | }; |
| 112673 | | -/* Number of pragmas: 60 on by default, 73 total. */ |
| 112988 | +/* Number of pragmas: 60 on by default, 74 total. */ |
| 112674 | 112989 | |
| 112675 | 112990 | /************** End of pragma.h **********************************************/ |
| 112676 | 112991 | /************** Continuing where we left off in pragma.c *********************/ |
| 112677 | 112992 | |
| 112678 | 112993 | /* |
| | @@ -112937,10 +113252,26 @@ |
| 112937 | 113252 | lwr = mid + 1; |
| 112938 | 113253 | } |
| 112939 | 113254 | } |
| 112940 | 113255 | return lwr>upr ? 0 : &aPragmaName[mid]; |
| 112941 | 113256 | } |
| 113257 | + |
| 113258 | +/* |
| 113259 | +** Helper subroutine for PRAGMA integrity_check: |
| 113260 | +** |
| 113261 | +** Generate code to output a single-column result row with the result |
| 113262 | +** held in register regResult. Decrement the result count and halt if |
| 113263 | +** the maximum number of result rows have been issued. |
| 113264 | +*/ |
| 113265 | +static int integrityCheckResultRow(Vdbe *v, int regResult){ |
| 113266 | + int addr; |
| 113267 | + sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1); |
| 113268 | + addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1); |
| 113269 | + VdbeCoverage(v); |
| 113270 | + sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 113271 | + return addr; |
| 113272 | +} |
| 112942 | 113273 | |
| 112943 | 113274 | /* |
| 112944 | 113275 | ** Process a pragma statement. |
| 112945 | 113276 | ** |
| 112946 | 113277 | ** Pragmas are of this form: |
| | @@ -113642,11 +113973,11 @@ |
| 113642 | 113973 | returnSingleInt(v, pDb->safety_level-1); |
| 113643 | 113974 | }else{ |
| 113644 | 113975 | if( !db->autoCommit ){ |
| 113645 | 113976 | sqlite3ErrorMsg(pParse, |
| 113646 | 113977 | "Safety level may not be changed inside a transaction"); |
| 113647 | | - }else{ |
| 113978 | + }else if( iDb!=1 ){ |
| 113648 | 113979 | int iLevel = (getSafetyLevel(zRight,0,1)+1) & PAGER_SYNCHRONOUS_MASK; |
| 113649 | 113980 | if( iLevel==0 ) iLevel = 1; |
| 113650 | 113981 | pDb->safety_level = iLevel; |
| 113651 | 113982 | pDb->bSyncSet = 1; |
| 113652 | 113983 | setAllPagerFlags(db); |
| | @@ -113741,33 +114072,37 @@ |
| 113741 | 114072 | } |
| 113742 | 114073 | } |
| 113743 | 114074 | } |
| 113744 | 114075 | break; |
| 113745 | 114076 | |
| 114077 | +#ifdef SQLITE_DEBUG |
| 113746 | 114078 | case PragTyp_STATS: { |
| 113747 | 114079 | Index *pIdx; |
| 113748 | 114080 | HashElem *i; |
| 113749 | | - pParse->nMem = 4; |
| 114081 | + pParse->nMem = 5; |
| 113750 | 114082 | sqlite3CodeVerifySchema(pParse, iDb); |
| 113751 | 114083 | for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){ |
| 113752 | 114084 | Table *pTab = sqliteHashData(i); |
| 113753 | | - sqlite3VdbeMultiLoad(v, 1, "ssii", |
| 114085 | + sqlite3VdbeMultiLoad(v, 1, "ssiii", |
| 113754 | 114086 | pTab->zName, |
| 113755 | 114087 | 0, |
| 113756 | 114088 | pTab->szTabRow, |
| 113757 | | - pTab->nRowLogEst); |
| 113758 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 114089 | + pTab->nRowLogEst, |
| 114090 | + pTab->tabFlags); |
| 114091 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5); |
| 113759 | 114092 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 113760 | | - sqlite3VdbeMultiLoad(v, 2, "sii", |
| 114093 | + sqlite3VdbeMultiLoad(v, 2, "siii", |
| 113761 | 114094 | pIdx->zName, |
| 113762 | 114095 | pIdx->szIdxRow, |
| 113763 | | - pIdx->aiRowLogEst[0]); |
| 113764 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 4); |
| 114096 | + pIdx->aiRowLogEst[0], |
| 114097 | + pIdx->hasStat1); |
| 114098 | + sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 5); |
| 113765 | 114099 | } |
| 113766 | 114100 | } |
| 113767 | 114101 | } |
| 113768 | 114102 | break; |
| 114103 | +#endif |
| 113769 | 114104 | |
| 113770 | 114105 | case PragTyp_INDEX_INFO: if( zRight ){ |
| 113771 | 114106 | Index *pIdx; |
| 113772 | 114107 | Table *pTab; |
| 113773 | 114108 | pIdx = sqlite3FindIndex(db, zRight, zDb); |
| | @@ -114020,13 +114355,21 @@ |
| 114020 | 114355 | #ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX |
| 114021 | 114356 | # define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100 |
| 114022 | 114357 | #endif |
| 114023 | 114358 | |
| 114024 | 114359 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
| 114025 | | - /* Pragma "quick_check" is reduced version of |
| 114360 | + /* PRAGMA integrity_check |
| 114361 | + ** PRAGMA integrity_check(N) |
| 114362 | + ** PRAGMA quick_check |
| 114363 | + ** PRAGMA quick_check(N) |
| 114364 | + ** |
| 114365 | + ** Verify the integrity of the database. |
| 114366 | + ** |
| 114367 | + ** The "quick_check" is reduced version of |
| 114026 | 114368 | ** integrity_check designed to detect most database corruption |
| 114027 | | - ** without most of the overhead of a full integrity-check. |
| 114369 | + ** without the overhead of cross-checking indexes. Quick_check |
| 114370 | + ** is linear time wherease integrity_check is O(NlogN). |
| 114028 | 114371 | */ |
| 114029 | 114372 | case PragTyp_INTEGRITY_CHECK: { |
| 114030 | 114373 | int i, j, addr, mxErr; |
| 114031 | 114374 | |
| 114032 | 114375 | int isQuick = (sqlite3Tolower(zLeft[0])=='q'); |
| | @@ -114053,11 +114396,11 @@ |
| 114053 | 114396 | sqlite3GetInt32(zRight, &mxErr); |
| 114054 | 114397 | if( mxErr<=0 ){ |
| 114055 | 114398 | mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX; |
| 114056 | 114399 | } |
| 114057 | 114400 | } |
| 114058 | | - sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1); /* reg[1] holds errors left */ |
| 114401 | + sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */ |
| 114059 | 114402 | |
| 114060 | 114403 | /* Do an integrity check on each database file */ |
| 114061 | 114404 | for(i=0; i<db->nDb; i++){ |
| 114062 | 114405 | HashElem *x; |
| 114063 | 114406 | Hash *pTbls; |
| | @@ -114068,14 +114411,10 @@ |
| 114068 | 114411 | |
| 114069 | 114412 | if( OMIT_TEMPDB && i==1 ) continue; |
| 114070 | 114413 | if( iDb>=0 && i!=iDb ) continue; |
| 114071 | 114414 | |
| 114072 | 114415 | sqlite3CodeVerifySchema(pParse, i); |
| 114073 | | - addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */ |
| 114074 | | - VdbeCoverage(v); |
| 114075 | | - sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 114076 | | - sqlite3VdbeJumpHere(v, addr); |
| 114077 | 114416 | |
| 114078 | 114417 | /* Do an integrity check of the B-Tree |
| 114079 | 114418 | ** |
| 114080 | 114419 | ** Begin by finding the root pages numbers |
| 114081 | 114420 | ** for all tables and indices in the database. |
| | @@ -114111,29 +114450,31 @@ |
| 114111 | 114450 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, |
| 114112 | 114451 | sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName), |
| 114113 | 114452 | P4_DYNAMIC); |
| 114114 | 114453 | sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1); |
| 114115 | 114454 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2); |
| 114116 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 2, 1); |
| 114455 | + integrityCheckResultRow(v, 2); |
| 114117 | 114456 | sqlite3VdbeJumpHere(v, addr); |
| 114118 | 114457 | |
| 114119 | 114458 | /* Make sure all the indices are constructed correctly. |
| 114120 | 114459 | */ |
| 114121 | | - for(x=sqliteHashFirst(pTbls); x && !isQuick; x=sqliteHashNext(x)){ |
| 114460 | + for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
| 114122 | 114461 | Table *pTab = sqliteHashData(x); |
| 114123 | 114462 | Index *pIdx, *pPk; |
| 114124 | 114463 | Index *pPrior = 0; |
| 114125 | 114464 | int loopTop; |
| 114126 | 114465 | int iDataCur, iIdxCur; |
| 114127 | 114466 | int r1 = -1; |
| 114128 | 114467 | |
| 114129 | | - if( pTab->pIndex==0 ) continue; |
| 114468 | + if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */ |
| 114469 | + if( pTab->pCheck==0 |
| 114470 | + && (pTab->tabFlags & TF_HasNotNull)==0 |
| 114471 | + && (pTab->pIndex==0 || isQuick) |
| 114472 | + ){ |
| 114473 | + continue; /* No additional checks needed for this table */ |
| 114474 | + } |
| 114130 | 114475 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 114131 | | - addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */ |
| 114132 | | - VdbeCoverage(v); |
| 114133 | | - sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 114134 | | - sqlite3VdbeJumpHere(v, addr); |
| 114135 | 114476 | sqlite3ExprCacheClear(pParse); |
| 114136 | 114477 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0, |
| 114137 | 114478 | 1, 0, &iDataCur, &iIdxCur); |
| 114138 | 114479 | sqlite3VdbeAddOp2(v, OP_Integer, 0, 7); |
| 114139 | 114480 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| | @@ -114144,28 +114485,46 @@ |
| 114144 | 114485 | sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v); |
| 114145 | 114486 | loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1); |
| 114146 | 114487 | /* Verify that all NOT NULL columns really are NOT NULL */ |
| 114147 | 114488 | for(j=0; j<pTab->nCol; j++){ |
| 114148 | 114489 | char *zErr; |
| 114149 | | - int jmp2, jmp3; |
| 114490 | + int jmp2; |
| 114150 | 114491 | if( j==pTab->iPKey ) continue; |
| 114151 | 114492 | if( pTab->aCol[j].notNull==0 ) continue; |
| 114152 | 114493 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3); |
| 114153 | 114494 | sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG); |
| 114154 | 114495 | jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v); |
| 114155 | | - sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
| 114156 | 114496 | zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName, |
| 114157 | 114497 | pTab->aCol[j].zName); |
| 114158 | 114498 | sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 114159 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
| 114160 | | - jmp3 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v); |
| 114161 | | - sqlite3VdbeAddOp0(v, OP_Halt); |
| 114499 | + integrityCheckResultRow(v, 3); |
| 114162 | 114500 | sqlite3VdbeJumpHere(v, jmp2); |
| 114163 | | - sqlite3VdbeJumpHere(v, jmp3); |
| 114501 | + } |
| 114502 | + /* Verify CHECK constraints */ |
| 114503 | + if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ |
| 114504 | + int addrCkFault = sqlite3VdbeMakeLabel(v); |
| 114505 | + int addrCkOk = sqlite3VdbeMakeLabel(v); |
| 114506 | + ExprList *pCheck = pTab->pCheck; |
| 114507 | + char *zErr; |
| 114508 | + int k; |
| 114509 | + pParse->iSelfTab = iDataCur; |
| 114510 | + sqlite3ExprCachePush(pParse); |
| 114511 | + for(k=pCheck->nExpr-1; k>0; k--){ |
| 114512 | + sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0); |
| 114513 | + } |
| 114514 | + sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk, |
| 114515 | + SQLITE_JUMPIFNULL); |
| 114516 | + sqlite3VdbeResolveLabel(v, addrCkFault); |
| 114517 | + zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s", |
| 114518 | + pTab->zName); |
| 114519 | + sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC); |
| 114520 | + integrityCheckResultRow(v, 3); |
| 114521 | + sqlite3VdbeResolveLabel(v, addrCkOk); |
| 114522 | + sqlite3ExprCachePop(pParse); |
| 114164 | 114523 | } |
| 114165 | 114524 | /* Validate index entries for the current row */ |
| 114166 | | - for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 114525 | + for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){ |
| 114167 | 114526 | int jmp2, jmp3, jmp4, jmp5; |
| 114168 | 114527 | int ckUniq = sqlite3VdbeMakeLabel(v); |
| 114169 | 114528 | if( pPk==pIdx ) continue; |
| 114170 | 114529 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 114171 | 114530 | pPrior, r1); |
| | @@ -114172,20 +114531,17 @@ |
| 114172 | 114531 | pPrior = pIdx; |
| 114173 | 114532 | sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */ |
| 114174 | 114533 | /* Verify that an index entry exists for the current table row */ |
| 114175 | 114534 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1, |
| 114176 | 114535 | pIdx->nColumn); VdbeCoverage(v); |
| 114177 | | - sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
| 114178 | 114536 | sqlite3VdbeLoadString(v, 3, "row "); |
| 114179 | 114537 | sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
| 114180 | 114538 | sqlite3VdbeLoadString(v, 4, " missing from index "); |
| 114181 | 114539 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 114182 | 114540 | jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName); |
| 114183 | 114541 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 114184 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1); |
| 114185 | | - jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v); |
| 114186 | | - sqlite3VdbeAddOp0(v, OP_Halt); |
| 114542 | + jmp4 = integrityCheckResultRow(v, 3); |
| 114187 | 114543 | sqlite3VdbeJumpHere(v, jmp2); |
| 114188 | 114544 | /* For UNIQUE indexes, verify that only one entry exists with the |
| 114189 | 114545 | ** current key. The entry is unique if (1) any column is NULL |
| 114190 | 114546 | ** or (2) the next entry has a different key */ |
| 114191 | 114547 | if( IsUniqueIndex(pIdx) ){ |
| | @@ -114202,11 +114558,10 @@ |
| 114202 | 114558 | jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v); |
| 114203 | 114559 | sqlite3VdbeGoto(v, uniqOk); |
| 114204 | 114560 | sqlite3VdbeJumpHere(v, jmp6); |
| 114205 | 114561 | sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1, |
| 114206 | 114562 | pIdx->nKeyCol); VdbeCoverage(v); |
| 114207 | | - sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */ |
| 114208 | 114563 | sqlite3VdbeLoadString(v, 3, "non-unique entry in index "); |
| 114209 | 114564 | sqlite3VdbeGoto(v, jmp5); |
| 114210 | 114565 | sqlite3VdbeResolveLabel(v, uniqOk); |
| 114211 | 114566 | } |
| 114212 | 114567 | sqlite3VdbeJumpHere(v, jmp4); |
| | @@ -114213,40 +114568,39 @@ |
| 114213 | 114568 | sqlite3ResolvePartIdxLabel(pParse, jmp3); |
| 114214 | 114569 | } |
| 114215 | 114570 | sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); |
| 114216 | 114571 | sqlite3VdbeJumpHere(v, loopTop-1); |
| 114217 | 114572 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 114218 | | - sqlite3VdbeLoadString(v, 2, "wrong # of entries in index "); |
| 114219 | | - for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 114220 | | - if( pPk==pIdx ) continue; |
| 114221 | | - addr = sqlite3VdbeCurrentAddr(v); |
| 114222 | | - sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v); |
| 114223 | | - sqlite3VdbeAddOp2(v, OP_Halt, 0, 0); |
| 114224 | | - sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
| 114225 | | - sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v); |
| 114226 | | - sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 114227 | | - sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); |
| 114228 | | - sqlite3VdbeLoadString(v, 3, pIdx->zName); |
| 114229 | | - sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); |
| 114230 | | - sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1); |
| 114573 | + if( !isQuick ){ |
| 114574 | + sqlite3VdbeLoadString(v, 2, "wrong # of entries in index "); |
| 114575 | + for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 114576 | + if( pPk==pIdx ) continue; |
| 114577 | + sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
| 114578 | + addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v); |
| 114579 | + sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); |
| 114580 | + sqlite3VdbeLoadString(v, 3, pIdx->zName); |
| 114581 | + sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7); |
| 114582 | + integrityCheckResultRow(v, 7); |
| 114583 | + sqlite3VdbeJumpHere(v, addr); |
| 114584 | + } |
| 114231 | 114585 | } |
| 114232 | 114586 | #endif /* SQLITE_OMIT_BTREECOUNT */ |
| 114233 | 114587 | } |
| 114234 | 114588 | } |
| 114235 | 114589 | { |
| 114236 | 114590 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 114237 | 114591 | static const VdbeOpList endCode[] = { |
| 114238 | 114592 | { OP_AddImm, 1, 0, 0}, /* 0 */ |
| 114239 | | - { OP_If, 1, 4, 0}, /* 1 */ |
| 114593 | + { OP_IfNotZero, 1, 4, 0}, /* 1 */ |
| 114240 | 114594 | { OP_String8, 0, 3, 0}, /* 2 */ |
| 114241 | 114595 | { OP_ResultRow, 3, 1, 0}, /* 3 */ |
| 114242 | 114596 | }; |
| 114243 | 114597 | VdbeOp *aOp; |
| 114244 | 114598 | |
| 114245 | 114599 | aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn); |
| 114246 | 114600 | if( aOp ){ |
| 114247 | | - aOp[0].p2 = -mxErr; |
| 114601 | + aOp[0].p2 = 1-mxErr; |
| 114248 | 114602 | aOp[2].p4type = P4_STATIC; |
| 114249 | 114603 | aOp[2].p4.z = "ok"; |
| 114250 | 114604 | } |
| 114251 | 114605 | } |
| 114252 | 114606 | } |
| | @@ -114466,10 +114820,122 @@ |
| 114466 | 114820 | */ |
| 114467 | 114821 | case PragTyp_SHRINK_MEMORY: { |
| 114468 | 114822 | sqlite3_db_release_memory(db); |
| 114469 | 114823 | break; |
| 114470 | 114824 | } |
| 114825 | + |
| 114826 | + /* |
| 114827 | + ** PRAGMA optimize |
| 114828 | + ** PRAGMA optimize(MASK) |
| 114829 | + ** PRAGMA schema.optimize |
| 114830 | + ** PRAGMA schema.optimize(MASK) |
| 114831 | + ** |
| 114832 | + ** Attempt to optimize the database. All schemas are optimized in the first |
| 114833 | + ** two forms, and only the specified schema is optimized in the latter two. |
| 114834 | + ** |
| 114835 | + ** The details of optimizations performed by this pragma are expected |
| 114836 | + ** to change and improve over time. Applications should anticipate that |
| 114837 | + ** this pragma will perform new optimizations in future releases. |
| 114838 | + ** |
| 114839 | + ** The optional argument is a bitmask of optimizations to perform: |
| 114840 | + ** |
| 114841 | + ** 0x0001 Debugging mode. Do not actually perform any optimizations |
| 114842 | + ** but instead return one line of text for each optimization |
| 114843 | + ** that would have been done. Off by default. |
| 114844 | + ** |
| 114845 | + ** 0x0002 Run ANALYZE on tables that might benefit. On by default. |
| 114846 | + ** See below for additional information. |
| 114847 | + ** |
| 114848 | + ** 0x0004 (Not yet implemented) Record usage and performance |
| 114849 | + ** information from the current session in the |
| 114850 | + ** database file so that it will be available to "optimize" |
| 114851 | + ** pragmas run by future database connections. |
| 114852 | + ** |
| 114853 | + ** 0x0008 (Not yet implemented) Create indexes that might have |
| 114854 | + ** been helpful to recent queries |
| 114855 | + ** |
| 114856 | + ** The default MASK is and always shall be 0xfffe. 0xfffe means perform all ** of the optimizations listed above except Debug Mode, including new |
| 114857 | + ** optimizations that have not yet been invented. If new optimizations are |
| 114858 | + ** ever added that should be off by default, those off-by-default |
| 114859 | + ** optimizations will have bitmasks of 0x10000 or larger. |
| 114860 | + ** |
| 114861 | + ** DETERMINATION OF WHEN TO RUN ANALYZE |
| 114862 | + ** |
| 114863 | + ** In the current implementation, a table is analyzed if only if all of |
| 114864 | + ** the following are true: |
| 114865 | + ** |
| 114866 | + ** (1) MASK bit 0x02 is set. |
| 114867 | + ** |
| 114868 | + ** (2) The query planner used sqlite_stat1-style statistics for one or |
| 114869 | + ** more indexes of the table at some point during the lifetime of |
| 114870 | + ** the current connection. |
| 114871 | + ** |
| 114872 | + ** (3) One or more indexes of the table are currently unanalyzed OR |
| 114873 | + ** the number of rows in the table has increased by 25 times or more |
| 114874 | + ** since the last time ANALYZE was run. |
| 114875 | + ** |
| 114876 | + ** The rules for when tables are analyzed are likely to change in |
| 114877 | + ** future releases. |
| 114878 | + */ |
| 114879 | + case PragTyp_OPTIMIZE: { |
| 114880 | + int iDbLast; /* Loop termination point for the schema loop */ |
| 114881 | + int iTabCur; /* Cursor for a table whose size needs checking */ |
| 114882 | + HashElem *k; /* Loop over tables of a schema */ |
| 114883 | + Schema *pSchema; /* The current schema */ |
| 114884 | + Table *pTab; /* A table in the schema */ |
| 114885 | + Index *pIdx; /* An index of the table */ |
| 114886 | + LogEst szThreshold; /* Size threshold above which reanalysis is needd */ |
| 114887 | + char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ |
| 114888 | + u32 opMask; /* Mask of operations to perform */ |
| 114889 | + |
| 114890 | + if( zRight ){ |
| 114891 | + opMask = (u32)sqlite3Atoi(zRight); |
| 114892 | + if( (opMask & 0x02)==0 ) break; |
| 114893 | + }else{ |
| 114894 | + opMask = 0xfffe; |
| 114895 | + } |
| 114896 | + iTabCur = pParse->nTab++; |
| 114897 | + for(iDbLast = zDb?iDb:db->nDb-1; iDb<=iDbLast; iDb++){ |
| 114898 | + if( iDb==1 ) continue; |
| 114899 | + sqlite3CodeVerifySchema(pParse, iDb); |
| 114900 | + pSchema = db->aDb[iDb].pSchema; |
| 114901 | + for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 114902 | + pTab = (Table*)sqliteHashData(k); |
| 114903 | + |
| 114904 | + /* If table pTab has not been used in a way that would benefit from |
| 114905 | + ** having analysis statistics during the current session, then skip it. |
| 114906 | + ** This also has the effect of skipping virtual tables and views */ |
| 114907 | + if( (pTab->tabFlags & TF_StatsUsed)==0 ) continue; |
| 114908 | + |
| 114909 | + /* Reanalyze if the table is 25 times larger than the last analysis */ |
| 114910 | + szThreshold = pTab->nRowLogEst + 46; assert( sqlite3LogEst(25)==46 ); |
| 114911 | + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 114912 | + if( !pIdx->hasStat1 ){ |
| 114913 | + szThreshold = 0; /* Always analyze if any index lacks statistics */ |
| 114914 | + break; |
| 114915 | + } |
| 114916 | + } |
| 114917 | + if( szThreshold ){ |
| 114918 | + sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead); |
| 114919 | + sqlite3VdbeAddOp3(v, OP_IfSmaller, iTabCur, |
| 114920 | + sqlite3VdbeCurrentAddr(v)+2+(opMask&1), szThreshold); |
| 114921 | + VdbeCoverage(v); |
| 114922 | + } |
| 114923 | + zSubSql = sqlite3MPrintf(db, "ANALYZE \"%w\".\"%w\"", |
| 114924 | + db->aDb[iDb].zDbSName, pTab->zName); |
| 114925 | + if( opMask & 0x01 ){ |
| 114926 | + int r1 = sqlite3GetTempReg(pParse); |
| 114927 | + sqlite3VdbeAddOp4(v, OP_String8, 0, r1, 0, zSubSql, P4_DYNAMIC); |
| 114928 | + sqlite3VdbeAddOp2(v, OP_ResultRow, r1, 1); |
| 114929 | + }else{ |
| 114930 | + sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0, zSubSql, P4_DYNAMIC); |
| 114931 | + } |
| 114932 | + } |
| 114933 | + } |
| 114934 | + sqlite3VdbeAddOp0(v, OP_Expire); |
| 114935 | + break; |
| 114936 | + } |
| 114471 | 114937 | |
| 114472 | 114938 | /* |
| 114473 | 114939 | ** PRAGMA busy_timeout |
| 114474 | 114940 | ** PRAGMA busy_timeout = N |
| 114475 | 114941 | ** |
| | @@ -119528,11 +119994,13 @@ |
| 119528 | 119994 | assert( pParent->pGroupBy==0 ); |
| 119529 | 119995 | pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0); |
| 119530 | 119996 | }else{ |
| 119531 | 119997 | pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere); |
| 119532 | 119998 | } |
| 119533 | | - substSelect(pParse, pParent, iParent, pSub->pEList, 0); |
| 119999 | + if( db->mallocFailed==0 ){ |
| 120000 | + substSelect(pParse, pParent, iParent, pSub->pEList, 0); |
| 120001 | + } |
| 119534 | 120002 | |
| 119535 | 120003 | /* The flattened query is distinct if either the inner or the |
| 119536 | 120004 | ** outer query is distinct. |
| 119537 | 120005 | */ |
| 119538 | 120006 | pParent->selFlags |= pSub->selFlags & SF_Distinct; |
| | @@ -123782,12 +124250,29 @@ |
| 123782 | 124250 | ** transient would cause the database file to appear to be deleted |
| 123783 | 124251 | ** following reboot. |
| 123784 | 124252 | */ |
| 123785 | 124253 | SQLITE_PRIVATE void sqlite3Vacuum(Parse *pParse, Token *pNm){ |
| 123786 | 124254 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 123787 | | - int iDb = pNm ? sqlite3TwoPartName(pParse, pNm, pNm, &pNm) : 0; |
| 123788 | | - if( v && (iDb>=2 || iDb==0) ){ |
| 124255 | + int iDb = 0; |
| 124256 | + if( v==0 ) return; |
| 124257 | + if( pNm ){ |
| 124258 | +#ifndef SQLITE_BUG_COMPATIBLE_20160819 |
| 124259 | + /* Default behavior: Report an error if the argument to VACUUM is |
| 124260 | + ** not recognized */ |
| 124261 | + iDb = sqlite3TwoPartName(pParse, pNm, pNm, &pNm); |
| 124262 | + if( iDb<0 ) return; |
| 124263 | +#else |
| 124264 | + /* When SQLITE_BUG_COMPATIBLE_20160819 is defined, unrecognized arguments |
| 124265 | + ** to VACUUM are silently ignored. This is a back-out of a bug fix that |
| 124266 | + ** occurred on 2016-08-19 (https://www.sqlite.org/src/info/083f9e6270). |
| 124267 | + ** The buggy behavior is required for binary compatibility with some |
| 124268 | + ** legacy applications. */ |
| 124269 | + iDb = sqlite3FindDb(pParse->db, pNm); |
| 124270 | + if( iDb<0 ) iDb = 0; |
| 124271 | +#endif |
| 124272 | + } |
| 124273 | + if( iDb!=1 ){ |
| 123789 | 124274 | sqlite3VdbeAddOp1(v, OP_Vacuum, iDb); |
| 123790 | 124275 | sqlite3VdbeUsesBtree(v, iDb); |
| 123791 | 124276 | } |
| 123792 | 124277 | return; |
| 123793 | 124278 | } |
| | @@ -124377,12 +124862,11 @@ |
| 124377 | 124862 | |
| 124378 | 124863 | db = pParse->db; |
| 124379 | 124864 | iDb = sqlite3SchemaToIndex(db, pTable->pSchema); |
| 124380 | 124865 | assert( iDb>=0 ); |
| 124381 | 124866 | |
| 124382 | | - pTable->tabFlags |= TF_Virtual; |
| 124383 | | - pTable->nModuleArg = 0; |
| 124867 | + assert( pTable->nModuleArg==0 ); |
| 124384 | 124868 | addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); |
| 124385 | 124869 | addModuleArgument(db, pTable, 0); |
| 124386 | 124870 | addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); |
| 124387 | 124871 | assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0) |
| 124388 | 124872 | || (pParse->sNameToken.z==pName1->z && pName2->z==0) |
| | @@ -124666,11 +125150,11 @@ |
| 124666 | 125150 | const char *zMod; |
| 124667 | 125151 | Module *pMod; |
| 124668 | 125152 | int rc; |
| 124669 | 125153 | |
| 124670 | 125154 | assert( pTab ); |
| 124671 | | - if( (pTab->tabFlags & TF_Virtual)==0 || sqlite3GetVTable(db, pTab) ){ |
| 125155 | + if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){ |
| 124672 | 125156 | return SQLITE_OK; |
| 124673 | 125157 | } |
| 124674 | 125158 | |
| 124675 | 125159 | /* Locate the required virtual table module */ |
| 124676 | 125160 | zMod = pTab->azModuleArg[0]; |
| | @@ -124736,11 +125220,11 @@ |
| 124736 | 125220 | Table *pTab; |
| 124737 | 125221 | Module *pMod; |
| 124738 | 125222 | const char *zMod; |
| 124739 | 125223 | |
| 124740 | 125224 | pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zDbSName); |
| 124741 | | - assert( pTab && (pTab->tabFlags & TF_Virtual)!=0 && !pTab->pVTable ); |
| 125225 | + assert( pTab && IsVirtual(pTab) && !pTab->pVTable ); |
| 124742 | 125226 | |
| 124743 | 125227 | /* Locate the required virtual table module */ |
| 124744 | 125228 | zMod = pTab->azModuleArg[0]; |
| 124745 | 125229 | pMod = (Module*)sqlite3HashFind(&db->aModule, zMod); |
| 124746 | 125230 | |
| | @@ -124790,11 +125274,11 @@ |
| 124790 | 125274 | sqlite3Error(db, SQLITE_MISUSE); |
| 124791 | 125275 | sqlite3_mutex_leave(db->mutex); |
| 124792 | 125276 | return SQLITE_MISUSE_BKPT; |
| 124793 | 125277 | } |
| 124794 | 125278 | pTab = pCtx->pTab; |
| 124795 | | - assert( (pTab->tabFlags & TF_Virtual)!=0 ); |
| 125279 | + assert( IsVirtual(pTab) ); |
| 124796 | 125280 | |
| 124797 | 125281 | pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); |
| 124798 | 125282 | if( pParse==0 ){ |
| 124799 | 125283 | rc = SQLITE_NOMEM_BKPT; |
| 124800 | 125284 | }else{ |
| | @@ -124804,11 +125288,11 @@ |
| 124804 | 125288 | |
| 124805 | 125289 | if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr) |
| 124806 | 125290 | && pParse->pNewTable |
| 124807 | 125291 | && !db->mallocFailed |
| 124808 | 125292 | && !pParse->pNewTable->pSelect |
| 124809 | | - && (pParse->pNewTable->tabFlags & TF_Virtual)==0 |
| 125293 | + && !IsVirtual(pParse->pNewTable) |
| 124810 | 125294 | ){ |
| 124811 | 125295 | if( !pTab->aCol ){ |
| 124812 | 125296 | Table *pNew = pParse->pNewTable; |
| 124813 | 125297 | Index *pIdx; |
| 124814 | 125298 | pTab->aCol = pNew->aCol; |
| | @@ -125093,11 +125577,11 @@ |
| 125093 | 125577 | /* Check to see the left operand is a column in a virtual table */ |
| 125094 | 125578 | if( NEVER(pExpr==0) ) return pDef; |
| 125095 | 125579 | if( pExpr->op!=TK_COLUMN ) return pDef; |
| 125096 | 125580 | pTab = pExpr->pTab; |
| 125097 | 125581 | if( NEVER(pTab==0) ) return pDef; |
| 125098 | | - if( (pTab->tabFlags & TF_Virtual)==0 ) return pDef; |
| 125582 | + if( !IsVirtual(pTab) ) return pDef; |
| 125099 | 125583 | pVtab = sqlite3GetVTable(db, pTab)->pVtab; |
| 125100 | 125584 | assert( pVtab!=0 ); |
| 125101 | 125585 | assert( pVtab->pModule!=0 ); |
| 125102 | 125586 | pMod = (sqlite3_module *)pVtab->pModule; |
| 125103 | 125587 | if( pMod->xFindFunction==0 ) return pDef; |
| | @@ -125188,12 +125672,11 @@ |
| 125188 | 125672 | return 0; |
| 125189 | 125673 | } |
| 125190 | 125674 | pMod->pEpoTab = pTab; |
| 125191 | 125675 | pTab->nTabRef = 1; |
| 125192 | 125676 | pTab->pSchema = db->aDb[0].pSchema; |
| 125193 | | - pTab->tabFlags |= TF_Virtual; |
| 125194 | | - pTab->nModuleArg = 0; |
| 125677 | + assert( pTab->nModuleArg==0 ); |
| 125195 | 125678 | pTab->iPKey = -1; |
| 125196 | 125679 | addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 125197 | 125680 | addModuleArgument(db, pTab, 0); |
| 125198 | 125681 | addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName)); |
| 125199 | 125682 | rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr); |
| | @@ -125260,11 +125743,11 @@ |
| 125260 | 125743 | case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 125261 | 125744 | VtabCtx *p = db->pVtabCtx; |
| 125262 | 125745 | if( !p ){ |
| 125263 | 125746 | rc = SQLITE_MISUSE_BKPT; |
| 125264 | 125747 | }else{ |
| 125265 | | - assert( p->pTab==0 || (p->pTab->tabFlags & TF_Virtual)!=0 ); |
| 125748 | + assert( p->pTab==0 || IsVirtual(p->pTab) ); |
| 125266 | 125749 | p->pVTable->bConstraint = (u8)va_arg(ap, int); |
| 125267 | 125750 | } |
| 125268 | 125751 | break; |
| 125269 | 125752 | } |
| 125270 | 125753 | default: |
| | @@ -125699,12 +126182,17 @@ |
| 125699 | 126182 | WhereOrSet *pOrSet; /* Record best loops here, if not NULL */ |
| 125700 | 126183 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 125701 | 126184 | UnpackedRecord *pRec; /* Probe for stat4 (if required) */ |
| 125702 | 126185 | int nRecValid; /* Number of valid fields currently in pRec */ |
| 125703 | 126186 | #endif |
| 126187 | + unsigned int bldFlags; /* SQLITE_BLDF_* flags */ |
| 125704 | 126188 | }; |
| 125705 | 126189 | |
| 126190 | +/* Allowed values for WhereLoopBuider.bldFlags */ |
| 126191 | +#define SQLITE_BLDF_INDEXED 0x0001 /* An index is used */ |
| 126192 | +#define SQLITE_BLDF_UNIQUE 0x0002 /* All keys of a UNIQUE index used */ |
| 126193 | + |
| 125706 | 126194 | /* |
| 125707 | 126195 | ** The WHERE clause processing routine has two halves. The |
| 125708 | 126196 | ** first part does the start of the WHERE loop and the second |
| 125709 | 126197 | ** half does the tail of the WHERE loop. An instance of |
| 125710 | 126198 | ** this structure is returned by the first half and passed |
| | @@ -125715,11 +126203,11 @@ |
| 125715 | 126203 | */ |
| 125716 | 126204 | struct WhereInfo { |
| 125717 | 126205 | Parse *pParse; /* Parsing and code generating context */ |
| 125718 | 126206 | SrcList *pTabList; /* List of tables in the join */ |
| 125719 | 126207 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 125720 | | - ExprList *pDistinctSet; /* DISTINCT over all these values */ |
| 126208 | + ExprList *pResultSet; /* Result set of the query */ |
| 125721 | 126209 | LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */ |
| 125722 | 126210 | int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ |
| 125723 | 126211 | int iContinue; /* Jump here to continue with next record */ |
| 125724 | 126212 | int iBreak; /* Jump here to break out of the loop */ |
| 125725 | 126213 | int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ |
| | @@ -126899,10 +127387,11 @@ |
| 126899 | 127387 | Parse *pParse; /* Parsing context */ |
| 126900 | 127388 | sqlite3 *db; /* Database connection */ |
| 126901 | 127389 | Vdbe *v; /* The prepared stmt under constructions */ |
| 126902 | 127390 | struct SrcList_item *pTabItem; /* FROM clause term being coded */ |
| 126903 | 127391 | int addrBrk; /* Jump here to break out of the loop */ |
| 127392 | + int addrHalt; /* addrBrk for the outermost loop */ |
| 126904 | 127393 | int addrCont; /* Jump here to continue with next cycle */ |
| 126905 | 127394 | int iRowidReg = 0; /* Rowid is stored in this register, if not zero */ |
| 126906 | 127395 | int iReleaseReg = 0; /* Temp register to free before returning */ |
| 126907 | 127396 | |
| 126908 | 127397 | pParse = pWInfo->pParse; |
| | @@ -126939,10 +127428,15 @@ |
| 126939 | 127428 | if( pLevel->iFrom>0 && (pTabItem[0].fg.jointype & JT_LEFT)!=0 ){ |
| 126940 | 127429 | pLevel->iLeftJoin = ++pParse->nMem; |
| 126941 | 127430 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin); |
| 126942 | 127431 | VdbeComment((v, "init LEFT JOIN no-match flag")); |
| 126943 | 127432 | } |
| 127433 | + |
| 127434 | + /* Compute a safe address to jump to if we discover that the table for |
| 127435 | + ** this loop is empty and can never contribute content. */ |
| 127436 | + for(j=iLevel; j>0 && pWInfo->a[j].iLeftJoin==0; j--){} |
| 127437 | + addrHalt = pWInfo->a[j].addrBrk; |
| 126944 | 127438 | |
| 126945 | 127439 | /* Special case of a FROM clause subquery implemented as a co-routine */ |
| 126946 | 127440 | if( pTabItem->fg.viaCoroutine ){ |
| 126947 | 127441 | int regYield = pTabItem->regReturn; |
| 126948 | 127442 | sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub); |
| | @@ -127124,11 +127618,11 @@ |
| 127124 | 127618 | VdbeCoverageIf(v, pX->op==TK_LT); |
| 127125 | 127619 | VdbeCoverageIf(v, pX->op==TK_GE); |
| 127126 | 127620 | sqlite3ExprCacheAffinityChange(pParse, r1, 1); |
| 127127 | 127621 | sqlite3ReleaseTempReg(pParse, rTemp); |
| 127128 | 127622 | }else{ |
| 127129 | | - sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk); |
| 127623 | + sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrHalt); |
| 127130 | 127624 | VdbeCoverageIf(v, bRev==0); |
| 127131 | 127625 | VdbeCoverageIf(v, bRev!=0); |
| 127132 | 127626 | } |
| 127133 | 127627 | if( pEnd ){ |
| 127134 | 127628 | Expr *pX; |
| | @@ -127770,11 +128264,11 @@ |
| 127770 | 128264 | pLevel->op = OP_Noop; |
| 127771 | 128265 | }else{ |
| 127772 | 128266 | codeCursorHint(pTabItem, pWInfo, pLevel, 0); |
| 127773 | 128267 | pLevel->op = aStep[bRev]; |
| 127774 | 128268 | pLevel->p1 = iCur; |
| 127775 | | - pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk); |
| 128269 | + pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrHalt); |
| 127776 | 128270 | VdbeCoverageIf(v, bRev==0); |
| 127777 | 128271 | VdbeCoverageIf(v, bRev!=0); |
| 127778 | 128272 | pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 127779 | 128273 | } |
| 127780 | 128274 | } |
| | @@ -128095,19 +128589,10 @@ |
| 128095 | 128589 | #ifdef SQLITE_EBCDIC |
| 128096 | 128590 | if( *pnoCase ) return 0; |
| 128097 | 128591 | #endif |
| 128098 | 128592 | pList = pExpr->x.pList; |
| 128099 | 128593 | pLeft = pList->a[1].pExpr; |
| 128100 | | - if( pLeft->op!=TK_COLUMN |
| 128101 | | - || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 128102 | | - || IsVirtual(pLeft->pTab) /* Value might be numeric */ |
| 128103 | | - ){ |
| 128104 | | - /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must |
| 128105 | | - ** be the name of an indexed column with TEXT affinity. */ |
| 128106 | | - return 0; |
| 128107 | | - } |
| 128108 | | - assert( pLeft->iColumn!=(-1) ); /* Because IPK never has AFF_TEXT */ |
| 128109 | 128594 | |
| 128110 | 128595 | pRight = sqlite3ExprSkipCollate(pList->a[0].pExpr); |
| 128111 | 128596 | op = pRight->op; |
| 128112 | 128597 | if( op==TK_VARIABLE ){ |
| 128113 | 128598 | Vdbe *pReprepare = pParse->pReprepare; |
| | @@ -128120,10 +128605,27 @@ |
| 128120 | 128605 | assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER ); |
| 128121 | 128606 | }else if( op==TK_STRING ){ |
| 128122 | 128607 | z = pRight->u.zToken; |
| 128123 | 128608 | } |
| 128124 | 128609 | if( z ){ |
| 128610 | + |
| 128611 | + /* If the RHS begins with a digit or a minus sign, then the LHS must |
| 128612 | + ** be an ordinary column (not a virtual table column) with TEXT affinity. |
| 128613 | + ** Otherwise the LHS might be numeric and "lhs >= rhs" would be false |
| 128614 | + ** even though "lhs LIKE rhs" is true. But if the RHS does not start |
| 128615 | + ** with a digit or '-', then "lhs LIKE rhs" will always be false if |
| 128616 | + ** the LHS is numeric and so the optimization still works. |
| 128617 | + */ |
| 128618 | + if( sqlite3Isdigit(z[0]) || z[0]=='-' ){ |
| 128619 | + if( pLeft->op!=TK_COLUMN |
| 128620 | + || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 128621 | + || IsVirtual(pLeft->pTab) /* Value might be numeric */ |
| 128622 | + ){ |
| 128623 | + sqlite3ValueFree(pVal); |
| 128624 | + return 0; |
| 128625 | + } |
| 128626 | + } |
| 128125 | 128627 | cnt = 0; |
| 128126 | 128628 | while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){ |
| 128127 | 128629 | cnt++; |
| 128128 | 128630 | } |
| 128129 | 128631 | if( cnt!=0 && 255!=(u8)z[cnt-1] ){ |
| | @@ -128748,11 +129250,11 @@ |
| 128748 | 129250 | iCur = pFrom->a[i].iCursor; |
| 128749 | 129251 | for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 128750 | 129252 | if( pIdx->aColExpr==0 ) continue; |
| 128751 | 129253 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 128752 | 129254 | if( pIdx->aiColumn[i]!=XN_EXPR ) continue; |
| 128753 | | - if( sqlite3ExprCompare(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){ |
| 129255 | + if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){ |
| 128754 | 129256 | *piCur = iCur; |
| 128755 | 129257 | *piColumn = XN_EXPR; |
| 128756 | 129258 | return 1; |
| 128757 | 129259 | } |
| 128758 | 129260 | } |
| | @@ -129539,11 +130041,12 @@ |
| 129539 | 130041 | do{ |
| 129540 | 130042 | for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){ |
| 129541 | 130043 | if( pTerm->leftCursor==iCur |
| 129542 | 130044 | && pTerm->u.leftColumn==iColumn |
| 129543 | 130045 | && (iColumn!=XN_EXPR |
| 129544 | | - || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0) |
| 130046 | + || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft, |
| 130047 | + pScan->pIdxExpr,iCur)==0) |
| 129545 | 130048 | && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin)) |
| 129546 | 130049 | ){ |
| 129547 | 130050 | if( (pTerm->eOperator & WO_EQUIV)!=0 |
| 129548 | 130051 | && pScan->nEquiv<ArraySize(pScan->aiCur) |
| 129549 | 130052 | && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN |
| | @@ -129846,18 +130349,20 @@ |
| 129846 | 130349 | ** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero, |
| 129847 | 130350 | ** then each OP_Rowid is transformed into an instruction to increment the |
| 129848 | 130351 | ** value stored in its output register. |
| 129849 | 130352 | */ |
| 129850 | 130353 | static void translateColumnToCopy( |
| 129851 | | - Vdbe *v, /* The VDBE containing code to translate */ |
| 130354 | + Parse *pParse, /* Parsing context */ |
| 129852 | 130355 | int iStart, /* Translate from this opcode to the end */ |
| 129853 | 130356 | int iTabCur, /* OP_Column/OP_Rowid references to this table */ |
| 129854 | 130357 | int iRegister, /* The first column is in this register */ |
| 129855 | 130358 | int bIncrRowid /* If non-zero, transform OP_rowid to OP_AddImm(1) */ |
| 129856 | 130359 | ){ |
| 130360 | + Vdbe *v = pParse->pVdbe; |
| 129857 | 130361 | VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart); |
| 129858 | 130362 | int iEnd = sqlite3VdbeCurrentAddr(v); |
| 130363 | + if( pParse->db->mallocFailed ) return; |
| 129859 | 130364 | for(; iStart<iEnd; iStart++, pOp++){ |
| 129860 | 130365 | if( pOp->p1!=iTabCur ) continue; |
| 129861 | 130366 | if( pOp->opcode==OP_Column ){ |
| 129862 | 130367 | pOp->opcode = OP_Copy; |
| 129863 | 130368 | pOp->p1 = pOp->p2 + iRegister; |
| | @@ -130131,11 +130636,13 @@ |
| 130131 | 130636 | sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); |
| 130132 | 130637 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 130133 | 130638 | if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue); |
| 130134 | 130639 | if( pTabItem->fg.viaCoroutine ){ |
| 130135 | 130640 | sqlite3VdbeChangeP2(v, addrCounter, regBase+n); |
| 130136 | | - translateColumnToCopy(v, addrTop, pLevel->iTabCur, pTabItem->regResult, 1); |
| 130641 | + testcase( pParse->db->mallocFailed ); |
| 130642 | + translateColumnToCopy(pParse, addrTop, pLevel->iTabCur, |
| 130643 | + pTabItem->regResult, 1); |
| 130137 | 130644 | sqlite3VdbeGoto(v, addrTop); |
| 130138 | 130645 | pTabItem->fg.viaCoroutine = 0; |
| 130139 | 130646 | }else{ |
| 130140 | 130647 | sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 130141 | 130648 | } |
| | @@ -131716,10 +132223,15 @@ |
| 131716 | 132223 | testcase( eOp & WO_IS ); |
| 131717 | 132224 | testcase( eOp & WO_ISNULL ); |
| 131718 | 132225 | continue; |
| 131719 | 132226 | } |
| 131720 | 132227 | |
| 132228 | + if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){ |
| 132229 | + pBuilder->bldFlags |= SQLITE_BLDF_UNIQUE; |
| 132230 | + }else{ |
| 132231 | + pBuilder->bldFlags |= SQLITE_BLDF_INDEXED; |
| 132232 | + } |
| 131721 | 132233 | pNew->wsFlags = saved_wsFlags; |
| 131722 | 132234 | pNew->u.btree.nEq = saved_nEq; |
| 131723 | 132235 | pNew->u.btree.nBtm = saved_nBtm; |
| 131724 | 132236 | pNew->u.btree.nTop = saved_nTop; |
| 131725 | 132237 | pNew->nLTerm = saved_nLTerm; |
| | @@ -132263,11 +132775,19 @@ |
| 132263 | 132775 | pNew->nOut = rSize; |
| 132264 | 132776 | if( rc ) break; |
| 132265 | 132777 | } |
| 132266 | 132778 | } |
| 132267 | 132779 | |
| 132780 | + pBuilder->bldFlags = 0; |
| 132268 | 132781 | rc = whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, 0); |
| 132782 | + if( pBuilder->bldFlags==SQLITE_BLDF_INDEXED ){ |
| 132783 | + /* If a non-unique index is used, or if a prefix of the key for |
| 132784 | + ** unique index is used (making the index functionally non-unique) |
| 132785 | + ** then the sqlite_stat1 data becomes important for scoring the |
| 132786 | + ** plan */ |
| 132787 | + pTab->tabFlags |= TF_StatsUsed; |
| 132788 | + } |
| 132269 | 132789 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 132270 | 132790 | sqlite3Stat4ProbeFree(pBuilder->pRec); |
| 132271 | 132791 | pBuilder->nRecValid = 0; |
| 132272 | 132792 | pBuilder->pRec = 0; |
| 132273 | 132793 | #endif |
| | @@ -133443,13 +133963,13 @@ |
| 133443 | 133963 | && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0 |
| 133444 | 133964 | && pWInfo->eDistinct==WHERE_DISTINCT_NOOP |
| 133445 | 133965 | && nRowEst |
| 133446 | 133966 | ){ |
| 133447 | 133967 | Bitmask notUsed; |
| 133448 | | - int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom, |
| 133968 | + int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom, |
| 133449 | 133969 | WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], ¬Used); |
| 133450 | | - if( rc==pWInfo->pDistinctSet->nExpr ){ |
| 133970 | + if( rc==pWInfo->pResultSet->nExpr ){ |
| 133451 | 133971 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| 133452 | 133972 | } |
| 133453 | 133973 | } |
| 133454 | 133974 | if( pWInfo->pOrderBy ){ |
| 133455 | 133975 | if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){ |
| | @@ -133682,11 +134202,11 @@ |
| 133682 | 134202 | SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( |
| 133683 | 134203 | Parse *pParse, /* The parser context */ |
| 133684 | 134204 | SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */ |
| 133685 | 134205 | Expr *pWhere, /* The WHERE clause */ |
| 133686 | 134206 | ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */ |
| 133687 | | - ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */ |
| 134207 | + ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */ |
| 133688 | 134208 | u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */ |
| 133689 | 134209 | int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number |
| 133690 | 134210 | ** If WHERE_USE_LIMIT, then the limit amount */ |
| 133691 | 134211 | ){ |
| 133692 | 134212 | int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */ |
| | @@ -133758,11 +134278,11 @@ |
| 133758 | 134278 | goto whereBeginError; |
| 133759 | 134279 | } |
| 133760 | 134280 | pWInfo->pParse = pParse; |
| 133761 | 134281 | pWInfo->pTabList = pTabList; |
| 133762 | 134282 | pWInfo->pOrderBy = pOrderBy; |
| 133763 | | - pWInfo->pDistinctSet = pDistinctSet; |
| 134283 | + pWInfo->pResultSet = pResultSet; |
| 133764 | 134284 | pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1; |
| 133765 | 134285 | pWInfo->nLevel = nTabList; |
| 133766 | 134286 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v); |
| 133767 | 134287 | pWInfo->wctrlFlags = wctrlFlags; |
| 133768 | 134288 | pWInfo->iLimit = iAuxArg; |
| | @@ -133836,17 +134356,17 @@ |
| 133836 | 134356 | /* Analyze all of the subexpressions. */ |
| 133837 | 134357 | sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC); |
| 133838 | 134358 | if( db->mallocFailed ) goto whereBeginError; |
| 133839 | 134359 | |
| 133840 | 134360 | if( wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 133841 | | - if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){ |
| 134361 | + if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ |
| 133842 | 134362 | /* The DISTINCT marking is pointless. Ignore it. */ |
| 133843 | 134363 | pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; |
| 133844 | 134364 | }else if( pOrderBy==0 ){ |
| 133845 | 134365 | /* Try to ORDER BY the result set to make distinct processing easier */ |
| 133846 | 134366 | pWInfo->wctrlFlags |= WHERE_DISTINCTBY; |
| 133847 | | - pWInfo->pOrderBy = pDistinctSet; |
| 134367 | + pWInfo->pOrderBy = pResultSet; |
| 133848 | 134368 | } |
| 133849 | 134369 | } |
| 133850 | 134370 | |
| 133851 | 134371 | /* Construct the WhereLoop objects */ |
| 133852 | 134372 | #if defined(WHERETRACE_ENABLED) |
| | @@ -133918,14 +134438,14 @@ |
| 133918 | 134438 | } |
| 133919 | 134439 | } |
| 133920 | 134440 | #endif |
| 133921 | 134441 | /* Attempt to omit tables from the join that do not effect the result */ |
| 133922 | 134442 | if( pWInfo->nLevel>=2 |
| 133923 | | - && pDistinctSet!=0 |
| 134443 | + && pResultSet!=0 |
| 133924 | 134444 | && OptimizationEnabled(db, SQLITE_OmitNoopJoin) |
| 133925 | 134445 | ){ |
| 133926 | | - Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet); |
| 134446 | + Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet); |
| 133927 | 134447 | if( sWLB.pOrderBy ){ |
| 133928 | 134448 | tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy); |
| 133929 | 134449 | } |
| 133930 | 134450 | while( pWInfo->nLevel>=2 ){ |
| 133931 | 134451 | WhereTerm *pTerm, *pEnd; |
| | @@ -134236,12 +134756,13 @@ |
| 134236 | 134756 | |
| 134237 | 134757 | /* For a co-routine, change all OP_Column references to the table of |
| 134238 | 134758 | ** the co-routine into OP_Copy of result contained in a register. |
| 134239 | 134759 | ** OP_Rowid becomes OP_Null. |
| 134240 | 134760 | */ |
| 134241 | | - if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){ |
| 134242 | | - translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur, |
| 134761 | + if( pTabItem->fg.viaCoroutine ){ |
| 134762 | + testcase( pParse->db->mallocFailed ); |
| 134763 | + translateColumnToCopy(pParse, pLevel->addrBody, pLevel->iTabCur, |
| 134243 | 134764 | pTabItem->regResult, 0); |
| 134244 | 134765 | continue; |
| 134245 | 134766 | } |
| 134246 | 134767 | |
| 134247 | 134768 | /* If this scan uses an index, make VDBE code substitutions to read data |
| | @@ -134704,166 +135225,166 @@ |
| 134704 | 135225 | ** |
| 134705 | 135226 | *********** Begin parsing tables **********************************************/ |
| 134706 | 135227 | #define YY_ACTTAB_COUNT (1567) |
| 134707 | 135228 | static const YYACTIONTYPE yy_action[] = { |
| 134708 | 135229 | /* 0 */ 325, 832, 351, 825, 5, 203, 203, 819, 99, 100, |
| 134709 | | - /* 10 */ 90, 842, 842, 854, 857, 846, 846, 97, 97, 98, |
| 135230 | + /* 10 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98, |
| 134710 | 135231 | /* 20 */ 98, 98, 98, 301, 96, 96, 96, 96, 95, 95, |
| 134711 | | - /* 30 */ 94, 94, 94, 93, 351, 325, 977, 977, 824, 824, |
| 134712 | | - /* 40 */ 826, 947, 354, 99, 100, 90, 842, 842, 854, 857, |
| 134713 | | - /* 50 */ 846, 846, 97, 97, 98, 98, 98, 98, 338, 96, |
| 135232 | + /* 30 */ 94, 94, 94, 93, 351, 325, 976, 976, 824, 824, |
| 135233 | + /* 40 */ 826, 946, 354, 99, 100, 90, 978, 978, 853, 856, |
| 135234 | + /* 50 */ 845, 845, 97, 97, 98, 98, 98, 98, 338, 96, |
| 134714 | 135235 | /* 60 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351, |
| 134715 | | - /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 977, 977, |
| 135236 | + /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 976, 976, |
| 134716 | 135237 | /* 80 */ 325, 94, 94, 94, 93, 351, 792, 75, 99, 100, |
| 134717 | | - /* 90 */ 90, 842, 842, 854, 857, 846, 846, 97, 97, 98, |
| 135238 | + /* 90 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98, |
| 134718 | 135239 | /* 100 */ 98, 98, 98, 450, 96, 96, 96, 96, 95, 95, |
| 134719 | 135240 | /* 110 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 325, |
| 134720 | 135241 | /* 120 */ 275, 146, 132, 52, 52, 93, 351, 99, 100, 90, |
| 134721 | | - /* 130 */ 842, 842, 854, 857, 846, 846, 97, 97, 98, 98, |
| 135242 | + /* 130 */ 978, 978, 853, 856, 845, 845, 97, 97, 98, 98, |
| 134722 | 135243 | /* 140 */ 98, 98, 101, 96, 96, 96, 96, 95, 95, 94, |
| 134723 | | - /* 150 */ 94, 94, 93, 351, 958, 958, 325, 268, 428, 413, |
| 134724 | | - /* 160 */ 411, 61, 752, 752, 99, 100, 90, 842, 842, 854, |
| 134725 | | - /* 170 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 60, |
| 135244 | + /* 150 */ 94, 94, 93, 351, 957, 957, 325, 268, 428, 413, |
| 135245 | + /* 160 */ 411, 61, 752, 752, 99, 100, 90, 978, 978, 853, |
| 135246 | + /* 170 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 60, |
| 134726 | 135247 | /* 180 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 134727 | | - /* 190 */ 351, 325, 270, 329, 273, 277, 959, 960, 250, 99, |
| 134728 | | - /* 200 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97, |
| 135248 | + /* 190 */ 351, 325, 270, 329, 273, 277, 958, 959, 250, 99, |
| 135249 | + /* 200 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97, |
| 134729 | 135250 | /* 210 */ 98, 98, 98, 98, 301, 96, 96, 96, 96, 95, |
| 134730 | | - /* 220 */ 95, 94, 94, 94, 93, 351, 325, 938, 1326, 698, |
| 134731 | | - /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 842, 842, 854, |
| 134732 | | - /* 240 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 347, |
| 135251 | + /* 220 */ 95, 94, 94, 94, 93, 351, 325, 937, 1326, 698, |
| 135252 | + /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 978, 978, 853, |
| 135253 | + /* 240 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 347, |
| 134733 | 135254 | /* 250 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 134734 | | - /* 260 */ 351, 325, 938, 1327, 384, 699, 1327, 381, 379, 99, |
| 134735 | | - /* 270 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97, |
| 135255 | + /* 260 */ 351, 325, 937, 1327, 384, 699, 1327, 381, 379, 99, |
| 135256 | + /* 270 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97, |
| 134736 | 135257 | /* 280 */ 98, 98, 98, 98, 701, 96, 96, 96, 96, 95, |
| 134737 | 135258 | /* 290 */ 95, 94, 94, 94, 93, 351, 325, 92, 89, 178, |
| 134738 | | - /* 300 */ 833, 936, 373, 700, 99, 100, 90, 842, 842, 854, |
| 134739 | | - /* 310 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 375, |
| 135259 | + /* 300 */ 833, 935, 373, 700, 99, 100, 90, 978, 978, 853, |
| 135260 | + /* 310 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 375, |
| 134740 | 135261 | /* 320 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 134741 | | - /* 330 */ 351, 325, 1276, 947, 354, 818, 936, 739, 739, 99, |
| 134742 | | - /* 340 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97, |
| 135262 | + /* 330 */ 351, 325, 1275, 946, 354, 818, 935, 739, 739, 99, |
| 135263 | + /* 340 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97, |
| 134743 | 135264 | /* 350 */ 98, 98, 98, 98, 230, 96, 96, 96, 96, 95, |
| 134744 | | - /* 360 */ 95, 94, 94, 94, 93, 351, 325, 969, 227, 92, |
| 134745 | | - /* 370 */ 89, 178, 373, 300, 99, 100, 90, 842, 842, 854, |
| 134746 | | - /* 380 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 921, |
| 135265 | + /* 360 */ 95, 94, 94, 94, 93, 351, 325, 968, 227, 92, |
| 135266 | + /* 370 */ 89, 178, 373, 300, 99, 100, 90, 978, 978, 853, |
| 135267 | + /* 380 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 920, |
| 134747 | 135268 | /* 390 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 134748 | 135269 | /* 400 */ 351, 325, 449, 447, 447, 447, 147, 737, 737, 99, |
| 134749 | | - /* 410 */ 100, 90, 842, 842, 854, 857, 846, 846, 97, 97, |
| 135270 | + /* 410 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97, |
| 134750 | 135271 | /* 420 */ 98, 98, 98, 98, 296, 96, 96, 96, 96, 95, |
| 134751 | | - /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 958, |
| 134752 | | - /* 440 */ 958, 158, 25, 422, 99, 100, 90, 842, 842, 854, |
| 134753 | | - /* 450 */ 857, 846, 846, 97, 97, 98, 98, 98, 98, 450, |
| 135272 | + /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 957, |
| 135273 | + /* 440 */ 957, 158, 25, 422, 99, 100, 90, 978, 978, 853, |
| 135274 | + /* 450 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 450, |
| 134754 | 135275 | /* 460 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 134755 | | - /* 470 */ 351, 443, 224, 224, 420, 958, 958, 962, 325, 52, |
| 134756 | | - /* 480 */ 52, 959, 960, 176, 415, 78, 99, 100, 90, 842, |
| 134757 | | - /* 490 */ 842, 854, 857, 846, 846, 97, 97, 98, 98, 98, |
| 135276 | + /* 470 */ 351, 443, 224, 224, 420, 957, 957, 961, 325, 52, |
| 135277 | + /* 480 */ 52, 958, 959, 176, 415, 78, 99, 100, 90, 978, |
| 135278 | + /* 490 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98, |
| 134758 | 135279 | /* 500 */ 98, 379, 96, 96, 96, 96, 95, 95, 94, 94, |
| 134759 | | - /* 510 */ 94, 93, 351, 325, 428, 418, 298, 959, 960, 962, |
| 134760 | | - /* 520 */ 81, 99, 88, 90, 842, 842, 854, 857, 846, 846, |
| 135280 | + /* 510 */ 94, 93, 351, 325, 428, 418, 298, 958, 959, 961, |
| 135281 | + /* 520 */ 81, 99, 88, 90, 978, 978, 853, 856, 845, 845, |
| 134761 | 135282 | /* 530 */ 97, 97, 98, 98, 98, 98, 717, 96, 96, 96, |
| 134762 | | - /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 843, |
| 134763 | | - /* 550 */ 843, 855, 858, 996, 318, 343, 379, 100, 90, 842, |
| 134764 | | - /* 560 */ 842, 854, 857, 846, 846, 97, 97, 98, 98, 98, |
| 135283 | + /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 842, |
| 135284 | + /* 550 */ 842, 854, 857, 996, 318, 343, 379, 100, 90, 978, |
| 135285 | + /* 560 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98, |
| 134765 | 135286 | /* 570 */ 98, 450, 96, 96, 96, 96, 95, 95, 94, 94, |
| 134766 | 135287 | /* 580 */ 94, 93, 351, 325, 350, 350, 350, 260, 377, 340, |
| 134767 | | - /* 590 */ 929, 52, 52, 90, 842, 842, 854, 857, 846, 846, |
| 135288 | + /* 590 */ 928, 52, 52, 90, 978, 978, 853, 856, 845, 845, |
| 134768 | 135289 | /* 600 */ 97, 97, 98, 98, 98, 98, 361, 96, 96, 96, |
| 134769 | 135290 | /* 610 */ 96, 95, 95, 94, 94, 94, 93, 351, 86, 445, |
| 134770 | | - /* 620 */ 847, 3, 1203, 361, 360, 378, 344, 813, 958, 958, |
| 134771 | | - /* 630 */ 1300, 86, 445, 729, 3, 212, 169, 287, 405, 282, |
| 135291 | + /* 620 */ 846, 3, 1202, 361, 360, 378, 344, 813, 957, 957, |
| 135292 | + /* 630 */ 1299, 86, 445, 729, 3, 212, 169, 287, 405, 282, |
| 134772 | 135293 | /* 640 */ 404, 199, 232, 450, 300, 760, 83, 84, 280, 245, |
| 134773 | 135294 | /* 650 */ 262, 365, 251, 85, 352, 352, 92, 89, 178, 83, |
| 134774 | 135295 | /* 660 */ 84, 242, 412, 52, 52, 448, 85, 352, 352, 246, |
| 134775 | | - /* 670 */ 959, 960, 194, 455, 670, 402, 399, 398, 448, 243, |
| 135296 | + /* 670 */ 958, 959, 194, 455, 670, 402, 399, 398, 448, 243, |
| 134776 | 135297 | /* 680 */ 221, 114, 434, 776, 361, 450, 397, 268, 747, 224, |
| 134777 | 135298 | /* 690 */ 224, 132, 132, 198, 832, 434, 452, 451, 428, 427, |
| 134778 | 135299 | /* 700 */ 819, 415, 734, 713, 132, 52, 52, 832, 268, 452, |
| 134779 | | - /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1271, |
| 134780 | | - /* 720 */ 1271, 23, 958, 958, 86, 445, 397, 3, 228, 429, |
| 134781 | | - /* 730 */ 895, 824, 824, 826, 827, 19, 203, 720, 52, 52, |
| 135300 | + /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1270, |
| 135301 | + /* 720 */ 1270, 23, 957, 957, 86, 445, 397, 3, 228, 429, |
| 135302 | + /* 730 */ 894, 824, 824, 826, 827, 19, 203, 720, 52, 52, |
| 134782 | 135303 | /* 740 */ 428, 408, 439, 249, 824, 824, 826, 827, 19, 229, |
| 134783 | 135304 | /* 750 */ 403, 153, 83, 84, 761, 177, 241, 450, 721, 85, |
| 134784 | | - /* 760 */ 352, 352, 120, 157, 959, 960, 58, 977, 409, 355, |
| 135305 | + /* 760 */ 352, 352, 120, 157, 958, 959, 58, 976, 409, 355, |
| 134785 | 135306 | /* 770 */ 330, 448, 268, 428, 430, 320, 790, 32, 32, 86, |
| 134786 | 135307 | /* 780 */ 445, 776, 3, 341, 98, 98, 98, 98, 434, 96, |
| 134787 | 135308 | /* 790 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351, |
| 134788 | | - /* 800 */ 832, 120, 452, 451, 813, 887, 819, 83, 84, 977, |
| 134789 | | - /* 810 */ 813, 132, 410, 920, 85, 352, 352, 132, 407, 789, |
| 134790 | | - /* 820 */ 958, 958, 92, 89, 178, 917, 448, 262, 370, 261, |
| 134791 | | - /* 830 */ 82, 914, 80, 262, 370, 261, 776, 824, 824, 826, |
| 134792 | | - /* 840 */ 827, 19, 934, 434, 96, 96, 96, 96, 95, 95, |
| 134793 | | - /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 958, |
| 134794 | | - /* 860 */ 958, 819, 959, 960, 120, 92, 89, 178, 945, 2, |
| 134795 | | - /* 870 */ 918, 965, 268, 1, 976, 76, 445, 762, 3, 708, |
| 134796 | | - /* 880 */ 901, 901, 387, 958, 958, 757, 919, 371, 740, 778, |
| 135309 | + /* 800 */ 832, 120, 452, 451, 813, 886, 819, 83, 84, 976, |
| 135310 | + /* 810 */ 813, 132, 410, 919, 85, 352, 352, 132, 407, 789, |
| 135311 | + /* 820 */ 957, 957, 92, 89, 178, 916, 448, 262, 370, 261, |
| 135312 | + /* 830 */ 82, 913, 80, 262, 370, 261, 776, 824, 824, 826, |
| 135313 | + /* 840 */ 827, 19, 933, 434, 96, 96, 96, 96, 95, 95, |
| 135314 | + /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 957, |
| 135315 | + /* 860 */ 957, 819, 958, 959, 120, 92, 89, 178, 944, 2, |
| 135316 | + /* 870 */ 917, 964, 268, 1, 975, 76, 445, 762, 3, 708, |
| 135317 | + /* 880 */ 900, 900, 387, 957, 957, 757, 918, 371, 740, 778, |
| 134797 | 135318 | /* 890 */ 756, 257, 824, 824, 826, 827, 19, 417, 741, 450, |
| 134798 | | - /* 900 */ 24, 959, 960, 83, 84, 369, 958, 958, 177, 226, |
| 134799 | | - /* 910 */ 85, 352, 352, 885, 315, 314, 313, 215, 311, 10, |
| 134800 | | - /* 920 */ 10, 683, 448, 349, 348, 959, 960, 909, 777, 157, |
| 134801 | | - /* 930 */ 120, 958, 958, 337, 776, 416, 711, 310, 450, 434, |
| 134802 | | - /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 959, 960, |
| 134803 | | - /* 950 */ 908, 832, 792, 452, 451, 9, 9, 819, 10, 10, |
| 135319 | + /* 900 */ 24, 958, 959, 83, 84, 369, 957, 957, 177, 226, |
| 135320 | + /* 910 */ 85, 352, 352, 884, 315, 314, 313, 215, 311, 10, |
| 135321 | + /* 920 */ 10, 683, 448, 349, 348, 958, 959, 908, 777, 157, |
| 135322 | + /* 930 */ 120, 957, 957, 337, 776, 416, 711, 310, 450, 434, |
| 135323 | + /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 958, 959, |
| 135324 | + /* 950 */ 907, 832, 792, 452, 451, 9, 9, 819, 10, 10, |
| 134804 | 135325 | /* 960 */ 52, 52, 51, 51, 180, 716, 248, 10, 10, 171, |
| 134805 | | - /* 970 */ 170, 167, 339, 959, 960, 247, 984, 702, 702, 450, |
| 134806 | | - /* 980 */ 715, 233, 686, 982, 889, 983, 182, 914, 824, 824, |
| 135326 | + /* 970 */ 170, 167, 339, 958, 959, 247, 984, 702, 702, 450, |
| 135327 | + /* 980 */ 715, 233, 686, 982, 888, 983, 182, 913, 824, 824, |
| 134807 | 135328 | /* 990 */ 826, 827, 19, 183, 256, 423, 132, 181, 394, 10, |
| 134808 | | - /* 1000 */ 10, 889, 891, 749, 958, 958, 917, 268, 985, 198, |
| 135329 | + /* 1000 */ 10, 888, 890, 749, 957, 957, 916, 268, 985, 198, |
| 134809 | 135330 | /* 1010 */ 985, 349, 348, 425, 415, 299, 817, 832, 326, 825, |
| 134810 | 135331 | /* 1020 */ 120, 332, 133, 819, 268, 98, 98, 98, 98, 91, |
| 134811 | 135332 | /* 1030 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93, |
| 134812 | | - /* 1040 */ 351, 157, 810, 371, 382, 359, 959, 960, 358, 268, |
| 134813 | | - /* 1050 */ 450, 918, 368, 324, 824, 824, 826, 450, 709, 450, |
| 134814 | | - /* 1060 */ 264, 380, 889, 450, 877, 746, 253, 919, 255, 433, |
| 135333 | + /* 1040 */ 351, 157, 810, 371, 382, 359, 958, 959, 358, 268, |
| 135334 | + /* 1050 */ 450, 917, 368, 324, 824, 824, 826, 450, 709, 450, |
| 135335 | + /* 1060 */ 264, 380, 888, 450, 876, 746, 253, 918, 255, 433, |
| 134815 | 135336 | /* 1070 */ 36, 36, 234, 450, 234, 120, 269, 37, 37, 12, |
| 134816 | 135337 | /* 1080 */ 12, 334, 272, 27, 27, 450, 330, 118, 450, 162, |
| 134817 | 135338 | /* 1090 */ 742, 280, 450, 38, 38, 450, 985, 356, 985, 450, |
| 134818 | | - /* 1100 */ 709, 1210, 450, 132, 450, 39, 39, 450, 40, 40, |
| 135339 | + /* 1100 */ 709, 1209, 450, 132, 450, 39, 39, 450, 40, 40, |
| 134819 | 135340 | /* 1110 */ 450, 362, 41, 41, 450, 42, 42, 450, 254, 28, |
| 134820 | 135341 | /* 1120 */ 28, 450, 29, 29, 31, 31, 450, 43, 43, 450, |
| 134821 | 135342 | /* 1130 */ 44, 44, 450, 714, 45, 45, 450, 11, 11, 767, |
| 134822 | 135343 | /* 1140 */ 450, 46, 46, 450, 268, 450, 105, 105, 450, 47, |
| 134823 | 135344 | /* 1150 */ 47, 450, 48, 48, 450, 237, 33, 33, 450, 172, |
| 134824 | 135345 | /* 1160 */ 49, 49, 450, 50, 50, 34, 34, 274, 122, 122, |
| 134825 | | - /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 898, 56, 56, |
| 134826 | | - /* 1180 */ 450, 897, 35, 35, 450, 267, 450, 817, 450, 817, |
| 135346 | + /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 897, 56, 56, |
| 135347 | + /* 1180 */ 450, 896, 35, 35, 450, 267, 450, 817, 450, 817, |
| 134827 | 135348 | /* 1190 */ 106, 106, 450, 53, 53, 385, 107, 107, 450, 817, |
| 134828 | 135349 | /* 1200 */ 108, 108, 817, 450, 104, 104, 121, 121, 119, 119, |
| 134829 | 135350 | /* 1210 */ 450, 117, 112, 112, 450, 276, 450, 225, 111, 111, |
| 134830 | | - /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 912, |
| 135351 | + /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 911, |
| 134831 | 135352 | /* 1230 */ 110, 110, 317, 998, 55, 55, 57, 57, 692, 331, |
| 134832 | | - /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 937, 197, |
| 135353 | + /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 936, 197, |
| 134833 | 135354 | /* 1250 */ 196, 195, 335, 281, 336, 446, 331, 745, 689, 436, |
| 134834 | | - /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 933, |
| 135355 | + /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 932, |
| 134835 | 135356 | /* 1270 */ 20, 286, 319, 756, 815, 372, 374, 202, 202, 202, |
| 134836 | | - /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 884, |
| 135357 | + /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 883, |
| 134837 | 135358 | /* 1290 */ 120, 120, 120, 120, 120, 754, 278, 828, 77, 74, |
| 134838 | | - /* 1300 */ 726, 727, 785, 783, 880, 202, 999, 208, 894, 893, |
| 134839 | | - /* 1310 */ 894, 893, 694, 816, 763, 116, 774, 1290, 431, 432, |
| 135359 | + /* 1300 */ 726, 727, 785, 783, 879, 202, 999, 208, 893, 892, |
| 135360 | + /* 1310 */ 893, 892, 694, 816, 763, 116, 774, 1289, 431, 432, |
| 134840 | 135361 | /* 1320 */ 302, 999, 390, 303, 823, 697, 691, 680, 159, 289, |
| 134841 | | - /* 1330 */ 679, 884, 681, 952, 291, 218, 293, 7, 316, 828, |
| 134842 | | - /* 1340 */ 173, 805, 259, 364, 252, 911, 376, 713, 295, 435, |
| 134843 | | - /* 1350 */ 308, 168, 955, 993, 135, 400, 990, 284, 882, 881, |
| 134844 | | - /* 1360 */ 205, 928, 926, 59, 333, 62, 144, 156, 130, 72, |
| 135362 | + /* 1330 */ 679, 883, 681, 951, 291, 218, 293, 7, 316, 828, |
| 135363 | + /* 1340 */ 173, 805, 259, 364, 252, 910, 376, 713, 295, 435, |
| 135364 | + /* 1350 */ 308, 168, 954, 993, 135, 400, 990, 284, 881, 880, |
| 135365 | + /* 1360 */ 205, 927, 925, 59, 333, 62, 144, 156, 130, 72, |
| 134845 | 135366 | /* 1370 */ 802, 366, 367, 393, 137, 185, 189, 160, 139, 383, |
| 134846 | | - /* 1380 */ 67, 896, 140, 141, 142, 148, 389, 812, 775, 266, |
| 134847 | | - /* 1390 */ 219, 190, 154, 391, 913, 876, 271, 406, 191, 322, |
| 135367 | + /* 1380 */ 67, 895, 140, 141, 142, 148, 389, 812, 775, 266, |
| 135368 | + /* 1390 */ 219, 190, 154, 391, 912, 875, 271, 406, 191, 322, |
| 134848 | 135369 | /* 1400 */ 682, 733, 192, 342, 732, 724, 731, 711, 723, 421, |
| 134849 | 135370 | /* 1410 */ 705, 71, 323, 6, 204, 771, 288, 79, 297, 346, |
| 134850 | | - /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 967, 239, |
| 134851 | | - /* 1430 */ 769, 102, 862, 438, 426, 240, 424, 442, 73, 213, |
| 134852 | | - /* 1440 */ 688, 238, 22, 453, 953, 214, 217, 216, 454, 677, |
| 135371 | + /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 966, 239, |
| 135372 | + /* 1430 */ 769, 102, 861, 438, 426, 240, 424, 442, 73, 213, |
| 135373 | + /* 1440 */ 688, 238, 22, 453, 952, 214, 217, 216, 454, 677, |
| 134853 | 135374 | /* 1450 */ 676, 671, 753, 125, 115, 235, 126, 669, 353, 166, |
| 134854 | | - /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 892, |
| 134855 | | - /* 1470 */ 327, 890, 811, 328, 134, 128, 136, 138, 743, 258, |
| 134856 | | - /* 1480 */ 907, 184, 143, 129, 910, 186, 63, 64, 145, 187, |
| 134857 | | - /* 1490 */ 906, 65, 8, 66, 13, 188, 202, 899, 265, 149, |
| 135375 | + /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 891, |
| 135376 | + /* 1470 */ 327, 889, 811, 328, 134, 128, 136, 138, 743, 258, |
| 135377 | + /* 1480 */ 906, 184, 143, 129, 909, 186, 63, 64, 145, 187, |
| 135378 | + /* 1490 */ 905, 65, 8, 66, 13, 188, 202, 898, 265, 149, |
| 134858 | 135379 | /* 1500 */ 987, 388, 150, 685, 161, 392, 285, 193, 279, 396, |
| 134859 | 135380 | /* 1510 */ 151, 401, 68, 14, 15, 722, 69, 236, 831, 131, |
| 134860 | | - /* 1520 */ 830, 860, 70, 751, 16, 414, 755, 4, 174, 220, |
| 134861 | | - /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 875, |
| 134862 | | - /* 1540 */ 861, 859, 916, 864, 915, 207, 206, 942, 163, 437, |
| 134863 | | - /* 1550 */ 948, 943, 164, 209, 1002, 441, 863, 165, 210, 829, |
| 134864 | | - /* 1560 */ 695, 87, 312, 211, 1292, 1291, 309, |
| 135381 | + /* 1520 */ 830, 859, 70, 751, 16, 414, 755, 4, 174, 220, |
| 135382 | + /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 874, |
| 135383 | + /* 1540 */ 860, 858, 915, 863, 914, 207, 206, 941, 163, 437, |
| 135384 | + /* 1550 */ 947, 942, 164, 209, 1002, 441, 862, 165, 210, 829, |
| 135385 | + /* 1560 */ 695, 87, 312, 211, 1291, 1290, 309, |
| 134865 | 135386 | }; |
| 134866 | 135387 | static const YYCODETYPE yy_lookahead[] = { |
| 134867 | 135388 | /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28, |
| 134868 | 135389 | /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, |
| 134869 | 135390 | /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48, |
| | @@ -135112,55 +135633,55 @@ |
| 135112 | 135633 | /* 300 */ 1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278, |
| 135113 | 135634 | /* 310 */ 1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228, |
| 135114 | 135635 | /* 320 */ 1288, 1291, 1276, 1277, 1295, |
| 135115 | 135636 | }; |
| 135116 | 135637 | static const YYACTIONTYPE yy_default[] = { |
| 135117 | | - /* 0 */ 1281, 1271, 1271, 1271, 1203, 1203, 1203, 1203, 1271, 1096, |
| 135118 | | - /* 10 */ 1125, 1125, 1255, 1332, 1332, 1332, 1332, 1332, 1332, 1202, |
| 135119 | | - /* 20 */ 1332, 1332, 1332, 1332, 1271, 1100, 1131, 1332, 1332, 1332, |
| 135120 | | - /* 30 */ 1332, 1204, 1205, 1332, 1332, 1332, 1254, 1256, 1141, 1140, |
| 135121 | | - /* 40 */ 1139, 1138, 1237, 1112, 1136, 1129, 1133, 1204, 1198, 1199, |
| 135122 | | - /* 50 */ 1197, 1201, 1205, 1332, 1132, 1167, 1182, 1166, 1332, 1332, |
| 135638 | + /* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096, |
| 135639 | + /* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201, |
| 135640 | + /* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332, |
| 135641 | + /* 30 */ 1332, 1203, 1204, 1332, 1332, 1332, 1253, 1255, 1141, 1140, |
| 135642 | + /* 40 */ 1139, 1138, 1236, 1112, 1136, 1129, 1133, 1203, 1197, 1198, |
| 135643 | + /* 50 */ 1196, 1200, 1204, 1332, 1132, 1167, 1181, 1166, 1332, 1332, |
| 135123 | 135644 | /* 60 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135124 | 135645 | /* 70 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135125 | 135646 | /* 80 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135126 | 135647 | /* 90 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135127 | | - /* 100 */ 1332, 1332, 1332, 1332, 1176, 1181, 1188, 1180, 1177, 1169, |
| 135648 | + /* 100 */ 1332, 1332, 1332, 1332, 1175, 1180, 1187, 1179, 1176, 1169, |
| 135128 | 135649 | /* 110 */ 1168, 1170, 1171, 1332, 1019, 1067, 1332, 1332, 1332, 1172, |
| 135129 | | - /* 120 */ 1332, 1173, 1185, 1184, 1183, 1262, 1289, 1288, 1332, 1332, |
| 135650 | + /* 120 */ 1332, 1173, 1184, 1183, 1182, 1261, 1288, 1287, 1332, 1332, |
| 135130 | 135651 | /* 130 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135131 | 135652 | /* 140 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135132 | | - /* 150 */ 1332, 1332, 1332, 1332, 1332, 1281, 1271, 1025, 1025, 1332, |
| 135133 | | - /* 160 */ 1271, 1271, 1271, 1271, 1271, 1271, 1267, 1100, 1091, 1332, |
| 135653 | + /* 150 */ 1332, 1332, 1332, 1332, 1332, 1280, 1270, 1025, 1025, 1332, |
| 135654 | + /* 160 */ 1270, 1270, 1270, 1270, 1270, 1270, 1266, 1100, 1091, 1332, |
| 135134 | 135655 | /* 170 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135135 | | - /* 180 */ 1259, 1257, 1332, 1218, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135656 | + /* 180 */ 1258, 1256, 1332, 1217, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135136 | 135657 | /* 190 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135137 | 135658 | /* 200 */ 1332, 1332, 1332, 1332, 1096, 1332, 1332, 1332, 1332, 1332, |
| 135138 | | - /* 210 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1283, 1332, 1232, |
| 135659 | + /* 210 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1282, 1332, 1231, |
| 135139 | 135660 | /* 220 */ 1096, 1096, 1096, 1098, 1080, 1090, 1004, 1135, 1114, 1114, |
| 135140 | | - /* 230 */ 1321, 1135, 1321, 1042, 1303, 1039, 1125, 1114, 1200, 1125, |
| 135661 | + /* 230 */ 1321, 1135, 1321, 1042, 1302, 1039, 1125, 1114, 1199, 1125, |
| 135141 | 135662 | /* 240 */ 1125, 1097, 1090, 1332, 1324, 1105, 1105, 1323, 1323, 1105, |
| 135142 | 135663 | /* 250 */ 1146, 1070, 1135, 1076, 1076, 1076, 1076, 1105, 1016, 1135, |
| 135143 | | - /* 260 */ 1146, 1070, 1070, 1135, 1105, 1016, 1236, 1318, 1105, 1105, |
| 135144 | | - /* 270 */ 1016, 1211, 1105, 1016, 1105, 1016, 1211, 1068, 1068, 1068, |
| 135145 | | - /* 280 */ 1057, 1211, 1068, 1042, 1068, 1057, 1068, 1068, 1118, 1113, |
| 135146 | | - /* 290 */ 1118, 1113, 1118, 1113, 1118, 1113, 1105, 1206, 1105, 1332, |
| 135147 | | - /* 300 */ 1211, 1215, 1215, 1211, 1130, 1119, 1128, 1126, 1135, 1022, |
| 135148 | | - /* 310 */ 1060, 1286, 1286, 1282, 1282, 1282, 1282, 1329, 1329, 1267, |
| 135149 | | - /* 320 */ 1298, 1298, 1044, 1044, 1298, 1332, 1332, 1332, 1332, 1332, |
| 135150 | | - /* 330 */ 1332, 1293, 1332, 1220, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135664 | + /* 260 */ 1146, 1070, 1070, 1135, 1105, 1016, 1235, 1318, 1105, 1105, |
| 135665 | + /* 270 */ 1016, 1210, 1105, 1016, 1105, 1016, 1210, 1068, 1068, 1068, |
| 135666 | + /* 280 */ 1057, 1210, 1068, 1042, 1068, 1057, 1068, 1068, 1118, 1113, |
| 135667 | + /* 290 */ 1118, 1113, 1118, 1113, 1118, 1113, 1105, 1205, 1105, 1332, |
| 135668 | + /* 300 */ 1210, 1214, 1214, 1210, 1130, 1119, 1128, 1126, 1135, 1022, |
| 135669 | + /* 310 */ 1060, 1285, 1285, 1281, 1281, 1281, 1281, 1329, 1329, 1266, |
| 135670 | + /* 320 */ 1297, 1297, 1044, 1044, 1297, 1332, 1332, 1332, 1332, 1332, |
| 135671 | + /* 330 */ 1332, 1292, 1332, 1219, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135151 | 135672 | /* 340 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135152 | | - /* 350 */ 1332, 1332, 1152, 1332, 1000, 1264, 1332, 1332, 1263, 1332, |
| 135673 | + /* 350 */ 1332, 1332, 1152, 1332, 1000, 1263, 1332, 1332, 1262, 1332, |
| 135153 | 135674 | /* 360 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135154 | 135675 | /* 370 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1320, |
| 135155 | | - /* 380 */ 1332, 1332, 1332, 1332, 1332, 1332, 1235, 1234, 1332, 1332, |
| 135676 | + /* 380 */ 1332, 1332, 1332, 1332, 1332, 1332, 1234, 1233, 1332, 1332, |
| 135156 | 135677 | /* 390 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135157 | 135678 | /* 400 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, |
| 135158 | | - /* 410 */ 1332, 1082, 1332, 1332, 1332, 1307, 1332, 1332, 1332, 1332, |
| 135679 | + /* 410 */ 1332, 1082, 1332, 1332, 1332, 1306, 1332, 1332, 1332, 1332, |
| 135159 | 135680 | /* 420 */ 1332, 1332, 1332, 1127, 1332, 1120, 1332, 1332, 1311, 1332, |
| 135160 | | - /* 430 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1273, |
| 135161 | | - /* 440 */ 1332, 1332, 1332, 1272, 1332, 1332, 1332, 1332, 1332, 1154, |
| 135681 | + /* 430 */ 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1272, |
| 135682 | + /* 440 */ 1332, 1332, 1332, 1271, 1332, 1332, 1332, 1332, 1332, 1154, |
| 135162 | 135683 | /* 450 */ 1332, 1153, 1157, 1332, 1010, 1332, |
| 135163 | 135684 | }; |
| 135164 | 135685 | /********** End of lemon-generated parsing tables *****************************/ |
| 135165 | 135686 | |
| 135166 | 135687 | /* The next table maps tokens (terminal symbols) into fallback tokens. |
| | @@ -135602,147 +136123,147 @@ |
| 135602 | 136123 | /* 169 */ "expr ::= expr EQ|NE expr", |
| 135603 | 136124 | /* 170 */ "expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr", |
| 135604 | 136125 | /* 171 */ "expr ::= expr PLUS|MINUS expr", |
| 135605 | 136126 | /* 172 */ "expr ::= expr STAR|SLASH|REM expr", |
| 135606 | 136127 | /* 173 */ "expr ::= expr CONCAT expr", |
| 135607 | | - /* 174 */ "likeop ::= LIKE_KW|MATCH", |
| 135608 | | - /* 175 */ "likeop ::= NOT LIKE_KW|MATCH", |
| 135609 | | - /* 176 */ "expr ::= expr likeop expr", |
| 135610 | | - /* 177 */ "expr ::= expr likeop expr ESCAPE expr", |
| 135611 | | - /* 178 */ "expr ::= expr ISNULL|NOTNULL", |
| 135612 | | - /* 179 */ "expr ::= expr NOT NULL", |
| 135613 | | - /* 180 */ "expr ::= expr IS expr", |
| 135614 | | - /* 181 */ "expr ::= expr IS NOT expr", |
| 135615 | | - /* 182 */ "expr ::= NOT expr", |
| 135616 | | - /* 183 */ "expr ::= BITNOT expr", |
| 135617 | | - /* 184 */ "expr ::= MINUS expr", |
| 135618 | | - /* 185 */ "expr ::= PLUS expr", |
| 135619 | | - /* 186 */ "between_op ::= BETWEEN", |
| 135620 | | - /* 187 */ "between_op ::= NOT BETWEEN", |
| 135621 | | - /* 188 */ "expr ::= expr between_op expr AND expr", |
| 135622 | | - /* 189 */ "in_op ::= IN", |
| 135623 | | - /* 190 */ "in_op ::= NOT IN", |
| 135624 | | - /* 191 */ "expr ::= expr in_op LP exprlist RP", |
| 135625 | | - /* 192 */ "expr ::= LP select RP", |
| 135626 | | - /* 193 */ "expr ::= expr in_op LP select RP", |
| 135627 | | - /* 194 */ "expr ::= expr in_op nm dbnm paren_exprlist", |
| 135628 | | - /* 195 */ "expr ::= EXISTS LP select RP", |
| 135629 | | - /* 196 */ "expr ::= CASE case_operand case_exprlist case_else END", |
| 135630 | | - /* 197 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", |
| 135631 | | - /* 198 */ "case_exprlist ::= WHEN expr THEN expr", |
| 135632 | | - /* 199 */ "case_else ::= ELSE expr", |
| 135633 | | - /* 200 */ "case_else ::=", |
| 135634 | | - /* 201 */ "case_operand ::= expr", |
| 135635 | | - /* 202 */ "case_operand ::=", |
| 135636 | | - /* 203 */ "exprlist ::=", |
| 135637 | | - /* 204 */ "nexprlist ::= nexprlist COMMA expr", |
| 135638 | | - /* 205 */ "nexprlist ::= expr", |
| 135639 | | - /* 206 */ "paren_exprlist ::=", |
| 135640 | | - /* 207 */ "paren_exprlist ::= LP exprlist RP", |
| 135641 | | - /* 208 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt", |
| 135642 | | - /* 209 */ "uniqueflag ::= UNIQUE", |
| 135643 | | - /* 210 */ "uniqueflag ::=", |
| 135644 | | - /* 211 */ "eidlist_opt ::=", |
| 135645 | | - /* 212 */ "eidlist_opt ::= LP eidlist RP", |
| 135646 | | - /* 213 */ "eidlist ::= eidlist COMMA nm collate sortorder", |
| 135647 | | - /* 214 */ "eidlist ::= nm collate sortorder", |
| 135648 | | - /* 215 */ "collate ::=", |
| 135649 | | - /* 216 */ "collate ::= COLLATE ID|STRING", |
| 135650 | | - /* 217 */ "cmd ::= DROP INDEX ifexists fullname", |
| 135651 | | - /* 218 */ "cmd ::= VACUUM", |
| 135652 | | - /* 219 */ "cmd ::= VACUUM nm", |
| 135653 | | - /* 220 */ "cmd ::= PRAGMA nm dbnm", |
| 135654 | | - /* 221 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", |
| 135655 | | - /* 222 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", |
| 135656 | | - /* 223 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", |
| 135657 | | - /* 224 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", |
| 135658 | | - /* 225 */ "plus_num ::= PLUS INTEGER|FLOAT", |
| 135659 | | - /* 226 */ "minus_num ::= MINUS INTEGER|FLOAT", |
| 135660 | | - /* 227 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", |
| 135661 | | - /* 228 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", |
| 135662 | | - /* 229 */ "trigger_time ::= BEFORE", |
| 135663 | | - /* 230 */ "trigger_time ::= AFTER", |
| 135664 | | - /* 231 */ "trigger_time ::= INSTEAD OF", |
| 135665 | | - /* 232 */ "trigger_time ::=", |
| 135666 | | - /* 233 */ "trigger_event ::= DELETE|INSERT", |
| 135667 | | - /* 234 */ "trigger_event ::= UPDATE", |
| 135668 | | - /* 235 */ "trigger_event ::= UPDATE OF idlist", |
| 135669 | | - /* 236 */ "when_clause ::=", |
| 135670 | | - /* 237 */ "when_clause ::= WHEN expr", |
| 135671 | | - /* 238 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", |
| 135672 | | - /* 239 */ "trigger_cmd_list ::= trigger_cmd SEMI", |
| 135673 | | - /* 240 */ "trnm ::= nm DOT nm", |
| 135674 | | - /* 241 */ "tridxby ::= INDEXED BY nm", |
| 135675 | | - /* 242 */ "tridxby ::= NOT INDEXED", |
| 135676 | | - /* 243 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt", |
| 135677 | | - /* 244 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select", |
| 135678 | | - /* 245 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt", |
| 135679 | | - /* 246 */ "trigger_cmd ::= select", |
| 135680 | | - /* 247 */ "expr ::= RAISE LP IGNORE RP", |
| 135681 | | - /* 248 */ "expr ::= RAISE LP raisetype COMMA nm RP", |
| 135682 | | - /* 249 */ "raisetype ::= ROLLBACK", |
| 135683 | | - /* 250 */ "raisetype ::= ABORT", |
| 135684 | | - /* 251 */ "raisetype ::= FAIL", |
| 135685 | | - /* 252 */ "cmd ::= DROP TRIGGER ifexists fullname", |
| 135686 | | - /* 253 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", |
| 135687 | | - /* 254 */ "cmd ::= DETACH database_kw_opt expr", |
| 135688 | | - /* 255 */ "key_opt ::=", |
| 135689 | | - /* 256 */ "key_opt ::= KEY expr", |
| 135690 | | - /* 257 */ "cmd ::= REINDEX", |
| 135691 | | - /* 258 */ "cmd ::= REINDEX nm dbnm", |
| 135692 | | - /* 259 */ "cmd ::= ANALYZE", |
| 135693 | | - /* 260 */ "cmd ::= ANALYZE nm dbnm", |
| 135694 | | - /* 261 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", |
| 135695 | | - /* 262 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist", |
| 135696 | | - /* 263 */ "add_column_fullname ::= fullname", |
| 135697 | | - /* 264 */ "cmd ::= create_vtab", |
| 135698 | | - /* 265 */ "cmd ::= create_vtab LP vtabarglist RP", |
| 135699 | | - /* 266 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", |
| 135700 | | - /* 267 */ "vtabarg ::=", |
| 135701 | | - /* 268 */ "vtabargtoken ::= ANY", |
| 135702 | | - /* 269 */ "vtabargtoken ::= lp anylist RP", |
| 135703 | | - /* 270 */ "lp ::= LP", |
| 135704 | | - /* 271 */ "with ::=", |
| 135705 | | - /* 272 */ "with ::= WITH wqlist", |
| 135706 | | - /* 273 */ "with ::= WITH RECURSIVE wqlist", |
| 135707 | | - /* 274 */ "wqlist ::= nm eidlist_opt AS LP select RP", |
| 135708 | | - /* 275 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP", |
| 135709 | | - /* 276 */ "input ::= cmdlist", |
| 135710 | | - /* 277 */ "cmdlist ::= cmdlist ecmd", |
| 135711 | | - /* 278 */ "cmdlist ::= ecmd", |
| 135712 | | - /* 279 */ "ecmd ::= SEMI", |
| 135713 | | - /* 280 */ "ecmd ::= explain cmdx SEMI", |
| 135714 | | - /* 281 */ "explain ::=", |
| 135715 | | - /* 282 */ "trans_opt ::=", |
| 135716 | | - /* 283 */ "trans_opt ::= TRANSACTION", |
| 135717 | | - /* 284 */ "trans_opt ::= TRANSACTION nm", |
| 135718 | | - /* 285 */ "savepoint_opt ::= SAVEPOINT", |
| 135719 | | - /* 286 */ "savepoint_opt ::=", |
| 135720 | | - /* 287 */ "cmd ::= create_table create_table_args", |
| 135721 | | - /* 288 */ "columnlist ::= columnlist COMMA columnname carglist", |
| 135722 | | - /* 289 */ "columnlist ::= columnname carglist", |
| 135723 | | - /* 290 */ "nm ::= ID|INDEXED", |
| 135724 | | - /* 291 */ "nm ::= STRING", |
| 135725 | | - /* 292 */ "nm ::= JOIN_KW", |
| 135726 | | - /* 293 */ "typetoken ::= typename", |
| 135727 | | - /* 294 */ "typename ::= ID|STRING", |
| 135728 | | - /* 295 */ "signed ::= plus_num", |
| 135729 | | - /* 296 */ "signed ::= minus_num", |
| 135730 | | - /* 297 */ "carglist ::= carglist ccons", |
| 135731 | | - /* 298 */ "carglist ::=", |
| 135732 | | - /* 299 */ "ccons ::= NULL onconf", |
| 135733 | | - /* 300 */ "conslist_opt ::= COMMA conslist", |
| 135734 | | - /* 301 */ "conslist ::= conslist tconscomma tcons", |
| 135735 | | - /* 302 */ "conslist ::= tcons", |
| 135736 | | - /* 303 */ "tconscomma ::=", |
| 135737 | | - /* 304 */ "defer_subclause_opt ::= defer_subclause", |
| 135738 | | - /* 305 */ "resolvetype ::= raisetype", |
| 135739 | | - /* 306 */ "selectnowith ::= oneselect", |
| 135740 | | - /* 307 */ "oneselect ::= values", |
| 135741 | | - /* 308 */ "sclp ::= selcollist COMMA", |
| 135742 | | - /* 309 */ "as ::= ID|STRING", |
| 135743 | | - /* 310 */ "expr ::= term", |
| 136128 | + /* 174 */ "likeop ::= NOT LIKE_KW|MATCH", |
| 136129 | + /* 175 */ "expr ::= expr likeop expr", |
| 136130 | + /* 176 */ "expr ::= expr likeop expr ESCAPE expr", |
| 136131 | + /* 177 */ "expr ::= expr ISNULL|NOTNULL", |
| 136132 | + /* 178 */ "expr ::= expr NOT NULL", |
| 136133 | + /* 179 */ "expr ::= expr IS expr", |
| 136134 | + /* 180 */ "expr ::= expr IS NOT expr", |
| 136135 | + /* 181 */ "expr ::= NOT expr", |
| 136136 | + /* 182 */ "expr ::= BITNOT expr", |
| 136137 | + /* 183 */ "expr ::= MINUS expr", |
| 136138 | + /* 184 */ "expr ::= PLUS expr", |
| 136139 | + /* 185 */ "between_op ::= BETWEEN", |
| 136140 | + /* 186 */ "between_op ::= NOT BETWEEN", |
| 136141 | + /* 187 */ "expr ::= expr between_op expr AND expr", |
| 136142 | + /* 188 */ "in_op ::= IN", |
| 136143 | + /* 189 */ "in_op ::= NOT IN", |
| 136144 | + /* 190 */ "expr ::= expr in_op LP exprlist RP", |
| 136145 | + /* 191 */ "expr ::= LP select RP", |
| 136146 | + /* 192 */ "expr ::= expr in_op LP select RP", |
| 136147 | + /* 193 */ "expr ::= expr in_op nm dbnm paren_exprlist", |
| 136148 | + /* 194 */ "expr ::= EXISTS LP select RP", |
| 136149 | + /* 195 */ "expr ::= CASE case_operand case_exprlist case_else END", |
| 136150 | + /* 196 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr", |
| 136151 | + /* 197 */ "case_exprlist ::= WHEN expr THEN expr", |
| 136152 | + /* 198 */ "case_else ::= ELSE expr", |
| 136153 | + /* 199 */ "case_else ::=", |
| 136154 | + /* 200 */ "case_operand ::= expr", |
| 136155 | + /* 201 */ "case_operand ::=", |
| 136156 | + /* 202 */ "exprlist ::=", |
| 136157 | + /* 203 */ "nexprlist ::= nexprlist COMMA expr", |
| 136158 | + /* 204 */ "nexprlist ::= expr", |
| 136159 | + /* 205 */ "paren_exprlist ::=", |
| 136160 | + /* 206 */ "paren_exprlist ::= LP exprlist RP", |
| 136161 | + /* 207 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt", |
| 136162 | + /* 208 */ "uniqueflag ::= UNIQUE", |
| 136163 | + /* 209 */ "uniqueflag ::=", |
| 136164 | + /* 210 */ "eidlist_opt ::=", |
| 136165 | + /* 211 */ "eidlist_opt ::= LP eidlist RP", |
| 136166 | + /* 212 */ "eidlist ::= eidlist COMMA nm collate sortorder", |
| 136167 | + /* 213 */ "eidlist ::= nm collate sortorder", |
| 136168 | + /* 214 */ "collate ::=", |
| 136169 | + /* 215 */ "collate ::= COLLATE ID|STRING", |
| 136170 | + /* 216 */ "cmd ::= DROP INDEX ifexists fullname", |
| 136171 | + /* 217 */ "cmd ::= VACUUM", |
| 136172 | + /* 218 */ "cmd ::= VACUUM nm", |
| 136173 | + /* 219 */ "cmd ::= PRAGMA nm dbnm", |
| 136174 | + /* 220 */ "cmd ::= PRAGMA nm dbnm EQ nmnum", |
| 136175 | + /* 221 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP", |
| 136176 | + /* 222 */ "cmd ::= PRAGMA nm dbnm EQ minus_num", |
| 136177 | + /* 223 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP", |
| 136178 | + /* 224 */ "plus_num ::= PLUS INTEGER|FLOAT", |
| 136179 | + /* 225 */ "minus_num ::= MINUS INTEGER|FLOAT", |
| 136180 | + /* 226 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END", |
| 136181 | + /* 227 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause", |
| 136182 | + /* 228 */ "trigger_time ::= BEFORE", |
| 136183 | + /* 229 */ "trigger_time ::= AFTER", |
| 136184 | + /* 230 */ "trigger_time ::= INSTEAD OF", |
| 136185 | + /* 231 */ "trigger_time ::=", |
| 136186 | + /* 232 */ "trigger_event ::= DELETE|INSERT", |
| 136187 | + /* 233 */ "trigger_event ::= UPDATE", |
| 136188 | + /* 234 */ "trigger_event ::= UPDATE OF idlist", |
| 136189 | + /* 235 */ "when_clause ::=", |
| 136190 | + /* 236 */ "when_clause ::= WHEN expr", |
| 136191 | + /* 237 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI", |
| 136192 | + /* 238 */ "trigger_cmd_list ::= trigger_cmd SEMI", |
| 136193 | + /* 239 */ "trnm ::= nm DOT nm", |
| 136194 | + /* 240 */ "tridxby ::= INDEXED BY nm", |
| 136195 | + /* 241 */ "tridxby ::= NOT INDEXED", |
| 136196 | + /* 242 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt", |
| 136197 | + /* 243 */ "trigger_cmd ::= insert_cmd INTO trnm idlist_opt select", |
| 136198 | + /* 244 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt", |
| 136199 | + /* 245 */ "trigger_cmd ::= select", |
| 136200 | + /* 246 */ "expr ::= RAISE LP IGNORE RP", |
| 136201 | + /* 247 */ "expr ::= RAISE LP raisetype COMMA nm RP", |
| 136202 | + /* 248 */ "raisetype ::= ROLLBACK", |
| 136203 | + /* 249 */ "raisetype ::= ABORT", |
| 136204 | + /* 250 */ "raisetype ::= FAIL", |
| 136205 | + /* 251 */ "cmd ::= DROP TRIGGER ifexists fullname", |
| 136206 | + /* 252 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt", |
| 136207 | + /* 253 */ "cmd ::= DETACH database_kw_opt expr", |
| 136208 | + /* 254 */ "key_opt ::=", |
| 136209 | + /* 255 */ "key_opt ::= KEY expr", |
| 136210 | + /* 256 */ "cmd ::= REINDEX", |
| 136211 | + /* 257 */ "cmd ::= REINDEX nm dbnm", |
| 136212 | + /* 258 */ "cmd ::= ANALYZE", |
| 136213 | + /* 259 */ "cmd ::= ANALYZE nm dbnm", |
| 136214 | + /* 260 */ "cmd ::= ALTER TABLE fullname RENAME TO nm", |
| 136215 | + /* 261 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist", |
| 136216 | + /* 262 */ "add_column_fullname ::= fullname", |
| 136217 | + /* 263 */ "cmd ::= create_vtab", |
| 136218 | + /* 264 */ "cmd ::= create_vtab LP vtabarglist RP", |
| 136219 | + /* 265 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm", |
| 136220 | + /* 266 */ "vtabarg ::=", |
| 136221 | + /* 267 */ "vtabargtoken ::= ANY", |
| 136222 | + /* 268 */ "vtabargtoken ::= lp anylist RP", |
| 136223 | + /* 269 */ "lp ::= LP", |
| 136224 | + /* 270 */ "with ::=", |
| 136225 | + /* 271 */ "with ::= WITH wqlist", |
| 136226 | + /* 272 */ "with ::= WITH RECURSIVE wqlist", |
| 136227 | + /* 273 */ "wqlist ::= nm eidlist_opt AS LP select RP", |
| 136228 | + /* 274 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP", |
| 136229 | + /* 275 */ "input ::= cmdlist", |
| 136230 | + /* 276 */ "cmdlist ::= cmdlist ecmd", |
| 136231 | + /* 277 */ "cmdlist ::= ecmd", |
| 136232 | + /* 278 */ "ecmd ::= SEMI", |
| 136233 | + /* 279 */ "ecmd ::= explain cmdx SEMI", |
| 136234 | + /* 280 */ "explain ::=", |
| 136235 | + /* 281 */ "trans_opt ::=", |
| 136236 | + /* 282 */ "trans_opt ::= TRANSACTION", |
| 136237 | + /* 283 */ "trans_opt ::= TRANSACTION nm", |
| 136238 | + /* 284 */ "savepoint_opt ::= SAVEPOINT", |
| 136239 | + /* 285 */ "savepoint_opt ::=", |
| 136240 | + /* 286 */ "cmd ::= create_table create_table_args", |
| 136241 | + /* 287 */ "columnlist ::= columnlist COMMA columnname carglist", |
| 136242 | + /* 288 */ "columnlist ::= columnname carglist", |
| 136243 | + /* 289 */ "nm ::= ID|INDEXED", |
| 136244 | + /* 290 */ "nm ::= STRING", |
| 136245 | + /* 291 */ "nm ::= JOIN_KW", |
| 136246 | + /* 292 */ "typetoken ::= typename", |
| 136247 | + /* 293 */ "typename ::= ID|STRING", |
| 136248 | + /* 294 */ "signed ::= plus_num", |
| 136249 | + /* 295 */ "signed ::= minus_num", |
| 136250 | + /* 296 */ "carglist ::= carglist ccons", |
| 136251 | + /* 297 */ "carglist ::=", |
| 136252 | + /* 298 */ "ccons ::= NULL onconf", |
| 136253 | + /* 299 */ "conslist_opt ::= COMMA conslist", |
| 136254 | + /* 300 */ "conslist ::= conslist tconscomma tcons", |
| 136255 | + /* 301 */ "conslist ::= tcons", |
| 136256 | + /* 302 */ "tconscomma ::=", |
| 136257 | + /* 303 */ "defer_subclause_opt ::= defer_subclause", |
| 136258 | + /* 304 */ "resolvetype ::= raisetype", |
| 136259 | + /* 305 */ "selectnowith ::= oneselect", |
| 136260 | + /* 306 */ "oneselect ::= values", |
| 136261 | + /* 307 */ "sclp ::= selcollist COMMA", |
| 136262 | + /* 308 */ "as ::= ID|STRING", |
| 136263 | + /* 309 */ "expr ::= term", |
| 136264 | + /* 310 */ "likeop ::= LIKE_KW|MATCH", |
| 135744 | 136265 | /* 311 */ "exprlist ::= nexprlist", |
| 135745 | 136266 | /* 312 */ "nmnum ::= plus_num", |
| 135746 | 136267 | /* 313 */ "nmnum ::= nm", |
| 135747 | 136268 | /* 314 */ "nmnum ::= ON", |
| 135748 | 136269 | /* 315 */ "nmnum ::= DELETE", |
| | @@ -136375,11 +136896,10 @@ |
| 136375 | 136896 | { 173, 3 }, |
| 136376 | 136897 | { 173, 3 }, |
| 136377 | 136898 | { 173, 3 }, |
| 136378 | 136899 | { 173, 3 }, |
| 136379 | 136900 | { 173, 3 }, |
| 136380 | | - { 221, 1 }, |
| 136381 | 136901 | { 221, 2 }, |
| 136382 | 136902 | { 173, 3 }, |
| 136383 | 136903 | { 173, 5 }, |
| 136384 | 136904 | { 173, 2 }, |
| 136385 | 136905 | { 173, 3 }, |
| | @@ -136512,10 +137032,11 @@ |
| 136512 | 137032 | { 194, 1 }, |
| 136513 | 137033 | { 195, 1 }, |
| 136514 | 137034 | { 209, 2 }, |
| 136515 | 137035 | { 210, 1 }, |
| 136516 | 137036 | { 173, 1 }, |
| 137037 | + { 221, 1 }, |
| 136517 | 137038 | { 208, 1 }, |
| 136518 | 137039 | { 230, 1 }, |
| 136519 | 137040 | { 230, 1 }, |
| 136520 | 137041 | { 230, 1 }, |
| 136521 | 137042 | { 230, 1 }, |
| | @@ -136654,11 +137175,11 @@ |
| 136654 | 137175 | case 42: /* autoinc ::= */ yytestcase(yyruleno==42); |
| 136655 | 137176 | case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57); |
| 136656 | 137177 | case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67); |
| 136657 | 137178 | case 76: /* ifexists ::= */ yytestcase(yyruleno==76); |
| 136658 | 137179 | case 90: /* distinct ::= */ yytestcase(yyruleno==90); |
| 136659 | | - case 215: /* collate ::= */ yytestcase(yyruleno==215); |
| 137180 | + case 214: /* collate ::= */ yytestcase(yyruleno==214); |
| 136660 | 137181 | {yymsp[1].minor.yy194 = 0;} |
| 136661 | 137182 | break; |
| 136662 | 137183 | case 17: /* ifnotexists ::= IF NOT EXISTS */ |
| 136663 | 137184 | {yymsp[-2].minor.yy194 = 1;} |
| 136664 | 137185 | break; |
| | @@ -136798,13 +137319,13 @@ |
| 136798 | 137319 | case 144: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==144); |
| 136799 | 137320 | {yymsp[-1].minor.yy194 = yymsp[0].minor.yy194;} |
| 136800 | 137321 | break; |
| 136801 | 137322 | case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */ |
| 136802 | 137323 | case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75); |
| 136803 | | - case 187: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==187); |
| 136804 | | - case 190: /* in_op ::= NOT IN */ yytestcase(yyruleno==190); |
| 136805 | | - case 216: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==216); |
| 137324 | + case 186: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==186); |
| 137325 | + case 189: /* in_op ::= NOT IN */ yytestcase(yyruleno==189); |
| 137326 | + case 215: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==215); |
| 136806 | 137327 | {yymsp[-1].minor.yy194 = 1;} |
| 136807 | 137328 | break; |
| 136808 | 137329 | case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ |
| 136809 | 137330 | {yymsp[-1].minor.yy194 = 0;} |
| 136810 | 137331 | break; |
| | @@ -136964,13 +137485,13 @@ |
| 136964 | 137485 | {yymsp[0].minor.yy194 = SF_All;} |
| 136965 | 137486 | break; |
| 136966 | 137487 | case 91: /* sclp ::= */ |
| 136967 | 137488 | case 119: /* orderby_opt ::= */ yytestcase(yyruleno==119); |
| 136968 | 137489 | case 126: /* groupby_opt ::= */ yytestcase(yyruleno==126); |
| 136969 | | - case 203: /* exprlist ::= */ yytestcase(yyruleno==203); |
| 136970 | | - case 206: /* paren_exprlist ::= */ yytestcase(yyruleno==206); |
| 136971 | | - case 211: /* eidlist_opt ::= */ yytestcase(yyruleno==211); |
| 137490 | + case 202: /* exprlist ::= */ yytestcase(yyruleno==202); |
| 137491 | + case 205: /* paren_exprlist ::= */ yytestcase(yyruleno==205); |
| 137492 | + case 210: /* eidlist_opt ::= */ yytestcase(yyruleno==210); |
| 136972 | 137493 | {yymsp[1].minor.yy148 = 0;} |
| 136973 | 137494 | break; |
| 136974 | 137495 | case 92: /* selcollist ::= sclp expr as */ |
| 136975 | 137496 | { |
| 136976 | 137497 | yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy148, yymsp[-1].minor.yy190.pExpr); |
| | @@ -136992,12 +137513,12 @@ |
| 136992 | 137513 | yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot); |
| 136993 | 137514 | } |
| 136994 | 137515 | break; |
| 136995 | 137516 | case 95: /* as ::= AS nm */ |
| 136996 | 137517 | case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106); |
| 136997 | | - case 225: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==225); |
| 136998 | | - case 226: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==226); |
| 137518 | + case 224: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==224); |
| 137519 | + case 225: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==225); |
| 136999 | 137520 | {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;} |
| 137000 | 137521 | break; |
| 137001 | 137522 | case 97: /* from ::= */ |
| 137002 | 137523 | {yymsp[1].minor.yy185 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy185));} |
| 137003 | 137524 | break; |
| | @@ -137076,18 +137597,18 @@ |
| 137076 | 137597 | {yymsp[-3].minor.yy194 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/} |
| 137077 | 137598 | break; |
| 137078 | 137599 | case 112: /* on_opt ::= ON expr */ |
| 137079 | 137600 | case 129: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==129); |
| 137080 | 137601 | case 136: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==136); |
| 137081 | | - case 199: /* case_else ::= ELSE expr */ yytestcase(yyruleno==199); |
| 137602 | + case 198: /* case_else ::= ELSE expr */ yytestcase(yyruleno==198); |
| 137082 | 137603 | {yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr;} |
| 137083 | 137604 | break; |
| 137084 | 137605 | case 113: /* on_opt ::= */ |
| 137085 | 137606 | case 128: /* having_opt ::= */ yytestcase(yyruleno==128); |
| 137086 | 137607 | case 135: /* where_opt ::= */ yytestcase(yyruleno==135); |
| 137087 | | - case 200: /* case_else ::= */ yytestcase(yyruleno==200); |
| 137088 | | - case 202: /* case_operand ::= */ yytestcase(yyruleno==202); |
| 137608 | + case 199: /* case_else ::= */ yytestcase(yyruleno==199); |
| 137609 | + case 201: /* case_operand ::= */ yytestcase(yyruleno==201); |
| 137089 | 137610 | {yymsp[1].minor.yy72 = 0;} |
| 137090 | 137611 | break; |
| 137091 | 137612 | case 115: /* indexed_opt ::= INDEXED BY nm */ |
| 137092 | 137613 | {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;} |
| 137093 | 137614 | break; |
| | @@ -137230,11 +137751,11 @@ |
| 137230 | 137751 | case 158: /* term ::= INTEGER */ |
| 137231 | 137752 | { |
| 137232 | 137753 | yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); |
| 137233 | 137754 | yylhsminor.yy190.zStart = yymsp[0].minor.yy0.z; |
| 137234 | 137755 | yylhsminor.yy190.zEnd = yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n; |
| 137235 | | - if( yylhsminor.yy190.pExpr ) yylhsminor.yy190.pExpr->flags |= EP_Leaf; |
| 137756 | + if( yylhsminor.yy190.pExpr ) yylhsminor.yy190.pExpr->flags |= EP_Leaf|EP_Resolved; |
| 137236 | 137757 | } |
| 137237 | 137758 | yymsp[0].minor.yy190 = yylhsminor.yy190; |
| 137238 | 137759 | break; |
| 137239 | 137760 | case 159: /* expr ::= VARIABLE */ |
| 137240 | 137761 | { |
| | @@ -137320,17 +137841,14 @@ |
| 137320 | 137841 | case 171: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==171); |
| 137321 | 137842 | case 172: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==172); |
| 137322 | 137843 | case 173: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==173); |
| 137323 | 137844 | {spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190);} |
| 137324 | 137845 | break; |
| 137325 | | - case 174: /* likeop ::= LIKE_KW|MATCH */ |
| 137326 | | -{yymsp[0].minor.yy0=yymsp[0].minor.yy0;/*A-overwrites-X*/} |
| 137327 | | - break; |
| 137328 | | - case 175: /* likeop ::= NOT LIKE_KW|MATCH */ |
| 137846 | + case 174: /* likeop ::= NOT LIKE_KW|MATCH */ |
| 137329 | 137847 | {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/} |
| 137330 | 137848 | break; |
| 137331 | | - case 176: /* expr ::= expr likeop expr */ |
| 137849 | + case 175: /* expr ::= expr likeop expr */ |
| 137332 | 137850 | { |
| 137333 | 137851 | ExprList *pList; |
| 137334 | 137852 | int bNot = yymsp[-1].minor.yy0.n & 0x80000000; |
| 137335 | 137853 | yymsp[-1].minor.yy0.n &= 0x7fffffff; |
| 137336 | 137854 | pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy190.pExpr); |
| | @@ -137339,11 +137857,11 @@ |
| 137339 | 137857 | exprNot(pParse, bNot, &yymsp[-2].minor.yy190); |
| 137340 | 137858 | yymsp[-2].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd; |
| 137341 | 137859 | if( yymsp[-2].minor.yy190.pExpr ) yymsp[-2].minor.yy190.pExpr->flags |= EP_InfixFunc; |
| 137342 | 137860 | } |
| 137343 | 137861 | break; |
| 137344 | | - case 177: /* expr ::= expr likeop expr ESCAPE expr */ |
| 137862 | + case 176: /* expr ::= expr likeop expr ESCAPE expr */ |
| 137345 | 137863 | { |
| 137346 | 137864 | ExprList *pList; |
| 137347 | 137865 | int bNot = yymsp[-3].minor.yy0.n & 0x80000000; |
| 137348 | 137866 | yymsp[-3].minor.yy0.n &= 0x7fffffff; |
| 137349 | 137867 | pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr); |
| | @@ -137353,43 +137871,43 @@ |
| 137353 | 137871 | exprNot(pParse, bNot, &yymsp[-4].minor.yy190); |
| 137354 | 137872 | yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd; |
| 137355 | 137873 | if( yymsp[-4].minor.yy190.pExpr ) yymsp[-4].minor.yy190.pExpr->flags |= EP_InfixFunc; |
| 137356 | 137874 | } |
| 137357 | 137875 | break; |
| 137358 | | - case 178: /* expr ::= expr ISNULL|NOTNULL */ |
| 137876 | + case 177: /* expr ::= expr ISNULL|NOTNULL */ |
| 137359 | 137877 | {spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy190,&yymsp[0].minor.yy0);} |
| 137360 | 137878 | break; |
| 137361 | | - case 179: /* expr ::= expr NOT NULL */ |
| 137879 | + case 178: /* expr ::= expr NOT NULL */ |
| 137362 | 137880 | {spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy0);} |
| 137363 | 137881 | break; |
| 137364 | | - case 180: /* expr ::= expr IS expr */ |
| 137882 | + case 179: /* expr ::= expr IS expr */ |
| 137365 | 137883 | { |
| 137366 | 137884 | spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy190,&yymsp[0].minor.yy190); |
| 137367 | 137885 | binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-2].minor.yy190.pExpr, TK_ISNULL); |
| 137368 | 137886 | } |
| 137369 | 137887 | break; |
| 137370 | | - case 181: /* expr ::= expr IS NOT expr */ |
| 137888 | + case 180: /* expr ::= expr IS NOT expr */ |
| 137371 | 137889 | { |
| 137372 | 137890 | spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy190,&yymsp[0].minor.yy190); |
| 137373 | 137891 | binaryToUnaryIfNull(pParse, yymsp[0].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, TK_NOTNULL); |
| 137374 | 137892 | } |
| 137375 | 137893 | break; |
| 137376 | | - case 182: /* expr ::= NOT expr */ |
| 137377 | | - case 183: /* expr ::= BITNOT expr */ yytestcase(yyruleno==183); |
| 137894 | + case 181: /* expr ::= NOT expr */ |
| 137895 | + case 182: /* expr ::= BITNOT expr */ yytestcase(yyruleno==182); |
| 137378 | 137896 | {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,yymsp[-1].major,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} |
| 137379 | 137897 | break; |
| 137380 | | - case 184: /* expr ::= MINUS expr */ |
| 137898 | + case 183: /* expr ::= MINUS expr */ |
| 137381 | 137899 | {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UMINUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} |
| 137382 | 137900 | break; |
| 137383 | | - case 185: /* expr ::= PLUS expr */ |
| 137901 | + case 184: /* expr ::= PLUS expr */ |
| 137384 | 137902 | {spanUnaryPrefix(&yymsp[-1].minor.yy190,pParse,TK_UPLUS,&yymsp[0].minor.yy190,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} |
| 137385 | 137903 | break; |
| 137386 | | - case 186: /* between_op ::= BETWEEN */ |
| 137387 | | - case 189: /* in_op ::= IN */ yytestcase(yyruleno==189); |
| 137904 | + case 185: /* between_op ::= BETWEEN */ |
| 137905 | + case 188: /* in_op ::= IN */ yytestcase(yyruleno==188); |
| 137388 | 137906 | {yymsp[0].minor.yy194 = 0;} |
| 137389 | 137907 | break; |
| 137390 | | - case 188: /* expr ::= expr between_op expr AND expr */ |
| 137908 | + case 187: /* expr ::= expr between_op expr AND expr */ |
| 137391 | 137909 | { |
| 137392 | 137910 | ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr); |
| 137393 | 137911 | pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr); |
| 137394 | 137912 | yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0); |
| 137395 | 137913 | if( yymsp[-4].minor.yy190.pExpr ){ |
| | @@ -137399,11 +137917,11 @@ |
| 137399 | 137917 | } |
| 137400 | 137918 | exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); |
| 137401 | 137919 | yymsp[-4].minor.yy190.zEnd = yymsp[0].minor.yy190.zEnd; |
| 137402 | 137920 | } |
| 137403 | 137921 | break; |
| 137404 | | - case 191: /* expr ::= expr in_op LP exprlist RP */ |
| 137922 | + case 190: /* expr ::= expr in_op LP exprlist RP */ |
| 137405 | 137923 | { |
| 137406 | 137924 | if( yymsp[-1].minor.yy148==0 ){ |
| 137407 | 137925 | /* Expressions of the form |
| 137408 | 137926 | ** |
| 137409 | 137927 | ** expr1 IN () |
| | @@ -137452,26 +137970,26 @@ |
| 137452 | 137970 | exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); |
| 137453 | 137971 | } |
| 137454 | 137972 | yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 137455 | 137973 | } |
| 137456 | 137974 | break; |
| 137457 | | - case 192: /* expr ::= LP select RP */ |
| 137975 | + case 191: /* expr ::= LP select RP */ |
| 137458 | 137976 | { |
| 137459 | 137977 | spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ |
| 137460 | 137978 | yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0); |
| 137461 | 137979 | sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243); |
| 137462 | 137980 | } |
| 137463 | 137981 | break; |
| 137464 | | - case 193: /* expr ::= expr in_op LP select RP */ |
| 137982 | + case 192: /* expr ::= expr in_op LP select RP */ |
| 137465 | 137983 | { |
| 137466 | 137984 | yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); |
| 137467 | 137985 | sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243); |
| 137468 | 137986 | exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); |
| 137469 | 137987 | yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 137470 | 137988 | } |
| 137471 | 137989 | break; |
| 137472 | | - case 194: /* expr ::= expr in_op nm dbnm paren_exprlist */ |
| 137990 | + case 193: /* expr ::= expr in_op nm dbnm paren_exprlist */ |
| 137473 | 137991 | { |
| 137474 | 137992 | SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); |
| 137475 | 137993 | Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); |
| 137476 | 137994 | if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148); |
| 137477 | 137995 | yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); |
| | @@ -137478,19 +137996,19 @@ |
| 137478 | 137996 | sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect); |
| 137479 | 137997 | exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); |
| 137480 | 137998 | yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n]; |
| 137481 | 137999 | } |
| 137482 | 138000 | break; |
| 137483 | | - case 195: /* expr ::= EXISTS LP select RP */ |
| 138001 | + case 194: /* expr ::= EXISTS LP select RP */ |
| 137484 | 138002 | { |
| 137485 | 138003 | Expr *p; |
| 137486 | 138004 | spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ |
| 137487 | 138005 | p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); |
| 137488 | 138006 | sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243); |
| 137489 | 138007 | } |
| 137490 | 138008 | break; |
| 137491 | | - case 196: /* expr ::= CASE case_operand case_exprlist case_else END */ |
| 138009 | + case 195: /* expr ::= CASE case_operand case_exprlist case_else END */ |
| 137492 | 138010 | { |
| 137493 | 138011 | spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/ |
| 137494 | 138012 | yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0); |
| 137495 | 138013 | if( yymsp[-4].minor.yy190.pExpr ){ |
| 137496 | 138014 | yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148; |
| | @@ -137499,313 +138017,314 @@ |
| 137499 | 138017 | sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148); |
| 137500 | 138018 | sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy72); |
| 137501 | 138019 | } |
| 137502 | 138020 | } |
| 137503 | 138021 | break; |
| 137504 | | - case 197: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ |
| 138022 | + case 196: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ |
| 137505 | 138023 | { |
| 137506 | 138024 | yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[-2].minor.yy190.pExpr); |
| 137507 | 138025 | yymsp[-4].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy148, yymsp[0].minor.yy190.pExpr); |
| 137508 | 138026 | } |
| 137509 | 138027 | break; |
| 137510 | | - case 198: /* case_exprlist ::= WHEN expr THEN expr */ |
| 138028 | + case 197: /* case_exprlist ::= WHEN expr THEN expr */ |
| 137511 | 138029 | { |
| 137512 | 138030 | yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr); |
| 137513 | 138031 | yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, yymsp[0].minor.yy190.pExpr); |
| 137514 | 138032 | } |
| 137515 | 138033 | break; |
| 137516 | | - case 201: /* case_operand ::= expr */ |
| 138034 | + case 200: /* case_operand ::= expr */ |
| 137517 | 138035 | {yymsp[0].minor.yy72 = yymsp[0].minor.yy190.pExpr; /*A-overwrites-X*/} |
| 137518 | 138036 | break; |
| 137519 | | - case 204: /* nexprlist ::= nexprlist COMMA expr */ |
| 138037 | + case 203: /* nexprlist ::= nexprlist COMMA expr */ |
| 137520 | 138038 | {yymsp[-2].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[0].minor.yy190.pExpr);} |
| 137521 | 138039 | break; |
| 137522 | | - case 205: /* nexprlist ::= expr */ |
| 138040 | + case 204: /* nexprlist ::= expr */ |
| 137523 | 138041 | {yymsp[0].minor.yy148 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy190.pExpr); /*A-overwrites-Y*/} |
| 137524 | 138042 | break; |
| 137525 | | - case 207: /* paren_exprlist ::= LP exprlist RP */ |
| 137526 | | - case 212: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==212); |
| 138043 | + case 206: /* paren_exprlist ::= LP exprlist RP */ |
| 138044 | + case 211: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==211); |
| 137527 | 138045 | {yymsp[-2].minor.yy148 = yymsp[-1].minor.yy148;} |
| 137528 | 138046 | break; |
| 137529 | | - case 208: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ |
| 138047 | + case 207: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */ |
| 137530 | 138048 | { |
| 137531 | 138049 | sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, |
| 137532 | 138050 | sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy148, yymsp[-10].minor.yy194, |
| 137533 | 138051 | &yymsp[-11].minor.yy0, yymsp[0].minor.yy72, SQLITE_SO_ASC, yymsp[-8].minor.yy194, SQLITE_IDXTYPE_APPDEF); |
| 137534 | 138052 | } |
| 137535 | 138053 | break; |
| 137536 | | - case 209: /* uniqueflag ::= UNIQUE */ |
| 137537 | | - case 250: /* raisetype ::= ABORT */ yytestcase(yyruleno==250); |
| 138054 | + case 208: /* uniqueflag ::= UNIQUE */ |
| 138055 | + case 249: /* raisetype ::= ABORT */ yytestcase(yyruleno==249); |
| 137538 | 138056 | {yymsp[0].minor.yy194 = OE_Abort;} |
| 137539 | 138057 | break; |
| 137540 | | - case 210: /* uniqueflag ::= */ |
| 138058 | + case 209: /* uniqueflag ::= */ |
| 137541 | 138059 | {yymsp[1].minor.yy194 = OE_None;} |
| 137542 | 138060 | break; |
| 137543 | | - case 213: /* eidlist ::= eidlist COMMA nm collate sortorder */ |
| 138061 | + case 212: /* eidlist ::= eidlist COMMA nm collate sortorder */ |
| 137544 | 138062 | { |
| 137545 | 138063 | yymsp[-4].minor.yy148 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy148, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); |
| 137546 | 138064 | } |
| 137547 | 138065 | break; |
| 137548 | | - case 214: /* eidlist ::= nm collate sortorder */ |
| 138066 | + case 213: /* eidlist ::= nm collate sortorder */ |
| 137549 | 138067 | { |
| 137550 | 138068 | yymsp[-2].minor.yy148 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy194, yymsp[0].minor.yy194); /*A-overwrites-Y*/ |
| 137551 | 138069 | } |
| 137552 | 138070 | break; |
| 137553 | | - case 217: /* cmd ::= DROP INDEX ifexists fullname */ |
| 138071 | + case 216: /* cmd ::= DROP INDEX ifexists fullname */ |
| 137554 | 138072 | {sqlite3DropIndex(pParse, yymsp[0].minor.yy185, yymsp[-1].minor.yy194);} |
| 137555 | 138073 | break; |
| 137556 | | - case 218: /* cmd ::= VACUUM */ |
| 138074 | + case 217: /* cmd ::= VACUUM */ |
| 137557 | 138075 | {sqlite3Vacuum(pParse,0);} |
| 137558 | 138076 | break; |
| 137559 | | - case 219: /* cmd ::= VACUUM nm */ |
| 138077 | + case 218: /* cmd ::= VACUUM nm */ |
| 137560 | 138078 | {sqlite3Vacuum(pParse,&yymsp[0].minor.yy0);} |
| 137561 | 138079 | break; |
| 137562 | | - case 220: /* cmd ::= PRAGMA nm dbnm */ |
| 138080 | + case 219: /* cmd ::= PRAGMA nm dbnm */ |
| 137563 | 138081 | {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);} |
| 137564 | 138082 | break; |
| 137565 | | - case 221: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ |
| 138083 | + case 220: /* cmd ::= PRAGMA nm dbnm EQ nmnum */ |
| 137566 | 138084 | {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);} |
| 137567 | 138085 | break; |
| 137568 | | - case 222: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ |
| 138086 | + case 221: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */ |
| 137569 | 138087 | {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);} |
| 137570 | 138088 | break; |
| 137571 | | - case 223: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ |
| 138089 | + case 222: /* cmd ::= PRAGMA nm dbnm EQ minus_num */ |
| 137572 | 138090 | {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);} |
| 137573 | 138091 | break; |
| 137574 | | - case 224: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ |
| 138092 | + case 223: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */ |
| 137575 | 138093 | {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);} |
| 137576 | 138094 | break; |
| 137577 | | - case 227: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ |
| 138095 | + case 226: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ |
| 137578 | 138096 | { |
| 137579 | 138097 | Token all; |
| 137580 | 138098 | all.z = yymsp[-3].minor.yy0.z; |
| 137581 | 138099 | all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n; |
| 137582 | 138100 | sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy145, &all); |
| 137583 | 138101 | } |
| 137584 | 138102 | break; |
| 137585 | | - case 228: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ |
| 138103 | + case 227: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ |
| 137586 | 138104 | { |
| 137587 | 138105 | sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy194, yymsp[-4].minor.yy332.a, yymsp[-4].minor.yy332.b, yymsp[-2].minor.yy185, yymsp[0].minor.yy72, yymsp[-10].minor.yy194, yymsp[-8].minor.yy194); |
| 137588 | 138106 | yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/ |
| 137589 | 138107 | } |
| 137590 | 138108 | break; |
| 137591 | | - case 229: /* trigger_time ::= BEFORE */ |
| 138109 | + case 228: /* trigger_time ::= BEFORE */ |
| 137592 | 138110 | { yymsp[0].minor.yy194 = TK_BEFORE; } |
| 137593 | 138111 | break; |
| 137594 | | - case 230: /* trigger_time ::= AFTER */ |
| 138112 | + case 229: /* trigger_time ::= AFTER */ |
| 137595 | 138113 | { yymsp[0].minor.yy194 = TK_AFTER; } |
| 137596 | 138114 | break; |
| 137597 | | - case 231: /* trigger_time ::= INSTEAD OF */ |
| 138115 | + case 230: /* trigger_time ::= INSTEAD OF */ |
| 137598 | 138116 | { yymsp[-1].minor.yy194 = TK_INSTEAD;} |
| 137599 | 138117 | break; |
| 137600 | | - case 232: /* trigger_time ::= */ |
| 138118 | + case 231: /* trigger_time ::= */ |
| 137601 | 138119 | { yymsp[1].minor.yy194 = TK_BEFORE; } |
| 137602 | 138120 | break; |
| 137603 | | - case 233: /* trigger_event ::= DELETE|INSERT */ |
| 137604 | | - case 234: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==234); |
| 138121 | + case 232: /* trigger_event ::= DELETE|INSERT */ |
| 138122 | + case 233: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==233); |
| 137605 | 138123 | {yymsp[0].minor.yy332.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy332.b = 0;} |
| 137606 | 138124 | break; |
| 137607 | | - case 235: /* trigger_event ::= UPDATE OF idlist */ |
| 138125 | + case 234: /* trigger_event ::= UPDATE OF idlist */ |
| 137608 | 138126 | {yymsp[-2].minor.yy332.a = TK_UPDATE; yymsp[-2].minor.yy332.b = yymsp[0].minor.yy254;} |
| 137609 | 138127 | break; |
| 137610 | | - case 236: /* when_clause ::= */ |
| 137611 | | - case 255: /* key_opt ::= */ yytestcase(yyruleno==255); |
| 138128 | + case 235: /* when_clause ::= */ |
| 138129 | + case 254: /* key_opt ::= */ yytestcase(yyruleno==254); |
| 137612 | 138130 | { yymsp[1].minor.yy72 = 0; } |
| 137613 | 138131 | break; |
| 137614 | | - case 237: /* when_clause ::= WHEN expr */ |
| 137615 | | - case 256: /* key_opt ::= KEY expr */ yytestcase(yyruleno==256); |
| 138132 | + case 236: /* when_clause ::= WHEN expr */ |
| 138133 | + case 255: /* key_opt ::= KEY expr */ yytestcase(yyruleno==255); |
| 137616 | 138134 | { yymsp[-1].minor.yy72 = yymsp[0].minor.yy190.pExpr; } |
| 137617 | 138135 | break; |
| 137618 | | - case 238: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ |
| 138136 | + case 237: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ |
| 137619 | 138137 | { |
| 137620 | 138138 | assert( yymsp[-2].minor.yy145!=0 ); |
| 137621 | 138139 | yymsp[-2].minor.yy145->pLast->pNext = yymsp[-1].minor.yy145; |
| 137622 | 138140 | yymsp[-2].minor.yy145->pLast = yymsp[-1].minor.yy145; |
| 137623 | 138141 | } |
| 137624 | 138142 | break; |
| 137625 | | - case 239: /* trigger_cmd_list ::= trigger_cmd SEMI */ |
| 138143 | + case 238: /* trigger_cmd_list ::= trigger_cmd SEMI */ |
| 137626 | 138144 | { |
| 137627 | 138145 | assert( yymsp[-1].minor.yy145!=0 ); |
| 137628 | 138146 | yymsp[-1].minor.yy145->pLast = yymsp[-1].minor.yy145; |
| 137629 | 138147 | } |
| 137630 | 138148 | break; |
| 137631 | | - case 240: /* trnm ::= nm DOT nm */ |
| 138149 | + case 239: /* trnm ::= nm DOT nm */ |
| 137632 | 138150 | { |
| 137633 | 138151 | yymsp[-2].minor.yy0 = yymsp[0].minor.yy0; |
| 137634 | 138152 | sqlite3ErrorMsg(pParse, |
| 137635 | 138153 | "qualified table names are not allowed on INSERT, UPDATE, and DELETE " |
| 137636 | 138154 | "statements within triggers"); |
| 137637 | 138155 | } |
| 137638 | 138156 | break; |
| 137639 | | - case 241: /* tridxby ::= INDEXED BY nm */ |
| 138157 | + case 240: /* tridxby ::= INDEXED BY nm */ |
| 137640 | 138158 | { |
| 137641 | 138159 | sqlite3ErrorMsg(pParse, |
| 137642 | 138160 | "the INDEXED BY clause is not allowed on UPDATE or DELETE statements " |
| 137643 | 138161 | "within triggers"); |
| 137644 | 138162 | } |
| 137645 | 138163 | break; |
| 137646 | | - case 242: /* tridxby ::= NOT INDEXED */ |
| 138164 | + case 241: /* tridxby ::= NOT INDEXED */ |
| 137647 | 138165 | { |
| 137648 | 138166 | sqlite3ErrorMsg(pParse, |
| 137649 | 138167 | "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements " |
| 137650 | 138168 | "within triggers"); |
| 137651 | 138169 | } |
| 137652 | 138170 | break; |
| 137653 | | - case 243: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */ |
| 138171 | + case 242: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */ |
| 137654 | 138172 | {yymsp[-6].minor.yy145 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy148, yymsp[0].minor.yy72, yymsp[-5].minor.yy194);} |
| 137655 | 138173 | break; |
| 137656 | | - case 244: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */ |
| 138174 | + case 243: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */ |
| 137657 | 138175 | {yymsp[-4].minor.yy145 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy254, yymsp[0].minor.yy243, yymsp[-4].minor.yy194);/*A-overwrites-R*/} |
| 137658 | 138176 | break; |
| 137659 | | - case 245: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */ |
| 138177 | + case 244: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */ |
| 137660 | 138178 | {yymsp[-4].minor.yy145 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy72);} |
| 137661 | 138179 | break; |
| 137662 | | - case 246: /* trigger_cmd ::= select */ |
| 138180 | + case 245: /* trigger_cmd ::= select */ |
| 137663 | 138181 | {yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/} |
| 137664 | 138182 | break; |
| 137665 | | - case 247: /* expr ::= RAISE LP IGNORE RP */ |
| 138183 | + case 246: /* expr ::= RAISE LP IGNORE RP */ |
| 137666 | 138184 | { |
| 137667 | 138185 | spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ |
| 137668 | 138186 | yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0); |
| 137669 | 138187 | if( yymsp[-3].minor.yy190.pExpr ){ |
| 137670 | 138188 | yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore; |
| 137671 | 138189 | } |
| 137672 | 138190 | } |
| 137673 | 138191 | break; |
| 137674 | | - case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */ |
| 138192 | + case 247: /* expr ::= RAISE LP raisetype COMMA nm RP */ |
| 137675 | 138193 | { |
| 137676 | 138194 | spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ |
| 137677 | 138195 | yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); |
| 137678 | 138196 | if( yymsp[-5].minor.yy190.pExpr ) { |
| 137679 | 138197 | yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194; |
| 137680 | 138198 | } |
| 137681 | 138199 | } |
| 137682 | 138200 | break; |
| 137683 | | - case 249: /* raisetype ::= ROLLBACK */ |
| 138201 | + case 248: /* raisetype ::= ROLLBACK */ |
| 137684 | 138202 | {yymsp[0].minor.yy194 = OE_Rollback;} |
| 137685 | 138203 | break; |
| 137686 | | - case 251: /* raisetype ::= FAIL */ |
| 138204 | + case 250: /* raisetype ::= FAIL */ |
| 137687 | 138205 | {yymsp[0].minor.yy194 = OE_Fail;} |
| 137688 | 138206 | break; |
| 137689 | | - case 252: /* cmd ::= DROP TRIGGER ifexists fullname */ |
| 138207 | + case 251: /* cmd ::= DROP TRIGGER ifexists fullname */ |
| 137690 | 138208 | { |
| 137691 | 138209 | sqlite3DropTrigger(pParse,yymsp[0].minor.yy185,yymsp[-1].minor.yy194); |
| 137692 | 138210 | } |
| 137693 | 138211 | break; |
| 137694 | | - case 253: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ |
| 138212 | + case 252: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */ |
| 137695 | 138213 | { |
| 137696 | 138214 | sqlite3Attach(pParse, yymsp[-3].minor.yy190.pExpr, yymsp[-1].minor.yy190.pExpr, yymsp[0].minor.yy72); |
| 137697 | 138215 | } |
| 137698 | 138216 | break; |
| 137699 | | - case 254: /* cmd ::= DETACH database_kw_opt expr */ |
| 138217 | + case 253: /* cmd ::= DETACH database_kw_opt expr */ |
| 137700 | 138218 | { |
| 137701 | 138219 | sqlite3Detach(pParse, yymsp[0].minor.yy190.pExpr); |
| 137702 | 138220 | } |
| 137703 | 138221 | break; |
| 137704 | | - case 257: /* cmd ::= REINDEX */ |
| 138222 | + case 256: /* cmd ::= REINDEX */ |
| 137705 | 138223 | {sqlite3Reindex(pParse, 0, 0);} |
| 137706 | 138224 | break; |
| 137707 | | - case 258: /* cmd ::= REINDEX nm dbnm */ |
| 138225 | + case 257: /* cmd ::= REINDEX nm dbnm */ |
| 137708 | 138226 | {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} |
| 137709 | 138227 | break; |
| 137710 | | - case 259: /* cmd ::= ANALYZE */ |
| 138228 | + case 258: /* cmd ::= ANALYZE */ |
| 137711 | 138229 | {sqlite3Analyze(pParse, 0, 0);} |
| 137712 | 138230 | break; |
| 137713 | | - case 260: /* cmd ::= ANALYZE nm dbnm */ |
| 138231 | + case 259: /* cmd ::= ANALYZE nm dbnm */ |
| 137714 | 138232 | {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);} |
| 137715 | 138233 | break; |
| 137716 | | - case 261: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ |
| 138234 | + case 260: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ |
| 137717 | 138235 | { |
| 137718 | 138236 | sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy185,&yymsp[0].minor.yy0); |
| 137719 | 138237 | } |
| 137720 | 138238 | break; |
| 137721 | | - case 262: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ |
| 138239 | + case 261: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */ |
| 137722 | 138240 | { |
| 137723 | 138241 | yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n; |
| 137724 | 138242 | sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0); |
| 137725 | 138243 | } |
| 137726 | 138244 | break; |
| 137727 | | - case 263: /* add_column_fullname ::= fullname */ |
| 138245 | + case 262: /* add_column_fullname ::= fullname */ |
| 137728 | 138246 | { |
| 137729 | 138247 | disableLookaside(pParse); |
| 137730 | 138248 | sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy185); |
| 137731 | 138249 | } |
| 137732 | 138250 | break; |
| 137733 | | - case 264: /* cmd ::= create_vtab */ |
| 138251 | + case 263: /* cmd ::= create_vtab */ |
| 137734 | 138252 | {sqlite3VtabFinishParse(pParse,0);} |
| 137735 | 138253 | break; |
| 137736 | | - case 265: /* cmd ::= create_vtab LP vtabarglist RP */ |
| 138254 | + case 264: /* cmd ::= create_vtab LP vtabarglist RP */ |
| 137737 | 138255 | {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);} |
| 137738 | 138256 | break; |
| 137739 | | - case 266: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ |
| 138257 | + case 265: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */ |
| 137740 | 138258 | { |
| 137741 | 138259 | sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy194); |
| 137742 | 138260 | } |
| 137743 | 138261 | break; |
| 137744 | | - case 267: /* vtabarg ::= */ |
| 138262 | + case 266: /* vtabarg ::= */ |
| 137745 | 138263 | {sqlite3VtabArgInit(pParse);} |
| 137746 | 138264 | break; |
| 137747 | | - case 268: /* vtabargtoken ::= ANY */ |
| 137748 | | - case 269: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==269); |
| 137749 | | - case 270: /* lp ::= LP */ yytestcase(yyruleno==270); |
| 138265 | + case 267: /* vtabargtoken ::= ANY */ |
| 138266 | + case 268: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==268); |
| 138267 | + case 269: /* lp ::= LP */ yytestcase(yyruleno==269); |
| 137750 | 138268 | {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);} |
| 137751 | 138269 | break; |
| 137752 | | - case 271: /* with ::= */ |
| 138270 | + case 270: /* with ::= */ |
| 137753 | 138271 | {yymsp[1].minor.yy285 = 0;} |
| 137754 | 138272 | break; |
| 137755 | | - case 272: /* with ::= WITH wqlist */ |
| 138273 | + case 271: /* with ::= WITH wqlist */ |
| 137756 | 138274 | { yymsp[-1].minor.yy285 = yymsp[0].minor.yy285; } |
| 137757 | 138275 | break; |
| 137758 | | - case 273: /* with ::= WITH RECURSIVE wqlist */ |
| 138276 | + case 272: /* with ::= WITH RECURSIVE wqlist */ |
| 137759 | 138277 | { yymsp[-2].minor.yy285 = yymsp[0].minor.yy285; } |
| 137760 | 138278 | break; |
| 137761 | | - case 274: /* wqlist ::= nm eidlist_opt AS LP select RP */ |
| 138279 | + case 273: /* wqlist ::= nm eidlist_opt AS LP select RP */ |
| 137762 | 138280 | { |
| 137763 | 138281 | yymsp[-5].minor.yy285 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); /*A-overwrites-X*/ |
| 137764 | 138282 | } |
| 137765 | 138283 | break; |
| 137766 | | - case 275: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */ |
| 138284 | + case 274: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */ |
| 137767 | 138285 | { |
| 137768 | 138286 | yymsp[-7].minor.yy285 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy285, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy148, yymsp[-1].minor.yy243); |
| 137769 | 138287 | } |
| 137770 | 138288 | break; |
| 137771 | 138289 | default: |
| 137772 | | - /* (276) input ::= cmdlist */ yytestcase(yyruleno==276); |
| 137773 | | - /* (277) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==277); |
| 137774 | | - /* (278) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=278); |
| 137775 | | - /* (279) ecmd ::= SEMI */ yytestcase(yyruleno==279); |
| 137776 | | - /* (280) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==280); |
| 137777 | | - /* (281) explain ::= */ yytestcase(yyruleno==281); |
| 137778 | | - /* (282) trans_opt ::= */ yytestcase(yyruleno==282); |
| 137779 | | - /* (283) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==283); |
| 137780 | | - /* (284) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==284); |
| 137781 | | - /* (285) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==285); |
| 137782 | | - /* (286) savepoint_opt ::= */ yytestcase(yyruleno==286); |
| 137783 | | - /* (287) cmd ::= create_table create_table_args */ yytestcase(yyruleno==287); |
| 137784 | | - /* (288) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==288); |
| 137785 | | - /* (289) columnlist ::= columnname carglist */ yytestcase(yyruleno==289); |
| 137786 | | - /* (290) nm ::= ID|INDEXED */ yytestcase(yyruleno==290); |
| 137787 | | - /* (291) nm ::= STRING */ yytestcase(yyruleno==291); |
| 137788 | | - /* (292) nm ::= JOIN_KW */ yytestcase(yyruleno==292); |
| 137789 | | - /* (293) typetoken ::= typename */ yytestcase(yyruleno==293); |
| 137790 | | - /* (294) typename ::= ID|STRING */ yytestcase(yyruleno==294); |
| 137791 | | - /* (295) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=295); |
| 137792 | | - /* (296) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=296); |
| 137793 | | - /* (297) carglist ::= carglist ccons */ yytestcase(yyruleno==297); |
| 137794 | | - /* (298) carglist ::= */ yytestcase(yyruleno==298); |
| 137795 | | - /* (299) ccons ::= NULL onconf */ yytestcase(yyruleno==299); |
| 137796 | | - /* (300) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==300); |
| 137797 | | - /* (301) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==301); |
| 137798 | | - /* (302) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=302); |
| 137799 | | - /* (303) tconscomma ::= */ yytestcase(yyruleno==303); |
| 137800 | | - /* (304) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=304); |
| 137801 | | - /* (305) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=305); |
| 137802 | | - /* (306) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=306); |
| 137803 | | - /* (307) oneselect ::= values */ yytestcase(yyruleno==307); |
| 137804 | | - /* (308) sclp ::= selcollist COMMA */ yytestcase(yyruleno==308); |
| 137805 | | - /* (309) as ::= ID|STRING */ yytestcase(yyruleno==309); |
| 137806 | | - /* (310) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=310); |
| 138290 | + /* (275) input ::= cmdlist */ yytestcase(yyruleno==275); |
| 138291 | + /* (276) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==276); |
| 138292 | + /* (277) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=277); |
| 138293 | + /* (278) ecmd ::= SEMI */ yytestcase(yyruleno==278); |
| 138294 | + /* (279) ecmd ::= explain cmdx SEMI */ yytestcase(yyruleno==279); |
| 138295 | + /* (280) explain ::= */ yytestcase(yyruleno==280); |
| 138296 | + /* (281) trans_opt ::= */ yytestcase(yyruleno==281); |
| 138297 | + /* (282) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==282); |
| 138298 | + /* (283) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==283); |
| 138299 | + /* (284) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==284); |
| 138300 | + /* (285) savepoint_opt ::= */ yytestcase(yyruleno==285); |
| 138301 | + /* (286) cmd ::= create_table create_table_args */ yytestcase(yyruleno==286); |
| 138302 | + /* (287) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==287); |
| 138303 | + /* (288) columnlist ::= columnname carglist */ yytestcase(yyruleno==288); |
| 138304 | + /* (289) nm ::= ID|INDEXED */ yytestcase(yyruleno==289); |
| 138305 | + /* (290) nm ::= STRING */ yytestcase(yyruleno==290); |
| 138306 | + /* (291) nm ::= JOIN_KW */ yytestcase(yyruleno==291); |
| 138307 | + /* (292) typetoken ::= typename */ yytestcase(yyruleno==292); |
| 138308 | + /* (293) typename ::= ID|STRING */ yytestcase(yyruleno==293); |
| 138309 | + /* (294) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=294); |
| 138310 | + /* (295) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=295); |
| 138311 | + /* (296) carglist ::= carglist ccons */ yytestcase(yyruleno==296); |
| 138312 | + /* (297) carglist ::= */ yytestcase(yyruleno==297); |
| 138313 | + /* (298) ccons ::= NULL onconf */ yytestcase(yyruleno==298); |
| 138314 | + /* (299) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==299); |
| 138315 | + /* (300) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==300); |
| 138316 | + /* (301) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=301); |
| 138317 | + /* (302) tconscomma ::= */ yytestcase(yyruleno==302); |
| 138318 | + /* (303) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=303); |
| 138319 | + /* (304) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=304); |
| 138320 | + /* (305) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=305); |
| 138321 | + /* (306) oneselect ::= values */ yytestcase(yyruleno==306); |
| 138322 | + /* (307) sclp ::= selcollist COMMA */ yytestcase(yyruleno==307); |
| 138323 | + /* (308) as ::= ID|STRING */ yytestcase(yyruleno==308); |
| 138324 | + /* (309) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=309); |
| 138325 | + /* (310) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==310); |
| 137807 | 138326 | /* (311) exprlist ::= nexprlist */ yytestcase(yyruleno==311); |
| 137808 | 138327 | /* (312) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=312); |
| 137809 | 138328 | /* (313) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=313); |
| 137810 | 138329 | /* (314) nmnum ::= ON */ yytestcase(yyruleno==314); |
| 137811 | 138330 | /* (315) nmnum ::= DELETE */ yytestcase(yyruleno==315); |
| | @@ -138854,12 +139373,12 @@ |
| 138854 | 139373 | ** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that |
| 138855 | 139374 | ** error message. |
| 138856 | 139375 | */ |
| 138857 | 139376 | SQLITE_PRIVATE int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){ |
| 138858 | 139377 | int nErr = 0; /* Number of errors encountered */ |
| 138859 | | - int i; /* Loop counter */ |
| 138860 | 139378 | void *pEngine; /* The LEMON-generated LALR(1) parser */ |
| 139379 | + int n = 0; /* Length of the next token token */ |
| 138861 | 139380 | int tokenType; /* type of the next token */ |
| 138862 | 139381 | int lastTokenParsed = -1; /* type of the previous token */ |
| 138863 | 139382 | sqlite3 *db = pParse->db; /* The database connection */ |
| 138864 | 139383 | int mxSqlLen; /* Max length of an SQL string */ |
| 138865 | 139384 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| | @@ -138871,11 +139390,10 @@ |
| 138871 | 139390 | if( db->nVdbeActive==0 ){ |
| 138872 | 139391 | db->u1.isInterrupted = 0; |
| 138873 | 139392 | } |
| 138874 | 139393 | pParse->rc = SQLITE_OK; |
| 138875 | 139394 | pParse->zTail = zSql; |
| 138876 | | - i = 0; |
| 138877 | 139395 | assert( pzErrMsg!=0 ); |
| 138878 | 139396 | /* sqlite3ParserTrace(stdout, "parser: "); */ |
| 138879 | 139397 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 138880 | 139398 | pEngine = zSpace; |
| 138881 | 139399 | sqlite3ParserInit(pEngine); |
| | @@ -138889,16 +139407,14 @@ |
| 138889 | 139407 | assert( pParse->pNewTable==0 ); |
| 138890 | 139408 | assert( pParse->pNewTrigger==0 ); |
| 138891 | 139409 | assert( pParse->nVar==0 ); |
| 138892 | 139410 | assert( pParse->pVList==0 ); |
| 138893 | 139411 | while( 1 ){ |
| 138894 | | - assert( i>=0 ); |
| 138895 | | - if( zSql[i]!=0 ){ |
| 138896 | | - pParse->sLastToken.z = &zSql[i]; |
| 138897 | | - pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType); |
| 138898 | | - i += pParse->sLastToken.n; |
| 138899 | | - if( i>mxSqlLen ){ |
| 139412 | + if( zSql[0]!=0 ){ |
| 139413 | + n = sqlite3GetToken((u8*)zSql, &tokenType); |
| 139414 | + mxSqlLen -= n; |
| 139415 | + if( mxSqlLen<0 ){ |
| 138900 | 139416 | pParse->rc = SQLITE_TOOBIG; |
| 138901 | 139417 | break; |
| 138902 | 139418 | } |
| 138903 | 139419 | }else{ |
| 138904 | 139420 | /* Upon reaching the end of input, call the parser two more times |
| | @@ -138908,30 +139424,34 @@ |
| 138908 | 139424 | }else if( lastTokenParsed==0 ){ |
| 138909 | 139425 | break; |
| 138910 | 139426 | }else{ |
| 138911 | 139427 | tokenType = TK_SEMI; |
| 138912 | 139428 | } |
| 139429 | + zSql -= n; |
| 138913 | 139430 | } |
| 138914 | 139431 | if( tokenType>=TK_SPACE ){ |
| 138915 | 139432 | assert( tokenType==TK_SPACE || tokenType==TK_ILLEGAL ); |
| 138916 | 139433 | if( db->u1.isInterrupted ){ |
| 138917 | 139434 | pParse->rc = SQLITE_INTERRUPT; |
| 138918 | 139435 | break; |
| 138919 | 139436 | } |
| 138920 | 139437 | if( tokenType==TK_ILLEGAL ){ |
| 138921 | | - sqlite3ErrorMsg(pParse, "unrecognized token: \"%T\"", |
| 138922 | | - &pParse->sLastToken); |
| 139438 | + sqlite3ErrorMsg(pParse, "unrecognized token: \"%.*s\"", n, zSql); |
| 138923 | 139439 | break; |
| 138924 | 139440 | } |
| 139441 | + zSql += n; |
| 138925 | 139442 | }else{ |
| 139443 | + pParse->sLastToken.z = zSql; |
| 139444 | + pParse->sLastToken.n = n; |
| 138926 | 139445 | sqlite3Parser(pEngine, tokenType, pParse->sLastToken, pParse); |
| 138927 | 139446 | lastTokenParsed = tokenType; |
| 139447 | + zSql += n; |
| 138928 | 139448 | if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break; |
| 138929 | 139449 | } |
| 138930 | 139450 | } |
| 138931 | 139451 | assert( nErr==0 ); |
| 138932 | | - pParse->zTail = &zSql[i]; |
| 139452 | + pParse->zTail = zSql; |
| 138933 | 139453 | #ifdef YYTRACKMAXSTACKDEPTH |
| 138934 | 139454 | sqlite3_mutex_enter(sqlite3MallocMutex()); |
| 138935 | 139455 | sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK, |
| 138936 | 139456 | sqlite3ParserStackPeak(pEngine) |
| 138937 | 139457 | ); |
| | @@ -140301,10 +140821,25 @@ |
| 140301 | 140821 | return 0; |
| 140302 | 140822 | } |
| 140303 | 140823 | #endif |
| 140304 | 140824 | return db->lastRowid; |
| 140305 | 140825 | } |
| 140826 | + |
| 140827 | +/* |
| 140828 | +** Set the value returned by the sqlite3_last_insert_rowid() API function. |
| 140829 | +*/ |
| 140830 | +SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3 *db, sqlite3_int64 iRowid){ |
| 140831 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 140832 | + if( !sqlite3SafetyCheckOk(db) ){ |
| 140833 | + (void)SQLITE_MISUSE_BKPT; |
| 140834 | + return; |
| 140835 | + } |
| 140836 | +#endif |
| 140837 | + sqlite3_mutex_enter(db->mutex); |
| 140838 | + db->lastRowid = iRowid; |
| 140839 | + sqlite3_mutex_leave(db->mutex); |
| 140840 | +} |
| 140306 | 140841 | |
| 140307 | 140842 | /* |
| 140308 | 140843 | ** Return the number of changes in the most recent call to sqlite3_exec(). |
| 140309 | 140844 | */ |
| 140310 | 140845 | SQLITE_API int sqlite3_changes(sqlite3 *db){ |
| | @@ -145052,12 +145587,13 @@ |
| 145052 | 145587 | /* |
| 145053 | 145588 | ** Read a 64-bit variable-length integer from memory starting at p[0]. |
| 145054 | 145589 | ** Return the number of bytes read, or 0 on error. |
| 145055 | 145590 | ** The value is stored in *v. |
| 145056 | 145591 | */ |
| 145057 | | -SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *p, sqlite_int64 *v){ |
| 145058 | | - const char *pStart = p; |
| 145592 | +SQLITE_PRIVATE int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){ |
| 145593 | + const unsigned char *p = (const unsigned char*)pBuf; |
| 145594 | + const unsigned char *pStart = p; |
| 145059 | 145595 | u32 a; |
| 145060 | 145596 | u64 b; |
| 145061 | 145597 | int shift; |
| 145062 | 145598 | |
| 145063 | 145599 | GETVARINT_INIT(a, p, 0, 0x00, 0x80, *v, 1); |
| | @@ -146100,11 +146636,13 @@ |
| 146100 | 146636 | /* Fill in the azColumn array */ |
| 146101 | 146637 | for(iCol=0; iCol<nCol; iCol++){ |
| 146102 | 146638 | char *z; |
| 146103 | 146639 | int n = 0; |
| 146104 | 146640 | z = (char *)sqlite3Fts3NextToken(aCol[iCol], &n); |
| 146105 | | - memcpy(zCsr, z, n); |
| 146641 | + if( n>0 ){ |
| 146642 | + memcpy(zCsr, z, n); |
| 146643 | + } |
| 146106 | 146644 | zCsr[n] = '\0'; |
| 146107 | 146645 | sqlite3Fts3Dequote(zCsr); |
| 146108 | 146646 | p->azColumn[iCol] = zCsr; |
| 146109 | 146647 | zCsr += n+1; |
| 146110 | 146648 | assert( zCsr <= &((char *)p)[nByte] ); |
| | @@ -148111,12 +148649,14 @@ |
| 148111 | 148649 | ** segments. |
| 148112 | 148650 | */ |
| 148113 | 148651 | const u32 nMinMerge = 64; /* Minimum amount of incr-merge work to do */ |
| 148114 | 148652 | |
| 148115 | 148653 | Fts3Table *p = (Fts3Table*)pVtab; |
| 148116 | | - int rc = sqlite3Fts3PendingTermsFlush(p); |
| 148654 | + int rc; |
| 148655 | + i64 iLastRowid = sqlite3_last_insert_rowid(p->db); |
| 148117 | 148656 | |
| 148657 | + rc = sqlite3Fts3PendingTermsFlush(p); |
| 148118 | 148658 | if( rc==SQLITE_OK |
| 148119 | 148659 | && p->nLeafAdd>(nMinMerge/16) |
| 148120 | 148660 | && p->nAutoincrmerge && p->nAutoincrmerge!=0xff |
| 148121 | 148661 | ){ |
| 148122 | 148662 | int mxLevel = 0; /* Maximum relative level value in db */ |
| | @@ -148127,10 +148667,11 @@ |
| 148127 | 148667 | A = p->nLeafAdd * mxLevel; |
| 148128 | 148668 | A += (A/2); |
| 148129 | 148669 | if( A>(int)nMinMerge ) rc = sqlite3Fts3Incrmerge(p, A, p->nAutoincrmerge); |
| 148130 | 148670 | } |
| 148131 | 148671 | sqlite3Fts3SegmentsClose(p); |
| 148672 | + sqlite3_set_last_insert_rowid(p->db, iLastRowid); |
| 148132 | 148673 | return rc; |
| 148133 | 148674 | } |
| 148134 | 148675 | |
| 148135 | 148676 | /* |
| 148136 | 148677 | ** If it is currently unknown whether or not the FTS table has an %_stat |
| | @@ -159737,15 +160278,18 @@ |
| 159737 | 160278 | |
| 159738 | 160279 | /* |
| 159739 | 160280 | ** Convert the text beginning at *pz into an integer and return |
| 159740 | 160281 | ** its value. Advance *pz to point to the first character past |
| 159741 | 160282 | ** the integer. |
| 160283 | +** |
| 160284 | +** This function used for parameters to merge= and incrmerge= |
| 160285 | +** commands. |
| 159742 | 160286 | */ |
| 159743 | 160287 | static int fts3Getint(const char **pz){ |
| 159744 | 160288 | const char *z = *pz; |
| 159745 | 160289 | int i = 0; |
| 159746 | | - while( (*z)>='0' && (*z)<='9' ) i = 10*i + *(z++) - '0'; |
| 160290 | + while( (*z)>='0' && (*z)<='9' && i<214748363 ) i = 10*i + *(z++) - '0'; |
| 159747 | 160291 | *pz = z; |
| 159748 | 160292 | return i; |
| 159749 | 160293 | } |
| 159750 | 160294 | |
| 159751 | 160295 | /* |
| | @@ -162307,20 +162851,20 @@ |
| 162307 | 162851 | const char *zIn, /* Array of characters to make exceptions */ |
| 162308 | 162852 | int nIn /* Length of z in bytes */ |
| 162309 | 162853 | ){ |
| 162310 | 162854 | const unsigned char *z = (const unsigned char *)zIn; |
| 162311 | 162855 | const unsigned char *zTerm = &z[nIn]; |
| 162312 | | - int iCode; |
| 162856 | + unsigned int iCode; |
| 162313 | 162857 | int nEntry = 0; |
| 162314 | 162858 | |
| 162315 | 162859 | assert( bAlnum==0 || bAlnum==1 ); |
| 162316 | 162860 | |
| 162317 | 162861 | while( z<zTerm ){ |
| 162318 | 162862 | READ_UTF8(z, zTerm, iCode); |
| 162319 | | - assert( (sqlite3FtsUnicodeIsalnum(iCode) & 0xFFFFFFFE)==0 ); |
| 162320 | | - if( sqlite3FtsUnicodeIsalnum(iCode)!=bAlnum |
| 162321 | | - && sqlite3FtsUnicodeIsdiacritic(iCode)==0 |
| 162863 | + assert( (sqlite3FtsUnicodeIsalnum((int)iCode) & 0xFFFFFFFE)==0 ); |
| 162864 | + if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum |
| 162865 | + && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0 |
| 162322 | 162866 | ){ |
| 162323 | 162867 | nEntry++; |
| 162324 | 162868 | } |
| 162325 | 162869 | } |
| 162326 | 162870 | |
| | @@ -162333,17 +162877,17 @@ |
| 162333 | 162877 | nNew = p->nException; |
| 162334 | 162878 | |
| 162335 | 162879 | z = (const unsigned char *)zIn; |
| 162336 | 162880 | while( z<zTerm ){ |
| 162337 | 162881 | READ_UTF8(z, zTerm, iCode); |
| 162338 | | - if( sqlite3FtsUnicodeIsalnum(iCode)!=bAlnum |
| 162339 | | - && sqlite3FtsUnicodeIsdiacritic(iCode)==0 |
| 162882 | + if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum |
| 162883 | + && sqlite3FtsUnicodeIsdiacritic((int)iCode)==0 |
| 162340 | 162884 | ){ |
| 162341 | 162885 | int i, j; |
| 162342 | | - for(i=0; i<nNew && aNew[i]<iCode; i++); |
| 162886 | + for(i=0; i<nNew && aNew[i]<(int)iCode; i++); |
| 162343 | 162887 | for(j=nNew; j>i; j--) aNew[j] = aNew[j-1]; |
| 162344 | | - aNew[i] = iCode; |
| 162888 | + aNew[i] = (int)iCode; |
| 162345 | 162889 | nNew++; |
| 162346 | 162890 | } |
| 162347 | 162891 | } |
| 162348 | 162892 | p->aiException = aNew; |
| 162349 | 162893 | p->nException = nNew; |
| | @@ -162489,11 +163033,11 @@ |
| 162489 | 163033 | int *piEnd, /* OUT: Ending offset of token */ |
| 162490 | 163034 | int *piPos /* OUT: Position integer of token */ |
| 162491 | 163035 | ){ |
| 162492 | 163036 | unicode_cursor *pCsr = (unicode_cursor *)pC; |
| 162493 | 163037 | unicode_tokenizer *p = ((unicode_tokenizer *)pCsr->base.pTokenizer); |
| 162494 | | - int iCode = 0; |
| 163038 | + unsigned int iCode = 0; |
| 162495 | 163039 | char *zOut; |
| 162496 | 163040 | const unsigned char *z = &pCsr->aInput[pCsr->iOff]; |
| 162497 | 163041 | const unsigned char *zStart = z; |
| 162498 | 163042 | const unsigned char *zEnd; |
| 162499 | 163043 | const unsigned char *zTerm = &pCsr->aInput[pCsr->nInput]; |
| | @@ -162501,11 +163045,11 @@ |
| 162501 | 163045 | /* Scan past any delimiter characters before the start of the next token. |
| 162502 | 163046 | ** Return SQLITE_DONE early if this takes us all the way to the end of |
| 162503 | 163047 | ** the input. */ |
| 162504 | 163048 | while( z<zTerm ){ |
| 162505 | 163049 | READ_UTF8(z, zTerm, iCode); |
| 162506 | | - if( unicodeIsAlnum(p, iCode) ) break; |
| 163050 | + if( unicodeIsAlnum(p, (int)iCode) ) break; |
| 162507 | 163051 | zStart = z; |
| 162508 | 163052 | } |
| 162509 | 163053 | if( zStart>=zTerm ) return SQLITE_DONE; |
| 162510 | 163054 | |
| 162511 | 163055 | zOut = pCsr->zToken; |
| | @@ -162521,20 +163065,20 @@ |
| 162521 | 163065 | pCsr->nAlloc += 64; |
| 162522 | 163066 | } |
| 162523 | 163067 | |
| 162524 | 163068 | /* Write the folded case of the last character read to the output */ |
| 162525 | 163069 | zEnd = z; |
| 162526 | | - iOut = sqlite3FtsUnicodeFold(iCode, p->bRemoveDiacritic); |
| 163070 | + iOut = sqlite3FtsUnicodeFold((int)iCode, p->bRemoveDiacritic); |
| 162527 | 163071 | if( iOut ){ |
| 162528 | 163072 | WRITE_UTF8(zOut, iOut); |
| 162529 | 163073 | } |
| 162530 | 163074 | |
| 162531 | 163075 | /* If the cursor is not at EOF, read the next character */ |
| 162532 | 163076 | if( z>=zTerm ) break; |
| 162533 | 163077 | READ_UTF8(z, zTerm, iCode); |
| 162534 | | - }while( unicodeIsAlnum(p, iCode) |
| 162535 | | - || sqlite3FtsUnicodeIsdiacritic(iCode) |
| 163078 | + }while( unicodeIsAlnum(p, (int)iCode) |
| 163079 | + || sqlite3FtsUnicodeIsdiacritic((int)iCode) |
| 162536 | 163080 | ); |
| 162537 | 163081 | |
| 162538 | 163082 | /* Set the output variables and return. */ |
| 162539 | 163083 | pCsr->iOff = (int)(z - pCsr->aInput); |
| 162540 | 163084 | *paToken = pCsr->zToken; |
| | @@ -162694,13 +163238,13 @@ |
| 162694 | 163238 | }; |
| 162695 | 163239 | static const unsigned int aAscii[4] = { |
| 162696 | 163240 | 0xFFFFFFFF, 0xFC00FFFF, 0xF8000001, 0xF8000001, |
| 162697 | 163241 | }; |
| 162698 | 163242 | |
| 162699 | | - if( c<128 ){ |
| 162700 | | - return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); |
| 162701 | | - }else if( c<(1<<22) ){ |
| 163243 | + if( (unsigned int)c<128 ){ |
| 163244 | + return ( (aAscii[c >> 5] & ((unsigned int)1 << (c & 0x001F)))==0 ); |
| 163245 | + }else if( (unsigned int)c<(1<<22) ){ |
| 162702 | 163246 | unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; |
| 162703 | 163247 | int iRes = 0; |
| 162704 | 163248 | int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; |
| 162705 | 163249 | int iLo = 0; |
| 162706 | 163250 | while( iHi>=iLo ){ |
| | @@ -162889,20 +163433,21 @@ |
| 162889 | 163433 | 65514, 65521, 65527, 65528, 65529, |
| 162890 | 163434 | }; |
| 162891 | 163435 | |
| 162892 | 163436 | int ret = c; |
| 162893 | 163437 | |
| 162894 | | - assert( c>=0 ); |
| 162895 | 163438 | assert( sizeof(unsigned short)==2 && sizeof(unsigned char)==1 ); |
| 162896 | 163439 | |
| 162897 | 163440 | if( c<128 ){ |
| 162898 | 163441 | if( c>='A' && c<='Z' ) ret = c + ('a' - 'A'); |
| 162899 | 163442 | }else if( c<65536 ){ |
| 163443 | + const struct TableEntry *p; |
| 162900 | 163444 | int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; |
| 162901 | 163445 | int iLo = 0; |
| 162902 | 163446 | int iRes = -1; |
| 162903 | 163447 | |
| 163448 | + assert( c>aEntry[0].iCode ); |
| 162904 | 163449 | while( iHi>=iLo ){ |
| 162905 | 163450 | int iTest = (iHi + iLo) / 2; |
| 162906 | 163451 | int cmp = (c - aEntry[iTest].iCode); |
| 162907 | 163452 | if( cmp>=0 ){ |
| 162908 | 163453 | iRes = iTest; |
| | @@ -162909,18 +163454,16 @@ |
| 162909 | 163454 | iLo = iTest+1; |
| 162910 | 163455 | }else{ |
| 162911 | 163456 | iHi = iTest-1; |
| 162912 | 163457 | } |
| 162913 | 163458 | } |
| 162914 | | - assert( iRes<0 || c>=aEntry[iRes].iCode ); |
| 162915 | | - |
| 162916 | | - if( iRes>=0 ){ |
| 162917 | | - const struct TableEntry *p = &aEntry[iRes]; |
| 162918 | | - if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){ |
| 162919 | | - ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF; |
| 162920 | | - assert( ret>0 ); |
| 162921 | | - } |
| 163459 | + |
| 163460 | + assert( iRes>=0 && c>=aEntry[iRes].iCode ); |
| 163461 | + p = &aEntry[iRes]; |
| 163462 | + if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){ |
| 163463 | + ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF; |
| 163464 | + assert( ret>0 ); |
| 162922 | 163465 | } |
| 162923 | 163466 | |
| 162924 | 163467 | if( bRemoveDiacritic ) ret = remove_diacritic(ret); |
| 162925 | 163468 | } |
| 162926 | 163469 | |
| | @@ -163393,19 +163936,19 @@ |
| 163393 | 163936 | #elif SQLITE_BYTEORDER==4321 |
| 163394 | 163937 | i64 x; |
| 163395 | 163938 | memcpy(&x, p, 8); |
| 163396 | 163939 | return x; |
| 163397 | 163940 | #else |
| 163398 | | - return ( |
| 163399 | | - (((i64)p[0]) << 56) + |
| 163400 | | - (((i64)p[1]) << 48) + |
| 163401 | | - (((i64)p[2]) << 40) + |
| 163402 | | - (((i64)p[3]) << 32) + |
| 163403 | | - (((i64)p[4]) << 24) + |
| 163404 | | - (((i64)p[5]) << 16) + |
| 163405 | | - (((i64)p[6]) << 8) + |
| 163406 | | - (((i64)p[7]) << 0) |
| 163941 | + return (i64)( |
| 163942 | + (((u64)p[0]) << 56) + |
| 163943 | + (((u64)p[1]) << 48) + |
| 163944 | + (((u64)p[2]) << 40) + |
| 163945 | + (((u64)p[3]) << 32) + |
| 163946 | + (((u64)p[4]) << 24) + |
| 163947 | + (((u64)p[5]) << 16) + |
| 163948 | + (((u64)p[6]) << 8) + |
| 163949 | + (((u64)p[7]) << 0) |
| 163407 | 163950 | ); |
| 163408 | 163951 | #endif |
| 163409 | 163952 | } |
| 163410 | 163953 | |
| 163411 | 163954 | /* |
| | @@ -168462,10 +169005,11 @@ |
| 168462 | 169005 | int nStep; /* Rows processed for current object */ |
| 168463 | 169006 | int nProgress; /* Rows processed for all objects */ |
| 168464 | 169007 | RbuObjIter objiter; /* Iterator for skipping through tbl/idx */ |
| 168465 | 169008 | const char *zVfsName; /* Name of automatically created rbu vfs */ |
| 168466 | 169009 | rbu_file *pTargetFd; /* File handle open on target db */ |
| 169010 | + int nPagePerSector; /* Pages per sector for pTargetFd */ |
| 168467 | 169011 | i64 iOalSz; |
| 168468 | 169012 | i64 nPhaseOneStep; |
| 168469 | 169013 | |
| 168470 | 169014 | /* The following state variables are used as part of the incremental |
| 168471 | 169015 | ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding |
| | @@ -170726,10 +171270,27 @@ |
| 170726 | 171270 | |
| 170727 | 171271 | if( p->rc==SQLITE_OK ){ |
| 170728 | 171272 | if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){ |
| 170729 | 171273 | p->rc = SQLITE_DONE; |
| 170730 | 171274 | p->eStage = RBU_STAGE_DONE; |
| 171275 | + }else{ |
| 171276 | + int nSectorSize; |
| 171277 | + sqlite3_file *pDb = p->pTargetFd->pReal; |
| 171278 | + sqlite3_file *pWal = p->pTargetFd->pWalFd->pReal; |
| 171279 | + assert( p->nPagePerSector==0 ); |
| 171280 | + nSectorSize = pDb->pMethods->xSectorSize(pDb); |
| 171281 | + if( nSectorSize>p->pgsz ){ |
| 171282 | + p->nPagePerSector = nSectorSize / p->pgsz; |
| 171283 | + }else{ |
| 171284 | + p->nPagePerSector = 1; |
| 171285 | + } |
| 171286 | + |
| 171287 | + /* Call xSync() on the wal file. This causes SQLite to sync the |
| 171288 | + ** directory in which the target database and the wal file reside, in |
| 171289 | + ** case it has not been synced since the rename() call in |
| 171290 | + ** rbuMoveOalFile(). */ |
| 171291 | + p->rc = pWal->pMethods->xSync(pWal, SQLITE_SYNC_NORMAL); |
| 170731 | 171292 | } |
| 170732 | 171293 | } |
| 170733 | 171294 | } |
| 170734 | 171295 | |
| 170735 | 171296 | /* |
| | @@ -171381,13 +171942,30 @@ |
| 171381 | 171942 | if( p->rc==SQLITE_OK ){ |
| 171382 | 171943 | p->eStage = RBU_STAGE_DONE; |
| 171383 | 171944 | p->rc = SQLITE_DONE; |
| 171384 | 171945 | } |
| 171385 | 171946 | }else{ |
| 171386 | | - RbuFrame *pFrame = &p->aFrame[p->nStep]; |
| 171387 | | - rbuCheckpointFrame(p, pFrame); |
| 171388 | | - p->nStep++; |
| 171947 | + /* At one point the following block copied a single frame from the |
| 171948 | + ** wal file to the database file. So that one call to sqlite3rbu_step() |
| 171949 | + ** checkpointed a single frame. |
| 171950 | + ** |
| 171951 | + ** However, if the sector-size is larger than the page-size, and the |
| 171952 | + ** application calls sqlite3rbu_savestate() or close() immediately |
| 171953 | + ** after this step, then rbu_step() again, then a power failure occurs, |
| 171954 | + ** then the database page written here may be damaged. Work around |
| 171955 | + ** this by checkpointing frames until the next page in the aFrame[] |
| 171956 | + ** lies on a different disk sector to the current one. */ |
| 171957 | + u32 iSector; |
| 171958 | + do{ |
| 171959 | + RbuFrame *pFrame = &p->aFrame[p->nStep]; |
| 171960 | + iSector = (pFrame->iDbPage-1) / p->nPagePerSector; |
| 171961 | + rbuCheckpointFrame(p, pFrame); |
| 171962 | + p->nStep++; |
| 171963 | + }while( p->nStep<p->nFrame |
| 171964 | + && iSector==((p->aFrame[p->nStep].iDbPage-1) / p->nPagePerSector) |
| 171965 | + && p->rc==SQLITE_OK |
| 171966 | + ); |
| 171389 | 171967 | } |
| 171390 | 171968 | p->nProgress++; |
| 171391 | 171969 | } |
| 171392 | 171970 | break; |
| 171393 | 171971 | } |
| | @@ -171823,10 +172401,16 @@ |
| 171823 | 172401 | |
| 171824 | 172402 | /* Commit the transaction to the *-oal file. */ |
| 171825 | 172403 | if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){ |
| 171826 | 172404 | p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg); |
| 171827 | 172405 | } |
| 172406 | + |
| 172407 | + /* Sync the db file if currently doing an incremental checkpoint */ |
| 172408 | + if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){ |
| 172409 | + sqlite3_file *pDb = p->pTargetFd->pReal; |
| 172410 | + p->rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL); |
| 172411 | + } |
| 171828 | 172412 | |
| 171829 | 172413 | rbuSaveState(p, p->eStage); |
| 171830 | 172414 | |
| 171831 | 172415 | if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){ |
| 171832 | 172416 | p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg); |
| | @@ -171947,10 +172531,16 @@ |
| 171947 | 172531 | assert( p->eStage>=RBU_STAGE_OAL && p->eStage<=RBU_STAGE_DONE ); |
| 171948 | 172532 | if( p->eStage==RBU_STAGE_OAL ){ |
| 171949 | 172533 | assert( rc!=SQLITE_DONE ); |
| 171950 | 172534 | if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0); |
| 171951 | 172535 | } |
| 172536 | + |
| 172537 | + /* Sync the db file */ |
| 172538 | + if( rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){ |
| 172539 | + sqlite3_file *pDb = p->pTargetFd->pReal; |
| 172540 | + rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL); |
| 172541 | + } |
| 171952 | 172542 | |
| 171953 | 172543 | p->rc = rc; |
| 171954 | 172544 | rbuSaveState(p, p->eStage); |
| 171955 | 172545 | rc = p->rc; |
| 171956 | 172546 | |
| | @@ -178363,26 +178953,28 @@ |
| 178363 | 178953 | /* Bit values for the JsonNode.jnFlag field |
| 178364 | 178954 | */ |
| 178365 | 178955 | #define JNODE_RAW 0x01 /* Content is raw, not JSON encoded */ |
| 178366 | 178956 | #define JNODE_ESCAPE 0x02 /* Content is text with \ escapes */ |
| 178367 | 178957 | #define JNODE_REMOVE 0x04 /* Do not output */ |
| 178368 | | -#define JNODE_REPLACE 0x08 /* Replace with JsonNode.iVal */ |
| 178369 | | -#define JNODE_APPEND 0x10 /* More ARRAY/OBJECT entries at u.iAppend */ |
| 178370 | | -#define JNODE_LABEL 0x20 /* Is a label of an object */ |
| 178958 | +#define JNODE_REPLACE 0x08 /* Replace with JsonNode.u.iReplace */ |
| 178959 | +#define JNODE_PATCH 0x10 /* Patch with JsonNode.u.pPatch */ |
| 178960 | +#define JNODE_APPEND 0x20 /* More ARRAY/OBJECT entries at u.iAppend */ |
| 178961 | +#define JNODE_LABEL 0x40 /* Is a label of an object */ |
| 178371 | 178962 | |
| 178372 | 178963 | |
| 178373 | 178964 | /* A single node of parsed JSON |
| 178374 | 178965 | */ |
| 178375 | 178966 | struct JsonNode { |
| 178376 | 178967 | u8 eType; /* One of the JSON_ type values */ |
| 178377 | 178968 | u8 jnFlags; /* JNODE flags */ |
| 178378 | | - u8 iVal; /* Replacement value when JNODE_REPLACE */ |
| 178379 | 178969 | u32 n; /* Bytes of content, or number of sub-nodes */ |
| 178380 | 178970 | union { |
| 178381 | 178971 | const char *zJContent; /* Content for INT, REAL, and STRING */ |
| 178382 | 178972 | u32 iAppend; /* More terms for ARRAY and OBJECT */ |
| 178383 | 178973 | u32 iKey; /* Key for ARRAY objects in json_tree() */ |
| 178974 | + u32 iReplace; /* Replacement content for JNODE_REPLACE */ |
| 178975 | + JsonNode *pPatch; /* Node chain of patch for JNODE_PATCH */ |
| 178384 | 178976 | } u; |
| 178385 | 178977 | }; |
| 178386 | 178978 | |
| 178387 | 178979 | /* A completely parsed JSON string |
| 178388 | 178980 | */ |
| | @@ -178635,10 +179227,17 @@ |
| 178635 | 179227 | static void jsonRenderNode( |
| 178636 | 179228 | JsonNode *pNode, /* The node to render */ |
| 178637 | 179229 | JsonString *pOut, /* Write JSON here */ |
| 178638 | 179230 | sqlite3_value **aReplace /* Replacement values */ |
| 178639 | 179231 | ){ |
| 179232 | + if( pNode->jnFlags & (JNODE_REPLACE|JNODE_PATCH) ){ |
| 179233 | + if( pNode->jnFlags & JNODE_REPLACE ){ |
| 179234 | + jsonAppendValue(pOut, aReplace[pNode->u.iReplace]); |
| 179235 | + return; |
| 179236 | + } |
| 179237 | + pNode = pNode->u.pPatch; |
| 179238 | + } |
| 178640 | 179239 | switch( pNode->eType ){ |
| 178641 | 179240 | default: { |
| 178642 | 179241 | assert( pNode->eType==JSON_NULL ); |
| 178643 | 179242 | jsonAppendRaw(pOut, "null", 4); |
| 178644 | 179243 | break; |
| | @@ -178666,16 +179265,11 @@ |
| 178666 | 179265 | case JSON_ARRAY: { |
| 178667 | 179266 | u32 j = 1; |
| 178668 | 179267 | jsonAppendChar(pOut, '['); |
| 178669 | 179268 | for(;;){ |
| 178670 | 179269 | while( j<=pNode->n ){ |
| 178671 | | - if( pNode[j].jnFlags & (JNODE_REMOVE|JNODE_REPLACE) ){ |
| 178672 | | - if( pNode[j].jnFlags & JNODE_REPLACE ){ |
| 178673 | | - jsonAppendSeparator(pOut); |
| 178674 | | - jsonAppendValue(pOut, aReplace[pNode[j].iVal]); |
| 178675 | | - } |
| 178676 | | - }else{ |
| 179270 | + if( (pNode[j].jnFlags & JNODE_REMOVE)==0 ){ |
| 178677 | 179271 | jsonAppendSeparator(pOut); |
| 178678 | 179272 | jsonRenderNode(&pNode[j], pOut, aReplace); |
| 178679 | 179273 | } |
| 178680 | 179274 | j += jsonNodeSize(&pNode[j]); |
| 178681 | 179275 | } |
| | @@ -178693,15 +179287,11 @@ |
| 178693 | 179287 | while( j<=pNode->n ){ |
| 178694 | 179288 | if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 ){ |
| 178695 | 179289 | jsonAppendSeparator(pOut); |
| 178696 | 179290 | jsonRenderNode(&pNode[j], pOut, aReplace); |
| 178697 | 179291 | jsonAppendChar(pOut, ':'); |
| 178698 | | - if( pNode[j+1].jnFlags & JNODE_REPLACE ){ |
| 178699 | | - jsonAppendValue(pOut, aReplace[pNode[j+1].iVal]); |
| 178700 | | - }else{ |
| 178701 | | - jsonRenderNode(&pNode[j+1], pOut, aReplace); |
| 178702 | | - } |
| 179292 | + jsonRenderNode(&pNode[j+1], pOut, aReplace); |
| 178703 | 179293 | } |
| 178704 | 179294 | j += 1 + jsonNodeSize(&pNode[j+1]); |
| 178705 | 179295 | } |
| 178706 | 179296 | if( (pNode->jnFlags & JNODE_APPEND)==0 ) break; |
| 178707 | 179297 | pNode = &pNode[pNode->u.iAppend]; |
| | @@ -178924,11 +179514,10 @@ |
| 178924 | 179514 | return jsonParseAddNodeExpand(pParse, eType, n, zContent); |
| 178925 | 179515 | } |
| 178926 | 179516 | p = &pParse->aNode[pParse->nNode]; |
| 178927 | 179517 | p->eType = (u8)eType; |
| 178928 | 179518 | p->jnFlags = 0; |
| 178929 | | - p->iVal = 0; |
| 178930 | 179519 | p->n = n; |
| 178931 | 179520 | p->u.zJContent = zContent; |
| 178932 | 179521 | return pParse->nNode++; |
| 178933 | 179522 | } |
| 178934 | 179523 | |
| | @@ -179390,10 +179979,29 @@ |
| 179390 | 179979 | zFuncName); |
| 179391 | 179980 | sqlite3_result_error(pCtx, zMsg, -1); |
| 179392 | 179981 | sqlite3_free(zMsg); |
| 179393 | 179982 | } |
| 179394 | 179983 | |
| 179984 | +/* |
| 179985 | +** Mark all NULL entries in the Object passed in as JNODE_REMOVE. |
| 179986 | +*/ |
| 179987 | +static void jsonRemoveAllNulls(JsonNode *pNode){ |
| 179988 | + int i, n; |
| 179989 | + assert( pNode->eType==JSON_OBJECT ); |
| 179990 | + n = pNode->n; |
| 179991 | + for(i=2; i<=n; i += jsonNodeSize(&pNode[i])+1){ |
| 179992 | + switch( pNode[i].eType ){ |
| 179993 | + case JSON_NULL: |
| 179994 | + pNode[i].jnFlags |= JNODE_REMOVE; |
| 179995 | + break; |
| 179996 | + case JSON_OBJECT: |
| 179997 | + jsonRemoveAllNulls(&pNode[i]); |
| 179998 | + break; |
| 179999 | + } |
| 180000 | + } |
| 180001 | +} |
| 180002 | + |
| 179395 | 180003 | |
| 179396 | 180004 | /**************************************************************************** |
| 179397 | 180005 | ** SQL functions used for testing and debugging |
| 179398 | 180006 | ****************************************************************************/ |
| 179399 | 180007 | |
| | @@ -179581,10 +180189,109 @@ |
| 179581 | 180189 | sqlite3_result_subtype(ctx, JSON_SUBTYPE); |
| 179582 | 180190 | } |
| 179583 | 180191 | jsonReset(&jx); |
| 179584 | 180192 | jsonParseReset(&x); |
| 179585 | 180193 | } |
| 180194 | + |
| 180195 | +/* This is the RFC 7396 MergePatch algorithm. |
| 180196 | +*/ |
| 180197 | +static JsonNode *jsonMergePatch( |
| 180198 | + JsonParse *pParse, /* The JSON parser that contains the TARGET */ |
| 180199 | + int iTarget, /* Node of the TARGET in pParse */ |
| 180200 | + JsonNode *pPatch /* The PATCH */ |
| 180201 | +){ |
| 180202 | + u32 i, j; |
| 180203 | + u32 iRoot; |
| 180204 | + JsonNode *pTarget; |
| 180205 | + if( pPatch->eType!=JSON_OBJECT ){ |
| 180206 | + return pPatch; |
| 180207 | + } |
| 180208 | + assert( iTarget>=0 && iTarget<pParse->nNode ); |
| 180209 | + pTarget = &pParse->aNode[iTarget]; |
| 180210 | + assert( (pPatch->jnFlags & JNODE_APPEND)==0 ); |
| 180211 | + if( pTarget->eType!=JSON_OBJECT ){ |
| 180212 | + jsonRemoveAllNulls(pPatch); |
| 180213 | + return pPatch; |
| 180214 | + } |
| 180215 | + iRoot = iTarget; |
| 180216 | + for(i=1; i<pPatch->n; i += jsonNodeSize(&pPatch[i+1])+1){ |
| 180217 | + u32 nKey; |
| 180218 | + const char *zKey; |
| 180219 | + assert( pPatch[i].eType==JSON_STRING ); |
| 180220 | + assert( pPatch[i].jnFlags & JNODE_LABEL ); |
| 180221 | + nKey = pPatch[i].n; |
| 180222 | + zKey = pPatch[i].u.zJContent; |
| 180223 | + assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); |
| 180224 | + for(j=1; j<pTarget->n; j += jsonNodeSize(&pTarget[j+1])+1 ){ |
| 180225 | + assert( pTarget[j].eType==JSON_STRING ); |
| 180226 | + assert( pTarget[j].jnFlags & JNODE_LABEL ); |
| 180227 | + assert( (pPatch[i].jnFlags & JNODE_RAW)==0 ); |
| 180228 | + if( pTarget[j].n==nKey && strncmp(pTarget[j].u.zJContent,zKey,nKey)==0 ){ |
| 180229 | + if( pTarget[j+1].jnFlags & (JNODE_REMOVE|JNODE_PATCH) ) break; |
| 180230 | + if( pPatch[i+1].eType==JSON_NULL ){ |
| 180231 | + pTarget[j+1].jnFlags |= JNODE_REMOVE; |
| 180232 | + }else{ |
| 180233 | + JsonNode *pNew = jsonMergePatch(pParse, iTarget+j+1, &pPatch[i+1]); |
| 180234 | + if( pNew==0 ) return 0; |
| 180235 | + pTarget = &pParse->aNode[iTarget]; |
| 180236 | + if( pNew!=&pTarget[j+1] ){ |
| 180237 | + pTarget[j+1].u.pPatch = pNew; |
| 180238 | + pTarget[j+1].jnFlags |= JNODE_PATCH; |
| 180239 | + } |
| 180240 | + } |
| 180241 | + break; |
| 180242 | + } |
| 180243 | + } |
| 180244 | + if( j>=pTarget->n && pPatch[i+1].eType!=JSON_NULL ){ |
| 180245 | + int iStart, iPatch; |
| 180246 | + iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0); |
| 180247 | + jsonParseAddNode(pParse, JSON_STRING, nKey, zKey); |
| 180248 | + iPatch = jsonParseAddNode(pParse, JSON_TRUE, 0, 0); |
| 180249 | + if( pParse->oom ) return 0; |
| 180250 | + jsonRemoveAllNulls(pPatch); |
| 180251 | + pTarget = &pParse->aNode[iTarget]; |
| 180252 | + pParse->aNode[iRoot].jnFlags |= JNODE_APPEND; |
| 180253 | + pParse->aNode[iRoot].u.iAppend = iStart - iRoot; |
| 180254 | + iRoot = iStart; |
| 180255 | + pParse->aNode[iPatch].jnFlags |= JNODE_PATCH; |
| 180256 | + pParse->aNode[iPatch].u.pPatch = &pPatch[i+1]; |
| 180257 | + } |
| 180258 | + } |
| 180259 | + return pTarget; |
| 180260 | +} |
| 180261 | + |
| 180262 | +/* |
| 180263 | +** Implementation of the json_mergepatch(JSON1,JSON2) function. Return a JSON |
| 180264 | +** object that is the result of running the RFC 7396 MergePatch() algorithm |
| 180265 | +** on the two arguments. |
| 180266 | +*/ |
| 180267 | +static void jsonPatchFunc( |
| 180268 | + sqlite3_context *ctx, |
| 180269 | + int argc, |
| 180270 | + sqlite3_value **argv |
| 180271 | +){ |
| 180272 | + JsonParse x; /* The JSON that is being patched */ |
| 180273 | + JsonParse y; /* The patch */ |
| 180274 | + JsonNode *pResult; /* The result of the merge */ |
| 180275 | + |
| 180276 | + UNUSED_PARAM(argc); |
| 180277 | + if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; |
| 180278 | + if( jsonParse(&y, ctx, (const char*)sqlite3_value_text(argv[1])) ){ |
| 180279 | + jsonParseReset(&x); |
| 180280 | + return; |
| 180281 | + } |
| 180282 | + pResult = jsonMergePatch(&x, 0, y.aNode); |
| 180283 | + assert( pResult!=0 || x.oom ); |
| 180284 | + if( pResult ){ |
| 180285 | + jsonReturnJson(pResult, ctx, 0); |
| 180286 | + }else{ |
| 180287 | + sqlite3_result_error_nomem(ctx); |
| 180288 | + } |
| 180289 | + jsonParseReset(&x); |
| 180290 | + jsonParseReset(&y); |
| 180291 | +} |
| 180292 | + |
| 179586 | 180293 | |
| 179587 | 180294 | /* |
| 179588 | 180295 | ** Implementation of the json_object(NAME,VALUE,...) function. Return a JSON |
| 179589 | 180296 | ** object that contains all name/value given in arguments. Or if any name |
| 179590 | 180297 | ** is not a string or if any value is a BLOB, throw an error. |
| | @@ -179685,15 +180392,15 @@ |
| 179685 | 180392 | zPath = (const char*)sqlite3_value_text(argv[i]); |
| 179686 | 180393 | pNode = jsonLookup(&x, zPath, 0, ctx); |
| 179687 | 180394 | if( x.nErr ) goto replace_err; |
| 179688 | 180395 | if( pNode ){ |
| 179689 | 180396 | pNode->jnFlags |= (u8)JNODE_REPLACE; |
| 179690 | | - pNode->iVal = (u8)(i+1); |
| 180397 | + pNode->u.iReplace = i + 1; |
| 179691 | 180398 | } |
| 179692 | 180399 | } |
| 179693 | 180400 | if( x.aNode[0].jnFlags & JNODE_REPLACE ){ |
| 179694 | | - sqlite3_result_value(ctx, argv[x.aNode[0].iVal]); |
| 180401 | + sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); |
| 179695 | 180402 | }else{ |
| 179696 | 180403 | jsonReturnJson(x.aNode, ctx, argv); |
| 179697 | 180404 | } |
| 179698 | 180405 | replace_err: |
| 179699 | 180406 | jsonParseReset(&x); |
| | @@ -179739,15 +180446,15 @@ |
| 179739 | 180446 | goto jsonSetDone; |
| 179740 | 180447 | }else if( x.nErr ){ |
| 179741 | 180448 | goto jsonSetDone; |
| 179742 | 180449 | }else if( pNode && (bApnd || bIsSet) ){ |
| 179743 | 180450 | pNode->jnFlags |= (u8)JNODE_REPLACE; |
| 179744 | | - pNode->iVal = (u8)(i+1); |
| 180451 | + pNode->u.iReplace = i + 1; |
| 179745 | 180452 | } |
| 179746 | 180453 | } |
| 179747 | 180454 | if( x.aNode[0].jnFlags & JNODE_REPLACE ){ |
| 179748 | | - sqlite3_result_value(ctx, argv[x.aNode[0].iVal]); |
| 180455 | + sqlite3_result_value(ctx, argv[x.aNode[0].u.iReplace]); |
| 179749 | 180456 | }else{ |
| 179750 | 180457 | jsonReturnJson(x.aNode, ctx, argv); |
| 179751 | 180458 | } |
| 179752 | 180459 | jsonSetDone: |
| 179753 | 180460 | jsonParseReset(&x); |
| | @@ -180386,10 +181093,11 @@ |
| 180386 | 181093 | { "json_array_length", 1, 0, jsonArrayLengthFunc }, |
| 180387 | 181094 | { "json_array_length", 2, 0, jsonArrayLengthFunc }, |
| 180388 | 181095 | { "json_extract", -1, 0, jsonExtractFunc }, |
| 180389 | 181096 | { "json_insert", -1, 0, jsonSetFunc }, |
| 180390 | 181097 | { "json_object", -1, 0, jsonObjectFunc }, |
| 181098 | + { "json_patch", 2, 0, jsonPatchFunc }, |
| 180391 | 181099 | { "json_quote", 1, 0, jsonQuoteFunc }, |
| 180392 | 181100 | { "json_remove", -1, 0, jsonRemoveFunc }, |
| 180393 | 181101 | { "json_replace", -1, 0, jsonReplaceFunc }, |
| 180394 | 181102 | { "json_set", -1, 1, jsonSetFunc }, |
| 180395 | 181103 | { "json_type", 1, 0, jsonTypeFunc }, |
| | @@ -181079,11 +181787,13 @@ |
| 181079 | 181787 | typedef unsigned short u16; |
| 181080 | 181788 | typedef short i16; |
| 181081 | 181789 | typedef sqlite3_int64 i64; |
| 181082 | 181790 | typedef sqlite3_uint64 u64; |
| 181083 | 181791 | |
| 181084 | | -#define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0]))) |
| 181792 | +#ifndef ArraySize |
| 181793 | +# define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0]))) |
| 181794 | +#endif |
| 181085 | 181795 | |
| 181086 | 181796 | #define testcase(x) |
| 181087 | 181797 | #define ALWAYS(x) 1 |
| 181088 | 181798 | #define NEVER(x) 0 |
| 181089 | 181799 | |
| | @@ -186302,11 +187012,14 @@ |
| 186302 | 187012 | if( p1->bEof==0 ){ |
| 186303 | 187013 | if( (p1->iRowid==iLast) |
| 186304 | 187014 | || (bFromValid && fts5RowidCmp(pExpr, p1->iRowid, iFrom)<0) |
| 186305 | 187015 | ){ |
| 186306 | 187016 | int rc = fts5ExprNodeNext(pExpr, p1, bFromValid, iFrom); |
| 186307 | | - if( rc!=SQLITE_OK ) return rc; |
| 187017 | + if( rc!=SQLITE_OK ){ |
| 187018 | + pNode->bNomatch = 0; |
| 187019 | + return rc; |
| 187020 | + } |
| 186308 | 187021 | } |
| 186309 | 187022 | } |
| 186310 | 187023 | } |
| 186311 | 187024 | |
| 186312 | 187025 | fts5ExprNodeTest_OR(pExpr, pNode); |
| | @@ -186333,11 +187046,14 @@ |
| 186333 | 187046 | Fts5ExprNode *pChild = pAnd->apChild[iChild]; |
| 186334 | 187047 | int cmp = fts5RowidCmp(pExpr, iLast, pChild->iRowid); |
| 186335 | 187048 | if( cmp>0 ){ |
| 186336 | 187049 | /* Advance pChild until it points to iLast or laster */ |
| 186337 | 187050 | rc = fts5ExprNodeNext(pExpr, pChild, 1, iLast); |
| 186338 | | - if( rc!=SQLITE_OK ) return rc; |
| 187051 | + if( rc!=SQLITE_OK ){ |
| 187052 | + pAnd->bNomatch = 0; |
| 187053 | + return rc; |
| 187054 | + } |
| 186339 | 187055 | } |
| 186340 | 187056 | |
| 186341 | 187057 | /* If the child node is now at EOF, so is the parent AND node. Otherwise, |
| 186342 | 187058 | ** the child node is guaranteed to have advanced at least as far as |
| 186343 | 187059 | ** rowid iLast. So if it is not at exactly iLast, pChild->iRowid is the |
| | @@ -186372,10 +187088,12 @@ |
| 186372 | 187088 | i64 iFrom |
| 186373 | 187089 | ){ |
| 186374 | 187090 | int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom); |
| 186375 | 187091 | if( rc==SQLITE_OK ){ |
| 186376 | 187092 | rc = fts5ExprNodeTest_AND(pExpr, pNode); |
| 187093 | + }else{ |
| 187094 | + pNode->bNomatch = 0; |
| 186377 | 187095 | } |
| 186378 | 187096 | return rc; |
| 186379 | 187097 | } |
| 186380 | 187098 | |
| 186381 | 187099 | static int fts5ExprNodeTest_NOT( |
| | @@ -186414,10 +187132,13 @@ |
| 186414 | 187132 | ){ |
| 186415 | 187133 | int rc = fts5ExprNodeNext(pExpr, pNode->apChild[0], bFromValid, iFrom); |
| 186416 | 187134 | if( rc==SQLITE_OK ){ |
| 186417 | 187135 | rc = fts5ExprNodeTest_NOT(pExpr, pNode); |
| 186418 | 187136 | } |
| 187137 | + if( rc!=SQLITE_OK ){ |
| 187138 | + pNode->bNomatch = 0; |
| 187139 | + } |
| 186419 | 187140 | return rc; |
| 186420 | 187141 | } |
| 186421 | 187142 | |
| 186422 | 187143 | /* |
| 186423 | 187144 | ** If pNode currently points to a match, this function returns SQLITE_OK |
| | @@ -197534,11 +198255,11 @@ |
| 197534 | 198255 | int nArg, /* Number of args */ |
| 197535 | 198256 | sqlite3_value **apUnused /* Function arguments */ |
| 197536 | 198257 | ){ |
| 197537 | 198258 | assert( nArg==0 ); |
| 197538 | 198259 | UNUSED_PARAM2(nArg, apUnused); |
| 197539 | | - sqlite3_result_text(pCtx, "fts5: 2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c", -1, SQLITE_TRANSIENT); |
| 198260 | + sqlite3_result_text(pCtx, "fts5: 2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37", -1, SQLITE_TRANSIENT); |
| 197540 | 198261 | } |
| 197541 | 198262 | |
| 197542 | 198263 | static int fts5Init(sqlite3 *db){ |
| 197543 | 198264 | static const sqlite3_module fts5Mod = { |
| 197544 | 198265 | /* iVersion */ 2, |
| | @@ -198197,15 +198918,10 @@ |
| 198197 | 198918 | sqlite3_step(pDel); |
| 198198 | 198919 | rc = sqlite3_reset(pDel); |
| 198199 | 198920 | } |
| 198200 | 198921 | } |
| 198201 | 198922 | |
| 198202 | | - /* Write the averages record */ |
| 198203 | | - if( rc==SQLITE_OK ){ |
| 198204 | | - rc = fts5StorageSaveTotals(p); |
| 198205 | | - } |
| 198206 | | - |
| 198207 | 198923 | return rc; |
| 198208 | 198924 | } |
| 198209 | 198925 | |
| 198210 | 198926 | /* |
| 198211 | 198927 | ** Delete all entries in the FTS5 index. |
| | @@ -198405,15 +199121,10 @@ |
| 198405 | 199121 | if( rc==SQLITE_OK ){ |
| 198406 | 199122 | rc = fts5StorageInsertDocsize(p, iRowid, &buf); |
| 198407 | 199123 | } |
| 198408 | 199124 | sqlite3_free(buf.p); |
| 198409 | 199125 | |
| 198410 | | - /* Write the averages record */ |
| 198411 | | - if( rc==SQLITE_OK ){ |
| 198412 | | - rc = fts5StorageSaveTotals(p); |
| 198413 | | - } |
| 198414 | | - |
| 198415 | 199126 | return rc; |
| 198416 | 199127 | } |
| 198417 | 199128 | |
| 198418 | 199129 | static int fts5StorageCount(Fts5Storage *p, const char *zSuffix, i64 *pnRow){ |
| 198419 | 199130 | Fts5Config *pConfig = p->pConfig; |
| | @@ -198744,16 +199455,21 @@ |
| 198744 | 199455 | |
| 198745 | 199456 | /* |
| 198746 | 199457 | ** Flush any data currently held in-memory to disk. |
| 198747 | 199458 | */ |
| 198748 | 199459 | static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){ |
| 198749 | | - if( bCommit && p->bTotalsValid ){ |
| 198750 | | - int rc = fts5StorageSaveTotals(p); |
| 198751 | | - p->bTotalsValid = 0; |
| 198752 | | - if( rc!=SQLITE_OK ) return rc; |
| 199460 | + int rc = SQLITE_OK; |
| 199461 | + i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db); |
| 199462 | + if( p->bTotalsValid ){ |
| 199463 | + rc = fts5StorageSaveTotals(p); |
| 199464 | + if( bCommit ) p->bTotalsValid = 0; |
| 198753 | 199465 | } |
| 198754 | | - return sqlite3Fts5IndexSync(p->pIndex, bCommit); |
| 199466 | + if( rc==SQLITE_OK ){ |
| 199467 | + rc = sqlite3Fts5IndexSync(p->pIndex, bCommit); |
| 199468 | + } |
| 199469 | + sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid); |
| 199470 | + return rc; |
| 198755 | 199471 | } |
| 198756 | 199472 | |
| 198757 | 199473 | static int sqlite3Fts5StorageRollback(Fts5Storage *p){ |
| 198758 | 199474 | p->bTotalsValid = 0; |
| 198759 | 199475 | return sqlite3Fts5IndexRollback(p->pIndex); |
| 198760 | 199476 | |