Fossil SCM

Update the built-in SQLite to the latest trunk version for testing and to make bug fixes available to Fossil.

drh 2025-06-03 15:14 trunk
Commit 92cdafddbb402acaf858cad0e328ed05f1ccd05dee028d11fa0751b04beb9ec5
+11 -2
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1266,16 +1266,25 @@
12661266
return 0x3fffffff & (int)(z2 - z);
12671267
}
12681268
12691269
/*
12701270
** Return the length of a string in characters. Multibyte UTF8 characters
1271
-** count as a single character.
1271
+** count as a single character for single-width characters, or as two
1272
+** characters for double-width characters.
12721273
*/
12731274
static int strlenChar(const char *z){
12741275
int n = 0;
12751276
while( *z ){
1276
- if( (0xc0&*(z++))!=0x80 ) n++;
1277
+ if( (0x80&z[0])==0 ){
1278
+ n++;
1279
+ z++;
1280
+ }else{
1281
+ int u = 0;
1282
+ int len = decodeUtf8((const u8*)z, &u);
1283
+ z += len;
1284
+ n += cli_wcwidth(u);
1285
+ }
12771286
}
12781287
return n;
12791288
}
12801289
12811290
/*
12821291
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1266,16 +1266,25 @@
1266 return 0x3fffffff & (int)(z2 - z);
1267 }
1268
1269 /*
1270 ** Return the length of a string in characters. Multibyte UTF8 characters
1271 ** count as a single character.
 
1272 */
1273 static int strlenChar(const char *z){
1274 int n = 0;
1275 while( *z ){
1276 if( (0xc0&*(z++))!=0x80 ) n++;
 
 
 
 
 
 
 
 
1277 }
1278 return n;
1279 }
1280
1281 /*
1282
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1266,16 +1266,25 @@
1266 return 0x3fffffff & (int)(z2 - z);
1267 }
1268
1269 /*
1270 ** Return the length of a string in characters. Multibyte UTF8 characters
1271 ** count as a single character for single-width characters, or as two
1272 ** characters for double-width characters.
1273 */
1274 static int strlenChar(const char *z){
1275 int n = 0;
1276 while( *z ){
1277 if( (0x80&z[0])==0 ){
1278 n++;
1279 z++;
1280 }else{
1281 int u = 0;
1282 int len = decodeUtf8((const u8*)z, &u);
1283 z += len;
1284 n += cli_wcwidth(u);
1285 }
1286 }
1287 return n;
1288 }
1289
1290 /*
1291
+136 -73
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** 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
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** dfc790f998f450d9c35e3ba1c8c89c17466c with changes in files:
21
+** ea1754f7d8a770477a1b19b606b27724fdc0 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463463
**
464464
** See also: [sqlite3_libversion()],
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
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"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -15174,11 +15174,11 @@
1517415174
/*
1517515175
** GCC does not define the offsetof() macro so we'll have to do it
1517615176
** ourselves.
1517715177
*/
1517815178
#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))
1518015180
#endif
1518115181
1518215182
/*
1518315183
** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
1518415184
** to avoid complaints from -fsanitize=strict-bounds.
@@ -17401,11 +17401,11 @@
1740117401
SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
1740217402
#endif
1740317403
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
1740417404
SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*);
1740517405
17406
-SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
17406
+SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(int,const void*,UnpackedRecord*);
1740717407
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
1740817408
SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
1740917409
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
1741017410
1741117411
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
@@ -18701,10 +18701,11 @@
1870118701
#define SQLITE_AFF_TEXT 0x42 /* 'B' */
1870218702
#define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
1870318703
#define SQLITE_AFF_INTEGER 0x44 /* 'D' */
1870418704
#define SQLITE_AFF_REAL 0x45 /* 'E' */
1870518705
#define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
18706
+#define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */
1870618707
1870718708
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
1870818709
1870918710
/*
1871018711
** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -19016,13 +19017,19 @@
1901619017
/*
1901719018
** An instance of the following structure is passed as the first
1901819019
** argument to sqlite3VdbeKeyCompare and is used to control the
1901919020
** comparison of the two index keys.
1902019021
**
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.
1902419031
*/
1902519032
struct KeyInfo {
1902619033
u32 nRef; /* Number of references to this KeyInfo object */
1902719034
u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
1902819035
u16 nKeyField; /* Number of key columns in the index */
@@ -19030,12 +19037,21 @@
1903019037
sqlite3 *db; /* The database connection */
1903119038
u8 *aSortFlags; /* Sort order for each column. */
1903219039
CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */
1903319040
};
1903419041
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[]. */
1903619045
#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
1903719053
1903819054
/*
1903919055
** Allowed bit values for entries in the KeyInfo.aSortFlags[] array.
1904019056
*/
1904119057
#define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
@@ -19051,23 +19067,22 @@
1905119067
** the OP_MakeRecord opcode of the VDBE and is disassembled by the
1905219068
** OP_Column opcode.
1905319069
**
1905419070
** An instance of this object serves as a "key" for doing a search on
1905519071
** 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.
1905919074
**
1906019075
** The r1 and r2 fields are the values to return if this key is less than
1906119076
** or greater than a key in the btree, respectively. These are normally
1906219077
** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
1906319078
** is in DESC order.
1906419079
**
1906519080
** The key comparison functions actually return default_rc when they find
1906619081
** an equals comparison. default_rc can be -1, 0, or +1. If there are
1906719082
** 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
1906919084
** cause the search to find the last match, or +1 to cause the search to
1907019085
** find the first match.
1907119086
**
1907219087
** The key comparison functions will set eqSeen to true if they ever
1907319088
** get and equal results when comparing this structure to a b-tree record.
@@ -19075,12 +19090,12 @@
1907519090
** before the first match or immediately after the last match. The
1907619091
** eqSeen field will indicate whether or not an exact match exists in the
1907719092
** b-tree.
1907819093
*/
1907919094
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 */
1908219097
union {
1908319098
char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
1908419099
i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
1908519100
} u;
1908619101
int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
@@ -24132,11 +24147,11 @@
2413224147
Mem oldipk; /* Memory cell holding "old" IPK value */
2413324148
Mem *aNew; /* Array of new.* values */
2413424149
Table *pTab; /* Schema object being updated */
2413524150
Index *pPk; /* PK index if pTab is WITHOUT ROWID */
2413624151
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 */
2413824153
};
2413924154
2414024155
/*
2414124156
** An instance of this object is used to pass an vector of values into
2414224157
** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -43872,25 +43887,24 @@
4387243887
assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
4387343888
4387443889
/* Check that, if this to be a blocking lock, no locks that occur later
4387543890
** in the following list than the lock being obtained are already held:
4387643891
**
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).
4388043896
**
4388143897
** In other words, if this is a blocking lock, none of the locks that
4388243898
** occur later in the above list than the lock being obtained may be
4388343899
** held.
43884
- **
43885
- ** It is not permitted to block on the RECOVER lock.
4388643900
*/
4388743901
#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
4388843902
{
4388943903
u16 lockMask = (p->exclMask|p->sharedMask);
4389043904
assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43891
- (ofst!=2) /* not RECOVER */
43905
+ (ofst!=2 || lockMask==0)
4389243906
&& (ofst!=1 || lockMask==0 || lockMask==2)
4389343907
&& (ofst!=0 || lockMask<3)
4389443908
&& (ofst<3 || lockMask<(1<<ofst))
4389543909
));
4389643910
}
@@ -49847,11 +49861,15 @@
4984749861
DWORD nDelay = (nMs==0 ? INFINITE : nMs);
4984849862
DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
4984949863
if( res==WAIT_OBJECT_0 ){
4985049864
ret = TRUE;
4985149865
}else if( res==WAIT_TIMEOUT ){
49866
+#if SQLITE_ENABLE_SETLK_TIMEOUT==1
4985249867
rc = SQLITE_BUSY_TIMEOUT;
49868
+#else
49869
+ rc = SQLITE_BUSY;
49870
+#endif
4985349871
}else{
4985449872
/* Some other error has occurred */
4985549873
rc = SQLITE_IOERR_LOCK;
4985649874
}
4985749875
@@ -51658,25 +51676,24 @@
5165851676
assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
5165951677
5166051678
/* Check that, if this to be a blocking lock, no locks that occur later
5166151679
** in the following list than the lock being obtained are already held:
5166251680
**
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).
5166651685
**
5166751686
** In other words, if this is a blocking lock, none of the locks that
5166851687
** occur later in the above list than the lock being obtained may be
5166951688
** held.
51670
- **
51671
- ** It is not permitted to block on the RECOVER lock.
5167251689
*/
5167351690
#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
5167451691
{
5167551692
u16 lockMask = (p->exclMask|p->sharedMask);
5167651693
assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51677
- (ofst!=2) /* not RECOVER */
51694
+ (ofst!=2 || lockMask==0)
5167851695
&& (ofst!=1 || lockMask==0 || lockMask==2)
5167951696
&& (ofst!=0 || lockMask<3)
5168051697
&& (ofst<3 || lockMask<(1<<ofst))
5168151698
));
5168251699
}
@@ -58748,10 +58765,13 @@
5874858765
PCache *pPCache; /* Pointer to page cache object */
5874958766
#ifndef SQLITE_OMIT_WAL
5875058767
Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
5875158768
char *zWal; /* File name for write-ahead log */
5875258769
#endif
58770
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
58771
+ sqlite3 *dbWal;
58772
+#endif
5875358773
};
5875458774
5875558775
/*
5875658776
** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
5875758777
** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS
@@ -65629,10 +65649,15 @@
6562965649
if( rc==SQLITE_OK ){
6563065650
rc = sqlite3WalOpen(pPager->pVfs,
6563165651
pPager->fd, pPager->zWal, pPager->exclusiveMode,
6563265652
pPager->journalSizeLimit, &pPager->pWal
6563365653
);
65654
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
65655
+ if( rc==SQLITE_OK ){
65656
+ sqlite3WalDb(pPager->pWal, pPager->dbWal);
65657
+ }
65658
+#endif
6563465659
}
6563565660
pagerFixMaplimit(pPager);
6563665661
6563765662
return rc;
6563865663
}
@@ -65748,10 +65773,11 @@
6574865773
/*
6574965774
** Set the database handle used by the wal layer to determine if
6575065775
** blocking locks are required.
6575165776
*/
6575265777
SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
65778
+ pPager->dbWal = db;
6575365779
if( pagerUseWal(pPager) ){
6575465780
sqlite3WalDb(pPager->pWal, db);
6575565781
}
6575665782
}
6575765783
#endif
@@ -68921,11 +68947,10 @@
6892168947
assert( rc==SQLITE_OK );
6892268948
if( pWal->bShmUnreliable==0 ){
6892368949
rc = walIndexReadHdr(pWal, pChanged);
6892468950
}
6892568951
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
68926
- walDisableBlocking(pWal);
6892768952
if( rc==SQLITE_BUSY_TIMEOUT ){
6892868953
rc = SQLITE_BUSY;
6892968954
*pCnt |= WAL_RETRY_BLOCKED_MASK;
6893068955
}
6893168956
#endif
@@ -68936,10 +68961,11 @@
6893668961
** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
6893768962
** would be technically correct. But the race is benign since with
6893868963
** WAL_RETRY this routine will be called again and will probably be
6893968964
** right on the second iteration.
6894068965
*/
68966
+ (void)walEnableBlocking(pWal);
6894168967
if( pWal->apWiData[0]==0 ){
6894268968
/* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
6894368969
** We assume this is a transient condition, so return WAL_RETRY. The
6894468970
** xShmMap() implementation used by the default unix and win32 VFS
6894568971
** modules may return SQLITE_BUSY due to a race condition in the
@@ -68952,10 +68978,11 @@
6895268978
rc = WAL_RETRY;
6895368979
}else if( rc==SQLITE_BUSY ){
6895468980
rc = SQLITE_BUSY_RECOVERY;
6895568981
}
6895668982
}
68983
+ walDisableBlocking(pWal);
6895768984
if( rc!=SQLITE_OK ){
6895868985
return rc;
6895968986
}
6896068987
else if( pWal->bShmUnreliable ){
6896168988
return walBeginShmUnreliable(pWal, pChanged);
@@ -72401,11 +72428,11 @@
7240172428
if( pKey ){
7240272429
KeyInfo *pKeyInfo = pCur->pKeyInfo;
7240372430
assert( nKey==(i64)(int)nKey );
7240472431
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
7240572432
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72406
- sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
72433
+ sqlite3VdbeRecordUnpack((int)nKey, pKey, pIdxKey);
7240772434
if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
7240872435
rc = SQLITE_CORRUPT_BKPT;
7240972436
}else{
7241072437
rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes);
7241172438
}
@@ -74385,10 +74412,11 @@
7438574412
removed = 1;
7438674413
}
7438774414
sqlite3_mutex_leave(pMainMtx);
7438874415
return removed;
7438974416
#else
74417
+ UNUSED_PARAMETER( pBt );
7439074418
return 1;
7439174419
#endif
7439274420
}
7439374421
7439474422
/*
@@ -75226,10 +75254,17 @@
7522675254
7522775255
if( rc!=SQLITE_OK ){
7522875256
(void)sqlite3PagerWalWriteLock(pPager, 0);
7522975257
unlockBtreeIfUnused(pBt);
7523075258
}
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
7523175266
}while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
7523275267
btreeInvokeBusyHandler(pBt) );
7523375268
sqlite3PagerWalDb(pPager, 0);
7523475269
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
7523575270
if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
@@ -82846,10 +82881,11 @@
8284682881
** btree as the argument handle holds an exclusive lock on the
8284782882
** sqlite_schema table. Otherwise SQLITE_OK.
8284882883
*/
8284982884
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
8285082885
int rc;
82886
+ UNUSED_PARAMETER(p); /* only used in DEBUG builds */
8285182887
assert( sqlite3_mutex_held(p->db->mutex) );
8285282888
sqlite3BtreeEnter(p);
8285382889
rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
8285482890
assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
8285582891
sqlite3BtreeLeave(p);
@@ -90066,34 +90102,26 @@
9006690102
}
9006790103
}
9006890104
return;
9006990105
}
9007090106
/*
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.
9008390112
*/
9008490113
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
9008590114
KeyInfo *pKeyInfo /* Description of the record */
9008690115
){
9008790116
UnpackedRecord *p; /* Unpacked record to return */
90088
- int nByte; /* Number of bytes required for *p */
90117
+ u64 nByte; /* Number of bytes required for *p */
9008990118
assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
9009090119
nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
9009190120
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
9009290121
if( !p ) return 0;
9009390122
p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
90094
- assert( pKeyInfo->aSortFlags!=0 );
9009590123
p->pKeyInfo = pKeyInfo;
9009690124
p->nField = pKeyInfo->nKeyField + 1;
9009790125
return p;
9009890126
}
9009990127
@@ -90101,11 +90129,10 @@
9010190129
** Given the nKey-byte encoding of a record in pKey[], populate the
9010290130
** UnpackedRecord structure indicated by the fourth argument with the
9010390131
** contents of the decoded record.
9010490132
*/
9010590133
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(
90106
- KeyInfo *pKeyInfo, /* Information about the record format */
9010790134
int nKey, /* Size of the binary record */
9010890135
const void *pKey, /* The binary record */
9010990136
UnpackedRecord *p /* Populate this structure before returning. */
9011090137
){
9011190138
const unsigned char *aKey = (const unsigned char *)pKey;
@@ -90112,10 +90139,11 @@
9011290139
u32 d;
9011390140
u32 idx; /* Offset in aKey[] to read from */
9011490141
u16 u; /* Unsigned loop counter */
9011590142
u32 szHdr;
9011690143
Mem *pMem = p->aMem;
90144
+ KeyInfo *pKeyInfo = p->pKeyInfo;
9011790145
9011890146
p->default_rc = 0;
9011990147
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
9012090148
idx = getVarint32(aKey, szHdr);
9012190149
d = szHdr;
@@ -90139,10 +90167,12 @@
9013990167
/* In a corrupt record entry, the last pMem might have been set up using
9014090168
** uninitialized memory. Overwrite its value with NULL, to prevent
9014190169
** warnings from MSAN. */
9014290170
sqlite3VdbeMemSetNull(pMem-1);
9014390171
}
90172
+ testcase( u == pKeyInfo->nKeyField + 1 );
90173
+ testcase( u < pKeyInfo->nKeyField + 1 );
9014490174
assert( u<=pKeyInfo->nKeyField + 1 );
9014590175
p->nField = u;
9014690176
}
9014790177
9014890178
#ifdef SQLITE_DEBUG
@@ -90998,10 +91028,11 @@
9099891028
** is an integer.
9099991029
**
9100091030
** The easiest way to enforce this limit is to consider only records with
9100191031
** 13 fields or less. If the first field is an integer, the maximum legal
9100291032
** header size is (12*5 + 1 + 1) bytes. */
91033
+ assert( p->pKeyInfo->aSortFlags!=0 );
9100391034
if( p->pKeyInfo->nAllField<=13 ){
9100491035
int flags = p->aMem[0].flags;
9100591036
if( p->pKeyInfo->aSortFlags[0] ){
9100691037
if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
9100791038
return sqlite3VdbeRecordCompare;
@@ -91356,11 +91387,10 @@
9135691387
){
9135791388
sqlite3 *db = v->db;
9135891389
i64 iKey2;
9135991390
PreUpdate preupdate;
9136091391
const char *zTbl = pTab->zName;
91361
- static const u8 fakeSortOrder = 0;
9136291392
#ifdef SQLITE_DEBUG
9136391393
int nRealCol;
9136491394
if( pTab->tabFlags & TF_WithoutRowid ){
9136591395
nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
9136691396
}else if( pTab->tabFlags & TF_HasVirtual ){
@@ -91395,11 +91425,11 @@
9139591425
preupdate.iNewReg = iReg;
9139691426
preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
9139791427
preupdate.pKeyinfo->db = db;
9139891428
preupdate.pKeyinfo->enc = ENC(db);
9139991429
preupdate.pKeyinfo->nKeyField = pTab->nCol;
91400
- preupdate.pKeyinfo->aSortFlags = (u8*)&fakeSortOrder;
91430
+ preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
9140191431
preupdate.iKey1 = iKey1;
9140291432
preupdate.iKey2 = iKey2;
9140391433
preupdate.pTab = pTab;
9140491434
preupdate.iBlobWrite = iBlobWrite;
9140591435
@@ -93592,11 +93622,11 @@
9359293622
UnpackedRecord *pRet; /* Return value */
9359393623
9359493624
pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
9359593625
if( pRet ){
9359693626
memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93597
- sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
93627
+ sqlite3VdbeRecordUnpack(nKey, pKey, pRet);
9359893628
}
9359993629
return pRet;
9360093630
}
9360193631
9360293632
/*
@@ -96785,10 +96815,11 @@
9678596815
}
9678696816
n = pOp->p3;
9678796817
pKeyInfo = pOp->p4.pKeyInfo;
9678896818
assert( n>0 );
9678996819
assert( pKeyInfo!=0 );
96820
+ assert( pKeyInfo->aSortFlags!=0 );
9679096821
p1 = pOp->p1;
9679196822
p2 = pOp->p2;
9679296823
#ifdef SQLITE_DEBUG
9679396824
if( aPermute ){
9679496825
int k, mx = 0;
@@ -99658,11 +99689,11 @@
9965899689
rc = ExpandBlob(r.aMem);
9965999690
assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
9966099691
if( rc ) goto no_mem;
9966199692
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
9966299693
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);
9966499695
pIdxKey->default_rc = 0;
9966599696
rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
9966699697
sqlite3DbFreeNN(db, pIdxKey);
9966799698
}
9966899699
if( rc!=SQLITE_OK ){
@@ -104834,11 +104865,11 @@
104834104865
const void *pKey1, int nKey1, /* Left side of comparison */
104835104866
const void *pKey2, int nKey2 /* Right side of comparison */
104836104867
){
104837104868
UnpackedRecord *r2 = pTask->pUnpacked;
104838104869
if( *pbKey2Cached==0 ){
104839
- sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
104870
+ sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
104840104871
*pbKey2Cached = 1;
104841104872
}
104842104873
return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
104843104874
}
104844104875
@@ -104861,11 +104892,11 @@
104861104892
const void *pKey1, int nKey1, /* Left side of comparison */
104862104893
const void *pKey2, int nKey2 /* Right side of comparison */
104863104894
){
104864104895
UnpackedRecord *r2 = pTask->pUnpacked;
104865104896
if( !*pbKey2Cached ){
104866
- sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
104897
+ sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
104867104898
*pbKey2Cached = 1;
104868104899
}
104869104900
return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
104870104901
}
104871104902
@@ -104901,10 +104932,11 @@
104901104932
res = vdbeSorterCompareTail(
104902104933
pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
104903104934
);
104904104935
}
104905104936
}else{
104937
+ assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
104906104938
assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
104907104939
if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
104908104940
res = res * -1;
104909104941
}
104910104942
}
@@ -104964,10 +104996,11 @@
104964104996
}else{
104965104997
if( *v2 & 0x80 ) res = +1;
104966104998
}
104967104999
}
104968105000
105001
+ assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
104969105002
if( res==0 ){
104970105003
if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
104971105004
res = vdbeSorterCompareTail(
104972105005
pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
104973105006
);
@@ -105037,11 +105070,12 @@
105037105070
assert( pCsr->pKeyInfo );
105038105071
assert( !pCsr->isEphemeral );
105039105072
assert( pCsr->eCurType==CURTYPE_SORTER );
105040105073
assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
105041105074
< 0x7fffffff );
105042
- szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nKeyField+1);
105075
+ assert( pCsr->pKeyInfo->nKeyField<=pCsr->pKeyInfo->nAllField );
105076
+ szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nAllField);
105043105077
sz = SZ_VDBESORTER(nWorker+1);
105044105078
105045105079
pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
105046105080
pCsr->uc.pSorter = pSorter;
105047105081
if( pSorter==0 ){
@@ -105051,11 +105085,16 @@
105051105085
pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
105052105086
memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
105053105087
pKeyInfo->db = 0;
105054105088
if( nField && nWorker==0 ){
105055105089
pKeyInfo->nKeyField = nField;
105090
+ assert( nField<=pCsr->pKeyInfo->nAllField );
105056105091
}
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 );
105057105096
sqlite3BtreeEnter(pBt);
105058105097
pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt);
105059105098
sqlite3BtreeLeave(pBt);
105060105099
pSorter->nTask = nWorker + 1;
105061105100
pSorter->iPrev = (u8)(nWorker - 1);
@@ -106831,11 +106870,11 @@
106831106870
r2->nField = nKeyCol;
106832106871
}
106833106872
assert( r2->nField==nKeyCol );
106834106873
106835106874
pKey = vdbeSorterRowkey(pSorter, &nKey);
106836
- sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2);
106875
+ sqlite3VdbeRecordUnpack(nKey, pKey, r2);
106837106876
for(i=0; i<nKeyCol; i++){
106838106877
if( r2->aMem[i].flags & MEM_Null ){
106839106878
*pRes = -1;
106840106879
return SQLITE_OK;
106841106880
}
@@ -110387,11 +110426,13 @@
110387110426
assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
110388110427
return sqlite3ExprAffinity(
110389110428
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
110390110429
);
110391110430
}
110392
- if( op==TK_VECTOR ){
110431
+ if( op==TK_VECTOR
110432
+ || (op==TK_FUNCTION && pExpr->affExpr==SQLITE_AFF_DEFER)
110433
+ ){
110393110434
assert( ExprUseXList(pExpr) );
110394110435
return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110395110436
}
110396110437
if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
110397110438
assert( pExpr->op==TK_COLLATE
@@ -110580,11 +110621,13 @@
110580110621
}
110581110622
if( op==TK_CAST || op==TK_UPLUS ){
110582110623
p = p->pLeft;
110583110624
continue;
110584110625
}
110585
- if( op==TK_VECTOR ){
110626
+ if( op==TK_VECTOR
110627
+ || (op==TK_FUNCTION && p->affExpr==SQLITE_AFF_DEFER)
110628
+ ){
110586110629
assert( ExprUseXList(p) );
110587110630
p = p->x.pList->a[0].pExpr;
110588110631
continue;
110589110632
}
110590110633
if( op==TK_COLLATE ){
@@ -145362,11 +145405,11 @@
145362145405
"not present in both tables", zName);
145363145406
return 1;
145364145407
}
145365145408
pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
145366145409
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 ){
145368145411
/* This branch runs if the query contains one or more RIGHT or FULL
145369145412
** JOINs. If only a single table on the left side of this join
145370145413
** contains the zName column, then this branch is a no-op.
145371145414
** But if there are two or more tables on the left side
145372145415
** of the join, construct a coalesce() function that gathers all
@@ -145378,10 +145421,12 @@
145378145421
** JOIN. But older versions of SQLite do not do that, so we avoid
145379145422
** adding a new error so as to not break legacy applications.
145380145423
*/
145381145424
ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145382145425
static const Token tkCoalesce = { "coalesce", 8 };
145426
+ assert( pE1!=0 );
145427
+ ExprSetProperty(pE1, EP_CanBeNull);
145383145428
while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
145384145429
pRight->fg.isSynthUsing)!=0 ){
145385145430
if( pSrc->a[iLeft].fg.isUsing==0
145386145431
|| sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145387145432
){
@@ -145394,11 +145439,17 @@
145394145439
sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145395145440
}
145396145441
if( pFuncArgs ){
145397145442
pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
145398145443
pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
145444
+ if( pE1 ){
145445
+ pE1->affExpr = SQLITE_AFF_DEFER;
145446
+ }
145399145447
}
145448
+ }else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){
145449
+ assert( pE1!=0 );
145450
+ ExprSetProperty(pE1, EP_CanBeNull);
145400145451
}
145401145452
pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
145402145453
sqlite3SrcItemColumnUsed(pRight, iRightCol);
145403145454
pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
145404145455
assert( pE2!=0 || pEq==0 );
@@ -146871,10 +146922,14 @@
146871146922
#else
146872146923
zType = columnType(&sNC, p, 0, 0, 0);
146873146924
#endif
146874146925
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
146875146926
}
146927
+#else
146928
+ UNUSED_PARAMETER(pParse);
146929
+ UNUSED_PARAMETER(pTabList);
146930
+ UNUSED_PARAMETER(pEList);
146876146931
#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
146877146932
}
146878146933
146879146934
146880146935
/*
@@ -149002,13 +149057,13 @@
149002149057
** other than the one FROM-clause subquery that is a candidate
149003149058
** for flattening. (This is due to ticket [2f7170d73bf9abf80]
149004149059
** from 2015-02-09.)
149005149060
**
149006149061
** (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"
149010149065
** (**) Was: "The outer query may not have a GROUP BY." This case
149011149066
** is now managed correctly
149012149067
** (3d) the outer query may not be DISTINCT.
149013149068
** See also (26) for restrictions on RIGHT JOIN.
149014149069
**
@@ -149220,11 +149275,11 @@
149220149275
**
149221149276
** See also tickets #306, #350, and #3300.
149222149277
*/
149223149278
if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149224149279
if( pSubSrc->nSrc>1 /* (3a) */
149225
- || IsVirtual(pSubSrc->a[0].pSTab) /* (3b) */
149280
+ /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */
149226149281
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
149227149282
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149228149283
){
149229149284
return 0;
149230149285
}
@@ -157245,11 +157300,12 @@
157245157300
saved_flags = db->flags;
157246157301
saved_mDbFlags = db->mDbFlags;
157247157302
saved_nChange = db->nChange;
157248157303
saved_nTotalChange = db->nTotalChange;
157249157304
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;
157251157307
db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
157252157308
db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder
157253157309
| SQLITE_Defensive | SQLITE_CountRows);
157254157310
db->mTrace = 0;
157255157311
@@ -161720,16 +161776,17 @@
161720161776
}
161721161777
161722161778
if( pLevel->iLeftJoin==0 ){
161723161779
/* If a partial index is driving the loop, try to eliminate WHERE clause
161724161780
** 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:
161726161783
**
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)
161729161786
*/
161730
- if( pIdx->pPartIdxWhere ){
161787
+ if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){
161731161788
whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
161732161789
}
161733161790
}else{
161734161791
testcase( pIdx->pPartIdxWhere );
161735161792
/* The following assert() is not a requirement, merely an observation:
@@ -188786,11 +188843,11 @@
188786188843
188787188844
/*
188788188845
** Macros needed to provide flexible arrays in a portable way
188789188846
*/
188790188847
#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))
188792188849
#endif
188793188850
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
188794188851
# define FLEXARRAY
188795188852
#else
188796188853
# define FLEXARRAY 1
@@ -209019,12 +209076,14 @@
209019209076
nExtra = 0;
209020209077
}else if( szType==12 ){
209021209078
nExtra = 1;
209022209079
}else if( szType==13 ){
209023209080
nExtra = 2;
209024
- }else{
209081
+ }else if( szType==14 ){
209025209082
nExtra = 4;
209083
+ }else{
209084
+ nExtra = 8;
209026209085
}
209027209086
if( szPayload<=11 ){
209028209087
nNeeded = 0;
209029209088
}else if( szPayload<=0xff ){
209030209089
nNeeded = 1;
@@ -213405,10 +213464,12 @@
213405213464
#else
213406213465
/* #include "sqlite3.h" */
213407213466
#endif
213408213467
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
213409213468
213469
+/* #include <stddef.h> */
213470
+
213410213471
/*
213411213472
** If building separately, we will need some setup that is normally
213412213473
** found in sqliteInt.h
213413213474
*/
213414213475
#if !defined(SQLITE_AMALGAMATION)
@@ -213436,11 +213497,11 @@
213436213497
#else
213437213498
# define ALWAYS(X) (X)
213438213499
# define NEVER(X) (X)
213439213500
#endif
213440213501
#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))
213442213503
#endif
213443213504
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
213444213505
# define FLEXARRAY
213445213506
#else
213446213507
# define FLEXARRAY 1
@@ -227753,11 +227814,12 @@
227753227814
DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
227754227815
int rc;
227755227816
sqlite3 *db = pTab->db;
227756227817
Btree *pBt;
227757227818
227758
- (void)idxStr;
227819
+ UNUSED_PARAMETER(idxStr);
227820
+ UNUSED_PARAMETER(argc);
227759227821
227760227822
/* Default setting is no rows of result */
227761227823
pCsr->pgno = 1;
227762227824
pCsr->mxPgno = 0;
227763227825
@@ -235447,10 +235509,11 @@
235447235509
/* #include "sqlite3ext.h" */
235448235510
SQLITE_EXTENSION_INIT1
235449235511
235450235512
/* #include <string.h> */
235451235513
/* #include <assert.h> */
235514
+/* #include <stddef.h> */
235452235515
235453235516
#ifndef SQLITE_AMALGAMATION
235454235517
235455235518
typedef unsigned char u8;
235456235519
typedef unsigned int u32;
@@ -235506,11 +235569,11 @@
235506235569
235507235570
/*
235508235571
** Macros needed to provide flexible arrays in a portable way
235509235572
*/
235510235573
#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))
235512235575
#endif
235513235576
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
235514235577
# define FLEXARRAY
235515235578
#else
235516235579
# define FLEXARRAY 1
@@ -257190,11 +257253,11 @@
257190257253
int nArg, /* Number of args */
257191257254
sqlite3_value **apUnused /* Function arguments */
257192257255
){
257193257256
assert( nArg==0 );
257194257257
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);
257196257259
}
257197257260
257198257261
/*
257199257262
** Implementation of fts5_locale(LOCALE, TEXT) function.
257200257263
**
257201257264
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
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
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** dfc790f998f450d9c35e3ba1c8c89c17466c with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
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"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -15174,11 +15174,11 @@
15174 /*
15175 ** GCC does not define the offsetof() macro so we'll have to do it
15176 ** ourselves.
15177 */
15178 #ifndef offsetof
15179 #define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
15180 #endif
15181
15182 /*
15183 ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
15184 ** to avoid complaints from -fsanitize=strict-bounds.
@@ -17401,11 +17401,11 @@
17401 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
17402 #endif
17403 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
17404 SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*);
17405
17406 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
17407 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
17408 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
17409 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
17410
17411 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
@@ -18701,10 +18701,11 @@
18701 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
18702 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
18703 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
18704 #define SQLITE_AFF_REAL 0x45 /* 'E' */
18705 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
 
