Fossil SCM

A branch for experimenting with SETLK_TIMEOUT in SQLite.

drh 2025-02-11 18:19 trunk
Commit dcbf6a1fbc92f58a5ce5049d2f71be26e2d055ba4ced96ff284fded6b14f9240
+1010 -613
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.49.0. By combining all the individual C code files into this
3
+** version 3.50.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 4a7dd425dc2a0e5082a9049c9b4a9d4f199a with changes in files:
21
+** e5ec5bb9f4dc3e02db7ab0e49686f47617af with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463463
**
464464
** See also: [sqlite3_libversion()],
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468
-#define SQLITE_VERSION "3.49.0"
469
-#define SQLITE_VERSION_NUMBER 3049000
470
-#define SQLITE_SOURCE_ID "2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde"
468
+#define SQLITE_VERSION "3.50.0"
469
+#define SQLITE_VERSION_NUMBER 3050000
470
+#define SQLITE_SOURCE_ID "2025-02-11 17:10:46 e5ec5bb9f4dc3e02db7ab0e49686f47617af75d3f7d4ab23288a1aea4a693e59"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -1480,10 +1480,15 @@
14801480
** obtain a file lock using the xLock or xShmLock methods of the VFS.
14811481
** The parameter is a pointer to a 32-bit signed integer that contains
14821482
** the value that M is to be set to. Before returning, the 32-bit signed
14831483
** integer is overwritten with the previous value of M.
14841484
**
1485
+** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]
1486
+** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the
1487
+** VFS to block when taking SHARED locks. This is used to implement the
1488
+** functionality associated with SQLITE_SETLK_BLOCK_ON_CONNECT.
1489
+**
14851490
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
14861491
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
14871492
** a database file. The argument is a pointer to a 32-bit unsigned integer.
14881493
** The "data version" for the pager is written into the pointer. The
14891494
** "data version" changes whenever any change occurs to the corresponding
@@ -1576,10 +1581,11 @@
15761581
#define SQLITE_FCNTL_CKPT_START 39
15771582
#define SQLITE_FCNTL_EXTERNAL_READER 40
15781583
#define SQLITE_FCNTL_CKSM_FILE 41
15791584
#define SQLITE_FCNTL_RESET_CACHE 42
15801585
#define SQLITE_FCNTL_NULL_IO 43
1586
+#define SQLITE_FCNTL_BLOCK_ON_CONNECT 44
15811587
15821588
/* deprecated names */
15831589
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
15841590
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
15851591
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3310,10 +3316,48 @@
33103316
**
33113317
** See also: [PRAGMA busy_timeout]
33123318
*/
33133319
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
33143320
3321
+/*
3322
+** CAPI3REF: Set the Setlk Timeout
3323
+** METHOD: sqlite3
3324
+**
3325
+** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If
3326
+** the VFS supports blocking locks, it sets the timeout in ms used by
3327
+** eligible locks taken on wal mode databases by the specified database
3328
+** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does
3329
+** not support blocking locks, this function is a no-op.
3330
+**
3331
+** Passing 0 to this function disables blocking locks altogether. Passing
3332
+** -1 to this function requests that the VFS blocks for a long time -
3333
+** indefinitely if possible. The results of passing any other negative value
3334
+** are undefined.
3335
+**
3336
+** Internally, each SQLite database handle store two timeout values - the
3337
+** busy-timeout (used for rollback mode databases, or if the VFS does not
3338
+** support blocking locks) and the setlk-timeout (used for blocking locks
3339
+** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3340
+** values, this function sets only the setlk-timeout value. Therefore,
3341
+** to configure separate busy-timeout and setlk-timeout values for a single
3342
+** database handle, call sqlite3_busy_timeout() followed by this function.
3343
+**
3344
+** Whenever the number of connections to a wal mode database falls from
3345
+** 1 to 0, the last connection takes an exclusive lock on the database,
3346
+** then checkpoints and deletes the wal file. While it is doing this, any
3347
+** new connection that tries to read from the database fails with an
3348
+** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is
3349
+** passed to this API, the new connection blocks until the exclusive lock
3350
+** has been released.
3351
+*/
3352
+SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);
3353
+
3354
+/*
3355
+** CAPI3REF: Flags for sqlite3_setlk_timeout()
3356
+*/
3357
+#define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01
3358
+
33153359
/*
33163360
** CAPI3REF: Convenience Routines For Running Queries
33173361
** METHOD: sqlite3
33183362
**
33193363
** This is a legacy interface that is preserved for backwards compatibility.
@@ -14747,10 +14791,11 @@
1474714791
*/
1474814792
struct HashElem {
1474914793
HashElem *next, *prev; /* Next and previous elements in the table */
1475014794
void *data; /* Data associated with this element */
1475114795
const char *pKey; /* Key associated with this element */
14796
+ unsigned int h; /* hash for pKey */
1475214797
};
1475314798
1475414799
/*
1475514800
** Access routines. To delete, insert a NULL pointer.
1475614801
*/
@@ -15184,10 +15229,15 @@
1518415229
typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
1518515230
typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
1518615231
typedef INT16_TYPE i16; /* 2-byte signed integer */
1518715232
typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
1518815233
typedef INT8_TYPE i8; /* 1-byte signed integer */
15234
+
15235
+/* A bitfield type for use inside of structures. Always follow with :N where
15236
+** N is the number of bits.
15237
+*/
15238
+typedef unsigned bft; /* Bit Field Type */
1518915239
1519015240
/*
1519115241
** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
1519215242
** that can be stored in a u32 without loss of data. The value
1519315243
** is 0x00000000ffffffff. But because of quirks of some compilers, we
@@ -18053,10 +18103,14 @@
1805318103
BusyHandler busyHandler; /* Busy callback */
1805418104
Db aDbStatic[2]; /* Static space for the 2 default backends */
1805518105
Savepoint *pSavepoint; /* List of active savepoints */
1805618106
int nAnalysisLimit; /* Number of index rows to ANALYZE */
1805718107
int busyTimeout; /* Busy handler timeout, in msec */
18108
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
18109
+ int setlkTimeout; /* Blocking lock timeout, in msec. -1 -> inf. */
18110
+ int setlkFlags; /* Flags passed to setlk_timeout() */
18111
+#endif
1805818112
int nSavepoint; /* Number of non-transaction savepoints */
1805918113
int nStatement; /* Number of nested statement-transactions */
1806018114
i64 nDeferredCons; /* Net deferred constraints this transaction. */
1806118115
i64 nDeferredImmCons; /* Net deferred immediate constraints */
1806218116
int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
@@ -18731,10 +18785,11 @@
1873118785
VTable *p; /* List of VTable objects. */
1873218786
} vtab;
1873318787
} u;
1873418788
Trigger *pTrigger; /* List of triggers on this object */
1873518789
Schema *pSchema; /* Schema that contains this table */
18790
+ u8 aHx[16]; /* Column aHt[K%sizeof(aHt)] might have hash K */
1873618791
};
1873718792
1873818793
/*
1873918794
** Allowed values for Table.tabFlags.
1874018795
**
@@ -20128,29 +20183,36 @@
2012820183
struct Parse {
2012920184
sqlite3 *db; /* The main database structure */
2013020185
char *zErrMsg; /* An error message */
2013120186
Vdbe *pVdbe; /* An engine for executing database bytecode */
2013220187
int rc; /* Return code from execution */
20133
- u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
20134
- u8 checkSchema; /* Causes schema cookie check after an error */
20188
+ LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
2013520189
u8 nested; /* Number of nested calls to the parser/code generator */
2013620190
u8 nTempReg; /* Number of temporary registers in aTempReg[] */
2013720191
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
2013820192
u8 mayAbort; /* True if statement may throw an ABORT exception */
2013920193
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
20140
- u8 okConstFactor; /* OK to factor out constants */
2014120194
u8 disableLookaside; /* Number of times lookaside has been disabled */
2014220195
u8 prepFlags; /* SQLITE_PREPARE_* flags */
2014320196
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20144
- u8 bHasWith; /* True if statement contains WITH */
2014520197
u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20198
+ u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20199
+ u8 bReturning; /* Coding a RETURNING trigger */
20200
+ u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20201
+ u8 disableTriggers; /* True to disable triggers */
2014620202
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
2014720203
u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
2014820204
#endif
2014920205
#ifdef SQLITE_DEBUG
2015020206
u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
20207
+ u8 isCreate; /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
20208
+ ** and ALTER TABLE ADD COLUMN. */
2015120209
#endif
20210
+ bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20211
+ bft bHasWith :1; /* True if statement contains WITH */
20212
+ bft okConstFactor :1; /* OK to factor out constants */
20213
+ bft checkSchema :1; /* Causes schema cookie check after an error */
2015220214
int nRangeReg; /* Size of the temporary register block */
2015320215
int iRangeReg; /* First register in temporary register block */
2015420216
int nErr; /* Number of errors seen */
2015520217
int nTab; /* Number of previously allocated VDBE cursors */
2015620218
int nMem; /* Number of memory cells used so far */
@@ -20161,16 +20223,13 @@
2016120223
int nLabelAlloc; /* Number of slots in aLabel */
2016220224
int *aLabel; /* Space to hold the labels */
2016320225
ExprList *pConstExpr;/* Constant expressions */
2016420226
IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
2016520227
IndexedExpr *pIdxPartExpr; /* Exprs constrained by index WHERE clauses */
20166
- Token constraintName;/* Name of the constraint currently being parsed */
2016720228
yDbMask writeMask; /* Start a write transaction on these databases */
2016820229
yDbMask cookieMask; /* Bitmask of schema verified databases */
20169
- int regRowid; /* Register holding rowid of CREATE TABLE entry */
20170
- int regRoot; /* Register holding root page number for new objects */
20171
- int nMaxArg; /* Max args passed to user function by sub-program */
20230
+ int nMaxArg; /* Max args to xUpdate and xFilter vtab methods */
2017220231
int nSelect; /* Number of SELECT stmts. Counter for Select.selId */
2017320232
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
2017420233
u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
2017520234
#endif
2017620235
#ifndef SQLITE_OMIT_SHARED_CACHE
@@ -20180,21 +20239,10 @@
2018020239
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
2018120240
Parse *pToplevel; /* Parse structure for main program (or NULL) */
2018220241
Table *pTriggerTab; /* Table triggers are being coded for */
2018320242
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
2018420243
ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
20185
- union {
20186
- int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
20187
- Returning *pReturning; /* The RETURNING clause */
20188
- } u1;
20189
- u32 oldmask; /* Mask of old.* columns referenced */
20190
- u32 newmask; /* Mask of new.* columns referenced */
20191
- LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
20192
- u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20193
- u8 bReturning; /* Coding a RETURNING trigger */
20194
- u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20195
- u8 disableTriggers; /* True to disable triggers */
2019620244
2019720245
/**************************************************************************
2019820246
** Fields above must be initialized to zero. The fields that follow,
2019920247
** down to the beginning of the recursive section, do not need to be
2020020248
** initialized as they will be set before being used. The boundary is
@@ -20202,10 +20250,23 @@
2020220250
**************************************************************************/
2020320251
2020420252
int aTempReg[8]; /* Holding area for temporary registers */
2020520253
Parse *pOuterParse; /* Outer Parse object when nested */
2020620254
Token sNameToken; /* Token with unqualified schema object name */
20255
+ u32 oldmask; /* Mask of old.* columns referenced */
20256
+ u32 newmask; /* Mask of new.* columns referenced */
20257
+ union {
20258
+ struct { /* These fields available when isCreate is true */
20259
+ int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
20260
+ int regRowid; /* Register holding rowid of CREATE TABLE entry */
20261
+ int regRoot; /* Register holding root page for new objects */
20262
+ Token constraintName; /* Name of the constraint currently being parsed */
20263
+ } cr;
20264
+ struct { /* These fields available to all other statements */
20265
+ Returning *pReturning; /* The RETURNING clause */
20266
+ } d;
20267
+ } u1;
2020720268
2020820269
/************************************************************************
2020920270
** Above is constant between recursions. Below is reset before and after
2021020271
** each recursion. The boundary between these two regions is determined
2021120272
** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -23831,14 +23892,10 @@
2383123892
u8 skipFlag; /* Skip accumulator loading if true */
2383223893
u16 argc; /* Number of arguments */
2383323894
sqlite3_value *argv[1]; /* Argument set */
2383423895
};
2383523896
23836
-/* A bitfield type for use inside of structures. Always follow with :N where
23837
-** N is the number of bits.
23838
-*/
23839
-typedef unsigned bft; /* Bit Field Type */
2384023897
2384123898
/* The ScanStatus object holds a single value for the
2384223899
** sqlite3_stmt_scanstatus() interface.
2384323900
**
2384423901
** aAddrRange[]:
@@ -23895,11 +23952,11 @@
2389523952
i64 iCurrentTime; /* Value of julianday('now') for this statement */
2389623953
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
2389723954
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
2389823955
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
2389923956
Mem *aMem; /* The memory locations */
23900
- Mem **apArg; /* Arguments to currently executing user function */
23957
+ Mem **apArg; /* Arguments xUpdate and xFilter vtab methods */
2390123958
VdbeCursor **apCsr; /* One element of this array for each open cursor */
2390223959
Mem *aVar; /* Values for the OP_Variable opcode. */
2390323960
2390423961
/* When allocating a new Vdbe object, all of the fields below should be
2390523962
** initialized to zero or NULL */
@@ -23915,10 +23972,11 @@
2391523972
i64 startTime; /* Time when query started - used for profiling */
2391623973
#endif
2391723974
#ifdef SQLITE_DEBUG
2391823975
int rcApp; /* errcode set by sqlite3_result_error_code() */
2391923976
u32 nWrite; /* Number of write operations that have occurred */
23977
+ int napArg; /* Size of the apArg[] array */
2392023978
#endif
2392123979
u16 nResColumn; /* Number of columns in one row of the result set */
2392223980
u16 nResAlloc; /* Column slots allocated to aColName[] */
2392323981
u8 errorAction; /* Recovery action to do in case of an error */
2392423982
u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -36398,11 +36456,15 @@
3639836456
}
3639936457
}
3640036458
}
3640136459
p->z = &p->zBuf[i+1];
3640236460
assert( i+p->n < sizeof(p->zBuf) );
36403
- while( ALWAYS(p->n>0) && p->z[p->n-1]=='0' ){ p->n--; }
36461
+ assert( p->n>0 );
36462
+ while( p->z[p->n-1]=='0' ){
36463
+ p->n--;
36464
+ assert( p->n>0 );
36465
+ }
3640436466
}
3640536467
3640636468
/*
3640736469
** Try to convert z into an unsigned 32-bit integer. Return true on
3640836470
** success and false if there is an error.
@@ -37184,16 +37246,23 @@
3718437246
/*
3718537247
** The hashing function.
3718637248
*/
3718737249
static unsigned int strHash(const char *z){
3718837250
unsigned int h = 0;
37189
- unsigned char c;
37190
- while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
37251
+ while( z[0] ){ /*OPTIMIZATION-IF-TRUE*/
3719137252
/* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
3719237253
** 0x9e3779b1 is 2654435761 which is the closest prime number to
37193
- ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */
37194
- h += sqlite3UpperToLower[c];
37254
+ ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2.
37255
+ **
37256
+ ** Only bits 0xdf for ASCII and bits 0xbf for EBCDIC each octet are
37257
+ ** hashed since the omitted bits determine the upper/lower case difference.
37258
+ */
37259
+#ifdef SQLITE_EBCDIC
37260
+ h += 0xbf & (unsigned char)*(z++);
37261
+#else
37262
+ h += 0xdf & (unsigned char)*(z++);
37263
+#endif
3719537264
h *= 0x9e3779b1;
3719637265
}
3719737266
return h;
3719837267
}
3719937268
@@ -37262,13 +37331,12 @@
3726237331
sqlite3_free(pH->ht);
3726337332
pH->ht = new_ht;
3726437333
pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
3726537334
memset(new_ht, 0, new_size*sizeof(struct _ht));
3726637335
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
37267
- unsigned int h = strHash(elem->pKey) % new_size;
3726837336
next_elem = elem->next;
37269
- insertElement(pH, &new_ht[h], elem);
37337
+ insertElement(pH, &new_ht[elem->h % new_size], elem);
3727037338
}
3727137339
return 1;
3727237340
}
3727337341
3727437342
/* This function (for internal use only) locates an element in an
@@ -37282,27 +37350,26 @@
3728237350
unsigned int *pHash /* Write the hash value here */
3728337351
){
3728437352
HashElem *elem; /* Used to loop thru the element list */
3728537353
unsigned int count; /* Number of elements left to test */
3728637354
unsigned int h; /* The computed hash */
37287
- static HashElem nullElement = { 0, 0, 0, 0 };
37355
+ static HashElem nullElement = { 0, 0, 0, 0, 0 };
3728837356
37357
+ h = strHash(pKey);
3728937358
if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
3729037359
struct _ht *pEntry;
37291
- h = strHash(pKey) % pH->htsize;
37292
- pEntry = &pH->ht[h];
37360
+ pEntry = &pH->ht[h % pH->htsize];
3729337361
elem = pEntry->chain;
3729437362
count = pEntry->count;
3729537363
}else{
37296
- h = 0;
3729737364
elem = pH->first;
3729837365
count = pH->count;
3729937366
}
3730037367
if( pHash ) *pHash = h;
3730137368
while( count ){
3730237369
assert( elem!=0 );
37303
- if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
37370
+ if( h==elem->h && sqlite3StrICmp(elem->pKey,pKey)==0 ){
3730437371
return elem;
3730537372
}
3730637373
elem = elem->next;
3730737374
count--;
3730837375
}
@@ -37310,14 +37377,13 @@
3731037377
}
3731137378
3731237379
/* Remove a single entry from the hash table given a pointer to that
3731337380
** element and a hash on the element's key.
3731437381
*/
37315
-static void removeElementGivenHash(
37382
+static void removeElement(
3731637383
Hash *pH, /* The pH containing "elem" */
37317
- HashElem* elem, /* The element to be removed from the pH */
37318
- unsigned int h /* Hash value for the element */
37384
+ HashElem *elem /* The element to be removed from the pH */
3731937385
){
3732037386
struct _ht *pEntry;
3732137387
if( elem->prev ){
3732237388
elem->prev->next = elem->next;
3732337389
}else{
@@ -37325,11 +37391,11 @@
3732537391
}
3732637392
if( elem->next ){
3732737393
elem->next->prev = elem->prev;
3732837394
}
3732937395
if( pH->ht ){
37330
- pEntry = &pH->ht[h];
37396
+ pEntry = &pH->ht[elem->h % pH->htsize];
3733137397
if( pEntry->chain==elem ){
3733237398
pEntry->chain = elem->next;
3733337399
}
3733437400
assert( pEntry->count>0 );
3733537401
pEntry->count--;
@@ -37376,11 +37442,11 @@
3737637442
assert( pKey!=0 );
3737737443
elem = findElementWithHash(pH,pKey,&h);
3737837444
if( elem->data ){
3737937445
void *old_data = elem->data;
3738037446
if( data==0 ){
37381
- removeElementGivenHash(pH,elem,h);
37447
+ removeElement(pH,elem);
3738237448
}else{
3738337449
elem->data = data;
3738437450
elem->pKey = pKey;
3738537451
}
3738637452
return old_data;
@@ -37387,19 +37453,17 @@
3738737453
}
3738837454
if( data==0 ) return 0;
3738937455
new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
3739037456
if( new_elem==0 ) return data;
3739137457
new_elem->pKey = pKey;
37458
+ new_elem->h = h;
3739237459
new_elem->data = data;
3739337460
pH->count++;
37394
- if( pH->count>=10 && pH->count > 2*pH->htsize ){
37395
- if( rehash(pH, pH->count*2) ){
37396
- assert( pH->htsize>0 );
37397
- h = strHash(pKey) % pH->htsize;
37398
- }
37461
+ if( pH->count>=5 && pH->count > 2*pH->htsize ){
37462
+ rehash(pH, pH->count*3);
3739937463
}
37400
- insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);
37464
+ insertElement(pH, pH->ht ? &pH->ht[new_elem->h % pH->htsize] : 0, new_elem);
3740137465
return 0;
3740237466
}
3740337467
3740437468
/************** End of hash.c ************************************************/
3740537469
/************** Begin file opcodes.c *****************************************/
@@ -38878,10 +38942,11 @@
3887838942
#if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
3887938943
unsigned fsFlags; /* cached details from statfs() */
3888038944
#endif
3888138945
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
3888238946
unsigned iBusyTimeout; /* Wait this many millisec on locks */
38947
+ int bBlockOnConnect; /* True to block for SHARED locks */
3888338948
#endif
3888438949
#if OS_VXWORKS
3888538950
struct vxworksFileId *pId; /* Unique file ID */
3888638951
#endif
3888738952
#ifdef SQLITE_DEBUG
@@ -40271,10 +40336,17 @@
4027140336
pInode->nLock++;
4027240337
}else{
4027340338
rc = 0;
4027440339
}
4027540340
}else{
40341
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
40342
+ if( pFile->bBlockOnConnect && pLock->l_type==F_RDLCK
40343
+ && pLock->l_start==SHARED_FIRST && pLock->l_len==SHARED_SIZE
40344
+ ){
40345
+ rc = osFcntl(pFile->h, F_SETLKW, pLock);
40346
+ }else
40347
+#endif
4027640348
rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile);
4027740349
}
4027840350
return rc;
4027940351
}
4028040352
@@ -42632,21 +42704,27 @@
4263242704
return SQLITE_OK;
4263342705
}
4263442706
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
4263542707
case SQLITE_FCNTL_LOCK_TIMEOUT: {
4263642708
int iOld = pFile->iBusyTimeout;
42709
+ int iNew = *(int*)pArg;
4263742710
#if SQLITE_ENABLE_SETLK_TIMEOUT==1
42638
- pFile->iBusyTimeout = *(int*)pArg;
42711
+ pFile->iBusyTimeout = iNew<0 ? 0x7FFFFFFF : (unsigned)iNew;
4263942712
#elif SQLITE_ENABLE_SETLK_TIMEOUT==2
4264042713
pFile->iBusyTimeout = !!(*(int*)pArg);
4264142714
#else
4264242715
# error "SQLITE_ENABLE_SETLK_TIMEOUT must be set to 1 or 2"
4264342716
#endif
4264442717
*(int*)pArg = iOld;
4264542718
return SQLITE_OK;
4264642719
}
42647
-#endif
42720
+ case SQLITE_FCNTL_BLOCK_ON_CONNECT: {
42721
+ int iNew = *(int*)pArg;
42722
+ pFile->bBlockOnConnect = iNew;
42723
+ return SQLITE_OK;
42724
+ }
42725
+#endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
4264842726
#if SQLITE_MAX_MMAP_SIZE>0
4264942727
case SQLITE_FCNTL_MMAP_SIZE: {
4265042728
i64 newLimit = *(i64*)pArg;
4265142729
int rc = SQLITE_OK;
4265242730
if( newLimit>sqlite3GlobalConfig.mxMmap ){
@@ -47155,11 +47233,21 @@
4715547233
HANDLE hMap; /* Handle for accessing memory mapping */
4715647234
void *pMapRegion; /* Area memory mapped */
4715747235
sqlite3_int64 mmapSize; /* Size of mapped region */
4715847236
sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
4715947237
#endif
47238
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
47239
+ DWORD iBusyTimeout; /* Wait this many millisec on locks */
47240
+ int bBlockOnConnect;
47241
+#endif
4716047242
};
47243
+
47244
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
47245
+# define winFileBusyTimeout(pDbFd) pDbFd->iBusyTimeout
47246
+#else
47247
+# define winFileBusyTimeout(pDbFd) 0
47248
+#endif
4716147249
4716247250
/*
4716347251
** The winVfsAppData structure is used for the pAppData member for all of the
4716447252
** Win32 VFS variants.
4716547253
*/
@@ -47590,10 +47678,16 @@
4759047678
#endif
4759147679
4759247680
#define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
4759347681
LPWSTR*))aSyscall[25].pCurrent)
4759447682
47683
+/*
47684
+** For GetLastError(), MSDN says:
47685
+**
47686
+** Minimum supported client: Windows XP [desktop apps | UWP apps]
47687
+** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
47688
+*/
4759547689
{ "GetLastError", (SYSCALL)GetLastError, 0 },
4759647690
4759747691
#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
4759847692
4759947693
#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
@@ -47872,15 +47966,17 @@
4787247966
#endif
4787347967
4787447968
#define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
4787547969
DWORD,DWORD))aSyscall[62].pCurrent)
4787647970
47877
-#if !SQLITE_OS_WINRT
47971
+/*
47972
+** For WaitForSingleObject(), MSDN says:
47973
+**
47974
+** Minimum supported client: Windows XP [desktop apps | UWP apps]
47975
+** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
47976
+*/
4787847977
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
47879
-#else
47880
- { "WaitForSingleObject", (SYSCALL)0, 0 },
47881
-#endif
4788247978
4788347979
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
4788447980
DWORD))aSyscall[63].pCurrent)
4788547981
4788647982
#if !SQLITE_OS_WINCE
@@ -48023,10 +48119,44 @@
4802348119
#endif
4802448120
4802548121
#define osFlushViewOfFile \
4802648122
((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
4802748123
48124
+/*
48125
+** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent()
48126
+** to implement blocking locks with timeouts. MSDN says:
48127
+**
48128
+** Minimum supported client: Windows XP [desktop apps | UWP apps]
48129
+** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
48130
+*/
48131
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
48132
+ { "CreateEvent", (SYSCALL)CreateEvent, 0 },
48133
+#else
48134
+ { "CreateEvent", (SYSCALL)0, 0 },
48135
+#endif
48136
+
48137
+#define osCreateEvent ( \
48138
+ (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
48139
+ aSyscall[80].pCurrent \
48140
+)
48141
+
48142
+/*
48143
+** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo()
48144
+** for the case where a timeout expires and a lock request must be
48145
+** cancelled.
48146
+**
48147
+** Minimum supported client: Windows XP [desktop apps | UWP apps]
48148
+** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
48149
+*/
48150
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
48151
+ { "CancelIo", (SYSCALL)CancelIo, 0 },
48152
+#else
48153
+ { "CancelIo", (SYSCALL)0, 0 },
48154
+#endif
48155
+
48156
+#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[81].pCurrent)
48157
+
4802848158
}; /* End of the overrideable system calls */
4802948159
4803048160
/*
4803148161
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
4803248162
** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -48321,11 +48451,13 @@
4832148451
(sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
4832248452
#endif
4832348453
}
4832448454
return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
4832548455
#elif SQLITE_TEST
48326
- return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
48456
+ return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2
48457
+ || osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0
48458
+ ;
4832748459
#else
4832848460
/*
4832948461
** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
4833048462
** deprecated are always assumed to be based on the NT kernel.
4833148463
*/
@@ -49407,10 +49539,89 @@
4940749539
return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
4940849540
numBytesHigh);
4940949541
}
4941049542
#endif
4941149543
}
49544
+
49545
+/*
49546
+** Lock a region of nByte bytes starting at offset offset of file hFile.
49547
+** Take an EXCLUSIVE lock if parameter bExclusive is true, or a SHARED lock
49548
+** otherwise. If nMs is greater than zero and the lock cannot be obtained
49549
+** immediately, block for that many ms before giving up.
49550
+**
49551
+** This function returns SQLITE_OK if the lock is obtained successfully. If
49552
+** some other process holds the lock, SQLITE_BUSY is returned if nMs==0, or
49553
+** SQLITE_BUSY_TIMEOUT otherwise. Or, if an error occurs, SQLITE_IOERR.
49554
+*/
49555
+static int winHandleLockTimeout(
49556
+ HANDLE hFile,
49557
+ DWORD offset,
49558
+ DWORD nByte,
49559
+ int bExcl,
49560
+ DWORD nMs
49561
+){
49562
+ DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0);
49563
+ int rc = SQLITE_OK;
49564
+ BOOL ret;
49565
+
49566
+ if( !osIsNT() ){
49567
+ ret = winLockFile(&hFile, flags, offset, 0, nByte, 0);
49568
+ }else{
49569
+ OVERLAPPED ovlp;
49570
+ memset(&ovlp, 0, sizeof(OVERLAPPED));
49571
+ ovlp.Offset = offset;
49572
+
49573
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49574
+ if( nMs!=0 ){
49575
+ flags &= ~LOCKFILE_FAIL_IMMEDIATELY;
49576
+ }
49577
+ ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL);
49578
+ if( ovlp.hEvent==NULL ){
49579
+ return SQLITE_IOERR_LOCK;
49580
+ }
49581
+#endif
49582
+
49583
+ ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp);
49584
+
49585
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49586
+ /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was
49587
+ ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to
49588
+ ** LockFileEx() may fail because the request is still pending. This can
49589
+ ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified.
49590
+ **
49591
+ ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags
49592
+ ** passed to LockFileEx(). In this case, if the operation is pending,
49593
+ ** block indefinitely until it is finished.
49594
+ **
49595
+ ** Otherwise, wait for up to nMs ms for the operation to finish. nMs
49596
+ ** may be set to INFINITE.
49597
+ */
49598
+ if( !ret && GetLastError()==ERROR_IO_PENDING ){
49599
+ DWORD nDelay = (nMs==0 ? INFINITE : nMs);
49600
+ DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
49601
+ if( res==WAIT_OBJECT_0 ){
49602
+ ret = TRUE;
49603
+ }else if( res==WAIT_TIMEOUT ){
49604
+ rc = SQLITE_BUSY_TIMEOUT;
49605
+ }else{
49606
+ /* Some other error has occurred */
49607
+ rc = SQLITE_IOERR_LOCK;
49608
+ }
49609
+
49610
+ /* If it is still pending, cancel the LockFileEx() call. */
49611
+ osCancelIo(hFile);
49612
+ }
49613
+
49614
+ osCloseHandle(ovlp.hEvent);
49615
+#endif
49616
+ }
49617
+
49618
+ if( rc==SQLITE_OK && !ret ){
49619
+ rc = SQLITE_BUSY;
49620
+ }
49621
+ return rc;
49622
+}
4941249623
4941349624
/*
4941449625
** Unlock a file region.
4941549626
*/
4941649627
static BOOL winUnlockFile(
@@ -49438,10 +49649,18 @@
4943849649
return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
4943949650
numBytesHigh);
4944049651
}
4944149652
#endif
4944249653
}
49654
+
49655
+/*
49656
+** Remove an nByte lock starting at offset iOff from HANDLE h.
49657
+*/
49658
+static int winHandleUnlock(HANDLE h, int iOff, int nByte){
49659
+ BOOL ret = winUnlockFile(&h, iOff, 0, nByte, 0);
49660
+ return (ret ? SQLITE_OK : SQLITE_IOERR_UNLOCK);
49661
+}
4944349662
4944449663
/*****************************************************************************
4944549664
** The next group of routines implement the I/O methods specified
4944649665
** by the sqlite3_io_methods object.
4944749666
******************************************************************************/
@@ -49452,69 +49671,73 @@
4945249671
#ifndef INVALID_SET_FILE_POINTER
4945349672
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
4945449673
#endif
4945549674
4945649675
/*
49457
-** Move the current position of the file handle passed as the first
49458
-** argument to offset iOffset within the file. If successful, return 0.
49459
-** Otherwise, set pFile->lastErrno and return non-zero.
49676
+** Seek the file handle h to offset nByte of the file.
49677
+**
49678
+** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite
49679
+** error code.
4946049680
*/
49461
-static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){
49681
+static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){
49682
+ int rc = SQLITE_OK; /* Return value */
49683
+
4946249684
#if !SQLITE_OS_WINRT
4946349685
LONG upperBits; /* Most sig. 32 bits of new offset */
4946449686
LONG lowerBits; /* Least sig. 32 bits of new offset */
4946549687
DWORD dwRet; /* Value returned by SetFilePointer() */
49466
- DWORD lastErrno; /* Value returned by GetLastError() */
49467
-
49468
- OSTRACE(("SEEK file=%p, offset=%lld\n", pFile->h, iOffset));
4946949688
4947049689
upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
4947149690
lowerBits = (LONG)(iOffset & 0xffffffff);
49691
+
49692
+ dwRet = osSetFilePointer(h, lowerBits, &upperBits, FILE_BEGIN);
4947249693
4947349694
/* API oddity: If successful, SetFilePointer() returns a dword
4947449695
** containing the lower 32-bits of the new file-offset. Or, if it fails,
4947549696
** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
4947649697
** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
4947749698
** whether an error has actually occurred, it is also necessary to call
49478
- ** GetLastError().
49479
- */
49480
- dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
49481
-
49482
- if( (dwRet==INVALID_SET_FILE_POINTER
49483
- && ((lastErrno = osGetLastError())!=NO_ERROR)) ){
49484
- pFile->lastErrno = lastErrno;
49485
- winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
49486
- "winSeekFile", pFile->zPath);
49487
- OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
49488
- return 1;
49489
- }
49490
-
49491
- OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
49492
- return 0;
49493
-#else
49494
- /*
49495
- ** Same as above, except that this implementation works for WinRT.
49496
- */
49497
-
49699
+ ** GetLastError(). */
49700
+ if( dwRet==INVALID_SET_FILE_POINTER ){
49701
+ DWORD lastErrno = osGetLastError();
49702
+ if( lastErrno!=NO_ERROR ){
49703
+ rc = SQLITE_IOERR_SEEK;
49704
+ }
49705
+ }
49706
+#else
49707
+ /* This implementation works for WinRT. */
4949849708
LARGE_INTEGER x; /* The new offset */
4949949709
BOOL bRet; /* Value returned by SetFilePointerEx() */
4950049710
4950149711
x.QuadPart = iOffset;
49502
- bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);
49712
+ bRet = osSetFilePointerEx(h, x, 0, FILE_BEGIN);
4950349713
4950449714
if(!bRet){
49715
+ rc = SQLITE_IOERR_SEEK;
49716
+ }
49717
+#endif
49718
+
49719
+ OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset, sqlite3ErrName(rc)));
49720
+ return rc;
49721
+}
49722
+
49723
+/*
49724
+** Move the current position of the file handle passed as the first
49725
+** argument to offset iOffset within the file. If successful, return 0.
49726
+** Otherwise, set pFile->lastErrno and return non-zero.
49727
+*/
49728
+static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){
49729
+ int rc;
49730
+
49731
+ rc = winHandleSeek(pFile->h, iOffset);
49732
+ if( rc!=SQLITE_OK ){
4950549733
pFile->lastErrno = osGetLastError();
49506
- winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
49507
- "winSeekFile", pFile->zPath);
49508
- OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
49509
- return 1;
49510
- }
49511
-
49512
- OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
49513
- return 0;
49514
-#endif
49515
-}
49734
+ winLogError(rc, pFile->lastErrno, "winSeekFile", pFile->zPath);
49735
+ }
49736
+ return rc;
49737
+}
49738
+
4951649739
4951749740
#if SQLITE_MAX_MMAP_SIZE>0
4951849741
/* Forward references to VFS helper methods used for memory mapped files */
4951949742
static int winMapfile(winFile*, sqlite3_int64);
4952049743
static int winUnmapfile(winFile*);
@@ -49770,10 +49993,64 @@
4977049993
}
4977149994
OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
4977249995
osGetCurrentProcessId(), pFile, pFile->h));
4977349996
return SQLITE_OK;
4977449997
}
49998
+
49999
+/*
50000
+** Truncate the file opened by handle h to nByte bytes in size.
50001
+*/
50002
+static int winHandleTruncate(HANDLE h, sqlite3_int64 nByte){
50003
+ int rc = SQLITE_OK; /* Return code */
50004
+ rc = winHandleSeek(h, nByte);
50005
+ if( rc==SQLITE_OK ){
50006
+ if( 0==osSetEndOfFile(h) ){
50007
+ rc = SQLITE_IOERR_TRUNCATE;
50008
+ }
50009
+ }
50010
+ return rc;
50011
+}
50012
+
50013
+/*
50014
+** Determine the size in bytes of the file opened by the handle passed as
50015
+** the first argument.
50016
+*/
50017
+static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){
50018
+ int rc = SQLITE_OK;
50019
+
50020
+#if SQLITE_OS_WINRT
50021
+ FILE_STANDARD_INFO info;
50022
+ BOOL b;
50023
+ b = osGetFileInformationByHandleEx(h, FileStandardInfo, &info, sizeof(info));
50024
+ if( b ){
50025
+ *pnByte = info.EndOfFile.QuadPart;
50026
+ }else{
50027
+ rc = SQLITE_IOERR_FSTAT;
50028
+ }
50029
+#else
50030
+ DWORD upperBits = 0;
50031
+ DWORD lowerBits = 0;
50032
+
50033
+ assert( pnByte );
50034
+ lowerBits = osGetFileSize(h, &upperBits);
50035
+ *pnByte = (((sqlite3_int64)upperBits)<<32) + lowerBits;
50036
+ if( lowerBits==INVALID_FILE_SIZE && osGetLastError()!=NO_ERROR ){
50037
+ rc = SQLITE_IOERR_FSTAT;
50038
+ }
50039
+#endif
50040
+
50041
+ return rc;
50042
+}
50043
+
50044
+/*
50045
+** Close the handle passed as the only argument.
50046
+*/
50047
+static void winHandleClose(HANDLE h){
50048
+ if( h!=INVALID_HANDLE_VALUE ){
50049
+ osCloseHandle(h);
50050
+ }
50051
+}
4977550052
4977650053
/*
4977750054
** Truncate an open file to a specified size
4977850055
*/
4977950056
static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
@@ -50026,31 +50303,32 @@
5002650303
/*
5002750304
** Acquire a reader lock.
5002850305
** Different API routines are called depending on whether or not this
5002950306
** is Win9x or WinNT.
5003050307
*/
50031
-static int winGetReadLock(winFile *pFile){
50308
+static int winGetReadLock(winFile *pFile, int bBlock){
5003250309
int res;
50310
+ DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0);
5003350311
OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
5003450312
if( osIsNT() ){
5003550313
#if SQLITE_OS_WINCE
5003650314
/*
5003750315
** NOTE: Windows CE is handled differently here due its lack of the Win32
5003850316
** API LockFileEx.
5003950317
*/
5004050318
res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
5004150319
#else
50042
- res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
50320
+ res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
5004350321
SHARED_SIZE, 0);
5004450322
#endif
5004550323
}
5004650324
#ifdef SQLITE_WIN32_HAS_ANSI
5004750325
else{
5004850326
int lk;
5004950327
sqlite3_randomness(sizeof(lk), &lk);
5005050328
pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
50051
- res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
50329
+ res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS&mask,
5005250330
SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
5005350331
}
5005450332
#endif
5005550333
if( res == 0 ){
5005650334
pFile->lastErrno = osGetLastError();
@@ -50180,11 +50458,11 @@
5018050458
5018150459
/* Acquire a shared lock
5018250460
*/
5018350461
if( locktype==SHARED_LOCK && res ){
5018450462
assert( pFile->locktype==NO_LOCK );
50185
- res = winGetReadLock(pFile);
50463
+ res = winGetReadLock(pFile, pFile->bBlockOnConnect);
5018650464
if( res ){
5018750465
newLocktype = SHARED_LOCK;
5018850466
}else{
5018950467
lastErrno = osGetLastError();
5019050468
}
@@ -50218,11 +50496,11 @@
5021850496
SHARED_SIZE, 0);
5021950497
if( res ){
5022050498
newLocktype = EXCLUSIVE_LOCK;
5022150499
}else{
5022250500
lastErrno = osGetLastError();
50223
- winGetReadLock(pFile);
50501
+ winGetReadLock(pFile, 0);
5022450502
}
5022550503
}
5022650504
5022750505
/* If we are holding a PENDING lock that ought to be released, then
5022850506
** release it now.
@@ -50508,10 +50786,32 @@
5050850786
}
5050950787
OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
5051050788
return rc;
5051150789
}
5051250790
#endif
50791
+
50792
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
50793
+ case SQLITE_FCNTL_LOCK_TIMEOUT: {
50794
+ int iOld = pFile->iBusyTimeout;
50795
+ int iNew = *(int*)pArg;
50796
+#if SQLITE_ENABLE_SETLK_TIMEOUT==1
50797
+ pFile->iBusyTimeout = (iNew < 0) ? INFINITE : (DWORD)iNew;
50798
+#elif SQLITE_ENABLE_SETLK_TIMEOUT==2
50799
+ pFile->iBusyTimeout = (DWORD)(!!iNew);
50800
+#else
50801
+# error "SQLITE_ENABLE_SETLK_TIMEOUT must be set to 1 or 2"
50802
+#endif
50803
+ *(int*)pArg = iOld;
50804
+ return SQLITE_OK;
50805
+ }
50806
+ case SQLITE_FCNTL_BLOCK_ON_CONNECT: {
50807
+ int iNew = *(int*)pArg;
50808
+ pFile->bBlockOnConnect = iNew;
50809
+ return SQLITE_OK;
50810
+ }
50811
+#endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
50812
+
5051350813
}
5051450814
OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
5051550815
return SQLITE_NOTFOUND;
5051650816
}
5051750817
@@ -50588,36 +50888,39 @@
5058850888
** nRef
5058950889
** pNext
5059050890
**
5059150891
** The following fields are read-only after the object is created:
5059250892
**
50593
-** fid
5059450893
** zFilename
5059550894
**
5059650895
** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
5059750896
** winShmMutexHeld() is true when reading or writing any other field
5059850897
** in this structure.
5059950898
**
50899
+** File-handle hSharedShm is used to (a) take the DMS lock, (b) truncate
50900
+** the *-shm file if the DMS-locking protocol demands it, and (c) map
50901
+** regions of the *-shm file into memory using MapViewOfFile() or
50902
+** similar. Other locks are taken by individual clients using the
50903
+** winShm.hShm handles.
5060050904
*/
5060150905
struct winShmNode {
5060250906
sqlite3_mutex *mutex; /* Mutex to access this object */
5060350907
char *zFilename; /* Name of the file */
50604
- winFile hFile; /* File handle from winOpen */
50908
+ HANDLE hSharedShm; /* File handle open on zFilename */
5060550909
50910
+ int isUnlocked; /* DMS lock has not yet been obtained */
50911
+ int isReadonly; /* True if read-only */
5060650912
int szRegion; /* Size of shared-memory regions */
5060750913
int nRegion; /* Size of array apRegion */
50608
- u8 isReadonly; /* True if read-only */
50609
- u8 isUnlocked; /* True if no DMS lock held */
5061050914
5061150915
struct ShmRegion {
5061250916
HANDLE hMap; /* File handle from CreateFileMapping */
5061350917
void *pMap;
5061450918
} *aRegion;
5061550919
DWORD lastErrno; /* The Windows errno from the last I/O error */
5061650920
5061750921
int nRef; /* Number of winShm objects pointing to this */
50618
- winShm *pFirst; /* All winShm objects pointing to this */
5061950922
winShmNode *pNext; /* Next in list of all winShmNode objects */
5062050923
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
5062150924
u8 nextShmId; /* Next available winShm.id value */
5062250925
#endif
5062350926
};
@@ -50629,27 +50932,19 @@
5062950932
*/
5063050933
static winShmNode *winShmNodeList = 0;
5063150934
5063250935
/*
5063350936
** Structure used internally by this VFS to record the state of an
50634
-** open shared memory connection.
50635
-**
50636
-** The following fields are initialized when this object is created and
50637
-** are read-only thereafter:
50638
-**
50639
-** winShm.pShmNode
50640
-** winShm.id
50641
-**
50642
-** All other fields are read/write. The winShm.pShmNode->mutex must be held
50643
-** while accessing any read/write fields.
50937
+** open shared memory connection. There is one such structure for each
50938
+** winFile open on a wal mode database.
5064450939
*/
5064550940
struct winShm {
5064650941
winShmNode *pShmNode; /* The underlying winShmNode object */
50647
- winShm *pNext; /* Next winShm with the same winShmNode */
50648
- u8 hasMutex; /* True if holding the winShmNode mutex */
5064950942
u16 sharedMask; /* Mask of shared locks held */
5065050943
u16 exclMask; /* Mask of exclusive locks held */
50944
+ HANDLE hShm; /* File-handle on *-shm file. For locking. */
50945
+ int bReadonly; /* True if hShm is opened read-only */
5065150946
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
5065250947
u8 id; /* Id of this connection with its winShmNode */
5065350948
#endif
5065450949
};
5065550950
@@ -50657,54 +50952,10 @@
5065750952
** Constants used for locking
5065850953
*/
5065950954
#define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
5066050955
#define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
5066150956
50662
-/*
50663
-** Apply advisory locks for all n bytes beginning at ofst.
50664
-*/
50665
-#define WINSHM_UNLCK 1
50666
-#define WINSHM_RDLCK 2
50667
-#define WINSHM_WRLCK 3
50668
-static int winShmSystemLock(
50669
- winShmNode *pFile, /* Apply locks to this open shared-memory segment */
50670
- int lockType, /* WINSHM_UNLCK, WINSHM_RDLCK, or WINSHM_WRLCK */
50671
- int ofst, /* Offset to first byte to be locked/unlocked */
50672
- int nByte /* Number of bytes to lock or unlock */
50673
-){
50674
- int rc = 0; /* Result code form Lock/UnlockFileEx() */
50675
-
50676
- /* Access to the winShmNode object is serialized by the caller */
50677
- assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) );
50678
-
50679
- OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n",
50680
- pFile->hFile.h, lockType, ofst, nByte));
50681
-
50682
- /* Release/Acquire the system-level lock */
50683
- if( lockType==WINSHM_UNLCK ){
50684
- rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
50685
- }else{
50686
- /* Initialize the locking parameters */
50687
- DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
50688
- if( lockType == WINSHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
50689
- rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
50690
- }
50691
-
50692
- if( rc!= 0 ){
50693
- rc = SQLITE_OK;
50694
- }else{
50695
- pFile->lastErrno = osGetLastError();
50696
- rc = SQLITE_BUSY;
50697
- }
50698
-
50699
- OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n",
50700
- pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" :
50701
- "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
50702
-
50703
- return rc;
50704
-}
50705
-
5070650957
/* Forward references to VFS methods */
5070750958
static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
5070850959
static int winDelete(sqlite3_vfs *,const char*,int);
5070950960
5071050961
/*
@@ -50732,15 +50983,11 @@
5073250983
bRc = osCloseHandle(p->aRegion[i].hMap);
5073350984
OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
5073450985
osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
5073550986
UNUSED_VARIABLE_VALUE(bRc);
5073650987
}
50737
- if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
50738
- SimulateIOErrorBenign(1);
50739
- winClose((sqlite3_file *)&p->hFile);
50740
- SimulateIOErrorBenign(0);
50741
- }
50988
+ winHandleClose(p->hSharedShm);
5074250989
if( deleteFlag ){
5074350990
SimulateIOErrorBenign(1);
5074450991
sqlite3BeginBenignMalloc();
5074550992
winDelete(pVfs, p->zFilename, 0);
5074650993
sqlite3EndBenignMalloc();
@@ -50754,46 +51001,166 @@
5075451001
}
5075551002
}
5075651003
}
5075751004
5075851005
/*
50759
-** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
50760
-** take it now. Return SQLITE_OK if successful, or an SQLite error
50761
-** code otherwise.
50762
-**
50763
-** If the DMS cannot be locked because this is a readonly_shm=1
50764
-** connection and no other process already holds a lock, return
50765
-** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1.
51006
+** The DMS lock has not yet been taken on the shm file associated with
51007
+** pShmNode. Take the lock. Truncate the *-shm file if required.
51008
+** Return SQLITE_OK if successful, or an SQLite error code otherwise.
5076651009
*/
50767
-static int winLockSharedMemory(winShmNode *pShmNode){
50768
- int rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1);
51010
+static int winLockSharedMemory(winShmNode *pShmNode, DWORD nMs){
51011
+ HANDLE h = pShmNode->hSharedShm;
51012
+ int rc = SQLITE_OK;
5076951013
51014
+ assert( sqlite3_mutex_held(pShmNode->mutex) );
51015
+ rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 1, 0);
5077051016
if( rc==SQLITE_OK ){
51017
+ /* We have an EXCLUSIVE lock on the DMS byte. This means that this
51018
+ ** is the first process to open the file. Truncate it to zero bytes
51019
+ ** in this case. */
5077151020
if( pShmNode->isReadonly ){
50772
- pShmNode->isUnlocked = 1;
50773
- winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50774
- return SQLITE_READONLY_CANTINIT;
50775
- }else if( winTruncate((sqlite3_file*)&pShmNode->hFile, 0) ){
50776
- winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50777
- return winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
50778
- "winLockSharedMemory", pShmNode->zFilename);
50779
- }
50780
- }
50781
-
50782
- if( rc==SQLITE_OK ){
50783
- winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50784
- }
50785
-
50786
- return winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1);
50787
-}
50788
-
50789
-/*
50790
-** Open the shared-memory area associated with database file pDbFd.
50791
-**
50792
-** When opening a new shared-memory file, if no other instances of that
50793
-** file are currently open, in this process or in other processes, then
50794
-** the file must be truncated to zero length or have its header cleared.
51021
+ rc = SQLITE_READONLY_CANTINIT;
51022
+ }else{
51023
+ rc = winHandleTruncate(h, 0);
51024
+ }
51025
+
51026
+ /* Release the EXCLUSIVE lock acquired above. */
51027
+ winUnlockFile(&h, WIN_SHM_DMS, 0, 1, 0);
51028
+ }else if( (rc & 0xFF)==SQLITE_BUSY ){
51029
+ rc = SQLITE_OK;
51030
+ }
51031
+
51032
+ if( rc==SQLITE_OK ){
51033
+ /* Take a SHARED lock on the DMS byte. */
51034
+ rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 0, nMs);
51035
+ if( rc==SQLITE_OK ){
51036
+ pShmNode->isUnlocked = 0;
51037
+ }
51038
+ }
51039
+
51040
+ return rc;
51041
+}
51042
+
51043
+
51044
+/*
51045
+** Convert a UTF-8 filename into whatever form the underlying
51046
+** operating system wants filenames in. Space to hold the result
51047
+** is obtained from malloc and must be freed by the calling
51048
+** function.
51049
+*/
51050
+static void *winConvertFromUtf8Filename(const char *zFilename){
51051
+ void *zConverted = 0;
51052
+ if( osIsNT() ){
51053
+ zConverted = winUtf8ToUnicode(zFilename);
51054
+ }
51055
+#ifdef SQLITE_WIN32_HAS_ANSI
51056
+ else{
51057
+ zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
51058
+ }
51059
+#endif
51060
+ /* caller will handle out of memory */
51061
+ return zConverted;
51062
+}
51063
+
51064
+/*
51065
+** This function is used to open a handle on a *-shm file.
51066
+**
51067
+** If SQLITE_ENABLE_SETLK_TIMEOUT is defined at build time, then the file
51068
+** is opened with FILE_FLAG_OVERLAPPED specified. If not, it is not.
51069
+*/
51070
+static int winHandleOpen(
51071
+ const char *zUtf8, /* File to open */
51072
+ int *pbReadonly, /* IN/OUT: True for readonly handle */
51073
+ HANDLE *ph /* OUT: New HANDLE for file */
51074
+){
51075
+ int rc = SQLITE_OK;
51076
+ void *zConverted = 0;
51077
+ int bReadonly = *pbReadonly;
51078
+ HANDLE h = INVALID_HANDLE_VALUE;
51079
+
51080
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51081
+ const DWORD flag_overlapped = FILE_FLAG_OVERLAPPED;
51082
+#else
51083
+ const DWORD flag_overlapped = 0;
51084
+#endif
51085
+
51086
+ /* Convert the filename to the system encoding. */
51087
+ zConverted = winConvertFromUtf8Filename(zUtf8);
51088
+ if( zConverted==0 ){
51089
+ OSTRACE(("OPEN name=%s, rc=SQLITE_IOERR_NOMEM", zUtf8));
51090
+ rc = SQLITE_IOERR_NOMEM_BKPT;
51091
+ goto winopenfile_out;
51092
+ }
51093
+
51094
+ /* Ensure the file we are trying to open is not actually a directory. */
51095
+ if( winIsDir(zConverted) ){
51096
+ OSTRACE(("OPEN name=%s, rc=SQLITE_CANTOPEN_ISDIR", zUtf8));
51097
+ rc = SQLITE_CANTOPEN_ISDIR;
51098
+ goto winopenfile_out;
51099
+ }
51100
+
51101
+ /* TODO: platforms.
51102
+ ** TODO: retry-on-ioerr.
51103
+ */
51104
+ if( osIsNT() ){
51105
+#if SQLITE_OS_WINRT
51106
+ CREATEFILE2_EXTENDED_PARAMETERS extendedParameters;
51107
+ memset(&extendedParameters, 0, sizeof(extendedParameters));
51108
+ extendedParameters.dwSize = sizeof(extendedParameters);
51109
+ extendedParameters.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
51110
+ extendedParameters.dwFileFlags = flag_overlapped;
51111
+ extendedParameters.dwSecurityQosFlags = SECURITY_ANONYMOUS;
51112
+ h = osCreateFile2((LPCWSTR)zConverted,
51113
+ (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)),/* dwDesiredAccess */
51114
+ FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51115
+ OPEN_ALWAYS, /* dwCreationDisposition */
51116
+ &extendedParameters
51117
+ );
51118
+#else
51119
+ h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
51120
+ (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51121
+ FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51122
+ NULL, /* lpSecurityAttributes */
51123
+ OPEN_ALWAYS, /* dwCreationDisposition */
51124
+ FILE_ATTRIBUTE_NORMAL|flag_overlapped,
51125
+ NULL
51126
+ );
51127
+#endif
51128
+ }else{
51129
+ /* Due to pre-processor directives earlier in this file,
51130
+ ** SQLITE_WIN32_HAS_ANSI is always defined if osIsNT() is false. */
51131
+#ifdef SQLITE_WIN32_HAS_ANSI
51132
+ h = osCreateFileA((LPCSTR)zConverted,
51133
+ (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51134
+ FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51135
+ NULL, /* lpSecurityAttributes */
51136
+ OPEN_ALWAYS, /* dwCreationDisposition */
51137
+ FILE_ATTRIBUTE_NORMAL|flag_overlapped,
51138
+ NULL
51139
+ );
51140
+#endif
51141
+ }
51142
+
51143
+ if( h==INVALID_HANDLE_VALUE ){
51144
+ if( bReadonly==0 ){
51145
+ bReadonly = 1;
51146
+ rc = winHandleOpen(zUtf8, &bReadonly, &h);
51147
+ }else{
51148
+ rc = SQLITE_CANTOPEN_BKPT;
51149
+ }
51150
+ }
51151
+
51152
+ winopenfile_out:
51153
+ sqlite3_free(zConverted);
51154
+ *pbReadonly = bReadonly;
51155
+ *ph = h;
51156
+ return rc;
51157
+}
51158
+
51159
+
51160
+/*
51161
+** Open the shared-memory area associated with database file pDbFd.
5079551162
*/
5079651163
static int winOpenSharedMemory(winFile *pDbFd){
5079751164
struct winShm *p; /* The connection to be opened */
5079851165
winShmNode *pShmNode = 0; /* The underlying mmapped file */
5079951166
int rc = SQLITE_OK; /* Result code */
@@ -50801,102 +51168,87 @@
5080151168
int nName; /* Size of zName in bytes */
5080251169
5080351170
assert( pDbFd->pShm==0 ); /* Not previously opened */
5080451171
5080551172
/* Allocate space for the new sqlite3_shm object. Also speculatively
50806
- ** allocate space for a new winShmNode and filename.
50807
- */
51173
+ ** allocate space for a new winShmNode and filename. */
5080851174
p = sqlite3MallocZero( sizeof(*p) );
5080951175
if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
5081051176
nName = sqlite3Strlen30(pDbFd->zPath);
5081151177
pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
5081251178
if( pNew==0 ){
5081351179
sqlite3_free(p);
5081451180
return SQLITE_IOERR_NOMEM_BKPT;
5081551181
}
5081651182
pNew->zFilename = (char*)&pNew[1];
51183
+ pNew->hSharedShm = INVALID_HANDLE_VALUE;
51184
+ pNew->isUnlocked = 1;
5081751185
sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
5081851186
sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
51187
+
51188
+ /* Open a file-handle on the *-shm file for this connection. This file-handle
51189
+ ** is only used for locking. The mapping of the *-shm file is created using
51190
+ ** the shared file handle in winShmNode.hSharedShm. */
51191
+ p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51192
+ rc = winHandleOpen(pNew->zFilename, &p->bReadonly, &p->hShm);
5081951193
5082051194
/* Look to see if there is an existing winShmNode that can be used.
50821
- ** If no matching winShmNode currently exists, create a new one.
50822
- */
51195
+ ** If no matching winShmNode currently exists, then create a new one. */
5082351196
winShmEnterMutex();
5082451197
for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
5082551198
/* TBD need to come up with better match here. Perhaps
50826
- ** use FILE_ID_BOTH_DIR_INFO Structure.
50827
- */
51199
+ ** use FILE_ID_BOTH_DIR_INFO Structure. */
5082851200
if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
5082951201
}
50830
- if( pShmNode ){
50831
- sqlite3_free(pNew);
50832
- }else{
50833
- int inFlags = SQLITE_OPEN_WAL;
50834
- int outFlags = 0;
50835
-
51202
+ if( pShmNode==0 ){
5083651203
pShmNode = pNew;
50837
- pNew = 0;
50838
- ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
50839
- pShmNode->pNext = winShmNodeList;
50840
- winShmNodeList = pShmNode;
5084151204
51205
+ /* Allocate a mutex for this winShmNode object, if one is required. */
5084251206
if( sqlite3GlobalConfig.bCoreMutex ){
5084351207
pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
50844
- if( pShmNode->mutex==0 ){
50845
- rc = SQLITE_IOERR_NOMEM_BKPT;
50846
- goto shm_open_err;
50847
- }
50848
- }
50849
-
50850
- if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
50851
- inFlags |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
50852
- }else{
50853
- inFlags |= SQLITE_OPEN_READONLY;
50854
- }
50855
- rc = winOpen(pDbFd->pVfs, pShmNode->zFilename,
50856
- (sqlite3_file*)&pShmNode->hFile,
50857
- inFlags, &outFlags);
50858
- if( rc!=SQLITE_OK ){
50859
- rc = winLogError(rc, osGetLastError(), "winOpenShm",
50860
- pShmNode->zFilename);
50861
- goto shm_open_err;
50862
- }
50863
- if( outFlags==SQLITE_OPEN_READONLY ) pShmNode->isReadonly = 1;
50864
-
50865
- rc = winLockSharedMemory(pShmNode);
50866
- if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
50867
- }
50868
-
50869
- /* Make the new connection a child of the winShmNode */
50870
- p->pShmNode = pShmNode;
51208
+ if( pShmNode->mutex==0 ) rc = SQLITE_IOERR_NOMEM_BKPT;
51209
+ }
51210
+
51211
+ /* Open a file-handle to use for mappings, and for the DMS lock. */
51212
+ if( rc==SQLITE_OK ){
51213
+ HANDLE h = INVALID_HANDLE_VALUE;
51214
+ pShmNode->isReadonly = p->bReadonly;
51215
+ rc = winHandleOpen(pNew->zFilename, &pShmNode->isReadonly, &h);
51216
+ pShmNode->hSharedShm = h;
51217
+ }
51218
+
51219
+ /* If successful, link the new winShmNode into the global list. If an
51220
+ ** error occurred, free the object. */
51221
+ if( rc==SQLITE_OK ){
51222
+ pShmNode->pNext = winShmNodeList;
51223
+ winShmNodeList = pShmNode;
51224
+ pNew = 0;
51225
+ }else{
51226
+ sqlite3_mutex_free(pShmNode->mutex);
51227
+ if( pShmNode->hSharedShm!=INVALID_HANDLE_VALUE ){
51228
+ osCloseHandle(pShmNode->hSharedShm);
51229
+ }
51230
+ }
51231
+ }
51232
+
51233
+ /* If no error has occurred, link the winShm object to the winShmNode and
51234
+ ** the winShm to pDbFd. */
51235
+ if( rc==SQLITE_OK ){
51236
+ p->pShmNode = pShmNode;
51237
+ pShmNode->nRef++;
5087151238
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
50872
- p->id = pShmNode->nextShmId++;
50873
-#endif
50874
- pShmNode->nRef++;
50875
- pDbFd->pShm = p;
50876
- winShmLeaveMutex();
50877
-
50878
- /* The reference count on pShmNode has already been incremented under
50879
- ** the cover of the winShmEnterMutex() mutex and the pointer from the
50880
- ** new (struct winShm) object to the pShmNode has been set. All that is
50881
- ** left to do is to link the new object into the linked list starting
50882
- ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex
50883
- ** mutex.
50884
- */
50885
- sqlite3_mutex_enter(pShmNode->mutex);
50886
- p->pNext = pShmNode->pFirst;
50887
- pShmNode->pFirst = p;
50888
- sqlite3_mutex_leave(pShmNode->mutex);
50889
- return rc;
50890
-
50891
- /* Jump here on any error */
50892
-shm_open_err:
50893
- winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50894
- winShmPurge(pDbFd->pVfs, 0); /* This call frees pShmNode if required */
50895
- sqlite3_free(p);
50896
- sqlite3_free(pNew);
50897
- winShmLeaveMutex();
51239
+ p->id = pShmNode->nextShmId++;
51240
+#endif
51241
+ pDbFd->pShm = p;
51242
+ }else if( p ){
51243
+ winHandleClose(p->hShm);
51244
+ sqlite3_free(p);
51245
+ }
51246
+
51247
+ assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 );
51248
+ winShmLeaveMutex();
51249
+ sqlite3_free(pNew);
5089851250
return rc;
5089951251
}
5090051252
5090151253
/*
5090251254
** Close a connection to shared-memory. Delete the underlying
@@ -50907,38 +51259,33 @@
5090751259
int deleteFlag /* Delete after closing if true */
5090851260
){
5090951261
winFile *pDbFd; /* Database holding shared-memory */
5091051262
winShm *p; /* The connection to be closed */
5091151263
winShmNode *pShmNode; /* The underlying shared-memory file */
50912
- winShm **pp; /* For looping over sibling connections */
5091351264
5091451265
pDbFd = (winFile*)fd;
5091551266
p = pDbFd->pShm;
5091651267
if( p==0 ) return SQLITE_OK;
51268
+ if( p->hShm!=INVALID_HANDLE_VALUE ){
51269
+ osCloseHandle(p->hShm);
51270
+ }
51271
+
5091751272
pShmNode = p->pShmNode;
50918
-
50919
- /* Remove connection p from the set of connections associated
50920
- ** with pShmNode */
50921
- sqlite3_mutex_enter(pShmNode->mutex);
50922
- for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){}
50923
- *pp = p->pNext;
50924
-
50925
- /* Free the connection p */
50926
- sqlite3_free(p);
50927
- pDbFd->pShm = 0;
50928
- sqlite3_mutex_leave(pShmNode->mutex);
51273
+ winShmEnterMutex();
5092951274
5093051275
/* If pShmNode->nRef has reached 0, then close the underlying
50931
- ** shared-memory file, too */
50932
- winShmEnterMutex();
51276
+ ** shared-memory file, too. */
5093351277
assert( pShmNode->nRef>0 );
5093451278
pShmNode->nRef--;
5093551279
if( pShmNode->nRef==0 ){
5093651280
winShmPurge(pDbFd->pVfs, deleteFlag);
5093751281
}
5093851282
winShmLeaveMutex();
5093951283
51284
+ /* Free the connection p */
51285
+ sqlite3_free(p);
51286
+ pDbFd->pShm = 0;
5094051287
return SQLITE_OK;
5094151288
}
5094251289
5094351290
/*
5094451291
** Change the lock state for a shared-memory segment.
@@ -50949,14 +51296,13 @@
5094951296
int n, /* Number of locks to acquire or release */
5095051297
int flags /* What to do with the lock */
5095151298
){
5095251299
winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
5095351300
winShm *p = pDbFd->pShm; /* The shared memory being locked */
50954
- winShm *pX; /* For looping over all siblings */
5095551301
winShmNode *pShmNode;
5095651302
int rc = SQLITE_OK; /* Result code */
50957
- u16 mask; /* Mask of locks to take or release */
51303
+ u16 mask = (u16)((1U<<(ofst+n)) - (1U<<ofst)); /* Mask of locks to [un]take */
5095851304
5095951305
if( p==0 ) return SQLITE_IOERR_SHMLOCK;
5096051306
pShmNode = p->pShmNode;
5096151307
if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
5096251308
@@ -50966,89 +51312,86 @@
5096651312
|| flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
5096751313
|| flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
5096851314
|| flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
5096951315
assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
5097051316
50971
- mask = (u16)((1U<<(ofst+n)) - (1U<<ofst));
50972
- assert( n>1 || mask==(1<<ofst) );
50973
- sqlite3_mutex_enter(pShmNode->mutex);
50974
- if( flags & SQLITE_SHM_UNLOCK ){
50975
- u16 allMask = 0; /* Mask of locks held by siblings */
50976
-
50977
- /* See if any siblings hold this same lock */
50978
- for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
50979
- if( pX==p ) continue;
50980
- assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 );
50981
- allMask |= pX->sharedMask;
50982
- }
50983
-
50984
- /* Unlock the system-level locks */
50985
- if( (mask & allMask)==0 ){
50986
- rc = winShmSystemLock(pShmNode, WINSHM_UNLCK, ofst+WIN_SHM_BASE, n);
50987
- }else{
50988
- rc = SQLITE_OK;
50989
- }
50990
-
50991
- /* Undo the local locks */
50992
- if( rc==SQLITE_OK ){
50993
- p->exclMask &= ~mask;
50994
- p->sharedMask &= ~mask;
50995
- }
50996
- }else if( flags & SQLITE_SHM_SHARED ){
50997
- u16 allShared = 0; /* Union of locks held by connections other than "p" */
50998
-
50999
- /* Find out which shared locks are already held by sibling connections.
51000
- ** If any sibling already holds an exclusive lock, go ahead and return
51001
- ** SQLITE_BUSY.
51002
- */
51003
- for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
51004
- if( (pX->exclMask & mask)!=0 ){
51005
- rc = SQLITE_BUSY;
51006
- break;
51007
- }
51008
- allShared |= pX->sharedMask;
51009
- }
51010
-
51011
- /* Get shared locks at the system level, if necessary */
51012
- if( rc==SQLITE_OK ){
51013
- if( (allShared & mask)==0 ){
51014
- rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, ofst+WIN_SHM_BASE, n);
51015
- }else{
51016
- rc = SQLITE_OK;
51017
- }
51018
- }
51019
-
51020
- /* Get the local shared locks */
51021
- if( rc==SQLITE_OK ){
51022
- p->sharedMask |= mask;
51023
- }
51024
- }else{
51025
- /* Make sure no sibling connections hold locks that will block this
51026
- ** lock. If any do, return SQLITE_BUSY right away.
51027
- */
51028
- for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
51029
- if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){
51030
- rc = SQLITE_BUSY;
51031
- break;
51032
- }
51033
- }
51034
-
51035
- /* Get the exclusive locks at the system level. Then if successful
51036
- ** also mark the local connection as being locked.
51037
- */
51038
- if( rc==SQLITE_OK ){
51039
- rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, ofst+WIN_SHM_BASE, n);
51040
- if( rc==SQLITE_OK ){
51041
- assert( (p->sharedMask & mask)==0 );
51042
- p->exclMask |= mask;
51043
- }
51044
- }
51045
- }
51046
- sqlite3_mutex_leave(pShmNode->mutex);
51047
- OSTRACE(("SHM-LOCK pid=%lu, id=%d, sharedMask=%03x, exclMask=%03x, rc=%s\n",
51048
- osGetCurrentProcessId(), p->id, p->sharedMask, p->exclMask,
51049
- sqlite3ErrName(rc)));
51317
+ /* Check that, if this to be a blocking lock, no locks that occur later
51318
+ ** in the following list than the lock being obtained are already held:
51319
+ **
51320
+ ** 1. Checkpointer lock (ofst==1).
51321
+ ** 2. Write lock (ofst==0).
51322
+ ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
51323
+ **
51324
+ ** In other words, if this is a blocking lock, none of the locks that
51325
+ ** occur later in the above list than the lock being obtained may be
51326
+ ** held.
51327
+ **
51328
+ ** It is not permitted to block on the RECOVER lock.
51329
+ */
51330
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51331
+ {
51332
+ u16 lockMask = (p->exclMask|p->sharedMask);
51333
+ assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51334
+ (ofst!=2) /* not RECOVER */
51335
+ && (ofst!=1 || lockMask==0 || lockMask==2)
51336
+ && (ofst!=0 || lockMask<3)
51337
+ && (ofst<3 || lockMask<(1<<ofst))
51338
+ ));
51339
+ }
51340
+#endif
51341
+
51342
+ /* Check if there is any work to do. There are three cases:
51343
+ **
51344
+ ** a) An unlock operation where there are locks to unlock,
51345
+ ** b) An shared lock where the requested lock is not already held
51346
+ ** c) An exclusive lock where the requested lock is not already held
51347
+ **
51348
+ ** The SQLite core never requests an exclusive lock that it already holds.
51349
+ ** This is assert()ed immediately below. */
51350
+ assert( flags!=(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK)
51351
+ || 0==(p->exclMask & mask)
51352
+ );
51353
+ if( ((flags & SQLITE_SHM_UNLOCK) && ((p->exclMask|p->sharedMask) & mask))
51354
+ || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
51355
+ || (flags==(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK))
51356
+ ){
51357
+
51358
+ if( flags & SQLITE_SHM_UNLOCK ){
51359
+ /* Case (a) - unlock. */
51360
+
51361
+ assert( (p->exclMask & p->sharedMask)==0 );
51362
+ assert( !(flags & SQLITE_SHM_EXCLUSIVE) || (p->exclMask & mask)==mask );
51363
+ assert( !(flags & SQLITE_SHM_SHARED) || (p->sharedMask & mask)==mask );
51364
+
51365
+ rc = winHandleUnlock(p->hShm, ofst+WIN_SHM_BASE, n);
51366
+
51367
+ /* If successful, also clear the bits in sharedMask/exclMask */
51368
+ if( rc==SQLITE_OK ){
51369
+ p->exclMask = (p->exclMask & ~mask);
51370
+ p->sharedMask = (p->sharedMask & ~mask);
51371
+ }
51372
+ }else{
51373
+ int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0);
51374
+ DWORD nMs = winFileBusyTimeout(pDbFd);
51375
+ rc = winHandleLockTimeout(p->hShm, ofst+WIN_SHM_BASE, n, bExcl, nMs);
51376
+ if( rc==SQLITE_OK ){
51377
+ if( bExcl ){
51378
+ p->exclMask = (p->exclMask | mask);
51379
+ }else{
51380
+ p->sharedMask = (p->sharedMask | mask);
51381
+ }
51382
+ }
51383
+ }
51384
+ }
51385
+
51386
+ OSTRACE((
51387
+ "SHM-LOCK(%d,%d,%d) pid=%lu, id=%d, sharedMask=%03x, exclMask=%03x,"
51388
+ " rc=%s\n",
51389
+ ofst, n, flags,
51390
+ osGetCurrentProcessId(), p->id, p->sharedMask, p->exclMask,
51391
+ sqlite3ErrName(rc))
51392
+ );
5105051393
return rc;
5105151394
}
5105251395
5105351396
/*
5105451397
** Implement a memory barrier or memory fence on shared memory.
@@ -51106,17 +51449,19 @@
5110651449
}
5110751450
pShmNode = pShm->pShmNode;
5110851451
5110951452
sqlite3_mutex_enter(pShmNode->mutex);
5111051453
if( pShmNode->isUnlocked ){
51111
- rc = winLockSharedMemory(pShmNode);
51454
+ /* Take the DMS lock. */
51455
+ assert( pShmNode->nRegion==0 );
51456
+ rc = winLockSharedMemory(pShmNode, winFileBusyTimeout(pDbFd));
5111251457
if( rc!=SQLITE_OK ) goto shmpage_out;
51113
- pShmNode->isUnlocked = 0;
5111451458
}
51459
+
5111551460
assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
51116
-
5111751461
if( pShmNode->nRegion<=iRegion ){
51462
+ HANDLE hShared = pShmNode->hSharedShm;
5111851463
struct ShmRegion *apNew; /* New aRegion[] array */
5111951464
int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
5112051465
sqlite3_int64 sz; /* Current size of wal-index file */
5112151466
5112251467
pShmNode->szRegion = szRegion;
@@ -51123,35 +51468,32 @@
5112351468
5112451469
/* The requested region is not mapped into this processes address space.
5112551470
** Check to see if it has been allocated (i.e. if the wal-index file is
5112651471
** large enough to contain the requested region).
5112751472
*/
51128
- rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz);
51473
+ rc = winHandleSize(hShared, &sz);
5112951474
if( rc!=SQLITE_OK ){
51130
- rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
51131
- "winShmMap1", pDbFd->zPath);
51475
+ rc = winLogError(rc, osGetLastError(), "winShmMap1", pDbFd->zPath);
5113251476
goto shmpage_out;
5113351477
}
5113451478
5113551479
if( sz<nByte ){
5113651480
/* The requested memory region does not exist. If isWrite is set to
5113751481
** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
5113851482
**
5113951483
** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
51140
- ** the requested memory region.
51141
- */
51484
+ ** the requested memory region. */
5114251485
if( !isWrite ) goto shmpage_out;
51143
- rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte);
51486
+ rc = winHandleTruncate(hShared, nByte);
5114451487
if( rc!=SQLITE_OK ){
51145
- rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
51146
- "winShmMap2", pDbFd->zPath);
51488
+ rc = winLogError(rc, osGetLastError(), "winShmMap2", pDbFd->zPath);
5114751489
goto shmpage_out;
5114851490
}
5114951491
}
5115051492
5115151493
/* Map the requested memory region into this processes address space. */
51152
- apNew = (struct ShmRegion *)sqlite3_realloc64(
51494
+ apNew = (struct ShmRegion*)sqlite3_realloc64(
5115351495
pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
5115451496
);
5115551497
if( !apNew ){
5115651498
rc = SQLITE_IOERR_NOMEM_BKPT;
5115751499
goto shmpage_out;
@@ -51166,22 +51508,17 @@
5116651508
while( pShmNode->nRegion<=iRegion ){
5116751509
HANDLE hMap = NULL; /* file-mapping handle */
5116851510
void *pMap = 0; /* Mapped memory region */
5116951511
5117051512
#if SQLITE_OS_WINRT
51171
- hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
51172
- NULL, protect, nByte, NULL
51173
- );
51513
+ hMap = osCreateFileMappingFromApp(hShared, NULL, protect, nByte, NULL);
5117451514
#elif defined(SQLITE_WIN32_HAS_WIDE)
51175
- hMap = osCreateFileMappingW(pShmNode->hFile.h,
51176
- NULL, protect, 0, nByte, NULL
51177
- );
51515
+ hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
5117851516
#elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
51179
- hMap = osCreateFileMappingA(pShmNode->hFile.h,
51180
- NULL, protect, 0, nByte, NULL
51181
- );
51517
+ hMap = osCreateFileMappingA(hShared, NULL, protect, 0, nByte, NULL);
5118251518
#endif
51519
+
5118351520
OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
5118451521
osGetCurrentProcessId(), pShmNode->nRegion, nByte,
5118551522
hMap ? "ok" : "failed"));
5118651523
if( hMap ){
5118751524
int iOffset = pShmNode->nRegion*szRegion;
@@ -51220,11 +51557,13 @@
5122051557
char *p = (char *)pShmNode->aRegion[iRegion].pMap;
5122151558
*pp = (void *)&p[iOffsetShift];
5122251559
}else{
5122351560
*pp = 0;
5122451561
}
51225
- if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY;
51562
+ if( pShmNode->isReadonly && rc==SQLITE_OK ){
51563
+ rc = SQLITE_READONLY;
51564
+ }
5122651565
sqlite3_mutex_leave(pShmNode->mutex);
5122751566
return rc;
5122851567
}
5122951568
5123051569
#else
@@ -51561,30 +51900,10 @@
5156151900
/* caller will handle out of memory */
5156251901
return zConverted;
5156351902
}
5156451903
#endif
5156551904
51566
-/*
51567
-** Convert a UTF-8 filename into whatever form the underlying
51568
-** operating system wants filenames in. Space to hold the result
51569
-** is obtained from malloc and must be freed by the calling
51570
-** function.
51571
-*/
51572
-static void *winConvertFromUtf8Filename(const char *zFilename){
51573
- void *zConverted = 0;
51574
- if( osIsNT() ){
51575
- zConverted = winUtf8ToUnicode(zFilename);
51576
- }
51577
-#ifdef SQLITE_WIN32_HAS_ANSI
51578
- else{
51579
- zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
51580
- }
51581
-#endif
51582
- /* caller will handle out of memory */
51583
- return zConverted;
51584
-}
51585
-
5158651905
/*
5158751906
** This function returns non-zero if the specified UTF-8 string buffer
5158851907
** ends with a directory separator character or one was successfully
5158951908
** added to it.
5159051909
*/
@@ -53035,11 +53354,11 @@
5303553354
};
5303653355
#endif
5303753356
5303853357
/* Double-check that the aSyscall[] array has been constructed
5303953358
** correctly. See ticket [bb3a86e890c8e96ab] */
53040
- assert( ArraySize(aSyscall)==80 );
53359
+ assert( ArraySize(aSyscall)==82 );
5304153360
5304253361
/* get memory map allocation granularity */
5304353362
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
5304453363
#if SQLITE_OS_WINRT
5304553364
osGetNativeSystemInfo(&winSysInfo);
@@ -65633,10 +65952,15 @@
6563365952
)
6563465953
6563565954
/*
6563665955
** An open write-ahead log file is represented by an instance of the
6563765956
** following object.
65957
+**
65958
+** writeLock:
65959
+** This is usually set to 1 whenever the WRITER lock is held. However,
65960
+** if it is set to 2, then the WRITER lock is held but must be released
65961
+** by walHandleException() if a SEH exception is thrown.
6563865962
*/
6563965963
struct Wal {
6564065964
sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */
6564165965
sqlite3_file *pDbFd; /* File handle for the database file */
6564265966
sqlite3_file *pWalFd; /* File handle for WAL file */
@@ -67158,11 +67482,11 @@
6715867482
** or 0 otherwise.
6715967483
*/
6716067484
static int walEnableBlocking(Wal *pWal){
6716167485
int res = 0;
6716267486
if( pWal->db ){
67163
- int tmout = pWal->db->busyTimeout;
67487
+ int tmout = pWal->db->setlkTimeout;
6716467488
if( tmout ){
6716567489
res = walEnableBlockingMs(pWal, tmout);
6716667490
}
6716767491
}
6716867492
return res;
@@ -67544,11 +67868,13 @@
6754467868
static int walHandleException(Wal *pWal){
6754567869
if( pWal->exclusiveMode==0 ){
6754667870
static const int S = 1;
6754767871
static const int E = (1<<SQLITE_SHM_NLOCK);
6754867872
int ii;
67549
- u32 mUnlock = pWal->lockMask & ~(
67873
+ u32 mUnlock;
67874
+ if( pWal->writeLock==2 ) pWal->writeLock = 0;
67875
+ mUnlock = pWal->lockMask & ~(
6755067876
(pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
6755167877
| (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
6755267878
| (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
6755367879
);
6755467880
for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){
@@ -67816,11 +68142,16 @@
6781668142
}else{
6781768143
int bWriteLock = pWal->writeLock;
6781868144
if( bWriteLock
6781968145
|| SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1))
6782068146
){
67821
- pWal->writeLock = 1;
68147
+ /* If the write-lock was just obtained, set writeLock to 2 instead of
68148
+ ** the usual 1. This causes walIndexPage() to behave as if the
68149
+ ** write-lock were held (so that it allocates new pages as required),
68150
+ ** and walHandleException() to unlock the write-lock if a SEH exception
68151
+ ** is thrown. */
68152
+ if( !bWriteLock ) pWal->writeLock = 2;
6782268153
if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
6782368154
badHdr = walIndexTryHdr(pWal, pChanged);
6782468155
if( badHdr ){
6782568156
/* If the wal-index header is still malformed even while holding
6782668157
** a WRITE lock, it can only mean that the header is corrupted and
@@ -68601,12 +68932,15 @@
6860168932
/*
6860268933
** Finish with a read transaction. All this does is release the
6860368934
** read-lock.
6860468935
*/
6860568936
SQLITE_PRIVATE void sqlite3WalEndReadTransaction(Wal *pWal){
68606
- sqlite3WalEndWriteTransaction(pWal);
68937
+#ifndef SQLITE_ENABLE_SETLK_TIMEOUT
68938
+ assert( pWal->writeLock==0 || pWal->readLock<0 );
68939
+#endif
6860768940
if( pWal->readLock>=0 ){
68941
+ sqlite3WalEndWriteTransaction(pWal);
6860868942
walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
6860968943
pWal->readLock = -1;
6861068944
}
6861168945
}
6861268946
@@ -68795,11 +69129,11 @@
6879569129
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
6879669130
/* If the write-lock is already held, then it was obtained before the
6879769131
** read-transaction was even opened, making this call a no-op.
6879869132
** Return early. */
6879969133
if( pWal->writeLock ){
68800
- assert( !memcmp(&pWal->hdr,(void *)walIndexHdr(pWal),sizeof(WalIndexHdr)) );
69134
+ assert( !memcmp(&pWal->hdr,(void*)pWal->apWiData[0],sizeof(WalIndexHdr)) );
6880169135
return SQLITE_OK;
6880269136
}
6880369137
#endif
6880469138
6880569139
/* Cannot start a write transaction without first holding a read
@@ -83370,11 +83704,11 @@
8337083704
if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
8337183705
/* pMem must be a string, and it cannot be an ephemeral or static string */
8337283706
return;
8337383707
}
8337483708
if( pMem->enc!=SQLITE_UTF8 ) return;
83375
- if( NEVER(pMem->z==0) ) return;
83709
+ assert( pMem->z!=0 );
8337683710
if( pMem->flags & MEM_Dyn ){
8337783711
if( pMem->xDel==sqlite3_free
8337883712
&& sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
8337983713
){
8338083714
pMem->z[pMem->n] = 0;
@@ -85958,12 +86292,12 @@
8595886292
** through all the opcodes and fixes up some details.
8595986293
**
8596086294
** (1) For each jump instruction with a negative P2 value (a label)
8596186295
** resolve the P2 value to an actual address.
8596286296
**
85963
-** (2) Compute the maximum number of arguments used by any SQL function
85964
-** and store that value in *pMaxFuncArgs.
86297
+** (2) Compute the maximum number of arguments used by the xUpdate/xFilter
86298
+** methods of any virtual table and store that value in *pMaxVtabArgs.
8596586299
**
8596686300
** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
8596786301
** indicate what the prepared statement actually does.
8596886302
**
8596986303
** (4) (discontinued)
@@ -85972,12 +86306,12 @@
8597286306
**
8597386307
** This routine will only function correctly if the mkopcodeh.tcl generator
8597486308
** script numbers the opcodes correctly. Changes to this routine must be
8597586309
** coordinated with changes to mkopcodeh.tcl.
8597686310
*/
85977
-static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
85978
- int nMaxArgs = *pMaxFuncArgs;
86311
+static void resolveP2Values(Vdbe *p, int *pMaxVtabArgs){
86312
+ int nMaxVtabArgs = *pMaxVtabArgs;
8597986313
Op *pOp;
8598086314
Parse *pParse = p->pParse;
8598186315
int *aLabel = pParse->aLabel;
8598286316
8598386317
assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
@@ -86018,19 +86352,23 @@
8601886352
assert( pOp->p2>=0 );
8601986353
goto resolve_p2_values_loop_exit;
8602086354
}
8602186355
#ifndef SQLITE_OMIT_VIRTUALTABLE
8602286356
case OP_VUpdate: {
86023
- if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
86357
+ if( pOp->p2>nMaxVtabArgs ) nMaxVtabArgs = pOp->p2;
8602486358
break;
8602586359
}
8602686360
case OP_VFilter: {
8602786361
int n;
86362
+ /* The instruction immediately prior to VFilter will be an
86363
+ ** OP_Integer that sets the "argc" value for the VFilter. See
86364
+ ** the code where OP_VFilter is generated at tag-20250207a. */
8602886365
assert( (pOp - p->aOp) >= 3 );
8602986366
assert( pOp[-1].opcode==OP_Integer );
86367
+ assert( pOp[-1].p2==pOp->p3+1 );
8603086368
n = pOp[-1].p1;
86031
- if( n>nMaxArgs ) nMaxArgs = n;
86369
+ if( n>nMaxVtabArgs ) nMaxVtabArgs = n;
8603286370
/* Fall through into the default case */
8603386371
/* no break */ deliberate_fall_through
8603486372
}
8603586373
#endif
8603686374
default: {
@@ -86067,11 +86405,11 @@
8606786405
if( aLabel ){
8606886406
sqlite3DbNNFreeNN(p->db, pParse->aLabel);
8606986407
pParse->aLabel = 0;
8607086408
}
8607186409
pParse->nLabel = 0;
86072
- *pMaxFuncArgs = nMaxArgs;
86410
+ *pMaxVtabArgs = nMaxVtabArgs;
8607386411
assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
8607486412
}
8607586413
8607686414
#ifdef SQLITE_DEBUG
8607786415
/*
@@ -87745,11 +88083,11 @@
8774588083
){
8774688084
sqlite3 *db; /* The database connection */
8774788085
int nVar; /* Number of parameters */
8774888086
int nMem; /* Number of VM memory registers */
8774988087
int nCursor; /* Number of cursors required */
87750
- int nArg; /* Number of arguments in subprograms */
88088
+ int nArg; /* Max number args to xFilter or xUpdate */
8775188089
int n; /* Loop counter */
8775288090
struct ReusableSpace x; /* Reusable bulk memory */
8775388091
8775488092
assert( p!=0 );
8775588093
assert( p->nOp>0 );
@@ -87817,10 +88155,13 @@
8781788155
p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
8781888156
p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
8781988157
p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
8782088158
}
8782188159
}
88160
+#ifdef SQLITE_DEBUG
88161
+ p->napArg = nArg;
88162
+#endif
8782288163
8782388164
if( db->mallocFailed ){
8782488165
p->nVar = 0;
8782588166
p->nCursor = 0;
8782688167
p->nMem = 0;
@@ -101897,10 +102238,11 @@
101897102238
nArg = (int)pArgc->u.i;
101898102239
iQuery = (int)pQuery->u.i;
101899102240
101900102241
/* Invoke the xFilter method */
101901102242
apArg = p->apArg;
102243
+ assert( nArg<=p->napArg );
101902102244
for(i = 0; i<nArg; i++){
101903102245
apArg[i] = &pArgc[i+1];
101904102246
}
101905102247
rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg);
101906102248
sqlite3VtabImportErrmsg(p, pVtab);
@@ -102107,10 +102449,11 @@
102107102449
assert( pOp->p4type==P4_VTAB );
102108102450
if( ALWAYS(pModule->xUpdate) ){
102109102451
u8 vtabOnConflict = db->vtabOnConflict;
102110102452
apArg = p->apArg;
102111102453
pX = &aMem[pOp->p3];
102454
+ assert( nArg<=p->napArg );
102112102455
for(i=0; i<nArg; i++){
102113102456
assert( memIsValid(pX) );
102114102457
memAboutToChange(p, pX);
102115102458
apArg[i] = pX;
102116102459
pX++;
@@ -102952,16 +103295,12 @@
102952103295
}
102953103296
pBlob->pTab = pTab;
102954103297
pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
102955103298
102956103299
/* Now search pTab for the exact column. */
102957
- for(iCol=0; iCol<pTab->nCol; iCol++) {
102958
- if( sqlite3StrICmp(pTab->aCol[iCol].zCnName, zColumn)==0 ){
102959
- break;
102960
- }
102961
- }
102962
- if( iCol==pTab->nCol ){
103300
+ iCol = sqlite3ColumnIndex(pTab, zColumn);
103301
+ if( iCol<0 ){
102963103302
sqlite3DbFree(db, zErr);
102964103303
zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
102965103304
rc = SQLITE_ERROR;
102966103305
sqlite3BtreeLeaveAll(db);
102967103306
goto blob_open_out;
@@ -107503,11 +107842,10 @@
107503107842
SrcItem *pMatch = 0; /* The matching pSrcList item */
107504107843
NameContext *pTopNC = pNC; /* First namecontext in the list */
107505107844
Schema *pSchema = 0; /* Schema of the expression */
107506107845
int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
107507107846
Table *pTab = 0; /* Table holding the row */
107508
- Column *pCol; /* A column of pTab */
107509107847
ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
107510107848
const char *zCol = pRight->u.zToken;
107511107849
107512107850
assert( pNC ); /* the name context cannot be NULL. */
107513107851
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -107554,11 +107892,10 @@
107554107892
ExprList *pEList;
107555107893
SrcList *pSrcList = pNC->pSrcList;
107556107894
107557107895
if( pSrcList ){
107558107896
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
107559
- u8 hCol;
107560107897
pTab = pItem->pSTab;
107561107898
assert( pTab!=0 && pTab->zName!=0 );
107562107899
assert( pTab->nCol>0 || pParse->nErr );
107563107900
assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem));
107564107901
if( pItem->fg.isNestedFrom ){
@@ -107642,47 +107979,42 @@
107642107979
assert( ExprUseYTab(pExpr) );
107643107980
if( IN_RENAME_OBJECT && pItem->zAlias ){
107644107981
sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
107645107982
}
107646107983
}
107647
- hCol = sqlite3StrIHash(zCol);
107648
- for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
107649
- if( pCol->hName==hCol
107650
- && sqlite3StrICmp(pCol->zCnName, zCol)==0
107651
- ){
107652
- if( cnt>0 ){
107653
- if( pItem->fg.isUsing==0
107654
- || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107655
- ){
107656
- /* Two or more tables have the same column name which is
107657
- ** not joined by USING. This is an error. Signal as much
107658
- ** by clearing pFJMatch and letting cnt go above 1. */
107659
- sqlite3ExprListDelete(db, pFJMatch);
107660
- pFJMatch = 0;
107661
- }else
107662
- if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107663
- /* An INNER or LEFT JOIN. Use the left-most table */
107664
- continue;
107665
- }else
107666
- if( (pItem->fg.jointype & JT_LEFT)==0 ){
107667
- /* A RIGHT JOIN. Use the right-most table */
107668
- cnt = 0;
107669
- sqlite3ExprListDelete(db, pFJMatch);
107670
- pFJMatch = 0;
107671
- }else{
107672
- /* For a FULL JOIN, we must construct a coalesce() func */
107673
- extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
107674
- }
107675
- }
107676
- cnt++;
107677
- pMatch = pItem;
107678
- /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
107679
- pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
107680
- if( pItem->fg.isNestedFrom ){
107681
- sqlite3SrcItemColumnUsed(pItem, j);
107682
- }
107683
- break;
107984
+ j = sqlite3ColumnIndex(pTab, zCol);
107985
+ if( j>=0 ){
107986
+ if( cnt>0 ){
107987
+ if( pItem->fg.isUsing==0
107988
+ || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107989
+ ){
107990
+ /* Two or more tables have the same column name which is
107991
+ ** not joined by USING. This is an error. Signal as much
107992
+ ** by clearing pFJMatch and letting cnt go above 1. */
107993
+ sqlite3ExprListDelete(db, pFJMatch);
107994
+ pFJMatch = 0;
107995
+ }else
107996
+ if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107997
+ /* An INNER or LEFT JOIN. Use the left-most table */
107998
+ continue;
107999
+ }else
108000
+ if( (pItem->fg.jointype & JT_LEFT)==0 ){
108001
+ /* A RIGHT JOIN. Use the right-most table */
108002
+ cnt = 0;
108003
+ sqlite3ExprListDelete(db, pFJMatch);
108004
+ pFJMatch = 0;
108005
+ }else{
108006
+ /* For a FULL JOIN, we must construct a coalesce() func */
108007
+ extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
108008
+ }
108009
+ }
108010
+ cnt++;
108011
+ pMatch = pItem;
108012
+ /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
108013
+ pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
108014
+ if( pItem->fg.isNestedFrom ){
108015
+ sqlite3SrcItemColumnUsed(pItem, j);
107684108016
}
107685108017
}
107686108018
if( 0==cnt && VisibleRowid(pTab) ){
107687108019
/* pTab is a potential ROWID match. Keep track of it and match
107688108020
** the ROWID later if that seems appropriate. (Search for "cntTab"
@@ -107768,26 +108100,21 @@
107768108100
}
107769108101
#endif /* SQLITE_OMIT_UPSERT */
107770108102
107771108103
if( pTab ){
107772108104
int iCol;
107773
- u8 hCol = sqlite3StrIHash(zCol);
107774108105
pSchema = pTab->pSchema;
107775108106
cntTab++;
107776
- for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
107777
- if( pCol->hName==hCol
107778
- && sqlite3StrICmp(pCol->zCnName, zCol)==0
107779
- ){
107780
- if( iCol==pTab->iPKey ){
107781
- iCol = -1;
107782
- }
107783
- break;
107784
- }
107785
- }
107786
- if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
107787
- /* IMP: R-51414-32910 */
107788
- iCol = -1;
108107
+ iCol = sqlite3ColumnIndex(pTab, zCol);
108108
+ if( iCol>=0 ){
108109
+ if( pTab->iPKey==iCol ) iCol = -1;
108110
+ }else{
108111
+ if( sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
108112
+ iCol = -1;
108113
+ }else{
108114
+ iCol = pTab->nCol;
108115
+ }
107789108116
}
107790108117
if( iCol<pTab->nCol ){
107791108118
cnt++;
107792108119
pMatch = 0;
107793108120
#ifndef SQLITE_OMIT_UPSERT
@@ -111379,11 +111706,10 @@
111379111706
pNewExpr->pLeft = pPriorSelectColNew;
111380111707
}
111381111708
}
111382111709
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
111383111710
pItem->fg = pOldItem->fg;
111384
- pItem->fg.done = 0;
111385111711
pItem->u = pOldItem->u;
111386111712
}
111387111713
return pNew;
111388111714
}
111389111715
@@ -112496,17 +112822,11 @@
112496112822
SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab){
112497112823
const char *azOpt[] = {"_ROWID_", "ROWID", "OID"};
112498112824
int ii;
112499112825
assert( VisibleRowid(pTab) );
112500112826
for(ii=0; ii<ArraySize(azOpt); ii++){
112501
- int iCol;
112502
- for(iCol=0; iCol<pTab->nCol; iCol++){
112503
- if( sqlite3_stricmp(azOpt[ii], pTab->aCol[iCol].zCnName)==0 ) break;
112504
- }
112505
- if( iCol==pTab->nCol ){
112506
- return azOpt[ii];
112507
- }
112827
+ if( sqlite3ColumnIndex(pTab, azOpt[ii])<0 ) return azOpt[ii];
112508112828
}
112509112829
return 0;
112510112830
}
112511112831
112512112832
/*
@@ -117551,14 +117871,12 @@
117551117871
117552117872
/* Make sure the old name really is a column name in the table to be
117553117873
** altered. Set iCol to be the index of the column being renamed */
117554117874
zOld = sqlite3NameFromToken(db, pOld);
117555117875
if( !zOld ) goto exit_rename_column;
117556
- for(iCol=0; iCol<pTab->nCol; iCol++){
117557
- if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
117558
- }
117559
- if( iCol==pTab->nCol ){
117876
+ iCol = sqlite3ColumnIndex(pTab, zOld);
117877
+ if( iCol<0 ){
117560117878
sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
117561117879
goto exit_rename_column;
117562117880
}
117563117881
117564117882
/* Ensure the schema contains no double-quoted strings */
@@ -119453,11 +119771,12 @@
119453119771
** of the new table in register pParse->regRoot. This is important
119454119772
** because the OpenWrite opcode below will be needing it. */
119455119773
sqlite3NestedParse(pParse,
119456119774
"CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
119457119775
);
119458
- aRoot[i] = (u32)pParse->regRoot;
119776
+ assert( pParse->isCreate || pParse->nErr );
119777
+ aRoot[i] = (u32)pParse->u1.cr.regRoot;
119459119778
aCreateTbl[i] = OPFLAG_P2ISREG;
119460119779
}
119461119780
}else{
119462119781
/* The table already exists. If zWhere is not NULL, delete all entries
119463119782
** associated with the table zWhere. If zWhere is NULL, delete the
@@ -121489,10 +121808,17 @@
121489121808
*/
121490121809
if( rc==SQLITE_OK ){
121491121810
sqlite3BtreeEnterAll(db);
121492121811
db->init.iDb = 0;
121493121812
db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
121813
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
121814
+ if( db->setlkFlags & SQLITE_SETLK_BLOCK_ON_CONNECT ){
121815
+ int val = 1;
121816
+ sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pNew->pBt));
121817
+ sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, &val);
121818
+ }
121819
+#endif
121494121820
if( !REOPEN_AS_MEMDB(db) ){
121495121821
rc = sqlite3Init(db, &zErrDyn);
121496121822
}
121497121823
sqlite3BtreeLeaveAll(db);
121498121824
assert( zErrDyn==0 || rc!=SQLITE_OK );
@@ -122311,14 +122637,16 @@
122311122637
}
122312122638
assert( !pParse->isMultiWrite
122313122639
|| sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
122314122640
if( v ){
122315122641
if( pParse->bReturning ){
122316
- Returning *pReturning = pParse->u1.pReturning;
122642
+ Returning *pReturning;
122317122643
int addrRewind;
122318122644
int reg;
122319122645
122646
+ assert( !pParse->isCreate );
122647
+ pReturning = pParse->u1.d.pReturning;
122320122648
if( pReturning->nRetCol ){
122321122649
sqlite3VdbeAddOp0(v, OP_FkCheck);
122322122650
addrRewind =
122323122651
sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
122324122652
VdbeCoverage(v);
@@ -122390,11 +122718,13 @@
122390122718
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
122391122719
}
122392122720
}
122393122721
122394122722
if( pParse->bReturning ){
122395
- Returning *pRet = pParse->u1.pReturning;
122723
+ Returning *pRet;
122724
+ assert( !pParse->isCreate );
122725
+ pRet = pParse->u1.d.pReturning;
122396122726
if( pRet->nRetCol ){
122397122727
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
122398122728
}
122399122729
}
122400122730
@@ -123462,12 +123792,13 @@
123462123792
#endif
123463123793
123464123794
/* If the file format and encoding in the database have not been set,
123465123795
** set them now.
123466123796
*/
123467
- reg1 = pParse->regRowid = ++pParse->nMem;
123468
- reg2 = pParse->regRoot = ++pParse->nMem;
123797
+ assert( pParse->isCreate );
123798
+ reg1 = pParse->u1.cr.regRowid = ++pParse->nMem;
123799
+ reg2 = pParse->u1.cr.regRoot = ++pParse->nMem;
123469123800
reg3 = ++pParse->nMem;
123470123801
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
123471123802
sqlite3VdbeUsesBtree(v, iDb);
123472123803
addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
123473123804
fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
@@ -123478,12 +123809,12 @@
123478123809
123479123810
/* This just creates a place-holder record in the sqlite_schema table.
123480123811
** The record created does not contain anything yet. It will be replaced
123481123812
** by the real entry in code generated at sqlite3EndTable().
123482123813
**
123483
- ** The rowid for the new entry is left in register pParse->regRowid.
123484
- ** The root page number of the new table is left in reg pParse->regRoot.
123814
+ ** The rowid for the new entry is left in register pParse->u1.cr.regRowid.
123815
+ ** The root page of the new table is left in reg pParse->u1.cr.regRoot.
123485123816
** The rowid and root page number values are needed by the code that
123486123817
** sqlite3EndTable will generate.
123487123818
*/
123488123819
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
123489123820
if( isView || isVirtual ){
@@ -123490,11 +123821,11 @@
123490123821
sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
123491123822
}else
123492123823
#endif
123493123824
{
123494123825
assert( !pParse->bReturning );
123495
- pParse->u1.addrCrTab =
123826
+ pParse->u1.cr.addrCrTab =
123496123827
sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
123497123828
}
123498123829
sqlite3OpenSchemaTable(pParse, iDb);
123499123830
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
123500123831
sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
@@ -123568,11 +123899,12 @@
123568123899
pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
123569123900
if( pRet==0 ){
123570123901
sqlite3ExprListDelete(db, pList);
123571123902
return;
123572123903
}
123573
- pParse->u1.pReturning = pRet;
123904
+ assert( !pParse->isCreate );
123905
+ pParse->u1.d.pReturning = pRet;
123574123906
pRet->pParse = pParse;
123575123907
pRet->pReturnEL = pList;
123576123908
sqlite3ParserAddCleanup(pParse, sqlite3DeleteReturning, pRet);
123577123909
testcase( pParse->earlyCleanup );
123578123910
if( db->mallocFailed ) return;
@@ -123610,11 +123942,10 @@
123610123942
int i;
123611123943
char *z;
123612123944
char *zType;
123613123945
Column *pCol;
123614123946
sqlite3 *db = pParse->db;
123615
- u8 hName;
123616123947
Column *aNew;
123617123948
u8 eType = COLTYPE_CUSTOM;
123618123949
u8 szEst = 1;
123619123950
char affinity = SQLITE_AFF_BLOB;
123620123951
@@ -123664,17 +123995,14 @@
123664123995
if( z==0 ) return;
123665123996
if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
123666123997
memcpy(z, sName.z, sName.n);
123667123998
z[sName.n] = 0;
123668123999
sqlite3Dequote(z);
123669
- hName = sqlite3StrIHash(z);
123670
- for(i=0; i<p->nCol; i++){
123671
- if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zCnName)==0 ){
123672
- sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
123673
- sqlite3DbFree(db, z);
123674
- return;
123675
- }
124000
+ if( p->nCol && sqlite3ColumnIndex(p, z)>=0 ){
124001
+ sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
124002
+ sqlite3DbFree(db, z);
124003
+ return;
123676124004
}
123677124005
aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
123678124006
if( aNew==0 ){
123679124007
sqlite3DbFree(db, z);
123680124008
return;
@@ -123681,11 +124009,11 @@
123681124009
}
123682124010
p->aCol = aNew;
123683124011
pCol = &p->aCol[p->nCol];
123684124012
memset(pCol, 0, sizeof(p->aCol[0]));
123685124013
pCol->zCnName = z;
123686
- pCol->hName = hName;
124014
+ pCol->hName = sqlite3StrIHash(z);
123687124015
sqlite3ColumnPropertiesFromName(p, pCol);
123688124016
123689124017
if( sType.n==0 ){
123690124018
/* If there is no type specified, columns have the default affinity
123691124019
** 'BLOB' with a default size of 4 bytes. */
@@ -123705,13 +124033,18 @@
123705124033
zType[sType.n] = 0;
123706124034
sqlite3Dequote(zType);
123707124035
pCol->affinity = sqlite3AffinityType(zType, pCol);
123708124036
pCol->colFlags |= COLFLAG_HASTYPE;
123709124037
}
124038
+ if( p->nCol<=0xff ){
124039
+ u8 h = pCol->hName % sizeof(p->aHx);
124040
+ p->aHx[h] = p->nCol;
124041
+ }
123710124042
p->nCol++;
123711124043
p->nNVCol++;
123712
- pParse->constraintName.n = 0;
124044
+ assert( pParse->isCreate );
124045
+ pParse->u1.cr.constraintName.n = 0;
123713124046
}
123714124047
123715124048
/*
123716124049
** This routine is called by the parser while in the middle of
123717124050
** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
@@ -123971,19 +124304,15 @@
123971124304
for(i=0; i<nTerm; i++){
123972124305
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
123973124306
assert( pCExpr!=0 );
123974124307
sqlite3StringToId(pCExpr);
123975124308
if( pCExpr->op==TK_ID ){
123976
- const char *zCName;
123977124309
assert( !ExprHasProperty(pCExpr, EP_IntValue) );
123978
- zCName = pCExpr->u.zToken;
123979
- for(iCol=0; iCol<pTab->nCol; iCol++){
123980
- if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
123981
- pCol = &pTab->aCol[iCol];
123982
- makeColumnPartOfPrimaryKey(pParse, pCol);
123983
- break;
123984
- }
124310
+ iCol = sqlite3ColumnIndex(pTab, pCExpr->u.zToken);
124311
+ if( iCol>=0 ){
124312
+ pCol = &pTab->aCol[iCol];
124313
+ makeColumnPartOfPrimaryKey(pParse, pCol);
123985124314
}
123986124315
}
123987124316
}
123988124317
}
123989124318
if( nTerm==1
@@ -124031,12 +124360,14 @@
124031124360
sqlite3 *db = pParse->db;
124032124361
if( pTab && !IN_DECLARE_VTAB
124033124362
&& !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
124034124363
){
124035124364
pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr);
124036
- if( pParse->constraintName.n ){
124037
- sqlite3ExprListSetName(pParse, pTab->pCheck, &pParse->constraintName, 1);
124365
+ assert( pParse->isCreate );
124366
+ if( pParse->u1.cr.constraintName.n ){
124367
+ sqlite3ExprListSetName(pParse, pTab->pCheck,
124368
+ &pParse->u1.cr.constraintName, 1);
124038124369
}else{
124039124370
Token t;
124040124371
for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
124041124372
while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; }
124042124373
t.z = zStart;
@@ -124482,13 +124813,13 @@
124482124813
124483124814
/* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
124484124815
** into BTREE_BLOBKEY.
124485124816
*/
124486124817
assert( !pParse->bReturning );
124487
- if( pParse->u1.addrCrTab ){
124818
+ if( pParse->u1.cr.addrCrTab ){
124488124819
assert( v );
124489
- sqlite3VdbeChangeP3(v, pParse->u1.addrCrTab, BTREE_BLOBKEY);
124820
+ sqlite3VdbeChangeP3(v, pParse->u1.cr.addrCrTab, BTREE_BLOBKEY);
124490124821
}
124491124822
124492124823
/* Locate the PRIMARY KEY index. Or, if this table was originally
124493124824
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
124494124825
*/
@@ -124924,11 +125255,11 @@
124924125255
#endif
124925125256
}
124926125257
124927125258
/* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
124928125259
** statement to populate the new table. The root-page number for the
124929
- ** new table is in register pParse->regRoot.
125260
+ ** new table is in register pParse->u1.cr.regRoot.
124930125261
**
124931125262
** Once the SELECT has been coded by sqlite3Select(), it is in a
124932125263
** suitable state to query for the column names and types to be used
124933125264
** by the new table.
124934125265
**
@@ -124955,11 +125286,12 @@
124955125286
iCsr = pParse->nTab++;
124956125287
regYield = ++pParse->nMem;
124957125288
regRec = ++pParse->nMem;
124958125289
regRowid = ++pParse->nMem;
124959125290
sqlite3MayAbort(pParse);
124960
- sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->regRoot, iDb);
125291
+ assert( pParse->isCreate );
125292
+ sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->u1.cr.regRoot, iDb);
124961125293
sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
124962125294
addrTop = sqlite3VdbeCurrentAddr(v) + 1;
124963125295
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
124964125296
if( pParse->nErr ) return;
124965125297
pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
@@ -125000,21 +125332,22 @@
125000125332
125001125333
/* A slot for the record has already been allocated in the
125002125334
** schema table. We just need to update that slot with all
125003125335
** the information we've collected.
125004125336
*/
125337
+ assert( pParse->isCreate );
125005125338
sqlite3NestedParse(pParse,
125006125339
"UPDATE %Q." LEGACY_SCHEMA_TABLE
125007125340
" SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
125008125341
" WHERE rowid=#%d",
125009125342
db->aDb[iDb].zDbSName,
125010125343
zType,
125011125344
p->zName,
125012125345
p->zName,
125013
- pParse->regRoot,
125346
+ pParse->u1.cr.regRoot,
125014125347
zStmt,
125015
- pParse->regRowid
125348
+ pParse->u1.cr.regRowid
125016125349
);
125017125350
sqlite3DbFree(db, zStmt);
125018125351
sqlite3ChangeCookie(pParse, iDb);
125019125352
125020125353
#ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -129850,15 +130183,10 @@
129850130183
int len;
129851130184
int p0type;
129852130185
i64 p1, p2;
129853130186
129854130187
assert( argc==3 || argc==2 );
129855
- if( sqlite3_value_type(argv[1])==SQLITE_NULL
129856
- || (argc==3 && sqlite3_value_type(argv[2])==SQLITE_NULL)
129857
- ){
129858
- return;
129859
- }
129860130188
p0type = sqlite3_value_type(argv[0]);
129861130189
p1 = sqlite3_value_int64(argv[1]);
129862130190
if( p0type==SQLITE_BLOB ){
129863130191
len = sqlite3_value_bytes(argv[0]);
129864130192
z = sqlite3_value_blob(argv[0]);
@@ -129872,23 +130200,27 @@
129872130200
for(z2=z; *z2; len++){
129873130201
SQLITE_SKIP_UTF8(z2);
129874130202
}
129875130203
}
129876130204
}
129877
-#ifdef SQLITE_SUBSTR_COMPATIBILITY
129878
- /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
129879
- ** as substr(X,1,N) - it returns the first N characters of X. This
129880
- ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
129881
- ** from 2009-02-02 for compatibility of applications that exploited the
129882
- ** old buggy behavior. */
129883
- if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
129884
-#endif
129885130205
if( argc==3 ){
129886130206
p2 = sqlite3_value_int64(argv[2]);
130207
+ if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
129887130208
}else{
129888130209
p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
129889130210
}
130211
+ if( p1==0 ){
130212
+#ifdef SQLITE_SUBSTR_COMPATIBILITY
130213
+ /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
130214
+ ** as substr(X,1,N) - it returns the first N characters of X. This
130215
+ ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
130216
+ ** from 2009-02-02 for compatibility of applications that exploited the
130217
+ ** old buggy behavior. */
130218
+ p1 = 1; /* <rdar://problem/6778339> */
130219
+#endif
130220
+ if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
130221
+ }
129890130222
if( p1<0 ){
129891130223
p1 += len;
129892130224
if( p1<0 ){
129893130225
if( p2<0 ){
129894130226
p2 = 0;
@@ -134900,32 +135232,26 @@
134900135232
bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
134901135233
if( pColumn ){
134902135234
aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int));
134903135235
if( aTabColMap==0 ) goto insert_cleanup;
134904135236
for(i=0; i<pColumn->nId; i++){
134905
- const char *zCName = pColumn->a[i].zName;
134906
- u8 hName = sqlite3StrIHash(zCName);
134907
- for(j=0; j<pTab->nCol; j++){
134908
- if( pTab->aCol[j].hName!=hName ) continue;
134909
- if( sqlite3StrICmp(zCName, pTab->aCol[j].zCnName)==0 ){
134910
- if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
134911
- if( i!=j ) bIdListInOrder = 0;
134912
- if( j==pTab->iPKey ){
134913
- ipkColumn = i; assert( !withoutRowid );
134914
- }
135237
+ j = sqlite3ColumnIndex(pTab, pColumn->a[i].zName);
135238
+ if( j>=0 ){
135239
+ if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
135240
+ if( i!=j ) bIdListInOrder = 0;
135241
+ if( j==pTab->iPKey ){
135242
+ ipkColumn = i; assert( !withoutRowid );
135243
+ }
134915135244
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
134916
- if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
134917
- sqlite3ErrorMsg(pParse,
134918
- "cannot INSERT into generated column \"%s\"",
134919
- pTab->aCol[j].zCnName);
134920
- goto insert_cleanup;
134921
- }
135245
+ if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
135246
+ sqlite3ErrorMsg(pParse,
135247
+ "cannot INSERT into generated column \"%s\"",
135248
+ pTab->aCol[j].zCnName);
135249
+ goto insert_cleanup;
135250
+ }
134922135251
#endif
134923
- break;
134924
- }
134925
- }
134926
- if( j>=pTab->nCol ){
135252
+ }else{
134927135253
if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
134928135254
ipkColumn = i;
134929135255
bIdListInOrder = 0;
134930135256
}else{
134931135257
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
@@ -135219,11 +135545,11 @@
135219135545
sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
135220135546
}
135221135547
continue;
135222135548
}else if( pColumn==0 ){
135223135549
/* Hidden columns that are not explicitly named in the INSERT
135224
- ** get there default value */
135550
+ ** get their default value */
135225135551
sqlite3ExprCodeFactorable(pParse,
135226135552
sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135227135553
iRegStore);
135228135554
continue;
135229135555
}
@@ -144166,14 +144492,37 @@
144166144492
** Return the index of a column in a table. Return -1 if the column
144167144493
** is not contained in the table.
144168144494
*/
144169144495
SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
144170144496
int i;
144171
- u8 h = sqlite3StrIHash(zCol);
144172
- Column *pCol;
144173
- for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
144174
- if( pCol->hName==h && sqlite3StrICmp(pCol->zCnName, zCol)==0 ) return i;
144497
+ u8 h;
144498
+ const Column *aCol;
144499
+ int nCol;
144500
+
144501
+ h = sqlite3StrIHash(zCol);
144502
+ aCol = pTab->aCol;
144503
+ nCol = pTab->nCol;
144504
+
144505
+ /* See if the aHx gives us a lucky match */
144506
+ i = pTab->aHx[h % sizeof(pTab->aHx)];
144507
+ assert( i<nCol );
144508
+ if( aCol[i].hName==h
144509
+ && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144510
+ ){
144511
+ return i;
144512
+ }
144513
+
144514
+ /* No lucky match from the hash table. Do a full search. */
144515
+ i = 0;
144516
+ while( 1 /*exit-by-break*/ ){
144517
+ if( aCol[i].hName==h
144518
+ && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144519
+ ){
144520
+ return i;
144521
+ }
144522
+ i++;
144523
+ if( i>=nCol ) break;
144175144524
}
144176144525
return -1;
144177144526
}
144178144527
144179144528
/*
@@ -152891,11 +153240,12 @@
152891153240
}else if( pTrig->op==TK_RETURNING ){
152892153241
#ifndef SQLITE_OMIT_VIRTUALTABLE
152893153242
assert( pParse->db->pVtabCtx==0 );
152894153243
#endif
152895153244
assert( pParse->bReturning );
152896
- assert( &(pParse->u1.pReturning->retTrig) == pTrig );
153245
+ assert( !pParse->isCreate );
153246
+ assert( &(pParse->u1.d.pReturning->retTrig) == pTrig );
152897153247
pTrig->table = pTab->zName;
152898153248
pTrig->pTabSchema = pTab->pSchema;
152899153249
pTrig->pNext = pList;
152900153250
pList = pTrig;
152901153251
}
@@ -153868,11 +154218,12 @@
153868154218
/* This RETURNING trigger must be for a different statement as
153869154219
** this statement lacks a RETURNING clause. */
153870154220
return;
153871154221
}
153872154222
assert( db->pParse==pParse );
153873
- pReturning = pParse->u1.pReturning;
154223
+ assert( !pParse->isCreate );
154224
+ pReturning = pParse->u1.d.pReturning;
153874154225
if( pTrigger != &(pReturning->retTrig) ){
153875154226
/* This RETURNING trigger is for a different statement */
153876154227
return;
153877154228
}
153878154229
memset(&sSelect, 0, sizeof(sSelect));
@@ -154098,10 +154449,12 @@
154098154449
sSubParse.pToplevel = pTop;
154099154450
sSubParse.zAuthContext = pTrigger->zName;
154100154451
sSubParse.eTriggerOp = pTrigger->op;
154101154452
sSubParse.nQueryLoop = pParse->nQueryLoop;
154102154453
sSubParse.prepFlags = pParse->prepFlags;
154454
+ sSubParse.oldmask = 0;
154455
+ sSubParse.newmask = 0;
154103154456
154104154457
v = sqlite3GetVdbe(&sSubParse);
154105154458
if( v ){
154106154459
VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
154107154460
pTrigger->zName, onErrorText(orconf),
@@ -154852,42 +155205,36 @@
154852155205
** column to be updated, make sure we have authorization to change
154853155206
** that column.
154854155207
*/
154855155208
chngRowid = chngPk = 0;
154856155209
for(i=0; i<pChanges->nExpr; i++){
154857
- u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName);
154858155210
/* If this is an UPDATE with a FROM clause, do not resolve expressions
154859155211
** here. The call to sqlite3Select() below will do that. */
154860155212
if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
154861155213
goto update_cleanup;
154862155214
}
154863
- for(j=0; j<pTab->nCol; j++){
154864
- if( pTab->aCol[j].hName==hCol
154865
- && sqlite3StrICmp(pTab->aCol[j].zCnName, pChanges->a[i].zEName)==0
154866
- ){
154867
- if( j==pTab->iPKey ){
154868
- chngRowid = 1;
154869
- pRowidExpr = pChanges->a[i].pExpr;
154870
- iRowidExpr = i;
154871
- }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
154872
- chngPk = 1;
154873
- }
155215
+ j = sqlite3ColumnIndex(pTab, pChanges->a[i].zEName);
155216
+ if( j>=0 ){
155217
+ if( j==pTab->iPKey ){
155218
+ chngRowid = 1;
155219
+ pRowidExpr = pChanges->a[i].pExpr;
155220
+ iRowidExpr = i;
155221
+ }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
155222
+ chngPk = 1;
155223
+ }
154874155224
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
154875
- else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
154876
- testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
154877
- testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
154878
- sqlite3ErrorMsg(pParse,
154879
- "cannot UPDATE generated column \"%s\"",
154880
- pTab->aCol[j].zCnName);
154881
- goto update_cleanup;
154882
- }
155225
+ else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
155226
+ testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
155227
+ testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
155228
+ sqlite3ErrorMsg(pParse,
155229
+ "cannot UPDATE generated column \"%s\"",
155230
+ pTab->aCol[j].zCnName);
155231
+ goto update_cleanup;
155232
+ }
154883155233
#endif
154884
- aXRef[j] = i;
154885
- break;
154886
- }
154887
- }
154888
- if( j>=pTab->nCol ){
155234
+ aXRef[j] = i;
155235
+ }else{
154889155236
if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
154890155237
j = -1;
154891155238
chngRowid = 1;
154892155239
pRowidExpr = pChanges->a[i].pExpr;
154893155240
iRowidExpr = i;
@@ -156990,24 +157337,25 @@
156990157337
156991157338
/* A slot for the record has already been allocated in the
156992157339
** schema table. We just need to update that slot with all
156993157340
** the information we've collected.
156994157341
**
156995
- ** The VM register number pParse->regRowid holds the rowid of an
157342
+ ** The VM register number pParse->u1.cr.regRowid holds the rowid of an
156996157343
** entry in the sqlite_schema table that was created for this vtab
156997157344
** by sqlite3StartTable().
156998157345
*/
156999157346
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
157347
+ assert( pParse->isCreate );
157000157348
sqlite3NestedParse(pParse,
157001157349
"UPDATE %Q." LEGACY_SCHEMA_TABLE " "
157002157350
"SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
157003157351
"WHERE rowid=#%d",
157004157352
db->aDb[iDb].zDbSName,
157005157353
pTab->zName,
157006157354
pTab->zName,
157007157355
zStmt,
157008
- pParse->regRowid
157356
+ pParse->u1.cr.regRowid
157009157357
);
157010157358
v = sqlite3GetVdbe(pParse);
157011157359
sqlite3ChangeCookie(pParse, iDb);
157012157360
157013157361
sqlite3VdbeAddOp0(v, OP_Expire);
@@ -160161,10 +160509,13 @@
160161160509
}
160162160510
}
160163160511
}
160164160512
sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
160165160513
sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
160514
+ /* The instruction immediately prior to OP_VFilter must be an OP_Integer
160515
+ ** that sets the "argc" value for xVFilter. This is necessary for
160516
+ ** resolveP2() to work correctly. See tag-20250207a. */
160166160517
sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
160167160518
pLoop->u.vtab.idxStr,
160168160519
pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
160169160520
VdbeCoverage(v);
160170160521
pLoop->u.vtab.needFree = 0;
@@ -174215,10 +174566,15 @@
174215174566
** to the original parse.y sources.
174216174567
*/
174217174568
174218174569
/* #include "sqliteInt.h" */
174219174570
174571
+/*
174572
+** Verify that the pParse->isCreate field is set
174573
+*/
174574
+#define ASSERT_IS_CREATE assert(pParse->isCreate)
174575
+
174220174576
/*
174221174577
** Disable all error recovery processing in the parser push-down
174222174578
** automaton.
174223174579
*/
174224174580
#define YYNOERRORRECOVERY 1
@@ -174278,10 +174634,14 @@
174278174634
** shared across database connections.
174279174635
*/
174280174636
static void disableLookaside(Parse *pParse){
174281174637
sqlite3 *db = pParse->db;
174282174638
pParse->disableLookaside++;
174639
+#ifdef SQLITE_DEBUG
174640
+ pParse->isCreate = 1;
174641
+#endif
174642
+ memset(&pParse->u1.cr, 0, sizeof(pParse->u1.cr));
174283174643
DisableLookaside;
174284174644
}
174285174645
174286174646
#if !defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) \
174287174647
&& defined(SQLITE_UDL_CAPABLE_PARSER)
@@ -177914,11 +178274,13 @@
177914178274
{
177915178275
sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[-2].minor.yy502);
177916178276
}
177917178277
break;
177918178278
case 14: /* createkw ::= CREATE */
177919
-{disableLookaside(pParse);}
178279
+{
178280
+ disableLookaside(pParse);
178281
+}
177920178282
break;
177921178283
case 15: /* ifnotexists ::= */
177922178284
case 18: /* temp ::= */ yytestcase(yyruleno==18);
177923178285
case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
177924178286
case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
@@ -178006,11 +178368,11 @@
178006178368
yymsp[1].minor.yy0 = yyLookaheadToken;
178007178369
}
178008178370
break;
178009178371
case 32: /* ccons ::= CONSTRAINT nm */
178010178372
case 67: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==67);
178011
-{pParse->constraintName = yymsp[0].minor.yy0;}
178373
+{ASSERT_IS_CREATE; pParse->u1.cr.constraintName = yymsp[0].minor.yy0;}
178012178374
break;
178013178375
case 33: /* ccons ::= DEFAULT scantok term */
178014178376
{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);}
178015178377
break;
178016178378
case 34: /* ccons ::= DEFAULT LP expr RP */
@@ -178116,11 +178478,11 @@
178116178478
break;
178117178479
case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
178118178480
{yymsp[-1].minor.yy502 = 0;}
178119178481
break;
178120178482
case 66: /* tconscomma ::= COMMA */
178121
-{pParse->constraintName.n = 0;}
178483
+{ASSERT_IS_CREATE; pParse->u1.cr.constraintName.n = 0;}
178122178484
break;
178123178485
case 68: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
178124178486
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);}
178125178487
break;
178126178488
case 69: /* tcons ::= UNIQUE LP sortlist RP onconf */
@@ -179009,10 +179371,14 @@
179009179371
break;
179010179372
case 261: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
179011179373
{
179012179374
sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy502, yymsp[-4].minor.yy28.a, yymsp[-4].minor.yy28.b, yymsp[-2].minor.yy563, yymsp[0].minor.yy590, yymsp[-10].minor.yy502, yymsp[-8].minor.yy502);
179013179375
yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
179376
+#ifdef SQLITE_DEBUG
179377
+ assert( pParse->isCreate ); /* Set by createkw reduce action */
179378
+ pParse->isCreate = 0; /* But, should not be set for CREATE TRIGGER */
179379
+#endif
179014179380
}
179015179381
break;
179016179382
case 262: /* trigger_time ::= BEFORE|AFTER */
179017179383
{ yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ }
179018179384
break;
@@ -183305,10 +183671,13 @@
183305183671
sqlite3_mutex_enter(db->mutex);
183306183672
db->busyHandler.xBusyHandler = xBusy;
183307183673
db->busyHandler.pBusyArg = pArg;
183308183674
db->busyHandler.nBusy = 0;
183309183675
db->busyTimeout = 0;
183676
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183677
+ db->setlkTimeout = 0;
183678
+#endif
183310183679
sqlite3_mutex_leave(db->mutex);
183311183680
return SQLITE_OK;
183312183681
}
183313183682
183314183683
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -183354,15 +183723,46 @@
183354183723
#endif
183355183724
if( ms>0 ){
183356183725
sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
183357183726
(void*)db);
183358183727
db->busyTimeout = ms;
183728
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183729
+ db->setlkTimeout = ms;
183730
+#endif
183359183731
}else{
183360183732
sqlite3_busy_handler(db, 0, 0);
183361183733
}
183362183734
return SQLITE_OK;
183363183735
}
183736
+
183737
+/*
183738
+** Set the setlk timeout value.
183739
+*/
183740
+SQLITE_API int sqlite3_setlk_timeout(sqlite3 *db, int ms, int flags){
183741
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183742
+ int iDb;
183743
+ int bBOC = ((flags & SQLITE_SETLK_BLOCK_ON_CONNECT) ? 1 : 0);
183744
+#endif
183745
+#ifdef SQLITE_ENABLE_API_ARMOR
183746
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
183747
+#endif
183748
+ if( ms<-1 ) return SQLITE_RANGE;
183749
+#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183750
+ db->setlkTimeout = ms;
183751
+ db->setlkFlags = flags;
183752
+ sqlite3BtreeEnterAll(db);
183753
+ for(iDb=0; iDb<db->nDb; iDb++){
183754
+ Btree *pBt = db->aDb[iDb].pBt;
183755
+ if( pBt ){
183756
+ sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
183757
+ sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
183758
+ }
183759
+ }
183760
+ sqlite3BtreeLeaveAll(db);
183761
+#endif
183762
+ return SQLITE_OK;
183763
+}
183364183764
183365183765
/*
183366183766
** Cause any pending operation to stop at its earliest opportunity.
183367183767
*/
183368183768
SQLITE_API void sqlite3_interrupt(sqlite3 *db){
@@ -185479,17 +185879,14 @@
185479185879
185480185880
/* Find the column for which info is requested */
185481185881
if( zColumnName==0 ){
185482185882
/* Query for existence of table only */
185483185883
}else{
185484
- for(iCol=0; iCol<pTab->nCol; iCol++){
185884
+ iCol = sqlite3ColumnIndex(pTab, zColumnName);
185885
+ if( iCol>=0 ){
185485185886
pCol = &pTab->aCol[iCol];
185486
- if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
185487
- break;
185488
- }
185489
- }
185490
- if( iCol==pTab->nCol ){
185887
+ }else{
185491185888
if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
185492185889
iCol = pTab->iPKey;
185493185890
pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
185494185891
}else{
185495185892
pTab = 0;
@@ -208697,14 +209094,11 @@
208697209094
*/
208698209095
static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){
208699209096
u8 x;
208700209097
u32 sz;
208701209098
u32 n;
208702
- if( NEVER(i>pParse->nBlob) ){
208703
- *pSz = 0;
208704
- return 0;
208705
- }
209099
+ assert( i<=pParse->nBlob );
208706209100
x = pParse->aBlob[i]>>4;
208707209101
if( x<=11 ){
208708209102
sz = x;
208709209103
n = 1;
208710209104
}else if( x==12 ){
@@ -208744,12 +209138,12 @@
208744209138
n = 9;
208745209139
}
208746209140
if( (i64)i+sz+n > pParse->nBlob
208747209141
&& (i64)i+sz+n > pParse->nBlob-pParse->delta
208748209142
){
208749
- sz = 0;
208750
- n = 0;
209143
+ *pSz = 0;
209144
+ return 0;
208751209145
}
208752209146
*pSz = sz;
208753209147
return n;
208754209148
}
208755209149
@@ -208842,13 +209236,16 @@
208842209236
}
208843209237
break;
208844209238
}
208845209239
case JSONB_TEXT:
208846209240
case JSONB_TEXTJ: {
208847
- jsonAppendChar(pOut, '"');
208848
- jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz);
208849
- jsonAppendChar(pOut, '"');
209241
+ if( pOut->nUsed+sz+2<=pOut->nAlloc || jsonStringGrow(pOut, sz+2)==0 ){
209242
+ pOut->zBuf[pOut->nUsed] = '"';
209243
+ memcpy(pOut->zBuf+pOut->nUsed+1,(const char*)&pParse->aBlob[i+n],sz);
209244
+ pOut->zBuf[pOut->nUsed+sz+1] = '"';
209245
+ pOut->nUsed += sz+2;
209246
+ }
208850209247
break;
208851209248
}
208852209249
case JSONB_TEXT5: {
208853209250
const char *zIn;
208854209251
u32 k;
@@ -255870,11 +256267,11 @@
255870256267
int nArg, /* Number of args */
255871256268
sqlite3_value **apUnused /* Function arguments */
255872256269
){
255873256270
assert( nArg==0 );
255874256271
UNUSED_PARAM2(nArg, apUnused);
255875
- sqlite3_result_text(pCtx, "fts5: 2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde", -1, SQLITE_TRANSIENT);
256272
+ sqlite3_result_text(pCtx, "fts5: 2025-02-11 17:10:46 e5ec5bb9f4dc3e02db7ab0e49686f47617af75d3f7d4ab23288a1aea4a693e59", -1, SQLITE_TRANSIENT);
255876256273
}
255877256274
255878256275
/*
255879256276
** Implementation of fts5_locale(LOCALE, TEXT) function.
255880256277
**
255881256278
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.49.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 4a7dd425dc2a0e5082a9049c9b4a9d4f199a with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.49.0"
469 #define SQLITE_VERSION_NUMBER 3049000
470 #define SQLITE_SOURCE_ID "2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -1480,10 +1480,15 @@
1480 ** obtain a file lock using the xLock or xShmLock methods of the VFS.
1481 ** The parameter is a pointer to a 32-bit signed integer that contains
1482 ** the value that M is to be set to. Before returning, the 32-bit signed
1483 ** integer is overwritten with the previous value of M.
1484 **
 
 
 
 
 
1485 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1486 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1487 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
1488 ** The "data version" for the pager is written into the pointer. The
1489 ** "data version" changes whenever any change occurs to the corresponding
@@ -1576,10 +1581,11 @@
1576 #define SQLITE_FCNTL_CKPT_START 39
1577 #define SQLITE_FCNTL_EXTERNAL_READER 40
1578 #define SQLITE_FCNTL_CKSM_FILE 41
1579 #define SQLITE_FCNTL_RESET_CACHE 42
1580 #define SQLITE_FCNTL_NULL_IO 43
 
1581
1582 /* deprecated names */
1583 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1584 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1585 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3310,10 +3316,48 @@
3310 **
3311 ** See also: [PRAGMA busy_timeout]
3312 */
3313 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
3314
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3315 /*
3316 ** CAPI3REF: Convenience Routines For Running Queries
3317 ** METHOD: sqlite3
3318 **
3319 ** This is a legacy interface that is preserved for backwards compatibility.
@@ -14747,10 +14791,11 @@
14747 */
14748 struct HashElem {
14749 HashElem *next, *prev; /* Next and previous elements in the table */
14750 void *data; /* Data associated with this element */
14751 const char *pKey; /* Key associated with this element */
 
14752 };
14753
14754 /*
14755 ** Access routines. To delete, insert a NULL pointer.
14756 */
@@ -15184,10 +15229,15 @@
15184 typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
15185 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
15186 typedef INT16_TYPE i16; /* 2-byte signed integer */
15187 typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
15188 typedef INT8_TYPE i8; /* 1-byte signed integer */
 
 
 
 
 
15189
15190 /*
15191 ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
15192 ** that can be stored in a u32 without loss of data. The value
15193 ** is 0x00000000ffffffff. But because of quirks of some compilers, we
@@ -18053,10 +18103,14 @@
18053 BusyHandler busyHandler; /* Busy callback */
18054 Db aDbStatic[2]; /* Static space for the 2 default backends */
18055 Savepoint *pSavepoint; /* List of active savepoints */
18056 int nAnalysisLimit; /* Number of index rows to ANALYZE */
18057 int busyTimeout; /* Busy handler timeout, in msec */
 
 
 
 
18058 int nSavepoint; /* Number of non-transaction savepoints */
18059 int nStatement; /* Number of nested statement-transactions */
18060 i64 nDeferredCons; /* Net deferred constraints this transaction. */
18061 i64 nDeferredImmCons; /* Net deferred immediate constraints */
18062 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
@@ -18731,10 +18785,11 @@
18731 VTable *p; /* List of VTable objects. */
18732 } vtab;
18733 } u;
18734 Trigger *pTrigger; /* List of triggers on this object */
18735 Schema *pSchema; /* Schema that contains this table */
 
18736 };
18737
18738 /*
18739 ** Allowed values for Table.tabFlags.
18740 **
@@ -20128,29 +20183,36 @@
20128 struct Parse {
20129 sqlite3 *db; /* The main database structure */
20130 char *zErrMsg; /* An error message */
20131 Vdbe *pVdbe; /* An engine for executing database bytecode */
20132 int rc; /* Return code from execution */
20133 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
20134 u8 checkSchema; /* Causes schema cookie check after an error */
20135 u8 nested; /* Number of nested calls to the parser/code generator */
20136 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
20137 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
20138 u8 mayAbort; /* True if statement may throw an ABORT exception */
20139 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
20140 u8 okConstFactor; /* OK to factor out constants */
20141 u8 disableLookaside; /* Number of times lookaside has been disabled */
20142 u8 prepFlags; /* SQLITE_PREPARE_* flags */
20143 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20144 u8 bHasWith; /* True if statement contains WITH */
20145 u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
 
 
 
 
20146 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
20147 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
20148 #endif
20149 #ifdef SQLITE_DEBUG
20150 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
 
 
20151 #endif
 
 
 
 
20152 int nRangeReg; /* Size of the temporary register block */
20153 int iRangeReg; /* First register in temporary register block */
20154 int nErr; /* Number of errors seen */
20155 int nTab; /* Number of previously allocated VDBE cursors */
20156 int nMem; /* Number of memory cells used so far */
@@ -20161,16 +20223,13 @@
20161 int nLabelAlloc; /* Number of slots in aLabel */
20162 int *aLabel; /* Space to hold the labels */
20163 ExprList *pConstExpr;/* Constant expressions */
20164 IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
20165 IndexedExpr *pIdxPartExpr; /* Exprs constrained by index WHERE clauses */
20166 Token constraintName;/* Name of the constraint currently being parsed */
20167 yDbMask writeMask; /* Start a write transaction on these databases */
20168 yDbMask cookieMask; /* Bitmask of schema verified databases */
20169 int regRowid; /* Register holding rowid of CREATE TABLE entry */
20170 int regRoot; /* Register holding root page number for new objects */
20171 int nMaxArg; /* Max args passed to user function by sub-program */
20172 int nSelect; /* Number of SELECT stmts. Counter for Select.selId */
20173 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
20174 u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
20175 #endif
20176 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -20180,21 +20239,10 @@
20180 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
20181 Parse *pToplevel; /* Parse structure for main program (or NULL) */
20182 Table *pTriggerTab; /* Table triggers are being coded for */
20183 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
20184 ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
20185 union {
20186 int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
20187 Returning *pReturning; /* The RETURNING clause */
20188 } u1;
20189 u32 oldmask; /* Mask of old.* columns referenced */
20190 u32 newmask; /* Mask of new.* columns referenced */
20191 LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
20192 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20193 u8 bReturning; /* Coding a RETURNING trigger */
20194 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20195 u8 disableTriggers; /* True to disable triggers */
20196
20197 /**************************************************************************
20198 ** Fields above must be initialized to zero. The fields that follow,
20199 ** down to the beginning of the recursive section, do not need to be
20200 ** initialized as they will be set before being used. The boundary is
@@ -20202,10 +20250,23 @@
20202 **************************************************************************/
20203
20204 int aTempReg[8]; /* Holding area for temporary registers */
20205 Parse *pOuterParse; /* Outer Parse object when nested */
20206 Token sNameToken; /* Token with unqualified schema object name */
 
 
 
 
 
 
 
 
 
 
 
 
 
20207
20208 /************************************************************************
20209 ** Above is constant between recursions. Below is reset before and after
20210 ** each recursion. The boundary between these two regions is determined
20211 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -23831,14 +23892,10 @@
23831 u8 skipFlag; /* Skip accumulator loading if true */
23832 u16 argc; /* Number of arguments */
23833 sqlite3_value *argv[1]; /* Argument set */
23834 };
23835
23836 /* A bitfield type for use inside of structures. Always follow with :N where
23837 ** N is the number of bits.
23838 */
23839 typedef unsigned bft; /* Bit Field Type */
23840
23841 /* The ScanStatus object holds a single value for the
23842 ** sqlite3_stmt_scanstatus() interface.
23843 **
23844 ** aAddrRange[]:
@@ -23895,11 +23952,11 @@
23895 i64 iCurrentTime; /* Value of julianday('now') for this statement */
23896 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
23897 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
23898 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
23899 Mem *aMem; /* The memory locations */
23900 Mem **apArg; /* Arguments to currently executing user function */
23901 VdbeCursor **apCsr; /* One element of this array for each open cursor */
23902 Mem *aVar; /* Values for the OP_Variable opcode. */
23903
23904 /* When allocating a new Vdbe object, all of the fields below should be
23905 ** initialized to zero or NULL */
@@ -23915,10 +23972,11 @@
23915 i64 startTime; /* Time when query started - used for profiling */
23916 #endif
23917 #ifdef SQLITE_DEBUG
23918 int rcApp; /* errcode set by sqlite3_result_error_code() */
23919 u32 nWrite; /* Number of write operations that have occurred */
 
23920 #endif
23921 u16 nResColumn; /* Number of columns in one row of the result set */
23922 u16 nResAlloc; /* Column slots allocated to aColName[] */
23923 u8 errorAction; /* Recovery action to do in case of an error */
23924 u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -36398,11 +36456,15 @@
36398 }
36399 }
36400 }
36401 p->z = &p->zBuf[i+1];
36402 assert( i+p->n < sizeof(p->zBuf) );
36403 while( ALWAYS(p->n>0) && p->z[p->n-1]=='0' ){ p->n--; }
 
 
 
 
36404 }
36405
36406 /*
36407 ** Try to convert z into an unsigned 32-bit integer. Return true on
36408 ** success and false if there is an error.
@@ -37184,16 +37246,23 @@
37184 /*
37185 ** The hashing function.
37186 */
37187 static unsigned int strHash(const char *z){
37188 unsigned int h = 0;
37189 unsigned char c;
37190 while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
37191 /* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
37192 ** 0x9e3779b1 is 2654435761 which is the closest prime number to
37193 ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */
37194 h += sqlite3UpperToLower[c];
 
 
 
 
 
 
 
 
37195 h *= 0x9e3779b1;
37196 }
37197 return h;
37198 }
37199
@@ -37262,13 +37331,12 @@
37262 sqlite3_free(pH->ht);
37263 pH->ht = new_ht;
37264 pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
37265 memset(new_ht, 0, new_size*sizeof(struct _ht));
37266 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
37267 unsigned int h = strHash(elem->pKey) % new_size;
37268 next_elem = elem->next;
37269 insertElement(pH, &new_ht[h], elem);
37270 }
37271 return 1;
37272 }
37273
37274 /* This function (for internal use only) locates an element in an
@@ -37282,27 +37350,26 @@
37282 unsigned int *pHash /* Write the hash value here */
37283 ){
37284 HashElem *elem; /* Used to loop thru the element list */
37285 unsigned int count; /* Number of elements left to test */
37286 unsigned int h; /* The computed hash */
37287 static HashElem nullElement = { 0, 0, 0, 0 };
37288
 
37289 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
37290 struct _ht *pEntry;
37291 h = strHash(pKey) % pH->htsize;
37292 pEntry = &pH->ht[h];
37293 elem = pEntry->chain;
37294 count = pEntry->count;
37295 }else{
37296 h = 0;
37297 elem = pH->first;
37298 count = pH->count;
37299 }
37300 if( pHash ) *pHash = h;
37301 while( count ){
37302 assert( elem!=0 );
37303 if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
37304 return elem;
37305 }
37306 elem = elem->next;
37307 count--;
37308 }
@@ -37310,14 +37377,13 @@
37310 }
37311
37312 /* Remove a single entry from the hash table given a pointer to that
37313 ** element and a hash on the element's key.
37314 */
37315 static void removeElementGivenHash(
37316 Hash *pH, /* The pH containing "elem" */
37317 HashElem* elem, /* The element to be removed from the pH */
37318 unsigned int h /* Hash value for the element */
37319 ){
37320 struct _ht *pEntry;
37321 if( elem->prev ){
37322 elem->prev->next = elem->next;
37323 }else{
@@ -37325,11 +37391,11 @@
37325 }
37326 if( elem->next ){
37327 elem->next->prev = elem->prev;
37328 }
37329 if( pH->ht ){
37330 pEntry = &pH->ht[h];
37331 if( pEntry->chain==elem ){
37332 pEntry->chain = elem->next;
37333 }
37334 assert( pEntry->count>0 );
37335 pEntry->count--;
@@ -37376,11 +37442,11 @@
37376 assert( pKey!=0 );
37377 elem = findElementWithHash(pH,pKey,&h);
37378 if( elem->data ){
37379 void *old_data = elem->data;
37380 if( data==0 ){
37381 removeElementGivenHash(pH,elem,h);
37382 }else{
37383 elem->data = data;
37384 elem->pKey = pKey;
37385 }
37386 return old_data;
@@ -37387,19 +37453,17 @@
37387 }
37388 if( data==0 ) return 0;
37389 new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
37390 if( new_elem==0 ) return data;
37391 new_elem->pKey = pKey;
 
37392 new_elem->data = data;
37393 pH->count++;
37394 if( pH->count>=10 && pH->count > 2*pH->htsize ){
37395 if( rehash(pH, pH->count*2) ){
37396 assert( pH->htsize>0 );
37397 h = strHash(pKey) % pH->htsize;
37398 }
37399 }
37400 insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);
37401 return 0;
37402 }
37403
37404 /************** End of hash.c ************************************************/
37405 /************** Begin file opcodes.c *****************************************/
@@ -38878,10 +38942,11 @@
38878 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
38879 unsigned fsFlags; /* cached details from statfs() */
38880 #endif
38881 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
38882 unsigned iBusyTimeout; /* Wait this many millisec on locks */
 
38883 #endif
38884 #if OS_VXWORKS
38885 struct vxworksFileId *pId; /* Unique file ID */
38886 #endif
38887 #ifdef SQLITE_DEBUG
@@ -40271,10 +40336,17 @@
40271 pInode->nLock++;
40272 }else{
40273 rc = 0;
40274 }
40275 }else{
 
 
 
 
 
 
 
40276 rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile);
40277 }
40278 return rc;
40279 }
40280
@@ -42632,21 +42704,27 @@
42632 return SQLITE_OK;
42633 }
42634 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
42635 case SQLITE_FCNTL_LOCK_TIMEOUT: {
42636 int iOld = pFile->iBusyTimeout;
 
42637 #if SQLITE_ENABLE_SETLK_TIMEOUT==1
42638 pFile->iBusyTimeout = *(int*)pArg;
42639 #elif SQLITE_ENABLE_SETLK_TIMEOUT==2
42640 pFile->iBusyTimeout = !!(*(int*)pArg);
42641 #else
42642 # error "SQLITE_ENABLE_SETLK_TIMEOUT must be set to 1 or 2"
42643 #endif
42644 *(int*)pArg = iOld;
42645 return SQLITE_OK;
42646 }
42647 #endif
 
 
 
 
 
42648 #if SQLITE_MAX_MMAP_SIZE>0
42649 case SQLITE_FCNTL_MMAP_SIZE: {
42650 i64 newLimit = *(i64*)pArg;
42651 int rc = SQLITE_OK;
42652 if( newLimit>sqlite3GlobalConfig.mxMmap ){
@@ -47155,11 +47233,21 @@
47155 HANDLE hMap; /* Handle for accessing memory mapping */
47156 void *pMapRegion; /* Area memory mapped */
47157 sqlite3_int64 mmapSize; /* Size of mapped region */
47158 sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
47159 #endif
 
 
 
 
47160 };
 
 
 
 
 
 
47161
47162 /*
47163 ** The winVfsAppData structure is used for the pAppData member for all of the
47164 ** Win32 VFS variants.
47165 */
@@ -47590,10 +47678,16 @@
47590 #endif
47591
47592 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
47593 LPWSTR*))aSyscall[25].pCurrent)
47594
 
 
 
 
 
 
47595 { "GetLastError", (SYSCALL)GetLastError, 0 },
47596
47597 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
47598
47599 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
@@ -47872,15 +47966,17 @@
47872 #endif
47873
47874 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
47875 DWORD,DWORD))aSyscall[62].pCurrent)
47876
47877 #if !SQLITE_OS_WINRT
 
 
 
 
 
47878 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
47879 #else
47880 { "WaitForSingleObject", (SYSCALL)0, 0 },
47881 #endif
47882
47883 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
47884 DWORD))aSyscall[63].pCurrent)
47885
47886 #if !SQLITE_OS_WINCE
@@ -48023,10 +48119,44 @@
48023 #endif
48024
48025 #define osFlushViewOfFile \
48026 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
48027
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48028 }; /* End of the overrideable system calls */
48029
48030 /*
48031 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
48032 ** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -48321,11 +48451,13 @@
48321 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
48322 #endif
48323 }
48324 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
48325 #elif SQLITE_TEST
48326 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
 
 
48327 #else
48328 /*
48329 ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
48330 ** deprecated are always assumed to be based on the NT kernel.
48331 */
@@ -49407,10 +49539,89 @@
49407 return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49408 numBytesHigh);
49409 }
49410 #endif
49411 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49412
49413 /*
49414 ** Unlock a file region.
49415 */
49416 static BOOL winUnlockFile(
@@ -49438,10 +49649,18 @@
49438 return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49439 numBytesHigh);
49440 }
49441 #endif
49442 }
 
 
 
 
 
 
 
 
49443
49444 /*****************************************************************************
49445 ** The next group of routines implement the I/O methods specified
49446 ** by the sqlite3_io_methods object.
49447 ******************************************************************************/
@@ -49452,69 +49671,73 @@
49452 #ifndef INVALID_SET_FILE_POINTER
49453 # define INVALID_SET_FILE_POINTER ((DWORD)-1)
49454 #endif
49455
49456 /*
49457 ** Move the current position of the file handle passed as the first
49458 ** argument to offset iOffset within the file. If successful, return 0.
49459 ** Otherwise, set pFile->lastErrno and return non-zero.
 
49460 */
49461 static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){
 
 
49462 #if !SQLITE_OS_WINRT
49463 LONG upperBits; /* Most sig. 32 bits of new offset */
49464 LONG lowerBits; /* Least sig. 32 bits of new offset */
49465 DWORD dwRet; /* Value returned by SetFilePointer() */
49466 DWORD lastErrno; /* Value returned by GetLastError() */
49467
49468 OSTRACE(("SEEK file=%p, offset=%lld\n", pFile->h, iOffset));
49469
49470 upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
49471 lowerBits = (LONG)(iOffset & 0xffffffff);
 
 
49472
49473 /* API oddity: If successful, SetFilePointer() returns a dword
49474 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
49475 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
49476 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
49477 ** whether an error has actually occurred, it is also necessary to call
49478 ** GetLastError().
49479 */
49480 dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
49481
49482 if( (dwRet==INVALID_SET_FILE_POINTER
49483 && ((lastErrno = osGetLastError())!=NO_ERROR)) ){
49484 pFile->lastErrno = lastErrno;
49485 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
49486 "winSeekFile", pFile->zPath);
49487 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
49488 return 1;
49489 }
49490
49491 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
49492 return 0;
49493 #else
49494 /*
49495 ** Same as above, except that this implementation works for WinRT.
49496 */
49497
49498 LARGE_INTEGER x; /* The new offset */
49499 BOOL bRet; /* Value returned by SetFilePointerEx() */
49500
49501 x.QuadPart = iOffset;
49502 bRet = osSetFilePointerEx(pFile->h, x, 0, FILE_BEGIN);
49503
49504 if(!bRet){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49505 pFile->lastErrno = osGetLastError();
49506 winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
49507 "winSeekFile", pFile->zPath);
49508 OSTRACE(("SEEK file=%p, rc=SQLITE_IOERR_SEEK\n", pFile->h));
49509 return 1;
49510 }
49511
49512 OSTRACE(("SEEK file=%p, rc=SQLITE_OK\n", pFile->h));
49513 return 0;
49514 #endif
49515 }
49516
49517 #if SQLITE_MAX_MMAP_SIZE>0
49518 /* Forward references to VFS helper methods used for memory mapped files */
49519 static int winMapfile(winFile*, sqlite3_int64);
49520 static int winUnmapfile(winFile*);
@@ -49770,10 +49993,64 @@
49770 }
49771 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
49772 osGetCurrentProcessId(), pFile, pFile->h));
49773 return SQLITE_OK;
49774 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49775
49776 /*
49777 ** Truncate an open file to a specified size
49778 */
49779 static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
@@ -50026,31 +50303,32 @@
50026 /*
50027 ** Acquire a reader lock.
50028 ** Different API routines are called depending on whether or not this
50029 ** is Win9x or WinNT.
50030 */
50031 static int winGetReadLock(winFile *pFile){
50032 int res;
 
50033 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
50034 if( osIsNT() ){
50035 #if SQLITE_OS_WINCE
50036 /*
50037 ** NOTE: Windows CE is handled differently here due its lack of the Win32
50038 ** API LockFileEx.
50039 */
50040 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
50041 #else
50042 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
50043 SHARED_SIZE, 0);
50044 #endif
50045 }
50046 #ifdef SQLITE_WIN32_HAS_ANSI
50047 else{
50048 int lk;
50049 sqlite3_randomness(sizeof(lk), &lk);
50050 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
50051 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
50052 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
50053 }
50054 #endif
50055 if( res == 0 ){
50056 pFile->lastErrno = osGetLastError();
@@ -50180,11 +50458,11 @@
50180
50181 /* Acquire a shared lock
50182 */
50183 if( locktype==SHARED_LOCK && res ){
50184 assert( pFile->locktype==NO_LOCK );
50185 res = winGetReadLock(pFile);
50186 if( res ){
50187 newLocktype = SHARED_LOCK;
50188 }else{
50189 lastErrno = osGetLastError();
50190 }
@@ -50218,11 +50496,11 @@
50218 SHARED_SIZE, 0);
50219 if( res ){
50220 newLocktype = EXCLUSIVE_LOCK;
50221 }else{
50222 lastErrno = osGetLastError();
50223 winGetReadLock(pFile);
50224 }
50225 }
50226
50227 /* If we are holding a PENDING lock that ought to be released, then
50228 ** release it now.
@@ -50508,10 +50786,32 @@
50508 }
50509 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
50510 return rc;
50511 }
50512 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50513 }
50514 OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
50515 return SQLITE_NOTFOUND;
50516 }
50517
@@ -50588,36 +50888,39 @@
50588 ** nRef
50589 ** pNext
50590 **
50591 ** The following fields are read-only after the object is created:
50592 **
50593 ** fid
50594 ** zFilename
50595 **
50596 ** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
50597 ** winShmMutexHeld() is true when reading or writing any other field
50598 ** in this structure.
50599 **
 
 
 
 
 
50600 */
50601 struct winShmNode {
50602 sqlite3_mutex *mutex; /* Mutex to access this object */
50603 char *zFilename; /* Name of the file */
50604 winFile hFile; /* File handle from winOpen */
50605
 
 
50606 int szRegion; /* Size of shared-memory regions */
50607 int nRegion; /* Size of array apRegion */
50608 u8 isReadonly; /* True if read-only */
50609 u8 isUnlocked; /* True if no DMS lock held */
50610
50611 struct ShmRegion {
50612 HANDLE hMap; /* File handle from CreateFileMapping */
50613 void *pMap;
50614 } *aRegion;
50615 DWORD lastErrno; /* The Windows errno from the last I/O error */
50616
50617 int nRef; /* Number of winShm objects pointing to this */
50618 winShm *pFirst; /* All winShm objects pointing to this */
50619 winShmNode *pNext; /* Next in list of all winShmNode objects */
50620 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
50621 u8 nextShmId; /* Next available winShm.id value */
50622 #endif
50623 };
@@ -50629,27 +50932,19 @@
50629 */
50630 static winShmNode *winShmNodeList = 0;
50631
50632 /*
50633 ** Structure used internally by this VFS to record the state of an
50634 ** open shared memory connection.
50635 **
50636 ** The following fields are initialized when this object is created and
50637 ** are read-only thereafter:
50638 **
50639 ** winShm.pShmNode
50640 ** winShm.id
50641 **
50642 ** All other fields are read/write. The winShm.pShmNode->mutex must be held
50643 ** while accessing any read/write fields.
50644 */
50645 struct winShm {
50646 winShmNode *pShmNode; /* The underlying winShmNode object */
50647 winShm *pNext; /* Next winShm with the same winShmNode */
50648 u8 hasMutex; /* True if holding the winShmNode mutex */
50649 u16 sharedMask; /* Mask of shared locks held */
50650 u16 exclMask; /* Mask of exclusive locks held */
 
 
50651 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
50652 u8 id; /* Id of this connection with its winShmNode */
50653 #endif
50654 };
50655
@@ -50657,54 +50952,10 @@
50657 ** Constants used for locking
50658 */
50659 #define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
50660 #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
50661
50662 /*
50663 ** Apply advisory locks for all n bytes beginning at ofst.
50664 */
50665 #define WINSHM_UNLCK 1
50666 #define WINSHM_RDLCK 2
50667 #define WINSHM_WRLCK 3
50668 static int winShmSystemLock(
50669 winShmNode *pFile, /* Apply locks to this open shared-memory segment */
50670 int lockType, /* WINSHM_UNLCK, WINSHM_RDLCK, or WINSHM_WRLCK */
50671 int ofst, /* Offset to first byte to be locked/unlocked */
50672 int nByte /* Number of bytes to lock or unlock */
50673 ){
50674 int rc = 0; /* Result code form Lock/UnlockFileEx() */
50675
50676 /* Access to the winShmNode object is serialized by the caller */
50677 assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) );
50678
50679 OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n",
50680 pFile->hFile.h, lockType, ofst, nByte));
50681
50682 /* Release/Acquire the system-level lock */
50683 if( lockType==WINSHM_UNLCK ){
50684 rc = winUnlockFile(&pFile->hFile.h, ofst, 0, nByte, 0);
50685 }else{
50686 /* Initialize the locking parameters */
50687 DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
50688 if( lockType == WINSHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
50689 rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
50690 }
50691
50692 if( rc!= 0 ){
50693 rc = SQLITE_OK;
50694 }else{
50695 pFile->lastErrno = osGetLastError();
50696 rc = SQLITE_BUSY;
50697 }
50698
50699 OSTRACE(("SHM-LOCK file=%p, func=%s, errno=%lu, rc=%s\n",
50700 pFile->hFile.h, (lockType == WINSHM_UNLCK) ? "winUnlockFile" :
50701 "winLockFile", pFile->lastErrno, sqlite3ErrName(rc)));
50702
50703 return rc;
50704 }
50705
50706 /* Forward references to VFS methods */
50707 static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
50708 static int winDelete(sqlite3_vfs *,const char*,int);
50709
50710 /*
@@ -50732,15 +50983,11 @@
50732 bRc = osCloseHandle(p->aRegion[i].hMap);
50733 OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
50734 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
50735 UNUSED_VARIABLE_VALUE(bRc);
50736 }
50737 if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
50738 SimulateIOErrorBenign(1);
50739 winClose((sqlite3_file *)&p->hFile);
50740 SimulateIOErrorBenign(0);
50741 }
50742 if( deleteFlag ){
50743 SimulateIOErrorBenign(1);
50744 sqlite3BeginBenignMalloc();
50745 winDelete(pVfs, p->zFilename, 0);
50746 sqlite3EndBenignMalloc();
@@ -50754,46 +51001,166 @@
50754 }
50755 }
50756 }
50757
50758 /*
50759 ** The DMS lock has not yet been taken on shm file pShmNode. Attempt to
50760 ** take it now. Return SQLITE_OK if successful, or an SQLite error
50761 ** code otherwise.
50762 **
50763 ** If the DMS cannot be locked because this is a readonly_shm=1
50764 ** connection and no other process already holds a lock, return
50765 ** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1.
50766 */
50767 static int winLockSharedMemory(winShmNode *pShmNode){
50768 int rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, WIN_SHM_DMS, 1);
 
50769
 
 
50770 if( rc==SQLITE_OK ){
 
 
 
50771 if( pShmNode->isReadonly ){
50772 pShmNode->isUnlocked = 1;
50773 winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50774 return SQLITE_READONLY_CANTINIT;
50775 }else if( winTruncate((sqlite3_file*)&pShmNode->hFile, 0) ){
50776 winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50777 return winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
50778 "winLockSharedMemory", pShmNode->zFilename);
50779 }
50780 }
50781
50782 if( rc==SQLITE_OK ){
50783 winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50784 }
50785
50786 return winShmSystemLock(pShmNode, WINSHM_RDLCK, WIN_SHM_DMS, 1);
50787 }
50788
50789 /*
50790 ** Open the shared-memory area associated with database file pDbFd.
50791 **
50792 ** When opening a new shared-memory file, if no other instances of that
50793 ** file are currently open, in this process or in other processes, then
50794 ** the file must be truncated to zero length or have its header cleared.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50795 */
50796 static int winOpenSharedMemory(winFile *pDbFd){
50797 struct winShm *p; /* The connection to be opened */
50798 winShmNode *pShmNode = 0; /* The underlying mmapped file */
50799 int rc = SQLITE_OK; /* Result code */
@@ -50801,102 +51168,87 @@
50801 int nName; /* Size of zName in bytes */
50802
50803 assert( pDbFd->pShm==0 ); /* Not previously opened */
50804
50805 /* Allocate space for the new sqlite3_shm object. Also speculatively
50806 ** allocate space for a new winShmNode and filename.
50807 */
50808 p = sqlite3MallocZero( sizeof(*p) );
50809 if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
50810 nName = sqlite3Strlen30(pDbFd->zPath);
50811 pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
50812 if( pNew==0 ){
50813 sqlite3_free(p);
50814 return SQLITE_IOERR_NOMEM_BKPT;
50815 }
50816 pNew->zFilename = (char*)&pNew[1];
 
 
50817 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
50818 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
 
 
 
 
 
 
50819
50820 /* Look to see if there is an existing winShmNode that can be used.
50821 ** If no matching winShmNode currently exists, create a new one.
50822 */
50823 winShmEnterMutex();
50824 for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
50825 /* TBD need to come up with better match here. Perhaps
50826 ** use FILE_ID_BOTH_DIR_INFO Structure.
50827 */
50828 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
50829 }
50830 if( pShmNode ){
50831 sqlite3_free(pNew);
50832 }else{
50833 int inFlags = SQLITE_OPEN_WAL;
50834 int outFlags = 0;
50835
50836 pShmNode = pNew;
50837 pNew = 0;
50838 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
50839 pShmNode->pNext = winShmNodeList;
50840 winShmNodeList = pShmNode;
50841
 
50842 if( sqlite3GlobalConfig.bCoreMutex ){
50843 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
50844 if( pShmNode->mutex==0 ){
50845 rc = SQLITE_IOERR_NOMEM_BKPT;
50846 goto shm_open_err;
50847 }
50848 }
50849
50850 if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
50851 inFlags |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
50852 }else{
50853 inFlags |= SQLITE_OPEN_READONLY;
50854 }
50855 rc = winOpen(pDbFd->pVfs, pShmNode->zFilename,
50856 (sqlite3_file*)&pShmNode->hFile,
50857 inFlags, &outFlags);
50858 if( rc!=SQLITE_OK ){
50859 rc = winLogError(rc, osGetLastError(), "winOpenShm",
50860 pShmNode->zFilename);
50861 goto shm_open_err;
50862 }
50863 if( outFlags==SQLITE_OPEN_READONLY ) pShmNode->isReadonly = 1;
50864
50865 rc = winLockSharedMemory(pShmNode);
50866 if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err;
50867 }
50868
50869 /* Make the new connection a child of the winShmNode */
50870 p->pShmNode = pShmNode;
 
 
 
50871 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
50872 p->id = pShmNode->nextShmId++;
50873 #endif
50874 pShmNode->nRef++;
50875 pDbFd->pShm = p;
50876 winShmLeaveMutex();
50877
50878 /* The reference count on pShmNode has already been incremented under
50879 ** the cover of the winShmEnterMutex() mutex and the pointer from the
50880 ** new (struct winShm) object to the pShmNode has been set. All that is
50881 ** left to do is to link the new object into the linked list starting
50882 ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex
50883 ** mutex.
50884 */
50885 sqlite3_mutex_enter(pShmNode->mutex);
50886 p->pNext = pShmNode->pFirst;
50887 pShmNode->pFirst = p;
50888 sqlite3_mutex_leave(pShmNode->mutex);
50889 return rc;
50890
50891 /* Jump here on any error */
50892 shm_open_err:
50893 winShmSystemLock(pShmNode, WINSHM_UNLCK, WIN_SHM_DMS, 1);
50894 winShmPurge(pDbFd->pVfs, 0); /* This call frees pShmNode if required */
50895 sqlite3_free(p);
50896 sqlite3_free(pNew);
50897 winShmLeaveMutex();
50898 return rc;
50899 }
50900
50901 /*
50902 ** Close a connection to shared-memory. Delete the underlying
@@ -50907,38 +51259,33 @@
50907 int deleteFlag /* Delete after closing if true */
50908 ){
50909 winFile *pDbFd; /* Database holding shared-memory */
50910 winShm *p; /* The connection to be closed */
50911 winShmNode *pShmNode; /* The underlying shared-memory file */
50912 winShm **pp; /* For looping over sibling connections */
50913
50914 pDbFd = (winFile*)fd;
50915 p = pDbFd->pShm;
50916 if( p==0 ) return SQLITE_OK;
 
 
 
 
50917 pShmNode = p->pShmNode;
50918
50919 /* Remove connection p from the set of connections associated
50920 ** with pShmNode */
50921 sqlite3_mutex_enter(pShmNode->mutex);
50922 for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){}
50923 *pp = p->pNext;
50924
50925 /* Free the connection p */
50926 sqlite3_free(p);
50927 pDbFd->pShm = 0;
50928 sqlite3_mutex_leave(pShmNode->mutex);
50929
50930 /* If pShmNode->nRef has reached 0, then close the underlying
50931 ** shared-memory file, too */
50932 winShmEnterMutex();
50933 assert( pShmNode->nRef>0 );
50934 pShmNode->nRef--;
50935 if( pShmNode->nRef==0 ){
50936 winShmPurge(pDbFd->pVfs, deleteFlag);
50937 }
50938 winShmLeaveMutex();
50939
 
 
 
50940 return SQLITE_OK;
50941 }
50942
50943 /*
50944 ** Change the lock state for a shared-memory segment.
@@ -50949,14 +51296,13 @@
50949 int n, /* Number of locks to acquire or release */
50950 int flags /* What to do with the lock */
50951 ){
50952 winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
50953 winShm *p = pDbFd->pShm; /* The shared memory being locked */
50954 winShm *pX; /* For looping over all siblings */
50955 winShmNode *pShmNode;
50956 int rc = SQLITE_OK; /* Result code */
50957 u16 mask; /* Mask of locks to take or release */
50958
50959 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
50960 pShmNode = p->pShmNode;
50961 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
50962
@@ -50966,89 +51312,86 @@
50966 || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
50967 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
50968 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
50969 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
50970
50971 mask = (u16)((1U<<(ofst+n)) - (1U<<ofst));
50972 assert( n>1 || mask==(1<<ofst) );
50973 sqlite3_mutex_enter(pShmNode->mutex);
50974 if( flags & SQLITE_SHM_UNLOCK ){
50975 u16 allMask = 0; /* Mask of locks held by siblings */
50976
50977 /* See if any siblings hold this same lock */
50978 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
50979 if( pX==p ) continue;
50980 assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 );
50981 allMask |= pX->sharedMask;
50982 }
50983
50984 /* Unlock the system-level locks */
50985 if( (mask & allMask)==0 ){
50986 rc = winShmSystemLock(pShmNode, WINSHM_UNLCK, ofst+WIN_SHM_BASE, n);
50987 }else{
50988 rc = SQLITE_OK;
50989 }
50990
50991 /* Undo the local locks */
50992 if( rc==SQLITE_OK ){
50993 p->exclMask &= ~mask;
50994 p->sharedMask &= ~mask;
50995 }
50996 }else if( flags & SQLITE_SHM_SHARED ){
50997 u16 allShared = 0; /* Union of locks held by connections other than "p" */
50998
50999 /* Find out which shared locks are already held by sibling connections.
51000 ** If any sibling already holds an exclusive lock, go ahead and return
51001 ** SQLITE_BUSY.
51002 */
51003 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
51004 if( (pX->exclMask & mask)!=0 ){
51005 rc = SQLITE_BUSY;
51006 break;
51007 }
51008 allShared |= pX->sharedMask;
51009 }
51010
51011 /* Get shared locks at the system level, if necessary */
51012 if( rc==SQLITE_OK ){
51013 if( (allShared & mask)==0 ){
51014 rc = winShmSystemLock(pShmNode, WINSHM_RDLCK, ofst+WIN_SHM_BASE, n);
51015 }else{
51016 rc = SQLITE_OK;
51017 }
51018 }
51019
51020 /* Get the local shared locks */
51021 if( rc==SQLITE_OK ){
51022 p->sharedMask |= mask;
51023 }
51024 }else{
51025 /* Make sure no sibling connections hold locks that will block this
51026 ** lock. If any do, return SQLITE_BUSY right away.
51027 */
51028 for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
51029 if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){
51030 rc = SQLITE_BUSY;
51031 break;
51032 }
51033 }
51034
51035 /* Get the exclusive locks at the system level. Then if successful
51036 ** also mark the local connection as being locked.
51037 */
51038 if( rc==SQLITE_OK ){
51039 rc = winShmSystemLock(pShmNode, WINSHM_WRLCK, ofst+WIN_SHM_BASE, n);
51040 if( rc==SQLITE_OK ){
51041 assert( (p->sharedMask & mask)==0 );
51042 p->exclMask |= mask;
51043 }
51044 }
51045 }
51046 sqlite3_mutex_leave(pShmNode->mutex);
51047 OSTRACE(("SHM-LOCK pid=%lu, id=%d, sharedMask=%03x, exclMask=%03x, rc=%s\n",
51048 osGetCurrentProcessId(), p->id, p->sharedMask, p->exclMask,
51049 sqlite3ErrName(rc)));
51050 return rc;
51051 }
51052
51053 /*
51054 ** Implement a memory barrier or memory fence on shared memory.
@@ -51106,17 +51449,19 @@
51106 }
51107 pShmNode = pShm->pShmNode;
51108
51109 sqlite3_mutex_enter(pShmNode->mutex);
51110 if( pShmNode->isUnlocked ){
51111 rc = winLockSharedMemory(pShmNode);
 
 
51112 if( rc!=SQLITE_OK ) goto shmpage_out;
51113 pShmNode->isUnlocked = 0;
51114 }
 
51115 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
51116
51117 if( pShmNode->nRegion<=iRegion ){
 
51118 struct ShmRegion *apNew; /* New aRegion[] array */
51119 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
51120 sqlite3_int64 sz; /* Current size of wal-index file */
51121
51122 pShmNode->szRegion = szRegion;
@@ -51123,35 +51468,32 @@
51123
51124 /* The requested region is not mapped into this processes address space.
51125 ** Check to see if it has been allocated (i.e. if the wal-index file is
51126 ** large enough to contain the requested region).
51127 */
51128 rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz);
51129 if( rc!=SQLITE_OK ){
51130 rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
51131 "winShmMap1", pDbFd->zPath);
51132 goto shmpage_out;
51133 }
51134
51135 if( sz<nByte ){
51136 /* The requested memory region does not exist. If isWrite is set to
51137 ** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
51138 **
51139 ** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
51140 ** the requested memory region.
51141 */
51142 if( !isWrite ) goto shmpage_out;
51143 rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte);
51144 if( rc!=SQLITE_OK ){
51145 rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
51146 "winShmMap2", pDbFd->zPath);
51147 goto shmpage_out;
51148 }
51149 }
51150
51151 /* Map the requested memory region into this processes address space. */
51152 apNew = (struct ShmRegion *)sqlite3_realloc64(
51153 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
51154 );
51155 if( !apNew ){
51156 rc = SQLITE_IOERR_NOMEM_BKPT;
51157 goto shmpage_out;
@@ -51166,22 +51508,17 @@
51166 while( pShmNode->nRegion<=iRegion ){
51167 HANDLE hMap = NULL; /* file-mapping handle */
51168 void *pMap = 0; /* Mapped memory region */
51169
51170 #if SQLITE_OS_WINRT
51171 hMap = osCreateFileMappingFromApp(pShmNode->hFile.h,
51172 NULL, protect, nByte, NULL
51173 );
51174 #elif defined(SQLITE_WIN32_HAS_WIDE)
51175 hMap = osCreateFileMappingW(pShmNode->hFile.h,
51176 NULL, protect, 0, nByte, NULL
51177 );
51178 #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
51179 hMap = osCreateFileMappingA(pShmNode->hFile.h,
51180 NULL, protect, 0, nByte, NULL
51181 );
51182 #endif
 
51183 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
51184 osGetCurrentProcessId(), pShmNode->nRegion, nByte,
51185 hMap ? "ok" : "failed"));
51186 if( hMap ){
51187 int iOffset = pShmNode->nRegion*szRegion;
@@ -51220,11 +51557,13 @@
51220 char *p = (char *)pShmNode->aRegion[iRegion].pMap;
51221 *pp = (void *)&p[iOffsetShift];
51222 }else{
51223 *pp = 0;
51224 }
51225 if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY;
 
 
51226 sqlite3_mutex_leave(pShmNode->mutex);
51227 return rc;
51228 }
51229
51230 #else
@@ -51561,30 +51900,10 @@
51561 /* caller will handle out of memory */
51562 return zConverted;
51563 }
51564 #endif
51565
51566 /*
51567 ** Convert a UTF-8 filename into whatever form the underlying
51568 ** operating system wants filenames in. Space to hold the result
51569 ** is obtained from malloc and must be freed by the calling
51570 ** function.
51571 */
51572 static void *winConvertFromUtf8Filename(const char *zFilename){
51573 void *zConverted = 0;
51574 if( osIsNT() ){
51575 zConverted = winUtf8ToUnicode(zFilename);
51576 }
51577 #ifdef SQLITE_WIN32_HAS_ANSI
51578 else{
51579 zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
51580 }
51581 #endif
51582 /* caller will handle out of memory */
51583 return zConverted;
51584 }
51585
51586 /*
51587 ** This function returns non-zero if the specified UTF-8 string buffer
51588 ** ends with a directory separator character or one was successfully
51589 ** added to it.
51590 */
@@ -53035,11 +53354,11 @@
53035 };
53036 #endif
53037
53038 /* Double-check that the aSyscall[] array has been constructed
53039 ** correctly. See ticket [bb3a86e890c8e96ab] */
53040 assert( ArraySize(aSyscall)==80 );
53041
53042 /* get memory map allocation granularity */
53043 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
53044 #if SQLITE_OS_WINRT
53045 osGetNativeSystemInfo(&winSysInfo);
@@ -65633,10 +65952,15 @@
65633 )
65634
65635 /*
65636 ** An open write-ahead log file is represented by an instance of the
65637 ** following object.
 
 
 
 
 
65638 */
65639 struct Wal {
65640 sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */
65641 sqlite3_file *pDbFd; /* File handle for the database file */
65642 sqlite3_file *pWalFd; /* File handle for WAL file */
@@ -67158,11 +67482,11 @@
67158 ** or 0 otherwise.
67159 */
67160 static int walEnableBlocking(Wal *pWal){
67161 int res = 0;
67162 if( pWal->db ){
67163 int tmout = pWal->db->busyTimeout;
67164 if( tmout ){
67165 res = walEnableBlockingMs(pWal, tmout);
67166 }
67167 }
67168 return res;
@@ -67544,11 +67868,13 @@
67544 static int walHandleException(Wal *pWal){
67545 if( pWal->exclusiveMode==0 ){
67546 static const int S = 1;
67547 static const int E = (1<<SQLITE_SHM_NLOCK);
67548 int ii;
67549 u32 mUnlock = pWal->lockMask & ~(
 
 
67550 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
67551 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
67552 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
67553 );
67554 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){
@@ -67816,11 +68142,16 @@
67816 }else{
67817 int bWriteLock = pWal->writeLock;
67818 if( bWriteLock
67819 || SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1))
67820 ){
67821 pWal->writeLock = 1;
 
 
 
 
 
67822 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
67823 badHdr = walIndexTryHdr(pWal, pChanged);
67824 if( badHdr ){
67825 /* If the wal-index header is still malformed even while holding
67826 ** a WRITE lock, it can only mean that the header is corrupted and
@@ -68601,12 +68932,15 @@
68601 /*
68602 ** Finish with a read transaction. All this does is release the
68603 ** read-lock.
68604 */
68605 SQLITE_PRIVATE void sqlite3WalEndReadTransaction(Wal *pWal){
68606 sqlite3WalEndWriteTransaction(pWal);
 
 
68607 if( pWal->readLock>=0 ){
 
68608 walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
68609 pWal->readLock = -1;
68610 }
68611 }
68612
@@ -68795,11 +69129,11 @@
68795 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
68796 /* If the write-lock is already held, then it was obtained before the
68797 ** read-transaction was even opened, making this call a no-op.
68798 ** Return early. */
68799 if( pWal->writeLock ){
68800 assert( !memcmp(&pWal->hdr,(void *)walIndexHdr(pWal),sizeof(WalIndexHdr)) );
68801 return SQLITE_OK;
68802 }
68803 #endif
68804
68805 /* Cannot start a write transaction without first holding a read
@@ -83370,11 +83704,11 @@
83370 if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
83371 /* pMem must be a string, and it cannot be an ephemeral or static string */
83372 return;
83373 }
83374 if( pMem->enc!=SQLITE_UTF8 ) return;
83375 if( NEVER(pMem->z==0) ) return;
83376 if( pMem->flags & MEM_Dyn ){
83377 if( pMem->xDel==sqlite3_free
83378 && sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
83379 ){
83380 pMem->z[pMem->n] = 0;
@@ -85958,12 +86292,12 @@
85958 ** through all the opcodes and fixes up some details.
85959 **
85960 ** (1) For each jump instruction with a negative P2 value (a label)
85961 ** resolve the P2 value to an actual address.
85962 **
85963 ** (2) Compute the maximum number of arguments used by any SQL function
85964 ** and store that value in *pMaxFuncArgs.
85965 **
85966 ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
85967 ** indicate what the prepared statement actually does.
85968 **
85969 ** (4) (discontinued)
@@ -85972,12 +86306,12 @@
85972 **
85973 ** This routine will only function correctly if the mkopcodeh.tcl generator
85974 ** script numbers the opcodes correctly. Changes to this routine must be
85975 ** coordinated with changes to mkopcodeh.tcl.
85976 */
85977 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
85978 int nMaxArgs = *pMaxFuncArgs;
85979 Op *pOp;
85980 Parse *pParse = p->pParse;
85981 int *aLabel = pParse->aLabel;
85982
85983 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
@@ -86018,19 +86352,23 @@
86018 assert( pOp->p2>=0 );
86019 goto resolve_p2_values_loop_exit;
86020 }
86021 #ifndef SQLITE_OMIT_VIRTUALTABLE
86022 case OP_VUpdate: {
86023 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
86024 break;
86025 }
86026 case OP_VFilter: {
86027 int n;
 
 
 
86028 assert( (pOp - p->aOp) >= 3 );
86029 assert( pOp[-1].opcode==OP_Integer );
 
86030 n = pOp[-1].p1;
86031 if( n>nMaxArgs ) nMaxArgs = n;
86032 /* Fall through into the default case */
86033 /* no break */ deliberate_fall_through
86034 }
86035 #endif
86036 default: {
@@ -86067,11 +86405,11 @@
86067 if( aLabel ){
86068 sqlite3DbNNFreeNN(p->db, pParse->aLabel);
86069 pParse->aLabel = 0;
86070 }
86071 pParse->nLabel = 0;
86072 *pMaxFuncArgs = nMaxArgs;
86073 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
86074 }
86075
86076 #ifdef SQLITE_DEBUG
86077 /*
@@ -87745,11 +88083,11 @@
87745 ){
87746 sqlite3 *db; /* The database connection */
87747 int nVar; /* Number of parameters */
87748 int nMem; /* Number of VM memory registers */
87749 int nCursor; /* Number of cursors required */
87750 int nArg; /* Number of arguments in subprograms */
87751 int n; /* Loop counter */
87752 struct ReusableSpace x; /* Reusable bulk memory */
87753
87754 assert( p!=0 );
87755 assert( p->nOp>0 );
@@ -87817,10 +88155,13 @@
87817 p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
87818 p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
87819 p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
87820 }
87821 }
 
 
 
87822
87823 if( db->mallocFailed ){
87824 p->nVar = 0;
87825 p->nCursor = 0;
87826 p->nMem = 0;
@@ -101897,10 +102238,11 @@
101897 nArg = (int)pArgc->u.i;
101898 iQuery = (int)pQuery->u.i;
101899
101900 /* Invoke the xFilter method */
101901 apArg = p->apArg;
 
101902 for(i = 0; i<nArg; i++){
101903 apArg[i] = &pArgc[i+1];
101904 }
101905 rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg);
101906 sqlite3VtabImportErrmsg(p, pVtab);
@@ -102107,10 +102449,11 @@
102107 assert( pOp->p4type==P4_VTAB );
102108 if( ALWAYS(pModule->xUpdate) ){
102109 u8 vtabOnConflict = db->vtabOnConflict;
102110 apArg = p->apArg;
102111 pX = &aMem[pOp->p3];
 
102112 for(i=0; i<nArg; i++){
102113 assert( memIsValid(pX) );
102114 memAboutToChange(p, pX);
102115 apArg[i] = pX;
102116 pX++;
@@ -102952,16 +103295,12 @@
102952 }
102953 pBlob->pTab = pTab;
102954 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
102955
102956 /* Now search pTab for the exact column. */
102957 for(iCol=0; iCol<pTab->nCol; iCol++) {
102958 if( sqlite3StrICmp(pTab->aCol[iCol].zCnName, zColumn)==0 ){
102959 break;
102960 }
102961 }
102962 if( iCol==pTab->nCol ){
102963 sqlite3DbFree(db, zErr);
102964 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
102965 rc = SQLITE_ERROR;
102966 sqlite3BtreeLeaveAll(db);
102967 goto blob_open_out;
@@ -107503,11 +107842,10 @@
107503 SrcItem *pMatch = 0; /* The matching pSrcList item */
107504 NameContext *pTopNC = pNC; /* First namecontext in the list */
107505 Schema *pSchema = 0; /* Schema of the expression */
107506 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
107507 Table *pTab = 0; /* Table holding the row */
107508 Column *pCol; /* A column of pTab */
107509 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
107510 const char *zCol = pRight->u.zToken;
107511
107512 assert( pNC ); /* the name context cannot be NULL. */
107513 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -107554,11 +107892,10 @@
107554 ExprList *pEList;
107555 SrcList *pSrcList = pNC->pSrcList;
107556
107557 if( pSrcList ){
107558 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
107559 u8 hCol;
107560 pTab = pItem->pSTab;
107561 assert( pTab!=0 && pTab->zName!=0 );
107562 assert( pTab->nCol>0 || pParse->nErr );
107563 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem));
107564 if( pItem->fg.isNestedFrom ){
@@ -107642,47 +107979,42 @@
107642 assert( ExprUseYTab(pExpr) );
107643 if( IN_RENAME_OBJECT && pItem->zAlias ){
107644 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
107645 }
107646 }
107647 hCol = sqlite3StrIHash(zCol);
107648 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
107649 if( pCol->hName==hCol
107650 && sqlite3StrICmp(pCol->zCnName, zCol)==0
107651 ){
107652 if( cnt>0 ){
107653 if( pItem->fg.isUsing==0
107654 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107655 ){
107656 /* Two or more tables have the same column name which is
107657 ** not joined by USING. This is an error. Signal as much
107658 ** by clearing pFJMatch and letting cnt go above 1. */
107659 sqlite3ExprListDelete(db, pFJMatch);
107660 pFJMatch = 0;
107661 }else
107662 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107663 /* An INNER or LEFT JOIN. Use the left-most table */
107664 continue;
107665 }else
107666 if( (pItem->fg.jointype & JT_LEFT)==0 ){
107667 /* A RIGHT JOIN. Use the right-most table */
107668 cnt = 0;
107669 sqlite3ExprListDelete(db, pFJMatch);
107670 pFJMatch = 0;
107671 }else{
107672 /* For a FULL JOIN, we must construct a coalesce() func */
107673 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
107674 }
107675 }
107676 cnt++;
107677 pMatch = pItem;
107678 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
107679 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
107680 if( pItem->fg.isNestedFrom ){
107681 sqlite3SrcItemColumnUsed(pItem, j);
107682 }
107683 break;
107684 }
107685 }
107686 if( 0==cnt && VisibleRowid(pTab) ){
107687 /* pTab is a potential ROWID match. Keep track of it and match
107688 ** the ROWID later if that seems appropriate. (Search for "cntTab"
@@ -107768,26 +108100,21 @@
107768 }
107769 #endif /* SQLITE_OMIT_UPSERT */
107770
107771 if( pTab ){
107772 int iCol;
107773 u8 hCol = sqlite3StrIHash(zCol);
107774 pSchema = pTab->pSchema;
107775 cntTab++;
107776 for(iCol=0, pCol=pTab->aCol; iCol<pTab->nCol; iCol++, pCol++){
107777 if( pCol->hName==hCol
107778 && sqlite3StrICmp(pCol->zCnName, zCol)==0
107779 ){
107780 if( iCol==pTab->iPKey ){
107781 iCol = -1;
107782 }
107783 break;
107784 }
107785 }
107786 if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
107787 /* IMP: R-51414-32910 */
107788 iCol = -1;
107789 }
107790 if( iCol<pTab->nCol ){
107791 cnt++;
107792 pMatch = 0;
107793 #ifndef SQLITE_OMIT_UPSERT
@@ -111379,11 +111706,10 @@
111379 pNewExpr->pLeft = pPriorSelectColNew;
111380 }
111381 }
111382 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
111383 pItem->fg = pOldItem->fg;
111384 pItem->fg.done = 0;
111385 pItem->u = pOldItem->u;
111386 }
111387 return pNew;
111388 }
111389
@@ -112496,17 +112822,11 @@
112496 SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab){
112497 const char *azOpt[] = {"_ROWID_", "ROWID", "OID"};
112498 int ii;
112499 assert( VisibleRowid(pTab) );
112500 for(ii=0; ii<ArraySize(azOpt); ii++){
112501 int iCol;
112502 for(iCol=0; iCol<pTab->nCol; iCol++){
112503 if( sqlite3_stricmp(azOpt[ii], pTab->aCol[iCol].zCnName)==0 ) break;
112504 }
112505 if( iCol==pTab->nCol ){
112506 return azOpt[ii];
112507 }
112508 }
112509 return 0;
112510 }
112511
112512 /*
@@ -117551,14 +117871,12 @@
117551
117552 /* Make sure the old name really is a column name in the table to be
117553 ** altered. Set iCol to be the index of the column being renamed */
117554 zOld = sqlite3NameFromToken(db, pOld);
117555 if( !zOld ) goto exit_rename_column;
117556 for(iCol=0; iCol<pTab->nCol; iCol++){
117557 if( 0==sqlite3StrICmp(pTab->aCol[iCol].zCnName, zOld) ) break;
117558 }
117559 if( iCol==pTab->nCol ){
117560 sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
117561 goto exit_rename_column;
117562 }
117563
117564 /* Ensure the schema contains no double-quoted strings */
@@ -119453,11 +119771,12 @@
119453 ** of the new table in register pParse->regRoot. This is important
119454 ** because the OpenWrite opcode below will be needing it. */
119455 sqlite3NestedParse(pParse,
119456 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
119457 );
119458 aRoot[i] = (u32)pParse->regRoot;
 
119459 aCreateTbl[i] = OPFLAG_P2ISREG;
119460 }
119461 }else{
119462 /* The table already exists. If zWhere is not NULL, delete all entries
119463 ** associated with the table zWhere. If zWhere is NULL, delete the
@@ -121489,10 +121808,17 @@
121489 */
121490 if( rc==SQLITE_OK ){
121491 sqlite3BtreeEnterAll(db);
121492 db->init.iDb = 0;
121493 db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
 
 
 
 
 
 
 
121494 if( !REOPEN_AS_MEMDB(db) ){
121495 rc = sqlite3Init(db, &zErrDyn);
121496 }
121497 sqlite3BtreeLeaveAll(db);
121498 assert( zErrDyn==0 || rc!=SQLITE_OK );
@@ -122311,14 +122637,16 @@
122311 }
122312 assert( !pParse->isMultiWrite
122313 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
122314 if( v ){
122315 if( pParse->bReturning ){
122316 Returning *pReturning = pParse->u1.pReturning;
122317 int addrRewind;
122318 int reg;
122319
 
 
122320 if( pReturning->nRetCol ){
122321 sqlite3VdbeAddOp0(v, OP_FkCheck);
122322 addrRewind =
122323 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
122324 VdbeCoverage(v);
@@ -122390,11 +122718,13 @@
122390 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
122391 }
122392 }
122393
122394 if( pParse->bReturning ){
122395 Returning *pRet = pParse->u1.pReturning;
 
 
122396 if( pRet->nRetCol ){
122397 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
122398 }
122399 }
122400
@@ -123462,12 +123792,13 @@
123462 #endif
123463
123464 /* If the file format and encoding in the database have not been set,
123465 ** set them now.
123466 */
123467 reg1 = pParse->regRowid = ++pParse->nMem;
123468 reg2 = pParse->regRoot = ++pParse->nMem;
 
123469 reg3 = ++pParse->nMem;
123470 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
123471 sqlite3VdbeUsesBtree(v, iDb);
123472 addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
123473 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
@@ -123478,12 +123809,12 @@
123478
123479 /* This just creates a place-holder record in the sqlite_schema table.
123480 ** The record created does not contain anything yet. It will be replaced
123481 ** by the real entry in code generated at sqlite3EndTable().
123482 **
123483 ** The rowid for the new entry is left in register pParse->regRowid.
123484 ** The root page number of the new table is left in reg pParse->regRoot.
123485 ** The rowid and root page number values are needed by the code that
123486 ** sqlite3EndTable will generate.
123487 */
123488 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
123489 if( isView || isVirtual ){
@@ -123490,11 +123821,11 @@
123490 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
123491 }else
123492 #endif
123493 {
123494 assert( !pParse->bReturning );
123495 pParse->u1.addrCrTab =
123496 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
123497 }
123498 sqlite3OpenSchemaTable(pParse, iDb);
123499 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
123500 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
@@ -123568,11 +123899,12 @@
123568 pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
123569 if( pRet==0 ){
123570 sqlite3ExprListDelete(db, pList);
123571 return;
123572 }
123573 pParse->u1.pReturning = pRet;
 
123574 pRet->pParse = pParse;
123575 pRet->pReturnEL = pList;
123576 sqlite3ParserAddCleanup(pParse, sqlite3DeleteReturning, pRet);
123577 testcase( pParse->earlyCleanup );
123578 if( db->mallocFailed ) return;
@@ -123610,11 +123942,10 @@
123610 int i;
123611 char *z;
123612 char *zType;
123613 Column *pCol;
123614 sqlite3 *db = pParse->db;
123615 u8 hName;
123616 Column *aNew;
123617 u8 eType = COLTYPE_CUSTOM;
123618 u8 szEst = 1;
123619 char affinity = SQLITE_AFF_BLOB;
123620
@@ -123664,17 +123995,14 @@
123664 if( z==0 ) return;
123665 if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
123666 memcpy(z, sName.z, sName.n);
123667 z[sName.n] = 0;
123668 sqlite3Dequote(z);
123669 hName = sqlite3StrIHash(z);
123670 for(i=0; i<p->nCol; i++){
123671 if( p->aCol[i].hName==hName && sqlite3StrICmp(z, p->aCol[i].zCnName)==0 ){
123672 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
123673 sqlite3DbFree(db, z);
123674 return;
123675 }
123676 }
123677 aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
123678 if( aNew==0 ){
123679 sqlite3DbFree(db, z);
123680 return;
@@ -123681,11 +124009,11 @@
123681 }
123682 p->aCol = aNew;
123683 pCol = &p->aCol[p->nCol];
123684 memset(pCol, 0, sizeof(p->aCol[0]));
123685 pCol->zCnName = z;
123686 pCol->hName = hName;
123687 sqlite3ColumnPropertiesFromName(p, pCol);
123688
123689 if( sType.n==0 ){
123690 /* If there is no type specified, columns have the default affinity
123691 ** 'BLOB' with a default size of 4 bytes. */
@@ -123705,13 +124033,18 @@
123705 zType[sType.n] = 0;
123706 sqlite3Dequote(zType);
123707 pCol->affinity = sqlite3AffinityType(zType, pCol);
123708 pCol->colFlags |= COLFLAG_HASTYPE;
123709 }
 
 
 
 
123710 p->nCol++;
123711 p->nNVCol++;
123712 pParse->constraintName.n = 0;
 
123713 }
123714
123715 /*
123716 ** This routine is called by the parser while in the middle of
123717 ** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
@@ -123971,19 +124304,15 @@
123971 for(i=0; i<nTerm; i++){
123972 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
123973 assert( pCExpr!=0 );
123974 sqlite3StringToId(pCExpr);
123975 if( pCExpr->op==TK_ID ){
123976 const char *zCName;
123977 assert( !ExprHasProperty(pCExpr, EP_IntValue) );
123978 zCName = pCExpr->u.zToken;
123979 for(iCol=0; iCol<pTab->nCol; iCol++){
123980 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zCnName)==0 ){
123981 pCol = &pTab->aCol[iCol];
123982 makeColumnPartOfPrimaryKey(pParse, pCol);
123983 break;
123984 }
123985 }
123986 }
123987 }
123988 }
123989 if( nTerm==1
@@ -124031,12 +124360,14 @@
124031 sqlite3 *db = pParse->db;
124032 if( pTab && !IN_DECLARE_VTAB
124033 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
124034 ){
124035 pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr);
124036 if( pParse->constraintName.n ){
124037 sqlite3ExprListSetName(pParse, pTab->pCheck, &pParse->constraintName, 1);
 
 
124038 }else{
124039 Token t;
124040 for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
124041 while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; }
124042 t.z = zStart;
@@ -124482,13 +124813,13 @@
124482
124483 /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
124484 ** into BTREE_BLOBKEY.
124485 */
124486 assert( !pParse->bReturning );
124487 if( pParse->u1.addrCrTab ){
124488 assert( v );
124489 sqlite3VdbeChangeP3(v, pParse->u1.addrCrTab, BTREE_BLOBKEY);
124490 }
124491
124492 /* Locate the PRIMARY KEY index. Or, if this table was originally
124493 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
124494 */
@@ -124924,11 +125255,11 @@
124924 #endif
124925 }
124926
124927 /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
124928 ** statement to populate the new table. The root-page number for the
124929 ** new table is in register pParse->regRoot.
124930 **
124931 ** Once the SELECT has been coded by sqlite3Select(), it is in a
124932 ** suitable state to query for the column names and types to be used
124933 ** by the new table.
124934 **
@@ -124955,11 +125286,12 @@
124955 iCsr = pParse->nTab++;
124956 regYield = ++pParse->nMem;
124957 regRec = ++pParse->nMem;
124958 regRowid = ++pParse->nMem;
124959 sqlite3MayAbort(pParse);
124960 sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->regRoot, iDb);
 
124961 sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
124962 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
124963 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
124964 if( pParse->nErr ) return;
124965 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
@@ -125000,21 +125332,22 @@
125000
125001 /* A slot for the record has already been allocated in the
125002 ** schema table. We just need to update that slot with all
125003 ** the information we've collected.
125004 */
 
125005 sqlite3NestedParse(pParse,
125006 "UPDATE %Q." LEGACY_SCHEMA_TABLE
125007 " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
125008 " WHERE rowid=#%d",
125009 db->aDb[iDb].zDbSName,
125010 zType,
125011 p->zName,
125012 p->zName,
125013 pParse->regRoot,
125014 zStmt,
125015 pParse->regRowid
125016 );
125017 sqlite3DbFree(db, zStmt);
125018 sqlite3ChangeCookie(pParse, iDb);
125019
125020 #ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -129850,15 +130183,10 @@
129850 int len;
129851 int p0type;
129852 i64 p1, p2;
129853
129854 assert( argc==3 || argc==2 );
129855 if( sqlite3_value_type(argv[1])==SQLITE_NULL
129856 || (argc==3 && sqlite3_value_type(argv[2])==SQLITE_NULL)
129857 ){
129858 return;
129859 }
129860 p0type = sqlite3_value_type(argv[0]);
129861 p1 = sqlite3_value_int64(argv[1]);
129862 if( p0type==SQLITE_BLOB ){
129863 len = sqlite3_value_bytes(argv[0]);
129864 z = sqlite3_value_blob(argv[0]);
@@ -129872,23 +130200,27 @@
129872 for(z2=z; *z2; len++){
129873 SQLITE_SKIP_UTF8(z2);
129874 }
129875 }
129876 }
129877 #ifdef SQLITE_SUBSTR_COMPATIBILITY
129878 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
129879 ** as substr(X,1,N) - it returns the first N characters of X. This
129880 ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
129881 ** from 2009-02-02 for compatibility of applications that exploited the
129882 ** old buggy behavior. */
129883 if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
129884 #endif
129885 if( argc==3 ){
129886 p2 = sqlite3_value_int64(argv[2]);
 
129887 }else{
129888 p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
129889 }
 
 
 
 
 
 
 
 
 
 
 
129890 if( p1<0 ){
129891 p1 += len;
129892 if( p1<0 ){
129893 if( p2<0 ){
129894 p2 = 0;
@@ -134900,32 +135232,26 @@
134900 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
134901 if( pColumn ){
134902 aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int));
134903 if( aTabColMap==0 ) goto insert_cleanup;
134904 for(i=0; i<pColumn->nId; i++){
134905 const char *zCName = pColumn->a[i].zName;
134906 u8 hName = sqlite3StrIHash(zCName);
134907 for(j=0; j<pTab->nCol; j++){
134908 if( pTab->aCol[j].hName!=hName ) continue;
134909 if( sqlite3StrICmp(zCName, pTab->aCol[j].zCnName)==0 ){
134910 if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
134911 if( i!=j ) bIdListInOrder = 0;
134912 if( j==pTab->iPKey ){
134913 ipkColumn = i; assert( !withoutRowid );
134914 }
134915 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
134916 if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
134917 sqlite3ErrorMsg(pParse,
134918 "cannot INSERT into generated column \"%s\"",
134919 pTab->aCol[j].zCnName);
134920 goto insert_cleanup;
134921 }
134922 #endif
134923 break;
134924 }
134925 }
134926 if( j>=pTab->nCol ){
134927 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
134928 ipkColumn = i;
134929 bIdListInOrder = 0;
134930 }else{
134931 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
@@ -135219,11 +135545,11 @@
135219 sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
135220 }
135221 continue;
135222 }else if( pColumn==0 ){
135223 /* Hidden columns that are not explicitly named in the INSERT
135224 ** get there default value */
135225 sqlite3ExprCodeFactorable(pParse,
135226 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135227 iRegStore);
135228 continue;
135229 }
@@ -144166,14 +144492,37 @@
144166 ** Return the index of a column in a table. Return -1 if the column
144167 ** is not contained in the table.
144168 */
144169 SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
144170 int i;
144171 u8 h = sqlite3StrIHash(zCol);
144172 Column *pCol;
144173 for(pCol=pTab->aCol, i=0; i<pTab->nCol; pCol++, i++){
144174 if( pCol->hName==h && sqlite3StrICmp(pCol->zCnName, zCol)==0 ) return i;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144175 }
144176 return -1;
144177 }
144178
144179 /*
@@ -152891,11 +153240,12 @@
152891 }else if( pTrig->op==TK_RETURNING ){
152892 #ifndef SQLITE_OMIT_VIRTUALTABLE
152893 assert( pParse->db->pVtabCtx==0 );
152894 #endif
152895 assert( pParse->bReturning );
152896 assert( &(pParse->u1.pReturning->retTrig) == pTrig );
 
152897 pTrig->table = pTab->zName;
152898 pTrig->pTabSchema = pTab->pSchema;
152899 pTrig->pNext = pList;
152900 pList = pTrig;
152901 }
@@ -153868,11 +154218,12 @@
153868 /* This RETURNING trigger must be for a different statement as
153869 ** this statement lacks a RETURNING clause. */
153870 return;
153871 }
153872 assert( db->pParse==pParse );
153873 pReturning = pParse->u1.pReturning;
 
153874 if( pTrigger != &(pReturning->retTrig) ){
153875 /* This RETURNING trigger is for a different statement */
153876 return;
153877 }
153878 memset(&sSelect, 0, sizeof(sSelect));
@@ -154098,10 +154449,12 @@
154098 sSubParse.pToplevel = pTop;
154099 sSubParse.zAuthContext = pTrigger->zName;
154100 sSubParse.eTriggerOp = pTrigger->op;
154101 sSubParse.nQueryLoop = pParse->nQueryLoop;
154102 sSubParse.prepFlags = pParse->prepFlags;
 
 
154103
154104 v = sqlite3GetVdbe(&sSubParse);
154105 if( v ){
154106 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
154107 pTrigger->zName, onErrorText(orconf),
@@ -154852,42 +155205,36 @@
154852 ** column to be updated, make sure we have authorization to change
154853 ** that column.
154854 */
154855 chngRowid = chngPk = 0;
154856 for(i=0; i<pChanges->nExpr; i++){
154857 u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName);
154858 /* If this is an UPDATE with a FROM clause, do not resolve expressions
154859 ** here. The call to sqlite3Select() below will do that. */
154860 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
154861 goto update_cleanup;
154862 }
154863 for(j=0; j<pTab->nCol; j++){
154864 if( pTab->aCol[j].hName==hCol
154865 && sqlite3StrICmp(pTab->aCol[j].zCnName, pChanges->a[i].zEName)==0
154866 ){
154867 if( j==pTab->iPKey ){
154868 chngRowid = 1;
154869 pRowidExpr = pChanges->a[i].pExpr;
154870 iRowidExpr = i;
154871 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
154872 chngPk = 1;
154873 }
154874 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
154875 else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
154876 testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
154877 testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
154878 sqlite3ErrorMsg(pParse,
154879 "cannot UPDATE generated column \"%s\"",
154880 pTab->aCol[j].zCnName);
154881 goto update_cleanup;
154882 }
154883 #endif
154884 aXRef[j] = i;
154885 break;
154886 }
154887 }
154888 if( j>=pTab->nCol ){
154889 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
154890 j = -1;
154891 chngRowid = 1;
154892 pRowidExpr = pChanges->a[i].pExpr;
154893 iRowidExpr = i;
@@ -156990,24 +157337,25 @@
156990
156991 /* A slot for the record has already been allocated in the
156992 ** schema table. We just need to update that slot with all
156993 ** the information we've collected.
156994 **
156995 ** The VM register number pParse->regRowid holds the rowid of an
156996 ** entry in the sqlite_schema table that was created for this vtab
156997 ** by sqlite3StartTable().
156998 */
156999 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
 
157000 sqlite3NestedParse(pParse,
157001 "UPDATE %Q." LEGACY_SCHEMA_TABLE " "
157002 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
157003 "WHERE rowid=#%d",
157004 db->aDb[iDb].zDbSName,
157005 pTab->zName,
157006 pTab->zName,
157007 zStmt,
157008 pParse->regRowid
157009 );
157010 v = sqlite3GetVdbe(pParse);
157011 sqlite3ChangeCookie(pParse, iDb);
157012
157013 sqlite3VdbeAddOp0(v, OP_Expire);
@@ -160161,10 +160509,13 @@
160161 }
160162 }
160163 }
160164 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
160165 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
 
 
 
160166 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
160167 pLoop->u.vtab.idxStr,
160168 pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
160169 VdbeCoverage(v);
160170 pLoop->u.vtab.needFree = 0;
@@ -174215,10 +174566,15 @@
174215 ** to the original parse.y sources.
174216 */
174217
174218 /* #include "sqliteInt.h" */
174219
 
 
 
 
 
174220 /*
174221 ** Disable all error recovery processing in the parser push-down
174222 ** automaton.
174223 */
174224 #define YYNOERRORRECOVERY 1
@@ -174278,10 +174634,14 @@
174278 ** shared across database connections.
174279 */
174280 static void disableLookaside(Parse *pParse){
174281 sqlite3 *db = pParse->db;
174282 pParse->disableLookaside++;
 
 
 
 
174283 DisableLookaside;
174284 }
174285
174286 #if !defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) \
174287 && defined(SQLITE_UDL_CAPABLE_PARSER)
@@ -177914,11 +178274,13 @@
177914 {
177915 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[-2].minor.yy502);
177916 }
177917 break;
177918 case 14: /* createkw ::= CREATE */
177919 {disableLookaside(pParse);}
 
 
177920 break;
177921 case 15: /* ifnotexists ::= */
177922 case 18: /* temp ::= */ yytestcase(yyruleno==18);
177923 case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
177924 case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
@@ -178006,11 +178368,11 @@
178006 yymsp[1].minor.yy0 = yyLookaheadToken;
178007 }
178008 break;
178009 case 32: /* ccons ::= CONSTRAINT nm */
178010 case 67: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==67);
178011 {pParse->constraintName = yymsp[0].minor.yy0;}
178012 break;
178013 case 33: /* ccons ::= DEFAULT scantok term */
178014 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);}
178015 break;
178016 case 34: /* ccons ::= DEFAULT LP expr RP */
@@ -178116,11 +178478,11 @@
178116 break;
178117 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
178118 {yymsp[-1].minor.yy502 = 0;}
178119 break;
178120 case 66: /* tconscomma ::= COMMA */
178121 {pParse->constraintName.n = 0;}
178122 break;
178123 case 68: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
178124 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);}
178125 break;
178126 case 69: /* tcons ::= UNIQUE LP sortlist RP onconf */
@@ -179009,10 +179371,14 @@
179009 break;
179010 case 261: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
179011 {
179012 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy502, yymsp[-4].minor.yy28.a, yymsp[-4].minor.yy28.b, yymsp[-2].minor.yy563, yymsp[0].minor.yy590, yymsp[-10].minor.yy502, yymsp[-8].minor.yy502);
179013 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
 
 
 
 
179014 }
179015 break;
179016 case 262: /* trigger_time ::= BEFORE|AFTER */
179017 { yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ }
179018 break;
@@ -183305,10 +183671,13 @@
183305 sqlite3_mutex_enter(db->mutex);
183306 db->busyHandler.xBusyHandler = xBusy;
183307 db->busyHandler.pBusyArg = pArg;
183308 db->busyHandler.nBusy = 0;
183309 db->busyTimeout = 0;
 
 
 
183310 sqlite3_mutex_leave(db->mutex);
183311 return SQLITE_OK;
183312 }
183313
183314 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -183354,15 +183723,46 @@
183354 #endif
183355 if( ms>0 ){
183356 sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
183357 (void*)db);
183358 db->busyTimeout = ms;
 
 
 
183359 }else{
183360 sqlite3_busy_handler(db, 0, 0);
183361 }
183362 return SQLITE_OK;
183363 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183364
183365 /*
183366 ** Cause any pending operation to stop at its earliest opportunity.
183367 */
183368 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
@@ -185479,17 +185879,14 @@
185479
185480 /* Find the column for which info is requested */
185481 if( zColumnName==0 ){
185482 /* Query for existence of table only */
185483 }else{
185484 for(iCol=0; iCol<pTab->nCol; iCol++){
 
185485 pCol = &pTab->aCol[iCol];
185486 if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
185487 break;
185488 }
185489 }
185490 if( iCol==pTab->nCol ){
185491 if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
185492 iCol = pTab->iPKey;
185493 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
185494 }else{
185495 pTab = 0;
@@ -208697,14 +209094,11 @@
208697 */
208698 static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){
208699 u8 x;
208700 u32 sz;
208701 u32 n;
208702 if( NEVER(i>pParse->nBlob) ){
208703 *pSz = 0;
208704 return 0;
208705 }
208706 x = pParse->aBlob[i]>>4;
208707 if( x<=11 ){
208708 sz = x;
208709 n = 1;
208710 }else if( x==12 ){
@@ -208744,12 +209138,12 @@
208744 n = 9;
208745 }
208746 if( (i64)i+sz+n > pParse->nBlob
208747 && (i64)i+sz+n > pParse->nBlob-pParse->delta
208748 ){
208749 sz = 0;
208750 n = 0;
208751 }
208752 *pSz = sz;
208753 return n;
208754 }
208755
@@ -208842,13 +209236,16 @@
208842 }
208843 break;
208844 }
208845 case JSONB_TEXT:
208846 case JSONB_TEXTJ: {
208847 jsonAppendChar(pOut, '"');
208848 jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz);
208849 jsonAppendChar(pOut, '"');
 
 
 
208850 break;
208851 }
208852 case JSONB_TEXT5: {
208853 const char *zIn;
208854 u32 k;
@@ -255870,11 +256267,11 @@
255870 int nArg, /* Number of args */
255871 sqlite3_value **apUnused /* Function arguments */
255872 ){
255873 assert( nArg==0 );
255874 UNUSED_PARAM2(nArg, apUnused);
255875 sqlite3_result_text(pCtx, "fts5: 2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde", -1, SQLITE_TRANSIENT);
255876 }
255877
255878 /*
255879 ** Implementation of fts5_locale(LOCALE, TEXT) function.
255880 **
255881
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.50.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** e5ec5bb9f4dc3e02db7ab0e49686f47617af with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -463,13 +463,13 @@
463 **
464 ** See also: [sqlite3_libversion()],
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.50.0"
469 #define SQLITE_VERSION_NUMBER 3050000
470 #define SQLITE_SOURCE_ID "2025-02-11 17:10:46 e5ec5bb9f4dc3e02db7ab0e49686f47617af75d3f7d4ab23288a1aea4a693e59"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -1480,10 +1480,15 @@
1480 ** obtain a file lock using the xLock or xShmLock methods of the VFS.
1481 ** The parameter is a pointer to a 32-bit signed integer that contains
1482 ** the value that M is to be set to. Before returning, the 32-bit signed
1483 ** integer is overwritten with the previous value of M.
1484 **
1485 ** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]
1486 ** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the
1487 ** VFS to block when taking SHARED locks. This is used to implement the
1488 ** functionality associated with SQLITE_SETLK_BLOCK_ON_CONNECT.
1489 **
1490 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1491 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1492 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
1493 ** The "data version" for the pager is written into the pointer. The
1494 ** "data version" changes whenever any change occurs to the corresponding
@@ -1576,10 +1581,11 @@
1581 #define SQLITE_FCNTL_CKPT_START 39
1582 #define SQLITE_FCNTL_EXTERNAL_READER 40
1583 #define SQLITE_FCNTL_CKSM_FILE 41
1584 #define SQLITE_FCNTL_RESET_CACHE 42
1585 #define SQLITE_FCNTL_NULL_IO 43
1586 #define SQLITE_FCNTL_BLOCK_ON_CONNECT 44
1587
1588 /* deprecated names */
1589 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1590 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1591 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3310,10 +3316,48 @@
3316 **
3317 ** See also: [PRAGMA busy_timeout]
3318 */
3319 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
3320
3321 /*
3322 ** CAPI3REF: Set the Setlk Timeout
3323 ** METHOD: sqlite3
3324 **
3325 ** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If
3326 ** the VFS supports blocking locks, it sets the timeout in ms used by
3327 ** eligible locks taken on wal mode databases by the specified database
3328 ** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does
3329 ** not support blocking locks, this function is a no-op.
3330 **
3331 ** Passing 0 to this function disables blocking locks altogether. Passing
3332 ** -1 to this function requests that the VFS blocks for a long time -
3333 ** indefinitely if possible. The results of passing any other negative value
3334 ** are undefined.
3335 **
3336 ** Internally, each SQLite database handle store two timeout values - the
3337 ** busy-timeout (used for rollback mode databases, or if the VFS does not
3338 ** support blocking locks) and the setlk-timeout (used for blocking locks
3339 ** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3340 ** values, this function sets only the setlk-timeout value. Therefore,
3341 ** to configure separate busy-timeout and setlk-timeout values for a single
3342 ** database handle, call sqlite3_busy_timeout() followed by this function.
3343 **
3344 ** Whenever the number of connections to a wal mode database falls from
3345 ** 1 to 0, the last connection takes an exclusive lock on the database,
3346 ** then checkpoints and deletes the wal file. While it is doing this, any
3347 ** new connection that tries to read from the database fails with an
3348 ** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is
3349 ** passed to this API, the new connection blocks until the exclusive lock
3350 ** has been released.
3351 */
3352 SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);
3353
3354 /*
3355 ** CAPI3REF: Flags for sqlite3_setlk_timeout()
3356 */
3357 #define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01
3358
3359 /*
3360 ** CAPI3REF: Convenience Routines For Running Queries
3361 ** METHOD: sqlite3
3362 **
3363 ** This is a legacy interface that is preserved for backwards compatibility.
@@ -14747,10 +14791,11 @@
14791 */
14792 struct HashElem {
14793 HashElem *next, *prev; /* Next and previous elements in the table */
14794 void *data; /* Data associated with this element */
14795 const char *pKey; /* Key associated with this element */
14796 unsigned int h; /* hash for pKey */
14797 };
14798
14799 /*
14800 ** Access routines. To delete, insert a NULL pointer.
14801 */
@@ -15184,10 +15229,15 @@
15229 typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
15230 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
15231 typedef INT16_TYPE i16; /* 2-byte signed integer */
15232 typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
15233 typedef INT8_TYPE i8; /* 1-byte signed integer */
15234
15235 /* A bitfield type for use inside of structures. Always follow with :N where
15236 ** N is the number of bits.
15237 */
15238 typedef unsigned bft; /* Bit Field Type */
15239
15240 /*
15241 ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
15242 ** that can be stored in a u32 without loss of data. The value
15243 ** is 0x00000000ffffffff. But because of quirks of some compilers, we
@@ -18053,10 +18103,14 @@
18103 BusyHandler busyHandler; /* Busy callback */
18104 Db aDbStatic[2]; /* Static space for the 2 default backends */
18105 Savepoint *pSavepoint; /* List of active savepoints */
18106 int nAnalysisLimit; /* Number of index rows to ANALYZE */
18107 int busyTimeout; /* Busy handler timeout, in msec */
18108 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
18109 int setlkTimeout; /* Blocking lock timeout, in msec. -1 -> inf. */
18110 int setlkFlags; /* Flags passed to setlk_timeout() */
18111 #endif
18112 int nSavepoint; /* Number of non-transaction savepoints */
18113 int nStatement; /* Number of nested statement-transactions */
18114 i64 nDeferredCons; /* Net deferred constraints this transaction. */
18115 i64 nDeferredImmCons; /* Net deferred immediate constraints */
18116 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
@@ -18731,10 +18785,11 @@
18785 VTable *p; /* List of VTable objects. */
18786 } vtab;
18787 } u;
18788 Trigger *pTrigger; /* List of triggers on this object */
18789 Schema *pSchema; /* Schema that contains this table */
18790 u8 aHx[16]; /* Column aHt[K%sizeof(aHt)] might have hash K */
18791 };
18792
18793 /*
18794 ** Allowed values for Table.tabFlags.
18795 **
@@ -20128,29 +20183,36 @@
20183 struct Parse {
20184 sqlite3 *db; /* The main database structure */
20185 char *zErrMsg; /* An error message */
20186 Vdbe *pVdbe; /* An engine for executing database bytecode */
20187 int rc; /* Return code from execution */
20188 LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
 
20189 u8 nested; /* Number of nested calls to the parser/code generator */
20190 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
20191 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
20192 u8 mayAbort; /* True if statement may throw an ABORT exception */
20193 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
 
20194 u8 disableLookaside; /* Number of times lookaside has been disabled */
20195 u8 prepFlags; /* SQLITE_PREPARE_* flags */
20196 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
 
20197 u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20198 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20199 u8 bReturning; /* Coding a RETURNING trigger */
20200 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20201 u8 disableTriggers; /* True to disable triggers */
20202 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
20203 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
20204 #endif
20205 #ifdef SQLITE_DEBUG
20206 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
20207 u8 isCreate; /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
20208 ** and ALTER TABLE ADD COLUMN. */
20209 #endif
20210 bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20211 bft bHasWith :1; /* True if statement contains WITH */
20212 bft okConstFactor :1; /* OK to factor out constants */
20213 bft checkSchema :1; /* Causes schema cookie check after an error */
20214 int nRangeReg; /* Size of the temporary register block */
20215 int iRangeReg; /* First register in temporary register block */
20216 int nErr; /* Number of errors seen */
20217 int nTab; /* Number of previously allocated VDBE cursors */
20218 int nMem; /* Number of memory cells used so far */
@@ -20161,16 +20223,13 @@
20223 int nLabelAlloc; /* Number of slots in aLabel */
20224 int *aLabel; /* Space to hold the labels */
20225 ExprList *pConstExpr;/* Constant expressions */
20226 IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
20227 IndexedExpr *pIdxPartExpr; /* Exprs constrained by index WHERE clauses */
 
20228 yDbMask writeMask; /* Start a write transaction on these databases */
20229 yDbMask cookieMask; /* Bitmask of schema verified databases */
20230 int nMaxArg; /* Max args to xUpdate and xFilter vtab methods */
 
 
20231 int nSelect; /* Number of SELECT stmts. Counter for Select.selId */
20232 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
20233 u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
20234 #endif
20235 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -20180,21 +20239,10 @@
20239 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
20240 Parse *pToplevel; /* Parse structure for main program (or NULL) */
20241 Table *pTriggerTab; /* Table triggers are being coded for */
20242 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
20243 ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
 
 
 
 
 
 
 
 
 
 
 
20244
20245 /**************************************************************************
20246 ** Fields above must be initialized to zero. The fields that follow,
20247 ** down to the beginning of the recursive section, do not need to be
20248 ** initialized as they will be set before being used. The boundary is
@@ -20202,10 +20250,23 @@
20250 **************************************************************************/
20251
20252 int aTempReg[8]; /* Holding area for temporary registers */
20253 Parse *pOuterParse; /* Outer Parse object when nested */
20254 Token sNameToken; /* Token with unqualified schema object name */
20255 u32 oldmask; /* Mask of old.* columns referenced */
20256 u32 newmask; /* Mask of new.* columns referenced */
20257 union {
20258 struct { /* These fields available when isCreate is true */
20259 int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
20260 int regRowid; /* Register holding rowid of CREATE TABLE entry */
20261 int regRoot; /* Register holding root page for new objects */
20262 Token constraintName; /* Name of the constraint currently being parsed */
20263 } cr;
20264 struct { /* These fields available to all other statements */
20265 Returning *pReturning; /* The RETURNING clause */
20266 } d;
20267 } u1;
20268
20269 /************************************************************************
20270 ** Above is constant between recursions. Below is reset before and after
20271 ** each recursion. The boundary between these two regions is determined
20272 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -23831,14 +23892,10 @@
23892 u8 skipFlag; /* Skip accumulator loading if true */
23893 u16 argc; /* Number of arguments */
23894 sqlite3_value *argv[1]; /* Argument set */
23895 };
23896
 
 
 
 
23897
23898 /* The ScanStatus object holds a single value for the
23899 ** sqlite3_stmt_scanstatus() interface.
23900 **
23901 ** aAddrRange[]:
@@ -23895,11 +23952,11 @@
23952 i64 iCurrentTime; /* Value of julianday('now') for this statement */
23953 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
23954 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
23955 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
23956 Mem *aMem; /* The memory locations */
23957 Mem **apArg; /* Arguments xUpdate and xFilter vtab methods */
23958 VdbeCursor **apCsr; /* One element of this array for each open cursor */
23959 Mem *aVar; /* Values for the OP_Variable opcode. */
23960
23961 /* When allocating a new Vdbe object, all of the fields below should be
23962 ** initialized to zero or NULL */
@@ -23915,10 +23972,11 @@
23972 i64 startTime; /* Time when query started - used for profiling */
23973 #endif
23974 #ifdef SQLITE_DEBUG
23975 int rcApp; /* errcode set by sqlite3_result_error_code() */
23976 u32 nWrite; /* Number of write operations that have occurred */
23977 int napArg; /* Size of the apArg[] array */
23978 #endif
23979 u16 nResColumn; /* Number of columns in one row of the result set */
23980 u16 nResAlloc; /* Column slots allocated to aColName[] */
23981 u8 errorAction; /* Recovery action to do in case of an error */
23982 u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -36398,11 +36456,15 @@
36456 }
36457 }
36458 }
36459 p->z = &p->zBuf[i+1];
36460 assert( i+p->n < sizeof(p->zBuf) );
36461 assert( p->n>0 );
36462 while( p->z[p->n-1]=='0' ){
36463 p->n--;
36464 assert( p->n>0 );
36465 }
36466 }
36467
36468 /*
36469 ** Try to convert z into an unsigned 32-bit integer. Return true on
36470 ** success and false if there is an error.
@@ -37184,16 +37246,23 @@
37246 /*
37247 ** The hashing function.
37248 */
37249 static unsigned int strHash(const char *z){
37250 unsigned int h = 0;
37251 while( z[0] ){ /*OPTIMIZATION-IF-TRUE*/
 
37252 /* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
37253 ** 0x9e3779b1 is 2654435761 which is the closest prime number to
37254 ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2.
37255 **
37256 ** Only bits 0xdf for ASCII and bits 0xbf for EBCDIC each octet are
37257 ** hashed since the omitted bits determine the upper/lower case difference.
37258 */
37259 #ifdef SQLITE_EBCDIC
37260 h += 0xbf & (unsigned char)*(z++);
37261 #else
37262 h += 0xdf & (unsigned char)*(z++);
37263 #endif
37264 h *= 0x9e3779b1;
37265 }
37266 return h;
37267 }
37268
@@ -37262,13 +37331,12 @@
37331 sqlite3_free(pH->ht);
37332 pH->ht = new_ht;
37333 pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
37334 memset(new_ht, 0, new_size*sizeof(struct _ht));
37335 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
 
37336 next_elem = elem->next;
37337 insertElement(pH, &new_ht[elem->h % new_size], elem);
37338 }
37339 return 1;
37340 }
37341
37342 /* This function (for internal use only) locates an element in an
@@ -37282,27 +37350,26 @@
37350 unsigned int *pHash /* Write the hash value here */
37351 ){
37352 HashElem *elem; /* Used to loop thru the element list */
37353 unsigned int count; /* Number of elements left to test */
37354 unsigned int h; /* The computed hash */
37355 static HashElem nullElement = { 0, 0, 0, 0, 0 };
37356
37357 h = strHash(pKey);
37358 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
37359 struct _ht *pEntry;
37360 pEntry = &pH->ht[h % pH->htsize];
 
37361 elem = pEntry->chain;
37362 count = pEntry->count;
37363 }else{
 
37364 elem = pH->first;
37365 count = pH->count;
37366 }
37367 if( pHash ) *pHash = h;
37368 while( count ){
37369 assert( elem!=0 );
37370 if( h==elem->h && sqlite3StrICmp(elem->pKey,pKey)==0 ){
37371 return elem;
37372 }
37373 elem = elem->next;
37374 count--;
37375 }
@@ -37310,14 +37377,13 @@
37377 }
37378
37379 /* Remove a single entry from the hash table given a pointer to that
37380 ** element and a hash on the element's key.
37381 */
37382 static void removeElement(
37383 Hash *pH, /* The pH containing "elem" */
37384 HashElem *elem /* The element to be removed from the pH */
 
37385 ){
37386 struct _ht *pEntry;
37387 if( elem->prev ){
37388 elem->prev->next = elem->next;
37389 }else{
@@ -37325,11 +37391,11 @@
37391 }
37392 if( elem->next ){
37393 elem->next->prev = elem->prev;
37394 }
37395 if( pH->ht ){
37396 pEntry = &pH->ht[elem->h % pH->htsize];
37397 if( pEntry->chain==elem ){
37398 pEntry->chain = elem->next;
37399 }
37400 assert( pEntry->count>0 );
37401 pEntry->count--;
@@ -37376,11 +37442,11 @@
37442 assert( pKey!=0 );
37443 elem = findElementWithHash(pH,pKey,&h);
37444 if( elem->data ){
37445 void *old_data = elem->data;
37446 if( data==0 ){
37447 removeElement(pH,elem);
37448 }else{
37449 elem->data = data;
37450 elem->pKey = pKey;
37451 }
37452 return old_data;
@@ -37387,19 +37453,17 @@
37453 }
37454 if( data==0 ) return 0;
37455 new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
37456 if( new_elem==0 ) return data;
37457 new_elem->pKey = pKey;
37458 new_elem->h = h;
37459 new_elem->data = data;
37460 pH->count++;
37461 if( pH->count>=5 && pH->count > 2*pH->htsize ){
37462 rehash(pH, pH->count*3);
 
 
 
37463 }
37464 insertElement(pH, pH->ht ? &pH->ht[new_elem->h % pH->htsize] : 0, new_elem);
37465 return 0;
37466 }
37467
37468 /************** End of hash.c ************************************************/
37469 /************** Begin file opcodes.c *****************************************/
@@ -38878,10 +38942,11 @@
38942 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
38943 unsigned fsFlags; /* cached details from statfs() */
38944 #endif
38945 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
38946 unsigned iBusyTimeout; /* Wait this many millisec on locks */
38947 int bBlockOnConnect; /* True to block for SHARED locks */
38948 #endif
38949 #if OS_VXWORKS
38950 struct vxworksFileId *pId; /* Unique file ID */
38951 #endif
38952 #ifdef SQLITE_DEBUG
@@ -40271,10 +40336,17 @@
40336 pInode->nLock++;
40337 }else{
40338 rc = 0;
40339 }
40340 }else{
40341 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
40342 if( pFile->bBlockOnConnect && pLock->l_type==F_RDLCK
40343 && pLock->l_start==SHARED_FIRST && pLock->l_len==SHARED_SIZE
40344 ){
40345 rc = osFcntl(pFile->h, F_SETLKW, pLock);
40346 }else
40347 #endif
40348 rc = osSetPosixAdvisoryLock(pFile->h, pLock, pFile);
40349 }
40350 return rc;
40351 }
40352
@@ -42632,21 +42704,27 @@
42704 return SQLITE_OK;
42705 }
42706 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
42707 case SQLITE_FCNTL_LOCK_TIMEOUT: {
42708 int iOld = pFile->iBusyTimeout;
42709 int iNew = *(int*)pArg;
42710 #if SQLITE_ENABLE_SETLK_TIMEOUT==1
42711 pFile->iBusyTimeout = iNew<0 ? 0x7FFFFFFF : (unsigned)iNew;
42712 #elif SQLITE_ENABLE_SETLK_TIMEOUT==2
42713 pFile->iBusyTimeout = !!(*(int*)pArg);
42714 #else
42715 # error "SQLITE_ENABLE_SETLK_TIMEOUT must be set to 1 or 2"
42716 #endif
42717 *(int*)pArg = iOld;
42718 return SQLITE_OK;
42719 }
42720 case SQLITE_FCNTL_BLOCK_ON_CONNECT: {
42721 int iNew = *(int*)pArg;
42722 pFile->bBlockOnConnect = iNew;
42723 return SQLITE_OK;
42724 }
42725 #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
42726 #if SQLITE_MAX_MMAP_SIZE>0
42727 case SQLITE_FCNTL_MMAP_SIZE: {
42728 i64 newLimit = *(i64*)pArg;
42729 int rc = SQLITE_OK;
42730 if( newLimit>sqlite3GlobalConfig.mxMmap ){
@@ -47155,11 +47233,21 @@
47233 HANDLE hMap; /* Handle for accessing memory mapping */
47234 void *pMapRegion; /* Area memory mapped */
47235 sqlite3_int64 mmapSize; /* Size of mapped region */
47236 sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
47237 #endif
47238 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
47239 DWORD iBusyTimeout; /* Wait this many millisec on locks */
47240 int bBlockOnConnect;
47241 #endif
47242 };
47243
47244 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
47245 # define winFileBusyTimeout(pDbFd) pDbFd->iBusyTimeout
47246 #else
47247 # define winFileBusyTimeout(pDbFd) 0
47248 #endif
47249
47250 /*
47251 ** The winVfsAppData structure is used for the pAppData member for all of the
47252 ** Win32 VFS variants.
47253 */
@@ -47590,10 +47678,16 @@
47678 #endif
47679
47680 #define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
47681 LPWSTR*))aSyscall[25].pCurrent)
47682
47683 /*
47684 ** For GetLastError(), MSDN says:
47685 **
47686 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
47687 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
47688 */
47689 { "GetLastError", (SYSCALL)GetLastError, 0 },
47690
47691 #define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
47692
47693 #if !defined(SQLITE_OMIT_LOAD_EXTENSION)
@@ -47872,15 +47966,17 @@
47966 #endif
47967
47968 #define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
47969 DWORD,DWORD))aSyscall[62].pCurrent)
47970
47971 /*
47972 ** For WaitForSingleObject(), MSDN says:
47973 **
47974 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
47975 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
47976 */
47977 { "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
 
 
 
47978
47979 #define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
47980 DWORD))aSyscall[63].pCurrent)
47981
47982 #if !SQLITE_OS_WINCE
@@ -48023,10 +48119,44 @@
48119 #endif
48120
48121 #define osFlushViewOfFile \
48122 ((BOOL(WINAPI*)(LPCVOID,SIZE_T))aSyscall[79].pCurrent)
48123
48124 /*
48125 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CreateEvent()
48126 ** to implement blocking locks with timeouts. MSDN says:
48127 **
48128 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
48129 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
48130 */
48131 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
48132 { "CreateEvent", (SYSCALL)CreateEvent, 0 },
48133 #else
48134 { "CreateEvent", (SYSCALL)0, 0 },
48135 #endif
48136
48137 #define osCreateEvent ( \
48138 (HANDLE(WINAPI*) (LPSECURITY_ATTRIBUTES,BOOL,BOOL,LPCSTR)) \
48139 aSyscall[80].pCurrent \
48140 )
48141
48142 /*
48143 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined, we require CancelIo()
48144 ** for the case where a timeout expires and a lock request must be
48145 ** cancelled.
48146 **
48147 ** Minimum supported client: Windows XP [desktop apps | UWP apps]
48148 ** Minimum supported server: Windows Server 2003 [desktop apps | UWP apps]
48149 */
48150 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
48151 { "CancelIo", (SYSCALL)CancelIo, 0 },
48152 #else
48153 { "CancelIo", (SYSCALL)0, 0 },
48154 #endif
48155
48156 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[81].pCurrent)
48157
48158 }; /* End of the overrideable system calls */
48159
48160 /*
48161 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
48162 ** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -48321,11 +48451,13 @@
48451 (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
48452 #endif
48453 }
48454 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
48455 #elif SQLITE_TEST
48456 return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2
48457 || osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0
48458 ;
48459 #else
48460 /*
48461 ** NOTE: All sub-platforms where the GetVersionEx[AW] functions are
48462 ** deprecated are always assumed to be based on the NT kernel.
48463 */
@@ -49407,10 +49539,89 @@
49539 return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49540 numBytesHigh);
49541 }
49542 #endif
49543 }
49544
49545 /*
49546 ** Lock a region of nByte bytes starting at offset offset of file hFile.
49547 ** Take an EXCLUSIVE lock if parameter bExclusive is true, or a SHARED lock
49548 ** otherwise. If nMs is greater than zero and the lock cannot be obtained
49549 ** immediately, block for that many ms before giving up.
49550 **
49551 ** This function returns SQLITE_OK if the lock is obtained successfully. If
49552 ** some other process holds the lock, SQLITE_BUSY is returned if nMs==0, or
49553 ** SQLITE_BUSY_TIMEOUT otherwise. Or, if an error occurs, SQLITE_IOERR.
49554 */
49555 static int winHandleLockTimeout(
49556 HANDLE hFile,
49557 DWORD offset,
49558 DWORD nByte,
49559 int bExcl,
49560 DWORD nMs
49561 ){
49562 DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | (bExcl?LOCKFILE_EXCLUSIVE_LOCK:0);
49563 int rc = SQLITE_OK;
49564 BOOL ret;
49565
49566 if( !osIsNT() ){
49567 ret = winLockFile(&hFile, flags, offset, 0, nByte, 0);
49568 }else{
49569 OVERLAPPED ovlp;
49570 memset(&ovlp, 0, sizeof(OVERLAPPED));
49571 ovlp.Offset = offset;
49572
49573 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49574 if( nMs!=0 ){
49575 flags &= ~LOCKFILE_FAIL_IMMEDIATELY;
49576 }
49577 ovlp.hEvent = osCreateEvent(NULL, TRUE, FALSE, NULL);
49578 if( ovlp.hEvent==NULL ){
49579 return SQLITE_IOERR_LOCK;
49580 }
49581 #endif
49582
49583 ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp);
49584
49585 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
49586 /* If SQLITE_ENABLE_SETLK_TIMEOUT is defined, then the file-handle was
49587 ** opened with FILE_FLAG_OVERHEAD specified. In this case, the call to
49588 ** LockFileEx() may fail because the request is still pending. This can
49589 ** happen even if LOCKFILE_FAIL_IMMEDIATELY was specified.
49590 **
49591 ** If nMs is 0, then LOCKFILE_FAIL_IMMEDIATELY was set in the flags
49592 ** passed to LockFileEx(). In this case, if the operation is pending,
49593 ** block indefinitely until it is finished.
49594 **
49595 ** Otherwise, wait for up to nMs ms for the operation to finish. nMs
49596 ** may be set to INFINITE.
49597 */
49598 if( !ret && GetLastError()==ERROR_IO_PENDING ){
49599 DWORD nDelay = (nMs==0 ? INFINITE : nMs);
49600 DWORD res = osWaitForSingleObject(ovlp.hEvent, nDelay);
49601 if( res==WAIT_OBJECT_0 ){
49602 ret = TRUE;
49603 }else if( res==WAIT_TIMEOUT ){
49604 rc = SQLITE_BUSY_TIMEOUT;
49605 }else{
49606 /* Some other error has occurred */
49607 rc = SQLITE_IOERR_LOCK;
49608 }
49609
49610 /* If it is still pending, cancel the LockFileEx() call. */
49611 osCancelIo(hFile);
49612 }
49613
49614 osCloseHandle(ovlp.hEvent);
49615 #endif
49616 }
49617
49618 if( rc==SQLITE_OK && !ret ){
49619 rc = SQLITE_BUSY;
49620 }
49621 return rc;
49622 }
49623
49624 /*
49625 ** Unlock a file region.
49626 */
49627 static BOOL winUnlockFile(
@@ -49438,10 +49649,18 @@
49649 return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49650 numBytesHigh);
49651 }
49652 #endif
49653 }
49654
49655 /*
49656 ** Remove an nByte lock starting at offset iOff from HANDLE h.
49657 */
49658 static int winHandleUnlock(HANDLE h, int iOff, int nByte){
49659 BOOL ret = winUnlockFile(&h, iOff, 0, nByte, 0);
49660 return (ret ? SQLITE_OK : SQLITE_IOERR_UNLOCK);
49661 }
49662
49663 /*****************************************************************************
49664 ** The next group of routines implement the I/O methods specified
49665 ** by the sqlite3_io_methods object.
49666 ******************************************************************************/
@@ -49452,69 +49671,73 @@
49671 #ifndef INVALID_SET_FILE_POINTER
49672 # define INVALID_SET_FILE_POINTER ((DWORD)-1)
49673 #endif
49674
49675 /*
49676 ** Seek the file handle h to offset nByte of the file.
49677 **
49678 ** If successful, return SQLITE_OK. Or, if an error occurs, return an SQLite
49679 ** error code.
49680 */
49681 static int winHandleSeek(HANDLE h, sqlite3_int64 iOffset){
49682 int rc = SQLITE_OK; /* Return value */
49683
49684 #if !SQLITE_OS_WINRT
49685 LONG upperBits; /* Most sig. 32 bits of new offset */
49686 LONG lowerBits; /* Least sig. 32 bits of new offset */
49687 DWORD dwRet; /* Value returned by SetFilePointer() */
 
 
 
49688
49689 upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
49690 lowerBits = (LONG)(iOffset & 0xffffffff);
49691
49692 dwRet = osSetFilePointer(h, lowerBits, &upperBits, FILE_BEGIN);
49693
49694 /* API oddity: If successful, SetFilePointer() returns a dword
49695 ** containing the lower 32-bits of the new file-offset. Or, if it fails,
49696 ** it returns INVALID_SET_FILE_POINTER. However according to MSDN,
49697 ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine
49698 ** whether an error has actually occurred, it is also necessary to call
49699 ** GetLastError(). */
49700 if( dwRet==INVALID_SET_FILE_POINTER ){
49701 DWORD lastErrno = osGetLastError();
49702 if( lastErrno!=NO_ERROR ){
49703 rc = SQLITE_IOERR_SEEK;
49704 }
49705 }
49706 #else
49707 /* This implementation works for WinRT. */
 
 
 
 
 
 
 
 
 
 
 
49708 LARGE_INTEGER x; /* The new offset */
49709 BOOL bRet; /* Value returned by SetFilePointerEx() */
49710
49711 x.QuadPart = iOffset;
49712 bRet = osSetFilePointerEx(h, x, 0, FILE_BEGIN);
49713
49714 if(!bRet){
49715 rc = SQLITE_IOERR_SEEK;
49716 }
49717 #endif
49718
49719 OSTRACE(("SEEK file=%p, offset=%lld rc=%s\n", h, iOffset, sqlite3ErrName(rc)));
49720 return rc;
49721 }
49722
49723 /*
49724 ** Move the current position of the file handle passed as the first
49725 ** argument to offset iOffset within the file. If successful, return 0.
49726 ** Otherwise, set pFile->lastErrno and return non-zero.
49727 */
49728 static int winSeekFile(winFile *pFile, sqlite3_int64 iOffset){
49729 int rc;
49730
49731 rc = winHandleSeek(pFile->h, iOffset);
49732 if( rc!=SQLITE_OK ){
49733 pFile->lastErrno = osGetLastError();
49734 winLogError(rc, pFile->lastErrno, "winSeekFile", pFile->zPath);
49735 }
49736 return rc;
49737 }
49738
 
 
 
 
 
49739
49740 #if SQLITE_MAX_MMAP_SIZE>0
49741 /* Forward references to VFS helper methods used for memory mapped files */
49742 static int winMapfile(winFile*, sqlite3_int64);
49743 static int winUnmapfile(winFile*);
@@ -49770,10 +49993,64 @@
49993 }
49994 OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n",
49995 osGetCurrentProcessId(), pFile, pFile->h));
49996 return SQLITE_OK;
49997 }
49998
49999 /*
50000 ** Truncate the file opened by handle h to nByte bytes in size.
50001 */
50002 static int winHandleTruncate(HANDLE h, sqlite3_int64 nByte){
50003 int rc = SQLITE_OK; /* Return code */
50004 rc = winHandleSeek(h, nByte);
50005 if( rc==SQLITE_OK ){
50006 if( 0==osSetEndOfFile(h) ){
50007 rc = SQLITE_IOERR_TRUNCATE;
50008 }
50009 }
50010 return rc;
50011 }
50012
50013 /*
50014 ** Determine the size in bytes of the file opened by the handle passed as
50015 ** the first argument.
50016 */
50017 static int winHandleSize(HANDLE h, sqlite3_int64 *pnByte){
50018 int rc = SQLITE_OK;
50019
50020 #if SQLITE_OS_WINRT
50021 FILE_STANDARD_INFO info;
50022 BOOL b;
50023 b = osGetFileInformationByHandleEx(h, FileStandardInfo, &info, sizeof(info));
50024 if( b ){
50025 *pnByte = info.EndOfFile.QuadPart;
50026 }else{
50027 rc = SQLITE_IOERR_FSTAT;
50028 }
50029 #else
50030 DWORD upperBits = 0;
50031 DWORD lowerBits = 0;
50032
50033 assert( pnByte );
50034 lowerBits = osGetFileSize(h, &upperBits);
50035 *pnByte = (((sqlite3_int64)upperBits)<<32) + lowerBits;
50036 if( lowerBits==INVALID_FILE_SIZE && osGetLastError()!=NO_ERROR ){
50037 rc = SQLITE_IOERR_FSTAT;
50038 }
50039 #endif
50040
50041 return rc;
50042 }
50043
50044 /*
50045 ** Close the handle passed as the only argument.
50046 */
50047 static void winHandleClose(HANDLE h){
50048 if( h!=INVALID_HANDLE_VALUE ){
50049 osCloseHandle(h);
50050 }
50051 }
50052
50053 /*
50054 ** Truncate an open file to a specified size
50055 */
50056 static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
@@ -50026,31 +50303,32 @@
50303 /*
50304 ** Acquire a reader lock.
50305 ** Different API routines are called depending on whether or not this
50306 ** is Win9x or WinNT.
50307 */
50308 static int winGetReadLock(winFile *pFile, int bBlock){
50309 int res;
50310 DWORD mask = ~(bBlock ? LOCKFILE_FAIL_IMMEDIATELY : 0);
50311 OSTRACE(("READ-LOCK file=%p, lock=%d\n", pFile->h, pFile->locktype));
50312 if( osIsNT() ){
50313 #if SQLITE_OS_WINCE
50314 /*
50315 ** NOTE: Windows CE is handled differently here due its lack of the Win32
50316 ** API LockFileEx.
50317 */
50318 res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
50319 #else
50320 res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS&mask, SHARED_FIRST, 0,
50321 SHARED_SIZE, 0);
50322 #endif
50323 }
50324 #ifdef SQLITE_WIN32_HAS_ANSI
50325 else{
50326 int lk;
50327 sqlite3_randomness(sizeof(lk), &lk);
50328 pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
50329 res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS&mask,
50330 SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
50331 }
50332 #endif
50333 if( res == 0 ){
50334 pFile->lastErrno = osGetLastError();
@@ -50180,11 +50458,11 @@
50458
50459 /* Acquire a shared lock
50460 */
50461 if( locktype==SHARED_LOCK && res ){
50462 assert( pFile->locktype==NO_LOCK );
50463 res = winGetReadLock(pFile, pFile->bBlockOnConnect);
50464 if( res ){
50465 newLocktype = SHARED_LOCK;
50466 }else{
50467 lastErrno = osGetLastError();
50468 }
@@ -50218,11 +50496,11 @@
50496 SHARED_SIZE, 0);
50497 if( res ){
50498 newLocktype = EXCLUSIVE_LOCK;
50499 }else{
50500 lastErrno = osGetLastError();
50501 winGetReadLock(pFile, 0);
50502 }
50503 }
50504
50505 /* If we are holding a PENDING lock that ought to be released, then
50506 ** release it now.
@@ -50508,10 +50786,32 @@
50786 }
50787 OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
50788 return rc;
50789 }
50790 #endif
50791
50792 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
50793 case SQLITE_FCNTL_LOCK_TIMEOUT: {
50794 int iOld = pFile->iBusyTimeout;
50795 int iNew = *(int*)pArg;
50796 #if SQLITE_ENABLE_SETLK_TIMEOUT==1
50797 pFile->iBusyTimeout = (iNew < 0) ? INFINITE : (DWORD)iNew;
50798 #elif SQLITE_ENABLE_SETLK_TIMEOUT==2
50799 pFile->iBusyTimeout = (DWORD)(!!iNew);
50800 #else
50801 # error "SQLITE_ENABLE_SETLK_TIMEOUT must be set to 1 or 2"
50802 #endif
50803 *(int*)pArg = iOld;
50804 return SQLITE_OK;
50805 }
50806 case SQLITE_FCNTL_BLOCK_ON_CONNECT: {
50807 int iNew = *(int*)pArg;
50808 pFile->bBlockOnConnect = iNew;
50809 return SQLITE_OK;
50810 }
50811 #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */
50812
50813 }
50814 OSTRACE(("FCNTL file=%p, rc=SQLITE_NOTFOUND\n", pFile->h));
50815 return SQLITE_NOTFOUND;
50816 }
50817
@@ -50588,36 +50888,39 @@
50888 ** nRef
50889 ** pNext
50890 **
50891 ** The following fields are read-only after the object is created:
50892 **
 
50893 ** zFilename
50894 **
50895 ** Either winShmNode.mutex must be held or winShmNode.nRef==0 and
50896 ** winShmMutexHeld() is true when reading or writing any other field
50897 ** in this structure.
50898 **
50899 ** File-handle hSharedShm is used to (a) take the DMS lock, (b) truncate
50900 ** the *-shm file if the DMS-locking protocol demands it, and (c) map
50901 ** regions of the *-shm file into memory using MapViewOfFile() or
50902 ** similar. Other locks are taken by individual clients using the
50903 ** winShm.hShm handles.
50904 */
50905 struct winShmNode {
50906 sqlite3_mutex *mutex; /* Mutex to access this object */
50907 char *zFilename; /* Name of the file */
50908 HANDLE hSharedShm; /* File handle open on zFilename */
50909
50910 int isUnlocked; /* DMS lock has not yet been obtained */
50911 int isReadonly; /* True if read-only */
50912 int szRegion; /* Size of shared-memory regions */
50913 int nRegion; /* Size of array apRegion */
 
 
50914
50915 struct ShmRegion {
50916 HANDLE hMap; /* File handle from CreateFileMapping */
50917 void *pMap;
50918 } *aRegion;
50919 DWORD lastErrno; /* The Windows errno from the last I/O error */
50920
50921 int nRef; /* Number of winShm objects pointing to this */
 
50922 winShmNode *pNext; /* Next in list of all winShmNode objects */
50923 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
50924 u8 nextShmId; /* Next available winShm.id value */
50925 #endif
50926 };
@@ -50629,27 +50932,19 @@
50932 */
50933 static winShmNode *winShmNodeList = 0;
50934
50935 /*
50936 ** Structure used internally by this VFS to record the state of an
50937 ** open shared memory connection. There is one such structure for each
50938 ** winFile open on a wal mode database.
 
 
 
 
 
 
 
 
50939 */
50940 struct winShm {
50941 winShmNode *pShmNode; /* The underlying winShmNode object */
 
 
50942 u16 sharedMask; /* Mask of shared locks held */
50943 u16 exclMask; /* Mask of exclusive locks held */
50944 HANDLE hShm; /* File-handle on *-shm file. For locking. */
50945 int bReadonly; /* True if hShm is opened read-only */
50946 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
50947 u8 id; /* Id of this connection with its winShmNode */
50948 #endif
50949 };
50950
@@ -50657,54 +50952,10 @@
50952 ** Constants used for locking
50953 */
50954 #define WIN_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
50955 #define WIN_SHM_DMS (WIN_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
50956
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50957 /* Forward references to VFS methods */
50958 static int winOpen(sqlite3_vfs*,const char*,sqlite3_file*,int,int*);
50959 static int winDelete(sqlite3_vfs *,const char*,int);
50960
50961 /*
@@ -50732,15 +50983,11 @@
50983 bRc = osCloseHandle(p->aRegion[i].hMap);
50984 OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
50985 osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
50986 UNUSED_VARIABLE_VALUE(bRc);
50987 }
50988 winHandleClose(p->hSharedShm);
 
 
 
 
50989 if( deleteFlag ){
50990 SimulateIOErrorBenign(1);
50991 sqlite3BeginBenignMalloc();
50992 winDelete(pVfs, p->zFilename, 0);
50993 sqlite3EndBenignMalloc();
@@ -50754,46 +51001,166 @@
51001 }
51002 }
51003 }
51004
51005 /*
51006 ** The DMS lock has not yet been taken on the shm file associated with
51007 ** pShmNode. Take the lock. Truncate the *-shm file if required.
51008 ** Return SQLITE_OK if successful, or an SQLite error code otherwise.
 
 
 
 
51009 */
51010 static int winLockSharedMemory(winShmNode *pShmNode, DWORD nMs){
51011 HANDLE h = pShmNode->hSharedShm;
51012 int rc = SQLITE_OK;
51013
51014 assert( sqlite3_mutex_held(pShmNode->mutex) );
51015 rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 1, 0);
51016 if( rc==SQLITE_OK ){
51017 /* We have an EXCLUSIVE lock on the DMS byte. This means that this
51018 ** is the first process to open the file. Truncate it to zero bytes
51019 ** in this case. */
51020 if( pShmNode->isReadonly ){
51021 rc = SQLITE_READONLY_CANTINIT;
51022 }else{
51023 rc = winHandleTruncate(h, 0);
51024 }
51025
51026 /* Release the EXCLUSIVE lock acquired above. */
51027 winUnlockFile(&h, WIN_SHM_DMS, 0, 1, 0);
51028 }else if( (rc & 0xFF)==SQLITE_BUSY ){
51029 rc = SQLITE_OK;
51030 }
51031
51032 if( rc==SQLITE_OK ){
51033 /* Take a SHARED lock on the DMS byte. */
51034 rc = winHandleLockTimeout(h, WIN_SHM_DMS, 1, 0, nMs);
51035 if( rc==SQLITE_OK ){
51036 pShmNode->isUnlocked = 0;
51037 }
51038 }
51039
51040 return rc;
51041 }
51042
51043
51044 /*
51045 ** Convert a UTF-8 filename into whatever form the underlying
51046 ** operating system wants filenames in. Space to hold the result
51047 ** is obtained from malloc and must be freed by the calling
51048 ** function.
51049 */
51050 static void *winConvertFromUtf8Filename(const char *zFilename){
51051 void *zConverted = 0;
51052 if( osIsNT() ){
51053 zConverted = winUtf8ToUnicode(zFilename);
51054 }
51055 #ifdef SQLITE_WIN32_HAS_ANSI
51056 else{
51057 zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
51058 }
51059 #endif
51060 /* caller will handle out of memory */
51061 return zConverted;
51062 }
51063
51064 /*
51065 ** This function is used to open a handle on a *-shm file.
51066 **
51067 ** If SQLITE_ENABLE_SETLK_TIMEOUT is defined at build time, then the file
51068 ** is opened with FILE_FLAG_OVERLAPPED specified. If not, it is not.
51069 */
51070 static int winHandleOpen(
51071 const char *zUtf8, /* File to open */
51072 int *pbReadonly, /* IN/OUT: True for readonly handle */
51073 HANDLE *ph /* OUT: New HANDLE for file */
51074 ){
51075 int rc = SQLITE_OK;
51076 void *zConverted = 0;
51077 int bReadonly = *pbReadonly;
51078 HANDLE h = INVALID_HANDLE_VALUE;
51079
51080 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51081 const DWORD flag_overlapped = FILE_FLAG_OVERLAPPED;
51082 #else
51083 const DWORD flag_overlapped = 0;
51084 #endif
51085
51086 /* Convert the filename to the system encoding. */
51087 zConverted = winConvertFromUtf8Filename(zUtf8);
51088 if( zConverted==0 ){
51089 OSTRACE(("OPEN name=%s, rc=SQLITE_IOERR_NOMEM", zUtf8));
51090 rc = SQLITE_IOERR_NOMEM_BKPT;
51091 goto winopenfile_out;
51092 }
51093
51094 /* Ensure the file we are trying to open is not actually a directory. */
51095 if( winIsDir(zConverted) ){
51096 OSTRACE(("OPEN name=%s, rc=SQLITE_CANTOPEN_ISDIR", zUtf8));
51097 rc = SQLITE_CANTOPEN_ISDIR;
51098 goto winopenfile_out;
51099 }
51100
51101 /* TODO: platforms.
51102 ** TODO: retry-on-ioerr.
51103 */
51104 if( osIsNT() ){
51105 #if SQLITE_OS_WINRT
51106 CREATEFILE2_EXTENDED_PARAMETERS extendedParameters;
51107 memset(&extendedParameters, 0, sizeof(extendedParameters));
51108 extendedParameters.dwSize = sizeof(extendedParameters);
51109 extendedParameters.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
51110 extendedParameters.dwFileFlags = flag_overlapped;
51111 extendedParameters.dwSecurityQosFlags = SECURITY_ANONYMOUS;
51112 h = osCreateFile2((LPCWSTR)zConverted,
51113 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)),/* dwDesiredAccess */
51114 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51115 OPEN_ALWAYS, /* dwCreationDisposition */
51116 &extendedParameters
51117 );
51118 #else
51119 h = osCreateFileW((LPCWSTR)zConverted, /* lpFileName */
51120 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51121 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51122 NULL, /* lpSecurityAttributes */
51123 OPEN_ALWAYS, /* dwCreationDisposition */
51124 FILE_ATTRIBUTE_NORMAL|flag_overlapped,
51125 NULL
51126 );
51127 #endif
51128 }else{
51129 /* Due to pre-processor directives earlier in this file,
51130 ** SQLITE_WIN32_HAS_ANSI is always defined if osIsNT() is false. */
51131 #ifdef SQLITE_WIN32_HAS_ANSI
51132 h = osCreateFileA((LPCSTR)zConverted,
51133 (GENERIC_READ | (bReadonly ? 0 : GENERIC_WRITE)), /* dwDesiredAccess */
51134 FILE_SHARE_READ | FILE_SHARE_WRITE, /* dwShareMode */
51135 NULL, /* lpSecurityAttributes */
51136 OPEN_ALWAYS, /* dwCreationDisposition */
51137 FILE_ATTRIBUTE_NORMAL|flag_overlapped,
51138 NULL
51139 );
51140 #endif
51141 }
51142
51143 if( h==INVALID_HANDLE_VALUE ){
51144 if( bReadonly==0 ){
51145 bReadonly = 1;
51146 rc = winHandleOpen(zUtf8, &bReadonly, &h);
51147 }else{
51148 rc = SQLITE_CANTOPEN_BKPT;
51149 }
51150 }
51151
51152 winopenfile_out:
51153 sqlite3_free(zConverted);
51154 *pbReadonly = bReadonly;
51155 *ph = h;
51156 return rc;
51157 }
51158
51159
51160 /*
51161 ** Open the shared-memory area associated with database file pDbFd.
51162 */
51163 static int winOpenSharedMemory(winFile *pDbFd){
51164 struct winShm *p; /* The connection to be opened */
51165 winShmNode *pShmNode = 0; /* The underlying mmapped file */
51166 int rc = SQLITE_OK; /* Result code */
@@ -50801,102 +51168,87 @@
51168 int nName; /* Size of zName in bytes */
51169
51170 assert( pDbFd->pShm==0 ); /* Not previously opened */
51171
51172 /* Allocate space for the new sqlite3_shm object. Also speculatively
51173 ** allocate space for a new winShmNode and filename. */
 
51174 p = sqlite3MallocZero( sizeof(*p) );
51175 if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
51176 nName = sqlite3Strlen30(pDbFd->zPath);
51177 pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
51178 if( pNew==0 ){
51179 sqlite3_free(p);
51180 return SQLITE_IOERR_NOMEM_BKPT;
51181 }
51182 pNew->zFilename = (char*)&pNew[1];
51183 pNew->hSharedShm = INVALID_HANDLE_VALUE;
51184 pNew->isUnlocked = 1;
51185 sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
51186 sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename);
51187
51188 /* Open a file-handle on the *-shm file for this connection. This file-handle
51189 ** is only used for locking. The mapping of the *-shm file is created using
51190 ** the shared file handle in winShmNode.hSharedShm. */
51191 p->bReadonly = sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0);
51192 rc = winHandleOpen(pNew->zFilename, &p->bReadonly, &p->hShm);
51193
51194 /* Look to see if there is an existing winShmNode that can be used.
51195 ** If no matching winShmNode currently exists, then create a new one. */
 
51196 winShmEnterMutex();
51197 for(pShmNode = winShmNodeList; pShmNode; pShmNode=pShmNode->pNext){
51198 /* TBD need to come up with better match here. Perhaps
51199 ** use FILE_ID_BOTH_DIR_INFO Structure. */
 
51200 if( sqlite3StrICmp(pShmNode->zFilename, pNew->zFilename)==0 ) break;
51201 }
51202 if( pShmNode==0 ){
 
 
 
 
 
51203 pShmNode = pNew;
 
 
 
 
51204
51205 /* Allocate a mutex for this winShmNode object, if one is required. */
51206 if( sqlite3GlobalConfig.bCoreMutex ){
51207 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
51208 if( pShmNode->mutex==0 ) rc = SQLITE_IOERR_NOMEM_BKPT;
51209 }
51210
51211 /* Open a file-handle to use for mappings, and for the DMS lock. */
51212 if( rc==SQLITE_OK ){
51213 HANDLE h = INVALID_HANDLE_VALUE;
51214 pShmNode->isReadonly = p->bReadonly;
51215 rc = winHandleOpen(pNew->zFilename, &pShmNode->isReadonly, &h);
51216 pShmNode->hSharedShm = h;
51217 }
51218
51219 /* If successful, link the new winShmNode into the global list. If an
51220 ** error occurred, free the object. */
51221 if( rc==SQLITE_OK ){
51222 pShmNode->pNext = winShmNodeList;
51223 winShmNodeList = pShmNode;
51224 pNew = 0;
51225 }else{
51226 sqlite3_mutex_free(pShmNode->mutex);
51227 if( pShmNode->hSharedShm!=INVALID_HANDLE_VALUE ){
51228 osCloseHandle(pShmNode->hSharedShm);
51229 }
51230 }
51231 }
51232
51233 /* If no error has occurred, link the winShm object to the winShmNode and
51234 ** the winShm to pDbFd. */
51235 if( rc==SQLITE_OK ){
51236 p->pShmNode = pShmNode;
51237 pShmNode->nRef++;
51238 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
51239 p->id = pShmNode->nextShmId++;
51240 #endif
51241 pDbFd->pShm = p;
51242 }else if( p ){
51243 winHandleClose(p->hShm);
51244 sqlite3_free(p);
51245 }
51246
51247 assert( rc!=SQLITE_OK || pShmNode->isUnlocked==0 || pShmNode->nRegion==0 );
51248 winShmLeaveMutex();
51249 sqlite3_free(pNew);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51250 return rc;
51251 }
51252
51253 /*
51254 ** Close a connection to shared-memory. Delete the underlying
@@ -50907,38 +51259,33 @@
51259 int deleteFlag /* Delete after closing if true */
51260 ){
51261 winFile *pDbFd; /* Database holding shared-memory */
51262 winShm *p; /* The connection to be closed */
51263 winShmNode *pShmNode; /* The underlying shared-memory file */
 
51264
51265 pDbFd = (winFile*)fd;
51266 p = pDbFd->pShm;
51267 if( p==0 ) return SQLITE_OK;
51268 if( p->hShm!=INVALID_HANDLE_VALUE ){
51269 osCloseHandle(p->hShm);
51270 }
51271
51272 pShmNode = p->pShmNode;
51273 winShmEnterMutex();
 
 
 
 
 
 
 
 
 
 
51274
51275 /* If pShmNode->nRef has reached 0, then close the underlying
51276 ** shared-memory file, too. */
 
51277 assert( pShmNode->nRef>0 );
51278 pShmNode->nRef--;
51279 if( pShmNode->nRef==0 ){
51280 winShmPurge(pDbFd->pVfs, deleteFlag);
51281 }
51282 winShmLeaveMutex();
51283
51284 /* Free the connection p */
51285 sqlite3_free(p);
51286 pDbFd->pShm = 0;
51287 return SQLITE_OK;
51288 }
51289
51290 /*
51291 ** Change the lock state for a shared-memory segment.
@@ -50949,14 +51296,13 @@
51296 int n, /* Number of locks to acquire or release */
51297 int flags /* What to do with the lock */
51298 ){
51299 winFile *pDbFd = (winFile*)fd; /* Connection holding shared memory */
51300 winShm *p = pDbFd->pShm; /* The shared memory being locked */
 
51301 winShmNode *pShmNode;
51302 int rc = SQLITE_OK; /* Result code */
51303 u16 mask = (u16)((1U<<(ofst+n)) - (1U<<ofst)); /* Mask of locks to [un]take */
51304
51305 if( p==0 ) return SQLITE_IOERR_SHMLOCK;
51306 pShmNode = p->pShmNode;
51307 if( NEVER(pShmNode==0) ) return SQLITE_IOERR_SHMLOCK;
51308
@@ -50966,89 +51312,86 @@
51312 || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE)
51313 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED)
51314 || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) );
51315 assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 );
51316
51317 /* Check that, if this to be a blocking lock, no locks that occur later
51318 ** in the following list than the lock being obtained are already held:
51319 **
51320 ** 1. Checkpointer lock (ofst==1).
51321 ** 2. Write lock (ofst==0).
51322 ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
51323 **
51324 ** In other words, if this is a blocking lock, none of the locks that
51325 ** occur later in the above list than the lock being obtained may be
51326 ** held.
51327 **
51328 ** It is not permitted to block on the RECOVER lock.
51329 */
51330 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
51331 {
51332 u16 lockMask = (p->exclMask|p->sharedMask);
51333 assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51334 (ofst!=2) /* not RECOVER */
51335 && (ofst!=1 || lockMask==0 || lockMask==2)
51336 && (ofst!=0 || lockMask<3)
51337 && (ofst<3 || lockMask<(1<<ofst))
51338 ));
51339 }
51340 #endif
51341
51342 /* Check if there is any work to do. There are three cases:
51343 **
51344 ** a) An unlock operation where there are locks to unlock,
51345 ** b) An shared lock where the requested lock is not already held
51346 ** c) An exclusive lock where the requested lock is not already held
51347 **
51348 ** The SQLite core never requests an exclusive lock that it already holds.
51349 ** This is assert()ed immediately below. */
51350 assert( flags!=(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK)
51351 || 0==(p->exclMask & mask)
51352 );
51353 if( ((flags & SQLITE_SHM_UNLOCK) && ((p->exclMask|p->sharedMask) & mask))
51354 || (flags==(SQLITE_SHM_SHARED|SQLITE_SHM_LOCK) && 0==(p->sharedMask & mask))
51355 || (flags==(SQLITE_SHM_EXCLUSIVE|SQLITE_SHM_LOCK))
51356 ){
51357
51358 if( flags & SQLITE_SHM_UNLOCK ){
51359 /* Case (a) - unlock. */
51360
51361 assert( (p->exclMask & p->sharedMask)==0 );
51362 assert( !(flags & SQLITE_SHM_EXCLUSIVE) || (p->exclMask & mask)==mask );
51363 assert( !(flags & SQLITE_SHM_SHARED) || (p->sharedMask & mask)==mask );
51364
51365 rc = winHandleUnlock(p->hShm, ofst+WIN_SHM_BASE, n);
51366
51367 /* If successful, also clear the bits in sharedMask/exclMask */
51368 if( rc==SQLITE_OK ){
51369 p->exclMask = (p->exclMask & ~mask);
51370 p->sharedMask = (p->sharedMask & ~mask);
51371 }
51372 }else{
51373 int bExcl = ((flags & SQLITE_SHM_EXCLUSIVE) ? 1 : 0);
51374 DWORD nMs = winFileBusyTimeout(pDbFd);
51375 rc = winHandleLockTimeout(p->hShm, ofst+WIN_SHM_BASE, n, bExcl, nMs);
51376 if( rc==SQLITE_OK ){
51377 if( bExcl ){
51378 p->exclMask = (p->exclMask | mask);
51379 }else{
51380 p->sharedMask = (p->sharedMask | mask);
51381 }
51382 }
51383 }
51384 }
51385
51386 OSTRACE((
51387 "SHM-LOCK(%d,%d,%d) pid=%lu, id=%d, sharedMask=%03x, exclMask=%03x,"
51388 " rc=%s\n",
51389 ofst, n, flags,
51390 osGetCurrentProcessId(), p->id, p->sharedMask, p->exclMask,
51391 sqlite3ErrName(rc))
51392 );
 
 
 
51393 return rc;
51394 }
51395
51396 /*
51397 ** Implement a memory barrier or memory fence on shared memory.
@@ -51106,17 +51449,19 @@
51449 }
51450 pShmNode = pShm->pShmNode;
51451
51452 sqlite3_mutex_enter(pShmNode->mutex);
51453 if( pShmNode->isUnlocked ){
51454 /* Take the DMS lock. */
51455 assert( pShmNode->nRegion==0 );
51456 rc = winLockSharedMemory(pShmNode, winFileBusyTimeout(pDbFd));
51457 if( rc!=SQLITE_OK ) goto shmpage_out;
 
51458 }
51459
51460 assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 );
 
51461 if( pShmNode->nRegion<=iRegion ){
51462 HANDLE hShared = pShmNode->hSharedShm;
51463 struct ShmRegion *apNew; /* New aRegion[] array */
51464 int nByte = (iRegion+1)*szRegion; /* Minimum required file size */
51465 sqlite3_int64 sz; /* Current size of wal-index file */
51466
51467 pShmNode->szRegion = szRegion;
@@ -51123,35 +51468,32 @@
51468
51469 /* The requested region is not mapped into this processes address space.
51470 ** Check to see if it has been allocated (i.e. if the wal-index file is
51471 ** large enough to contain the requested region).
51472 */
51473 rc = winHandleSize(hShared, &sz);
51474 if( rc!=SQLITE_OK ){
51475 rc = winLogError(rc, osGetLastError(), "winShmMap1", pDbFd->zPath);
 
51476 goto shmpage_out;
51477 }
51478
51479 if( sz<nByte ){
51480 /* The requested memory region does not exist. If isWrite is set to
51481 ** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
51482 **
51483 ** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
51484 ** the requested memory region. */
 
51485 if( !isWrite ) goto shmpage_out;
51486 rc = winHandleTruncate(hShared, nByte);
51487 if( rc!=SQLITE_OK ){
51488 rc = winLogError(rc, osGetLastError(), "winShmMap2", pDbFd->zPath);
 
51489 goto shmpage_out;
51490 }
51491 }
51492
51493 /* Map the requested memory region into this processes address space. */
51494 apNew = (struct ShmRegion*)sqlite3_realloc64(
51495 pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
51496 );
51497 if( !apNew ){
51498 rc = SQLITE_IOERR_NOMEM_BKPT;
51499 goto shmpage_out;
@@ -51166,22 +51508,17 @@
51508 while( pShmNode->nRegion<=iRegion ){
51509 HANDLE hMap = NULL; /* file-mapping handle */
51510 void *pMap = 0; /* Mapped memory region */
51511
51512 #if SQLITE_OS_WINRT
51513 hMap = osCreateFileMappingFromApp(hShared, NULL, protect, nByte, NULL);
 
 
51514 #elif defined(SQLITE_WIN32_HAS_WIDE)
51515 hMap = osCreateFileMappingW(hShared, NULL, protect, 0, nByte, NULL);
 
 
51516 #elif defined(SQLITE_WIN32_HAS_ANSI) && SQLITE_WIN32_CREATEFILEMAPPINGA
51517 hMap = osCreateFileMappingA(hShared, NULL, protect, 0, nByte, NULL);
 
 
51518 #endif
51519
51520 OSTRACE(("SHM-MAP-CREATE pid=%lu, region=%d, size=%d, rc=%s\n",
51521 osGetCurrentProcessId(), pShmNode->nRegion, nByte,
51522 hMap ? "ok" : "failed"));
51523 if( hMap ){
51524 int iOffset = pShmNode->nRegion*szRegion;
@@ -51220,11 +51557,13 @@
51557 char *p = (char *)pShmNode->aRegion[iRegion].pMap;
51558 *pp = (void *)&p[iOffsetShift];
51559 }else{
51560 *pp = 0;
51561 }
51562 if( pShmNode->isReadonly && rc==SQLITE_OK ){
51563 rc = SQLITE_READONLY;
51564 }
51565 sqlite3_mutex_leave(pShmNode->mutex);
51566 return rc;
51567 }
51568
51569 #else
@@ -51561,30 +51900,10 @@
51900 /* caller will handle out of memory */
51901 return zConverted;
51902 }
51903 #endif
51904
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51905 /*
51906 ** This function returns non-zero if the specified UTF-8 string buffer
51907 ** ends with a directory separator character or one was successfully
51908 ** added to it.
51909 */
@@ -53035,11 +53354,11 @@
53354 };
53355 #endif
53356
53357 /* Double-check that the aSyscall[] array has been constructed
53358 ** correctly. See ticket [bb3a86e890c8e96ab] */
53359 assert( ArraySize(aSyscall)==82 );
53360
53361 /* get memory map allocation granularity */
53362 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
53363 #if SQLITE_OS_WINRT
53364 osGetNativeSystemInfo(&winSysInfo);
@@ -65633,10 +65952,15 @@
65952 )
65953
65954 /*
65955 ** An open write-ahead log file is represented by an instance of the
65956 ** following object.
65957 **
65958 ** writeLock:
65959 ** This is usually set to 1 whenever the WRITER lock is held. However,
65960 ** if it is set to 2, then the WRITER lock is held but must be released
65961 ** by walHandleException() if a SEH exception is thrown.
65962 */
65963 struct Wal {
65964 sqlite3_vfs *pVfs; /* The VFS used to create pDbFd */
65965 sqlite3_file *pDbFd; /* File handle for the database file */
65966 sqlite3_file *pWalFd; /* File handle for WAL file */
@@ -67158,11 +67482,11 @@
67482 ** or 0 otherwise.
67483 */
67484 static int walEnableBlocking(Wal *pWal){
67485 int res = 0;
67486 if( pWal->db ){
67487 int tmout = pWal->db->setlkTimeout;
67488 if( tmout ){
67489 res = walEnableBlockingMs(pWal, tmout);
67490 }
67491 }
67492 return res;
@@ -67544,11 +67868,13 @@
67868 static int walHandleException(Wal *pWal){
67869 if( pWal->exclusiveMode==0 ){
67870 static const int S = 1;
67871 static const int E = (1<<SQLITE_SHM_NLOCK);
67872 int ii;
67873 u32 mUnlock;
67874 if( pWal->writeLock==2 ) pWal->writeLock = 0;
67875 mUnlock = pWal->lockMask & ~(
67876 (pWal->readLock<0 ? 0 : (S << WAL_READ_LOCK(pWal->readLock)))
67877 | (pWal->writeLock ? (E << WAL_WRITE_LOCK) : 0)
67878 | (pWal->ckptLock ? (E << WAL_CKPT_LOCK) : 0)
67879 );
67880 for(ii=0; ii<SQLITE_SHM_NLOCK; ii++){
@@ -67816,11 +68142,16 @@
68142 }else{
68143 int bWriteLock = pWal->writeLock;
68144 if( bWriteLock
68145 || SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1))
68146 ){
68147 /* If the write-lock was just obtained, set writeLock to 2 instead of
68148 ** the usual 1. This causes walIndexPage() to behave as if the
68149 ** write-lock were held (so that it allocates new pages as required),
68150 ** and walHandleException() to unlock the write-lock if a SEH exception
68151 ** is thrown. */
68152 if( !bWriteLock ) pWal->writeLock = 2;
68153 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
68154 badHdr = walIndexTryHdr(pWal, pChanged);
68155 if( badHdr ){
68156 /* If the wal-index header is still malformed even while holding
68157 ** a WRITE lock, it can only mean that the header is corrupted and
@@ -68601,12 +68932,15 @@
68932 /*
68933 ** Finish with a read transaction. All this does is release the
68934 ** read-lock.
68935 */
68936 SQLITE_PRIVATE void sqlite3WalEndReadTransaction(Wal *pWal){
68937 #ifndef SQLITE_ENABLE_SETLK_TIMEOUT
68938 assert( pWal->writeLock==0 || pWal->readLock<0 );
68939 #endif
68940 if( pWal->readLock>=0 ){
68941 sqlite3WalEndWriteTransaction(pWal);
68942 walUnlockShared(pWal, WAL_READ_LOCK(pWal->readLock));
68943 pWal->readLock = -1;
68944 }
68945 }
68946
@@ -68795,11 +69129,11 @@
69129 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
69130 /* If the write-lock is already held, then it was obtained before the
69131 ** read-transaction was even opened, making this call a no-op.
69132 ** Return early. */
69133 if( pWal->writeLock ){
69134 assert( !memcmp(&pWal->hdr,(void*)pWal->apWiData[0],sizeof(WalIndexHdr)) );
69135 return SQLITE_OK;
69136 }
69137 #endif
69138
69139 /* Cannot start a write transaction without first holding a read
@@ -83370,11 +83704,11 @@
83704 if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
83705 /* pMem must be a string, and it cannot be an ephemeral or static string */
83706 return;
83707 }
83708 if( pMem->enc!=SQLITE_UTF8 ) return;
83709 assert( pMem->z!=0 );
83710 if( pMem->flags & MEM_Dyn ){
83711 if( pMem->xDel==sqlite3_free
83712 && sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
83713 ){
83714 pMem->z[pMem->n] = 0;
@@ -85958,12 +86292,12 @@
86292 ** through all the opcodes and fixes up some details.
86293 **
86294 ** (1) For each jump instruction with a negative P2 value (a label)
86295 ** resolve the P2 value to an actual address.
86296 **
86297 ** (2) Compute the maximum number of arguments used by the xUpdate/xFilter
86298 ** methods of any virtual table and store that value in *pMaxVtabArgs.
86299 **
86300 ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
86301 ** indicate what the prepared statement actually does.
86302 **
86303 ** (4) (discontinued)
@@ -85972,12 +86306,12 @@
86306 **
86307 ** This routine will only function correctly if the mkopcodeh.tcl generator
86308 ** script numbers the opcodes correctly. Changes to this routine must be
86309 ** coordinated with changes to mkopcodeh.tcl.
86310 */
86311 static void resolveP2Values(Vdbe *p, int *pMaxVtabArgs){
86312 int nMaxVtabArgs = *pMaxVtabArgs;
86313 Op *pOp;
86314 Parse *pParse = p->pParse;
86315 int *aLabel = pParse->aLabel;
86316
86317 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
@@ -86018,19 +86352,23 @@
86352 assert( pOp->p2>=0 );
86353 goto resolve_p2_values_loop_exit;
86354 }
86355 #ifndef SQLITE_OMIT_VIRTUALTABLE
86356 case OP_VUpdate: {
86357 if( pOp->p2>nMaxVtabArgs ) nMaxVtabArgs = pOp->p2;
86358 break;
86359 }
86360 case OP_VFilter: {
86361 int n;
86362 /* The instruction immediately prior to VFilter will be an
86363 ** OP_Integer that sets the "argc" value for the VFilter. See
86364 ** the code where OP_VFilter is generated at tag-20250207a. */
86365 assert( (pOp - p->aOp) >= 3 );
86366 assert( pOp[-1].opcode==OP_Integer );
86367 assert( pOp[-1].p2==pOp->p3+1 );
86368 n = pOp[-1].p1;
86369 if( n>nMaxVtabArgs ) nMaxVtabArgs = n;
86370 /* Fall through into the default case */
86371 /* no break */ deliberate_fall_through
86372 }
86373 #endif
86374 default: {
@@ -86067,11 +86405,11 @@
86405 if( aLabel ){
86406 sqlite3DbNNFreeNN(p->db, pParse->aLabel);
86407 pParse->aLabel = 0;
86408 }
86409 pParse->nLabel = 0;
86410 *pMaxVtabArgs = nMaxVtabArgs;
86411 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
86412 }
86413
86414 #ifdef SQLITE_DEBUG
86415 /*
@@ -87745,11 +88083,11 @@
88083 ){
88084 sqlite3 *db; /* The database connection */
88085 int nVar; /* Number of parameters */
88086 int nMem; /* Number of VM memory registers */
88087 int nCursor; /* Number of cursors required */
88088 int nArg; /* Max number args to xFilter or xUpdate */
88089 int n; /* Loop counter */
88090 struct ReusableSpace x; /* Reusable bulk memory */
88091
88092 assert( p!=0 );
88093 assert( p->nOp>0 );
@@ -87817,10 +88155,13 @@
88155 p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
88156 p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
88157 p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
88158 }
88159 }
88160 #ifdef SQLITE_DEBUG
88161 p->napArg = nArg;
88162 #endif
88163
88164 if( db->mallocFailed ){
88165 p->nVar = 0;
88166 p->nCursor = 0;
88167 p->nMem = 0;
@@ -101897,10 +102238,11 @@
102238 nArg = (int)pArgc->u.i;
102239 iQuery = (int)pQuery->u.i;
102240
102241 /* Invoke the xFilter method */
102242 apArg = p->apArg;
102243 assert( nArg<=p->napArg );
102244 for(i = 0; i<nArg; i++){
102245 apArg[i] = &pArgc[i+1];
102246 }
102247 rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg);
102248 sqlite3VtabImportErrmsg(p, pVtab);
@@ -102107,10 +102449,11 @@
102449 assert( pOp->p4type==P4_VTAB );
102450 if( ALWAYS(pModule->xUpdate) ){
102451 u8 vtabOnConflict = db->vtabOnConflict;
102452 apArg = p->apArg;
102453 pX = &aMem[pOp->p3];
102454 assert( nArg<=p->napArg );
102455 for(i=0; i<nArg; i++){
102456 assert( memIsValid(pX) );
102457 memAboutToChange(p, pX);
102458 apArg[i] = pX;
102459 pX++;
@@ -102952,16 +103295,12 @@
103295 }
103296 pBlob->pTab = pTab;
103297 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
103298
103299 /* Now search pTab for the exact column. */
103300 iCol = sqlite3ColumnIndex(pTab, zColumn);
103301 if( iCol<0 ){
 
 
 
 
103302 sqlite3DbFree(db, zErr);
103303 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
103304 rc = SQLITE_ERROR;
103305 sqlite3BtreeLeaveAll(db);
103306 goto blob_open_out;
@@ -107503,11 +107842,10 @@
107842 SrcItem *pMatch = 0; /* The matching pSrcList item */
107843 NameContext *pTopNC = pNC; /* First namecontext in the list */
107844 Schema *pSchema = 0; /* Schema of the expression */
107845 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
107846 Table *pTab = 0; /* Table holding the row */
 
107847 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
107848 const char *zCol = pRight->u.zToken;
107849
107850 assert( pNC ); /* the name context cannot be NULL. */
107851 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -107554,11 +107892,10 @@
107892 ExprList *pEList;
107893 SrcList *pSrcList = pNC->pSrcList;
107894
107895 if( pSrcList ){
107896 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
 
107897 pTab = pItem->pSTab;
107898 assert( pTab!=0 && pTab->zName!=0 );
107899 assert( pTab->nCol>0 || pParse->nErr );
107900 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem));
107901 if( pItem->fg.isNestedFrom ){
@@ -107642,47 +107979,42 @@
107979 assert( ExprUseYTab(pExpr) );
107980 if( IN_RENAME_OBJECT && pItem->zAlias ){
107981 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
107982 }
107983 }
107984 j = sqlite3ColumnIndex(pTab, zCol);
107985 if( j>=0 ){
107986 if( cnt>0 ){
107987 if( pItem->fg.isUsing==0
107988 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107989 ){
107990 /* Two or more tables have the same column name which is
107991 ** not joined by USING. This is an error. Signal as much
107992 ** by clearing pFJMatch and letting cnt go above 1. */
107993 sqlite3ExprListDelete(db, pFJMatch);
107994 pFJMatch = 0;
107995 }else
107996 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107997 /* An INNER or LEFT JOIN. Use the left-most table */
107998 continue;
107999 }else
108000 if( (pItem->fg.jointype & JT_LEFT)==0 ){
108001 /* A RIGHT JOIN. Use the right-most table */
108002 cnt = 0;
108003 sqlite3ExprListDelete(db, pFJMatch);
108004 pFJMatch = 0;
108005 }else{
108006 /* For a FULL JOIN, we must construct a coalesce() func */
108007 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
108008 }
108009 }
108010 cnt++;
108011 pMatch = pItem;
108012 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
108013 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
108014 if( pItem->fg.isNestedFrom ){
108015 sqlite3SrcItemColumnUsed(pItem, j);
 
 
 
 
 
108016 }
108017 }
108018 if( 0==cnt && VisibleRowid(pTab) ){
108019 /* pTab is a potential ROWID match. Keep track of it and match
108020 ** the ROWID later if that seems appropriate. (Search for "cntTab"
@@ -107768,26 +108100,21 @@
108100 }
108101 #endif /* SQLITE_OMIT_UPSERT */
108102
108103 if( pTab ){
108104 int iCol;
 
108105 pSchema = pTab->pSchema;
108106 cntTab++;
108107 iCol = sqlite3ColumnIndex(pTab, zCol);
108108 if( iCol>=0 ){
108109 if( pTab->iPKey==iCol ) iCol = -1;
108110 }else{
108111 if( sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
108112 iCol = -1;
108113 }else{
108114 iCol = pTab->nCol;
108115 }
 
 
 
 
108116 }
108117 if( iCol<pTab->nCol ){
108118 cnt++;
108119 pMatch = 0;
108120 #ifndef SQLITE_OMIT_UPSERT
@@ -111379,11 +111706,10 @@
111706 pNewExpr->pLeft = pPriorSelectColNew;
111707 }
111708 }
111709 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
111710 pItem->fg = pOldItem->fg;
 
111711 pItem->u = pOldItem->u;
111712 }
111713 return pNew;
111714 }
111715
@@ -112496,17 +112822,11 @@
112822 SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab){
112823 const char *azOpt[] = {"_ROWID_", "ROWID", "OID"};
112824 int ii;
112825 assert( VisibleRowid(pTab) );
112826 for(ii=0; ii<ArraySize(azOpt); ii++){
112827 if( sqlite3ColumnIndex(pTab, azOpt[ii])<0 ) return azOpt[ii];
 
 
 
 
 
 
112828 }
112829 return 0;
112830 }
112831
112832 /*
@@ -117551,14 +117871,12 @@
117871
117872 /* Make sure the old name really is a column name in the table to be
117873 ** altered. Set iCol to be the index of the column being renamed */
117874 zOld = sqlite3NameFromToken(db, pOld);
117875 if( !zOld ) goto exit_rename_column;
117876 iCol = sqlite3ColumnIndex(pTab, zOld);
117877 if( iCol<0 ){
 
 
117878 sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
117879 goto exit_rename_column;
117880 }
117881
117882 /* Ensure the schema contains no double-quoted strings */
@@ -119453,11 +119771,12 @@
119771 ** of the new table in register pParse->regRoot. This is important
119772 ** because the OpenWrite opcode below will be needing it. */
119773 sqlite3NestedParse(pParse,
119774 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
119775 );
119776 assert( pParse->isCreate || pParse->nErr );
119777 aRoot[i] = (u32)pParse->u1.cr.regRoot;
119778 aCreateTbl[i] = OPFLAG_P2ISREG;
119779 }
119780 }else{
119781 /* The table already exists. If zWhere is not NULL, delete all entries
119782 ** associated with the table zWhere. If zWhere is NULL, delete the
@@ -121489,10 +121808,17 @@
121808 */
121809 if( rc==SQLITE_OK ){
121810 sqlite3BtreeEnterAll(db);
121811 db->init.iDb = 0;
121812 db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
121813 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
121814 if( db->setlkFlags & SQLITE_SETLK_BLOCK_ON_CONNECT ){
121815 int val = 1;
121816 sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pNew->pBt));
121817 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, &val);
121818 }
121819 #endif
121820 if( !REOPEN_AS_MEMDB(db) ){
121821 rc = sqlite3Init(db, &zErrDyn);
121822 }
121823 sqlite3BtreeLeaveAll(db);
121824 assert( zErrDyn==0 || rc!=SQLITE_OK );
@@ -122311,14 +122637,16 @@
122637 }
122638 assert( !pParse->isMultiWrite
122639 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
122640 if( v ){
122641 if( pParse->bReturning ){
122642 Returning *pReturning;
122643 int addrRewind;
122644 int reg;
122645
122646 assert( !pParse->isCreate );
122647 pReturning = pParse->u1.d.pReturning;
122648 if( pReturning->nRetCol ){
122649 sqlite3VdbeAddOp0(v, OP_FkCheck);
122650 addrRewind =
122651 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
122652 VdbeCoverage(v);
@@ -122390,11 +122718,13 @@
122718 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
122719 }
122720 }
122721
122722 if( pParse->bReturning ){
122723 Returning *pRet;
122724 assert( !pParse->isCreate );
122725 pRet = pParse->u1.d.pReturning;
122726 if( pRet->nRetCol ){
122727 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
122728 }
122729 }
122730
@@ -123462,12 +123792,13 @@
123792 #endif
123793
123794 /* If the file format and encoding in the database have not been set,
123795 ** set them now.
123796 */
123797 assert( pParse->isCreate );
123798 reg1 = pParse->u1.cr.regRowid = ++pParse->nMem;
123799 reg2 = pParse->u1.cr.regRoot = ++pParse->nMem;
123800 reg3 = ++pParse->nMem;
123801 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
123802 sqlite3VdbeUsesBtree(v, iDb);
123803 addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
123804 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
@@ -123478,12 +123809,12 @@
123809
123810 /* This just creates a place-holder record in the sqlite_schema table.
123811 ** The record created does not contain anything yet. It will be replaced
123812 ** by the real entry in code generated at sqlite3EndTable().
123813 **
123814 ** The rowid for the new entry is left in register pParse->u1.cr.regRowid.
123815 ** The root page of the new table is left in reg pParse->u1.cr.regRoot.
123816 ** The rowid and root page number values are needed by the code that
123817 ** sqlite3EndTable will generate.
123818 */
123819 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
123820 if( isView || isVirtual ){
@@ -123490,11 +123821,11 @@
123821 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
123822 }else
123823 #endif
123824 {
123825 assert( !pParse->bReturning );
123826 pParse->u1.cr.addrCrTab =
123827 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
123828 }
123829 sqlite3OpenSchemaTable(pParse, iDb);
123830 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
123831 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
@@ -123568,11 +123899,12 @@
123899 pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
123900 if( pRet==0 ){
123901 sqlite3ExprListDelete(db, pList);
123902 return;
123903 }
123904 assert( !pParse->isCreate );
123905 pParse->u1.d.pReturning = pRet;
123906 pRet->pParse = pParse;
123907 pRet->pReturnEL = pList;
123908 sqlite3ParserAddCleanup(pParse, sqlite3DeleteReturning, pRet);
123909 testcase( pParse->earlyCleanup );
123910 if( db->mallocFailed ) return;
@@ -123610,11 +123942,10 @@
123942 int i;
123943 char *z;
123944 char *zType;
123945 Column *pCol;
123946 sqlite3 *db = pParse->db;
 
123947 Column *aNew;
123948 u8 eType = COLTYPE_CUSTOM;
123949 u8 szEst = 1;
123950 char affinity = SQLITE_AFF_BLOB;
123951
@@ -123664,17 +123995,14 @@
123995 if( z==0 ) return;
123996 if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
123997 memcpy(z, sName.z, sName.n);
123998 z[sName.n] = 0;
123999 sqlite3Dequote(z);
124000 if( p->nCol && sqlite3ColumnIndex(p, z)>=0 ){
124001 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
124002 sqlite3DbFree(db, z);
124003 return;
 
 
 
124004 }
124005 aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
124006 if( aNew==0 ){
124007 sqlite3DbFree(db, z);
124008 return;
@@ -123681,11 +124009,11 @@
124009 }
124010 p->aCol = aNew;
124011 pCol = &p->aCol[p->nCol];
124012 memset(pCol, 0, sizeof(p->aCol[0]));
124013 pCol->zCnName = z;
124014 pCol->hName = sqlite3StrIHash(z);
124015 sqlite3ColumnPropertiesFromName(p, pCol);
124016
124017 if( sType.n==0 ){
124018 /* If there is no type specified, columns have the default affinity
124019 ** 'BLOB' with a default size of 4 bytes. */
@@ -123705,13 +124033,18 @@
124033 zType[sType.n] = 0;
124034 sqlite3Dequote(zType);
124035 pCol->affinity = sqlite3AffinityType(zType, pCol);
124036 pCol->colFlags |= COLFLAG_HASTYPE;
124037 }
124038 if( p->nCol<=0xff ){
124039 u8 h = pCol->hName % sizeof(p->aHx);
124040 p->aHx[h] = p->nCol;
124041 }
124042 p->nCol++;
124043 p->nNVCol++;
124044 assert( pParse->isCreate );
124045 pParse->u1.cr.constraintName.n = 0;
124046 }
124047
124048 /*
124049 ** This routine is called by the parser while in the middle of
124050 ** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
@@ -123971,19 +124304,15 @@
124304 for(i=0; i<nTerm; i++){
124305 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
124306 assert( pCExpr!=0 );
124307 sqlite3StringToId(pCExpr);
124308 if( pCExpr->op==TK_ID ){
 
124309 assert( !ExprHasProperty(pCExpr, EP_IntValue) );
124310 iCol = sqlite3ColumnIndex(pTab, pCExpr->u.zToken);
124311 if( iCol>=0 ){
124312 pCol = &pTab->aCol[iCol];
124313 makeColumnPartOfPrimaryKey(pParse, pCol);
 
 
 
124314 }
124315 }
124316 }
124317 }
124318 if( nTerm==1
@@ -124031,12 +124360,14 @@
124360 sqlite3 *db = pParse->db;
124361 if( pTab && !IN_DECLARE_VTAB
124362 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
124363 ){
124364 pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr);
124365 assert( pParse->isCreate );
124366 if( pParse->u1.cr.constraintName.n ){
124367 sqlite3ExprListSetName(pParse, pTab->pCheck,
124368 &pParse->u1.cr.constraintName, 1);
124369 }else{
124370 Token t;
124371 for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
124372 while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; }
124373 t.z = zStart;
@@ -124482,13 +124813,13 @@
124813
124814 /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
124815 ** into BTREE_BLOBKEY.
124816 */
124817 assert( !pParse->bReturning );
124818 if( pParse->u1.cr.addrCrTab ){
124819 assert( v );
124820 sqlite3VdbeChangeP3(v, pParse->u1.cr.addrCrTab, BTREE_BLOBKEY);
124821 }
124822
124823 /* Locate the PRIMARY KEY index. Or, if this table was originally
124824 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
124825 */
@@ -124924,11 +125255,11 @@
125255 #endif
125256 }
125257
125258 /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
125259 ** statement to populate the new table. The root-page number for the
125260 ** new table is in register pParse->u1.cr.regRoot.
125261 **
125262 ** Once the SELECT has been coded by sqlite3Select(), it is in a
125263 ** suitable state to query for the column names and types to be used
125264 ** by the new table.
125265 **
@@ -124955,11 +125286,12 @@
125286 iCsr = pParse->nTab++;
125287 regYield = ++pParse->nMem;
125288 regRec = ++pParse->nMem;
125289 regRowid = ++pParse->nMem;
125290 sqlite3MayAbort(pParse);
125291 assert( pParse->isCreate );
125292 sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->u1.cr.regRoot, iDb);
125293 sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
125294 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
125295 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
125296 if( pParse->nErr ) return;
125297 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
@@ -125000,21 +125332,22 @@
125332
125333 /* A slot for the record has already been allocated in the
125334 ** schema table. We just need to update that slot with all
125335 ** the information we've collected.
125336 */
125337 assert( pParse->isCreate );
125338 sqlite3NestedParse(pParse,
125339 "UPDATE %Q." LEGACY_SCHEMA_TABLE
125340 " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
125341 " WHERE rowid=#%d",
125342 db->aDb[iDb].zDbSName,
125343 zType,
125344 p->zName,
125345 p->zName,
125346 pParse->u1.cr.regRoot,
125347 zStmt,
125348 pParse->u1.cr.regRowid
125349 );
125350 sqlite3DbFree(db, zStmt);
125351 sqlite3ChangeCookie(pParse, iDb);
125352
125353 #ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -129850,15 +130183,10 @@
130183 int len;
130184 int p0type;
130185 i64 p1, p2;
130186
130187 assert( argc==3 || argc==2 );
 
 
 
 
 
130188 p0type = sqlite3_value_type(argv[0]);
130189 p1 = sqlite3_value_int64(argv[1]);
130190 if( p0type==SQLITE_BLOB ){
130191 len = sqlite3_value_bytes(argv[0]);
130192 z = sqlite3_value_blob(argv[0]);
@@ -129872,23 +130200,27 @@
130200 for(z2=z; *z2; len++){
130201 SQLITE_SKIP_UTF8(z2);
130202 }
130203 }
130204 }
 
 
 
 
 
 
 
 
130205 if( argc==3 ){
130206 p2 = sqlite3_value_int64(argv[2]);
130207 if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
130208 }else{
130209 p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
130210 }
130211 if( p1==0 ){
130212 #ifdef SQLITE_SUBSTR_COMPATIBILITY
130213 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
130214 ** as substr(X,1,N) - it returns the first N characters of X. This
130215 ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
130216 ** from 2009-02-02 for compatibility of applications that exploited the
130217 ** old buggy behavior. */
130218 p1 = 1; /* <rdar://problem/6778339> */
130219 #endif
130220 if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
130221 }
130222 if( p1<0 ){
130223 p1 += len;
130224 if( p1<0 ){
130225 if( p2<0 ){
130226 p2 = 0;
@@ -134900,32 +135232,26 @@
135232 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
135233 if( pColumn ){
135234 aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int));
135235 if( aTabColMap==0 ) goto insert_cleanup;
135236 for(i=0; i<pColumn->nId; i++){
135237 j = sqlite3ColumnIndex(pTab, pColumn->a[i].zName);
135238 if( j>=0 ){
135239 if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
135240 if( i!=j ) bIdListInOrder = 0;
135241 if( j==pTab->iPKey ){
135242 ipkColumn = i; assert( !withoutRowid );
135243 }
 
 
 
135244 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
135245 if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
135246 sqlite3ErrorMsg(pParse,
135247 "cannot INSERT into generated column \"%s\"",
135248 pTab->aCol[j].zCnName);
135249 goto insert_cleanup;
135250 }
135251 #endif
135252 }else{
 
 
 
135253 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
135254 ipkColumn = i;
135255 bIdListInOrder = 0;
135256 }else{
135257 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
@@ -135219,11 +135545,11 @@
135545 sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
135546 }
135547 continue;
135548 }else if( pColumn==0 ){
135549 /* Hidden columns that are not explicitly named in the INSERT
135550 ** get their default value */
135551 sqlite3ExprCodeFactorable(pParse,
135552 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135553 iRegStore);
135554 continue;
135555 }
@@ -144166,14 +144492,37 @@
144492 ** Return the index of a column in a table. Return -1 if the column
144493 ** is not contained in the table.
144494 */
144495 SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
144496 int i;
144497 u8 h;
144498 const Column *aCol;
144499 int nCol;
144500
144501 h = sqlite3StrIHash(zCol);
144502 aCol = pTab->aCol;
144503 nCol = pTab->nCol;
144504
144505 /* See if the aHx gives us a lucky match */
144506 i = pTab->aHx[h % sizeof(pTab->aHx)];
144507 assert( i<nCol );
144508 if( aCol[i].hName==h
144509 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144510 ){
144511 return i;
144512 }
144513
144514 /* No lucky match from the hash table. Do a full search. */
144515 i = 0;
144516 while( 1 /*exit-by-break*/ ){
144517 if( aCol[i].hName==h
144518 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144519 ){
144520 return i;
144521 }
144522 i++;
144523 if( i>=nCol ) break;
144524 }
144525 return -1;
144526 }
144527
144528 /*
@@ -152891,11 +153240,12 @@
153240 }else if( pTrig->op==TK_RETURNING ){
153241 #ifndef SQLITE_OMIT_VIRTUALTABLE
153242 assert( pParse->db->pVtabCtx==0 );
153243 #endif
153244 assert( pParse->bReturning );
153245 assert( !pParse->isCreate );
153246 assert( &(pParse->u1.d.pReturning->retTrig) == pTrig );
153247 pTrig->table = pTab->zName;
153248 pTrig->pTabSchema = pTab->pSchema;
153249 pTrig->pNext = pList;
153250 pList = pTrig;
153251 }
@@ -153868,11 +154218,12 @@
154218 /* This RETURNING trigger must be for a different statement as
154219 ** this statement lacks a RETURNING clause. */
154220 return;
154221 }
154222 assert( db->pParse==pParse );
154223 assert( !pParse->isCreate );
154224 pReturning = pParse->u1.d.pReturning;
154225 if( pTrigger != &(pReturning->retTrig) ){
154226 /* This RETURNING trigger is for a different statement */
154227 return;
154228 }
154229 memset(&sSelect, 0, sizeof(sSelect));
@@ -154098,10 +154449,12 @@
154449 sSubParse.pToplevel = pTop;
154450 sSubParse.zAuthContext = pTrigger->zName;
154451 sSubParse.eTriggerOp = pTrigger->op;
154452 sSubParse.nQueryLoop = pParse->nQueryLoop;
154453 sSubParse.prepFlags = pParse->prepFlags;
154454 sSubParse.oldmask = 0;
154455 sSubParse.newmask = 0;
154456
154457 v = sqlite3GetVdbe(&sSubParse);
154458 if( v ){
154459 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
154460 pTrigger->zName, onErrorText(orconf),
@@ -154852,42 +155205,36 @@
155205 ** column to be updated, make sure we have authorization to change
155206 ** that column.
155207 */
155208 chngRowid = chngPk = 0;
155209 for(i=0; i<pChanges->nExpr; i++){
 
155210 /* If this is an UPDATE with a FROM clause, do not resolve expressions
155211 ** here. The call to sqlite3Select() below will do that. */
155212 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
155213 goto update_cleanup;
155214 }
155215 j = sqlite3ColumnIndex(pTab, pChanges->a[i].zEName);
155216 if( j>=0 ){
155217 if( j==pTab->iPKey ){
155218 chngRowid = 1;
155219 pRowidExpr = pChanges->a[i].pExpr;
155220 iRowidExpr = i;
155221 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
155222 chngPk = 1;
155223 }
 
 
155224 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
155225 else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
155226 testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
155227 testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
155228 sqlite3ErrorMsg(pParse,
155229 "cannot UPDATE generated column \"%s\"",
155230 pTab->aCol[j].zCnName);
155231 goto update_cleanup;
155232 }
155233 #endif
155234 aXRef[j] = i;
155235 }else{
 
 
 
155236 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
155237 j = -1;
155238 chngRowid = 1;
155239 pRowidExpr = pChanges->a[i].pExpr;
155240 iRowidExpr = i;
@@ -156990,24 +157337,25 @@
157337
157338 /* A slot for the record has already been allocated in the
157339 ** schema table. We just need to update that slot with all
157340 ** the information we've collected.
157341 **
157342 ** The VM register number pParse->u1.cr.regRowid holds the rowid of an
157343 ** entry in the sqlite_schema table that was created for this vtab
157344 ** by sqlite3StartTable().
157345 */
157346 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
157347 assert( pParse->isCreate );
157348 sqlite3NestedParse(pParse,
157349 "UPDATE %Q." LEGACY_SCHEMA_TABLE " "
157350 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
157351 "WHERE rowid=#%d",
157352 db->aDb[iDb].zDbSName,
157353 pTab->zName,
157354 pTab->zName,
157355 zStmt,
157356 pParse->u1.cr.regRowid
157357 );
157358 v = sqlite3GetVdbe(pParse);
157359 sqlite3ChangeCookie(pParse, iDb);
157360
157361 sqlite3VdbeAddOp0(v, OP_Expire);
@@ -160161,10 +160509,13 @@
160509 }
160510 }
160511 }
160512 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
160513 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
160514 /* The instruction immediately prior to OP_VFilter must be an OP_Integer
160515 ** that sets the "argc" value for xVFilter. This is necessary for
160516 ** resolveP2() to work correctly. See tag-20250207a. */
160517 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
160518 pLoop->u.vtab.idxStr,
160519 pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
160520 VdbeCoverage(v);
160521 pLoop->u.vtab.needFree = 0;
@@ -174215,10 +174566,15 @@
174566 ** to the original parse.y sources.
174567 */
174568
174569 /* #include "sqliteInt.h" */
174570
174571 /*
174572 ** Verify that the pParse->isCreate field is set
174573 */
174574 #define ASSERT_IS_CREATE assert(pParse->isCreate)
174575
174576 /*
174577 ** Disable all error recovery processing in the parser push-down
174578 ** automaton.
174579 */
174580 #define YYNOERRORRECOVERY 1
@@ -174278,10 +174634,14 @@
174634 ** shared across database connections.
174635 */
174636 static void disableLookaside(Parse *pParse){
174637 sqlite3 *db = pParse->db;
174638 pParse->disableLookaside++;
174639 #ifdef SQLITE_DEBUG
174640 pParse->isCreate = 1;
174641 #endif
174642 memset(&pParse->u1.cr, 0, sizeof(pParse->u1.cr));
174643 DisableLookaside;
174644 }
174645
174646 #if !defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) \
174647 && defined(SQLITE_UDL_CAPABLE_PARSER)
@@ -177914,11 +178274,13 @@
178274 {
178275 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[-2].minor.yy502);
178276 }
178277 break;
178278 case 14: /* createkw ::= CREATE */
178279 {
178280 disableLookaside(pParse);
178281 }
178282 break;
178283 case 15: /* ifnotexists ::= */
178284 case 18: /* temp ::= */ yytestcase(yyruleno==18);
178285 case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
178286 case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
@@ -178006,11 +178368,11 @@
178368 yymsp[1].minor.yy0 = yyLookaheadToken;
178369 }
178370 break;
178371 case 32: /* ccons ::= CONSTRAINT nm */
178372 case 67: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==67);
178373 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName = yymsp[0].minor.yy0;}
178374 break;
178375 case 33: /* ccons ::= DEFAULT scantok term */
178376 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);}
178377 break;
178378 case 34: /* ccons ::= DEFAULT LP expr RP */
@@ -178116,11 +178478,11 @@
178478 break;
178479 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
178480 {yymsp[-1].minor.yy502 = 0;}
178481 break;
178482 case 66: /* tconscomma ::= COMMA */
178483 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName.n = 0;}
178484 break;
178485 case 68: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
178486 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);}
178487 break;
178488 case 69: /* tcons ::= UNIQUE LP sortlist RP onconf */
@@ -179009,10 +179371,14 @@
179371 break;
179372 case 261: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
179373 {
179374 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy502, yymsp[-4].minor.yy28.a, yymsp[-4].minor.yy28.b, yymsp[-2].minor.yy563, yymsp[0].minor.yy590, yymsp[-10].minor.yy502, yymsp[-8].minor.yy502);
179375 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
179376 #ifdef SQLITE_DEBUG
179377 assert( pParse->isCreate ); /* Set by createkw reduce action */
179378 pParse->isCreate = 0; /* But, should not be set for CREATE TRIGGER */
179379 #endif
179380 }
179381 break;
179382 case 262: /* trigger_time ::= BEFORE|AFTER */
179383 { yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ }
179384 break;
@@ -183305,10 +183671,13 @@
183671 sqlite3_mutex_enter(db->mutex);
183672 db->busyHandler.xBusyHandler = xBusy;
183673 db->busyHandler.pBusyArg = pArg;
183674 db->busyHandler.nBusy = 0;
183675 db->busyTimeout = 0;
183676 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183677 db->setlkTimeout = 0;
183678 #endif
183679 sqlite3_mutex_leave(db->mutex);
183680 return SQLITE_OK;
183681 }
183682
183683 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
@@ -183354,15 +183723,46 @@
183723 #endif
183724 if( ms>0 ){
183725 sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
183726 (void*)db);
183727 db->busyTimeout = ms;
183728 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183729 db->setlkTimeout = ms;
183730 #endif
183731 }else{
183732 sqlite3_busy_handler(db, 0, 0);
183733 }
183734 return SQLITE_OK;
183735 }
183736
183737 /*
183738 ** Set the setlk timeout value.
183739 */
183740 SQLITE_API int sqlite3_setlk_timeout(sqlite3 *db, int ms, int flags){
183741 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183742 int iDb;
183743 int bBOC = ((flags & SQLITE_SETLK_BLOCK_ON_CONNECT) ? 1 : 0);
183744 #endif
183745 #ifdef SQLITE_ENABLE_API_ARMOR
183746 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
183747 #endif
183748 if( ms<-1 ) return SQLITE_RANGE;
183749 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
183750 db->setlkTimeout = ms;
183751 db->setlkFlags = flags;
183752 sqlite3BtreeEnterAll(db);
183753 for(iDb=0; iDb<db->nDb; iDb++){
183754 Btree *pBt = db->aDb[iDb].pBt;
183755 if( pBt ){
183756 sqlite3_file *fd = sqlite3PagerFile(sqlite3BtreePager(pBt));
183757 sqlite3OsFileControlHint(fd, SQLITE_FCNTL_BLOCK_ON_CONNECT, (void*)&bBOC);
183758 }
183759 }
183760 sqlite3BtreeLeaveAll(db);
183761 #endif
183762 return SQLITE_OK;
183763 }
183764
183765 /*
183766 ** Cause any pending operation to stop at its earliest opportunity.
183767 */
183768 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
@@ -185479,17 +185879,14 @@
185879
185880 /* Find the column for which info is requested */
185881 if( zColumnName==0 ){
185882 /* Query for existence of table only */
185883 }else{
185884 iCol = sqlite3ColumnIndex(pTab, zColumnName);
185885 if( iCol>=0 ){
185886 pCol = &pTab->aCol[iCol];
185887 }else{
 
 
 
 
185888 if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
185889 iCol = pTab->iPKey;
185890 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
185891 }else{
185892 pTab = 0;
@@ -208697,14 +209094,11 @@
209094 */
209095 static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){
209096 u8 x;
209097 u32 sz;
209098 u32 n;
209099 assert( i<=pParse->nBlob );
 
 
 
209100 x = pParse->aBlob[i]>>4;
209101 if( x<=11 ){
209102 sz = x;
209103 n = 1;
209104 }else if( x==12 ){
@@ -208744,12 +209138,12 @@
209138 n = 9;
209139 }
209140 if( (i64)i+sz+n > pParse->nBlob
209141 && (i64)i+sz+n > pParse->nBlob-pParse->delta
209142 ){
209143 *pSz = 0;
209144 return 0;
209145 }
209146 *pSz = sz;
209147 return n;
209148 }
209149
@@ -208842,13 +209236,16 @@
209236 }
209237 break;
209238 }
209239 case JSONB_TEXT:
209240 case JSONB_TEXTJ: {
209241 if( pOut->nUsed+sz+2<=pOut->nAlloc || jsonStringGrow(pOut, sz+2)==0 ){
209242 pOut->zBuf[pOut->nUsed] = '"';
209243 memcpy(pOut->zBuf+pOut->nUsed+1,(const char*)&pParse->aBlob[i+n],sz);
209244 pOut->zBuf[pOut->nUsed+sz+1] = '"';
209245 pOut->nUsed += sz+2;
209246 }
209247 break;
209248 }
209249 case JSONB_TEXT5: {
209250 const char *zIn;
209251 u32 k;
@@ -255870,11 +256267,11 @@
256267 int nArg, /* Number of args */
256268 sqlite3_value **apUnused /* Function arguments */
256269 ){
256270 assert( nArg==0 );
256271 UNUSED_PARAM2(nArg, apUnused);
256272 sqlite3_result_text(pCtx, "fts5: 2025-02-11 17:10:46 e5ec5bb9f4dc3e02db7ab0e49686f47617af75d3f7d4ab23288a1aea4a693e59", -1, SQLITE_TRANSIENT);
256273 }
256274
256275 /*
256276 ** Implementation of fts5_locale(LOCALE, TEXT) function.
256277 **
256278
+47 -3
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.49.0"
150
-#define SQLITE_VERSION_NUMBER 3049000
151
-#define SQLITE_SOURCE_ID "2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde"
149
+#define SQLITE_VERSION "3.50.0"
150
+#define SQLITE_VERSION_NUMBER 3050000
151
+#define SQLITE_SOURCE_ID "2025-02-11 17:10:46 e5ec5bb9f4dc3e02db7ab0e49686f47617af75d3f7d4ab23288a1aea4a693e59"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -1161,10 +1161,15 @@
11611161
** obtain a file lock using the xLock or xShmLock methods of the VFS.
11621162
** The parameter is a pointer to a 32-bit signed integer that contains
11631163
** the value that M is to be set to. Before returning, the 32-bit signed
11641164
** integer is overwritten with the previous value of M.
11651165
**
1166
+** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]
1167
+** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the
1168
+** VFS to block when taking SHARED locks. This is used to implement the
1169
+** functionality associated with SQLITE_SETLK_BLOCK_ON_CONNECT.
1170
+**
11661171
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
11671172
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
11681173
** a database file. The argument is a pointer to a 32-bit unsigned integer.
11691174
** The "data version" for the pager is written into the pointer. The
11701175
** "data version" changes whenever any change occurs to the corresponding
@@ -1257,10 +1262,11 @@
12571262
#define SQLITE_FCNTL_CKPT_START 39
12581263
#define SQLITE_FCNTL_EXTERNAL_READER 40
12591264
#define SQLITE_FCNTL_CKSM_FILE 41
12601265
#define SQLITE_FCNTL_RESET_CACHE 42
12611266
#define SQLITE_FCNTL_NULL_IO 43
1267
+#define SQLITE_FCNTL_BLOCK_ON_CONNECT 44
12621268
12631269
/* deprecated names */
12641270
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
12651271
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
12661272
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2991,10 +2997,48 @@
29912997
**
29922998
** See also: [PRAGMA busy_timeout]
29932999
*/
29943000
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
29953001
3002
+/*
3003
+** CAPI3REF: Set the Setlk Timeout
3004
+** METHOD: sqlite3
3005
+**
3006
+** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If
3007
+** the VFS supports blocking locks, it sets the timeout in ms used by
3008
+** eligible locks taken on wal mode databases by the specified database
3009
+** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does
3010
+** not support blocking locks, this function is a no-op.
3011
+**
3012
+** Passing 0 to this function disables blocking locks altogether. Passing
3013
+** -1 to this function requests that the VFS blocks for a long time -
3014
+** indefinitely if possible. The results of passing any other negative value
3015
+** are undefined.
3016
+**
3017
+** Internally, each SQLite database handle store two timeout values - the
3018
+** busy-timeout (used for rollback mode databases, or if the VFS does not
3019
+** support blocking locks) and the setlk-timeout (used for blocking locks
3020
+** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3021
+** values, this function sets only the setlk-timeout value. Therefore,
3022
+** to configure separate busy-timeout and setlk-timeout values for a single
3023
+** database handle, call sqlite3_busy_timeout() followed by this function.
3024
+**
3025
+** Whenever the number of connections to a wal mode database falls from
3026
+** 1 to 0, the last connection takes an exclusive lock on the database,
3027
+** then checkpoints and deletes the wal file. While it is doing this, any
3028
+** new connection that tries to read from the database fails with an
3029
+** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is
3030
+** passed to this API, the new connection blocks until the exclusive lock
3031
+** has been released.
3032
+*/
3033
+SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);
3034
+
3035
+/*
3036
+** CAPI3REF: Flags for sqlite3_setlk_timeout()
3037
+*/
3038
+#define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01
3039
+
29963040
/*
29973041
** CAPI3REF: Convenience Routines For Running Queries
29983042
** METHOD: sqlite3
29993043
**
30003044
** This is a legacy interface that is preserved for backwards compatibility.
30013045
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.49.0"
150 #define SQLITE_VERSION_NUMBER 3049000
151 #define SQLITE_SOURCE_ID "2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -1161,10 +1161,15 @@
1161 ** obtain a file lock using the xLock or xShmLock methods of the VFS.
1162 ** The parameter is a pointer to a 32-bit signed integer that contains
1163 ** the value that M is to be set to. Before returning, the 32-bit signed
1164 ** integer is overwritten with the previous value of M.
1165 **
 
 
 
 
 
1166 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1167 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1168 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
1169 ** The "data version" for the pager is written into the pointer. The
1170 ** "data version" changes whenever any change occurs to the corresponding
@@ -1257,10 +1262,11 @@
1257 #define SQLITE_FCNTL_CKPT_START 39
1258 #define SQLITE_FCNTL_EXTERNAL_READER 40
1259 #define SQLITE_FCNTL_CKSM_FILE 41
1260 #define SQLITE_FCNTL_RESET_CACHE 42
1261 #define SQLITE_FCNTL_NULL_IO 43
 
1262
1263 /* deprecated names */
1264 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1265 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1266 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2991,10 +2997,48 @@
2991 **
2992 ** See also: [PRAGMA busy_timeout]
2993 */
2994 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
2995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2996 /*
2997 ** CAPI3REF: Convenience Routines For Running Queries
2998 ** METHOD: sqlite3
2999 **
3000 ** This is a legacy interface that is preserved for backwards compatibility.
3001
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.50.0"
150 #define SQLITE_VERSION_NUMBER 3050000
151 #define SQLITE_SOURCE_ID "2025-02-11 17:10:46 e5ec5bb9f4dc3e02db7ab0e49686f47617af75d3f7d4ab23288a1aea4a693e59"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -1161,10 +1161,15 @@
1161 ** obtain a file lock using the xLock or xShmLock methods of the VFS.
1162 ** The parameter is a pointer to a 32-bit signed integer that contains
1163 ** the value that M is to be set to. Before returning, the 32-bit signed
1164 ** integer is overwritten with the previous value of M.
1165 **
1166 ** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]
1167 ** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the
1168 ** VFS to block when taking SHARED locks. This is used to implement the
1169 ** functionality associated with SQLITE_SETLK_BLOCK_ON_CONNECT.
1170 **
1171 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1172 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1173 ** a database file. The argument is a pointer to a 32-bit unsigned integer.
1174 ** The "data version" for the pager is written into the pointer. The
1175 ** "data version" changes whenever any change occurs to the corresponding
@@ -1257,10 +1262,11 @@
1262 #define SQLITE_FCNTL_CKPT_START 39
1263 #define SQLITE_FCNTL_EXTERNAL_READER 40
1264 #define SQLITE_FCNTL_CKSM_FILE 41
1265 #define SQLITE_FCNTL_RESET_CACHE 42
1266 #define SQLITE_FCNTL_NULL_IO 43
1267 #define SQLITE_FCNTL_BLOCK_ON_CONNECT 44
1268
1269 /* deprecated names */
1270 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1271 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1272 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2991,10 +2997,48 @@
2997 **
2998 ** See also: [PRAGMA busy_timeout]
2999 */
3000 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
3001
3002 /*
3003 ** CAPI3REF: Set the Setlk Timeout
3004 ** METHOD: sqlite3
3005 **
3006 ** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If
3007 ** the VFS supports blocking locks, it sets the timeout in ms used by
3008 ** eligible locks taken on wal mode databases by the specified database
3009 ** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does
3010 ** not support blocking locks, this function is a no-op.
3011 **
3012 ** Passing 0 to this function disables blocking locks altogether. Passing
3013 ** -1 to this function requests that the VFS blocks for a long time -
3014 ** indefinitely if possible. The results of passing any other negative value
3015 ** are undefined.
3016 **
3017 ** Internally, each SQLite database handle store two timeout values - the
3018 ** busy-timeout (used for rollback mode databases, or if the VFS does not
3019 ** support blocking locks) and the setlk-timeout (used for blocking locks
3020 ** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3021 ** values, this function sets only the setlk-timeout value. Therefore,
3022 ** to configure separate busy-timeout and setlk-timeout values for a single
3023 ** database handle, call sqlite3_busy_timeout() followed by this function.
3024 **
3025 ** Whenever the number of connections to a wal mode database falls from
3026 ** 1 to 0, the last connection takes an exclusive lock on the database,
3027 ** then checkpoints and deletes the wal file. While it is doing this, any
3028 ** new connection that tries to read from the database fails with an
3029 ** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is
3030 ** passed to this API, the new connection blocks until the exclusive lock
3031 ** has been released.
3032 */
3033 SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);
3034
3035 /*
3036 ** CAPI3REF: Flags for sqlite3_setlk_timeout()
3037 */
3038 #define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01
3039
3040 /*
3041 ** CAPI3REF: Convenience Routines For Running Queries
3042 ** METHOD: sqlite3
3043 **
3044 ** This is a legacy interface that is preserved for backwards compatibility.
3045
+1
--- src/db.c
+++ src/db.c
@@ -2192,10 +2192,11 @@
21922192
sqlite3_db_config(db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, 0, &rc);
21932193
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, &rc);
21942194
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, &rc);
21952195
sqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, 1, &rc);
21962196
sqlite3_busy_timeout(db, 15000);
2197
+ sqlite3_setlk_timeout(db, 15000, SQLITE_SETLK_BLOCK_ON_CONNECT);
21972198
sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
21982199
sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
21992200
sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
22002201
sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
22012202
sqlite3_create_function(db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
22022203
--- src/db.c
+++ src/db.c
@@ -2192,10 +2192,11 @@
2192 sqlite3_db_config(db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, 0, &rc);
2193 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, &rc);
2194 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, &rc);
2195 sqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, 1, &rc);
2196 sqlite3_busy_timeout(db, 15000);
 
2197 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
2198 sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
2199 sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
2200 sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
2201 sqlite3_create_function(db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
2202
--- src/db.c
+++ src/db.c
@@ -2192,10 +2192,11 @@
2192 sqlite3_db_config(db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, 0, &rc);
2193 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, &rc);
2194 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, &rc);
2195 sqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, 1, &rc);
2196 sqlite3_busy_timeout(db, 15000);
2197 sqlite3_setlk_timeout(db, 15000, SQLITE_SETLK_BLOCK_ON_CONNECT);
2198 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
2199 sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
2200 sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
2201 sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
2202 sqlite3_create_function(db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
2203
--- src/main.mk
+++ src/main.mk
@@ -657,10 +657,11 @@
657657
-DSQLITE_ENABLE_MATH_FUNCTIONS \
658658
-DSQLITE_ENABLE_STMTVTAB \
659659
-DSQLITE_HAVE_ZLIB \
660660
-DSQLITE_ENABLE_DBPAGE_VTAB \
661661
-DSQLITE_TRUSTED_SCHEMA=0 \
662
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
662663
-DHAVE_USLEEP
663664
664665
# Setup the options used to compile the included SQLite shell.
665666
SHELL_OPTIONS = -DNDEBUG=1 \
666667
-DSQLITE_DQS=0 \
@@ -683,10 +684,11 @@
683684
-DSQLITE_ENABLE_MATH_FUNCTIONS \
684685
-DSQLITE_ENABLE_STMTVTAB \
685686
-DSQLITE_HAVE_ZLIB \
686687
-DSQLITE_ENABLE_DBPAGE_VTAB \
687688
-DSQLITE_TRUSTED_SCHEMA=0 \
689
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
688690
-DHAVE_USLEEP \
689691
-Dmain=sqlite3_shell \
690692
-DSQLITE_SHELL_IS_UTF8=1 \
691693
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
692694
-DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
693695
--- src/main.mk
+++ src/main.mk
@@ -657,10 +657,11 @@
657 -DSQLITE_ENABLE_MATH_FUNCTIONS \
658 -DSQLITE_ENABLE_STMTVTAB \
659 -DSQLITE_HAVE_ZLIB \
660 -DSQLITE_ENABLE_DBPAGE_VTAB \
661 -DSQLITE_TRUSTED_SCHEMA=0 \
 
662 -DHAVE_USLEEP
663
664 # Setup the options used to compile the included SQLite shell.
665 SHELL_OPTIONS = -DNDEBUG=1 \
666 -DSQLITE_DQS=0 \
@@ -683,10 +684,11 @@
683 -DSQLITE_ENABLE_MATH_FUNCTIONS \
684 -DSQLITE_ENABLE_STMTVTAB \
685 -DSQLITE_HAVE_ZLIB \
686 -DSQLITE_ENABLE_DBPAGE_VTAB \
687 -DSQLITE_TRUSTED_SCHEMA=0 \
 
688 -DHAVE_USLEEP \
689 -Dmain=sqlite3_shell \
690 -DSQLITE_SHELL_IS_UTF8=1 \
691 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
692 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
693
--- src/main.mk
+++ src/main.mk
@@ -657,10 +657,11 @@
657 -DSQLITE_ENABLE_MATH_FUNCTIONS \
658 -DSQLITE_ENABLE_STMTVTAB \
659 -DSQLITE_HAVE_ZLIB \
660 -DSQLITE_ENABLE_DBPAGE_VTAB \
661 -DSQLITE_TRUSTED_SCHEMA=0 \
662 -DSQLITE_ENABLE_SETLK_TIMEOUT \
663 -DHAVE_USLEEP
664
665 # Setup the options used to compile the included SQLite shell.
666 SHELL_OPTIONS = -DNDEBUG=1 \
667 -DSQLITE_DQS=0 \
@@ -683,10 +684,11 @@
684 -DSQLITE_ENABLE_MATH_FUNCTIONS \
685 -DSQLITE_ENABLE_STMTVTAB \
686 -DSQLITE_HAVE_ZLIB \
687 -DSQLITE_ENABLE_DBPAGE_VTAB \
688 -DSQLITE_TRUSTED_SCHEMA=0 \
689 -DSQLITE_ENABLE_SETLK_TIMEOUT \
690 -DHAVE_USLEEP \
691 -Dmain=sqlite3_shell \
692 -DSQLITE_SHELL_IS_UTF8=1 \
693 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
694 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
695
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -249,10 +249,11 @@
249249
-DSQLITE_ENABLE_MATH_FUNCTIONS
250250
-DSQLITE_ENABLE_STMTVTAB
251251
-DSQLITE_HAVE_ZLIB
252252
-DSQLITE_ENABLE_DBPAGE_VTAB
253253
-DSQLITE_TRUSTED_SCHEMA=0
254
+ -DSQLITE_ENABLE_SETLK_TIMEOUT
254255
-DHAVE_USLEEP
255256
}
256257
#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
257258
#lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
258259
#lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
259260
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -249,10 +249,11 @@
249 -DSQLITE_ENABLE_MATH_FUNCTIONS
250 -DSQLITE_ENABLE_STMTVTAB
251 -DSQLITE_HAVE_ZLIB
252 -DSQLITE_ENABLE_DBPAGE_VTAB
253 -DSQLITE_TRUSTED_SCHEMA=0
 
254 -DHAVE_USLEEP
255 }
256 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
257 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
258 #lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
259
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -249,10 +249,11 @@
249 -DSQLITE_ENABLE_MATH_FUNCTIONS
250 -DSQLITE_ENABLE_STMTVTAB
251 -DSQLITE_HAVE_ZLIB
252 -DSQLITE_ENABLE_DBPAGE_VTAB
253 -DSQLITE_TRUSTED_SCHEMA=0
254 -DSQLITE_ENABLE_SETLK_TIMEOUT
255 -DHAVE_USLEEP
256 }
257 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_FTS3=1
258 #lappend SQLITE_OPTIONS -DSQLITE_ENABLE_STAT4
259 #lappend SQLITE_OPTIONS -DSQLITE_WIN32_NO_ANSI
260
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
2626
CFLAGS = -o
2727
BCC = $(DMDIR)\bin\dmc $(CFLAGS)
2828
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2929
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
3030
31
-SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
31
+SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DSQLITE_ENABLE_SETLK_TIMEOUT -DHAVE_USLEEP
3232
33
-SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
33
+SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DSQLITE_ENABLE_SETLK_TIMEOUT -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3434
3535
PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
3636
3737
SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
3838
3939
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
26 CFLAGS = -o
27 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
28 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
29 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
30
31 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP
32
33 SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
34
35 PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
36
37 SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
38
39
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,13 +26,13 @@
26 CFLAGS = -o
27 BCC = $(DMDIR)\bin\dmc $(CFLAGS)
28 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
29 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32 dnsapi
30
31 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DSQLITE_ENABLE_SETLK_TIMEOUT -DHAVE_USLEEP
32
33 SHELL_OPTIONS = -DNDEBUG=1 -DSQLITE_DQS=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_ENABLE_STMTVTAB -DSQLITE_HAVE_ZLIB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_TRUSTED_SCHEMA=0 -DSQLITE_ENABLE_SETLK_TIMEOUT -DHAVE_USLEEP -Dmain=sqlite3_shell -DSQLITE_SHELL_IS_UTF8=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=sqlcmd_get_dbname -DSQLITE_SHELL_INIT_PROC=sqlcmd_init_proc -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
34
35 PIKCHR_OPTIONS = -DPIKCHR_TOKEN_LIMIT=10000
36
37 SRC = add_.c ajax_.c alerts_.c allrepo_.c attach_.c backlink_.c backoffice_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c capabilities_.c captcha_.c cgi_.c chat_.c checkin_.c checkout_.c clearsign_.c clone_.c color_.c comformat_.c configure_.c content_.c cookies_.c db_.c delta_.c deltacmd_.c deltafunc_.c descendants_.c diff_.c diffcmd_.c dispatch_.c doc_.c encode_.c etag_.c event_.c export_.c extcgi_.c file_.c fileedit_.c finfo_.c foci_.c forum_.c fshell_.c fusefs_.c fuzz_.c glob_.c graph_.c gzip_.c hname_.c hook_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c interwiki_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c match_.c md5_.c merge_.c merge3_.c moderate_.c name_.c patch_.c path_.c piechart_.c pikchrshow_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c repolist_.c report_.c rss_.c schema_.c search_.c security_audit_.c setup_.c setupuser_.c sha1_.c sha1hard_.c sha3_.c shun_.c sitemap_.c skins_.c smtp_.c sqlcmd_.c stash_.c stat_.c statrep_.c style_.c sync_.c tag_.c tar_.c terminal_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c unversioned_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c xfer_.c xfersetup_.c zip_.c
38
39
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2537,10 +2537,11 @@
25372537
-DSQLITE_ENABLE_MATH_FUNCTIONS \
25382538
-DSQLITE_ENABLE_STMTVTAB \
25392539
-DSQLITE_HAVE_ZLIB \
25402540
-DSQLITE_ENABLE_DBPAGE_VTAB \
25412541
-DSQLITE_TRUSTED_SCHEMA=0 \
2542
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
25422543
-DHAVE_USLEEP \
25432544
-DSQLITE_WIN32_NO_ANSI \
25442545
$(MINGW_OPTIONS) \
25452546
-DSQLITE_USE_MALLOC_H \
25462547
-DSQLITE_USE_MSIZE
@@ -2566,10 +2567,11 @@
25662567
-DSQLITE_ENABLE_MATH_FUNCTIONS \
25672568
-DSQLITE_ENABLE_STMTVTAB \
25682569
-DSQLITE_HAVE_ZLIB \
25692570
-DSQLITE_ENABLE_DBPAGE_VTAB \
25702571
-DSQLITE_TRUSTED_SCHEMA=0 \
2572
+ -DSQLITE_ENABLE_SETLK_TIMEOUT \
25712573
-DHAVE_USLEEP \
25722574
-Dmain=sqlite3_shell \
25732575
-DSQLITE_SHELL_IS_UTF8=1 \
25742576
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
25752577
-DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
25762578
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2537,10 +2537,11 @@
2537 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2538 -DSQLITE_ENABLE_STMTVTAB \
2539 -DSQLITE_HAVE_ZLIB \
2540 -DSQLITE_ENABLE_DBPAGE_VTAB \
2541 -DSQLITE_TRUSTED_SCHEMA=0 \
 
2542 -DHAVE_USLEEP \
2543 -DSQLITE_WIN32_NO_ANSI \
2544 $(MINGW_OPTIONS) \
2545 -DSQLITE_USE_MALLOC_H \
2546 -DSQLITE_USE_MSIZE
@@ -2566,10 +2567,11 @@
2566 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2567 -DSQLITE_ENABLE_STMTVTAB \
2568 -DSQLITE_HAVE_ZLIB \
2569 -DSQLITE_ENABLE_DBPAGE_VTAB \
2570 -DSQLITE_TRUSTED_SCHEMA=0 \
 
2571 -DHAVE_USLEEP \
2572 -Dmain=sqlite3_shell \
2573 -DSQLITE_SHELL_IS_UTF8=1 \
2574 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
2575 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
2576
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -2537,10 +2537,11 @@
2537 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2538 -DSQLITE_ENABLE_STMTVTAB \
2539 -DSQLITE_HAVE_ZLIB \
2540 -DSQLITE_ENABLE_DBPAGE_VTAB \
2541 -DSQLITE_TRUSTED_SCHEMA=0 \
2542 -DSQLITE_ENABLE_SETLK_TIMEOUT \
2543 -DHAVE_USLEEP \
2544 -DSQLITE_WIN32_NO_ANSI \
2545 $(MINGW_OPTIONS) \
2546 -DSQLITE_USE_MALLOC_H \
2547 -DSQLITE_USE_MSIZE
@@ -2566,10 +2567,11 @@
2567 -DSQLITE_ENABLE_MATH_FUNCTIONS \
2568 -DSQLITE_ENABLE_STMTVTAB \
2569 -DSQLITE_HAVE_ZLIB \
2570 -DSQLITE_ENABLE_DBPAGE_VTAB \
2571 -DSQLITE_TRUSTED_SCHEMA=0 \
2572 -DSQLITE_ENABLE_SETLK_TIMEOUT \
2573 -DHAVE_USLEEP \
2574 -Dmain=sqlite3_shell \
2575 -DSQLITE_SHELL_IS_UTF8=1 \
2576 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
2577 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
2578
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -320,10 +320,11 @@
320320
/DSQLITE_ENABLE_MATH_FUNCTIONS \
321321
/DSQLITE_ENABLE_STMTVTAB \
322322
/DSQLITE_HAVE_ZLIB \
323323
/DSQLITE_ENABLE_DBPAGE_VTAB \
324324
/DSQLITE_TRUSTED_SCHEMA=0 \
325
+ /DSQLITE_ENABLE_SETLK_TIMEOUT \
325326
/DHAVE_USLEEP \
326327
/DSQLITE_WIN32_NO_ANSI
327328
328329
SHELL_OPTIONS = /DNDEBUG=1 \
329330
/DSQLITE_DQS=0 \
@@ -346,10 +347,11 @@
346347
/DSQLITE_ENABLE_MATH_FUNCTIONS \
347348
/DSQLITE_ENABLE_STMTVTAB \
348349
/DSQLITE_HAVE_ZLIB \
349350
/DSQLITE_ENABLE_DBPAGE_VTAB \
350351
/DSQLITE_TRUSTED_SCHEMA=0 \
352
+ /DSQLITE_ENABLE_SETLK_TIMEOUT \
351353
/DHAVE_USLEEP \
352354
/Dmain=sqlite3_shell \
353355
/DSQLITE_SHELL_IS_UTF8=1 \
354356
/DSQLITE_OMIT_LOAD_EXTENSION=1 \
355357
/DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
356358
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -320,10 +320,11 @@
320 /DSQLITE_ENABLE_MATH_FUNCTIONS \
321 /DSQLITE_ENABLE_STMTVTAB \
322 /DSQLITE_HAVE_ZLIB \
323 /DSQLITE_ENABLE_DBPAGE_VTAB \
324 /DSQLITE_TRUSTED_SCHEMA=0 \
 
325 /DHAVE_USLEEP \
326 /DSQLITE_WIN32_NO_ANSI
327
328 SHELL_OPTIONS = /DNDEBUG=1 \
329 /DSQLITE_DQS=0 \
@@ -346,10 +347,11 @@
346 /DSQLITE_ENABLE_MATH_FUNCTIONS \
347 /DSQLITE_ENABLE_STMTVTAB \
348 /DSQLITE_HAVE_ZLIB \
349 /DSQLITE_ENABLE_DBPAGE_VTAB \
350 /DSQLITE_TRUSTED_SCHEMA=0 \
 
351 /DHAVE_USLEEP \
352 /Dmain=sqlite3_shell \
353 /DSQLITE_SHELL_IS_UTF8=1 \
354 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
355 /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
356
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -320,10 +320,11 @@
320 /DSQLITE_ENABLE_MATH_FUNCTIONS \
321 /DSQLITE_ENABLE_STMTVTAB \
322 /DSQLITE_HAVE_ZLIB \
323 /DSQLITE_ENABLE_DBPAGE_VTAB \
324 /DSQLITE_TRUSTED_SCHEMA=0 \
325 /DSQLITE_ENABLE_SETLK_TIMEOUT \
326 /DHAVE_USLEEP \
327 /DSQLITE_WIN32_NO_ANSI
328
329 SHELL_OPTIONS = /DNDEBUG=1 \
330 /DSQLITE_DQS=0 \
@@ -346,10 +347,11 @@
347 /DSQLITE_ENABLE_MATH_FUNCTIONS \
348 /DSQLITE_ENABLE_STMTVTAB \
349 /DSQLITE_HAVE_ZLIB \
350 /DSQLITE_ENABLE_DBPAGE_VTAB \
351 /DSQLITE_TRUSTED_SCHEMA=0 \
352 /DSQLITE_ENABLE_SETLK_TIMEOUT \
353 /DHAVE_USLEEP \
354 /Dmain=sqlite3_shell \
355 /DSQLITE_SHELL_IS_UTF8=1 \
356 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
357 /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
358

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button