| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.50.0. By combining all the individual C code files into this |
| 3 | +** version 3.51.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. |
| | @@ -16,11 +16,11 @@ |
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | | -** dfc790f998f450d9c35e3ba1c8c89c17466c with changes in files: |
| 21 | +** ea1754f7d8a770477a1b19b606b27724fdc0 with changes in files: |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| | @@ -463,13 +463,13 @@ |
| 463 | 463 | ** |
| 464 | 464 | ** See also: [sqlite3_libversion()], |
| 465 | 465 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 466 | 466 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 467 | 467 | */ |
| 468 | | -#define SQLITE_VERSION "3.50.0" |
| 469 | | -#define SQLITE_VERSION_NUMBER 3050000 |
| 470 | | -#define SQLITE_SOURCE_ID "2025-05-29 14:26:00 dfc790f998f450d9c35e3ba1c8c89c17466cb559f87b0239e4aab9d34e28f742" |
| 468 | +#define SQLITE_VERSION "3.51.0" |
| 469 | +#define SQLITE_VERSION_NUMBER 3051000 |
| 470 | +#define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5" |
| 471 | 471 | |
| 472 | 472 | /* |
| 473 | 473 | ** CAPI3REF: Run-Time Library Version Numbers |
| 474 | 474 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 475 | 475 | ** |
| | @@ -15174,11 +15174,11 @@ |
| 15174 | 15174 | /* |
| 15175 | 15175 | ** GCC does not define the offsetof() macro so we'll have to do it |
| 15176 | 15176 | ** ourselves. |
| 15177 | 15177 | */ |
| 15178 | 15178 | #ifndef offsetof |
| 15179 | | -#define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD)) |
| 15179 | +# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0)) |
| 15180 | 15180 | #endif |
| 15181 | 15181 | |
| 15182 | 15182 | /* |
| 15183 | 15183 | ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as |
| 15184 | 15184 | ** to avoid complaints from -fsanitize=strict-bounds. |
| | @@ -17401,11 +17401,11 @@ |
| 17401 | 17401 | SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*); |
| 17402 | 17402 | #endif |
| 17403 | 17403 | SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*); |
| 17404 | 17404 | SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*); |
| 17405 | 17405 | |
| 17406 | | -SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*); |
| 17406 | +SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(int,const void*,UnpackedRecord*); |
| 17407 | 17407 | SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*); |
| 17408 | 17408 | SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int); |
| 17409 | 17409 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*); |
| 17410 | 17410 | |
| 17411 | 17411 | typedef int (*RecordCompare)(int,const void*,UnpackedRecord*); |
| | @@ -18701,10 +18701,11 @@ |
| 18701 | 18701 | #define SQLITE_AFF_TEXT 0x42 /* 'B' */ |
| 18702 | 18702 | #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */ |
| 18703 | 18703 | #define SQLITE_AFF_INTEGER 0x44 /* 'D' */ |
| 18704 | 18704 | #define SQLITE_AFF_REAL 0x45 /* 'E' */ |
| 18705 | 18705 | #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */ |
| 18706 | +#define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */ |
| 18706 | 18707 | |
| 18707 | 18708 | #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC) |
| 18708 | 18709 | |
| 18709 | 18710 | /* |
| 18710 | 18711 | ** The SQLITE_AFF_MASK values masks off the significant bits of an |
| | @@ -19016,13 +19017,19 @@ |
| 19016 | 19017 | /* |
| 19017 | 19018 | ** An instance of the following structure is passed as the first |
| 19018 | 19019 | ** argument to sqlite3VdbeKeyCompare and is used to control the |
| 19019 | 19020 | ** comparison of the two index keys. |
| 19020 | 19021 | ** |
| 19021 | | -** Note that aSortOrder[] and aColl[] have nField+1 slots. There |
| 19022 | | -** are nField slots for the columns of an index then one extra slot |
| 19023 | | -** for the rowid at the end. |
| 19022 | +** The aSortOrder[] and aColl[] arrays have nAllField slots each. There |
| 19023 | +** are nKeyField slots for the columns of an index then extra slots |
| 19024 | +** for the rowid or key at the end. The aSortOrder array is located after |
| 19025 | +** the aColl[] array. |
| 19026 | +** |
| 19027 | +** If SQLITE_ENABLE_PREUPDATE_HOOK is defined, then aSortFlags might be NULL |
| 19028 | +** to indicate that this object is for use by a preupdate hook. When aSortFlags |
| 19029 | +** is NULL, then nAllField is uninitialized and no space is allocated for |
| 19030 | +** aColl[], so those fields may not be used. |
| 19024 | 19031 | */ |
| 19025 | 19032 | struct KeyInfo { |
| 19026 | 19033 | u32 nRef; /* Number of references to this KeyInfo object */ |
| 19027 | 19034 | u8 enc; /* Text encoding - one of the SQLITE_UTF* values */ |
| 19028 | 19035 | u16 nKeyField; /* Number of key columns in the index */ |
| | @@ -19030,12 +19037,21 @@ |
| 19030 | 19037 | sqlite3 *db; /* The database connection */ |
| 19031 | 19038 | u8 *aSortFlags; /* Sort order for each column. */ |
| 19032 | 19039 | CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */ |
| 19033 | 19040 | }; |
| 19034 | 19041 | |
| 19035 | | -/* The size (in bytes) of a KeyInfo object with up to N fields */ |
| 19042 | +/* The size (in bytes) of a KeyInfo object with up to N fields. This includes |
| 19043 | +** the main body of the KeyInfo object and the aColl[] array of N elements, |
| 19044 | +** but does not count the memory used to hold aSortFlags[]. */ |
| 19036 | 19045 | #define SZ_KEYINFO(N) (offsetof(KeyInfo,aColl) + (N)*sizeof(CollSeq*)) |
| 19046 | + |
| 19047 | +/* The size of a bare KeyInfo with no aColl[] entries */ |
| 19048 | +#if FLEXARRAY+1 > 1 |
| 19049 | +# define SZ_KEYINFO_0 offsetof(KeyInfo,aColl) |
| 19050 | +#else |
| 19051 | +# define SZ_KEYINFO_0 sizeof(KeyInfo) |
| 19052 | +#endif |
| 19037 | 19053 | |
| 19038 | 19054 | /* |
| 19039 | 19055 | ** Allowed bit values for entries in the KeyInfo.aSortFlags[] array. |
| 19040 | 19056 | */ |
| 19041 | 19057 | #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */ |
| | @@ -19051,23 +19067,22 @@ |
| 19051 | 19067 | ** the OP_MakeRecord opcode of the VDBE and is disassembled by the |
| 19052 | 19068 | ** OP_Column opcode. |
| 19053 | 19069 | ** |
| 19054 | 19070 | ** An instance of this object serves as a "key" for doing a search on |
| 19055 | 19071 | ** an index b+tree. The goal of the search is to find the entry that |
| 19056 | | -** is closed to the key described by this object. This object might hold |
| 19057 | | -** just a prefix of the key. The number of fields is given by |
| 19058 | | -** pKeyInfo->nField. |
| 19072 | +** is closest to the key described by this object. This object might hold |
| 19073 | +** just a prefix of the key. The number of fields is given by nField. |
| 19059 | 19074 | ** |
| 19060 | 19075 | ** The r1 and r2 fields are the values to return if this key is less than |
| 19061 | 19076 | ** or greater than a key in the btree, respectively. These are normally |
| 19062 | 19077 | ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree |
| 19063 | 19078 | ** is in DESC order. |
| 19064 | 19079 | ** |
| 19065 | 19080 | ** The key comparison functions actually return default_rc when they find |
| 19066 | 19081 | ** an equals comparison. default_rc can be -1, 0, or +1. If there are |
| 19067 | 19082 | ** multiple entries in the b-tree with the same key (when only looking |
| 19068 | | -** at the first pKeyInfo->nFields,) then default_rc can be set to -1 to |
| 19083 | +** at the first nField elements) then default_rc can be set to -1 to |
| 19069 | 19084 | ** cause the search to find the last match, or +1 to cause the search to |
| 19070 | 19085 | ** find the first match. |
| 19071 | 19086 | ** |
| 19072 | 19087 | ** The key comparison functions will set eqSeen to true if they ever |
| 19073 | 19088 | ** get and equal results when comparing this structure to a b-tree record. |
| | @@ -19075,12 +19090,12 @@ |
| 19075 | 19090 | ** before the first match or immediately after the last match. The |
| 19076 | 19091 | ** eqSeen field will indicate whether or not an exact match exists in the |
| 19077 | 19092 | ** b-tree. |
| 19078 | 19093 | */ |
| 19079 | 19094 | struct UnpackedRecord { |
| 19080 | | - KeyInfo *pKeyInfo; /* Collation and sort-order information */ |
| 19081 | | - Mem *aMem; /* Values */ |
| 19095 | + KeyInfo *pKeyInfo; /* Comparison info for the index that is unpacked */ |
| 19096 | + Mem *aMem; /* Values for columns of the index */ |
| 19082 | 19097 | union { |
| 19083 | 19098 | char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */ |
| 19084 | 19099 | i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */ |
| 19085 | 19100 | } u; |
| 19086 | 19101 | int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */ |
| | @@ -24132,11 +24147,11 @@ |
| 24132 | 24147 | Mem oldipk; /* Memory cell holding "old" IPK value */ |
| 24133 | 24148 | Mem *aNew; /* Array of new.* values */ |
| 24134 | 24149 | Table *pTab; /* Schema object being updated */ |
| 24135 | 24150 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 24136 | 24151 | sqlite3_value **apDflt; /* Array of default values, if required */ |
| 24137 | | - u8 keyinfoSpace[SZ_KEYINFO(0)]; /* Space to hold pKeyinfo[0] content */ |
| 24152 | + u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */ |
| 24138 | 24153 | }; |
| 24139 | 24154 | |
| 24140 | 24155 | /* |
| 24141 | 24156 | ** An instance of this object is used to pass an vector of values into |
| 24142 | 24157 | ** OP_VFilter, the xFilter method of a virtual table. The vector is the |
| | @@ -43872,25 +43887,24 @@ |
| 43872 | 43887 | assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); |
| 43873 | 43888 | |
| 43874 | 43889 | /* Check that, if this to be a blocking lock, no locks that occur later |
| 43875 | 43890 | ** in the following list than the lock being obtained are already held: |
| 43876 | 43891 | ** |
| 43877 | | - ** 1. Checkpointer lock (ofst==1). |
| 43878 | | - ** 2. Write lock (ofst==0). |
| 43879 | | - ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 43892 | + ** 1. Recovery lock (ofst==2). |
| 43893 | + ** 2. Checkpointer lock (ofst==1). |
| 43894 | + ** 3. Write lock (ofst==0). |
| 43895 | + ** 4. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 43880 | 43896 | ** |
| 43881 | 43897 | ** In other words, if this is a blocking lock, none of the locks that |
| 43882 | 43898 | ** occur later in the above list than the lock being obtained may be |
| 43883 | 43899 | ** held. |
| 43884 | | - ** |
| 43885 | | - ** It is not permitted to block on the RECOVER lock. |
| 43886 | 43900 | */ |
| 43887 | 43901 | #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG) |
| 43888 | 43902 | { |
| 43889 | 43903 | u16 lockMask = (p->exclMask|p->sharedMask); |
| 43890 | 43904 | assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || ( |
| 43891 | | - (ofst!=2) /* not RECOVER */ |
| 43905 | + (ofst!=2 || lockMask==0) |
| 43892 | 43906 | && (ofst!=1 || lockMask==0 || lockMask==2) |
| 43893 | 43907 | && (ofst!=0 || lockMask<3) |
| 43894 | 43908 | && (ofst<3 || lockMask<(1<<ofst)) |
| 43895 | 43909 | )); |
| 43896 | 43910 | } |
| | @@ -49847,11 +49861,15 @@ |
| 49847 | 49861 | DWORD nDelay = (nMs==0 ? INFINITE : nMs); |
| 49848 | 49862 | DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay); |
| 49849 | 49863 | if( res==WAIT_OBJECT_0 ){ |
| 49850 | 49864 | ret = TRUE; |
| 49851 | 49865 | }else if( res==WAIT_TIMEOUT ){ |
| 49866 | +#if SQLITE_ENABLE_SETLK_TIMEOUT==1 |
| 49852 | 49867 | rc = SQLITE_BUSY_TIMEOUT; |
| 49868 | +#else |
| 49869 | + rc = SQLITE_BUSY; |
| 49870 | +#endif |
| 49853 | 49871 | }else{ |
| 49854 | 49872 | /* Some other error has occurred */ |
| 49855 | 49873 | rc = SQLITE_IOERR_LOCK; |
| 49856 | 49874 | } |
| 49857 | 49875 | |
| | @@ -51658,25 +51676,24 @@ |
| 51658 | 51676 | assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); |
| 51659 | 51677 | |
| 51660 | 51678 | /* Check that, if this to be a blocking lock, no locks that occur later |
| 51661 | 51679 | ** in the following list than the lock being obtained are already held: |
| 51662 | 51680 | ** |
| 51663 | | - ** 1. Checkpointer lock (ofst==1). |
| 51664 | | - ** 2. Write lock (ofst==0). |
| 51665 | | - ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 51681 | + ** 1. Recovery lock (ofst==2). |
| 51682 | + ** 2. Checkpointer lock (ofst==1). |
| 51683 | + ** 3. Write lock (ofst==0). |
| 51684 | + ** 4. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 51666 | 51685 | ** |
| 51667 | 51686 | ** In other words, if this is a blocking lock, none of the locks that |
| 51668 | 51687 | ** occur later in the above list than the lock being obtained may be |
| 51669 | 51688 | ** held. |
| 51670 | | - ** |
| 51671 | | - ** It is not permitted to block on the RECOVER lock. |
| 51672 | 51689 | */ |
| 51673 | 51690 | #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG) |
| 51674 | 51691 | { |
| 51675 | 51692 | u16 lockMask = (p->exclMask|p->sharedMask); |
| 51676 | 51693 | assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || ( |
| 51677 | | - (ofst!=2) /* not RECOVER */ |
| 51694 | + (ofst!=2 || lockMask==0) |
| 51678 | 51695 | && (ofst!=1 || lockMask==0 || lockMask==2) |
| 51679 | 51696 | && (ofst!=0 || lockMask<3) |
| 51680 | 51697 | && (ofst<3 || lockMask<(1<<ofst)) |
| 51681 | 51698 | )); |
| 51682 | 51699 | } |
| | @@ -58748,10 +58765,13 @@ |
| 58748 | 58765 | PCache *pPCache; /* Pointer to page cache object */ |
| 58749 | 58766 | #ifndef SQLITE_OMIT_WAL |
| 58750 | 58767 | Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */ |
| 58751 | 58768 | char *zWal; /* File name for write-ahead log */ |
| 58752 | 58769 | #endif |
| 58770 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 58771 | + sqlite3 *dbWal; |
| 58772 | +#endif |
| 58753 | 58773 | }; |
| 58754 | 58774 | |
| 58755 | 58775 | /* |
| 58756 | 58776 | ** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains |
| 58757 | 58777 | ** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS |
| | @@ -65629,10 +65649,15 @@ |
| 65629 | 65649 | if( rc==SQLITE_OK ){ |
| 65630 | 65650 | rc = sqlite3WalOpen(pPager->pVfs, |
| 65631 | 65651 | pPager->fd, pPager->zWal, pPager->exclusiveMode, |
| 65632 | 65652 | pPager->journalSizeLimit, &pPager->pWal |
| 65633 | 65653 | ); |
| 65654 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 65655 | + if( rc==SQLITE_OK ){ |
| 65656 | + sqlite3WalDb(pPager->pWal, pPager->dbWal); |
| 65657 | + } |
| 65658 | +#endif |
| 65634 | 65659 | } |
| 65635 | 65660 | pagerFixMaplimit(pPager); |
| 65636 | 65661 | |
| 65637 | 65662 | return rc; |
| 65638 | 65663 | } |
| | @@ -65748,10 +65773,11 @@ |
| 65748 | 65773 | /* |
| 65749 | 65774 | ** Set the database handle used by the wal layer to determine if |
| 65750 | 65775 | ** blocking locks are required. |
| 65751 | 65776 | */ |
| 65752 | 65777 | SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){ |
| 65778 | + pPager->dbWal = db; |
| 65753 | 65779 | if( pagerUseWal(pPager) ){ |
| 65754 | 65780 | sqlite3WalDb(pPager->pWal, db); |
| 65755 | 65781 | } |
| 65756 | 65782 | } |
| 65757 | 65783 | #endif |
| | @@ -68921,11 +68947,10 @@ |
| 68921 | 68947 | assert( rc==SQLITE_OK ); |
| 68922 | 68948 | if( pWal->bShmUnreliable==0 ){ |
| 68923 | 68949 | rc = walIndexReadHdr(pWal, pChanged); |
| 68924 | 68950 | } |
| 68925 | 68951 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 68926 | | - walDisableBlocking(pWal); |
| 68927 | 68952 | if( rc==SQLITE_BUSY_TIMEOUT ){ |
| 68928 | 68953 | rc = SQLITE_BUSY; |
| 68929 | 68954 | *pCnt |= WAL_RETRY_BLOCKED_MASK; |
| 68930 | 68955 | } |
| 68931 | 68956 | #endif |
| | @@ -68936,10 +68961,11 @@ |
| 68936 | 68961 | ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY |
| 68937 | 68962 | ** would be technically correct. But the race is benign since with |
| 68938 | 68963 | ** WAL_RETRY this routine will be called again and will probably be |
| 68939 | 68964 | ** right on the second iteration. |
| 68940 | 68965 | */ |
| 68966 | + (void)walEnableBlocking(pWal); |
| 68941 | 68967 | if( pWal->apWiData[0]==0 ){ |
| 68942 | 68968 | /* This branch is taken when the xShmMap() method returns SQLITE_BUSY. |
| 68943 | 68969 | ** We assume this is a transient condition, so return WAL_RETRY. The |
| 68944 | 68970 | ** xShmMap() implementation used by the default unix and win32 VFS |
| 68945 | 68971 | ** modules may return SQLITE_BUSY due to a race condition in the |
| | @@ -68952,10 +68978,11 @@ |
| 68952 | 68978 | rc = WAL_RETRY; |
| 68953 | 68979 | }else if( rc==SQLITE_BUSY ){ |
| 68954 | 68980 | rc = SQLITE_BUSY_RECOVERY; |
| 68955 | 68981 | } |
| 68956 | 68982 | } |
| 68983 | + walDisableBlocking(pWal); |
| 68957 | 68984 | if( rc!=SQLITE_OK ){ |
| 68958 | 68985 | return rc; |
| 68959 | 68986 | } |
| 68960 | 68987 | else if( pWal->bShmUnreliable ){ |
| 68961 | 68988 | return walBeginShmUnreliable(pWal, pChanged); |
| | @@ -72401,11 +72428,11 @@ |
| 72401 | 72428 | if( pKey ){ |
| 72402 | 72429 | KeyInfo *pKeyInfo = pCur->pKeyInfo; |
| 72403 | 72430 | assert( nKey==(i64)(int)nKey ); |
| 72404 | 72431 | pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo); |
| 72405 | 72432 | if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT; |
| 72406 | | - sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey); |
| 72433 | + sqlite3VdbeRecordUnpack((int)nKey, pKey, pIdxKey); |
| 72407 | 72434 | if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){ |
| 72408 | 72435 | rc = SQLITE_CORRUPT_BKPT; |
| 72409 | 72436 | }else{ |
| 72410 | 72437 | rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes); |
| 72411 | 72438 | } |
| | @@ -74385,10 +74412,11 @@ |
| 74385 | 74412 | removed = 1; |
| 74386 | 74413 | } |
| 74387 | 74414 | sqlite3_mutex_leave(pMainMtx); |
| 74388 | 74415 | return removed; |
| 74389 | 74416 | #else |
| 74417 | + UNUSED_PARAMETER( pBt ); |
| 74390 | 74418 | return 1; |
| 74391 | 74419 | #endif |
| 74392 | 74420 | } |
| 74393 | 74421 | |
| 74394 | 74422 | /* |
| | @@ -75226,10 +75254,17 @@ |
| 75226 | 75254 | |
| 75227 | 75255 | if( rc!=SQLITE_OK ){ |
| 75228 | 75256 | (void)sqlite3PagerWalWriteLock(pPager, 0); |
| 75229 | 75257 | unlockBtreeIfUnused(pBt); |
| 75230 | 75258 | } |
| 75259 | +#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) |
| 75260 | + if( rc==SQLITE_BUSY_TIMEOUT ){ |
| 75261 | + /* If a blocking lock timed out, break out of the loop here so that |
| 75262 | + ** the busy-handler is not invoked. */ |
| 75263 | + break; |
| 75264 | + } |
| 75265 | +#endif |
| 75231 | 75266 | }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE && |
| 75232 | 75267 | btreeInvokeBusyHandler(pBt) ); |
| 75233 | 75268 | sqlite3PagerWalDb(pPager, 0); |
| 75234 | 75269 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 75235 | 75270 | if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY; |
| | @@ -82846,10 +82881,11 @@ |
| 82846 | 82881 | ** btree as the argument handle holds an exclusive lock on the |
| 82847 | 82882 | ** sqlite_schema table. Otherwise SQLITE_OK. |
| 82848 | 82883 | */ |
| 82849 | 82884 | SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){ |
| 82850 | 82885 | int rc; |
| 82886 | + UNUSED_PARAMETER(p); /* only used in DEBUG builds */ |
| 82851 | 82887 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 82852 | 82888 | sqlite3BtreeEnter(p); |
| 82853 | 82889 | rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK); |
| 82854 | 82890 | assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE ); |
| 82855 | 82891 | sqlite3BtreeLeave(p); |
| | @@ -90066,34 +90102,26 @@ |
| 90066 | 90102 | } |
| 90067 | 90103 | } |
| 90068 | 90104 | return; |
| 90069 | 90105 | } |
| 90070 | 90106 | /* |
| 90071 | | -** This routine is used to allocate sufficient space for an UnpackedRecord |
| 90072 | | -** structure large enough to be used with sqlite3VdbeRecordUnpack() if |
| 90073 | | -** the first argument is a pointer to KeyInfo structure pKeyInfo. |
| 90074 | | -** |
| 90075 | | -** The space is either allocated using sqlite3DbMallocRaw() or from within |
| 90076 | | -** the unaligned buffer passed via the second and third arguments (presumably |
| 90077 | | -** stack space). If the former, then *ppFree is set to a pointer that should |
| 90078 | | -** be eventually freed by the caller using sqlite3DbFree(). Or, if the |
| 90079 | | -** allocation comes from the pSpace/szSpace buffer, *ppFree is set to NULL |
| 90080 | | -** before returning. |
| 90081 | | -** |
| 90082 | | -** If an OOM error occurs, NULL is returned. |
| 90107 | +** Allocate sufficient space for an UnpackedRecord structure large enough |
| 90108 | +** to hold a decoded index record for pKeyInfo. |
| 90109 | +** |
| 90110 | +** The space is allocated using sqlite3DbMallocRaw(). If an OOM error |
| 90111 | +** occurs, NULL is returned. |
| 90083 | 90112 | */ |
| 90084 | 90113 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord( |
| 90085 | 90114 | KeyInfo *pKeyInfo /* Description of the record */ |
| 90086 | 90115 | ){ |
| 90087 | 90116 | UnpackedRecord *p; /* Unpacked record to return */ |
| 90088 | | - int nByte; /* Number of bytes required for *p */ |
| 90117 | + u64 nByte; /* Number of bytes required for *p */ |
| 90089 | 90118 | assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff ); |
| 90090 | 90119 | nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1); |
| 90091 | 90120 | p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte); |
| 90092 | 90121 | if( !p ) return 0; |
| 90093 | 90122 | p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))]; |
| 90094 | | - assert( pKeyInfo->aSortFlags!=0 ); |
| 90095 | 90123 | p->pKeyInfo = pKeyInfo; |
| 90096 | 90124 | p->nField = pKeyInfo->nKeyField + 1; |
| 90097 | 90125 | return p; |
| 90098 | 90126 | } |
| 90099 | 90127 | |
| | @@ -90101,11 +90129,10 @@ |
| 90101 | 90129 | ** Given the nKey-byte encoding of a record in pKey[], populate the |
| 90102 | 90130 | ** UnpackedRecord structure indicated by the fourth argument with the |
| 90103 | 90131 | ** contents of the decoded record. |
| 90104 | 90132 | */ |
| 90105 | 90133 | SQLITE_PRIVATE void sqlite3VdbeRecordUnpack( |
| 90106 | | - KeyInfo *pKeyInfo, /* Information about the record format */ |
| 90107 | 90134 | int nKey, /* Size of the binary record */ |
| 90108 | 90135 | const void *pKey, /* The binary record */ |
| 90109 | 90136 | UnpackedRecord *p /* Populate this structure before returning. */ |
| 90110 | 90137 | ){ |
| 90111 | 90138 | const unsigned char *aKey = (const unsigned char *)pKey; |
| | @@ -90112,10 +90139,11 @@ |
| 90112 | 90139 | u32 d; |
| 90113 | 90140 | u32 idx; /* Offset in aKey[] to read from */ |
| 90114 | 90141 | u16 u; /* Unsigned loop counter */ |
| 90115 | 90142 | u32 szHdr; |
| 90116 | 90143 | Mem *pMem = p->aMem; |
| 90144 | + KeyInfo *pKeyInfo = p->pKeyInfo; |
| 90117 | 90145 | |
| 90118 | 90146 | p->default_rc = 0; |
| 90119 | 90147 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 90120 | 90148 | idx = getVarint32(aKey, szHdr); |
| 90121 | 90149 | d = szHdr; |
| | @@ -90139,10 +90167,12 @@ |
| 90139 | 90167 | /* In a corrupt record entry, the last pMem might have been set up using |
| 90140 | 90168 | ** uninitialized memory. Overwrite its value with NULL, to prevent |
| 90141 | 90169 | ** warnings from MSAN. */ |
| 90142 | 90170 | sqlite3VdbeMemSetNull(pMem-1); |
| 90143 | 90171 | } |
| 90172 | + testcase( u == pKeyInfo->nKeyField + 1 ); |
| 90173 | + testcase( u < pKeyInfo->nKeyField + 1 ); |
| 90144 | 90174 | assert( u<=pKeyInfo->nKeyField + 1 ); |
| 90145 | 90175 | p->nField = u; |
| 90146 | 90176 | } |
| 90147 | 90177 | |
| 90148 | 90178 | #ifdef SQLITE_DEBUG |
| | @@ -90998,10 +91028,11 @@ |
| 90998 | 91028 | ** is an integer. |
| 90999 | 91029 | ** |
| 91000 | 91030 | ** The easiest way to enforce this limit is to consider only records with |
| 91001 | 91031 | ** 13 fields or less. If the first field is an integer, the maximum legal |
| 91002 | 91032 | ** header size is (12*5 + 1 + 1) bytes. */ |
| 91033 | + assert( p->pKeyInfo->aSortFlags!=0 ); |
| 91003 | 91034 | if( p->pKeyInfo->nAllField<=13 ){ |
| 91004 | 91035 | int flags = p->aMem[0].flags; |
| 91005 | 91036 | if( p->pKeyInfo->aSortFlags[0] ){ |
| 91006 | 91037 | if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){ |
| 91007 | 91038 | return sqlite3VdbeRecordCompare; |
| | @@ -91356,11 +91387,10 @@ |
| 91356 | 91387 | ){ |
| 91357 | 91388 | sqlite3 *db = v->db; |
| 91358 | 91389 | i64 iKey2; |
| 91359 | 91390 | PreUpdate preupdate; |
| 91360 | 91391 | const char *zTbl = pTab->zName; |
| 91361 | | - static const u8 fakeSortOrder = 0; |
| 91362 | 91392 | #ifdef SQLITE_DEBUG |
| 91363 | 91393 | int nRealCol; |
| 91364 | 91394 | if( pTab->tabFlags & TF_WithoutRowid ){ |
| 91365 | 91395 | nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn; |
| 91366 | 91396 | }else if( pTab->tabFlags & TF_HasVirtual ){ |
| | @@ -91395,11 +91425,11 @@ |
| 91395 | 91425 | preupdate.iNewReg = iReg; |
| 91396 | 91426 | preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace; |
| 91397 | 91427 | preupdate.pKeyinfo->db = db; |
| 91398 | 91428 | preupdate.pKeyinfo->enc = ENC(db); |
| 91399 | 91429 | preupdate.pKeyinfo->nKeyField = pTab->nCol; |
| 91400 | | - preupdate.pKeyinfo->aSortFlags = (u8*)&fakeSortOrder; |
| 91430 | + preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */ |
| 91401 | 91431 | preupdate.iKey1 = iKey1; |
| 91402 | 91432 | preupdate.iKey2 = iKey2; |
| 91403 | 91433 | preupdate.pTab = pTab; |
| 91404 | 91434 | preupdate.iBlobWrite = iBlobWrite; |
| 91405 | 91435 | |
| | @@ -93592,11 +93622,11 @@ |
| 93592 | 93622 | UnpackedRecord *pRet; /* Return value */ |
| 93593 | 93623 | |
| 93594 | 93624 | pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo); |
| 93595 | 93625 | if( pRet ){ |
| 93596 | 93626 | memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1)); |
| 93597 | | - sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet); |
| 93627 | + sqlite3VdbeRecordUnpack(nKey, pKey, pRet); |
| 93598 | 93628 | } |
| 93599 | 93629 | return pRet; |
| 93600 | 93630 | } |
| 93601 | 93631 | |
| 93602 | 93632 | /* |
| | @@ -96785,10 +96815,11 @@ |
| 96785 | 96815 | } |
| 96786 | 96816 | n = pOp->p3; |
| 96787 | 96817 | pKeyInfo = pOp->p4.pKeyInfo; |
| 96788 | 96818 | assert( n>0 ); |
| 96789 | 96819 | assert( pKeyInfo!=0 ); |
| 96820 | + assert( pKeyInfo->aSortFlags!=0 ); |
| 96790 | 96821 | p1 = pOp->p1; |
| 96791 | 96822 | p2 = pOp->p2; |
| 96792 | 96823 | #ifdef SQLITE_DEBUG |
| 96793 | 96824 | if( aPermute ){ |
| 96794 | 96825 | int k, mx = 0; |
| | @@ -99658,11 +99689,11 @@ |
| 99658 | 99689 | rc = ExpandBlob(r.aMem); |
| 99659 | 99690 | assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); |
| 99660 | 99691 | if( rc ) goto no_mem; |
| 99661 | 99692 | pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo); |
| 99662 | 99693 | if( pIdxKey==0 ) goto no_mem; |
| 99663 | | - sqlite3VdbeRecordUnpack(pC->pKeyInfo, r.aMem->n, r.aMem->z, pIdxKey); |
| 99694 | + sqlite3VdbeRecordUnpack(r.aMem->n, r.aMem->z, pIdxKey); |
| 99664 | 99695 | pIdxKey->default_rc = 0; |
| 99665 | 99696 | rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult); |
| 99666 | 99697 | sqlite3DbFreeNN(db, pIdxKey); |
| 99667 | 99698 | } |
| 99668 | 99699 | if( rc!=SQLITE_OK ){ |
| | @@ -104834,11 +104865,11 @@ |
| 104834 | 104865 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 104835 | 104866 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 104836 | 104867 | ){ |
| 104837 | 104868 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 104838 | 104869 | if( *pbKey2Cached==0 ){ |
| 104839 | | - sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 104870 | + sqlite3VdbeRecordUnpack(nKey2, pKey2, r2); |
| 104840 | 104871 | *pbKey2Cached = 1; |
| 104841 | 104872 | } |
| 104842 | 104873 | return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1); |
| 104843 | 104874 | } |
| 104844 | 104875 | |
| | @@ -104861,11 +104892,11 @@ |
| 104861 | 104892 | const void *pKey1, int nKey1, /* Left side of comparison */ |
| 104862 | 104893 | const void *pKey2, int nKey2 /* Right side of comparison */ |
| 104863 | 104894 | ){ |
| 104864 | 104895 | UnpackedRecord *r2 = pTask->pUnpacked; |
| 104865 | 104896 | if( !*pbKey2Cached ){ |
| 104866 | | - sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2); |
| 104897 | + sqlite3VdbeRecordUnpack(nKey2, pKey2, r2); |
| 104867 | 104898 | *pbKey2Cached = 1; |
| 104868 | 104899 | } |
| 104869 | 104900 | return sqlite3VdbeRecordCompare(nKey1, pKey1, r2); |
| 104870 | 104901 | } |
| 104871 | 104902 | |
| | @@ -104901,10 +104932,11 @@ |
| 104901 | 104932 | res = vdbeSorterCompareTail( |
| 104902 | 104933 | pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 104903 | 104934 | ); |
| 104904 | 104935 | } |
| 104905 | 104936 | }else{ |
| 104937 | + assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 ); |
| 104906 | 104938 | assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) ); |
| 104907 | 104939 | if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){ |
| 104908 | 104940 | res = res * -1; |
| 104909 | 104941 | } |
| 104910 | 104942 | } |
| | @@ -104964,10 +104996,11 @@ |
| 104964 | 104996 | }else{ |
| 104965 | 104997 | if( *v2 & 0x80 ) res = +1; |
| 104966 | 104998 | } |
| 104967 | 104999 | } |
| 104968 | 105000 | |
| 105001 | + assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 ); |
| 104969 | 105002 | if( res==0 ){ |
| 104970 | 105003 | if( pTask->pSorter->pKeyInfo->nKeyField>1 ){ |
| 104971 | 105004 | res = vdbeSorterCompareTail( |
| 104972 | 105005 | pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2 |
| 104973 | 105006 | ); |
| | @@ -105037,11 +105070,12 @@ |
| 105037 | 105070 | assert( pCsr->pKeyInfo ); |
| 105038 | 105071 | assert( !pCsr->isEphemeral ); |
| 105039 | 105072 | assert( pCsr->eCurType==CURTYPE_SORTER ); |
| 105040 | 105073 | assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*) |
| 105041 | 105074 | < 0x7fffffff ); |
| 105042 | | - szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nKeyField+1); |
| 105075 | + assert( pCsr->pKeyInfo->nKeyField<=pCsr->pKeyInfo->nAllField ); |
| 105076 | + szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nAllField); |
| 105043 | 105077 | sz = SZ_VDBESORTER(nWorker+1); |
| 105044 | 105078 | |
| 105045 | 105079 | pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo); |
| 105046 | 105080 | pCsr->uc.pSorter = pSorter; |
| 105047 | 105081 | if( pSorter==0 ){ |
| | @@ -105051,11 +105085,16 @@ |
| 105051 | 105085 | pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); |
| 105052 | 105086 | memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); |
| 105053 | 105087 | pKeyInfo->db = 0; |
| 105054 | 105088 | if( nField && nWorker==0 ){ |
| 105055 | 105089 | pKeyInfo->nKeyField = nField; |
| 105090 | + assert( nField<=pCsr->pKeyInfo->nAllField ); |
| 105056 | 105091 | } |
| 105092 | + /* It is OK that pKeyInfo reuses the aSortFlags field from pCsr->pKeyInfo, |
| 105093 | + ** since the pCsr->pKeyInfo->aSortFlags[] array is invariant and lives |
| 105094 | + ** longer that pSorter. */ |
| 105095 | + assert( pKeyInfo->aSortFlags==pCsr->pKeyInfo->aSortFlags ); |
| 105057 | 105096 | sqlite3BtreeEnter(pBt); |
| 105058 | 105097 | pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt); |
| 105059 | 105098 | sqlite3BtreeLeave(pBt); |
| 105060 | 105099 | pSorter->nTask = nWorker + 1; |
| 105061 | 105100 | pSorter->iPrev = (u8)(nWorker - 1); |
| | @@ -106831,11 +106870,11 @@ |
| 106831 | 106870 | r2->nField = nKeyCol; |
| 106832 | 106871 | } |
| 106833 | 106872 | assert( r2->nField==nKeyCol ); |
| 106834 | 106873 | |
| 106835 | 106874 | pKey = vdbeSorterRowkey(pSorter, &nKey); |
| 106836 | | - sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2); |
| 106875 | + sqlite3VdbeRecordUnpack(nKey, pKey, r2); |
| 106837 | 106876 | for(i=0; i<nKeyCol; i++){ |
| 106838 | 106877 | if( r2->aMem[i].flags & MEM_Null ){ |
| 106839 | 106878 | *pRes = -1; |
| 106840 | 106879 | return SQLITE_OK; |
| 106841 | 106880 | } |
| | @@ -110387,11 +110426,13 @@ |
| 110387 | 110426 | assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); |
| 110388 | 110427 | return sqlite3ExprAffinity( |
| 110389 | 110428 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 110390 | 110429 | ); |
| 110391 | 110430 | } |
| 110392 | | - if( op==TK_VECTOR ){ |
| 110431 | + if( op==TK_VECTOR |
| 110432 | + || (op==TK_FUNCTION && pExpr->affExpr==SQLITE_AFF_DEFER) |
| 110433 | + ){ |
| 110393 | 110434 | assert( ExprUseXList(pExpr) ); |
| 110394 | 110435 | return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr); |
| 110395 | 110436 | } |
| 110396 | 110437 | if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){ |
| 110397 | 110438 | assert( pExpr->op==TK_COLLATE |
| | @@ -110580,11 +110621,13 @@ |
| 110580 | 110621 | } |
| 110581 | 110622 | if( op==TK_CAST || op==TK_UPLUS ){ |
| 110582 | 110623 | p = p->pLeft; |
| 110583 | 110624 | continue; |
| 110584 | 110625 | } |
| 110585 | | - if( op==TK_VECTOR ){ |
| 110626 | + if( op==TK_VECTOR |
| 110627 | + || (op==TK_FUNCTION && p->affExpr==SQLITE_AFF_DEFER) |
| 110628 | + ){ |
| 110586 | 110629 | assert( ExprUseXList(p) ); |
| 110587 | 110630 | p = p->x.pList->a[0].pExpr; |
| 110588 | 110631 | continue; |
| 110589 | 110632 | } |
| 110590 | 110633 | if( op==TK_COLLATE ){ |
| | @@ -145362,11 +145405,11 @@ |
| 145362 | 145405 | "not present in both tables", zName); |
| 145363 | 145406 | return 1; |
| 145364 | 145407 | } |
| 145365 | 145408 | pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol); |
| 145366 | 145409 | sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol); |
| 145367 | | - if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){ |
| 145410 | + if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 && pParse->nErr==0 ){ |
| 145368 | 145411 | /* This branch runs if the query contains one or more RIGHT or FULL |
| 145369 | 145412 | ** JOINs. If only a single table on the left side of this join |
| 145370 | 145413 | ** contains the zName column, then this branch is a no-op. |
| 145371 | 145414 | ** But if there are two or more tables on the left side |
| 145372 | 145415 | ** of the join, construct a coalesce() function that gathers all |
| | @@ -145378,10 +145421,12 @@ |
| 145378 | 145421 | ** JOIN. But older versions of SQLite do not do that, so we avoid |
| 145379 | 145422 | ** adding a new error so as to not break legacy applications. |
| 145380 | 145423 | */ |
| 145381 | 145424 | ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */ |
| 145382 | 145425 | static const Token tkCoalesce = { "coalesce", 8 }; |
| 145426 | + assert( pE1!=0 ); |
| 145427 | + ExprSetProperty(pE1, EP_CanBeNull); |
| 145383 | 145428 | while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol, |
| 145384 | 145429 | pRight->fg.isSynthUsing)!=0 ){ |
| 145385 | 145430 | if( pSrc->a[iLeft].fg.isUsing==0 |
| 145386 | 145431 | || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0 |
| 145387 | 145432 | ){ |
| | @@ -145394,11 +145439,17 @@ |
| 145394 | 145439 | sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol); |
| 145395 | 145440 | } |
| 145396 | 145441 | if( pFuncArgs ){ |
| 145397 | 145442 | pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1); |
| 145398 | 145443 | pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0); |
| 145444 | + if( pE1 ){ |
| 145445 | + pE1->affExpr = SQLITE_AFF_DEFER; |
| 145446 | + } |
| 145399 | 145447 | } |
| 145448 | + }else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){ |
| 145449 | + assert( pE1!=0 ); |
| 145450 | + ExprSetProperty(pE1, EP_CanBeNull); |
| 145400 | 145451 | } |
| 145401 | 145452 | pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol); |
| 145402 | 145453 | sqlite3SrcItemColumnUsed(pRight, iRightCol); |
| 145403 | 145454 | pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2); |
| 145404 | 145455 | assert( pE2!=0 || pEq==0 ); |
| | @@ -146871,10 +146922,14 @@ |
| 146871 | 146922 | #else |
| 146872 | 146923 | zType = columnType(&sNC, p, 0, 0, 0); |
| 146873 | 146924 | #endif |
| 146874 | 146925 | sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT); |
| 146875 | 146926 | } |
| 146927 | +#else |
| 146928 | + UNUSED_PARAMETER(pParse); |
| 146929 | + UNUSED_PARAMETER(pTabList); |
| 146930 | + UNUSED_PARAMETER(pEList); |
| 146876 | 146931 | #endif /* !defined(SQLITE_OMIT_DECLTYPE) */ |
| 146877 | 146932 | } |
| 146878 | 146933 | |
| 146879 | 146934 | |
| 146880 | 146935 | /* |
| | @@ -149002,13 +149057,13 @@ |
| 149002 | 149057 | ** other than the one FROM-clause subquery that is a candidate |
| 149003 | 149058 | ** for flattening. (This is due to ticket [2f7170d73bf9abf80] |
| 149004 | 149059 | ** from 2015-02-09.) |
| 149005 | 149060 | ** |
| 149006 | 149061 | ** (3) If the subquery is the right operand of a LEFT JOIN then |
| 149007 | | -** (3a) the subquery may not be a join and |
| 149008 | | -** (3b) the FROM clause of the subquery may not contain a virtual |
| 149009 | | -** table and |
| 149062 | +** (3a) the subquery may not be a join |
| 149063 | +** (**) Was (3b): "the FROM clause of the subquery may not contain |
| 149064 | +** a virtual table" |
| 149010 | 149065 | ** (**) Was: "The outer query may not have a GROUP BY." This case |
| 149011 | 149066 | ** is now managed correctly |
| 149012 | 149067 | ** (3d) the outer query may not be DISTINCT. |
| 149013 | 149068 | ** See also (26) for restrictions on RIGHT JOIN. |
| 149014 | 149069 | ** |
| | @@ -149220,11 +149275,11 @@ |
| 149220 | 149275 | ** |
| 149221 | 149276 | ** See also tickets #306, #350, and #3300. |
| 149222 | 149277 | */ |
| 149223 | 149278 | if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){ |
| 149224 | 149279 | if( pSubSrc->nSrc>1 /* (3a) */ |
| 149225 | | - || IsVirtual(pSubSrc->a[0].pSTab) /* (3b) */ |
| 149280 | + /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */ |
| 149226 | 149281 | || (p->selFlags & SF_Distinct)!=0 /* (3d) */ |
| 149227 | 149282 | || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */ |
| 149228 | 149283 | ){ |
| 149229 | 149284 | return 0; |
| 149230 | 149285 | } |
| | @@ -157245,11 +157300,12 @@ |
| 157245 | 157300 | saved_flags = db->flags; |
| 157246 | 157301 | saved_mDbFlags = db->mDbFlags; |
| 157247 | 157302 | saved_nChange = db->nChange; |
| 157248 | 157303 | saved_nTotalChange = db->nTotalChange; |
| 157249 | 157304 | saved_mTrace = db->mTrace; |
| 157250 | | - db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments; |
| 157305 | + db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments |
| 157306 | + | SQLITE_AttachCreate | SQLITE_AttachWrite; |
| 157251 | 157307 | db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum; |
| 157252 | 157308 | db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder |
| 157253 | 157309 | | SQLITE_Defensive | SQLITE_CountRows); |
| 157254 | 157310 | db->mTrace = 0; |
| 157255 | 157311 | |
| | @@ -161720,16 +161776,17 @@ |
| 161720 | 161776 | } |
| 161721 | 161777 | |
| 161722 | 161778 | if( pLevel->iLeftJoin==0 ){ |
| 161723 | 161779 | /* If a partial index is driving the loop, try to eliminate WHERE clause |
| 161724 | 161780 | ** terms from the query that must be true due to the WHERE clause of |
| 161725 | | - ** the partial index. |
| 161781 | + ** the partial index. This optimization does not work on an outer join, |
| 161782 | + ** as shown by: |
| 161726 | 161783 | ** |
| 161727 | | - ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work |
| 161728 | | - ** for a LEFT JOIN. |
| 161784 | + ** 2019-11-02 ticket 623eff57e76d45f6 (LEFT JOIN) |
| 161785 | + ** 2025-05-29 forum post 7dee41d32506c4ae (RIGHT JOIN) |
| 161729 | 161786 | */ |
| 161730 | | - if( pIdx->pPartIdxWhere ){ |
| 161787 | + if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){ |
| 161731 | 161788 | whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC); |
| 161732 | 161789 | } |
| 161733 | 161790 | }else{ |
| 161734 | 161791 | testcase( pIdx->pPartIdxWhere ); |
| 161735 | 161792 | /* The following assert() is not a requirement, merely an observation: |
| | @@ -188786,11 +188843,11 @@ |
| 188786 | 188843 | |
| 188787 | 188844 | /* |
| 188788 | 188845 | ** Macros needed to provide flexible arrays in a portable way |
| 188789 | 188846 | */ |
| 188790 | 188847 | #ifndef offsetof |
| 188791 | | -# define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD)) |
| 188848 | +# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0)) |
| 188792 | 188849 | #endif |
| 188793 | 188850 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) |
| 188794 | 188851 | # define FLEXARRAY |
| 188795 | 188852 | #else |
| 188796 | 188853 | # define FLEXARRAY 1 |
| | @@ -209019,12 +209076,14 @@ |
| 209019 | 209076 | nExtra = 0; |
| 209020 | 209077 | }else if( szType==12 ){ |
| 209021 | 209078 | nExtra = 1; |
| 209022 | 209079 | }else if( szType==13 ){ |
| 209023 | 209080 | nExtra = 2; |
| 209024 | | - }else{ |
| 209081 | + }else if( szType==14 ){ |
| 209025 | 209082 | nExtra = 4; |
| 209083 | + }else{ |
| 209084 | + nExtra = 8; |
| 209026 | 209085 | } |
| 209027 | 209086 | if( szPayload<=11 ){ |
| 209028 | 209087 | nNeeded = 0; |
| 209029 | 209088 | }else if( szPayload<=0xff ){ |
| 209030 | 209089 | nNeeded = 1; |
| | @@ -213405,10 +213464,12 @@ |
| 213405 | 213464 | #else |
| 213406 | 213465 | /* #include "sqlite3.h" */ |
| 213407 | 213466 | #endif |
| 213408 | 213467 | SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */ |
| 213409 | 213468 | |
| 213469 | +/* #include <stddef.h> */ |
| 213470 | + |
| 213410 | 213471 | /* |
| 213411 | 213472 | ** If building separately, we will need some setup that is normally |
| 213412 | 213473 | ** found in sqliteInt.h |
| 213413 | 213474 | */ |
| 213414 | 213475 | #if !defined(SQLITE_AMALGAMATION) |
| | @@ -213436,11 +213497,11 @@ |
| 213436 | 213497 | #else |
| 213437 | 213498 | # define ALWAYS(X) (X) |
| 213438 | 213499 | # define NEVER(X) (X) |
| 213439 | 213500 | #endif |
| 213440 | 213501 | #ifndef offsetof |
| 213441 | | -#define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD)) |
| 213502 | +# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0)) |
| 213442 | 213503 | #endif |
| 213443 | 213504 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) |
| 213444 | 213505 | # define FLEXARRAY |
| 213445 | 213506 | #else |
| 213446 | 213507 | # define FLEXARRAY 1 |
| | @@ -227753,11 +227814,12 @@ |
| 227753 | 227814 | DbpageTable *pTab = (DbpageTable *)pCursor->pVtab; |
| 227754 | 227815 | int rc; |
| 227755 | 227816 | sqlite3 *db = pTab->db; |
| 227756 | 227817 | Btree *pBt; |
| 227757 | 227818 | |
| 227758 | | - (void)idxStr; |
| 227819 | + UNUSED_PARAMETER(idxStr); |
| 227820 | + UNUSED_PARAMETER(argc); |
| 227759 | 227821 | |
| 227760 | 227822 | /* Default setting is no rows of result */ |
| 227761 | 227823 | pCsr->pgno = 1; |
| 227762 | 227824 | pCsr->mxPgno = 0; |
| 227763 | 227825 | |
| | @@ -235447,10 +235509,11 @@ |
| 235447 | 235509 | /* #include "sqlite3ext.h" */ |
| 235448 | 235510 | SQLITE_EXTENSION_INIT1 |
| 235449 | 235511 | |
| 235450 | 235512 | /* #include <string.h> */ |
| 235451 | 235513 | /* #include <assert.h> */ |
| 235514 | +/* #include <stddef.h> */ |
| 235452 | 235515 | |
| 235453 | 235516 | #ifndef SQLITE_AMALGAMATION |
| 235454 | 235517 | |
| 235455 | 235518 | typedef unsigned char u8; |
| 235456 | 235519 | typedef unsigned int u32; |
| | @@ -235506,11 +235569,11 @@ |
| 235506 | 235569 | |
| 235507 | 235570 | /* |
| 235508 | 235571 | ** Macros needed to provide flexible arrays in a portable way |
| 235509 | 235572 | */ |
| 235510 | 235573 | #ifndef offsetof |
| 235511 | | -# define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD)) |
| 235574 | +# define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0)) |
| 235512 | 235575 | #endif |
| 235513 | 235576 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) |
| 235514 | 235577 | # define FLEXARRAY |
| 235515 | 235578 | #else |
| 235516 | 235579 | # define FLEXARRAY 1 |
| | @@ -257190,11 +257253,11 @@ |
| 257190 | 257253 | int nArg, /* Number of args */ |
| 257191 | 257254 | sqlite3_value **apUnused /* Function arguments */ |
| 257192 | 257255 | ){ |
| 257193 | 257256 | assert( nArg==0 ); |
| 257194 | 257257 | UNUSED_PARAM2(nArg, apUnused); |
| 257195 | | - sqlite3_result_text(pCtx, "fts5: 2025-05-29 14:26:00 dfc790f998f450d9c35e3ba1c8c89c17466cb559f87b0239e4aab9d34e28f742", -1, SQLITE_TRANSIENT); |
| 257258 | + sqlite3_result_text(pCtx, "fts5: 2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5", -1, SQLITE_TRANSIENT); |
| 257196 | 257259 | } |
| 257197 | 257260 | |
| 257198 | 257261 | /* |
| 257199 | 257262 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 257200 | 257263 | ** |
| 257201 | 257264 | |