18706
18707 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
18708
18709 /*
18710 ** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -19016,13 +19017,19 @@
19016 /*
19017 ** An instance of the following structure is passed as the first
19018 ** argument to sqlite3VdbeKeyCompare and is used to control the
19019 ** comparison of the two index keys.
19020 **
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.
 
 
 
 
 
 
19024 */
19025 struct KeyInfo {
19026 u32 nRef; /* Number of references to this KeyInfo object */
19027 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
19028 u16 nKeyField; /* Number of key columns in the index */
@@ -19030,12 +19037,21 @@
19030 sqlite3 *db; /* The database connection */
19031 u8 *aSortFlags; /* Sort order for each column. */
19032 CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */
19033 };
19034
19035 /* The size (in bytes) of a KeyInfo object with up to N fields */
 
 
19036 #define SZ_KEYINFO(N) (offsetof(KeyInfo,aColl) + (N)*sizeof(CollSeq*))
 
 
 
 
 
 
 
19037
19038 /*
19039 ** Allowed bit values for entries in the KeyInfo.aSortFlags[] array.
19040 */
19041 #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
@@ -19051,23 +19067,22 @@
19051 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
19052 ** OP_Column opcode.
19053 **
19054 ** An instance of this object serves as a "key" for doing a search on
19055 ** 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.
19059 **
19060 ** The r1 and r2 fields are the values to return if this key is less than
19061 ** or greater than a key in the btree, respectively. These are normally
19062 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
19063 ** is in DESC order.
19064 **
19065 ** The key comparison functions actually return default_rc when they find
19066 ** an equals comparison. default_rc can be -1, 0, or +1. If there are
19067 ** 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
19069 ** cause the search to find the last match, or +1 to cause the search to
19070 ** find the first match.
19071 **
19072 ** The key comparison functions will set eqSeen to true if they ever
19073 ** get and equal results when comparing this structure to a b-tree record.
@@ -19075,12 +19090,12 @@
19075 ** before the first match or immediately after the last match. The
19076 ** eqSeen field will indicate whether or not an exact match exists in the
19077 ** b-tree.
19078 */
19079 struct UnpackedRecord {
19080 KeyInfo *pKeyInfo; /* Collation and sort-order information */
19081 Mem *aMem; /* Values */
19082 union {
19083 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
19084 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
19085 } u;
19086 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
@@ -24132,11 +24147,11 @@
24132 Mem oldipk; /* Memory cell holding "old" IPK value */
24133 Mem *aNew; /* Array of new.* values */
24134 Table *pTab; /* Schema object being updated */
24135 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
24136 sqlite3_value **apDflt; /* Array of default values, if required */
24137 u8 keyinfoSpace[SZ_KEYINFO(0)]; /* Space to hold pKeyinfo[0] content */
24138 };
24139
24140 /*
24141 ** An instance of this object is used to pass an vector of values into
24142 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -43872,25 +43887,24 @@
43872 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
43873
43874 /* Check that, if this to be a blocking lock, no locks that occur later
43875 ** in the following list than the lock being obtained are already held:
43876 **
43877 ** 1. Checkpointer lock (ofst==1).
43878 ** 2. Write lock (ofst==0).
43879 ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
 
43880 **
43881 ** In other words, if this is a blocking lock, none of the locks that
43882 ** occur later in the above list than the lock being obtained may be
43883 ** held.
43884 **
43885 ** It is not permitted to block on the RECOVER lock.
43886 */
43887 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
43888 {
43889 u16 lockMask = (p->exclMask|p->sharedMask);
43890 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43891 (ofst!=2) /* not RECOVER */
43892 && (ofst!=1 || lockMask==0 || lockMask==2)
43893 && (ofst!=0 || lockMask<3)
43894 && (ofst<3 || lockMask<(1<<ofst))
43895 ));
43896 }
@@ -49847,11 +49861,15 @@
49847 DWORD nDelay = (nMs==0 ? INFINITE : nMs);
49848 DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
49849 if( res==WAIT_OBJECT_0 ){
49850 ret = TRUE;
49851 }else if( res==WAIT_TIMEOUT ){
 
49852 rc = SQLITE_BUSY_TIMEOUT;
 
 
 
49853 }else{
49854 /* Some other error has occurred */
49855 rc = SQLITE_IOERR_LOCK;
49856 }
49857
@@ -51658,25 +51676,24 @@
51658 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
51659
51660 /* Check that, if this to be a blocking lock, no locks that occur later
51661 ** in the following list than the lock being obtained are already held:
51662 **
51663 ** 1. Checkpointer lock (ofst==1).
51664 ** 2. Write lock (ofst==0).
51665 ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
 
51666 **
51667 ** In other words, if this is a blocking lock, none of the locks that
51668 ** occur later in the above list than the lock being obtained may be
51669 ** held.
51670 **
51671 ** It is not permitted to block on the RECOVER lock.
51672 */
51673 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
51674 {
51675 u16 lockMask = (p->exclMask|p->sharedMask);
51676 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51677 (ofst!=2) /* not RECOVER */
51678 && (ofst!=1 || lockMask==0 || lockMask==2)
51679 && (ofst!=0 || lockMask<3)
51680 && (ofst<3 || lockMask<(1<<ofst))
51681 ));
51682 }
@@ -58748,10 +58765,13 @@
58748 PCache *pPCache; /* Pointer to page cache object */
58749 #ifndef SQLITE_OMIT_WAL
58750 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
58751 char *zWal; /* File name for write-ahead log */
58752 #endif
 
 
 
