Fossil SCM

Update the built-in SQLite to the latest trunk version, that includes a patch to shell.c that tries to work around a nuisance warning from some implementations of MSVC. [forum:/forumpost/bd0844268f0fab71|Forum post bd0844268f0fab71].

drh 2022-03-23 10:09 trunk
Commit 92fd091703a28c0746b6afd4c959a538d9aedd09a4f76d1dd55e87914ccecd9e
+20 -8
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -7962,13 +7962,18 @@
79627962
zFile = pTab->zFile;
79637963
}else if( idxNum==0 ){
79647964
zipfileCursorErr(pCsr, "zipfile() function requires an argument");
79657965
return SQLITE_ERROR;
79667966
}else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
7967
+ static const u8 aEmptyBlob = 0;
79677968
const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]);
79687969
int nBlob = sqlite3_value_bytes(argv[0]);
79697970
assert( pTab->pFirstEntry==0 );
7971
+ if( aBlob==0 ){
7972
+ aBlob = &aEmptyBlob;
7973
+ nBlob = 0;
7974
+ }
79707975
rc = zipfileLoadDirectory(pTab, aBlob, nBlob);
79717976
pCsr->pFreeEntry = pTab->pFirstEntry;
79727977
pTab->pFirstEntry = pTab->pLastEntry = 0;
79737978
if( rc!=SQLITE_OK ) return rc;
79747979
bInMemory = 1;
@@ -16078,12 +16083,14 @@
1607816083
sqlite3_series_init(p->db, 0, 0);
1607916084
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1608016085
sqlite3_dbdata_init(p->db, 0, 0);
1608116086
#endif
1608216087
#ifdef SQLITE_HAVE_ZLIB
16083
- sqlite3_zipfile_init(p->db, 0, 0);
16084
- sqlite3_sqlar_init(p->db, 0, 0);
16088
+ if( !p->bSafeModePersist ){
16089
+ sqlite3_zipfile_init(p->db, 0, 0);
16090
+ sqlite3_sqlar_init(p->db, 0, 0);
16091
+ }
1608516092
#endif
1608616093
sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
1608716094
shellAddSchemaName, 0, 0);
1608816095
sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
1608916096
shellModuleSchema, 0, 0);
@@ -20670,13 +20677,14 @@
2067020677
){
2067120678
char *zFile = 0;
2067220679
int bTxtMode = 0;
2067320680
int i;
2067420681
int eMode = 0;
20675
- int bBOM = 0;
20676
- int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */
20682
+ int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */
20683
+ unsigned char zBOM[4]; /* Byte-order mark to using if --bom is present */
2067720684
20685
+ zBOM[0] = 0;
2067820686
failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]);
2067920687
if( c=='e' ){
2068020688
eMode = 'x';
2068120689
bOnce = 2;
2068220690
}else if( strncmp(azArg[0],"once",n)==0 ){
@@ -20685,11 +20693,14 @@
2068520693
for(i=1; i<nArg; i++){
2068620694
char *z = azArg[i];
2068720695
if( z[0]=='-' ){
2068820696
if( z[1]=='-' ) z++;
2068920697
if( strcmp(z,"-bom")==0 ){
20690
- bBOM = 1;
20698
+ zBOM[0] = 0xef;
20699
+ zBOM[1] = 0xbb;
20700
+ zBOM[2] = 0xbf;
20701
+ zBOM[3] = 0;
2069120702
}else if( c!='e' && strcmp(z,"-x")==0 ){
2069220703
eMode = 'x'; /* spreadsheet */
2069320704
}else if( c!='e' && strcmp(z,"-e")==0 ){
2069420705
eMode = 'e'; /* text editor */
2069520706
}else{
@@ -20754,11 +20765,11 @@
2075420765
if( p->out==0 ){
2075520766
utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
2075620767
p->out = stdout;
2075720768
rc = 1;
2075820769
}else{
20759
- if( bBOM ) fprintf(p->out,"\357\273\277");
20770
+ if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out);
2076020771
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2076120772
}
2076220773
#endif
2076320774
}else{
2076420775
p->out = output_file_open(zFile, bTxtMode);
@@ -20767,11 +20778,11 @@
2076720778
utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
2076820779
}
2076920780
p->out = stdout;
2077020781
rc = 1;
2077120782
} else {
20772
- if( bBOM ) fprintf(p->out,"\357\273\277");
20783
+ if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out);
2077320784
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2077420785
}
2077520786
}
2077620787
sqlite3_free(zFile);
2077720788
}else
@@ -22641,11 +22652,12 @@
2264122652
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
2264222653
nSql = 0;
2264322654
qss = QSS_Start;
2264422655
}
2264522656
}
22646
- if( nSql && QSS_PLAINDARK(qss) ){
22657
+ if( nSql ){
22658
+ /* This may be incomplete. Let the SQL parser deal with that. */
2264722659
errCnt += runOneSqlLine(p, zSql, p->in, startline);
2264822660
}
2264922661
free(zSql);
2265022662
free(zLine);
2265122663
--p->inputNesting;
2265222664
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -7962,13 +7962,18 @@
7962 zFile = pTab->zFile;
7963 }else if( idxNum==0 ){
7964 zipfileCursorErr(pCsr, "zipfile() function requires an argument");
7965 return SQLITE_ERROR;
7966 }else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
 
