Fossil SCM

Update the built-in SQLite to the 3.45.1 patch release.

drh 2024-01-30 18:00 trunk
Commit 55a0a4d01a50b292d5e383e84b7ec02aeffca0afeaa95d9141fb83550186eb8e
+59 -51
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -28277,65 +28277,73 @@
2827728277
**
2827828278
** The implementation uses the ShellState.eRestoreState to maintain state:
2827928279
**
2828028280
** 0: Have not seen any SQL.
2828128281
** 1: Have seen "PRAGMA foreign_keys=OFF;".
28282
-** 2: Currently assuming we are parsing ".dump" restore, defensive mode
28283
-** should be disabled following the current transaction.
28284
-** 3: Nothing left to do.
28282
+** 2-6: Currently running .dump transaction. If the "2" bit is set,
28283
+** disable DEFENSIVE when done. If "4" is set, disable DQS_DDL.
28284
+** 7: Nothing left to do. This function becomes a no-op.
2828528285
*/
2828628286
static int doAutoDetectRestore(ShellState *p, const char *zSql){
2828728287
int rc = SQLITE_OK;
2828828288
28289
- switch( p->eRestoreState ){
28290
- case 0: {
28291
- int bDefense = 0; /* True if in defensive mode */
28292
- const char *zExpect = "PRAGMA foreign_keys=OFF;";
28293
- assert( strlen(zExpect)==24 );
28294
- sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &bDefense);
28295
- if( p->bSafeMode==0 && bDefense && memcmp(zSql, zExpect, 25)==0 ){
28296
- p->eRestoreState = 1;
28297
- }else{
28298
- p->eRestoreState = 3;
28299
- }
28300
- break;
28301
- };
28302
-
28303
- case 1: {
28304
- const char *zExpect = "BEGIN TRANSACTION;";
28305
- assert( strlen(zExpect)==18 );
28306
- if( memcmp(zSql, zExpect, 19)==0 ){
28307
- /* Now check if the database is empty. */
28308
- const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
28309
- sqlite3_stmt *pStmt = 0;
28310
- int bEmpty = 1;
28311
-
28312
- shellPrepare(p->db, &rc, zQuery, &pStmt);
28313
- if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
28314
- bEmpty = 0;
28315
- }
28316
- shellFinalize(&rc, pStmt);
28317
- if( bEmpty && rc==SQLITE_OK ){
28318
- sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
28319
- }else{
28320
- p->eRestoreState = 3;
28321
- }
28322
- }
28323
- break;
28324
- }
28325
-
28326
- case 2: {
28327
- if( sqlite3_get_autocommit(p->db) ){
28328
- sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
28329
- p->eRestoreState = 3;
28330
- }
28331
- break;
28332
- }
28333
-
28334
- default: /* Nothing to do */
28335
- assert( p->eRestoreState==3 );
28336
- break;
28289
+ if( p->eRestoreState<7 ){
28290
+ switch( p->eRestoreState ){
28291
+ case 0: {
28292
+ const char *zExpect = "PRAGMA foreign_keys=OFF;";
28293
+ assert( strlen(zExpect)==24 );
28294
+ if( p->bSafeMode==0 && memcmp(zSql, zExpect, 25)==0 ){
28295
+ p->eRestoreState = 1;
28296
+ }else{
28297
+ p->eRestoreState = 7;
28298
+ }
28299
+ break;
28300
+ };
28301
+
28302
+ case 1: {
28303
+ int bIsDump = 0;
28304
+ const char *zExpect = "BEGIN TRANSACTION;";
28305
+ assert( strlen(zExpect)==18 );
28306
+ if( memcmp(zSql, zExpect, 19)==0 ){
28307
+ /* Now check if the database is empty. */
28308
+ const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
28309
+ sqlite3_stmt *pStmt = 0;
28310
+
28311
+ bIsDump = 1;
28312
+ shellPrepare(p->db, &rc, zQuery, &pStmt);
28313
+ if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
28314
+ bIsDump = 0;
28315
+ }
28316
+ shellFinalize(&rc, pStmt);
28317
+ }
28318
+ if( bIsDump && rc==SQLITE_OK ){
28319
+ int bDefense = 0;
28320
+ int bDqsDdl = 0;
28321
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &bDefense);
28322
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, -1, &bDqsDdl);
28323
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
28324
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 1, 0);
28325
+ p->eRestoreState = (bDefense ? 2 : 0) + (bDqsDdl ? 4 : 0);
28326
+ }else{
28327
+ p->eRestoreState = 7;
28328
+ }
28329
+ break;
28330
+ }
28331
+
28332
+ default: {
28333
+ if( sqlite3_get_autocommit(p->db) ){
28334
+ if( (p->eRestoreState & 2) ){
28335
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 1, 0);
28336
+ }
28337
+ if( (p->eRestoreState & 4) ){
28338
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 0, 0);
28339
+ }
28340
+ p->eRestoreState = 7;
28341
+ }
28342
+ break;
28343
+ }
28344
+ }
2833728345
}
2833828346
2833928347
return rc;
2834028348
}
2834128349
2834228350
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -28277,65 +28277,73 @@
28277 **
28278 ** The implementation uses the ShellState.eRestoreState to maintain state:
28279 **
28280 ** 0: Have not seen any SQL.
28281 ** 1: Have seen "PRAGMA foreign_keys=OFF;".
28282 ** 2: Currently assuming we are parsing ".dump" restore, defensive mode
28283 ** should be disabled following the current transaction.
28284 ** 3: Nothing left to do.
28285 */
28286 static int doAutoDetectRestore(ShellState *p, const char *zSql){
28287 int rc = SQLITE_OK;
28288
28289 switch( p->eRestoreState ){
28290 case 0: {
28291 int bDefense = 0; /* True if in defensive mode */
28292 const char *zExpect = "PRAGMA foreign_keys=OFF;";
28293 assert( strlen(zExpect)==24 );
28294 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &bDefense);
28295 if( p->bSafeMode==0 && bDefense && memcmp(zSql, zExpect, 25)==0 ){
28296 p->eRestoreState = 1;
28297 }else{
28298 p->eRestoreState = 3;
28299 }
28300 break;
28301 };
28302
28303 case 1: {
28304 const char *zExpect = "BEGIN TRANSACTION;";
28305 assert( strlen(zExpect)==18 );
28306 if( memcmp(zSql, zExpect, 19)==0 ){
28307 /* Now check if the database is empty. */
28308 const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
28309 sqlite3_stmt *pStmt = 0;
28310 int bEmpty = 1;
28311
28312 shellPrepare(p->db, &rc, zQuery, &pStmt);
28313 if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
28314 bEmpty = 0;
28315 }
28316 shellFinalize(&rc, pStmt);
28317 if( bEmpty && rc==SQLITE_OK ){
28318 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
28319 }else{
28320 p->eRestoreState = 3;
28321 }
28322 }
28323 break;
28324 }
28325
28326 case 2: {
28327 if( sqlite3_get_autocommit(p->db) ){
28328 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
28329 p->eRestoreState = 3;
28330 }
28331 break;
28332 }
28333
28334 default: /* Nothing to do */
28335 assert( p->eRestoreState==3 );
28336 break;
 
 
 
 
 
 
 
 
28337 }
28338
28339 return rc;
28340 }
28341
28342
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -28277,65 +28277,73 @@
28277 **
28278 ** The implementation uses the ShellState.eRestoreState to maintain state:
28279 **
28280 ** 0: Have not seen any SQL.
28281 ** 1: Have seen "PRAGMA foreign_keys=OFF;".
28282 ** 2-6: Currently running .dump transaction. If the "2" bit is set,
28283 ** disable DEFENSIVE when done. If "4" is set, disable DQS_DDL.
28284 ** 7: Nothing left to do. This function becomes a no-op.
28285 */
28286 static int doAutoDetectRestore(ShellState *p, const char *zSql){
28287 int rc = SQLITE_OK;
28288
28289 if( p->eRestoreState<7 ){
28290 switch( p->eRestoreState ){
28291 case 0: {
28292 const char *zExpect = "PRAGMA foreign_keys=OFF;";
28293 assert( strlen(zExpect)==24 );
28294 if( p->bSafeMode==0 && memcmp(zSql, zExpect, 25)==0 ){
28295 p->eRestoreState = 1;
28296 }else{
28297 p->eRestoreState = 7;
28298 }
28299 break;
28300 };
28301
28302 case 1: {
28303 int bIsDump = 0;
28304 const char *zExpect = "BEGIN TRANSACTION;";
28305 assert( strlen(zExpect)==18 );
28306 if( memcmp(zSql, zExpect, 19)==0 ){
28307 /* Now check if the database is empty. */
28308 const char *zQuery = "SELECT 1 FROM sqlite_schema LIMIT 1";
28309 sqlite3_stmt *pStmt = 0;
28310
28311 bIsDump = 1;
28312 shellPrepare(p->db, &rc, zQuery, &pStmt);
28313 if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
28314 bIsDump = 0;
28315 }
28316 shellFinalize(&rc, pStmt);
28317 }
28318 if( bIsDump && rc==SQLITE_OK ){
28319 int bDefense = 0;
28320 int bDqsDdl = 0;
28321 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &bDefense);
28322 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, -1, &bDqsDdl);
28323 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
28324 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 1, 0);
28325 p->eRestoreState = (bDefense ? 2 : 0) + (bDqsDdl ? 4 : 0);
28326 }else{
28327 p->eRestoreState = 7;
28328 }
28329 break;
28330 }
28331
28332 default: {
28333 if( sqlite3_get_autocommit(p->db) ){
28334 if( (p->eRestoreState & 2) ){
28335 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 1, 0);
28336 }
28337 if( (p->eRestoreState & 4) ){
28338 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DQS_DDL, 0, 0);
28339 }
28340 p->eRestoreState = 7;
28341 }
28342 break;
28343 }
28344 }
28345 }
28346
28347 return rc;
28348 }
28349
28350
+142 -93
--- 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.45.0. By combining all the individual C code files into this
3
+** version 3.45.1. 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
-** 97709ce2a1f5ae05495e412ca27108048e5b.
21
+** e876e51a0ed5c5b3126f52e532044363a014.
2222
*/
2323
#define SQLITE_CORE 1
2424
#define SQLITE_AMALGAMATION 1
2525
#ifndef SQLITE_PRIVATE
2626
# define SQLITE_PRIVATE static
@@ -457,13 +457,13 @@
457457
**
458458
** See also: [sqlite3_libversion()],
459459
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460460
** [sqlite_version()] and [sqlite_source_id()].
461461
*/
462
-#define SQLITE_VERSION "3.45.0"
463
-#define SQLITE_VERSION_NUMBER 3045000
464
-#define SQLITE_SOURCE_ID "2024-01-09 12:28:51 97709ce2a1f5ae05495e412ca27108048e5b8a63a1e3bca4be13933f7527da7b"
462
+#define SQLITE_VERSION "3.45.1"
463
+#define SQLITE_VERSION_NUMBER 3045001
464
+#define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
465465
466466
/*
467467
** CAPI3REF: Run-Time Library Version Numbers
468468
** KEYWORDS: sqlite3_version sqlite3_sourceid
469469
**
@@ -43406,15 +43406,20 @@
4340643406
#endif
4340743407
*pp = 0;
4340843408
4340943409
#if SQLITE_MAX_MMAP_SIZE>0
4341043410
if( pFd->mmapSizeMax>0 ){
43411
+ /* Ensure that there is always at least a 256 byte buffer of addressable
43412
+ ** memory following the returned page. If the database is corrupt,
43413
+ ** SQLite may overread the page slightly (in practice only a few bytes,
43414
+ ** but 256 is safe, round, number). */
43415
+ const int nEofBuffer = 256;
4341143416
if( pFd->pMapRegion==0 ){
4341243417
int rc = unixMapfile(pFd, -1);
4341343418
if( rc!=SQLITE_OK ) return rc;
4341443419
}
43415
- if( pFd->mmapSize >= iOff+nAmt ){
43420
+ if( pFd->mmapSize >= (iOff+nAmt+nEofBuffer) ){
4341643421
*pp = &((u8 *)pFd->pMapRegion)[iOff];
4341743422
pFd->nFetchOut++;
4341843423
}
4341943424
}
4342043425
#endif
@@ -50763,19 +50768,24 @@
5076350768
OSTRACE(("FETCH pid=%lu, pFile=%p, offset=%lld, amount=%d, pp=%p\n",
5076450769
osGetCurrentProcessId(), fd, iOff, nAmt, pp));
5076550770
5076650771
#if SQLITE_MAX_MMAP_SIZE>0
5076750772
if( pFd->mmapSizeMax>0 ){
50773
+ /* Ensure that there is always at least a 256 byte buffer of addressable
50774
+ ** memory following the returned page. If the database is corrupt,
50775
+ ** SQLite may overread the page slightly (in practice only a few bytes,
50776
+ ** but 256 is safe, round, number). */
50777
+ const int nEofBuffer = 256;
5076850778
if( pFd->pMapRegion==0 ){
5076950779
int rc = winMapfile(pFd, -1);
5077050780
if( rc!=SQLITE_OK ){
5077150781
OSTRACE(("FETCH pid=%lu, pFile=%p, rc=%s\n",
5077250782
osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
5077350783
return rc;
5077450784
}
5077550785
}
50776
- if( pFd->mmapSize >= iOff+nAmt ){
50786
+ if( pFd->mmapSize >= (iOff+nAmt+nEofBuffer) ){
5077750787
assert( pFd->pMapRegion!=0 );
5077850788
*pp = &((u8 *)pFd->pMapRegion)[iOff];
5077950789
pFd->nFetchOut++;
5078050790
}
5078150791
}
@@ -67665,13 +67675,17 @@
6766567675
6766667676
(void)walEnableBlockingMs(pWal, nBlockTmout);
6766767677
rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
6766867678
walDisableBlocking(pWal);
6766967679
if( rc ){
67680
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
6767067681
if( rc==SQLITE_BUSY_TIMEOUT ){
6767167682
*pCnt |= WAL_RETRY_BLOCKED_MASK;
6767267683
}
67684
+#else
67685
+ assert( rc!=SQLITE_BUSY_TIMEOUT );
67686
+#endif
6767367687
assert( (rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT );
6767467688
return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
6767567689
}
6767667690
/* Now that the read-lock has been obtained, check that neither the
6767767691
** value in the aReadMark[] array or the contents of the wal-index
@@ -76396,11 +76410,14 @@
7639676410
if( pCur->skipNext<0 ) return SQLITE_OK;
7639776411
}
7639876412
}
7639976413
7640076414
pPage = pCur->pPage;
76401
- assert( pPage->isInit );
76415
+ if( sqlite3FaultSim(412) ) pPage->isInit = 0;
76416
+ if( !pPage->isInit ){
76417
+ return SQLITE_CORRUPT_BKPT;
76418
+ }
7640276419
if( !pPage->leaf ){
7640376420
int idx = pCur->ix;
7640476421
rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
7640576422
if( rc ) return rc;
7640676423
rc = moveToRightmost(pCur);
@@ -166806,11 +166823,14 @@
166806166823
db = pParse->db;
166807166824
memset(&sWLB, 0, sizeof(sWLB));
166808166825
166809166826
/* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
166810166827
testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
166811
- if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
166828
+ if( pOrderBy && pOrderBy->nExpr>=BMS ){
166829
+ pOrderBy = 0;
166830
+ wctrlFlags &= ~WHERE_WANT_DISTINCT;
166831
+ }
166812166832
166813166833
/* The number of tables in the FROM clause is limited by the number of
166814166834
** bits in a Bitmask
166815166835
*/
166816166836
testcase( pTabList->nSrc==BMS );
@@ -184743,10 +184763,12 @@
184743184763
SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
184744184764
#endif
184745184765
184746184766
SQLITE_PRIVATE int sqlite3Fts3ExprIterate(Fts3Expr*, int (*x)(Fts3Expr*,int,void*), void*);
184747184767
184768
+SQLITE_PRIVATE int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk);
184769
+
184748184770
#endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
184749184771
#endif /* _FTSINT_H */
184750184772
184751184773
/************** End of fts3Int.h *********************************************/
184752184774
/************** Continuing where we left off in fts3.c ***********************/
@@ -188465,42 +188487,33 @@
188465188487
188466188488
/*
188467188489
** Implementation of the xIntegrity() method on the FTS3/FTS4 virtual
188468188490
** table.
188469188491
*/
188470
-static int fts3Integrity(
188492
+static int fts3IntegrityMethod(
188471188493
sqlite3_vtab *pVtab, /* The virtual table to be checked */
188472188494
const char *zSchema, /* Name of schema in which pVtab lives */
188473188495
const char *zTabname, /* Name of the pVTab table */
188474188496
int isQuick, /* True if this is a quick_check */
188475188497
char **pzErr /* Write error message here */
188476188498
){
188477188499
Fts3Table *p = (Fts3Table*)pVtab;
188478
- char *zSql;
188479188500
int rc;
188480
- char *zErr = 0;
188501
+ int bOk = 0;
188481188502
188482
- assert( pzErr!=0 );
188483
- assert( *pzErr==0 );
188484188503
UNUSED_PARAMETER(isQuick);
188485
- zSql = sqlite3_mprintf(
188486
- "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
188487
- zSchema, zTabname, zTabname);
188488
- if( zSql==0 ){
188489
- return SQLITE_NOMEM;
188490
- }
188491
- rc = sqlite3_exec(p->db, zSql, 0, 0, &zErr);
188492
- sqlite3_free(zSql);
188493
- if( (rc&0xff)==SQLITE_CORRUPT ){
188504
+ rc = sqlite3Fts3IntegrityCheck(p, &bOk);
188505
+ assert( rc!=SQLITE_CORRUPT_VTAB || bOk==0 );
188506
+ if( rc!=SQLITE_OK && rc!=SQLITE_CORRUPT_VTAB ){
188507
+ *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
188508
+ " FTS%d table %s.%s: %s",
188509
+ p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
188510
+ }else if( bOk==0 ){
188494188511
*pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
188495188512
p->bFts4 ? 4 : 3, zSchema, zTabname);
188496
- }else if( rc!=SQLITE_OK ){
188497
- *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
188498
- " FTS%d table %s.%s: %s",
188499
- p->bFts4 ? 4 : 3, zSchema, zTabname, zErr);
188500188513
}
188501
- sqlite3_free(zErr);
188514
+ sqlite3Fts3SegmentsClose(p);
188502188515
return SQLITE_OK;
188503188516
}
188504188517
188505188518
188506188519
@@ -188527,11 +188540,11 @@
188527188540
/* xRename */ fts3RenameMethod,
188528188541
/* xSavepoint */ fts3SavepointMethod,
188529188542
/* xRelease */ fts3ReleaseMethod,
188530188543
/* xRollbackTo */ fts3RollbackToMethod,
188531188544
/* xShadowName */ fts3ShadowName,
188532
- /* xIntegrity */ fts3Integrity,
188545
+ /* xIntegrity */ fts3IntegrityMethod,
188533188546
};
188534188547
188535188548
/*
188536188549
** This function is registered as the module destructor (called when an
188537188550
** FTS3 enabled database connection is closed). It frees the memory
@@ -200081,11 +200094,11 @@
200081200094
** to false before returning.
200082200095
**
200083200096
** If an error occurs (e.g. an OOM or IO error), return an SQLite error
200084200097
** code. The final value of *pbOk is undefined in this case.
200085200098
*/
200086
-static int fts3IntegrityCheck(Fts3Table *p, int *pbOk){
200099
+SQLITE_PRIVATE int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk){
200087200100
int rc = SQLITE_OK; /* Return code */
200088200101
u64 cksum1 = 0; /* Checksum based on FTS index contents */
200089200102
u64 cksum2 = 0; /* Checksum based on %_content contents */
200090200103
sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
200091200104
@@ -200159,11 +200172,11 @@
200159200172
}
200160200173
200161200174
sqlite3_finalize(pStmt);
200162200175
}
200163200176
200164
- *pbOk = (cksum1==cksum2);
200177
+ *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
200165200178
return rc;
200166200179
}
200167200180
200168200181
/*
200169200182
** Run the integrity-check. If no error occurs and the current contents of
@@ -200199,11 +200212,11 @@
200199200212
static int fts3DoIntegrityCheck(
200200200213
Fts3Table *p /* FTS3 table handle */
200201200214
){
200202200215
int rc;
200203200216
int bOk = 0;
200204
- rc = fts3IntegrityCheck(p, &bOk);
200217
+ rc = sqlite3Fts3IntegrityCheck(p, &bOk);
200205200218
if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
200206200219
return rc;
200207200220
}
200208200221
200209200222
/*
@@ -203751,19 +203764,29 @@
203751203764
jsonAppendCharExpand(p,c);
203752203765
}else{
203753203766
p->zBuf[p->nUsed++] = c;
203754203767
}
203755203768
}
203769
+
203770
+/* Remove a single character from the end of the string
203771
+*/
203772
+static void jsonStringTrimOneChar(JsonString *p){
203773
+ if( p->eErr==0 ){
203774
+ assert( p->nUsed>0 );
203775
+ p->nUsed--;
203776
+ }
203777
+}
203778
+
203756203779
203757203780
/* Make sure there is a zero terminator on p->zBuf[]
203758203781
**
203759203782
** Return true on success. Return false if an OOM prevents this
203760203783
** from happening.
203761203784
*/
203762203785
static int jsonStringTerminate(JsonString *p){
203763203786
jsonAppendChar(p, 0);
203764
- p->nUsed--;
203787
+ jsonStringTrimOneChar(p);
203765203788
return p->eErr==0;
203766203789
}
203767203790
203768203791
/* Append a comma separator to the output buffer, if the previous
203769203792
** character is not '[' or '{'.
@@ -205225,12 +205248,12 @@
205225205248
}
205226205249
sz = (pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
205227205250
(pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
205228205251
n = 9;
205229205252
}
205230
- if( i+sz+n > pParse->nBlob
205231
- && i+sz+n > pParse->nBlob-pParse->delta
205253
+ if( (i64)i+sz+n > pParse->nBlob
205254
+ && (i64)i+sz+n > pParse->nBlob-pParse->delta
205232205255
){
205233205256
sz = 0;
205234205257
n = 0;
205235205258
}
205236205259
*pSz = sz;
@@ -205276,18 +205299,20 @@
205276205299
jsonAppendRawNZ(pOut, "false", 5);
205277205300
return i+1;
205278205301
}
205279205302
case JSONB_INT:
205280205303
case JSONB_FLOAT: {
205304
+ if( sz==0 ) goto malformed_jsonb;
205281205305
jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz);
205282205306
break;
205283205307
}
205284205308
case JSONB_INT5: { /* Integer literal in hexadecimal notation */
205285205309
u32 k = 2;
205286205310
sqlite3_uint64 u = 0;
205287205311
const char *zIn = (const char*)&pParse->aBlob[i+n];
205288205312
int bOverflow = 0;
205313
+ if( sz==0 ) goto malformed_jsonb;
205289205314
if( zIn[0]=='-' ){
205290205315
jsonAppendChar(pOut, '-');
205291205316
k++;
205292205317
}else if( zIn[0]=='+' ){
205293205318
k++;
@@ -205306,10 +205331,11 @@
205306205331
break;
205307205332
}
205308205333
case JSONB_FLOAT5: { /* Float literal missing digits beside "." */
205309205334
u32 k = 0;
205310205335
const char *zIn = (const char*)&pParse->aBlob[i+n];
205336
+ if( sz==0 ) goto malformed_jsonb;
205311205337
if( zIn[0]=='-' ){
205312205338
jsonAppendChar(pOut, '-');
205313205339
k++;
205314205340
}
205315205341
if( zIn[k]=='.' ){
@@ -205419,34 +205445,36 @@
205419205445
}
205420205446
case JSONB_ARRAY: {
205421205447
jsonAppendChar(pOut, '[');
205422205448
j = i+n;
205423205449
iEnd = j+sz;
205424
- while( j<iEnd ){
205450
+ while( j<iEnd && pOut->eErr==0 ){
205425205451
j = jsonTranslateBlobToText(pParse, j, pOut);
205426205452
jsonAppendChar(pOut, ',');
205427205453
}
205428
- if( sz>0 ) pOut->nUsed--;
205454
+ if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
205455
+ if( sz>0 ) jsonStringTrimOneChar(pOut);
205429205456
jsonAppendChar(pOut, ']');
205430205457
break;
205431205458
}
205432205459
case JSONB_OBJECT: {
205433205460
int x = 0;
205434205461
jsonAppendChar(pOut, '{');
205435205462
j = i+n;
205436205463
iEnd = j+sz;
205437
- while( j<iEnd ){
205464
+ while( j<iEnd && pOut->eErr==0 ){
205438205465
j = jsonTranslateBlobToText(pParse, j, pOut);
205439205466
jsonAppendChar(pOut, (x++ & 1) ? ',' : ':');
205440205467
}
205441
- if( x & 1 ) pOut->eErr |= JSTRING_MALFORMED;
205442
- if( sz>0 ) pOut->nUsed--;
205468
+ if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
205469
+ if( sz>0 ) jsonStringTrimOneChar(pOut);
205443205470
jsonAppendChar(pOut, '}');
205444205471
break;
205445205472
}
205446205473
205447205474
default: {
205475
+ malformed_jsonb:
205448205476
pOut->eErr |= JSTRING_MALFORMED;
205449205477
break;
205450205478
}
205451205479
}
205452205480
return i+n+sz;
@@ -206368,10 +206396,42 @@
206368206396
}else{
206369206397
jsonBadPathError(ctx, zPath);
206370206398
}
206371206399
return;
206372206400
}
206401
+
206402
+/*
206403
+** If pArg is a blob that seems like a JSONB blob, then initialize
206404
+** p to point to that JSONB and return TRUE. If pArg does not seem like
206405
+** a JSONB blob, then return FALSE;
206406
+**
206407
+** This routine is only called if it is already known that pArg is a
206408
+** blob. The only open question is whether or not the blob appears
206409
+** to be a JSONB blob.
206410
+*/
206411
+static int jsonArgIsJsonb(sqlite3_value *pArg, JsonParse *p){
206412
+ u32 n, sz = 0;
206413
+ p->aBlob = (u8*)sqlite3_value_blob(pArg);
206414
+ p->nBlob = (u32)sqlite3_value_bytes(pArg);
206415
+ if( p->nBlob==0 ){
206416
+ p->aBlob = 0;
206417
+ return 0;
206418
+ }
206419
+ if( NEVER(p->aBlob==0) ){
206420
+ return 0;
206421
+ }
206422
+ if( (p->aBlob[0] & 0x0f)<=JSONB_OBJECT
206423
+ && (n = jsonbPayloadSize(p, 0, &sz))>0
206424
+ && sz+n==p->nBlob
206425
+ && ((p->aBlob[0] & 0x0f)>JSONB_FALSE || sz==0)
206426
+ ){
206427
+ return 1;
206428
+ }
206429
+ p->aBlob = 0;
206430
+ p->nBlob = 0;
206431
+ return 0;
206432
+}
206373206433
206374206434
/*
206375206435
** Generate a JsonParse object, containing valid JSONB in aBlob and nBlob,
206376206436
** from the SQL function argument pArg. Return a pointer to the new
206377206437
** JsonParse object.
@@ -206425,33 +206485,28 @@
206425206485
p->hasNonstd = pFromCache->hasNonstd;
206426206486
jsonParseFree(pFromCache);
206427206487
return p;
206428206488
}
206429206489
if( eType==SQLITE_BLOB ){
206430
- u32 n, sz = 0;
206431
- p->aBlob = (u8*)sqlite3_value_blob(pArg);
206432
- p->nBlob = (u32)sqlite3_value_bytes(pArg);
206433
- if( p->nBlob==0 ){
206434
- goto json_pfa_malformed;
206435
- }
206436
- if( NEVER(p->aBlob==0) ){
206437
- goto json_pfa_oom;
206438
- }
206439
- if( (p->aBlob[0] & 0x0f)>JSONB_OBJECT ){
206440
- goto json_pfa_malformed;
206441
- }
206442
- n = jsonbPayloadSize(p, 0, &sz);
206443
- if( n==0
206444
- || sz+n!=p->nBlob
206445
- || ((p->aBlob[0] & 0x0f)<=JSONB_FALSE && sz>0)
206446
- ){
206447
- goto json_pfa_malformed;
206448
- }
206449
- if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){
206450
- goto json_pfa_oom;
206451
- }
206452
- return p;
206490
+ if( jsonArgIsJsonb(pArg,p) ){
206491
+ if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){
206492
+ goto json_pfa_oom;
206493
+ }
206494
+ return p;
206495
+ }
206496
+ /* If the blob is not valid JSONB, fall through into trying to cast
206497
+ ** the blob into text which is then interpreted as JSON. (tag-20240123-a)
206498
+ **
206499
+ ** This goes against all historical documentation about how the SQLite
206500
+ ** JSON functions were suppose to work. From the beginning, blob was
206501
+ ** reserved for expansion and a blob value should have raised an error.
206502
+ ** But it did not, due to a bug. And many applications came to depend
206503
+ ** upon this buggy behavior, espeically when using the CLI and reading
206504
+ ** JSON text using readfile(), which returns a blob. For this reason
206505
+ ** we will continue to support the bug moving forward.
206506
+ ** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d
206507
+ */
206453206508
}
206454206509
p->zJson = (char*)sqlite3_value_text(pArg);
206455206510
p->nJson = sqlite3_value_bytes(pArg);
206456206511
if( p->nJson==0 ) goto json_pfa_malformed;
206457206512
if( NEVER(p->zJson==0) ) goto json_pfa_oom;
@@ -207423,16 +207478,16 @@
207423207478
sqlite3_result_int(ctx, 0);
207424207479
#endif
207425207480
return;
207426207481
}
207427207482
case SQLITE_BLOB: {
207428
- if( (flags & 0x0c)!=0 && jsonFuncArgMightBeBinary(argv[0]) ){
207483
+ if( jsonFuncArgMightBeBinary(argv[0]) ){
207429207484
if( flags & 0x04 ){
207430207485
/* Superficial checking only - accomplished by the
207431207486
** jsonFuncArgMightBeBinary() call above. */
207432207487
res = 1;
207433
- }else{
207488
+ }else if( flags & 0x08 ){
207434207489
/* Strict checking. Check by translating BLOB->TEXT->BLOB. If
207435207490
** no errors occur, call that a "strict check". */
207436207491
JsonParse px;
207437207492
u32 iErr;
207438207493
memset(&px, 0, sizeof(px));
@@ -207439,12 +207494,15 @@
207439207494
px.aBlob = (u8*)sqlite3_value_blob(argv[0]);
207440207495
px.nBlob = sqlite3_value_bytes(argv[0]);
207441207496
iErr = jsonbValidityCheck(&px, 0, px.nBlob, 1);
207442207497
res = iErr==0;
207443207498
}
207499
+ break;
207444207500
}
207445
- break;
207501
+ /* Fall through into interpreting the input as text. See note
207502
+ ** above at tag-20240123-a. */
207503
+ /* no break */ deliberate_fall_through
207446207504
}
207447207505
default: {
207448207506
JsonParse px;
207449207507
if( (flags & 0x3)==0 ) break;
207450207508
memset(&px, 0, sizeof(px));
@@ -207565,21 +207623,21 @@
207565207623
}else if( flags & JSON_BLOB ){
207566207624
jsonReturnStringAsBlob(pStr);
207567207625
if( isFinal ){
207568207626
if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
207569207627
}else{
207570
- pStr->nUsed--;
207628
+ jsonStringTrimOneChar(pStr);
207571207629
}
207572207630
return;
207573207631
}else if( isFinal ){
207574207632
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
207575207633
pStr->bStatic ? SQLITE_TRANSIENT :
207576207634
sqlite3RCStrUnref);
207577207635
pStr->bStatic = 1;
207578207636
}else{
207579207637
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
207580
- pStr->nUsed--;
207638
+ jsonStringTrimOneChar(pStr);
207581207639
}
207582207640
}else{
207583207641
sqlite3_result_text(ctx, "[]", 2, SQLITE_STATIC);
207584207642
}
207585207643
sqlite3_result_subtype(ctx, JSON_SUBTYPE);
@@ -207685,21 +207743,21 @@
207685207743
}else if( flags & JSON_BLOB ){
207686207744
jsonReturnStringAsBlob(pStr);
207687207745
if( isFinal ){
207688207746
if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
207689207747
}else{
207690
- pStr->nUsed--;
207748
+ jsonStringTrimOneChar(pStr);
207691207749
}
207692207750
return;
207693207751
}else if( isFinal ){
207694207752
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
207695207753
pStr->bStatic ? SQLITE_TRANSIENT :
207696207754
sqlite3RCStrUnref);
207697207755
pStr->bStatic = 1;
207698207756
}else{
207699207757
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
207700
- pStr->nUsed--;
207758
+ jsonStringTrimOneChar(pStr);
207701207759
}
207702207760
}else{
207703207761
sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
207704207762
}
207705207763
sqlite3_result_subtype(ctx, JSON_SUBTYPE);
@@ -208176,17 +208234,13 @@
208176208234
jsonEachCursorReset(p);
208177208235
if( idxNum==0 ) return SQLITE_OK;
208178208236
memset(&p->sParse, 0, sizeof(p->sParse));
208179208237
p->sParse.nJPRef = 1;
208180208238
p->sParse.db = p->db;
208181
- if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
208182
- if( jsonFuncArgMightBeBinary(argv[0]) ){
208183
- p->sParse.nBlob = sqlite3_value_bytes(argv[0]);
208184
- p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]);
208185
- }else{
208186
- goto json_each_malformed_input;
208187
- }
208239
+ if( jsonFuncArgMightBeBinary(argv[0]) ){
208240
+ p->sParse.nBlob = sqlite3_value_bytes(argv[0]);
208241
+ p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]);
208188208242
}else{
208189208243
p->sParse.zJson = (char*)sqlite3_value_text(argv[0]);
208190208244
p->sParse.nJson = sqlite3_value_bytes(argv[0]);
208191208245
if( p->sParse.zJson==0 ){
208192208246
p->i = p->iEnd = 0;
@@ -225283,13 +225337,11 @@
225283225337
225284225338
/* Delete all attached table objects. And the contents of their
225285225339
** associated hash-tables. */
225286225340
sessionDeleteTable(pSession, pSession->pTable);
225287225341
225288
- /* Assert that all allocations have been freed and then free the
225289
- ** session object itself. */
225290
- // assert( pSession->nMalloc==0 );
225342
+ /* Free the session object. */
225291225343
sqlite3_free(pSession);
225292225344
}
225293225345
225294225346
/*
225295225347
** Set a table filter on a Session Object.
@@ -249139,11 +249191,14 @@
249139249191
pConfig->bPrefixIndex = sqlite3_value_int(pVal);
249140249192
#endif
249141249193
}else if( 0==sqlite3_stricmp("flush", zCmd) ){
249142249194
rc = sqlite3Fts5FlushToDisk(&pTab->p);
249143249195
}else{
249144
- rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
249196
+ rc = sqlite3Fts5FlushToDisk(&pTab->p);
249197
+ if( rc==SQLITE_OK ){
249198
+ rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
249199
+ }
249145249200
if( rc==SQLITE_OK ){
249146249201
rc = sqlite3Fts5ConfigSetValue(pTab->p.pConfig, zCmd, pVal, &bError);
249147249202
}
249148249203
if( rc==SQLITE_OK ){
249149249204
if( bError ){
@@ -250490,11 +250545,11 @@
250490250545
int nArg, /* Number of args */
250491250546
sqlite3_value **apUnused /* Function arguments */
250492250547
){
250493250548
assert( nArg==0 );
250494250549
UNUSED_PARAM2(nArg, apUnused);
250495
- sqlite3_result_text(pCtx, "fts5: 2024-01-08 19:55:40 cd016f26bb61549a304f2148035e050f76a8f4a35cdb7131bba2f5fc5d09f49e", -1, SQLITE_TRANSIENT);
250550
+ sqlite3_result_text(pCtx, "fts5: 2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a", -1, SQLITE_TRANSIENT);
250496250551
}
250497250552
250498250553
/*
250499250554
** Return true if zName is the extension on one of the shadow tables used
250500250555
** by this module.
@@ -250521,31 +250576,25 @@
250521250576
const char *zTabname, /* Name of the table itself */
250522250577
int isQuick, /* True if this is a quick-check */
250523250578
char **pzErr /* Write error message here */
250524250579
){
250525250580
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
250526
- Fts5Config *pConfig = pTab->p.pConfig;
250527
- char *zSql;
250528
- char *zErr = 0;
250529250581
int rc;
250582
+
250530250583
assert( pzErr!=0 && *pzErr==0 );
250531250584
UNUSED_PARAM(isQuick);
250532
- zSql = sqlite3_mprintf(
250533
- "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
250534
- zSchema, zTabname, pConfig->zName);
250535
- if( zSql==0 ) return SQLITE_NOMEM;
250536
- rc = sqlite3_exec(pConfig->db, zSql, 0, 0, &zErr);
250537
- sqlite3_free(zSql);
250585
+ rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
250538250586
if( (rc&0xff)==SQLITE_CORRUPT ){
250539250587
*pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
250540250588
zSchema, zTabname);
250541250589
}else if( rc!=SQLITE_OK ){
250542250590
*pzErr = sqlite3_mprintf("unable to validate the inverted index for"
250543250591
" FTS5 table %s.%s: %s",
250544
- zSchema, zTabname, zErr);
250592
+ zSchema, zTabname, sqlite3_errstr(rc));
250545250593
}
250546
- sqlite3_free(zErr);
250594
+ sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
250595
+
250547250596
return SQLITE_OK;
250548250597
}
250549250598
250550250599
static int fts5Init(sqlite3 *db){
250551250600
static const sqlite3_module fts5Mod = {
250552250601
--- 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.45.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 ** 97709ce2a1f5ae05495e412ca27108048e5b.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -457,13 +457,13 @@
457 **
458 ** See also: [sqlite3_libversion()],
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.45.0"
463 #define SQLITE_VERSION_NUMBER 3045000
464 #define SQLITE_SOURCE_ID "2024-01-09 12:28:51 97709ce2a1f5ae05495e412ca27108048e5b8a63a1e3bca4be13933f7527da7b"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -43406,15 +43406,20 @@
43406 #endif
43407 *pp = 0;
43408
43409 #if SQLITE_MAX_MMAP_SIZE>0
43410 if( pFd->mmapSizeMax>0 ){
 
 
 
 
 
43411 if( pFd->pMapRegion==0 ){
43412 int rc = unixMapfile(pFd, -1);
43413 if( rc!=SQLITE_OK ) return rc;
43414 }
43415 if( pFd->mmapSize >= iOff+nAmt ){
43416 *pp = &((u8 *)pFd->pMapRegion)[iOff];
43417 pFd->nFetchOut++;
43418 }
43419 }
43420 #endif
@@ -50763,19 +50768,24 @@
50763 OSTRACE(("FETCH pid=%lu, pFile=%p, offset=%lld, amount=%d, pp=%p\n",
50764 osGetCurrentProcessId(), fd, iOff, nAmt, pp));
50765
50766 #if SQLITE_MAX_MMAP_SIZE>0
50767 if( pFd->mmapSizeMax>0 ){
 
 
 
 
 
50768 if( pFd->pMapRegion==0 ){
50769 int rc = winMapfile(pFd, -1);
50770 if( rc!=SQLITE_OK ){
50771 OSTRACE(("FETCH pid=%lu, pFile=%p, rc=%s\n",
50772 osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
50773 return rc;
50774 }
50775 }
50776 if( pFd->mmapSize >= iOff+nAmt ){
50777 assert( pFd->pMapRegion!=0 );
50778 *pp = &((u8 *)pFd->pMapRegion)[iOff];
50779 pFd->nFetchOut++;
50780 }
50781 }
@@ -67665,13 +67675,17 @@
67665
67666 (void)walEnableBlockingMs(pWal, nBlockTmout);
67667 rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
67668 walDisableBlocking(pWal);
67669 if( rc ){
 
67670 if( rc==SQLITE_BUSY_TIMEOUT ){
67671 *pCnt |= WAL_RETRY_BLOCKED_MASK;
67672 }
 
 
 
67673 assert( (rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT );
67674 return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
67675 }
67676 /* Now that the read-lock has been obtained, check that neither the
67677 ** value in the aReadMark[] array or the contents of the wal-index
@@ -76396,11 +76410,14 @@
76396 if( pCur->skipNext<0 ) return SQLITE_OK;
76397 }
76398 }
76399
76400 pPage = pCur->pPage;
76401 assert( pPage->isInit );
 
 
 
76402 if( !pPage->leaf ){
76403 int idx = pCur->ix;
76404 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
76405 if( rc ) return rc;
76406 rc = moveToRightmost(pCur);
@@ -166806,11 +166823,14 @@
166806 db = pParse->db;
166807 memset(&sWLB, 0, sizeof(sWLB));
166808
166809 /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
166810 testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
166811 if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
 
 
 
166812
166813 /* The number of tables in the FROM clause is limited by the number of
166814 ** bits in a Bitmask
166815 */
166816 testcase( pTabList->nSrc==BMS );
@@ -184743,10 +184763,12 @@
184743 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
184744 #endif
184745
184746 SQLITE_PRIVATE int sqlite3Fts3ExprIterate(Fts3Expr*, int (*x)(Fts3Expr*,int,void*), void*);
184747
 
 
184748 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
184749 #endif /* _FTSINT_H */
184750
184751 /************** End of fts3Int.h *********************************************/
184752 /************** Continuing where we left off in fts3.c ***********************/
@@ -188465,42 +188487,33 @@
188465
188466 /*
188467 ** Implementation of the xIntegrity() method on the FTS3/FTS4 virtual
188468 ** table.
188469 */
188470 static int fts3Integrity(
188471 sqlite3_vtab *pVtab, /* The virtual table to be checked */
188472 const char *zSchema, /* Name of schema in which pVtab lives */
188473 const char *zTabname, /* Name of the pVTab table */
188474 int isQuick, /* True if this is a quick_check */
188475 char **pzErr /* Write error message here */
188476 ){
188477 Fts3Table *p = (Fts3Table*)pVtab;
188478 char *zSql;
188479 int rc;
188480 char *zErr = 0;
188481
188482 assert( pzErr!=0 );
188483 assert( *pzErr==0 );
188484 UNUSED_PARAMETER(isQuick);
188485 zSql = sqlite3_mprintf(
188486 "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
188487 zSchema, zTabname, zTabname);
188488 if( zSql==0 ){
188489 return SQLITE_NOMEM;
188490 }
188491 rc = sqlite3_exec(p->db, zSql, 0, 0, &zErr);
188492 sqlite3_free(zSql);
188493 if( (rc&0xff)==SQLITE_CORRUPT ){
188494 *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
188495 p->bFts4 ? 4 : 3, zSchema, zTabname);
188496 }else if( rc!=SQLITE_OK ){
188497 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
188498 " FTS%d table %s.%s: %s",
188499 p->bFts4 ? 4 : 3, zSchema, zTabname, zErr);
188500 }
188501 sqlite3_free(zErr);
188502 return SQLITE_OK;
188503 }
188504
188505
188506
@@ -188527,11 +188540,11 @@
188527 /* xRename */ fts3RenameMethod,
188528 /* xSavepoint */ fts3SavepointMethod,
188529 /* xRelease */ fts3ReleaseMethod,
188530 /* xRollbackTo */ fts3RollbackToMethod,
188531 /* xShadowName */ fts3ShadowName,
188532 /* xIntegrity */ fts3Integrity,
188533 };
188534
188535 /*
188536 ** This function is registered as the module destructor (called when an
188537 ** FTS3 enabled database connection is closed). It frees the memory
@@ -200081,11 +200094,11 @@
200081 ** to false before returning.
200082 **
200083 ** If an error occurs (e.g. an OOM or IO error), return an SQLite error
200084 ** code. The final value of *pbOk is undefined in this case.
200085 */
200086 static int fts3IntegrityCheck(Fts3Table *p, int *pbOk){
200087 int rc = SQLITE_OK; /* Return code */
200088 u64 cksum1 = 0; /* Checksum based on FTS index contents */
200089 u64 cksum2 = 0; /* Checksum based on %_content contents */
200090 sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
200091
@@ -200159,11 +200172,11 @@
200159 }
200160
200161 sqlite3_finalize(pStmt);
200162 }
200163
200164 *pbOk = (cksum1==cksum2);
200165 return rc;
200166 }
200167
200168 /*
200169 ** Run the integrity-check. If no error occurs and the current contents of
@@ -200199,11 +200212,11 @@
200199 static int fts3DoIntegrityCheck(
200200 Fts3Table *p /* FTS3 table handle */
200201 ){
200202 int rc;
200203 int bOk = 0;
200204 rc = fts3IntegrityCheck(p, &bOk);
200205 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
200206 return rc;
200207 }
200208
200209 /*
@@ -203751,19 +203764,29 @@
203751 jsonAppendCharExpand(p,c);
203752 }else{
203753 p->zBuf[p->nUsed++] = c;
203754 }
203755 }
 
 
 
 
 
 
 
 
 
 
203756
203757 /* Make sure there is a zero terminator on p->zBuf[]
203758 **
203759 ** Return true on success. Return false if an OOM prevents this
203760 ** from happening.
203761 */
203762 static int jsonStringTerminate(JsonString *p){
203763 jsonAppendChar(p, 0);
203764 p->nUsed--;
203765 return p->eErr==0;
203766 }
203767
203768 /* Append a comma separator to the output buffer, if the previous
203769 ** character is not '[' or '{'.
@@ -205225,12 +205248,12 @@
205225 }
205226 sz = (pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
205227 (pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
205228 n = 9;
205229 }
205230 if( i+sz+n > pParse->nBlob
205231 && i+sz+n > pParse->nBlob-pParse->delta
205232 ){
205233 sz = 0;
205234 n = 0;
205235 }
205236 *pSz = sz;
@@ -205276,18 +205299,20 @@
205276 jsonAppendRawNZ(pOut, "false", 5);
205277 return i+1;
205278 }
205279 case JSONB_INT:
205280 case JSONB_FLOAT: {
 
205281 jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz);
205282 break;
205283 }
205284 case JSONB_INT5: { /* Integer literal in hexadecimal notation */
205285 u32 k = 2;
205286 sqlite3_uint64 u = 0;
205287 const char *zIn = (const char*)&pParse->aBlob[i+n];
205288 int bOverflow = 0;
 
