| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.42.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3042000 |
| 457 | | -#define SQLITE_SOURCE_ID "2023-04-01 15:51:21 a4fb2864fe01cce9694242a0750623ca47fcecd68f74c4239d3eb5fbf978770a" |
| 457 | +#define SQLITE_SOURCE_ID "2023-04-10 18:44:00 4c5a3c5fb351cc1c2ce16c33314ce19c53531f09263f87456283d9d756002f9d" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -2800,11 +2800,11 @@ |
| 2800 | 2800 | #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */ |
| 2801 | 2801 | #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */ |
| 2802 | 2802 | #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */ |
| 2803 | 2803 | #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */ |
| 2804 | 2804 | #define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */ |
| 2805 | | -#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1080 /* int int* */ |
| 2805 | +#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */ |
| 2806 | 2806 | #define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */ |
| 2807 | 2807 | #define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */ |
| 2808 | 2808 | |
| 2809 | 2809 | /* |
| 2810 | 2810 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| | @@ -9910,22 +9910,32 @@ |
| 9910 | 9910 | ** </dd> |
| 9911 | 9911 | ** |
| 9912 | 9912 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| 9913 | 9913 | ** <dd>Calls of the form |
| 9914 | 9914 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the |
| 9915 | | -** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| 9915 | +** the [xConnect] or [xCreate] methods of a [virtual table] implementation |
| 9916 | 9916 | ** identify that virtual table as being safe to use from within triggers |
| 9917 | 9917 | ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the |
| 9918 | 9918 | ** virtual table can do no serious harm even if it is controlled by a |
| 9919 | 9919 | ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS |
| 9920 | 9920 | ** flag unless absolutely necessary. |
| 9921 | 9921 | ** </dd> |
| 9922 | +** |
| 9923 | +** [[SQLITE_VTAB_USES_ALL_SCHEMAS]]<dt>SQLITE_VTAB_USES_ALL_SCHEMAS</dt> |
| 9924 | +** <dd>Calls of the form |
| 9925 | +** [sqlite3_vtab_config](db,SQLITE_VTAB_USES_ALL_SCHEMA) from within the |
| 9926 | +** the [xConnect] or [xCreate] methods of a [virtual table] implementation |
| 9927 | +** instruct the query planner to begin at least a read transaction on |
| 9928 | +** all schemas ("main", "temp", and any ATTACH-ed databases) whenever the |
| 9929 | +** virtual table is used. |
| 9930 | +** </dd> |
| 9922 | 9931 | ** </dl> |
| 9923 | 9932 | */ |
| 9924 | 9933 | #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 |
| 9925 | 9934 | #define SQLITE_VTAB_INNOCUOUS 2 |
| 9926 | 9935 | #define SQLITE_VTAB_DIRECTONLY 3 |
| 9936 | +#define SQLITE_VTAB_USES_ALL_SCHEMAS 4 |
| 9927 | 9937 | |
| 9928 | 9938 | /* |
| 9929 | 9939 | ** CAPI3REF: Determine The Virtual Table Conflict Policy |
| 9930 | 9940 | ** |
| 9931 | 9941 | ** This function may only be called from within a call to the [xUpdate] method |
| | @@ -13629,19 +13639,26 @@ |
| 13629 | 13639 | # define SQLITE_INT_TO_PTR(X) ((void*)(X)) |
| 13630 | 13640 | # define SQLITE_PTR_TO_INT(X) ((int)(X)) |
| 13631 | 13641 | #endif |
| 13632 | 13642 | |
| 13633 | 13643 | /* |
| 13634 | | -** A macro to hint to the compiler that a function should not be |
| 13644 | +** Macros to hint to the compiler that a function should or should not be |
| 13635 | 13645 | ** inlined. |
| 13636 | 13646 | */ |
| 13637 | 13647 | #if defined(__GNUC__) |
| 13638 | 13648 | # define SQLITE_NOINLINE __attribute__((noinline)) |
| 13649 | +# define SQLITE_INLINE __attribute__((always_inline)) inline |
| 13639 | 13650 | #elif defined(_MSC_VER) && _MSC_VER>=1310 |
| 13640 | 13651 | # define SQLITE_NOINLINE __declspec(noinline) |
| 13652 | +# define SQLITE_INLINE __forceinline |
| 13641 | 13653 | #else |
| 13642 | 13654 | # define SQLITE_NOINLINE |
| 13655 | +# define SQLITE_INLINE |
| 13656 | +#endif |
| 13657 | +#if defined(SQLITE_COVERAGE_TEST) |
| 13658 | +# undef SQLITE_INLINE |
| 13659 | +# define SQLITE_INLINE |
| 13643 | 13660 | #endif |
| 13644 | 13661 | |
| 13645 | 13662 | /* |
| 13646 | 13663 | ** Make sure that the compiler intrinsics we desire are enabled when |
| 13647 | 13664 | ** compiling with an appropriate version of MSVC unless prevented by |
| | @@ -16597,10 +16614,14 @@ |
| 16597 | 16614 | #endif |
| 16598 | 16615 | |
| 16599 | 16616 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 16600 | 16617 | SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, VdbeOp*); |
| 16601 | 16618 | #endif |
| 16619 | + |
| 16620 | +#if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG) |
| 16621 | +SQLITE_PRIVATE int sqlite3CursorRangeHintExprCheck(Walker *pWalker, Expr *pExpr); |
| 16622 | +#endif |
| 16602 | 16623 | |
| 16603 | 16624 | #endif /* SQLITE_VDBE_H */ |
| 16604 | 16625 | |
| 16605 | 16626 | /************** End of vdbe.h ************************************************/ |
| 16606 | 16627 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| | @@ -17862,10 +17883,11 @@ |
| 17862 | 17883 | sqlite3 *db; /* Database connection associated with this table */ |
| 17863 | 17884 | Module *pMod; /* Pointer to module implementation */ |
| 17864 | 17885 | sqlite3_vtab *pVtab; /* Pointer to vtab instance */ |
| 17865 | 17886 | int nRef; /* Number of pointers to this structure */ |
| 17866 | 17887 | u8 bConstraint; /* True if constraints are supported */ |
| 17888 | + u8 bAllSchemas; /* True if might use any attached schema */ |
| 17867 | 17889 | u8 eVtabRisk; /* Riskiness of allowing hacker access */ |
| 17868 | 17890 | int iSavepoint; /* Depth of the SAVEPOINT stack */ |
| 17869 | 17891 | VTable *pNext; /* Next in linked list (see above) */ |
| 17870 | 17892 | }; |
| 17871 | 17893 | |
| | @@ -19728,10 +19750,11 @@ |
| 19728 | 19750 | struct RenameCtx *pRename; /* RENAME COLUMN context */ |
| 19729 | 19751 | struct Table *pTab; /* Table of generated column */ |
| 19730 | 19752 | struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */ |
| 19731 | 19753 | SrcItem *pSrcItem; /* A single FROM clause item */ |
| 19732 | 19754 | DbFixer *pFix; /* See sqlite3FixSelect() */ |
| 19755 | + Mem *aMem; /* See sqlite3BtreeCursorHint() */ |
| 19733 | 19756 | } u; |
| 19734 | 19757 | }; |
| 19735 | 19758 | |
| 19736 | 19759 | /* |
| 19737 | 19760 | ** The following structure contains information used by the sqliteFix... |
| | @@ -20890,14 +20913,11 @@ |
| 20890 | 20913 | SQLITE_PRIVATE int sqlite3VtabCallConnect(Parse*, Table*); |
| 20891 | 20914 | SQLITE_PRIVATE int sqlite3VtabCallDestroy(sqlite3*, int, const char *); |
| 20892 | 20915 | SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *); |
| 20893 | 20916 | |
| 20894 | 20917 | SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); |
| 20895 | | -#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ |
| 20896 | | - && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 20897 | | -SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(sqlite3_index_info*); |
| 20898 | | -#endif |
| 20918 | +SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(Parse*); |
| 20899 | 20919 | SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); |
| 20900 | 20920 | SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); |
| 20901 | 20921 | SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); |
| 20902 | 20922 | SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*); |
| 20903 | 20923 | SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*); |
| | @@ -69500,12 +69520,29 @@ |
| 69500 | 69520 | ** and number of the varargs parameters) is determined by the eHintType |
| 69501 | 69521 | ** parameter. See the definitions of the BTREE_HINT_* macros for details. |
| 69502 | 69522 | */ |
| 69503 | 69523 | SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor *pCur, int eHintType, ...){ |
| 69504 | 69524 | /* Used only by system that substitute their own storage engine */ |
| 69525 | +#ifdef SQLITE_DEBUG |
| 69526 | + if( ALWAYS(eHintType==BTREE_HINT_RANGE) ){ |
| 69527 | + va_list ap; |
| 69528 | + Expr *pExpr; |
| 69529 | + Walker w; |
| 69530 | + memset(&w, 0, sizeof(w)); |
| 69531 | + w.xExprCallback = sqlite3CursorRangeHintExprCheck; |
| 69532 | + va_start(ap, eHintType); |
| 69533 | + pExpr = va_arg(ap, Expr*); |
| 69534 | + w.u.aMem = va_arg(ap, Mem*); |
| 69535 | + va_end(ap); |
| 69536 | + assert( pExpr!=0 ); |
| 69537 | + assert( w.u.aMem!=0 ); |
| 69538 | + sqlite3WalkExpr(&w, pExpr); |
| 69539 | + } |
| 69540 | +#endif /* SQLITE_DEBUG */ |
| 69505 | 69541 | } |
| 69506 | | -#endif |
| 69542 | +#endif /* SQLITE_ENABLE_CURSOR_HINTS */ |
| 69543 | + |
| 69507 | 69544 | |
| 69508 | 69545 | /* |
| 69509 | 69546 | ** Provide flag hints to the cursor. |
| 69510 | 69547 | */ |
| 69511 | 69548 | SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor *pCur, unsigned x){ |
| | @@ -70300,11 +70337,11 @@ |
| 70300 | 70337 | ** all the space together, however. This routine will avoid using |
| 70301 | 70338 | ** the first two bytes past the cell pointer area since presumably this |
| 70302 | 70339 | ** allocation is being made in order to insert a new cell, so we will |
| 70303 | 70340 | ** also end up needing a new cell pointer. |
| 70304 | 70341 | */ |
| 70305 | | -static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 70342 | +static SQLITE_INLINE int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 70306 | 70343 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 70307 | 70344 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 70308 | 70345 | int top; /* First byte of cell content area */ |
| 70309 | 70346 | int rc = SQLITE_OK; /* Integer return code */ |
| 70310 | 70347 | u8 *pTmp; /* Temp ptr into data[] */ |
| | @@ -70326,17 +70363,18 @@ |
| 70326 | 70363 | ** then the cell content offset of an empty page wants to be 65536. |
| 70327 | 70364 | ** However, that integer is too large to be stored in a 2-byte unsigned |
| 70328 | 70365 | ** integer, so a value of 0 is used in its place. */ |
| 70329 | 70366 | pTmp = &data[hdr+5]; |
| 70330 | 70367 | top = get2byte(pTmp); |
| 70331 | | - assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */ |
| 70332 | 70368 | if( gap>top ){ |
| 70333 | 70369 | if( top==0 && pPage->pBt->usableSize==65536 ){ |
| 70334 | 70370 | top = 65536; |
| 70335 | 70371 | }else{ |
| 70336 | 70372 | return SQLITE_CORRUPT_PAGE(pPage); |
| 70337 | 70373 | } |
| 70374 | + }else if( top>(int)pPage->pBt->usableSize ){ |
| 70375 | + return SQLITE_CORRUPT_PAGE(pPage); |
| 70338 | 70376 | } |
| 70339 | 70377 | |
| 70340 | 70378 | /* If there is enough space between gap and top for one more cell pointer, |
| 70341 | 70379 | ** and if the freelist is not empty, then search the |
| 70342 | 70380 | ** freelist looking for a slot big enough to satisfy the request. |
| | @@ -70415,11 +70453,11 @@ |
| 70415 | 70453 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 70416 | 70454 | assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 70417 | 70455 | assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| 70418 | 70456 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 70419 | 70457 | assert( iSize>=4 ); /* Minimum cell size is 4 */ |
| 70420 | | - assert( iStart<=pPage->pBt->usableSize-4 ); |
| 70458 | + assert( CORRUPT_DB || iStart<=pPage->pBt->usableSize-4 ); |
| 70421 | 70459 | |
| 70422 | 70460 | /* The list of freeblocks must be in ascending order. Find the |
| 70423 | 70461 | ** spot on the list where iStart should be inserted. |
| 70424 | 70462 | */ |
| 70425 | 70463 | hdr = pPage->hdrOffset; |
| | @@ -70472,10 +70510,15 @@ |
| 70472 | 70510 | if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); |
| 70473 | 70511 | data[hdr+7] -= nFrag; |
| 70474 | 70512 | } |
| 70475 | 70513 | pTmp = &data[hdr+5]; |
| 70476 | 70514 | x = get2byte(pTmp); |
| 70515 | + if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){ |
| 70516 | + /* Overwrite deleted information with zeros when the secure_delete |
| 70517 | + ** option is enabled */ |
| 70518 | + memset(&data[iStart], 0, iSize); |
| 70519 | + } |
| 70477 | 70520 | if( iStart<=x ){ |
| 70478 | 70521 | /* The new freeblock is at the beginning of the cell content area, |
| 70479 | 70522 | ** so just extend the cell content area rather than create another |
| 70480 | 70523 | ** freelist entry */ |
| 70481 | 70524 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| | @@ -70483,18 +70526,13 @@ |
| 70483 | 70526 | put2byte(&data[hdr+1], iFreeBlk); |
| 70484 | 70527 | put2byte(&data[hdr+5], iEnd); |
| 70485 | 70528 | }else{ |
| 70486 | 70529 | /* Insert the new freeblock into the freelist */ |
| 70487 | 70530 | put2byte(&data[iPtr], iStart); |
| 70488 | | - } |
| 70489 | | - if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){ |
| 70490 | | - /* Overwrite deleted information with zeros when the secure_delete |
| 70491 | | - ** option is enabled */ |
| 70492 | | - memset(&data[iStart], 0, iSize); |
| 70493 | | - } |
| 70494 | | - put2byte(&data[iStart], iFreeBlk); |
| 70495 | | - put2byte(&data[iStart+2], iSize); |
| 70531 | + put2byte(&data[iStart], iFreeBlk); |
| 70532 | + put2byte(&data[iStart+2], iSize); |
| 70533 | + } |
| 70496 | 70534 | pPage->nFree += iOrigSize; |
| 70497 | 70535 | return SQLITE_OK; |
| 70498 | 70536 | } |
| 70499 | 70537 | |
| 70500 | 70538 | /* |
| | @@ -75649,10 +75687,18 @@ |
| 75649 | 75687 | ** pTemp is not null. Regardless of pTemp, allocate a new entry |
| 75650 | 75688 | ** in pPage->apOvfl[] and make it point to the cell content (either |
| 75651 | 75689 | ** in pTemp or the original pCell) and also record its index. |
| 75652 | 75690 | ** Allocating a new entry in pPage->aCell[] implies that |
| 75653 | 75691 | ** pPage->nOverflow is incremented. |
| 75692 | +** |
| 75693 | +** The insertCellFast() routine below works exactly the same as |
| 75694 | +** insertCell() except that it lacks the pTemp and iChild parameters |
| 75695 | +** which are assumed zero. Other than that, the two routines are the |
| 75696 | +** same. |
| 75697 | +** |
| 75698 | +** Fixes or enhancements to this routine should be reflected in |
| 75699 | +** insertCellFast()! |
| 75654 | 75700 | */ |
| 75655 | 75701 | static int insertCell( |
| 75656 | 75702 | MemPage *pPage, /* Page into which we are copying */ |
| 75657 | 75703 | int i, /* New cell becomes the i-th cell of the page */ |
| 75658 | 75704 | u8 *pCell, /* Content of the new cell */ |
| | @@ -75671,18 +75717,107 @@ |
| 75671 | 75717 | assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) ); |
| 75672 | 75718 | assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) ); |
| 75673 | 75719 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 75674 | 75720 | assert( sz==pPage->xCellSize(pPage, pCell) || CORRUPT_DB ); |
| 75675 | 75721 | assert( pPage->nFree>=0 ); |
| 75722 | + assert( iChild>0 ); |
| 75676 | 75723 | if( pPage->nOverflow || sz+2>pPage->nFree ){ |
| 75677 | 75724 | if( pTemp ){ |
| 75678 | 75725 | memcpy(pTemp, pCell, sz); |
| 75679 | 75726 | pCell = pTemp; |
| 75680 | 75727 | } |
| 75681 | | - if( iChild ){ |
| 75682 | | - put4byte(pCell, iChild); |
| 75728 | + put4byte(pCell, iChild); |
| 75729 | + j = pPage->nOverflow++; |
| 75730 | + /* Comparison against ArraySize-1 since we hold back one extra slot |
| 75731 | + ** as a contingency. In other words, never need more than 3 overflow |
| 75732 | + ** slots but 4 are allocated, just to be safe. */ |
| 75733 | + assert( j < ArraySize(pPage->apOvfl)-1 ); |
| 75734 | + pPage->apOvfl[j] = pCell; |
| 75735 | + pPage->aiOvfl[j] = (u16)i; |
| 75736 | + |
| 75737 | + /* When multiple overflows occur, they are always sequential and in |
| 75738 | + ** sorted order. This invariants arise because multiple overflows can |
| 75739 | + ** only occur when inserting divider cells into the parent page during |
| 75740 | + ** balancing, and the dividers are adjacent and sorted. |
| 75741 | + */ |
| 75742 | + assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */ |
| 75743 | + assert( j==0 || i==pPage->aiOvfl[j-1]+1 ); /* Overflows are sequential */ |
| 75744 | + }else{ |
| 75745 | + int rc = sqlite3PagerWrite(pPage->pDbPage); |
| 75746 | + if( NEVER(rc!=SQLITE_OK) ){ |
| 75747 | + return rc; |
| 75683 | 75748 | } |
| 75749 | + assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 75750 | + data = pPage->aData; |
| 75751 | + assert( &data[pPage->cellOffset]==pPage->aCellIdx ); |
| 75752 | + rc = allocateSpace(pPage, sz, &idx); |
| 75753 | + if( rc ){ return rc; } |
| 75754 | + /* The allocateSpace() routine guarantees the following properties |
| 75755 | + ** if it returns successfully */ |
| 75756 | + assert( idx >= 0 ); |
| 75757 | + assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB ); |
| 75758 | + assert( idx+sz <= (int)pPage->pBt->usableSize ); |
| 75759 | + pPage->nFree -= (u16)(2 + sz); |
| 75760 | + /* In a corrupt database where an entry in the cell index section of |
| 75761 | + ** a btree page has a value of 3 or less, the pCell value might point |
| 75762 | + ** as many as 4 bytes in front of the start of the aData buffer for |
| 75763 | + ** the source page. Make sure this does not cause problems by not |
| 75764 | + ** reading the first 4 bytes */ |
| 75765 | + memcpy(&data[idx+4], pCell+4, sz-4); |
| 75766 | + put4byte(&data[idx], iChild); |
| 75767 | + pIns = pPage->aCellIdx + i*2; |
| 75768 | + memmove(pIns+2, pIns, 2*(pPage->nCell - i)); |
| 75769 | + put2byte(pIns, idx); |
| 75770 | + pPage->nCell++; |
| 75771 | + /* increment the cell count */ |
| 75772 | + if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++; |
| 75773 | + assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB ); |
| 75774 | +#ifndef SQLITE_OMIT_AUTOVACUUM |
| 75775 | + if( pPage->pBt->autoVacuum ){ |
| 75776 | + int rc2 = SQLITE_OK; |
| 75777 | + /* The cell may contain a pointer to an overflow page. If so, write |
| 75778 | + ** the entry for the overflow page into the pointer map. |
| 75779 | + */ |
| 75780 | + ptrmapPutOvflPtr(pPage, pPage, pCell, &rc2); |
| 75781 | + if( rc2 ) return rc2; |
| 75782 | + } |
| 75783 | +#endif |
| 75784 | + } |
| 75785 | + return SQLITE_OK; |
| 75786 | +} |
| 75787 | + |
| 75788 | +/* |
| 75789 | +** This variant of insertCell() assumes that the pTemp and iChild |
| 75790 | +** parameters are both zero. Use this variant in sqlite3BtreeInsert() |
| 75791 | +** for performance improvement, and also so that this variant is only |
| 75792 | +** called from that one place, and is thus inlined, and thus runs must |
| 75793 | +** faster. |
| 75794 | +** |
| 75795 | +** Fixes or enhancements to this routine should be reflected into |
| 75796 | +** the insertCell() routine. |
| 75797 | +*/ |
| 75798 | +static int insertCellFast( |
| 75799 | + MemPage *pPage, /* Page into which we are copying */ |
| 75800 | + int i, /* New cell becomes the i-th cell of the page */ |
| 75801 | + u8 *pCell, /* Content of the new cell */ |
| 75802 | + int sz /* Bytes of content in pCell */ |
| 75803 | +){ |
| 75804 | + int idx = 0; /* Where to write new cell content in data[] */ |
| 75805 | + int j; /* Loop counter */ |
| 75806 | + u8 *data; /* The content of the whole page */ |
| 75807 | + u8 *pIns; /* The point in pPage->aCellIdx[] where no cell inserted */ |
| 75808 | + |
| 75809 | + assert( i>=0 && i<=pPage->nCell+pPage->nOverflow ); |
| 75810 | + assert( MX_CELL(pPage->pBt)<=10921 ); |
| 75811 | + assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB ); |
| 75812 | + assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) ); |
| 75813 | + assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) ); |
| 75814 | + assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 75815 | + assert( sz==pPage->xCellSize(pPage, pCell) || CORRUPT_DB ); |
| 75816 | + assert( pPage->nFree>=0 ); |
| 75817 | + assert( pPage->nOverflow==0 ); |
| 75818 | + if( sz+2>pPage->nFree ){ |
| 75684 | 75819 | j = pPage->nOverflow++; |
| 75685 | 75820 | /* Comparison against ArraySize-1 since we hold back one extra slot |
| 75686 | 75821 | ** as a contingency. In other words, never need more than 3 overflow |
| 75687 | 75822 | ** slots but 4 are allocated, just to be safe. */ |
| 75688 | 75823 | assert( j < ArraySize(pPage->apOvfl)-1 ); |
| | @@ -75710,21 +75845,11 @@ |
| 75710 | 75845 | ** if it returns successfully */ |
| 75711 | 75846 | assert( idx >= 0 ); |
| 75712 | 75847 | assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB ); |
| 75713 | 75848 | assert( idx+sz <= (int)pPage->pBt->usableSize ); |
| 75714 | 75849 | pPage->nFree -= (u16)(2 + sz); |
| 75715 | | - if( iChild ){ |
| 75716 | | - /* In a corrupt database where an entry in the cell index section of |
| 75717 | | - ** a btree page has a value of 3 or less, the pCell value might point |
| 75718 | | - ** as many as 4 bytes in front of the start of the aData buffer for |
| 75719 | | - ** the source page. Make sure this does not cause problems by not |
| 75720 | | - ** reading the first 4 bytes */ |
| 75721 | | - memcpy(&data[idx+4], pCell+4, sz-4); |
| 75722 | | - put4byte(&data[idx], iChild); |
| 75723 | | - }else{ |
| 75724 | | - memcpy(&data[idx], pCell, sz); |
| 75725 | | - } |
| 75850 | + memcpy(&data[idx], pCell, sz); |
| 75726 | 75851 | pIns = pPage->aCellIdx + i*2; |
| 75727 | 75852 | memmove(pIns+2, pIns, 2*(pPage->nCell - i)); |
| 75728 | 75853 | put2byte(pIns, idx); |
| 75729 | 75854 | pPage->nCell++; |
| 75730 | 75855 | /* increment the cell count */ |
| | @@ -75905,11 +76030,11 @@ |
| 75905 | 76030 | int k; /* Current slot in pCArray->apEnd[] */ |
| 75906 | 76031 | u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ |
| 75907 | 76032 | |
| 75908 | 76033 | assert( i<iEnd ); |
| 75909 | 76034 | j = get2byte(&aData[hdr+5]); |
| 75910 | | - if( j>(u32)usableSize ){ j = 0; } |
| 76035 | + if( NEVER(j>(u32)usableSize) ){ j = 0; } |
| 75911 | 76036 | memcpy(&pTmp[j], &aData[j], usableSize - j); |
| 75912 | 76037 | |
| 75913 | 76038 | for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){} |
| 75914 | 76039 | pSrcEnd = pCArray->apEnd[k]; |
| 75915 | 76040 | |
| | @@ -76049,46 +76174,54 @@ |
| 76049 | 76174 | ){ |
| 76050 | 76175 | u8 * const aData = pPg->aData; |
| 76051 | 76176 | u8 * const pEnd = &aData[pPg->pBt->usableSize]; |
| 76052 | 76177 | u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize]; |
| 76053 | 76178 | int nRet = 0; |
| 76054 | | - int i; |
| 76179 | + int i, j; |
| 76055 | 76180 | int iEnd = iFirst + nCell; |
| 76056 | | - u8 *pFree = 0; /* \__ Parameters for pending call to */ |
| 76057 | | - int szFree = 0; /* / freeSpace() */ |
| 76181 | + int nFree = 0; |
| 76182 | + int aOfst[10]; |
| 76183 | + int aAfter[10]; |
| 76058 | 76184 | |
| 76059 | 76185 | for(i=iFirst; i<iEnd; i++){ |
| 76060 | 76186 | u8 *pCell = pCArray->apCell[i]; |
| 76061 | 76187 | if( SQLITE_WITHIN(pCell, pStart, pEnd) ){ |
| 76062 | 76188 | int sz; |
| 76189 | + int iAfter; |
| 76190 | + int iOfst; |
| 76063 | 76191 | /* No need to use cachedCellSize() here. The sizes of all cells that |
| 76064 | 76192 | ** are to be freed have already been computing while deciding which |
| 76065 | 76193 | ** cells need freeing */ |
| 76066 | 76194 | sz = pCArray->szCell[i]; assert( sz>0 ); |
| 76067 | | - if( pFree!=(pCell + sz) ){ |
| 76068 | | - if( pFree ){ |
| 76069 | | - assert( pFree>aData && (pFree - aData)<65536 ); |
| 76070 | | - freeSpace(pPg, (u16)(pFree - aData), szFree); |
| 76071 | | - } |
| 76072 | | - pFree = pCell; |
| 76073 | | - szFree = sz; |
| 76074 | | - if( pFree+sz>pEnd ){ |
| 76075 | | - return 0; |
| 76076 | | - } |
| 76077 | | - }else{ |
| 76078 | | - /* The current cell is adjacent to and before the pFree cell. |
| 76079 | | - ** Combine the two regions into one to reduce the number of calls |
| 76080 | | - ** to freeSpace(). */ |
| 76081 | | - pFree = pCell; |
| 76082 | | - szFree += sz; |
| 76195 | + iOfst = (u16)(pCell - aData); |
| 76196 | + iAfter = iOfst+sz; |
| 76197 | + for(j=0; j<nFree; j++){ |
| 76198 | + if( aOfst[j]==iAfter ){ |
| 76199 | + aOfst[j] = iOfst; |
| 76200 | + break; |
| 76201 | + }else if( aAfter[j]==iOfst ){ |
| 76202 | + aAfter[j] = iAfter; |
| 76203 | + break; |
| 76204 | + } |
| 76205 | + } |
| 76206 | + if( j>=nFree ){ |
| 76207 | + if( nFree>=sizeof(aOfst)/sizeof(aOfst[0]) ){ |
| 76208 | + for(j=0; j<nFree; j++){ |
| 76209 | + freeSpace(pPg, aOfst[j], aAfter[j]-aOfst[j]); |
| 76210 | + } |
| 76211 | + nFree = 0; |
| 76212 | + } |
| 76213 | + aOfst[nFree] = iOfst; |
| 76214 | + aAfter[nFree] = iAfter; |
| 76215 | + if( &aData[iAfter]>pEnd ) return 0; |
| 76216 | + nFree++; |
| 76083 | 76217 | } |
| 76084 | 76218 | nRet++; |
| 76085 | 76219 | } |
| 76086 | 76220 | } |
| 76087 | | - if( pFree ){ |
| 76088 | | - assert( pFree>aData && (pFree - aData)<65536 ); |
| 76089 | | - freeSpace(pPg, (u16)(pFree - aData), szFree); |
| 76221 | + for(j=0; j<nFree; j++){ |
| 76222 | + freeSpace(pPg, aOfst[j], aAfter[j]-aOfst[j]); |
| 76090 | 76223 | } |
| 76091 | 76224 | return nRet; |
| 76092 | 76225 | } |
| 76093 | 76226 | |
| 76094 | 76227 | /* |
| | @@ -76139,11 +76272,11 @@ |
| 76139 | 76272 | nCell -= nTail; |
| 76140 | 76273 | } |
| 76141 | 76274 | |
| 76142 | 76275 | pData = &aData[get2byteNotZero(&aData[hdr+5])]; |
| 76143 | 76276 | if( pData<pBegin ) goto editpage_fail; |
| 76144 | | - if( pData>pPg->aDataEnd ) goto editpage_fail; |
| 76277 | + if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail; |
| 76145 | 76278 | |
| 76146 | 76279 | /* Add cells to the start of the page */ |
| 76147 | 76280 | if( iNew<iOld ){ |
| 76148 | 76281 | int nAdd = MIN(nNew,iOld-iNew); |
| 76149 | 76282 | assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB ); |
| | @@ -77865,11 +77998,11 @@ |
| 77865 | 77998 | idx = ++pCur->ix; |
| 77866 | 77999 | pCur->curFlags &= ~BTCF_ValidNKey; |
| 77867 | 78000 | }else{ |
| 77868 | 78001 | assert( pPage->leaf ); |
| 77869 | 78002 | } |
| 77870 | | - rc = insertCell(pPage, idx, newCell, szNew, 0, 0); |
| 78003 | + rc = insertCellFast(pPage, idx, newCell, szNew); |
| 77871 | 78004 | assert( pPage->nOverflow==0 || rc==SQLITE_OK ); |
| 77872 | 78005 | assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 ); |
| 77873 | 78006 | |
| 77874 | 78007 | /* If no error has occurred and pPage has an overflow cell, call balance() |
| 77875 | 78008 | ** to redistribute the cells within the tree. Since balance() may move |
| | @@ -78088,10 +78221,13 @@ |
| 78088 | 78221 | return SQLITE_CORRUPT_BKPT; |
| 78089 | 78222 | } |
| 78090 | 78223 | pCell = findCell(pPage, iCellIdx); |
| 78091 | 78224 | if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ){ |
| 78092 | 78225 | return SQLITE_CORRUPT_BKPT; |
| 78226 | + } |
| 78227 | + if( pCell<&pPage->aCellIdx[pPage->nCell] ){ |
| 78228 | + return SQLITE_CORRUPT_BKPT; |
| 78093 | 78229 | } |
| 78094 | 78230 | |
| 78095 | 78231 | /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must |
| 78096 | 78232 | ** be preserved following this delete operation. If the current delete |
| 78097 | 78233 | ** will cause a b-tree rebalance, then this is done by saving the cursor |
| | @@ -80991,11 +81127,11 @@ |
| 80991 | 81127 | return SQLITE_NOMEM_BKPT; |
| 80992 | 81128 | } |
| 80993 | 81129 | |
| 80994 | 81130 | vdbeMemRenderNum(nByte, pMem->z, pMem); |
| 80995 | 81131 | assert( pMem->z!=0 ); |
| 80996 | | - assert( pMem->n==sqlite3Strlen30NN(pMem->z) ); |
| 81132 | + assert( pMem->n==(int)sqlite3Strlen30NN(pMem->z) ); |
| 80997 | 81133 | pMem->enc = SQLITE_UTF8; |
| 80998 | 81134 | pMem->flags |= MEM_Str|MEM_Term; |
| 80999 | 81135 | if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal); |
| 81000 | 81136 | sqlite3VdbeChangeEncoding(pMem, enc); |
| 81001 | 81137 | return SQLITE_OK; |
| | @@ -82035,10 +82171,13 @@ |
| 82035 | 82171 | assert( ExprUseXList(p) ); |
| 82036 | 82172 | pList = p->x.pList; |
| 82037 | 82173 | if( pList ) nVal = pList->nExpr; |
| 82038 | 82174 | assert( !ExprHasProperty(p, EP_IntValue) ); |
| 82039 | 82175 | pFunc = sqlite3FindFunction(db, p->u.zToken, nVal, enc, 0); |
| 82176 | +#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 82177 | + if( pFunc==0 ) return SQLITE_OK; |
| 82178 | +#endif |
| 82040 | 82179 | assert( pFunc ); |
| 82041 | 82180 | if( (pFunc->funcFlags & (SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG))==0 |
| 82042 | 82181 | || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL) |
| 82043 | 82182 | ){ |
| 82044 | 82183 | return SQLITE_OK; |
| | @@ -85875,10 +86014,12 @@ |
| 85875 | 86014 | db->nDeferredCons = 0; |
| 85876 | 86015 | db->nDeferredImmCons = 0; |
| 85877 | 86016 | db->flags &= ~(u64)SQLITE_DeferFKs; |
| 85878 | 86017 | sqlite3CommitInternalChanges(db); |
| 85879 | 86018 | } |
| 86019 | + }else if( p->rc==SQLITE_SCHEMA && db->nVdbeActive>1 ){ |
| 86020 | + p->nChange = 0; |
| 85880 | 86021 | }else{ |
| 85881 | 86022 | sqlite3RollbackAll(db, SQLITE_OK); |
| 85882 | 86023 | p->nChange = 0; |
| 85883 | 86024 | } |
| 85884 | 86025 | db->nStatement = 0; |
| | @@ -87822,10 +87963,24 @@ |
| 87822 | 87963 | return 0; |
| 87823 | 87964 | } |
| 87824 | 87965 | return 1; |
| 87825 | 87966 | } |
| 87826 | 87967 | |
| 87968 | +#if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG) |
| 87969 | +/* |
| 87970 | +** This Walker callback is used to help verify that calls to |
| 87971 | +** sqlite3BtreeCursorHint() with opcode BTREE_HINT_RANGE have |
| 87972 | +** byte-code register values correctly initialized. |
| 87973 | +*/ |
| 87974 | +SQLITE_PRIVATE int sqlite3CursorRangeHintExprCheck(Walker *pWalker, Expr *pExpr){ |
| 87975 | + if( pExpr->op==TK_REGISTER ){ |
| 87976 | + assert( (pWalker->u.aMem[pExpr->iTable].flags & MEM_Undefined)==0 ); |
| 87977 | + } |
| 87978 | + return WRC_Continue; |
| 87979 | +} |
| 87980 | +#endif /* SQLITE_ENABLE_CURSOR_HINTS && SQLITE_DEBUG */ |
| 87981 | + |
| 87827 | 87982 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 87828 | 87983 | /* |
| 87829 | 87984 | ** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored |
| 87830 | 87985 | ** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored |
| 87831 | 87986 | ** in memory obtained from sqlite3DbMalloc). |
| | @@ -88208,11 +88363,11 @@ |
| 88208 | 88363 | SQLITE_NULL, /* 0x1d (not possible) */ |
| 88209 | 88364 | SQLITE_INTEGER, /* 0x1e (not possible) */ |
| 88210 | 88365 | SQLITE_NULL, /* 0x1f (not possible) */ |
| 88211 | 88366 | SQLITE_FLOAT, /* 0x20 INTREAL */ |
| 88212 | 88367 | SQLITE_NULL, /* 0x21 (not possible) */ |
| 88213 | | - SQLITE_TEXT, /* 0x22 INTREAL + TEXT */ |
| 88368 | + SQLITE_FLOAT, /* 0x22 INTREAL + TEXT */ |
| 88214 | 88369 | SQLITE_NULL, /* 0x23 (not possible) */ |
| 88215 | 88370 | SQLITE_FLOAT, /* 0x24 (not possible) */ |
| 88216 | 88371 | SQLITE_NULL, /* 0x25 (not possible) */ |
| 88217 | 88372 | SQLITE_FLOAT, /* 0x26 (not possible) */ |
| 88218 | 88373 | SQLITE_NULL, /* 0x27 (not possible) */ |
| | @@ -106208,15 +106363,14 @@ |
| 106208 | 106363 | if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){ |
| 106209 | 106364 | p = p->pLeft; |
| 106210 | 106365 | }else{ |
| 106211 | 106366 | Expr *pNext = p->pRight; |
| 106212 | 106367 | /* The Expr.x union is never used at the same time as Expr.pRight */ |
| 106213 | | - assert( ExprUseXList(p) ); |
| 106214 | | - assert( p->x.pList==0 || p->pRight==0 ); |
| 106215 | | - if( p->x.pList!=0 && !db->mallocFailed ){ |
| 106368 | + assert( !ExprUseXList(p) || p->x.pList==0 || p->pRight==0 ); |
| 106369 | + if( ExprUseXList(p) && p->x.pList!=0 && !db->mallocFailed ){ |
| 106216 | 106370 | int i; |
| 106217 | | - for(i=0; ALWAYS(i<p->x.pList->nExpr); i++){ |
| 106371 | + for(i=0; i<p->x.pList->nExpr; i++){ |
| 106218 | 106372 | if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){ |
| 106219 | 106373 | pNext = p->x.pList->a[i].pExpr; |
| 106220 | 106374 | break; |
| 106221 | 106375 | } |
| 106222 | 106376 | } |
| | @@ -108866,11 +109020,10 @@ |
| 108866 | 109020 | Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i); |
| 108867 | 109021 | Expr *pRhs = pEList->a[i].pExpr; |
| 108868 | 109022 | CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs); |
| 108869 | 109023 | int j; |
| 108870 | 109024 | |
| 108871 | | - assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr ); |
| 108872 | 109025 | for(j=0; j<nExpr; j++){ |
| 108873 | 109026 | if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue; |
| 108874 | 109027 | assert( pIdx->azColl[j] ); |
| 108875 | 109028 | if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){ |
| 108876 | 109029 | continue; |
| | @@ -111031,11 +111184,13 @@ |
| 111031 | 111184 | assert( pParse->pVdbe!=0 || pParse->db->mallocFailed ); |
| 111032 | 111185 | if( pParse->pVdbe==0 ) return; |
| 111033 | 111186 | inReg = sqlite3ExprCodeTarget(pParse, pExpr, target); |
| 111034 | 111187 | if( inReg!=target ){ |
| 111035 | 111188 | u8 op; |
| 111036 | | - if( ALWAYS(pExpr) && ExprHasProperty(pExpr,EP_Subquery) ){ |
| 111189 | + if( ALWAYS(pExpr) |
| 111190 | + && (ExprHasProperty(pExpr,EP_Subquery) || pExpr->op==TK_REGISTER) |
| 111191 | + ){ |
| 111037 | 111192 | op = OP_Copy; |
| 111038 | 111193 | }else{ |
| 111039 | 111194 | op = OP_SCopy; |
| 111040 | 111195 | } |
| 111041 | 111196 | sqlite3VdbeAddOp2(pParse->pVdbe, op, inReg, target); |
| | @@ -112218,11 +112373,11 @@ |
| 112218 | 112373 | int iAgg = pExpr->iAgg; |
| 112219 | 112374 | Parse *pParse = pWalker->pParse; |
| 112220 | 112375 | sqlite3 *db = pParse->db; |
| 112221 | 112376 | assert( iAgg>=0 ); |
| 112222 | 112377 | if( pExpr->op!=TK_AGG_FUNCTION ){ |
| 112223 | | - if( iAgg<pAggInfo->nColumn |
| 112378 | + if( ALWAYS(iAgg<pAggInfo->nColumn) |
| 112224 | 112379 | && pAggInfo->aCol[iAgg].pCExpr==pExpr |
| 112225 | 112380 | ){ |
| 112226 | 112381 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 112227 | 112382 | if( pExpr ){ |
| 112228 | 112383 | pAggInfo->aCol[iAgg].pCExpr = pExpr; |
| | @@ -112381,11 +112536,15 @@ |
| 112381 | 112536 | if( iDataCur<0 ) continue; |
| 112382 | 112537 | if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break; |
| 112383 | 112538 | } |
| 112384 | 112539 | if( pIEpr==0 ) break; |
| 112385 | 112540 | if( NEVER(!ExprUseYTab(pExpr)) ) break; |
| 112386 | | - if( pExpr->pAggInfo!=0 ) break; /* Already resolved by outer context */ |
| 112541 | + for(i=0; i<pSrcList->nSrc; i++){ |
| 112542 | + if( pSrcList->a[0].iCursor==pIEpr->iDataCur ) break; |
| 112543 | + } |
| 112544 | + if( i>=pSrcList->nSrc ) break; |
| 112545 | + if( NEVER(pExpr->pAggInfo!=0) ) break; /* Resolved by outer context */ |
| 112387 | 112546 | if( pParse->nErr ){ return WRC_Abort; } |
| 112388 | 112547 | |
| 112389 | 112548 | /* If we reach this point, it means that expression pExpr can be |
| 112390 | 112549 | ** translated into a reference to an index column as described by |
| 112391 | 112550 | ** pIEpr. |
| | @@ -145087,16 +145246,17 @@ |
| 145087 | 145246 | if( pExpr->pAggInfo==0 ) return WRC_Continue; |
| 145088 | 145247 | if( pExpr->op==TK_AGG_COLUMN ) return WRC_Continue; |
| 145089 | 145248 | if( pExpr->op==TK_AGG_FUNCTION ) return WRC_Continue; |
| 145090 | 145249 | if( pExpr->op==TK_IF_NULL_ROW ) return WRC_Continue; |
| 145091 | 145250 | pAggInfo = pExpr->pAggInfo; |
| 145092 | | - if( pExpr->iAgg>=pAggInfo->nColumn ) return WRC_Continue; |
| 145251 | + if( NEVER(pExpr->iAgg>=pAggInfo->nColumn) ) return WRC_Continue; |
| 145093 | 145252 | assert( pExpr->iAgg>=0 ); |
| 145094 | 145253 | pCol = &pAggInfo->aCol[pExpr->iAgg]; |
| 145095 | 145254 | pExpr->op = TK_AGG_COLUMN; |
| 145096 | 145255 | pExpr->iTable = pCol->iTable; |
| 145097 | 145256 | pExpr->iColumn = pCol->iColumn; |
| 145257 | + ExprClearProperty(pExpr, EP_Skip|EP_Collate); |
| 145098 | 145258 | return WRC_Prune; |
| 145099 | 145259 | } |
| 145100 | 145260 | |
| 145101 | 145261 | /* |
| 145102 | 145262 | ** Convert every pAggInfo->aFunc[].pExpr such that any node within |
| | @@ -152012,10 +152172,14 @@ |
| 152012 | 152172 | break; |
| 152013 | 152173 | } |
| 152014 | 152174 | case SQLITE_VTAB_DIRECTONLY: { |
| 152015 | 152175 | p->pVTable->eVtabRisk = SQLITE_VTABRISK_High; |
| 152016 | 152176 | break; |
| 152177 | + } |
| 152178 | + case SQLITE_VTAB_USES_ALL_SCHEMAS: { |
| 152179 | + p->pVTable->bAllSchemas = 1; |
| 152180 | + break; |
| 152017 | 152181 | } |
| 152018 | 152182 | default: { |
| 152019 | 152183 | rc = SQLITE_MISUSE_BKPT; |
| 152020 | 152184 | break; |
| 152021 | 152185 | } |
| | @@ -153686,31 +153850,29 @@ |
| 153686 | 153850 | ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into |
| 153687 | 153851 | ** an access of the index rather than the original table. |
| 153688 | 153852 | */ |
| 153689 | 153853 | static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){ |
| 153690 | 153854 | int rc = WRC_Continue; |
| 153855 | + int reg; |
| 153691 | 153856 | struct CCurHint *pHint = pWalker->u.pCCurHint; |
| 153692 | 153857 | if( pExpr->op==TK_COLUMN ){ |
| 153693 | 153858 | if( pExpr->iTable!=pHint->iTabCur ){ |
| 153694 | | - int reg = ++pWalker->pParse->nMem; /* Register for column value */ |
| 153695 | | - sqlite3ExprCode(pWalker->pParse, pExpr, reg); |
| 153859 | + reg = ++pWalker->pParse->nMem; /* Register for column value */ |
| 153860 | + reg = sqlite3ExprCodeTarget(pWalker->pParse, pExpr, reg); |
| 153696 | 153861 | pExpr->op = TK_REGISTER; |
| 153697 | 153862 | pExpr->iTable = reg; |
| 153698 | 153863 | }else if( pHint->pIdx!=0 ){ |
| 153699 | 153864 | pExpr->iTable = pHint->iIdxCur; |
| 153700 | 153865 | pExpr->iColumn = sqlite3TableColumnToIndex(pHint->pIdx, pExpr->iColumn); |
| 153701 | 153866 | assert( pExpr->iColumn>=0 ); |
| 153702 | 153867 | } |
| 153703 | | - }else if( pExpr->op==TK_AGG_FUNCTION ){ |
| 153704 | | - /* An aggregate function in the WHERE clause of a query means this must |
| 153705 | | - ** be a correlated sub-query, and expression pExpr is an aggregate from |
| 153706 | | - ** the parent context. Do not walk the function arguments in this case. |
| 153707 | | - ** |
| 153708 | | - ** todo: It should be possible to replace this node with a TK_REGISTER |
| 153709 | | - ** expression, as the result of the expression must be stored in a |
| 153710 | | - ** register at this point. The same holds for TK_AGG_COLUMN nodes. */ |
| 153868 | + }else if( pExpr->pAggInfo ){ |
| 153711 | 153869 | rc = WRC_Prune; |
| 153870 | + reg = ++pWalker->pParse->nMem; /* Register for column value */ |
| 153871 | + reg = sqlite3ExprCodeTarget(pWalker->pParse, pExpr, reg); |
| 153872 | + pExpr->op = TK_REGISTER; |
| 153873 | + pExpr->iTable = reg; |
| 153712 | 153874 | } |
| 153713 | 153875 | return rc; |
| 153714 | 153876 | } |
| 153715 | 153877 | |
| 153716 | 153878 | /* |
| | @@ -158823,10 +158985,13 @@ |
| 158823 | 158985 | sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc)); |
| 158824 | 158986 | }else{ |
| 158825 | 158987 | sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg); |
| 158826 | 158988 | } |
| 158827 | 158989 | } |
| 158990 | + if( pTab->u.vtab.p->bAllSchemas ){ |
| 158991 | + sqlite3VtabUsesAllSchemas(pParse); |
| 158992 | + } |
| 158828 | 158993 | sqlite3_free(pVtab->zErrMsg); |
| 158829 | 158994 | pVtab->zErrMsg = 0; |
| 158830 | 158995 | return rc; |
| 158831 | 158996 | } |
| 158832 | 158997 | #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */ |
| | @@ -159353,11 +159518,11 @@ |
| 159353 | 159518 | #else |
| 159354 | 159519 | UNUSED_PARAMETER(pParse); |
| 159355 | 159520 | UNUSED_PARAMETER(pBuilder); |
| 159356 | 159521 | assert( pLower || pUpper ); |
| 159357 | 159522 | #endif |
| 159358 | | - assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 ); |
| 159523 | + assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 || pParse->nErr>0 ); |
| 159359 | 159524 | nNew = whereRangeAdjust(pLower, nOut); |
| 159360 | 159525 | nNew = whereRangeAdjust(pUpper, nNew); |
| 159361 | 159526 | |
| 159362 | 159527 | /* TUNING: If there is both an upper and lower limit and neither limit |
| 159363 | 159528 | ** has an application-defined likelihood(), assume the range is |
| | @@ -161454,24 +161619,20 @@ |
| 161454 | 161619 | HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 161455 | 161620 | assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 ); |
| 161456 | 161621 | return pHidden->eDistinct; |
| 161457 | 161622 | } |
| 161458 | 161623 | |
| 161459 | | -#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \ |
| 161460 | | - && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 161461 | 161624 | /* |
| 161462 | 161625 | ** Cause the prepared statement that is associated with a call to |
| 161463 | 161626 | ** xBestIndex to potentially use all schemas. If the statement being |
| 161464 | 161627 | ** prepared is read-only, then just start read transactions on all |
| 161465 | 161628 | ** schemas. But if this is a write operation, start writes on all |
| 161466 | 161629 | ** schemas. |
| 161467 | 161630 | ** |
| 161468 | 161631 | ** This is used by the (built-in) sqlite_dbpage virtual table. |
| 161469 | 161632 | */ |
| 161470 | | -SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(sqlite3_index_info *pIdxInfo){ |
| 161471 | | - HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1]; |
| 161472 | | - Parse *pParse = pHidden->pParse; |
| 161633 | +SQLITE_PRIVATE void sqlite3VtabUsesAllSchemas(Parse *pParse){ |
| 161473 | 161634 | int nDb = pParse->db->nDb; |
| 161474 | 161635 | int i; |
| 161475 | 161636 | for(i=0; i<nDb; i++){ |
| 161476 | 161637 | sqlite3CodeVerifySchema(pParse, i); |
| 161477 | 161638 | } |
| | @@ -161479,11 +161640,10 @@ |
| 161479 | 161640 | for(i=0; i<nDb; i++){ |
| 161480 | 161641 | sqlite3BeginWriteOperation(pParse, 0, i); |
| 161481 | 161642 | } |
| 161482 | 161643 | } |
| 161483 | 161644 | } |
| 161484 | | -#endif |
| 161485 | 161645 | |
| 161486 | 161646 | /* |
| 161487 | 161647 | ** Add all WhereLoop objects for a table of the join identified by |
| 161488 | 161648 | ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table. |
| 161489 | 161649 | ** |
| | @@ -164036,11 +164196,12 @@ |
| 164036 | 164196 | } |
| 164037 | 164197 | } |
| 164038 | 164198 | k = pLevel->addrBody + 1; |
| 164039 | 164199 | #ifdef SQLITE_DEBUG |
| 164040 | 164200 | if( db->flags & SQLITE_VdbeAddopTrace ){ |
| 164041 | | - printf("TRANSLATE opcodes in range %d..%d\n", k, last-1); |
| 164201 | + printf("TRANSLATE cursor %d->%d in opcode range %d..%d\n", |
| 164202 | + pLevel->iTabCur, pLevel->iIdxCur, k, last-1); |
| 164042 | 164203 | } |
| 164043 | 164204 | /* Proof that the "+1" on the k value above is safe */ |
| 164044 | 164205 | pOp = sqlite3VdbeGetOp(v, k - 1); |
| 164045 | 164206 | assert( pOp->opcode!=OP_Column || pOp->p1!=pLevel->iTabCur ); |
| 164046 | 164207 | assert( pOp->opcode!=OP_Rowid || pOp->p1!=pLevel->iTabCur ); |
| | @@ -172901,11 +173062,11 @@ |
| 172901 | 173062 | 132, 0, 98, 38, 39, 0, 20, 45, 117, 93, |
| 172902 | 173063 | }; |
| 172903 | 173064 | /* aKWNext[] forms the hash collision chain. If aKWHash[i]==0 |
| 172904 | 173065 | ** then the i-th keyword has no more hash collisions. Otherwise, |
| 172905 | 173066 | ** the next keyword with the same hash is aKWHash[i]-1. */ |
| 172906 | | -static const unsigned char aKWNext[147] = { |
| 173067 | +static const unsigned char aKWNext[148] = {0, |
| 172907 | 173068 | 0, 0, 0, 0, 4, 0, 43, 0, 0, 106, 114, 0, 0, |
| 172908 | 173069 | 0, 2, 0, 0, 143, 0, 0, 0, 13, 0, 0, 0, 0, |
| 172909 | 173070 | 141, 0, 0, 119, 52, 0, 0, 137, 12, 0, 0, 62, 0, |
| 172910 | 173071 | 138, 0, 133, 0, 0, 36, 0, 0, 28, 77, 0, 0, 0, |
| 172911 | 173072 | 0, 59, 0, 47, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| | @@ -172916,11 +173077,11 @@ |
| 172916 | 173077 | 112, 21, 7, 67, 0, 79, 96, 118, 0, 0, 68, 0, 0, |
| 172917 | 173078 | 99, 44, 0, 55, 0, 76, 0, 95, 32, 33, 57, 25, 0, |
| 172918 | 173079 | 102, 0, 0, 87, |
| 172919 | 173080 | }; |
| 172920 | 173081 | /* aKWLen[i] is the length (in bytes) of the i-th keyword */ |
| 172921 | | -static const unsigned char aKWLen[147] = { |
| 173082 | +static const unsigned char aKWLen[148] = {0, |
| 172922 | 173083 | 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6, |
| 172923 | 173084 | 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 7, |
| 172924 | 173085 | 6, 9, 4, 2, 6, 5, 9, 9, 4, 7, 3, 2, 4, |
| 172925 | 173086 | 4, 6, 11, 6, 2, 7, 5, 5, 9, 6, 10, 4, 6, |
| 172926 | 173087 | 2, 3, 7, 5, 9, 6, 6, 4, 5, 5, 10, 6, 5, |
| | @@ -172932,11 +173093,11 @@ |
| 172932 | 173093 | 4, 9, 5, 8, 4, 3, 9, 5, 5, 6, 4, 6, 2, |
| 172933 | 173094 | 2, 9, 3, 7, |
| 172934 | 173095 | }; |
| 172935 | 173096 | /* aKWOffset[i] is the index into zKWText[] of the start of |
| 172936 | 173097 | ** the text for the i-th keyword. */ |
| 172937 | | -static const unsigned short int aKWOffset[147] = { |
| 173098 | +static const unsigned short int aKWOffset[148] = {0, |
| 172938 | 173099 | 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33, |
| 172939 | 173100 | 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81, |
| 172940 | 173101 | 86, 90, 90, 94, 99, 101, 105, 111, 119, 123, 123, 123, 126, |
| 172941 | 173102 | 129, 132, 137, 142, 146, 147, 152, 156, 160, 168, 174, 181, 184, |
| 172942 | 173103 | 184, 187, 189, 195, 198, 206, 211, 216, 219, 222, 226, 236, 239, |
| | @@ -172947,11 +173108,11 @@ |
| 172947 | 173108 | 520, 523, 527, 532, 539, 544, 553, 557, 560, 565, 567, 571, 579, |
| 172948 | 173109 | 585, 588, 597, 602, 610, 610, 614, 623, 628, 633, 639, 642, 645, |
| 172949 | 173110 | 648, 650, 655, 659, |
| 172950 | 173111 | }; |
| 172951 | 173112 | /* aKWCode[i] is the parser symbol code for the i-th keyword */ |
| 172952 | | -static const unsigned char aKWCode[147] = { |
| 173113 | +static const unsigned char aKWCode[148] = {0, |
| 172953 | 173114 | TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE, |
| 172954 | 173115 | TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN, |
| 172955 | 173116 | TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD, |
| 172956 | 173117 | TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE, |
| 172957 | 173118 | TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE, |
| | @@ -173116,11 +173277,11 @@ |
| 173116 | 173277 | static int keywordCode(const char *z, int n, int *pType){ |
| 173117 | 173278 | int i, j; |
| 173118 | 173279 | const char *zKW; |
| 173119 | 173280 | if( n>=2 ){ |
| 173120 | 173281 | i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n*1) % 127; |
| 173121 | | - for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){ |
| 173282 | + for(i=(int)aKWHash[i]; i>0; i=aKWNext[i]){ |
| 173122 | 173283 | if( aKWLen[i]!=n ) continue; |
| 173123 | 173284 | zKW = &zKWText[aKWOffset[i]]; |
| 173124 | 173285 | #ifdef SQLITE_ASCII |
| 173125 | 173286 | if( (z[0]&~0x20)!=zKW[0] ) continue; |
| 173126 | 173287 | if( (z[1]&~0x20)!=zKW[1] ) continue; |
| | @@ -173132,157 +173293,157 @@ |
| 173132 | 173293 | if( toupper(z[1])!=zKW[1] ) continue; |
| 173133 | 173294 | j = 2; |
| 173134 | 173295 | while( j<n && toupper(z[j])==zKW[j] ){ j++; } |
| 173135 | 173296 | #endif |
| 173136 | 173297 | if( j<n ) continue; |
| 173137 | | - testcase( i==0 ); /* REINDEX */ |
| 173138 | | - testcase( i==1 ); /* INDEXED */ |
| 173139 | | - testcase( i==2 ); /* INDEX */ |
| 173140 | | - testcase( i==3 ); /* DESC */ |
| 173141 | | - testcase( i==4 ); /* ESCAPE */ |
| 173142 | | - testcase( i==5 ); /* EACH */ |
| 173143 | | - testcase( i==6 ); /* CHECK */ |
| 173144 | | - testcase( i==7 ); /* KEY */ |
| 173145 | | - testcase( i==8 ); /* BEFORE */ |
| 173146 | | - testcase( i==9 ); /* FOREIGN */ |
| 173147 | | - testcase( i==10 ); /* FOR */ |
| 173148 | | - testcase( i==11 ); /* IGNORE */ |
| 173149 | | - testcase( i==12 ); /* REGEXP */ |
| 173150 | | - testcase( i==13 ); /* EXPLAIN */ |
| 173151 | | - testcase( i==14 ); /* INSTEAD */ |
| 173152 | | - testcase( i==15 ); /* ADD */ |
| 173153 | | - testcase( i==16 ); /* DATABASE */ |
| 173154 | | - testcase( i==17 ); /* AS */ |
| 173155 | | - testcase( i==18 ); /* SELECT */ |
| 173156 | | - testcase( i==19 ); /* TABLE */ |
| 173157 | | - testcase( i==20 ); /* LEFT */ |
| 173158 | | - testcase( i==21 ); /* THEN */ |
| 173159 | | - testcase( i==22 ); /* END */ |
| 173160 | | - testcase( i==23 ); /* DEFERRABLE */ |
| 173161 | | - testcase( i==24 ); /* ELSE */ |
| 173162 | | - testcase( i==25 ); /* EXCLUDE */ |
| 173163 | | - testcase( i==26 ); /* DELETE */ |
| 173164 | | - testcase( i==27 ); /* TEMPORARY */ |
| 173165 | | - testcase( i==28 ); /* TEMP */ |
| 173166 | | - testcase( i==29 ); /* OR */ |
| 173167 | | - testcase( i==30 ); /* ISNULL */ |
| 173168 | | - testcase( i==31 ); /* NULLS */ |
| 173169 | | - testcase( i==32 ); /* SAVEPOINT */ |
| 173170 | | - testcase( i==33 ); /* INTERSECT */ |
| 173171 | | - testcase( i==34 ); /* TIES */ |
| 173172 | | - testcase( i==35 ); /* NOTNULL */ |
| 173173 | | - testcase( i==36 ); /* NOT */ |
| 173174 | | - testcase( i==37 ); /* NO */ |
| 173175 | | - testcase( i==38 ); /* NULL */ |
| 173176 | | - testcase( i==39 ); /* LIKE */ |
| 173177 | | - testcase( i==40 ); /* EXCEPT */ |
| 173178 | | - testcase( i==41 ); /* TRANSACTION */ |
| 173179 | | - testcase( i==42 ); /* ACTION */ |
| 173180 | | - testcase( i==43 ); /* ON */ |
| 173181 | | - testcase( i==44 ); /* NATURAL */ |
| 173182 | | - testcase( i==45 ); /* ALTER */ |
| 173183 | | - testcase( i==46 ); /* RAISE */ |
| 173184 | | - testcase( i==47 ); /* EXCLUSIVE */ |
| 173185 | | - testcase( i==48 ); /* EXISTS */ |
| 173186 | | - testcase( i==49 ); /* CONSTRAINT */ |
| 173187 | | - testcase( i==50 ); /* INTO */ |
| 173188 | | - testcase( i==51 ); /* OFFSET */ |
| 173189 | | - testcase( i==52 ); /* OF */ |
| 173190 | | - testcase( i==53 ); /* SET */ |
| 173191 | | - testcase( i==54 ); /* TRIGGER */ |
| 173192 | | - testcase( i==55 ); /* RANGE */ |
| 173193 | | - testcase( i==56 ); /* GENERATED */ |
| 173194 | | - testcase( i==57 ); /* DETACH */ |
| 173195 | | - testcase( i==58 ); /* HAVING */ |
| 173196 | | - testcase( i==59 ); /* GLOB */ |
| 173197 | | - testcase( i==60 ); /* BEGIN */ |
| 173198 | | - testcase( i==61 ); /* INNER */ |
| 173199 | | - testcase( i==62 ); /* REFERENCES */ |
| 173200 | | - testcase( i==63 ); /* UNIQUE */ |
| 173201 | | - testcase( i==64 ); /* QUERY */ |
| 173202 | | - testcase( i==65 ); /* WITHOUT */ |
| 173203 | | - testcase( i==66 ); /* WITH */ |
| 173204 | | - testcase( i==67 ); /* OUTER */ |
| 173205 | | - testcase( i==68 ); /* RELEASE */ |
| 173206 | | - testcase( i==69 ); /* ATTACH */ |
| 173207 | | - testcase( i==70 ); /* BETWEEN */ |
| 173208 | | - testcase( i==71 ); /* NOTHING */ |
| 173209 | | - testcase( i==72 ); /* GROUPS */ |
| 173210 | | - testcase( i==73 ); /* GROUP */ |
| 173211 | | - testcase( i==74 ); /* CASCADE */ |
| 173212 | | - testcase( i==75 ); /* ASC */ |
| 173213 | | - testcase( i==76 ); /* DEFAULT */ |
| 173214 | | - testcase( i==77 ); /* CASE */ |
| 173215 | | - testcase( i==78 ); /* COLLATE */ |
| 173216 | | - testcase( i==79 ); /* CREATE */ |
| 173217 | | - testcase( i==80 ); /* CURRENT_DATE */ |
| 173218 | | - testcase( i==81 ); /* IMMEDIATE */ |
| 173219 | | - testcase( i==82 ); /* JOIN */ |
| 173220 | | - testcase( i==83 ); /* INSERT */ |
| 173221 | | - testcase( i==84 ); /* MATCH */ |
| 173222 | | - testcase( i==85 ); /* PLAN */ |
| 173223 | | - testcase( i==86 ); /* ANALYZE */ |
| 173224 | | - testcase( i==87 ); /* PRAGMA */ |
| 173225 | | - testcase( i==88 ); /* MATERIALIZED */ |
| 173226 | | - testcase( i==89 ); /* DEFERRED */ |
| 173227 | | - testcase( i==90 ); /* DISTINCT */ |
| 173228 | | - testcase( i==91 ); /* IS */ |
| 173229 | | - testcase( i==92 ); /* UPDATE */ |
| 173230 | | - testcase( i==93 ); /* VALUES */ |
| 173231 | | - testcase( i==94 ); /* VIRTUAL */ |
| 173232 | | - testcase( i==95 ); /* ALWAYS */ |
| 173233 | | - testcase( i==96 ); /* WHEN */ |
| 173234 | | - testcase( i==97 ); /* WHERE */ |
| 173235 | | - testcase( i==98 ); /* RECURSIVE */ |
| 173236 | | - testcase( i==99 ); /* ABORT */ |
| 173237 | | - testcase( i==100 ); /* AFTER */ |
| 173238 | | - testcase( i==101 ); /* RENAME */ |
| 173239 | | - testcase( i==102 ); /* AND */ |
| 173240 | | - testcase( i==103 ); /* DROP */ |
| 173241 | | - testcase( i==104 ); /* PARTITION */ |
| 173242 | | - testcase( i==105 ); /* AUTOINCREMENT */ |
| 173243 | | - testcase( i==106 ); /* TO */ |
| 173244 | | - testcase( i==107 ); /* IN */ |
| 173245 | | - testcase( i==108 ); /* CAST */ |
| 173246 | | - testcase( i==109 ); /* COLUMN */ |
| 173247 | | - testcase( i==110 ); /* COMMIT */ |
| 173248 | | - testcase( i==111 ); /* CONFLICT */ |
| 173249 | | - testcase( i==112 ); /* CROSS */ |
| 173250 | | - testcase( i==113 ); /* CURRENT_TIMESTAMP */ |
| 173251 | | - testcase( i==114 ); /* CURRENT_TIME */ |
| 173252 | | - testcase( i==115 ); /* CURRENT */ |
| 173253 | | - testcase( i==116 ); /* PRECEDING */ |
| 173254 | | - testcase( i==117 ); /* FAIL */ |
| 173255 | | - testcase( i==118 ); /* LAST */ |
| 173256 | | - testcase( i==119 ); /* FILTER */ |
| 173257 | | - testcase( i==120 ); /* REPLACE */ |
| 173258 | | - testcase( i==121 ); /* FIRST */ |
| 173259 | | - testcase( i==122 ); /* FOLLOWING */ |
| 173260 | | - testcase( i==123 ); /* FROM */ |
| 173261 | | - testcase( i==124 ); /* FULL */ |
| 173262 | | - testcase( i==125 ); /* LIMIT */ |
| 173263 | | - testcase( i==126 ); /* IF */ |
| 173264 | | - testcase( i==127 ); /* ORDER */ |
| 173265 | | - testcase( i==128 ); /* RESTRICT */ |
| 173266 | | - testcase( i==129 ); /* OTHERS */ |
| 173267 | | - testcase( i==130 ); /* OVER */ |
| 173268 | | - testcase( i==131 ); /* RETURNING */ |
| 173269 | | - testcase( i==132 ); /* RIGHT */ |
| 173270 | | - testcase( i==133 ); /* ROLLBACK */ |
| 173271 | | - testcase( i==134 ); /* ROWS */ |
| 173272 | | - testcase( i==135 ); /* ROW */ |
| 173273 | | - testcase( i==136 ); /* UNBOUNDED */ |
| 173274 | | - testcase( i==137 ); /* UNION */ |
| 173275 | | - testcase( i==138 ); /* USING */ |
| 173276 | | - testcase( i==139 ); /* VACUUM */ |
| 173277 | | - testcase( i==140 ); /* VIEW */ |
| 173278 | | - testcase( i==141 ); /* WINDOW */ |
| 173279 | | - testcase( i==142 ); /* DO */ |
| 173280 | | - testcase( i==143 ); /* BY */ |
| 173281 | | - testcase( i==144 ); /* INITIALLY */ |
| 173282 | | - testcase( i==145 ); /* ALL */ |
| 173283 | | - testcase( i==146 ); /* PRIMARY */ |
| 173298 | + testcase( i==1 ); /* REINDEX */ |
| 173299 | + testcase( i==2 ); /* INDEXED */ |
| 173300 | + testcase( i==3 ); /* INDEX */ |
| 173301 | + testcase( i==4 ); /* DESC */ |
| 173302 | + testcase( i==5 ); /* ESCAPE */ |
| 173303 | + testcase( i==6 ); /* EACH */ |
| 173304 | + testcase( i==7 ); /* CHECK */ |
| 173305 | + testcase( i==8 ); /* KEY */ |
| 173306 | + testcase( i==9 ); /* BEFORE */ |
| 173307 | + testcase( i==10 ); /* FOREIGN */ |
| 173308 | + testcase( i==11 ); /* FOR */ |
| 173309 | + testcase( i==12 ); /* IGNORE */ |
| 173310 | + testcase( i==13 ); /* REGEXP */ |
| 173311 | + testcase( i==14 ); /* EXPLAIN */ |
| 173312 | + testcase( i==15 ); /* INSTEAD */ |
| 173313 | + testcase( i==16 ); /* ADD */ |
| 173314 | + testcase( i==17 ); /* DATABASE */ |
| 173315 | + testcase( i==18 ); /* AS */ |
| 173316 | + testcase( i==19 ); /* SELECT */ |
| 173317 | + testcase( i==20 ); /* TABLE */ |
| 173318 | + testcase( i==21 ); /* LEFT */ |
| 173319 | + testcase( i==22 ); /* THEN */ |
| 173320 | + testcase( i==23 ); /* END */ |
| 173321 | + testcase( i==24 ); /* DEFERRABLE */ |
| 173322 | + testcase( i==25 ); /* ELSE */ |
| 173323 | + testcase( i==26 ); /* EXCLUDE */ |
| 173324 | + testcase( i==27 ); /* DELETE */ |
| 173325 | + testcase( i==28 ); /* TEMPORARY */ |
| 173326 | + testcase( i==29 ); /* TEMP */ |
| 173327 | + testcase( i==30 ); /* OR */ |
| 173328 | + testcase( i==31 ); /* ISNULL */ |
| 173329 | + testcase( i==32 ); /* NULLS */ |
| 173330 | + testcase( i==33 ); /* SAVEPOINT */ |
| 173331 | + testcase( i==34 ); /* INTERSECT */ |
| 173332 | + testcase( i==35 ); /* TIES */ |
| 173333 | + testcase( i==36 ); /* NOTNULL */ |
| 173334 | + testcase( i==37 ); /* NOT */ |
| 173335 | + testcase( i==38 ); /* NO */ |
| 173336 | + testcase( i==39 ); /* NULL */ |
| 173337 | + testcase( i==40 ); /* LIKE */ |
| 173338 | + testcase( i==41 ); /* EXCEPT */ |
| 173339 | + testcase( i==42 ); /* TRANSACTION */ |
| 173340 | + testcase( i==43 ); /* ACTION */ |
| 173341 | + testcase( i==44 ); /* ON */ |
| 173342 | + testcase( i==45 ); /* NATURAL */ |
| 173343 | + testcase( i==46 ); /* ALTER */ |
| 173344 | + testcase( i==47 ); /* RAISE */ |
| 173345 | + testcase( i==48 ); /* EXCLUSIVE */ |
| 173346 | + testcase( i==49 ); /* EXISTS */ |
| 173347 | + testcase( i==50 ); /* CONSTRAINT */ |
| 173348 | + testcase( i==51 ); /* INTO */ |
| 173349 | + testcase( i==52 ); /* OFFSET */ |
| 173350 | + testcase( i==53 ); /* OF */ |
| 173351 | + testcase( i==54 ); /* SET */ |
| 173352 | + testcase( i==55 ); /* TRIGGER */ |
| 173353 | + testcase( i==56 ); /* RANGE */ |
| 173354 | + testcase( i==57 ); /* GENERATED */ |
| 173355 | + testcase( i==58 ); /* DETACH */ |
| 173356 | + testcase( i==59 ); /* HAVING */ |
| 173357 | + testcase( i==60 ); /* GLOB */ |
| 173358 | + testcase( i==61 ); /* BEGIN */ |
| 173359 | + testcase( i==62 ); /* INNER */ |
| 173360 | + testcase( i==63 ); /* REFERENCES */ |
| 173361 | + testcase( i==64 ); /* UNIQUE */ |
| 173362 | + testcase( i==65 ); /* QUERY */ |
| 173363 | + testcase( i==66 ); /* WITHOUT */ |
| 173364 | + testcase( i==67 ); /* WITH */ |
| 173365 | + testcase( i==68 ); /* OUTER */ |
| 173366 | + testcase( i==69 ); /* RELEASE */ |
| 173367 | + testcase( i==70 ); /* ATTACH */ |
| 173368 | + testcase( i==71 ); /* BETWEEN */ |
| 173369 | + testcase( i==72 ); /* NOTHING */ |
| 173370 | + testcase( i==73 ); /* GROUPS */ |
| 173371 | + testcase( i==74 ); /* GROUP */ |
| 173372 | + testcase( i==75 ); /* CASCADE */ |
| 173373 | + testcase( i==76 ); /* ASC */ |
| 173374 | + testcase( i==77 ); /* DEFAULT */ |
| 173375 | + testcase( i==78 ); /* CASE */ |
| 173376 | + testcase( i==79 ); /* COLLATE */ |
| 173377 | + testcase( i==80 ); /* CREATE */ |
| 173378 | + testcase( i==81 ); /* CURRENT_DATE */ |
| 173379 | + testcase( i==82 ); /* IMMEDIATE */ |
| 173380 | + testcase( i==83 ); /* JOIN */ |
| 173381 | + testcase( i==84 ); /* INSERT */ |
| 173382 | + testcase( i==85 ); /* MATCH */ |
| 173383 | + testcase( i==86 ); /* PLAN */ |
| 173384 | + testcase( i==87 ); /* ANALYZE */ |
| 173385 | + testcase( i==88 ); /* PRAGMA */ |
| 173386 | + testcase( i==89 ); /* MATERIALIZED */ |
| 173387 | + testcase( i==90 ); /* DEFERRED */ |
| 173388 | + testcase( i==91 ); /* DISTINCT */ |
| 173389 | + testcase( i==92 ); /* IS */ |
| 173390 | + testcase( i==93 ); /* UPDATE */ |
| 173391 | + testcase( i==94 ); /* VALUES */ |
| 173392 | + testcase( i==95 ); /* VIRTUAL */ |
| 173393 | + testcase( i==96 ); /* ALWAYS */ |
| 173394 | + testcase( i==97 ); /* WHEN */ |
| 173395 | + testcase( i==98 ); /* WHERE */ |
| 173396 | + testcase( i==99 ); /* RECURSIVE */ |
| 173397 | + testcase( i==100 ); /* ABORT */ |
| 173398 | + testcase( i==101 ); /* AFTER */ |
| 173399 | + testcase( i==102 ); /* RENAME */ |
| 173400 | + testcase( i==103 ); /* AND */ |
| 173401 | + testcase( i==104 ); /* DROP */ |
| 173402 | + testcase( i==105 ); /* PARTITION */ |
| 173403 | + testcase( i==106 ); /* AUTOINCREMENT */ |
| 173404 | + testcase( i==107 ); /* TO */ |
| 173405 | + testcase( i==108 ); /* IN */ |
| 173406 | + testcase( i==109 ); /* CAST */ |
| 173407 | + testcase( i==110 ); /* COLUMN */ |
| 173408 | + testcase( i==111 ); /* COMMIT */ |
| 173409 | + testcase( i==112 ); /* CONFLICT */ |
| 173410 | + testcase( i==113 ); /* CROSS */ |
| 173411 | + testcase( i==114 ); /* CURRENT_TIMESTAMP */ |
| 173412 | + testcase( i==115 ); /* CURRENT_TIME */ |
| 173413 | + testcase( i==116 ); /* CURRENT */ |
| 173414 | + testcase( i==117 ); /* PRECEDING */ |
| 173415 | + testcase( i==118 ); /* FAIL */ |
| 173416 | + testcase( i==119 ); /* LAST */ |
| 173417 | + testcase( i==120 ); /* FILTER */ |
| 173418 | + testcase( i==121 ); /* REPLACE */ |
| 173419 | + testcase( i==122 ); /* FIRST */ |
| 173420 | + testcase( i==123 ); /* FOLLOWING */ |
| 173421 | + testcase( i==124 ); /* FROM */ |
| 173422 | + testcase( i==125 ); /* FULL */ |
| 173423 | + testcase( i==126 ); /* LIMIT */ |
| 173424 | + testcase( i==127 ); /* IF */ |
| 173425 | + testcase( i==128 ); /* ORDER */ |
| 173426 | + testcase( i==129 ); /* RESTRICT */ |
| 173427 | + testcase( i==130 ); /* OTHERS */ |
| 173428 | + testcase( i==131 ); /* OVER */ |
| 173429 | + testcase( i==132 ); /* RETURNING */ |
| 173430 | + testcase( i==133 ); /* RIGHT */ |
| 173431 | + testcase( i==134 ); /* ROLLBACK */ |
| 173432 | + testcase( i==135 ); /* ROWS */ |
| 173433 | + testcase( i==136 ); /* ROW */ |
| 173434 | + testcase( i==137 ); /* UNBOUNDED */ |
| 173435 | + testcase( i==138 ); /* UNION */ |
| 173436 | + testcase( i==139 ); /* USING */ |
| 173437 | + testcase( i==140 ); /* VACUUM */ |
| 173438 | + testcase( i==141 ); /* VIEW */ |
| 173439 | + testcase( i==142 ); /* WINDOW */ |
| 173440 | + testcase( i==143 ); /* DO */ |
| 173441 | + testcase( i==144 ); /* BY */ |
| 173442 | + testcase( i==145 ); /* INITIALLY */ |
| 173443 | + testcase( i==146 ); /* ALL */ |
| 173444 | + testcase( i==147 ); /* PRIMARY */ |
| 173284 | 173445 | *pType = aKWCode[i]; |
| 173285 | 173446 | break; |
| 173286 | 173447 | } |
| 173287 | 173448 | } |
| 173288 | 173449 | return n; |
| | @@ -173293,10 +173454,11 @@ |
| 173293 | 173454 | return id; |
| 173294 | 173455 | } |
| 173295 | 173456 | #define SQLITE_N_KEYWORD 147 |
| 173296 | 173457 | SQLITE_API int sqlite3_keyword_name(int i,const char **pzName,int *pnName){ |
| 173297 | 173458 | if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR; |
| 173459 | + i++; |
| 173298 | 173460 | *pzName = zKWText + aKWOffset[i]; |
| 173299 | 173461 | *pnName = aKWLen[i]; |
| 173300 | 173462 | return SQLITE_OK; |
| 173301 | 173463 | } |
| 173302 | 173464 | SQLITE_API int sqlite3_keyword_count(void){ return SQLITE_N_KEYWORD; } |
| | @@ -199991,10 +200153,31 @@ |
| 199991 | 200153 | int i; |
| 199992 | 200154 | for(i=0; i<4; i++) if( !sqlite3Isxdigit(z[i]) ) return 0; |
| 199993 | 200155 | return 1; |
| 199994 | 200156 | } |
| 199995 | 200157 | |
| 200158 | +#ifdef SQLITE_ENABLE_JSON_NAN_INF |
| 200159 | +/* |
| 200160 | +** Extra floating-point literals to allow in JSON. |
| 200161 | +*/ |
| 200162 | +static const struct NanInfName { |
| 200163 | + char c1; |
| 200164 | + char c2; |
| 200165 | + char n; |
| 200166 | + char eType; |
| 200167 | + char nRepl; |
| 200168 | + char *zMatch; |
| 200169 | + char *zRepl; |
| 200170 | +} aNanInfName[] = { |
| 200171 | + { 'i', 'I', 3, JSON_REAL, 7, "inf", "9.0e999" }, |
| 200172 | + { 'i', 'I', 8, JSON_REAL, 7, "infinity", "9.0e999" }, |
| 200173 | + { 'n', 'N', 3, JSON_NULL, 4, "NaN", "null" }, |
| 200174 | + { 'q', 'Q', 4, JSON_NULL, 4, "QNaN", "null" }, |
| 200175 | + { 's', 'S', 4, JSON_NULL, 4, "SNaN", "null" }, |
| 200176 | +}; |
| 200177 | +#endif /* SQLITE_ENABLE_JSON_NAN_INF */ |
| 200178 | + |
| 199996 | 200179 | /* |
| 199997 | 200180 | ** Parse a single JSON value which begins at pParse->zJson[i]. Return the |
| 199998 | 200181 | ** index of the first character past the end of the value parsed. |
| 199999 | 200182 | ** |
| 200000 | 200183 | ** Return negative for a syntax error. Special cases: return -2 if the |
| | @@ -200136,10 +200319,28 @@ |
| 200136 | 200319 | c = z[j+1]; |
| 200137 | 200320 | } |
| 200138 | 200321 | if( c<'0' || c>'9' ) return -1; |
| 200139 | 200322 | continue; |
| 200140 | 200323 | } |
| 200324 | +#ifdef SQLITE_ENABLE_JSON_NAN_INF |
| 200325 | + /* Non-standard JSON: Allow "-Inf" (in any case) |
| 200326 | + ** to be understood as floating point literals. */ |
| 200327 | + if( (c=='i' || c=='I') |
| 200328 | + && j==i+1 |
| 200329 | + && z[i]=='-' |
| 200330 | + && sqlite3StrNICmp(&z[j], "inf",3)==0 |
| 200331 | + ){ |
| 200332 | + if( !sqlite3Isalnum(z[j+3]) ){ |
| 200333 | + jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999"); |
| 200334 | + return i+4; |
| 200335 | + }else if( (sqlite3StrNICmp(&z[j],"infinity",8)==0 && |
| 200336 | + !sqlite3Isalnum(z[j+8])) ){ |
| 200337 | + jsonParseAddNode(pParse, JSON_REAL, 8, "-9.0e999"); |
| 200338 | + return i+9; |
| 200339 | + } |
| 200340 | + } |
| 200341 | +#endif |
| 200141 | 200342 | break; |
| 200142 | 200343 | } |
| 200143 | 200344 | if( z[j-1]<'0' ) return -1; |
| 200144 | 200345 | jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT, |
| 200145 | 200346 | j - i, &z[i]); |
| | @@ -200149,10 +200350,24 @@ |
| 200149 | 200350 | }else if( c==']' ){ |
| 200150 | 200351 | return -3; /* End of [...] */ |
| 200151 | 200352 | }else if( c==0 ){ |
| 200152 | 200353 | return 0; /* End of file */ |
| 200153 | 200354 | }else{ |
| 200355 | +#ifdef SQLITE_ENABLE_JSON_NAN_INF |
| 200356 | + int k, nn; |
| 200357 | + for(k=0; k<sizeof(aNanInfName)/sizeof(aNanInfName[0]); k++){ |
| 200358 | + if( c!=aNanInfName[k].c1 && c!=aNanInfName[k].c2 ) continue; |
| 200359 | + nn = aNanInfName[k].n; |
| 200360 | + if( sqlite3StrNICmp(&z[i], aNanInfName[k].zMatch, nn)!=0 ){ |
| 200361 | + continue; |
| 200362 | + } |
| 200363 | + if( sqlite3Isalnum(z[i+nn]) ) continue; |
| 200364 | + jsonParseAddNode(pParse, aNanInfName[k].eType, |
| 200365 | + aNanInfName[k].nRepl, aNanInfName[k].zRepl); |
| 200366 | + return i + nn; |
| 200367 | + } |
| 200368 | +#endif |
| 200154 | 200369 | return -1; /* Syntax error */ |
| 200155 | 200370 | } |
| 200156 | 200371 | } |
| 200157 | 200372 | |
| 200158 | 200373 | /* |
| | @@ -212971,19 +213186,28 @@ |
| 212971 | 213186 | |
| 212972 | 213187 | iOff = (i64)(pFrame->iDbPage-1) * p->pgsz; |
| 212973 | 213188 | p->rc = pDb->pMethods->xWrite(pDb, p->aBuf, p->pgsz, iOff); |
| 212974 | 213189 | } |
| 212975 | 213190 | |
| 213191 | +/* |
| 213192 | +** This value is copied from the definition of ZIPVFS_CTRL_FILE_POINTER |
| 213193 | +** in zipvfs.h. |
| 213194 | +*/ |
| 213195 | +#define RBU_ZIPVFS_CTRL_FILE_POINTER 230439 |
| 212976 | 213196 | |
| 212977 | 213197 | /* |
| 212978 | 213198 | ** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if |
| 212979 | 213199 | ** successful, or an SQLite error code otherwise. |
| 212980 | 213200 | */ |
| 212981 | 213201 | static int rbuLockDatabase(sqlite3 *db){ |
| 212982 | 213202 | int rc = SQLITE_OK; |
| 212983 | 213203 | sqlite3_file *fd = 0; |
| 212984 | | - sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd); |
| 213204 | + |
| 213205 | + sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd); |
| 213206 | + if( fd==0 ){ |
| 213207 | + sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd); |
| 213208 | + } |
| 212985 | 213209 | |
| 212986 | 213210 | if( fd->pMethods ){ |
| 212987 | 213211 | rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED); |
| 212988 | 213212 | if( rc==SQLITE_OK ){ |
| 212989 | 213213 | rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE); |
| | @@ -216218,10 +216442,11 @@ |
| 216218 | 216442 | (void)argc; |
| 216219 | 216443 | (void)argv; |
| 216220 | 216444 | (void)pzErr; |
| 216221 | 216445 | |
| 216222 | 216446 | sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY); |
| 216447 | + sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS); |
| 216223 | 216448 | rc = sqlite3_declare_vtab(db, |
| 216224 | 216449 | "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)"); |
| 216225 | 216450 | if( rc==SQLITE_OK ){ |
| 216226 | 216451 | pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable)); |
| 216227 | 216452 | if( pTab==0 ) rc = SQLITE_NOMEM_BKPT; |
| | @@ -216301,11 +216526,10 @@ |
| 216301 | 216526 | && pIdxInfo->aOrderBy[0].iColumn<=0 |
| 216302 | 216527 | && pIdxInfo->aOrderBy[0].desc==0 |
| 216303 | 216528 | ){ |
| 216304 | 216529 | pIdxInfo->orderByConsumed = 1; |
| 216305 | 216530 | } |
| 216306 | | - sqlite3VtabUsesAllSchemas(pIdxInfo); |
| 216307 | 216531 | return SQLITE_OK; |
| 216308 | 216532 | } |
| 216309 | 216533 | |
| 216310 | 216534 | /* |
| 216311 | 216535 | ** Open a new dbpagevfs cursor. |
| | @@ -240797,11 +241021,11 @@ |
| 240797 | 241021 | int nArg, /* Number of args */ |
| 240798 | 241022 | sqlite3_value **apUnused /* Function arguments */ |
| 240799 | 241023 | ){ |
| 240800 | 241024 | assert( nArg==0 ); |
| 240801 | 241025 | UNUSED_PARAM2(nArg, apUnused); |
| 240802 | | - sqlite3_result_text(pCtx, "fts5: 2023-04-01 12:22:57 33ac62d8eec56eb71f20ccd28a5d6e4e8051522feb2db0199abee9e18ce1f64e", -1, SQLITE_TRANSIENT); |
| 241026 | + sqlite3_result_text(pCtx, "fts5: 2023-04-10 13:20:51 49ba030080dd00b4fdf788fd3da057b333e705fa0fe37d653e2461bf96ca3785", -1, SQLITE_TRANSIENT); |
| 240803 | 241027 | } |
| 240804 | 241028 | |
| 240805 | 241029 | /* |
| 240806 | 241030 | ** Return true if zName is the extension on one of the shadow tables used |
| 240807 | 241031 | ** by this module. |
| 240808 | 241032 | |