7967 const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]);
7968 int nBlob = sqlite3_value_bytes(argv[0]);
7969 assert( pTab->pFirstEntry==0 );
 
 
 
 
7970 rc = zipfileLoadDirectory(pTab, aBlob, nBlob);
7971 pCsr->pFreeEntry = pTab->pFirstEntry;
7972 pTab->pFirstEntry = pTab->pLastEntry = 0;
7973 if( rc!=SQLITE_OK ) return rc;
7974 bInMemory = 1;
@@ -16078,12 +16083,14 @@
16078 sqlite3_series_init(p->db, 0, 0);
16079 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16080 sqlite3_dbdata_init(p->db, 0, 0);
16081 #endif
16082 #ifdef SQLITE_HAVE_ZLIB
16083 sqlite3_zipfile_init(p->db, 0, 0);
16084 sqlite3_sqlar_init(p->db, 0, 0);
 
 
16085 #endif
16086 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
16087 shellAddSchemaName, 0, 0);
16088 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
16089 shellModuleSchema, 0, 0);
@@ -20670,13 +20677,14 @@
20670 ){
20671 char *zFile = 0;
20672 int bTxtMode = 0;
20673 int i;
20674 int eMode = 0;
20675 int bBOM = 0;
20676 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */
20677
 
20678 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]);
20679 if( c=='e' ){
20680 eMode = 'x';
20681 bOnce = 2;
20682 }else if( strncmp(azArg[0],"once",n)==0 ){
@@ -20685,11 +20693,14 @@
20685 for(i=1; i<nArg; i++){
20686 char *z = azArg[i];
20687 if( z[0]=='-' ){
20688 if( z[1]=='-' ) z++;
20689 if( strcmp(z,"-bom")==0 ){
20690 bBOM = 1;
 
 
 
20691 }else if( c!='e' && strcmp(z,"-x")==0 ){
20692 eMode = 'x'; /* spreadsheet */
20693 }else if( c!='e' && strcmp(z,"-e")==0 ){
20694 eMode = 'e'; /* text editor */
20695 }else{
@@ -20754,11 +20765,11 @@
20754 if( p->out==0 ){
20755 utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
20756 p->out = stdout;
20757 rc = 1;
20758 }else{
20759 if( bBOM ) fprintf(p->out,"\357\273\277");
20760 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20761 }
20762 #endif
20763 }else{
20764 p->out = output_file_open(zFile, bTxtMode);
@@ -20767,11 +20778,11 @@
20767 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
20768 }
20769 p->out = stdout;
20770 rc = 1;
20771 } else {
20772 if( bBOM ) fprintf(p->out,"\357\273\277");
20773 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20774 }
20775 }
20776 sqlite3_free(zFile);
20777 }else
@@ -22641,11 +22652,12 @@
22641 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
22642 nSql = 0;
22643 qss = QSS_Start;
22644 }
22645 }
22646 if( nSql && QSS_PLAINDARK(qss) ){
 
22647 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22648 }
22649 free(zSql);
22650 free(zLine);
22651 --p->inputNesting;
22652
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -7962,13 +7962,18 @@
7962 zFile = pTab->zFile;
7963 }else if( idxNum==0 ){
7964 zipfileCursorErr(pCsr, "zipfile() function requires an argument");
7965 return SQLITE_ERROR;
7966 }else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
7967 static const u8 aEmptyBlob = 0;
7968 const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]);
7969 int nBlob = sqlite3_value_bytes(argv[0]);
7970 assert( pTab->pFirstEntry==0 );
7971 if( aBlob==0 ){
7972 aBlob = &aEmptyBlob;
7973 nBlob = 0;
7974 }
7975 rc = zipfileLoadDirectory(pTab, aBlob, nBlob);
7976 pCsr->pFreeEntry = pTab->pFirstEntry;
7977 pTab->pFirstEntry = pTab->pLastEntry = 0;
7978 if( rc!=SQLITE_OK ) return rc;
7979 bInMemory = 1;
@@ -16078,12 +16083,14 @@
16083 sqlite3_series_init(p->db, 0, 0);
16084 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16085 sqlite3_dbdata_init(p->db, 0, 0);
16086 #endif
16087 #ifdef SQLITE_HAVE_ZLIB
16088 if( !p->bSafeModePersist ){
16089 sqlite3_zipfile_init(p->db, 0, 0);
16090 sqlite3_sqlar_init(p->db, 0, 0);
16091 }
16092 #endif
16093 sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
16094 shellAddSchemaName, 0, 0);
16095 sqlite3_create_function(p->db, "shell_module_schema", 1, SQLITE_UTF8, 0,
16096 shellModuleSchema, 0, 0);
@@ -20670,13 +20677,14 @@
20677 ){
20678 char *zFile = 0;
20679 int bTxtMode = 0;
20680 int i;
20681 int eMode = 0;
20682 int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */
20683 unsigned char zBOM[4]; /* Byte-order mark to using if --bom is present */
20684
20685 zBOM[0] = 0;
20686 failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]);
20687 if( c=='e' ){
20688 eMode = 'x';
20689 bOnce = 2;
20690 }else if( strncmp(azArg[0],"once",n)==0 ){
@@ -20685,11 +20693,14 @@
20693 for(i=1; i<nArg; i++){
20694 char *z = azArg[i];
20695 if( z[0]=='-' ){
20696 if( z[1]=='-' ) z++;
20697 if( strcmp(z,"-bom")==0 ){
20698 zBOM[0] = 0xef;
20699 zBOM[1] = 0xbb;
20700 zBOM[2] = 0xbf;
20701 zBOM[3] = 0;
20702 }else if( c!='e' && strcmp(z,"-x")==0 ){
20703 eMode = 'x'; /* spreadsheet */
20704 }else if( c!='e' && strcmp(z,"-e")==0 ){
20705 eMode = 'e'; /* text editor */
20706 }else{
@@ -20754,11 +20765,11 @@
20765 if( p->out==0 ){
20766 utf8_printf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
20767 p->out = stdout;
20768 rc = 1;
20769 }else{
20770 if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out);
20771 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20772 }
20773 #endif
20774 }else{
20775 p->out = output_file_open(zFile, bTxtMode);
@@ -20767,11 +20778,11 @@
20778 utf8_printf(stderr,"Error: cannot write to \"%s\"\n", zFile);
20779 }
20780 p->out = stdout;
20781 rc = 1;
20782 } else {
20783 if( zBOM[0] ) fwrite(zBOM, 1, 3, p->out);
20784 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20785 }
20786 }
20787 sqlite3_free(zFile);
20788 }else
@@ -22641,11 +22652,12 @@
22652 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
22653 nSql = 0;
22654 qss = QSS_Start;
22655 }
22656 }
22657 if( nSql ){
22658 /* This may be incomplete. Let the SQL parser deal with that. */
22659 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22660 }
22661 free(zSql);
22662 free(zLine);
22663 --p->inputNesting;
22664
+146 -61
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.39.0"
456456
#define SQLITE_VERSION_NUMBER 3039000
457
-#define SQLITE_SOURCE_ID "2022-03-11 15:42:05 0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea"
457
+#define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -5897,11 +5897,12 @@
58975897
**
58985898
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
58995899
** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
59005900
** is a [protected sqlite3_value] object even if the input is not.
59015901
** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5902
-** memory allocation fails.
5902
+** memory allocation fails. ^If V is a [pointer value], then the result
5903
+** of sqlite3_value_dup(V) is a NULL value.
59035904
**
59045905
** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
59055906
** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
59065907
** then sqlite3_value_free(V) is a harmless no-op.
59075908
*/
@@ -9858,12 +9859,12 @@
98589859
**
98599860
** This API may only be used from within an [xBestIndex|xBestIndex method]
98609861
** of a [virtual table] implementation. The result of calling this
98619862
** interface from outside of xBestIndex() is undefined and probably harmful.
98629863
**
9863
-** ^The sqlite3_vtab_distinct() interface returns an integer that is
9864
-** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9864
+** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9865
+** 3. The integer returned by sqlite3_vtab_distinct()
98659866
** gives the virtual table additional information about how the query
98669867
** planner wants the output to be ordered. As long as the virtual table
98679868
** can meet the ordering requirements of the query planner, it may set
98689869
** the "orderByConsumed" flag.
98699870
**
@@ -9891,10 +9892,17 @@
98919892
** values in all "aOrderBy" columns to be returned, as long as all such rows
98929893
** are adjacent. ^The virtual table may, if it chooses, omit extra rows
98939894
** that have the same value for all columns identified by "aOrderBy".
98949895
** ^However omitting the extra rows is optional.
98959896
** This mode is used for a DISTINCT query.
9897
+** <li value="3"><p>
9898
+** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9899
+** that the query planner needs only distinct rows but it does need the
9900
+** rows to be sorted.)^ ^The virtual table implementation is free to omit
9901
+** rows that are identical in all aOrderBy columns, if it wants to, but
9902
+** it is not required to omit any rows. This mode is used for queries
9903
+** that have both DISTINCT and ORDER BY clauses.
98969904
** </ol>
98979905
**
98989906
** ^For the purposes of comparing virtual table output values to see if the
98999907
** values are same value for sorting purposes, two NULL values are considered
99009908
** to be the same. In other words, the comparison operator is "IS"
@@ -39731,15 +39739,21 @@
3973139739
int ofst, /* First lock to acquire or release */
3973239740
int n, /* Number of locks to acquire or release */
3973339741
int flags /* What to do with the lock */
3973439742
){
3973539743
unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
39736
- unixShm *p = pDbFd->pShm; /* The shared memory being locked */
39737
- unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
39744
+ unixShm *p; /* The shared memory being locked */
39745
+ unixShmNode *pShmNode; /* The underlying file iNode */
3973839746
int rc = SQLITE_OK; /* Result code */
3973939747
u16 mask; /* Mask of locks to take or release */
39740
- int *aLock = pShmNode->aLock;
39748
+ int *aLock;
39749
+
39750
+ p = pDbFd->pShm;
39751
+ if( p==0 ) return SQLITE_IOERR_SHMLOCK;
39752
+ pShmNode = p->pShmNode;
39753
+ if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
39754
+ aLock = pShmNode->aLock;
3974139755
3974239756
assert( pShmNode==pDbFd->pInode->pShmNode );
3974339757
assert( pShmNode->pInode==pDbFd->pInode );
3974439758
assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
3974539759
assert( n>=1 );
@@ -47026,14 +47040,18 @@
4702647040
int flags /* What to do with the lock */
4702747041
){
4702847042
winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
4702947043
winShm *p = pDbFd->pShm; /* The shared memory being locked */
4703047044
winShm *pX; /* For looping over all siblings */
47031
- winShmNode *pShmNode = p->pShmNode;
47045
+ winShmNode *pShmNode;
4703247046
int rc = SQLITE_OK; /* Result code */
4703347047
u16 mask; /* Mask of locks to take or release */
4703447048
47049
+ if( p==0 ) return SQLITE_IOERR_SHMLOCK;
47050
+ pShmNode = p->pShmNode;
47051
+ if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
47052
+
4703547053
assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
4703647054
assert( n>=1 );
4703747055
assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
4703847056
|| flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
4703947057
|| flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
@@ -50959,12 +50977,11 @@
5095950977
/*
5096050978
** Make sure the page is marked as dirty. If it isn't dirty already,
5096150979
** make it so.
5096250980
*/
5096350981
SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
50964
- assert( p->nRef>0 || p->pCache->bPurgeable==0 );
50965
- testcase( p->nRef==0 );
50982
+ assert( p->nRef>0 );
5096650983
assert( sqlite3PcachePageSanity(p) );
5096750984
if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
5096850985
p->flags &= ~PGHDR_DONT_WRITE;
5096950986
if( p->flags & PGHDR_CLEAN ){
5097050987
p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
@@ -75197,28 +75214,10 @@
7519775214
unsigned char *newCell = 0;
7519875215
7519975216
assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
7520075217
assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
7520175218
75202
- if( pCur->eState==CURSOR_FAULT ){
75203
- assert( pCur->skipNext!=SQLITE_OK );
75204
- return pCur->skipNext;
75205
- }
75206
-
75207
- assert( cursorOwnsBtShared(pCur) );
75208
- assert( (pCur->curFlags & BTCF_WriteFlag)!=0
75209
- && pBt->inTransaction==TRANS_WRITE
75210
- && (pBt->btsFlags & BTS_READ_ONLY)==0 );
75211
- assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75212
-
75213
- /* Assert that the caller has been consistent. If this cursor was opened
75214
- ** expecting an index b-tree, then the caller should be inserting blob
75215
- ** keys with no associated data. If the cursor was opened expecting an
75216
- ** intkey table, the caller should be inserting integer keys with a
75217
- ** blob of associated data. */
75218
- assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
75219
-
7522075219
/* Save the positions of any other cursors open on this table.
7522175220
**
7522275221
** In some cases, the call to btreeMoveto() below is a no-op. For
7522375222
** example, when inserting data into a table with auto-generated integer
7522475223
** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
@@ -75239,10 +75238,33 @@
7523975238
** set the flag, load the schema, and then unset the flag. */
7524075239
return SQLITE_CORRUPT_BKPT;
7524175240
}
7524275241
}
7524375242
75243
+ /* Ensure that the cursor is not in the CURSOR_FAULT state and that it
75244
+ ** points to a valid cell.
75245
+ */
75246
+ if( pCur->eState>=CURSOR_REQUIRESEEK ){
75247
+ testcase( pCur->eState==CURSOR_REQUIRESEEK );
75248
+ testcase( pCur->eState==CURSOR_FAULT );
75249
+ rc = moveToRoot(pCur);
75250
+ if( rc && rc!=SQLITE_EMPTY ) return rc;
75251
+ }
75252
+
75253
+ assert( cursorOwnsBtShared(pCur) );
75254
+ assert( (pCur->curFlags & BTCF_WriteFlag)!=0
75255
+ && pBt->inTransaction==TRANS_WRITE
75256
+ && (pBt->btsFlags & BTS_READ_ONLY)==0 );
75257
+ assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75258
+
75259
+ /* Assert that the caller has been consistent. If this cursor was opened
75260
+ ** expecting an index b-tree, then the caller should be inserting blob
75261
+ ** keys with no associated data. If the cursor was opened expecting an
75262
+ ** intkey table, the caller should be inserting integer keys with a
75263
+ ** blob of associated data. */
75264
+ assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
75265
+
7524475266
if( pCur->pKeyInfo==0 ){
7524575267
assert( pX->pKey==0 );
7524675268
/* If this is an insert into a table b-tree, invalidate any incrblob
7524775269
** cursors open on the row being replaced */
7524875270
if( p->hasIncrblobCur ){
@@ -75327,18 +75349,18 @@
7532775349
return btreeOverwriteCell(pCur, &x2);
7532875350
}
7532975351
}
7533075352
}
7533175353
assert( pCur->eState==CURSOR_VALID
75332
- || (pCur->eState==CURSOR_INVALID && loc)
75333
- || CORRUPT_DB );
75354
+ || (pCur->eState==CURSOR_INVALID && loc) );
7533475355
7533575356
pPage = pCur->pPage;
7533675357
assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
7533775358
assert( pPage->leaf || !pPage->intKey );
7533875359
if( pPage->nFree<0 ){
75339
- if( pCur->eState>CURSOR_INVALID ){
75360
+ if( NEVER(pCur->eState>CURSOR_INVALID) ){
75361
+ /* ^^^^^--- due to the moveToRoot() call above */
7534075362
rc = SQLITE_CORRUPT_BKPT;
7534175363
}else{
7534275364
rc = btreeComputeFreeSpace(pPage);
7534375365
}
7534475366
if( rc ) return rc;
@@ -75615,16 +75637,20 @@
7561575637
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
7561675638
assert( pCur->curFlags & BTCF_WriteFlag );
7561775639
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
7561875640
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
7561975641
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
75620
- if( pCur->eState==CURSOR_REQUIRESEEK ){
75621
- rc = btreeRestoreCursorPosition(pCur);
75622
- assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
75623
- if( rc || pCur->eState!=CURSOR_VALID ) return rc;
75642
+ if( pCur->eState!=CURSOR_VALID ){
75643
+ if( pCur->eState>=CURSOR_REQUIRESEEK ){
75644
+ rc = btreeRestoreCursorPosition(pCur);
75645
+ assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
75646
+ if( rc || pCur->eState!=CURSOR_VALID ) return rc;
75647
+ }else{
75648
+ return SQLITE_CORRUPT_BKPT;
75649
+ }
7562475650
}
75625
- assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
75651
+ assert( pCur->eState==CURSOR_VALID );
7562675652
7562775653
iCellDepth = pCur->iPage;
7562875654
iCellIdx = pCur->ix;
7562975655
pPage = pCur->pPage;
7563075656
if( pPage->nCell<=iCellIdx ){
@@ -75652,11 +75678,12 @@
7565275678
** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT.
7565375679
*/
7565475680
bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
7565575681
if( bPreserve ){
7565675682
if( !pPage->leaf
75657
- || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
75683
+ || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2) >
75684
+ (int)(pBt->usableSize*2/3)
7565875685
|| pPage->nCell==1 /* See dbfuzz001.test for a test case */
7565975686
){
7566075687
/* A b-tree rebalance will be required after deleting this entry.
7566175688
** Save the cursor key. */
7566275689
rc = saveCursorKey(pCur);
@@ -82987,11 +83014,11 @@
8298783014
|| (!deferred && p->nFkConstraint>0)
8298883015
){
8298983016
p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
8299083017
p->errorAction = OE_Abort;
8299183018
sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
82992
- return SQLITE_ERROR;
83019
+ return SQLITE_CONSTRAINT_FOREIGNKEY;
8299383020
}
8299483021
return SQLITE_OK;
8299583022
}
8299683023
#endif
8299783024
@@ -85578,10 +85605,13 @@
8557885605
pNew->flags |= MEM_Ephem;
8557985606
if( sqlite3VdbeMemMakeWriteable(pNew)!=SQLITE_OK ){
8558085607
sqlite3ValueFree(pNew);
8558185608
pNew = 0;
8558285609
}
85610
+ }else if( pNew->flags & MEM_Null ){
85611
+ /* Do not duplicate pointer values */
85612
+ pNew->flags &= ~(MEM_Term|MEM_Subtype);
8558385613
}
8558485614
return pNew;
8558585615
}
8558685616
8558785617
/* Destroy an sqlite3_value object previously obtained from
@@ -125318,11 +125348,11 @@
125318125348
sqlite3OomFault(db);
125319125349
return;
125320125350
}
125321125351
125322125352
for(i=j=0; i<pTab->nCol; i++){
125323
- assert( pTab->aCol[i].affinity!=0 );
125353
+ assert( pTab->aCol[i].affinity!=0 || sqlite3VdbeParser(v)->nErr>0 );
125324125354
if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
125325125355
zColAff[j++] = pTab->aCol[i].affinity;
125326125356
}
125327125357
}
125328125358
do{
@@ -128783,10 +128813,15 @@
128783128813
int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128784128814
int (*vtab_distinct)(sqlite3_index_info*);
128785128815
int (*vtab_in)(sqlite3_index_info*,int,int);
128786128816
int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128787128817
int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
128818
+ /* Version 3.39.0 and later */
128819
+ int (*deserialize)(sqlite3*,const char*,unsigned char*,
128820
+ sqlite3_int64,sqlite3_int64,unsigned);
128821
+ unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
128822
+ unsigned int);
128788128823
};
128789128824
128790128825
/*
128791128826
** This is the function signature used for all extension entry points. It
128792128827
** is also defined in the file "loadext.c".
@@ -129101,10 +129136,14 @@
129101129136
#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
129102129137
#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
129103129138
#define sqlite3_vtab_in sqlite3_api->vtab_in
129104129139
#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
129105129140
#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
129141
+#ifndef SQLITE_OMIT_DESERIALIZE
129142
+#define sqlite3_deserialize sqlite3_api->deserialize
129143
+#define sqlite3_serialize sqlite3_api->serialize
129144
+#endif
129106129145
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
129107129146
129108129147
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
129109129148
/* This case when the file really is being compiled as a loadable
129110129149
** extension */
@@ -129596,11 +129635,19 @@
129596129635
sqlite3_error_offset,
129597129636
sqlite3_vtab_rhs_value,
129598129637
sqlite3_vtab_distinct,
129599129638
sqlite3_vtab_in,
129600129639
sqlite3_vtab_in_first,
129601
- sqlite3_vtab_in_next
129640
+ sqlite3_vtab_in_next,
129641
+ /* Version 3.39.0 and later */
129642
+#ifndef SQLITE_OMIT_DESERIALIZE
129643
+ sqlite3_deserialize,
129644
+ sqlite3_serialize
129645
+#else
129646
+ 0,
129647
+ 0
129648
+#endif
129602129649
};
129603129650
129604129651
/* True if x is the directory separator character
129605129652
*/
129606129653
#if SQLITE_OS_WIN
@@ -134449,11 +134496,11 @@
134449134496
** how to process the DISTINCT keyword, to simplify passing that information
134450134497
** into the selectInnerLoop() routine.
134451134498
*/
134452134499
typedef struct DistinctCtx DistinctCtx;
134453134500
struct DistinctCtx {
134454
- u8 isTnct; /* True if the DISTINCT keyword is present */
134501
+ u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */
134455134502
u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */
134456134503
int tabTnct; /* Ephemeral table used for DISTINCT processing */
134457134504
int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */
134458134505
};
134459134506
@@ -141249,10 +141296,11 @@
141249141296
p->selFlags |= SF_Aggregate;
141250141297
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
141251141298
** the sDistinct.isTnct is still set. Hence, isTnct represents the
141252141299
** original setting of the SF_Distinct flag, not the current setting */
141253141300
assert( sDistinct.isTnct );
141301
+ sDistinct.isTnct = 2;
141254141302
141255141303
#if SELECTTRACE_ENABLED
141256141304
if( sqlite3SelectTrace & 0x400 ){
141257141305
SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
141258141306
sqlite3TreeViewSelect(0, p, 0);
@@ -141592,11 +141640,12 @@
141592141640
** in the right order to begin with.
141593141641
*/
141594141642
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
141595141643
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
141596141644
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
141597
- 0, (WHERE_GROUPBY|(orderByGrp ? WHERE_SORTBYGROUP : 0)|distFlag), 0
141645
+ 0, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY)
141646
+ | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
141598141647
);
141599141648
if( pWInfo==0 ){
141600141649
sqlite3ExprListDelete(db, pDistinct);
141601141650
goto select_end;
141602141651
}
@@ -141774,11 +141823,11 @@
141774141823
resetAccumulator(pParse, pAggInfo);
141775141824
sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
141776141825
VdbeComment((v, "indicate accumulator empty"));
141777141826
sqlite3VdbeAddOp1(v, OP_Return, regReset);
141778141827
141779
- if( eDist!=WHERE_DISTINCT_NOOP ){
141828
+ if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
141780141829
struct AggInfo_func *pF = &pAggInfo->aFunc[0];
141781141830
fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
141782141831
}
141783141832
} /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
141784141833
else {
@@ -142248,15 +142297,14 @@
142248142297
&& 0==sqlite3StrICmp(pTrig->table, pTab->zName)
142249142298
&& pTrig->pTabSchema!=pTmpSchema
142250142299
){
142251142300
pTrig->pNext = pList;
142252142301
pList = pTrig;
142253
- }else if( pTrig->op==TK_RETURNING
142302
+ }else if( pTrig->op==TK_RETURNING ){
142254142303
#ifndef SQLITE_OMIT_VIRTUALTABLE
142255
- && pParse->db->pVtabCtx==0
142304
+ assert( pParse->db->pVtabCtx==0 );
142256142305
#endif
142257
- ){
142258142306
assert( pParse->bReturning );
142259142307
assert( &(pParse->u1.pReturning->retTrig) == pTrig );
142260142308
pTrig->table = pTab->zName;
142261142309
pTrig->pTabSchema = pTab->pSchema;
142262142310
pTrig->pNext = pList;
@@ -146506,10 +146554,11 @@
146506146554
pTab = pCtx->pTab;
146507146555
assert( IsVirtual(pTab) );
146508146556
146509146557
sqlite3ParseObjectInit(&sParse, db);
146510146558
sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
146559
+ sParse.disableTriggers = 1;
146511146560
/* We should never be able to reach this point while loading the
146512146561
** schema. Nevertheless, defend against that (turn off db->init.busy)
146513146562
** in case a bug arises. */
146514146563
assert( db->init.busy==0 );
146515146564
initBusy = db->init.busy;
@@ -153429,12 +153478,14 @@
153429153478
/* No matches cause a break out of the loop */
153430153479
break;
153431153480
}
153432153481
if( i==n ){
153433153482
nOrderBy = n;
153434
- if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
153435
- eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
153483
+ if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) ){
153484
+ eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
153485
+ }else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){
153486
+ eDistinct = 1;
153436153487
}
153437153488
}
153438153489
}
153439153490
153440153491
/* Allocate the sqlite3_index_info structure
@@ -155986,13 +156037,11 @@
155986156037
/*
155987156038
** Return true if ORDER BY clause may be handled as DISTINCT.
155988156039
*/
155989156040
SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155990156041
HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155991
- assert( pHidden->eDistinct==0
155992
- || pHidden->eDistinct==1
155993
- || pHidden->eDistinct==2 );
156042
+ assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 );
155994156043
return pHidden->eDistinct;
155995156044
}
155996156045
155997156046
#if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
155998156047
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -156447,11 +156496,13 @@
156447156496
if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
156448156497
}else{
156449156498
pLoop = pLast;
156450156499
}
156451156500
if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
156452
- if( pLoop->u.vtab.isOrdered && (wctrlFlags & WHERE_DISTINCTBY)==0 ){
156501
+ if( pLoop->u.vtab.isOrdered
156502
+ && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
156503
+ ){
156453156504
obSat = obDone;
156454156505
}
156455156506
break;
156456156507
}else if( wctrlFlags & WHERE_DISTINCTBY ){
156457156508
pLoop->u.btree.nDistinctCol = 0;
@@ -156714,11 +156765,11 @@
156714156765
**
156715156766
** SELECT * FROM t1 GROUP BY x,y ORDER BY x,y; -- IsSorted()==1
156716156767
** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
156717156768
*/
156718156769
SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo *pWInfo){
156719
- assert( pWInfo->wctrlFlags & WHERE_GROUPBY );
156770
+ assert( pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY) );
156720156771
assert( pWInfo->wctrlFlags & WHERE_SORTBYGROUP );
156721156772
return pWInfo->sorted;
156722156773
}
156723156774
156724156775
#ifdef WHERETRACE_ENABLED
@@ -157115,16 +157166,16 @@
157115157166
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
157116157167
}
157117157168
}
157118157169
pWInfo->bOrderedInnerLoop = 0;
157119157170
if( pWInfo->pOrderBy ){
157171
+ pWInfo->nOBSat = pFrom->isOrdered;
157120157172
if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
157121157173
if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
157122157174
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
157123157175
}
157124157176
}else{
157125
- pWInfo->nOBSat = pFrom->isOrdered;
157126157177
pWInfo->revMask = pFrom->revLoop;
157127157178
if( pWInfo->nOBSat<=0 ){
157128157179
pWInfo->nOBSat = 0;
157129157180
if( nLoop>0 ){
157130157181
u32 wsFlags = pFrom->aLoop[nLoop-1]->wsFlags;
@@ -158111,10 +158162,30 @@
158111158162
if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return;
158112158163
sqlite3VdbePrintOp(0, pc, pOp);
158113158164
}
158114158165
#endif
158115158166
158167
+#ifdef SQLITE_DEBUG
158168
+/*
158169
+** Return true if cursor iCur is opened by instruction k of the
158170
+** bytecode. Used inside of assert() only.
158171
+*/
158172
+static int cursorIsOpen(Vdbe *v, int iCur, int k){
158173
+ while( k>=0 ){
158174
+ VdbeOp *pOp = sqlite3VdbeGetOp(v,k--);
158175
+ if( pOp->p1!=iCur ) continue;
158176
+ if( pOp->opcode==OP_Close ) return 0;
158177
+ if( pOp->opcode==OP_OpenRead ) return 1;
158178
+ if( pOp->opcode==OP_OpenWrite ) return 1;
158179
+ if( pOp->opcode==OP_OpenDup ) return 1;
158180
+ if( pOp->opcode==OP_OpenAutoindex ) return 1;
158181
+ if( pOp->opcode==OP_OpenEphemeral ) return 1;
158182
+ }
158183
+ return 0;
158184
+}
158185
+#endif /* SQLITE_DEBUG */
158186
+
158116158187
/*
158117158188
** Generate the end of the WHERE loop. See comments on
158118158189
** sqlite3WhereBegin() for additional information.
158119158190
*/
158120158191
SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
@@ -158363,30 +158434,44 @@
158363158434
|| pOp->opcode==OP_Offset
158364158435
#endif
158365158436
){
158366158437
int x = pOp->p2;
158367158438
assert( pIdx->pTable==pTab );
158439
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158440
+ if( pOp->opcode==OP_Offset ){
158441
+ /* Do not need to translate the column number */
158442
+ }else
158443
+#endif
158368158444
if( !HasRowid(pTab) ){
158369158445
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
158370158446
x = pPk->aiColumn[x];
158371158447
assert( x>=0 );
158372
-#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158373
- }else if( pOp->opcode==OP_Offset ){
158374
- /* Do not need to translate the column number */
158375
-#endif
158376158448
}else{
158377158449
testcase( x!=sqlite3StorageColumnToTable(pTab,x) );
158378158450
x = sqlite3StorageColumnToTable(pTab,x);
158379158451
}
158380158452
x = sqlite3TableColumnToIndex(pIdx, x);
158381158453
if( x>=0 ){
158382158454
pOp->p2 = x;
158383158455
pOp->p1 = pLevel->iIdxCur;
158384158456
OpcodeRewriteTrace(db, k, pOp);
158457
+ }else{
158458
+ /* Unable to translate the table reference into an index
158459
+ ** reference. Verify that this is harmless - that the
158460
+ ** table being referenced really is open.
158461
+ */
158462
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158463
+ assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
158464
+ || cursorIsOpen(v,pOp->p1,k)
158465
+ || pOp->opcode==OP_Offset
158466
+ );
158467
+#else
158468
+ assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
158469
+ || cursorIsOpen(v,pOp->p1,k)
158470
+ );
158471
+#endif
158385158472
}
158386
- assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
158387
- || pWInfo->eOnePass );
158388158473
}else if( pOp->opcode==OP_Rowid ){
158389158474
pOp->p1 = pLevel->iIdxCur;
158390158475
pOp->opcode = OP_IdxRowid;
158391158476
OpcodeRewriteTrace(db, k, pOp);
158392158477
}else if( pOp->opcode==OP_IfNullRow ){
@@ -234607,11 +234692,11 @@
234607234692
int nArg, /* Number of args */
234608234693
sqlite3_value **apUnused /* Function arguments */
234609234694
){
234610234695
assert( nArg==0 );
234611234696
UNUSED_PARAM2(nArg, apUnused);
234612
- sqlite3_result_text(pCtx, "fts5: 2022-03-11 15:42:05 0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea", -1, SQLITE_TRANSIENT);
234697
+ sqlite3_result_text(pCtx, "fts5: 2022-03-14 20:31:57 387ab17b8a0a4b87903aab52abc7da79098b882aff2ab687a554d5794e9d183e", -1, SQLITE_TRANSIENT);
234613234698
}
234614234699
234615234700
/*
234616234701
** Return true if zName is the extension on one of the shadow tables used
234617234702
** by this module.
234618234703
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-03-11 15:42:05 0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -5897,11 +5897,12 @@
5897 **
5898 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
5899 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5900 ** is a [protected sqlite3_value] object even if the input is not.
5901 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5902 ** memory allocation fails.
 
5903 **
5904 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5905 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
5906 ** then sqlite3_value_free(V) is a harmless no-op.
5907 */
@@ -9858,12 +9859,12 @@
9858 **
9859 ** This API may only be used from within an [xBestIndex|xBestIndex method]
9860 ** of a [virtual table] implementation. The result of calling this
9861 ** interface from outside of xBestIndex() is undefined and probably harmful.
9862 **
9863 ** ^The sqlite3_vtab_distinct() interface returns an integer that is
9864 ** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9865 ** gives the virtual table additional information about how the query
9866 ** planner wants the output to be ordered. As long as the virtual table
9867 ** can meet the ordering requirements of the query planner, it may set
9868 ** the "orderByConsumed" flag.
9869 **
@@ -9891,10 +9892,17 @@
9891 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9892 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9893 ** that have the same value for all columns identified by "aOrderBy".
9894 ** ^However omitting the extra rows is optional.
9895 ** This mode is used for a DISTINCT query.
 
 
 
 
 
 
 
