| | @@ -16,11 +16,11 @@ |
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | | -** d22475b81c4e26ccc50f3b5626d43b32f7a2 with changes in files: |
| 21 | +** 20abf1ec107f942e4527901685d61283c9c2 with changes in files: |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| | @@ -465,11 +465,11 @@ |
| 465 | 465 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 466 | 466 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 467 | 467 | */ |
| 468 | 468 | #define SQLITE_VERSION "3.50.0" |
| 469 | 469 | #define SQLITE_VERSION_NUMBER 3050000 |
| 470 | | -#define SQLITE_SOURCE_ID "2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5" |
| 470 | +#define SQLITE_SOURCE_ID "2025-04-30 14:37:00 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849" |
| 471 | 471 | |
| 472 | 472 | /* |
| 473 | 473 | ** CAPI3REF: Run-Time Library Version Numbers |
| 474 | 474 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 475 | 475 | ** |
| | @@ -11872,13 +11872,14 @@ |
| 11872 | 11872 | ** This may appear to have some counter-intuitive effects if a single row |
| 11873 | 11873 | ** is written to more than once during a session. For example, if a row |
| 11874 | 11874 | ** is inserted while a session object is enabled, then later deleted while |
| 11875 | 11875 | ** the same session object is disabled, no INSERT record will appear in the |
| 11876 | 11876 | ** changeset, even though the delete took place while the session was disabled. |
| 11877 | | -** Or, if one field of a row is updated while a session is disabled, and |
| 11878 | | -** another field of the same row is updated while the session is enabled, the |
| 11879 | | -** resulting changeset will contain an UPDATE change that updates both fields. |
| 11877 | +** Or, if one field of a row is updated while a session is enabled, and |
| 11878 | +** then another field of the same row is updated while the session is disabled, |
| 11879 | +** the resulting changeset will contain an UPDATE change that updates both |
| 11880 | +** fields. |
| 11880 | 11881 | */ |
| 11881 | 11882 | SQLITE_API int sqlite3session_changeset( |
| 11882 | 11883 | sqlite3_session *pSession, /* Session object */ |
| 11883 | 11884 | int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */ |
| 11884 | 11885 | void **ppChangeset /* OUT: Buffer containing changeset */ |
| | @@ -32987,10 +32988,19 @@ |
| 32987 | 32988 | va_end(ap); |
| 32988 | 32989 | zBuf[acc.nChar] = 0; |
| 32989 | 32990 | return zBuf; |
| 32990 | 32991 | } |
| 32991 | 32992 | |
| 32993 | +/* Maximum size of an sqlite3_log() message. */ |
| 32994 | +#if defined(SQLITE_MAX_LOG_MESSAGE) |
| 32995 | + /* Leave the definition as supplied */ |
| 32996 | +#elif SQLITE_PRINT_BUF_SIZE*10>10000 |
| 32997 | +# define SQLITE_MAX_LOG_MESSAGE 10000 |
| 32998 | +#else |
| 32999 | +# define SQLITE_MAX_LOG_MESSAGE (SQLITE_PRINT_BUF_SIZE*10) |
| 33000 | +#endif |
| 33001 | + |
| 32992 | 33002 | /* |
| 32993 | 33003 | ** This is the routine that actually formats the sqlite3_log() message. |
| 32994 | 33004 | ** We house it in a separate routine from sqlite3_log() to avoid using |
| 32995 | 33005 | ** stack space on small-stack systems when logging is disabled. |
| 32996 | 33006 | ** |
| | @@ -33003,11 +33013,11 @@ |
| 33003 | 33013 | ** Care must be taken that any sqlite3_log() calls that occur while the |
| 33004 | 33014 | ** memory mutex is held do not use these mechanisms. |
| 33005 | 33015 | */ |
| 33006 | 33016 | static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){ |
| 33007 | 33017 | StrAccum acc; /* String accumulator */ |
| 33008 | | - char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */ |
| 33018 | + char zMsg[SQLITE_MAX_LOG_MESSAGE]; /* Complete log message */ |
| 33009 | 33019 | |
| 33010 | 33020 | sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0); |
| 33011 | 33021 | sqlite3_str_vappendf(&acc, zFormat, ap); |
| 33012 | 33022 | sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode, |
| 33013 | 33023 | sqlite3StrAccumFinish(&acc)); |
| | @@ -95716,11 +95726,11 @@ |
| 95716 | 95726 | } |
| 95717 | 95727 | }else{ |
| 95718 | 95728 | sqlite3VdbeError(p, "%s", pOp->p4.z); |
| 95719 | 95729 | } |
| 95720 | 95730 | pcx = (int)(pOp - aOp); |
| 95721 | | - sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg); |
| 95731 | + sqlite3_log(pOp->p1, "abort at %d: %s; [%s]", pcx, p->zErrMsg, p->zSql); |
| 95722 | 95732 | } |
| 95723 | 95733 | rc = sqlite3VdbeHalt(p); |
| 95724 | 95734 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 95725 | 95735 | if( rc==SQLITE_BUSY ){ |
| 95726 | 95736 | p->rc = SQLITE_BUSY; |
| | @@ -97042,11 +97052,11 @@ |
| 97042 | 97052 | pOut->u.i = ~sqlite3VdbeIntValue(pIn1); |
| 97043 | 97053 | } |
| 97044 | 97054 | break; |
| 97045 | 97055 | } |
| 97046 | 97056 | |
| 97047 | | -/* Opcode: Once P1 P2 * * * |
| 97057 | +/* Opcode: Once P1 P2 P3 * * |
| 97048 | 97058 | ** |
| 97049 | 97059 | ** Fall through to the next instruction the first time this opcode is |
| 97050 | 97060 | ** encountered on each invocation of the byte-code program. Jump to P2 |
| 97051 | 97061 | ** on the second and all subsequent encounters during the same invocation. |
| 97052 | 97062 | ** |
| | @@ -97058,10 +97068,16 @@ |
| 97058 | 97068 | ** |
| 97059 | 97069 | ** For subprograms, there is a bitmask in the VdbeFrame that determines |
| 97060 | 97070 | ** whether or not the jump should be taken. The bitmask is necessary |
| 97061 | 97071 | ** because the self-altering code trick does not work for recursive |
| 97062 | 97072 | ** triggers. |
| 97073 | +** |
| 97074 | +** The P3 operand is not used directly by this opcode. However P3 is |
| 97075 | +** used by the code generator as follows: If this opcode is the start |
| 97076 | +** of a subroutine and that subroutine uses a Bloom filter, then P3 will |
| 97077 | +** be the register that holds that Bloom filter. See tag-202407032019 |
| 97078 | +** in the source code for implementation details. |
| 97063 | 97079 | */ |
| 97064 | 97080 | case OP_Once: { /* jump */ |
| 97065 | 97081 | u32 iAddr; /* Address of this instruction */ |
| 97066 | 97082 | assert( p->aOp[0].opcode==OP_Init ); |
| 97067 | 97083 | if( p->pFrame ){ |
| | @@ -103551,12 +103567,12 @@ |
| 103551 | 103567 | sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc)); |
| 103552 | 103568 | } |
| 103553 | 103569 | p->rc = rc; |
| 103554 | 103570 | sqlite3SystemError(db, rc); |
| 103555 | 103571 | testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 103556 | | - sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 103557 | | - (int)(pOp - aOp), p->zSql, p->zErrMsg); |
| 103572 | + sqlite3_log(rc, "statement aborts at %d: %s; [%s]", |
| 103573 | + (int)(pOp - aOp), p->zErrMsg, p->zSql); |
| 103558 | 103574 | if( p->eVdbeState==VDBE_RUN_STATE ) sqlite3VdbeHalt(p); |
| 103559 | 103575 | if( rc==SQLITE_IOERR_NOMEM ) sqlite3OomFault(db); |
| 103560 | 103576 | if( rc==SQLITE_CORRUPT && db->autoCommit==0 ){ |
| 103561 | 103577 | db->flags |= SQLITE_CorruptRdOnly; |
| 103562 | 103578 | } |
| | @@ -114022,15 +114038,16 @@ |
| 114022 | 114038 | pCopy = sqlite3SelectDup(pParse->db, pSelect, 0); |
| 114023 | 114039 | rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest); |
| 114024 | 114040 | sqlite3SelectDelete(pParse->db, pCopy); |
| 114025 | 114041 | sqlite3DbFree(pParse->db, dest.zAffSdst); |
| 114026 | 114042 | if( addrBloom ){ |
| 114043 | + /* Remember that location of the Bloom filter in the P3 operand |
| 114044 | + ** of the OP_Once that began this subroutine. tag-202407032019 */ |
| 114027 | 114045 | sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2; |
| 114028 | 114046 | if( dest.iSDParm2==0 ){ |
| 114029 | | - sqlite3VdbeChangeToNoop(v, addrBloom); |
| 114030 | | - }else{ |
| 114031 | | - sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2; |
| 114047 | + /* If the Bloom filter won't actually be used, keep it small */ |
| 114048 | + sqlite3VdbeGetOp(v, addrBloom)->p1 = 10; |
| 114032 | 114049 | } |
| 114033 | 114050 | } |
| 114034 | 114051 | if( rc ){ |
| 114035 | 114052 | sqlite3KeyInfoUnref(pKeyInfo); |
| 114036 | 114053 | return; |
| | @@ -114473,11 +114490,11 @@ |
| 114473 | 114490 | if( destIfFalse==destIfNull ){ |
| 114474 | 114491 | /* Combine Step 3 and Step 5 into a single opcode */ |
| 114475 | 114492 | if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 114476 | 114493 | const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr); |
| 114477 | 114494 | assert( pOp->opcode==OP_Once || pParse->nErr ); |
| 114478 | | - if( pOp->opcode==OP_Once && pOp->p3>0 ){ |
| 114495 | + if( pOp->opcode==OP_Once && pOp->p3>0 ){ /* tag-202407032019 */ |
| 114479 | 114496 | assert( OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ); |
| 114480 | 114497 | sqlite3VdbeAddOp4Int(v, OP_Filter, pOp->p3, destIfFalse, |
| 114481 | 114498 | rLhs, nVector); VdbeCoverage(v); |
| 114482 | 114499 | } |
| 114483 | 114500 | } |
| | @@ -124091,11 +124108,11 @@ |
| 124091 | 124108 | */ |
| 124092 | 124109 | SQLITE_PRIVATE int sqlite3TableColumnToIndex(Index *pIdx, int iCol){ |
| 124093 | 124110 | int i; |
| 124094 | 124111 | i16 iCol16; |
| 124095 | 124112 | assert( iCol>=(-1) && iCol<=SQLITE_MAX_COLUMN ); |
| 124096 | | - assert( pIdx->nColumn<=SQLITE_MAX_COLUMN ); |
| 124113 | + assert( pIdx->nColumn<=SQLITE_MAX_COLUMN+1 ); |
| 124097 | 124114 | iCol16 = iCol; |
| 124098 | 124115 | for(i=0; i<pIdx->nColumn; i++){ |
| 124099 | 124116 | if( iCol16==pIdx->aiColumn[i] ){ |
| 124100 | 124117 | return i; |
| 124101 | 124118 | } |
| | @@ -207968,60 +207985,113 @@ |
| 207968 | 207985 | ** Growing our own isspace() routine this way is twice as fast as |
| 207969 | 207986 | ** the library isspace() function, resulting in a 7% overall performance |
| 207970 | 207987 | ** increase for the text-JSON parser. (Ubuntu14.10 gcc 4.8.4 x64 with -Os). |
| 207971 | 207988 | */ |
| 207972 | 207989 | static const char jsonIsSpace[] = { |
| 207973 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, |
| 207974 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207975 | | - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207976 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207977 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207978 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207979 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207980 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207981 | | - |
| 207982 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207983 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207984 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207985 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207986 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207987 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207988 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207989 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 207990 | +#ifdef SQLITE_ASCII |
| 207991 | +/*0 1 2 3 4 5 6 7 8 9 a b c d e f */ |
| 207992 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0 */ |
| 207993 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */ |
| 207994 | + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */ |
| 207995 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3 */ |
| 207996 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4 */ |
| 207997 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5 */ |
| 207998 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 6 */ |
| 207999 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7 */ |
| 208000 | + |
| 208001 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 8 */ |
| 208002 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */ |
| 208003 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a */ |
| 208004 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b */ |
| 208005 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c */ |
| 208006 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */ |
| 208007 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e */ |
| 208008 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f */ |
| 208009 | +#endif |
| 208010 | +#ifdef SQLITE_EBCDIC |
| 208011 | +/*0 1 2 3 4 5 6 7 8 9 a b c d e f */ |
| 208012 | + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, /* 0 */ |
| 208013 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */ |
| 208014 | + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */ |
| 208015 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3 */ |
| 208016 | + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4 */ |
| 208017 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5 */ |
| 208018 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 6 */ |
| 208019 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7 */ |
| 208020 | + |
| 208021 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 8 */ |
| 208022 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9 */ |
| 208023 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a */ |
| 208024 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* b */ |
| 208025 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* c */ |
| 208026 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */ |
| 208027 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* e */ |
| 208028 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* f */ |
| 208029 | +#endif |
| 208030 | + |
| 207990 | 208031 | }; |
| 207991 | 208032 | #define jsonIsspace(x) (jsonIsSpace[(unsigned char)x]) |
| 207992 | 208033 | |
| 207993 | 208034 | /* |
| 207994 | 208035 | ** The set of all space characters recognized by jsonIsspace(). |
| 207995 | 208036 | ** Useful as the second argument to strspn(). |
| 207996 | 208037 | */ |
| 208038 | +#ifdef SQLITE_ASCII |
| 207997 | 208039 | static const char jsonSpaces[] = "\011\012\015\040"; |
| 208040 | +#endif |
| 208041 | +#ifdef SQLITE_EBCDIC |
| 208042 | +static const char jsonSpaces[] = "\005\045\015\100"; |
| 208043 | +#endif |
| 208044 | + |
| 207998 | 208045 | |
| 207999 | 208046 | /* |
| 208000 | 208047 | ** Characters that are special to JSON. Control characters, |
| 208001 | 208048 | ** '"' and '\\' and '\''. Actually, '\'' is not special to |
| 208002 | 208049 | ** canonical JSON, but it is special in JSON-5, so we include |
| 208003 | 208050 | ** it in the set of special characters. |
| 208004 | 208051 | */ |
| 208005 | 208052 | static const char jsonIsOk[256] = { |
| 208006 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 208007 | | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 208008 | | - 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208009 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208010 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208011 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, |
| 208012 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208013 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208014 | | - |
| 208015 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208016 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208017 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208018 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208019 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208020 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208021 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 208022 | | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 |
| 208053 | +#ifdef SQLITE_ASCII |
| 208054 | +/*0 1 2 3 4 5 6 7 8 9 a b c d e f */ |
| 208055 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 */ |
| 208056 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */ |
| 208057 | + 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, /* 2 */ |
| 208058 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 3 */ |
| 208059 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4 */ |
| 208060 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, /* 5 */ |
| 208061 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6 */ |
| 208062 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 7 */ |
| 208063 | + |
| 208064 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 8 */ |
| 208065 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 9 */ |
| 208066 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* a */ |
| 208067 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* b */ |
| 208068 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* c */ |
| 208069 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* d */ |
| 208070 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* e */ |
| 208071 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /* f */ |
| 208072 | +#endif |
| 208073 | +#ifdef SQLITE_EBCDIC |
| 208074 | +/*0 1 2 3 4 5 6 7 8 9 a b c d e f */ |
| 208075 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 */ |
| 208076 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1 */ |
| 208077 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2 */ |
| 208078 | + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, /* 3 */ |
| 208079 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4 */ |
| 208080 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 5 */ |
| 208081 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6 */ |
| 208082 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, /* 7 */ |
| 208083 | + |
| 208084 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 8 */ |
| 208085 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 9 */ |
| 208086 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* a */ |
| 208087 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* b */ |
| 208088 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* c */ |
| 208089 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* d */ |
| 208090 | + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* e */ |
| 208091 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /* f */ |
| 208092 | +#endif |
| 208023 | 208093 | }; |
| 208024 | 208094 | |
| 208025 | 208095 | /* Objects */ |
| 208026 | 208096 | typedef struct JsonCache JsonCache; |
| 208027 | 208097 | typedef struct JsonString JsonString; |
| | @@ -208162,11 +208232,11 @@ |
| 208162 | 208232 | |
| 208163 | 208233 | /************************************************************************** |
| 208164 | 208234 | ** Forward references |
| 208165 | 208235 | **************************************************************************/ |
| 208166 | 208236 | static void jsonReturnStringAsBlob(JsonString*); |
| 208167 | | -static int jsonFuncArgMightBeBinary(sqlite3_value *pJson); |
| 208237 | +static int jsonArgIsJsonb(sqlite3_value *pJson, JsonParse *p); |
| 208168 | 208238 | static u32 jsonTranslateBlobToText(const JsonParse*,u32,JsonString*); |
| 208169 | 208239 | static void jsonReturnParse(sqlite3_context*,JsonParse*); |
| 208170 | 208240 | static JsonParse *jsonParseFuncArg(sqlite3_context*,sqlite3_value*,u32); |
| 208171 | 208241 | static void jsonParseFree(JsonParse*); |
| 208172 | 208242 | static u32 jsonbPayloadSize(const JsonParse*, u32, u32*); |
| | @@ -208580,15 +208650,13 @@ |
| 208580 | 208650 | jsonAppendString(p, z, n); |
| 208581 | 208651 | } |
| 208582 | 208652 | break; |
| 208583 | 208653 | } |
| 208584 | 208654 | default: { |
| 208585 | | - if( jsonFuncArgMightBeBinary(pValue) ){ |
| 208586 | | - JsonParse px; |
| 208587 | | - memset(&px, 0, sizeof(px)); |
| 208588 | | - px.aBlob = (u8*)sqlite3_value_blob(pValue); |
| 208589 | | - px.nBlob = sqlite3_value_bytes(pValue); |
| 208655 | + JsonParse px; |
| 208656 | + memset(&px, 0, sizeof(px)); |
| 208657 | + if( jsonArgIsJsonb(pValue, &px) ){ |
| 208590 | 208658 | jsonTranslateBlobToText(&px, 0, p); |
| 208591 | 208659 | }else if( p->eErr==0 ){ |
| 208592 | 208660 | sqlite3_result_error(p->pCtx, "JSON cannot hold BLOB values", -1); |
| 208593 | 208661 | p->eErr = JSTRING_ERR; |
| 208594 | 208662 | jsonStringReset(p); |
| | @@ -210258,37 +210326,10 @@ |
| 210258 | 210326 | } |
| 210259 | 210327 | } |
| 210260 | 210328 | return i; |
| 210261 | 210329 | } |
| 210262 | 210330 | |
| 210263 | | - |
| 210264 | | -/* Return true if the input pJson |
| 210265 | | -** |
| 210266 | | -** For performance reasons, this routine does not do a detailed check of the |
| 210267 | | -** input BLOB to ensure that it is well-formed. Hence, false positives are |
| 210268 | | -** possible. False negatives should never occur, however. |
| 210269 | | -*/ |
| 210270 | | -static int jsonFuncArgMightBeBinary(sqlite3_value *pJson){ |
| 210271 | | - u32 sz, n; |
| 210272 | | - const u8 *aBlob; |
| 210273 | | - int nBlob; |
| 210274 | | - JsonParse s; |
| 210275 | | - if( sqlite3_value_type(pJson)!=SQLITE_BLOB ) return 0; |
| 210276 | | - aBlob = sqlite3_value_blob(pJson); |
| 210277 | | - nBlob = sqlite3_value_bytes(pJson); |
| 210278 | | - if( nBlob<1 ) return 0; |
| 210279 | | - if( NEVER(aBlob==0) || (aBlob[0] & 0x0f)>JSONB_OBJECT ) return 0; |
| 210280 | | - memset(&s, 0, sizeof(s)); |
| 210281 | | - s.aBlob = (u8*)aBlob; |
| 210282 | | - s.nBlob = nBlob; |
| 210283 | | - n = jsonbPayloadSize(&s, 0, &sz); |
| 210284 | | - if( n==0 ) return 0; |
| 210285 | | - if( sz+n!=(u32)nBlob ) return 0; |
| 210286 | | - if( (aBlob[0] & 0x0f)<=JSONB_FALSE && sz>0 ) return 0; |
| 210287 | | - return sz+n==(u32)nBlob; |
| 210288 | | -} |
| 210289 | | - |
| 210290 | 210331 | /* |
| 210291 | 210332 | ** Given that a JSONB_ARRAY object starts at offset i, return |
| 210292 | 210333 | ** the number of entries in that array. |
| 210293 | 210334 | */ |
| 210294 | 210335 | static u32 jsonbArrayCount(JsonParse *pParse, u32 iRoot){ |
| | @@ -211112,14 +211153,11 @@ |
| 211112 | 211153 | pParse->aBlob = aNull; |
| 211113 | 211154 | pParse->nBlob = 1; |
| 211114 | 211155 | return 0; |
| 211115 | 211156 | } |
| 211116 | 211157 | case SQLITE_BLOB: { |
| 211117 | | - if( jsonFuncArgMightBeBinary(pArg) ){ |
| 211118 | | - pParse->aBlob = (u8*)sqlite3_value_blob(pArg); |
| 211119 | | - pParse->nBlob = sqlite3_value_bytes(pArg); |
| 211120 | | - }else{ |
| 211158 | + if( !jsonArgIsJsonb(pArg, pParse) ){ |
| 211121 | 211159 | sqlite3_result_error(ctx, "JSON cannot hold BLOB values", -1); |
| 211122 | 211160 | return 1; |
| 211123 | 211161 | } |
| 211124 | 211162 | break; |
| 211125 | 211163 | } |
| | @@ -211266,31 +211304,50 @@ |
| 211266 | 211304 | } |
| 211267 | 211305 | |
| 211268 | 211306 | /* |
| 211269 | 211307 | ** If pArg is a blob that seems like a JSONB blob, then initialize |
| 211270 | 211308 | ** p to point to that JSONB and return TRUE. If pArg does not seem like |
| 211271 | | -** a JSONB blob, then return FALSE; |
| 211309 | +** a JSONB blob, then return FALSE. |
| 211272 | 211310 | ** |
| 211273 | | -** This routine is only called if it is already known that pArg is a |
| 211274 | | -** blob. The only open question is whether or not the blob appears |
| 211275 | | -** to be a JSONB blob. |
| 211311 | +** For small BLOBs (having no more than 7 bytes of payload) a full |
| 211312 | +** validity check is done. So for small BLOBs this routine only returns |
| 211313 | +** true if the value is guaranteed to be a valid JSONB. For larger BLOBs |
| 211314 | +** (8 byte or more of payload) only the size of the outermost element is |
| 211315 | +** checked to verify that the BLOB is superficially valid JSONB. |
| 211316 | +** |
| 211317 | +** A full JSONB validation is done on smaller BLOBs because those BLOBs might |
| 211318 | +** also be text JSON that has been incorrectly cast into a BLOB. |
| 211319 | +** (See tag-20240123-a and https://sqlite.org/forum/forumpost/012136abd5) |
| 211320 | +** If the BLOB is 9 bytes are larger, then it is not possible for the |
| 211321 | +** superficial size check done here to pass if the input is really text |
| 211322 | +** JSON so we do not need to look deeper in that case. |
| 211323 | +** |
| 211324 | +** Why we only need to do full JSONB validation for smaller BLOBs: |
| 211325 | +** |
| 211326 | +** The first byte of valid JSON text must be one of: '{', '[', '"', ' ', '\n', |
| 211327 | +** '\r', '\t', '-', or a digit '0' through '9'. Of these, only a subset |
| 211328 | +** can also be the first byte of JSONB: '{', '[', and digits '3' |
| 211329 | +** through '9'. In every one of those cases, the payload size is 7 bytes |
| 211330 | +** or less. So if we do full JSONB validation for every BLOB where the |
| 211331 | +** payload is less than 7 bytes, we will never get a false positive for |
| 211332 | +** JSONB on an input that is really text JSON. |
| 211276 | 211333 | */ |
| 211277 | 211334 | static int jsonArgIsJsonb(sqlite3_value *pArg, JsonParse *p){ |
| 211278 | 211335 | u32 n, sz = 0; |
| 211336 | + u8 c; |
| 211337 | + if( sqlite3_value_type(pArg)!=SQLITE_BLOB ) return 0; |
| 211279 | 211338 | p->aBlob = (u8*)sqlite3_value_blob(pArg); |
| 211280 | 211339 | p->nBlob = (u32)sqlite3_value_bytes(pArg); |
| 211281 | | - if( p->nBlob==0 ){ |
| 211282 | | - p->aBlob = 0; |
| 211283 | | - return 0; |
| 211284 | | - } |
| 211285 | | - if( NEVER(p->aBlob==0) ){ |
| 211286 | | - return 0; |
| 211287 | | - } |
| 211288 | | - if( (p->aBlob[0] & 0x0f)<=JSONB_OBJECT |
| 211340 | + if( p->nBlob>0 |
| 211341 | + && ALWAYS(p->aBlob!=0) |
| 211342 | + && ((c = p->aBlob[0]) & 0x0f)<=JSONB_OBJECT |
| 211289 | 211343 | && (n = jsonbPayloadSize(p, 0, &sz))>0 |
| 211290 | 211344 | && sz+n==p->nBlob |
| 211291 | | - && ((p->aBlob[0] & 0x0f)>JSONB_FALSE || sz==0) |
| 211345 | + && ((c & 0x0f)>JSONB_FALSE || sz==0) |
| 211346 | + && (sz>7 |
| 211347 | + || (c!=0x7b && c!=0x5b && !sqlite3Isdigit(c)) |
| 211348 | + || jsonbValidityCheck(p, 0, p->nBlob, 1)==0) |
| 211292 | 211349 | ){ |
| 211293 | 211350 | return 1; |
| 211294 | 211351 | } |
| 211295 | 211352 | p->aBlob = 0; |
| 211296 | 211353 | p->nBlob = 0; |
| | @@ -212379,25 +212436,21 @@ |
| 212379 | 212436 | sqlite3_result_int(ctx, 0); |
| 212380 | 212437 | #endif |
| 212381 | 212438 | return; |
| 212382 | 212439 | } |
| 212383 | 212440 | case SQLITE_BLOB: { |
| 212384 | | - if( jsonFuncArgMightBeBinary(argv[0]) ){ |
| 212441 | + JsonParse py; |
| 212442 | + memset(&py, 0, sizeof(py)); |
| 212443 | + if( jsonArgIsJsonb(argv[0], &py) ){ |
| 212385 | 212444 | if( flags & 0x04 ){ |
| 212386 | 212445 | /* Superficial checking only - accomplished by the |
| 212387 | | - ** jsonFuncArgMightBeBinary() call above. */ |
| 212446 | + ** jsonArgIsJsonb() call above. */ |
| 212388 | 212447 | res = 1; |
| 212389 | 212448 | }else if( flags & 0x08 ){ |
| 212390 | 212449 | /* Strict checking. Check by translating BLOB->TEXT->BLOB. If |
| 212391 | 212450 | ** no errors occur, call that a "strict check". */ |
| 212392 | | - JsonParse px; |
| 212393 | | - u32 iErr; |
| 212394 | | - memset(&px, 0, sizeof(px)); |
| 212395 | | - px.aBlob = (u8*)sqlite3_value_blob(argv[0]); |
| 212396 | | - px.nBlob = sqlite3_value_bytes(argv[0]); |
| 212397 | | - iErr = jsonbValidityCheck(&px, 0, px.nBlob, 1); |
| 212398 | | - res = iErr==0; |
| 212451 | + res = 0==jsonbValidityCheck(&py, 0, py.nBlob, 1); |
| 212399 | 212452 | } |
| 212400 | 212453 | break; |
| 212401 | 212454 | } |
| 212402 | 212455 | /* Fall through into interpreting the input as text. See note |
| 212403 | 212456 | ** above at tag-20240123-a. */ |
| | @@ -212451,13 +212504,11 @@ |
| 212451 | 212504 | |
| 212452 | 212505 | assert( argc==1 ); |
| 212453 | 212506 | UNUSED_PARAMETER(argc); |
| 212454 | 212507 | memset(&s, 0, sizeof(s)); |
| 212455 | 212508 | s.db = sqlite3_context_db_handle(ctx); |
| 212456 | | - if( jsonFuncArgMightBeBinary(argv[0]) ){ |
| 212457 | | - s.aBlob = (u8*)sqlite3_value_blob(argv[0]); |
| 212458 | | - s.nBlob = sqlite3_value_bytes(argv[0]); |
| 212509 | + if( jsonArgIsJsonb(argv[0], &s) ){ |
| 212459 | 212510 | iErrPos = (i64)jsonbValidityCheck(&s, 0, s.nBlob, 1); |
| 212460 | 212511 | }else{ |
| 212461 | 212512 | s.zJson = (char*)sqlite3_value_text(argv[0]); |
| 212462 | 212513 | if( s.zJson==0 ) return; /* NULL input or OOM */ |
| 212463 | 212514 | s.nJson = sqlite3_value_bytes(argv[0]); |
| | @@ -213138,13 +213189,12 @@ |
| 213138 | 213189 | jsonEachCursorReset(p); |
| 213139 | 213190 | if( idxNum==0 ) return SQLITE_OK; |
| 213140 | 213191 | memset(&p->sParse, 0, sizeof(p->sParse)); |
| 213141 | 213192 | p->sParse.nJPRef = 1; |
| 213142 | 213193 | p->sParse.db = p->db; |
| 213143 | | - if( jsonFuncArgMightBeBinary(argv[0]) ){ |
| 213144 | | - p->sParse.nBlob = sqlite3_value_bytes(argv[0]); |
| 213145 | | - p->sParse.aBlob = (u8*)sqlite3_value_blob(argv[0]); |
| 213194 | + if( jsonArgIsJsonb(argv[0], &p->sParse) ){ |
| 213195 | + /* We have JSONB */ |
| 213146 | 213196 | }else{ |
| 213147 | 213197 | p->sParse.zJson = (char*)sqlite3_value_text(argv[0]); |
| 213148 | 213198 | p->sParse.nJson = sqlite3_value_bytes(argv[0]); |
| 213149 | 213199 | if( p->sParse.zJson==0 ){ |
| 213150 | 213200 | p->i = p->iEnd = 0; |
| | @@ -257213,11 +257263,11 @@ |
| 257213 | 257263 | int nArg, /* Number of args */ |
| 257214 | 257264 | sqlite3_value **apUnused /* Function arguments */ |
| 257215 | 257265 | ){ |
| 257216 | 257266 | assert( nArg==0 ); |
| 257217 | 257267 | UNUSED_PARAM2(nArg, apUnused); |
| 257218 | | - sqlite3_result_text(pCtx, "fts5: 2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5", -1, SQLITE_TRANSIENT); |
| 257268 | + sqlite3_result_text(pCtx, "fts5: 2025-04-30 14:37:00 20abf1ec107f942e4527901685d61283c9c2fe7bcefad63dbf5c6cbf050da849", -1, SQLITE_TRANSIENT); |
| 257219 | 257269 | } |
| 257220 | 257270 | |
| 257221 | 257271 | /* |
| 257222 | 257272 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 257223 | 257273 | ** |
| 257224 | 257274 | |