58753 };
58754
58755 /*
58756 ** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
58757 ** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS
@@ -65629,10 +65649,15 @@
65629 if( rc==SQLITE_OK ){
65630 rc = sqlite3WalOpen(pPager->pVfs,
65631 pPager->fd, pPager->zWal, pPager->exclusiveMode,
65632 pPager->journalSizeLimit, &pPager->pWal
65633 );
 
 
 
 
 
65634 }
65635 pagerFixMaplimit(pPager);
65636
65637 return rc;
65638 }
@@ -65748,10 +65773,11 @@
65748 /*
65749 ** Set the database handle used by the wal layer to determine if
65750 ** blocking locks are required.
65751 */
65752 SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
 
65753 if( pagerUseWal(pPager) ){
65754 sqlite3WalDb(pPager->pWal, db);
65755 }
65756 }
65757 #endif
@@ -68921,11 +68947,10 @@
68921 assert( rc==SQLITE_OK );
68922 if( pWal->bShmUnreliable==0 ){
68923 rc = walIndexReadHdr(pWal, pChanged);
68924 }
68925 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
68926 walDisableBlocking(pWal);
68927 if( rc==SQLITE_BUSY_TIMEOUT ){
68928 rc = SQLITE_BUSY;
68929 *pCnt |= WAL_RETRY_BLOCKED_MASK;
68930 }
68931 #endif
@@ -68936,10 +68961,11 @@
68936 ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
68937 ** would be technically correct. But the race is benign since with
68938 ** WAL_RETRY this routine will be called again and will probably be
68939 ** right on the second iteration.
68940 */
 