9896 ** </ol>
9897 **
9898 ** ^For the purposes of comparing virtual table output values to see if the
9899 ** values are same value for sorting purposes, two NULL values are considered
9900 ** to be the same. In other words, the comparison operator is "IS"
@@ -39731,15 +39739,21 @@
39731 int ofst, /* First lock to acquire or release */
39732 int n, /* Number of locks to acquire or release */
39733 int flags /* What to do with the lock */
39734 ){
39735 unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
39736 unixShm *p = pDbFd->pShm; /* The shared memory being locked */
39737 unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
39738 int rc = SQLITE_OK; /* Result code */
39739 u16 mask; /* Mask of locks to take or release */
39740 int *aLock = pShmNode->aLock;
 
 
 
 
 
 
39741
39742 assert( pShmNode==pDbFd->pInode->pShmNode );
39743 assert( pShmNode->pInode==pDbFd->pInode );
39744 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
39745 assert( n>=1 );
@@ -47026,14 +47040,18 @@
47026 int flags /* What to do with the lock */
47027 ){
47028 winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
47029 winShm *p = pDbFd->pShm; /* The shared memory being locked */
47030 winShm *pX; /* For looping over all siblings */
47031 winShmNode *pShmNode = p->pShmNode;
47032 int rc = SQLITE_OK; /* Result code */
47033 u16 mask; /* Mask of locks to take or release */
47034
 
 
 
 
47035 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
47036 assert( n>=1 );
47037 assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
47038 || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
47039 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
@@ -50959,12 +50977,11 @@
50959 /*
50960 ** Make sure the page is marked as dirty. If it isn't dirty already,
50961 ** make it so.
50962 */
50963 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
50964 assert( p->nRef>0 || p->pCache->bPurgeable==0 );
50965 testcase( p->nRef==0 );
50966 assert( sqlite3PcachePageSanity(p) );
50967 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
50968 p->flags &= ~PGHDR_DONT_WRITE;
50969 if( p->flags & PGHDR_CLEAN ){
50970 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
@@ -75197,28 +75214,10 @@
75197 unsigned char *newCell = 0;
75198
75199 assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
75200 assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
75201
75202 if( pCur->eState==CURSOR_FAULT ){
75203 assert( pCur->skipNext!=SQLITE_OK );
75204 return pCur->skipNext;
75205 }
75206
75207 assert( cursorOwnsBtShared(pCur) );
75208 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
75209 && pBt->inTransaction==TRANS_WRITE
75210 && (pBt->btsFlags & BTS_READ_ONLY)==0 );
75211 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75212
75213 /* Assert that the caller has been consistent. If this cursor was opened
75214 ** expecting an index b-tree, then the caller should be inserting blob
75215 ** keys with no associated data. If the cursor was opened expecting an
75216 ** intkey table, the caller should be inserting integer keys with a
75217 ** blob of associated data. */
75218 assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
75219
75220 /* Save the positions of any other cursors open on this table.
75221 **
75222 ** In some cases, the call to btreeMoveto() below is a no-op. For
75223 ** example, when inserting data into a table with auto-generated integer
75224 ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
@@ -75239,10 +75238,33 @@
75239 ** set the flag, load the schema, and then unset the flag. */
75240 return SQLITE_CORRUPT_BKPT;
75241 }
75242 }
75243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75244 if( pCur->pKeyInfo==0 ){
75245 assert( pX->pKey==0 );
75246 /* If this is an insert into a table b-tree, invalidate any incrblob
75247 ** cursors open on the row being replaced */
75248 if( p->hasIncrblobCur ){
@@ -75327,18 +75349,18 @@
75327 return btreeOverwriteCell(pCur, &x2);
75328 }
75329 }
75330 }
75331 assert( pCur->eState==CURSOR_VALID
75332 || (pCur->eState==CURSOR_INVALID && loc)
75333 || CORRUPT_DB );
75334
75335 pPage = pCur->pPage;
75336 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
75337 assert( pPage->leaf || !pPage->intKey );
75338 if( pPage->nFree<0 ){
75339 if( pCur->eState>CURSOR_INVALID ){
 
75340 rc = SQLITE_CORRUPT_BKPT;
75341 }else{
75342 rc = btreeComputeFreeSpace(pPage);
75343 }
75344 if( rc ) return rc;
@@ -75615,16 +75637,20 @@
75615 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
75616 assert( pCur->curFlags & BTCF_WriteFlag );
75617 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75618 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
75619 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
75620 if( pCur->eState==CURSOR_REQUIRESEEK ){
75621 rc = btreeRestoreCursorPosition(pCur);
75622 assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
75623 if( rc || pCur->eState!=CURSOR_VALID ) return rc;
 
 
 
 
75624 }
75625 assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
75626
75627 iCellDepth = pCur->iPage;
75628 iCellIdx = pCur->ix;
75629 pPage = pCur->pPage;
75630 if( pPage->nCell<=iCellIdx ){
@@ -75652,11 +75678,12 @@
75652 ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT.
75653 */
75654 bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
75655 if( bPreserve ){
75656 if( !pPage->leaf
75657 || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
 
75658 || pPage->nCell==1 /* See dbfuzz001.test for a test case */
75659 ){
75660 /* A b-tree rebalance will be required after deleting this entry.
75661 ** Save the cursor key. */
75662 rc = saveCursorKey(pCur);
@@ -82987,11 +83014,11 @@
82987 || (!deferred && p->nFkConstraint>0)
82988 ){
82989 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
82990 p->errorAction = OE_Abort;
82991 sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
82992 return SQLITE_ERROR;
82993 }
82994 return SQLITE_OK;
82995 }
82996 #endif
82997
@@ -85578,10 +85605,13 @@
85578 pNew->flags |= MEM_Ephem;
85579 if( sqlite3VdbeMemMakeWriteable(pNew)!=SQLITE_OK ){
85580 sqlite3ValueFree(pNew);
85581 pNew = 0;
85582 }
 
 
 
85583 }
85584 return pNew;
85585 }
85586
85587 /* Destroy an sqlite3_value object previously obtained from
@@ -125318,11 +125348,11 @@
125318 sqlite3OomFault(db);
125319 return;
125320 }
125321
125322 for(i=j=0; i<pTab->nCol; i++){
125323 assert( pTab->aCol[i].affinity!=0 );
125324 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
125325 zColAff[j++] = pTab->aCol[i].affinity;
125326 }
125327 }
125328 do{
@@ -128783,10 +128813,15 @@
128783 int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128784 int (*vtab_distinct)(sqlite3_index_info*);
128785 int (*vtab_in)(sqlite3_index_info*,int,int);
128786 int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128787 int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
 
 
 
 
 
128788 };
128789
128790 /*
128791 ** This is the function signature used for all extension entry points. It
128792 ** is also defined in the file "loadext.c".
@@ -129101,10 +129136,14 @@
129101 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
129102 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
129103 #define sqlite3_vtab_in sqlite3_api->vtab_in
129104 #define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
129105 #define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
 
 
 
 
129106 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
129107
129108 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
129109 /* This case when the file really is being compiled as a loadable
129110 ** extension */
@@ -129596,11 +129635,19 @@
129596 sqlite3_error_offset,
129597 sqlite3_vtab_rhs_value,
129598 sqlite3_vtab_distinct,
129599 sqlite3_vtab_in,
129600 sqlite3_vtab_in_first,
129601 sqlite3_vtab_in_next
 
 
 
 
 
 
 
 
129602 };
129603
129604 /* True if x is the directory separator character
129605 */
129606 #if SQLITE_OS_WIN
@@ -134449,11 +134496,11 @@
134449 ** how to process the DISTINCT keyword, to simplify passing that information
134450 ** into the selectInnerLoop() routine.
134451 */
134452 typedef struct DistinctCtx DistinctCtx;
134453 struct DistinctCtx {
134454 u8 isTnct; /* True if the DISTINCT keyword is present */
134455 u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */
134456 int tabTnct; /* Ephemeral table used for DISTINCT processing */
134457 int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */
134458 };
134459
@@ -141249,10 +141296,11 @@
141249 p->selFlags |= SF_Aggregate;
141250 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
141251 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
141252 ** original setting of the SF_Distinct flag, not the current setting */
141253 assert( sDistinct.isTnct );
 
