| | @@ -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 | | -** ea1754f7d8a770477a1b19b606b27724fdc0 with changes in files: |
| 21 | +** a88bb75288a06492a04ab1278e8a2101a74f 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.51.0" |
| 469 | 469 | #define SQLITE_VERSION_NUMBER 3051000 |
| 470 | | -#define SQLITE_SOURCE_ID "2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5" |
| 470 | +#define SQLITE_SOURCE_ID "2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d" |
| 471 | 471 | |
| 472 | 472 | /* |
| 473 | 473 | ** CAPI3REF: Run-Time Library Version Numbers |
| 474 | 474 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 475 | 475 | ** |
| | @@ -4396,11 +4396,11 @@ |
| 4396 | 4396 | ** These interfaces are provided for use by [VFS shim] implementations and |
| 4397 | 4397 | ** are not useful outside of that context. |
| 4398 | 4398 | ** |
| 4399 | 4399 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 4400 | 4400 | ** database filename D with corresponding journal file J and WAL file W and |
| 4401 | | -** with N URI parameters key/values pairs in the array P. The result from |
| 4401 | +** an array P of N URI Key/Value pairs. The result from |
| 4402 | 4402 | ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that |
| 4403 | 4403 | ** is safe to pass to routines like: |
| 4404 | 4404 | ** <ul> |
| 4405 | 4405 | ** <li> [sqlite3_uri_parameter()], |
| 4406 | 4406 | ** <li> [sqlite3_uri_boolean()], |
| | @@ -5077,11 +5077,11 @@ |
| 5077 | 5077 | ** KEYWORDS: {host parameter} {host parameters} {host parameter name} |
| 5078 | 5078 | ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} |
| 5079 | 5079 | ** METHOD: sqlite3_stmt |
| 5080 | 5080 | ** |
| 5081 | 5081 | ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, |
| 5082 | | -** literals may be replaced by a [parameter] that matches one of following |
| 5082 | +** literals may be replaced by a [parameter] that matches one of the following |
| 5083 | 5083 | ** templates: |
| 5084 | 5084 | ** |
| 5085 | 5085 | ** <ul> |
| 5086 | 5086 | ** <li> ? |
| 5087 | 5087 | ** <li> ?NNN |
| | @@ -5122,11 +5122,11 @@ |
| 5122 | 5122 | ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16 |
| 5123 | 5123 | ** otherwise. |
| 5124 | 5124 | ** |
| 5125 | 5125 | ** [[byte-order determination rules]] ^The byte-order of |
| 5126 | 5126 | ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF) |
| 5127 | | -** found in first character, which is removed, or in the absence of a BOM |
| 5127 | +** found in the first character, which is removed, or in the absence of a BOM |
| 5128 | 5128 | ** the byte order is the native byte order of the host |
| 5129 | 5129 | ** machine for sqlite3_bind_text16() or the byte order specified in |
| 5130 | 5130 | ** the 6th parameter for sqlite3_bind_text64().)^ |
| 5131 | 5131 | ** ^If UTF16 input text contains invalid unicode |
| 5132 | 5132 | ** characters, then SQLite might change those invalid characters |
| | @@ -5142,11 +5142,11 @@ |
| 5142 | 5142 | ** the behavior is undefined. |
| 5143 | 5143 | ** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
| 5144 | 5144 | ** or sqlite3_bind_text16() or sqlite3_bind_text64() then |
| 5145 | 5145 | ** that parameter must be the byte offset |
| 5146 | 5146 | ** where the NUL terminator would occur assuming the string were NUL |
| 5147 | | -** terminated. If any NUL characters occurs at byte offsets less than |
| 5147 | +** terminated. If any NUL characters occur at byte offsets less than |
| 5148 | 5148 | ** the value of the fourth parameter then the resulting string value will |
| 5149 | 5149 | ** contain embedded NULs. The result of expressions involving strings |
| 5150 | 5150 | ** with embedded NULs is undefined. |
| 5151 | 5151 | ** |
| 5152 | 5152 | ** ^The fifth argument to the BLOB and string binding interfaces controls |
| | @@ -5354,11 +5354,11 @@ |
| 5354 | 5354 | /* |
| 5355 | 5355 | ** CAPI3REF: Source Of Data In A Query Result |
| 5356 | 5356 | ** METHOD: sqlite3_stmt |
| 5357 | 5357 | ** |
| 5358 | 5358 | ** ^These routines provide a means to determine the database, table, and |
| 5359 | | -** table column that is the origin of a particular result column in |
| 5359 | +** table column that is the origin of a particular result column in a |
| 5360 | 5360 | ** [SELECT] statement. |
| 5361 | 5361 | ** ^The name of the database or table or column can be returned as |
| 5362 | 5362 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 5363 | 5363 | ** the database name, the _table_ routines return the table name, and |
| 5364 | 5364 | ** the origin_ routines return the column name. |
| | @@ -5923,12 +5923,12 @@ |
| 5923 | 5923 | ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions, |
| 5924 | 5924 | ** index expressions, or the WHERE clause of partial indexes. |
| 5925 | 5925 | ** |
| 5926 | 5926 | ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for |
| 5927 | 5927 | ** all application-defined SQL functions that do not need to be |
| 5928 | | -** used inside of triggers, view, CHECK constraints, or other elements of |
| 5929 | | -** the database schema. This flags is especially recommended for SQL |
| 5928 | +** used inside of triggers, views, CHECK constraints, or other elements of |
| 5929 | +** the database schema. This flag is especially recommended for SQL |
| 5930 | 5930 | ** functions that have side effects or reveal internal application state. |
| 5931 | 5931 | ** Without this flag, an attacker might be able to modify the schema of |
| 5932 | 5932 | ** a database file to include invocations of the function with parameters |
| 5933 | 5933 | ** chosen by the attacker, which the application will then execute when |
| 5934 | 5934 | ** the database file is opened and read. |
| | @@ -5955,11 +5955,11 @@ |
| 5955 | 5955 | ** or aggregate window function. More details regarding the implementation |
| 5956 | 5956 | ** of aggregate window functions are |
| 5957 | 5957 | ** [user-defined window functions|available here]. |
| 5958 | 5958 | ** |
| 5959 | 5959 | ** ^(If the final parameter to sqlite3_create_function_v2() or |
| 5960 | | -** sqlite3_create_window_function() is not NULL, then it is destructor for |
| 5960 | +** sqlite3_create_window_function() is not NULL, then it is the destructor for |
| 5961 | 5961 | ** the application data pointer. The destructor is invoked when the function |
| 5962 | 5962 | ** is deleted, either by being overloaded or when the database connection |
| 5963 | 5963 | ** closes.)^ ^The destructor is also invoked if the call to |
| 5964 | 5964 | ** sqlite3_create_function_v2() fails. ^When the destructor callback is |
| 5965 | 5965 | ** invoked, it is passed a single argument which is a copy of the application |
| | @@ -7763,11 +7763,11 @@ |
| 7763 | 7763 | ** that is to be automatically loaded into all new database connections. |
| 7764 | 7764 | ** |
| 7765 | 7765 | ** ^(Even though the function prototype shows that xEntryPoint() takes |
| 7766 | 7766 | ** no arguments and returns void, SQLite invokes xEntryPoint() with three |
| 7767 | 7767 | ** arguments and expects an integer result as if the signature of the |
| 7768 | | -** entry point where as follows: |
| 7768 | +** entry point were as follows: |
| 7769 | 7769 | ** |
| 7770 | 7770 | ** <blockquote><pre> |
| 7771 | 7771 | ** int xEntryPoint( |
| 7772 | 7772 | ** sqlite3 *db, |
| 7773 | 7773 | ** const char **pzErrMsg, |
| | @@ -8094,11 +8094,11 @@ |
| 8094 | 8094 | ** by the first parameter. ^The name of the module is given by the |
| 8095 | 8095 | ** second parameter. ^The third parameter is a pointer to |
| 8096 | 8096 | ** the implementation of the [virtual table module]. ^The fourth |
| 8097 | 8097 | ** parameter is an arbitrary client data pointer that is passed through |
| 8098 | 8098 | ** into the [xCreate] and [xConnect] methods of the virtual table module |
| 8099 | | -** when a new virtual table is be being created or reinitialized. |
| 8099 | +** when a new virtual table is being created or reinitialized. |
| 8100 | 8100 | ** |
| 8101 | 8101 | ** ^The sqlite3_create_module_v2() interface has a fifth parameter which |
| 8102 | 8102 | ** is a pointer to a destructor for the pClientData. ^SQLite will |
| 8103 | 8103 | ** invoke the destructor function (if it is not NULL) when SQLite |
| 8104 | 8104 | ** no longer needs the pClientData pointer. ^The destructor will also |
| | @@ -8259,11 +8259,11 @@ |
| 8259 | 8259 | ** |
| 8260 | 8260 | ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored |
| 8261 | 8261 | ** in *ppBlob. Otherwise an [error code] is returned and, unless the error |
| 8262 | 8262 | ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided |
| 8263 | 8263 | ** the API is not misused, it is always safe to call [sqlite3_blob_close()] |
| 8264 | | -** on *ppBlob after this function it returns. |
| 8264 | +** on *ppBlob after this function returns. |
| 8265 | 8265 | ** |
| 8266 | 8266 | ** This function fails with SQLITE_ERROR if any of the following are true: |
| 8267 | 8267 | ** <ul> |
| 8268 | 8268 | ** <li> ^(Database zDb does not exist)^, |
| 8269 | 8269 | ** <li> ^(Table zTable does not exist within database zDb)^, |
| | @@ -8379,11 +8379,11 @@ |
| 8379 | 8379 | ** CAPI3REF: Return The Size Of An Open BLOB |
| 8380 | 8380 | ** METHOD: sqlite3_blob |
| 8381 | 8381 | ** |
| 8382 | 8382 | ** ^Returns the size in bytes of the BLOB accessible via the |
| 8383 | 8383 | ** successfully opened [BLOB handle] in its only argument. ^The |
| 8384 | | -** incremental blob I/O routines can only read or overwriting existing |
| 8384 | +** incremental blob I/O routines can only read or overwrite existing |
| 8385 | 8385 | ** blob content; they cannot change the size of a blob. |
| 8386 | 8386 | ** |
| 8387 | 8387 | ** This routine only works on a [BLOB handle] which has been created |
| 8388 | 8388 | ** by a prior successful call to [sqlite3_blob_open()] and which has not |
| 8389 | 8389 | ** been closed by [sqlite3_blob_close()]. Passing any other pointer in |
| | @@ -9782,11 +9782,11 @@ |
| 9782 | 9782 | ** sqlite3_backup_step(), the source database may be modified mid-way |
| 9783 | 9783 | ** through the backup process. ^If the source database is modified by an |
| 9784 | 9784 | ** external process or via a database connection other than the one being |
| 9785 | 9785 | ** used by the backup operation, then the backup will be automatically |
| 9786 | 9786 | ** restarted by the next call to sqlite3_backup_step(). ^If the source |
| 9787 | | -** database is modified by the using the same database connection as is used |
| 9787 | +** database is modified by using the same database connection as is used |
| 9788 | 9788 | ** by the backup operation, then the backup database is automatically |
| 9789 | 9789 | ** updated at the same time. |
| 9790 | 9790 | ** |
| 9791 | 9791 | ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> |
| 9792 | 9792 | ** |
| | @@ -9799,11 +9799,11 @@ |
| 9799 | 9799 | ** active write-transaction on the destination database is rolled back. |
| 9800 | 9800 | ** The [sqlite3_backup] object is invalid |
| 9801 | 9801 | ** and may not be used following a call to sqlite3_backup_finish(). |
| 9802 | 9802 | ** |
| 9803 | 9803 | ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no |
| 9804 | | -** sqlite3_backup_step() errors occurred, regardless or whether or not |
| 9804 | +** sqlite3_backup_step() errors occurred, regardless of whether or not |
| 9805 | 9805 | ** sqlite3_backup_step() completed. |
| 9806 | 9806 | ** ^If an out-of-memory condition or IO error occurred during any prior |
| 9807 | 9807 | ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then |
| 9808 | 9808 | ** sqlite3_backup_finish() returns the corresponding [error code]. |
| 9809 | 9809 | ** |
| | @@ -10869,11 +10869,11 @@ |
| 10869 | 10869 | /* |
| 10870 | 10870 | ** CAPI3REF: Flush caches to disk mid-transaction |
| 10871 | 10871 | ** METHOD: sqlite3 |
| 10872 | 10872 | ** |
| 10873 | 10873 | ** ^If a write-transaction is open on [database connection] D when the |
| 10874 | | -** [sqlite3_db_cacheflush(D)] interface invoked, any dirty |
| 10874 | +** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty |
| 10875 | 10875 | ** pages in the pager-cache that are not currently in use are written out |
| 10876 | 10876 | ** to disk. A dirty page may be in use if a database cursor created by an |
| 10877 | 10877 | ** active SQL statement is reading from it, or if it is page 1 of a database |
| 10878 | 10878 | ** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)] |
| 10879 | 10879 | ** interface flushes caches for all schemas - "main", "temp", and |
| | @@ -15562,10 +15562,11 @@ |
| 15562 | 15562 | ** 0x00008000 After all FROM-clause analysis |
| 15563 | 15563 | ** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing |
| 15564 | 15564 | ** 0x00020000 Transform DISTINCT into GROUP BY |
| 15565 | 15565 | ** 0x00040000 SELECT tree dump after all code has been generated |
| 15566 | 15566 | ** 0x00080000 NOT NULL strength reduction |
| 15567 | +** 0x00100000 Pointers are all shown as zero |
| 15567 | 15568 | */ |
| 15568 | 15569 | |
| 15569 | 15570 | /* |
| 15570 | 15571 | ** Macros for "wheretrace" |
| 15571 | 15572 | */ |
| | @@ -15606,10 +15607,11 @@ |
| 15606 | 15607 | ** |
| 15607 | 15608 | ** 0x00010000 Show more detail when printing WHERE terms |
| 15608 | 15609 | ** 0x00020000 Show WHERE terms returned from whereScanNext() |
| 15609 | 15610 | ** 0x00040000 Solver overview messages |
| 15610 | 15611 | ** 0x00080000 Star-query heuristic |
| 15612 | +** 0x00100000 Pointers are all shown as zero |
| 15611 | 15613 | */ |
| 15612 | 15614 | |
| 15613 | 15615 | |
| 15614 | 15616 | /* |
| 15615 | 15617 | ** An instance of the following structure is used to store the busy-handler |
| | @@ -15678,11 +15680,11 @@ |
| 15678 | 15680 | ** one parameter that destructors normally want. So we have to introduce |
| 15679 | 15681 | ** this magic value that the code knows to handle differently. Any |
| 15680 | 15682 | ** pointer will work here as long as it is distinct from SQLITE_STATIC |
| 15681 | 15683 | ** and SQLITE_TRANSIENT. |
| 15682 | 15684 | */ |
| 15683 | | -#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3OomClear) |
| 15685 | +#define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3RowSetClear) |
| 15684 | 15686 | |
| 15685 | 15687 | /* |
| 15686 | 15688 | ** When SQLITE_OMIT_WSD is defined, it means that the target platform does |
| 15687 | 15689 | ** not support Writable Static Data (WSD) such as global and static variables. |
| 15688 | 15690 | ** All variables must either be on the stack or dynamically allocated from |
| | @@ -21266,10 +21268,11 @@ |
| 21266 | 21268 | #endif |
| 21267 | 21269 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 21268 | 21270 | SQLITE_PRIVATE void sqlite3ShowWindow(const Window*); |
| 21269 | 21271 | SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*); |
| 21270 | 21272 | #endif |
| 21273 | +SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec*); |
| 21271 | 21274 | #endif |
| 21272 | 21275 | |
| 21273 | 21276 | SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); |
| 21274 | 21277 | SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*); |
| 21275 | 21278 | SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); |
| | @@ -32077,10 +32080,18 @@ |
| 32077 | 32080 | }else{ |
| 32078 | 32081 | longvalue = va_arg(ap,unsigned int); |
| 32079 | 32082 | } |
| 32080 | 32083 | prefix = 0; |
| 32081 | 32084 | } |
| 32085 | + |
| 32086 | +#if WHERETRACE_ENABLED |
| 32087 | + if( xtype==etPOINTER && sqlite3WhereTrace & 0x100000 ) longvalue = 0; |
| 32088 | +#endif |
| 32089 | +#if TREETRACE_ENABLED |
| 32090 | + if( xtype==etPOINTER && sqlite3TreeTrace & 0x100000 ) longvalue = 0; |
| 32091 | +#endif |
| 32092 | + |
| 32082 | 32093 | if( longvalue==0 ) flag_alternateform = 0; |
| 32083 | 32094 | if( flag_zeropad && precision<width-(prefix!=0) ){ |
| 32084 | 32095 | precision = width-(prefix!=0); |
| 32085 | 32096 | } |
| 32086 | 32097 | if( precision<etBUFSIZE-10-etBUFSIZE/3 ){ |
| | @@ -54868,10 +54879,11 @@ |
| 54868 | 54879 | BITVEC_TELEM aBitmap[BITVEC_NELEM]; /* Bitmap representation */ |
| 54869 | 54880 | u32 aHash[BITVEC_NINT]; /* Hash table representation */ |
| 54870 | 54881 | Bitvec *apSub[BITVEC_NPTR]; /* Recursive representation */ |
| 54871 | 54882 | } u; |
| 54872 | 54883 | }; |
| 54884 | + |
| 54873 | 54885 | |
| 54874 | 54886 | /* |
| 54875 | 54887 | ** Create a new bitmap object able to handle bits between 0 and iSize, |
| 54876 | 54888 | ** inclusive. Return a pointer to the new object. Return NULL if |
| 54877 | 54889 | ** malloc fails. |
| | @@ -54978,11 +54990,13 @@ |
| 54978 | 54990 | if( aiValues==0 ){ |
| 54979 | 54991 | return SQLITE_NOMEM_BKPT; |
| 54980 | 54992 | }else{ |
| 54981 | 54993 | memcpy(aiValues, p->u.aHash, sizeof(p->u.aHash)); |
| 54982 | 54994 | memset(p->u.apSub, 0, sizeof(p->u.apSub)); |
| 54983 | | - p->iDivisor = (p->iSize + BITVEC_NPTR - 1)/BITVEC_NPTR; |
| 54995 | + p->iDivisor = p->iSize/BITVEC_NPTR; |
| 54996 | + if( (p->iSize%BITVEC_NPTR)!=0 ) p->iDivisor++; |
| 54997 | + if( p->iDivisor<BITVEC_NBIT ) p->iDivisor = BITVEC_NBIT; |
| 54984 | 54998 | rc = sqlite3BitvecSet(p, i); |
| 54985 | 54999 | for(j=0; j<BITVEC_NINT; j++){ |
| 54986 | 55000 | if( aiValues[j] ) rc |= sqlite3BitvecSet(p, aiValues[j]); |
| 54987 | 55001 | } |
| 54988 | 55002 | sqlite3StackFree(0, aiValues); |
| | @@ -55054,10 +55068,56 @@ |
| 55054 | 55068 | ** was created. |
| 55055 | 55069 | */ |
| 55056 | 55070 | SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){ |
| 55057 | 55071 | return p->iSize; |
| 55058 | 55072 | } |
| 55073 | + |
| 55074 | +#ifdef SQLITE_DEBUG |
| 55075 | +/* |
| 55076 | +** Show the content of a Bitvec option and its children. Indent |
| 55077 | +** everything by n spaces. Add x to each bitvec value. |
| 55078 | +** |
| 55079 | +** From a debugger such as gdb, one can type: |
| 55080 | +** |
| 55081 | +** call sqlite3ShowBitvec(p) |
| 55082 | +** |
| 55083 | +** For some Bitvec p and see a recursive view of the Bitvec's content. |
| 55084 | +*/ |
| 55085 | +static void showBitvec(Bitvec *p, int n, unsigned x){ |
| 55086 | + int i; |
| 55087 | + if( p==0 ){ |
| 55088 | + printf("NULL\n"); |
| 55089 | + return; |
| 55090 | + } |
| 55091 | + printf("Bitvec 0x%p iSize=%u", p, p->iSize); |
| 55092 | + if( p->iSize<=BITVEC_NBIT ){ |
| 55093 | + printf(" bitmap\n"); |
| 55094 | + printf("%*s bits:", n, ""); |
| 55095 | + for(i=1; i<=BITVEC_NBIT; i++){ |
| 55096 | + if( sqlite3BitvecTest(p,i) ) printf(" %u", x+(unsigned)i); |
| 55097 | + } |
| 55098 | + printf("\n"); |
| 55099 | + }else if( p->iDivisor==0 ){ |
| 55100 | + printf(" hash with %u entries\n", p->nSet); |
| 55101 | + printf("%*s bits:", n, ""); |
| 55102 | + for(i=0; i<BITVEC_NINT; i++){ |
| 55103 | + if( p->u.aHash[i] ) printf(" %u", x+(unsigned)p->u.aHash[i]); |
| 55104 | + } |
| 55105 | + printf("\n"); |
| 55106 | + }else{ |
| 55107 | + printf(" sub-bitvec with iDivisor=%u\n", p->iDivisor); |
| 55108 | + for(i=0; i<BITVEC_NPTR; i++){ |
| 55109 | + if( p->u.apSub[i]==0 ) continue; |
| 55110 | + printf("%*s apSub[%d]=", n, "", i); |
| 55111 | + showBitvec(p->u.apSub[i], n+4, i*p->iDivisor); |
| 55112 | + } |
| 55113 | + } |
| 55114 | +} |
| 55115 | +SQLITE_PRIVATE void sqlite3ShowBitvec(Bitvec *p){ |
| 55116 | + showBitvec(p, 0, 0); |
| 55117 | +} |
| 55118 | +#endif |
| 55059 | 55119 | |
| 55060 | 55120 | #ifndef SQLITE_UNTESTABLE |
| 55061 | 55121 | /* |
| 55062 | 55122 | ** Let V[] be an array of unsigned characters sufficient to hold |
| 55063 | 55123 | ** up to N bits. Let I be an integer between 0 and N. 0<=I<N. |
| | @@ -55065,40 +55125,48 @@ |
| 55065 | 55125 | ** individual bits within V. |
| 55066 | 55126 | */ |
| 55067 | 55127 | #define SETBIT(V,I) V[I>>3] |= (1<<(I&7)) |
| 55068 | 55128 | #define CLEARBIT(V,I) V[I>>3] &= ~(BITVEC_TELEM)(1<<(I&7)) |
| 55069 | 55129 | #define TESTBIT(V,I) (V[I>>3]&(1<<(I&7)))!=0 |
| 55130 | + |
| 55070 | 55131 | |
| 55071 | 55132 | /* |
| 55072 | 55133 | ** This routine runs an extensive test of the Bitvec code. |
| 55073 | 55134 | ** |
| 55074 | 55135 | ** The input is an array of integers that acts as a program |
| 55075 | 55136 | ** to test the Bitvec. The integers are opcodes followed |
| 55076 | 55137 | ** by 0, 1, or 3 operands, depending on the opcode. Another |
| 55077 | 55138 | ** opcode follows immediately after the last operand. |
| 55078 | 55139 | ** |
| 55079 | | -** There are 6 opcodes numbered from 0 through 5. 0 is the |
| 55140 | +** There are opcodes numbered starting with 0. 0 is the |
| 55080 | 55141 | ** "halt" opcode and causes the test to end. |
| 55081 | 55142 | ** |
| 55082 | 55143 | ** 0 Halt and return the number of errors |
| 55083 | 55144 | ** 1 N S X Set N bits beginning with S and incrementing by X |
| 55084 | 55145 | ** 2 N S X Clear N bits beginning with S and incrementing by X |
| 55085 | 55146 | ** 3 N Set N randomly chosen bits |
| 55086 | 55147 | ** 4 N Clear N randomly chosen bits |
| 55087 | 55148 | ** 5 N S X Set N bits from S increment X in array only, not in bitvec |
| 55149 | +** 6 Invoice sqlite3ShowBitvec() on the Bitvec object so far |
| 55150 | +** 7 X Show compile-time parameters and the hash of X |
| 55088 | 55151 | ** |
| 55089 | 55152 | ** The opcodes 1 through 4 perform set and clear operations are performed |
| 55090 | 55153 | ** on both a Bitvec object and on a linear array of bits obtained from malloc. |
| 55091 | 55154 | ** Opcode 5 works on the linear array only, not on the Bitvec. |
| 55092 | 55155 | ** Opcode 5 is used to deliberately induce a fault in order to |
| 55093 | | -** confirm that error detection works. |
| 55156 | +** confirm that error detection works. Opcodes 6 and greater are |
| 55157 | +** state output opcodes. Opcodes 6 and greater are no-ops unless |
| 55158 | +** SQLite has been compiled with SQLITE_DEBUG. |
| 55094 | 55159 | ** |
| 55095 | 55160 | ** At the conclusion of the test the linear array is compared |
| 55096 | 55161 | ** against the Bitvec object. If there are any differences, |
| 55097 | 55162 | ** an error is returned. If they are the same, zero is returned. |
| 55098 | 55163 | ** |
| 55099 | 55164 | ** If a memory allocation error occurs, return -1. |
| 55165 | +** |
| 55166 | +** sz is the size of the Bitvec. Or if sz is negative, make the size |
| 55167 | +** 2*(unsigned)(-sz) and disabled the linear vector check. |
| 55100 | 55168 | */ |
| 55101 | 55169 | SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int sz, int *aOp){ |
| 55102 | 55170 | Bitvec *pBitvec = 0; |
| 55103 | 55171 | unsigned char *pV = 0; |
| 55104 | 55172 | int rc = -1; |
| | @@ -55105,22 +55173,45 @@ |
| 55105 | 55173 | int i, nx, pc, op; |
| 55106 | 55174 | void *pTmpSpace; |
| 55107 | 55175 | |
| 55108 | 55176 | /* Allocate the Bitvec to be tested and a linear array of |
| 55109 | 55177 | ** bits to act as the reference */ |
| 55110 | | - pBitvec = sqlite3BitvecCreate( sz ); |
| 55111 | | - pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 ); |
| 55178 | + if( sz<=0 ){ |
| 55179 | + pBitvec = sqlite3BitvecCreate( 2*(unsigned)(-sz) ); |
| 55180 | + pV = 0; |
| 55181 | + }else{ |
| 55182 | + pBitvec = sqlite3BitvecCreate( sz ); |
| 55183 | + pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 ); |
| 55184 | + } |
| 55112 | 55185 | pTmpSpace = sqlite3_malloc64(BITVEC_SZ); |
| 55113 | | - if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; |
| 55186 | + if( pBitvec==0 || pTmpSpace==0 || (pV==0 && sz>0) ) goto bitvec_end; |
| 55114 | 55187 | |
| 55115 | 55188 | /* NULL pBitvec tests */ |
| 55116 | 55189 | sqlite3BitvecSet(0, 1); |
| 55117 | 55190 | sqlite3BitvecClear(0, 1, pTmpSpace); |
| 55118 | 55191 | |
| 55119 | 55192 | /* Run the program */ |
| 55120 | 55193 | pc = i = 0; |
| 55121 | 55194 | while( (op = aOp[pc])!=0 ){ |
| 55195 | + if( op>=6 ){ |
| 55196 | +#ifdef SQLITE_DEBUG |
| 55197 | + if( op==6 ){ |
| 55198 | + sqlite3ShowBitvec(pBitvec); |
| 55199 | + }else if( op==7 ){ |
| 55200 | + printf("BITVEC_SZ = %d (%d by sizeof)\n", |
| 55201 | + BITVEC_SZ, (int)sizeof(Bitvec)); |
| 55202 | + printf("BITVEC_USIZE = %d\n", (int)BITVEC_USIZE); |
| 55203 | + printf("BITVEC_NELEM = %d\n", (int)BITVEC_NELEM); |
| 55204 | + printf("BITVEC_NBIT = %d\n", (int)BITVEC_NBIT); |
| 55205 | + printf("BITVEC_NINT = %d\n", (int)BITVEC_NINT); |
| 55206 | + printf("BITVEC_MXHASH = %d\n", (int)BITVEC_MXHASH); |
| 55207 | + printf("BITVEC_NPTR = %d\n", (int)BITVEC_NPTR); |
| 55208 | + } |
| 55209 | +#endif |
| 55210 | + pc++; |
| 55211 | + continue; |
| 55212 | + } |
| 55122 | 55213 | switch( op ){ |
| 55123 | 55214 | case 1: |
| 55124 | 55215 | case 2: |
| 55125 | 55216 | case 5: { |
| 55126 | 55217 | nx = 4; |
| | @@ -55138,33 +55229,37 @@ |
| 55138 | 55229 | } |
| 55139 | 55230 | if( (--aOp[pc+1]) > 0 ) nx = 0; |
| 55140 | 55231 | pc += nx; |
| 55141 | 55232 | i = (i & 0x7fffffff)%sz; |
| 55142 | 55233 | if( (op & 1)!=0 ){ |
| 55143 | | - SETBIT(pV, (i+1)); |
| 55234 | + if( pV ) SETBIT(pV, (i+1)); |
| 55144 | 55235 | if( op!=5 ){ |
| 55145 | 55236 | if( sqlite3BitvecSet(pBitvec, i+1) ) goto bitvec_end; |
| 55146 | 55237 | } |
| 55147 | 55238 | }else{ |
| 55148 | | - CLEARBIT(pV, (i+1)); |
| 55239 | + if( pV ) CLEARBIT(pV, (i+1)); |
| 55149 | 55240 | sqlite3BitvecClear(pBitvec, i+1, pTmpSpace); |
| 55150 | 55241 | } |
| 55151 | 55242 | } |
| 55152 | 55243 | |
| 55153 | 55244 | /* Test to make sure the linear array exactly matches the |
| 55154 | 55245 | ** Bitvec object. Start with the assumption that they do |
| 55155 | 55246 | ** match (rc==0). Change rc to non-zero if a discrepancy |
| 55156 | 55247 | ** is found. |
| 55157 | 55248 | */ |
| 55158 | | - rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1) |
| 55159 | | - + sqlite3BitvecTest(pBitvec, 0) |
| 55160 | | - + (sqlite3BitvecSize(pBitvec) - sz); |
| 55161 | | - for(i=1; i<=sz; i++){ |
| 55162 | | - if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){ |
| 55163 | | - rc = i; |
| 55164 | | - break; |
| 55165 | | - } |
| 55249 | + if( pV ){ |
| 55250 | + rc = sqlite3BitvecTest(0,0) + sqlite3BitvecTest(pBitvec, sz+1) |
| 55251 | + + sqlite3BitvecTest(pBitvec, 0) |
| 55252 | + + (sqlite3BitvecSize(pBitvec) - sz); |
| 55253 | + for(i=1; i<=sz; i++){ |
| 55254 | + if( (TESTBIT(pV,i))!=sqlite3BitvecTest(pBitvec,i) ){ |
| 55255 | + rc = i; |
| 55256 | + break; |
| 55257 | + } |
| 55258 | + } |
| 55259 | + }else{ |
| 55260 | + rc = 0; |
| 55166 | 55261 | } |
| 55167 | 55262 | |
| 55168 | 55263 | /* Free allocated structure */ |
| 55169 | 55264 | bitvec_end: |
| 55170 | 55265 | sqlite3_free(pTmpSpace); |
| | @@ -69666,10 +69761,11 @@ |
| 69666 | 69761 | rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame)); |
| 69667 | 69762 | } |
| 69668 | 69763 | if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal); |
| 69669 | 69764 | } |
| 69670 | 69765 | SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; ) |
| 69766 | + pWal->iReCksum = 0; |
| 69671 | 69767 | } |
| 69672 | 69768 | return rc; |
| 69673 | 69769 | } |
| 69674 | 69770 | |
| 69675 | 69771 | /* |
| | @@ -69713,10 +69809,13 @@ |
| 69713 | 69809 | pWal->hdr.aFrameCksum[1] = aWalData[2]; |
| 69714 | 69810 | SEH_TRY { |
| 69715 | 69811 | walCleanupHash(pWal); |
| 69716 | 69812 | } |
| 69717 | 69813 | SEH_EXCEPT( rc = SQLITE_IOERR_IN_PAGE; ) |
| 69814 | + if( pWal->iReCksum>pWal->hdr.mxFrame ){ |
| 69815 | + pWal->iReCksum = 0; |
| 69816 | + } |
| 69718 | 69817 | } |
| 69719 | 69818 | |
| 69720 | 69819 | return rc; |
| 69721 | 69820 | } |
| 69722 | 69821 | |
| | @@ -77438,12 +77537,12 @@ |
| 77438 | 77537 | assert( (pCur->curFlags & BTCF_ValidOvfl)==0 ); |
| 77439 | 77538 | return rc; |
| 77440 | 77539 | } |
| 77441 | 77540 | |
| 77442 | 77541 | /* |
| 77443 | | -** Compare the "idx"-th cell on the page the cursor pCur is currently |
| 77444 | | -** pointing to to pIdxKey using xRecordCompare. Return negative or |
| 77542 | +** Compare the "idx"-th cell on the page pPage against the key |
| 77543 | +** pointing to by pIdxKey using xRecordCompare. Return negative or |
| 77445 | 77544 | ** zero if the cell is less than or equal pIdxKey. Return positive |
| 77446 | 77545 | ** if unknown. |
| 77447 | 77546 | ** |
| 77448 | 77547 | ** Return value negative: Cell at pCur[idx] less than pIdxKey |
| 77449 | 77548 | ** |
| | @@ -77454,16 +77553,15 @@ |
| 77454 | 77553 | ** |
| 77455 | 77554 | ** This routine is part of an optimization. It is always safe to return |
| 77456 | 77555 | ** a positive value as that will cause the optimization to be skipped. |
| 77457 | 77556 | */ |
| 77458 | 77557 | static int indexCellCompare( |
| 77459 | | - BtCursor *pCur, |
| 77558 | + MemPage *pPage, |
| 77460 | 77559 | int idx, |
| 77461 | 77560 | UnpackedRecord *pIdxKey, |
| 77462 | 77561 | RecordCompare xRecordCompare |
| 77463 | 77562 | ){ |
| 77464 | | - MemPage *pPage = pCur->pPage; |
| 77465 | 77563 | int c; |
| 77466 | 77564 | int nCell; /* Size of the pCell cell in bytes */ |
| 77467 | 77565 | u8 *pCell = findCellPastPtr(pPage, idx); |
| 77468 | 77566 | |
| 77469 | 77567 | nCell = pCell[0]; |
| | @@ -77568,18 +77666,18 @@ |
| 77568 | 77666 | && pCur->pPage->leaf |
| 77569 | 77667 | && cursorOnLastPage(pCur) |
| 77570 | 77668 | ){ |
| 77571 | 77669 | int c; |
| 77572 | 77670 | if( pCur->ix==pCur->pPage->nCell-1 |
| 77573 | | - && (c = indexCellCompare(pCur, pCur->ix, pIdxKey, xRecordCompare))<=0 |
| 77671 | + && (c = indexCellCompare(pCur->pPage,pCur->ix,pIdxKey,xRecordCompare))<=0 |
| 77574 | 77672 | && pIdxKey->errCode==SQLITE_OK |
| 77575 | 77673 | ){ |
| 77576 | 77674 | *pRes = c; |
| 77577 | 77675 | return SQLITE_OK; /* Cursor already pointing at the correct spot */ |
| 77578 | 77676 | } |
| 77579 | 77677 | if( pCur->iPage>0 |
| 77580 | | - && indexCellCompare(pCur, 0, pIdxKey, xRecordCompare)<=0 |
| 77678 | + && indexCellCompare(pCur->pPage, 0, pIdxKey, xRecordCompare)<=0 |
| 77581 | 77679 | && pIdxKey->errCode==SQLITE_OK |
| 77582 | 77680 | ){ |
| 77583 | 77681 | pCur->curFlags &= ~(BTCF_ValidOvfl|BTCF_AtLast); |
| 77584 | 77682 | if( !pCur->pPage->isInit ){ |
| 77585 | 77683 | return SQLITE_CORRUPT_BKPT; |
| | @@ -77792,11 +77890,11 @@ |
| 77792 | 77890 | if( pCur->eState!=CURSOR_VALID ) return 0; |
| 77793 | 77891 | if( NEVER(pCur->pPage->leaf==0) ) return -1; |
| 77794 | 77892 | |
| 77795 | 77893 | n = pCur->pPage->nCell; |
| 77796 | 77894 | for(i=0; i<pCur->iPage; i++){ |
| 77797 | | - n *= pCur->apPage[i]->nCell; |
| 77895 | + n *= pCur->apPage[i]->nCell+1; |
| 77798 | 77896 | } |
| 77799 | 77897 | return n; |
| 77800 | 77898 | } |
| 77801 | 77899 | |
| 77802 | 77900 | /* |
| | @@ -97577,10 +97675,19 @@ |
| 97577 | 97675 | ** Synopsis: typecheck(r[P1@P2]) |
| 97578 | 97676 | ** |
| 97579 | 97677 | ** Apply affinities to the range of P2 registers beginning with P1. |
| 97580 | 97678 | ** Take the affinities from the Table object in P4. If any value |
| 97581 | 97679 | ** cannot be coerced into the correct type, then raise an error. |
| 97680 | +** |
| 97681 | +** If P3==0, then omit checking of VIRTUAL columns. |
| 97682 | +** |
| 97683 | +** If P3==1, then omit checking of all generated column, both VIRTUAL |
| 97684 | +** and STORED. |
| 97685 | +** |
| 97686 | +** If P3>=2, then only check column number P3-2 in the table (which will |
| 97687 | +** be a VIRTUAL column) against the value in reg[P1]. In this case, |
| 97688 | +** P2 will be 1. |
| 97582 | 97689 | ** |
| 97583 | 97690 | ** This opcode is similar to OP_Affinity except that this opcode |
| 97584 | 97691 | ** forces the register type to the Table column type. This is used |
| 97585 | 97692 | ** to implement "strict affinity". |
| 97586 | 97693 | ** |
| | @@ -97591,30 +97698,42 @@ |
| 97591 | 97698 | ** |
| 97592 | 97699 | ** Preconditions: |
| 97593 | 97700 | ** |
| 97594 | 97701 | ** <ul> |
| 97595 | 97702 | ** <li> P2 should be the number of non-virtual columns in the |
| 97596 | | -** table of P4. |
| 97597 | | -** <li> Table P4 should be a STRICT table. |
| 97703 | +** table of P4 unless P3>1, in which case P2 will be 1. |
| 97704 | +** <li> Table P4 is a STRICT table. |
| 97598 | 97705 | ** </ul> |
| 97599 | 97706 | ** |
| 97600 | 97707 | ** If any precondition is false, an assertion fault occurs. |
| 97601 | 97708 | */ |
| 97602 | 97709 | case OP_TypeCheck: { |
| 97603 | 97710 | Table *pTab; |
| 97604 | 97711 | Column *aCol; |
| 97605 | 97712 | int i; |
| 97713 | + int nCol; |
| 97606 | 97714 | |
| 97607 | 97715 | assert( pOp->p4type==P4_TABLE ); |
| 97608 | 97716 | pTab = pOp->p4.pTab; |
| 97609 | 97717 | assert( pTab->tabFlags & TF_Strict ); |
| 97610 | | - assert( pTab->nNVCol==pOp->p2 ); |
| 97718 | + assert( pOp->p3>=0 && pOp->p3<pTab->nCol+2 ); |
| 97611 | 97719 | aCol = pTab->aCol; |
| 97612 | 97720 | pIn1 = &aMem[pOp->p1]; |
| 97613 | | - for(i=0; i<pTab->nCol; i++){ |
| 97614 | | - if( aCol[i].colFlags & COLFLAG_GENERATED ){ |
| 97615 | | - if( aCol[i].colFlags & COLFLAG_VIRTUAL ) continue; |
| 97721 | + if( pOp->p3<2 ){ |
| 97722 | + assert( pTab->nNVCol==pOp->p2 ); |
| 97723 | + i = 0; |
| 97724 | + nCol = pTab->nCol; |
| 97725 | + }else{ |
| 97726 | + i = pOp->p3-2; |
| 97727 | + nCol = i+1; |
| 97728 | + assert( i<pTab->nCol ); |
| 97729 | + assert( aCol[i].colFlags & COLFLAG_VIRTUAL ); |
| 97730 | + assert( pOp->p2==1 ); |
| 97731 | + } |
| 97732 | + for(; i<nCol; i++){ |
| 97733 | + if( (aCol[i].colFlags & COLFLAG_GENERATED)!=0 && pOp->p3<2 ){ |
| 97734 | + if( (aCol[i].colFlags & COLFLAG_VIRTUAL)!=0 ) continue; |
| 97616 | 97735 | if( pOp->p3 ){ pIn1++; continue; } |
| 97617 | 97736 | } |
| 97618 | 97737 | assert( pIn1 < &aMem[pOp->p1+pOp->p2] ); |
| 97619 | 97738 | applyAffinity(pIn1, aCol[i].affinity, encoding); |
| 97620 | 97739 | if( (pIn1->flags & MEM_Null)==0 ){ |
| | @@ -114622,11 +114741,16 @@ |
| 114622 | 114741 | iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut); |
| 114623 | 114742 | }else{ |
| 114624 | 114743 | iAddr = 0; |
| 114625 | 114744 | } |
| 114626 | 114745 | sqlite3ExprCodeCopy(pParse, sqlite3ColumnExpr(pTab,pCol), regOut); |
| 114627 | | - if( pCol->affinity>=SQLITE_AFF_TEXT ){ |
| 114746 | + if( (pCol->colFlags & COLFLAG_VIRTUAL)!=0 |
| 114747 | + && (pTab->tabFlags & TF_Strict)!=0 |
| 114748 | + ){ |
| 114749 | + int p3 = 2+(int)(pCol - pTab->aCol); |
| 114750 | + sqlite3VdbeAddOp4(v, OP_TypeCheck, regOut, 1, p3, (char*)pTab, P4_TABLE); |
| 114751 | + }else if( pCol->affinity>=SQLITE_AFF_TEXT ){ |
| 114628 | 114752 | sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1); |
| 114629 | 114753 | } |
| 114630 | 114754 | if( iAddr ) sqlite3VdbeJumpHere(v, iAddr); |
| 114631 | 114755 | if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1; |
| 114632 | 114756 | } |
| | @@ -132016,11 +132140,11 @@ |
| 132016 | 132140 | int argc, |
| 132017 | 132141 | sqlite3_value **argv, |
| 132018 | 132142 | int nSep, |
| 132019 | 132143 | const char *zSep |
| 132020 | 132144 | ){ |
| 132021 | | - i64 j, k, n = 0; |
| 132145 | + i64 j, n = 0; |
| 132022 | 132146 | int i; |
| 132023 | 132147 | char *z; |
| 132024 | 132148 | for(i=0; i<argc; i++){ |
| 132025 | 132149 | n += sqlite3_value_bytes(argv[i]); |
| 132026 | 132150 | } |
| | @@ -132030,12 +132154,12 @@ |
| 132030 | 132154 | sqlite3_result_error_nomem(context); |
| 132031 | 132155 | return; |
| 132032 | 132156 | } |
| 132033 | 132157 | j = 0; |
| 132034 | 132158 | for(i=0; i<argc; i++){ |
| 132035 | | - k = sqlite3_value_bytes(argv[i]); |
| 132036 | | - if( k>0 ){ |
| 132159 | + if( sqlite3_value_type(argv[i])!=SQLITE_NULL ){ |
| 132160 | + int k = sqlite3_value_bytes(argv[i]); |
| 132037 | 132161 | const char *v = (const char*)sqlite3_value_text(argv[i]); |
| 132038 | 132162 | if( v!=0 ){ |
| 132039 | 132163 | if( j>0 && nSep>0 ){ |
| 132040 | 132164 | memcpy(&z[j], zSep, nSep); |
| 132041 | 132165 | j += nSep; |
| | @@ -134969,16 +135093,19 @@ |
| 134969 | 135093 | if( iReg==0 ){ |
| 134970 | 135094 | /* Move the previous opcode (which should be OP_MakeRecord) forward |
| 134971 | 135095 | ** by one slot and insert a new OP_TypeCheck where the current |
| 134972 | 135096 | ** OP_MakeRecord is found */ |
| 134973 | 135097 | VdbeOp *pPrev; |
| 135098 | + int p3; |
| 134974 | 135099 | sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 134975 | 135100 | pPrev = sqlite3VdbeGetLastOp(v); |
| 134976 | 135101 | assert( pPrev!=0 ); |
| 134977 | 135102 | assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed ); |
| 134978 | 135103 | pPrev->opcode = OP_TypeCheck; |
| 134979 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3); |
| 135104 | + p3 = pPrev->p3; |
| 135105 | + pPrev->p3 = 0; |
| 135106 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, p3); |
| 134980 | 135107 | }else{ |
| 134981 | 135108 | /* Insert an isolated OP_Typecheck */ |
| 134982 | 135109 | sqlite3VdbeAddOp2(v, OP_TypeCheck, iReg, pTab->nNVCol); |
| 134983 | 135110 | sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 134984 | 135111 | } |
| | @@ -159209,10 +159336,13 @@ |
| 159209 | 159336 | u16 eOperator; /* A WO_xx value describing <op> */ |
| 159210 | 159337 | u8 nChild; /* Number of children that must disable us */ |
| 159211 | 159338 | u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */ |
| 159212 | 159339 | int iParent; /* Disable pWC->a[iParent] when this term disabled */ |
| 159213 | 159340 | int leftCursor; /* Cursor number of X in "X <op> <expr>" */ |
| 159341 | +#ifdef SQLITE_DEBUG |
| 159342 | + int iTerm; /* Which WhereTerm is this, for debug purposes */ |
| 159343 | +#endif |
| 159214 | 159344 | union { |
| 159215 | 159345 | struct { |
| 159216 | 159346 | int leftColumn; /* Column number of X in "X <op> <expr>" */ |
| 159217 | 159347 | int iField; /* Field in (?,?,?) IN (SELECT...) vector */ |
| 159218 | 159348 | } x; /* Opcode other than OP_OR or OP_AND */ |
| | @@ -161406,40 +161536,40 @@ |
| 161406 | 161536 | VdbeCoverageIf(v, testOp==OP_Ge); |
| 161407 | 161537 | VdbeCoverageIf(v, testOp==OP_Gt); |
| 161408 | 161538 | sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL); |
| 161409 | 161539 | } |
| 161410 | 161540 | }else if( pLoop->wsFlags & WHERE_INDEXED ){ |
| 161411 | | - /* Case 4: A scan using an index. |
| 161412 | | - ** |
| 161413 | | - ** The WHERE clause may contain zero or more equality |
| 161414 | | - ** terms ("==" or "IN" operators) that refer to the N |
| 161415 | | - ** left-most columns of the index. It may also contain |
| 161416 | | - ** inequality constraints (>, <, >= or <=) on the indexed |
| 161417 | | - ** column that immediately follows the N equalities. Only |
| 161418 | | - ** the right-most column can be an inequality - the rest must |
| 161419 | | - ** use the "==" and "IN" operators. For example, if the |
| 161420 | | - ** index is on (x,y,z), then the following clauses are all |
| 161421 | | - ** optimized: |
| 161422 | | - ** |
| 161423 | | - ** x=5 |
| 161424 | | - ** x=5 AND y=10 |
| 161425 | | - ** x=5 AND y<10 |
| 161426 | | - ** x=5 AND y>5 AND y<10 |
| 161427 | | - ** x=5 AND y=5 AND z<=10 |
| 161428 | | - ** |
| 161429 | | - ** The z<10 term of the following cannot be used, only |
| 161430 | | - ** the x=5 term: |
| 161431 | | - ** |
| 161432 | | - ** x=5 AND z<10 |
| 161433 | | - ** |
| 161434 | | - ** N may be zero if there are inequality constraints. |
| 161435 | | - ** If there are no inequality constraints, then N is at |
| 161436 | | - ** least one. |
| 161437 | | - ** |
| 161438 | | - ** This case is also used when there are no WHERE clause |
| 161439 | | - ** constraints but an index is selected anyway, in order |
| 161440 | | - ** to force the output order to conform to an ORDER BY. |
| 161541 | + /* Case 4: Search using an index. |
| 161542 | + ** |
| 161543 | + ** The WHERE clause may contain zero or more equality |
| 161544 | + ** terms ("==" or "IN" or "IS" operators) that refer to the N |
| 161545 | + ** left-most columns of the index. It may also contain |
| 161546 | + ** inequality constraints (>, <, >= or <=) on the indexed |
| 161547 | + ** column that immediately follows the N equalities. Only |
| 161548 | + ** the right-most column can be an inequality - the rest must |
| 161549 | + ** use the "==", "IN", or "IS" operators. For example, if the |
| 161550 | + ** index is on (x,y,z), then the following clauses are all |
| 161551 | + ** optimized: |
| 161552 | + ** |
| 161553 | + ** x=5 |
| 161554 | + ** x=5 AND y=10 |
| 161555 | + ** x=5 AND y<10 |
| 161556 | + ** x=5 AND y>5 AND y<10 |
| 161557 | + ** x=5 AND y=5 AND z<=10 |
| 161558 | + ** |
| 161559 | + ** The z<10 term of the following cannot be used, only |
| 161560 | + ** the x=5 term: |
| 161561 | + ** |
| 161562 | + ** x=5 AND z<10 |
| 161563 | + ** |
| 161564 | + ** N may be zero if there are inequality constraints. |
| 161565 | + ** If there are no inequality constraints, then N is at |
| 161566 | + ** least one. |
| 161567 | + ** |
| 161568 | + ** This case is also used when there are no WHERE clause |
| 161569 | + ** constraints but an index is selected anyway, in order |
| 161570 | + ** to force the output order to conform to an ORDER BY. |
| 161441 | 161571 | */ |
| 161442 | 161572 | static const u8 aStartOp[] = { |
| 161443 | 161573 | 0, |
| 161444 | 161574 | 0, |
| 161445 | 161575 | OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */ |
| | @@ -163455,34 +163585,46 @@ |
| 163455 | 163585 | ** column references. This routine checks to see if pExpr is an equivalence |
| 163456 | 163586 | ** relation: |
| 163457 | 163587 | ** 1. The SQLITE_Transitive optimization must be enabled |
| 163458 | 163588 | ** 2. Must be either an == or an IS operator |
| 163459 | 163589 | ** 3. Not originating in the ON clause of an OUTER JOIN |
| 163460 | | -** 4. The affinities of A and B must be compatible |
| 163461 | | -** 5a. Both operands use the same collating sequence OR |
| 163462 | | -** 5b. The overall collating sequence is BINARY |
| 163590 | +** 4. The operator is not IS or else the query does not contain RIGHT JOIN |
| 163591 | +** 5. The affinities of A and B must be compatible |
| 163592 | +** 6a. Both operands use the same collating sequence OR |
| 163593 | +** 6b. The overall collating sequence is BINARY |
| 163463 | 163594 | ** If this routine returns TRUE, that means that the RHS can be substituted |
| 163464 | 163595 | ** for the LHS anyplace else in the WHERE clause where the LHS column occurs. |
| 163465 | 163596 | ** This is an optimization. No harm comes from returning 0. But if 1 is |
| 163466 | 163597 | ** returned when it should not be, then incorrect answers might result. |
| 163467 | 163598 | */ |
| 163468 | | -static int termIsEquivalence(Parse *pParse, Expr *pExpr){ |
| 163599 | +static int termIsEquivalence(Parse *pParse, Expr *pExpr, SrcList *pSrc){ |
| 163469 | 163600 | char aff1, aff2; |
| 163470 | 163601 | CollSeq *pColl; |
| 163471 | | - if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; |
| 163472 | | - if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; |
| 163473 | | - if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; |
| 163602 | + if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0; /* (1) */ |
| 163603 | + if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0; /* (2) */ |
| 163604 | + if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* (3) */ |
| 163605 | + assert( pSrc!=0 ); |
| 163606 | + if( pExpr->op==TK_IS |
| 163607 | + && pSrc->nSrc |
| 163608 | + && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 |
| 163609 | + ){ |
| 163610 | + return 0; /* (4) */ |
| 163611 | + } |
| 163474 | 163612 | aff1 = sqlite3ExprAffinity(pExpr->pLeft); |
| 163475 | 163613 | aff2 = sqlite3ExprAffinity(pExpr->pRight); |
| 163476 | 163614 | if( aff1!=aff2 |
| 163477 | 163615 | && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2)) |
| 163478 | 163616 | ){ |
| 163479 | | - return 0; |
| 163617 | + return 0; /* (5) */ |
| 163480 | 163618 | } |
| 163481 | 163619 | pColl = sqlite3ExprCompareCollSeq(pParse, pExpr); |
| 163482 | | - if( sqlite3IsBinary(pColl) ) return 1; |
| 163483 | | - return sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight); |
| 163620 | + if( !sqlite3IsBinary(pColl) |
| 163621 | + && !sqlite3ExprCollSeqMatch(pParse, pExpr->pLeft, pExpr->pRight) |
| 163622 | + ){ |
| 163623 | + return 0; /* (6) */ |
| 163624 | + } |
| 163625 | + return 1; |
| 163484 | 163626 | } |
| 163485 | 163627 | |
| 163486 | 163628 | /* |
| 163487 | 163629 | ** Recursively walk the expressions of a SELECT statement and generate |
| 163488 | 163630 | ** a bitmask indicating which tables are used in that expression |
| | @@ -163636,10 +163778,13 @@ |
| 163636 | 163778 | if( db->mallocFailed ){ |
| 163637 | 163779 | return; |
| 163638 | 163780 | } |
| 163639 | 163781 | assert( pWC->nTerm > idxTerm ); |
| 163640 | 163782 | pTerm = &pWC->a[idxTerm]; |
| 163783 | +#ifdef SQLITE_DEBUG |
| 163784 | + pTerm->iTerm = idxTerm; |
| 163785 | +#endif |
| 163641 | 163786 | pMaskSet = &pWInfo->sMaskSet; |
| 163642 | 163787 | pExpr = pTerm->pExpr; |
| 163643 | 163788 | assert( pExpr!=0 ); /* Because malloc() has not failed */ |
| 163644 | 163789 | assert( pExpr->op!=TK_AS && pExpr->op!=TK_COLLATE ); |
| 163645 | 163790 | pMaskSet->bVarSelect = 0; |
| | @@ -163743,12 +163888,12 @@ |
| 163743 | 163888 | pNew = &pWC->a[idxNew]; |
| 163744 | 163889 | markTermAsChild(pWC, idxNew, idxTerm); |
| 163745 | 163890 | if( op==TK_IS ) pNew->wtFlags |= TERM_IS; |
| 163746 | 163891 | pTerm = &pWC->a[idxTerm]; |
| 163747 | 163892 | pTerm->wtFlags |= TERM_COPIED; |
| 163748 | | - |
| 163749 | | - if( termIsEquivalence(pParse, pDup) ){ |
| 163893 | + assert( pWInfo->pTabList!=0 ); |
| 163894 | + if( termIsEquivalence(pParse, pDup, pWInfo->pTabList) ){ |
| 163750 | 163895 | pTerm->eOperator |= WO_EQUIV; |
| 163751 | 163896 | eExtraOp = WO_EQUIV; |
| 163752 | 163897 | } |
| 163753 | 163898 | }else{ |
| 163754 | 163899 | pDup = pExpr; |
| | @@ -164863,15 +165008,15 @@ |
| 164863 | 165008 | continue; |
| 164864 | 165009 | } |
| 164865 | 165010 | pScan->pWC = pWC; |
| 164866 | 165011 | pScan->k = k+1; |
| 164867 | 165012 | #ifdef WHERETRACE_ENABLED |
| 164868 | | - if( sqlite3WhereTrace & 0x20000 ){ |
| 165013 | + if( (sqlite3WhereTrace & 0x20000)!=0 && pScan->nEquiv>1 ){ |
| 164869 | 165014 | int ii; |
| 164870 | | - sqlite3DebugPrintf("SCAN-TERM %p: nEquiv=%d", |
| 164871 | | - pTerm, pScan->nEquiv); |
| 164872 | | - for(ii=0; ii<pScan->nEquiv; ii++){ |
| 165015 | + sqlite3DebugPrintf("EQUIVALENT TO {%d:%d} (due to TERM-%d):", |
| 165016 | + pScan->aiCur[0], pScan->aiColumn[0], pTerm->iTerm); |
| 165017 | + for(ii=1; ii<pScan->nEquiv; ii++){ |
| 164873 | 165018 | sqlite3DebugPrintf(" {%d:%d}", |
| 164874 | 165019 | pScan->aiCur[ii], pScan->aiColumn[ii]); |
| 164875 | 165020 | } |
| 164876 | 165021 | sqlite3DebugPrintf("\n"); |
| 164877 | 165022 | } |
| | @@ -166822,10 +166967,11 @@ |
| 166822 | 166967 | sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%llx", |
| 166823 | 166968 | pTerm->u.pOrInfo->indexable); |
| 166824 | 166969 | }else{ |
| 166825 | 166970 | sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor); |
| 166826 | 166971 | } |
| 166972 | + iTerm = pTerm->iTerm = MAX(iTerm,pTerm->iTerm); |
| 166827 | 166973 | sqlite3DebugPrintf( |
| 166828 | 166974 | "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x", |
| 166829 | 166975 | iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags); |
| 166830 | 166976 | /* The 0x10000 .wheretrace flag causes extra information to be |
| 166831 | 166977 | ** shown about each Term */ |
| | @@ -184446,10 +184592,11 @@ |
| 184446 | 184592 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 184447 | 184593 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 184448 | 184594 | #endif |
| 184449 | 184595 | if( ms<-1 ) return SQLITE_RANGE; |
| 184450 | 184596 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 184597 | + sqlite3_mutex_enter(db->mutex); |
| 184451 | 184598 | db->setlkTimeout = ms; |
| 184452 | 184599 | db->setlkFlags = flags; |
| 184453 | 184600 | sqlite3BtreeEnterAll(db); |
| 184454 | 184601 | for(iDb=0; iDb<db->nDb; iDb++){ |
| 184455 | 184602 | Btree *pBt = db->aDb[iDb].pBt; |
| | @@ -184457,10 +184604,11 @@ |
| 184457 | 184604 | sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt)); |
| 184458 | 184605 | sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC); |
| 184459 | 184606 | } |
| 184460 | 184607 | } |
| 184461 | 184608 | sqlite3BtreeLeaveAll(db); |
| 184609 | + sqlite3_mutex_leave(db->mutex); |
| 184462 | 184610 | #endif |
| 184463 | 184611 | #if !defined(SQLITE_ENABLE_API_ARMOR) && !defined(SQLITE_ENABLE_SETLK_TIMEOUT) |
| 184464 | 184612 | UNUSED_PARAMETER(db); |
| 184465 | 184613 | UNUSED_PARAMETER(flags); |
| 184466 | 184614 | #endif |
| | @@ -257253,11 +257401,11 @@ |
| 257253 | 257401 | int nArg, /* Number of args */ |
| 257254 | 257402 | sqlite3_value **apUnused /* Function arguments */ |
| 257255 | 257403 | ){ |
| 257256 | 257404 | assert( nArg==0 ); |
| 257257 | 257405 | UNUSED_PARAM2(nArg, apUnused); |
| 257258 | | - sqlite3_result_text(pCtx, "fts5: 2025-06-03 10:49:51 ea1754f7d8a770477a1b19b606b27724fdc0b733e51fef32c1ef834f972c3cc5", -1, SQLITE_TRANSIENT); |
| 257406 | + sqlite3_result_text(pCtx, "fts5: 2025-06-19 20:19:12 a88bb75288a06492a04ab1278e8a2101a74f4ba712d328b4c73e86ac01cb946d", -1, SQLITE_TRANSIENT); |
| 257259 | 257407 | } |
| 257260 | 257408 | |
| 257261 | 257409 | /* |
| 257262 | 257410 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 257263 | 257411 | ** |
| | @@ -258068,10 +258216,11 @@ |
| 258068 | 258216 | ctx.pStorage = p; |
| 258069 | 258217 | ctx.iCol = -1; |
| 258070 | 258218 | for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){ |
| 258071 | 258219 | if( pConfig->abUnindexed[iCol-1]==0 ){ |
| 258072 | 258220 | sqlite3_value *pVal = 0; |
| 258221 | + sqlite3_value *pFree = 0; |
| 258073 | 258222 | const char *pText = 0; |
| 258074 | 258223 | int nText = 0; |
| 258075 | 258224 | const char *pLoc = 0; |
| 258076 | 258225 | int nLoc = 0; |
| 258077 | 258226 | |
| | @@ -258084,15 +258233,26 @@ |
| 258084 | 258233 | } |
| 258085 | 258234 | |
| 258086 | 258235 | if( pConfig->bLocale && sqlite3Fts5IsLocaleValue(pConfig, pVal) ){ |
| 258087 | 258236 | rc = sqlite3Fts5DecodeLocaleValue(pVal, &pText, &nText, &pLoc, &nLoc); |
| 258088 | 258237 | }else{ |
| 258089 | | - pText = (const char*)sqlite3_value_text(pVal); |
| 258090 | | - nText = sqlite3_value_bytes(pVal); |
| 258091 | | - if( pConfig->bLocale && pSeek ){ |
| 258092 | | - pLoc = (const char*)sqlite3_column_text(pSeek, iCol + pConfig->nCol); |
| 258093 | | - nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol); |
| 258238 | + if( sqlite3_value_type(pVal)!=SQLITE_TEXT ){ |
| 258239 | + /* Make a copy of the value to work with. This is because the call |
| 258240 | + ** to sqlite3_value_text() below forces the type of the value to |
| 258241 | + ** SQLITE_TEXT, and we may need to use it again later. */ |
| 258242 | + pFree = pVal = sqlite3_value_dup(pVal); |
| 258243 | + if( pVal==0 ){ |
| 258244 | + rc = SQLITE_NOMEM; |
| 258245 | + } |
| 258246 | + } |
| 258247 | + if( rc==SQLITE_OK ){ |
| 258248 | + pText = (const char*)sqlite3_value_text(pVal); |
| 258249 | + nText = sqlite3_value_bytes(pVal); |
| 258250 | + if( pConfig->bLocale && pSeek ){ |
| 258251 | + pLoc = (const char*)sqlite3_column_text(pSeek, iCol+pConfig->nCol); |
| 258252 | + nLoc = sqlite3_column_bytes(pSeek, iCol + pConfig->nCol); |
| 258253 | + } |
| 258094 | 258254 | } |
| 258095 | 258255 | } |
| 258096 | 258256 | |
| 258097 | 258257 | if( rc==SQLITE_OK ){ |
| 258098 | 258258 | sqlite3Fts5SetLocale(pConfig, pLoc, nLoc); |
| | @@ -258104,10 +258264,11 @@ |
| 258104 | 258264 | if( rc==SQLITE_OK && p->aTotalSize[iCol-1]<0 ){ |
| 258105 | 258265 | rc = FTS5_CORRUPT; |
| 258106 | 258266 | } |
| 258107 | 258267 | sqlite3Fts5ClearLocale(pConfig); |
| 258108 | 258268 | } |
| 258269 | + sqlite3_value_free(pFree); |
| 258109 | 258270 | } |
| 258110 | 258271 | } |
| 258111 | 258272 | if( rc==SQLITE_OK && p->nTotalRow<1 ){ |
| 258112 | 258273 | rc = FTS5_CORRUPT; |
| 258113 | 258274 | }else{ |
| 258114 | 258275 | |