205289 if( zIn[0]=='-' ){
205290 jsonAppendChar(pOut, '-');
205291 k++;
205292 }else if( zIn[0]=='+' ){
205293 k++;
@@ -205306,10 +205331,11 @@
205306 break;
205307 }
205308 case JSONB_FLOAT5: { /* Float literal missing digits beside "." */
205309 u32 k = 0;
205310 const char *zIn = (const char*)&pParse->aBlob[i+n];
 
205311 if( zIn[0]=='-' ){
205312 jsonAppendChar(pOut, '-');
205313 k++;
205314 }
205315 if( zIn[k]=='.' ){
@@ -205419,34 +205445,36 @@
205419 }
205420 case JSONB_ARRAY: {
205421 jsonAppendChar(pOut, '[');
205422 j = i+n;
205423 iEnd = j+sz;
205424 while( j<iEnd ){
205425 j = jsonTranslateBlobToText(pParse, j, pOut);
205426 jsonAppendChar(pOut, ',');
205427 }
205428 if( sz>0 ) pOut->nUsed--;
 
205429 jsonAppendChar(pOut, ']');
205430 break;
205431 }
205432 case JSONB_OBJECT: {
205433 int x = 0;
205434 jsonAppendChar(pOut, '{');
205435 j = i+n;
205436 iEnd = j+sz;
205437 while( j<iEnd ){
205438 j = jsonTranslateBlobToText(pParse, j, pOut);
205439 jsonAppendChar(pOut, (x++ & 1) ? ',' : ':');
205440 }
205441 if( x & 1 ) pOut->eErr |= JSTRING_MALFORMED;
205442 if( sz>0 ) pOut->nUsed--;
205443 jsonAppendChar(pOut, '}');
205444 break;
205445 }
205446
205447 default: {
 
205448 pOut->eErr |= JSTRING_MALFORMED;
205449 break;
205450 }
205451 }
205452 return i+n+sz;
@@ -206368,10 +206396,42 @@
206368 }else{
206369 jsonBadPathError(ctx, zPath);
206370 }
206371 return;
206372 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206373
206374 /*
206375 ** Generate a JsonParse object, containing valid JSONB in aBlob and nBlob,
206376 ** from the SQL function argument pArg. Return a pointer to the new
206377 ** JsonParse object.
@@ -206425,33 +206485,28 @@
206425 p->hasNonstd = pFromCache->hasNonstd;
206426 jsonParseFree(pFromCache);
206427 return p;
206428 }
206429 if( eType==SQLITE_BLOB ){
206430 u32 n, sz = 0;
206431 p->aBlob = (u8*)sqlite3_value_blob(pArg);
206432 p->nBlob = (u32)sqlite3_value_bytes(pArg);
206433 if( p->nBlob==0 ){
206434 goto json_pfa_malformed;
206435 }
206436 if( NEVER(p->aBlob==0) ){
206437 goto json_pfa_oom;
206438 }
206439 if( (p->aBlob[0] & 0x0f)>JSONB_OBJECT ){
206440 goto json_pfa_malformed;
206441 }
206442 n = jsonbPayloadSize(p, 0, &sz);
206443 if( n==0
206444 || sz+n!=p->nBlob
206445 || ((p->aBlob[0] & 0x0f)<=JSONB_FALSE && sz>0)
206446 ){
206447 goto json_pfa_malformed;
206448 }
206449 if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){
206450 goto json_pfa_oom;
206451 }
206452 return p;
206453 }
206454 p->zJson = (char*)sqlite3_value_text(pArg);
206455 p->nJson = sqlite3_value_bytes(pArg);
206456 if( p->nJson==0 ) goto json_pfa_malformed;
206457 if( NEVER(p->zJson==0) ) goto json_pfa_oom;
@@ -207423,16 +207478,16 @@
207423 sqlite3_result_int(ctx, 0);
207424 #endif
207425 return;
207426 }
207427 case SQLITE_BLOB: {
207428 if( (flags & 0x0c)!=0 && jsonFuncArgMightBeBinary(argv[0]) ){
207429 if( flags & 0x04 ){
207430 /* Superficial checking only - accomplished by the
207431 ** jsonFuncArgMightBeBinary() call above. */
207432 res = 1;
207433 }else{
207434 /* Strict checking. Check by translating BLOB->TEXT->BLOB. If
207435 ** no errors occur, call that a "strict check". */
207436 JsonParse px;
207437 u32 iErr;
207438 memset(&px, 0, sizeof(px));
@@ -207439,12 +207494,15 @@
207439 px.aBlob = (u8*)sqlite3_value_blob(argv[0]);
207440 px.nBlob = sqlite3_value_bytes(argv[0]);
207441 iErr = jsonbValidityCheck(&px, 0, px.nBlob, 1);
207442 res = iErr==0;
207443 }
 