141254
141255 #if SELECTTRACE_ENABLED
141256 if( sqlite3SelectTrace & 0x400 ){
141257 SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
141258 sqlite3TreeViewSelect(0, p, 0);
@@ -141592,11 +141640,12 @@
141592 ** in the right order to begin with.
141593 */
141594 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
141595 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
141596 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
141597 0, (WHERE_GROUPBY|(orderByGrp ? WHERE_SORTBYGROUP : 0)|distFlag), 0
 
141598 );
141599 if( pWInfo==0 ){
141600 sqlite3ExprListDelete(db, pDistinct);
141601 goto select_end;
141602 }
@@ -141774,11 +141823,11 @@
141774 resetAccumulator(pParse, pAggInfo);
141775 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
141776 VdbeComment((v, "indicate accumulator empty"));
141777 sqlite3VdbeAddOp1(v, OP_Return, regReset);
141778
141779 if( eDist!=WHERE_DISTINCT_NOOP ){
141780 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
141781 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
141782 }
141783 } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
141784 else {
@@ -142248,15 +142297,14 @@
142248 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
142249 && pTrig->pTabSchema!=pTmpSchema
142250 ){
142251 pTrig->pNext = pList;
142252 pList = pTrig;
142253 }else if( pTrig->op==TK_RETURNING
142254 #ifndef SQLITE_OMIT_VIRTUALTABLE
142255 && pParse->db->pVtabCtx==0
142256 #endif
142257 ){
142258 assert( pParse->bReturning );
142259 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
142260 pTrig->table = pTab->zName;
142261 pTrig->pTabSchema = pTab->pSchema;
142262 pTrig->pNext = pList;
@@ -146506,10 +146554,11 @@
146506 pTab = pCtx->pTab;
146507 assert( IsVirtual(pTab) );
146508
146509 sqlite3ParseObjectInit(&sParse, db);
146510 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
 
146511 /* We should never be able to reach this point while loading the
146512 ** schema. Nevertheless, defend against that (turn off db->init.busy)
146513 ** in case a bug arises. */
146514 assert( db->init.busy==0 );
146515 initBusy = db->init.busy;
@@ -153429,12 +153478,14 @@
153429 /* No matches cause a break out of the loop */
153430 break;
153431 }
153432 if( i==n ){
153433 nOrderBy = n;
153434 if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
153435 eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
 
 
153436 }
153437 }
153438 }
153439
153440 /* Allocate the sqlite3_index_info structure
@@ -155986,13 +156037,11 @@
155986 /*
155987 ** Return true if ORDER BY clause may be handled as DISTINCT.
155988 */
155989 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155990 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155991 assert( pHidden->eDistinct==0
155992 || pHidden->eDistinct==1
155993 || pHidden->eDistinct==2 );
155994 return pHidden->eDistinct;
155995 }
155996
155997 #if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
155998 && !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -156447,11 +156496,13 @@
156447 if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
156448 }else{
156449 pLoop = pLast;
156450 }
156451 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
156452 if( pLoop->u.vtab.isOrdered && (wctrlFlags & WHERE_DISTINCTBY)==0 ){
 
 
156453 obSat = obDone;
156454 }
156455 break;
156456 }else if( wctrlFlags & WHERE_DISTINCTBY ){
156457 pLoop->u.btree.nDistinctCol = 0;
@@ -156714,11 +156765,11 @@
156714 **
156715 ** SELECT * FROM t1 GROUP BY x,y ORDER BY x,y; -- IsSorted()==1
156716 ** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
156717 */
156718 SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo *pWInfo){
156719 assert( pWInfo->wctrlFlags & WHERE_GROUPBY );
156720 assert( pWInfo->wctrlFlags & WHERE_SORTBYGROUP );
156721 return pWInfo->sorted;
156722 }
156723
156724 #ifdef WHERETRACE_ENABLED
@@ -157115,16 +157166,16 @@
157115 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
157116 }
157117 }
157118 pWInfo->bOrderedInnerLoop = 0;
157119 if( pWInfo->pOrderBy ){
 
157120 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
157121 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
157122 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
157123 }
157124 }else{
157125 pWInfo->nOBSat = pFrom->isOrdered;
157126 pWInfo->revMask = pFrom->revLoop;
157127 if( pWInfo->nOBSat<=0 ){
157128 pWInfo->nOBSat = 0;
157129 if( nLoop>0 ){
157130 u32 wsFlags = pFrom->aLoop[nLoop-1]->wsFlags;
@@ -158111,10 +158162,30 @@
158111 if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return;
158112 sqlite3VdbePrintOp(0, pc, pOp);
158113 }
158114 #endif
158115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158116 /*
158117 ** Generate the end of the WHERE loop. See comments on
158118 ** sqlite3WhereBegin() for additional information.
158119 */
158120 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
@@ -158363,30 +158434,44 @@
158363 || pOp->opcode==OP_Offset
158364 #endif
158365 ){
158366 int x = pOp->p2;
158367 assert( pIdx->pTable==pTab );
 
 
 
 
 
158368 if( !HasRowid(pTab) ){
158369 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
158370 x = pPk->aiColumn[x];
158371 assert( x>=0 );
158372 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158373 }else if( pOp->opcode==OP_Offset ){
158374 /* Do not need to translate the column number */
158375 #endif
158376 }else{
158377 testcase( x!=sqlite3StorageColumnToTable(pTab,x) );
158378 x = sqlite3StorageColumnToTable(pTab,x);
158379 }
158380 x = sqlite3TableColumnToIndex(pIdx, x);
158381 if( x>=0 ){
158382 pOp->p2 = x;
158383 pOp->p1 = pLevel->iIdxCur;
158384 OpcodeRewriteTrace(db, k, pOp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158385 }
158386 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
158387 || pWInfo->eOnePass );
158388 }else if( pOp->opcode==OP_Rowid ){
158389 pOp->p1 = pLevel->iIdxCur;
158390 pOp->opcode = OP_IdxRowid;
158391 OpcodeRewriteTrace(db, k, pOp);
158392 }else if( pOp->opcode==OP_IfNullRow ){
@@ -234607,11 +234692,11 @@
234607 int nArg, /* Number of args */
234608 sqlite3_value **apUnused /* Function arguments */
234609 ){
234610 assert( nArg==0 );
234611 UNUSED_PARAM2(nArg, apUnused);
234612 sqlite3_result_text(pCtx, "fts5: 2022-03-11 15:42:05 0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea", -1, SQLITE_TRANSIENT);
234613 }
234614
234615 /*
234616 ** Return true if zName is the extension on one of the shadow tables used
234617 ** by this module.
234618
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -5897,11 +5897,12 @@
5897 **
5898 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
5899 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5900 ** is a [protected sqlite3_value] object even if the input is not.
5901 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5902 ** memory allocation fails. ^If V is a [pointer value], then the result
5903 ** of sqlite3_value_dup(V) is a NULL value.
5904 **
5905 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5906 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
5907 ** then sqlite3_value_free(V) is a harmless no-op.
5908 */
@@ -9858,12 +9859,12 @@
9859 **
9860 ** This API may only be used from within an [xBestIndex|xBestIndex method]
9861 ** of a [virtual table] implementation. The result of calling this
9862 ** interface from outside of xBestIndex() is undefined and probably harmful.
9863 **
9864 ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9865 ** 3. The integer returned by sqlite3_vtab_distinct()
9866 ** gives the virtual table additional information about how the query
9867 ** planner wants the output to be ordered. As long as the virtual table
9868 ** can meet the ordering requirements of the query planner, it may set
9869 ** the "orderByConsumed" flag.
9870 **
@@ -9891,10 +9892,17 @@
9892 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9893 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9894 ** that have the same value for all columns identified by "aOrderBy".
9895 ** ^However omitting the extra rows is optional.
9896 ** This mode is used for a DISTINCT query.
9897 ** <li value="3"><p>
9898 ** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9899 ** that the query planner needs only distinct rows but it does need the
9900 ** rows to be sorted.)^ ^The virtual table implementation is free to omit
9901 ** rows that are identical in all aOrderBy columns, if it wants to, but
9902 ** it is not required to omit any rows. This mode is used for queries
9903 ** that have both DISTINCT and ORDER BY clauses.
9904 ** </ol>
9905 **
9906 ** ^For the purposes of comparing virtual table output values to see if the
9907 ** values are same value for sorting purposes, two NULL values are considered
9908 ** to be the same. In other words, the comparison operator is "IS"
@@ -39731,15 +39739,21 @@
39739 int ofst, /* First lock to acquire or release */
39740 int n, /* Number of locks to acquire or release */
39741 int flags /* What to do with the lock */
39742 ){
39743 unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
39744 unixShm *p; /* The shared memory being locked */
39745 unixShmNode *pShmNode; /* The underlying file iNode */
39746 int rc = SQLITE_OK; /* Result code */
39747 u16 mask; /* Mask of locks to take or release */
39748 int *aLock;
39749
39750 p = pDbFd->pShm;
39751 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
39752 pShmNode = p->pShmNode;
39753 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
39754 aLock = pShmNode->aLock;
39755
39756 assert( pShmNode==pDbFd->pInode->pShmNode );
39757 assert( pShmNode->pInode==pDbFd->pInode );
39758 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
39759 assert( n>=1 );
@@ -47026,14 +47040,18 @@
47040 int flags /* What to do with the lock */
47041 ){
47042 winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
47043 winShm *p = pDbFd->pShm; /* The shared memory being locked */
47044 winShm *pX; /* For looping over all siblings */
47045 winShmNode *pShmNode;
47046 int rc = SQLITE_OK; /* Result code */
47047 u16 mask; /* Mask of locks to take or release */
47048
47049 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
47050 pShmNode = p->pShmNode;
47051 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
47052
47053 assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK );
47054 assert( n>=1 );
47055 assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED)
47056 || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
47057 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
@@ -50959,12 +50977,11 @@
50977 /*
50978 ** Make sure the page is marked as dirty. If it isn't dirty already,
50979 ** make it so.
50980 */
50981 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
50982 assert( p->nRef>0 );
 
