| | @@ -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 | | -** cf7163f82ca380958a79350473b2c5a2cebd with changes in files: |
| 21 | +** 0f31711591c56f3896fb6f092752fb82c4ea with changes in files: |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| | @@ -465,11 +465,14 @@ |
| 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-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1" |
| 470 | +#define SQLITE_SOURCE_ID "2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091" |
| 471 | +#define SQLITE_SCM_BRANCH "trunk" |
| 472 | +#define SQLITE_SCM_TAGS "" |
| 473 | +#define SQLITE_SCM_DATETIME "2025-09-09T10:28:06.692Z" |
| 471 | 474 | |
| 472 | 475 | /* |
| 473 | 476 | ** CAPI3REF: Run-Time Library Version Numbers |
| 474 | 477 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 475 | 478 | ** |
| | @@ -2657,21 +2660,24 @@ |
| 2657 | 2660 | ** views in the main database schema or in the schemas of ATTACH-ed |
| 2658 | 2661 | ** databases.)^ </dd> |
| 2659 | 2662 | ** |
| 2660 | 2663 | ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] |
| 2661 | 2664 | ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> |
| 2662 | | -** <dd> ^This option is used to enable or disable the |
| 2663 | | -** [fts3_tokenizer()] function which is part of the |
| 2664 | | -** [FTS3] full-text search engine extension. |
| 2665 | | -** There must be two additional arguments. |
| 2666 | | -** The first argument is an integer which is 0 to disable fts3_tokenizer() or |
| 2667 | | -** positive to enable fts3_tokenizer() or negative to leave the setting |
| 2668 | | -** unchanged. |
| 2669 | | -** The second parameter is a pointer to an integer into which |
| 2670 | | -** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled |
| 2671 | | -** following this call. The second parameter may be a NULL pointer, in |
| 2672 | | -** which case the new setting is not reported back. </dd> |
| 2665 | +** <dd> ^This option is used to enable or disable using the |
| 2666 | +** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine |
| 2667 | +** extension - without using bound parameters as the parameters. Doing so |
| 2668 | +** is disabled by default. There must be two additional arguments. The first |
| 2669 | +** argument is an integer. If it is passed 0, then using fts3_tokenizer() |
| 2670 | +** without bound parameters is disabled. If it is passed a positive value, |
| 2671 | +** then calling fts3_tokenizer without bound parameters is enabled. If it |
| 2672 | +** is passed a negative value, this setting is not modified - this can be |
| 2673 | +** used to query for the current setting. The second parameter is a pointer |
| 2674 | +** to an integer into which is written 0 or 1 to indicate the current value |
| 2675 | +** of this setting (after it is modified, if applicable). The second |
| 2676 | +** parameter may be a NULL pointer, in which case the value of the setting |
| 2677 | +** is not reported back. Refer to [FTS3] documentation for further details. |
| 2678 | +** </dd> |
| 2673 | 2679 | ** |
| 2674 | 2680 | ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]] |
| 2675 | 2681 | ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> |
| 2676 | 2682 | ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] |
| 2677 | 2683 | ** interface independently of the [load_extension()] SQL function. |
| | @@ -6527,10 +6533,11 @@ |
| 6527 | 6533 | ** to be attached to [database connection] D using name N. Subsequent |
| 6528 | 6534 | ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P |
| 6529 | 6535 | ** or a NULL pointer if there were no prior calls to |
| 6530 | 6536 | ** sqlite3_set_clientdata() with the same values of D and N. |
| 6531 | 6537 | ** Names are compared using strcmp() and are thus case sensitive. |
| 6538 | +** It returns 0 on success and SQLITE_NOMEM on allocation failure. |
| 6532 | 6539 | ** |
| 6533 | 6540 | ** If P and X are both non-NULL, then the destructor X is invoked with |
| 6534 | 6541 | ** argument P on the first of the following occurrences: |
| 6535 | 6542 | ** <ul> |
| 6536 | 6543 | ** <li> An out-of-memory error occurs during the call to |
| | @@ -10098,25 +10105,38 @@ |
| 10098 | 10105 | ** ^The third parameter is the name of the database that was written to - |
| 10099 | 10106 | ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter |
| 10100 | 10107 | ** is the number of pages currently in the write-ahead log file, |
| 10101 | 10108 | ** including those that were just committed. |
| 10102 | 10109 | ** |
| 10103 | | -** The callback function should normally return [SQLITE_OK]. ^If an error |
| 10110 | +** ^The callback function should normally return [SQLITE_OK]. ^If an error |
| 10104 | 10111 | ** code is returned, that error will propagate back up through the |
| 10105 | 10112 | ** SQLite code base to cause the statement that provoked the callback |
| 10106 | 10113 | ** to report an error, though the commit will have still occurred. If the |
| 10107 | 10114 | ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value |
| 10108 | 10115 | ** that does not correspond to any valid SQLite error code, the results |
| 10109 | 10116 | ** are undefined. |
| 10110 | 10117 | ** |
| 10111 | | -** A single database handle may have at most a single write-ahead log callback |
| 10112 | | -** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any |
| 10113 | | -** previously registered write-ahead log callback. ^The return value is |
| 10114 | | -** a copy of the third parameter from the previous call, if any, or 0. |
| 10115 | | -** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the |
| 10116 | | -** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will |
| 10117 | | -** overwrite any prior [sqlite3_wal_hook()] settings. |
| 10118 | +** ^A single database handle may have at most a single write-ahead log |
| 10119 | +** callback registered at one time. ^Calling [sqlite3_wal_hook()] |
| 10120 | +** replaces the default behavior or previously registered write-ahead |
| 10121 | +** log callback. |
| 10122 | +** |
| 10123 | +** ^The return value is a copy of the third parameter from the |
| 10124 | +** previous call, if any, or 0. |
| 10125 | +** |
| 10126 | +** ^The [sqlite3_wal_autocheckpoint()] interface and the |
| 10127 | +** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and |
| 10128 | +** will overwrite any prior [sqlite3_wal_hook()] settings. |
| 10129 | +** |
| 10130 | +** ^If a write-ahead log callback is set using this function then |
| 10131 | +** [sqlite3_wal_checkpoint_v2()] or [PRAGMA wal_checkpoint] |
| 10132 | +** should be invoked periodically to keep the write-ahead log file |
| 10133 | +** from growing without bound. |
| 10134 | +** |
| 10135 | +** ^Passing a NULL pointer for the callback disables automatic |
| 10136 | +** checkpointing entirely. To re-enable the default behavior, call |
| 10137 | +** sqlite3_wal_autocheckpoint(db,1000) or use [PRAGMA wal_checkpoint]. |
| 10118 | 10138 | */ |
| 10119 | 10139 | SQLITE_API void *sqlite3_wal_hook( |
| 10120 | 10140 | sqlite3*, |
| 10121 | 10141 | int(*)(void *,sqlite3*,const char*,int), |
| 10122 | 10142 | void* |
| | @@ -10129,11 +10149,11 @@ |
| 10129 | 10149 | ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around |
| 10130 | 10150 | ** [sqlite3_wal_hook()] that causes any database on [database connection] D |
| 10131 | 10151 | ** to automatically [checkpoint] |
| 10132 | 10152 | ** after committing a transaction if there are N or |
| 10133 | 10153 | ** more frames in the [write-ahead log] file. ^Passing zero or |
| 10134 | | -** a negative value as the nFrame parameter disables automatic |
| 10154 | +** a negative value as the N parameter disables automatic |
| 10135 | 10155 | ** checkpoints entirely. |
| 10136 | 10156 | ** |
| 10137 | 10157 | ** ^The callback registered by this function replaces any existing callback |
| 10138 | 10158 | ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback |
| 10139 | 10159 | ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism |
| | @@ -10145,13 +10165,14 @@ |
| 10145 | 10165 | ** ^Checkpoints initiated by this mechanism are |
| 10146 | 10166 | ** [sqlite3_wal_checkpoint_v2|PASSIVE]. |
| 10147 | 10167 | ** |
| 10148 | 10168 | ** ^Every new [database connection] defaults to having the auto-checkpoint |
| 10149 | 10169 | ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] |
| 10150 | | -** pages. The use of this interface |
| 10151 | | -** is only necessary if the default setting is found to be suboptimal |
| 10152 | | -** for a particular application. |
| 10170 | +** pages. |
| 10171 | +** |
| 10172 | +** ^The use of this interface is only necessary if the default setting |
| 10173 | +** is found to be suboptimal for a particular application. |
| 10153 | 10174 | */ |
| 10154 | 10175 | SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); |
| 10155 | 10176 | |
| 10156 | 10177 | /* |
| 10157 | 10178 | ** CAPI3REF: Checkpoint a database |
| | @@ -10212,10 +10233,15 @@ |
| 10212 | 10233 | ** |
| 10213 | 10234 | ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd> |
| 10214 | 10235 | ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the |
| 10215 | 10236 | ** addition that it also truncates the log file to zero bytes just prior |
| 10216 | 10237 | ** to a successful return. |
| 10238 | +** |
| 10239 | +** <dt>SQLITE_CHECKPOINT_NOOP<dd> |
| 10240 | +** ^This mode always checkpoints zero frames. The only reason to invoke |
| 10241 | +** a NOOP checkpoint is to access the values returned by |
| 10242 | +** sqlite3_wal_checkpoint_v2() via output parameters *pnLog and *pnCkpt. |
| 10217 | 10243 | ** </dl> |
| 10218 | 10244 | ** |
| 10219 | 10245 | ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in |
| 10220 | 10246 | ** the log file or to -1 if the checkpoint could not run because |
| 10221 | 10247 | ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not |
| | @@ -10282,10 +10308,11 @@ |
| 10282 | 10308 | ** These constants define all valid values for the "checkpoint mode" passed |
| 10283 | 10309 | ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface. |
| 10284 | 10310 | ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the |
| 10285 | 10311 | ** meaning of each of these checkpoint modes. |
| 10286 | 10312 | */ |
| 10313 | +#define SQLITE_CHECKPOINT_NOOP -1 /* Do no work at all */ |
| 10287 | 10314 | #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */ |
| 10288 | 10315 | #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */ |
| 10289 | 10316 | #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */ |
| 10290 | 10317 | #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */ |
| 10291 | 10318 | |
| | @@ -11109,11 +11136,11 @@ |
| 11109 | 11136 | ** to avoid a memory leak. |
| 11110 | 11137 | ** |
| 11111 | 11138 | ** The [sqlite3_snapshot_get()] interface is only available when the |
| 11112 | 11139 | ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. |
| 11113 | 11140 | */ |
| 11114 | | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get( |
| 11141 | +SQLITE_API int sqlite3_snapshot_get( |
| 11115 | 11142 | sqlite3 *db, |
| 11116 | 11143 | const char *zSchema, |
| 11117 | 11144 | sqlite3_snapshot **ppSnapshot |
| 11118 | 11145 | ); |
| 11119 | 11146 | |
| | @@ -11158,11 +11185,11 @@ |
| 11158 | 11185 | ** database connection in order to make it ready to use snapshots.) |
| 11159 | 11186 | ** |
| 11160 | 11187 | ** The [sqlite3_snapshot_open()] interface is only available when the |
| 11161 | 11188 | ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. |
| 11162 | 11189 | */ |
| 11163 | | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open( |
| 11190 | +SQLITE_API int sqlite3_snapshot_open( |
| 11164 | 11191 | sqlite3 *db, |
| 11165 | 11192 | const char *zSchema, |
| 11166 | 11193 | sqlite3_snapshot *pSnapshot |
| 11167 | 11194 | ); |
| 11168 | 11195 | |
| | @@ -11175,11 +11202,11 @@ |
| 11175 | 11202 | ** using this routine to avoid a memory leak. |
| 11176 | 11203 | ** |
| 11177 | 11204 | ** The [sqlite3_snapshot_free()] interface is only available when the |
| 11178 | 11205 | ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used. |
| 11179 | 11206 | */ |
| 11180 | | -SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*); |
| 11207 | +SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*); |
| 11181 | 11208 | |
| 11182 | 11209 | /* |
| 11183 | 11210 | ** CAPI3REF: Compare the ages of two snapshot handles. |
| 11184 | 11211 | ** METHOD: sqlite3_snapshot |
| 11185 | 11212 | ** |
| | @@ -11202,11 +11229,11 @@ |
| 11202 | 11229 | ** snapshot, and a positive value if P1 is a newer snapshot than P2. |
| 11203 | 11230 | ** |
| 11204 | 11231 | ** This interface is only available if SQLite is compiled with the |
| 11205 | 11232 | ** [SQLITE_ENABLE_SNAPSHOT] option. |
| 11206 | 11233 | */ |
| 11207 | | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( |
| 11234 | +SQLITE_API int sqlite3_snapshot_cmp( |
| 11208 | 11235 | sqlite3_snapshot *p1, |
| 11209 | 11236 | sqlite3_snapshot *p2 |
| 11210 | 11237 | ); |
| 11211 | 11238 | |
| 11212 | 11239 | /* |
| | @@ -11230,11 +11257,11 @@ |
| 11230 | 11257 | ** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 11231 | 11258 | ** |
| 11232 | 11259 | ** This interface is only available if SQLite is compiled with the |
| 11233 | 11260 | ** [SQLITE_ENABLE_SNAPSHOT] option. |
| 11234 | 11261 | */ |
| 11235 | | -SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); |
| 11262 | +SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); |
| 11236 | 11263 | |
| 11237 | 11264 | /* |
| 11238 | 11265 | ** CAPI3REF: Serialize a database |
| 11239 | 11266 | ** |
| 11240 | 11267 | ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to |
| | @@ -11304,16 +11331,17 @@ |
| 11304 | 11331 | /* |
| 11305 | 11332 | ** CAPI3REF: Deserialize a database |
| 11306 | 11333 | ** |
| 11307 | 11334 | ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the |
| 11308 | 11335 | ** [database connection] D to disconnect from database S and then |
| 11309 | | -** reopen S as an in-memory database based on the serialization contained |
| 11310 | | -** in P. The serialized database P is N bytes in size. M is the size of |
| 11311 | | -** the buffer P, which might be larger than N. If M is larger than N, and |
| 11312 | | -** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is |
| 11313 | | -** permitted to add content to the in-memory database as long as the total |
| 11314 | | -** size does not exceed M bytes. |
| 11336 | +** reopen S as an in-memory database based on the serialization |
| 11337 | +** contained in P. If S is a NULL pointer, the main database is |
| 11338 | +** used. The serialized database P is N bytes in size. M is the size |
| 11339 | +** of the buffer P, which might be larger than N. If M is larger than |
| 11340 | +** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then |
| 11341 | +** SQLite is permitted to add content to the in-memory database as |
| 11342 | +** long as the total size does not exceed M bytes. |
| 11315 | 11343 | ** |
| 11316 | 11344 | ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will |
| 11317 | 11345 | ** invoke sqlite3_free() on the serialization buffer when the database |
| 11318 | 11346 | ** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then |
| 11319 | 11347 | ** SQLite will try to increase the buffer size using sqlite3_realloc64() |
| | @@ -14356,11 +14384,11 @@ |
| 14356 | 14384 | |
| 14357 | 14385 | /* |
| 14358 | 14386 | ** Maximum number of pages in one database file. |
| 14359 | 14387 | ** |
| 14360 | 14388 | ** This is really just the default value for the max_page_count pragma. |
| 14361 | | -** This value can be lowered (or raised) at run-time using that the |
| 14389 | +** This value can be lowered (or raised) at run-time using the |
| 14362 | 14390 | ** max_page_count macro. |
| 14363 | 14391 | */ |
| 14364 | 14392 | #ifndef SQLITE_MAX_PAGE_COUNT |
| 14365 | 14393 | # define SQLITE_MAX_PAGE_COUNT 0xfffffffe /* 4294967294 */ |
| 14366 | 14394 | #endif |
| | @@ -20086,10 +20114,11 @@ |
| 20086 | 20114 | #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */ |
| 20087 | 20115 | #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */ |
| 20088 | 20116 | #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */ |
| 20089 | 20117 | #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */ |
| 20090 | 20118 | #define SF_Correlated 0x20000000 /* True if references the outer context */ |
| 20119 | +#define SF_OnToWhere 0x40000000 /* One or more ON clauses moved to WHERE */ |
| 20091 | 20120 | |
| 20092 | 20121 | /* True if SrcItem X is a subquery that has SF_NestedFrom */ |
| 20093 | 20122 | #define IsNestedFrom(X) \ |
| 20094 | 20123 | ((X)->fg.isSubquery && \ |
| 20095 | 20124 | ((X)->u4.pSubq->pSelect->selFlags&SF_NestedFrom)!=0) |
| | @@ -20839,10 +20868,11 @@ |
| 20839 | 20868 | struct Table *pTab; /* Table of generated column */ |
| 20840 | 20869 | struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */ |
| 20841 | 20870 | SrcItem *pSrcItem; /* A single FROM clause item */ |
| 20842 | 20871 | DbFixer *pFix; /* See sqlite3FixSelect() */ |
| 20843 | 20872 | Mem *aMem; /* See sqlite3BtreeCursorHint() */ |
| 20873 | + struct CheckOnCtx *pCheckOnCtx; /* See selectCheckOnClauses() */ |
| 20844 | 20874 | } u; |
| 20845 | 20875 | }; |
| 20846 | 20876 | |
| 20847 | 20877 | /* |
| 20848 | 20878 | ** The following structure contains information used by the sqliteFix... |
| | @@ -24209,11 +24239,14 @@ |
| 24209 | 24239 | Mem oldipk; /* Memory cell holding "old" IPK value */ |
| 24210 | 24240 | Mem *aNew; /* Array of new.* values */ |
| 24211 | 24241 | Table *pTab; /* Schema object being updated */ |
| 24212 | 24242 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 24213 | 24243 | sqlite3_value **apDflt; /* Array of default values, if required */ |
| 24214 | | - u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */ |
| 24244 | + union { |
| 24245 | + KeyInfo sKey; |
| 24246 | + u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */ |
| 24247 | + } uKey; |
| 24215 | 24248 | }; |
| 24216 | 24249 | |
| 24217 | 24250 | /* |
| 24218 | 24251 | ** An instance of this object is used to pass an vector of values into |
| 24219 | 24252 | ** OP_VFilter, the xFilter method of a virtual table. The vector is the |
| | @@ -33486,13 +33519,17 @@ |
| 33486 | 33519 | sqlite3StrAccumFinish(&x); |
| 33487 | 33520 | sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
| 33488 | 33521 | n = 0; |
| 33489 | 33522 | if( pItem->fg.isSubquery ) n++; |
| 33490 | 33523 | if( pItem->fg.isTabFunc ) n++; |
| 33491 | | - if( pItem->fg.isUsing ) n++; |
| 33524 | + if( pItem->fg.isUsing || pItem->u3.pOn!=0 ) n++; |
| 33492 | 33525 | if( pItem->fg.isUsing ){ |
| 33493 | 33526 | sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); |
| 33527 | + }else if( pItem->u3.pOn!=0 ){ |
| 33528 | + sqlite3TreeViewItem(pView, "ON", (--n)>0); |
| 33529 | + sqlite3TreeViewExpr(pView, pItem->u3.pOn, 0); |
| 33530 | + sqlite3TreeViewPop(&pView); |
| 33494 | 33531 | } |
| 33495 | 33532 | if( pItem->fg.isSubquery ){ |
| 33496 | 33533 | assert( n==1 ); |
| 33497 | 33534 | if( pItem->pSTab ){ |
| 33498 | 33535 | Table *pTab = pItem->pSTab; |
| | @@ -39437,14 +39474,15 @@ |
| 39437 | 39474 | #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\ |
| 39438 | 39475 | aSyscall[13].pCurrent) |
| 39439 | 39476 | |
| 39440 | 39477 | #if defined(HAVE_FCHMOD) |
| 39441 | 39478 | { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, |
| 39479 | +#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) |
| 39442 | 39480 | #else |
| 39443 | 39481 | { "fchmod", (sqlite3_syscall_ptr)0, 0 }, |
| 39482 | +#define osFchmod(FID,MODE) 0 |
| 39444 | 39483 | #endif |
| 39445 | | -#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) |
| 39446 | 39484 | |
| 39447 | 39485 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 39448 | 39486 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 39449 | 39487 | #else |
| 39450 | 39488 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, |
| | @@ -40391,10 +40429,14 @@ |
| 40391 | 40429 | do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR ); |
| 40392 | 40430 | if( rc!=1 ){ |
| 40393 | 40431 | storeLastErrno(pFile, errno); |
| 40394 | 40432 | return SQLITE_IOERR; |
| 40395 | 40433 | } |
| 40434 | + if( fsync(fd) ){ |
| 40435 | + storeLastErrno(pFile, errno); |
| 40436 | + return SQLITE_IOERR_FSYNC; |
| 40437 | + } |
| 40396 | 40438 | rc = osFstat(fd, &statbuf); |
| 40397 | 40439 | if( rc!=0 ){ |
| 40398 | 40440 | storeLastErrno(pFile, errno); |
| 40399 | 40441 | return SQLITE_IOERR; |
| 40400 | 40442 | } |
| | @@ -40560,22 +40602,46 @@ |
| 40560 | 40602 | static int osSetPosixAdvisoryLock( |
| 40561 | 40603 | int h, /* The file descriptor on which to take the lock */ |
| 40562 | 40604 | struct flock *pLock, /* The description of the lock */ |
| 40563 | 40605 | unixFile *pFile /* Structure holding timeout value */ |
| 40564 | 40606 | ){ |
| 40565 | | - int tm = pFile->iBusyTimeout; |
| 40566 | | - int rc = osFcntl(h,F_SETLK,pLock); |
| 40567 | | - while( rc<0 && tm>0 ){ |
| 40568 | | - /* On systems that support some kind of blocking file lock with a timeout, |
| 40569 | | - ** make appropriate changes here to invoke that blocking file lock. On |
| 40570 | | - ** generic posix, however, there is no such API. So we simply try the |
| 40571 | | - ** lock once every millisecond until either the timeout expires, or until |
| 40572 | | - ** the lock is obtained. */ |
| 40573 | | - unixSleep(0,1000); |
| 40607 | + int rc = 0; |
| 40608 | + |
| 40609 | + if( pFile->iBusyTimeout==0 ){ |
| 40610 | + /* unixFile->iBusyTimeout is set to 0. In this case, attempt a |
| 40611 | + ** non-blocking lock. */ |
| 40612 | + rc = osFcntl(h,F_SETLK,pLock); |
| 40613 | + }else{ |
| 40614 | + /* unixFile->iBusyTimeout is set to greater than zero. In this case, |
| 40615 | + ** attempt a blocking-lock with a unixFile->iBusyTimeout ms timeout. |
| 40616 | + ** |
| 40617 | + ** On systems that support some kind of blocking file lock operation, |
| 40618 | + ** this block should be replaced by code to attempt a blocking lock |
| 40619 | + ** with a timeout of unixFile->iBusyTimeout ms. The code below is |
| 40620 | + ** placeholder code. If SQLITE_TEST is defined, the placeholder code |
| 40621 | + ** retries the lock once every 1ms until it succeeds or the timeout |
| 40622 | + ** is reached. Or, if SQLITE_TEST is not defined, the placeholder |
| 40623 | + ** code attempts a non-blocking lock and sets unixFile->iBusyTimeout |
| 40624 | + ** to 0. This causes the caller to return SQLITE_BUSY, instead of |
| 40625 | + ** SQLITE_BUSY_TIMEOUT to SQLite - as required by a VFS that does not |
| 40626 | + ** support blocking locks. |
| 40627 | + */ |
| 40628 | +#ifdef SQLITE_TEST |
| 40629 | + int tm = pFile->iBusyTimeout; |
| 40630 | + while( tm>0 ){ |
| 40631 | + rc = osFcntl(h,F_SETLK,pLock); |
| 40632 | + if( rc==0 ) break; |
| 40633 | + unixSleep(0,1000); |
| 40634 | + tm--; |
| 40635 | + } |
| 40636 | +#else |
| 40574 | 40637 | rc = osFcntl(h,F_SETLK,pLock); |
| 40575 | | - tm--; |
| 40638 | + pFile->iBusyTimeout = 0; |
| 40639 | +#endif |
| 40640 | + /* End of code to replace with real blocking-locks code. */ |
| 40576 | 40641 | } |
| 40642 | + |
| 40577 | 40643 | return rc; |
| 40578 | 40644 | } |
| 40579 | 40645 | #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */ |
| 40580 | 40646 | |
| 40581 | 40647 | |
| | @@ -51349,33 +51415,39 @@ |
| 51349 | 51415 | ** log-summary, each thread has its own winFile object, but they all |
| 51350 | 51416 | ** point to a single instance of this object. In other words, each |
| 51351 | 51417 | ** log-summary is opened only once per process. |
| 51352 | 51418 | ** |
| 51353 | 51419 | ** winShmMutexHeld() must be true when creating or destroying |
| 51354 | | -** this object or while reading or writing the following fields: |
| 51420 | +** this object, or while editing the global linked list that starts |
| 51421 | +** at winShmNodeList. |
| 51355 | 51422 | ** |
| 51356 | | -** nRef |
| 51357 | | -** pNext |
| 51423 | +** When reading or writing the linked list starting at winShmNode.pWinShmList, |
| 51424 | +** pShmNode->mutex must be held. |
| 51358 | 51425 | ** |
| 51359 | | -** The following fields are read-only after the object is created: |
| 51426 | +** The following fields are constant after the object is created: |
| 51360 | 51427 | ** |
| 51361 | 51428 | ** zFilename |
| 51429 | +** hSharedShm |
| 51430 | +** mutex |
| 51431 | +** bUseSharedLockHandle |
| 51362 | 51432 | ** |
| 51363 | | -** Either winShmNode.mutex must be held or winShmNode.nRef==0 and |
| 51433 | +** Either winShmNode.mutex must be held or winShmNode.pWinShmList==0 and |
| 51364 | 51434 | ** winShmMutexHeld() is true when reading or writing any other field |
| 51365 | 51435 | ** in this structure. |
| 51366 | 51436 | ** |
| 51367 | | -** File-handle hSharedShm is used to (a) take the DMS lock, (b) truncate |
| 51368 | | -** the *-shm file if the DMS-locking protocol demands it, and (c) map |
| 51369 | | -** regions of the *-shm file into memory using MapViewOfFile() or |
| 51370 | | -** similar. Other locks are taken by individual clients using the |
| 51371 | | -** winShm.hShm handles. |
| 51437 | +** File-handle hSharedShm is always used to (a) take the DMS lock, (b) |
| 51438 | +** truncate the *-shm file if the DMS-locking protocol demands it, and |
| 51439 | +** (c) map regions of the *-shm file into memory using MapViewOfFile() |
| 51440 | +** or similar. If bUseSharedLockHandle is true, then other locks are also |
| 51441 | +** taken on hSharedShm. Or, if bUseSharedLockHandle is false, then other |
| 51442 | +** locks are taken using each connection's winShm.hShm handles. |
| 51372 | 51443 | */ |
| 51373 | 51444 | struct winShmNode { |
| 51374 | 51445 | sqlite3_mutex *mutex; /* Mutex to access this object */ |
| 51375 | 51446 | char *zFilename; /* Name of the file */ |
| 51376 | 51447 | HANDLE hSharedShm; /* File handle open on zFilename */ |
| 51448 | + int bUseSharedLockHandle; /* True to use hSharedShm for everything */ |
| 51377 | 51449 | |
| 51378 | 51450 | int isUnlocked; /* DMS lock has not yet been obtained */ |
| 51379 | 51451 | int isReadonly; /* True if read-only */ |
| 51380 | 51452 | int szRegion; /* Size of shared-memory regions */ |
| 51381 | 51453 | int nRegion; /* Size of array apRegion */ |
| | @@ -51384,11 +51456,12 @@ |
| 51384 | 51456 | HANDLE hMap; /* File handle from CreateFileMapping */ |
| 51385 | 51457 | void *pMap; |
| 51386 | 51458 | } *aRegion; |
| 51387 | 51459 | DWORD lastErrno; /* The Windows errno from the last I/O error */ |
| 51388 | 51460 | |
| 51389 | | - int nRef; /* Number of winShm objects pointing to this */ |
| 51461 | + winShm *pWinShmList; /* List of winShm objects with ptrs to this */ |
| 51462 | + |
| 51390 | 51463 | winShmNode *pNext; /* Next in list of all winShmNode objects */ |
| 51391 | 51464 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 51392 | 51465 | u8 nextShmId; /* Next available winShm.id value */ |
| 51393 | 51466 | #endif |
| 51394 | 51467 | }; |
| | @@ -51412,10 +51485,11 @@ |
| 51412 | 51485 | HANDLE hShm; /* File-handle on *-shm file. For locking. */ |
| 51413 | 51486 | int bReadonly; /* True if hShm is opened read-only */ |
| 51414 | 51487 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 51415 | 51488 | u8 id; /* Id of this connection with its winShmNode */ |
| 51416 | 51489 | #endif |
| 51490 | + winShm *pWinShmNext; /* Next winShm object on same winShmNode */ |
| 51417 | 51491 | }; |
| 51418 | 51492 | |
| 51419 | 51493 | /* |
| 51420 | 51494 | ** Constants used for locking |
| 51421 | 51495 | */ |
| | @@ -51425,11 +51499,11 @@ |
| 51425 | 51499 | /* Forward references to VFS methods */ |
| 51426 | 51500 | static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*); |
| 51427 | 51501 | static int winDelete(sqlite3_vfs *,const char*,int); |
| 51428 | 51502 | |
| 51429 | 51503 | /* |
| 51430 | | -** Purge the winShmNodeList list of all entries with winShmNode.nRef==0. |
| 51504 | +** Purge the winShmNodeList list of all entries with winShmNode.pWinShmList==0. |
| 51431 | 51505 | ** |
| 51432 | 51506 | ** This is not a VFS shared-memory method; it is a utility function called |
| 51433 | 51507 | ** by VFS shared-memory methods. |
| 51434 | 51508 | */ |
| 51435 | 51509 | static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){ |
| | @@ -51438,11 +51512,11 @@ |
| 51438 | 51512 | assert( winShmMutexHeld() ); |
| 51439 | 51513 | OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n", |
| 51440 | 51514 | osGetCurrentProcessId(), deleteFlag)); |
| 51441 | 51515 | pp = &winShmNodeList; |
| 51442 | 51516 | while( (p = *pp)!=0 ){ |
| 51443 | | - if( p->nRef==0 ){ |
| 51517 | + if( p->pWinShmList==0 ){ |
| 51444 | 51518 | int i; |
| 51445 | 51519 | if( p->mutex ){ sqlite3_mutex_free(p->mutex); } |
| 51446 | 51520 | for(i=0; i<p->nRegion; i++){ |
| 51447 | 51521 | BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap); |
| 51448 | 51522 | OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n", |
| | @@ -51602,10 +51676,64 @@ |
| 51602 | 51676 | *pbReadonly = bReadonly; |
| 51603 | 51677 | *ph = h; |
| 51604 | 51678 | return rc; |
| 51605 | 51679 | } |
| 51606 | 51680 | |
| 51681 | +/* |
| 51682 | +** Close pDbFd's connection to shared-memory. Delete the underlying |
| 51683 | +** *-shm file if deleteFlag is true. |
| 51684 | +*/ |
| 51685 | +static int winCloseSharedMemory(winFile *pDbFd, int deleteFlag){ |
| 51686 | + winShm *p; /* The connection to be closed */ |
| 51687 | + winShm **pp; /* Iterator for pShmNode->pWinShmList */ |
| 51688 | + winShmNode *pShmNode; /* The underlying shared-memory file */ |
| 51689 | + |
| 51690 | + p = pDbFd->pShm; |
| 51691 | + if( p==0 ) return SQLITE_OK; |
| 51692 | + if( p->hShm!=INVALID_HANDLE_VALUE ){ |
| 51693 | + osCloseHandle(p->hShm); |
| 51694 | + } |
| 51695 | + |
| 51696 | + winShmEnterMutex(); |
| 51697 | + pShmNode = p->pShmNode; |
| 51698 | + |
| 51699 | + /* Remove this connection from the winShmNode.pWinShmList list */ |
| 51700 | + sqlite3_mutex_enter(pShmNode->mutex); |
| 51701 | + for(pp=&pShmNode->pWinShmList; *pp!=p; pp=&(*pp)->pWinShmNext){} |
| 51702 | + *pp = p->pWinShmNext; |
| 51703 | + sqlite3_mutex_leave(pShmNode->mutex); |
| 51704 | + |
| 51705 | + winShmPurge(pDbFd->pVfs, deleteFlag); |
| 51706 | + winShmLeaveMutex(); |
| 51707 | + |
| 51708 | + /* Free the connection p */ |
| 51709 | + sqlite3_free(p); |
| 51710 | + pDbFd->pShm = 0; |
| 51711 | + return SQLITE_OK; |
| 51712 | +} |
| 51713 | + |
| 51714 | +/* |
| 51715 | +** testfixture builds may set this global variable to true via a |
| 51716 | +** Tcl interface. This forces the VFS to use the locking normally |
| 51717 | +** only used for UNC paths for all files. |
| 51718 | +*/ |
| 51719 | +#ifdef SQLITE_TEST |
| 51720 | +SQLITE_API int sqlite3_win_test_unc_locking = 0; |
| 51721 | +#else |
| 51722 | +# define sqlite3_win_test_unc_locking 0 |
| 51723 | +#endif |
| 51724 | + |
| 51725 | +/* |
| 51726 | +** Return true if the string passed as the only argument is likely |
| 51727 | +** to be a UNC path. In other words, if it starts with "\\". |
| 51728 | +*/ |
| 51729 | +static int winIsUNCPath(const char *zFile){ |
| 51730 | + if( zFile[0]=='\\' && zFile[1]=='\\' ){ |
| 51731 | + return 1; |
| 51732 | + } |
| 51733 | + return sqlite3_win_test_unc_locking; |
| 51734 | +} |
| 51607 | 51735 | |
| 51608 | 51736 | /* |
| 51609 | 51737 | ** Open the shared-memory area associated with database file pDbFd. |
| 51610 | 51738 | */ |
| 51611 | 51739 | static int winOpenSharedMemory(winFile *pDbFd){ |
| | @@ -51628,19 +51756,14 @@ |
| 51628 | 51756 | return SQLITE_IOERR_NOMEM_BKPT; |
| 51629 | 51757 | } |
| 51630 | 51758 | pNew->zFilename = (char*)&pNew[1]; |
| 51631 | 51759 | pNew->hSharedShm = INVALID_HANDLE_VALUE; |
| 51632 | 51760 | pNew->isUnlocked = 1; |
| 51761 | + pNew->bUseSharedLockHandle = winIsUNCPath(pDbFd->zPath); |
| 51633 | 51762 | sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); |
| 51634 | 51763 | sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); |
| 51635 | 51764 | |
| 51636 | | - /* Open a file-handle on the *-shm file for this connection. This file-handle |
| 51637 | | - ** is only used for locking. The mapping of the *-shm file is created using |
| 51638 | | - ** the shared file handle in winShmNode.hSharedShm. */ |
| 51639 | | - p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0); |
| 51640 | | - rc = winHandleOpen(pNew->zFilename, &p->bReadonly, &p->hShm); |
| 51641 | | - |
| 51642 | 51765 | /* Look to see if there is an existing winShmNode that can be used. |
| 51643 | 51766 | ** If no matching winShmNode currently exists, then create a new one. */ |
| 51644 | 51767 | winShmEnterMutex(); |
| 51645 | 51768 | for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){ |
| 51646 | 51769 | /* TBD need to come up with better match here. Perhaps |
| | @@ -51657,11 +51780,11 @@ |
| 51657 | 51780 | } |
| 51658 | 51781 | |
| 51659 | 51782 | /* Open a file-handle to use for mappings, and for the DMS lock. */ |
| 51660 | 51783 | if( rc==SQLITE_OK ){ |
| 51661 | 51784 | HANDLE h = INVALID_HANDLE_VALUE; |
| 51662 | | - pShmNode->isReadonly = p->bReadonly; |
| 51785 | + pShmNode->isReadonly = sqlite3_uri_boolean(pDbFd->zPath,"readonly_shm",0); |
| 51663 | 51786 | rc = winHandleOpen(pNew->zFilename, &pShmNode->isReadonly, &h); |
| 51664 | 51787 | pShmNode->hSharedShm = h; |
| 51665 | 51788 | } |
| 51666 | 51789 | |
| 51667 | 51790 | /* If successful, link the new winShmNode into the global list. If an |
| | @@ -51679,24 +51802,39 @@ |
| 51679 | 51802 | } |
| 51680 | 51803 | |
| 51681 | 51804 | /* If no error has occurred, link the winShm object to the winShmNode and |
| 51682 | 51805 | ** the winShm to pDbFd. */ |
| 51683 | 51806 | if( rc==SQLITE_OK ){ |
| 51807 | + sqlite3_mutex_enter(pShmNode->mutex); |
| 51684 | 51808 | p->pShmNode = pShmNode; |
| 51685 | | - pShmNode->nRef++; |
| 51809 | + p->pWinShmNext = pShmNode->pWinShmList; |
| 51810 | + pShmNode->pWinShmList = p; |
| 51686 | 51811 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE) |
| 51687 | 51812 | p->id = pShmNode->nextShmId++; |
| 51688 | 51813 | #endif |
| 51689 | 51814 | pDbFd->pShm = p; |
| 51815 | + sqlite3_mutex_leave(pShmNode->mutex); |
| 51690 | 51816 | }else if( p ){ |
| 51691 | | - winHandleClose(p->hShm); |
| 51692 | 51817 | sqlite3_free(p); |
| 51693 | 51818 | } |
| 51694 | 51819 | |
| 51695 | 51820 | assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 ); |
| 51696 | 51821 | winShmLeaveMutex(); |
| 51697 | 51822 | sqlite3_free(pNew); |
| 51823 | + |
| 51824 | + /* Open a file-handle on the *-shm file for this connection. This file-handle |
| 51825 | + ** is only used for locking. The mapping of the *-shm file is created using |
| 51826 | + ** the shared file handle in winShmNode.hSharedShm. */ |
| 51827 | + if( rc==SQLITE_OK && pShmNode->bUseSharedLockHandle==0 ){ |
| 51828 | + p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0); |
| 51829 | + rc = winHandleOpen(pShmNode->zFilename, &p->bReadonly, &p->hShm); |
| 51830 | + if( rc!=SQLITE_OK ){ |
| 51831 | + assert( p->hShm==INVALID_HANDLE_VALUE ); |
| 51832 | + winCloseSharedMemory(pDbFd, 0); |
| 51833 | + } |
| 51834 | + } |
| 51835 | + |
| 51698 | 51836 | return rc; |
| 51699 | 51837 | } |
| 51700 | 51838 | |
| 51701 | 51839 | /* |
| 51702 | 51840 | ** Close a connection to shared-memory. Delete the underlying |
| | @@ -51704,37 +51842,11 @@ |
| 51704 | 51842 | */ |
| 51705 | 51843 | static int winShmUnmap( |
| 51706 | 51844 | sqlite3_file *fd, /* Database holding shared memory */ |
| 51707 | 51845 | int deleteFlag /* Delete after closing if true */ |
| 51708 | 51846 | ){ |
| 51709 | | - winFile *pDbFd; /* Database holding shared-memory */ |
| 51710 | | - winShm *p; /* The connection to be closed */ |
| 51711 | | - winShmNode *pShmNode; /* The underlying shared-memory file */ |
| 51712 | | - |
| 51713 | | - pDbFd = (winFile*)fd; |
| 51714 | | - p = pDbFd->pShm; |
| 51715 | | - if( p==0 ) return SQLITE_OK; |
| 51716 | | - if( p->hShm!=INVALID_HANDLE_VALUE ){ |
| 51717 | | - osCloseHandle(p->hShm); |
| 51718 | | - } |
| 51719 | | - |
| 51720 | | - pShmNode = p->pShmNode; |
| 51721 | | - winShmEnterMutex(); |
| 51722 | | - |
| 51723 | | - /* If pShmNode->nRef has reached 0, then close the underlying |
| 51724 | | - ** shared-memory file, too. */ |
| 51725 | | - assert( pShmNode->nRef>0 ); |
| 51726 | | - pShmNode->nRef--; |
| 51727 | | - if( pShmNode->nRef==0 ){ |
| 51728 | | - winShmPurge(pDbFd->pVfs, deleteFlag); |
| 51729 | | - } |
| 51730 | | - winShmLeaveMutex(); |
| 51731 | | - |
| 51732 | | - /* Free the connection p */ |
| 51733 | | - sqlite3_free(p); |
| 51734 | | - pDbFd->pShm = 0; |
| 51735 | | - return SQLITE_OK; |
| 51847 | + return winCloseSharedMemory((winFile*)fd, deleteFlag); |
| 51736 | 51848 | } |
| 51737 | 51849 | |
| 51738 | 51850 | /* |
| 51739 | 51851 | ** Change the lock state for a shared-memory segment. |
| 51740 | 51852 | */ |
| | @@ -51799,29 +51911,75 @@ |
| 51799 | 51911 | ); |
| 51800 | 51912 | if( ((flags & SQLITE_SHM_UNLOCK) && ((p->exclMask|p->sharedMask) & mask)) |
| 51801 | 51913 | || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask)) |
| 51802 | 51914 | || (flags==(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK)) |
| 51803 | 51915 | ){ |
| 51916 | + HANDLE h = p->hShm; |
| 51804 | 51917 | |
| 51805 | 51918 | if( flags & SQLITE_SHM_UNLOCK ){ |
| 51806 | 51919 | /* Case (a) - unlock. */ |
| 51807 | 51920 | |
| 51808 | 51921 | assert( (p->exclMask & p->sharedMask)==0 ); |
| 51809 | 51922 | assert( !(flags & SQLITE_SHM_EXCLUSIVE) || (p->exclMask & mask)==mask ); |
| 51810 | 51923 | assert( !(flags & SQLITE_SHM_SHARED) || (p->sharedMask & mask)==mask ); |
| 51811 | 51924 | |
| 51812 | | - rc = winHandleUnlock(p->hShm, ofst+WIN_SHM_BASE, n); |
| 51925 | + assert( !(flags & SQLITE_SHM_SHARED) || n==1 ); |
| 51926 | + if( pShmNode->bUseSharedLockHandle ){ |
| 51927 | + h = pShmNode->hSharedShm; |
| 51928 | + if( flags & SQLITE_SHM_SHARED ){ |
| 51929 | + winShm *pShm; |
| 51930 | + sqlite3_mutex_enter(pShmNode->mutex); |
| 51931 | + for(pShm=pShmNode->pWinShmList; pShm; pShm=pShm->pWinShmNext){ |
| 51932 | + if( pShm!=p && (pShm->sharedMask & mask) ){ |
| 51933 | + /* Another connection within this process is also holding this |
| 51934 | + ** SHARED lock. So do not actually release the OS lock. */ |
| 51935 | + h = INVALID_HANDLE_VALUE; |
| 51936 | + break; |
| 51937 | + } |
| 51938 | + } |
| 51939 | + sqlite3_mutex_leave(pShmNode->mutex); |
| 51940 | + } |
| 51941 | + } |
| 51942 | + |
| 51943 | + if( h!=INVALID_HANDLE_VALUE ){ |
| 51944 | + rc = winHandleUnlock(h, ofst+WIN_SHM_BASE, n); |
| 51945 | + } |
| 51813 | 51946 | |
| 51814 | 51947 | /* If successful, also clear the bits in sharedMask/exclMask */ |
| 51815 | 51948 | if( rc==SQLITE_OK ){ |
| 51816 | 51949 | p->exclMask = (p->exclMask & ~mask); |
| 51817 | 51950 | p->sharedMask = (p->sharedMask & ~mask); |
| 51818 | 51951 | } |
| 51819 | 51952 | }else{ |
| 51820 | 51953 | int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0); |
| 51821 | 51954 | DWORD nMs = winFileBusyTimeout(pDbFd); |
| 51822 | | - rc = winHandleLockTimeout(p->hShm, ofst+WIN_SHM_BASE, n, bExcl, nMs); |
| 51955 | + |
| 51956 | + if( pShmNode->bUseSharedLockHandle ){ |
| 51957 | + winShm *pShm; |
| 51958 | + h = pShmNode->hSharedShm; |
| 51959 | + sqlite3_mutex_enter(pShmNode->mutex); |
| 51960 | + for(pShm=pShmNode->pWinShmList; pShm; pShm=pShm->pWinShmNext){ |
| 51961 | + if( bExcl ){ |
| 51962 | + if( (pShm->sharedMask|pShm->exclMask) & mask ){ |
| 51963 | + rc = SQLITE_BUSY; |
| 51964 | + h = INVALID_HANDLE_VALUE; |
| 51965 | + } |
| 51966 | + }else{ |
| 51967 | + if( pShm->sharedMask & mask ){ |
| 51968 | + h = INVALID_HANDLE_VALUE; |
| 51969 | + }else if( pShm->exclMask & mask ){ |
| 51970 | + rc = SQLITE_BUSY; |
| 51971 | + h = INVALID_HANDLE_VALUE; |
| 51972 | + } |
| 51973 | + } |
| 51974 | + } |
| 51975 | + sqlite3_mutex_leave(pShmNode->mutex); |
| 51976 | + } |
| 51977 | + |
| 51978 | + if( h!=INVALID_HANDLE_VALUE ){ |
| 51979 | + rc = winHandleLockTimeout(h, ofst+WIN_SHM_BASE, n, bExcl, nMs); |
| 51980 | + } |
| 51823 | 51981 | if( rc==SQLITE_OK ){ |
| 51824 | 51982 | if( bExcl ){ |
| 51825 | 51983 | p->exclMask = (p->exclMask | mask); |
| 51826 | 51984 | }else{ |
| 51827 | 51985 | p->sharedMask = (p->sharedMask | mask); |
| | @@ -65748,11 +65906,11 @@ |
| 65748 | 65906 | */ |
| 65749 | 65907 | sqlite3_exec(db, "PRAGMA table_list",0,0,0); |
| 65750 | 65908 | } |
| 65751 | 65909 | if( pPager->pWal ){ |
| 65752 | 65910 | rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode, |
| 65753 | | - (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 65911 | + (eMode<=SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 65754 | 65912 | pPager->pBusyHandlerArg, |
| 65755 | 65913 | pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 65756 | 65914 | pnLog, pnCkpt |
| 65757 | 65915 | ); |
| 65758 | 65916 | } |
| | @@ -70353,11 +70511,12 @@ |
| 70353 | 70511 | assert( pWal->ckptLock==0 ); |
| 70354 | 70512 | assert( pWal->writeLock==0 ); |
| 70355 | 70513 | |
| 70356 | 70514 | /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked |
| 70357 | 70515 | ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ |
| 70358 | | - assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 70516 | + assert( SQLITE_CHECKPOINT_NOOP<SQLITE_CHECKPOINT_PASSIVE ); |
| 70517 | + assert( eMode>SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 70359 | 70518 | |
| 70360 | 70519 | if( pWal->readOnly ) return SQLITE_READONLY; |
| 70361 | 70520 | WALTRACE(("WAL%p: checkpoint begins\n", pWal)); |
| 70362 | 70521 | |
| 70363 | 70522 | /* Enable blocking locks, if possible. */ |
| | @@ -70370,35 +70529,39 @@ |
| 70370 | 70529 | ** checkpoint operation at the same time, the lock cannot be obtained and |
| 70371 | 70530 | ** SQLITE_BUSY is returned. |
| 70372 | 70531 | ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, |
| 70373 | 70532 | ** it will not be invoked in this case. |
| 70374 | 70533 | */ |
| 70375 | | - rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 70376 | | - testcase( rc==SQLITE_BUSY ); |
| 70377 | | - testcase( rc!=SQLITE_OK && xBusy2!=0 ); |
| 70378 | | - if( rc==SQLITE_OK ){ |
| 70379 | | - pWal->ckptLock = 1; |
| 70380 | | - |
| 70381 | | - /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and |
| 70382 | | - ** TRUNCATE modes also obtain the exclusive "writer" lock on the database |
| 70383 | | - ** file. |
| 70384 | | - ** |
| 70385 | | - ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained |
| 70386 | | - ** immediately, and a busy-handler is configured, it is invoked and the |
| 70387 | | - ** writer lock retried until either the busy-handler returns 0 or the |
| 70388 | | - ** lock is successfully obtained. |
| 70389 | | - */ |
| 70390 | | - if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 70391 | | - rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1); |
| 70392 | | - if( rc==SQLITE_OK ){ |
| 70393 | | - pWal->writeLock = 1; |
| 70394 | | - }else if( rc==SQLITE_BUSY ){ |
| 70395 | | - eMode2 = SQLITE_CHECKPOINT_PASSIVE; |
| 70396 | | - xBusy2 = 0; |
| 70397 | | - rc = SQLITE_OK; |
| 70398 | | - } |
| 70399 | | - } |
| 70534 | + if( eMode!=SQLITE_CHECKPOINT_NOOP ){ |
| 70535 | + rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 70536 | + testcase( rc==SQLITE_BUSY ); |
| 70537 | + testcase( rc!=SQLITE_OK && xBusy2!=0 ); |
| 70538 | + if( rc==SQLITE_OK ){ |
| 70539 | + pWal->ckptLock = 1; |
| 70540 | + |
| 70541 | + /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART |
| 70542 | + ** and TRUNCATE modes also obtain the exclusive "writer" lock on the |
| 70543 | + ** database file. |
| 70544 | + ** |
| 70545 | + ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained |
| 70546 | + ** immediately, and a busy-handler is configured, it is invoked and the |
| 70547 | + ** writer lock retried until either the busy-handler returns 0 or the |
| 70548 | + ** lock is successfully obtained. |
| 70549 | + */ |
| 70550 | + if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 70551 | + rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1); |
| 70552 | + if( rc==SQLITE_OK ){ |
| 70553 | + pWal->writeLock = 1; |
| 70554 | + }else if( rc==SQLITE_BUSY ){ |
| 70555 | + eMode2 = SQLITE_CHECKPOINT_PASSIVE; |
| 70556 | + xBusy2 = 0; |
| 70557 | + rc = SQLITE_OK; |
| 70558 | + } |
| 70559 | + } |
| 70560 | + } |
| 70561 | + }else{ |
| 70562 | + rc = SQLITE_OK; |
| 70400 | 70563 | } |
| 70401 | 70564 | |
| 70402 | 70565 | |
| 70403 | 70566 | /* Read the wal-index header. */ |
| 70404 | 70567 | SEH_TRY { |
| | @@ -70408,21 +70571,21 @@ |
| 70408 | 70571 | ** or invoke the busy handler. The only lock such a checkpoint may |
| 70409 | 70572 | ** attempt to obtain is a lock on a read-slot, and it should give up |
| 70410 | 70573 | ** immediately and do a partial checkpoint if it cannot obtain it. */ |
| 70411 | 70574 | walDisableBlocking(pWal); |
| 70412 | 70575 | rc = walIndexReadHdr(pWal, &isChanged); |
| 70413 | | - if( eMode2!=SQLITE_CHECKPOINT_PASSIVE ) (void)walEnableBlocking(pWal); |
| 70576 | + if( eMode2>SQLITE_CHECKPOINT_PASSIVE ) (void)walEnableBlocking(pWal); |
| 70414 | 70577 | if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){ |
| 70415 | 70578 | sqlite3OsUnfetch(pWal->pDbFd, 0, 0); |
| 70416 | 70579 | } |
| 70417 | 70580 | } |
| 70418 | 70581 | |
| 70419 | 70582 | /* Copy data from the log to the database file. */ |
| 70420 | 70583 | if( rc==SQLITE_OK ){ |
| 70421 | 70584 | if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){ |
| 70422 | 70585 | rc = SQLITE_CORRUPT_BKPT; |
| 70423 | | - }else{ |
| 70586 | + }else if( eMode2!=SQLITE_CHECKPOINT_NOOP ){ |
| 70424 | 70587 | rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags,zBuf); |
| 70425 | 70588 | } |
| 70426 | 70589 | |
| 70427 | 70590 | /* If no error occurred, set the output variables. */ |
| 70428 | 70591 | if( rc==SQLITE_OK || rc==SQLITE_BUSY ){ |
| | @@ -91645,11 +91808,11 @@ |
| 91645 | 91808 | |
| 91646 | 91809 | preupdate.v = v; |
| 91647 | 91810 | preupdate.pCsr = pCsr; |
| 91648 | 91811 | preupdate.op = op; |
| 91649 | 91812 | preupdate.iNewReg = iReg; |
| 91650 | | - preupdate.pKeyinfo = (KeyInfo*)&preupdate.keyinfoSpace; |
| 91813 | + preupdate.pKeyinfo = &preupdate.uKey.sKey; |
| 91651 | 91814 | preupdate.pKeyinfo->db = db; |
| 91652 | 91815 | preupdate.pKeyinfo->enc = ENC(db); |
| 91653 | 91816 | preupdate.pKeyinfo->nKeyField = pTab->nCol; |
| 91654 | 91817 | preupdate.pKeyinfo->aSortFlags = 0; /* Indicate .aColl, .nAllField uninit */ |
| 91655 | 91818 | preupdate.iKey1 = iKey1; |
| | @@ -102528,10 +102691,11 @@ |
| 102528 | 102691 | aRes[1] = aRes[2] = -1; |
| 102529 | 102692 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 102530 | 102693 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 102531 | 102694 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 102532 | 102695 | || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE |
| 102696 | + || pOp->p2==SQLITE_CHECKPOINT_NOOP |
| 102533 | 102697 | ); |
| 102534 | 102698 | rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); |
| 102535 | 102699 | if( rc ){ |
| 102536 | 102700 | if( rc!=SQLITE_BUSY ) goto abort_due_to_error; |
| 102537 | 102701 | rc = SQLITE_OK; |
| | @@ -110651,18 +110815,21 @@ |
| 110651 | 110815 | ExprList *pList /* Expression list to resolve. May be NULL. */ |
| 110652 | 110816 | ){ |
| 110653 | 110817 | SrcList *pSrc; /* Fake SrcList for pParse->pNewTable */ |
| 110654 | 110818 | NameContext sNC; /* Name context for pParse->pNewTable */ |
| 110655 | 110819 | int rc; |
| 110656 | | - u8 srcSpace[SZ_SRCLIST_1]; /* Memory space for the fake SrcList */ |
| 110820 | + union { |
| 110821 | + SrcList sSrc; |
| 110822 | + u8 srcSpace[SZ_SRCLIST_1]; /* Memory space for the fake SrcList */ |
| 110823 | + } uSrc; |
| 110657 | 110824 | |
| 110658 | 110825 | assert( type==0 || pTab!=0 ); |
| 110659 | 110826 | assert( type==NC_IsCheck || type==NC_PartIdx || type==NC_IdxExpr |
| 110660 | 110827 | || type==NC_GenCol || pTab==0 ); |
| 110661 | 110828 | memset(&sNC, 0, sizeof(sNC)); |
| 110662 | | - pSrc = (SrcList*)srcSpace; |
| 110663 | | - memset(pSrc, 0, SZ_SRCLIST_1); |
| 110829 | + memset(&uSrc, 0, sizeof(uSrc)); |
| 110830 | + pSrc = &uSrc.sSrc; |
| 110664 | 110831 | if( pTab ){ |
| 110665 | 110832 | pSrc->nSrc = 1; |
| 110666 | 110833 | pSrc->a[0].zName = pTab->zName; |
| 110667 | 110834 | pSrc->a[0].pSTab = pTab; |
| 110668 | 110835 | pSrc->a[0].iCursor = -1; |
| | @@ -111920,10 +112087,15 @@ |
| 111920 | 112087 | } |
| 111921 | 112088 | if( IsWindowFunc(pExpr) ){ |
| 111922 | 112089 | sqlite3ExprOrderByAggregateError(pParse, pExpr); |
| 111923 | 112090 | sqlite3ExprListDelete(db, pOrderBy); |
| 111924 | 112091 | return; |
| 112092 | + } |
| 112093 | + if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 112094 | + sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause"); |
| 112095 | + sqlite3ExprListDelete(db, pOrderBy); |
| 112096 | + return; |
| 111925 | 112097 | } |
| 111926 | 112098 | |
| 111927 | 112099 | pOB = sqlite3ExprAlloc(db, TK_ORDER, 0, 0); |
| 111928 | 112100 | if( pOB==0 ){ |
| 111929 | 112101 | sqlite3ExprListDelete(db, pOrderBy); |
| | @@ -114683,11 +114855,10 @@ |
| 114683 | 114855 | int destIfNull /* Jump here if the results are unknown due to NULLs */ |
| 114684 | 114856 | ){ |
| 114685 | 114857 | int rRhsHasNull = 0; /* Register that is true if RHS contains NULL values */ |
| 114686 | 114858 | int eType; /* Type of the RHS */ |
| 114687 | 114859 | int rLhs; /* Register(s) holding the LHS values */ |
| 114688 | | - int rLhsOrig; /* LHS values prior to reordering by aiMap[] */ |
| 114689 | 114860 | Vdbe *v; /* Statement under construction */ |
| 114690 | 114861 | int *aiMap = 0; /* Map from vector field to index column */ |
| 114691 | 114862 | char *zAff = 0; /* Affinity string for comparisons */ |
| 114692 | 114863 | int nVector; /* Size of vectors for this IN operator */ |
| 114693 | 114864 | int iDummy; /* Dummy parameter to exprCodeVector() */ |
| | @@ -114746,23 +114917,12 @@ |
| 114746 | 114917 | ** Avoid factoring the LHS of the IN(...) expression out of the loop, |
| 114747 | 114918 | ** even if it is constant, as OP_Affinity may be used on the register |
| 114748 | 114919 | ** by code generated below. */ |
| 114749 | 114920 | assert( pParse->okConstFactor==okConstFactor ); |
| 114750 | 114921 | pParse->okConstFactor = 0; |
| 114751 | | - rLhsOrig = exprCodeVector(pParse, pLeft, &iDummy); |
| 114922 | + rLhs = exprCodeVector(pParse, pLeft, &iDummy); |
| 114752 | 114923 | pParse->okConstFactor = okConstFactor; |
| 114753 | | - for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */ |
| 114754 | | - if( i==nVector ){ |
| 114755 | | - /* LHS fields are not reordered */ |
| 114756 | | - rLhs = rLhsOrig; |
| 114757 | | - }else{ |
| 114758 | | - /* Need to reorder the LHS fields according to aiMap */ |
| 114759 | | - rLhs = sqlite3GetTempRange(pParse, nVector); |
| 114760 | | - for(i=0; i<nVector; i++){ |
| 114761 | | - sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0); |
| 114762 | | - } |
| 114763 | | - } |
| 114764 | 114924 | |
| 114765 | 114925 | /* If sqlite3FindInIndex() did not find or create an index that is |
| 114766 | 114926 | ** suitable for evaluating the IN operator, then evaluate using a |
| 114767 | 114927 | ** sequence of comparisons. |
| 114768 | 114928 | ** |
| | @@ -114773,10 +114933,11 @@ |
| 114773 | 114933 | CollSeq *pColl; |
| 114774 | 114934 | int labelOk = sqlite3VdbeMakeLabel(pParse); |
| 114775 | 114935 | int r2, regToFree; |
| 114776 | 114936 | int regCkNull = 0; |
| 114777 | 114937 | int ii; |
| 114938 | + assert( nVector==1 ); |
| 114778 | 114939 | assert( ExprUseXList(pExpr) ); |
| 114779 | 114940 | pList = pExpr->x.pList; |
| 114780 | 114941 | pColl = sqlite3ExprCollSeq(pParse, pExpr->pLeft); |
| 114781 | 114942 | if( destIfNull!=destIfFalse ){ |
| 114782 | 114943 | regCkNull = sqlite3GetTempReg(pParse); |
| | @@ -114813,10 +114974,30 @@ |
| 114813 | 114974 | } |
| 114814 | 114975 | sqlite3VdbeResolveLabel(v, labelOk); |
| 114815 | 114976 | sqlite3ReleaseTempReg(pParse, regCkNull); |
| 114816 | 114977 | goto sqlite3ExprCodeIN_finished; |
| 114817 | 114978 | } |
| 114979 | + |
| 114980 | + if( eType!=IN_INDEX_ROWID ){ |
| 114981 | + /* If this IN operator will use an index, then the order of columns in the |
| 114982 | + ** vector might be different from the order in the index. In that case, |
| 114983 | + ** we need to reorder the LHS values to be in index order. Run Affinity |
| 114984 | + ** before reordering the columns, so that the affinity is correct. |
| 114985 | + */ |
| 114986 | + sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector); |
| 114987 | + for(i=0; i<nVector && aiMap[i]==i; i++){} /* Are LHS fields reordered? */ |
| 114988 | + if( i!=nVector ){ |
| 114989 | + /* Need to reorder the LHS fields according to aiMap */ |
| 114990 | + int rLhsOrig = rLhs; |
| 114991 | + rLhs = sqlite3GetTempRange(pParse, nVector); |
| 114992 | + for(i=0; i<nVector; i++){ |
| 114993 | + sqlite3VdbeAddOp3(v, OP_Copy, rLhsOrig+i, rLhs+aiMap[i], 0); |
| 114994 | + } |
| 114995 | + sqlite3ReleaseTempReg(pParse, rLhsOrig); |
| 114996 | + } |
| 114997 | + } |
| 114998 | + |
| 114818 | 114999 | |
| 114819 | 115000 | /* Step 2: Check to see if the LHS contains any NULL columns. If the |
| 114820 | 115001 | ** LHS does contain NULLs then the result must be either FALSE or NULL. |
| 114821 | 115002 | ** We will then skip the binary search of the RHS. |
| 114822 | 115003 | */ |
| | @@ -114840,15 +115021,15 @@ |
| 114840 | 115021 | */ |
| 114841 | 115022 | if( eType==IN_INDEX_ROWID ){ |
| 114842 | 115023 | /* In this case, the RHS is the ROWID of table b-tree and so we also |
| 114843 | 115024 | ** know that the RHS is non-NULL. Hence, we combine steps 3 and 4 |
| 114844 | 115025 | ** into a single opcode. */ |
| 115026 | + assert( nVector==1 ); |
| 114845 | 115027 | sqlite3VdbeAddOp3(v, OP_SeekRowid, iTab, destIfFalse, rLhs); |
| 114846 | 115028 | VdbeCoverage(v); |
| 114847 | 115029 | addrTruthOp = sqlite3VdbeAddOp0(v, OP_Goto); /* Return True */ |
| 114848 | 115030 | }else{ |
| 114849 | | - sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector); |
| 114850 | 115031 | if( destIfFalse==destIfNull ){ |
| 114851 | 115032 | /* Combine Step 3 and Step 5 into a single opcode */ |
| 114852 | 115033 | if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 114853 | 115034 | const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr); |
| 114854 | 115035 | assert( pOp->opcode==OP_Once || pParse->nErr ); |
| | @@ -114922,11 +115103,10 @@ |
| 114922 | 115103 | |
| 114923 | 115104 | /* Jumps here in order to return true. */ |
| 114924 | 115105 | sqlite3VdbeJumpHere(v, addrTruthOp); |
| 114925 | 115106 | |
| 114926 | 115107 | sqlite3ExprCodeIN_finished: |
| 114927 | | - if( rLhs!=rLhsOrig ) sqlite3ReleaseTempReg(pParse, rLhs); |
| 114928 | 115108 | VdbeComment((v, "end IN expr")); |
| 114929 | 115109 | sqlite3ExprCodeIN_oom_error: |
| 114930 | 115110 | sqlite3DbFree(pParse->db, aiMap); |
| 114931 | 115111 | sqlite3DbFree(pParse->db, zAff); |
| 114932 | 115112 | } |
| | @@ -124573,11 +124753,11 @@ |
| 124573 | 124753 | */ |
| 124574 | 124754 | SQLITE_PRIVATE int sqlite3TableColumnToIndex(Index *pIdx, int iCol){ |
| 124575 | 124755 | int i; |
| 124576 | 124756 | i16 iCol16; |
| 124577 | 124757 | assert( iCol>=(-1) && iCol<=SQLITE_MAX_COLUMN ); |
| 124578 | | - assert( pIdx->nColumn<=SQLITE_MAX_COLUMN+1 ); |
| 124758 | + assert( pIdx->nColumn<=SQLITE_MAX_COLUMN*2 ); |
| 124579 | 124759 | iCol16 = iCol; |
| 124580 | 124760 | for(i=0; i<pIdx->nColumn; i++){ |
| 124581 | 124761 | if( iCol16==pIdx->aiColumn[i] ){ |
| 124582 | 124762 | return i; |
| 124583 | 124763 | } |
| | @@ -129165,18 +129345,23 @@ |
| 129165 | 129345 | pKey->aSortFlags[i] = pIdx->aSortOrder[i]; |
| 129166 | 129346 | assert( 0==(pKey->aSortFlags[i] & KEYINFO_ORDER_BIGNULL) ); |
| 129167 | 129347 | } |
| 129168 | 129348 | if( pParse->nErr ){ |
| 129169 | 129349 | assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ ); |
| 129170 | | - if( pIdx->bNoQuery==0 ){ |
| 129350 | + if( pIdx->bNoQuery==0 |
| 129351 | + && sqlite3HashFind(&pIdx->pSchema->idxHash, pIdx->zName) |
| 129352 | + ){ |
| 129171 | 129353 | /* Deactivate the index because it contains an unknown collating |
| 129172 | 129354 | ** sequence. The only way to reactive the index is to reload the |
| 129173 | 129355 | ** schema. Adding the missing collating sequence later does not |
| 129174 | 129356 | ** reactive the index. The application had the chance to register |
| 129175 | 129357 | ** the missing index using the collation-needed callback. For |
| 129176 | 129358 | ** simplicity, SQLite will not give the application a second chance. |
| 129177 | | - */ |
| 129359 | + ** |
| 129360 | + ** Except, do not do this if the index is not in the schema hash |
| 129361 | + ** table. In this case the index is currently being constructed |
| 129362 | + ** by a CREATE INDEX statement, and retrying will not help. */ |
| 129178 | 129363 | pIdx->bNoQuery = 1; |
| 129179 | 129364 | pParse->rc = SQLITE_ERROR_RETRY; |
| 129180 | 129365 | } |
| 129181 | 129366 | sqlite3KeyInfoUnref(pKey); |
| 129182 | 129367 | pKey = 0; |
| | @@ -143548,10 +143733,12 @@ |
| 143548 | 143733 | eMode = SQLITE_CHECKPOINT_FULL; |
| 143549 | 143734 | }else if( sqlite3StrICmp(zRight, "restart")==0 ){ |
| 143550 | 143735 | eMode = SQLITE_CHECKPOINT_RESTART; |
| 143551 | 143736 | }else if( sqlite3StrICmp(zRight, "truncate")==0 ){ |
| 143552 | 143737 | eMode = SQLITE_CHECKPOINT_TRUNCATE; |
| 143738 | + }else if( sqlite3StrICmp(zRight, "noop")==0 ){ |
| 143739 | + eMode = SQLITE_CHECKPOINT_NOOP; |
| 143553 | 143740 | } |
| 143554 | 143741 | } |
| 143555 | 143742 | pParse->nMem = 3; |
| 143556 | 143743 | sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1); |
| 143557 | 143744 | sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3); |
| | @@ -145114,13 +145301,15 @@ |
| 145114 | 145301 | ** or encounters a permanent error. A schema problem after one schema |
| 145115 | 145302 | ** reset is considered a permanent error. */ |
| 145116 | 145303 | rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 145117 | 145304 | assert( rc==SQLITE_OK || *ppStmt==0 ); |
| 145118 | 145305 | if( rc==SQLITE_OK || db->mallocFailed ) break; |
| 145119 | | - }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY) |
| 145120 | | - || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) ); |
| 145306 | + cnt++; |
| 145307 | + }while( (rc==SQLITE_ERROR_RETRY && ALWAYS(cnt<=SQLITE_MAX_PREPARE_RETRY)) |
| 145308 | + || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt)==1) ); |
| 145121 | 145309 | sqlite3BtreeLeaveAll(db); |
| 145310 | + assert( rc!=SQLITE_ERROR_RETRY ); |
| 145122 | 145311 | rc = sqlite3ApiExit(db, rc); |
| 145123 | 145312 | assert( (rc&db->errMask)==rc ); |
| 145124 | 145313 | db->busyHandler.nBusy = 0; |
| 145125 | 145314 | sqlite3_mutex_leave(db->mutex); |
| 145126 | 145315 | assert( rc==SQLITE_OK || (*ppStmt)==0 ); |
| | @@ -145790,12 +145979,11 @@ |
| 145790 | 145979 | while( p ){ |
| 145791 | 145980 | ExprSetProperty(p, joinFlag); |
| 145792 | 145981 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 145793 | 145982 | ExprSetVVAProperty(p, EP_NoReduce); |
| 145794 | 145983 | p->w.iJoin = iTable; |
| 145795 | | - if( p->op==TK_FUNCTION ){ |
| 145796 | | - assert( ExprUseXList(p) ); |
| 145984 | + if( ExprUseXList(p) ){ |
| 145797 | 145985 | if( p->x.pList ){ |
| 145798 | 145986 | int i; |
| 145799 | 145987 | for(i=0; i<p->x.pList->nExpr; i++){ |
| 145800 | 145988 | sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable, joinFlag); |
| 145801 | 145989 | } |
| | @@ -146007,10 +146195,11 @@ |
| 146007 | 146195 | else if( pRight->u3.pOn ){ |
| 146008 | 146196 | sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType); |
| 146009 | 146197 | p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn); |
| 146010 | 146198 | pRight->u3.pOn = 0; |
| 146011 | 146199 | pRight->fg.isOn = 1; |
| 146200 | + p->selFlags |= SF_OnToWhere; |
| 146012 | 146201 | } |
| 146013 | 146202 | } |
| 146014 | 146203 | return 0; |
| 146015 | 146204 | } |
| 146016 | 146205 | |
| | @@ -146893,11 +147082,14 @@ |
| 146893 | 147082 | ** Allocate a KeyInfo object sufficient for an index of N key columns and |
| 146894 | 147083 | ** X extra columns. |
| 146895 | 147084 | */ |
| 146896 | 147085 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){ |
| 146897 | 147086 | int nExtra = (N+X)*(sizeof(CollSeq*)+1); |
| 146898 | | - KeyInfo *p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra); |
| 147087 | + KeyInfo *p; |
| 147088 | + assert( X>=0 ); |
| 147089 | + if( NEVER(N+X>0xffff) ) return (KeyInfo*)sqlite3OomFault(db); |
| 147090 | + p = sqlite3DbMallocRawNN(db, SZ_KEYINFO(0) + nExtra); |
| 146899 | 147091 | if( p ){ |
| 146900 | 147092 | p->aSortFlags = (u8*)&p->aColl[N+X]; |
| 146901 | 147093 | p->nKeyField = (u16)N; |
| 146902 | 147094 | p->nAllField = (u16)(N+X); |
| 146903 | 147095 | p->enc = ENC(db); |
| | @@ -149212,11 +149404,11 @@ |
| 149212 | 149404 | ** expressions in pEList. |
| 149213 | 149405 | ** |
| 149214 | 149406 | ** ## About "isOuterJoin": |
| 149215 | 149407 | ** |
| 149216 | 149408 | ** The isOuterJoin column indicates that the replacement will occur into a |
| 149217 | | -** position in the parent that NULL-able due to an OUTER JOIN. Either the |
| 149409 | +** position in the parent that is NULL-able due to an OUTER JOIN. Either the |
| 149218 | 149410 | ** target slot in the parent is the right operand of a LEFT JOIN, or one of |
| 149219 | 149411 | ** the left operands of a RIGHT JOIN. In either case, we need to potentially |
| 149220 | 149412 | ** bypass the substituted expression with OP_IfNullRow. |
| 149221 | 149413 | ** |
| 149222 | 149414 | ** Suppose the original expression is an integer constant. Even though the table |
| | @@ -150050,21 +150242,16 @@ |
| 150050 | 150242 | ** elements we are now copying in. |
| 150051 | 150243 | */ |
| 150052 | 150244 | pSub = pSub1; |
| 150053 | 150245 | for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){ |
| 150054 | 150246 | int nSubSrc; |
| 150055 | | - u8 jointype = 0; |
| 150056 | | - u8 ltorj = pSrc->a[iFrom].fg.jointype & JT_LTORJ; |
| 150247 | + u8 jointype = pSubitem->fg.jointype; |
| 150057 | 150248 | assert( pSub!=0 ); |
| 150058 | 150249 | pSubSrc = pSub->pSrc; /* FROM clause of subquery */ |
| 150059 | 150250 | nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */ |
| 150060 | 150251 | pSrc = pParent->pSrc; /* FROM clause of the outer query */ |
| 150061 | 150252 | |
| 150062 | | - if( pParent==p ){ |
| 150063 | | - jointype = pSubitem->fg.jointype; /* First time through the loop */ |
| 150064 | | - } |
| 150065 | | - |
| 150066 | 150253 | /* The subquery uses a single slot of the FROM clause of the outer |
| 150067 | 150254 | ** query. If the subquery has more than one element in its FROM clause, |
| 150068 | 150255 | ** then expand the outer query to make space for it to hold all elements |
| 150069 | 150256 | ** of the subquery. |
| 150070 | 150257 | ** |
| | @@ -150080,10 +150267,11 @@ |
| 150080 | 150267 | */ |
| 150081 | 150268 | if( nSubSrc>1 ){ |
| 150082 | 150269 | pSrc = sqlite3SrcListEnlarge(pParse, pSrc, nSubSrc-1,iFrom+1); |
| 150083 | 150270 | if( pSrc==0 ) break; |
| 150084 | 150271 | pParent->pSrc = pSrc; |
| 150272 | + pSubitem = &pSrc->a[iFrom]; |
| 150085 | 150273 | } |
| 150086 | 150274 | |
| 150087 | 150275 | /* Transfer the FROM clause terms from the subquery into the |
| 150088 | 150276 | ** outer query. |
| 150089 | 150277 | */ |
| | @@ -150094,15 +150282,14 @@ |
| 150094 | 150282 | assert( pItem->fg.isSubquery |
| 150095 | 150283 | || pItem->fg.fixedSchema |
| 150096 | 150284 | || pItem->u4.zDatabase==0 ); |
| 150097 | 150285 | if( pItem->fg.isUsing ) sqlite3IdListDelete(db, pItem->u3.pUsing); |
| 150098 | 150286 | *pItem = pSubSrc->a[i]; |
| 150099 | | - pItem->fg.jointype |= ltorj; |
| 150287 | + pItem->fg.jointype |= (jointype & JT_LTORJ); |
| 150100 | 150288 | memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i])); |
| 150101 | 150289 | } |
| 150102 | | - pSrc->a[iFrom].fg.jointype &= JT_LTORJ; |
| 150103 | | - pSrc->a[iFrom].fg.jointype |= jointype | ltorj; |
| 150290 | + pSubitem->fg.jointype |= jointype; |
| 150104 | 150291 | |
| 150105 | 150292 | /* Now begin substituting subquery result set expressions for |
| 150106 | 150293 | ** references to the iParent in the outer query. |
| 150107 | 150294 | ** |
| 150108 | 150295 | ** Example: |
| | @@ -152838,10 +153025,119 @@ |
| 152838 | 153025 | existsToJoin(pParse, p, pSubWhere); |
| 152839 | 153026 | } |
| 152840 | 153027 | } |
| 152841 | 153028 | } |
| 152842 | 153029 | } |
| 153030 | + |
| 153031 | +/* |
| 153032 | +** Type used for Walker callbacks by selectCheckOnClauses(). |
| 153033 | +*/ |
| 153034 | +typedef struct CheckOnCtx CheckOnCtx; |
| 153035 | +struct CheckOnCtx { |
| 153036 | + SrcList *pSrc; /* SrcList for this context */ |
| 153037 | + int iJoin; /* Cursor numbers must be =< than this */ |
| 153038 | + CheckOnCtx *pParent; /* Parent context */ |
| 153039 | +}; |
| 153040 | + |
| 153041 | +/* |
| 153042 | +** True if the SrcList passed as the only argument contains at least |
| 153043 | +** one RIGHT or FULL JOIN. False otherwise. |
| 153044 | +*/ |
| 153045 | +#define hasRightJoin(pSrc) (((pSrc)->a[0].fg.jointype & JT_LTORJ)!=0) |
| 153046 | + |
| 153047 | +/* |
| 153048 | +** The xExpr callback for the search of invalid ON clause terms. |
| 153049 | +*/ |
| 153050 | +static int selectCheckOnClausesExpr(Walker *pWalker, Expr *pExpr){ |
| 153051 | + CheckOnCtx *pCtx = pWalker->u.pCheckOnCtx; |
| 153052 | + |
| 153053 | + /* Check if pExpr is root or near-root of an ON clause constraint that needs |
| 153054 | + ** to be checked to ensure that it does not refer to tables in its FROM |
| 153055 | + ** clause to the right of itself. i.e. it is either: |
| 153056 | + ** |
| 153057 | + ** + an ON clause on an OUTER join, or |
| 153058 | + ** + an ON clause on an INNER join within a FROM that features at |
| 153059 | + ** least one RIGHT or FULL join. |
| 153060 | + */ |
| 153061 | + if( (ExprHasProperty(pExpr, EP_OuterON)) |
| 153062 | + || (ExprHasProperty(pExpr, EP_InnerON) && hasRightJoin(pCtx->pSrc)) |
| 153063 | + ){ |
| 153064 | + /* If CheckOnCtx.iJoin is already set, then fall through and process |
| 153065 | + ** this expression node as normal. Or, if CheckOnCtx.iJoin is still 0, |
| 153066 | + ** set it to the cursor number of the RHS of the join to which this |
| 153067 | + ** ON expression was attached and then iterate through the entire |
| 153068 | + ** expression. */ |
| 153069 | + assert( pCtx->iJoin==0 || pCtx->iJoin==pExpr->w.iJoin ); |
| 153070 | + if( pCtx->iJoin==0 ){ |
| 153071 | + pCtx->iJoin = pExpr->w.iJoin; |
| 153072 | + sqlite3WalkExprNN(pWalker, pExpr); |
| 153073 | + pCtx->iJoin = 0; |
| 153074 | + return WRC_Prune; |
| 153075 | + } |
| 153076 | + } |
| 153077 | + |
| 153078 | + if( pExpr->op==TK_COLUMN ){ |
| 153079 | + /* A column expression. Find the SrcList (if any) to which it refers. |
| 153080 | + ** Then, if CheckOnCtx.iJoin indicates that this expression is part of an |
| 153081 | + ** ON clause from that SrcList (i.e. if iJoin is non-zero), check that it |
| 153082 | + ** does not refer to a table to the right of CheckOnCtx.iJoin. */ |
| 153083 | + do { |
| 153084 | + SrcList *pSrc = pCtx->pSrc; |
| 153085 | + int iTab = pExpr->iTable; |
| 153086 | + if( iTab>=pSrc->a[0].iCursor && iTab<=pSrc->a[pSrc->nSrc-1].iCursor ){ |
| 153087 | + if( pCtx->iJoin && iTab>pCtx->iJoin ){ |
| 153088 | + sqlite3ErrorMsg(pWalker->pParse, |
| 153089 | + "ON clause references tables to its right"); |
| 153090 | + return WRC_Abort; |
| 153091 | + } |
| 153092 | + break; |
| 153093 | + } |
| 153094 | + pCtx = pCtx->pParent; |
| 153095 | + }while( pCtx ); |
| 153096 | + } |
| 153097 | + return WRC_Continue; |
| 153098 | +} |
| 153099 | + |
| 153100 | +/* |
| 153101 | +** The xSelect callback for the search of invalid ON clause terms. |
| 153102 | +*/ |
| 153103 | +static int selectCheckOnClausesSelect(Walker *pWalker, Select *pSelect){ |
| 153104 | + CheckOnCtx *pCtx = pWalker->u.pCheckOnCtx; |
| 153105 | + if( pSelect->pSrc==pCtx->pSrc || pSelect->pSrc->nSrc==0 ){ |
| 153106 | + return WRC_Continue; |
| 153107 | + }else{ |
| 153108 | + CheckOnCtx sCtx; |
| 153109 | + memset(&sCtx, 0, sizeof(sCtx)); |
| 153110 | + sCtx.pSrc = pSelect->pSrc; |
| 153111 | + sCtx.pParent = pCtx; |
| 153112 | + pWalker->u.pCheckOnCtx = &sCtx; |
| 153113 | + sqlite3WalkSelect(pWalker, pSelect); |
| 153114 | + pWalker->u.pCheckOnCtx = pCtx; |
| 153115 | + pSelect->selFlags &= ~SF_OnToWhere; |
| 153116 | + return WRC_Prune; |
| 153117 | + } |
| 153118 | +} |
| 153119 | + |
| 153120 | +/* |
| 153121 | +** Check all ON clauses in pSelect to verify that they do not reference |
| 153122 | +** columns to the right. |
| 153123 | +*/ |
| 153124 | +static void selectCheckOnClauses(Parse *pParse, Select *pSelect){ |
| 153125 | + Walker w; |
| 153126 | + CheckOnCtx sCtx; |
| 153127 | + assert( pSelect->selFlags & SF_OnToWhere ); |
| 153128 | + assert( pSelect->pSrc!=0 && pSelect->pSrc->nSrc>=2 ); |
| 153129 | + memset(&w, 0, sizeof(w)); |
| 153130 | + w.pParse = pParse; |
| 153131 | + w.xExprCallback = selectCheckOnClausesExpr; |
| 153132 | + w.xSelectCallback = selectCheckOnClausesSelect; |
| 153133 | + w.u.pCheckOnCtx = &sCtx; |
| 153134 | + memset(&sCtx, 0, sizeof(sCtx)); |
| 153135 | + sCtx.pSrc = pSelect->pSrc; |
| 153136 | + sqlite3WalkExprNN(&w, pSelect->pWhere); |
| 153137 | + pSelect->selFlags &= ~SF_OnToWhere; |
| 153138 | +} |
| 152843 | 153139 | |
| 152844 | 153140 | /* |
| 152845 | 153141 | ** Generate byte-code for the SELECT statement given in the p argument. |
| 152846 | 153142 | ** |
| 152847 | 153143 | ** The results are returned according to the SelectDest structure. |
| | @@ -152965,10 +153261,22 @@ |
| 152965 | 153261 | if( sqlite3TreeTrace & 0x10 ){ |
| 152966 | 153262 | TREETRACE(0x10,pParse,p, ("after name resolution:\n")); |
| 152967 | 153263 | sqlite3TreeViewSelect(0, p, 0); |
| 152968 | 153264 | } |
| 152969 | 153265 | #endif |
| 153266 | + |
| 153267 | + /* If the SELECT statement contains ON clauses that were moved into |
| 153268 | + ** the WHERE clause, go through and verify that none of the terms |
| 153269 | + ** in the ON clauses reference tables to the right of the ON clause. |
| 153270 | + ** Do this now, after name resolution, but before query flattening |
| 153271 | + */ |
| 153272 | + if( p->selFlags & SF_OnToWhere ){ |
| 153273 | + selectCheckOnClauses(pParse, p); |
| 153274 | + if( pParse->nErr ){ |
| 153275 | + goto select_end; |
| 153276 | + } |
| 153277 | + } |
| 152970 | 153278 | |
| 152971 | 153279 | /* If the SF_UFSrcCheck flag is set, then this function is being called |
| 152972 | 153280 | ** as part of populating the temp table for an UPDATE...FROM statement. |
| 152973 | 153281 | ** In this case, it is an error if the target object (pSrc->a[0]) name |
| 152974 | 153282 | ** or alias is duplicated within FROM clause (pSrc->a[1..n]). |
| | @@ -155531,11 +155839,14 @@ |
| 155531 | 155839 | sqlite3 *db = pParse->db; |
| 155532 | 155840 | ExprList *pNew; |
| 155533 | 155841 | Returning *pReturning; |
| 155534 | 155842 | Select sSelect; |
| 155535 | 155843 | SrcList *pFrom; |
| 155536 | | - u8 fromSpace[SZ_SRCLIST_1]; |
| 155844 | + union { |
| 155845 | + SrcList sSrc; |
| 155846 | + u8 fromSpace[SZ_SRCLIST_1]; |
| 155847 | + } uSrc; |
| 155537 | 155848 | |
| 155538 | 155849 | assert( v!=0 ); |
| 155539 | 155850 | if( !pParse->bReturning ){ |
| 155540 | 155851 | /* This RETURNING trigger must be for a different statement as |
| 155541 | 155852 | ** this statement lacks a RETURNING clause. */ |
| | @@ -155547,12 +155858,12 @@ |
| 155547 | 155858 | if( pTrigger != &(pReturning->retTrig) ){ |
| 155548 | 155859 | /* This RETURNING trigger is for a different statement */ |
| 155549 | 155860 | return; |
| 155550 | 155861 | } |
| 155551 | 155862 | memset(&sSelect, 0, sizeof(sSelect)); |
| 155552 | | - pFrom = (SrcList*)fromSpace; |
| 155553 | | - memset(pFrom, 0, SZ_SRCLIST_1); |
| 155863 | + memset(&uSrc, 0, sizeof(uSrc)); |
| 155864 | + pFrom = &uSrc.sSrc; |
| 155554 | 155865 | sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0); |
| 155555 | 155866 | sSelect.pSrc = pFrom; |
| 155556 | 155867 | pFrom->nSrc = 1; |
| 155557 | 155868 | pFrom->a[0].pSTab = pTab; |
| 155558 | 155869 | pFrom->a[0].zName = pTab->zName; /* tag-20240424-1 */ |
| | @@ -163079,11 +163390,14 @@ |
| 163079 | 163390 | WhereClause *pWC = &pWInfo->sWC; |
| 163080 | 163391 | WhereInfo *pSubWInfo; |
| 163081 | 163392 | WhereLoop *pLoop = pLevel->pWLoop; |
| 163082 | 163393 | SrcItem *pTabItem = &pWInfo->pTabList->a[pLevel->iFrom]; |
| 163083 | 163394 | SrcList *pFrom; |
| 163084 | | - u8 fromSpace[SZ_SRCLIST_1]; |
| 163395 | + union { |
| 163396 | + SrcList sSrc; |
| 163397 | + u8 fromSpace[SZ_SRCLIST_1]; |
| 163398 | + } uSrc; |
| 163085 | 163399 | Bitmask mAll = 0; |
| 163086 | 163400 | int k; |
| 163087 | 163401 | |
| 163088 | 163402 | ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pSTab->zName)); |
| 163089 | 163403 | sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn, |
| | @@ -163123,11 +163437,11 @@ |
| 163123 | 163437 | if( ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) ) continue; |
| 163124 | 163438 | pSubWhere = sqlite3ExprAnd(pParse, pSubWhere, |
| 163125 | 163439 | sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); |
| 163126 | 163440 | } |
| 163127 | 163441 | } |
| 163128 | | - pFrom = (SrcList*)fromSpace; |
| 163442 | + pFrom = &uSrc.sSrc; |
| 163129 | 163443 | pFrom->nSrc = 1; |
| 163130 | 163444 | pFrom->nAlloc = 1; |
| 163131 | 163445 | memcpy(&pFrom->a[0], pTabItem, sizeof(SrcItem)); |
| 163132 | 163446 | pFrom->a[0].fg.jointype = 0; |
| 163133 | 163447 | assert( pParse->withinRJSubrtn < 100 ); |
| | @@ -164340,25 +164654,11 @@ |
| 164340 | 164654 | Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin); |
| 164341 | 164655 | if( ExprHasProperty(pExpr, EP_OuterON) ){ |
| 164342 | 164656 | prereqAll |= x; |
| 164343 | 164657 | extraRight = x-1; /* ON clause terms may not be used with an index |
| 164344 | 164658 | ** on left table of a LEFT JOIN. Ticket #3015 */ |
| 164345 | | - if( (prereqAll>>1)>=x ){ |
| 164346 | | - sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); |
| 164347 | | - return; |
| 164348 | | - } |
| 164349 | 164659 | }else if( (prereqAll>>1)>=x ){ |
| 164350 | | - /* The ON clause of an INNER JOIN references a table to its right. |
| 164351 | | - ** Most other SQL database engines raise an error. But SQLite versions |
| 164352 | | - ** 3.0 through 3.38 just put the ON clause constraint into the WHERE |
| 164353 | | - ** clause and carried on. Beginning with 3.39, raise an error only |
| 164354 | | - ** if there is a RIGHT or FULL JOIN in the query. This makes SQLite |
| 164355 | | - ** more like other systems, and also preserves legacy. */ |
| 164356 | | - if( ALWAYS(pSrc->nSrc>0) && (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){ |
| 164357 | | - sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); |
| 164358 | | - return; |
| 164359 | | - } |
| 164360 | 164660 | ExprClearProperty(pExpr, EP_InnerON); |
| 164361 | 164661 | } |
| 164362 | 164662 | } |
| 164363 | 164663 | pTerm->prereqAll = prereqAll; |
| 164364 | 164664 | pTerm->leftCursor = -1; |
| | @@ -184839,10 +185139,13 @@ |
| 184839 | 185139 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 184840 | 185140 | switch( rc ){ |
| 184841 | 185141 | case SQLITE_OK: zName = "SQLITE_OK"; break; |
| 184842 | 185142 | case SQLITE_ERROR: zName = "SQLITE_ERROR"; break; |
| 184843 | 185143 | case SQLITE_ERROR_SNAPSHOT: zName = "SQLITE_ERROR_SNAPSHOT"; break; |
| 185144 | + case SQLITE_ERROR_RETRY: zName = "SQLITE_ERROR_RETRY"; break; |
| 185145 | + case SQLITE_ERROR_MISSING_COLLSEQ: |
| 185146 | + zName = "SQLITE_ERROR_MISSING_COLLSEQ"; break; |
| 184844 | 185147 | case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break; |
| 184845 | 185148 | case SQLITE_PERM: zName = "SQLITE_PERM"; break; |
| 184846 | 185149 | case SQLITE_ABORT: zName = "SQLITE_ABORT"; break; |
| 184847 | 185150 | case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break; |
| 184848 | 185151 | case SQLITE_BUSY: zName = "SQLITE_BUSY"; break; |
| | @@ -189087,21 +189390,24 @@ |
| 189087 | 189390 | ** |
| 189088 | 189391 | */ |
| 189089 | 189392 | #ifndef _FTSINT_H |
| 189090 | 189393 | #define _FTSINT_H |
| 189091 | 189394 | |
| 189395 | +/* |
| 189396 | +** Activate assert() only if SQLITE_TEST is enabled. |
| 189397 | +*/ |
| 189398 | +#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
| 189399 | +# define NDEBUG 1 |
| 189400 | +#endif |
| 189401 | + |
| 189092 | 189402 | /* #include <assert.h> */ |
| 189093 | 189403 | /* #include <stdlib.h> */ |
| 189094 | 189404 | /* #include <stddef.h> */ |
| 189095 | 189405 | /* #include <stdio.h> */ |
| 189096 | 189406 | /* #include <string.h> */ |
| 189097 | 189407 | /* #include <stdarg.h> */ |
| 189098 | 189408 | |
| 189099 | | -#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
| 189100 | | -# define NDEBUG 1 |
| 189101 | | -#endif |
| 189102 | | - |
| 189103 | 189409 | /* FTS3/FTS4 require virtual tables */ |
| 189104 | 189410 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 189105 | 189411 | # undef SQLITE_ENABLE_FTS3 |
| 189106 | 189412 | # undef SQLITE_ENABLE_FTS4 |
| 189107 | 189413 | #endif |
| | @@ -189540,17 +189846,10 @@ |
| 189540 | 189846 | /* |
| 189541 | 189847 | ** Macro used to suppress compiler warnings for unused parameters. |
| 189542 | 189848 | */ |
| 189543 | 189849 | #define UNUSED_PARAMETER(x) (void)(x) |
| 189544 | 189850 | |
| 189545 | | -/* |
| 189546 | | -** Activate assert() only if SQLITE_TEST is enabled. |
| 189547 | | -*/ |
| 189548 | | -#if !defined(NDEBUG) && !defined(SQLITE_DEBUG) |
| 189549 | | -# define NDEBUG 1 |
| 189550 | | -#endif |
| 189551 | | - |
| 189552 | 189851 | /* |
| 189553 | 189852 | ** The TESTONLY macro is used to enclose variable declarations or |
| 189554 | 189853 | ** other bits of code that are needed to support the arguments |
| 189555 | 189854 | ** within testcase() and assert() macros. |
| 189556 | 189855 | */ |
| | @@ -203821,12 +204120,12 @@ |
| 203821 | 204120 | /* |
| 203822 | 204121 | ** An object of this type contains the state required to create or append |
| 203823 | 204122 | ** to an appendable b-tree segment. |
| 203824 | 204123 | */ |
| 203825 | 204124 | struct IncrmergeWriter { |
| 203826 | | - int nLeafEst; /* Space allocated for leaf blocks */ |
| 203827 | | - int nWork; /* Number of leaf pages flushed */ |
| 204125 | + i64 nLeafEst; /* Space allocated for leaf blocks */ |
| 204126 | + i64 nWork; /* Number of leaf pages flushed */ |
| 203828 | 204127 | sqlite3_int64 iAbsLevel; /* Absolute level of input segments */ |
| 203829 | 204128 | int iIdx; /* Index of *output* segment in iAbsLevel+1 */ |
| 203830 | 204129 | sqlite3_int64 iStart; /* Block number of first allocated block */ |
| 203831 | 204130 | sqlite3_int64 iEnd; /* Block number of last allocated block */ |
| 203832 | 204131 | sqlite3_int64 nLeafData; /* Bytes of leaf page data so far */ |
| | @@ -204568,21 +204867,21 @@ |
| 204568 | 204867 | Fts3MultiSegReader *pCsr, /* Cursor that data will be read from */ |
| 204569 | 204868 | IncrmergeWriter *pWriter /* Populate this object */ |
| 204570 | 204869 | ){ |
| 204571 | 204870 | int rc; /* Return Code */ |
| 204572 | 204871 | int i; /* Iterator variable */ |
| 204573 | | - int nLeafEst = 0; /* Blocks allocated for leaf nodes */ |
| 204872 | + i64 nLeafEst = 0; /* Blocks allocated for leaf nodes */ |
| 204574 | 204873 | sqlite3_stmt *pLeafEst = 0; /* SQL used to determine nLeafEst */ |
| 204575 | 204874 | sqlite3_stmt *pFirstBlock = 0; /* SQL used to determine first block */ |
| 204576 | 204875 | |
| 204577 | 204876 | /* Calculate nLeafEst. */ |
| 204578 | 204877 | rc = fts3SqlStmt(p, SQL_MAX_LEAF_NODE_ESTIMATE, &pLeafEst, 0); |
| 204579 | 204878 | if( rc==SQLITE_OK ){ |
| 204580 | 204879 | sqlite3_bind_int64(pLeafEst, 1, iAbsLevel); |
| 204581 | 204880 | sqlite3_bind_int64(pLeafEst, 2, pCsr->nSegment); |
| 204582 | 204881 | if( SQLITE_ROW==sqlite3_step(pLeafEst) ){ |
| 204583 | | - nLeafEst = sqlite3_column_int(pLeafEst, 0); |
| 204882 | + nLeafEst = sqlite3_column_int64(pLeafEst, 0); |
| 204584 | 204883 | } |
| 204585 | 204884 | rc = sqlite3_reset(pLeafEst); |
| 204586 | 204885 | } |
| 204587 | 204886 | if( rc!=SQLITE_OK ) return rc; |
| 204588 | 204887 | |
| | @@ -228353,11 +228652,11 @@ |
| 228353 | 228652 | typedef struct DbpageTable DbpageTable; |
| 228354 | 228653 | typedef struct DbpageCursor DbpageCursor; |
| 228355 | 228654 | |
| 228356 | 228655 | struct DbpageCursor { |
| 228357 | 228656 | sqlite3_vtab_cursor base; /* Base class. Must be first */ |
| 228358 | | - int pgno; /* Current page number */ |
| 228657 | + Pgno pgno; /* Current page number */ |
| 228359 | 228658 | int mxPgno; /* Last page to visit on this scan */ |
| 228360 | 228659 | Pager *pPager; /* Pager being read/written */ |
| 228361 | 228660 | DbPage *pPage1; /* Page 1 of the database */ |
| 228362 | 228661 | int iDb; /* Index of database to analyze */ |
| 228363 | 228662 | int szPage; /* Size of each page in bytes */ |
| | @@ -228491,11 +228790,11 @@ |
| 228491 | 228790 | if( pCsr==0 ){ |
| 228492 | 228791 | return SQLITE_NOMEM_BKPT; |
| 228493 | 228792 | }else{ |
| 228494 | 228793 | memset(pCsr, 0, sizeof(DbpageCursor)); |
| 228495 | 228794 | pCsr->base.pVtab = pVTab; |
| 228496 | | - pCsr->pgno = -1; |
| 228795 | + pCsr->pgno = 0; |
| 228497 | 228796 | } |
| 228498 | 228797 | |
| 228499 | 228798 | *ppCursor = (sqlite3_vtab_cursor *)pCsr; |
| 228500 | 228799 | return SQLITE_OK; |
| 228501 | 228800 | } |
| | @@ -228591,16 +228890,16 @@ |
| 228591 | 228890 | ){ |
| 228592 | 228891 | DbpageCursor *pCsr = (DbpageCursor *)pCursor; |
| 228593 | 228892 | int rc = SQLITE_OK; |
| 228594 | 228893 | switch( i ){ |
| 228595 | 228894 | case 0: { /* pgno */ |
| 228596 | | - sqlite3_result_int(ctx, pCsr->pgno); |
| 228895 | + sqlite3_result_int64(ctx, (sqlite3_int64)pCsr->pgno); |
| 228597 | 228896 | break; |
| 228598 | 228897 | } |
| 228599 | 228898 | case 1: { /* data */ |
| 228600 | 228899 | DbPage *pDbPage = 0; |
| 228601 | | - if( pCsr->pgno==((PENDING_BYTE/pCsr->szPage)+1) ){ |
| 228900 | + if( pCsr->pgno==(Pgno)((PENDING_BYTE/pCsr->szPage)+1) ){ |
| 228602 | 228901 | /* The pending byte page. Assume it is zeroed out. Attempting to |
| 228603 | 228902 | ** request this page from the page is an SQLITE_CORRUPT error. */ |
| 228604 | 228903 | sqlite3_result_zeroblob(ctx, pCsr->szPage); |
| 228605 | 228904 | }else{ |
| 228606 | 228905 | rc = sqlite3PagerGet(pCsr->pPager, pCsr->pgno, (DbPage**)&pDbPage, 0); |
| | @@ -228670,14 +228969,14 @@ |
| 228670 | 228969 | if( argc==1 ){ |
| 228671 | 228970 | zErr = "cannot delete"; |
| 228672 | 228971 | goto update_fail; |
| 228673 | 228972 | } |
| 228674 | 228973 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ){ |
| 228675 | | - pgno = (Pgno)sqlite3_value_int(argv[2]); |
| 228974 | + pgno = (Pgno)sqlite3_value_int64(argv[2]); |
| 228676 | 228975 | isInsert = 1; |
| 228677 | 228976 | }else{ |
| 228678 | | - pgno = sqlite3_value_int(argv[0]); |
| 228977 | + pgno = (Pgno)sqlite3_value_int64(argv[0]); |
| 228679 | 228978 | if( (Pgno)sqlite3_value_int(argv[1])!=pgno ){ |
| 228680 | 228979 | zErr = "cannot insert"; |
| 228681 | 228980 | goto update_fail; |
| 228682 | 228981 | } |
| 228683 | 228982 | isInsert = 0; |
| | @@ -233644,11 +233943,11 @@ |
| 233644 | 233943 | sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 233645 | 233944 | int(*xConflict)(void *, int, sqlite3_changeset_iter*), |
| 233646 | 233945 | void *pCtx, /* First argument for conflict handler */ |
| 233647 | 233946 | int *pbReplace /* OUT: Set to true if PK row is found */ |
| 233648 | 233947 | ){ |
| 233649 | | - int res = 0; /* Value returned by conflict handler */ |
| 233948 | + int res = SQLITE_CHANGESET_OMIT;/* Value returned by conflict handler */ |
| 233650 | 233949 | int rc; |
| 233651 | 233950 | int nCol; |
| 233652 | 233951 | int op; |
| 233653 | 233952 | const char *zDummy; |
| 233654 | 233953 | |
| | @@ -233665,15 +233964,13 @@ |
| 233665 | 233964 | rc = SQLITE_OK; |
| 233666 | 233965 | } |
| 233667 | 233966 | |
| 233668 | 233967 | if( rc==SQLITE_ROW ){ |
| 233669 | 233968 | /* There exists another row with the new.* primary key. */ |
| 233670 | | - if( p->bIgnoreNoop |
| 233671 | | - && sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1) |
| 233969 | + if( 0==p->bIgnoreNoop |
| 233970 | + || 0==sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1) |
| 233672 | 233971 | ){ |
| 233673 | | - res = SQLITE_CHANGESET_OMIT; |
| 233674 | | - }else{ |
| 233675 | 233972 | pIter->pConflict = p->pSelect; |
| 233676 | 233973 | res = xConflict(pCtx, eType, pIter); |
| 233677 | 233974 | pIter->pConflict = 0; |
| 233678 | 233975 | } |
| 233679 | 233976 | rc = sqlite3_reset(p->pSelect); |
| | @@ -233683,11 +233980,13 @@ |
| 233683 | 233980 | ** to the SessionApplyCtx.constraints buffer. */ |
| 233684 | 233981 | u8 *aBlob = &pIter->in.aData[pIter->in.iCurrent]; |
| 233685 | 233982 | int nBlob = pIter->in.iNext - pIter->in.iCurrent; |
| 233686 | 233983 | sessionAppendBlob(&p->constraints, aBlob, nBlob, &rc); |
| 233687 | 233984 | return SQLITE_OK; |
| 233688 | | - }else{ |
| 233985 | + }else if( p->bIgnoreNoop==0 || op!=SQLITE_DELETE |
| 233986 | + || eType==SQLITE_CHANGESET_CONFLICT |
| 233987 | + ){ |
| 233689 | 233988 | /* No other row with the new.* primary key. */ |
| 233690 | 233989 | res = xConflict(pCtx, eType+1, pIter); |
| 233691 | 233990 | if( res==SQLITE_CHANGESET_REPLACE ) rc = SQLITE_MISUSE; |
| 233692 | 233991 | } |
| 233693 | 233992 | } |
| | @@ -233781,11 +234080,11 @@ |
| 233781 | 234080 | } |
| 233782 | 234081 | if( rc!=SQLITE_OK ) return rc; |
| 233783 | 234082 | |
| 233784 | 234083 | sqlite3_step(p->pDelete); |
| 233785 | 234084 | rc = sqlite3_reset(p->pDelete); |
| 233786 | | - if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){ |
| 234085 | + if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){ |
| 233787 | 234086 | rc = sessionConflictHandler( |
| 233788 | 234087 | SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry |
| 233789 | 234088 | ); |
| 233790 | 234089 | }else if( (rc&0xff)==SQLITE_CONSTRAINT ){ |
| 233791 | 234090 | rc = sessionConflictHandler( |
| | @@ -236412,25 +236711,18 @@ |
| 236412 | 236711 | ** Constants for the largest and smallest possible 64-bit signed integers. |
| 236413 | 236712 | */ |
| 236414 | 236713 | # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) |
| 236415 | 236714 | # define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) |
| 236416 | 236715 | |
| 236417 | | -/* The uptr type is an unsigned integer large enough to hold a pointer |
| 236716 | +/* |
| 236717 | +** This macro is used in a single assert() within fts5 to check that an |
| 236718 | +** allocation is aligned to an 8-byte boundary. But it is a complicated |
| 236719 | +** macro to get right for multiple platforms without generating warnings. |
| 236720 | +** So instead of reproducing the entire definition from sqliteInt.h, we |
| 236721 | +** just do without this assert() for the rare non-amalgamation builds. |
| 236418 | 236722 | */ |
| 236419 | | -#if defined(HAVE_STDINT_H) |
| 236420 | | - typedef uintptr_t uptr; |
| 236421 | | -#elif SQLITE_PTRSIZE==4 |
| 236422 | | - typedef u32 uptr; |
| 236423 | | -#else |
| 236424 | | - typedef u64 uptr; |
| 236425 | | -#endif |
| 236426 | | - |
| 236427 | | -#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC |
| 236428 | | -# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0) |
| 236429 | | -#else |
| 236430 | | -# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0) |
| 236431 | | -#endif |
| 236723 | +#define EIGHT_BYTE_ALIGNMENT(x) 1 |
| 236432 | 236724 | |
| 236433 | 236725 | /* |
| 236434 | 236726 | ** Macros needed to provide flexible arrays in a portable way |
| 236435 | 236727 | */ |
| 236436 | 236728 | #ifndef offsetof |
| | @@ -251885,14 +252177,17 @@ |
| 251885 | 252177 | ** function populates it with the initial structure objects for each index, |
| 251886 | 252178 | ** and the initial version of the "averages" record (a zero-byte blob). |
| 251887 | 252179 | */ |
| 251888 | 252180 | static int sqlite3Fts5IndexReinit(Fts5Index *p){ |
| 251889 | 252181 | Fts5Structure *pTmp; |
| 251890 | | - u8 tmpSpace[SZ_FTS5STRUCTURE(1)]; |
| 252182 | + union { |
| 252183 | + Fts5Structure sFts; |
| 252184 | + u8 tmpSpace[SZ_FTS5STRUCTURE(1)]; |
| 252185 | + } uFts; |
| 251891 | 252186 | fts5StructureInvalidate(p); |
| 251892 | 252187 | fts5IndexDiscardData(p); |
| 251893 | | - pTmp = (Fts5Structure*)tmpSpace; |
| 252188 | + pTmp = &uFts.sFts; |
| 251894 | 252189 | memset(pTmp, 0, SZ_FTS5STRUCTURE(1)); |
| 251895 | 252190 | if( p->pConfig->bContentlessDelete ){ |
| 251896 | 252191 | pTmp->nOriginCntr = 1; |
| 251897 | 252192 | } |
| 251898 | 252193 | fts5DataWrite(p, FTS5_AVERAGES_ROWID, (const u8*)"", 0); |
| | @@ -258177,11 +258472,11 @@ |
| 258177 | 258472 | int nArg, /* Number of args */ |
| 258178 | 258473 | sqlite3_value **apUnused /* Function arguments */ |
| 258179 | 258474 | ){ |
| 258180 | 258475 | assert( nArg==0 ); |
| 258181 | 258476 | UNUSED_PARAM2(nArg, apUnused); |
| 258182 | | - sqlite3_result_text(pCtx, "fts5: 2025-07-30 16:17:14 cf7163f82ca380958a79350473b2c5a2cebda7496d6d575fa2835c362010fea1", -1, SQLITE_TRANSIENT); |
| 258477 | + sqlite3_result_text(pCtx, "fts5: 2025-09-09 10:28:06 0f31711591c56f3896fb6f092752fb82c4ea646bf8e5838dfbe55302994ea091", -1, SQLITE_TRANSIENT); |
| 258183 | 258478 | } |
| 258184 | 258479 | |
| 258185 | 258480 | /* |
| 258186 | 258481 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 258187 | 258482 | ** |
| 258188 | 258483 | |