68941 if( pWal->apWiData[0]==0 ){
68942 /* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
68943 ** We assume this is a transient condition, so return WAL_RETRY. The
68944 ** xShmMap() implementation used by the default unix and win32 VFS
68945 ** modules may return SQLITE_BUSY due to a race condition in the
@@ -68952,10 +68978,11 @@
68952 rc = WAL_RETRY;
68953 }else if( rc==SQLITE_BUSY ){
68954 rc = SQLITE_BUSY_RECOVERY;
68955 }
68956 }
 
68957 if( rc!=SQLITE_OK ){
68958 return rc;
68959 }
68960 else if( pWal->bShmUnreliable ){
68961 return walBeginShmUnreliable(pWal, pChanged);
@@ -72401,11 +72428,11 @@
72401 if( pKey ){
72402 KeyInfo *pKeyInfo = pCur->pKeyInfo;
72403 assert( nKey==(i64)(int)nKey );
72404 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
72405 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72406 sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
72407 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
72408 rc = SQLITE_CORRUPT_BKPT;
72409 }else{
72410 rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes);
72411 }
@@ -74385,10 +74412,11 @@
74385 removed = 1;
74386 }
74387 sqlite3_mutex_leave(pMainMtx);
74388 return removed;
74389 #else
 
74390 return 1;
74391 #endif
74392 }
74393
74394 /*
@@ -75226,10 +75254,17 @@
75226
75227 if( rc!=SQLITE_OK ){
75228 (void)sqlite3PagerWalWriteLock(pPager, 0);
75229 unlockBtreeIfUnused(pBt);
75230 }
 
 
 
 
 
 
 
75231 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
75232 btreeInvokeBusyHandler(pBt) );
75233 sqlite3PagerWalDb(pPager, 0);
75234 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
75235 if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
@@ -82846,10 +82881,11 @@
82846 ** btree as the argument handle holds an exclusive lock on the
82847 ** sqlite_schema table. Otherwise SQLITE_OK.
82848 */
82849 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
82850 int rc;
 
82851 assert( sqlite3_mutex_held(p->db->mutex) );
82852 sqlite3BtreeEnter(p);
82853 rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
82854 assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
82855 sqlite3BtreeLeave(p);
@@ -90066,34 +90102,26 @@
90066 }
90067 }
90068 return;
90069 }
90070 /*
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.
90083 */
90084 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
90085 KeyInfo *pKeyInfo /* Description of the record */
90086 ){
90087 UnpackedRecord *p; /* Unpacked record to return */
90088 int nByte; /* Number of bytes required for *p */
90089 assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
90090 nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
90091 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
90092 if( !p ) return 0;
90093 p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
90094 assert( pKeyInfo->aSortFlags!=0 );
90095 p->pKeyInfo = pKeyInfo;
90096 p->nField = pKeyInfo->nKeyField + 1;
90097 return p;
90098 }
90099
@@ -90101,11 +90129,10 @@
90101 ** Given the nKey-byte encoding of a record in pKey[], populate the
90102 ** UnpackedRecord structure indicated by the fourth argument with the
90103 ** contents of the decoded record.
90104 */
90105 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(
90106 KeyInfo *pKeyInfo, /* Information about the record format */
90107 int nKey, /* Size of the binary record */
90108 const void *pKey, /* The binary record */
90109 UnpackedRecord *p /* Populate this structure before returning. */
90110 ){
90111 const unsigned char *aKey = (const unsigned char *)pKey;
@@ -90112,10 +90139,11 @@
90112 u32 d;
90113 u32 idx; /* Offset in aKey[] to read from */
90114 u16 u; /* Unsigned loop counter */
90115 u32 szHdr;
90116 Mem *pMem = p->aMem;
 
90117
90118 p->default_rc = 0;
90119 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
90120 idx = getVarint32(aKey, szHdr);
90121 d = szHdr;
@@ -90139,10 +90167,12 @@
90139 /* In a corrupt record entry, the last pMem might have been set up using
90140 ** uninitialized memory. Overwrite its value with NULL, to prevent
90141 ** warnings from MSAN. */
90142 sqlite3VdbeMemSetNull(pMem-1);
90143 }
 
 
90144 assert( u<=pKeyInfo->nKeyField + 1 );
90145 p->nField = u;
90146 }
90147
90148 #ifdef SQLITE_DEBUG
@@ -90998,10 +91028,11 @@
90998 ** is an integer.
90999 **
91000 ** The easiest way to enforce this limit is to consider only records with
91001 ** 13 fields or less. If the first field is an integer, the maximum legal
91002 ** header size is (12*5 + 1 + 1) bytes. */
 