207444 }
207445 break;
 
 
207446 }
207447 default: {
207448 JsonParse px;
207449 if( (flags & 0x3)==0 ) break;
207450 memset(&px, 0, sizeof(px));
@@ -207565,21 +207623,21 @@
207565 }else if( flags & JSON_BLOB ){
207566 jsonReturnStringAsBlob(pStr);
207567 if( isFinal ){
207568 if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
207569 }else{
207570 pStr->nUsed--;
207571 }
207572 return;
207573 }else if( isFinal ){
207574 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
207575 pStr->bStatic ? SQLITE_TRANSIENT :
207576 sqlite3RCStrUnref);
207577 pStr->bStatic = 1;
207578 }else{
207579 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
207580 pStr->nUsed--;
207581 }
207582 }else{
207583 sqlite3_result_text(ctx, "[]", 2, SQLITE_STATIC);
207584 }
207585 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
@@ -207685,21 +207743,21 @@
207685 }else if( flags & JSON_BLOB ){
207686 jsonReturnStringAsBlob(pStr);
207687 if( isFinal ){
207688 if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
207689 }else{
207690 pStr->nUsed--;
207691 }
207692 return;
207693 }else if( isFinal ){
207694 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
207695 pStr->bStatic ? SQLITE_TRANSIENT :
207696 sqlite3RCStrUnref);
207697 pStr->bStatic = 1;
207698 }else{
207699 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
207700 pStr->nUsed--;
207701 }
207702 }else{
207703 sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
207704 }
207705 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
@@ -208176,17 +208234,13 @@
208176 jsonEachCursorReset(p);
208177 if( idxNum==0 ) return SQLITE_OK;
208178 memset(&p->sParse, 0, sizeof(p->sParse));
208179 p->sParse.nJPRef = 1;
208180 p->sParse.db = p->db;
208181 if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){
208182 if( jsonFuncArgMightBeBinary(argv[0]) ){
208183 p->sParse.nBlob = sqlite3_value_bytes(argv[0]);
208184 p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]);
208185 }else{
208186 goto json_each_malformed_input;
208187 }
208188 }else{
208189 p->sParse.zJson = (char*)sqlite3_value_text(argv[0]);
208190 p->sParse.nJson = sqlite3_value_bytes(argv[0]);
208191 if( p->sParse.zJson==0 ){
208192 p->i = p->iEnd = 0;
@@ -225283,13 +225337,11 @@
225283
225284 /* Delete all attached table objects. And the contents of their
225285 ** associated hash-tables. */
225286 sessionDeleteTable(pSession, pSession->pTable);
225287
225288 /* Assert that all allocations have been freed and then free the
225289 ** session object itself. */
225290 // assert( pSession->nMalloc==0 );
225291 sqlite3_free(pSession);
225292 }
225293
225294 /*
225295 ** Set a table filter on a Session Object.
@@ -249139,11 +249191,14 @@
249139 pConfig->bPrefixIndex = sqlite3_value_int(pVal);
249140 #endif
249141 }else if( 0==sqlite3_stricmp("flush", zCmd) ){
249142 rc = sqlite3Fts5FlushToDisk(&pTab->p);
249143 }else{
249144 rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
 
 
 
249145 if( rc==SQLITE_OK ){
249146 rc = sqlite3Fts5ConfigSetValue(pTab->p.pConfig, zCmd, pVal, &bError);
249147 }
249148 if( rc==SQLITE_OK ){
249149 if( bError ){
@@ -250490,11 +250545,11 @@
250490 int nArg, /* Number of args */
250491 sqlite3_value **apUnused /* Function arguments */
250492 ){
250493 assert( nArg==0 );
250494 UNUSED_PARAM2(nArg, apUnused);
250495 sqlite3_result_text(pCtx, "fts5: 2024-01-08 19:55:40 cd016f26bb61549a304f2148035e050f76a8f4a35cdb7131bba2f5fc5d09f49e", -1, SQLITE_TRANSIENT);
250496 }
250497
250498 /*
250499 ** Return true if zName is the extension on one of the shadow tables used
250500 ** by this module.
@@ -250521,31 +250576,25 @@
250521 const char *zTabname, /* Name of the table itself */
250522 int isQuick, /* True if this is a quick-check */
250523 char **pzErr /* Write error message here */
250524 ){
250525 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
250526 Fts5Config *pConfig = pTab->p.pConfig;
250527 char *zSql;
250528 char *zErr = 0;
250529 int rc;
 
250530 assert( pzErr!=0 && *pzErr==0 );
250531 UNUSED_PARAM(isQuick);
250532 zSql = sqlite3_mprintf(
250533 "INSERT INTO \"%w\".\"%w\"(\"%w\") VALUES('integrity-check');",
250534 zSchema, zTabname, pConfig->zName);
250535 if( zSql==0 ) return SQLITE_NOMEM;
250536 rc = sqlite3_exec(pConfig->db, zSql, 0, 0, &zErr);
250537 sqlite3_free(zSql);
250538 if( (rc&0xff)==SQLITE_CORRUPT ){
250539 *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
250540 zSchema, zTabname);
250541 }else if( rc!=SQLITE_OK ){
250542 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
250543 " FTS5 table %s.%s: %s",
250544 zSchema, zTabname, zErr);
250545 }
250546 sqlite3_free(zErr);
 
