| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.41.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3041000 |
| 457 | | -#define SQLITE_SOURCE_ID "2022-12-29 18:54:15 eed1e030722deb24674e7c2d165a2a359576c6bb5769d3bdd5fa645bc0f2ecc7" |
| 457 | +#define SQLITE_SOURCE_ID "2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -2983,12 +2983,16 @@ |
| 2983 | 2983 | ** that are started after the running statement count reaches zero are |
| 2984 | 2984 | ** not effected by the sqlite3_interrupt(). |
| 2985 | 2985 | ** ^A call to sqlite3_interrupt(D) that occurs when there are no running |
| 2986 | 2986 | ** SQL statements is a no-op and has no effect on SQL statements |
| 2987 | 2987 | ** that are started after the sqlite3_interrupt() call returns. |
| 2988 | +** |
| 2989 | +** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
| 2990 | +** or not an interrupt is currently in effect for [database connection] D. |
| 2988 | 2991 | */ |
| 2989 | 2992 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 2993 | +SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
| 2990 | 2994 | |
| 2991 | 2995 | /* |
| 2992 | 2996 | ** CAPI3REF: Determine If An SQL Statement Is Complete |
| 2993 | 2997 | ** |
| 2994 | 2998 | ** These routines are useful during command-line input to determine if the |
| | @@ -3666,11 +3670,11 @@ |
| 3666 | 3670 | ** CAPI3REF: Query Progress Callbacks |
| 3667 | 3671 | ** METHOD: sqlite3 |
| 3668 | 3672 | ** |
| 3669 | 3673 | ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback |
| 3670 | 3674 | ** function X to be invoked periodically during long running calls to |
| 3671 | | -** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for |
| 3675 | +** [sqlite3_step()] and [sqlite3_prepare()] and similar for |
| 3672 | 3676 | ** database connection D. An example use for this |
| 3673 | 3677 | ** interface is to keep a GUI updated during a large query. |
| 3674 | 3678 | ** |
| 3675 | 3679 | ** ^The parameter P is passed through as the only parameter to the |
| 3676 | 3680 | ** callback function X. ^The parameter N is the approximate number of |
| | @@ -3691,10 +3695,17 @@ |
| 3691 | 3695 | ** The progress handler callback must not do anything that will modify |
| 3692 | 3696 | ** the database connection that invoked the progress handler. |
| 3693 | 3697 | ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their |
| 3694 | 3698 | ** database connections for the meaning of "modify" in this paragraph. |
| 3695 | 3699 | ** |
| 3700 | +** The progress handler callback would originally only be invoked from the |
| 3701 | +** bytecode engine. It still might be invoked during [sqlite3_prepare()] |
| 3702 | +** and similar because those routines might force a reparse of the schema |
| 3703 | +** which involves running the bytecode engine. However, beginning with |
| 3704 | +** SQLite version 3.41.0, the progress handler callback might also be |
| 3705 | +** invoked directly from [sqlite3_prepare()] while analyzing and generating |
| 3706 | +** code for complex queries. |
| 3696 | 3707 | */ |
| 3697 | 3708 | SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); |
| 3698 | 3709 | |
| 3699 | 3710 | /* |
| 3700 | 3711 | ** CAPI3REF: Opening A New Database Connection |
| | @@ -3727,17 +3738,22 @@ |
| 3727 | 3738 | ** sqlite3_open_v2() must include, at a minimum, one of the following |
| 3728 | 3739 | ** three flag combinations:)^ |
| 3729 | 3740 | ** |
| 3730 | 3741 | ** <dl> |
| 3731 | 3742 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 3732 | | -** <dd>The database is opened in read-only mode. If the database does not |
| 3733 | | -** already exist, an error is returned.</dd>)^ |
| 3743 | +** <dd>The database is opened in read-only mode. If the database does |
| 3744 | +** not already exist, an error is returned.</dd>)^ |
| 3734 | 3745 | ** |
| 3735 | 3746 | ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> |
| 3736 | | -** <dd>The database is opened for reading and writing if possible, or reading |
| 3737 | | -** only if the file is write protected by the operating system. In either |
| 3738 | | -** case the database must already exist, otherwise an error is returned.</dd>)^ |
| 3747 | +** <dd>The database is opened for reading and writing if possible, or |
| 3748 | +** reading only if the file is write protected by the operating |
| 3749 | +** system. In either case the database must already exist, otherwise |
| 3750 | +** an error is returned. For historical reasons, if opening in |
| 3751 | +** read-write mode fails due to OS-level permissions, an attempt is |
| 3752 | +** made to open it in read-only mode. [sqlite3_db_readonly()] can be |
| 3753 | +** used to determine whether the database is actually |
| 3754 | +** read-write.</dd>)^ |
| 3739 | 3755 | ** |
| 3740 | 3756 | ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> |
| 3741 | 3757 | ** <dd>The database is opened for reading and writing, and is created if |
| 3742 | 3758 | ** it does not already exist. This is the behavior that is always used for |
| 3743 | 3759 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| | @@ -5714,14 +5730,25 @@ |
| 5714 | 5730 | ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd> |
| 5715 | 5731 | ** The SQLITE_DIRECTONLY flag means that the function may only be invoked |
| 5716 | 5732 | ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in |
| 5717 | 5733 | ** schema structures such as [CHECK constraints], [DEFAULT clauses], |
| 5718 | 5734 | ** [expression indexes], [partial indexes], or [generated columns]. |
| 5719 | | -** The SQLITE_DIRECTONLY flags is a security feature which is recommended |
| 5720 | | -** for all [application-defined SQL functions], and especially for functions |
| 5721 | | -** that have side-effects or that could potentially leak sensitive |
| 5722 | | -** information. |
| 5735 | +** <p> |
| 5736 | +** The SQLITE_DIRECTONLY flag is recommended for any |
| 5737 | +** [application-defined SQL function] |
| 5738 | +** that has side-effects or that could potentially leak sensitive information. |
| 5739 | +** This will prevent attacks in which an application is tricked |
| 5740 | +** into using a database file that has had its schema surreptiously |
| 5741 | +** modified to invoke the application-defined function in ways that are |
| 5742 | +** harmful. |
| 5743 | +** <p> |
| 5744 | +** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
| 5745 | +** [application-defined SQL functions], regardless of whether or not they |
| 5746 | +** are security sensitive, as doing so prevents those functions from being used |
| 5747 | +** inside of the database schema, and thus ensures that the database |
| 5748 | +** can be inspected and modified using generic tools (such as the [CLI]) |
| 5749 | +** that do not have access to the application-defined functions. |
| 5723 | 5750 | ** </dd> |
| 5724 | 5751 | ** |
| 5725 | 5752 | ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd> |
| 5726 | 5753 | ** The SQLITE_INNOCUOUS flag means that the function is unlikely |
| 5727 | 5754 | ** to cause problems even if misused. An innocuous function should have |
| | @@ -7441,14 +7468,14 @@ |
| 7441 | 7468 | ** checked separately in byte code. If the omit flag is change to true, then |
| 7442 | 7469 | ** the constraint may or may not be checked in byte code. In other words, |
| 7443 | 7470 | ** when the omit flag is true there is no guarantee that the constraint will |
| 7444 | 7471 | ** not be checked again using byte code.)^ |
| 7445 | 7472 | ** |
| 7446 | | -** ^The idxNum and idxPtr values are recorded and passed into the |
| 7473 | +** ^The idxNum and idxStr values are recorded and passed into the |
| 7447 | 7474 | ** [xFilter] method. |
| 7448 | | -** ^[sqlite3_free()] is used to free idxPtr if and only if |
| 7449 | | -** needToFreeIdxPtr is true. |
| 7475 | +** ^[sqlite3_free()] is used to free idxStr if and only if |
| 7476 | +** needToFreeIdxStr is true. |
| 7450 | 7477 | ** |
| 7451 | 7478 | ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in |
| 7452 | 7479 | ** the correct order to satisfy the ORDER BY clause so that no separate |
| 7453 | 7480 | ** sorting step is required. |
| 7454 | 7481 | ** |
| | @@ -10400,10 +10427,14 @@ |
| 10400 | 10427 | ** parameter is undefined. For an INSERT or UPDATE on a rowid table the |
| 10401 | 10428 | ** seventh parameter is the final rowid value of the row being inserted |
| 10402 | 10429 | ** or updated. The value of the seventh parameter passed to the callback |
| 10403 | 10430 | ** function is not defined for operations on WITHOUT ROWID tables, or for |
| 10404 | 10431 | ** DELETE operations on rowid tables. |
| 10432 | +** |
| 10433 | +** ^The sqlite3_update_hook(D,C,P) function returns the P argument from |
| 10434 | +** the previous call on the same [database connection] D, or NULL for |
| 10435 | +** the first call on D. |
| 10405 | 10436 | ** |
| 10406 | 10437 | ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 10407 | 10438 | ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 10408 | 10439 | ** provide additional information about a preupdate event. These routines |
| 10409 | 10440 | ** may only be called from within a preupdate callback. Invoking any of |
| | @@ -15767,11 +15798,19 @@ |
| 15767 | 15798 | SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); |
| 15768 | 15799 | SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); |
| 15769 | 15800 | SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*); |
| 15770 | 15801 | SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*); |
| 15771 | 15802 | |
| 15772 | | -SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,Pgno*aRoot,int nRoot,int,int*); |
| 15803 | +SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck( |
| 15804 | + sqlite3 *db, /* Database connection that is running the check */ |
| 15805 | + Btree *p, /* The btree to be checked */ |
| 15806 | + Pgno *aRoot, /* An array of root pages numbers for individual trees */ |
| 15807 | + int nRoot, /* Number of entries in aRoot[] */ |
| 15808 | + int mxErr, /* Stop reporting errors after this many */ |
| 15809 | + int *pnErr, /* OUT: Write number of errors seen to this variable */ |
| 15810 | + char **pzOut /* OUT: Write the error message string here */ |
| 15811 | +); |
| 15773 | 15812 | SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); |
| 15774 | 15813 | SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*); |
| 15775 | 15814 | |
| 15776 | 15815 | #ifndef SQLITE_OMIT_INCRBLOB |
| 15777 | 15816 | SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*); |
| | @@ -17373,12 +17412,18 @@ |
| 17373 | 17412 | ** SQLITE_FUNC_ANYORDER == NC_OrderAgg == SF_OrderByReqd |
| 17374 | 17413 | ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG |
| 17375 | 17414 | ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG |
| 17376 | 17415 | ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API |
| 17377 | 17416 | ** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API |
| 17378 | | -** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS |
| 17417 | +** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!! |
| 17379 | 17418 | ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 17419 | +** |
| 17420 | +** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the |
| 17421 | +** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is |
| 17422 | +** used internally and if set means tha the function has side effects. |
| 17423 | +** SQLITE_INNOCUOUS is used by application code and means "not unsafe". |
| 17424 | +** See multiple instances of tag-20230109-1. |
| 17380 | 17425 | */ |
| 17381 | 17426 | #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 17382 | 17427 | #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| 17383 | 17428 | #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ |
| 17384 | 17429 | #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ |
| | @@ -17491,11 +17536,11 @@ |
| 17491 | 17536 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 17492 | 17537 | #define MFUNCTION(zName, nArg, xPtr, xFunc) \ |
| 17493 | 17538 | {nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ |
| 17494 | 17539 | xPtr, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 17495 | 17540 | #define JFUNCTION(zName, nArg, iArg, xFunc) \ |
| 17496 | | - {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|\ |
| 17541 | + {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|\ |
| 17497 | 17542 | SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \ |
| 17498 | 17543 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 17499 | 17544 | #define INLINE_FUNC(zName, nArg, iArg, mFlags) \ |
| 17500 | 17545 | {nArg, SQLITE_FUNC_BUILTIN|\ |
| 17501 | 17546 | SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ |
| | @@ -19192,10 +19237,13 @@ |
| 19192 | 19237 | Returning *pReturning; /* The RETURNING clause */ |
| 19193 | 19238 | } u1; |
| 19194 | 19239 | u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| 19195 | 19240 | u32 oldmask; /* Mask of old.* columns referenced */ |
| 19196 | 19241 | u32 newmask; /* Mask of new.* columns referenced */ |
| 19242 | +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 19243 | + u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */ |
| 19244 | +#endif |
| 19197 | 19245 | u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 19198 | 19246 | u8 bReturning; /* Coding a RETURNING trigger */ |
| 19199 | 19247 | u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ |
| 19200 | 19248 | u8 disableTriggers; /* True to disable triggers */ |
| 19201 | 19249 | |
| | @@ -19940,17 +19988,15 @@ |
| 19940 | 19988 | ** that deal with sqlite3StackAlloc() failures to be unreachable. |
| 19941 | 19989 | */ |
| 19942 | 19990 | #ifdef SQLITE_USE_ALLOCA |
| 19943 | 19991 | # define sqlite3StackAllocRaw(D,N) alloca(N) |
| 19944 | 19992 | # define sqlite3StackAllocRawNN(D,N) alloca(N) |
| 19945 | | -# define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N) |
| 19946 | 19993 | # define sqlite3StackFree(D,P) |
| 19947 | 19994 | # define sqlite3StackFreeNN(D,P) |
| 19948 | 19995 | #else |
| 19949 | 19996 | # define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N) |
| 19950 | 19997 | # define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N) |
| 19951 | | -# define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N) |
| 19952 | 19998 | # define sqlite3StackFree(D,P) sqlite3DbFree(D,P) |
| 19953 | 19999 | # define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P) |
| 19954 | 20000 | #endif |
| 19955 | 20001 | |
| 19956 | 20002 | /* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they |
| | @@ -20071,10 +20117,11 @@ |
| 20071 | 20117 | SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*); |
| 20072 | 20118 | #endif |
| 20073 | 20119 | #endif |
| 20074 | 20120 | |
| 20075 | 20121 | SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); |
| 20122 | +SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*); |
| 20076 | 20123 | SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); |
| 20077 | 20124 | SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int); |
| 20078 | 20125 | SQLITE_PRIVATE void sqlite3Dequote(char*); |
| 20079 | 20126 | SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*); |
| 20080 | 20127 | SQLITE_PRIVATE void sqlite3DequoteToken(Token*); |
| | @@ -20448,11 +20495,11 @@ |
| 20448 | 20495 | SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*); |
| 20449 | 20496 | SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*); |
| 20450 | 20497 | SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); |
| 20451 | 20498 | SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64); |
| 20452 | 20499 | SQLITE_PRIVATE i64 sqlite3RealToI64(double); |
| 20453 | | -SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*); |
| 20500 | +SQLITE_PRIVATE int sqlite3Int64ToText(i64,char*); |
| 20454 | 20501 | SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8); |
| 20455 | 20502 | SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*); |
| 20456 | 20503 | SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*); |
| 20457 | 20504 | SQLITE_PRIVATE int sqlite3Atoi(const char*); |
| 20458 | 20505 | #ifndef SQLITE_OMIT_UTF16 |
| | @@ -33722,10 +33769,30 @@ |
| 33722 | 33769 | z = sqlite3VMPrintf(db, zFormat, ap); |
| 33723 | 33770 | va_end(ap); |
| 33724 | 33771 | sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC); |
| 33725 | 33772 | } |
| 33726 | 33773 | } |
| 33774 | + |
| 33775 | +/* |
| 33776 | +** Check for interrupts and invoke progress callback. |
| 33777 | +*/ |
| 33778 | +SQLITE_PRIVATE void sqlite3ProgressCheck(Parse *p){ |
| 33779 | + sqlite3 *db = p->db; |
| 33780 | + if( AtomicLoad(&db->u1.isInterrupted) ){ |
| 33781 | + p->nErr++; |
| 33782 | + p->rc = SQLITE_INTERRUPT; |
| 33783 | + } |
| 33784 | +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 33785 | + if( db->xProgress && (++p->nProgressSteps)>=db->nProgressOps ){ |
| 33786 | + if( db->xProgress(db->pProgressArg) ){ |
| 33787 | + p->nErr++; |
| 33788 | + p->rc = SQLITE_INTERRUPT; |
| 33789 | + } |
| 33790 | + p->nProgressSteps = 0; |
| 33791 | + } |
| 33792 | +#endif |
| 33793 | +} |
| 33727 | 33794 | |
| 33728 | 33795 | /* |
| 33729 | 33796 | ** Add an error message to pParse->zErrMsg and increment pParse->nErr. |
| 33730 | 33797 | ** |
| 33731 | 33798 | ** This function should be used to report any error that occurs while |
| | @@ -34180,15 +34247,18 @@ |
| 34180 | 34247 | #if defined(_MSC_VER) |
| 34181 | 34248 | #pragma warning(default : 4756) |
| 34182 | 34249 | #endif |
| 34183 | 34250 | |
| 34184 | 34251 | /* |
| 34185 | | -** Render an signed 64-bit integer as text. Store the result in zOut[]. |
| 34252 | +** Render an signed 64-bit integer as text. Store the result in zOut[] and |
| 34253 | +** return the length of the string that was stored, in bytes. The value |
| 34254 | +** returned does not include the zero terminator at the end of the output |
| 34255 | +** string. |
| 34186 | 34256 | ** |
| 34187 | 34257 | ** The caller must ensure that zOut[] is at least 21 bytes in size. |
| 34188 | 34258 | */ |
| 34189 | | -SQLITE_PRIVATE void sqlite3Int64ToText(i64 v, char *zOut){ |
| 34259 | +SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){ |
| 34190 | 34260 | int i; |
| 34191 | 34261 | u64 x; |
| 34192 | 34262 | char zTemp[22]; |
| 34193 | 34263 | if( v<0 ){ |
| 34194 | 34264 | x = (v==SMALLEST_INT64) ? ((u64)1)<<63 : (u64)-v; |
| | @@ -34201,10 +34271,11 @@ |
| 34201 | 34271 | zTemp[i--] = (x%10) + '0'; |
| 34202 | 34272 | x = x/10; |
| 34203 | 34273 | }while( x ); |
| 34204 | 34274 | if( v<0 ) zTemp[i--] = '-'; |
| 34205 | 34275 | memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i); |
| 34276 | + return sizeof(zTemp)-2-i; |
| 34206 | 34277 | } |
| 34207 | 34278 | |
| 34208 | 34279 | /* |
| 34209 | 34280 | ** Compare the 19-character string zNum against the text representation |
| 34210 | 34281 | ** value 2^63: 9223372036854775808. Return negative, zero, or positive |
| | @@ -35530,16 +35601,17 @@ |
| 35530 | 35601 | h = 0; |
| 35531 | 35602 | elem = pH->first; |
| 35532 | 35603 | count = pH->count; |
| 35533 | 35604 | } |
| 35534 | 35605 | if( pHash ) *pHash = h; |
| 35535 | | - while( count-- ){ |
| 35606 | + while( count ){ |
| 35536 | 35607 | assert( elem!=0 ); |
| 35537 | 35608 | if( sqlite3StrICmp(elem->pKey,pKey)==0 ){ |
| 35538 | 35609 | return elem; |
| 35539 | 35610 | } |
| 35540 | 35611 | elem = elem->next; |
| 35612 | + count--; |
| 35541 | 35613 | } |
| 35542 | 35614 | return &nullElement; |
| 35543 | 35615 | } |
| 35544 | 35616 | |
| 35545 | 35617 | /* Remove a single entry from the hash table given a pointer to that |
| | @@ -36259,12 +36331,11 @@ |
| 36259 | 36331 | c = aIn[++i]; |
| 36260 | 36332 | } |
| 36261 | 36333 | if( j+n>nOut ) return -1; |
| 36262 | 36334 | memset(&aOut[j], 0, n); |
| 36263 | 36335 | j += n; |
| 36264 | | - c = aIn[i]; |
| 36265 | | - if( c==0 ) break; |
| 36336 | + if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */ |
| 36266 | 36337 | }else{ |
| 36267 | 36338 | aOut[j] = c<<4; |
| 36268 | 36339 | c = kvvfsHexValue[aIn[++i]]; |
| 36269 | 36340 | if( c<0 ) break; |
| 36270 | 36341 | aOut[j++] += c; |
| | @@ -43287,16 +43358,14 @@ |
| 43287 | 43358 | assert( nName>0 ); |
| 43288 | 43359 | assert( zName!=0 ); |
| 43289 | 43360 | if( zName[0]=='.' ){ |
| 43290 | 43361 | if( nName==1 ) return; |
| 43291 | 43362 | if( zName[1]=='.' && nName==2 ){ |
| 43292 | | - if( pPath->nUsed<=1 ){ |
| 43293 | | - pPath->rc = SQLITE_ERROR; |
| 43294 | | - return; |
| 43363 | + if( pPath->nUsed>1 ){ |
| 43364 | + assert( pPath->zOut[0]=='/' ); |
| 43365 | + while( pPath->zOut[--pPath->nUsed]!='/' ){} |
| 43295 | 43366 | } |
| 43296 | | - assert( pPath->zOut[0]=='/' ); |
| 43297 | | - while( pPath->zOut[--pPath->nUsed]!='/' ){} |
| 43298 | 43367 | return; |
| 43299 | 43368 | } |
| 43300 | 43369 | } |
| 43301 | 43370 | if( pPath->nUsed + nName + 2 >= pPath->nOut ){ |
| 43302 | 43371 | pPath->rc = SQLITE_ERROR; |
| | @@ -67958,12 +68027,12 @@ |
| 67958 | 68027 | #define ISAUTOVACUUM(pBt) 0 |
| 67959 | 68028 | #endif |
| 67960 | 68029 | |
| 67961 | 68030 | |
| 67962 | 68031 | /* |
| 67963 | | -** This structure is passed around through all the sanity checking routines |
| 67964 | | -** in order to keep track of some global state information. |
| 68032 | +** This structure is passed around through all the PRAGMA integrity_check |
| 68033 | +** checking routines in order to keep track of some global state information. |
| 67965 | 68034 | ** |
| 67966 | 68035 | ** The aRef[] array is allocated so that there is 1 bit for each page in |
| 67967 | 68036 | ** the database. As the integrity-check proceeds, for each page used in |
| 67968 | 68037 | ** the database the corresponding bit is set. This allows integrity-check to |
| 67969 | 68038 | ** detect pages that are used twice and orphaned pages (both of which |
| | @@ -67975,11 +68044,12 @@ |
| 67975 | 68044 | Pager *pPager; /* The associated pager. Also accessible by pBt->pPager */ |
| 67976 | 68045 | u8 *aPgRef; /* 1 bit per page in the db (see above) */ |
| 67977 | 68046 | Pgno nPage; /* Number of pages in the database */ |
| 67978 | 68047 | int mxErr; /* Stop accumulating errors when this reaches zero */ |
| 67979 | 68048 | int nErr; /* Number of messages written to zErrMsg so far */ |
| 67980 | | - int bOomFault; /* A memory allocation error has occurred */ |
| 68049 | + int rc; /* SQLITE_OK, SQLITE_NOMEM, or SQLITE_INTERRUPT */ |
| 68050 | + u32 nStep; /* Number of steps into the integrity_check process */ |
| 67981 | 68051 | const char *zPfx; /* Error message prefix */ |
| 67982 | 68052 | Pgno v1; /* Value for first %u substitution in zPfx */ |
| 67983 | 68053 | int v2; /* Value for second %d substitution in zPfx */ |
| 67984 | 68054 | StrAccum errMsg; /* Accumulate the error message text here */ |
| 67985 | 68055 | u32 *heap; /* Min-heap used for analyzing cell coverage */ |
| | @@ -77219,31 +77289,31 @@ |
| 77219 | 77289 | return SQLITE_OK; |
| 77220 | 77290 | } |
| 77221 | 77291 | |
| 77222 | 77292 | /* |
| 77223 | 77293 | ** Overwrite the cell that cursor pCur is pointing to with fresh content |
| 77224 | | -** contained in pX. |
| 77294 | +** contained in pX. In this variant, pCur is pointing to an overflow |
| 77295 | +** cell. |
| 77225 | 77296 | */ |
| 77226 | | -static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){ |
| 77297 | +static SQLITE_NOINLINE int btreeOverwriteOverflowCell( |
| 77298 | + BtCursor *pCur, /* Cursor pointing to cell to ovewrite */ |
| 77299 | + const BtreePayload *pX /* Content to write into the cell */ |
| 77300 | +){ |
| 77227 | 77301 | int iOffset; /* Next byte of pX->pData to write */ |
| 77228 | 77302 | int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */ |
| 77229 | 77303 | int rc; /* Return code */ |
| 77230 | 77304 | MemPage *pPage = pCur->pPage; /* Page being written */ |
| 77231 | 77305 | BtShared *pBt; /* Btree */ |
| 77232 | 77306 | Pgno ovflPgno; /* Next overflow page to write */ |
| 77233 | 77307 | u32 ovflPageSize; /* Size to write on overflow page */ |
| 77234 | 77308 | |
| 77235 | | - if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd |
| 77236 | | - || pCur->info.pPayload < pPage->aData + pPage->cellOffset |
| 77237 | | - ){ |
| 77238 | | - return SQLITE_CORRUPT_BKPT; |
| 77239 | | - } |
| 77309 | + assert( pCur->info.nLocal<nTotal ); /* pCur is an overflow cell */ |
| 77310 | + |
| 77240 | 77311 | /* Overwrite the local portion first */ |
| 77241 | 77312 | rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX, |
| 77242 | 77313 | 0, pCur->info.nLocal); |
| 77243 | 77314 | if( rc ) return rc; |
| 77244 | | - if( pCur->info.nLocal==nTotal ) return SQLITE_OK; |
| 77245 | 77315 | |
| 77246 | 77316 | /* Now overwrite the overflow pages */ |
| 77247 | 77317 | iOffset = pCur->info.nLocal; |
| 77248 | 77318 | assert( nTotal>=0 ); |
| 77249 | 77319 | assert( iOffset>=0 ); |
| | @@ -77268,10 +77338,33 @@ |
| 77268 | 77338 | if( rc ) return rc; |
| 77269 | 77339 | iOffset += ovflPageSize; |
| 77270 | 77340 | }while( iOffset<nTotal ); |
| 77271 | 77341 | return SQLITE_OK; |
| 77272 | 77342 | } |
| 77343 | + |
| 77344 | +/* |
| 77345 | +** Overwrite the cell that cursor pCur is pointing to with fresh content |
| 77346 | +** contained in pX. |
| 77347 | +*/ |
| 77348 | +static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){ |
| 77349 | + int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */ |
| 77350 | + MemPage *pPage = pCur->pPage; /* Page being written */ |
| 77351 | + |
| 77352 | + if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd |
| 77353 | + || pCur->info.pPayload < pPage->aData + pPage->cellOffset |
| 77354 | + ){ |
| 77355 | + return SQLITE_CORRUPT_BKPT; |
| 77356 | + } |
| 77357 | + if( pCur->info.nLocal==nTotal ){ |
| 77358 | + /* The entire cell is local */ |
| 77359 | + return btreeOverwriteContent(pPage, pCur->info.pPayload, pX, |
| 77360 | + 0, pCur->info.nLocal); |
| 77361 | + }else{ |
| 77362 | + /* The cell contains overflow content */ |
| 77363 | + return btreeOverwriteOverflowCell(pCur, pX); |
| 77364 | + } |
| 77365 | +} |
| 77273 | 77366 | |
| 77274 | 77367 | |
| 77275 | 77368 | /* |
| 77276 | 77369 | ** Insert a new record into the BTree. The content of the new record |
| 77277 | 77370 | ** is described by the pX object. The pCur cursor is used only to |
| | @@ -78463,19 +78556,55 @@ |
| 78463 | 78556 | SQLITE_PRIVATE Pager *sqlite3BtreePager(Btree *p){ |
| 78464 | 78557 | return p->pBt->pPager; |
| 78465 | 78558 | } |
| 78466 | 78559 | |
| 78467 | 78560 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
| 78561 | +/* |
| 78562 | +** Record an OOM error during integrity_check |
| 78563 | +*/ |
| 78564 | +static void checkOom(IntegrityCk *pCheck){ |
| 78565 | + pCheck->rc = SQLITE_NOMEM; |
| 78566 | + pCheck->mxErr = 0; /* Causes integrity_check processing to stop */ |
| 78567 | + if( pCheck->nErr==0 ) pCheck->nErr++; |
| 78568 | +} |
| 78569 | + |
| 78570 | +/* |
| 78571 | +** Invoke the progress handler, if appropriate. Also check for an |
| 78572 | +** interrupt. |
| 78573 | +*/ |
| 78574 | +static void checkProgress(IntegrityCk *pCheck){ |
| 78575 | + sqlite3 *db = pCheck->db; |
| 78576 | + if( AtomicLoad(&db->u1.isInterrupted) ){ |
| 78577 | + pCheck->rc = SQLITE_INTERRUPT; |
| 78578 | + pCheck->nErr++; |
| 78579 | + pCheck->mxErr = 0; |
| 78580 | + } |
| 78581 | +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 78582 | + if( db->xProgress ){ |
| 78583 | + assert( db->nProgressOps>0 ); |
| 78584 | + pCheck->nStep++; |
| 78585 | + if( (pCheck->nStep % db->nProgressOps)==0 |
| 78586 | + && db->xProgress(db->pProgressArg) |
| 78587 | + ){ |
| 78588 | + pCheck->rc = SQLITE_INTERRUPT; |
| 78589 | + pCheck->nErr++; |
| 78590 | + pCheck->mxErr = 0; |
| 78591 | + } |
| 78592 | + } |
| 78593 | +#endif |
| 78594 | +} |
| 78595 | + |
| 78468 | 78596 | /* |
| 78469 | 78597 | ** Append a message to the error message string. |
| 78470 | 78598 | */ |
| 78471 | 78599 | static void checkAppendMsg( |
| 78472 | 78600 | IntegrityCk *pCheck, |
| 78473 | 78601 | const char *zFormat, |
| 78474 | 78602 | ... |
| 78475 | 78603 | ){ |
| 78476 | 78604 | va_list ap; |
| 78605 | + checkProgress(pCheck); |
| 78477 | 78606 | if( !pCheck->mxErr ) return; |
| 78478 | 78607 | pCheck->mxErr--; |
| 78479 | 78608 | pCheck->nErr++; |
| 78480 | 78609 | va_start(ap, zFormat); |
| 78481 | 78610 | if( pCheck->errMsg.nChar ){ |
| | @@ -78485,11 +78614,11 @@ |
| 78485 | 78614 | sqlite3_str_appendf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2); |
| 78486 | 78615 | } |
| 78487 | 78616 | sqlite3_str_vappendf(&pCheck->errMsg, zFormat, ap); |
| 78488 | 78617 | va_end(ap); |
| 78489 | 78618 | if( pCheck->errMsg.accError==SQLITE_NOMEM ){ |
| 78490 | | - pCheck->bOomFault = 1; |
| 78619 | + checkOom(pCheck); |
| 78491 | 78620 | } |
| 78492 | 78621 | } |
| 78493 | 78622 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 78494 | 78623 | |
| 78495 | 78624 | #ifndef SQLITE_OMIT_INTEGRITY_CHECK |
| | @@ -78527,11 +78656,10 @@ |
| 78527 | 78656 | } |
| 78528 | 78657 | if( getPageReferenced(pCheck, iPage) ){ |
| 78529 | 78658 | checkAppendMsg(pCheck, "2nd reference to page %d", iPage); |
| 78530 | 78659 | return 1; |
| 78531 | 78660 | } |
| 78532 | | - if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1; |
| 78533 | 78661 | setPageReferenced(pCheck, iPage); |
| 78534 | 78662 | return 0; |
| 78535 | 78663 | } |
| 78536 | 78664 | |
| 78537 | 78665 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| | @@ -78550,11 +78678,11 @@ |
| 78550 | 78678 | u8 ePtrmapType; |
| 78551 | 78679 | Pgno iPtrmapParent; |
| 78552 | 78680 | |
| 78553 | 78681 | rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent); |
| 78554 | 78682 | if( rc!=SQLITE_OK ){ |
| 78555 | | - if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->bOomFault = 1; |
| 78683 | + if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) checkOom(pCheck); |
| 78556 | 78684 | checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild); |
| 78557 | 78685 | return; |
| 78558 | 78686 | } |
| 78559 | 78687 | |
| 78560 | 78688 | if( ePtrmapType!=eType || iPtrmapParent!=iParent ){ |
| | @@ -78734,10 +78862,12 @@ |
| 78734 | 78862 | int saved_v2 = pCheck->v2; |
| 78735 | 78863 | u8 savedIsInit = 0; |
| 78736 | 78864 | |
| 78737 | 78865 | /* Check that the page exists |
| 78738 | 78866 | */ |
| 78867 | + checkProgress(pCheck); |
| 78868 | + if( pCheck->mxErr==0 ) goto end_of_check; |
| 78739 | 78869 | pBt = pCheck->pBt; |
| 78740 | 78870 | usableSize = pBt->usableSize; |
| 78741 | 78871 | if( iPage==0 ) return 0; |
| 78742 | 78872 | if( checkRef(pCheck, iPage) ) return 0; |
| 78743 | 78873 | pCheck->zPfx = "Page %u: "; |
| | @@ -78979,17 +79109,18 @@ |
| 78979 | 79109 | ** and the checks to make sure every page is referenced are also skipped, |
| 78980 | 79110 | ** since obviously it is not possible to know which pages are covered by |
| 78981 | 79111 | ** the unverified btrees. Except, if aRoot[1] is 1, then the freelist |
| 78982 | 79112 | ** checks are still performed. |
| 78983 | 79113 | */ |
| 78984 | | -SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck( |
| 79114 | +SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck( |
| 78985 | 79115 | sqlite3 *db, /* Database connection that is running the check */ |
| 78986 | 79116 | Btree *p, /* The btree to be checked */ |
| 78987 | 79117 | Pgno *aRoot, /* An array of root pages numbers for individual trees */ |
| 78988 | 79118 | int nRoot, /* Number of entries in aRoot[] */ |
| 78989 | 79119 | int mxErr, /* Stop reporting errors after this many */ |
| 78990 | | - int *pnErr /* Write number of errors seen to this variable */ |
| 79120 | + int *pnErr, /* OUT: Write number of errors seen to this variable */ |
| 79121 | + char **pzOut /* OUT: Write the error message string here */ |
| 78991 | 79122 | ){ |
| 78992 | 79123 | Pgno i; |
| 78993 | 79124 | IntegrityCk sCheck; |
| 78994 | 79125 | BtShared *pBt = p->pBt; |
| 78995 | 79126 | u64 savedDbFlags = pBt->db->flags; |
| | @@ -79008,36 +79139,30 @@ |
| 79008 | 79139 | |
| 79009 | 79140 | sqlite3BtreeEnter(p); |
| 79010 | 79141 | assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE ); |
| 79011 | 79142 | VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) ); |
| 79012 | 79143 | assert( nRef>=0 ); |
| 79144 | + memset(&sCheck, 0, sizeof(sCheck)); |
| 79013 | 79145 | sCheck.db = db; |
| 79014 | 79146 | sCheck.pBt = pBt; |
| 79015 | 79147 | sCheck.pPager = pBt->pPager; |
| 79016 | 79148 | sCheck.nPage = btreePagecount(sCheck.pBt); |
| 79017 | 79149 | sCheck.mxErr = mxErr; |
| 79018 | | - sCheck.nErr = 0; |
| 79019 | | - sCheck.bOomFault = 0; |
| 79020 | | - sCheck.zPfx = 0; |
| 79021 | | - sCheck.v1 = 0; |
| 79022 | | - sCheck.v2 = 0; |
| 79023 | | - sCheck.aPgRef = 0; |
| 79024 | | - sCheck.heap = 0; |
| 79025 | 79150 | sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH); |
| 79026 | 79151 | sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL; |
| 79027 | 79152 | if( sCheck.nPage==0 ){ |
| 79028 | 79153 | goto integrity_ck_cleanup; |
| 79029 | 79154 | } |
| 79030 | 79155 | |
| 79031 | 79156 | sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1); |
| 79032 | 79157 | if( !sCheck.aPgRef ){ |
| 79033 | | - sCheck.bOomFault = 1; |
| 79158 | + checkOom(&sCheck); |
| 79034 | 79159 | goto integrity_ck_cleanup; |
| 79035 | 79160 | } |
| 79036 | 79161 | sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize ); |
| 79037 | 79162 | if( sCheck.heap==0 ){ |
| 79038 | | - sCheck.bOomFault = 1; |
| 79163 | + checkOom(&sCheck); |
| 79039 | 79164 | goto integrity_ck_cleanup; |
| 79040 | 79165 | } |
| 79041 | 79166 | |
| 79042 | 79167 | i = PENDING_BYTE_PAGE(pBt); |
| 79043 | 79168 | if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i); |
| | @@ -79114,20 +79239,21 @@ |
| 79114 | 79239 | /* Clean up and report errors. |
| 79115 | 79240 | */ |
| 79116 | 79241 | integrity_ck_cleanup: |
| 79117 | 79242 | sqlite3PageFree(sCheck.heap); |
| 79118 | 79243 | sqlite3_free(sCheck.aPgRef); |
| 79119 | | - if( sCheck.bOomFault ){ |
| 79244 | + *pnErr = sCheck.nErr; |
| 79245 | + if( sCheck.nErr==0 ){ |
| 79120 | 79246 | sqlite3_str_reset(&sCheck.errMsg); |
| 79121 | | - sCheck.nErr++; |
| 79247 | + *pzOut = 0; |
| 79248 | + }else{ |
| 79249 | + *pzOut = sqlite3StrAccumFinish(&sCheck.errMsg); |
| 79122 | 79250 | } |
| 79123 | | - *pnErr = sCheck.nErr; |
| 79124 | | - if( sCheck.nErr==0 ) sqlite3_str_reset(&sCheck.errMsg); |
| 79125 | 79251 | /* Make sure this analysis did not leave any unref() pages. */ |
| 79126 | 79252 | assert( nRef==sqlite3PagerRefcount(pBt->pPager) ); |
| 79127 | 79253 | sqlite3BtreeLeave(p); |
| 79128 | | - return sqlite3StrAccumFinish(&sCheck.errMsg); |
| 79254 | + return sCheck.rc; |
| 79129 | 79255 | } |
| 79130 | 79256 | #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ |
| 79131 | 79257 | |
| 79132 | 79258 | /* |
| 79133 | 79259 | ** Return the full pathname of the underlying database file. Return |
| | @@ -80309,20 +80435,21 @@ |
| 80309 | 80435 | /* Work-around for GCC bug |
| 80310 | 80436 | ** https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96270 */ |
| 80311 | 80437 | i64 x; |
| 80312 | 80438 | assert( (p->flags&MEM_Int)*2==sizeof(x) ); |
| 80313 | 80439 | memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2); |
| 80314 | | - sqlite3Int64ToText(x, zBuf); |
| 80440 | + p->n = sqlite3Int64ToText(x, zBuf); |
| 80315 | 80441 | #else |
| 80316 | | - sqlite3Int64ToText(p->u.i, zBuf); |
| 80442 | + p->n = sqlite3Int64ToText(p->u.i, zBuf); |
| 80317 | 80443 | #endif |
| 80318 | 80444 | }else{ |
| 80319 | 80445 | sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0); |
| 80320 | 80446 | sqlite3_str_appendf(&acc, "%!.15g", |
| 80321 | 80447 | (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r); |
| 80322 | 80448 | assert( acc.zText==zBuf && acc.mxAlloc<=0 ); |
| 80323 | 80449 | zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */ |
| 80450 | + p->n = acc.nChar; |
| 80324 | 80451 | } |
| 80325 | 80452 | } |
| 80326 | 80453 | |
| 80327 | 80454 | #ifdef SQLITE_DEBUG |
| 80328 | 80455 | /* |
| | @@ -80346,10 +80473,11 @@ |
| 80346 | 80473 | ** true if everything is ok and false if there is a problem. |
| 80347 | 80474 | ** |
| 80348 | 80475 | ** This routine is for use inside of assert() statements only. |
| 80349 | 80476 | */ |
| 80350 | 80477 | SQLITE_PRIVATE int sqlite3VdbeMemValidStrRep(Mem *p){ |
| 80478 | + Mem tmp; |
| 80351 | 80479 | char zBuf[100]; |
| 80352 | 80480 | char *z; |
| 80353 | 80481 | int i, j, incr; |
| 80354 | 80482 | if( (p->flags & MEM_Str)==0 ) return 1; |
| 80355 | 80483 | if( p->flags & MEM_Term ){ |
| | @@ -80362,11 +80490,12 @@ |
| 80362 | 80490 | assert( p->z[p->n]==0 ); |
| 80363 | 80491 | assert( p->enc==SQLITE_UTF8 || p->z[(p->n+1)&~1]==0 ); |
| 80364 | 80492 | assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 ); |
| 80365 | 80493 | } |
| 80366 | 80494 | if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1; |
| 80367 | | - vdbeMemRenderNum(sizeof(zBuf), zBuf, p); |
| 80495 | + memcpy(&tmp, p, sizeof(tmp)); |
| 80496 | + vdbeMemRenderNum(sizeof(zBuf), zBuf, &tmp); |
| 80368 | 80497 | z = p->z; |
| 80369 | 80498 | i = j = 0; |
| 80370 | 80499 | incr = 1; |
| 80371 | 80500 | if( p->enc!=SQLITE_UTF8 ){ |
| 80372 | 80501 | incr = 2; |
| | @@ -80631,11 +80760,11 @@ |
| 80631 | 80760 | return SQLITE_NOMEM_BKPT; |
| 80632 | 80761 | } |
| 80633 | 80762 | |
| 80634 | 80763 | vdbeMemRenderNum(nByte, pMem->z, pMem); |
| 80635 | 80764 | assert( pMem->z!=0 ); |
| 80636 | | - pMem->n = sqlite3Strlen30NN(pMem->z); |
| 80765 | + assert( pMem->n==sqlite3Strlen30NN(pMem->z) ); |
| 80637 | 80766 | pMem->enc = SQLITE_UTF8; |
| 80638 | 80767 | pMem->flags |= MEM_Str|MEM_Term; |
| 80639 | 80768 | if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal); |
| 80640 | 80769 | sqlite3VdbeChangeEncoding(pMem, enc); |
| 80641 | 80770 | return SQLITE_OK; |
| | @@ -80871,36 +81000,39 @@ |
| 80871 | 81000 | if( pMem->flags & MEM_Null ) return ifNull; |
| 80872 | 81001 | return sqlite3VdbeRealValue(pMem)!=0.0; |
| 80873 | 81002 | } |
| 80874 | 81003 | |
| 80875 | 81004 | /* |
| 80876 | | -** The MEM structure is already a MEM_Real. Try to also make it a |
| 80877 | | -** MEM_Int if we can. |
| 81005 | +** The MEM structure is already a MEM_Real or MEM_IntReal. Try to |
| 81006 | +** make it a MEM_Int if we can. |
| 80878 | 81007 | */ |
| 80879 | 81008 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){ |
| 80880 | | - i64 ix; |
| 80881 | 81009 | assert( pMem!=0 ); |
| 80882 | | - assert( pMem->flags & MEM_Real ); |
| 81010 | + assert( pMem->flags & (MEM_Real|MEM_IntReal) ); |
| 80883 | 81011 | assert( !sqlite3VdbeMemIsRowSet(pMem) ); |
| 80884 | 81012 | assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) ); |
| 80885 | 81013 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 80886 | 81014 | |
| 80887 | | - ix = doubleToInt64(pMem->u.r); |
| 80888 | | - |
| 80889 | | - /* Only mark the value as an integer if |
| 80890 | | - ** |
| 80891 | | - ** (1) the round-trip conversion real->int->real is a no-op, and |
| 80892 | | - ** (2) The integer is neither the largest nor the smallest |
| 80893 | | - ** possible integer (ticket #3922) |
| 80894 | | - ** |
| 80895 | | - ** The second and third terms in the following conditional enforces |
| 80896 | | - ** the second condition under the assumption that addition overflow causes |
| 80897 | | - ** values to wrap around. |
| 80898 | | - */ |
| 80899 | | - if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){ |
| 80900 | | - pMem->u.i = ix; |
| 81015 | + if( pMem->flags & MEM_IntReal ){ |
| 80901 | 81016 | MemSetTypeFlag(pMem, MEM_Int); |
| 81017 | + }else{ |
| 81018 | + i64 ix = doubleToInt64(pMem->u.r); |
| 81019 | + |
| 81020 | + /* Only mark the value as an integer if |
| 81021 | + ** |
| 81022 | + ** (1) the round-trip conversion real->int->real is a no-op, and |
| 81023 | + ** (2) The integer is neither the largest nor the smallest |
| 81024 | + ** possible integer (ticket #3922) |
| 81025 | + ** |
| 81026 | + ** The second and third terms in the following conditional enforces |
| 81027 | + ** the second condition under the assumption that addition overflow causes |
| 81028 | + ** values to wrap around. |
| 81029 | + */ |
| 81030 | + if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){ |
| 81031 | + pMem->u.i = ix; |
| 81032 | + MemSetTypeFlag(pMem, MEM_Int); |
| 81033 | + } |
| 80902 | 81034 | } |
| 80903 | 81035 | } |
| 80904 | 81036 | |
| 80905 | 81037 | /* |
| 80906 | 81038 | ** Convert pMem to type integer. Invalidate any prior representations. |
| | @@ -82755,10 +82887,13 @@ |
| 82755 | 82887 | }else{ |
| 82756 | 82888 | #ifdef SQLITE_DEBUG |
| 82757 | 82889 | int i; |
| 82758 | 82890 | for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1; |
| 82759 | 82891 | #endif |
| 82892 | + if( nNewSize>=100 && (nNewSize/100)>(p->nLabelAlloc/100) ){ |
| 82893 | + sqlite3ProgressCheck(p); |
| 82894 | + } |
| 82760 | 82895 | p->nLabelAlloc = nNewSize; |
| 82761 | 82896 | p->aLabel[j] = v->nOp; |
| 82762 | 82897 | } |
| 82763 | 82898 | } |
| 82764 | 82899 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ |
| | @@ -90423,11 +90558,11 @@ |
| 90423 | 90558 | ){ |
| 90424 | 90559 | if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 90425 | 90560 | assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL |
| 90426 | 90561 | || affinity==SQLITE_AFF_NUMERIC || affinity==SQLITE_AFF_FLEXNUM ); |
| 90427 | 90562 | if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 90428 | | - if( (pRec->flags & MEM_Real)==0 ){ |
| 90563 | + if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){ |
| 90429 | 90564 | if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1); |
| 90430 | 90565 | }else if( affinity<=SQLITE_AFF_REAL ){ |
| 90431 | 90566 | sqlite3VdbeIntegerAffinity(pRec); |
| 90432 | 90567 | } |
| 90433 | 90568 | } |
| | @@ -91179,10 +91314,16 @@ |
| 91179 | 91314 | int pcx; |
| 91180 | 91315 | |
| 91181 | 91316 | #ifdef SQLITE_DEBUG |
| 91182 | 91317 | if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); } |
| 91183 | 91318 | #endif |
| 91319 | + |
| 91320 | + /* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates |
| 91321 | + ** something is wrong with the code generator. Raise and assertion in order |
| 91322 | + ** to bring this to the attention of fuzzers and other testing tools. */ |
| 91323 | + assert( pOp->p1!=SQLITE_INTERNAL ); |
| 91324 | + |
| 91184 | 91325 | if( p->pFrame && pOp->p1==SQLITE_OK ){ |
| 91185 | 91326 | /* Halt the sub-program. Return control to the parent frame. */ |
| 91186 | 91327 | pFrame = p->pFrame; |
| 91187 | 91328 | p->pFrame = pFrame->pParent; |
| 91188 | 91329 | p->nFrame--; |
| | @@ -93171,11 +93312,11 @@ |
| 93171 | 93312 | if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error; |
| 93172 | 93313 | break; |
| 93173 | 93314 | } |
| 93174 | 93315 | case COLTYPE_REAL: { |
| 93175 | 93316 | testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real ); |
| 93176 | | - testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal ); |
| 93317 | + assert( (pIn1->flags & MEM_IntReal)==0 ); |
| 93177 | 93318 | if( pIn1->flags & MEM_Int ){ |
| 93178 | 93319 | /* When applying REAL affinity, if the result is still an MEM_Int |
| 93179 | 93320 | ** that will fit in 6 bytes, then change the type to MEM_IntReal |
| 93180 | 93321 | ** so that we keep the high-resolution integer value but know that |
| 93181 | 93322 | ** the type really wants to be REAL. */ |
| | @@ -96148,10 +96289,13 @@ |
| 96148 | 96289 | ** The next use of the Rowid or Column or Next instruction for P1 |
| 96149 | 96290 | ** will refer to the first entry in the database table or index. |
| 96150 | 96291 | ** If the table or index is empty, jump immediately to P2. |
| 96151 | 96292 | ** If the table or index is not empty, fall through to the following |
| 96152 | 96293 | ** instruction. |
| 96294 | +** |
| 96295 | +** If P2 is zero, that is an assertion that the P1 table is never |
| 96296 | +** empty and hence the jump will never be taken. |
| 96153 | 96297 | ** |
| 96154 | 96298 | ** This opcode leaves the cursor configured to move in forward order, |
| 96155 | 96299 | ** from the beginning toward the end. In other words, the cursor is |
| 96156 | 96300 | ** configured to use Next, not Prev. |
| 96157 | 96301 | */ |
| | @@ -96160,10 +96304,12 @@ |
| 96160 | 96304 | BtCursor *pCrsr; |
| 96161 | 96305 | int res; |
| 96162 | 96306 | |
| 96163 | 96307 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 96164 | 96308 | assert( pOp->p5==0 ); |
| 96309 | + assert( pOp->p2>=0 && pOp->p2<p->nOp ); |
| 96310 | + |
| 96165 | 96311 | pC = p->apCsr[pOp->p1]; |
| 96166 | 96312 | assert( pC!=0 ); |
| 96167 | 96313 | assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) ); |
| 96168 | 96314 | res = 1; |
| 96169 | 96315 | #ifdef SQLITE_DEBUG |
| | @@ -96179,13 +96325,14 @@ |
| 96179 | 96325 | pC->deferredMoveto = 0; |
| 96180 | 96326 | pC->cacheStatus = CACHE_STALE; |
| 96181 | 96327 | } |
| 96182 | 96328 | if( rc ) goto abort_due_to_error; |
| 96183 | 96329 | pC->nullRow = (u8)res; |
| 96184 | | - assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 96185 | | - VdbeBranchTaken(res!=0,2); |
| 96186 | | - if( res ) goto jump_to_p2; |
| 96330 | + if( pOp->p2>0 ){ |
| 96331 | + VdbeBranchTaken(res!=0,2); |
| 96332 | + if( res ) goto jump_to_p2; |
| 96333 | + } |
| 96187 | 96334 | break; |
| 96188 | 96335 | } |
| 96189 | 96336 | |
| 96190 | 96337 | /* Opcode: Next P1 P2 P3 * P5 |
| 96191 | 96338 | ** |
| | @@ -96987,17 +97134,18 @@ |
| 96987 | 97134 | assert( (pnErr->flags & MEM_Int)!=0 ); |
| 96988 | 97135 | assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); |
| 96989 | 97136 | pIn1 = &aMem[pOp->p1]; |
| 96990 | 97137 | assert( pOp->p5<db->nDb ); |
| 96991 | 97138 | assert( DbMaskTest(p->btreeMask, pOp->p5) ); |
| 96992 | | - z = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot, |
| 96993 | | - (int)pnErr->u.i+1, &nErr); |
| 97139 | + rc = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot, |
| 97140 | + (int)pnErr->u.i+1, &nErr, &z); |
| 96994 | 97141 | sqlite3VdbeMemSetNull(pIn1); |
| 96995 | 97142 | if( nErr==0 ){ |
| 96996 | 97143 | assert( z==0 ); |
| 96997 | | - }else if( z==0 ){ |
| 96998 | | - goto no_mem; |
| 97144 | + }else if( rc ){ |
| 97145 | + sqlite3_free(z); |
| 97146 | + goto abort_due_to_error; |
| 96999 | 97147 | }else{ |
| 97000 | 97148 | pnErr->u.i -= nErr-1; |
| 97001 | 97149 | sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free); |
| 97002 | 97150 | } |
| 97003 | 97151 | UPDATE_MAX_BLOBSIZE(pIn1); |
| | @@ -103838,10 +103986,11 @@ |
| 103838 | 103986 | assert( ExprUseYTab(pExpr) ); |
| 103839 | 103987 | pExpr->y.pTab = pTab; |
| 103840 | 103988 | if( pParse->bReturning ){ |
| 103841 | 103989 | eNewExprOp = TK_REGISTER; |
| 103842 | 103990 | pExpr->op2 = TK_COLUMN; |
| 103991 | + pExpr->iColumn = iCol; |
| 103843 | 103992 | pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable + |
| 103844 | 103993 | sqlite3TableColumnToStorage(pTab, iCol) + 1; |
| 103845 | 103994 | }else{ |
| 103846 | 103995 | pExpr->iColumn = (i16)iCol; |
| 103847 | 103996 | eNewExprOp = TK_TRIGGER; |
| | @@ -132018,10 +132167,12 @@ |
| 132018 | 132167 | unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*, |
| 132019 | 132168 | unsigned int); |
| 132020 | 132169 | const char *(*db_name)(sqlite3*,int); |
| 132021 | 132170 | /* Version 3.40.0 and later */ |
| 132022 | 132171 | int (*value_encoding)(sqlite3_value*); |
| 132172 | + /* Version 3.41.0 and later */ |
| 132173 | + int (*is_interrupted)(sqlite3*); |
| 132023 | 132174 | }; |
| 132024 | 132175 | |
| 132025 | 132176 | /* |
| 132026 | 132177 | ** This is the function signature used for all extension entry points. It |
| 132027 | 132178 | ** is also defined in the file "loadext.c". |
| | @@ -132344,10 +132495,12 @@ |
| 132344 | 132495 | #define sqlite3_serialize sqlite3_api->serialize |
| 132345 | 132496 | #endif |
| 132346 | 132497 | #define sqlite3_db_name sqlite3_api->db_name |
| 132347 | 132498 | /* Version 3.40.0 and later */ |
| 132348 | 132499 | #define sqlite3_value_encoding sqlite3_api->value_encoding |
| 132500 | +/* Version 3.41.0 and later */ |
| 132501 | +#define sqlite3_is_interrupted sqlite3_api->is_interrupted |
| 132349 | 132502 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 132350 | 132503 | |
| 132351 | 132504 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 132352 | 132505 | /* This case when the file really is being compiled as a loadable |
| 132353 | 132506 | ** extension */ |
| | @@ -132858,11 +133011,13 @@ |
| 132858 | 133011 | 0, |
| 132859 | 133012 | 0, |
| 132860 | 133013 | #endif |
| 132861 | 133014 | sqlite3_db_name, |
| 132862 | 133015 | /* Version 3.40.0 and later */ |
| 132863 | | - sqlite3_value_encoding |
| 133016 | + sqlite3_value_encoding, |
| 133017 | + /* Version 3.41.0 and later */ |
| 133018 | + sqlite3_is_interrupted |
| 132864 | 133019 | }; |
| 132865 | 133020 | |
| 132866 | 133021 | /* True if x is the directory separator character |
| 132867 | 133022 | */ |
| 132868 | 133023 | #if SQLITE_OS_WIN |
| | @@ -135868,11 +136023,12 @@ |
| 135868 | 136023 | sqlite3ExprListDelete(db, pCheck); |
| 135869 | 136024 | } |
| 135870 | 136025 | if( !isQuick ){ /* Omit the remaining tests for quick_check */ |
| 135871 | 136026 | /* Validate index entries for the current row */ |
| 135872 | 136027 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 135873 | | - int jmp2, jmp3, jmp4, jmp5; |
| 136028 | + int jmp2, jmp3, jmp4, jmp5, label6; |
| 136029 | + int kk; |
| 135874 | 136030 | int ckUniq = sqlite3VdbeMakeLabel(pParse); |
| 135875 | 136031 | if( pPk==pIdx ) continue; |
| 135876 | 136032 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3, |
| 135877 | 136033 | pPrior, r1); |
| 135878 | 136034 | pPrior = pIdx; |
| | @@ -135886,17 +136042,36 @@ |
| 135886 | 136042 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 135887 | 136043 | jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName); |
| 135888 | 136044 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3); |
| 135889 | 136045 | jmp4 = integrityCheckResultRow(v); |
| 135890 | 136046 | sqlite3VdbeJumpHere(v, jmp2); |
| 136047 | + |
| 136048 | + /* Any indexed columns with non-BINARY collations must still hold |
| 136049 | + ** the exact same text value as the table. */ |
| 136050 | + label6 = 0; |
| 136051 | + for(kk=0; kk<pIdx->nKeyCol; kk++){ |
| 136052 | + if( pIdx->azColl[kk]==sqlite3StrBINARY ) continue; |
| 136053 | + if( label6==0 ) label6 = sqlite3VdbeMakeLabel(pParse); |
| 136054 | + sqlite3VdbeAddOp3(v, OP_Column, iIdxCur+j, kk, 3); |
| 136055 | + sqlite3VdbeAddOp3(v, OP_Ne, 3, label6, r1+kk); VdbeCoverage(v); |
| 136056 | + } |
| 136057 | + if( label6 ){ |
| 136058 | + int jmp6 = sqlite3VdbeAddOp0(v, OP_Goto); |
| 136059 | + sqlite3VdbeResolveLabel(v, label6); |
| 136060 | + sqlite3VdbeLoadString(v, 3, "row "); |
| 136061 | + sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3); |
| 136062 | + sqlite3VdbeLoadString(v, 4, " values differ from index "); |
| 136063 | + sqlite3VdbeGoto(v, jmp5-1); |
| 136064 | + sqlite3VdbeJumpHere(v, jmp6); |
| 136065 | + } |
| 136066 | + |
| 135891 | 136067 | /* For UNIQUE indexes, verify that only one entry exists with the |
| 135892 | 136068 | ** current key. The entry is unique if (1) any column is NULL |
| 135893 | 136069 | ** or (2) the next entry has a different key */ |
| 135894 | 136070 | if( IsUniqueIndex(pIdx) ){ |
| 135895 | 136071 | int uniqOk = sqlite3VdbeMakeLabel(pParse); |
| 135896 | 136072 | int jmp6; |
| 135897 | | - int kk; |
| 135898 | 136073 | for(kk=0; kk<pIdx->nKeyCol; kk++){ |
| 135899 | 136074 | int iCol = pIdx->aiColumn[kk]; |
| 135900 | 136075 | assert( iCol!=XN_ROWID && iCol<pTab->nCol ); |
| 135901 | 136076 | if( iCol>=0 && pTab->aCol[iCol].notNull ) continue; |
| 135902 | 136077 | sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk); |
| | @@ -139696,11 +139871,10 @@ |
| 139696 | 139871 | #ifdef SQLITE_ENABLE_COLUMN_METADATA |
| 139697 | 139872 | # define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E) |
| 139698 | 139873 | #else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */ |
| 139699 | 139874 | # define columnType(A,B,C,D,E) columnTypeImpl(A,B) |
| 139700 | 139875 | #endif |
| 139701 | | -#ifndef SQLITE_OMIT_DECLTYPE |
| 139702 | 139876 | static const char *columnTypeImpl( |
| 139703 | 139877 | NameContext *pNC, |
| 139704 | 139878 | #ifndef SQLITE_ENABLE_COLUMN_METADATA |
| 139705 | 139879 | Expr *pExpr |
| 139706 | 139880 | #else |
| | @@ -139727,11 +139901,11 @@ |
| 139727 | 139901 | ** database table or a subquery. |
| 139728 | 139902 | */ |
| 139729 | 139903 | Table *pTab = 0; /* Table structure column is extracted from */ |
| 139730 | 139904 | Select *pS = 0; /* Select the column is extracted from */ |
| 139731 | 139905 | int iCol = pExpr->iColumn; /* Index of column in pTab */ |
| 139732 | | - while( ALWAYS(pNC) && !pTab ){ |
| 139906 | + while( pNC && !pTab ){ |
| 139733 | 139907 | SrcList *pTabList = pNC->pSrcList; |
| 139734 | 139908 | for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++); |
| 139735 | 139909 | if( j<pTabList->nSrc ){ |
| 139736 | 139910 | pTab = pTabList->a[j].pTab; |
| 139737 | 139911 | pS = pTabList->a[j].pSelect; |
| | @@ -139738,11 +139912,11 @@ |
| 139738 | 139912 | }else{ |
| 139739 | 139913 | pNC = pNC->pNext; |
| 139740 | 139914 | } |
| 139741 | 139915 | } |
| 139742 | 139916 | |
| 139743 | | - if( NEVER(pTab==0) ){ |
| 139917 | + if( pTab==0 ){ |
| 139744 | 139918 | /* At one time, code such as "SELECT new.x" within a trigger would |
| 139745 | 139919 | ** cause this condition to run. Since then, we have restructured how |
| 139746 | 139920 | ** trigger code is generated and so this condition is no longer |
| 139747 | 139921 | ** possible. However, it can still be true for statements like |
| 139748 | 139922 | ** the following: |
| | @@ -139843,11 +140017,10 @@ |
| 139843 | 140017 | *pzOrigCol = zOrigCol; |
| 139844 | 140018 | } |
| 139845 | 140019 | #endif |
| 139846 | 140020 | return zType; |
| 139847 | 140021 | } |
| 139848 | | -#endif /* !defined(SQLITE_OMIT_DECLTYPE) */ |
| 139849 | 140022 | |
| 139850 | 140023 | /* |
| 139851 | 140024 | ** Generate code that will tell the VDBE the declaration types of columns |
| 139852 | 140025 | ** in the result set. |
| 139853 | 140026 | */ |
| | @@ -140039,11 +140212,11 @@ |
| 140039 | 140212 | } |
| 140040 | 140213 | assert( nCol==(i16)nCol ); |
| 140041 | 140214 | *pnCol = nCol; |
| 140042 | 140215 | *paCol = aCol; |
| 140043 | 140216 | |
| 140044 | | - for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){ |
| 140217 | + for(i=0, pCol=aCol; i<nCol && !pParse->nErr; i++, pCol++){ |
| 140045 | 140218 | struct ExprList_item *pX = &pEList->a[i]; |
| 140046 | 140219 | struct ExprList_item *pCollide; |
| 140047 | 140220 | /* Get an appropriate name for the column |
| 140048 | 140221 | */ |
| 140049 | 140222 | if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){ |
| | @@ -140089,11 +140262,14 @@ |
| 140089 | 140262 | if( nName>0 ){ |
| 140090 | 140263 | for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){} |
| 140091 | 140264 | if( zName[j]==':' ) nName = j; |
| 140092 | 140265 | } |
| 140093 | 140266 | zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); |
| 140094 | | - if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); |
| 140267 | + sqlite3ProgressCheck(pParse); |
| 140268 | + if( cnt>3 ){ |
| 140269 | + sqlite3_randomness(sizeof(cnt), &cnt); |
| 140270 | + } |
| 140095 | 140271 | } |
| 140096 | 140272 | pCol->zCnName = zName; |
| 140097 | 140273 | pCol->hName = sqlite3StrIHash(zName); |
| 140098 | 140274 | if( pX->fg.bNoExpand ){ |
| 140099 | 140275 | pCol->colFlags |= COLFLAG_NOEXPAND; |
| | @@ -140102,18 +140278,18 @@ |
| 140102 | 140278 | if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){ |
| 140103 | 140279 | sqlite3OomFault(db); |
| 140104 | 140280 | } |
| 140105 | 140281 | } |
| 140106 | 140282 | sqlite3HashClear(&ht); |
| 140107 | | - if( db->mallocFailed ){ |
| 140283 | + if( pParse->nErr ){ |
| 140108 | 140284 | for(j=0; j<i; j++){ |
| 140109 | 140285 | sqlite3DbFree(db, aCol[j].zCnName); |
| 140110 | 140286 | } |
| 140111 | 140287 | sqlite3DbFree(db, aCol); |
| 140112 | 140288 | *paCol = 0; |
| 140113 | 140289 | *pnCol = 0; |
| 140114 | | - return SQLITE_NOMEM_BKPT; |
| 140290 | + return pParse->rc; |
| 140115 | 140291 | } |
| 140116 | 140292 | return SQLITE_OK; |
| 140117 | 140293 | } |
| 140118 | 140294 | |
| 140119 | 140295 | /* |
| | @@ -140137,18 +140313,21 @@ |
| 140137 | 140313 | Column *pCol; |
| 140138 | 140314 | CollSeq *pColl; |
| 140139 | 140315 | int i,j; |
| 140140 | 140316 | Expr *p; |
| 140141 | 140317 | struct ExprList_item *a; |
| 140318 | + NameContext sNC; |
| 140142 | 140319 | |
| 140143 | 140320 | assert( pSelect!=0 ); |
| 140144 | 140321 | assert( (pSelect->selFlags & SF_Resolved)!=0 ); |
| 140145 | | - assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed ); |
| 140322 | + assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 ); |
| 140146 | 140323 | assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB ); |
| 140147 | 140324 | if( db->mallocFailed ) return; |
| 140148 | 140325 | while( pSelect->pPrior ) pSelect = pSelect->pPrior; |
| 140149 | 140326 | a = pSelect->pEList->a; |
| 140327 | + memset(&sNC, 0, sizeof(sNC)); |
| 140328 | + sNC.pSrcList = pSelect->pSrc; |
| 140150 | 140329 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 140151 | 140330 | const char *zType; |
| 140152 | 140331 | i64 n; |
| 140153 | 140332 | pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT); |
| 140154 | 140333 | p = a[i].pExpr; |
| | @@ -140170,32 +140349,35 @@ |
| 140170 | 140349 | }else |
| 140171 | 140350 | if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){ |
| 140172 | 140351 | pCol->affinity = SQLITE_AFF_BLOB; |
| 140173 | 140352 | } |
| 140174 | 140353 | } |
| 140175 | | - if( pCol->affinity==SQLITE_AFF_NUMERIC |
| 140176 | | - || pCol->affinity==SQLITE_AFF_FLEXNUM |
| 140177 | | - ){ |
| 140178 | | - zType = "NUM"; |
| 140179 | | - }else{ |
| 140180 | | - zType = 0; |
| 140181 | | - for(j=1; j<SQLITE_N_STDTYPE; j++){ |
| 140182 | | - if( sqlite3StdTypeAffinity[j]==pCol->affinity ){ |
| 140183 | | - zType = sqlite3StdType[j]; |
| 140184 | | - break; |
| 140185 | | - } |
| 140186 | | - } |
| 140187 | | - } |
| 140188 | | - if( zType ){ |
| 140189 | | - i64 m = sqlite3Strlen30(zType); |
| 140190 | | - n = sqlite3Strlen30(pCol->zCnName); |
| 140191 | | - pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); |
| 140192 | | - if( pCol->zCnName ){ |
| 140193 | | - memcpy(&pCol->zCnName[n+1], zType, m+1); |
| 140194 | | - pCol->colFlags |= COLFLAG_HASTYPE; |
| 140195 | | - }else{ |
| 140196 | | - testcase( pCol->colFlags & COLFLAG_HASTYPE ); |
| 140354 | + zType = columnType(&sNC, p, 0, 0, 0); |
| 140355 | + if( zType==0 || pCol->affinity!=sqlite3AffinityType(zType, 0) ){ |
| 140356 | + if( pCol->affinity==SQLITE_AFF_NUMERIC |
| 140357 | + || pCol->affinity==SQLITE_AFF_FLEXNUM |
| 140358 | + ){ |
| 140359 | + zType = "NUM"; |
| 140360 | + }else{ |
| 140361 | + zType = 0; |
| 140362 | + for(j=1; j<SQLITE_N_STDTYPE; j++){ |
| 140363 | + if( sqlite3StdTypeAffinity[j]==pCol->affinity ){ |
| 140364 | + zType = sqlite3StdType[j]; |
| 140365 | + break; |
| 140366 | + } |
| 140367 | + } |
| 140368 | + } |
| 140369 | + } |
| 140370 | + if( zType ){ |
| 140371 | + i64 m = sqlite3Strlen30(zType); |
| 140372 | + n = sqlite3Strlen30(pCol->zCnName); |
| 140373 | + pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2); |
| 140374 | + if( pCol->zCnName ){ |
| 140375 | + memcpy(&pCol->zCnName[n+1], zType, m+1); |
| 140376 | + pCol->colFlags |= COLFLAG_HASTYPE; |
| 140377 | + }else{ |
| 140378 | + testcase( pCol->colFlags & COLFLAG_HASTYPE ); |
| 140197 | 140379 | pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL); |
| 140198 | 140380 | } |
| 140199 | 140381 | } |
| 140200 | 140382 | pColl = sqlite3ExprCollSeq(pParse, p); |
| 140201 | 140383 | if( pColl ){ |
| | @@ -156196,10 +156378,17 @@ |
| 156196 | 156378 | /* This term is a vector operation that has been decomposed into |
| 156197 | 156379 | ** other, subsequent terms. It can be ignored. See tag-20220128a */ |
| 156198 | 156380 | assert( pWC->a[ii].wtFlags & TERM_VIRTUAL ); |
| 156199 | 156381 | assert( pWC->a[ii].eOperator==WO_ROWVAL ); |
| 156200 | 156382 | continue; |
| 156383 | + } |
| 156384 | + if( pWC->a[ii].nChild ){ |
| 156385 | + /* If this term has child terms, then they are also part of the |
| 156386 | + ** pWC->a[] array. So this term can be ignored, as a LIMIT clause |
| 156387 | + ** will only be added if each of the child terms passes the |
| 156388 | + ** (leftCursor==iCsr) test below. */ |
| 156389 | + continue; |
| 156201 | 156390 | } |
| 156202 | 156391 | if( pWC->a[ii].leftCursor!=iCsr ) return; |
| 156203 | 156392 | } |
| 156204 | 156393 | |
| 156205 | 156394 | /* Check condition (5). Return early if it is not met. */ |
| | @@ -159128,10 +159317,11 @@ |
| 159128 | 159317 | if( pX==0 ) continue; |
| 159129 | 159318 | if( pX==pTerm ) break; |
| 159130 | 159319 | if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break; |
| 159131 | 159320 | } |
| 159132 | 159321 | if( j<0 ){ |
| 159322 | + sqlite3ProgressCheck(pWC->pWInfo->pParse); |
| 159133 | 159323 | if( pLoop->maskSelf==pTerm->prereqAll ){ |
| 159134 | 159324 | /* If there are extra terms in the WHERE clause not used by an index |
| 159135 | 159325 | ** that depend only on the table being scanned, and that will tend to |
| 159136 | 159326 | ** cause many rows to be omitted, then mark that table as |
| 159137 | 159327 | ** "self-culling". |
| | @@ -159295,11 +159485,14 @@ |
| 159295 | 159485 | LogEst rSize; /* Number of rows in the table */ |
| 159296 | 159486 | LogEst rLogSize; /* Logarithm of table size */ |
| 159297 | 159487 | WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */ |
| 159298 | 159488 | |
| 159299 | 159489 | pNew = pBuilder->pNew; |
| 159300 | | - if( db->mallocFailed ) return SQLITE_NOMEM_BKPT; |
| 159490 | + assert( db->mallocFailed==0 || pParse->nErr>0 ); |
| 159491 | + if( pParse->nErr ){ |
| 159492 | + return pParse->rc; |
| 159493 | + } |
| 159301 | 159494 | WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d, rRun=%d\n", |
| 159302 | 159495 | pProbe->pTable->zName,pProbe->zName, |
| 159303 | 159496 | pNew->u.btree.nEq, pNew->nSkip, pNew->rRun)); |
| 159304 | 159497 | |
| 159305 | 159498 | assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 ); |
| | @@ -159611,10 +159804,13 @@ |
| 159611 | 159804 | if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 |
| 159612 | 159805 | && pNew->u.btree.nEq<pProbe->nColumn |
| 159613 | 159806 | && (pNew->u.btree.nEq<pProbe->nKeyCol || |
| 159614 | 159807 | pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY) |
| 159615 | 159808 | ){ |
| 159809 | + if( pNew->u.btree.nEq>3 ){ |
| 159810 | + sqlite3ProgressCheck(pParse); |
| 159811 | + } |
| 159616 | 159812 | whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn); |
| 159617 | 159813 | } |
| 159618 | 159814 | pNew->nOut = saved_nOut; |
| 159619 | 159815 | #ifdef SQLITE_ENABLE_STAT4 |
| 159620 | 159816 | pBuilder->nRecValid = nRecValid; |
| | @@ -160770,12 +160966,10 @@ |
| 160770 | 160966 | rc = whereLoopAddBtree(&sSubBuild, mPrereq); |
| 160771 | 160967 | } |
| 160772 | 160968 | if( rc==SQLITE_OK ){ |
| 160773 | 160969 | rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable); |
| 160774 | 160970 | } |
| 160775 | | - assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 |
| 160776 | | - || rc==SQLITE_NOMEM ); |
| 160777 | 160971 | testcase( rc==SQLITE_NOMEM && sCur.n>0 ); |
| 160778 | 160972 | testcase( rc==SQLITE_DONE ); |
| 160779 | 160973 | if( sCur.n==0 ){ |
| 160780 | 160974 | sSum.n = 0; |
| 160781 | 160975 | break; |
| | @@ -166126,12 +166320,11 @@ |
| 166126 | 166320 | int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le); |
| 166127 | 166321 | int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd); |
| 166128 | 166322 | VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */ |
| 166129 | 166323 | VdbeCoverageNeverNullIf(v, op==OP_Le); /* values previously checked */ |
| 166130 | 166324 | windowAggFinal(&s, 0); |
| 166131 | | - sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1); |
| 166132 | | - VdbeCoverageNeverTaken(v); |
| 166325 | + sqlite3VdbeAddOp1(v, OP_Rewind, s.current.csr); |
| 166133 | 166326 | windowReturnOneRow(&s); |
| 166134 | 166327 | sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr); |
| 166135 | 166328 | sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd); |
| 166136 | 166329 | sqlite3VdbeJumpHere(v, addrGe); |
| 166137 | 166330 | } |
| | @@ -166139,17 +166332,14 @@ |
| 166139 | 166332 | assert( pMWin->eEnd==TK_FOLLOWING ); |
| 166140 | 166333 | sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart); |
| 166141 | 166334 | } |
| 166142 | 166335 | |
| 166143 | 166336 | if( pMWin->eStart!=TK_UNBOUNDED ){ |
| 166144 | | - sqlite3VdbeAddOp2(v, OP_Rewind, s.start.csr, 1); |
| 166145 | | - VdbeCoverageNeverTaken(v); |
| 166337 | + sqlite3VdbeAddOp1(v, OP_Rewind, s.start.csr); |
| 166146 | 166338 | } |
| 166147 | | - sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1); |
| 166148 | | - VdbeCoverageNeverTaken(v); |
| 166149 | | - sqlite3VdbeAddOp2(v, OP_Rewind, s.end.csr, 1); |
| 166150 | | - VdbeCoverageNeverTaken(v); |
| 166339 | + sqlite3VdbeAddOp1(v, OP_Rewind, s.current.csr); |
| 166340 | + sqlite3VdbeAddOp1(v, OP_Rewind, s.end.csr); |
| 166151 | 166341 | if( regPeer && pOrderBy ){ |
| 166152 | 166342 | sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1); |
| 166153 | 166343 | sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1); |
| 166154 | 166344 | sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1); |
| 166155 | 166345 | sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1); |
| | @@ -175259,18 +175449,35 @@ |
| 175259 | 175449 | /* |
| 175260 | 175450 | ** Cause any pending operation to stop at its earliest opportunity. |
| 175261 | 175451 | */ |
| 175262 | 175452 | SQLITE_API void sqlite3_interrupt(sqlite3 *db){ |
| 175263 | 175453 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 175264 | | - if( !sqlite3SafetyCheckOk(db) && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE) ){ |
| 175454 | + if( !sqlite3SafetyCheckOk(db) |
| 175455 | + && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE) |
| 175456 | + ){ |
| 175265 | 175457 | (void)SQLITE_MISUSE_BKPT; |
| 175266 | 175458 | return; |
| 175267 | 175459 | } |
| 175268 | 175460 | #endif |
| 175269 | 175461 | AtomicStore(&db->u1.isInterrupted, 1); |
| 175270 | 175462 | } |
| 175271 | 175463 | |
| 175464 | +/* |
| 175465 | +** Return true or false depending on whether or not an interrupt is |
| 175466 | +** pending on connection db. |
| 175467 | +*/ |
| 175468 | +SQLITE_API int sqlite3_is_interrupted(sqlite3 *db){ |
| 175469 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 175470 | + if( !sqlite3SafetyCheckOk(db) |
| 175471 | + && (db==0 || db->eOpenState!=SQLITE_STATE_ZOMBIE) |
| 175472 | + ){ |
| 175473 | + (void)SQLITE_MISUSE_BKPT; |
| 175474 | + return 0; |
| 175475 | + } |
| 175476 | +#endif |
| 175477 | + return AtomicLoad(&db->u1.isInterrupted)!=0; |
| 175478 | +} |
| 175272 | 175479 | |
| 175273 | 175480 | /* |
| 175274 | 175481 | ** This function is exactly the same as sqlite3_create_function(), except |
| 175275 | 175482 | ** that it is designed to be called by internal code. The difference is |
| 175276 | 175483 | ** that if a malloc() fails in sqlite3_create_function(), an error code |
| | @@ -175311,11 +175518,11 @@ |
| 175311 | 175518 | enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY); |
| 175312 | 175519 | |
| 175313 | 175520 | /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But |
| 175314 | 175521 | ** the meaning is inverted. So flip the bit. */ |
| 175315 | 175522 | assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS ); |
| 175316 | | - extraFlags ^= SQLITE_FUNC_UNSAFE; |
| 175523 | + extraFlags ^= SQLITE_FUNC_UNSAFE; /* tag-20230109-1 */ |
| 175317 | 175524 | |
| 175318 | 175525 | |
| 175319 | 175526 | #ifndef SQLITE_OMIT_UTF16 |
| 175320 | 175527 | /* If SQLITE_UTF16 is specified as the encoding type, transform this |
| 175321 | 175528 | ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| | @@ -175329,15 +175536,15 @@ |
| 175329 | 175536 | enc = SQLITE_UTF16NATIVE; |
| 175330 | 175537 | break; |
| 175331 | 175538 | case SQLITE_ANY: { |
| 175332 | 175539 | int rc; |
| 175333 | 175540 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 175334 | | - (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 175541 | + (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE, /* tag-20230109-1 */ |
| 175335 | 175542 | pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 175336 | 175543 | if( rc==SQLITE_OK ){ |
| 175337 | 175544 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 175338 | | - (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 175545 | + (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE, /* tag-20230109-1*/ |
| 175339 | 175546 | pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 175340 | 175547 | } |
| 175341 | 175548 | if( rc!=SQLITE_OK ){ |
| 175342 | 175549 | return rc; |
| 175343 | 175550 | } |
| | @@ -212650,11 +212857,12 @@ |
| 212650 | 212857 | ** leave an error code and error message in the rbu handle. |
| 212651 | 212858 | */ |
| 212652 | 212859 | static void rbuDeleteOalFile(sqlite3rbu *p){ |
| 212653 | 212860 | char *zOal = rbuMPrintf(p, "%s-oal", p->zTarget); |
| 212654 | 212861 | if( zOal ){ |
| 212655 | | - sqlite3_vfs *pVfs = sqlite3_vfs_find(0); |
| 212862 | + sqlite3_vfs *pVfs = 0; |
| 212863 | + sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_VFS_POINTER, &pVfs); |
| 212656 | 212864 | assert( pVfs && p->rc==SQLITE_OK && p->zErrmsg==0 ); |
| 212657 | 212865 | pVfs->xDelete(pVfs, zOal, 0); |
| 212658 | 212866 | sqlite3_free(zOal); |
| 212659 | 212867 | } |
| 212660 | 212868 | } |
| | @@ -213407,13 +213615,16 @@ |
| 213407 | 213615 | sqlite3_free(p->apShm); |
| 213408 | 213616 | p->apShm = 0; |
| 213409 | 213617 | sqlite3_free(p->zDel); |
| 213410 | 213618 | |
| 213411 | 213619 | if( p->openFlags & SQLITE_OPEN_MAIN_DB ){ |
| 213620 | + const sqlite3_io_methods *pMeth = p->pReal->pMethods; |
| 213412 | 213621 | rbuMainlistRemove(p); |
| 213413 | 213622 | rbuUnlockShm(p); |
| 213414 | | - p->pReal->pMethods->xShmUnmap(p->pReal, 0); |
| 213623 | + if( pMeth->iVersion>1 && pMeth->xShmUnmap ){ |
| 213624 | + pMeth->xShmUnmap(p->pReal, 0); |
| 213625 | + } |
| 213415 | 213626 | } |
| 213416 | 213627 | else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){ |
| 213417 | 213628 | rbuUpdateTempSize(p, 0); |
| 213418 | 213629 | } |
| 213419 | 213630 | assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p ); |
| | @@ -213868,10 +214079,29 @@ |
| 213868 | 214079 | rbuVfsShmLock, /* xShmLock */ |
| 213869 | 214080 | rbuVfsShmBarrier, /* xShmBarrier */ |
| 213870 | 214081 | rbuVfsShmUnmap, /* xShmUnmap */ |
| 213871 | 214082 | 0, 0 /* xFetch, xUnfetch */ |
| 213872 | 214083 | }; |
| 214084 | + static sqlite3_io_methods rbuvfs_io_methods1 = { |
| 214085 | + 1, /* iVersion */ |
| 214086 | + rbuVfsClose, /* xClose */ |
| 214087 | + rbuVfsRead, /* xRead */ |
| 214088 | + rbuVfsWrite, /* xWrite */ |
| 214089 | + rbuVfsTruncate, /* xTruncate */ |
| 214090 | + rbuVfsSync, /* xSync */ |
| 214091 | + rbuVfsFileSize, /* xFileSize */ |
| 214092 | + rbuVfsLock, /* xLock */ |
| 214093 | + rbuVfsUnlock, /* xUnlock */ |
| 214094 | + rbuVfsCheckReservedLock, /* xCheckReservedLock */ |
| 214095 | + rbuVfsFileControl, /* xFileControl */ |
| 214096 | + rbuVfsSectorSize, /* xSectorSize */ |
| 214097 | + rbuVfsDeviceCharacteristics, /* xDeviceCharacteristics */ |
| 214098 | + 0, 0, 0, 0, 0, 0 |
| 214099 | + }; |
| 214100 | + |
| 214101 | + |
| 214102 | + |
| 213873 | 214103 | rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs; |
| 213874 | 214104 | sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs; |
| 213875 | 214105 | rbu_file *pFd = (rbu_file *)pFile; |
| 213876 | 214106 | int rc = SQLITE_OK; |
| 213877 | 214107 | const char *zOpen = zName; |
| | @@ -213922,14 +214152,19 @@ |
| 213922 | 214152 | |
| 213923 | 214153 | if( rc==SQLITE_OK ){ |
| 213924 | 214154 | rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags); |
| 213925 | 214155 | } |
| 213926 | 214156 | if( pFd->pReal->pMethods ){ |
| 214157 | + const sqlite3_io_methods *pMeth = pFd->pReal->pMethods; |
| 213927 | 214158 | /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods |
| 213928 | 214159 | ** pointer and, if the file is a main database file, link it into the |
| 213929 | 214160 | ** mutex protected linked list of all such files. */ |
| 213930 | | - pFile->pMethods = &rbuvfs_io_methods; |
| 214161 | + if( pMeth->iVersion<2 || pMeth->xShmLock==0 ){ |
| 214162 | + pFile->pMethods = &rbuvfs_io_methods1; |
| 214163 | + }else{ |
| 214164 | + pFile->pMethods = &rbuvfs_io_methods; |
| 214165 | + } |
| 213931 | 214166 | if( flags & SQLITE_OPEN_MAIN_DB ){ |
| 213932 | 214167 | rbuMainlistAdd(pFd); |
| 213933 | 214168 | } |
| 213934 | 214169 | }else{ |
| 213935 | 214170 | sqlite3_free(pFd->zDel); |
| | @@ -239641,11 +239876,11 @@ |
| 239641 | 239876 | int nArg, /* Number of args */ |
| 239642 | 239877 | sqlite3_value **apUnused /* Function arguments */ |
| 239643 | 239878 | ){ |
| 239644 | 239879 | assert( nArg==0 ); |
| 239645 | 239880 | UNUSED_PARAM2(nArg, apUnused); |
| 239646 | | - sqlite3_result_text(pCtx, "fts5: 2022-12-27 22:46:49 e8afad630b085a9208491e0516a6a30c9cda77a20b1aa2cba49b2f44eb9fa2f8", -1, SQLITE_TRANSIENT); |
| 239881 | + sqlite3_result_text(pCtx, "fts5: 2023-01-16 18:13:00 83f21285fe86430a66ce6841606e3ad7c27da52ac75a034c6a00c7a9fdb9791d", -1, SQLITE_TRANSIENT); |
| 239647 | 239882 | } |
| 239648 | 239883 | |
| 239649 | 239884 | /* |
| 239650 | 239885 | ** Return true if zName is the extension on one of the shadow tables used |
| 239651 | 239886 | ** by this module. |
| 239652 | 239887 | |