Fossil SCM

Update the built-in SQLite to the latest trunk version that includes all recent fixes.

drh 2025-02-18 12:23 trunk
Commit 679265a7261fb8a6215aa237330cc6c542aa4f109863f0011ce2dba7f6580aa8
2 files changed +469 -379 +45 -36
+469 -379
--- 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
+** 57caa3136d1bfca06e4f2285734a4977b8d3 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-18 01:16:26 57caa3136d1bfca06e4f2285734a4977b8d3fa1f75bf87453b975867e9de38fc"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -2306,17 +2306,20 @@
23062306
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
23072307
** return [SQLITE_ERROR].</dd>
23082308
**
23092309
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
23102310
** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
2311
-** the default size of lookaside memory on each [database connection].
2311
+** the default size of [lookaside memory] on each [database connection].
23122312
** The first argument is the
2313
-** size of each lookaside buffer slot and the second is the number of
2314
-** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
2315
-** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
2316
-** option to [sqlite3_db_config()] can be used to change the lookaside
2317
-** configuration on individual connections.)^ </dd>
2313
+** size of each lookaside buffer slot ("sz") and the second is the number of
2314
+** slots allocated to each database connection ("cnt").)^
2315
+** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.
2316
+** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can
2317
+** be used to change the lookaside configuration on individual connections.)^
2318
+** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the
2319
+** default lookaside configuration at compile-time.
2320
+** </dd>
23182321
**
23192322
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
23202323
** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
23212324
** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
23222325
** the interface to a custom page cache implementation.)^
@@ -2549,35 +2552,54 @@
25492552
**
25502553
** <dl>
25512554
** [[SQLITE_DBCONFIG_LOOKASIDE]]
25522555
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
25532556
** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2554
-** configuration of the lookaside memory allocator within a database
2557
+** configuration of the [lookaside memory allocator] within a database
25552558
** connection.
25562559
** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
25572560
** in the [DBCONFIG arguments|usual format].
25582561
** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
25592562
** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
25602563
** should have a total of five parameters.
2561
-** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2564
+** <ol>
2565
+** <li><p>The first argument ("buf") is a
25622566
** pointer to a memory buffer to use for lookaside memory.
2563
-** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2564
-** may be NULL in which case SQLite will allocate the
2565
-** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2566
-** size of each lookaside buffer slot. ^The third argument is the number of
2567
-** slots. The size of the buffer in the first argument must be greater than
2568
-** or equal to the product of the second and third arguments. The buffer
2569
-** must be aligned to an 8-byte boundary. ^If the second argument to
2570
-** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2571
-** rounded down to the next smaller multiple of 8. ^(The lookaside memory
2567
+** The first argument may be NULL in which case SQLite will allocate the
2568
+** lookaside buffer itself using [sqlite3_malloc()].
2569
+** <li><P>The second argument ("sz") is the
2570
+** size of each lookaside buffer slot. Lookaside is disabled if "sz"
2571
+** is less than 8. The "sz" argument should be a multiple of 8 less than
2572
+** 65536. If "sz" does not meet this constraint, it is reduced in size until
2573
+** it does.
2574
+** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled
2575
+** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so
2576
+** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt"
2577
+** parameter is usually chosen so that the product of "sz" and "cnt" is less
2578
+** than 1,000,000.
2579
+** </ol>
2580
+** <p>If the "buf" argument is not NULL, then it must
2581
+** point to a memory buffer with a size that is greater than
2582
+** or equal to the product of "sz" and "cnt".
2583
+** The buffer must be aligned to an 8-byte boundary.
2584
+** The lookaside memory
25722585
** configuration for a database connection can only be changed when that
25732586
** connection is not currently using lookaside memory, or in other words
2574
-** when the "current value" returned by
2575
-** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2587
+** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.
25762588
** Any attempt to change the lookaside memory configuration when lookaside
25772589
** memory is in use leaves the configuration unchanged and returns
2578
-** [SQLITE_BUSY].)^</dd>
2590
+** [SQLITE_BUSY].
2591
+** If the "buf" argument is NULL and an attempt
2592
+** to allocate memory based on "sz" and "cnt" fails, then
2593
+** lookaside is silently disabled.
2594
+** <p>
2595
+** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the
2596
+** default lookaside configuration at initialization. The
2597
+** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside
2598
+** configuration at compile-time. Typical values for lookaside are 1200 for
2599
+** "sz" and 40 to 100 for "cnt".
2600
+** </dd>
25792601
**
25802602
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
25812603
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
25822604
** <dd> ^This option is used to enable or disable the enforcement of
25832605
** [foreign key constraints]. This is the same setting that is
@@ -12328,23 +12350,10 @@
1232812350
void *pB, /* Pointer to buffer containing changeset B */
1232912351
int *pnOut, /* OUT: Number of bytes in output changeset */
1233012352
void **ppOut /* OUT: Buffer containing output changeset */
1233112353
);
1233212354
12333
-
12334
-/*
12335
-** CAPI3REF: Upgrade the Schema of a Changeset/Patchset
12336
-*/
12337
-SQLITE_API int sqlite3changeset_upgrade(
12338
- sqlite3 *db,
12339
- const char *zDb,
12340
- int nIn, const void *pIn, /* Input changeset */
12341
- int *pnOut, void **ppOut /* OUT: Inverse of input */
12342
-);
12343
-
12344
-
12345
-
1234612355
/*
1234712356
** CAPI3REF: Changegroup Handle
1234812357
**
1234912358
** A changegroup is an object used to combine two or more
1235012359
** [changesets] or [patchsets]
@@ -14747,10 +14756,11 @@
1474714756
*/
1474814757
struct HashElem {
1474914758
HashElem *next, *prev; /* Next and previous elements in the table */
1475014759
void *data; /* Data associated with this element */
1475114760
const char *pKey; /* Key associated with this element */
14761
+ unsigned int h; /* hash for pKey */
1475214762
};
1475314763
1475414764
/*
1475514765
** Access routines. To delete, insert a NULL pointer.
1475614766
*/
@@ -15185,10 +15195,15 @@
1518515195
typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
1518615196
typedef INT16_TYPE i16; /* 2-byte signed integer */
1518715197
typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
1518815198
typedef INT8_TYPE i8; /* 1-byte signed integer */
1518915199
15200
+/* A bitfield type for use inside of structures. Always follow with :N where
15201
+** N is the number of bits.
15202
+*/
15203
+typedef unsigned bft; /* Bit Field Type */
15204
+
1519015205
/*
1519115206
** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
1519215207
** that can be stored in a u32 without loss of data. The value
1519315208
** is 0x00000000ffffffff. But because of quirks of some compilers, we
1519415209
** have to specify the value in the less intuitive manner shown:
@@ -15353,10 +15368,18 @@
1535315368
*/
1535415369
#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
1535515370
#define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32))
1535615371
#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
1535715372
15373
+/*
15374
+** Macro SMXV(n) return the maximum value that can be held in variable n,
15375
+** assuming n is a signed integer type. UMXV(n) is similar for unsigned
15376
+** integer types.
15377
+*/
15378
+#define SMXV(n) ((((i64)1)<<(sizeof(n)-1))-1)
15379
+#define UMXV(n) ((((i64)1)<<(sizeof(n)))-1)
15380
+
1535815381
/*
1535915382
** Round up a number to the next larger multiple of 8. This is used
1536015383
** to force 8-byte alignment on 64-bit architectures.
1536115384
**
1536215385
** ROUND8() always does the rounding, for any argument.
@@ -18731,10 +18754,11 @@
1873118754
VTable *p; /* List of VTable objects. */
1873218755
} vtab;
1873318756
} u;
1873418757
Trigger *pTrigger; /* List of triggers on this object */
1873518758
Schema *pSchema; /* Schema that contains this table */
18759
+ u8 aHx[16]; /* Column aHt[K%sizeof(aHt)] might have hash K */
1873618760
};
1873718761
1873818762
/*
1873918763
** Allowed values for Table.tabFlags.
1874018764
**
@@ -20128,29 +20152,36 @@
2012820152
struct Parse {
2012920153
sqlite3 *db; /* The main database structure */
2013020154
char *zErrMsg; /* An error message */
2013120155
Vdbe *pVdbe; /* An engine for executing database bytecode */
2013220156
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 */
20157
+ LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
2013520158
u8 nested; /* Number of nested calls to the parser/code generator */
2013620159
u8 nTempReg; /* Number of temporary registers in aTempReg[] */
2013720160
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
2013820161
u8 mayAbort; /* True if statement may throw an ABORT exception */
2013920162
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
20140
- u8 okConstFactor; /* OK to factor out constants */
2014120163
u8 disableLookaside; /* Number of times lookaside has been disabled */
2014220164
u8 prepFlags; /* SQLITE_PREPARE_* flags */
2014320165
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
20144
- u8 bHasWith; /* True if statement contains WITH */
2014520166
u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20167
+ u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20168
+ u8 bReturning; /* Coding a RETURNING trigger */
20169
+ u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20170
+ u8 disableTriggers; /* True to disable triggers */
2014620171
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
2014720172
u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
2014820173
#endif
2014920174
#ifdef SQLITE_DEBUG
2015020175
u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
20176
+ u8 isCreate; /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
20177
+ ** and ALTER TABLE ADD COLUMN. */
2015120178
#endif
20179
+ bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20180
+ bft bHasWith :1; /* True if statement contains WITH */
20181
+ bft okConstFactor :1; /* OK to factor out constants */
20182
+ bft checkSchema :1; /* Causes schema cookie check after an error */
2015220183
int nRangeReg; /* Size of the temporary register block */
2015320184
int iRangeReg; /* First register in temporary register block */
2015420185
int nErr; /* Number of errors seen */
2015520186
int nTab; /* Number of previously allocated VDBE cursors */
2015620187
int nMem; /* Number of memory cells used so far */
@@ -20161,16 +20192,13 @@
2016120192
int nLabelAlloc; /* Number of slots in aLabel */
2016220193
int *aLabel; /* Space to hold the labels */
2016320194
ExprList *pConstExpr;/* Constant expressions */
2016420195
IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
2016520196
IndexedExpr *pIdxPartExpr; /* Exprs constrained by index WHERE clauses */
20166
- Token constraintName;/* Name of the constraint currently being parsed */
2016720197
yDbMask writeMask; /* Start a write transaction on these databases */
2016820198
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 */
20199
+ int nMaxArg; /* Max args to xUpdate and xFilter vtab methods */
2017220200
int nSelect; /* Number of SELECT stmts. Counter for Select.selId */
2017320201
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
2017420202
u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
2017520203
#endif
2017620204
#ifndef SQLITE_OMIT_SHARED_CACHE
@@ -20180,21 +20208,10 @@
2018020208
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
2018120209
Parse *pToplevel; /* Parse structure for main program (or NULL) */
2018220210
Table *pTriggerTab; /* Table triggers are being coded for */
2018320211
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
2018420212
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 */
2019620213
2019720214
/**************************************************************************
2019820215
** Fields above must be initialized to zero. The fields that follow,
2019920216
** down to the beginning of the recursive section, do not need to be
2020020217
** initialized as they will be set before being used. The boundary is
@@ -20202,10 +20219,23 @@
2020220219
**************************************************************************/
2020320220
2020420221
int aTempReg[8]; /* Holding area for temporary registers */
2020520222
Parse *pOuterParse; /* Outer Parse object when nested */
2020620223
Token sNameToken; /* Token with unqualified schema object name */
20224
+ u32 oldmask; /* Mask of old.* columns referenced */
20225
+ u32 newmask; /* Mask of new.* columns referenced */
20226
+ union {
20227
+ struct { /* These fields available when isCreate is true */
20228
+ int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
20229
+ int regRowid; /* Register holding rowid of CREATE TABLE entry */
20230
+ int regRoot; /* Register holding root page for new objects */
20231
+ Token constraintName; /* Name of the constraint currently being parsed */
20232
+ } cr;
20233
+ struct { /* These fields available to all other statements */
20234
+ Returning *pReturning; /* The RETURNING clause */
20235
+ } d;
20236
+ } u1;
2020720237
2020820238
/************************************************************************
2020920239
** Above is constant between recursions. Below is reset before and after
2021020240
** each recursion. The boundary between these two regions is determined
2021120241
** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -23831,14 +23861,10 @@
2383123861
u8 skipFlag; /* Skip accumulator loading if true */
2383223862
u16 argc; /* Number of arguments */
2383323863
sqlite3_value *argv[1]; /* Argument set */
2383423864
};
2383523865
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 */
2384023866
2384123867
/* The ScanStatus object holds a single value for the
2384223868
** sqlite3_stmt_scanstatus() interface.
2384323869
**
2384423870
** aAddrRange[]:
@@ -23895,11 +23921,11 @@
2389523921
i64 iCurrentTime; /* Value of julianday('now') for this statement */
2389623922
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
2389723923
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
2389823924
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
2389923925
Mem *aMem; /* The memory locations */
23900
- Mem **apArg; /* Arguments to currently executing user function */
23926
+ Mem **apArg; /* Arguments xUpdate and xFilter vtab methods */
2390123927
VdbeCursor **apCsr; /* One element of this array for each open cursor */
2390223928
Mem *aVar; /* Values for the OP_Variable opcode. */
2390323929
2390423930
/* When allocating a new Vdbe object, all of the fields below should be
2390523931
** initialized to zero or NULL */
@@ -23915,10 +23941,11 @@
2391523941
i64 startTime; /* Time when query started - used for profiling */
2391623942
#endif
2391723943
#ifdef SQLITE_DEBUG
2391823944
int rcApp; /* errcode set by sqlite3_result_error_code() */
2391923945
u32 nWrite; /* Number of write operations that have occurred */
23946
+ int napArg; /* Size of the apArg[] array */
2392023947
#endif
2392123948
u16 nResColumn; /* Number of columns in one row of the result set */
2392223949
u16 nResAlloc; /* Column slots allocated to aColName[] */
2392323950
u8 errorAction; /* Recovery action to do in case of an error */
2392423951
u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -32546,11 +32573,11 @@
3254632573
** pointer if any kind of error was encountered.
3254732574
*/
3254832575
static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
3254932576
char *zText;
3255032577
assert( p->mxAlloc>0 && !isMalloced(p) );
32551
- zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
32578
+ zText = sqlite3DbMallocRaw(p->db, 1+(u64)p->nChar );
3255232579
if( zText ){
3255332580
memcpy(zText, p->zText, p->nChar+1);
3255432581
p->printfFlags |= SQLITE_PRINTF_MALLOCED;
3255532582
}else{
3255632583
sqlite3StrAccumSetError(p, SQLITE_NOMEM);
@@ -36398,11 +36425,15 @@
3639836425
}
3639936426
}
3640036427
}
3640136428
p->z = &p->zBuf[i+1];
3640236429
assert( i+p->n < sizeof(p->zBuf) );
36403
- while( ALWAYS(p->n>0) && p->z[p->n-1]=='0' ){ p->n--; }
36430
+ assert( p->n>0 );
36431
+ while( p->z[p->n-1]=='0' ){
36432
+ p->n--;
36433
+ assert( p->n>0 );
36434
+ }
3640436435
}
3640536436
3640636437
/*
3640736438
** Try to convert z into an unsigned 32-bit integer. Return true on
3640836439
** success and false if there is an error.
@@ -37184,16 +37215,23 @@
3718437215
/*
3718537216
** The hashing function.
3718637217
*/
3718737218
static unsigned int strHash(const char *z){
3718837219
unsigned int h = 0;
37189
- unsigned char c;
37190
- while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
37220
+ while( z[0] ){ /*OPTIMIZATION-IF-TRUE*/
3719137221
/* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
3719237222
** 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];
37223
+ ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2.
37224
+ **
37225
+ ** Only bits 0xdf for ASCII and bits 0xbf for EBCDIC each octet are
37226
+ ** hashed since the omitted bits determine the upper/lower case difference.
37227
+ */
37228
+#ifdef SQLITE_EBCDIC
37229
+ h += 0xbf & (unsigned char)*(z++);
37230
+#else
37231
+ h += 0xdf & (unsigned char)*(z++);
37232
+#endif
3719537233
h *= 0x9e3779b1;
3719637234
}
3719737235
return h;
3719837236
}
3719937237
@@ -37262,13 +37300,12 @@
3726237300
sqlite3_free(pH->ht);
3726337301
pH->ht = new_ht;
3726437302
pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
3726537303
memset(new_ht, 0, new_size*sizeof(struct _ht));
3726637304
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
37267
- unsigned int h = strHash(elem->pKey) % new_size;
3726837305
next_elem = elem->next;
37269
- insertElement(pH, &new_ht[h], elem);
37306
+ insertElement(pH, &new_ht[elem->h % new_size], elem);
3727037307
}
3727137308
return 1;
3727237309
}
3727337310
3727437311
/* This function (for internal use only) locates an element in an
@@ -37282,27 +37319,26 @@
3728237319
unsigned int *pHash /* Write the hash value here */
3728337320
){
3728437321
HashElem *elem; /* Used to loop thru the element list */
3728537322
unsigned int count; /* Number of elements left to test */
3728637323
unsigned int h; /* The computed hash */
37287
- static HashElem nullElement = { 0, 0, 0, 0 };
37324
+ static HashElem nullElement = { 0, 0, 0, 0, 0 };
3728837325
37326
+ h = strHash(pKey);
3728937327
if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
3729037328
struct _ht *pEntry;
37291
- h = strHash(pKey) % pH->htsize;
37292
- pEntry = &pH->ht[h];
37329
+ pEntry = &pH->ht[h % pH->htsize];
3729337330
elem = pEntry->chain;
3729437331
count = pEntry->count;
3729537332
}else{
37296
- h = 0;
3729737333
elem = pH->first;
3729837334
count = pH->count;
3729937335
}
3730037336
if( pHash ) *pHash = h;
3730137337
while( count ){
3730237338
assert( elem!=0 );
37303
- if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
37339
+ if( h==elem->h && sqlite3StrICmp(elem->pKey,pKey)==0 ){
3730437340
return elem;
3730537341
}
3730637342
elem = elem->next;
3730737343
count--;
3730837344
}
@@ -37310,14 +37346,13 @@
3731037346
}
3731137347
3731237348
/* Remove a single entry from the hash table given a pointer to that
3731337349
** element and a hash on the element's key.
3731437350
*/
37315
-static void removeElementGivenHash(
37351
+static void removeElement(
3731637352
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 */
37353
+ HashElem *elem /* The element to be removed from the pH */
3731937354
){
3732037355
struct _ht *pEntry;
3732137356
if( elem->prev ){
3732237357
elem->prev->next = elem->next;
3732337358
}else{
@@ -37325,11 +37360,11 @@
3732537360
}
3732637361
if( elem->next ){
3732737362
elem->next->prev = elem->prev;
3732837363
}
3732937364
if( pH->ht ){
37330
- pEntry = &pH->ht[h];
37365
+ pEntry = &pH->ht[elem->h % pH->htsize];
3733137366
if( pEntry->chain==elem ){
3733237367
pEntry->chain = elem->next;
3733337368
}
3733437369
assert( pEntry->count>0 );
3733537370
pEntry->count--;
@@ -37376,11 +37411,11 @@
3737637411
assert( pKey!=0 );
3737737412
elem = findElementWithHash(pH,pKey,&h);
3737837413
if( elem->data ){
3737937414
void *old_data = elem->data;
3738037415
if( data==0 ){
37381
- removeElementGivenHash(pH,elem,h);
37416
+ removeElement(pH,elem);
3738237417
}else{
3738337418
elem->data = data;
3738437419
elem->pKey = pKey;
3738537420
}
3738637421
return old_data;
@@ -37387,19 +37422,17 @@
3738737422
}
3738837423
if( data==0 ) return 0;
3738937424
new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
3739037425
if( new_elem==0 ) return data;
3739137426
new_elem->pKey = pKey;
37427
+ new_elem->h = h;
3739237428
new_elem->data = data;
3739337429
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
- }
37430
+ if( pH->count>=5 && pH->count > 2*pH->htsize ){
37431
+ rehash(pH, pH->count*3);
3739937432
}
37400
- insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);
37433
+ insertElement(pH, pH->ht ? &pH->ht[new_elem->h % pH->htsize] : 0, new_elem);
3740137434
return 0;
3740237435
}
3740337436
3740437437
/************** End of hash.c ************************************************/
3740537438
/************** Begin file opcodes.c *****************************************/
@@ -50806,11 +50839,11 @@
5080650839
** allocate space for a new winShmNode and filename.
5080750840
*/
5080850841
p = sqlite3MallocZero( sizeof(*p) );
5080950842
if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
5081050843
nName = sqlite3Strlen30(pDbFd->zPath);
50811
- pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
50844
+ pNew = sqlite3MallocZero( sizeof(*pShmNode) + (i64)nName + 17 );
5081250845
if( pNew==0 ){
5081350846
sqlite3_free(p);
5081450847
return SQLITE_IOERR_NOMEM_BKPT;
5081550848
}
5081650849
pNew->zFilename = (char*)&pNew[1];
@@ -51627,11 +51660,11 @@
5162751660
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
5162851661
"0123456789";
5162951662
size_t i, j;
5163051663
DWORD pid;
5163151664
int nPre = sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX);
51632
- int nMax, nBuf, nDir, nLen;
51665
+ i64 nMax, nBuf, nDir, nLen;
5163351666
char *zBuf;
5163451667
5163551668
/* It's odd to simulate an io-error here, but really this is just
5163651669
** using the io-error infrastructure to test that SQLite handles this
5163751670
** function failing.
@@ -51639,11 +51672,12 @@
5163951672
SimulateIOError( return SQLITE_IOERR );
5164051673
5164151674
/* Allocate a temporary buffer to store the fully qualified file
5164251675
** name for the temporary file. If this fails, we cannot continue.
5164351676
*/
51644
- nMax = pVfs->mxPathname; nBuf = nMax + 2;
51677
+ nMax = pVfs->mxPathname;
51678
+ nBuf = 2 + (i64)nMax;
5164551679
zBuf = sqlite3MallocZero( nBuf );
5164651680
if( !zBuf ){
5164751681
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
5164851682
return SQLITE_IOERR_NOMEM_BKPT;
5164951683
}
@@ -52498,11 +52532,11 @@
5249852532
** NOTE: We are dealing with a relative path name and the data
5249952533
** directory has been set. Therefore, use it as the basis
5250052534
** for converting the relative path name to an absolute
5250152535
** one by prepending the data directory and a slash.
5250252536
*/
52503
- char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
52537
+ char *zOut = sqlite3MallocZero( 1+(u64)pVfs->mxPathname );
5250452538
if( !zOut ){
5250552539
return SQLITE_IOERR_NOMEM_BKPT;
5250652540
}
5250752541
if( cygwin_conv_path(
5250852542
(osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
@@ -52593,17 +52627,16 @@
5259352627
if( nByte==0 ){
5259452628
sqlite3_free(zConverted);
5259552629
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5259652630
"winFullPathname1", zRelative);
5259752631
}
52598
- nByte += 3;
52599
- zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
52632
+ zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
5260052633
if( zTemp==0 ){
5260152634
sqlite3_free(zConverted);
5260252635
return SQLITE_IOERR_NOMEM_BKPT;
5260352636
}
52604
- nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
52637
+ nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte+3, zTemp, 0);
5260552638
if( nByte==0 ){
5260652639
sqlite3_free(zConverted);
5260752640
sqlite3_free(zTemp);
5260852641
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5260952642
"winFullPathname2", zRelative);
@@ -52619,17 +52652,16 @@
5261952652
if( nByte==0 ){
5262052653
sqlite3_free(zConverted);
5262152654
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5262252655
"winFullPathname3", zRelative);
5262352656
}
52624
- nByte += 3;
52625
- zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
52657
+ zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
5262652658
if( zTemp==0 ){
5262752659
sqlite3_free(zConverted);
5262852660
return SQLITE_IOERR_NOMEM_BKPT;
5262952661
}
52630
- nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
52662
+ nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0);
5263152663
if( nByte==0 ){
5263252664
sqlite3_free(zConverted);
5263352665
sqlite3_free(zTemp);
5263452666
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5263552667
"winFullPathname4", zRelative);
@@ -53654,17 +53686,17 @@
5365453686
break;
5365553687
}
5365653688
}
5365753689
if( p==0 ){
5365853690
MemStore **apNew;
53659
- p = sqlite3Malloc( sizeof(*p) + szName + 3 );
53691
+ p = sqlite3Malloc( sizeof(*p) + (i64)szName + 3 );
5366053692
if( p==0 ){
5366153693
sqlite3_mutex_leave(pVfsMutex);
5366253694
return SQLITE_NOMEM;
5366353695
}
5366453696
apNew = sqlite3Realloc(memdb_g.apMemStore,
53665
- sizeof(apNew[0])*(memdb_g.nMemStore+1) );
53697
+ sizeof(apNew[0])*(1+(i64)memdb_g.nMemStore) );
5366653698
if( apNew==0 ){
5366753699
sqlite3_free(p);
5366853700
sqlite3_mutex_leave(pVfsMutex);
5366953701
return SQLITE_NOMEM;
5367053702
}
@@ -54370,11 +54402,11 @@
5437054402
void *pTmpSpace;
5437154403
5437254404
/* Allocate the Bitvec to be tested and a linear array of
5437354405
** bits to act as the reference */
5437454406
pBitvec = sqlite3BitvecCreate( sz );
54375
- pV = sqlite3MallocZero( (sz+7)/8 + 1 );
54407
+ pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
5437654408
pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
5437754409
if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
5437854410
5437954411
/* NULL pBitvec tests */
5438054412
sqlite3BitvecSet(0, 1);
@@ -55917,16 +55949,16 @@
5591755949
**
5591855950
** The PCache mutex must be held when this function is called.
5591955951
*/
5592055952
static void pcache1ResizeHash(PCache1 *p){
5592155953
PgHdr1 **apNew;
55922
- unsigned int nNew;
55923
- unsigned int i;
55954
+ u64 nNew;
55955
+ u32 i;
5592455956
5592555957
assert( sqlite3_mutex_held(p->pGroup->mutex) );
5592655958
55927
- nNew = p->nHash*2;
55959
+ nNew = 2*(u64)p->nHash;
5592855960
if( nNew<256 ){
5592955961
nNew = 256;
5593055962
}
5593155963
5593255964
pcache1LeaveMutex(p->pGroup);
@@ -56145,11 +56177,11 @@
5614556177
** Allocate a new cache.
5614656178
*/
5614756179
static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
5614856180
PCache1 *pCache; /* The newly created page cache */
5614956181
PGroup *pGroup; /* The group the new page cache will belong to */
56150
- int sz; /* Bytes of memory required to allocate the new cache */
56182
+ i64 sz; /* Bytes of memory required to allocate the new cache */
5615156183
5615256184
assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
5615356185
assert( szExtra < 300 );
5615456186
5615556187
sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache;
@@ -58624,11 +58656,11 @@
5862458656
** zSuper[0] is set to 0 and SQLITE_OK returned.
5862558657
**
5862658658
** If an error occurs while reading from the journal file, an SQLite
5862758659
** error code is returned.
5862858660
*/
58629
-static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper){
58661
+static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){
5863058662
int rc; /* Return code */
5863158663
u32 len; /* Length in bytes of super-journal name */
5863258664
i64 szJ; /* Total size in bytes of journal file pJrnl */
5863358665
u32 cksum; /* MJ checksum value read from journal */
5863458666
u32 u; /* Unsigned loop counter */
@@ -59860,16 +59892,16 @@
5986059892
char *zSuperJournal = 0; /* Contents of super-journal file */
5986159893
i64 nSuperJournal; /* Size of super-journal file */
5986259894
char *zJournal; /* Pointer to one journal within MJ file */
5986359895
char *zSuperPtr; /* Space to hold super-journal filename */
5986459896
char *zFree = 0; /* Free this buffer */
59865
- int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
59897
+ i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
5986659898
5986759899
/* Allocate space for both the pJournal and pSuper file descriptors.
5986859900
** If successful, open the super-journal file for reading.
5986959901
*/
59870
- pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
59902
+ pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
5987159903
if( !pSuper ){
5987259904
rc = SQLITE_NOMEM_BKPT;
5987359905
pJournal = 0;
5987459906
}else{
5987559907
const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
@@ -59883,15 +59915,18 @@
5988359915
** sufficient space (in zSuperPtr) to hold the names of super-journal
5988459916
** files extracted from regular rollback-journals.
5988559917
*/
5988659918
rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
5988759919
if( rc!=SQLITE_OK ) goto delsuper_out;
59888
- nSuperPtr = pVfs->mxPathname+1;
59920
+ nSuperPtr = 1 + (i64)pVfs->mxPathname;
59921
+ assert( nSuperJournal>=0 && nSuperPtr>0 );
5988959922
zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2);
5989059923
if( !zFree ){
5989159924
rc = SQLITE_NOMEM_BKPT;
5989259925
goto delsuper_out;
59926
+ }else{
59927
+ assert( nSuperJournal<=0x7fffffff );
5989359928
}
5989459929
zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
5989559930
zSuperJournal = &zFree[4];
5989659931
zSuperPtr = &zSuperJournal[nSuperJournal+2];
5989759932
rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
@@ -60148,11 +60183,11 @@
6014860183
** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
6014960184
** mxPathname is 512, which is the same as the minimum allowable value
6015060185
** for pageSize.
6015160186
*/
6015260187
zSuper = pPager->pTmpSpace;
60153
- rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
60188
+ rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
6015460189
if( rc==SQLITE_OK && zSuper[0] ){
6015560190
rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
6015660191
}
6015760192
zSuper = 0;
6015860193
if( rc!=SQLITE_OK || !res ){
@@ -60287,11 +60322,11 @@
6028760322
/* Leave 4 bytes of space before the super-journal filename in memory.
6028860323
** This is because it may end up being passed to sqlite3OsOpen(), in
6028960324
** which case it requires 4 0x00 bytes in memory immediately before
6029060325
** the filename. */
6029160326
zSuper = &pPager->pTmpSpace[4];
60292
- rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
60327
+ rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
6029360328
testcase( rc!=SQLITE_OK );
6029460329
}
6029560330
if( rc==SQLITE_OK
6029660331
&& (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
6029760332
){
@@ -62057,10 +62092,11 @@
6205762092
int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
6205862093
int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
6205962094
u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
6206062095
const char *zUri = 0; /* URI args to copy */
6206162096
int nUriByte = 1; /* Number of bytes of URI args at *zUri */
62097
+
6206262098
6206362099
/* Figure out how much space is required for each journal file-handle
6206462100
** (there are two of them, the main journal and the sub-journal). */
6206562101
journalFileSize = ROUND8(sqlite3JournalSize(pVfs));
6206662102
@@ -62083,12 +62119,12 @@
6208362119
** to by zPathname, length nPathname. Or, if this is a temporary file,
6208462120
** leave both nPathname and zPathname set to 0.
6208562121
*/
6208662122
if( zFilename && zFilename[0] ){
6208762123
const char *z;
62088
- nPathname = pVfs->mxPathname+1;
62089
- zPathname = sqlite3DbMallocRaw(0, nPathname*2);
62124
+ nPathname = pVfs->mxPathname + 1;
62125
+ zPathname = sqlite3DbMallocRaw(0, 2*(i64)nPathname);
6209062126
if( zPathname==0 ){
6209162127
return SQLITE_NOMEM_BKPT;
6209262128
}
6209362129
zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
6209462130
rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
@@ -62171,18 +62207,18 @@
6217162207
assert( SQLITE_PTRSIZE==sizeof(Pager*) );
6217262208
pPtr = (u8 *)sqlite3MallocZero(
6217362209
ROUND8(sizeof(*pPager)) + /* Pager structure */
6217462210
ROUND8(pcacheSize) + /* PCache object */
6217562211
ROUND8(pVfs->szOsFile) + /* The main db file */
62176
- journalFileSize * 2 + /* The two journal files */
62212
+ (u64)journalFileSize * 2 + /* The two journal files */
6217762213
SQLITE_PTRSIZE + /* Space to hold a pointer */
6217862214
4 + /* Database prefix */
62179
- nPathname + 1 + /* database filename */
62180
- nUriByte + /* query parameters */
62181
- nPathname + 8 + 1 + /* Journal filename */
62215
+ (u64)nPathname + 1 + /* database filename */
62216
+ (u64)nUriByte + /* query parameters */
62217
+ (u64)nPathname + 8 + 1 + /* Journal filename */
6218262218
#ifndef SQLITE_OMIT_WAL
62183
- nPathname + 4 + 1 + /* WAL filename */
62219
+ (u64)nPathname + 4 + 1 + /* WAL filename */
6218462220
#endif
6218562221
3 /* Terminator */
6218662222
);
6218762223
assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
6218862224
if( !pPtr ){
@@ -65884,11 +65920,11 @@
6588465920
){
6588565921
int rc = SQLITE_OK;
6588665922
6588765923
/* Enlarge the pWal->apWiData[] array if required */
6588865924
if( pWal->nWiData<=iPage ){
65889
- sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
65925
+ sqlite3_int64 nByte = sizeof(u32*)*(1+(i64)iPage);
6589065926
volatile u32 **apNew;
6589165927
apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte);
6589265928
if( !apNew ){
6589365929
*ppPage = 0;
6589465930
return SQLITE_NOMEM_BKPT;
@@ -71508,11 +71544,11 @@
7150871544
** up to the size of 1 varint plus 1 8-byte value when the cursor
7150971545
** position is restored. Hence the 17 bytes of padding allocated
7151071546
** below. */
7151171547
void *pKey;
7151271548
pCur->nKey = sqlite3BtreePayloadSize(pCur);
71513
- pKey = sqlite3Malloc( pCur->nKey + 9 + 8 );
71549
+ pKey = sqlite3Malloc( ((i64)pCur->nKey) + 9 + 8 );
7151471550
if( pKey ){
7151571551
rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
7151671552
if( rc==SQLITE_OK ){
7151771553
memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
7151871554
pCur->pKey = pKey;
@@ -76879,11 +76915,11 @@
7687976915
testcase( nCell==2 ); /* Minimum legal index key size */
7688076916
if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
7688176917
rc = SQLITE_CORRUPT_PAGE(pPage);
7688276918
goto moveto_index_finish;
7688376919
}
76884
- pCellKey = sqlite3Malloc( nCell+nOverrun );
76920
+ pCellKey = sqlite3Malloc( (u64)nCell+(u64)nOverrun );
7688576921
if( pCellKey==0 ){
7688676922
rc = SQLITE_NOMEM_BKPT;
7688776923
goto moveto_index_finish;
7688876924
}
7688976925
pCur->ix = (u16)idx;
@@ -82068,10 +82104,11 @@
8206882104
** blob of allocated memory. The xFree function should not call sqlite3_free()
8206982105
** on the memory, the btree layer does that.
8207082106
*/
8207182107
SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
8207282108
BtShared *pBt = p->pBt;
82109
+ assert( nBytes==0 || nBytes==sizeof(Schema) );
8207382110
sqlite3BtreeEnter(p);
8207482111
if( !pBt->pSchema && nBytes ){
8207582112
pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
8207682113
pBt->xFreeSchema = xFree;
8207782114
}
@@ -83370,11 +83407,11 @@
8337083407
if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
8337183408
/* pMem must be a string, and it cannot be an ephemeral or static string */
8337283409
return;
8337383410
}
8337483411
if( pMem->enc!=SQLITE_UTF8 ) return;
83375
- if( NEVER(pMem->z==0) ) return;
83412
+ assert( pMem->z!=0 );
8337683413
if( pMem->flags & MEM_Dyn ){
8337783414
if( pMem->xDel==sqlite3_free
8337883415
&& sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
8337983416
){
8338083417
pMem->z[pMem->n] = 0;
@@ -84483,11 +84520,11 @@
8448384520
if( p ){
8448484521
UnpackedRecord *pRec = p->ppRec[0];
8448584522
8448684523
if( pRec==0 ){
8448784524
Index *pIdx = p->pIdx; /* Index being probed */
84488
- int nByte; /* Bytes of space to allocate */
84525
+ i64 nByte; /* Bytes of space to allocate */
8448984526
int i; /* Counter variable */
8449084527
int nCol = pIdx->nColumn; /* Number of index columns including rowid */
8449184528
8449284529
nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
8449384530
pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
@@ -84549,11 +84586,11 @@
8454984586
sqlite3_value **ppVal, /* Write the new value here */
8455084587
struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */
8455184588
){
8455284589
sqlite3_context ctx; /* Context object for function invocation */
8455384590
sqlite3_value **apVal = 0; /* Function arguments */
84554
- int nVal = 0; /* Size of apVal[] array */
84591
+ int nVal = 0; /* Number of function arguments */
8455584592
FuncDef *pFunc = 0; /* Function definition */
8455684593
sqlite3_value *pVal = 0; /* New value */
8455784594
int rc = SQLITE_OK; /* Return code */
8455884595
ExprList *pList = 0; /* Function arguments */
8455984596
int i; /* Iterator variable */
@@ -85828,11 +85865,11 @@
8582885865
p->iSub++;
8582985866
p->iAddr = 0;
8583085867
}
8583185868
8583285869
if( pRet->p4type==P4_SUBPROGRAM ){
85833
- int nByte = (p->nSub+1)*sizeof(SubProgram*);
85870
+ i64 nByte = (1+(u64)p->nSub)*sizeof(SubProgram*);
8583485871
int j;
8583585872
for(j=0; j<p->nSub; j++){
8583685873
if( p->apSub[j]==pRet->p4.pProgram ) break;
8583785874
}
8583885875
if( j==p->nSub ){
@@ -85958,12 +85995,12 @@
8595885995
** through all the opcodes and fixes up some details.
8595985996
**
8596085997
** (1) For each jump instruction with a negative P2 value (a label)
8596185998
** resolve the P2 value to an actual address.
8596285999
**
85963
-** (2) Compute the maximum number of arguments used by any SQL function
85964
-** and store that value in *pMaxFuncArgs.
86000
+** (2) Compute the maximum number of arguments used by the xUpdate/xFilter
86001
+** methods of any virtual table and store that value in *pMaxVtabArgs.
8596586002
**
8596686003
** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
8596786004
** indicate what the prepared statement actually does.
8596886005
**
8596986006
** (4) (discontinued)
@@ -85972,12 +86009,12 @@
8597286009
**
8597386010
** This routine will only function correctly if the mkopcodeh.tcl generator
8597486011
** script numbers the opcodes correctly. Changes to this routine must be
8597586012
** coordinated with changes to mkopcodeh.tcl.
8597686013
*/
85977
-static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
85978
- int nMaxArgs = *pMaxFuncArgs;
86014
+static void resolveP2Values(Vdbe *p, int *pMaxVtabArgs){
86015
+ int nMaxVtabArgs = *pMaxVtabArgs;
8597986016
Op *pOp;
8598086017
Parse *pParse = p->pParse;
8598186018
int *aLabel = pParse->aLabel;
8598286019
8598386020
assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
@@ -86018,19 +86055,23 @@
8601886055
assert( pOp->p2>=0 );
8601986056
goto resolve_p2_values_loop_exit;
8602086057
}
8602186058
#ifndef SQLITE_OMIT_VIRTUALTABLE
8602286059
case OP_VUpdate: {
86023
- if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
86060
+ if( pOp->p2>nMaxVtabArgs ) nMaxVtabArgs = pOp->p2;
8602486061
break;
8602586062
}
8602686063
case OP_VFilter: {
8602786064
int n;
86065
+ /* The instruction immediately prior to VFilter will be an
86066
+ ** OP_Integer that sets the "argc" value for the VFilter. See
86067
+ ** the code where OP_VFilter is generated at tag-20250207a. */
8602886068
assert( (pOp - p->aOp) >= 3 );
8602986069
assert( pOp[-1].opcode==OP_Integer );
86070
+ assert( pOp[-1].p2==pOp->p3+1 );
8603086071
n = pOp[-1].p1;
86031
- if( n>nMaxArgs ) nMaxArgs = n;
86072
+ if( n>nMaxVtabArgs ) nMaxVtabArgs = n;
8603286073
/* Fall through into the default case */
8603386074
/* no break */ deliberate_fall_through
8603486075
}
8603586076
#endif
8603686077
default: {
@@ -86067,11 +86108,11 @@
8606786108
if( aLabel ){
8606886109
sqlite3DbNNFreeNN(p->db, pParse->aLabel);
8606986110
pParse->aLabel = 0;
8607086111
}
8607186112
pParse->nLabel = 0;
86072
- *pMaxFuncArgs = nMaxArgs;
86113
+ *pMaxVtabArgs = nMaxVtabArgs;
8607386114
assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
8607486115
}
8607586116
8607686117
#ifdef SQLITE_DEBUG
8607786118
/*
@@ -86296,11 +86337,11 @@
8629686337
int addrVisit, /* Address of rows visited counter */
8629786338
LogEst nEst, /* Estimated number of output rows */
8629886339
const char *zName /* Name of table or index being scanned */
8629986340
){
8630086341
if( IS_STMT_SCANSTATUS(p->db) ){
86301
- sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
86342
+ i64 nByte = (1+(i64)p->nScan) * sizeof(ScanStatus);
8630286343
ScanStatus *aNew;
8630386344
aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
8630486345
if( aNew ){
8630586346
ScanStatus *pNew = &aNew[p->nScan++];
8630686347
memset(pNew, 0, sizeof(ScanStatus));
@@ -87745,11 +87786,11 @@
8774587786
){
8774687787
sqlite3 *db; /* The database connection */
8774787788
int nVar; /* Number of parameters */
8774887789
int nMem; /* Number of VM memory registers */
8774987790
int nCursor; /* Number of cursors required */
87750
- int nArg; /* Number of arguments in subprograms */
87791
+ int nArg; /* Max number args to xFilter or xUpdate */
8775187792
int n; /* Loop counter */
8775287793
struct ReusableSpace x; /* Reusable bulk memory */
8775387794
8775487795
assert( p!=0 );
8775587796
assert( p->nOp>0 );
@@ -87817,10 +87858,13 @@
8781787858
p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
8781887859
p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
8781987860
p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
8782087861
}
8782187862
}
87863
+#ifdef SQLITE_DEBUG
87864
+ p->napArg = nArg;
87865
+#endif
8782287866
8782387867
if( db->mallocFailed ){
8782487868
p->nVar = 0;
8782587869
p->nCursor = 0;
8782687870
p->nMem = 0;
@@ -89314,10 +89358,11 @@
8931489358
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
8931589359
KeyInfo *pKeyInfo /* Description of the record */
8931689360
){
8931789361
UnpackedRecord *p; /* Unpacked record to return */
8931889362
int nByte; /* Number of bytes required for *p */
89363
+ assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
8931989364
nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
8932089365
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
8932189366
if( !p ) return 0;
8932289367
p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
8932389368
assert( pKeyInfo->aSortFlags!=0 );
@@ -92890,11 +92935,13 @@
9289092935
/* This occurs when the table has been extended using ALTER TABLE
9289192936
** ADD COLUMN. The value to return is the default value of the column. */
9289292937
Column *pCol = &p->pTab->aCol[iIdx];
9289392938
if( pCol->iDflt>0 ){
9289492939
if( p->apDflt==0 ){
92895
- int nByte = sizeof(sqlite3_value*)*p->pTab->nCol;
92940
+ int nByte;
92941
+ assert( sizeof(sqlite3_value*)*UMXV(p->pTab->nCol) < 0x7fffffff );
92942
+ nByte = sizeof(sqlite3_value*)*p->pTab->nCol;
9289692943
p->apDflt = (sqlite3_value**)sqlite3DbMallocZero(db, nByte);
9289792944
if( p->apDflt==0 ) goto preupdate_old_out;
9289892945
}
9289992946
if( p->apDflt[iIdx]==0 ){
9290092947
sqlite3_value *pVal = 0;
@@ -93040,11 +93087,12 @@
9304093087
** It is not safe to return a pointer to the memory cell itself as the
9304193088
** caller may modify the value text encoding.
9304293089
*/
9304393090
assert( p->op==SQLITE_UPDATE );
9304493091
if( !p->aNew ){
93045
- p->aNew = (Mem *)sqlite3DbMallocZero(db, sizeof(Mem) * p->pCsr->nField);
93092
+ assert( sizeof(Mem)*UMXV(p->pCsr->nField) < 0x7fffffff );
93093
+ p->aNew = (Mem *)sqlite3DbMallocZero(db, sizeof(Mem)*p->pCsr->nField);
9304693094
if( !p->aNew ){
9304793095
rc = SQLITE_NOMEM;
9304893096
goto preupdate_new_out;
9304993097
}
9305093098
}
@@ -93810,11 +93858,11 @@
9381093858
** the top of the register space. Cursor 1 is at Mem[p->nMem-1].
9381193859
** Cursor 2 is at Mem[p->nMem-2]. And so forth.
9381293860
*/
9381393861
Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
9381493862
93815
- int nByte;
93863
+ i64 nByte;
9381693864
VdbeCursor *pCx = 0;
9381793865
nByte =
9381893866
ROUND8P(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
9381993867
(eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
9382093868
@@ -93838,11 +93886,11 @@
9383893886
pMem->z = pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, nByte);
9383993887
if( pMem->zMalloc==0 ){
9384093888
pMem->szMalloc = 0;
9384193889
return 0;
9384293890
}
93843
- pMem->szMalloc = nByte;
93891
+ pMem->szMalloc = (int)nByte;
9384493892
}
9384593893
9384693894
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
9384793895
memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
9384893896
pCx->eCurType = eCurType;
@@ -100859,11 +100907,11 @@
100859100907
**
100860100908
** If P5 is non-zero, then recursive program invocation is enabled.
100861100909
*/
100862100910
case OP_Program: { /* jump0 */
100863100911
int nMem; /* Number of memory registers for sub-program */
100864
- int nByte; /* Bytes of runtime space required for sub-program */
100912
+ i64 nByte; /* Bytes of runtime space required for sub-program */
100865100913
Mem *pRt; /* Register to allocate runtime space */
100866100914
Mem *pMem; /* Used to iterate through memory cells */
100867100915
Mem *pEnd; /* Last memory cell in new array */
100868100916
VdbeFrame *pFrame; /* New vdbe frame to execute in */
100869100917
SubProgram *pProgram; /* Sub-program to execute */
@@ -100910,19 +100958,19 @@
100910100958
assert( nMem>0 );
100911100959
if( pProgram->nCsr==0 ) nMem++;
100912100960
nByte = ROUND8(sizeof(VdbeFrame))
100913100961
+ nMem * sizeof(Mem)
100914100962
+ pProgram->nCsr * sizeof(VdbeCursor*)
100915
- + (pProgram->nOp + 7)/8;
100963
+ + (7 + (i64)pProgram->nOp)/8;
100916100964
pFrame = sqlite3DbMallocZero(db, nByte);
100917100965
if( !pFrame ){
100918100966
goto no_mem;
100919100967
}
100920100968
sqlite3VdbeMemRelease(pRt);
100921100969
pRt->flags = MEM_Blob|MEM_Dyn;
100922100970
pRt->z = (char*)pFrame;
100923
- pRt->n = nByte;
100971
+ pRt->n = (int)nByte;
100924100972
pRt->xDel = sqlite3VdbeFrameMemDel;
100925100973
100926100974
pFrame->v = p;
100927100975
pFrame->nChildMem = nMem;
100928100976
pFrame->nChildCsr = pProgram->nCsr;
@@ -101017,16 +101065,18 @@
101017101065
** If P1 is non-zero, the database constraint counter is incremented
101018101066
** (deferred foreign key constraints). Otherwise, if P1 is zero, the
101019101067
** statement counter is incremented (immediate foreign key constraints).
101020101068
*/
101021101069
case OP_FkCounter: {
101022
- if( db->flags & SQLITE_DeferFKs ){
101023
- db->nDeferredImmCons += pOp->p2;
101024
- }else if( pOp->p1 ){
101070
+ if( pOp->p1 ){
101025101071
db->nDeferredCons += pOp->p2;
101026101072
}else{
101027
- p->nFkConstraint += pOp->p2;
101073
+ if( db->flags & SQLITE_DeferFKs ){
101074
+ db->nDeferredImmCons += pOp->p2;
101075
+ }else{
101076
+ p->nFkConstraint += pOp->p2;
101077
+ }
101028101078
}
101029101079
break;
101030101080
}
101031101081
101032101082
/* Opcode: FkIfZero P1 P2 * * *
@@ -101897,10 +101947,11 @@
101897101947
nArg = (int)pArgc->u.i;
101898101948
iQuery = (int)pQuery->u.i;
101899101949
101900101950
/* Invoke the xFilter method */
101901101951
apArg = p->apArg;
101952
+ assert( nArg<=p->napArg );
101902101953
for(i = 0; i<nArg; i++){
101903101954
apArg[i] = &pArgc[i+1];
101904101955
}
101905101956
rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg);
101906101957
sqlite3VtabImportErrmsg(p, pVtab);
@@ -102107,10 +102158,11 @@
102107102158
assert( pOp->p4type==P4_VTAB );
102108102159
if( ALWAYS(pModule->xUpdate) ){
102109102160
u8 vtabOnConflict = db->vtabOnConflict;
102110102161
apArg = p->apArg;
102111102162
pX = &aMem[pOp->p3];
102163
+ assert( nArg<=p->napArg );
102112102164
for(i=0; i<nArg; i++){
102113102165
assert( memIsValid(pX) );
102114102166
memAboutToChange(p, pX);
102115102167
apArg[i] = pX;
102116102168
pX++;
@@ -102952,16 +103004,12 @@
102952103004
}
102953103005
pBlob->pTab = pTab;
102954103006
pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
102955103007
102956103008
/* 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 ){
103009
+ iCol = sqlite3ColumnIndex(pTab, zColumn);
103010
+ if( iCol<0 ){
102963103011
sqlite3DbFree(db, zErr);
102964103012
zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
102965103013
rc = SQLITE_ERROR;
102966103014
sqlite3BtreeLeaveAll(db);
102967103015
goto blob_open_out;
@@ -104219,11 +104267,11 @@
104219104267
int pgsz; /* Page size of main database */
104220104268
int i; /* Used to iterate through aTask[] */
104221104269
VdbeSorter *pSorter; /* The new sorter */
104222104270
KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
104223104271
int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
104224
- int sz; /* Size of pSorter in bytes */
104272
+ i64 sz; /* Size of pSorter in bytes */
104225104273
int rc = SQLITE_OK;
104226104274
#if SQLITE_MAX_WORKER_THREADS==0
104227104275
# define nWorker 0
104228104276
#else
104229104277
int nWorker;
@@ -104247,10 +104295,12 @@
104247104295
#endif
104248104296
104249104297
assert( pCsr->pKeyInfo );
104250104298
assert( !pCsr->isEphemeral );
104251104299
assert( pCsr->eCurType==CURTYPE_SORTER );
104300
+ assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
104301
+ < 0x7fffffff );
104252104302
szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
104253104303
sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
104254104304
104255104305
pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
104256104306
pCsr->uc.pSorter = pSorter;
@@ -104460,11 +104510,11 @@
104460104510
** nReader is automatically rounded up to the next power of two.
104461104511
** nReader may not exceed SORTER_MAX_MERGE_COUNT even after rounding up.
104462104512
*/
104463104513
static MergeEngine *vdbeMergeEngineNew(int nReader){
104464104514
int N = 2; /* Smallest power of two >= nReader */
104465
- int nByte; /* Total bytes of space to allocate */
104515
+ i64 nByte; /* Total bytes of space to allocate */
104466104516
MergeEngine *pNew; /* Pointer to allocated object to return */
104467104517
104468104518
assert( nReader<=SORTER_MAX_MERGE_COUNT );
104469104519
104470104520
while( N<nReader ) N += N;
@@ -107503,11 +107553,10 @@
107503107553
SrcItem *pMatch = 0; /* The matching pSrcList item */
107504107554
NameContext *pTopNC = pNC; /* First namecontext in the list */
107505107555
Schema *pSchema = 0; /* Schema of the expression */
107506107556
int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
107507107557
Table *pTab = 0; /* Table holding the row */
107508
- Column *pCol; /* A column of pTab */
107509107558
ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
107510107559
const char *zCol = pRight->u.zToken;
107511107560
107512107561
assert( pNC ); /* the name context cannot be NULL. */
107513107562
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -107554,11 +107603,10 @@
107554107603
ExprList *pEList;
107555107604
SrcList *pSrcList = pNC->pSrcList;
107556107605
107557107606
if( pSrcList ){
107558107607
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
107559
- u8 hCol;
107560107608
pTab = pItem->pSTab;
107561107609
assert( pTab!=0 && pTab->zName!=0 );
107562107610
assert( pTab->nCol>0 || pParse->nErr );
107563107611
assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem));
107564107612
if( pItem->fg.isNestedFrom ){
@@ -107642,47 +107690,42 @@
107642107690
assert( ExprUseYTab(pExpr) );
107643107691
if( IN_RENAME_OBJECT && pItem->zAlias ){
107644107692
sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
107645107693
}
107646107694
}
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;
107695
+ j = sqlite3ColumnIndex(pTab, zCol);
107696
+ if( j>=0 ){
107697
+ if( cnt>0 ){
107698
+ if( pItem->fg.isUsing==0
107699
+ || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107700
+ ){
107701
+ /* Two or more tables have the same column name which is
107702
+ ** not joined by USING. This is an error. Signal as much
107703
+ ** by clearing pFJMatch and letting cnt go above 1. */
107704
+ sqlite3ExprListDelete(db, pFJMatch);
107705
+ pFJMatch = 0;
107706
+ }else
107707
+ if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107708
+ /* An INNER or LEFT JOIN. Use the left-most table */
107709
+ continue;
107710
+ }else
107711
+ if( (pItem->fg.jointype & JT_LEFT)==0 ){
107712
+ /* A RIGHT JOIN. Use the right-most table */
107713
+ cnt = 0;
107714
+ sqlite3ExprListDelete(db, pFJMatch);
107715
+ pFJMatch = 0;
107716
+ }else{
107717
+ /* For a FULL JOIN, we must construct a coalesce() func */
107718
+ extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
107719
+ }
107720
+ }
107721
+ cnt++;
107722
+ pMatch = pItem;
107723
+ /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
107724
+ pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
107725
+ if( pItem->fg.isNestedFrom ){
107726
+ sqlite3SrcItemColumnUsed(pItem, j);
107684107727
}
107685107728
}
107686107729
if( 0==cnt && VisibleRowid(pTab) ){
107687107730
/* pTab is a potential ROWID match. Keep track of it and match
107688107731
** the ROWID later if that seems appropriate. (Search for "cntTab"
@@ -107768,26 +107811,21 @@
107768107811
}
107769107812
#endif /* SQLITE_OMIT_UPSERT */
107770107813
107771107814
if( pTab ){
107772107815
int iCol;
107773
- u8 hCol = sqlite3StrIHash(zCol);
107774107816
pSchema = pTab->pSchema;
107775107817
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;
107818
+ iCol = sqlite3ColumnIndex(pTab, zCol);
107819
+ if( iCol>=0 ){
107820
+ if( pTab->iPKey==iCol ) iCol = -1;
107821
+ }else{
107822
+ if( sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
107823
+ iCol = -1;
107824
+ }else{
107825
+ iCol = pTab->nCol;
107826
+ }
107789107827
}
107790107828
if( iCol<pTab->nCol ){
107791107829
cnt++;
107792107830
pMatch = 0;
107793107831
#ifndef SQLITE_OMIT_UPSERT
@@ -111379,11 +111417,10 @@
111379111417
pNewExpr->pLeft = pPriorSelectColNew;
111380111418
}
111381111419
}
111382111420
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
111383111421
pItem->fg = pOldItem->fg;
111384
- pItem->fg.done = 0;
111385111422
pItem->u = pOldItem->u;
111386111423
}
111387111424
return pNew;
111388111425
}
111389111426
@@ -112496,17 +112533,11 @@
112496112533
SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab){
112497112534
const char *azOpt[] = {"_ROWID_", "ROWID", "OID"};
112498112535
int ii;
112499112536
assert( VisibleRowid(pTab) );
112500112537
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
- }
112538
+ if( sqlite3ColumnIndex(pTab, azOpt[ii])<0 ) return azOpt[ii];
112508112539
}
112509112540
return 0;
112510112541
}
112511112542
112512112543
/*
@@ -112906,11 +112937,11 @@
112906112937
int nVal = sqlite3ExprVectorSize(pLeft);
112907112938
Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
112908112939
char *zRet;
112909112940
112910112941
assert( pExpr->op==TK_IN );
112911
- zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
112942
+ zRet = sqlite3DbMallocRaw(pParse->db, 1+(i64)nVal);
112912112943
if( zRet ){
112913112944
int i;
112914112945
for(i=0; i<nVal; i++){
112915112946
Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i);
112916112947
char a = sqlite3ExprAffinity(pA);
@@ -117551,14 +117582,12 @@
117551117582
117552117583
/* Make sure the old name really is a column name in the table to be
117553117584
** altered. Set iCol to be the index of the column being renamed */
117554117585
zOld = sqlite3NameFromToken(db, pOld);
117555117586
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 ){
117587
+ iCol = sqlite3ColumnIndex(pTab, zOld);
117588
+ if( iCol<0 ){
117560117589
sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
117561117590
goto exit_rename_column;
117562117591
}
117563117592
117564117593
/* Ensure the schema contains no double-quoted strings */
@@ -119453,11 +119482,12 @@
119453119482
** of the new table in register pParse->regRoot. This is important
119454119483
** because the OpenWrite opcode below will be needing it. */
119455119484
sqlite3NestedParse(pParse,
119456119485
"CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
119457119486
);
119458
- aRoot[i] = (u32)pParse->regRoot;
119487
+ assert( pParse->isCreate || pParse->nErr );
119488
+ aRoot[i] = (u32)pParse->u1.cr.regRoot;
119459119489
aCreateTbl[i] = OPFLAG_P2ISREG;
119460119490
}
119461119491
}else{
119462119492
/* The table already exists. If zWhere is not NULL, delete all entries
119463119493
** associated with the table zWhere. If zWhere is NULL, delete the
@@ -119644,11 +119674,11 @@
119644119674
){
119645119675
StatAccum *p;
119646119676
int nCol; /* Number of columns in index being sampled */
119647119677
int nKeyCol; /* Number of key columns */
119648119678
int nColUp; /* nCol rounded up for alignment */
119649
- int n; /* Bytes of space to allocate */
119679
+ i64 n; /* Bytes of space to allocate */
119650119680
sqlite3 *db = sqlite3_context_db_handle(context); /* Database connection */
119651119681
#ifdef SQLITE_ENABLE_STAT4
119652119682
/* Maximum number of samples. 0 if STAT4 data is not collected */
119653119683
int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0;
119654119684
#endif
@@ -121418,11 +121448,11 @@
121418121448
if( db->aDb==db->aDbStatic ){
121419121449
aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
121420121450
if( aNew==0 ) return;
121421121451
memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
121422121452
}else{
121423
- aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
121453
+ aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(1+(i64)db->nDb));
121424121454
if( aNew==0 ) return;
121425121455
}
121426121456
db->aDb = aNew;
121427121457
pNew = &db->aDb[db->nDb];
121428121458
memset(pNew, 0, sizeof(*pNew));
@@ -122211,10 +122241,11 @@
122211122241
p->isWriteLock = (p->isWriteLock || isWriteLock);
122212122242
return;
122213122243
}
122214122244
}
122215122245
122246
+ assert( pToplevel->nTableLock < 0x7fff0000 );
122216122247
nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
122217122248
pToplevel->aTableLock =
122218122249
sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
122219122250
if( pToplevel->aTableLock ){
122220122251
p = &pToplevel->aTableLock[pToplevel->nTableLock++];
@@ -122311,14 +122342,16 @@
122311122342
}
122312122343
assert( !pParse->isMultiWrite
122313122344
|| sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
122314122345
if( v ){
122315122346
if( pParse->bReturning ){
122316
- Returning *pReturning = pParse->u1.pReturning;
122347
+ Returning *pReturning;
122317122348
int addrRewind;
122318122349
int reg;
122319122350
122351
+ assert( !pParse->isCreate );
122352
+ pReturning = pParse->u1.d.pReturning;
122320122353
if( pReturning->nRetCol ){
122321122354
sqlite3VdbeAddOp0(v, OP_FkCheck);
122322122355
addrRewind =
122323122356
sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
122324122357
VdbeCoverage(v);
@@ -122390,11 +122423,13 @@
122390122423
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
122391122424
}
122392122425
}
122393122426
122394122427
if( pParse->bReturning ){
122395
- Returning *pRet = pParse->u1.pReturning;
122428
+ Returning *pRet;
122429
+ assert( !pParse->isCreate );
122430
+ pRet = pParse->u1.d.pReturning;
122396122431
if( pRet->nRetCol ){
122397122432
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
122398122433
}
122399122434
}
122400122435
@@ -123462,12 +123497,13 @@
123462123497
#endif
123463123498
123464123499
/* If the file format and encoding in the database have not been set,
123465123500
** set them now.
123466123501
*/
123467
- reg1 = pParse->regRowid = ++pParse->nMem;
123468
- reg2 = pParse->regRoot = ++pParse->nMem;
123502
+ assert( pParse->isCreate );
123503
+ reg1 = pParse->u1.cr.regRowid = ++pParse->nMem;
123504
+ reg2 = pParse->u1.cr.regRoot = ++pParse->nMem;
123469123505
reg3 = ++pParse->nMem;
123470123506
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
123471123507
sqlite3VdbeUsesBtree(v, iDb);
123472123508
addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
123473123509
fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
@@ -123478,12 +123514,12 @@
123478123514
123479123515
/* This just creates a place-holder record in the sqlite_schema table.
123480123516
** The record created does not contain anything yet. It will be replaced
123481123517
** by the real entry in code generated at sqlite3EndTable().
123482123518
**
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.
123519
+ ** The rowid for the new entry is left in register pParse->u1.cr.regRowid.
123520
+ ** The root page of the new table is left in reg pParse->u1.cr.regRoot.
123485123521
** The rowid and root page number values are needed by the code that
123486123522
** sqlite3EndTable will generate.
123487123523
*/
123488123524
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
123489123525
if( isView || isVirtual ){
@@ -123490,11 +123526,11 @@
123490123526
sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
123491123527
}else
123492123528
#endif
123493123529
{
123494123530
assert( !pParse->bReturning );
123495
- pParse->u1.addrCrTab =
123531
+ pParse->u1.cr.addrCrTab =
123496123532
sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
123497123533
}
123498123534
sqlite3OpenSchemaTable(pParse, iDb);
123499123535
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
123500123536
sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
@@ -123568,11 +123604,12 @@
123568123604
pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
123569123605
if( pRet==0 ){
123570123606
sqlite3ExprListDelete(db, pList);
123571123607
return;
123572123608
}
123573
- pParse->u1.pReturning = pRet;
123609
+ assert( !pParse->isCreate );
123610
+ pParse->u1.d.pReturning = pRet;
123574123611
pRet->pParse = pParse;
123575123612
pRet->pReturnEL = pList;
123576123613
sqlite3ParserAddCleanup(pParse, sqlite3DeleteReturning, pRet);
123577123614
testcase( pParse->earlyCleanup );
123578123615
if( db->mallocFailed ) return;
@@ -123610,11 +123647,10 @@
123610123647
int i;
123611123648
char *z;
123612123649
char *zType;
123613123650
Column *pCol;
123614123651
sqlite3 *db = pParse->db;
123615
- u8 hName;
123616123652
Column *aNew;
123617123653
u8 eType = COLTYPE_CUSTOM;
123618123654
u8 szEst = 1;
123619123655
char affinity = SQLITE_AFF_BLOB;
123620123656
@@ -123664,17 +123700,14 @@
123664123700
if( z==0 ) return;
123665123701
if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
123666123702
memcpy(z, sName.z, sName.n);
123667123703
z[sName.n] = 0;
123668123704
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
- }
123705
+ if( p->nCol && sqlite3ColumnIndex(p, z)>=0 ){
123706
+ sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
123707
+ sqlite3DbFree(db, z);
123708
+ return;
123676123709
}
123677123710
aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
123678123711
if( aNew==0 ){
123679123712
sqlite3DbFree(db, z);
123680123713
return;
@@ -123681,11 +123714,11 @@
123681123714
}
123682123715
p->aCol = aNew;
123683123716
pCol = &p->aCol[p->nCol];
123684123717
memset(pCol, 0, sizeof(p->aCol[0]));
123685123718
pCol->zCnName = z;
123686
- pCol->hName = hName;
123719
+ pCol->hName = sqlite3StrIHash(z);
123687123720
sqlite3ColumnPropertiesFromName(p, pCol);
123688123721
123689123722
if( sType.n==0 ){
123690123723
/* If there is no type specified, columns have the default affinity
123691123724
** 'BLOB' with a default size of 4 bytes. */
@@ -123705,13 +123738,18 @@
123705123738
zType[sType.n] = 0;
123706123739
sqlite3Dequote(zType);
123707123740
pCol->affinity = sqlite3AffinityType(zType, pCol);
123708123741
pCol->colFlags |= COLFLAG_HASTYPE;
123709123742
}
123743
+ if( p->nCol<=0xff ){
123744
+ u8 h = pCol->hName % sizeof(p->aHx);
123745
+ p->aHx[h] = p->nCol;
123746
+ }
123710123747
p->nCol++;
123711123748
p->nNVCol++;
123712
- pParse->constraintName.n = 0;
123749
+ assert( pParse->isCreate );
123750
+ pParse->u1.cr.constraintName.n = 0;
123713123751
}
123714123752
123715123753
/*
123716123754
** This routine is called by the parser while in the middle of
123717123755
** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
@@ -123971,19 +124009,15 @@
123971124009
for(i=0; i<nTerm; i++){
123972124010
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
123973124011
assert( pCExpr!=0 );
123974124012
sqlite3StringToId(pCExpr);
123975124013
if( pCExpr->op==TK_ID ){
123976
- const char *zCName;
123977124014
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
- }
124015
+ iCol = sqlite3ColumnIndex(pTab, pCExpr->u.zToken);
124016
+ if( iCol>=0 ){
124017
+ pCol = &pTab->aCol[iCol];
124018
+ makeColumnPartOfPrimaryKey(pParse, pCol);
123985124019
}
123986124020
}
123987124021
}
123988124022
}
123989124023
if( nTerm==1
@@ -124031,12 +124065,14 @@
124031124065
sqlite3 *db = pParse->db;
124032124066
if( pTab && !IN_DECLARE_VTAB
124033124067
&& !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
124034124068
){
124035124069
pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr);
124036
- if( pParse->constraintName.n ){
124037
- sqlite3ExprListSetName(pParse, pTab->pCheck, &pParse->constraintName, 1);
124070
+ assert( pParse->isCreate );
124071
+ if( pParse->u1.cr.constraintName.n ){
124072
+ sqlite3ExprListSetName(pParse, pTab->pCheck,
124073
+ &pParse->u1.cr.constraintName, 1);
124038124074
}else{
124039124075
Token t;
124040124076
for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
124041124077
while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; }
124042124078
t.z = zStart;
@@ -124227,11 +124263,12 @@
124227124263
** Generate a CREATE TABLE statement appropriate for the given
124228124264
** table. Memory to hold the text of the statement is obtained
124229124265
** from sqliteMalloc() and must be freed by the calling function.
124230124266
*/
124231124267
static char *createTableStmt(sqlite3 *db, Table *p){
124232
- int i, k, n;
124268
+ int i, k, len;
124269
+ i64 n;
124233124270
char *zStmt;
124234124271
char *zSep, *zSep2, *zEnd;
124235124272
Column *pCol;
124236124273
n = 0;
124237124274
for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
@@ -124251,12 +124288,13 @@
124251124288
zStmt = sqlite3DbMallocRaw(0, n);
124252124289
if( zStmt==0 ){
124253124290
sqlite3OomFault(db);
124254124291
return 0;
124255124292
}
124256
- sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
124257
- k = sqlite3Strlen30(zStmt);
124293
+ assert( n>14 && n<=0x7fffffff );
124294
+ memcpy(zStmt, "CREATE TABLE ", 13);
124295
+ k = 13;
124258124296
identPut(zStmt, &k, p->zName);
124259124297
zStmt[k++] = '(';
124260124298
for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
124261124299
static const char * const azType[] = {
124262124300
/* SQLITE_AFF_BLOB */ "",
@@ -124264,17 +124302,19 @@
124264124302
/* SQLITE_AFF_NUMERIC */ " NUM",
124265124303
/* SQLITE_AFF_INTEGER */ " INT",
124266124304
/* SQLITE_AFF_REAL */ " REAL",
124267124305
/* SQLITE_AFF_FLEXNUM */ " NUM",
124268124306
};
124269
- int len;
124270124307
const char *zType;
124271124308
124272
- sqlite3_snprintf(n-k, &zStmt[k], zSep);
124273
- k += sqlite3Strlen30(&zStmt[k]);
124309
+ len = sqlite3Strlen30(zSep);
124310
+ assert( k+len<n );
124311
+ memcpy(&zStmt[k], zSep, len);
124312
+ k += len;
124274124313
zSep = zSep2;
124275124314
identPut(zStmt, &k, pCol->zCnName);
124315
+ assert( k<n );
124276124316
assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
124277124317
assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
124278124318
testcase( pCol->affinity==SQLITE_AFF_BLOB );
124279124319
testcase( pCol->affinity==SQLITE_AFF_TEXT );
124280124320
testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
@@ -124285,15 +124325,18 @@
124285124325
zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
124286124326
len = sqlite3Strlen30(zType);
124287124327
assert( pCol->affinity==SQLITE_AFF_BLOB
124288124328
|| pCol->affinity==SQLITE_AFF_FLEXNUM
124289124329
|| pCol->affinity==sqlite3AffinityType(zType, 0) );
124330
+ assert( k+len<n );
124290124331
memcpy(&zStmt[k], zType, len);
124291124332
k += len;
124292124333
assert( k<=n );
124293124334
}
124294
- sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd);
124335
+ len = sqlite3Strlen30(zEnd);
124336
+ assert( k+len<n );
124337
+ memcpy(&zStmt[k], zEnd, len+1);
124295124338
return zStmt;
124296124339
}
124297124340
124298124341
/*
124299124342
** Resize an Index object to hold N columns total. Return SQLITE_OK
@@ -124482,13 +124525,13 @@
124482124525
124483124526
/* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
124484124527
** into BTREE_BLOBKEY.
124485124528
*/
124486124529
assert( !pParse->bReturning );
124487
- if( pParse->u1.addrCrTab ){
124530
+ if( pParse->u1.cr.addrCrTab ){
124488124531
assert( v );
124489
- sqlite3VdbeChangeP3(v, pParse->u1.addrCrTab, BTREE_BLOBKEY);
124532
+ sqlite3VdbeChangeP3(v, pParse->u1.cr.addrCrTab, BTREE_BLOBKEY);
124490124533
}
124491124534
124492124535
/* Locate the PRIMARY KEY index. Or, if this table was originally
124493124536
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
124494124537
*/
@@ -124924,11 +124967,11 @@
124924124967
#endif
124925124968
}
124926124969
124927124970
/* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
124928124971
** statement to populate the new table. The root-page number for the
124929
- ** new table is in register pParse->regRoot.
124972
+ ** new table is in register pParse->u1.cr.regRoot.
124930124973
**
124931124974
** Once the SELECT has been coded by sqlite3Select(), it is in a
124932124975
** suitable state to query for the column names and types to be used
124933124976
** by the new table.
124934124977
**
@@ -124955,11 +124998,12 @@
124955124998
iCsr = pParse->nTab++;
124956124999
regYield = ++pParse->nMem;
124957125000
regRec = ++pParse->nMem;
124958125001
regRowid = ++pParse->nMem;
124959125002
sqlite3MayAbort(pParse);
124960
- sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->regRoot, iDb);
125003
+ assert( pParse->isCreate );
125004
+ sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->u1.cr.regRoot, iDb);
124961125005
sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
124962125006
addrTop = sqlite3VdbeCurrentAddr(v) + 1;
124963125007
sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
124964125008
if( pParse->nErr ) return;
124965125009
pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
@@ -125000,21 +125044,22 @@
125000125044
125001125045
/* A slot for the record has already been allocated in the
125002125046
** schema table. We just need to update that slot with all
125003125047
** the information we've collected.
125004125048
*/
125049
+ assert( pParse->isCreate );
125005125050
sqlite3NestedParse(pParse,
125006125051
"UPDATE %Q." LEGACY_SCHEMA_TABLE
125007125052
" SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
125008125053
" WHERE rowid=#%d",
125009125054
db->aDb[iDb].zDbSName,
125010125055
zType,
125011125056
p->zName,
125012125057
p->zName,
125013
- pParse->regRoot,
125058
+ pParse->u1.cr.regRoot,
125014125059
zStmt,
125015
- pParse->regRowid
125060
+ pParse->u1.cr.regRowid
125016125061
);
125017125062
sqlite3DbFree(db, zStmt);
125018125063
sqlite3ChangeCookie(pParse, iDb);
125019125064
125020125065
#ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -125981,11 +126026,11 @@
125981126026
i16 nCol, /* Total number of columns in the index */
125982126027
int nExtra, /* Number of bytes of extra space to alloc */
125983126028
char **ppExtra /* Pointer to the "extra" space */
125984126029
){
125985126030
Index *p; /* Allocated index object */
125986
- int nByte; /* Bytes of space for Index object + arrays */
126031
+ i64 nByte; /* Bytes of space for Index object + arrays */
125987126032
125988126033
nByte = ROUND8(sizeof(Index)) + /* Index structure */
125989126034
ROUND8(sizeof(char*)*nCol) + /* Index.azColl */
125990126035
ROUND8(sizeof(LogEst)*(nCol+1) + /* Index.aiRowLogEst */
125991126036
sizeof(i16)*nCol + /* Index.aiColumn */
@@ -129850,15 +129895,10 @@
129850129895
int len;
129851129896
int p0type;
129852129897
i64 p1, p2;
129853129898
129854129899
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
- }
129860129900
p0type = sqlite3_value_type(argv[0]);
129861129901
p1 = sqlite3_value_int64(argv[1]);
129862129902
if( p0type==SQLITE_BLOB ){
129863129903
len = sqlite3_value_bytes(argv[0]);
129864129904
z = sqlite3_value_blob(argv[0]);
@@ -129872,23 +129912,27 @@
129872129912
for(z2=z; *z2; len++){
129873129913
SQLITE_SKIP_UTF8(z2);
129874129914
}
129875129915
}
129876129916
}
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
129885129917
if( argc==3 ){
129886129918
p2 = sqlite3_value_int64(argv[2]);
129919
+ if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
129887129920
}else{
129888129921
p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
129889129922
}
129923
+ if( p1==0 ){
129924
+#ifdef SQLITE_SUBSTR_COMPATIBILITY
129925
+ /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
129926
+ ** as substr(X,1,N) - it returns the first N characters of X. This
129927
+ ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
129928
+ ** from 2009-02-02 for compatibility of applications that exploited the
129929
+ ** old buggy behavior. */
129930
+ p1 = 1; /* <rdar://problem/6778339> */
129931
+#endif
129932
+ if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
129933
+ }
129890129934
if( p1<0 ){
129891129935
p1 += len;
129892129936
if( p1<0 ){
129893129937
if( p2<0 ){
129894129938
p2 = 0;
@@ -130915,11 +130959,11 @@
130915130959
if( zRep==0 ) return;
130916130960
nRep = sqlite3_value_bytes(argv[2]);
130917130961
assert( zRep==sqlite3_value_text(argv[2]) );
130918130962
nOut = nStr + 1;
130919130963
assert( nOut<SQLITE_MAX_LENGTH );
130920
- zOut = contextMalloc(context, (i64)nOut);
130964
+ zOut = contextMalloc(context, nOut);
130921130965
if( zOut==0 ){
130922130966
return;
130923130967
}
130924130968
loopLimit = nStr - nPattern;
130925130969
cntExpand = 0;
@@ -131065,11 +131109,11 @@
131065131109
int i;
131066131110
char *z;
131067131111
for(i=0; i<argc; i++){
131068131112
n += sqlite3_value_bytes(argv[i]);
131069131113
}
131070
- n += (argc-1)*nSep;
131114
+ n += (argc-1)*(i64)nSep;
131071131115
z = sqlite3_malloc64(n+1);
131072131116
if( z==0 ){
131073131117
sqlite3_result_error_nomem(context);
131074131118
return;
131075131119
}
@@ -134900,32 +134944,26 @@
134900134944
bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
134901134945
if( pColumn ){
134902134946
aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int));
134903134947
if( aTabColMap==0 ) goto insert_cleanup;
134904134948
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
- }
134949
+ j = sqlite3ColumnIndex(pTab, pColumn->a[i].zName);
134950
+ if( j>=0 ){
134951
+ if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
134952
+ if( i!=j ) bIdListInOrder = 0;
134953
+ if( j==pTab->iPKey ){
134954
+ ipkColumn = i; assert( !withoutRowid );
134955
+ }
134915134956
#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
- }
134957
+ if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
134958
+ sqlite3ErrorMsg(pParse,
134959
+ "cannot INSERT into generated column \"%s\"",
134960
+ pTab->aCol[j].zCnName);
134961
+ goto insert_cleanup;
134962
+ }
134922134963
#endif
134923
- break;
134924
- }
134925
- }
134926
- if( j>=pTab->nCol ){
134964
+ }else{
134927134965
if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
134928134966
ipkColumn = i;
134929134967
bIdListInOrder = 0;
134930134968
}else{
134931134969
sqlite3ErrorMsg(pParse, "table %S has no column named %s",
@@ -135219,11 +135257,11 @@
135219135257
sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
135220135258
}
135221135259
continue;
135222135260
}else if( pColumn==0 ){
135223135261
/* Hidden columns that are not explicitly named in the INSERT
135224
- ** get there default value */
135262
+ ** get their default value */
135225135263
sqlite3ExprCodeFactorable(pParse,
135226135264
sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135227135265
iRegStore);
135228135266
continue;
135229135267
}
@@ -140832,11 +140870,14 @@
140832140870
){
140833140871
db->flags |= mask;
140834140872
}
140835140873
}else{
140836140874
db->flags &= ~mask;
140837
- if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
140875
+ if( mask==SQLITE_DeferFKs ){
140876
+ db->nDeferredImmCons = 0;
140877
+ db->nDeferredCons = 0;
140878
+ }
140838140879
if( (mask & SQLITE_WriteSchema)!=0
140839140880
&& sqlite3_stricmp(zRight, "reset")==0
140840140881
){
140841140882
/* IMP: R-60817-01178 If the argument is "RESET" then schema
140842140883
** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
@@ -144166,14 +144207,37 @@
144166144207
** Return the index of a column in a table. Return -1 if the column
144167144208
** is not contained in the table.
144168144209
*/
144169144210
SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
144170144211
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;
144212
+ u8 h;
144213
+ const Column *aCol;
144214
+ int nCol;
144215
+
144216
+ h = sqlite3StrIHash(zCol);
144217
+ aCol = pTab->aCol;
144218
+ nCol = pTab->nCol;
144219
+
144220
+ /* See if the aHx gives us a lucky match */
144221
+ i = pTab->aHx[h % sizeof(pTab->aHx)];
144222
+ assert( i<nCol );
144223
+ if( aCol[i].hName==h
144224
+ && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144225
+ ){
144226
+ return i;
144227
+ }
144228
+
144229
+ /* No lucky match from the hash table. Do a full search. */
144230
+ i = 0;
144231
+ while( 1 /*exit-by-break*/ ){
144232
+ if( aCol[i].hName==h
144233
+ && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144234
+ ){
144235
+ return i;
144236
+ }
144237
+ i++;
144238
+ if( i>=nCol ) break;
144175144239
}
144176144240
return -1;
144177144241
}
144178144242
144179144243
/*
@@ -152891,11 +152955,12 @@
152891152955
}else if( pTrig->op==TK_RETURNING ){
152892152956
#ifndef SQLITE_OMIT_VIRTUALTABLE
152893152957
assert( pParse->db->pVtabCtx==0 );
152894152958
#endif
152895152959
assert( pParse->bReturning );
152896
- assert( &(pParse->u1.pReturning->retTrig) == pTrig );
152960
+ assert( !pParse->isCreate );
152961
+ assert( &(pParse->u1.d.pReturning->retTrig) == pTrig );
152897152962
pTrig->table = pTab->zName;
152898152963
pTrig->pTabSchema = pTab->pSchema;
152899152964
pTrig->pNext = pList;
152900152965
pList = pTrig;
152901152966
}
@@ -153868,11 +153933,12 @@
153868153933
/* This RETURNING trigger must be for a different statement as
153869153934
** this statement lacks a RETURNING clause. */
153870153935
return;
153871153936
}
153872153937
assert( db->pParse==pParse );
153873
- pReturning = pParse->u1.pReturning;
153938
+ assert( !pParse->isCreate );
153939
+ pReturning = pParse->u1.d.pReturning;
153874153940
if( pTrigger != &(pReturning->retTrig) ){
153875153941
/* This RETURNING trigger is for a different statement */
153876153942
return;
153877153943
}
153878153944
memset(&sSelect, 0, sizeof(sSelect));
@@ -154098,10 +154164,12 @@
154098154164
sSubParse.pToplevel = pTop;
154099154165
sSubParse.zAuthContext = pTrigger->zName;
154100154166
sSubParse.eTriggerOp = pTrigger->op;
154101154167
sSubParse.nQueryLoop = pParse->nQueryLoop;
154102154168
sSubParse.prepFlags = pParse->prepFlags;
154169
+ sSubParse.oldmask = 0;
154170
+ sSubParse.newmask = 0;
154103154171
154104154172
v = sqlite3GetVdbe(&sSubParse);
154105154173
if( v ){
154106154174
VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
154107154175
pTrigger->zName, onErrorText(orconf),
@@ -154852,42 +154920,36 @@
154852154920
** column to be updated, make sure we have authorization to change
154853154921
** that column.
154854154922
*/
154855154923
chngRowid = chngPk = 0;
154856154924
for(i=0; i<pChanges->nExpr; i++){
154857
- u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName);
154858154925
/* If this is an UPDATE with a FROM clause, do not resolve expressions
154859154926
** here. The call to sqlite3Select() below will do that. */
154860154927
if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
154861154928
goto update_cleanup;
154862154929
}
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
- }
154930
+ j = sqlite3ColumnIndex(pTab, pChanges->a[i].zEName);
154931
+ if( j>=0 ){
154932
+ if( j==pTab->iPKey ){
154933
+ chngRowid = 1;
154934
+ pRowidExpr = pChanges->a[i].pExpr;
154935
+ iRowidExpr = i;
154936
+ }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
154937
+ chngPk = 1;
154938
+ }
154874154939
#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
- }
154940
+ else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
154941
+ testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
154942
+ testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
154943
+ sqlite3ErrorMsg(pParse,
154944
+ "cannot UPDATE generated column \"%s\"",
154945
+ pTab->aCol[j].zCnName);
154946
+ goto update_cleanup;
154947
+ }
154883154948
#endif
154884
- aXRef[j] = i;
154885
- break;
154886
- }
154887
- }
154888
- if( j>=pTab->nCol ){
154949
+ aXRef[j] = i;
154950
+ }else{
154889154951
if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
154890154952
j = -1;
154891154953
chngRowid = 1;
154892154954
pRowidExpr = pChanges->a[i].pExpr;
154893154955
iRowidExpr = i;
@@ -156990,24 +157052,25 @@
156990157052
156991157053
/* A slot for the record has already been allocated in the
156992157054
** schema table. We just need to update that slot with all
156993157055
** the information we've collected.
156994157056
**
156995
- ** The VM register number pParse->regRowid holds the rowid of an
157057
+ ** The VM register number pParse->u1.cr.regRowid holds the rowid of an
156996157058
** entry in the sqlite_schema table that was created for this vtab
156997157059
** by sqlite3StartTable().
156998157060
*/
156999157061
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
157062
+ assert( pParse->isCreate );
157000157063
sqlite3NestedParse(pParse,
157001157064
"UPDATE %Q." LEGACY_SCHEMA_TABLE " "
157002157065
"SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
157003157066
"WHERE rowid=#%d",
157004157067
db->aDb[iDb].zDbSName,
157005157068
pTab->zName,
157006157069
pTab->zName,
157007157070
zStmt,
157008
- pParse->regRowid
157071
+ pParse->u1.cr.regRowid
157009157072
);
157010157073
v = sqlite3GetVdbe(pParse);
157011157074
sqlite3ChangeCookie(pParse, iDb);
157012157075
157013157076
sqlite3VdbeAddOp0(v, OP_Expire);
@@ -160161,10 +160224,13 @@
160161160224
}
160162160225
}
160163160226
}
160164160227
sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
160165160228
sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
160229
+ /* The instruction immediately prior to OP_VFilter must be an OP_Integer
160230
+ ** that sets the "argc" value for xVFilter. This is necessary for
160231
+ ** resolveP2() to work correctly. See tag-20250207a. */
160166160232
sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
160167160233
pLoop->u.vtab.idxStr,
160168160234
pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
160169160235
VdbeCoverage(v);
160170160236
pLoop->u.vtab.needFree = 0;
@@ -174215,10 +174281,15 @@
174215174281
** to the original parse.y sources.
174216174282
*/
174217174283
174218174284
/* #include "sqliteInt.h" */
174219174285
174286
+/*
174287
+** Verify that the pParse->isCreate field is set
174288
+*/
174289
+#define ASSERT_IS_CREATE assert(pParse->isCreate)
174290
+
174220174291
/*
174221174292
** Disable all error recovery processing in the parser push-down
174222174293
** automaton.
174223174294
*/
174224174295
#define YYNOERRORRECOVERY 1
@@ -174278,10 +174349,14 @@
174278174349
** shared across database connections.
174279174350
*/
174280174351
static void disableLookaside(Parse *pParse){
174281174352
sqlite3 *db = pParse->db;
174282174353
pParse->disableLookaside++;
174354
+#ifdef SQLITE_DEBUG
174355
+ pParse->isCreate = 1;
174356
+#endif
174357
+ memset(&pParse->u1.cr, 0, sizeof(pParse->u1.cr));
174283174358
DisableLookaside;
174284174359
}
174285174360
174286174361
#if !defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) \
174287174362
&& defined(SQLITE_UDL_CAPABLE_PARSER)
@@ -177914,11 +177989,13 @@
177914177989
{
177915177990
sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[-2].minor.yy502);
177916177991
}
177917177992
break;
177918177993
case 14: /* createkw ::= CREATE */
177919
-{disableLookaside(pParse);}
177994
+{
177995
+ disableLookaside(pParse);
177996
+}
177920177997
break;
177921177998
case 15: /* ifnotexists ::= */
177922177999
case 18: /* temp ::= */ yytestcase(yyruleno==18);
177923178000
case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
177924178001
case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
@@ -178006,11 +178083,11 @@
178006178083
yymsp[1].minor.yy0 = yyLookaheadToken;
178007178084
}
178008178085
break;
178009178086
case 32: /* ccons ::= CONSTRAINT nm */
178010178087
case 67: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==67);
178011
-{pParse->constraintName = yymsp[0].minor.yy0;}
178088
+{ASSERT_IS_CREATE; pParse->u1.cr.constraintName = yymsp[0].minor.yy0;}
178012178089
break;
178013178090
case 33: /* ccons ::= DEFAULT scantok term */
178014178091
{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);}
178015178092
break;
178016178093
case 34: /* ccons ::= DEFAULT LP expr RP */
@@ -178116,11 +178193,11 @@
178116178193
break;
178117178194
case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
178118178195
{yymsp[-1].minor.yy502 = 0;}
178119178196
break;
178120178197
case 66: /* tconscomma ::= COMMA */
178121
-{pParse->constraintName.n = 0;}
178198
+{ASSERT_IS_CREATE; pParse->u1.cr.constraintName.n = 0;}
178122178199
break;
178123178200
case 68: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
178124178201
{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);}
178125178202
break;
178126178203
case 69: /* tcons ::= UNIQUE LP sortlist RP onconf */
@@ -179009,10 +179086,14 @@
179009179086
break;
179010179087
case 261: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
179011179088
{
179012179089
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);
179013179090
yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
179091
+#ifdef SQLITE_DEBUG
179092
+ assert( pParse->isCreate ); /* Set by createkw reduce action */
179093
+ pParse->isCreate = 0; /* But, should not be set for CREATE TRIGGER */
179094
+#endif
179014179095
}
179015179096
break;
179016179097
case 262: /* trigger_time ::= BEFORE|AFTER */
179017179098
{ yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ }
179018179099
break;
@@ -182295,21 +182376,26 @@
182295182376
** Set up the lookaside buffers for a database connection.
182296182377
** Return SQLITE_OK on success.
182297182378
** If lookaside is already active, return SQLITE_BUSY.
182298182379
**
182299182380
** The sz parameter is the number of bytes in each lookaside slot.
182300
-** The cnt parameter is the number of slots. If pStart is NULL the
182301
-** space for the lookaside memory is obtained from sqlite3_malloc().
182302
-** If pStart is not NULL then it is sz*cnt bytes of memory to use for
182303
-** the lookaside memory.
182381
+** The cnt parameter is the number of slots. If pBuf is NULL the
182382
+** space for the lookaside memory is obtained from sqlite3_malloc()
182383
+** or similar. If pBuf is not NULL then it is sz*cnt bytes of memory
182384
+** to use for the lookaside memory.
182304182385
*/
182305
-static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
182386
+static int setupLookaside(
182387
+ sqlite3 *db, /* Database connection being configured */
182388
+ void *pBuf, /* Memory to use for lookaside. May be NULL */
182389
+ int sz, /* Desired size of each lookaside memory slot */
182390
+ int cnt /* Number of slots to allocate */
182391
+){
182306182392
#ifndef SQLITE_OMIT_LOOKASIDE
182307
- void *pStart;
182308
- sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
182309
- int nBig; /* Number of full-size slots */
182310
- int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
182393
+ void *pStart; /* Start of the lookaside buffer */
182394
+ sqlite3_int64 szAlloc; /* Total space set aside for lookaside memory */
182395
+ int nBig; /* Number of full-size slots */
182396
+ int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
182311182397
182312182398
if( sqlite3LookasideUsed(db,0)>0 ){
182313182399
return SQLITE_BUSY;
182314182400
}
182315182401
/* Free any existing lookaside buffer for this handle before
@@ -182318,33 +182404,38 @@
182318182404
*/
182319182405
if( db->lookaside.bMalloced ){
182320182406
sqlite3_free(db->lookaside.pStart);
182321182407
}
182322182408
/* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
182323
- ** than a pointer to be useful.
182409
+ ** than a pointer and small enough to fit in a u16.
182324182410
*/
182325
- sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
182411
+ sz = ROUNDDOWN8(sz);
182326182412
if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
182327
- if( cnt<0 ) cnt = 0;
182328
- if( sz==0 || cnt==0 ){
182413
+ if( sz>65528 ) sz = 65528;
182414
+ /* Count must be at least 1 to be useful, but not so large as to use
182415
+ ** more than 0x7fff0000 total bytes for lookaside. */
182416
+ if( cnt<1 ) cnt = 0;
182417
+ if( sz>0 && cnt>(0x7fff0000/sz) ) cnt = 0x7fff0000/sz;
182418
+ szAlloc = (i64)sz*(i64)cnt;
182419
+ if( szAlloc==0 ){
182329182420
sz = 0;
182330182421
pStart = 0;
182331182422
}else if( pBuf==0 ){
182332182423
sqlite3BeginBenignMalloc();
182333
- pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */
182424
+ pStart = sqlite3Malloc( szAlloc );
182334182425
sqlite3EndBenignMalloc();
182335182426
if( pStart ) szAlloc = sqlite3MallocSize(pStart);
182336182427
}else{
182337182428
pStart = pBuf;
182338182429
}
182339182430
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
182340182431
if( sz>=LOOKASIDE_SMALL*3 ){
182341182432
nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);
182342
- nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
182433
+ nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL;
182343182434
}else if( sz>=LOOKASIDE_SMALL*2 ){
182344182435
nBig = szAlloc/(LOOKASIDE_SMALL+sz);
182345
- nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
182436
+ nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL;
182346182437
}else
182347182438
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
182348182439
if( sz>0 ){
182349182440
nBig = szAlloc/sz;
182350182441
nSm = 0;
@@ -185479,17 +185570,14 @@
185479185570
185480185571
/* Find the column for which info is requested */
185481185572
if( zColumnName==0 ){
185482185573
/* Query for existence of table only */
185483185574
}else{
185484
- for(iCol=0; iCol<pTab->nCol; iCol++){
185575
+ iCol = sqlite3ColumnIndex(pTab, zColumnName);
185576
+ if( iCol>=0 ){
185485185577
pCol = &pTab->aCol[iCol];
185486
- if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){
185487
- break;
185488
- }
185489
- }
185490
- if( iCol==pTab->nCol ){
185578
+ }else{
185491185579
if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
185492185580
iCol = pTab->iPKey;
185493185581
pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
185494185582
}else{
185495185583
pTab = 0;
@@ -192338,11 +192426,11 @@
192338192426
p1 = pPhrase->doclist.pList;
192339192427
p2 = aPoslist;
192340192428
nDistance = iPrev - nMaxUndeferred;
192341192429
}
192342192430
192343
- aOut = (char *)sqlite3Fts3MallocZero(nPoslist+FTS3_BUFFER_PADDING);
192431
+ aOut = (char *)sqlite3Fts3MallocZero(((i64)nPoslist)+FTS3_BUFFER_PADDING);
192344192432
if( !aOut ){
192345192433
sqlite3_free(aPoslist);
192346192434
return SQLITE_NOMEM;
192347192435
}
192348192436
@@ -194958,11 +195046,11 @@
194958195046
sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
194959195047
int rc;
194960195048
Fts3Expr *p = 0;
194961195049
sqlite3_tokenizer_cursor *pCursor = 0;
194962195050
char *zTemp = 0;
194963
- int nTemp = 0;
195051
+ i64 nTemp = 0;
194964195052
194965195053
const int nSpace = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
194966195054
int nToken = 0;
194967195055
194968195056
/* The final Fts3Expr data structure, including the Fts3Phrase,
@@ -207729,22 +207817,23 @@
207729207817
**
207730207818
** Return the number of errors.
207731207819
*/
207732207820
static int jsonBlobExpand(JsonParse *pParse, u32 N){
207733207821
u8 *aNew;
207734
- u32 t;
207822
+ u64 t;
207735207823
assert( N>pParse->nBlobAlloc );
207736207824
if( pParse->nBlobAlloc==0 ){
207737207825
t = 100;
207738207826
}else{
207739207827
t = pParse->nBlobAlloc*2;
207740207828
}
207741207829
if( t<N ) t = N+100;
207742207830
aNew = sqlite3DbRealloc(pParse->db, pParse->aBlob, t);
207743207831
if( aNew==0 ){ pParse->oom = 1; return 1; }
207832
+ assert( t<0x7fffffff );
207744207833
pParse->aBlob = aNew;
207745
- pParse->nBlobAlloc = t;
207834
+ pParse->nBlobAlloc = (u32)t;
207746207835
return 0;
207747207836
}
207748207837
207749207838
/*
207750207839
** If pParse->aBlob is not previously editable (because it is taken
@@ -208697,14 +208786,11 @@
208697208786
*/
208698208787
static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){
208699208788
u8 x;
208700208789
u32 sz;
208701208790
u32 n;
208702
- if( NEVER(i>pParse->nBlob) ){
208703
- *pSz = 0;
208704
- return 0;
208705
- }
208791
+ assert( i<=pParse->nBlob );
208706208792
x = pParse->aBlob[i]>>4;
208707208793
if( x<=11 ){
208708208794
sz = x;
208709208795
n = 1;
208710208796
}else if( x==12 ){
@@ -208744,12 +208830,12 @@
208744208830
n = 9;
208745208831
}
208746208832
if( (i64)i+sz+n > pParse->nBlob
208747208833
&& (i64)i+sz+n > pParse->nBlob-pParse->delta
208748208834
){
208749
- sz = 0;
208750
- n = 0;
208835
+ *pSz = 0;
208836
+ return 0;
208751208837
}
208752208838
*pSz = sz;
208753208839
return n;
208754208840
}
208755208841
@@ -208842,13 +208928,16 @@
208842208928
}
208843208929
break;
208844208930
}
208845208931
case JSONB_TEXT:
208846208932
case JSONB_TEXTJ: {
208847
- jsonAppendChar(pOut, '"');
208848
- jsonAppendRaw(pOut, (const char*)&pParse->aBlob[i+n], sz);
208849
- jsonAppendChar(pOut, '"');
208933
+ if( pOut->nUsed+sz+2<=pOut->nAlloc || jsonStringGrow(pOut, sz+2)==0 ){
208934
+ pOut->zBuf[pOut->nUsed] = '"';
208935
+ memcpy(pOut->zBuf+pOut->nUsed+1,(const char*)&pParse->aBlob[i+n],sz);
208936
+ pOut->zBuf[pOut->nUsed+sz+1] = '"';
208937
+ pOut->nUsed += sz+2;
208938
+ }
208850208939
break;
208851208940
}
208852208941
case JSONB_TEXT5: {
208853208942
const char *zIn;
208854208943
u32 k;
@@ -209759,11 +209848,11 @@
209759209848
u32 iIn, iOut;
209760209849
const char *z;
209761209850
char *zOut;
209762209851
u32 nOut = sz;
209763209852
z = (const char*)&pParse->aBlob[i+n];
209764
- zOut = sqlite3DbMallocRaw(db, nOut+1);
209853
+ zOut = sqlite3DbMallocRaw(db, ((u64)nOut)+1);
209765209854
if( zOut==0 ) goto returnfromblob_oom;
209766209855
for(iIn=iOut=0; iIn<sz; iIn++){
209767209856
char c = z[iIn];
209768209857
if( c=='\\' ){
209769209858
u32 v;
@@ -248043,11 +248132,11 @@
248043248132
int iIdx = 0;
248044248133
int iStart = 0;
248045248134
int iDelKeyOff = 0; /* Offset of deleted key, if any */
248046248135
248047248136
nIdx = nPg-iPgIdx;
248048
- aIdx = sqlite3Fts5MallocZero(&p->rc, nIdx+16);
248137
+ aIdx = sqlite3Fts5MallocZero(&p->rc, ((i64)nIdx)+16);
248049248138
if( p->rc ) return;
248050248139
memcpy(aIdx, &aPg[iPgIdx], nIdx);
248051248140
248052248141
/* At this point segment iterator pSeg points to the entry
248053248142
** this function should remove from the b-tree segment.
@@ -248637,11 +248726,11 @@
248637248726
return pStruct;
248638248727
}
248639248728
assert( pStruct->aLevel[i].nMerge<=nThis );
248640248729
}
248641248730
248642
- nByte += (pStruct->nLevel+1) * sizeof(Fts5StructureLevel);
248731
+ nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel);
248643248732
pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
248644248733
248645248734
if( pNew ){
248646248735
Fts5StructureLevel *pLvl;
248647248736
nByte = nSeg * sizeof(Fts5StructureSegment);
@@ -249525,11 +249614,12 @@
249525249614
for(iFree=i; iFree<i+s.nMerge; iFree++){
249526249615
fts5BufferFree(&s.aBuf[iFree]);
249527249616
}
249528249617
}
249529249618
249530
- pData = fts5IdxMalloc(p, sizeof(*pData)+s.doclist.n+FTS5_DATA_ZERO_PADDING);
249619
+ pData = fts5IdxMalloc(p, sizeof(*pData)
249620
+ + ((i64)s.doclist.n)+FTS5_DATA_ZERO_PADDING);
249531249621
assert( pData!=0 || p->rc!=SQLITE_OK );
249532249622
if( pData ){
249533249623
pData->p = (u8*)&pData[1];
249534249624
pData->nn = pData->szLeaf = s.doclist.n;
249535249625
if( s.doclist.n ) memcpy(pData->p, s.doclist.p, s.doclist.n);
@@ -251749,11 +251839,11 @@
251749251839
/* Make a copy of the second argument (a blob) in aBlob[]. The aBlob[]
251750251840
** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
251751251841
** buffer overreads even if the record is corrupt. */
251752251842
n = sqlite3_value_bytes(apVal[1]);
251753251843
aBlob = sqlite3_value_blob(apVal[1]);
251754
- nSpace = n + FTS5_DATA_ZERO_PADDING;
251844
+ nSpace = ((i64)n) + FTS5_DATA_ZERO_PADDING;
251755251845
a = (u8*)sqlite3Fts5MallocZero(&rc, nSpace);
251756251846
if( a==0 ) goto decode_out;
251757251847
if( n>0 ) memcpy(a, aBlob, n);
251758251848
251759251849
fts5DecodeRowid(iRowid, &bTomb, &iSegid, &bDlidx, &iHeight, &iPgno);
@@ -255870,11 +255960,11 @@
255870255960
int nArg, /* Number of args */
255871255961
sqlite3_value **apUnused /* Function arguments */
255872255962
){
255873255963
assert( nArg==0 );
255874255964
UNUSED_PARAM2(nArg, apUnused);
255875
- sqlite3_result_text(pCtx, "fts5: 2025-02-06 11:55:18 4a7dd425dc2a0e5082a9049c9b4a9d4f199a71583d014c24b4cfe276c5a77cde", -1, SQLITE_TRANSIENT);
255965
+ sqlite3_result_text(pCtx, "fts5: 2025-02-18 01:16:26 57caa3136d1bfca06e4f2285734a4977b8d3fa1f75bf87453b975867e9de38fc", -1, SQLITE_TRANSIENT);
255876255966
}
255877255967
255878255968
/*
255879255969
** Implementation of fts5_locale(LOCALE, TEXT) function.
255880255970
**
@@ -260475,16 +260565,16 @@
260475260565
260476260566
if( argc!=5 && bDb==0 ){
260477260567
*pzErr = sqlite3_mprintf("wrong number of vtable arguments");
260478260568
rc = SQLITE_ERROR;
260479260569
}else{
260480
- int nByte; /* Bytes of space to allocate */
260570
+ i64 nByte; /* Bytes of space to allocate */
260481260571
const char *zDb = bDb ? argv[3] : argv[1];
260482260572
const char *zTab = bDb ? argv[4] : argv[3];
260483260573
const char *zType = bDb ? argv[5] : argv[4];
260484
- int nDb = (int)strlen(zDb)+1;
260485
- int nTab = (int)strlen(zTab)+1;
260574
+ i64 nDb = strlen(zDb)+1;
260575
+ i64 nTab = strlen(zTab)+1;
260486260576
int eType = 0;
260487260577
260488260578
rc = fts5VocabTableType(zType, pzErr, &eType);
260489260579
if( rc==SQLITE_OK ){
260490260580
assert( eType>=0 && eType<ArraySize(azSchema) );
260491260581
--- 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 **
@@ -2306,17 +2306,20 @@
2306 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
2307 ** return [SQLITE_ERROR].</dd>
2308 **
2309 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
2310 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
2311 ** the default size of lookaside memory on each [database connection].
2312 ** The first argument is the
2313 ** size of each lookaside buffer slot and the second is the number of
2314 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
2315 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
2316 ** option to [sqlite3_db_config()] can be used to change the lookaside
2317 ** configuration on individual connections.)^ </dd>
 
 
 
2318 **
2319 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
2320 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
2321 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
2322 ** the interface to a custom page cache implementation.)^
@@ -2549,35 +2552,54 @@
2549 **
2550 ** <dl>
2551 ** [[SQLITE_DBCONFIG_LOOKASIDE]]
2552 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2553 ** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2554 ** configuration of the lookaside memory allocator within a database
2555 ** connection.
2556 ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2557 ** in the [DBCONFIG arguments|usual format].
2558 ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2559 ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2560 ** should have a total of five parameters.
2561 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
 
2562 ** pointer to a memory buffer to use for lookaside memory.
2563 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2564 ** may be NULL in which case SQLite will allocate the
2565 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2566 ** size of each lookaside buffer slot. ^The third argument is the number of
2567 ** slots. The size of the buffer in the first argument must be greater than
2568 ** or equal to the product of the second and third arguments. The buffer
2569 ** must be aligned to an 8-byte boundary. ^If the second argument to
2570 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2571 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
 
 
 
 
 
 
 
 
 
2572 ** configuration for a database connection can only be changed when that
2573 ** connection is not currently using lookaside memory, or in other words
2574 ** when the "current value" returned by
2575 ** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2576 ** Any attempt to change the lookaside memory configuration when lookaside
2577 ** memory is in use leaves the configuration unchanged and returns
2578 ** [SQLITE_BUSY].)^</dd>
 
 
 
 
 
 
 
 
 
 
2579 **
2580 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2581 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2582 ** <dd> ^This option is used to enable or disable the enforcement of
2583 ** [foreign key constraints]. This is the same setting that is
@@ -12328,23 +12350,10 @@
12328 void *pB, /* Pointer to buffer containing changeset B */
12329 int *pnOut, /* OUT: Number of bytes in output changeset */
12330 void **ppOut /* OUT: Buffer containing output changeset */
12331 );
12332
12333
12334 /*
12335 ** CAPI3REF: Upgrade the Schema of a Changeset/Patchset
12336 */
12337 SQLITE_API int sqlite3changeset_upgrade(
12338 sqlite3 *db,
12339 const char *zDb,
12340 int nIn, const void *pIn, /* Input changeset */
12341 int *pnOut, void **ppOut /* OUT: Inverse of input */
12342 );
12343
12344
12345
12346 /*
12347 ** CAPI3REF: Changegroup Handle
12348 **
12349 ** A changegroup is an object used to combine two or more
12350 ** [changesets] or [patchsets]
@@ -14747,10 +14756,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 */
@@ -15185,10 +15195,15 @@
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
15194 ** have to specify the value in the less intuitive manner shown:
@@ -15353,10 +15368,18 @@
15353 */
15354 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
15355 #define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32))
15356 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
15357
 
 
 
 
 
 
 
 
15358 /*
15359 ** Round up a number to the next larger multiple of 8. This is used
15360 ** to force 8-byte alignment on 64-bit architectures.
15361 **
15362 ** ROUND8() always does the rounding, for any argument.
@@ -18731,10 +18754,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 +20152,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 +20192,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 +20208,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 +20219,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 +23861,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 +23921,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 +23941,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 */
@@ -32546,11 +32573,11 @@
32546 ** pointer if any kind of error was encountered.
32547 */
32548 static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
32549 char *zText;
32550 assert( p->mxAlloc>0 && !isMalloced(p) );
32551 zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
32552 if( zText ){
32553 memcpy(zText, p->zText, p->nChar+1);
32554 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
32555 }else{
32556 sqlite3StrAccumSetError(p, SQLITE_NOMEM);
@@ -36398,11 +36425,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 +37215,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 +37300,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 +37319,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 +37346,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 +37360,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 +37411,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 +37422,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 *****************************************/
@@ -50806,11 +50839,11 @@
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];
@@ -51627,11 +51660,11 @@
51627 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
51628 "0123456789";
51629 size_t i, j;
51630 DWORD pid;
51631 int nPre = sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX);
51632 int nMax, nBuf, nDir, nLen;
51633 char *zBuf;
51634
51635 /* It's odd to simulate an io-error here, but really this is just
51636 ** using the io-error infrastructure to test that SQLite handles this
51637 ** function failing.
@@ -51639,11 +51672,12 @@
51639 SimulateIOError( return SQLITE_IOERR );
51640
51641 /* Allocate a temporary buffer to store the fully qualified file
51642 ** name for the temporary file. If this fails, we cannot continue.
51643 */
51644 nMax = pVfs->mxPathname; nBuf = nMax + 2;
 