91003 if( p->pKeyInfo->nAllField<=13 ){
91004 int flags = p->aMem[0].flags;
91005 if( p->pKeyInfo->aSortFlags[0] ){
91006 if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
91007 return sqlite3VdbeRecordCompare;
@@ -91356,11 +91387,10 @@
91356 ){
91357 sqlite3 *db = v->db;
91358 i64 iKey2;
91359 PreUpdate preupdate;
91360 const char *zTbl = pTab->zName;
91361 static const u8 fakeSortOrder = 0;
91362 #ifdef SQLITE_DEBUG
91363 int nRealCol;
91364 if( pTab->tabFlags & TF_WithoutRowid ){
91365 nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
91366 }else if( pTab->tabFlags & TF_HasVirtual ){
@@ -91395,11 +91425,11 @@
91395 preupdate.iNewReg = iReg;
91396 preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
91397 preupdate.pKeyinfo->db = db;
91398 preupdate.pKeyinfo->enc = ENC(db);
91399 preupdate.pKeyinfo->nKeyField = pTab->nCol;
91400 preupdate.pKeyinfo->aSortFlags = (u8*)&fakeSortOrder;
91401 preupdate.iKey1 = iKey1;
91402 preupdate.iKey2 = iKey2;
91403 preupdate.pTab = pTab;
91404 preupdate.iBlobWrite = iBlobWrite;
91405
@@ -93592,11 +93622,11 @@
93592 UnpackedRecord *pRet; /* Return value */
93593
93594 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
93595 if( pRet ){
93596 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93597 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
93598 }
93599 return pRet;
93600 }
93601
93602 /*
@@ -96785,10 +96815,11 @@
96785 }
96786 n = pOp->p3;
96787 pKeyInfo = pOp->p4.pKeyInfo;
96788 assert( n>0 );
96789 assert( pKeyInfo!=0 );
 
96790 p1 = pOp->p1;
96791 p2 = pOp->p2;
96792 #ifdef SQLITE_DEBUG
96793 if( aPermute ){
96794 int k, mx = 0;
@@ -99658,11 +99689,11 @@
99658 rc = ExpandBlob(r.aMem);
99659 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
99660 if( rc ) goto no_mem;
99661 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
99662 if( pIdxKey==0 ) goto no_mem;
99663 sqlite3VdbeRecordUnpack(pC->pKeyInfo, r.aMem->n, r.aMem->z, pIdxKey);
99664 pIdxKey->default_rc = 0;
99665 rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
99666 sqlite3DbFreeNN(db, pIdxKey);
99667 }
99668 if( rc!=SQLITE_OK ){
@@ -104834,11 +104865,11 @@
104834 const void *pKey1, int nKey1, /* Left side of comparison */
104835 const void *pKey2, int nKey2 /* Right side of comparison */
104836 ){
104837 UnpackedRecord *r2 = pTask->pUnpacked;
104838 if( *pbKey2Cached==0 ){
104839 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
104840 *pbKey2Cached = 1;
104841 }
104842 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
104843 }
104844
@@ -104861,11 +104892,11 @@
104861 const void *pKey1, int nKey1, /* Left side of comparison */
104862 const void *pKey2, int nKey2 /* Right side of comparison */
104863 ){
104864 UnpackedRecord *r2 = pTask->pUnpacked;
104865 if( !*pbKey2Cached ){
104866 sqlite3VdbeRecordUnpack(pTask->pSorter->pKeyInfo, nKey2, pKey2, r2);
104867 *pbKey2Cached = 1;
104868 }
104869 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
104870 }
104871
@@ -104901,10 +104932,11 @@
104901 res = vdbeSorterCompareTail(
104902 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
104903 );
104904 }
104905 }else{
 
104906 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
104907 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
104908 res = res * -1;
104909 }
104910 }
@@ -104964,10 +104996,11 @@
104964 }else{
104965 if( *v2 & 0x80 ) res = +1;
104966 }
104967 }
104968
 
104969 if( res==0 ){
104970 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
104971 res = vdbeSorterCompareTail(
104972 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
104973 );
@@ -105037,11 +105070,12 @@
105037 assert( pCsr->pKeyInfo );
105038 assert( !pCsr->isEphemeral );
105039 assert( pCsr->eCurType==CURTYPE_SORTER );
105040 assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
105041 < 0x7fffffff );
105042 szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nKeyField+1);
 
105043 sz = SZ_VDBESORTER(nWorker+1);
105044
105045 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
105046 pCsr->uc.pSorter = pSorter;
105047 if( pSorter==0 ){
@@ -105051,11 +105085,16 @@
105051 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
105052 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
105053 pKeyInfo->db = 0;
105054 if( nField && nWorker==0 ){
105055 pKeyInfo->nKeyField = nField;
 
105056 }
 
 
 
 
105057 sqlite3BtreeEnter(pBt);
105058 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt);
105059 sqlite3BtreeLeave(pBt);
105060 pSorter->nTask = nWorker + 1;
105061 pSorter->iPrev = (u8)(nWorker - 1);
@@ -106831,11 +106870,11 @@
106831 r2->nField = nKeyCol;
106832 }
106833 assert( r2->nField==nKeyCol );
106834
106835 pKey = vdbeSorterRowkey(pSorter, &nKey);
106836 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, r2);
106837 for(i=0; i<nKeyCol; i++){
106838 if( r2->aMem[i].flags & MEM_Null ){
106839 *pRes = -1;
106840 return SQLITE_OK;
106841 }
@@ -110387,11 +110426,13 @@
110387 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
110388 return sqlite3ExprAffinity(
110389 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
110390 );
110391 }
110392 if( op==TK_VECTOR ){
 
 
110393 assert( ExprUseXList(pExpr) );
110394 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110395 }
110396 if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
110397 assert( pExpr->op==TK_COLLATE
@@ -110580,11 +110621,13 @@
110580 }
110581 if( op==TK_CAST || op==TK_UPLUS ){
110582 p = p->pLeft;
110583 continue;
110584 }
110585 if( op==TK_VECTOR ){
 
 
110586 assert( ExprUseXList(p) );
110587 p = p->x.pList->a[0].pExpr;
110588 continue;
110589 }
110590 if( op==TK_COLLATE ){
@@ -145362,11 +145405,11 @@
145362 "not present in both tables", zName);
145363 return 1;
145364 }
145365 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
145366 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145367 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
145368 /* This branch runs if the query contains one or more RIGHT or FULL
145369 ** JOINs. If only a single table on the left side of this join
145370 ** contains the zName column, then this branch is a no-op.
145371 ** But if there are two or more tables on the left side
145372 ** of the join, construct a coalesce() function that gathers all
@@ -145378,10 +145421,12 @@
145378 ** JOIN. But older versions of SQLite do not do that, so we avoid
145379 ** adding a new error so as to not break legacy applications.
145380 */
145381 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145382 static const Token tkCoalesce = { "coalesce", 8 };
 
 
145383 while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
145384 pRight->fg.isSynthUsing)!=0 ){
145385 if( pSrc->a[iLeft].fg.isUsing==0
145386 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145387 ){
@@ -145394,11 +145439,17 @@
145394 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145395 }
145396 if( pFuncArgs ){
145397 pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
145398 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
 
 
 
145399 }
 
 
 
145400 }
145401 pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
145402 sqlite3SrcItemColumnUsed(pRight, iRightCol);
145403 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
145404 assert( pE2!=0 || pEq==0 );
@@ -146871,10 +146922,14 @@
146871 #else
146872 zType = columnType(&sNC, p, 0, 0, 0);
146873 #endif
146874 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
146875 }
 
 
 
 
146876 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
146877 }
146878
146879
146880 /*
@@ -149002,13 +149057,13 @@
149002 ** other than the one FROM-clause subquery that is a candidate
149003 ** for flattening. (This is due to ticket [2f7170d73bf9abf80]
149004 ** from 2015-02-09.)
149005 **
149006 ** (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
149010 ** (**) Was: "The outer query may not have a GROUP BY." This case
149011 ** is now managed correctly
149012 ** (3d) the outer query may not be DISTINCT.
149013 ** See also (26) for restrictions on RIGHT JOIN.
149014 **
@@ -149220,11 +149275,11 @@
149220 **
149221 ** See also tickets #306, #350, and #3300.
149222 */
149223 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149224 if( pSubSrc->nSrc>1 /* (3a) */
149225 || IsVirtual(pSubSrc->a[0].pSTab) /* (3b) */
149226 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
149227 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149228 ){
149229 return 0;
149230 }
@@ -157245,11 +157300,12 @@
157245 saved_flags = db->flags;
157246 saved_mDbFlags = db->mDbFlags;
157247 saved_nChange = db->nChange;
157248 saved_nTotalChange = db->nTotalChange;
157249 saved_mTrace = db->mTrace;
157250 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments;
 