250547 return SQLITE_OK;
250548 }
250549
250550 static int fts5Init(sqlite3 *db){
250551 static const sqlite3_module fts5Mod = {
250552
--- 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.45.1. 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 ** e876e51a0ed5c5b3126f52e532044363a014.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -457,13 +457,13 @@
457 **
458 ** See also: [sqlite3_libversion()],
459 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460 ** [sqlite_version()] and [sqlite_source_id()].
461 */
462 #define SQLITE_VERSION "3.45.1"
463 #define SQLITE_VERSION_NUMBER 3045001
464 #define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
465
466 /*
467 ** CAPI3REF: Run-Time Library Version Numbers
468 ** KEYWORDS: sqlite3_version sqlite3_sourceid
469 **
@@ -43406,15 +43406,20 @@
43406 #endif
43407 *pp = 0;
43408
43409 #if SQLITE_MAX_MMAP_SIZE>0
43410 if( pFd->mmapSizeMax>0 ){
43411 /* Ensure that there is always at least a 256 byte buffer of addressable
43412 ** memory following the returned page. If the database is corrupt,
43413 ** SQLite may overread the page slightly (in practice only a few bytes,
43414 ** but 256 is safe, round, number). */
43415 const int nEofBuffer = 256;
43416 if( pFd->pMapRegion==0 ){
43417 int rc = unixMapfile(pFd, -1);
43418 if( rc!=SQLITE_OK ) return rc;
43419 }
43420 if( pFd->mmapSize >= (iOff+nAmt+nEofBuffer) ){
43421 *pp = &((u8 *)pFd->pMapRegion)[iOff];
43422 pFd->nFetchOut++;
43423 }
43424 }
43425 #endif
@@ -50763,19 +50768,24 @@
50768 OSTRACE(("FETCH pid=%lu, pFile=%p, offset=%lld, amount=%d, pp=%p\n",
50769 osGetCurrentProcessId(), fd, iOff, nAmt, pp));
50770
50771 #if SQLITE_MAX_MMAP_SIZE>0
50772 if( pFd->mmapSizeMax>0 ){
50773 /* Ensure that there is always at least a 256 byte buffer of addressable
50774 ** memory following the returned page. If the database is corrupt,
50775 ** SQLite may overread the page slightly (in practice only a few bytes,
50776 ** but 256 is safe, round, number). */
50777 const int nEofBuffer = 256;
50778 if( pFd->pMapRegion==0 ){
50779 int rc = winMapfile(pFd, -1);
50780 if( rc!=SQLITE_OK ){
50781 OSTRACE(("FETCH pid=%lu, pFile=%p, rc=%s\n",
50782 osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
50783 return rc;
50784 }
50785 }
50786 if( pFd->mmapSize >= (iOff+nAmt+nEofBuffer) ){
50787 assert( pFd->pMapRegion!=0 );
50788 *pp = &((u8 *)pFd->pMapRegion)[iOff];
50789 pFd->nFetchOut++;
50790 }
50791 }
@@ -67665,13 +67675,17 @@
67675
67676 (void)walEnableBlockingMs(pWal, nBlockTmout);
67677 rc = walLockShared(pWal, WAL_READ_LOCK(mxI));
67678 walDisableBlocking(pWal);
67679 if( rc ){
67680 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
67681 if( rc==SQLITE_BUSY_TIMEOUT ){
67682 *pCnt |= WAL_RETRY_BLOCKED_MASK;
67683 }
67684 #else
67685 assert( rc!=SQLITE_BUSY_TIMEOUT );
67686 #endif
67687 assert( (rc&0xFF)!=SQLITE_BUSY||rc==SQLITE_BUSY||rc==SQLITE_BUSY_TIMEOUT );
67688 return (rc&0xFF)==SQLITE_BUSY ? WAL_RETRY : rc;
67689 }
67690 /* Now that the read-lock has been obtained, check that neither the
67691 ** value in the aReadMark[] array or the contents of the wal-index
@@ -76396,11 +76410,14 @@
76410 if( pCur->skipNext<0 ) return SQLITE_OK;
76411 }
76412 }
76413
76414 pPage = pCur->pPage;
76415 if( sqlite3FaultSim(412) ) pPage->isInit = 0;
76416 if( !pPage->isInit ){
76417 return SQLITE_CORRUPT_BKPT;
76418 }
76419 if( !pPage->leaf ){
76420 int idx = pCur->ix;
76421 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
76422 if( rc ) return rc;
76423 rc = moveToRightmost(pCur);
@@ -166806,11 +166823,14 @@
166823 db = pParse->db;
166824 memset(&sWLB, 0, sizeof(sWLB));
166825
166826 /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
166827 testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
166828 if( pOrderBy && pOrderBy->nExpr>=BMS ){
166829 pOrderBy = 0;
166830 wctrlFlags &= ~WHERE_WANT_DISTINCT;
166831 }
166832
166833 /* The number of tables in the FROM clause is limited by the number of
166834 ** bits in a Bitmask
166835 */
166836 testcase( pTabList->nSrc==BMS );
@@ -184743,10 +184763,12 @@
184763 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
184764 #endif
184765
184766 SQLITE_PRIVATE int sqlite3Fts3ExprIterate(Fts3Expr*, int (*x)(Fts3Expr*,int,void*), void*);
184767
184768 SQLITE_PRIVATE int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk);
184769
184770 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */
184771 #endif /* _FTSINT_H */
184772
184773 /************** End of fts3Int.h *********************************************/
184774 /************** Continuing where we left off in fts3.c ***********************/
@@ -188465,42 +188487,33 @@
188487
188488 /*
188489 ** Implementation of the xIntegrity() method on the FTS3/FTS4 virtual
188490 ** table.
188491 */
188492 static int fts3IntegrityMethod(
188493 sqlite3_vtab *pVtab, /* The virtual table to be checked */
188494 const char *zSchema, /* Name of schema in which pVtab lives */
188495 const char *zTabname, /* Name of the pVTab table */
188496 int isQuick, /* True if this is a quick_check */
188497 char **pzErr /* Write error message here */
188498 ){
188499 Fts3Table *p = (Fts3Table*)pVtab;
 
188500 int rc;
188501 int bOk = 0;
188502
 
 
188503 UNUSED_PARAMETER(isQuick);
188504 rc = sqlite3Fts3IntegrityCheck(p, &bOk);
188505 assert( rc!=SQLITE_CORRUPT_VTAB || bOk==0 );
188506 if( rc!=SQLITE_OK && rc!=SQLITE_CORRUPT_VTAB ){
188507 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
188508 " FTS%d table %s.%s: %s",
188509 p->bFts4 ? 4 : 3, zSchema, zTabname, sqlite3_errstr(rc));
188510 }else if( bOk==0 ){
 
 
188511 *pzErr = sqlite3_mprintf("malformed inverted index for FTS%d table %s.%s",
188512 p->bFts4 ? 4 : 3, zSchema, zTabname);
 
 
 
 
188513 }
188514 sqlite3Fts3SegmentsClose(p);
188515 return SQLITE_OK;
188516 }
188517
188518
188519
@@ -188527,11 +188540,11 @@
188540 /* xRename */ fts3RenameMethod,
188541 /* xSavepoint */ fts3SavepointMethod,
188542 /* xRelease */ fts3ReleaseMethod,
188543 /* xRollbackTo */ fts3RollbackToMethod,
188544 /* xShadowName */ fts3ShadowName,
188545 /* xIntegrity */ fts3IntegrityMethod,
188546 };
188547
188548 /*
188549 ** This function is registered as the module destructor (called when an
188550 ** FTS3 enabled database connection is closed). It frees the memory
@@ -200081,11 +200094,11 @@
200094 ** to false before returning.
200095 **
200096 ** If an error occurs (e.g. an OOM or IO error), return an SQLite error
200097 ** code. The final value of *pbOk is undefined in this case.
200098 */
200099 SQLITE_PRIVATE int sqlite3Fts3IntegrityCheck(Fts3Table *p, int *pbOk){
200100 int rc = SQLITE_OK; /* Return code */
200101 u64 cksum1 = 0; /* Checksum based on FTS index contents */
200102 u64 cksum2 = 0; /* Checksum based on %_content contents */
200103 sqlite3_stmt *pAllLangid = 0; /* Statement to return all language-ids */
200104
@@ -200159,11 +200172,11 @@
200172 }
200173
200174 sqlite3_finalize(pStmt);
200175 }
200176
200177 *pbOk = (rc==SQLITE_OK && cksum1==cksum2);
200178 return rc;
200179 }
200180
200181 /*
200182 ** Run the integrity-check. If no error occurs and the current contents of
@@ -200199,11 +200212,11 @@
200212 static int fts3DoIntegrityCheck(
200213 Fts3Table *p /* FTS3 table handle */
200214 ){
200215 int rc;
200216 int bOk = 0;
200217 rc = sqlite3Fts3IntegrityCheck(p, &bOk);
200218 if( rc==SQLITE_OK && bOk==0 ) rc = FTS_CORRUPT_VTAB;
200219 return rc;
200220 }
200221
200222 /*
@@ -203751,19 +203764,29 @@
203764 jsonAppendCharExpand(p,c);
203765 }else{
203766 p->zBuf[p->nUsed++] = c;
203767 }
203768 }
203769
203770 /* Remove a single character from the end of the string
203771 */
203772 static void jsonStringTrimOneChar(JsonString *p){
203773 if( p->eErr==0 ){
203774 assert( p->nUsed>0 );
203775 p->nUsed--;
203776 }
203777 }
203778
203779
203780 /* Make sure there is a zero terminator on p->zBuf[]
203781 **
203782 ** Return true on success. Return false if an OOM prevents this
203783 ** from happening.
203784 */
203785 static int jsonStringTerminate(JsonString *p){
203786 jsonAppendChar(p, 0);
203787 jsonStringTrimOneChar(p);
203788 return p->eErr==0;
203789 }
203790
203791 /* Append a comma separator to the output buffer, if the previous
203792 ** character is not '[' or '{'.
@@ -205225,12 +205248,12 @@
205248 }
205249 sz = (pParse->aBlob[i+5]<<24) + (pParse->aBlob[i+6]<<16) +
205250 (pParse->aBlob[i+7]<<8) + pParse->aBlob[i+8];
205251 n = 9;
205252 }
205253 if( (i64)i+sz+n > pParse->nBlob
205254 && (i64)i+sz+n > pParse->nBlob-pParse->delta
205255 ){
205256 sz = 0;
205257 n = 0;
205258 }
205259 *pSz = sz;
@@ -205276,18 +205299,20 @@
205299 jsonAppendRawNZ(pOut, "false", 5);
205300 return i+1;
205301 }
205302 case JSONB_INT:
205303 case JSONB_FLOAT: {
205304 if( sz==0 ) goto malformed_jsonb;
205305 jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz);
205306 break;
205307 }
205308 case JSONB_INT5: { /* Integer literal in hexadecimal notation */
205309 u32 k = 2;
205310 sqlite3_uint64 u = 0;
205311 const char *zIn = (const char*)&pParse->aBlob[i+n];
205312 int bOverflow = 0;
205313 if( sz==0 ) goto malformed_jsonb;
205314 if( zIn[0]=='-' ){
205315 jsonAppendChar(pOut, '-');
205316 k++;
205317 }else if( zIn[0]=='+' ){
205318 k++;
@@ -205306,10 +205331,11 @@
205331 break;
205332 }
205333 case JSONB_FLOAT5: { /* Float literal missing digits beside "." */
205334 u32 k = 0;
205335 const char *zIn = (const char*)&pParse->aBlob[i+n];
205336 if( sz==0 ) goto malformed_jsonb;
205337 if( zIn[0]=='-' ){
205338 jsonAppendChar(pOut, '-');
205339 k++;
205340 }
205341 if( zIn[k]=='.' ){
@@ -205419,34 +205445,36 @@
205445 }
205446 case JSONB_ARRAY: {
205447 jsonAppendChar(pOut, '[');
205448 j = i+n;
205449 iEnd = j+sz;
205450 while( j<iEnd && pOut->eErr==0 ){
205451 j = jsonTranslateBlobToText(pParse, j, pOut);
205452 jsonAppendChar(pOut, ',');
205453 }
205454 if( j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
205455 if( sz>0 ) jsonStringTrimOneChar(pOut);
205456 jsonAppendChar(pOut, ']');
205457 break;
205458 }
205459 case JSONB_OBJECT: {
205460 int x = 0;
205461 jsonAppendChar(pOut, '{');
205462 j = i+n;
205463 iEnd = j+sz;
205464 while( j<iEnd && pOut->eErr==0 ){
205465 j = jsonTranslateBlobToText(pParse, j, pOut);
205466 jsonAppendChar(pOut, (x++ & 1) ? ',' : ':');
205467 }
205468 if( (x & 1)!=0 || j>iEnd ) pOut->eErr |= JSTRING_MALFORMED;
205469 if( sz>0 ) jsonStringTrimOneChar(pOut);
205470 jsonAppendChar(pOut, '}');
205471 break;
205472 }
205473
205474 default: {
205475 malformed_jsonb:
205476 pOut->eErr |= JSTRING_MALFORMED;
205477 break;
205478 }
205479 }
205480 return i+n+sz;
@@ -206368,10 +206396,42 @@
206396 }else{
206397 jsonBadPathError(ctx, zPath);
206398 }
206399 return;
206400 }
206401
206402 /*
206403 ** If pArg is a blob that seems like a JSONB blob, then initialize
206404 ** p to point to that JSONB and return TRUE. If pArg does not seem like
206405 ** a JSONB blob, then return FALSE;
206406 **
206407 ** This routine is only called if it is already known that pArg is a
206408 ** blob. The only open question is whether or not the blob appears
206409 ** to be a JSONB blob.
206410 */
206411 static int jsonArgIsJsonb(sqlite3_value *pArg, JsonParse *p){
206412 u32 n, sz = 0;
206413 p->aBlob = (u8*)sqlite3_value_blob(pArg);
206414 p->nBlob = (u32)sqlite3_value_bytes(pArg);
206415 if( p->nBlob==0 ){
206416 p->aBlob = 0;
206417 return 0;
206418 }
206419 if( NEVER(p->aBlob==0) ){
206420 return 0;
206421 }
206422 if( (p->aBlob[0] & 0x0f)<=JSONB_OBJECT
206423 && (n = jsonbPayloadSize(p, 0, &sz))>0
206424 && sz+n==p->nBlob
206425 && ((p->aBlob[0] & 0x0f)>JSONB_FALSE || sz==0)
206426 ){
206427 return 1;
206428 }
206429 p->aBlob = 0;
206430 p->nBlob = 0;
206431 return 0;
206432 }
206433
206434 /*
206435 ** Generate a JsonParse object, containing valid JSONB in aBlob and nBlob,
206436 ** from the SQL function argument pArg. Return a pointer to the new
206437 ** JsonParse object.
@@ -206425,33 +206485,28 @@
206485 p->hasNonstd = pFromCache->hasNonstd;
206486 jsonParseFree(pFromCache);
206487 return p;
206488 }
206489 if( eType==SQLITE_BLOB ){
206490 if( jsonArgIsJsonb(pArg,p) ){
206491 if( (flgs & JSON_EDITABLE)!=0 && jsonBlobMakeEditable(p, 0)==0 ){
206492 goto json_pfa_oom;
206493 }
206494 return p;
206495 }
206496 /* If the blob is not valid JSONB, fall through into trying to cast
206497 ** the blob into text which is then interpreted as JSON. (tag-20240123-a)
206498 **
206499 ** This goes against all historical documentation about how the SQLite
206500 ** JSON functions were suppose to work. From the beginning, blob was
206501 ** reserved for expansion and a blob value should have raised an error.
206502 ** But it did not, due to a bug. And many applications came to depend
206503 ** upon this buggy behavior, espeically when using the CLI and reading
206504 ** JSON text using readfile(), which returns a blob. For this reason
206505 ** we will continue to support the bug moving forward.
206506 ** See for example https://sqlite.org/forum/forumpost/012136abd5292b8d
206507 */
 
 
 
 
 