51645 zBuf = sqlite3MallocZero( nBuf );
51646 if( !zBuf ){
51647 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
51648 return SQLITE_IOERR_NOMEM_BKPT;
51649 }
@@ -52498,11 +52532,11 @@
52498 ** NOTE: We are dealing with a relative path name and the data
52499 ** directory has been set. Therefore, use it as the basis
52500 ** for converting the relative path name to an absolute
52501 ** one by prepending the data directory and a slash.
52502 */
52503 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
52504 if( !zOut ){
52505 return SQLITE_IOERR_NOMEM_BKPT;
52506 }
52507 if( cygwin_conv_path(
52508 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
@@ -52593,17 +52627,16 @@
52593 if( nByte==0 ){
52594 sqlite3_free(zConverted);
52595 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52596 "winFullPathname1", zRelative);
52597 }
52598 nByte += 3;
52599 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
52600 if( zTemp==0 ){
52601 sqlite3_free(zConverted);
52602 return SQLITE_IOERR_NOMEM_BKPT;
52603 }
52604 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
52605 if( nByte==0 ){
52606 sqlite3_free(zConverted);
52607 sqlite3_free(zTemp);
52608 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52609 "winFullPathname2", zRelative);
@@ -52619,17 +52652,16 @@
52619 if( nByte==0 ){
52620 sqlite3_free(zConverted);
52621 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52622 "winFullPathname3", zRelative);
52623 }
52624 nByte += 3;
52625 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
52626 if( zTemp==0 ){
52627 sqlite3_free(zConverted);
52628 return SQLITE_IOERR_NOMEM_BKPT;
52629 }
52630 nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
52631 if( nByte==0 ){
52632 sqlite3_free(zConverted);
52633 sqlite3_free(zTemp);
52634 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52635 "winFullPathname4", zRelative);
@@ -53654,17 +53686,17 @@
53654 break;
53655 }
53656 }
53657 if( p==0 ){
53658 MemStore **apNew;
53659 p = sqlite3Malloc( sizeof(*p) + szName + 3 );
53660 if( p==0 ){
53661 sqlite3_mutex_leave(pVfsMutex);
53662 return SQLITE_NOMEM;
53663 }
53664 apNew = sqlite3Realloc(memdb_g.apMemStore,
53665 sizeof(apNew[0])*(memdb_g.nMemStore+1) );
53666 if( apNew==0 ){
53667 sqlite3_free(p);
53668 sqlite3_mutex_leave(pVfsMutex);
53669 return SQLITE_NOMEM;
53670 }
@@ -54370,11 +54402,11 @@
54370 void *pTmpSpace;
54371
54372 /* Allocate the Bitvec to be tested and a linear array of
54373 ** bits to act as the reference */
54374 pBitvec = sqlite3BitvecCreate( sz );
54375 pV = sqlite3MallocZero( (sz+7)/8 + 1 );
54376 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
54377 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
54378
54379 /* NULL pBitvec tests */
54380 sqlite3BitvecSet(0, 1);
@@ -55917,16 +55949,16 @@
55917 **
55918 ** The PCache mutex must be held when this function is called.
55919 */
55920 static void pcache1ResizeHash(PCache1 *p){
55921 PgHdr1 **apNew;
55922 unsigned int nNew;
55923 unsigned int i;
55924
55925 assert( sqlite3_mutex_held(p->pGroup->mutex) );
55926
55927 nNew = p->nHash*2;
55928 if( nNew<256 ){
55929 nNew = 256;
55930 }
55931
55932 pcache1LeaveMutex(p->pGroup);
@@ -56145,11 +56177,11 @@
56145 ** Allocate a new cache.
56146 */
56147 static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
56148 PCache1 *pCache; /* The newly created page cache */
56149 PGroup *pGroup; /* The group the new page cache will belong to */
56150 int sz; /* Bytes of memory required to allocate the new cache */
56151
56152 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
56153 assert( szExtra < 300 );
56154
56155 sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache;
@@ -58624,11 +58656,11 @@
58624 ** zSuper[0] is set to 0 and SQLITE_OK returned.
58625 **
58626 ** If an error occurs while reading from the journal file, an SQLite
58627 ** error code is returned.
58628 */
58629 static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper){
58630 int rc; /* Return code */
58631 u32 len; /* Length in bytes of super-journal name */
58632 i64 szJ; /* Total size in bytes of journal file pJrnl */
58633 u32 cksum; /* MJ checksum value read from journal */
58634 u32 u; /* Unsigned loop counter */
@@ -59860,16 +59892,16 @@
59860 char *zSuperJournal = 0; /* Contents of super-journal file */
59861 i64 nSuperJournal; /* Size of super-journal file */
59862 char *zJournal; /* Pointer to one journal within MJ file */
59863 char *zSuperPtr; /* Space to hold super-journal filename */
59864 char *zFree = 0; /* Free this buffer */
59865 int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
59866
59867 /* Allocate space for both the pJournal and pSuper file descriptors.
59868 ** If successful, open the super-journal file for reading.
59869 */
59870 pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
59871 if( !pSuper ){
59872 rc = SQLITE_NOMEM_BKPT;
59873 pJournal = 0;
59874 }else{
59875 const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
@@ -59883,15 +59915,18 @@
59883 ** sufficient space (in zSuperPtr) to hold the names of super-journal
59884 ** files extracted from regular rollback-journals.
59885 */
59886 rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
59887 if( rc!=SQLITE_OK ) goto delsuper_out;
59888 nSuperPtr = pVfs->mxPathname+1;
 
59889 zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2);
59890 if( !zFree ){
59891 rc = SQLITE_NOMEM_BKPT;
59892 goto delsuper_out;
 
 
59893 }
59894 zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
59895 zSuperJournal = &zFree[4];
59896 zSuperPtr = &zSuperJournal[nSuperJournal+2];
59897 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
@@ -60148,11 +60183,11 @@
60148 ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
60149 ** mxPathname is 512, which is the same as the minimum allowable value
60150 ** for pageSize.
60151 */
60152 zSuper = pPager->pTmpSpace;
60153 rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
60154 if( rc==SQLITE_OK && zSuper[0] ){
60155 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
60156 }
60157 zSuper = 0;
60158 if( rc!=SQLITE_OK || !res ){
@@ -60287,11 +60322,11 @@
60287 /* Leave 4 bytes of space before the super-journal filename in memory.
60288 ** This is because it may end up being passed to sqlite3OsOpen(), in
60289 ** which case it requires 4 0x00 bytes in memory immediately before
60290 ** the filename. */
60291 zSuper = &pPager->pTmpSpace[4];
60292 rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
60293 testcase( rc!=SQLITE_OK );
60294 }
60295 if( rc==SQLITE_OK
60296 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
60297 ){
@@ -62057,10 +62092,11 @@
62057 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
62058 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
62059 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
62060 const char *zUri = 0; /* URI args to copy */
62061 int nUriByte = 1; /* Number of bytes of URI args at *zUri */
 
62062
62063 /* Figure out how much space is required for each journal file-handle
62064 ** (there are two of them, the main journal and the sub-journal). */
62065 journalFileSize = ROUND8(sqlite3JournalSize(pVfs));
62066
@@ -62083,12 +62119,12 @@
62083 ** to by zPathname, length nPathname. Or, if this is a temporary file,
62084 ** leave both nPathname and zPathname set to 0.
62085 */
62086 if( zFilename && zFilename[0] ){
62087 const char *z;
62088 nPathname = pVfs->mxPathname+1;
62089 zPathname = sqlite3DbMallocRaw(0, nPathname*2);
62090 if( zPathname==0 ){
62091 return SQLITE_NOMEM_BKPT;
62092 }
62093 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
62094 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
@@ -62171,18 +62207,18 @@
62171 assert( SQLITE_PTRSIZE==sizeof(Pager*) );
62172 pPtr = (u8 *)sqlite3MallocZero(
62173 ROUND8(sizeof(*pPager)) + /* Pager structure */
62174 ROUND8(pcacheSize) + /* PCache object */
62175 ROUND8(pVfs->szOsFile) + /* The main db file */
62176 journalFileSize * 2 + /* The two journal files */
62177 SQLITE_PTRSIZE + /* Space to hold a pointer */
62178 4 + /* Database prefix */
62179 nPathname + 1 + /* database filename */
62180 nUriByte + /* query parameters */
62181 nPathname + 8 + 1 + /* Journal filename */
62182 #ifndef SQLITE_OMIT_WAL
62183 nPathname + 4 + 1 + /* WAL filename */
62184 #endif
62185 3 /* Terminator */
62186 );
62187 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
62188 if( !pPtr ){
@@ -65884,11 +65920,11 @@
65884 ){
65885 int rc = SQLITE_OK;
65886
65887 /* Enlarge the pWal->apWiData[] array if required */
65888 if( pWal->nWiData<=iPage ){
65889 sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
65890 volatile u32 **apNew;
65891 apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte);
65892 if( !apNew ){
65893 *ppPage = 0;
65894 return SQLITE_NOMEM_BKPT;
@@ -71508,11 +71544,11 @@
71508 ** up to the size of 1 varint plus 1 8-byte value when the cursor
71509 ** position is restored. Hence the 17 bytes of padding allocated
71510 ** below. */
71511 void *pKey;
71512 pCur->nKey = sqlite3BtreePayloadSize(pCur);
71513 pKey = sqlite3Malloc( pCur->nKey + 9 + 8 );
71514 if( pKey ){
71515 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
71516 if( rc==SQLITE_OK ){
71517 memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
71518 pCur->pKey = pKey;
@@ -76879,11 +76915,11 @@
76879 testcase( nCell==2 ); /* Minimum legal index key size */
76880 if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
76881 rc = SQLITE_CORRUPT_PAGE(pPage);
76882 goto moveto_index_finish;
76883 }
76884 pCellKey = sqlite3Malloc( nCell+nOverrun );
76885 if( pCellKey==0 ){
76886 rc = SQLITE_NOMEM_BKPT;
76887 goto moveto_index_finish;
76888 }
76889 pCur->ix = (u16)idx;
@@ -82068,10 +82104,11 @@
82068 ** blob of allocated memory. The xFree function should not call sqlite3_free()
82069 ** on the memory, the btree layer does that.
82070 */
82071 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
82072 BtShared *pBt = p->pBt;
 
82073 sqlite3BtreeEnter(p);
82074 if( !pBt->pSchema && nBytes ){
82075 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
82076 pBt->xFreeSchema = xFree;
82077 }
@@ -83370,11 +83407,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;
@@ -84483,11 +84520,11 @@
84483 if( p ){
84484 UnpackedRecord *pRec = p->ppRec[0];
84485
84486 if( pRec==0 ){
84487 Index *pIdx = p->pIdx; /* Index being probed */
84488 int nByte; /* Bytes of space to allocate */
84489 int i; /* Counter variable */
84490 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
84491
84492 nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
84493 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
@@ -84549,11 +84586,11 @@
84549 sqlite3_value **ppVal, /* Write the new value here */
84550 struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */
84551 ){
84552 sqlite3_context ctx; /* Context object for function invocation */
84553 sqlite3_value **apVal = 0; /* Function arguments */
84554 int nVal = 0; /* Size of apVal[] array */
84555 FuncDef *pFunc = 0; /* Function definition */
84556 sqlite3_value *pVal = 0; /* New value */
84557 int rc = SQLITE_OK; /* Return code */
84558 ExprList *pList = 0; /* Function arguments */
84559 int i; /* Iterator variable */
@@ -85828,11 +85865,11 @@
85828 p->iSub++;
85829 p->iAddr = 0;
85830 }
85831
85832 if( pRet->p4type==P4_SUBPROGRAM ){
85833 int nByte = (p->nSub+1)*sizeof(SubProgram*);
85834 int j;
85835 for(j=0; j<p->nSub; j++){
85836 if( p->apSub[j]==pRet->p4.pProgram ) break;
85837 }
85838 if( j==p->nSub ){
@@ -85958,12 +85995,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 +86009,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 +86055,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 +86108,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 /*
@@ -86296,11 +86337,11 @@
86296 int addrVisit, /* Address of rows visited counter */
86297 LogEst nEst, /* Estimated number of output rows */
86298 const char *zName /* Name of table or index being scanned */
86299 ){
86300 if( IS_STMT_SCANSTATUS(p->db) ){
86301 sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
86302 ScanStatus *aNew;
86303 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
86304 if( aNew ){
86305 ScanStatus *pNew = &aNew[p->nScan++];
86306 memset(pNew, 0, sizeof(ScanStatus));
@@ -87745,11 +87786,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 +87858,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;
@@ -89314,10 +89358,11 @@
89314 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
89315 KeyInfo *pKeyInfo /* Description of the record */
89316 ){
89317 UnpackedRecord *p; /* Unpacked record to return */
89318 int nByte; /* Number of bytes required for *p */
 
89319 nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
89320 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
89321 if( !p ) return 0;
89322 p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
89323 assert( pKeyInfo->aSortFlags!=0 );
@@ -92890,11 +92935,13 @@
92890 /* This occurs when the table has been extended using ALTER TABLE
92891 ** ADD COLUMN. The value to return is the default value of the column. */
92892 Column *pCol = &p->pTab->aCol[iIdx];
92893 if( pCol->iDflt>0 ){
92894 if( p->apDflt==0 ){
92895 int nByte = sizeof(sqlite3_value*)*p->pTab->nCol;
 
 
92896 p->apDflt = (sqlite3_value**)sqlite3DbMallocZero(db, nByte);
92897 if( p->apDflt==0 ) goto preupdate_old_out;
92898 }
92899 if( p->apDflt[iIdx]==0 ){
92900 sqlite3_value *pVal = 0;
@@ -93040,11 +93087,12 @@
93040 ** It is not safe to return a pointer to the memory cell itself as the
93041 ** caller may modify the value text encoding.
93042 */
93043 assert( p->op==SQLITE_UPDATE );
93044 if( !p->aNew ){
93045 p->aNew = (Mem *)sqlite3DbMallocZero(db, sizeof(Mem) * p->pCsr->nField);
 
93046 if( !p->aNew ){
93047 rc = SQLITE_NOMEM;
93048 goto preupdate_new_out;
93049 }
93050 }
@@ -93810,11 +93858,11 @@
93810 ** the top of the register space. Cursor 1 is at Mem[p->nMem-1].
93811 ** Cursor 2 is at Mem[p->nMem-2]. And so forth.
93812 */
93813 Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
93814
93815 int nByte;
93816 VdbeCursor *pCx = 0;
93817 nByte =
93818 ROUND8P(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
93819 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
93820
@@ -93838,11 +93886,11 @@
93838 pMem->z = pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, nByte);
93839 if( pMem->zMalloc==0 ){
93840 pMem->szMalloc = 0;
93841 return 0;
93842 }
93843 pMem->szMalloc = nByte;
93844 }
93845
93846 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
93847 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
93848 pCx->eCurType = eCurType;
@@ -100859,11 +100907,11 @@
100859 **
100860 ** If P5 is non-zero, then recursive program invocation is enabled.
100861 */
100862 case OP_Program: { /* jump0 */
100863 int nMem; /* Number of memory registers for sub-program */
100864 int nByte; /* Bytes of runtime space required for sub-program */
100865 Mem *pRt; /* Register to allocate runtime space */
100866 Mem *pMem; /* Used to iterate through memory cells */
100867 Mem *pEnd; /* Last memory cell in new array */
100868 VdbeFrame *pFrame; /* New vdbe frame to execute in */
100869 SubProgram *pProgram; /* Sub-program to execute */
@@ -100910,19 +100958,19 @@
100910 assert( nMem>0 );
100911 if( pProgram->nCsr==0 ) nMem++;
100912 nByte = ROUND8(sizeof(VdbeFrame))
100913 + nMem * sizeof(Mem)
100914 + pProgram->nCsr * sizeof(VdbeCursor*)
100915 + (pProgram->nOp + 7)/8;
100916 pFrame = sqlite3DbMallocZero(db, nByte);
100917 if( !pFrame ){
100918 goto no_mem;
100919 }
100920 sqlite3VdbeMemRelease(pRt);
100921 pRt->flags = MEM_Blob|MEM_Dyn;
100922 pRt->z = (char*)pFrame;
100923 pRt->n = nByte;
100924 pRt->xDel = sqlite3VdbeFrameMemDel;
100925
100926 pFrame->v = p;
100927 pFrame->nChildMem = nMem;
100928 pFrame->nChildCsr = pProgram->nCsr;
@@ -101017,16 +101065,18 @@
101017 ** If P1 is non-zero, the database constraint counter is incremented
101018 ** (deferred foreign key constraints). Otherwise, if P1 is zero, the
101019 ** statement counter is incremented (immediate foreign key constraints).
101020 */
101021 case OP_FkCounter: {
101022 if( db->flags & SQLITE_DeferFKs ){
101023 db->nDeferredImmCons += pOp->p2;
101024 }else if( pOp->p1 ){
101025 db->nDeferredCons += pOp->p2;
101026 }else{
101027 p->nFkConstraint += pOp->p2;
 
 
 
 
101028 }
101029 break;
101030 }
101031
101032 /* Opcode: FkIfZero P1 P2 * * *
@@ -101897,10 +101947,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 +102158,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 +103004,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;
@@ -104219,11 +104267,11 @@
104219 int pgsz; /* Page size of main database */
104220 int i; /* Used to iterate through aTask[] */
104221 VdbeSorter *pSorter; /* The new sorter */
104222 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
104223 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
104224 int sz; /* Size of pSorter in bytes */
104225 int rc = SQLITE_OK;
104226 #if SQLITE_MAX_WORKER_THREADS==0
104227 # define nWorker 0
104228 #else
104229 int nWorker;
@@ -104247,10 +104295,12 @@
104247 #endif
104248
104249 assert( pCsr->pKeyInfo );
104250 assert( !pCsr->isEphemeral );
104251 assert( pCsr->eCurType==CURTYPE_SORTER );
 
 
104252 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
104253 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
104254
104255 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
104256 pCsr->uc.pSorter = pSorter;
@@ -104460,11 +104510,11 @@
104460 ** nReader is automatically rounded up to the next power of two.
104461 ** nReader may not exceed SORTER_MAX_MERGE_COUNT even after rounding up.
104462 */
104463 static MergeEngine *vdbeMergeEngineNew(int nReader){
104464 int N = 2; /* Smallest power of two >= nReader */
104465 int nByte; /* Total bytes of space to allocate */
104466 MergeEngine *pNew; /* Pointer to allocated object to return */
104467
104468 assert( nReader<=SORTER_MAX_MERGE_COUNT );
104469
104470 while( N<nReader ) N += N;
@@ -107503,11 +107553,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 +107603,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 +107690,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 +107811,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 +111417,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 +112533,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 /*
@@ -112906,11 +112937,11 @@
112906 int nVal = sqlite3ExprVectorSize(pLeft);
112907 Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
112908 char *zRet;
112909
112910 assert( pExpr->op==TK_IN );
112911 zRet = sqlite3DbMallocRaw(pParse->db, nVal+1);
112912 if( zRet ){
112913 int i;
112914 for(i=0; i<nVal; i++){
112915 Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i);
112916 char a = sqlite3ExprAffinity(pA);
@@ -117551,14 +117582,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 +119482,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
@@ -119644,11 +119674,11 @@
119644 ){
119645 StatAccum *p;
119646 int nCol; /* Number of columns in index being sampled */
119647 int nKeyCol; /* Number of key columns */
119648 int nColUp; /* nCol rounded up for alignment */
119649 int n; /* Bytes of space to allocate */
119650 sqlite3 *db = sqlite3_context_db_handle(context); /* Database connection */
119651 #ifdef SQLITE_ENABLE_STAT4
119652 /* Maximum number of samples. 0 if STAT4 data is not collected */
119653 int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0;
119654 #endif
@@ -121418,11 +121448,11 @@
121418 if( db->aDb==db->aDbStatic ){
121419 aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
121420 if( aNew==0 ) return;
121421 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
121422 }else{
121423 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
121424 if( aNew==0 ) return;
121425 }
121426 db->aDb = aNew;
121427 pNew = &db->aDb[db->nDb];
121428 memset(pNew, 0, sizeof(*pNew));
@@ -122211,10 +122241,11 @@
122211 p->isWriteLock = (p->isWriteLock || isWriteLock);
122212 return;
122213 }
122214 }
122215
 
122216 nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
122217 pToplevel->aTableLock =
122218 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
122219 if( pToplevel->aTableLock ){
122220 p = &pToplevel->aTableLock[pToplevel->nTableLock++];
@@ -122311,14 +122342,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 +122423,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 +123497,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 +123514,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 +123526,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 +123604,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 +123647,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 +123700,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 +123714,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 +123738,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 +124009,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 +124065,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;
@@ -124227,11 +124263,12 @@
124227 ** Generate a CREATE TABLE statement appropriate for the given
124228 ** table. Memory to hold the text of the statement is obtained
124229 ** from sqliteMalloc() and must be freed by the calling function.
124230 */
124231 static char *createTableStmt(sqlite3 *db, Table *p){
124232 int i, k, n;
 
124233 char *zStmt;
124234 char *zSep, *zSep2, *zEnd;
124235 Column *pCol;
124236 n = 0;
124237 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
@@ -124251,12 +124288,13 @@
124251 zStmt = sqlite3DbMallocRaw(0, n);
124252 if( zStmt==0 ){
124253 sqlite3OomFault(db);
124254 return 0;
124255 }
124256 sqlite3_snprintf(n, zStmt, "CREATE TABLE ");
124257 k = sqlite3Strlen30(zStmt);
 
124258 identPut(zStmt, &k, p->zName);
124259 zStmt[k++] = '(';
124260 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
124261 static const char * const azType[] = {
124262 /* SQLITE_AFF_BLOB */ "",
@@ -124264,17 +124302,19 @@
124264 /* SQLITE_AFF_NUMERIC */ " NUM",
124265 /* SQLITE_AFF_INTEGER */ " INT",
124266 /* SQLITE_AFF_REAL */ " REAL",
124267 /* SQLITE_AFF_FLEXNUM */ " NUM",
124268 };
124269 int len;
124270 const char *zType;
124271
124272 sqlite3_snprintf(n-k, &zStmt[k], zSep);
124273 k += sqlite3Strlen30(&zStmt[k]);
 
 
124274 zSep = zSep2;
124275 identPut(zStmt, &k, pCol->zCnName);
 
124276 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
124277 assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
124278 testcase( pCol->affinity==SQLITE_AFF_BLOB );
124279 testcase( pCol->affinity==SQLITE_AFF_TEXT );
124280 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
@@ -124285,15 +124325,18 @@
124285 zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
124286 len = sqlite3Strlen30(zType);
124287 assert( pCol->affinity==SQLITE_AFF_BLOB
124288 || pCol->affinity==SQLITE_AFF_FLEXNUM
124289 || pCol->affinity==sqlite3AffinityType(zType, 0) );
 
124290 memcpy(&zStmt[k], zType, len);
124291 k += len;
124292 assert( k<=n );
124293 }
124294 sqlite3_snprintf(n-k, &zStmt[k], "%s", zEnd);
 
 
124295 return zStmt;
124296 }
124297
124298 /*
124299 ** Resize an Index object to hold N columns total. Return SQLITE_OK
@@ -124482,13 +124525,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 +124967,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 +124998,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 +125044,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
@@ -125981,11 +126026,11 @@
125981 i16 nCol, /* Total number of columns in the index */
125982 int nExtra, /* Number of bytes of extra space to alloc */
125983 char **ppExtra /* Pointer to the "extra" space */
125984 ){
125985 Index *p; /* Allocated index object */
125986 int nByte; /* Bytes of space for Index object + arrays */
125987
125988 nByte = ROUND8(sizeof(Index)) + /* Index structure */
125989 ROUND8(sizeof(char*)*nCol) + /* Index.azColl */
125990 ROUND8(sizeof(LogEst)*(nCol+1) + /* Index.aiRowLogEst */
125991 sizeof(i16)*nCol + /* Index.aiColumn */
@@ -129850,15 +129895,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 +129912,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;
@@ -130915,11 +130959,11 @@
130915 if( zRep==0 ) return;
130916 nRep = sqlite3_value_bytes(argv[2]);
130917 assert( zRep==sqlite3_value_text(argv[2]) );
130918 nOut = nStr + 1;
130919 assert( nOut<SQLITE_MAX_LENGTH );
130920 zOut = contextMalloc(context, (i64)nOut);
130921 if( zOut==0 ){
130922 return;
130923 }
130924 loopLimit = nStr - nPattern;
130925 cntExpand = 0;
@@ -131065,11 +131109,11 @@
131065 int i;
131066 char *z;
131067 for(i=0; i<argc; i++){
131068 n += sqlite3_value_bytes(argv[i]);
131069 }
131070 n += (argc-1)*nSep;
131071 z = sqlite3_malloc64(n+1);
131072 if( z==0 ){
131073 sqlite3_result_error_nomem(context);
131074 return;
131075 }
@@ -134900,32 +134944,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 +135257,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 }
@@ -140832,11 +140870,14 @@
140832 ){
140833 db->flags |= mask;
140834 }
140835 }else{
140836 db->flags &= ~mask;
140837 if( mask==SQLITE_DeferFKs ) db->nDeferredImmCons = 0;
 
 
 
140838 if( (mask & SQLITE_WriteSchema)!=0
140839 && sqlite3_stricmp(zRight, "reset")==0
140840 ){
140841 /* IMP: R-60817-01178 If the argument is "RESET" then schema
140842 ** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
@@ -144166,14 +144207,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 +152955,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 +153933,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 +154164,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 +154920,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 +157052,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 +160224,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 +174281,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 +174349,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 +177989,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 +178083,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 +178193,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 +179086,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;
@@ -182295,21 +182376,26 @@
182295 ** Set up the lookaside buffers for a database connection.
182296 ** Return SQLITE_OK on success.
182297 ** If lookaside is already active, return SQLITE_BUSY.
182298 **
182299 ** The sz parameter is the number of bytes in each lookaside slot.
182300 ** The cnt parameter is the number of slots. If pStart is NULL the
182301 ** space for the lookaside memory is obtained from sqlite3_malloc().
182302 ** If pStart is not NULL then it is sz*cnt bytes of memory to use for
182303 ** the lookaside memory.
182304 */
182305 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
 
 
 
 
 
182306 #ifndef SQLITE_OMIT_LOOKASIDE
182307 void *pStart;
182308 sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt;
182309 int nBig; /* Number of full-size slots */
182310 int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
182311
182312 if( sqlite3LookasideUsed(db,0)>0 ){
182313 return SQLITE_BUSY;
182314 }
182315 /* Free any existing lookaside buffer for this handle before
@@ -182318,33 +182404,38 @@
182318 */
182319 if( db->lookaside.bMalloced ){
182320 sqlite3_free(db->lookaside.pStart);
182321 }
182322 /* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
182323 ** than a pointer to be useful.
182324 */
182325 sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
182326 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
182327 if( cnt<0 ) cnt = 0;
182328 if( sz==0 || cnt==0 ){
 
 
 
 
 
182329 sz = 0;
182330 pStart = 0;
182331 }else if( pBuf==0 ){
182332 sqlite3BeginBenignMalloc();
182333 pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */
182334 sqlite3EndBenignMalloc();
182335 if( pStart ) szAlloc = sqlite3MallocSize(pStart);
182336 }else{
182337 pStart = pBuf;
182338 }
182339 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
182340 if( sz>=LOOKASIDE_SMALL*3 ){
182341 nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);
182342 nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
182343 }else if( sz>=LOOKASIDE_SMALL*2 ){
182344 nBig = szAlloc/(LOOKASIDE_SMALL+sz);
182345 nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL;
182346 }else
182347 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
182348 if( sz>0 ){
182349 nBig = szAlloc/sz;
182350 nSm = 0;
@@ -185479,17 +185570,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;
@@ -192338,11 +192426,11 @@
192338 p1 = pPhrase->doclist.pList;
192339 p2 = aPoslist;
192340 nDistance = iPrev - nMaxUndeferred;
192341 }
192342
192343 aOut = (char *)sqlite3Fts3MallocZero(nPoslist+FTS3_BUFFER_PADDING);
192344 if( !aOut ){
192345 sqlite3_free(aPoslist);
192346 return SQLITE_NOMEM;
192347 }
192348
@@ -194958,11 +195046,11 @@
194958 sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
194959 int rc;
194960 Fts3Expr *p = 0;
194961 sqlite3_tokenizer_cursor *pCursor = 0;
194962 char *zTemp = 0;
194963 int nTemp = 0;
194964
194965 const int nSpace = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
194966 int nToken = 0;
194967
194968 /* The final Fts3Expr data structure, including the Fts3Phrase,
@@ -207729,22 +207817,23 @@
207729 **
207730 ** Return the number of errors.
207731 */
207732 static int jsonBlobExpand(JsonParse *pParse, u32 N){
207733 u8 *aNew;
207734 u32 t;
207735 assert( N>pParse->nBlobAlloc );
207736 if( pParse->nBlobAlloc==0 ){
207737 t = 100;
207738 }else{
207739 t = pParse->nBlobAlloc*2;
207740 }
207741 if( t<N ) t = N+100;
207742 aNew = sqlite3DbRealloc(pParse->db, pParse->aBlob, t);
207743 if( aNew==0 ){ pParse->oom = 1; return 1; }
 
207744 pParse->aBlob = aNew;
207745 pParse->nBlobAlloc = t;
207746 return 0;
207747 }
207748
207749 /*
207750 ** If pParse->aBlob is not previously editable (because it is taken
@@ -208697,14 +208786,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 +208830,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 +208928,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;
@@ -209759,11 +209848,11 @@
209759 u32 iIn, iOut;
209760 const char *z;
209761 char *zOut;
209762 u32 nOut = sz;
209763 z = (const char*)&pParse->aBlob[i+n];
209764 zOut = sqlite3DbMallocRaw(db, nOut+1);
209765 if( zOut==0 ) goto returnfromblob_oom;
209766 for(iIn=iOut=0; iIn<sz; iIn++){
209767 char c = z[iIn];
209768 if( c=='\\' ){
209769 u32 v;
@@ -248043,11 +248132,11 @@
248043 int iIdx = 0;
248044 int iStart = 0;
248045 int iDelKeyOff = 0; /* Offset of deleted key, if any */
248046
248047 nIdx = nPg-iPgIdx;
248048 aIdx = sqlite3Fts5MallocZero(&p->rc, nIdx+16);
248049 if( p->rc ) return;
248050 memcpy(aIdx, &aPg[iPgIdx], nIdx);
248051
248052 /* At this point segment iterator pSeg points to the entry
248053 ** this function should remove from the b-tree segment.
@@ -248637,11 +248726,11 @@
248637 return pStruct;
248638 }
248639 assert( pStruct->aLevel[i].nMerge<=nThis );
248640 }
248641
248642 nByte += (pStruct->nLevel+1) * sizeof(Fts5StructureLevel);
248643 pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
248644
248645 if( pNew ){
248646 Fts5StructureLevel *pLvl;
248647 nByte = nSeg * sizeof(Fts5StructureSegment);
@@ -249525,11 +249614,12 @@
249525 for(iFree=i; iFree<i+s.nMerge; iFree++){
249526 fts5BufferFree(&s.aBuf[iFree]);
249527 }
249528 }
249529
249530 pData = fts5IdxMalloc(p, sizeof(*pData)+s.doclist.n+FTS5_DATA_ZERO_PADDING);
 
249531 assert( pData!=0 || p->rc!=SQLITE_OK );
249532 if( pData ){
249533 pData->p = (u8*)&pData[1];
249534 pData->nn = pData->szLeaf = s.doclist.n;
249535 if( s.doclist.n ) memcpy(pData->p, s.doclist.p, s.doclist.n);
@@ -251749,11 +251839,11 @@
251749 /* Make a copy of the second argument (a blob) in aBlob[]. The aBlob[]
251750 ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
251751 ** buffer overreads even if the record is corrupt. */
251752 n = sqlite3_value_bytes(apVal[1]);
251753 aBlob = sqlite3_value_blob(apVal[1]);
251754 nSpace = n + FTS5_DATA_ZERO_PADDING;
251755 a = (u8*)sqlite3Fts5MallocZero(&rc, nSpace);
251756 if( a==0 ) goto decode_out;
251757 if( n>0 ) memcpy(a, aBlob, n);
251758
251759 fts5DecodeRowid(iRowid, &bTomb, &iSegid, &bDlidx, &iHeight, &iPgno);
@@ -255870,11 +255960,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 **
@@ -260475,16 +260565,16 @@
260475
260476 if( argc!=5 && bDb==0 ){
260477 *pzErr = sqlite3_mprintf("wrong number of vtable arguments");
260478 rc = SQLITE_ERROR;
260479 }else{
260480 int nByte; /* Bytes of space to allocate */
260481 const char *zDb = bDb ? argv[3] : argv[1];
260482 const char *zTab = bDb ? argv[4] : argv[3];
260483 const char *zType = bDb ? argv[5] : argv[4];
260484 int nDb = (int)strlen(zDb)+1;
260485 int nTab = (int)strlen(zTab)+1;
260486 int eType = 0;
260487
260488 rc = fts5VocabTableType(zType, pzErr, &eType);
260489 if( rc==SQLITE_OK ){
260490 assert( eType>=0 && eType<ArraySize(azSchema) );
260491
--- 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 ** 57caa3136d1bfca06e4f2285734a4977b8d3 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-18 01:16:26 57caa3136d1bfca06e4f2285734a4977b8d3fa1f75bf87453b975867e9de38fc"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -2306,17 +2306,20 @@
2306 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
2307 ** return [SQLITE_ERROR].</dd>
2308 **
2309 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
2310 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
2311 ** the default size of [lookaside memory] on each [database connection].
2312 ** The first argument is the
2313 ** size of each lookaside buffer slot ("sz") and the second is the number of
2314 ** slots allocated to each database connection ("cnt").)^
2315 ** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.
2316 ** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can
2317 ** be used to change the lookaside configuration on individual connections.)^
2318 ** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the
2319 ** default lookaside configuration at compile-time.
2320 ** </dd>
2321 **
2322 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
2323 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
2324 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
2325 ** the interface to a custom page cache implementation.)^
@@ -2549,35 +2552,54 @@
2552 **
2553 ** <dl>
2554 ** [[SQLITE_DBCONFIG_LOOKASIDE]]
2555 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2556 ** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2557 ** configuration of the [lookaside memory allocator] within a database
2558 ** connection.
2559 ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2560 ** in the [DBCONFIG arguments|usual format].
2561 ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2562 ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2563 ** should have a total of five parameters.
2564 ** <ol>
2565 ** <li><p>The first argument ("buf") is a
2566 ** pointer to a memory buffer to use for lookaside memory.
2567 ** The first argument may be NULL in which case SQLite will allocate the
2568 ** lookaside buffer itself using [sqlite3_malloc()].
2569 ** <li><P>The second argument ("sz") is the
2570 ** size of each lookaside buffer slot. Lookaside is disabled if "sz"
2571 ** is less than 8. The "sz" argument should be a multiple of 8 less than
2572 ** 65536. If "sz" does not meet this constraint, it is reduced in size until
2573 ** it does.
2574 ** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled
2575 ** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so
2576 ** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt"
2577 ** parameter is usually chosen so that the product of "sz" and "cnt" is less
2578 ** than 1,000,000.
2579 ** </ol>
2580 ** <p>If the "buf" argument is not NULL, then it must
2581 ** point to a memory buffer with a size that is greater than
2582 ** or equal to the product of "sz" and "cnt".
2583 ** The buffer must be aligned to an 8-byte boundary.
2584 ** The lookaside memory
2585 ** configuration for a database connection can only be changed when that
2586 ** connection is not currently using lookaside memory, or in other words
2587 ** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.
 
2588 ** Any attempt to change the lookaside memory configuration when lookaside
2589 ** memory is in use leaves the configuration unchanged and returns
2590 ** [SQLITE_BUSY].
2591 ** If the "buf" argument is NULL and an attempt
2592 ** to allocate memory based on "sz" and "cnt" fails, then
2593 ** lookaside is silently disabled.
2594 ** <p>
2595 ** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the
2596 ** default lookaside configuration at initialization. The
2597 ** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside
2598 ** configuration at compile-time. Typical values for lookaside are 1200 for
2599 ** "sz" and 40 to 100 for "cnt".
2600 ** </dd>
2601 **
2602 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2603 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2604 ** <dd> ^This option is used to enable or disable the enforcement of
2605 ** [foreign key constraints]. This is the same setting that is
@@ -12328,23 +12350,10 @@
12350 void *pB, /* Pointer to buffer containing changeset B */
12351 int *pnOut, /* OUT: Number of bytes in output changeset */
12352 void **ppOut /* OUT: Buffer containing output changeset */
12353 );
12354
 
 
 
 
 
 
 
 
 
 
 
 
 
12355 /*
12356 ** CAPI3REF: Changegroup Handle
12357 **
12358 ** A changegroup is an object used to combine two or more
12359 ** [changesets] or [patchsets]
@@ -14747,10 +14756,11 @@
14756 */
14757 struct HashElem {
14758 HashElem *next, *prev; /* Next and previous elements in the table */
14759 void *data; /* Data associated with this element */
14760 const char *pKey; /* Key associated with this element */
14761 unsigned int h; /* hash for pKey */
14762 };
14763
14764 /*
14765 ** Access routines. To delete, insert a NULL pointer.
14766 */
@@ -15185,10 +15195,15 @@
15195 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
15196 typedef INT16_TYPE i16; /* 2-byte signed integer */
15197 typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
15198 typedef INT8_TYPE i8; /* 1-byte signed integer */
15199
15200 /* A bitfield type for use inside of structures. Always follow with :N where
15201 ** N is the number of bits.
15202 */
15203 typedef unsigned bft; /* Bit Field Type */
15204
15205 /*
15206 ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value
15207 ** that can be stored in a u32 without loss of data. The value
15208 ** is 0x00000000ffffffff. But because of quirks of some compilers, we
15209 ** have to specify the value in the less intuitive manner shown:
@@ -15353,10 +15368,18 @@
15368 */
15369 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
15370 #define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32))
15371 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
15372
15373 /*
15374 ** Macro SMXV(n) return the maximum value that can be held in variable n,
15375 ** assuming n is a signed integer type. UMXV(n) is similar for unsigned
15376 ** integer types.
15377 */
15378 #define SMXV(n) ((((i64)1)<<(sizeof(n)-1))-1)
15379 #define UMXV(n) ((((i64)1)<<(sizeof(n)))-1)
15380
15381 /*
15382 ** Round up a number to the next larger multiple of 8. This is used
15383 ** to force 8-byte alignment on 64-bit architectures.
15384 **
15385 ** ROUND8() always does the rounding, for any argument.
@@ -18731,10 +18754,11 @@
18754 VTable *p; /* List of VTable objects. */
18755 } vtab;
18756 } u;
18757 Trigger *pTrigger; /* List of triggers on this object */
18758 Schema *pSchema; /* Schema that contains this table */
18759 u8 aHx[16]; /* Column aHt[K%sizeof(aHt)] might have hash K */
18760 };
18761
18762 /*
18763 ** Allowed values for Table.tabFlags.
18764 **
@@ -20128,29 +20152,36 @@
20152 struct Parse {
20153 sqlite3 *db; /* The main database structure */
20154 char *zErrMsg; /* An error message */
20155 Vdbe *pVdbe; /* An engine for executing database bytecode */
20156 int rc; /* Return code from execution */
20157 LogEst nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
 
20158 u8 nested; /* Number of nested calls to the parser/code generator */
20159 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
20160 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
20161 u8 mayAbort; /* True if statement may throw an ABORT exception */
20162 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
 
20163 u8 disableLookaside; /* Number of times lookaside has been disabled */
20164 u8 prepFlags; /* SQLITE_PREPARE_* flags */
20165 u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
 
20166 u8 mSubrtnSig; /* mini Bloom filter on available SubrtnSig.selId */
20167 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
20168 u8 bReturning; /* Coding a RETURNING trigger */
20169 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
20170 u8 disableTriggers; /* True to disable triggers */
20171 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
20172 u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
20173 #endif
20174 #ifdef SQLITE_DEBUG
20175 u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
20176 u8 isCreate; /* CREATE TABLE, INDEX, or VIEW (but not TRIGGER)
20177 ** and ALTER TABLE ADD COLUMN. */
20178 #endif
20179 bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20180 bft bHasWith :1; /* True if statement contains WITH */
20181 bft okConstFactor :1; /* OK to factor out constants */
20182 bft checkSchema :1; /* Causes schema cookie check after an error */
20183 int nRangeReg; /* Size of the temporary register block */
20184 int iRangeReg; /* First register in temporary register block */
20185 int nErr; /* Number of errors seen */
20186 int nTab; /* Number of previously allocated VDBE cursors */
20187 int nMem; /* Number of memory cells used so far */
@@ -20161,16 +20192,13 @@
20192 int nLabelAlloc; /* Number of slots in aLabel */
20193 int *aLabel; /* Space to hold the labels */
20194 ExprList *pConstExpr;/* Constant expressions */
20195 IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
20196 IndexedExpr *pIdxPartExpr; /* Exprs constrained by index WHERE clauses */
 
20197 yDbMask writeMask; /* Start a write transaction on these databases */
20198 yDbMask cookieMask; /* Bitmask of schema verified databases */
20199 int nMaxArg; /* Max args to xUpdate and xFilter vtab methods */
 
 
20200 int nSelect; /* Number of SELECT stmts. Counter for Select.selId */
20201 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
20202 u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
20203 #endif
20204 #ifndef SQLITE_OMIT_SHARED_CACHE
@@ -20180,21 +20208,10 @@
20208 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
20209 Parse *pToplevel; /* Parse structure for main program (or NULL) */
20210 Table *pTriggerTab; /* Table triggers are being coded for */
20211 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
20212 ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
 
 
 
 
 
 
 
 
 
 
 
20213
20214 /**************************************************************************
20215 ** Fields above must be initialized to zero. The fields that follow,
20216 ** down to the beginning of the recursive section, do not need to be
20217 ** initialized as they will be set before being used. The boundary is
@@ -20202,10 +20219,23 @@
20219 **************************************************************************/
20220
20221 int aTempReg[8]; /* Holding area for temporary registers */
20222 Parse *pOuterParse; /* Outer Parse object when nested */
20223 Token sNameToken; /* Token with unqualified schema object name */
20224 u32 oldmask; /* Mask of old.* columns referenced */
20225 u32 newmask; /* Mask of new.* columns referenced */
20226 union {
20227 struct { /* These fields available when isCreate is true */
20228 int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
20229 int regRowid; /* Register holding rowid of CREATE TABLE entry */
20230 int regRoot; /* Register holding root page for new objects */
20231 Token constraintName; /* Name of the constraint currently being parsed */
20232 } cr;
20233 struct { /* These fields available to all other statements */
20234 Returning *pReturning; /* The RETURNING clause */
20235 } d;
20236 } u1;
20237
20238 /************************************************************************
20239 ** Above is constant between recursions. Below is reset before and after
20240 ** each recursion. The boundary between these two regions is determined
20241 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -23831,14 +23861,10 @@
23861 u8 skipFlag; /* Skip accumulator loading if true */
23862 u16 argc; /* Number of arguments */
23863 sqlite3_value *argv[1]; /* Argument set */
23864 };
23865
 
 
 
 
23866
23867 /* The ScanStatus object holds a single value for the
23868 ** sqlite3_stmt_scanstatus() interface.
23869 **
23870 ** aAddrRange[]:
@@ -23895,11 +23921,11 @@
23921 i64 iCurrentTime; /* Value of julianday('now') for this statement */
23922 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
23923 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
23924 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
23925 Mem *aMem; /* The memory locations */
23926 Mem **apArg; /* Arguments xUpdate and xFilter vtab methods */
23927 VdbeCursor **apCsr; /* One element of this array for each open cursor */
23928 Mem *aVar; /* Values for the OP_Variable opcode. */
23929
23930 /* When allocating a new Vdbe object, all of the fields below should be
23931 ** initialized to zero or NULL */
@@ -23915,10 +23941,11 @@
23941 i64 startTime; /* Time when query started - used for profiling */
23942 #endif
23943 #ifdef SQLITE_DEBUG
23944 int rcApp; /* errcode set by sqlite3_result_error_code() */
23945 u32 nWrite; /* Number of write operations that have occurred */
23946 int napArg; /* Size of the apArg[] array */
23947 #endif
23948 u16 nResColumn; /* Number of columns in one row of the result set */
23949 u16 nResAlloc; /* Column slots allocated to aColName[] */
23950 u8 errorAction; /* Recovery action to do in case of an error */
23951 u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -32546,11 +32573,11 @@
32573 ** pointer if any kind of error was encountered.
32574 */
32575 static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
32576 char *zText;
32577 assert( p->mxAlloc>0 && !isMalloced(p) );
32578 zText = sqlite3DbMallocRaw(p->db, 1+(u64)p->nChar );
32579 if( zText ){
32580 memcpy(zText, p->zText, p->nChar+1);
32581 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
32582 }else{
32583 sqlite3StrAccumSetError(p, SQLITE_NOMEM);
@@ -36398,11 +36425,15 @@
36425 }
36426 }
36427 }
36428 p->z = &p->zBuf[i+1];
36429 assert( i+p->n < sizeof(p->zBuf) );
36430 assert( p->n>0 );
36431 while( p->z[p->n-1]=='0' ){
36432 p->n--;
36433 assert( p->n>0 );
36434 }
36435 }
36436
36437 /*
36438 ** Try to convert z into an unsigned 32-bit integer. Return true on
36439 ** success and false if there is an error.
@@ -37184,16 +37215,23 @@
37215 /*
37216 ** The hashing function.
37217 */
37218 static unsigned int strHash(const char *z){
37219 unsigned int h = 0;
37220 while( z[0] ){ /*OPTIMIZATION-IF-TRUE*/
 
37221 /* Knuth multiplicative hashing. (Sorting & Searching, p. 510).
37222 ** 0x9e3779b1 is 2654435761 which is the closest prime number to
37223 ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2.
37224 **
37225 ** Only bits 0xdf for ASCII and bits 0xbf for EBCDIC each octet are
37226 ** hashed since the omitted bits determine the upper/lower case difference.
37227 */
37228 #ifdef SQLITE_EBCDIC
37229 h += 0xbf & (unsigned char)*(z++);
37230 #else
37231 h += 0xdf & (unsigned char)*(z++);
37232 #endif
37233 h *= 0x9e3779b1;
37234 }
37235 return h;
37236 }
37237
@@ -37262,13 +37300,12 @@
37300 sqlite3_free(pH->ht);
37301 pH->ht = new_ht;
37302 pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
37303 memset(new_ht, 0, new_size*sizeof(struct _ht));
37304 for(elem=pH->first, pH->first=0; elem; elem = next_elem){
 
37305 next_elem = elem->next;
37306 insertElement(pH, &new_ht[elem->h % new_size], elem);
37307 }
37308 return 1;
37309 }
37310
37311 /* This function (for internal use only) locates an element in an
@@ -37282,27 +37319,26 @@
37319 unsigned int *pHash /* Write the hash value here */
37320 ){
37321 HashElem *elem; /* Used to loop thru the element list */
37322 unsigned int count; /* Number of elements left to test */
37323 unsigned int h; /* The computed hash */
37324 static HashElem nullElement = { 0, 0, 0, 0, 0 };
37325
37326 h = strHash(pKey);
37327 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
37328 struct _ht *pEntry;
37329 pEntry = &pH->ht[h % pH->htsize];
 
37330 elem = pEntry->chain;
37331 count = pEntry->count;
37332 }else{
 
37333 elem = pH->first;
37334 count = pH->count;
37335 }
37336 if( pHash ) *pHash = h;
37337 while( count ){
37338 assert( elem!=0 );
37339 if( h==elem->h && sqlite3StrICmp(elem->pKey,pKey)==0 ){
37340 return elem;
37341 }
37342 elem = elem->next;
37343 count--;
37344 }
@@ -37310,14 +37346,13 @@
37346 }
37347
37348 /* Remove a single entry from the hash table given a pointer to that
37349 ** element and a hash on the element's key.
37350 */
37351 static void removeElement(
37352 Hash *pH, /* The pH containing "elem" */
37353 HashElem *elem /* The element to be removed from the pH */
 
37354 ){
37355 struct _ht *pEntry;
37356 if( elem->prev ){
37357 elem->prev->next = elem->next;
37358 }else{
@@ -37325,11 +37360,11 @@
37360 }
37361 if( elem->next ){
37362 elem->next->prev = elem->prev;
37363 }
37364 if( pH->ht ){
37365 pEntry = &pH->ht[elem->h % pH->htsize];
37366 if( pEntry->chain==elem ){
37367 pEntry->chain = elem->next;
37368 }
37369 assert( pEntry->count>0 );
37370 pEntry->count--;
@@ -37376,11 +37411,11 @@
37411 assert( pKey!=0 );
37412 elem = findElementWithHash(pH,pKey,&h);
37413 if( elem->data ){
37414 void *old_data = elem->data;
37415 if( data==0 ){
37416 removeElement(pH,elem);
37417 }else{
37418 elem->data = data;
37419 elem->pKey = pKey;
37420 }
37421 return old_data;
@@ -37387,19 +37422,17 @@
37422 }
37423 if( data==0 ) return 0;
37424 new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
37425 if( new_elem==0 ) return data;
37426 new_elem->pKey = pKey;
37427 new_elem->h = h;
37428 new_elem->data = data;
37429 pH->count++;
37430 if( pH->count>=5 && pH->count > 2*pH->htsize ){
37431 rehash(pH, pH->count*3);
 
 
 
37432 }
37433 insertElement(pH, pH->ht ? &pH->ht[new_elem->h % pH->htsize] : 0, new_elem);
37434 return 0;
37435 }
37436
37437 /************** End of hash.c ************************************************/
37438 /************** Begin file opcodes.c *****************************************/
@@ -50806,11 +50839,11 @@
50839 ** allocate space for a new winShmNode and filename.
50840 */
50841 p = sqlite3MallocZero( sizeof(*p) );
50842 if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT;
50843 nName = sqlite3Strlen30(pDbFd->zPath);
50844 pNew = sqlite3MallocZero( sizeof(*pShmNode) + (i64)nName + 17 );
50845 if( pNew==0 ){
50846 sqlite3_free(p);
50847 return SQLITE_IOERR_NOMEM_BKPT;
50848 }
50849 pNew->zFilename = (char*)&pNew[1];
@@ -51627,11 +51660,11 @@
51660 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
51661 "0123456789";
51662 size_t i, j;
51663 DWORD pid;
51664 int nPre = sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX);
51665 i64 nMax, nBuf, nDir, nLen;
51666 char *zBuf;
51667
51668 /* It's odd to simulate an io-error here, but really this is just
51669 ** using the io-error infrastructure to test that SQLite handles this
51670 ** function failing.
@@ -51639,11 +51672,12 @@
51672 SimulateIOError( return SQLITE_IOERR );
51673
51674 /* Allocate a temporary buffer to store the fully qualified file
51675 ** name for the temporary file. If this fails, we cannot continue.
51676 */
51677 nMax = pVfs->mxPathname;
51678 nBuf = 2 + (i64)nMax;
51679 zBuf = sqlite3MallocZero( nBuf );
51680 if( !zBuf ){
51681 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
51682 return SQLITE_IOERR_NOMEM_BKPT;
51683 }
@@ -52498,11 +52532,11 @@
52532 ** NOTE: We are dealing with a relative path name and the data
52533 ** directory has been set. Therefore, use it as the basis
52534 ** for converting the relative path name to an absolute
52535 ** one by prepending the data directory and a slash.
52536 */
52537 char *zOut = sqlite3MallocZero( 1+(u64)pVfs->mxPathname );
52538 if( !zOut ){
52539 return SQLITE_IOERR_NOMEM_BKPT;
52540 }
52541 if( cygwin_conv_path(
52542 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
@@ -52593,17 +52627,16 @@
52627 if( nByte==0 ){
52628 sqlite3_free(zConverted);
52629 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52630 "winFullPathname1", zRelative);
52631 }
52632 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
 
52633 if( zTemp==0 ){
52634 sqlite3_free(zConverted);
52635 return SQLITE_IOERR_NOMEM_BKPT;
52636 }
52637 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte+3, zTemp, 0);
52638 if( nByte==0 ){
52639 sqlite3_free(zConverted);
52640 sqlite3_free(zTemp);
52641 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52642 "winFullPathname2", zRelative);
@@ -52619,17 +52652,16 @@
52652 if( nByte==0 ){
52653 sqlite3_free(zConverted);
52654 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52655 "winFullPathname3", zRelative);
52656 }
52657 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
 