157251 db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
157252 db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder
157253 | SQLITE_Defensive | SQLITE_CountRows);
157254 db->mTrace = 0;
157255
@@ -161720,16 +161776,17 @@
161720 }
161721
161722 if( pLevel->iLeftJoin==0 ){
161723 /* If a partial index is driving the loop, try to eliminate WHERE clause
161724 ** terms from the query that must be true due to the WHERE clause of
161725 ** the partial index.
 
161726 **
161727 ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work
161728 ** for a LEFT JOIN.
161729 */
161730 if( pIdx->pPartIdxWhere ){
161731 whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
161732 }
161733 }else{
161734 testcase( pIdx->pPartIdxWhere );
161735 /* The following assert() is not a requirement, merely an observation:
@@ -188786,11 +188843,11 @@
188786
188787 /*
188788 ** Macros needed to provide flexible arrays in a portable way
188789 */
188790 #ifndef offsetof
188791 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
188792 #endif
188793 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
188794 # define FLEXARRAY
188795 #else
188796 # define FLEXARRAY 1
@@ -209019,12 +209076,14 @@
209019 nExtra = 0;
209020 }else if( szType==12 ){
209021 nExtra = 1;
209022 }else if( szType==13 ){
209023 nExtra = 2;
209024 }else{
209025 nExtra = 4;
 
 
209026 }
209027 if( szPayload<=11 ){
209028 nNeeded = 0;
209029 }else if( szPayload<=0xff ){
209030 nNeeded = 1;
@@ -213405,10 +213464,12 @@
213405 #else
213406 /* #include "sqlite3.h" */
213407 #endif
213408 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
213409
 
 
213410 /*
213411 ** If building separately, we will need some setup that is normally
213412 ** found in sqliteInt.h
213413 */
213414 #if !defined(SQLITE_AMALGAMATION)
@@ -213436,11 +213497,11 @@
213436 #else
213437 # define ALWAYS(X) (X)
213438 # define NEVER(X) (X)
213439 #endif
213440 #ifndef offsetof
213441 #define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
213442 #endif
213443 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
213444 # define FLEXARRAY
213445 #else
213446 # define FLEXARRAY 1
@@ -227753,11 +227814,12 @@
227753 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
227754 int rc;
227755 sqlite3 *db = pTab->db;
227756 Btree *pBt;
227757
227758 (void)idxStr;
 
227759
227760 /* Default setting is no rows of result */
227761 pCsr->pgno = 1;
227762 pCsr->mxPgno = 0;
227763
@@ -235447,10 +235509,11 @@
235447 /* #include "sqlite3ext.h" */
235448 SQLITE_EXTENSION_INIT1
235449
235450 /* #include <string.h> */
235451 /* #include <assert.h> */
 
235452
235453 #ifndef SQLITE_AMALGAMATION
235454
235455 typedef unsigned char u8;
235456 typedef unsigned int u32;
@@ -235506,11 +235569,11 @@
235506
235507 /*
235508 ** Macros needed to provide flexible arrays in a portable way
235509 */
235510 #ifndef offsetof
235511 # define offsetof(STRUCTURE,FIELD) ((size_t)((char*)&((STRUCTURE*)0)->FIELD))
235512 #endif
235513 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
235514 # define FLEXARRAY
235515 #else
235516 # define FLEXARRAY 1
@@ -257190,11 +257253,11 @@
257190 int nArg, /* Number of args */
257191 sqlite3_value **apUnused /* Function arguments */
257192 ){
257193 assert( nArg==0 );
257194 UNUSED_PARAM2(nArg, apUnused);
257195 sqlite3_result_text(pCtx, "fts5: 2025-05-29 14:26:00 dfc790f998f450d9c35e3ba1c8c89c17466cb559f87b0239e4aab9d34e28f742", -1, SQLITE_TRANSIENT);
257196 }
257197
257198 /*
257199 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257200 **
257201
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.51.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** ea1754f7d8a770477a1b19b606b27724fdc0 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
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
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -15174,11 +15174,11 @@
15174 /*
15175 ** GCC does not define the offsetof() macro so we'll have to do it
15176 ** ourselves.
15177 */
15178 #ifndef offsetof
15179 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
15180 #endif
15181
15182 /*
15183 ** Work around C99 "flex-array" syntax for pre-C99 compilers, so as
15184 ** to avoid complaints from -fsanitize=strict-bounds.
@@ -17401,11 +17401,11 @@
17401 SQLITE_PRIVATE char *sqlite3VdbeExpandSql(Vdbe*, const char*);
17402 #endif
17403 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
17404 SQLITE_PRIVATE int sqlite3BlobCompare(const Mem*, const Mem*);
17405
17406 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(int,const void*,UnpackedRecord*);
17407 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
17408 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
17409 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
17410
17411 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
@@ -18701,10 +18701,11 @@
18701 #define SQLITE_AFF_TEXT 0x42 /* 'B' */
18702 #define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
18703 #define SQLITE_AFF_INTEGER 0x44 /* 'D' */
18704 #define SQLITE_AFF_REAL 0x45 /* 'E' */
18705 #define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
18706 #define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */
18707
18708 #define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
18709
18710 /*
18711 ** The SQLITE_AFF_MASK values masks off the significant bits of an
@@ -19016,13 +19017,19 @@
19017 /*
19018 ** An instance of the following structure is passed as the first
19019 ** argument to sqlite3VdbeKeyCompare and is used to control the
19020 ** comparison of the two index keys.
19021 **
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.
19031 */
19032 struct KeyInfo {
19033 u32 nRef; /* Number of references to this KeyInfo object */
19034 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
19035 u16 nKeyField; /* Number of key columns in the index */
@@ -19030,12 +19037,21 @@
19037 sqlite3 *db; /* The database connection */
19038 u8 *aSortFlags; /* Sort order for each column. */
19039 CollSeq *aColl[FLEXARRAY]; /* Collating sequence for each term of the key */
19040 };
19041
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[]. */
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
19053
19054 /*
19055 ** Allowed bit values for entries in the KeyInfo.aSortFlags[] array.
19056 */
19057 #define KEYINFO_ORDER_DESC 0x01 /* DESC sort order */
@@ -19051,23 +19067,22 @@
19067 ** the OP_MakeRecord opcode of the VDBE and is disassembled by the
19068 ** OP_Column opcode.
19069 **
19070 ** An instance of this object serves as a "key" for doing a search on
19071 ** an index b+tree. The goal of the search is to find the entry that
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.
 
19074 **
19075 ** The r1 and r2 fields are the values to return if this key is less than
19076 ** or greater than a key in the btree, respectively. These are normally
19077 ** -1 and +1 respectively, but might be inverted to +1 and -1 if the b-tree
19078 ** is in DESC order.
19079 **
19080 ** The key comparison functions actually return default_rc when they find
19081 ** an equals comparison. default_rc can be -1, 0, or +1. If there are
19082 ** multiple entries in the b-tree with the same key (when only looking
19083 ** at the first nField elements) then default_rc can be set to -1 to
19084 ** cause the search to find the last match, or +1 to cause the search to
19085 ** find the first match.
19086 **
19087 ** The key comparison functions will set eqSeen to true if they ever
19088 ** get and equal results when comparing this structure to a b-tree record.
@@ -19075,12 +19090,12 @@
19090 ** before the first match or immediately after the last match. The
19091 ** eqSeen field will indicate whether or not an exact match exists in the
19092 ** b-tree.
19093 */
19094 struct UnpackedRecord {
19095 KeyInfo *pKeyInfo; /* Comparison info for the index that is unpacked */
19096 Mem *aMem; /* Values for columns of the index */
19097 union {
19098 char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */
19099 i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */
19100 } u;
19101 int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */
@@ -24132,11 +24147,11 @@
24147 Mem oldipk; /* Memory cell holding "old" IPK value */
24148 Mem *aNew; /* Array of new.* values */
24149 Table *pTab; /* Schema object being updated */
24150 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
24151 sqlite3_value **apDflt; /* Array of default values, if required */
24152 u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
24153 };
24154
24155 /*
24156 ** An instance of this object is used to pass an vector of values into
24157 ** OP_VFilter, the xFilter method of a virtual table. The vector is the
@@ -43872,25 +43887,24 @@
43887 assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 );
43888
43889 /* Check that, if this to be a blocking lock, no locks that occur later
43890 ** in the following list than the lock being obtained are already held:
43891 **
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).
43896 **
43897 ** In other words, if this is a blocking lock, none of the locks that
43898 ** occur later in the above list than the lock being obtained may be
43899 ** held.
 
 
43900 */
43901 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
43902 {
43903 u16 lockMask = (p->exclMask|p->sharedMask);
43904 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43905 (ofst!=2 || lockMask==0)
43906 && (ofst!=1 || lockMask==0 || lockMask==2)
43907 && (ofst!=0 || lockMask<3)
43908 && (ofst<3 || lockMask<(1<<ofst))
43909 ));
43910 }
@@ -49847,11 +49861,15 @@
49861 DWORD nDelay = (nMs==0 ? INFINITE : nMs);
49862 DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
49863 if( res==WAIT_OBJECT_0 ){
49864 ret = TRUE;
49865 }else if( res==WAIT_TIMEOUT ){
49866 #if SQLITE_ENABLE_SETLK_TIMEOUT==1
49867 rc = SQLITE_BUSY_TIMEOUT;
49868 #else
49869 rc = SQLITE_BUSY;
49870 #endif
49871 }else{
49872 /* Some other error has occurred */
49873 rc = SQLITE_IOERR_LOCK;
49874 }
49875
@@ -51658,25 +51676,24 @@
51676 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
51677
51678 /* Check that, if this to be a blocking lock, no locks that occur later
51679 ** in the following list than the lock being obtained are already held:
51680 **
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).
51685 **
51686 ** In other words, if this is a blocking lock, none of the locks that
51687 ** occur later in the above list than the lock being obtained may be
51688 ** held.
 
 
51689 */
51690 #if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
51691 {
51692 u16 lockMask = (p->exclMask|p->sharedMask);
51693 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51694 (ofst!=2 || lockMask==0)
51695 && (ofst!=1 || lockMask==0 || lockMask==2)
51696 && (ofst!=0 || lockMask<3)
51697 && (ofst<3 || lockMask<(1<<ofst))
51698 ));
51699 }
@@ -58748,10 +58765,13 @@
58765 PCache *pPCache; /* Pointer to page cache object */
58766 #ifndef SQLITE_OMIT_WAL
58767 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
58768 char *zWal; /* File name for write-ahead log */
58769 #endif
58770 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
58771 sqlite3 *dbWal;
58772 #endif
58773 };
58774
58775 /*
58776 ** Indexes for use with Pager.aStat[]. The Pager.aStat[] array contains
58777 ** the values accessed by passing SQLITE_DBSTATUS_CACHE_HIT, CACHE_MISS
@@ -65629,10 +65649,15 @@
65649 if( rc==SQLITE_OK ){
65650 rc = sqlite3WalOpen(pPager->pVfs,
65651 pPager->fd, pPager->zWal, pPager->exclusiveMode,
65652 pPager->journalSizeLimit, &pPager->pWal
65653 );
65654 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
65655 if( rc==SQLITE_OK ){
65656 sqlite3WalDb(pPager->pWal, pPager->dbWal);
65657 }
65658 #endif
65659 }
65660 pagerFixMaplimit(pPager);
65661
65662 return rc;
65663 }
@@ -65748,10 +65773,11 @@
65773 /*
65774 ** Set the database handle used by the wal layer to determine if
65775 ** blocking locks are required.
65776 */
65777 SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
65778 pPager->dbWal = db;
65779 if( pagerUseWal(pPager) ){
65780 sqlite3WalDb(pPager->pWal, db);
65781 }
65782 }
65783 #endif
@@ -68921,11 +68947,10 @@
68947 assert( rc==SQLITE_OK );
68948 if( pWal->bShmUnreliable==0 ){
68949 rc = walIndexReadHdr(pWal, pChanged);
68950 }
68951 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
 