50983 assert( sqlite3PcachePageSanity(p) );
50984 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
50985 p->flags &= ~PGHDR_DONT_WRITE;
50986 if( p->flags & PGHDR_CLEAN ){
50987 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
@@ -75197,28 +75214,10 @@
75214 unsigned char *newCell = 0;
75215
75216 assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
75217 assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
75218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75219 /* Save the positions of any other cursors open on this table.
75220 **
75221 ** In some cases, the call to btreeMoveto() below is a no-op. For
75222 ** example, when inserting data into a table with auto-generated integer
75223 ** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
@@ -75239,10 +75238,33 @@
75238 ** set the flag, load the schema, and then unset the flag. */
75239 return SQLITE_CORRUPT_BKPT;
75240 }
75241 }
75242
75243 /* Ensure that the cursor is not in the CURSOR_FAULT state and that it
75244 ** points to a valid cell.
75245 */
75246 if( pCur->eState>=CURSOR_REQUIRESEEK ){
75247 testcase( pCur->eState==CURSOR_REQUIRESEEK );
75248 testcase( pCur->eState==CURSOR_FAULT );
75249 rc = moveToRoot(pCur);
75250 if( rc && rc!=SQLITE_EMPTY ) return rc;
75251 }
75252
75253 assert( cursorOwnsBtShared(pCur) );
75254 assert( (pCur->curFlags & BTCF_WriteFlag)!=0
75255 && pBt->inTransaction==TRANS_WRITE
75256 && (pBt->btsFlags & BTS_READ_ONLY)==0 );
75257 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75258
75259 /* Assert that the caller has been consistent. If this cursor was opened
75260 ** expecting an index b-tree, then the caller should be inserting blob
75261 ** keys with no associated data. If the cursor was opened expecting an
75262 ** intkey table, the caller should be inserting integer keys with a
75263 ** blob of associated data. */
75264 assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
75265
75266 if( pCur->pKeyInfo==0 ){
75267 assert( pX->pKey==0 );
75268 /* If this is an insert into a table b-tree, invalidate any incrblob
75269 ** cursors open on the row being replaced */
75270 if( p->hasIncrblobCur ){
@@ -75327,18 +75349,18 @@
75349 return btreeOverwriteCell(pCur, &x2);
75350 }
75351 }
75352 }
75353 assert( pCur->eState==CURSOR_VALID
75354 || (pCur->eState==CURSOR_INVALID && loc) );
 