52658 if( zTemp==0 ){
52659 sqlite3_free(zConverted);
52660 return SQLITE_IOERR_NOMEM_BKPT;
52661 }
52662 nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0);
52663 if( nByte==0 ){
52664 sqlite3_free(zConverted);
52665 sqlite3_free(zTemp);
52666 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
52667 "winFullPathname4", zRelative);
@@ -53654,17 +53686,17 @@
53686 break;
53687 }
53688 }
53689 if( p==0 ){
53690 MemStore **apNew;
53691 p = sqlite3Malloc( sizeof(*p) + (i64)szName + 3 );
53692 if( p==0 ){
53693 sqlite3_mutex_leave(pVfsMutex);
53694 return SQLITE_NOMEM;
53695 }
53696 apNew = sqlite3Realloc(memdb_g.apMemStore,
53697 sizeof(apNew[0])*(1+(i64)memdb_g.nMemStore) );
53698 if( apNew==0 ){
53699 sqlite3_free(p);
53700 sqlite3_mutex_leave(pVfsMutex);
53701 return SQLITE_NOMEM;
53702 }
@@ -54370,11 +54402,11 @@
54402 void *pTmpSpace;
54403
54404 /* Allocate the Bitvec to be tested and a linear array of
54405 ** bits to act as the reference */
54406 pBitvec = sqlite3BitvecCreate( sz );
54407 pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 );
54408 pTmpSpace = sqlite3_malloc64(BITVEC_SZ);
54409 if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end;
54410
54411 /* NULL pBitvec tests */
54412 sqlite3BitvecSet(0, 1);
@@ -55917,16 +55949,16 @@
55949 **
55950 ** The PCache mutex must be held when this function is called.
55951 */
55952 static void pcache1ResizeHash(PCache1 *p){
55953 PgHdr1 **apNew;
55954 u64 nNew;
55955 u32 i;
55956
55957 assert( sqlite3_mutex_held(p->pGroup->mutex) );
55958
55959 nNew = 2*(u64)p->nHash;
55960 if( nNew<256 ){
55961 nNew = 256;
55962 }
55963
55964 pcache1LeaveMutex(p->pGroup);
@@ -56145,11 +56177,11 @@
56177 ** Allocate a new cache.
56178 */
56179 static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
56180 PCache1 *pCache; /* The newly created page cache */
56181 PGroup *pGroup; /* The group the new page cache will belong to */
56182 i64 sz; /* Bytes of memory required to allocate the new cache */
56183
56184 assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
56185 assert( szExtra < 300 );
56186
56187 sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache;
@@ -58624,11 +58656,11 @@
58656 ** zSuper[0] is set to 0 and SQLITE_OK returned.
58657 **
58658 ** If an error occurs while reading from the journal file, an SQLite
58659 ** error code is returned.
58660 */
58661 static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){
58662 int rc; /* Return code */
58663 u32 len; /* Length in bytes of super-journal name */
58664 i64 szJ; /* Total size in bytes of journal file pJrnl */
58665 u32 cksum; /* MJ checksum value read from journal */
58666 u32 u; /* Unsigned loop counter */
@@ -59860,16 +59892,16 @@
59892 char *zSuperJournal = 0; /* Contents of super-journal file */
59893 i64 nSuperJournal; /* Size of super-journal file */
59894 char *zJournal; /* Pointer to one journal within MJ file */
59895 char *zSuperPtr; /* Space to hold super-journal filename */
59896 char *zFree = 0; /* Free this buffer */
59897 i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
59898
59899 /* Allocate space for both the pJournal and pSuper file descriptors.
59900 ** If successful, open the super-journal file for reading.
59901 */
59902 pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
59903 if( !pSuper ){
59904 rc = SQLITE_NOMEM_BKPT;
59905 pJournal = 0;
59906 }else{
59907 const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
@@ -59883,15 +59915,18 @@
59915 ** sufficient space (in zSuperPtr) to hold the names of super-journal
59916 ** files extracted from regular rollback-journals.
59917 */
59918 rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
59919 if( rc!=SQLITE_OK ) goto delsuper_out;
59920 nSuperPtr = 1 + (i64)pVfs->mxPathname;
59921 assert( nSuperJournal>=0 && nSuperPtr>0 );
59922 zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2);
59923 if( !zFree ){
59924 rc = SQLITE_NOMEM_BKPT;
59925 goto delsuper_out;
59926 }else{
59927 assert( nSuperJournal<=0x7fffffff );
59928 }
59929 zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
59930 zSuperJournal = &zFree[4];
59931 zSuperPtr = &zSuperJournal[nSuperJournal+2];
59932 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
@@ -60148,11 +60183,11 @@
60183 ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
60184 ** mxPathname is 512, which is the same as the minimum allowable value
60185 ** for pageSize.
60186 */
60187 zSuper = pPager->pTmpSpace;
60188 rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
60189 if( rc==SQLITE_OK && zSuper[0] ){
60190 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
60191 }
60192 zSuper = 0;
60193 if( rc!=SQLITE_OK || !res ){
@@ -60287,11 +60322,11 @@
60322 /* Leave 4 bytes of space before the super-journal filename in memory.
60323 ** This is because it may end up being passed to sqlite3OsOpen(), in
60324 ** which case it requires 4 0x00 bytes in memory immediately before
60325 ** the filename. */
60326 zSuper = &pPager->pTmpSpace[4];
60327 rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname);
60328 testcase( rc!=SQLITE_OK );
60329 }
60330 if( rc==SQLITE_OK
60331 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
60332 ){
@@ -62057,10 +62092,11 @@
62092 int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
62093 int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */
62094 u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
62095 const char *zUri = 0; /* URI args to copy */
62096 int nUriByte = 1; /* Number of bytes of URI args at *zUri */
62097
62098
62099 /* Figure out how much space is required for each journal file-handle
62100 ** (there are two of them, the main journal and the sub-journal). */
62101 journalFileSize = ROUND8(sqlite3JournalSize(pVfs));
62102
@@ -62083,12 +62119,12 @@
62119 ** to by zPathname, length nPathname. Or, if this is a temporary file,
62120 ** leave both nPathname and zPathname set to 0.
62121 */
62122 if( zFilename && zFilename[0] ){
62123 const char *z;
62124 nPathname = pVfs->mxPathname + 1;
62125 zPathname = sqlite3DbMallocRaw(0, 2*(i64)nPathname);
62126 if( zPathname==0 ){
62127 return SQLITE_NOMEM_BKPT;
62128 }
62129 zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
62130 rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
@@ -62171,18 +62207,18 @@
62207 assert( SQLITE_PTRSIZE==sizeof(Pager*) );
62208 pPtr = (u8 *)sqlite3MallocZero(
62209 ROUND8(sizeof(*pPager)) + /* Pager structure */
62210 ROUND8(pcacheSize) + /* PCache object */
62211 ROUND8(pVfs->szOsFile) + /* The main db file */
62212 (u64)journalFileSize * 2 + /* The two journal files */
62213 SQLITE_PTRSIZE + /* Space to hold a pointer */
62214 4 + /* Database prefix */
62215 (u64)nPathname + 1 + /* database filename */
62216 (u64)nUriByte + /* query parameters */
62217 (u64)nPathname + 8 + 1 + /* Journal filename */
62218 #ifndef SQLITE_OMIT_WAL
62219 (u64)nPathname + 4 + 1 + /* WAL filename */
62220 #endif
62221 3 /* Terminator */
62222 );
62223 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
62224 if( !pPtr ){
@@ -65884,11 +65920,11 @@
65920 ){
65921 int rc = SQLITE_OK;
65922
65923 /* Enlarge the pWal->apWiData[] array if required */
65924 if( pWal->nWiData<=iPage ){
65925 sqlite3_int64 nByte = sizeof(u32*)*(1+(i64)iPage);
65926 volatile u32 **apNew;
65927 apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte);
65928 if( !apNew ){
65929 *ppPage = 0;
65930 return SQLITE_NOMEM_BKPT;
@@ -71508,11 +71544,11 @@
71544 ** up to the size of 1 varint plus 1 8-byte value when the cursor
71545 ** position is restored. Hence the 17 bytes of padding allocated
71546 ** below. */
71547 void *pKey;
71548 pCur->nKey = sqlite3BtreePayloadSize(pCur);
71549 pKey = sqlite3Malloc( ((i64)pCur->nKey) + 9 + 8 );
71550 if( pKey ){
71551 rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
71552 if( rc==SQLITE_OK ){
71553 memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
71554 pCur->pKey = pKey;
@@ -76879,11 +76915,11 @@
76915 testcase( nCell==2 ); /* Minimum legal index key size */
76916 if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
76917 rc = SQLITE_CORRUPT_PAGE(pPage);
76918 goto moveto_index_finish;
76919 }
76920 pCellKey = sqlite3Malloc( (u64)nCell+(u64)nOverrun );
76921 if( pCellKey==0 ){
76922 rc = SQLITE_NOMEM_BKPT;
76923 goto moveto_index_finish;
76924 }
76925 pCur->ix = (u16)idx;
@@ -82068,10 +82104,11 @@
82104 ** blob of allocated memory. The xFree function should not call sqlite3_free()
82105 ** on the memory, the btree layer does that.
82106 */
82107 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
82108 BtShared *pBt = p->pBt;
82109 assert( nBytes==0 || nBytes==sizeof(Schema) );
82110 sqlite3BtreeEnter(p);
82111 if( !pBt->pSchema && nBytes ){
82112 pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
82113 pBt->xFreeSchema = xFree;
82114 }
@@ -83370,11 +83407,11 @@
83407 if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){
83408 /* pMem must be a string, and it cannot be an ephemeral or static string */
83409 return;
83410 }
83411 if( pMem->enc!=SQLITE_UTF8 ) return;
83412 assert( pMem->z!=0 );
83413 if( pMem->flags & MEM_Dyn ){
83414 if( pMem->xDel==sqlite3_free
83415 && sqlite3_msize(pMem->z) >= (u64)(pMem->n+1)
83416 ){
83417 pMem->z[pMem->n] = 0;
@@ -84483,11 +84520,11 @@
84520 if( p ){
84521 UnpackedRecord *pRec = p->ppRec[0];
84522
84523 if( pRec==0 ){
84524 Index *pIdx = p->pIdx; /* Index being probed */
84525 i64 nByte; /* Bytes of space to allocate */
84526 int i; /* Counter variable */
84527 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
84528
84529 nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
84530 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
@@ -84549,11 +84586,11 @@
84586 sqlite3_value **ppVal, /* Write the new value here */
84587 struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */
84588 ){
84589 sqlite3_context ctx; /* Context object for function invocation */
84590 sqlite3_value **apVal = 0; /* Function arguments */
84591 int nVal = 0; /* Number of function arguments */
84592 FuncDef *pFunc = 0; /* Function definition */
84593 sqlite3_value *pVal = 0; /* New value */
84594 int rc = SQLITE_OK; /* Return code */
84595 ExprList *pList = 0; /* Function arguments */
84596 int i; /* Iterator variable */
@@ -85828,11 +85865,11 @@
85865 p->iSub++;
85866 p->iAddr = 0;
85867 }
85868
85869 if( pRet->p4type==P4_SUBPROGRAM ){
85870 i64 nByte = (1+(u64)p->nSub)*sizeof(SubProgram*);
85871 int j;
85872 for(j=0; j<p->nSub; j++){
85873 if( p->apSub[j]==pRet->p4.pProgram ) break;
85874 }
85875 if( j==p->nSub ){
@@ -85958,12 +85995,12 @@
85995 ** through all the opcodes and fixes up some details.
85996 **
85997 ** (1) For each jump instruction with a negative P2 value (a label)
85998 ** resolve the P2 value to an actual address.
85999 **
86000 ** (2) Compute the maximum number of arguments used by the xUpdate/xFilter
86001 ** methods of any virtual table and store that value in *pMaxVtabArgs.
86002 **
86003 ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately
86004 ** indicate what the prepared statement actually does.
86005 **
86006 ** (4) (discontinued)
@@ -85972,12 +86009,12 @@
86009 **
86010 ** This routine will only function correctly if the mkopcodeh.tcl generator
86011 ** script numbers the opcodes correctly. Changes to this routine must be
86012 ** coordinated with changes to mkopcodeh.tcl.
86013 */
86014 static void resolveP2Values(Vdbe *p, int *pMaxVtabArgs){
86015 int nMaxVtabArgs = *pMaxVtabArgs;
86016 Op *pOp;
86017 Parse *pParse = p->pParse;
86018 int *aLabel = pParse->aLabel;
86019
86020 assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */
@@ -86018,19 +86055,23 @@
86055 assert( pOp->p2>=0 );
86056 goto resolve_p2_values_loop_exit;
86057 }
86058 #ifndef SQLITE_OMIT_VIRTUALTABLE
86059 case OP_VUpdate: {
86060 if( pOp->p2>nMaxVtabArgs ) nMaxVtabArgs = pOp->p2;
86061 break;
86062 }
86063 case OP_VFilter: {
86064 int n;
86065 /* The instruction immediately prior to VFilter will be an
86066 ** OP_Integer that sets the "argc" value for the VFilter. See
86067 ** the code where OP_VFilter is generated at tag-20250207a. */
86068 assert( (pOp - p->aOp) >= 3 );
86069 assert( pOp[-1].opcode==OP_Integer );
86070 assert( pOp[-1].p2==pOp->p3+1 );
86071 n = pOp[-1].p1;
86072 if( n>nMaxVtabArgs ) nMaxVtabArgs = n;
86073 /* Fall through into the default case */
86074 /* no break */ deliberate_fall_through
86075 }
86076 #endif
86077 default: {
@@ -86067,11 +86108,11 @@
86108 if( aLabel ){
86109 sqlite3DbNNFreeNN(p->db, pParse->aLabel);
86110 pParse->aLabel = 0;
86111 }
86112 pParse->nLabel = 0;
86113 *pMaxVtabArgs = nMaxVtabArgs;
86114 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
86115 }
86116
86117 #ifdef SQLITE_DEBUG
86118 /*
@@ -86296,11 +86337,11 @@
86337 int addrVisit, /* Address of rows visited counter */
86338 LogEst nEst, /* Estimated number of output rows */
86339 const char *zName /* Name of table or index being scanned */
86340 ){
86341 if( IS_STMT_SCANSTATUS(p->db) ){
86342 i64 nByte = (1+(i64)p->nScan) * sizeof(ScanStatus);
86343 ScanStatus *aNew;
86344 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
86345 if( aNew ){
86346 ScanStatus *pNew = &aNew[p->nScan++];
86347 memset(pNew, 0, sizeof(ScanStatus));
@@ -87745,11 +87786,11 @@
87786 ){
87787 sqlite3 *db; /* The database connection */
87788 int nVar; /* Number of parameters */
87789 int nMem; /* Number of VM memory registers */
87790 int nCursor; /* Number of cursors required */
87791 int nArg; /* Max number args to xFilter or xUpdate */
87792 int n; /* Loop counter */
87793 struct ReusableSpace x; /* Reusable bulk memory */
87794
87795 assert( p!=0 );
87796 assert( p->nOp>0 );
@@ -87817,10 +87858,13 @@
87858 p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
87859 p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
87860 p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
87861 }
87862 }
87863 #ifdef SQLITE_DEBUG
87864 p->napArg = nArg;
87865 #endif
87866
87867 if( db->mallocFailed ){
87868 p->nVar = 0;
87869 p->nCursor = 0;
87870 p->nMem = 0;
@@ -89314,10 +89358,11 @@
89358 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
89359 KeyInfo *pKeyInfo /* Description of the record */
89360 ){
89361 UnpackedRecord *p; /* Unpacked record to return */
89362 int nByte; /* Number of bytes required for *p */
89363 assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff );
89364 nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
89365 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
89366 if( !p ) return 0;
89367 p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))];
89368 assert( pKeyInfo->aSortFlags!=0 );
@@ -92890,11 +92935,13 @@
92935 /* This occurs when the table has been extended using ALTER TABLE
92936 ** ADD COLUMN. The value to return is the default value of the column. */
92937 Column *pCol = &p->pTab->aCol[iIdx];
92938 if( pCol->iDflt>0 ){
92939 if( p->apDflt==0 ){
92940 int nByte;
92941 assert( sizeof(sqlite3_value*)*UMXV(p->pTab->nCol) < 0x7fffffff );
92942 nByte = sizeof(sqlite3_value*)*p->pTab->nCol;
92943 p->apDflt = (sqlite3_value**)sqlite3DbMallocZero(db, nByte);
92944 if( p->apDflt==0 ) goto preupdate_old_out;
92945 }
92946 if( p->apDflt[iIdx]==0 ){
92947 sqlite3_value *pVal = 0;
@@ -93040,11 +93087,12 @@
93087 ** It is not safe to return a pointer to the memory cell itself as the
93088 ** caller may modify the value text encoding.
93089 */
93090 assert( p->op==SQLITE_UPDATE );
93091 if( !p->aNew ){
93092 assert( sizeof(Mem)*UMXV(p->pCsr->nField) < 0x7fffffff );
93093 p->aNew = (Mem *)sqlite3DbMallocZero(db, sizeof(Mem)*p->pCsr->nField);
93094 if( !p->aNew ){
93095 rc = SQLITE_NOMEM;
93096 goto preupdate_new_out;
93097 }
93098 }
@@ -93810,11 +93858,11 @@
93858 ** the top of the register space. Cursor 1 is at Mem[p->nMem-1].
93859 ** Cursor 2 is at Mem[p->nMem-2]. And so forth.
93860 */
93861 Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
93862
93863 i64 nByte;
93864 VdbeCursor *pCx = 0;
93865 nByte =
93866 ROUND8P(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
93867 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
93868
@@ -93838,11 +93886,11 @@
93886 pMem->z = pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, nByte);
93887 if( pMem->zMalloc==0 ){
93888 pMem->szMalloc = 0;
93889 return 0;
93890 }
93891 pMem->szMalloc = (int)nByte;
93892 }
93893
93894 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
93895 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
93896 pCx->eCurType = eCurType;
@@ -100859,11 +100907,11 @@
100907 **
100908 ** If P5 is non-zero, then recursive program invocation is enabled.
100909 */
100910 case OP_Program: { /* jump0 */
100911 int nMem; /* Number of memory registers for sub-program */
100912 i64 nByte; /* Bytes of runtime space required for sub-program */
100913 Mem *pRt; /* Register to allocate runtime space */
100914 Mem *pMem; /* Used to iterate through memory cells */
100915 Mem *pEnd; /* Last memory cell in new array */
100916 VdbeFrame *pFrame; /* New vdbe frame to execute in */
100917 SubProgram *pProgram; /* Sub-program to execute */
@@ -100910,19 +100958,19 @@
100958 assert( nMem>0 );
100959 if( pProgram->nCsr==0 ) nMem++;
100960 nByte = ROUND8(sizeof(VdbeFrame))
100961 + nMem * sizeof(Mem)
100962 + pProgram->nCsr * sizeof(VdbeCursor*)
100963 + (7 + (i64)pProgram->nOp)/8;
100964 pFrame = sqlite3DbMallocZero(db, nByte);
100965 if( !pFrame ){
100966 goto no_mem;
100967 }
100968 sqlite3VdbeMemRelease(pRt);
100969 pRt->flags = MEM_Blob|MEM_Dyn;
100970 pRt->z = (char*)pFrame;
100971 pRt->n = (int)nByte;
100972 pRt->xDel = sqlite3VdbeFrameMemDel;
100973
100974 pFrame->v = p;
100975 pFrame->nChildMem = nMem;
100976 pFrame->nChildCsr = pProgram->nCsr;
@@ -101017,16 +101065,18 @@
101065 ** If P1 is non-zero, the database constraint counter is incremented
101066 ** (deferred foreign key constraints). Otherwise, if P1 is zero, the
101067 ** statement counter is incremented (immediate foreign key constraints).
101068 */
101069 case OP_FkCounter: {
101070 if( pOp->p1 ){
 
 
101071 db->nDeferredCons += pOp->p2;
101072 }else{
101073 if( db->flags & SQLITE_DeferFKs ){
101074 db->nDeferredImmCons += pOp->p2;
101075 }else{
101076 p->nFkConstraint += pOp->p2;
101077 }
101078 }
101079 break;
101080 }
101081
101082 /* Opcode: FkIfZero P1 P2 * * *
@@ -101897,10 +101947,11 @@
101947 nArg = (int)pArgc->u.i;
101948 iQuery = (int)pQuery->u.i;
101949
101950 /* Invoke the xFilter method */
101951 apArg = p->apArg;
101952 assert( nArg<=p->napArg );
101953 for(i = 0; i<nArg; i++){
101954 apArg[i] = &pArgc[i+1];
101955 }
101956 rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg);
101957 sqlite3VtabImportErrmsg(p, pVtab);
@@ -102107,10 +102158,11 @@
102158 assert( pOp->p4type==P4_VTAB );
102159 if( ALWAYS(pModule->xUpdate) ){
102160 u8 vtabOnConflict = db->vtabOnConflict;
102161 apArg = p->apArg;
102162 pX = &aMem[pOp->p3];
102163 assert( nArg<=p->napArg );
102164 for(i=0; i<nArg; i++){
102165 assert( memIsValid(pX) );
102166 memAboutToChange(p, pX);
102167 apArg[i] = pX;
102168 pX++;
@@ -102952,16 +103004,12 @@
103004 }
103005 pBlob->pTab = pTab;
103006 pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName;
103007
103008 /* Now search pTab for the exact column. */
103009 iCol = sqlite3ColumnIndex(pTab, zColumn);
103010 if( iCol<0 ){
 
 
 
 
103011 sqlite3DbFree(db, zErr);
103012 zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
103013 rc = SQLITE_ERROR;
103014 sqlite3BtreeLeaveAll(db);
103015 goto blob_open_out;
@@ -104219,11 +104267,11 @@
104267 int pgsz; /* Page size of main database */
104268 int i; /* Used to iterate through aTask[] */
104269 VdbeSorter *pSorter; /* The new sorter */
104270 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
104271 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
104272 i64 sz; /* Size of pSorter in bytes */
104273 int rc = SQLITE_OK;
104274 #if SQLITE_MAX_WORKER_THREADS==0
104275 # define nWorker 0
104276 #else
104277 int nWorker;
@@ -104247,10 +104295,12 @@
104295 #endif
104296
104297 assert( pCsr->pKeyInfo );
104298 assert( !pCsr->isEphemeral );
104299 assert( pCsr->eCurType==CURTYPE_SORTER );
104300 assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
104301 < 0x7fffffff );
104302 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
104303 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
104304
104305 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
104306 pCsr->uc.pSorter = pSorter;
@@ -104460,11 +104510,11 @@
104510 ** nReader is automatically rounded up to the next power of two.
104511 ** nReader may not exceed SORTER_MAX_MERGE_COUNT even after rounding up.
104512 */
104513 static MergeEngine *vdbeMergeEngineNew(int nReader){
104514 int N = 2; /* Smallest power of two >= nReader */
104515 i64 nByte; /* Total bytes of space to allocate */
104516 MergeEngine *pNew; /* Pointer to allocated object to return */
104517
104518 assert( nReader<=SORTER_MAX_MERGE_COUNT );
104519
104520 while( N<nReader ) N += N;
@@ -107503,11 +107553,10 @@
107553 SrcItem *pMatch = 0; /* The matching pSrcList item */
107554 NameContext *pTopNC = pNC; /* First namecontext in the list */
107555 Schema *pSchema = 0; /* Schema of the expression */
107556 int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */
107557 Table *pTab = 0; /* Table holding the row */
 
107558 ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */
107559 const char *zCol = pRight->u.zToken;
107560
107561 assert( pNC ); /* the name context cannot be NULL. */
107562 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -107554,11 +107603,10 @@
107603 ExprList *pEList;
107604 SrcList *pSrcList = pNC->pSrcList;
107605
107606 if( pSrcList ){
107607 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
 
107608 pTab = pItem->pSTab;
107609 assert( pTab!=0 && pTab->zName!=0 );
107610 assert( pTab->nCol>0 || pParse->nErr );
107611 assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem));
107612 if( pItem->fg.isNestedFrom ){
@@ -107642,47 +107690,42 @@
107690 assert( ExprUseYTab(pExpr) );
107691 if( IN_RENAME_OBJECT && pItem->zAlias ){
107692 sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
107693 }
107694 }
107695 j = sqlite3ColumnIndex(pTab, zCol);
107696 if( j>=0 ){
107697 if( cnt>0 ){
107698 if( pItem->fg.isUsing==0
107699 || sqlite3IdListIndex(pItem->u3.pUsing, zCol)<0
107700 ){
107701 /* Two or more tables have the same column name which is
107702 ** not joined by USING. This is an error. Signal as much
107703 ** by clearing pFJMatch and letting cnt go above 1. */
107704 sqlite3ExprListDelete(db, pFJMatch);
107705 pFJMatch = 0;
107706 }else
107707 if( (pItem->fg.jointype & JT_RIGHT)==0 ){
107708 /* An INNER or LEFT JOIN. Use the left-most table */
107709 continue;
107710 }else
107711 if( (pItem->fg.jointype & JT_LEFT)==0 ){
107712 /* A RIGHT JOIN. Use the right-most table */
107713 cnt = 0;
107714 sqlite3ExprListDelete(db, pFJMatch);
107715 pFJMatch = 0;
107716 }else{
107717 /* For a FULL JOIN, we must construct a coalesce() func */
107718 extendFJMatch(pParse, &pFJMatch, pMatch, pExpr->iColumn);
107719 }
107720 }
107721 cnt++;
107722 pMatch = pItem;
107723 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
107724 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
107725 if( pItem->fg.isNestedFrom ){
107726 sqlite3SrcItemColumnUsed(pItem, j);
 
 
 
 
 
107727 }
107728 }
107729 if( 0==cnt && VisibleRowid(pTab) ){
107730 /* pTab is a potential ROWID match. Keep track of it and match
107731 ** the ROWID later if that seems appropriate. (Search for "cntTab"
@@ -107768,26 +107811,21 @@
107811 }
107812 #endif /* SQLITE_OMIT_UPSERT */
107813
107814 if( pTab ){
107815 int iCol;
 
107816 pSchema = pTab->pSchema;
107817 cntTab++;
107818 iCol = sqlite3ColumnIndex(pTab, zCol);
107819 if( iCol>=0 ){
107820 if( pTab->iPKey==iCol ) iCol = -1;
107821 }else{
107822 if( sqlite3IsRowid(zCol) && VisibleRowid(pTab) ){
107823 iCol = -1;
107824 }else{
107825 iCol = pTab->nCol;
107826 }
 
 
 
 
107827 }
107828 if( iCol<pTab->nCol ){
107829 cnt++;
107830 pMatch = 0;
107831 #ifndef SQLITE_OMIT_UPSERT
@@ -111379,11 +111417,10 @@
111417 pNewExpr->pLeft = pPriorSelectColNew;
111418 }
111419 }
111420 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
111421 pItem->fg = pOldItem->fg;
 
111422 pItem->u = pOldItem->u;
111423 }
111424 return pNew;
111425 }
111426
@@ -112496,17 +112533,11 @@
112533 SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab){
112534 const char *azOpt[] = {"_ROWID_", "ROWID", "OID"};
112535 int ii;
112536 assert( VisibleRowid(pTab) );
112537 for(ii=0; ii<ArraySize(azOpt); ii++){
112538 if( sqlite3ColumnIndex(pTab, azOpt[ii])<0 ) return azOpt[ii];
 
 
 
 
 
 
112539 }
112540 return 0;
112541 }
112542
112543 /*
@@ -112906,11 +112937,11 @@
112937 int nVal = sqlite3ExprVectorSize(pLeft);
112938 Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0;
112939 char *zRet;
112940
112941 assert( pExpr->op==TK_IN );
112942 zRet = sqlite3DbMallocRaw(pParse->db, 1+(i64)nVal);
112943 if( zRet ){
112944 int i;
112945 for(i=0; i<nVal; i++){
112946 Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i);
112947 char a = sqlite3ExprAffinity(pA);
@@ -117551,14 +117582,12 @@
117582
117583 /* Make sure the old name really is a column name in the table to be
117584 ** altered. Set iCol to be the index of the column being renamed */
117585 zOld = sqlite3NameFromToken(db, pOld);
117586 if( !zOld ) goto exit_rename_column;
117587 iCol = sqlite3ColumnIndex(pTab, zOld);
117588 if( iCol<0 ){
 
 
117589 sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld);
117590 goto exit_rename_column;
117591 }
117592
117593 /* Ensure the schema contains no double-quoted strings */
@@ -119453,11 +119482,12 @@
119482 ** of the new table in register pParse->regRoot. This is important
119483 ** because the OpenWrite opcode below will be needing it. */
119484 sqlite3NestedParse(pParse,
119485 "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols
119486 );
119487 assert( pParse->isCreate || pParse->nErr );
119488 aRoot[i] = (u32)pParse->u1.cr.regRoot;
119489 aCreateTbl[i] = OPFLAG_P2ISREG;
119490 }
119491 }else{
119492 /* The table already exists. If zWhere is not NULL, delete all entries
119493 ** associated with the table zWhere. If zWhere is NULL, delete the
@@ -119644,11 +119674,11 @@
119674 ){
119675 StatAccum *p;
119676 int nCol; /* Number of columns in index being sampled */
119677 int nKeyCol; /* Number of key columns */
119678 int nColUp; /* nCol rounded up for alignment */
119679 i64 n; /* Bytes of space to allocate */
119680 sqlite3 *db = sqlite3_context_db_handle(context); /* Database connection */
119681 #ifdef SQLITE_ENABLE_STAT4
119682 /* Maximum number of samples. 0 if STAT4 data is not collected */
119683 int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0;
119684 #endif
@@ -121418,11 +121448,11 @@
121448 if( db->aDb==db->aDbStatic ){
121449 aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 );
121450 if( aNew==0 ) return;
121451 memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
121452 }else{
121453 aNew = sqlite3DbRealloc(db, db->aDb, sizeof(db->aDb[0])*(1+(i64)db->nDb));
121454 if( aNew==0 ) return;
121455 }
121456 db->aDb = aNew;
121457 pNew = &db->aDb[db->nDb];
121458 memset(pNew, 0, sizeof(*pNew));
@@ -122211,10 +122241,11 @@
122241 p->isWriteLock = (p->isWriteLock || isWriteLock);
122242 return;
122243 }
122244 }
122245
122246 assert( pToplevel->nTableLock < 0x7fff0000 );
122247 nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
122248 pToplevel->aTableLock =
122249 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
122250 if( pToplevel->aTableLock ){
122251 p = &pToplevel->aTableLock[pToplevel->nTableLock++];
@@ -122311,14 +122342,16 @@
122342 }
122343 assert( !pParse->isMultiWrite
122344 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
122345 if( v ){
122346 if( pParse->bReturning ){
122347 Returning *pReturning;
122348 int addrRewind;
122349 int reg;
122350
122351 assert( !pParse->isCreate );
122352 pReturning = pParse->u1.d.pReturning;
122353 if( pReturning->nRetCol ){
122354 sqlite3VdbeAddOp0(v, OP_FkCheck);
122355 addrRewind =
122356 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
122357 VdbeCoverage(v);
@@ -122390,11 +122423,13 @@
122423 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
122424 }
122425 }
122426
122427 if( pParse->bReturning ){
122428 Returning *pRet;
122429 assert( !pParse->isCreate );
122430 pRet = pParse->u1.d.pReturning;
122431 if( pRet->nRetCol ){
122432 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
122433 }
122434 }
122435
@@ -123462,12 +123497,13 @@
123497 #endif
123498
123499 /* If the file format and encoding in the database have not been set,
123500 ** set them now.
123501 */
123502 assert( pParse->isCreate );
123503 reg1 = pParse->u1.cr.regRowid = ++pParse->nMem;
123504 reg2 = pParse->u1.cr.regRoot = ++pParse->nMem;
123505 reg3 = ++pParse->nMem;
123506 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
123507 sqlite3VdbeUsesBtree(v, iDb);
123508 addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
123509 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
@@ -123478,12 +123514,12 @@
123514
123515 /* This just creates a place-holder record in the sqlite_schema table.
123516 ** The record created does not contain anything yet. It will be replaced
123517 ** by the real entry in code generated at sqlite3EndTable().
123518 **
123519 ** The rowid for the new entry is left in register pParse->u1.cr.regRowid.
123520 ** The root page of the new table is left in reg pParse->u1.cr.regRoot.
123521 ** The rowid and root page number values are needed by the code that
123522 ** sqlite3EndTable will generate.
123523 */
123524 #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
123525 if( isView || isVirtual ){
@@ -123490,11 +123526,11 @@
123526 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
123527 }else
123528 #endif
123529 {
123530 assert( !pParse->bReturning );
123531 pParse->u1.cr.addrCrTab =
123532 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
123533 }
123534 sqlite3OpenSchemaTable(pParse, iDb);
123535 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
123536 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
@@ -123568,11 +123604,12 @@
123604 pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
123605 if( pRet==0 ){
123606 sqlite3ExprListDelete(db, pList);
123607 return;
123608 }
123609 assert( !pParse->isCreate );
123610 pParse->u1.d.pReturning = pRet;
123611 pRet->pParse = pParse;
123612 pRet->pReturnEL = pList;
123613 sqlite3ParserAddCleanup(pParse, sqlite3DeleteReturning, pRet);
123614 testcase( pParse->earlyCleanup );
123615 if( db->mallocFailed ) return;
@@ -123610,11 +123647,10 @@
123647 int i;
123648 char *z;
123649 char *zType;
123650 Column *pCol;
123651 sqlite3 *db = pParse->db;
 
123652 Column *aNew;
123653 u8 eType = COLTYPE_CUSTOM;
123654 u8 szEst = 1;
123655 char affinity = SQLITE_AFF_BLOB;
123656
@@ -123664,17 +123700,14 @@
123700 if( z==0 ) return;
123701 if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName);
123702 memcpy(z, sName.z, sName.n);
123703 z[sName.n] = 0;
123704 sqlite3Dequote(z);
123705 if( p->nCol && sqlite3ColumnIndex(p, z)>=0 ){
123706 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
123707 sqlite3DbFree(db, z);
123708 return;
 
 
 
123709 }
123710 aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0]));
123711 if( aNew==0 ){
123712 sqlite3DbFree(db, z);
123713 return;
@@ -123681,11 +123714,11 @@
123714 }
123715 p->aCol = aNew;
123716 pCol = &p->aCol[p->nCol];
123717 memset(pCol, 0, sizeof(p->aCol[0]));
123718 pCol->zCnName = z;
123719 pCol->hName = sqlite3StrIHash(z);
123720 sqlite3ColumnPropertiesFromName(p, pCol);
123721
123722 if( sType.n==0 ){
123723 /* If there is no type specified, columns have the default affinity
123724 ** 'BLOB' with a default size of 4 bytes. */
@@ -123705,13 +123738,18 @@
123738 zType[sType.n] = 0;
123739 sqlite3Dequote(zType);
123740 pCol->affinity = sqlite3AffinityType(zType, pCol);
123741 pCol->colFlags |= COLFLAG_HASTYPE;
123742 }
123743 if( p->nCol<=0xff ){
123744 u8 h = pCol->hName % sizeof(p->aHx);
123745 p->aHx[h] = p->nCol;
123746 }
123747 p->nCol++;
123748 p->nNVCol++;
123749 assert( pParse->isCreate );
123750 pParse->u1.cr.constraintName.n = 0;
123751 }
123752
123753 /*
123754 ** This routine is called by the parser while in the middle of
123755 ** parsing a CREATE TABLE statement. A "NOT NULL" constraint has
@@ -123971,19 +124009,15 @@
124009 for(i=0; i<nTerm; i++){
124010 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
124011 assert( pCExpr!=0 );
124012 sqlite3StringToId(pCExpr);
124013 if( pCExpr->op==TK_ID ){
 
124014 assert( !ExprHasProperty(pCExpr, EP_IntValue) );
124015 iCol = sqlite3ColumnIndex(pTab, pCExpr->u.zToken);
124016 if( iCol>=0 ){
124017 pCol = &pTab->aCol[iCol];
124018 makeColumnPartOfPrimaryKey(pParse, pCol);
 
 
 
124019 }
124020 }
124021 }
124022 }
124023 if( nTerm==1
@@ -124031,12 +124065,14 @@
124065 sqlite3 *db = pParse->db;
124066 if( pTab && !IN_DECLARE_VTAB
124067 && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt)
124068 ){
124069 pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr);
124070 assert( pParse->isCreate );
124071 if( pParse->u1.cr.constraintName.n ){
124072 sqlite3ExprListSetName(pParse, pTab->pCheck,
124073 &pParse->u1.cr.constraintName, 1);
124074 }else{
124075 Token t;
124076 for(zStart++; sqlite3Isspace(zStart[0]); zStart++){}
124077 while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; }
124078 t.z = zStart;
@@ -124227,11 +124263,12 @@
124263 ** Generate a CREATE TABLE statement appropriate for the given
124264 ** table. Memory to hold the text of the statement is obtained
124265 ** from sqliteMalloc() and must be freed by the calling function.
124266 */
124267 static char *createTableStmt(sqlite3 *db, Table *p){
124268 int i, k, len;
124269 i64 n;
124270 char *zStmt;
124271 char *zSep, *zSep2, *zEnd;
124272 Column *pCol;
124273 n = 0;
124274 for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){
@@ -124251,12 +124288,13 @@
124288 zStmt = sqlite3DbMallocRaw(0, n);
124289 if( zStmt==0 ){
124290 sqlite3OomFault(db);
124291 return 0;
124292 }
124293 assert( n>14 && n<=0x7fffffff );
124294 memcpy(zStmt, "CREATE TABLE ", 13);
124295 k = 13;
124296 identPut(zStmt, &k, p->zName);
124297 zStmt[k++] = '(';
124298 for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){
124299 static const char * const azType[] = {
124300 /* SQLITE_AFF_BLOB */ "",
@@ -124264,17 +124302,19 @@
124302 /* SQLITE_AFF_NUMERIC */ " NUM",
124303 /* SQLITE_AFF_INTEGER */ " INT",
124304 /* SQLITE_AFF_REAL */ " REAL",
124305 /* SQLITE_AFF_FLEXNUM */ " NUM",
124306 };
 
124307 const char *zType;
124308
124309 len = sqlite3Strlen30(zSep);
124310 assert( k+len<n );
124311 memcpy(&zStmt[k], zSep, len);
124312 k += len;
124313 zSep = zSep2;
124314 identPut(zStmt, &k, pCol->zCnName);
124315 assert( k<n );
124316 assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 );
124317 assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) );
124318 testcase( pCol->affinity==SQLITE_AFF_BLOB );
124319 testcase( pCol->affinity==SQLITE_AFF_TEXT );
124320 testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
@@ -124285,15 +124325,18 @@
124325 zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
124326 len = sqlite3Strlen30(zType);
124327 assert( pCol->affinity==SQLITE_AFF_BLOB
124328 || pCol->affinity==SQLITE_AFF_FLEXNUM
124329 || pCol->affinity==sqlite3AffinityType(zType, 0) );
124330 assert( k+len<n );
124331 memcpy(&zStmt[k], zType, len);
124332 k += len;
124333 assert( k<=n );
124334 }
124335 len = sqlite3Strlen30(zEnd);
124336 assert( k+len<n );
124337 memcpy(&zStmt[k], zEnd, len+1);
124338 return zStmt;
124339 }
124340
124341 /*
124342 ** Resize an Index object to hold N columns total. Return SQLITE_OK
@@ -124482,13 +124525,13 @@
124525
124526 /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
124527 ** into BTREE_BLOBKEY.
124528 */
124529 assert( !pParse->bReturning );
124530 if( pParse->u1.cr.addrCrTab ){
124531 assert( v );
124532 sqlite3VdbeChangeP3(v, pParse->u1.cr.addrCrTab, BTREE_BLOBKEY);
124533 }
124534
124535 /* Locate the PRIMARY KEY index. Or, if this table was originally
124536 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
124537 */
@@ -124924,11 +124967,11 @@
124967 #endif
124968 }
124969
124970 /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
124971 ** statement to populate the new table. The root-page number for the
124972 ** new table is in register pParse->u1.cr.regRoot.
124973 **
124974 ** Once the SELECT has been coded by sqlite3Select(), it is in a
124975 ** suitable state to query for the column names and types to be used
124976 ** by the new table.
124977 **
@@ -124955,11 +124998,12 @@
124998 iCsr = pParse->nTab++;
124999 regYield = ++pParse->nMem;
125000 regRec = ++pParse->nMem;
125001 regRowid = ++pParse->nMem;
125002 sqlite3MayAbort(pParse);
125003 assert( pParse->isCreate );
125004 sqlite3VdbeAddOp3(v, OP_OpenWrite, iCsr, pParse->u1.cr.regRoot, iDb);
125005 sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG);
125006 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
125007 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
125008 if( pParse->nErr ) return;
125009 pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB);
@@ -125000,21 +125044,22 @@
125044
125045 /* A slot for the record has already been allocated in the
125046 ** schema table. We just need to update that slot with all
125047 ** the information we've collected.
125048 */
125049 assert( pParse->isCreate );
125050 sqlite3NestedParse(pParse,
125051 "UPDATE %Q." LEGACY_SCHEMA_TABLE
125052 " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
125053 " WHERE rowid=#%d",
125054 db->aDb[iDb].zDbSName,
125055 zType,
125056 p->zName,
125057 p->zName,
125058 pParse->u1.cr.regRoot,
125059 zStmt,
125060 pParse->u1.cr.regRowid
125061 );
125062 sqlite3DbFree(db, zStmt);
125063 sqlite3ChangeCookie(pParse, iDb);
125064
125065 #ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -125981,11 +126026,11 @@
126026 i16 nCol, /* Total number of columns in the index */
126027 int nExtra, /* Number of bytes of extra space to alloc */
126028 char **ppExtra /* Pointer to the "extra" space */
126029 ){
126030 Index *p; /* Allocated index object */
126031 i64 nByte; /* Bytes of space for Index object + arrays */
126032
126033 nByte = ROUND8(sizeof(Index)) + /* Index structure */
126034 ROUND8(sizeof(char*)*nCol) + /* Index.azColl */
126035 ROUND8(sizeof(LogEst)*(nCol+1) + /* Index.aiRowLogEst */
126036 sizeof(i16)*nCol + /* Index.aiColumn */
@@ -129850,15 +129895,10 @@
129895 int len;
129896 int p0type;
129897 i64 p1, p2;
129898
129899 assert( argc==3 || argc==2 );
 
 
 
 
 
129900 p0type = sqlite3_value_type(argv[0]);
129901 p1 = sqlite3_value_int64(argv[1]);
129902 if( p0type==SQLITE_BLOB ){
129903 len = sqlite3_value_bytes(argv[0]);
129904 z = sqlite3_value_blob(argv[0]);
@@ -129872,23 +129912,27 @@
129912 for(z2=z; *z2; len++){
129913 SQLITE_SKIP_UTF8(z2);
129914 }
129915 }
129916 }
 
 
 
 
 
 
 
 
129917 if( argc==3 ){
129918 p2 = sqlite3_value_int64(argv[2]);
129919 if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return;
129920 }else{
129921 p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
129922 }
129923 if( p1==0 ){
129924 #ifdef SQLITE_SUBSTR_COMPATIBILITY
129925 /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
129926 ** as substr(X,1,N) - it returns the first N characters of X. This
129927 ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
129928 ** from 2009-02-02 for compatibility of applications that exploited the
129929 ** old buggy behavior. */
129930 p1 = 1; /* <rdar://problem/6778339> */
129931 #endif
129932 if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
129933 }
129934 if( p1<0 ){
129935 p1 += len;
129936 if( p1<0 ){
129937 if( p2<0 ){
129938 p2 = 0;
@@ -130915,11 +130959,11 @@
130959 if( zRep==0 ) return;
130960 nRep = sqlite3_value_bytes(argv[2]);
130961 assert( zRep==sqlite3_value_text(argv[2]) );
130962 nOut = nStr + 1;
130963 assert( nOut<SQLITE_MAX_LENGTH );
130964 zOut = contextMalloc(context, nOut);
130965 if( zOut==0 ){
130966 return;
130967 }
130968 loopLimit = nStr - nPattern;
130969 cntExpand = 0;
@@ -131065,11 +131109,11 @@
131109 int i;
131110 char *z;
131111 for(i=0; i<argc; i++){
131112 n += sqlite3_value_bytes(argv[i]);
131113 }
131114 n += (argc-1)*(i64)nSep;
131115 z = sqlite3_malloc64(n+1);
131116 if( z==0 ){
131117 sqlite3_result_error_nomem(context);
131118 return;
131119 }
@@ -134900,32 +134944,26 @@
134944 bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0;
134945 if( pColumn ){
134946 aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int));
134947 if( aTabColMap==0 ) goto insert_cleanup;
134948 for(i=0; i<pColumn->nId; i++){
134949 j = sqlite3ColumnIndex(pTab, pColumn->a[i].zName);
134950 if( j>=0 ){
134951 if( aTabColMap[j]==0 ) aTabColMap[j] = i+1;
134952 if( i!=j ) bIdListInOrder = 0;
134953 if( j==pTab->iPKey ){
134954 ipkColumn = i; assert( !withoutRowid );
134955 }
 
 
 
134956 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
134957 if( pTab->aCol[j].colFlags & (COLFLAG_STORED|COLFLAG_VIRTUAL) ){
134958 sqlite3ErrorMsg(pParse,
134959 "cannot INSERT into generated column \"%s\"",
134960 pTab->aCol[j].zCnName);
134961 goto insert_cleanup;
134962 }
134963 #endif
134964 }else{
 
 
 
134965 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
134966 ipkColumn = i;
134967 bIdListInOrder = 0;
134968 }else{
134969 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
@@ -135219,11 +135257,11 @@
135257 sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
135258 }
135259 continue;
135260 }else if( pColumn==0 ){
135261 /* Hidden columns that are not explicitly named in the INSERT
135262 ** get their default value */
135263 sqlite3ExprCodeFactorable(pParse,
135264 sqlite3ColumnExpr(pTab, &pTab->aCol[i]),
135265 iRegStore);
135266 continue;
135267 }
@@ -140832,11 +140870,14 @@
140870 ){
140871 db->flags |= mask;
140872 }
140873 }else{
140874 db->flags &= ~mask;
140875 if( mask==SQLITE_DeferFKs ){
140876 db->nDeferredImmCons = 0;
140877 db->nDeferredCons = 0;
140878 }
140879 if( (mask & SQLITE_WriteSchema)!=0
140880 && sqlite3_stricmp(zRight, "reset")==0
140881 ){
140882 /* IMP: R-60817-01178 If the argument is "RESET" then schema
140883 ** writing is disabled (as with "PRAGMA writable_schema=OFF") and,
@@ -144166,14 +144207,37 @@
144207 ** Return the index of a column in a table. Return -1 if the column
144208 ** is not contained in the table.
144209 */
144210 SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){
144211 int i;
144212 u8 h;
144213 const Column *aCol;
144214 int nCol;
144215
144216 h = sqlite3StrIHash(zCol);
144217 aCol = pTab->aCol;
144218 nCol = pTab->nCol;
144219
144220 /* See if the aHx gives us a lucky match */
144221 i = pTab->aHx[h % sizeof(pTab->aHx)];
144222 assert( i<nCol );
144223 if( aCol[i].hName==h
144224 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144225 ){
144226 return i;
144227 }
144228
144229 /* No lucky match from the hash table. Do a full search. */
144230 i = 0;
144231 while( 1 /*exit-by-break*/ ){
144232 if( aCol[i].hName==h
144233 && sqlite3StrICmp(aCol[i].zCnName, zCol)==0
144234 ){
144235 return i;
144236 }
144237 i++;
144238 if( i>=nCol ) break;
144239 }
144240 return -1;
144241 }
144242
144243 /*
@@ -152891,11 +152955,12 @@
152955 }else if( pTrig->op==TK_RETURNING ){
152956 #ifndef SQLITE_OMIT_VIRTUALTABLE
152957 assert( pParse->db->pVtabCtx==0 );
152958 #endif
152959 assert( pParse->bReturning );
152960 assert( !pParse->isCreate );
152961 assert( &(pParse->u1.d.pReturning->retTrig) == pTrig );
152962 pTrig->table = pTab->zName;
152963 pTrig->pTabSchema = pTab->pSchema;
152964 pTrig->pNext = pList;
152965 pList = pTrig;
152966 }
@@ -153868,11 +153933,12 @@
153933 /* This RETURNING trigger must be for a different statement as
153934 ** this statement lacks a RETURNING clause. */
153935 return;
153936 }
153937 assert( db->pParse==pParse );
153938 assert( !pParse->isCreate );
153939 pReturning = pParse->u1.d.pReturning;
153940 if( pTrigger != &(pReturning->retTrig) ){
153941 /* This RETURNING trigger is for a different statement */
153942 return;
153943 }
153944 memset(&sSelect, 0, sizeof(sSelect));
@@ -154098,10 +154164,12 @@
154164 sSubParse.pToplevel = pTop;
154165 sSubParse.zAuthContext = pTrigger->zName;
154166 sSubParse.eTriggerOp = pTrigger->op;
154167 sSubParse.nQueryLoop = pParse->nQueryLoop;
154168 sSubParse.prepFlags = pParse->prepFlags;
154169 sSubParse.oldmask = 0;
154170 sSubParse.newmask = 0;
154171
154172 v = sqlite3GetVdbe(&sSubParse);
154173 if( v ){
154174 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
154175 pTrigger->zName, onErrorText(orconf),
@@ -154852,42 +154920,36 @@
154920 ** column to be updated, make sure we have authorization to change
154921 ** that column.
154922 */
154923 chngRowid = chngPk = 0;
154924 for(i=0; i<pChanges->nExpr; i++){
 
154925 /* If this is an UPDATE with a FROM clause, do not resolve expressions
154926 ** here. The call to sqlite3Select() below will do that. */
154927 if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){
154928 goto update_cleanup;
154929 }
154930 j = sqlite3ColumnIndex(pTab, pChanges->a[i].zEName);
154931 if( j>=0 ){
154932 if( j==pTab->iPKey ){
154933 chngRowid = 1;
154934 pRowidExpr = pChanges->a[i].pExpr;
154935 iRowidExpr = i;
154936 }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){
154937 chngPk = 1;
154938 }
 
 
154939 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
154940 else if( pTab->aCol[j].colFlags & COLFLAG_GENERATED ){
154941 testcase( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL );
154942 testcase( pTab->aCol[j].colFlags & COLFLAG_STORED );
154943 sqlite3ErrorMsg(pParse,
154944 "cannot UPDATE generated column \"%s\"",
154945 pTab->aCol[j].zCnName);
154946 goto update_cleanup;
154947 }
154948 #endif
154949 aXRef[j] = i;
154950 }else{
 
 
 
154951 if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){
154952 j = -1;
154953 chngRowid = 1;
154954 pRowidExpr = pChanges->a[i].pExpr;
154955 iRowidExpr = i;
@@ -156990,24 +157052,25 @@
157052
157053 /* A slot for the record has already been allocated in the
157054 ** schema table. We just need to update that slot with all
157055 ** the information we've collected.
157056 **
157057 ** The VM register number pParse->u1.cr.regRowid holds the rowid of an
157058 ** entry in the sqlite_schema table that was created for this vtab
157059 ** by sqlite3StartTable().
157060 */
157061 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
157062 assert( pParse->isCreate );
157063 sqlite3NestedParse(pParse,
157064 "UPDATE %Q." LEGACY_SCHEMA_TABLE " "
157065 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
157066 "WHERE rowid=#%d",
157067 db->aDb[iDb].zDbSName,
157068 pTab->zName,
157069 pTab->zName,
157070 zStmt,
157071 pParse->u1.cr.regRowid
157072 );
157073 v = sqlite3GetVdbe(pParse);
157074 sqlite3ChangeCookie(pParse, iDb);
157075
157076 sqlite3VdbeAddOp0(v, OP_Expire);
@@ -160161,10 +160224,13 @@
160224 }
160225 }
160226 }
160227 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
160228 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
160229 /* The instruction immediately prior to OP_VFilter must be an OP_Integer
160230 ** that sets the "argc" value for xVFilter. This is necessary for
160231 ** resolveP2() to work correctly. See tag-20250207a. */
160232 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
160233 pLoop->u.vtab.idxStr,
160234 pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC);
160235 VdbeCoverage(v);
160236 pLoop->u.vtab.needFree = 0;
@@ -174215,10 +174281,15 @@
174281 ** to the original parse.y sources.
174282 */
174283
174284 /* #include "sqliteInt.h" */
174285
174286 /*
174287 ** Verify that the pParse->isCreate field is set
174288 */
174289 #define ASSERT_IS_CREATE assert(pParse->isCreate)
174290
174291 /*
174292 ** Disable all error recovery processing in the parser push-down
174293 ** automaton.
174294 */
174295 #define YYNOERRORRECOVERY 1
@@ -174278,10 +174349,14 @@
174349 ** shared across database connections.
174350 */
174351 static void disableLookaside(Parse *pParse){
174352 sqlite3 *db = pParse->db;
174353 pParse->disableLookaside++;
174354 #ifdef SQLITE_DEBUG
174355 pParse->isCreate = 1;
174356 #endif
174357 memset(&pParse->u1.cr, 0, sizeof(pParse->u1.cr));
174358 DisableLookaside;
174359 }
174360
174361 #if !defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) \
174362 && defined(SQLITE_UDL_CAPABLE_PARSER)
@@ -177914,11 +177989,13 @@
177989 {
177990 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[-2].minor.yy502);
177991 }
177992 break;
177993 case 14: /* createkw ::= CREATE */
177994 {
177995 disableLookaside(pParse);
177996 }
177997 break;
177998 case 15: /* ifnotexists ::= */
177999 case 18: /* temp ::= */ yytestcase(yyruleno==18);
178000 case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
178001 case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
@@ -178006,11 +178083,11 @@
178083 yymsp[1].minor.yy0 = yyLookaheadToken;
178084 }
178085 break;
178086 case 32: /* ccons ::= CONSTRAINT nm */
178087 case 67: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==67);
178088 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName = yymsp[0].minor.yy0;}
178089 break;
178090 case 33: /* ccons ::= DEFAULT scantok term */
178091 {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);}
178092 break;
178093 case 34: /* ccons ::= DEFAULT LP expr RP */
@@ -178116,11 +178193,11 @@
178193 break;
178194 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
178195 {yymsp[-1].minor.yy502 = 0;}
178196 break;
178197 case 66: /* tconscomma ::= COMMA */
178198 {ASSERT_IS_CREATE; pParse->u1.cr.constraintName.n = 0;}
178199 break;
178200 case 68: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
178201 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);}
178202 break;
178203 case 69: /* tcons ::= UNIQUE LP sortlist RP onconf */
@@ -179009,10 +179086,14 @@
179086 break;
179087 case 261: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
179088 {
179089 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);
179090 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
179091 #ifdef SQLITE_DEBUG
179092 assert( pParse->isCreate ); /* Set by createkw reduce action */
179093 pParse->isCreate = 0; /* But, should not be set for CREATE TRIGGER */
179094 #endif
179095 }
179096 break;
179097 case 262: /* trigger_time ::= BEFORE|AFTER */
179098 { yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ }
179099 break;
@@ -182295,21 +182376,26 @@
182376 ** Set up the lookaside buffers for a database connection.
182377 ** Return SQLITE_OK on success.
182378 ** If lookaside is already active, return SQLITE_BUSY.
182379 **
182380 ** The sz parameter is the number of bytes in each lookaside slot.
182381 ** The cnt parameter is the number of slots. If pBuf is NULL the
182382 ** space for the lookaside memory is obtained from sqlite3_malloc()
182383 ** or similar. If pBuf is not NULL then it is sz*cnt bytes of memory
182384 ** to use for the lookaside memory.
182385 */
182386 static int setupLookaside(
182387 sqlite3 *db, /* Database connection being configured */
182388 void *pBuf, /* Memory to use for lookaside. May be NULL */
182389 int sz, /* Desired size of each lookaside memory slot */
182390 int cnt /* Number of slots to allocate */
182391 ){
182392 #ifndef SQLITE_OMIT_LOOKASIDE
182393 void *pStart; /* Start of the lookaside buffer */
182394 sqlite3_int64 szAlloc; /* Total space set aside for lookaside memory */
182395 int nBig; /* Number of full-size slots */
182396 int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */
182397
182398 if( sqlite3LookasideUsed(db,0)>0 ){
182399 return SQLITE_BUSY;
182400 }
182401 /* Free any existing lookaside buffer for this handle before
@@ -182318,33 +182404,38 @@
182404 */
182405 if( db->lookaside.bMalloced ){
182406 sqlite3_free(db->lookaside.pStart);
182407 }
182408 /* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
182409 ** than a pointer and small enough to fit in a u16.
182410 */
182411 sz = ROUNDDOWN8(sz);
182412 if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
182413 if( sz>65528 ) sz = 65528;
182414 /* Count must be at least 1 to be useful, but not so large as to use
182415 ** more than 0x7fff0000 total bytes for lookaside. */
182416 if( cnt<1 ) cnt = 0;
182417 if( sz>0 && cnt>(0x7fff0000/sz) ) cnt = 0x7fff0000/sz;
182418 szAlloc = (i64)sz*(i64)cnt;
182419 if( szAlloc==0 ){
182420 sz = 0;
182421 pStart = 0;
182422 }else if( pBuf==0 ){
182423 sqlite3BeginBenignMalloc();
182424 pStart = sqlite3Malloc( szAlloc );
182425 sqlite3EndBenignMalloc();
182426 if( pStart ) szAlloc = sqlite3MallocSize(pStart);
182427 }else{
182428 pStart = pBuf;
182429 }
182430 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
182431 if( sz>=LOOKASIDE_SMALL*3 ){
182432 nBig = szAlloc/(3*LOOKASIDE_SMALL+sz);
182433 nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL;
182434 }else if( sz>=LOOKASIDE_SMALL*2 ){
182435 nBig = szAlloc/(LOOKASIDE_SMALL+sz);
182436 nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL;
182437 }else
182438 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
182439 if( sz>0 ){
182440 nBig = szAlloc/sz;
182441 nSm = 0;
@@ -185479,17 +185570,14 @@
185570
185571 /* Find the column for which info is requested */
185572 if( zColumnName==0 ){
185573 /* Query for existence of table only */
185574 }else{
185575 iCol = sqlite3ColumnIndex(pTab, zColumnName);
185576 if( iCol>=0 ){
185577 pCol = &pTab->aCol[iCol];
185578 }else{
 
 
 
 
185579 if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
185580 iCol = pTab->iPKey;
185581 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
185582 }else{
185583 pTab = 0;
@@ -192338,11 +192426,11 @@
192426 p1 = pPhrase->doclist.pList;
192427 p2 = aPoslist;
192428 nDistance = iPrev - nMaxUndeferred;
192429 }
192430
192431 aOut = (char *)sqlite3Fts3MallocZero(((i64)nPoslist)+FTS3_BUFFER_PADDING);
192432 if( !aOut ){
192433 sqlite3_free(aPoslist);
192434 return SQLITE_NOMEM;
192435 }
192436
@@ -194958,11 +195046,11 @@
195046 sqlite3_tokenizer_module const *pModule = pTokenizer->pModule;
195047 int rc;
195048 Fts3Expr *p = 0;
195049 sqlite3_tokenizer_cursor *pCursor = 0;
195050 char *zTemp = 0;
195051 i64 nTemp = 0;
195052
195053 const int nSpace = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
195054 int nToken = 0;
195055
195056 /* The final Fts3Expr data structure, including the Fts3Phrase,
@@ -207729,22 +207817,23 @@
207817 **
207818 ** Return the number of errors.
207819 */
207820 static int jsonBlobExpand(JsonParse *pParse, u32 N){
207821 u8 *aNew;
207822 u64 t;
207823 assert( N>pParse->nBlobAlloc );
207824 if( pParse->nBlobAlloc==0 ){
207825 t = 100;
207826 }else{
207827 t = pParse->nBlobAlloc*2;
207828 }
207829 if( t<N ) t = N+100;
207830 aNew = sqlite3DbRealloc(pParse->db, pParse->aBlob, t);
207831 if( aNew==0 ){ pParse->oom = 1; return 1; }
207832 assert( t<0x7fffffff );
207833 pParse->aBlob = aNew;
207834 pParse->nBlobAlloc = (u32)t;
207835 return 0;
207836 }
207837
207838 /*
207839 ** If pParse->aBlob is not previously editable (because it is taken
@@ -208697,14 +208786,11 @@
208786 */
208787 static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){
208788 u8 x;
208789 u32 sz;
208790 u32 n;
208791 assert( i<=pParse->nBlob );
 
 
 
208792 x = pParse->aBlob[i]>>4;
208793 if( x<=11 ){
208794 sz = x;
208795 n = 1;
208796 }else if( x==12 ){
@@ -208744,12 +208830,12 @@
208830 n = 9;
208831 }
208832 if( (i64)i+sz+n > pParse->nBlob
208833 && (i64)i+sz+n > pParse->nBlob-pParse->delta
208834 ){
208835 *pSz = 0;
208836 return 0;
208837 }
208838 *pSz = sz;
208839 return n;
208840 }
208841
@@ -208842,13 +208928,16 @@
208928 }
208929 break;
208930 }
208931 case JSONB_TEXT:
208932 case JSONB_TEXTJ: {
208933 if( pOut->nUsed+sz+2<=pOut->nAlloc || jsonStringGrow(pOut, sz+2)==0 ){
208934 pOut->zBuf[pOut->nUsed] = '"';
208935 memcpy(pOut->zBuf+pOut->nUsed+1,(const char*)&pParse->aBlob[i+n],sz);
208936 pOut->zBuf[pOut->nUsed+sz+1] = '"';
208937 pOut->nUsed += sz+2;
208938 }
208939 break;
208940 }
208941 case JSONB_TEXT5: {
208942 const char *zIn;
208943 u32 k;
@@ -209759,11 +209848,11 @@
209848 u32 iIn, iOut;
209849 const char *z;
209850 char *zOut;
209851 u32 nOut = sz;
209852 z = (const char*)&pParse->aBlob[i+n];
209853 zOut = sqlite3DbMallocRaw(db, ((u64)nOut)+1);
209854 if( zOut==0 ) goto returnfromblob_oom;
209855 for(iIn=iOut=0; iIn<sz; iIn++){
209856 char c = z[iIn];
209857 if( c=='\\' ){
209858 u32 v;
@@ -248043,11 +248132,11 @@
248132 int iIdx = 0;
248133 int iStart = 0;
248134 int iDelKeyOff = 0; /* Offset of deleted key, if any */
248135
248136 nIdx = nPg-iPgIdx;
248137 aIdx = sqlite3Fts5MallocZero(&p->rc, ((i64)nIdx)+16);
248138 if( p->rc ) return;
248139 memcpy(aIdx, &aPg[iPgIdx], nIdx);
248140
248141 /* At this point segment iterator pSeg points to the entry
248142 ** this function should remove from the b-tree segment.
@@ -248637,11 +248726,11 @@
248726 return pStruct;
248727 }
248728 assert( pStruct->aLevel[i].nMerge<=nThis );
248729 }
248730
248731 nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel);
248732 pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte);
248733
248734 if( pNew ){
248735 Fts5StructureLevel *pLvl;
248736 nByte = nSeg * sizeof(Fts5StructureSegment);
@@ -249525,11 +249614,12 @@
249614 for(iFree=i; iFree<i+s.nMerge; iFree++){
249615 fts5BufferFree(&s.aBuf[iFree]);
249616 }
249617 }
249618
249619 pData = fts5IdxMalloc(p, sizeof(*pData)
249620 + ((i64)s.doclist.n)+FTS5_DATA_ZERO_PADDING);
249621 assert( pData!=0 || p->rc!=SQLITE_OK );
249622 if( pData ){
249623 pData->p = (u8*)&pData[1];
249624 pData->nn = pData->szLeaf = s.doclist.n;
249625 if( s.doclist.n ) memcpy(pData->p, s.doclist.p, s.doclist.n);
@@ -251749,11 +251839,11 @@
251839 /* Make a copy of the second argument (a blob) in aBlob[]. The aBlob[]
251840 ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
251841 ** buffer overreads even if the record is corrupt. */
251842 n = sqlite3_value_bytes(apVal[1]);
251843 aBlob = sqlite3_value_blob(apVal[1]);
251844 nSpace = ((i64)n) + FTS5_DATA_ZERO_PADDING;
251845 a = (u8*)sqlite3Fts5MallocZero(&rc, nSpace);
251846 if( a==0 ) goto decode_out;
251847 if( n>0 ) memcpy(a, aBlob, n);
251848
251849 fts5DecodeRowid(iRowid, &bTomb, &iSegid, &bDlidx, &iHeight, &iPgno);
@@ -255870,11 +255960,11 @@
255960 int nArg, /* Number of args */
255961 sqlite3_value **apUnused /* Function arguments */
255962 ){
255963 assert( nArg==0 );
255964 UNUSED_PARAM2(nArg, apUnused);
255965 sqlite3_result_text(pCtx, "fts5: 2025-02-18 01:16:26 57caa3136d1bfca06e4f2285734a4977b8d3fa1f75bf87453b975867e9de38fc", -1, SQLITE_TRANSIENT);
255966 }
255967
255968 /*
255969 ** Implementation of fts5_locale(LOCALE, TEXT) function.
255970 **
@@ -260475,16 +260565,16 @@
260565
260566 if( argc!=5 && bDb==0 ){
260567 *pzErr = sqlite3_mprintf("wrong number of vtable arguments");
260568 rc = SQLITE_ERROR;
260569 }else{
260570 i64 nByte; /* Bytes of space to allocate */
260571 const char *zDb = bDb ? argv[3] : argv[1];
260572 const char *zTab = bDb ? argv[4] : argv[3];
260573 const char *zType = bDb ? argv[5] : argv[4];
260574 i64 nDb = strlen(zDb)+1;
260575 i64 nTab = strlen(zTab)+1;
260576 int eType = 0;
260577
260578 rc = fts5VocabTableType(zType, pzErr, &eType);
260579 if( rc==SQLITE_OK ){
260580 assert( eType>=0 && eType<ArraySize(azSchema) );
260581
+45 -36
--- 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-18 01:16:26 57caa3136d1bfca06e4f2285734a4977b8d3fa1f75bf87453b975867e9de38fc"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -1987,17 +1987,20 @@
19871987
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
19881988
** return [SQLITE_ERROR].</dd>
19891989
**
19901990
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
19911991
** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1992
-** the default size of lookaside memory on each [database connection].
1992
+** the default size of [lookaside memory] on each [database connection].
19931993
** The first argument is the
1994
-** size of each lookaside buffer slot and the second is the number of
1995
-** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1996
-** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1997
-** option to [sqlite3_db_config()] can be used to change the lookaside
1998
-** configuration on individual connections.)^ </dd>
1994
+** size of each lookaside buffer slot ("sz") and the second is the number of
1995
+** slots allocated to each database connection ("cnt").)^
1996
+** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.
1997
+** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can
1998
+** be used to change the lookaside configuration on individual connections.)^
1999
+** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the
2000
+** default lookaside configuration at compile-time.
2001
+** </dd>
19992002
**
20002003
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
20012004
** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
20022005
** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
20032006
** the interface to a custom page cache implementation.)^
@@ -2230,35 +2233,54 @@
22302233
**
22312234
** <dl>
22322235
** [[SQLITE_DBCONFIG_LOOKASIDE]]
22332236
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
22342237
** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2235
-** configuration of the lookaside memory allocator within a database
2238
+** configuration of the [lookaside memory allocator] within a database
22362239
** connection.
22372240
** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
22382241
** in the [DBCONFIG arguments|usual format].
22392242
** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
22402243
** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
22412244
** should have a total of five parameters.
2242
-** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2245
+** <ol>
2246
+** <li><p>The first argument ("buf") is a
22432247
** pointer to a memory buffer to use for lookaside memory.
2244
-** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2245
-** may be NULL in which case SQLite will allocate the
2246
-** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2247
-** size of each lookaside buffer slot. ^The third argument is the number of
2248
-** slots. The size of the buffer in the first argument must be greater than
2249
-** or equal to the product of the second and third arguments. The buffer
2250
-** must be aligned to an 8-byte boundary. ^If the second argument to
2251
-** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2252
-** rounded down to the next smaller multiple of 8. ^(The lookaside memory
2248
+** The first argument may be NULL in which case SQLite will allocate the
2249
+** lookaside buffer itself using [sqlite3_malloc()].
2250
+** <li><P>The second argument ("sz") is the
2251
+** size of each lookaside buffer slot. Lookaside is disabled if "sz"
2252
+** is less than 8. The "sz" argument should be a multiple of 8 less than
2253
+** 65536. If "sz" does not meet this constraint, it is reduced in size until
2254
+** it does.
2255
+** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled
2256
+** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so
2257
+** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt"
2258
+** parameter is usually chosen so that the product of "sz" and "cnt" is less
2259
+** than 1,000,000.
2260
+** </ol>
2261
+** <p>If the "buf" argument is not NULL, then it must
2262
+** point to a memory buffer with a size that is greater than
2263
+** or equal to the product of "sz" and "cnt".
2264
+** The buffer must be aligned to an 8-byte boundary.
2265
+** The lookaside memory
22532266
** configuration for a database connection can only be changed when that
22542267
** connection is not currently using lookaside memory, or in other words
2255
-** when the "current value" returned by
2256
-** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2268
+** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.
22572269
** Any attempt to change the lookaside memory configuration when lookaside
22582270
** memory is in use leaves the configuration unchanged and returns
2259
-** [SQLITE_BUSY].)^</dd>
2271
+** [SQLITE_BUSY].
2272
+** If the "buf" argument is NULL and an attempt
2273
+** to allocate memory based on "sz" and "cnt" fails, then
2274
+** lookaside is silently disabled.
2275
+** <p>
2276
+** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the
2277
+** default lookaside configuration at initialization. The
2278
+** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside
2279
+** configuration at compile-time. Typical values for lookaside are 1200 for
2280
+** "sz" and 40 to 100 for "cnt".
2281
+** </dd>
22602282
**
22612283
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
22622284
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
22632285
** <dd> ^This option is used to enable or disable the enforcement of
22642286
** [foreign key constraints]. This is the same setting that is
@@ -12008,23 +12030,10 @@
1200812030
int nB, /* Number of bytes in buffer pB */
1200912031
void *pB, /* Pointer to buffer containing changeset B */
1201012032
int *pnOut, /* OUT: Number of bytes in output changeset */
1201112033
void **ppOut /* OUT: Buffer containing output changeset */
1201212034
);
12013
-
12014
-
12015
-/*
12016
-** CAPI3REF: Upgrade the Schema of a Changeset/Patchset
12017
-*/
12018
-SQLITE_API int sqlite3changeset_upgrade(
12019
- sqlite3 *db,
12020
- const char *zDb,
12021
- int nIn, const void *pIn, /* Input changeset */
12022
- int *pnOut, void **ppOut /* OUT: Inverse of input */
12023
-);
12024
-
12025
-
1202612035
1202712036
/*
1202812037
** CAPI3REF: Changegroup Handle
1202912038
**
1203012039
** A changegroup is an object used to combine two or more
1203112040
--- 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 **
@@ -1987,17 +1987,20 @@
1987 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1988 ** return [SQLITE_ERROR].</dd>
1989 **
1990 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1991 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1992 ** the default size of lookaside memory on each [database connection].
1993 ** The first argument is the
1994 ** size of each lookaside buffer slot and the second is the number of
1995 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1996 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1997 ** option to [sqlite3_db_config()] can be used to change the lookaside
1998 ** configuration on individual connections.)^ </dd>
 
 
 
1999 **
2000 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
2001 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
2002 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
2003 ** the interface to a custom page cache implementation.)^
@@ -2230,35 +2233,54 @@
2230 **
2231 ** <dl>
2232 ** [[SQLITE_DBCONFIG_LOOKASIDE]]
2233 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2234 ** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2235 ** configuration of the lookaside memory allocator within a database
2236 ** connection.
2237 ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2238 ** in the [DBCONFIG arguments|usual format].
2239 ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2240 ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2241 ** should have a total of five parameters.
2242 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
 
2243 ** pointer to a memory buffer to use for lookaside memory.
2244 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2245 ** may be NULL in which case SQLite will allocate the
2246 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2247 ** size of each lookaside buffer slot. ^The third argument is the number of
2248 ** slots. The size of the buffer in the first argument must be greater than
2249 ** or equal to the product of the second and third arguments. The buffer
2250 ** must be aligned to an 8-byte boundary. ^If the second argument to
2251 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2252 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
 
 
 
 
 
 
 
 
 
2253 ** configuration for a database connection can only be changed when that
2254 ** connection is not currently using lookaside memory, or in other words
2255 ** when the "current value" returned by
2256 ** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2257 ** Any attempt to change the lookaside memory configuration when lookaside
2258 ** memory is in use leaves the configuration unchanged and returns
2259 ** [SQLITE_BUSY].)^</dd>
 
 
 
 
 
 
 
 
 
 
2260 **
2261 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2262 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2263 ** <dd> ^This option is used to enable or disable the enforcement of
2264 ** [foreign key constraints]. This is the same setting that is
@@ -12008,23 +12030,10 @@
12008 int nB, /* Number of bytes in buffer pB */
12009 void *pB, /* Pointer to buffer containing changeset B */
12010 int *pnOut, /* OUT: Number of bytes in output changeset */
12011 void **ppOut /* OUT: Buffer containing output changeset */
12012 );
12013
12014
12015 /*
12016 ** CAPI3REF: Upgrade the Schema of a Changeset/Patchset
12017 */
12018 SQLITE_API int sqlite3changeset_upgrade(
12019 sqlite3 *db,
12020 const char *zDb,
12021 int nIn, const void *pIn, /* Input changeset */
12022 int *pnOut, void **ppOut /* OUT: Inverse of input */
12023 );
12024
12025
12026
12027 /*
12028 ** CAPI3REF: Changegroup Handle
12029 **
12030 ** A changegroup is an object used to combine two or more
12031
--- 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-18 01:16:26 57caa3136d1bfca06e4f2285734a4977b8d3fa1f75bf87453b975867e9de38fc"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -1987,17 +1987,20 @@
1987 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1988 ** return [SQLITE_ERROR].</dd>
1989 **
1990 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1991 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1992 ** the default size of [lookaside memory] on each [database connection].
1993 ** The first argument is the
1994 ** size of each lookaside buffer slot ("sz") and the second is the number of
1995 ** slots allocated to each database connection ("cnt").)^
1996 ** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.
1997 ** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can
1998 ** be used to change the lookaside configuration on individual connections.)^
1999 ** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the
2000 ** default lookaside configuration at compile-time.
2001 ** </dd>
2002 **
2003 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
2004 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
2005 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
2006 ** the interface to a custom page cache implementation.)^
@@ -2230,35 +2233,54 @@
2233 **
2234 ** <dl>
2235 ** [[SQLITE_DBCONFIG_LOOKASIDE]]
2236 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2237 ** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2238 ** configuration of the [lookaside memory allocator] within a database
2239 ** connection.
2240 ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2241 ** in the [DBCONFIG arguments|usual format].
2242 ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2243 ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2244 ** should have a total of five parameters.
2245 ** <ol>
2246 ** <li><p>The first argument ("buf") is a
2247 ** pointer to a memory buffer to use for lookaside memory.
2248 ** The first argument may be NULL in which case SQLite will allocate the
2249 ** lookaside buffer itself using [sqlite3_malloc()].
2250 ** <li><P>The second argument ("sz") is the
2251 ** size of each lookaside buffer slot. Lookaside is disabled if "sz"
2252 ** is less than 8. The "sz" argument should be a multiple of 8 less than
2253 ** 65536. If "sz" does not meet this constraint, it is reduced in size until
2254 ** it does.
2255 ** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled
2256 ** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so
2257 ** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt"
2258 ** parameter is usually chosen so that the product of "sz" and "cnt" is less
2259 ** than 1,000,000.
2260 ** </ol>
2261 ** <p>If the "buf" argument is not NULL, then it must
2262 ** point to a memory buffer with a size that is greater than
2263 ** or equal to the product of "sz" and "cnt".
2264 ** The buffer must be aligned to an 8-byte boundary.
2265 ** The lookaside memory
2266 ** configuration for a database connection can only be changed when that
2267 ** connection is not currently using lookaside memory, or in other words
2268 ** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.
 
2269 ** Any attempt to change the lookaside memory configuration when lookaside
2270 ** memory is in use leaves the configuration unchanged and returns
2271 ** [SQLITE_BUSY].
2272 ** If the "buf" argument is NULL and an attempt
2273 ** to allocate memory based on "sz" and "cnt" fails, then
2274 ** lookaside is silently disabled.
2275 ** <p>
2276 ** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the
2277 ** default lookaside configuration at initialization. The
2278 ** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside
2279 ** configuration at compile-time. Typical values for lookaside are 1200 for
2280 ** "sz" and 40 to 100 for "cnt".
2281 ** </dd>
2282 **
2283 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2284 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2285 ** <dd> ^This option is used to enable or disable the enforcement of
2286 ** [foreign key constraints]. This is the same setting that is
@@ -12008,23 +12030,10 @@
12030 int nB, /* Number of bytes in buffer pB */
12031 void *pB, /* Pointer to buffer containing changeset B */
12032 int *pnOut, /* OUT: Number of bytes in output changeset */
12033 void **ppOut /* OUT: Buffer containing output changeset */
12034 );
 
 
 
 
 
 
 
 
 
 
 
 
 
12035
12036 /*
12037 ** CAPI3REF: Changegroup Handle
12038 **
12039 ** A changegroup is an object used to combine two or more
12040

Keyboard Shortcuts

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