68952 if( rc==SQLITE_BUSY_TIMEOUT ){
68953 rc = SQLITE_BUSY;
68954 *pCnt |= WAL_RETRY_BLOCKED_MASK;
68955 }
68956 #endif
@@ -68936,10 +68961,11 @@
68961 ** which might cause WAL_RETRY to be returned even if BUSY_RECOVERY
68962 ** would be technically correct. But the race is benign since with
68963 ** WAL_RETRY this routine will be called again and will probably be
68964 ** right on the second iteration.
68965 */
68966 (void)walEnableBlocking(pWal);
68967 if( pWal->apWiData[0]==0 ){
68968 /* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
68969 ** We assume this is a transient condition, so return WAL_RETRY. The
68970 ** xShmMap() implementation used by the default unix and win32 VFS
68971 ** modules may return SQLITE_BUSY due to a race condition in the
@@ -68952,10 +68978,11 @@
68978 rc = WAL_RETRY;
68979 }else if( rc==SQLITE_BUSY ){
68980 rc = SQLITE_BUSY_RECOVERY;
68981 }
68982 }
68983 walDisableBlocking(pWal);
68984 if( rc!=SQLITE_OK ){
68985 return rc;
68986 }
68987 else if( pWal->bShmUnreliable ){
68988 return walBeginShmUnreliable(pWal, pChanged);
@@ -72401,11 +72428,11 @@
72428 if( pKey ){
72429 KeyInfo *pKeyInfo = pCur->pKeyInfo;
72430 assert( nKey==(i64)(int)nKey );
72431 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
72432 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
72433 sqlite3VdbeRecordUnpack((int)nKey, pKey, pIdxKey);
72434 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
72435 rc = SQLITE_CORRUPT_BKPT;
72436 }else{
72437 rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes);
72438 }
@@ -74385,10 +74412,11 @@
74412 removed = 1;
74413 }
74414 sqlite3_mutex_leave(pMainMtx);
74415 return removed;
74416 #else
74417 UNUSED_PARAMETER( pBt );
74418 return 1;
74419 #endif
74420 }
74421
74422 /*
@@ -75226,10 +75254,17 @@
75254
75255 if( rc!=SQLITE_OK ){
75256 (void)sqlite3PagerWalWriteLock(pPager, 0);
75257 unlockBtreeIfUnused(pBt);
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
75266 }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
75267 btreeInvokeBusyHandler(pBt) );
75268 sqlite3PagerWalDb(pPager, 0);
75269 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
75270 if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY;
@@ -82846,10 +82881,11 @@
82881 ** btree as the argument handle holds an exclusive lock on the
82882 ** sqlite_schema table. Otherwise SQLITE_OK.
82883 */
82884 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
82885 int rc;
82886 UNUSED_PARAMETER(p); /* only used in DEBUG builds */
82887 assert( sqlite3_mutex_held(p->db->mutex) );
82888 sqlite3BtreeEnter(p);
82889 rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
82890 assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
82891 sqlite3BtreeLeave(p);
@@ -90066,34 +90102,26 @@
90102 }
90103 }
90104 return;
90105 }
90106 /*
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.
 
 
 
 
 
 
 
90112 */
90113 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
90114 KeyInfo *pKeyInfo /* Description of the record */
90115 ){
90116 UnpackedRecord *p; /* Unpacked record to return */
90117 u64 nByte; /* Number of bytes required for *p */
90118 assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
90119 nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
90120 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
90121 if( !p ) return 0;
90122 p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
 
90123 p->pKeyInfo = pKeyInfo;
90124 p->nField = pKeyInfo->nKeyField + 1;
90125 return p;
90126 }
90127
@@ -90101,11 +90129,10 @@
90129 ** Given the nKey-byte encoding of a record in pKey[], populate the
90130 ** UnpackedRecord structure indicated by the fourth argument with the
90131 ** contents of the decoded record.
90132 */
90133 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(
 
90134 int nKey, /* Size of the binary record */
90135 const void *pKey, /* The binary record */
90136 UnpackedRecord *p /* Populate this structure before returning. */
90137 ){
90138 const unsigned char *aKey = (const unsigned char *)pKey;
@@ -90112,10 +90139,11 @@
90139 u32 d;
90140 u32 idx; /* Offset in aKey[] to read from */
90141 u16 u; /* Unsigned loop counter */
90142 u32 szHdr;
90143 Mem *pMem = p->aMem;
90144 KeyInfo *pKeyInfo = p->pKeyInfo;
90145
90146 p->default_rc = 0;
90147 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
90148 idx = getVarint32(aKey, szHdr);
90149 d = szHdr;
@@ -90139,10 +90167,12 @@
90167 /* In a corrupt record entry, the last pMem might have been set up using
90168 ** uninitialized memory. Overwrite its value with NULL, to prevent
90169 ** warnings from MSAN. */
90170 sqlite3VdbeMemSetNull(pMem-1);
90171 }
90172 testcase( u == pKeyInfo->nKeyField + 1 );
90173 testcase( u < pKeyInfo->nKeyField + 1 );
90174 assert( u<=pKeyInfo->nKeyField + 1 );
90175 p->nField = u;
90176 }
90177
90178 #ifdef SQLITE_DEBUG
@@ -90998,10 +91028,11 @@
91028 ** is an integer.
91029 **
91030 ** The easiest way to enforce this limit is to consider only records with
91031 ** 13 fields or less. If the first field is an integer, the maximum legal
91032 ** header size is (12*5 + 1 + 1) bytes. */
91033 assert( p->pKeyInfo->aSortFlags!=0 );
91034 if( p->pKeyInfo->nAllField<=13 ){
91035 int flags = p->aMem[0].flags;
91036 if( p->pKeyInfo->aSortFlags[0] ){
91037 if( p->pKeyInfo->aSortFlags[0] & KEYINFO_ORDER_BIGNULL ){
91038 return sqlite3VdbeRecordCompare;
@@ -91356,11 +91387,10 @@
91387 ){
91388 sqlite3 *db = v->db;
91389 i64 iKey2;
91390 PreUpdate preupdate;
91391 const char *zTbl = pTab->zName;
 
91392 #ifdef SQLITE_DEBUG
91393 int nRealCol;
91394 if( pTab->tabFlags & TF_WithoutRowid ){
91395 nRealCol = sqlite3PrimaryKeyIndex(pTab)->nColumn;
91396 }else if( pTab->tabFlags & TF_HasVirtual ){
@@ -91395,11 +91425,11 @@
91425 preupdate.iNewReg = iReg;
91426 preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace;
91427 preupdate.pKeyinfo->db = db;
91428 preupdate.pKeyinfo->enc = ENC(db);
91429 preupdate.pKeyinfo->nKeyField = pTab->nCol;
91430 preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */
91431 preupdate.iKey1 = iKey1;
91432 preupdate.iKey2 = iKey2;
91433 preupdate.pTab = pTab;
91434 preupdate.iBlobWrite = iBlobWrite;
91435
@@ -93592,11 +93622,11 @@
93622 UnpackedRecord *pRet; /* Return value */
93623
93624 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
93625 if( pRet ){
93626 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
93627 sqlite3VdbeRecordUnpack(nKey, pKey, pRet);
93628 }
93629 return pRet;
93630 }
93631
93632 /*
@@ -96785,10 +96815,11 @@
96815 }
96816 n = pOp->p3;
96817 pKeyInfo = pOp->p4.pKeyInfo;
96818 assert( n>0 );
96819 assert( pKeyInfo!=0 );
96820 assert( pKeyInfo->aSortFlags!=0 );
96821 p1 = pOp->p1;
96822 p2 = pOp->p2;
96823 #ifdef SQLITE_DEBUG
96824 if( aPermute ){
96825 int k, mx = 0;
@@ -99658,11 +99689,11 @@
99689 rc = ExpandBlob(r.aMem);
99690 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
99691 if( rc ) goto no_mem;
99692 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
99693 if( pIdxKey==0 ) goto no_mem;
99694 sqlite3VdbeRecordUnpack(r.aMem->n, r.aMem->z, pIdxKey);
99695 pIdxKey->default_rc = 0;
99696 rc = sqlite3BtreeIndexMoveto(pC->uc.pCursor, pIdxKey, &pC->seekResult);
99697 sqlite3DbFreeNN(db, pIdxKey);
99698 }
99699 if( rc!=SQLITE_OK ){
@@ -104834,11 +104865,11 @@
104865 const void *pKey1, int nKey1, /* Left side of comparison */
104866 const void *pKey2, int nKey2 /* Right side of comparison */
104867 ){
104868 UnpackedRecord *r2 = pTask->pUnpacked;
104869 if( *pbKey2Cached==0 ){
104870 sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
104871 *pbKey2Cached = 1;
104872 }
104873 return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, r2, 1);
104874 }
104875
@@ -104861,11 +104892,11 @@
104892 const void *pKey1, int nKey1, /* Left side of comparison */
104893 const void *pKey2, int nKey2 /* Right side of comparison */
104894 ){
104895 UnpackedRecord *r2 = pTask->pUnpacked;
104896 if( !*pbKey2Cached ){
104897 sqlite3VdbeRecordUnpack(nKey2, pKey2, r2);
104898 *pbKey2Cached = 1;
104899 }
104900 return sqlite3VdbeRecordCompare(nKey1, pKey1, r2);
104901 }
104902
@@ -104901,10 +104932,11 @@
104932 res = vdbeSorterCompareTail(
104933 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
104934 );
104935 }
104936 }else{
104937 assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
104938 assert( !(pTask->pSorter->pKeyInfo->aSortFlags[0]&KEYINFO_ORDER_BIGNULL) );
104939 if( pTask->pSorter->pKeyInfo->aSortFlags[0] ){
104940 res = res * -1;
104941 }
104942 }
@@ -104964,10 +104996,11 @@
104996 }else{
104997 if( *v2 & 0x80 ) res = +1;
104998 }
104999 }
105000
105001 assert( pTask->pSorter->pKeyInfo->aSortFlags!=0 );
105002 if( res==0 ){
105003 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
105004 res = vdbeSorterCompareTail(
105005 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
105006 );
@@ -105037,11 +105070,12 @@
105070 assert( pCsr->pKeyInfo );
105071 assert( !pCsr->isEphemeral );
105072 assert( pCsr->eCurType==CURTYPE_SORTER );
105073 assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
105074 < 0x7fffffff );
105075 assert( pCsr->pKeyInfo->nKeyField<=pCsr->pKeyInfo->nAllField );
105076 szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nAllField);
105077 sz = SZ_VDBESORTER(nWorker+1);
105078
105079 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
105080 pCsr->uc.pSorter = pSorter;
105081 if( pSorter==0 ){
@@ -105051,11 +105085,16 @@
105085 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
105086 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
105087 pKeyInfo->db = 0;
105088 if( nField && nWorker==0 ){
105089 pKeyInfo->nKeyField = nField;
105090 assert( nField<=pCsr->pKeyInfo->nAllField );
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 );
105096 sqlite3BtreeEnter(pBt);
105097 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt);
105098 sqlite3BtreeLeave(pBt);
105099 pSorter->nTask = nWorker + 1;
105100 pSorter->iPrev = (u8)(nWorker - 1);
@@ -106831,11 +106870,11 @@
106870 r2->nField = nKeyCol;
106871 }
106872 assert( r2->nField==nKeyCol );
106873
106874 pKey = vdbeSorterRowkey(pSorter, &nKey);
106875 sqlite3VdbeRecordUnpack(nKey, pKey, r2);
106876 for(i=0; i<nKeyCol; i++){
106877 if( r2->aMem[i].flags & MEM_Null ){
106878 *pRes = -1;
106879 return SQLITE_OK;
106880 }
@@ -110387,11 +110426,13 @@
110426 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
110427 return sqlite3ExprAffinity(
110428 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
110429 );
110430 }
110431 if( op==TK_VECTOR
110432 || (op==TK_FUNCTION && pExpr->affExpr==SQLITE_AFF_DEFER)
110433 ){
110434 assert( ExprUseXList(pExpr) );
110435 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110436 }
110437 if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
110438 assert( pExpr->op==TK_COLLATE
@@ -110580,11 +110621,13 @@
110621 }
110622 if( op==TK_CAST || op==TK_UPLUS ){
110623 p = p->pLeft;
110624 continue;
110625 }
110626 if( op==TK_VECTOR
110627 || (op==TK_FUNCTION && p->affExpr==SQLITE_AFF_DEFER)
110628 ){
110629 assert( ExprUseXList(p) );
110630 p = p->x.pList->a[0].pExpr;
110631 continue;
110632 }
110633 if( op==TK_COLLATE ){
@@ -145362,11 +145405,11 @@
145405 "not present in both tables", zName);
145406 return 1;
145407 }
145408 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
145409 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145410 if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 && pParse->nErr==0 ){
145411 /* This branch runs if the query contains one or more RIGHT or FULL
145412 ** JOINs. If only a single table on the left side of this join
145413 ** contains the zName column, then this branch is a no-op.
145414 ** But if there are two or more tables on the left side
145415 ** of the join, construct a coalesce() function that gathers all
@@ -145378,10 +145421,12 @@
145421 ** JOIN. But older versions of SQLite do not do that, so we avoid
145422 ** adding a new error so as to not break legacy applications.
145423 */
145424 ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145425 static const Token tkCoalesce = { "coalesce", 8 };
145426 assert( pE1!=0 );
145427 ExprSetProperty(pE1, EP_CanBeNull);
145428 while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
145429 pRight->fg.isSynthUsing)!=0 ){
145430 if( pSrc->a[iLeft].fg.isUsing==0
145431 || sqlite3IdListIndex(pSrc->a[iLeft].u3.pUsing, zName)<0
145432 ){
@@ -145394,11 +145439,17 @@
145439 sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145440 }
145441 if( pFuncArgs ){
145442 pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
145443 pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
145444 if( pE1 ){
145445 pE1->affExpr = SQLITE_AFF_DEFER;
145446 }
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);
145451 }
145452 pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
145453 sqlite3SrcItemColumnUsed(pRight, iRightCol);
145454 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
145455 assert( pE2!=0 || pEq==0 );
@@ -146871,10 +146922,14 @@
146922 #else
146923 zType = columnType(&sNC, p, 0, 0, 0);
146924 #endif
146925 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
146926 }
146927 #else
146928 UNUSED_PARAMETER(pParse);
146929 UNUSED_PARAMETER(pTabList);
146930 UNUSED_PARAMETER(pEList);
146931 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
146932 }
146933
146934
146935 /*
@@ -149002,13 +149057,13 @@
149057 ** other than the one FROM-clause subquery that is a candidate
149058 ** for flattening. (This is due to ticket [2f7170d73bf9abf80]
149059 ** from 2015-02-09.)
149060 **
149061 ** (3) If the subquery is the right operand of a LEFT JOIN then
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"
149065 ** (**) Was: "The outer query may not have a GROUP BY." This case
149066 ** is now managed correctly
149067 ** (3d) the outer query may not be DISTINCT.
149068 ** See also (26) for restrictions on RIGHT JOIN.
149069 **
@@ -149220,11 +149275,11 @@
149275 **
149276 ** See also tickets #306, #350, and #3300.
149277 */
149278 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149279 if( pSubSrc->nSrc>1 /* (3a) */
149280 /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */
149281 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
149282 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149283 ){
149284 return 0;
149285 }
@@ -157245,11 +157300,12 @@
157300 saved_flags = db->flags;
157301 saved_mDbFlags = db->mDbFlags;
157302 saved_nChange = db->nChange;
157303 saved_nTotalChange = db->nTotalChange;
157304 saved_mTrace = db->mTrace;
157305 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks | SQLITE_Comments
157306 | SQLITE_AttachCreate | SQLITE_AttachWrite;
157307 db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
157308 db->flags &= ~(u64)(SQLITE_ForeignKeys | SQLITE_ReverseOrder
157309 | SQLITE_Defensive | SQLITE_CountRows);
157310 db->mTrace = 0;
157311
@@ -161720,16 +161776,17 @@
161776 }
161777
161778 if( pLevel->iLeftJoin==0 ){
161779 /* If a partial index is driving the loop, try to eliminate WHERE clause
161780 ** terms from the query that must be true due to the WHERE clause of
161781 ** the partial index. This optimization does not work on an outer join,
161782 ** as shown by:
161783 **
161784 ** 2019-11-02 ticket 623eff57e76d45f6 (LEFT JOIN)
161785 ** 2025-05-29 forum post 7dee41d32506c4ae (RIGHT JOIN)
161786 */
161787 if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){
161788 whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
161789 }
161790 }else{
161791 testcase( pIdx->pPartIdxWhere );
161792 /* The following assert() is not a requirement, merely an observation:
@@ -188786,11 +188843,11 @@
188843
188844 /*
188845 ** Macros needed to provide flexible arrays in a portable way
188846 */
188847 #ifndef offsetof
188848 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
188849 #endif
188850 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
188851 # define FLEXARRAY
188852 #else
188853 # define FLEXARRAY 1
@@ -209019,12 +209076,14 @@
209076 nExtra = 0;
209077 }else if( szType==12 ){
209078 nExtra = 1;
209079 }else if( szType==13 ){
209080 nExtra = 2;
209081 }else if( szType==14 ){
209082 nExtra = 4;
209083 }else{
209084 nExtra = 8;
209085 }
209086 if( szPayload<=11 ){
209087 nNeeded = 0;
209088 }else if( szPayload<=0xff ){
209089 nNeeded = 1;
@@ -213405,10 +213464,12 @@
213464 #else
213465 /* #include "sqlite3.h" */
213466 #endif
213467 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
213468
213469 /* #include <stddef.h> */
213470
213471 /*
213472 ** If building separately, we will need some setup that is normally
213473 ** found in sqliteInt.h
213474 */
213475 #if !defined(SQLITE_AMALGAMATION)
@@ -213436,11 +213497,11 @@
213497 #else
213498 # define ALWAYS(X) (X)
213499 # define NEVER(X) (X)
213500 #endif
213501 #ifndef offsetof
213502 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
213503 #endif
213504 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
213505 # define FLEXARRAY
213506 #else
213507 # define FLEXARRAY 1
@@ -227753,11 +227814,12 @@
227814 DbpageTable *pTab = (DbpageTable *)pCursor->pVtab;
227815 int rc;
227816 sqlite3 *db = pTab->db;
227817 Btree *pBt;
227818
227819 UNUSED_PARAMETER(idxStr);
227820 UNUSED_PARAMETER(argc);
227821
227822 /* Default setting is no rows of result */
227823 pCsr->pgno = 1;
227824 pCsr->mxPgno = 0;
227825
@@ -235447,10 +235509,11 @@
235509 /* #include "sqlite3ext.h" */
235510 SQLITE_EXTENSION_INIT1
235511
235512 /* #include <string.h> */
235513 /* #include <assert.h> */
235514 /* #include <stddef.h> */
235515
235516 #ifndef SQLITE_AMALGAMATION
235517
235518 typedef unsigned char u8;
235519 typedef unsigned int u32;
@@ -235506,11 +235569,11 @@
235569
235570 /*
235571 ** Macros needed to provide flexible arrays in a portable way
235572 */
235573 #ifndef offsetof
235574 # define offsetof(ST,M) ((size_t)((char*)&((ST*)0)->M - (char*)0))
235575 #endif
235576 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
235577 # define FLEXARRAY
235578 #else
235579 # define FLEXARRAY 1
@@ -257190,11 +257253,11 @@
257253 int nArg, /* Number of args */
257254 sqlite3_value **apUnused /* Function arguments */
257255 ){
257256 assert( nArg==0 );
257257 UNUSED_PARAM2(nArg, apUnused);
257258 sqlite3_result_text(pCtx, "fts5: 2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5", -1, SQLITE_TRANSIENT);
257259 }
257260
257261 /*
257262 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257263 **
257264
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.50.0"
150
-#define SQLITE_VERSION_NUMBER 3050000
151
-#define SQLITE_SOURCE_ID "2025-05-29 14:26:00 dfc790f998f450d9c35e3ba1c8c89c17466cb559f87b0239e4aab9d34e28f742"
149
+#define SQLITE_VERSION "3.51.0"
150
+#define SQLITE_VERSION_NUMBER 3051000
151
+#define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.50.0"
150 #define SQLITE_VERSION_NUMBER 3050000
151 #define SQLITE_SOURCE_ID "2025-05-29 14:26:00 dfc790f998f450d9c35e3ba1c8c89c17466cb559f87b0239e4aab9d34e28f742"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.51.0"
150 #define SQLITE_VERSION_NUMBER 3051000
151 #define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button