75355
75356 pPage = pCur->pPage;
75357 assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
75358 assert( pPage->leaf || !pPage->intKey );
75359 if( pPage->nFree<0 ){
75360 if( NEVER(pCur->eState>CURSOR_INVALID) ){
75361 /* ^^^^^--- due to the moveToRoot() call above */
75362 rc = SQLITE_CORRUPT_BKPT;
75363 }else{
75364 rc = btreeComputeFreeSpace(pPage);
75365 }
75366 if( rc ) return rc;
@@ -75615,16 +75637,20 @@
75637 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
75638 assert( pCur->curFlags & BTCF_WriteFlag );
75639 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
75640 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
75641 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
75642 if( pCur->eState!=CURSOR_VALID ){
75643 if( pCur->eState>=CURSOR_REQUIRESEEK ){
75644 rc = btreeRestoreCursorPosition(pCur);
75645 assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
75646 if( rc || pCur->eState!=CURSOR_VALID ) return rc;
75647 }else{
75648 return SQLITE_CORRUPT_BKPT;
75649 }
75650 }
75651 assert( pCur->eState==CURSOR_VALID );
75652
75653 iCellDepth = pCur->iPage;
75654 iCellIdx = pCur->ix;
75655 pPage = pCur->pPage;
75656 if( pPage->nCell<=iCellIdx ){
@@ -75652,11 +75678,12 @@
75678 ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT.
75679 */
75680 bPreserve = (flags & BTREE_SAVEPOSITION)!=0;
75681 if( bPreserve ){
75682 if( !pPage->leaf
75683 || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2) >
75684 (int)(pBt->usableSize*2/3)
75685 || pPage->nCell==1 /* See dbfuzz001.test for a test case */
75686 ){
75687 /* A b-tree rebalance will be required after deleting this entry.
75688 ** Save the cursor key. */
75689 rc = saveCursorKey(pCur);
@@ -82987,11 +83014,11 @@
83014 || (!deferred && p->nFkConstraint>0)
83015 ){
83016 p->rc = SQLITE_CONSTRAINT_FOREIGNKEY;
83017 p->errorAction = OE_Abort;
83018 sqlite3VdbeError(p, "FOREIGN KEY constraint failed");
83019 return SQLITE_CONSTRAINT_FOREIGNKEY;
83020 }
83021 return SQLITE_OK;
83022 }
83023 #endif
83024
@@ -85578,10 +85605,13 @@
85605 pNew->flags |= MEM_Ephem;
85606 if( sqlite3VdbeMemMakeWriteable(pNew)!=SQLITE_OK ){
85607 sqlite3ValueFree(pNew);
85608 pNew = 0;
85609 }
85610 }else if( pNew->flags & MEM_Null ){
85611 /* Do not duplicate pointer values */
85612 pNew->flags &= ~(MEM_Term|MEM_Subtype);
85613 }
85614 return pNew;
85615 }
85616
85617 /* Destroy an sqlite3_value object previously obtained from
@@ -125318,11 +125348,11 @@
125348 sqlite3OomFault(db);
125349 return;
125350 }
125351
125352 for(i=j=0; i<pTab->nCol; i++){
125353 assert( pTab->aCol[i].affinity!=0 || sqlite3VdbeParser(v)->nErr>0 );
125354 if( (pTab->aCol[i].colFlags & COLFLAG_VIRTUAL)==0 ){
125355 zColAff[j++] = pTab->aCol[i].affinity;
125356 }
125357 }
125358 do{
@@ -128783,10 +128813,15 @@
128813 int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128814 int (*vtab_distinct)(sqlite3_index_info*);
128815 int (*vtab_in)(sqlite3_index_info*,int,int);
128816 int (*vtab_in_first)(sqlite3_value*,sqlite3_value**);
128817 int (*vtab_in_next)(sqlite3_value*,sqlite3_value**);
128818 /* Version 3.39.0 and later */
128819 int (*deserialize)(sqlite3*,const char*,unsigned char*,
128820 sqlite3_int64,sqlite3_int64,unsigned);
128821 unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
128822 unsigned int);
128823 };
128824
128825 /*
128826 ** This is the function signature used for all extension entry points. It
128827 ** is also defined in the file "loadext.c".
@@ -129101,10 +129136,14 @@
129136 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
129137 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
129138 #define sqlite3_vtab_in sqlite3_api->vtab_in
129139 #define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
129140 #define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
129141 #ifndef SQLITE_OMIT_DESERIALIZE
129142 #define sqlite3_deserialize sqlite3_api->deserialize
129143 #define sqlite3_serialize sqlite3_api->serialize
129144 #endif
129145 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
129146
129147 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
129148 /* This case when the file really is being compiled as a loadable
129149 ** extension */
@@ -129596,11 +129635,19 @@
129635 sqlite3_error_offset,
129636 sqlite3_vtab_rhs_value,
129637 sqlite3_vtab_distinct,
129638 sqlite3_vtab_in,
129639 sqlite3_vtab_in_first,
129640 sqlite3_vtab_in_next,
129641 /* Version 3.39.0 and later */
129642 #ifndef SQLITE_OMIT_DESERIALIZE
129643 sqlite3_deserialize,
129644 sqlite3_serialize
129645 #else
129646 0,
129647 0
129648 #endif
129649 };
129650
129651 /* True if x is the directory separator character
129652 */
129653 #if SQLITE_OS_WIN
@@ -134449,11 +134496,11 @@
134496 ** how to process the DISTINCT keyword, to simplify passing that information
134497 ** into the selectInnerLoop() routine.
134498 */
134499 typedef struct DistinctCtx DistinctCtx;
134500 struct DistinctCtx {
134501 u8 isTnct; /* 0: Not distinct. 1: DISTICT 2: DISTINCT and ORDER BY */
134502 u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */
134503 int tabTnct; /* Ephemeral table used for DISTINCT processing */
134504 int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */
134505 };
134506
@@ -141249,10 +141296,11 @@
141296 p->selFlags |= SF_Aggregate;
141297 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
141298 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
141299 ** original setting of the SF_Distinct flag, not the current setting */
141300 assert( sDistinct.isTnct );
141301 sDistinct.isTnct = 2;
141302
141303 #if SELECTTRACE_ENABLED
141304 if( sqlite3SelectTrace & 0x400 ){
141305 SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
141306 sqlite3TreeViewSelect(0, p, 0);
@@ -141592,11 +141640,12 @@
141640 ** in the right order to begin with.
141641 */
141642 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
141643 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
141644 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
141645 0, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY)
141646 | (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
141647 );
141648 if( pWInfo==0 ){
141649 sqlite3ExprListDelete(db, pDistinct);
141650 goto select_end;
141651 }
@@ -141774,11 +141823,11 @@
141823 resetAccumulator(pParse, pAggInfo);
141824 sqlite3VdbeAddOp2(v, OP_Integer, 0, iUseFlag);
141825 VdbeComment((v, "indicate accumulator empty"));
141826 sqlite3VdbeAddOp1(v, OP_Return, regReset);
141827
141828 if( distFlag!=0 && eDist!=WHERE_DISTINCT_NOOP ){
141829 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
141830 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
141831 }
141832 } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */
141833 else {
@@ -142248,15 +142297,14 @@
142297 && 0==sqlite3StrICmp(pTrig->table, pTab->zName)
142298 && pTrig->pTabSchema!=pTmpSchema
142299 ){
142300 pTrig->pNext = pList;
142301 pList = pTrig;
142302 }else if( pTrig->op==TK_RETURNING ){
142303 #ifndef SQLITE_OMIT_VIRTUALTABLE
142304 assert( pParse->db->pVtabCtx==0 );
142305 #endif
 
142306 assert( pParse->bReturning );
142307 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
142308 pTrig->table = pTab->zName;
142309 pTrig->pTabSchema = pTab->pSchema;
142310 pTrig->pNext = pList;
@@ -146506,10 +146554,11 @@
146554 pTab = pCtx->pTab;
146555 assert( IsVirtual(pTab) );
146556
146557 sqlite3ParseObjectInit(&sParse, db);
146558 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
146559 sParse.disableTriggers = 1;
146560 /* We should never be able to reach this point while loading the
146561 ** schema. Nevertheless, defend against that (turn off db->init.busy)
146562 ** in case a bug arises. */
146563 assert( db->init.busy==0 );
146564 initBusy = db->init.busy;
@@ -153429,12 +153478,14 @@
153478 /* No matches cause a break out of the loop */
153479 break;
153480 }
153481 if( i==n ){
153482 nOrderBy = n;
153483 if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY) ){
153484 eDistinct = 2 + ((pWInfo->wctrlFlags & WHERE_SORTBYGROUP)!=0);
153485 }else if( pWInfo->wctrlFlags & WHERE_GROUPBY ){
153486 eDistinct = 1;
153487 }
153488 }
153489 }
153490
153491 /* Allocate the sqlite3_index_info structure
@@ -155986,13 +156037,11 @@
156037 /*
156038 ** Return true if ORDER BY clause may be handled as DISTINCT.
156039 */
156040 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
156041 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
156042 assert( pHidden->eDistinct>=0 && pHidden->eDistinct<=3 );
 
 
156043 return pHidden->eDistinct;
156044 }
156045
156046 #if (defined(SQLITE_ENABLE_DBPAGE_VTAB) || defined(SQLITE_TEST)) \
156047 && !defined(SQLITE_OMIT_VIRTUALTABLE)
@@ -156447,11 +156496,13 @@
156496 if( wctrlFlags & WHERE_ORDERBY_LIMIT ) continue;
156497 }else{
156498 pLoop = pLast;
156499 }
156500 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
156501 if( pLoop->u.vtab.isOrdered
156502 && ((wctrlFlags&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP))!=WHERE_DISTINCTBY)
156503 ){
156504 obSat = obDone;
156505 }
156506 break;
156507 }else if( wctrlFlags & WHERE_DISTINCTBY ){
156508 pLoop->u.btree.nDistinctCol = 0;
@@ -156714,11 +156765,11 @@
156765 **
156766 ** SELECT * FROM t1 GROUP BY x,y ORDER BY x,y; -- IsSorted()==1
156767 ** SELECT * FROM t1 GROUP BY y,x ORDER BY y,x; -- IsSorted()==0
156768 */
156769 SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo *pWInfo){
156770 assert( pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY) );
156771 assert( pWInfo->wctrlFlags & WHERE_SORTBYGROUP );
156772 return pWInfo->sorted;
156773 }
156774
156775 #ifdef WHERETRACE_ENABLED
@@ -157115,16 +157166,16 @@
157166 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
157167 }
157168 }
157169 pWInfo->bOrderedInnerLoop = 0;
157170 if( pWInfo->pOrderBy ){
157171 pWInfo->nOBSat = pFrom->isOrdered;
157172 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
157173 if( pFrom->isOrdered==pWInfo->pOrderBy->nExpr ){
157174 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
157175 }
157176 }else{
 
157177 pWInfo->revMask = pFrom->revLoop;
157178 if( pWInfo->nOBSat<=0 ){
157179 pWInfo->nOBSat = 0;
157180 if( nLoop>0 ){
157181 u32 wsFlags = pFrom->aLoop[nLoop-1]->wsFlags;
@@ -158111,10 +158162,30 @@
158162 if( (db->flags & SQLITE_VdbeAddopTrace)==0 ) return;
158163 sqlite3VdbePrintOp(0, pc, pOp);
158164 }
158165 #endif
158166
158167 #ifdef SQLITE_DEBUG
158168 /*
158169 ** Return true if cursor iCur is opened by instruction k of the
158170 ** bytecode. Used inside of assert() only.
158171 */
158172 static int cursorIsOpen(Vdbe *v, int iCur, int k){
158173 while( k>=0 ){
158174 VdbeOp *pOp = sqlite3VdbeGetOp(v,k--);
158175 if( pOp->p1!=iCur ) continue;
158176 if( pOp->opcode==OP_Close ) return 0;
158177 if( pOp->opcode==OP_OpenRead ) return 1;
158178 if( pOp->opcode==OP_OpenWrite ) return 1;
158179 if( pOp->opcode==OP_OpenDup ) return 1;
158180 if( pOp->opcode==OP_OpenAutoindex ) return 1;
158181 if( pOp->opcode==OP_OpenEphemeral ) return 1;
158182 }
158183 return 0;
158184 }
158185 #endif /* SQLITE_DEBUG */
158186
158187 /*
158188 ** Generate the end of the WHERE loop. See comments on
158189 ** sqlite3WhereBegin() for additional information.
158190 */
158191 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
@@ -158363,30 +158434,44 @@
158434 || pOp->opcode==OP_Offset
158435 #endif
158436 ){
158437 int x = pOp->p2;
158438 assert( pIdx->pTable==pTab );
158439 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158440 if( pOp->opcode==OP_Offset ){
158441 /* Do not need to translate the column number */
158442 }else
158443 #endif
158444 if( !HasRowid(pTab) ){
158445 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
158446 x = pPk->aiColumn[x];
158447 assert( x>=0 );
 
 
 
 
158448 }else{
158449 testcase( x!=sqlite3StorageColumnToTable(pTab,x) );
158450 x = sqlite3StorageColumnToTable(pTab,x);
158451 }
158452 x = sqlite3TableColumnToIndex(pIdx, x);
158453 if( x>=0 ){
158454 pOp->p2 = x;
158455 pOp->p1 = pLevel->iIdxCur;
158456 OpcodeRewriteTrace(db, k, pOp);
158457 }else{
158458 /* Unable to translate the table reference into an index
158459 ** reference. Verify that this is harmless - that the
158460 ** table being referenced really is open.
158461 */
158462 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
158463 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
158464 || cursorIsOpen(v,pOp->p1,k)
158465 || pOp->opcode==OP_Offset
158466 );
158467 #else
158468 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
158469 || cursorIsOpen(v,pOp->p1,k)
158470 );
158471 #endif
158472 }
 
 
158473 }else if( pOp->opcode==OP_Rowid ){
158474 pOp->p1 = pLevel->iIdxCur;
158475 pOp->opcode = OP_IdxRowid;
158476 OpcodeRewriteTrace(db, k, pOp);
158477 }else if( pOp->opcode==OP_IfNullRow ){
@@ -234607,11 +234692,11 @@
234692 int nArg, /* Number of args */
234693 sqlite3_value **apUnused /* Function arguments */
234694 ){
234695 assert( nArg==0 );
234696 UNUSED_PARAM2(nArg, apUnused);
234697 sqlite3_result_text(pCtx, "fts5: 2022-03-14 20:31:57 387ab17b8a0a4b87903aab52abc7da79098b882aff2ab687a554d5794e9d183e", -1, SQLITE_TRANSIENT);
234698 }
234699
234700 /*
234701 ** Return true if zName is the extension on one of the shadow tables used
234702 ** by this module.
234703
+12 -4
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.39.0"
150150
#define SQLITE_VERSION_NUMBER 3039000
151
-#define SQLITE_SOURCE_ID "2022-03-11 15:42:05 0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea"
151
+#define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -5591,11 +5591,12 @@
55915591
**
55925592
** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
55935593
** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
55945594
** is a [protected sqlite3_value] object even if the input is not.
55955595
** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5596
-** memory allocation fails.
5596
+** memory allocation fails. ^If V is a [pointer value], then the result
5597
+** of sqlite3_value_dup(V) is a NULL value.
55975598
**
55985599
** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
55995600
** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
56005601
** then sqlite3_value_free(V) is a harmless no-op.
56015602
*/
@@ -9552,12 +9553,12 @@
95529553
**
95539554
** This API may only be used from within an [xBestIndex|xBestIndex method]
95549555
** of a [virtual table] implementation. The result of calling this
95559556
** interface from outside of xBestIndex() is undefined and probably harmful.
95569557
**
9557
-** ^The sqlite3_vtab_distinct() interface returns an integer that is
9558
-** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9558
+** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9559
+** 3. The integer returned by sqlite3_vtab_distinct()
95599560
** gives the virtual table additional information about how the query
95609561
** planner wants the output to be ordered. As long as the virtual table
95619562
** can meet the ordering requirements of the query planner, it may set
95629563
** the "orderByConsumed" flag.
95639564
**
@@ -9585,10 +9586,17 @@
95859586
** values in all "aOrderBy" columns to be returned, as long as all such rows
95869587
** are adjacent. ^The virtual table may, if it chooses, omit extra rows
95879588
** that have the same value for all columns identified by "aOrderBy".
95889589
** ^However omitting the extra rows is optional.
95899590
** This mode is used for a DISTINCT query.
9591
+** <li value="3"><p>
9592
+** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9593
+** that the query planner needs only distinct rows but it does need the
9594
+** rows to be sorted.)^ ^The virtual table implementation is free to omit
9595
+** rows that are identical in all aOrderBy columns, if it wants to, but
9596
+** it is not required to omit any rows. This mode is used for queries
9597
+** that have both DISTINCT and ORDER BY clauses.
95909598
** </ol>
95919599
**
95929600
** ^For the purposes of comparing virtual table output values to see if the
95939601
** values are same value for sorting purposes, two NULL values are considered
95949602
** to be the same. In other words, the comparison operator is "IS"
95959603
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-03-11 15:42:05 0606e8e93edb5de4d154f377dbf91f15295d25ca9013c0f1612ae6d63a0139ea"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -5591,11 +5591,12 @@
5591 **
5592 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
5593 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5594 ** is a [protected sqlite3_value] object even if the input is not.
5595 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5596 ** memory allocation fails.
 