206508 }
206509 p->zJson = (char*)sqlite3_value_text(pArg);
206510 p->nJson = sqlite3_value_bytes(pArg);
206511 if( p->nJson==0 ) goto json_pfa_malformed;
206512 if( NEVER(p->zJson==0) ) goto json_pfa_oom;
@@ -207423,16 +207478,16 @@
207478 sqlite3_result_int(ctx, 0);
207479 #endif
207480 return;
207481 }
207482 case SQLITE_BLOB: {
207483 if( jsonFuncArgMightBeBinary(argv[0]) ){
207484 if( flags & 0x04 ){
207485 /* Superficial checking only - accomplished by the
207486 ** jsonFuncArgMightBeBinary() call above. */
207487 res = 1;
207488 }else if( flags & 0x08 ){
207489 /* Strict checking. Check by translating BLOB->TEXT->BLOB. If
207490 ** no errors occur, call that a "strict check". */
207491 JsonParse px;
207492 u32 iErr;
207493 memset(&px, 0, sizeof(px));
@@ -207439,12 +207494,15 @@
207494 px.aBlob = (u8*)sqlite3_value_blob(argv[0]);
207495 px.nBlob = sqlite3_value_bytes(argv[0]);
207496 iErr = jsonbValidityCheck(&px, 0, px.nBlob, 1);
207497 res = iErr==0;
207498 }
207499 break;
207500 }
207501 /* Fall through into interpreting the input as text. See note
207502 ** above at tag-20240123-a. */
207503 /* no break */ deliberate_fall_through
207504 }
207505 default: {
207506 JsonParse px;
207507 if( (flags & 0x3)==0 ) break;
207508 memset(&px, 0, sizeof(px));
@@ -207565,21 +207623,21 @@
207623 }else if( flags & JSON_BLOB ){
207624 jsonReturnStringAsBlob(pStr);
207625 if( isFinal ){
207626 if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
207627 }else{
207628 jsonStringTrimOneChar(pStr);
207629 }
207630 return;
207631 }else if( isFinal ){
207632 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
207633 pStr->bStatic ? SQLITE_TRANSIENT :
207634 sqlite3RCStrUnref);
207635 pStr->bStatic = 1;
207636 }else{
207637 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
207638 jsonStringTrimOneChar(pStr);
207639 }
207640 }else{
207641 sqlite3_result_text(ctx, "[]", 2, SQLITE_STATIC);
207642 }
207643 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
@@ -207685,21 +207743,21 @@
207743 }else if( flags & JSON_BLOB ){
207744 jsonReturnStringAsBlob(pStr);
207745 if( isFinal ){
207746 if( !pStr->bStatic ) sqlite3RCStrUnref(pStr->zBuf);
207747 }else{
207748 jsonStringTrimOneChar(pStr);
207749 }
207750 return;
207751 }else if( isFinal ){
207752 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
207753 pStr->bStatic ? SQLITE_TRANSIENT :
207754 sqlite3RCStrUnref);
207755 pStr->bStatic = 1;
207756 }else{
207757 sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
207758 jsonStringTrimOneChar(pStr);
207759 }
207760 }else{
207761 sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
207762 }
207763 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
@@ -208176,17 +208234,13 @@
208234 jsonEachCursorReset(p);
208235 if( idxNum==0 ) return SQLITE_OK;
208236 memset(&p->sParse, 0, sizeof(p->sParse));
208237 p->sParse.nJPRef = 1;
208238 p->sParse.db = p->db;
208239 if( jsonFuncArgMightBeBinary(argv[0]) ){
208240 p->sParse.nBlob = sqlite3_value_bytes(argv[0]);
208241 p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]);
 
 
 
 
208242 }else{
208243 p->sParse.zJson = (char*)sqlite3_value_text(argv[0]);
208244 p->sParse.nJson = sqlite3_value_bytes(argv[0]);
208245 if( p->sParse.zJson==0 ){
208246 p->i = p->iEnd = 0;
@@ -225283,13 +225337,11 @@
225337
225338 /* Delete all attached table objects. And the contents of their
225339 ** associated hash-tables. */
225340 sessionDeleteTable(pSession, pSession->pTable);
225341
225342 /* Free the session object. */
 
 
225343 sqlite3_free(pSession);
225344 }
225345
225346 /*
225347 ** Set a table filter on a Session Object.
@@ -249139,11 +249191,14 @@
249191 pConfig->bPrefixIndex = sqlite3_value_int(pVal);
249192 #endif
249193 }else if( 0==sqlite3_stricmp("flush", zCmd) ){
249194 rc = sqlite3Fts5FlushToDisk(&pTab->p);
249195 }else{
249196 rc = sqlite3Fts5FlushToDisk(&pTab->p);
249197 if( rc==SQLITE_OK ){
249198 rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
249199 }
249200 if( rc==SQLITE_OK ){
249201 rc = sqlite3Fts5ConfigSetValue(pTab->p.pConfig, zCmd, pVal, &bError);
249202 }
249203 if( rc==SQLITE_OK ){
249204 if( bError ){
@@ -250490,11 +250545,11 @@
250545 int nArg, /* Number of args */
250546 sqlite3_value **apUnused /* Function arguments */
250547 ){
250548 assert( nArg==0 );
250549 UNUSED_PARAM2(nArg, apUnused);
250550 sqlite3_result_text(pCtx, "fts5: 2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a", -1, SQLITE_TRANSIENT);
250551 }
250552
250553 /*
250554 ** Return true if zName is the extension on one of the shadow tables used
250555 ** by this module.
@@ -250521,31 +250576,25 @@
250576 const char *zTabname, /* Name of the table itself */
250577 int isQuick, /* True if this is a quick-check */
250578 char **pzErr /* Write error message here */
250579 ){
250580 Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
 
 
 
250581 int rc;
250582
250583 assert( pzErr!=0 && *pzErr==0 );
250584 UNUSED_PARAM(isQuick);
250585 rc = sqlite3Fts5StorageIntegrity(pTab->pStorage, 0);
 
 
 
 
 
250586 if( (rc&0xff)==SQLITE_CORRUPT ){
250587 *pzErr = sqlite3_mprintf("malformed inverted index for FTS5 table %s.%s",
250588 zSchema, zTabname);
250589 }else if( rc!=SQLITE_OK ){
250590 *pzErr = sqlite3_mprintf("unable to validate the inverted index for"
250591 " FTS5 table %s.%s: %s",
250592 zSchema, zTabname, sqlite3_errstr(rc));
250593 }
250594 sqlite3Fts5IndexCloseReader(pTab->p.pIndex);
250595
250596 return SQLITE_OK;
250597 }
250598
250599 static int fts5Init(sqlite3 *db){
250600 static const sqlite3_module fts5Mod = {
250601
--- 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.45.0"
150
-#define SQLITE_VERSION_NUMBER 3045000
151
-#define SQLITE_SOURCE_ID "2024-01-09 12:28:51 97709ce2a1f5ae05495e412ca27108048e5b8a63a1e3bca4be13933f7527da7b"
149
+#define SQLITE_VERSION "3.45.1"
150
+#define SQLITE_VERSION_NUMBER 3045001
151
+#define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
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.45.0"
150 #define SQLITE_VERSION_NUMBER 3045000
151 #define SQLITE_SOURCE_ID "2024-01-09 12:28:51 97709ce2a1f5ae05495e412ca27108048e5b8a63a1e3bca4be13933f7527da7b"
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.45.1"
150 #define SQLITE_VERSION_NUMBER 3045001
151 #define SQLITE_SOURCE_ID "2024-01-30 16:01:20 e876e51a0ed5c5b3126f52e532044363a014bc594cfefa87ffb5b82257cc467a"
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