5597 **
5598 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5599 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
5600 ** then sqlite3_value_free(V) is a harmless no-op.
5601 */
@@ -9552,12 +9553,12 @@
9552 **
9553 ** This API may only be used from within an [xBestIndex|xBestIndex method]
9554 ** of a [virtual table] implementation. The result of calling this
9555 ** interface from outside of xBestIndex() is undefined and probably harmful.
9556 **
9557 ** ^The sqlite3_vtab_distinct() interface returns an integer that is
9558 ** either 0, 1, or 2. The integer returned by sqlite3_vtab_distinct()
9559 ** gives the virtual table additional information about how the query
9560 ** planner wants the output to be ordered. As long as the virtual table
9561 ** can meet the ordering requirements of the query planner, it may set
9562 ** the "orderByConsumed" flag.
9563 **
@@ -9585,10 +9586,17 @@
9585 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9586 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9587 ** that have the same value for all columns identified by "aOrderBy".
9588 ** ^However omitting the extra rows is optional.
9589 ** This mode is used for a DISTINCT query.
 
 
 
 
 
 
 
9590 ** </ol>
9591 **
9592 ** ^For the purposes of comparing virtual table output values to see if the
9593 ** values are same value for sorting purposes, two NULL values are considered
9594 ** to be the same. In other words, the comparison operator is "IS"
9595
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-03-23 10:04:52 43143ad131f17734fd2eff849e0a1bc2e26daf6a28c7e07d697d38732e6af5fc"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -5591,11 +5591,12 @@
5591 **
5592 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
5593 ** object D and returns a pointer to that copy. ^The [sqlite3_value] returned
5594 ** is a [protected sqlite3_value] object even if the input is not.
5595 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5596 ** memory allocation fails. ^If V is a [pointer value], then the result
5597 ** of sqlite3_value_dup(V) is a NULL value.
5598 **
5599 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5600 ** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer
5601 ** then sqlite3_value_free(V) is a harmless no-op.
5602 */
@@ -9552,12 +9553,12 @@
9553 **
9554 ** This API may only be used from within an [xBestIndex|xBestIndex method]
9555 ** of a [virtual table] implementation. The result of calling this
9556 ** interface from outside of xBestIndex() is undefined and probably harmful.
9557 **
9558 ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
9559 ** 3. The integer returned by sqlite3_vtab_distinct()
9560 ** gives the virtual table additional information about how the query
9561 ** planner wants the output to be ordered. As long as the virtual table
9562 ** can meet the ordering requirements of the query planner, it may set
9563 ** the "orderByConsumed" flag.
9564 **
@@ -9585,10 +9586,17 @@
9586 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9587 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9588 ** that have the same value for all columns identified by "aOrderBy".
9589 ** ^However omitting the extra rows is optional.
9590 ** This mode is used for a DISTINCT query.
9591 ** <li value="3"><p>
9592 ** ^(If the sqlite3_vtab_distinct() interface returns 3, that means
9593 ** that the query planner needs only distinct rows but it does need the
9594 ** rows to be sorted.)^ ^The virtual table implementation is free to omit
9595 ** rows that are identical in all aOrderBy columns, if it wants to, but
9596 ** it is not required to omit any rows. This mode is used for queries
9597 ** that have both DISTINCT and ORDER BY clauses.
9598 ** </ol>
9599 **
9600 ** ^For the purposes of comparing virtual table output values to see if the
9601 ** values are same value for sorting purposes, two NULL values are considered
9602 ** to be the same. In other words, the comparison operator is "IS"
9603

Keyboard Shortcuts

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