Fossil SCM
Update the built-in SQLite to the latest trunk version that includes all recent fixes.
Commit
679265a7261fb8a6215aa237330cc6c542aa4f109863f0011ce2dba7f6580aa8
Parent
f8e522e4673c698…
2 files changed
+469
-379
+45
-36
+469
-379
| --- extsrc/sqlite3.c | ||
| +++ extsrc/sqlite3.c | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 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 | |
| 3 | +** version 3.50.0. By combining all the individual C code files into this | |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| @@ -16,11 +16,11 @@ | ||
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | 19 | ** |
| 20 | 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | -** 4a7dd425dc2a0e5082a9049c9b4a9d4f199a with changes in files: | |
| 21 | +** 57caa3136d1bfca06e4f2285734a4977b8d3 with changes in files: | |
| 22 | 22 | ** |
| 23 | 23 | ** |
| 24 | 24 | */ |
| 25 | 25 | #ifndef SQLITE_AMALGAMATION |
| 26 | 26 | #define SQLITE_CORE 1 |
| @@ -463,13 +463,13 @@ | ||
| 463 | 463 | ** |
| 464 | 464 | ** See also: [sqlite3_libversion()], |
| 465 | 465 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 466 | 466 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 467 | 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" | |
| 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 | 471 | |
| 472 | 472 | /* |
| 473 | 473 | ** CAPI3REF: Run-Time Library Version Numbers |
| 474 | 474 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 475 | 475 | ** |
| @@ -2306,17 +2306,20 @@ | ||
| 2306 | 2306 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 2307 | 2307 | ** return [SQLITE_ERROR].</dd> |
| 2308 | 2308 | ** |
| 2309 | 2309 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 2310 | 2310 | ** <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]. | |
| 2312 | 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> | |
| 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> | |
| 2318 | 2321 | ** |
| 2319 | 2322 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 2320 | 2323 | ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is |
| 2321 | 2324 | ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies |
| 2322 | 2325 | ** the interface to a custom page cache implementation.)^ |
| @@ -2549,35 +2552,54 @@ | ||
| 2549 | 2552 | ** |
| 2550 | 2553 | ** <dl> |
| 2551 | 2554 | ** [[SQLITE_DBCONFIG_LOOKASIDE]] |
| 2552 | 2555 | ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> |
| 2553 | 2556 | ** <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 | |
| 2555 | 2558 | ** connection. |
| 2556 | 2559 | ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i> |
| 2557 | 2560 | ** in the [DBCONFIG arguments|usual format]. |
| 2558 | 2561 | ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two, |
| 2559 | 2562 | ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE |
| 2560 | 2563 | ** 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 | |
| 2562 | 2566 | ** 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 | |
| 2572 | 2585 | ** configuration for a database connection can only be changed when that |
| 2573 | 2586 | ** 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. | |
| 2576 | 2588 | ** Any attempt to change the lookaside memory configuration when lookaside |
| 2577 | 2589 | ** 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> | |
| 2579 | 2601 | ** |
| 2580 | 2602 | ** [[SQLITE_DBCONFIG_ENABLE_FKEY]] |
| 2581 | 2603 | ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> |
| 2582 | 2604 | ** <dd> ^This option is used to enable or disable the enforcement of |
| 2583 | 2605 | ** [foreign key constraints]. This is the same setting that is |
| @@ -12328,23 +12350,10 @@ | ||
| 12328 | 12350 | void *pB, /* Pointer to buffer containing changeset B */ |
| 12329 | 12351 | int *pnOut, /* OUT: Number of bytes in output changeset */ |
| 12330 | 12352 | void **ppOut /* OUT: Buffer containing output changeset */ |
| 12331 | 12353 | ); |
| 12332 | 12354 | |
| 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 | 12355 | /* |
| 12347 | 12356 | ** CAPI3REF: Changegroup Handle |
| 12348 | 12357 | ** |
| 12349 | 12358 | ** A changegroup is an object used to combine two or more |
| 12350 | 12359 | ** [changesets] or [patchsets] |
| @@ -14747,10 +14756,11 @@ | ||
| 14747 | 14756 | */ |
| 14748 | 14757 | struct HashElem { |
| 14749 | 14758 | HashElem *next, *prev; /* Next and previous elements in the table */ |
| 14750 | 14759 | void *data; /* Data associated with this element */ |
| 14751 | 14760 | const char *pKey; /* Key associated with this element */ |
| 14761 | + unsigned int h; /* hash for pKey */ | |
| 14752 | 14762 | }; |
| 14753 | 14763 | |
| 14754 | 14764 | /* |
| 14755 | 14765 | ** Access routines. To delete, insert a NULL pointer. |
| 14756 | 14766 | */ |
| @@ -15185,10 +15195,15 @@ | ||
| 15185 | 15195 | typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ |
| 15186 | 15196 | typedef INT16_TYPE i16; /* 2-byte signed integer */ |
| 15187 | 15197 | typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ |
| 15188 | 15198 | typedef INT8_TYPE i8; /* 1-byte signed integer */ |
| 15189 | 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 | + | |
| 15190 | 15205 | /* |
| 15191 | 15206 | ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value |
| 15192 | 15207 | ** that can be stored in a u32 without loss of data. The value |
| 15193 | 15208 | ** is 0x00000000ffffffff. But because of quirks of some compilers, we |
| 15194 | 15209 | ** have to specify the value in the less intuitive manner shown: |
| @@ -15353,10 +15368,18 @@ | ||
| 15353 | 15368 | */ |
| 15354 | 15369 | #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) |
| 15355 | 15370 | #define LARGEST_UINT64 (0xffffffff|(((u64)0xffffffff)<<32)) |
| 15356 | 15371 | #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) |
| 15357 | 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 | + | |
| 15358 | 15381 | /* |
| 15359 | 15382 | ** Round up a number to the next larger multiple of 8. This is used |
| 15360 | 15383 | ** to force 8-byte alignment on 64-bit architectures. |
| 15361 | 15384 | ** |
| 15362 | 15385 | ** ROUND8() always does the rounding, for any argument. |
| @@ -18731,10 +18754,11 @@ | ||
| 18731 | 18754 | VTable *p; /* List of VTable objects. */ |
| 18732 | 18755 | } vtab; |
| 18733 | 18756 | } u; |
| 18734 | 18757 | Trigger *pTrigger; /* List of triggers on this object */ |
| 18735 | 18758 | Schema *pSchema; /* Schema that contains this table */ |
| 18759 | + u8 aHx[16]; /* Column aHt[K%sizeof(aHt)] might have hash K */ | |
| 18736 | 18760 | }; |
| 18737 | 18761 | |
| 18738 | 18762 | /* |
| 18739 | 18763 | ** Allowed values for Table.tabFlags. |
| 18740 | 18764 | ** |
| @@ -20128,29 +20152,36 @@ | ||
| 20128 | 20152 | struct Parse { |
| 20129 | 20153 | sqlite3 *db; /* The main database structure */ |
| 20130 | 20154 | char *zErrMsg; /* An error message */ |
| 20131 | 20155 | Vdbe *pVdbe; /* An engine for executing database bytecode */ |
| 20132 | 20156 | 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)) */ | |
| 20135 | 20158 | u8 nested; /* Number of nested calls to the parser/code generator */ |
| 20136 | 20159 | u8 nTempReg; /* Number of temporary registers in aTempReg[] */ |
| 20137 | 20160 | u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ |
| 20138 | 20161 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 20139 | 20162 | u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ |
| 20140 | - u8 okConstFactor; /* OK to factor out constants */ | |
| 20141 | 20163 | u8 disableLookaside; /* Number of times lookaside has been disabled */ |
| 20142 | 20164 | u8 prepFlags; /* SQLITE_PREPARE_* flags */ |
| 20143 | 20165 | u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */ |
| 20144 | - u8 bHasWith; /* True if statement contains WITH */ | |
| 20145 | 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 */ | |
| 20146 | 20171 | #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) |
| 20147 | 20172 | u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */ |
| 20148 | 20173 | #endif |
| 20149 | 20174 | #ifdef SQLITE_DEBUG |
| 20150 | 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. */ | |
| 20151 | 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 */ | |
| 20152 | 20183 | int nRangeReg; /* Size of the temporary register block */ |
| 20153 | 20184 | int iRangeReg; /* First register in temporary register block */ |
| 20154 | 20185 | int nErr; /* Number of errors seen */ |
| 20155 | 20186 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 20156 | 20187 | int nMem; /* Number of memory cells used so far */ |
| @@ -20161,16 +20192,13 @@ | ||
| 20161 | 20192 | int nLabelAlloc; /* Number of slots in aLabel */ |
| 20162 | 20193 | int *aLabel; /* Space to hold the labels */ |
| 20163 | 20194 | ExprList *pConstExpr;/* Constant expressions */ |
| 20164 | 20195 | IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */ |
| 20165 | 20196 | IndexedExpr *pIdxPartExpr; /* Exprs constrained by index WHERE clauses */ |
| 20166 | - Token constraintName;/* Name of the constraint currently being parsed */ | |
| 20167 | 20197 | yDbMask writeMask; /* Start a write transaction on these databases */ |
| 20168 | 20198 | 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 */ | |
| 20172 | 20200 | int nSelect; /* Number of SELECT stmts. Counter for Select.selId */ |
| 20173 | 20201 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 20174 | 20202 | u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */ |
| 20175 | 20203 | #endif |
| 20176 | 20204 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| @@ -20180,21 +20208,10 @@ | ||
| 20180 | 20208 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 20181 | 20209 | Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 20182 | 20210 | Table *pTriggerTab; /* Table triggers are being coded for */ |
| 20183 | 20211 | TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ |
| 20184 | 20212 | 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 | 20213 | |
| 20197 | 20214 | /************************************************************************** |
| 20198 | 20215 | ** Fields above must be initialized to zero. The fields that follow, |
| 20199 | 20216 | ** down to the beginning of the recursive section, do not need to be |
| 20200 | 20217 | ** initialized as they will be set before being used. The boundary is |
| @@ -20202,10 +20219,23 @@ | ||
| 20202 | 20219 | **************************************************************************/ |
| 20203 | 20220 | |
| 20204 | 20221 | int aTempReg[8]; /* Holding area for temporary registers */ |
| 20205 | 20222 | Parse *pOuterParse; /* Outer Parse object when nested */ |
| 20206 | 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; | |
| 20207 | 20237 | |
| 20208 | 20238 | /************************************************************************ |
| 20209 | 20239 | ** Above is constant between recursions. Below is reset before and after |
| 20210 | 20240 | ** each recursion. The boundary between these two regions is determined |
| 20211 | 20241 | ** using offsetof(Parse,sLastToken) so the sLastToken field must be the |
| @@ -23831,14 +23861,10 @@ | ||
| 23831 | 23861 | u8 skipFlag; /* Skip accumulator loading if true */ |
| 23832 | 23862 | u16 argc; /* Number of arguments */ |
| 23833 | 23863 | sqlite3_value *argv[1]; /* Argument set */ |
| 23834 | 23864 | }; |
| 23835 | 23865 | |
| 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 | 23866 | |
| 23841 | 23867 | /* The ScanStatus object holds a single value for the |
| 23842 | 23868 | ** sqlite3_stmt_scanstatus() interface. |
| 23843 | 23869 | ** |
| 23844 | 23870 | ** aAddrRange[]: |
| @@ -23895,11 +23921,11 @@ | ||
| 23895 | 23921 | i64 iCurrentTime; /* Value of julianday('now') for this statement */ |
| 23896 | 23922 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 23897 | 23923 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| 23898 | 23924 | i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */ |
| 23899 | 23925 | Mem *aMem; /* The memory locations */ |
| 23900 | - Mem **apArg; /* Arguments to currently executing user function */ | |
| 23926 | + Mem **apArg; /* Arguments xUpdate and xFilter vtab methods */ | |
| 23901 | 23927 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| 23902 | 23928 | Mem *aVar; /* Values for the OP_Variable opcode. */ |
| 23903 | 23929 | |
| 23904 | 23930 | /* When allocating a new Vdbe object, all of the fields below should be |
| 23905 | 23931 | ** initialized to zero or NULL */ |
| @@ -23915,10 +23941,11 @@ | ||
| 23915 | 23941 | i64 startTime; /* Time when query started - used for profiling */ |
| 23916 | 23942 | #endif |
| 23917 | 23943 | #ifdef SQLITE_DEBUG |
| 23918 | 23944 | int rcApp; /* errcode set by sqlite3_result_error_code() */ |
| 23919 | 23945 | u32 nWrite; /* Number of write operations that have occurred */ |
| 23946 | + int napArg; /* Size of the apArg[] array */ | |
| 23920 | 23947 | #endif |
| 23921 | 23948 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 23922 | 23949 | u16 nResAlloc; /* Column slots allocated to aColName[] */ |
| 23923 | 23950 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 23924 | 23951 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| @@ -32546,11 +32573,11 @@ | ||
| 32546 | 32573 | ** pointer if any kind of error was encountered. |
| 32547 | 32574 | */ |
| 32548 | 32575 | static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){ |
| 32549 | 32576 | char *zText; |
| 32550 | 32577 | assert( p->mxAlloc>0 && !isMalloced(p) ); |
| 32551 | - zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); | |
| 32578 | + zText = sqlite3DbMallocRaw(p->db, 1+(u64)p->nChar ); | |
| 32552 | 32579 | if( zText ){ |
| 32553 | 32580 | memcpy(zText, p->zText, p->nChar+1); |
| 32554 | 32581 | p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 32555 | 32582 | }else{ |
| 32556 | 32583 | sqlite3StrAccumSetError(p, SQLITE_NOMEM); |
| @@ -36398,11 +36425,15 @@ | ||
| 36398 | 36425 | } |
| 36399 | 36426 | } |
| 36400 | 36427 | } |
| 36401 | 36428 | p->z = &p->zBuf[i+1]; |
| 36402 | 36429 | 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 | + } | |
| 36404 | 36435 | } |
| 36405 | 36436 | |
| 36406 | 36437 | /* |
| 36407 | 36438 | ** Try to convert z into an unsigned 32-bit integer. Return true on |
| 36408 | 36439 | ** success and false if there is an error. |
| @@ -37184,16 +37215,23 @@ | ||
| 37184 | 37215 | /* |
| 37185 | 37216 | ** The hashing function. |
| 37186 | 37217 | */ |
| 37187 | 37218 | static unsigned int strHash(const char *z){ |
| 37188 | 37219 | 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*/ | |
| 37191 | 37221 | /* Knuth multiplicative hashing. (Sorting & Searching, p. 510). |
| 37192 | 37222 | ** 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 | |
| 37195 | 37233 | h *= 0x9e3779b1; |
| 37196 | 37234 | } |
| 37197 | 37235 | return h; |
| 37198 | 37236 | } |
| 37199 | 37237 | |
| @@ -37262,13 +37300,12 @@ | ||
| 37262 | 37300 | sqlite3_free(pH->ht); |
| 37263 | 37301 | pH->ht = new_ht; |
| 37264 | 37302 | pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht); |
| 37265 | 37303 | memset(new_ht, 0, new_size*sizeof(struct _ht)); |
| 37266 | 37304 | for(elem=pH->first, pH->first=0; elem; elem = next_elem){ |
| 37267 | - unsigned int h = strHash(elem->pKey) % new_size; | |
| 37268 | 37305 | next_elem = elem->next; |
| 37269 | - insertElement(pH, &new_ht[h], elem); | |
| 37306 | + insertElement(pH, &new_ht[elem->h % new_size], elem); | |
| 37270 | 37307 | } |
| 37271 | 37308 | return 1; |
| 37272 | 37309 | } |
| 37273 | 37310 | |
| 37274 | 37311 | /* This function (for internal use only) locates an element in an |
| @@ -37282,27 +37319,26 @@ | ||
| 37282 | 37319 | unsigned int *pHash /* Write the hash value here */ |
| 37283 | 37320 | ){ |
| 37284 | 37321 | HashElem *elem; /* Used to loop thru the element list */ |
| 37285 | 37322 | unsigned int count; /* Number of elements left to test */ |
| 37286 | 37323 | unsigned int h; /* The computed hash */ |
| 37287 | - static HashElem nullElement = { 0, 0, 0, 0 }; | |
| 37324 | + static HashElem nullElement = { 0, 0, 0, 0, 0 }; | |
| 37288 | 37325 | |
| 37326 | + h = strHash(pKey); | |
| 37289 | 37327 | if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/ |
| 37290 | 37328 | struct _ht *pEntry; |
| 37291 | - h = strHash(pKey) % pH->htsize; | |
| 37292 | - pEntry = &pH->ht[h]; | |
| 37329 | + pEntry = &pH->ht[h % pH->htsize]; | |
| 37293 | 37330 | elem = pEntry->chain; |
| 37294 | 37331 | count = pEntry->count; |
| 37295 | 37332 | }else{ |
| 37296 | - h = 0; | |
| 37297 | 37333 | elem = pH->first; |
| 37298 | 37334 | count = pH->count; |
| 37299 | 37335 | } |
| 37300 | 37336 | if( pHash ) *pHash = h; |
| 37301 | 37337 | while( count ){ |
| 37302 | 37338 | assert( elem!=0 ); |
| 37303 | - if( sqlite3StrICmp(elem->pKey,pKey)==0 ){ | |
| 37339 | + if( h==elem->h && sqlite3StrICmp(elem->pKey,pKey)==0 ){ | |
| 37304 | 37340 | return elem; |
| 37305 | 37341 | } |
| 37306 | 37342 | elem = elem->next; |
| 37307 | 37343 | count--; |
| 37308 | 37344 | } |
| @@ -37310,14 +37346,13 @@ | ||
| 37310 | 37346 | } |
| 37311 | 37347 | |
| 37312 | 37348 | /* Remove a single entry from the hash table given a pointer to that |
| 37313 | 37349 | ** element and a hash on the element's key. |
| 37314 | 37350 | */ |
| 37315 | -static void removeElementGivenHash( | |
| 37351 | +static void removeElement( | |
| 37316 | 37352 | 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 */ | |
| 37319 | 37354 | ){ |
| 37320 | 37355 | struct _ht *pEntry; |
| 37321 | 37356 | if( elem->prev ){ |
| 37322 | 37357 | elem->prev->next = elem->next; |
| 37323 | 37358 | }else{ |
| @@ -37325,11 +37360,11 @@ | ||
| 37325 | 37360 | } |
| 37326 | 37361 | if( elem->next ){ |
| 37327 | 37362 | elem->next->prev = elem->prev; |
| 37328 | 37363 | } |
| 37329 | 37364 | if( pH->ht ){ |
| 37330 | - pEntry = &pH->ht[h]; | |
| 37365 | + pEntry = &pH->ht[elem->h % pH->htsize]; | |
| 37331 | 37366 | if( pEntry->chain==elem ){ |
| 37332 | 37367 | pEntry->chain = elem->next; |
| 37333 | 37368 | } |
| 37334 | 37369 | assert( pEntry->count>0 ); |
| 37335 | 37370 | pEntry->count--; |
| @@ -37376,11 +37411,11 @@ | ||
| 37376 | 37411 | assert( pKey!=0 ); |
| 37377 | 37412 | elem = findElementWithHash(pH,pKey,&h); |
| 37378 | 37413 | if( elem->data ){ |
| 37379 | 37414 | void *old_data = elem->data; |
| 37380 | 37415 | if( data==0 ){ |
| 37381 | - removeElementGivenHash(pH,elem,h); | |
| 37416 | + removeElement(pH,elem); | |
| 37382 | 37417 | }else{ |
| 37383 | 37418 | elem->data = data; |
| 37384 | 37419 | elem->pKey = pKey; |
| 37385 | 37420 | } |
| 37386 | 37421 | return old_data; |
| @@ -37387,19 +37422,17 @@ | ||
| 37387 | 37422 | } |
| 37388 | 37423 | if( data==0 ) return 0; |
| 37389 | 37424 | new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) ); |
| 37390 | 37425 | if( new_elem==0 ) return data; |
| 37391 | 37426 | new_elem->pKey = pKey; |
| 37427 | + new_elem->h = h; | |
| 37392 | 37428 | new_elem->data = data; |
| 37393 | 37429 | 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); | |
| 37399 | 37432 | } |
| 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); | |
| 37401 | 37434 | return 0; |
| 37402 | 37435 | } |
| 37403 | 37436 | |
| 37404 | 37437 | /************** End of hash.c ************************************************/ |
| 37405 | 37438 | /************** Begin file opcodes.c *****************************************/ |
| @@ -50806,11 +50839,11 @@ | ||
| 50806 | 50839 | ** allocate space for a new winShmNode and filename. |
| 50807 | 50840 | */ |
| 50808 | 50841 | p = sqlite3MallocZero( sizeof(*p) ); |
| 50809 | 50842 | if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT; |
| 50810 | 50843 | nName = sqlite3Strlen30(pDbFd->zPath); |
| 50811 | - pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 ); | |
| 50844 | + pNew = sqlite3MallocZero( sizeof(*pShmNode) + (i64)nName + 17 ); | |
| 50812 | 50845 | if( pNew==0 ){ |
| 50813 | 50846 | sqlite3_free(p); |
| 50814 | 50847 | return SQLITE_IOERR_NOMEM_BKPT; |
| 50815 | 50848 | } |
| 50816 | 50849 | pNew->zFilename = (char*)&pNew[1]; |
| @@ -51627,11 +51660,11 @@ | ||
| 51627 | 51660 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 51628 | 51661 | "0123456789"; |
| 51629 | 51662 | size_t i, j; |
| 51630 | 51663 | DWORD pid; |
| 51631 | 51664 | int nPre = sqlite3Strlen30(SQLITE_TEMP_FILE_PREFIX); |
| 51632 | - int nMax, nBuf, nDir, nLen; | |
| 51665 | + i64 nMax, nBuf, nDir, nLen; | |
| 51633 | 51666 | char *zBuf; |
| 51634 | 51667 | |
| 51635 | 51668 | /* It's odd to simulate an io-error here, but really this is just |
| 51636 | 51669 | ** using the io-error infrastructure to test that SQLite handles this |
| 51637 | 51670 | ** function failing. |
| @@ -51639,11 +51672,12 @@ | ||
| 51639 | 51672 | SimulateIOError( return SQLITE_IOERR ); |
| 51640 | 51673 | |
| 51641 | 51674 | /* Allocate a temporary buffer to store the fully qualified file |
| 51642 | 51675 | ** name for the temporary file. If this fails, we cannot continue. |
| 51643 | 51676 | */ |
| 51644 | - nMax = pVfs->mxPathname; nBuf = nMax + 2; | |
| 51677 | + nMax = pVfs->mxPathname; | |
| 51678 | + nBuf = 2 + (i64)nMax; | |
| 51645 | 51679 | zBuf = sqlite3MallocZero( nBuf ); |
| 51646 | 51680 | if( !zBuf ){ |
| 51647 | 51681 | OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n")); |
| 51648 | 51682 | return SQLITE_IOERR_NOMEM_BKPT; |
| 51649 | 51683 | } |
| @@ -52498,11 +52532,11 @@ | ||
| 52498 | 52532 | ** NOTE: We are dealing with a relative path name and the data |
| 52499 | 52533 | ** directory has been set. Therefore, use it as the basis |
| 52500 | 52534 | ** for converting the relative path name to an absolute |
| 52501 | 52535 | ** one by prepending the data directory and a slash. |
| 52502 | 52536 | */ |
| 52503 | - char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 ); | |
| 52537 | + char *zOut = sqlite3MallocZero( 1+(u64)pVfs->mxPathname ); | |
| 52504 | 52538 | if( !zOut ){ |
| 52505 | 52539 | return SQLITE_IOERR_NOMEM_BKPT; |
| 52506 | 52540 | } |
| 52507 | 52541 | if( cygwin_conv_path( |
| 52508 | 52542 | (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) | |
| @@ -52593,17 +52627,16 @@ | ||
| 52593 | 52627 | if( nByte==0 ){ |
| 52594 | 52628 | sqlite3_free(zConverted); |
| 52595 | 52629 | return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
| 52596 | 52630 | "winFullPathname1", zRelative); |
| 52597 | 52631 | } |
| 52598 | - nByte += 3; | |
| 52599 | - zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); | |
| 52632 | + zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) ); | |
| 52600 | 52633 | if( zTemp==0 ){ |
| 52601 | 52634 | sqlite3_free(zConverted); |
| 52602 | 52635 | return SQLITE_IOERR_NOMEM_BKPT; |
| 52603 | 52636 | } |
| 52604 | - nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0); | |
| 52637 | + nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte+3, zTemp, 0); | |
| 52605 | 52638 | if( nByte==0 ){ |
| 52606 | 52639 | sqlite3_free(zConverted); |
| 52607 | 52640 | sqlite3_free(zTemp); |
| 52608 | 52641 | return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
| 52609 | 52642 | "winFullPathname2", zRelative); |
| @@ -52619,17 +52652,16 @@ | ||
| 52619 | 52652 | if( nByte==0 ){ |
| 52620 | 52653 | sqlite3_free(zConverted); |
| 52621 | 52654 | return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
| 52622 | 52655 | "winFullPathname3", zRelative); |
| 52623 | 52656 | } |
| 52624 | - nByte += 3; | |
| 52625 | - zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) ); | |
| 52657 | + zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) ); | |
| 52626 | 52658 | if( zTemp==0 ){ |
| 52627 | 52659 | sqlite3_free(zConverted); |
| 52628 | 52660 | return SQLITE_IOERR_NOMEM_BKPT; |
| 52629 | 52661 | } |
| 52630 | - nByte = osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0); | |
| 52662 | + nByte = osGetFullPathNameA((char*)zConverted, nByte+3, zTemp, 0); | |
| 52631 | 52663 | if( nByte==0 ){ |
| 52632 | 52664 | sqlite3_free(zConverted); |
| 52633 | 52665 | sqlite3_free(zTemp); |
| 52634 | 52666 | return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(), |
| 52635 | 52667 | "winFullPathname4", zRelative); |
| @@ -53654,17 +53686,17 @@ | ||
| 53654 | 53686 | break; |
| 53655 | 53687 | } |
| 53656 | 53688 | } |
| 53657 | 53689 | if( p==0 ){ |
| 53658 | 53690 | MemStore **apNew; |
| 53659 | - p = sqlite3Malloc( sizeof(*p) + szName + 3 ); | |
| 53691 | + p = sqlite3Malloc( sizeof(*p) + (i64)szName + 3 ); | |
| 53660 | 53692 | if( p==0 ){ |
| 53661 | 53693 | sqlite3_mutex_leave(pVfsMutex); |
| 53662 | 53694 | return SQLITE_NOMEM; |
| 53663 | 53695 | } |
| 53664 | 53696 | apNew = sqlite3Realloc(memdb_g.apMemStore, |
| 53665 | - sizeof(apNew[0])*(memdb_g.nMemStore+1) ); | |
| 53697 | + sizeof(apNew[0])*(1+(i64)memdb_g.nMemStore) ); | |
| 53666 | 53698 | if( apNew==0 ){ |
| 53667 | 53699 | sqlite3_free(p); |
| 53668 | 53700 | sqlite3_mutex_leave(pVfsMutex); |
| 53669 | 53701 | return SQLITE_NOMEM; |
| 53670 | 53702 | } |
| @@ -54370,11 +54402,11 @@ | ||
| 54370 | 54402 | void *pTmpSpace; |
| 54371 | 54403 | |
| 54372 | 54404 | /* Allocate the Bitvec to be tested and a linear array of |
| 54373 | 54405 | ** bits to act as the reference */ |
| 54374 | 54406 | pBitvec = sqlite3BitvecCreate( sz ); |
| 54375 | - pV = sqlite3MallocZero( (sz+7)/8 + 1 ); | |
| 54407 | + pV = sqlite3MallocZero( (7+(i64)sz)/8 + 1 ); | |
| 54376 | 54408 | pTmpSpace = sqlite3_malloc64(BITVEC_SZ); |
| 54377 | 54409 | if( pBitvec==0 || pV==0 || pTmpSpace==0 ) goto bitvec_end; |
| 54378 | 54410 | |
| 54379 | 54411 | /* NULL pBitvec tests */ |
| 54380 | 54412 | sqlite3BitvecSet(0, 1); |
| @@ -55917,16 +55949,16 @@ | ||
| 55917 | 55949 | ** |
| 55918 | 55950 | ** The PCache mutex must be held when this function is called. |
| 55919 | 55951 | */ |
| 55920 | 55952 | static void pcache1ResizeHash(PCache1 *p){ |
| 55921 | 55953 | PgHdr1 **apNew; |
| 55922 | - unsigned int nNew; | |
| 55923 | - unsigned int i; | |
| 55954 | + u64 nNew; | |
| 55955 | + u32 i; | |
| 55924 | 55956 | |
| 55925 | 55957 | assert( sqlite3_mutex_held(p->pGroup->mutex) ); |
| 55926 | 55958 | |
| 55927 | - nNew = p->nHash*2; | |
| 55959 | + nNew = 2*(u64)p->nHash; | |
| 55928 | 55960 | if( nNew<256 ){ |
| 55929 | 55961 | nNew = 256; |
| 55930 | 55962 | } |
| 55931 | 55963 | |
| 55932 | 55964 | pcache1LeaveMutex(p->pGroup); |
| @@ -56145,11 +56177,11 @@ | ||
| 56145 | 56177 | ** Allocate a new cache. |
| 56146 | 56178 | */ |
| 56147 | 56179 | static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){ |
| 56148 | 56180 | PCache1 *pCache; /* The newly created page cache */ |
| 56149 | 56181 | 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 */ | |
| 56151 | 56183 | |
| 56152 | 56184 | assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 ); |
| 56153 | 56185 | assert( szExtra < 300 ); |
| 56154 | 56186 | |
| 56155 | 56187 | sz = sizeof(PCache1) + sizeof(PGroup)*pcache1.separateCache; |
| @@ -58624,11 +58656,11 @@ | ||
| 58624 | 58656 | ** zSuper[0] is set to 0 and SQLITE_OK returned. |
| 58625 | 58657 | ** |
| 58626 | 58658 | ** If an error occurs while reading from the journal file, an SQLite |
| 58627 | 58659 | ** error code is returned. |
| 58628 | 58660 | */ |
| 58629 | -static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper){ | |
| 58661 | +static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u64 nSuper){ | |
| 58630 | 58662 | int rc; /* Return code */ |
| 58631 | 58663 | u32 len; /* Length in bytes of super-journal name */ |
| 58632 | 58664 | i64 szJ; /* Total size in bytes of journal file pJrnl */ |
| 58633 | 58665 | u32 cksum; /* MJ checksum value read from journal */ |
| 58634 | 58666 | u32 u; /* Unsigned loop counter */ |
| @@ -59860,16 +59892,16 @@ | ||
| 59860 | 59892 | char *zSuperJournal = 0; /* Contents of super-journal file */ |
| 59861 | 59893 | i64 nSuperJournal; /* Size of super-journal file */ |
| 59862 | 59894 | char *zJournal; /* Pointer to one journal within MJ file */ |
| 59863 | 59895 | char *zSuperPtr; /* Space to hold super-journal filename */ |
| 59864 | 59896 | char *zFree = 0; /* Free this buffer */ |
| 59865 | - int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */ | |
| 59897 | + i64 nSuperPtr; /* Amount of space allocated to zSuperPtr[] */ | |
| 59866 | 59898 | |
| 59867 | 59899 | /* Allocate space for both the pJournal and pSuper file descriptors. |
| 59868 | 59900 | ** If successful, open the super-journal file for reading. |
| 59869 | 59901 | */ |
| 59870 | - pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2); | |
| 59902 | + pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile); | |
| 59871 | 59903 | if( !pSuper ){ |
| 59872 | 59904 | rc = SQLITE_NOMEM_BKPT; |
| 59873 | 59905 | pJournal = 0; |
| 59874 | 59906 | }else{ |
| 59875 | 59907 | const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL); |
| @@ -59883,15 +59915,18 @@ | ||
| 59883 | 59915 | ** sufficient space (in zSuperPtr) to hold the names of super-journal |
| 59884 | 59916 | ** files extracted from regular rollback-journals. |
| 59885 | 59917 | */ |
| 59886 | 59918 | rc = sqlite3OsFileSize(pSuper, &nSuperJournal); |
| 59887 | 59919 | if( rc!=SQLITE_OK ) goto delsuper_out; |
| 59888 | - nSuperPtr = pVfs->mxPathname+1; | |
| 59920 | + nSuperPtr = 1 + (i64)pVfs->mxPathname; | |
| 59921 | + assert( nSuperJournal>=0 && nSuperPtr>0 ); | |
| 59889 | 59922 | zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2); |
| 59890 | 59923 | if( !zFree ){ |
| 59891 | 59924 | rc = SQLITE_NOMEM_BKPT; |
| 59892 | 59925 | goto delsuper_out; |
| 59926 | + }else{ | |
| 59927 | + assert( nSuperJournal<=0x7fffffff ); | |
| 59893 | 59928 | } |
| 59894 | 59929 | zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0; |
| 59895 | 59930 | zSuperJournal = &zFree[4]; |
| 59896 | 59931 | zSuperPtr = &zSuperJournal[nSuperJournal+2]; |
| 59897 | 59932 | rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0); |
| @@ -60148,11 +60183,11 @@ | ||
| 60148 | 60183 | ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c, |
| 60149 | 60184 | ** mxPathname is 512, which is the same as the minimum allowable value |
| 60150 | 60185 | ** for pageSize. |
| 60151 | 60186 | */ |
| 60152 | 60187 | zSuper = pPager->pTmpSpace; |
| 60153 | - rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1); | |
| 60188 | + rc = readSuperJournal(pPager->jfd, zSuper, 1+(i64)pPager->pVfs->mxPathname); | |
| 60154 | 60189 | if( rc==SQLITE_OK && zSuper[0] ){ |
| 60155 | 60190 | rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res); |
| 60156 | 60191 | } |
| 60157 | 60192 | zSuper = 0; |
| 60158 | 60193 | if( rc!=SQLITE_OK || !res ){ |
| @@ -60287,11 +60322,11 @@ | ||
| 60287 | 60322 | /* Leave 4 bytes of space before the super-journal filename in memory. |
| 60288 | 60323 | ** This is because it may end up being passed to sqlite3OsOpen(), in |
| 60289 | 60324 | ** which case it requires 4 0x00 bytes in memory immediately before |
| 60290 | 60325 | ** the filename. */ |
| 60291 | 60326 | 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); | |
| 60293 | 60328 | testcase( rc!=SQLITE_OK ); |
| 60294 | 60329 | } |
| 60295 | 60330 | if( rc==SQLITE_OK |
| 60296 | 60331 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 60297 | 60332 | ){ |
| @@ -62057,10 +62092,11 @@ | ||
| 62057 | 62092 | int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */ |
| 62058 | 62093 | int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */ |
| 62059 | 62094 | u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */ |
| 62060 | 62095 | const char *zUri = 0; /* URI args to copy */ |
| 62061 | 62096 | int nUriByte = 1; /* Number of bytes of URI args at *zUri */ |
| 62097 | + | |
| 62062 | 62098 | |
| 62063 | 62099 | /* Figure out how much space is required for each journal file-handle |
| 62064 | 62100 | ** (there are two of them, the main journal and the sub-journal). */ |
| 62065 | 62101 | journalFileSize = ROUND8(sqlite3JournalSize(pVfs)); |
| 62066 | 62102 | |
| @@ -62083,12 +62119,12 @@ | ||
| 62083 | 62119 | ** to by zPathname, length nPathname. Or, if this is a temporary file, |
| 62084 | 62120 | ** leave both nPathname and zPathname set to 0. |
| 62085 | 62121 | */ |
| 62086 | 62122 | if( zFilename && zFilename[0] ){ |
| 62087 | 62123 | 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); | |
| 62090 | 62126 | if( zPathname==0 ){ |
| 62091 | 62127 | return SQLITE_NOMEM_BKPT; |
| 62092 | 62128 | } |
| 62093 | 62129 | zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */ |
| 62094 | 62130 | rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname); |
| @@ -62171,18 +62207,18 @@ | ||
| 62171 | 62207 | assert( SQLITE_PTRSIZE==sizeof(Pager*) ); |
| 62172 | 62208 | pPtr = (u8 *)sqlite3MallocZero( |
| 62173 | 62209 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 62174 | 62210 | ROUND8(pcacheSize) + /* PCache object */ |
| 62175 | 62211 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 62176 | - journalFileSize * 2 + /* The two journal files */ | |
| 62212 | + (u64)journalFileSize * 2 + /* The two journal files */ | |
| 62177 | 62213 | SQLITE_PTRSIZE + /* Space to hold a pointer */ |
| 62178 | 62214 | 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 */ | |
| 62182 | 62218 | #ifndef SQLITE_OMIT_WAL |
| 62183 | - nPathname + 4 + 1 + /* WAL filename */ | |
| 62219 | + (u64)nPathname + 4 + 1 + /* WAL filename */ | |
| 62184 | 62220 | #endif |
| 62185 | 62221 | 3 /* Terminator */ |
| 62186 | 62222 | ); |
| 62187 | 62223 | assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) ); |
| 62188 | 62224 | if( !pPtr ){ |
| @@ -65884,11 +65920,11 @@ | ||
| 65884 | 65920 | ){ |
| 65885 | 65921 | int rc = SQLITE_OK; |
| 65886 | 65922 | |
| 65887 | 65923 | /* Enlarge the pWal->apWiData[] array if required */ |
| 65888 | 65924 | if( pWal->nWiData<=iPage ){ |
| 65889 | - sqlite3_int64 nByte = sizeof(u32*)*(iPage+1); | |
| 65925 | + sqlite3_int64 nByte = sizeof(u32*)*(1+(i64)iPage); | |
| 65890 | 65926 | volatile u32 **apNew; |
| 65891 | 65927 | apNew = (volatile u32 **)sqlite3Realloc((void *)pWal->apWiData, nByte); |
| 65892 | 65928 | if( !apNew ){ |
| 65893 | 65929 | *ppPage = 0; |
| 65894 | 65930 | return SQLITE_NOMEM_BKPT; |
| @@ -71508,11 +71544,11 @@ | ||
| 71508 | 71544 | ** up to the size of 1 varint plus 1 8-byte value when the cursor |
| 71509 | 71545 | ** position is restored. Hence the 17 bytes of padding allocated |
| 71510 | 71546 | ** below. */ |
| 71511 | 71547 | void *pKey; |
| 71512 | 71548 | pCur->nKey = sqlite3BtreePayloadSize(pCur); |
| 71513 | - pKey = sqlite3Malloc( pCur->nKey + 9 + 8 ); | |
| 71549 | + pKey = sqlite3Malloc( ((i64)pCur->nKey) + 9 + 8 ); | |
| 71514 | 71550 | if( pKey ){ |
| 71515 | 71551 | rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey); |
| 71516 | 71552 | if( rc==SQLITE_OK ){ |
| 71517 | 71553 | memset(((u8*)pKey)+pCur->nKey, 0, 9+8); |
| 71518 | 71554 | pCur->pKey = pKey; |
| @@ -76879,11 +76915,11 @@ | ||
| 76879 | 76915 | testcase( nCell==2 ); /* Minimum legal index key size */ |
| 76880 | 76916 | if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){ |
| 76881 | 76917 | rc = SQLITE_CORRUPT_PAGE(pPage); |
| 76882 | 76918 | goto moveto_index_finish; |
| 76883 | 76919 | } |
| 76884 | - pCellKey = sqlite3Malloc( nCell+nOverrun ); | |
| 76920 | + pCellKey = sqlite3Malloc( (u64)nCell+(u64)nOverrun ); | |
| 76885 | 76921 | if( pCellKey==0 ){ |
| 76886 | 76922 | rc = SQLITE_NOMEM_BKPT; |
| 76887 | 76923 | goto moveto_index_finish; |
| 76888 | 76924 | } |
| 76889 | 76925 | pCur->ix = (u16)idx; |
| @@ -82068,10 +82104,11 @@ | ||
| 82068 | 82104 | ** blob of allocated memory. The xFree function should not call sqlite3_free() |
| 82069 | 82105 | ** on the memory, the btree layer does that. |
| 82070 | 82106 | */ |
| 82071 | 82107 | SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){ |
| 82072 | 82108 | BtShared *pBt = p->pBt; |
| 82109 | + assert( nBytes==0 || nBytes==sizeof(Schema) ); | |
| 82073 | 82110 | sqlite3BtreeEnter(p); |
| 82074 | 82111 | if( !pBt->pSchema && nBytes ){ |
| 82075 | 82112 | pBt->pSchema = sqlite3DbMallocZero(0, nBytes); |
| 82076 | 82113 | pBt->xFreeSchema = xFree; |
| 82077 | 82114 | } |
| @@ -83370,11 +83407,11 @@ | ||
| 83370 | 83407 | if( (pMem->flags & (MEM_Str|MEM_Term|MEM_Ephem|MEM_Static))!=MEM_Str ){ |
| 83371 | 83408 | /* pMem must be a string, and it cannot be an ephemeral or static string */ |
| 83372 | 83409 | return; |
| 83373 | 83410 | } |
| 83374 | 83411 | if( pMem->enc!=SQLITE_UTF8 ) return; |
| 83375 | - if( NEVER(pMem->z==0) ) return; | |
| 83412 | + assert( pMem->z!=0 ); | |
| 83376 | 83413 | if( pMem->flags & MEM_Dyn ){ |
| 83377 | 83414 | if( pMem->xDel==sqlite3_free |
| 83378 | 83415 | && sqlite3_msize(pMem->z) >= (u64)(pMem->n+1) |
| 83379 | 83416 | ){ |
| 83380 | 83417 | pMem->z[pMem->n] = 0; |
| @@ -84483,11 +84520,11 @@ | ||
| 84483 | 84520 | if( p ){ |
| 84484 | 84521 | UnpackedRecord *pRec = p->ppRec[0]; |
| 84485 | 84522 | |
| 84486 | 84523 | if( pRec==0 ){ |
| 84487 | 84524 | Index *pIdx = p->pIdx; /* Index being probed */ |
| 84488 | - int nByte; /* Bytes of space to allocate */ | |
| 84525 | + i64 nByte; /* Bytes of space to allocate */ | |
| 84489 | 84526 | int i; /* Counter variable */ |
| 84490 | 84527 | int nCol = pIdx->nColumn; /* Number of index columns including rowid */ |
| 84491 | 84528 | |
| 84492 | 84529 | nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord)); |
| 84493 | 84530 | pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte); |
| @@ -84549,11 +84586,11 @@ | ||
| 84549 | 84586 | sqlite3_value **ppVal, /* Write the new value here */ |
| 84550 | 84587 | struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */ |
| 84551 | 84588 | ){ |
| 84552 | 84589 | sqlite3_context ctx; /* Context object for function invocation */ |
| 84553 | 84590 | sqlite3_value **apVal = 0; /* Function arguments */ |
| 84554 | - int nVal = 0; /* Size of apVal[] array */ | |
| 84591 | + int nVal = 0; /* Number of function arguments */ | |
| 84555 | 84592 | FuncDef *pFunc = 0; /* Function definition */ |
| 84556 | 84593 | sqlite3_value *pVal = 0; /* New value */ |
| 84557 | 84594 | int rc = SQLITE_OK; /* Return code */ |
| 84558 | 84595 | ExprList *pList = 0; /* Function arguments */ |
| 84559 | 84596 | int i; /* Iterator variable */ |
| @@ -85828,11 +85865,11 @@ | ||
| 85828 | 85865 | p->iSub++; |
| 85829 | 85866 | p->iAddr = 0; |
| 85830 | 85867 | } |
| 85831 | 85868 | |
| 85832 | 85869 | if( pRet->p4type==P4_SUBPROGRAM ){ |
| 85833 | - int nByte = (p->nSub+1)*sizeof(SubProgram*); | |
| 85870 | + i64 nByte = (1+(u64)p->nSub)*sizeof(SubProgram*); | |
| 85834 | 85871 | int j; |
| 85835 | 85872 | for(j=0; j<p->nSub; j++){ |
| 85836 | 85873 | if( p->apSub[j]==pRet->p4.pProgram ) break; |
| 85837 | 85874 | } |
| 85838 | 85875 | if( j==p->nSub ){ |
| @@ -85958,12 +85995,12 @@ | ||
| 85958 | 85995 | ** through all the opcodes and fixes up some details. |
| 85959 | 85996 | ** |
| 85960 | 85997 | ** (1) For each jump instruction with a negative P2 value (a label) |
| 85961 | 85998 | ** resolve the P2 value to an actual address. |
| 85962 | 85999 | ** |
| 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. | |
| 85965 | 86002 | ** |
| 85966 | 86003 | ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately |
| 85967 | 86004 | ** indicate what the prepared statement actually does. |
| 85968 | 86005 | ** |
| 85969 | 86006 | ** (4) (discontinued) |
| @@ -85972,12 +86009,12 @@ | ||
| 85972 | 86009 | ** |
| 85973 | 86010 | ** This routine will only function correctly if the mkopcodeh.tcl generator |
| 85974 | 86011 | ** script numbers the opcodes correctly. Changes to this routine must be |
| 85975 | 86012 | ** coordinated with changes to mkopcodeh.tcl. |
| 85976 | 86013 | */ |
| 85977 | -static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ | |
| 85978 | - int nMaxArgs = *pMaxFuncArgs; | |
| 86014 | +static void resolveP2Values(Vdbe *p, int *pMaxVtabArgs){ | |
| 86015 | + int nMaxVtabArgs = *pMaxVtabArgs; | |
| 85979 | 86016 | Op *pOp; |
| 85980 | 86017 | Parse *pParse = p->pParse; |
| 85981 | 86018 | int *aLabel = pParse->aLabel; |
| 85982 | 86019 | |
| 85983 | 86020 | assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */ |
| @@ -86018,19 +86055,23 @@ | ||
| 86018 | 86055 | assert( pOp->p2>=0 ); |
| 86019 | 86056 | goto resolve_p2_values_loop_exit; |
| 86020 | 86057 | } |
| 86021 | 86058 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 86022 | 86059 | case OP_VUpdate: { |
| 86023 | - if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; | |
| 86060 | + if( pOp->p2>nMaxVtabArgs ) nMaxVtabArgs = pOp->p2; | |
| 86024 | 86061 | break; |
| 86025 | 86062 | } |
| 86026 | 86063 | case OP_VFilter: { |
| 86027 | 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. */ | |
| 86028 | 86068 | assert( (pOp - p->aOp) >= 3 ); |
| 86029 | 86069 | assert( pOp[-1].opcode==OP_Integer ); |
| 86070 | + assert( pOp[-1].p2==pOp->p3+1 ); | |
| 86030 | 86071 | n = pOp[-1].p1; |
| 86031 | - if( n>nMaxArgs ) nMaxArgs = n; | |
| 86072 | + if( n>nMaxVtabArgs ) nMaxVtabArgs = n; | |
| 86032 | 86073 | /* Fall through into the default case */ |
| 86033 | 86074 | /* no break */ deliberate_fall_through |
| 86034 | 86075 | } |
| 86035 | 86076 | #endif |
| 86036 | 86077 | default: { |
| @@ -86067,11 +86108,11 @@ | ||
| 86067 | 86108 | if( aLabel ){ |
| 86068 | 86109 | sqlite3DbNNFreeNN(p->db, pParse->aLabel); |
| 86069 | 86110 | pParse->aLabel = 0; |
| 86070 | 86111 | } |
| 86071 | 86112 | pParse->nLabel = 0; |
| 86072 | - *pMaxFuncArgs = nMaxArgs; | |
| 86113 | + *pMaxVtabArgs = nMaxVtabArgs; | |
| 86073 | 86114 | assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) ); |
| 86074 | 86115 | } |
| 86075 | 86116 | |
| 86076 | 86117 | #ifdef SQLITE_DEBUG |
| 86077 | 86118 | /* |
| @@ -86296,11 +86337,11 @@ | ||
| 86296 | 86337 | int addrVisit, /* Address of rows visited counter */ |
| 86297 | 86338 | LogEst nEst, /* Estimated number of output rows */ |
| 86298 | 86339 | const char *zName /* Name of table or index being scanned */ |
| 86299 | 86340 | ){ |
| 86300 | 86341 | if( IS_STMT_SCANSTATUS(p->db) ){ |
| 86301 | - sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus); | |
| 86342 | + i64 nByte = (1+(i64)p->nScan) * sizeof(ScanStatus); | |
| 86302 | 86343 | ScanStatus *aNew; |
| 86303 | 86344 | aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte); |
| 86304 | 86345 | if( aNew ){ |
| 86305 | 86346 | ScanStatus *pNew = &aNew[p->nScan++]; |
| 86306 | 86347 | memset(pNew, 0, sizeof(ScanStatus)); |
| @@ -87745,11 +87786,11 @@ | ||
| 87745 | 87786 | ){ |
| 87746 | 87787 | sqlite3 *db; /* The database connection */ |
| 87747 | 87788 | int nVar; /* Number of parameters */ |
| 87748 | 87789 | int nMem; /* Number of VM memory registers */ |
| 87749 | 87790 | int nCursor; /* Number of cursors required */ |
| 87750 | - int nArg; /* Number of arguments in subprograms */ | |
| 87791 | + int nArg; /* Max number args to xFilter or xUpdate */ | |
| 87751 | 87792 | int n; /* Loop counter */ |
| 87752 | 87793 | struct ReusableSpace x; /* Reusable bulk memory */ |
| 87753 | 87794 | |
| 87754 | 87795 | assert( p!=0 ); |
| 87755 | 87796 | assert( p->nOp>0 ); |
| @@ -87817,10 +87858,13 @@ | ||
| 87817 | 87858 | p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem)); |
| 87818 | 87859 | p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*)); |
| 87819 | 87860 | p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*)); |
| 87820 | 87861 | } |
| 87821 | 87862 | } |
| 87863 | +#ifdef SQLITE_DEBUG | |
| 87864 | + p->napArg = nArg; | |
| 87865 | +#endif | |
| 87822 | 87866 | |
| 87823 | 87867 | if( db->mallocFailed ){ |
| 87824 | 87868 | p->nVar = 0; |
| 87825 | 87869 | p->nCursor = 0; |
| 87826 | 87870 | p->nMem = 0; |
| @@ -89314,10 +89358,11 @@ | ||
| 89314 | 89358 | SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord( |
| 89315 | 89359 | KeyInfo *pKeyInfo /* Description of the record */ |
| 89316 | 89360 | ){ |
| 89317 | 89361 | UnpackedRecord *p; /* Unpacked record to return */ |
| 89318 | 89362 | int nByte; /* Number of bytes required for *p */ |
| 89363 | + assert( sizeof(UnpackedRecord) + sizeof(Mem)*65536 < 0x7fffffff ); | |
| 89319 | 89364 | nByte = ROUND8P(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1); |
| 89320 | 89365 | p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte); |
| 89321 | 89366 | if( !p ) return 0; |
| 89322 | 89367 | p->aMem = (Mem*)&((char*)p)[ROUND8P(sizeof(UnpackedRecord))]; |
| 89323 | 89368 | assert( pKeyInfo->aSortFlags!=0 ); |
| @@ -92890,11 +92935,13 @@ | ||
| 92890 | 92935 | /* This occurs when the table has been extended using ALTER TABLE |
| 92891 | 92936 | ** ADD COLUMN. The value to return is the default value of the column. */ |
| 92892 | 92937 | Column *pCol = &p->pTab->aCol[iIdx]; |
| 92893 | 92938 | if( pCol->iDflt>0 ){ |
| 92894 | 92939 | 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; | |
| 92896 | 92943 | p->apDflt = (sqlite3_value**)sqlite3DbMallocZero(db, nByte); |
| 92897 | 92944 | if( p->apDflt==0 ) goto preupdate_old_out; |
| 92898 | 92945 | } |
| 92899 | 92946 | if( p->apDflt[iIdx]==0 ){ |
| 92900 | 92947 | sqlite3_value *pVal = 0; |
| @@ -93040,11 +93087,12 @@ | ||
| 93040 | 93087 | ** It is not safe to return a pointer to the memory cell itself as the |
| 93041 | 93088 | ** caller may modify the value text encoding. |
| 93042 | 93089 | */ |
| 93043 | 93090 | assert( p->op==SQLITE_UPDATE ); |
| 93044 | 93091 | 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); | |
| 93046 | 93094 | if( !p->aNew ){ |
| 93047 | 93095 | rc = SQLITE_NOMEM; |
| 93048 | 93096 | goto preupdate_new_out; |
| 93049 | 93097 | } |
| 93050 | 93098 | } |
| @@ -93810,11 +93858,11 @@ | ||
| 93810 | 93858 | ** the top of the register space. Cursor 1 is at Mem[p->nMem-1]. |
| 93811 | 93859 | ** Cursor 2 is at Mem[p->nMem-2]. And so forth. |
| 93812 | 93860 | */ |
| 93813 | 93861 | Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem; |
| 93814 | 93862 | |
| 93815 | - int nByte; | |
| 93863 | + i64 nByte; | |
| 93816 | 93864 | VdbeCursor *pCx = 0; |
| 93817 | 93865 | nByte = |
| 93818 | 93866 | ROUND8P(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + |
| 93819 | 93867 | (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0); |
| 93820 | 93868 | |
| @@ -93838,11 +93886,11 @@ | ||
| 93838 | 93886 | pMem->z = pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, nByte); |
| 93839 | 93887 | if( pMem->zMalloc==0 ){ |
| 93840 | 93888 | pMem->szMalloc = 0; |
| 93841 | 93889 | return 0; |
| 93842 | 93890 | } |
| 93843 | - pMem->szMalloc = nByte; | |
| 93891 | + pMem->szMalloc = (int)nByte; | |
| 93844 | 93892 | } |
| 93845 | 93893 | |
| 93846 | 93894 | p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc; |
| 93847 | 93895 | memset(pCx, 0, offsetof(VdbeCursor,pAltCursor)); |
| 93848 | 93896 | pCx->eCurType = eCurType; |
| @@ -100859,11 +100907,11 @@ | ||
| 100859 | 100907 | ** |
| 100860 | 100908 | ** If P5 is non-zero, then recursive program invocation is enabled. |
| 100861 | 100909 | */ |
| 100862 | 100910 | case OP_Program: { /* jump0 */ |
| 100863 | 100911 | 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 */ | |
| 100865 | 100913 | Mem *pRt; /* Register to allocate runtime space */ |
| 100866 | 100914 | Mem *pMem; /* Used to iterate through memory cells */ |
| 100867 | 100915 | Mem *pEnd; /* Last memory cell in new array */ |
| 100868 | 100916 | VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 100869 | 100917 | SubProgram *pProgram; /* Sub-program to execute */ |
| @@ -100910,19 +100958,19 @@ | ||
| 100910 | 100958 | assert( nMem>0 ); |
| 100911 | 100959 | if( pProgram->nCsr==0 ) nMem++; |
| 100912 | 100960 | nByte = ROUND8(sizeof(VdbeFrame)) |
| 100913 | 100961 | + nMem * sizeof(Mem) |
| 100914 | 100962 | + pProgram->nCsr * sizeof(VdbeCursor*) |
| 100915 | - + (pProgram->nOp + 7)/8; | |
| 100963 | + + (7 + (i64)pProgram->nOp)/8; | |
| 100916 | 100964 | pFrame = sqlite3DbMallocZero(db, nByte); |
| 100917 | 100965 | if( !pFrame ){ |
| 100918 | 100966 | goto no_mem; |
| 100919 | 100967 | } |
| 100920 | 100968 | sqlite3VdbeMemRelease(pRt); |
| 100921 | 100969 | pRt->flags = MEM_Blob|MEM_Dyn; |
| 100922 | 100970 | pRt->z = (char*)pFrame; |
| 100923 | - pRt->n = nByte; | |
| 100971 | + pRt->n = (int)nByte; | |
| 100924 | 100972 | pRt->xDel = sqlite3VdbeFrameMemDel; |
| 100925 | 100973 | |
| 100926 | 100974 | pFrame->v = p; |
| 100927 | 100975 | pFrame->nChildMem = nMem; |
| 100928 | 100976 | pFrame->nChildCsr = pProgram->nCsr; |
| @@ -101017,16 +101065,18 @@ | ||
| 101017 | 101065 | ** If P1 is non-zero, the database constraint counter is incremented |
| 101018 | 101066 | ** (deferred foreign key constraints). Otherwise, if P1 is zero, the |
| 101019 | 101067 | ** statement counter is incremented (immediate foreign key constraints). |
| 101020 | 101068 | */ |
| 101021 | 101069 | case OP_FkCounter: { |
| 101022 | - if( db->flags & SQLITE_DeferFKs ){ | |
| 101023 | - db->nDeferredImmCons += pOp->p2; | |
| 101024 | - }else if( pOp->p1 ){ | |
| 101070 | + if( pOp->p1 ){ | |
| 101025 | 101071 | db->nDeferredCons += pOp->p2; |
| 101026 | 101072 | }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 | + } | |
| 101028 | 101078 | } |
| 101029 | 101079 | break; |
| 101030 | 101080 | } |
| 101031 | 101081 | |
| 101032 | 101082 | /* Opcode: FkIfZero P1 P2 * * * |
| @@ -101897,10 +101947,11 @@ | ||
| 101897 | 101947 | nArg = (int)pArgc->u.i; |
| 101898 | 101948 | iQuery = (int)pQuery->u.i; |
| 101899 | 101949 | |
| 101900 | 101950 | /* Invoke the xFilter method */ |
| 101901 | 101951 | apArg = p->apArg; |
| 101952 | + assert( nArg<=p->napArg ); | |
| 101902 | 101953 | for(i = 0; i<nArg; i++){ |
| 101903 | 101954 | apArg[i] = &pArgc[i+1]; |
| 101904 | 101955 | } |
| 101905 | 101956 | rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg); |
| 101906 | 101957 | sqlite3VtabImportErrmsg(p, pVtab); |
| @@ -102107,10 +102158,11 @@ | ||
| 102107 | 102158 | assert( pOp->p4type==P4_VTAB ); |
| 102108 | 102159 | if( ALWAYS(pModule->xUpdate) ){ |
| 102109 | 102160 | u8 vtabOnConflict = db->vtabOnConflict; |
| 102110 | 102161 | apArg = p->apArg; |
| 102111 | 102162 | pX = &aMem[pOp->p3]; |
| 102163 | + assert( nArg<=p->napArg ); | |
| 102112 | 102164 | for(i=0; i<nArg; i++){ |
| 102113 | 102165 | assert( memIsValid(pX) ); |
| 102114 | 102166 | memAboutToChange(p, pX); |
| 102115 | 102167 | apArg[i] = pX; |
| 102116 | 102168 | pX++; |
| @@ -102952,16 +103004,12 @@ | ||
| 102952 | 103004 | } |
| 102953 | 103005 | pBlob->pTab = pTab; |
| 102954 | 103006 | pBlob->zDb = db->aDb[sqlite3SchemaToIndex(db, pTab->pSchema)].zDbSName; |
| 102955 | 103007 | |
| 102956 | 103008 | /* 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 ){ | |
| 102963 | 103011 | sqlite3DbFree(db, zErr); |
| 102964 | 103012 | zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn); |
| 102965 | 103013 | rc = SQLITE_ERROR; |
| 102966 | 103014 | sqlite3BtreeLeaveAll(db); |
| 102967 | 103015 | goto blob_open_out; |
| @@ -104219,11 +104267,11 @@ | ||
| 104219 | 104267 | int pgsz; /* Page size of main database */ |
| 104220 | 104268 | int i; /* Used to iterate through aTask[] */ |
| 104221 | 104269 | VdbeSorter *pSorter; /* The new sorter */ |
| 104222 | 104270 | KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */ |
| 104223 | 104271 | int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */ |
| 104224 | - int sz; /* Size of pSorter in bytes */ | |
| 104272 | + i64 sz; /* Size of pSorter in bytes */ | |
| 104225 | 104273 | int rc = SQLITE_OK; |
| 104226 | 104274 | #if SQLITE_MAX_WORKER_THREADS==0 |
| 104227 | 104275 | # define nWorker 0 |
| 104228 | 104276 | #else |
| 104229 | 104277 | int nWorker; |
| @@ -104247,10 +104295,12 @@ | ||
| 104247 | 104295 | #endif |
| 104248 | 104296 | |
| 104249 | 104297 | assert( pCsr->pKeyInfo ); |
| 104250 | 104298 | assert( !pCsr->isEphemeral ); |
| 104251 | 104299 | assert( pCsr->eCurType==CURTYPE_SORTER ); |
| 104300 | + assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*) | |
| 104301 | + < 0x7fffffff ); | |
| 104252 | 104302 | szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*); |
| 104253 | 104303 | sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask); |
| 104254 | 104304 | |
| 104255 | 104305 | pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo); |
| 104256 | 104306 | pCsr->uc.pSorter = pSorter; |
| @@ -104460,11 +104510,11 @@ | ||
| 104460 | 104510 | ** nReader is automatically rounded up to the next power of two. |
| 104461 | 104511 | ** nReader may not exceed SORTER_MAX_MERGE_COUNT even after rounding up. |
| 104462 | 104512 | */ |
| 104463 | 104513 | static MergeEngine *vdbeMergeEngineNew(int nReader){ |
| 104464 | 104514 | 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 */ | |
| 104466 | 104516 | MergeEngine *pNew; /* Pointer to allocated object to return */ |
| 104467 | 104517 | |
| 104468 | 104518 | assert( nReader<=SORTER_MAX_MERGE_COUNT ); |
| 104469 | 104519 | |
| 104470 | 104520 | while( N<nReader ) N += N; |
| @@ -107503,11 +107553,10 @@ | ||
| 107503 | 107553 | SrcItem *pMatch = 0; /* The matching pSrcList item */ |
| 107504 | 107554 | NameContext *pTopNC = pNC; /* First namecontext in the list */ |
| 107505 | 107555 | Schema *pSchema = 0; /* Schema of the expression */ |
| 107506 | 107556 | int eNewExprOp = TK_COLUMN; /* New value for pExpr->op on success */ |
| 107507 | 107557 | Table *pTab = 0; /* Table holding the row */ |
| 107508 | - Column *pCol; /* A column of pTab */ | |
| 107509 | 107558 | ExprList *pFJMatch = 0; /* Matches for FULL JOIN .. USING */ |
| 107510 | 107559 | const char *zCol = pRight->u.zToken; |
| 107511 | 107560 | |
| 107512 | 107561 | assert( pNC ); /* the name context cannot be NULL. */ |
| 107513 | 107562 | assert( zCol ); /* The Z in X.Y.Z cannot be NULL */ |
| @@ -107554,11 +107603,10 @@ | ||
| 107554 | 107603 | ExprList *pEList; |
| 107555 | 107604 | SrcList *pSrcList = pNC->pSrcList; |
| 107556 | 107605 | |
| 107557 | 107606 | if( pSrcList ){ |
| 107558 | 107607 | for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){ |
| 107559 | - u8 hCol; | |
| 107560 | 107608 | pTab = pItem->pSTab; |
| 107561 | 107609 | assert( pTab!=0 && pTab->zName!=0 ); |
| 107562 | 107610 | assert( pTab->nCol>0 || pParse->nErr ); |
| 107563 | 107611 | assert( (int)pItem->fg.isNestedFrom == IsNestedFrom(pItem)); |
| 107564 | 107612 | if( pItem->fg.isNestedFrom ){ |
| @@ -107642,47 +107690,42 @@ | ||
| 107642 | 107690 | assert( ExprUseYTab(pExpr) ); |
| 107643 | 107691 | if( IN_RENAME_OBJECT && pItem->zAlias ){ |
| 107644 | 107692 | sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); |
| 107645 | 107693 | } |
| 107646 | 107694 | } |
| 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); | |
| 107684 | 107727 | } |
| 107685 | 107728 | } |
| 107686 | 107729 | if( 0==cnt && VisibleRowid(pTab) ){ |
| 107687 | 107730 | /* pTab is a potential ROWID match. Keep track of it and match |
| 107688 | 107731 | ** the ROWID later if that seems appropriate. (Search for "cntTab" |
| @@ -107768,26 +107811,21 @@ | ||
| 107768 | 107811 | } |
| 107769 | 107812 | #endif /* SQLITE_OMIT_UPSERT */ |
| 107770 | 107813 | |
| 107771 | 107814 | if( pTab ){ |
| 107772 | 107815 | int iCol; |
| 107773 | - u8 hCol = sqlite3StrIHash(zCol); | |
| 107774 | 107816 | pSchema = pTab->pSchema; |
| 107775 | 107817 | 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 | + } | |
| 107789 | 107827 | } |
| 107790 | 107828 | if( iCol<pTab->nCol ){ |
| 107791 | 107829 | cnt++; |
| 107792 | 107830 | pMatch = 0; |
| 107793 | 107831 | #ifndef SQLITE_OMIT_UPSERT |
| @@ -111379,11 +111417,10 @@ | ||
| 111379 | 111417 | pNewExpr->pLeft = pPriorSelectColNew; |
| 111380 | 111418 | } |
| 111381 | 111419 | } |
| 111382 | 111420 | pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName); |
| 111383 | 111421 | pItem->fg = pOldItem->fg; |
| 111384 | - pItem->fg.done = 0; | |
| 111385 | 111422 | pItem->u = pOldItem->u; |
| 111386 | 111423 | } |
| 111387 | 111424 | return pNew; |
| 111388 | 111425 | } |
| 111389 | 111426 | |
| @@ -112496,17 +112533,11 @@ | ||
| 112496 | 112533 | SQLITE_PRIVATE const char *sqlite3RowidAlias(Table *pTab){ |
| 112497 | 112534 | const char *azOpt[] = {"_ROWID_", "ROWID", "OID"}; |
| 112498 | 112535 | int ii; |
| 112499 | 112536 | assert( VisibleRowid(pTab) ); |
| 112500 | 112537 | 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]; | |
| 112508 | 112539 | } |
| 112509 | 112540 | return 0; |
| 112510 | 112541 | } |
| 112511 | 112542 | |
| 112512 | 112543 | /* |
| @@ -112906,11 +112937,11 @@ | ||
| 112906 | 112937 | int nVal = sqlite3ExprVectorSize(pLeft); |
| 112907 | 112938 | Select *pSelect = ExprUseXSelect(pExpr) ? pExpr->x.pSelect : 0; |
| 112908 | 112939 | char *zRet; |
| 112909 | 112940 | |
| 112910 | 112941 | assert( pExpr->op==TK_IN ); |
| 112911 | - zRet = sqlite3DbMallocRaw(pParse->db, nVal+1); | |
| 112942 | + zRet = sqlite3DbMallocRaw(pParse->db, 1+(i64)nVal); | |
| 112912 | 112943 | if( zRet ){ |
| 112913 | 112944 | int i; |
| 112914 | 112945 | for(i=0; i<nVal; i++){ |
| 112915 | 112946 | Expr *pA = sqlite3VectorFieldSubexpr(pLeft, i); |
| 112916 | 112947 | char a = sqlite3ExprAffinity(pA); |
| @@ -117551,14 +117582,12 @@ | ||
| 117551 | 117582 | |
| 117552 | 117583 | /* Make sure the old name really is a column name in the table to be |
| 117553 | 117584 | ** altered. Set iCol to be the index of the column being renamed */ |
| 117554 | 117585 | zOld = sqlite3NameFromToken(db, pOld); |
| 117555 | 117586 | 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 ){ | |
| 117560 | 117589 | sqlite3ErrorMsg(pParse, "no such column: \"%T\"", pOld); |
| 117561 | 117590 | goto exit_rename_column; |
| 117562 | 117591 | } |
| 117563 | 117592 | |
| 117564 | 117593 | /* Ensure the schema contains no double-quoted strings */ |
| @@ -119453,11 +119482,12 @@ | ||
| 119453 | 119482 | ** of the new table in register pParse->regRoot. This is important |
| 119454 | 119483 | ** because the OpenWrite opcode below will be needing it. */ |
| 119455 | 119484 | sqlite3NestedParse(pParse, |
| 119456 | 119485 | "CREATE TABLE %Q.%s(%s)", pDb->zDbSName, zTab, aTable[i].zCols |
| 119457 | 119486 | ); |
| 119458 | - aRoot[i] = (u32)pParse->regRoot; | |
| 119487 | + assert( pParse->isCreate || pParse->nErr ); | |
| 119488 | + aRoot[i] = (u32)pParse->u1.cr.regRoot; | |
| 119459 | 119489 | aCreateTbl[i] = OPFLAG_P2ISREG; |
| 119460 | 119490 | } |
| 119461 | 119491 | }else{ |
| 119462 | 119492 | /* The table already exists. If zWhere is not NULL, delete all entries |
| 119463 | 119493 | ** associated with the table zWhere. If zWhere is NULL, delete the |
| @@ -119644,11 +119674,11 @@ | ||
| 119644 | 119674 | ){ |
| 119645 | 119675 | StatAccum *p; |
| 119646 | 119676 | int nCol; /* Number of columns in index being sampled */ |
| 119647 | 119677 | int nKeyCol; /* Number of key columns */ |
| 119648 | 119678 | int nColUp; /* nCol rounded up for alignment */ |
| 119649 | - int n; /* Bytes of space to allocate */ | |
| 119679 | + i64 n; /* Bytes of space to allocate */ | |
| 119650 | 119680 | sqlite3 *db = sqlite3_context_db_handle(context); /* Database connection */ |
| 119651 | 119681 | #ifdef SQLITE_ENABLE_STAT4 |
| 119652 | 119682 | /* Maximum number of samples. 0 if STAT4 data is not collected */ |
| 119653 | 119683 | int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0; |
| 119654 | 119684 | #endif |
| @@ -121418,11 +121448,11 @@ | ||
| 121418 | 121448 | if( db->aDb==db->aDbStatic ){ |
| 121419 | 121449 | aNew = sqlite3DbMallocRawNN(db, sizeof(db->aDb[0])*3 ); |
| 121420 | 121450 | if( aNew==0 ) return; |
| 121421 | 121451 | memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2); |
| 121422 | 121452 | }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)); | |
| 121424 | 121454 | if( aNew==0 ) return; |
| 121425 | 121455 | } |
| 121426 | 121456 | db->aDb = aNew; |
| 121427 | 121457 | pNew = &db->aDb[db->nDb]; |
| 121428 | 121458 | memset(pNew, 0, sizeof(*pNew)); |
| @@ -122211,10 +122241,11 @@ | ||
| 122211 | 122241 | p->isWriteLock = (p->isWriteLock || isWriteLock); |
| 122212 | 122242 | return; |
| 122213 | 122243 | } |
| 122214 | 122244 | } |
| 122215 | 122245 | |
| 122246 | + assert( pToplevel->nTableLock < 0x7fff0000 ); | |
| 122216 | 122247 | nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1); |
| 122217 | 122248 | pToplevel->aTableLock = |
| 122218 | 122249 | sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes); |
| 122219 | 122250 | if( pToplevel->aTableLock ){ |
| 122220 | 122251 | p = &pToplevel->aTableLock[pToplevel->nTableLock++]; |
| @@ -122311,14 +122342,16 @@ | ||
| 122311 | 122342 | } |
| 122312 | 122343 | assert( !pParse->isMultiWrite |
| 122313 | 122344 | || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort)); |
| 122314 | 122345 | if( v ){ |
| 122315 | 122346 | if( pParse->bReturning ){ |
| 122316 | - Returning *pReturning = pParse->u1.pReturning; | |
| 122347 | + Returning *pReturning; | |
| 122317 | 122348 | int addrRewind; |
| 122318 | 122349 | int reg; |
| 122319 | 122350 | |
| 122351 | + assert( !pParse->isCreate ); | |
| 122352 | + pReturning = pParse->u1.d.pReturning; | |
| 122320 | 122353 | if( pReturning->nRetCol ){ |
| 122321 | 122354 | sqlite3VdbeAddOp0(v, OP_FkCheck); |
| 122322 | 122355 | addrRewind = |
| 122323 | 122356 | sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); |
| 122324 | 122357 | VdbeCoverage(v); |
| @@ -122390,11 +122423,13 @@ | ||
| 122390 | 122423 | sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg); |
| 122391 | 122424 | } |
| 122392 | 122425 | } |
| 122393 | 122426 | |
| 122394 | 122427 | if( pParse->bReturning ){ |
| 122395 | - Returning *pRet = pParse->u1.pReturning; | |
| 122428 | + Returning *pRet; | |
| 122429 | + assert( !pParse->isCreate ); | |
| 122430 | + pRet = pParse->u1.d.pReturning; | |
| 122396 | 122431 | if( pRet->nRetCol ){ |
| 122397 | 122432 | sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); |
| 122398 | 122433 | } |
| 122399 | 122434 | } |
| 122400 | 122435 | |
| @@ -123462,12 +123497,13 @@ | ||
| 123462 | 123497 | #endif |
| 123463 | 123498 | |
| 123464 | 123499 | /* If the file format and encoding in the database have not been set, |
| 123465 | 123500 | ** set them now. |
| 123466 | 123501 | */ |
| 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; | |
| 123469 | 123505 | reg3 = ++pParse->nMem; |
| 123470 | 123506 | sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT); |
| 123471 | 123507 | sqlite3VdbeUsesBtree(v, iDb); |
| 123472 | 123508 | addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v); |
| 123473 | 123509 | fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ? |
| @@ -123478,12 +123514,12 @@ | ||
| 123478 | 123514 | |
| 123479 | 123515 | /* This just creates a place-holder record in the sqlite_schema table. |
| 123480 | 123516 | ** The record created does not contain anything yet. It will be replaced |
| 123481 | 123517 | ** by the real entry in code generated at sqlite3EndTable(). |
| 123482 | 123518 | ** |
| 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. | |
| 123485 | 123521 | ** The rowid and root page number values are needed by the code that |
| 123486 | 123522 | ** sqlite3EndTable will generate. |
| 123487 | 123523 | */ |
| 123488 | 123524 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 123489 | 123525 | if( isView || isVirtual ){ |
| @@ -123490,11 +123526,11 @@ | ||
| 123490 | 123526 | sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2); |
| 123491 | 123527 | }else |
| 123492 | 123528 | #endif |
| 123493 | 123529 | { |
| 123494 | 123530 | assert( !pParse->bReturning ); |
| 123495 | - pParse->u1.addrCrTab = | |
| 123531 | + pParse->u1.cr.addrCrTab = | |
| 123496 | 123532 | sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY); |
| 123497 | 123533 | } |
| 123498 | 123534 | sqlite3OpenSchemaTable(pParse, iDb); |
| 123499 | 123535 | sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1); |
| 123500 | 123536 | sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC); |
| @@ -123568,11 +123604,12 @@ | ||
| 123568 | 123604 | pRet = sqlite3DbMallocZero(db, sizeof(*pRet)); |
| 123569 | 123605 | if( pRet==0 ){ |
| 123570 | 123606 | sqlite3ExprListDelete(db, pList); |
| 123571 | 123607 | return; |
| 123572 | 123608 | } |
| 123573 | - pParse->u1.pReturning = pRet; | |
| 123609 | + assert( !pParse->isCreate ); | |
| 123610 | + pParse->u1.d.pReturning = pRet; | |
| 123574 | 123611 | pRet->pParse = pParse; |
| 123575 | 123612 | pRet->pReturnEL = pList; |
| 123576 | 123613 | sqlite3ParserAddCleanup(pParse, sqlite3DeleteReturning, pRet); |
| 123577 | 123614 | testcase( pParse->earlyCleanup ); |
| 123578 | 123615 | if( db->mallocFailed ) return; |
| @@ -123610,11 +123647,10 @@ | ||
| 123610 | 123647 | int i; |
| 123611 | 123648 | char *z; |
| 123612 | 123649 | char *zType; |
| 123613 | 123650 | Column *pCol; |
| 123614 | 123651 | sqlite3 *db = pParse->db; |
| 123615 | - u8 hName; | |
| 123616 | 123652 | Column *aNew; |
| 123617 | 123653 | u8 eType = COLTYPE_CUSTOM; |
| 123618 | 123654 | u8 szEst = 1; |
| 123619 | 123655 | char affinity = SQLITE_AFF_BLOB; |
| 123620 | 123656 | |
| @@ -123664,17 +123700,14 @@ | ||
| 123664 | 123700 | if( z==0 ) return; |
| 123665 | 123701 | if( IN_RENAME_OBJECT ) sqlite3RenameTokenMap(pParse, (void*)z, &sName); |
| 123666 | 123702 | memcpy(z, sName.z, sName.n); |
| 123667 | 123703 | z[sName.n] = 0; |
| 123668 | 123704 | 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; | |
| 123676 | 123709 | } |
| 123677 | 123710 | aNew = sqlite3DbRealloc(db,p->aCol,((i64)p->nCol+1)*sizeof(p->aCol[0])); |
| 123678 | 123711 | if( aNew==0 ){ |
| 123679 | 123712 | sqlite3DbFree(db, z); |
| 123680 | 123713 | return; |
| @@ -123681,11 +123714,11 @@ | ||
| 123681 | 123714 | } |
| 123682 | 123715 | p->aCol = aNew; |
| 123683 | 123716 | pCol = &p->aCol[p->nCol]; |
| 123684 | 123717 | memset(pCol, 0, sizeof(p->aCol[0])); |
| 123685 | 123718 | pCol->zCnName = z; |
| 123686 | - pCol->hName = hName; | |
| 123719 | + pCol->hName = sqlite3StrIHash(z); | |
| 123687 | 123720 | sqlite3ColumnPropertiesFromName(p, pCol); |
| 123688 | 123721 | |
| 123689 | 123722 | if( sType.n==0 ){ |
| 123690 | 123723 | /* If there is no type specified, columns have the default affinity |
| 123691 | 123724 | ** 'BLOB' with a default size of 4 bytes. */ |
| @@ -123705,13 +123738,18 @@ | ||
| 123705 | 123738 | zType[sType.n] = 0; |
| 123706 | 123739 | sqlite3Dequote(zType); |
| 123707 | 123740 | pCol->affinity = sqlite3AffinityType(zType, pCol); |
| 123708 | 123741 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 123709 | 123742 | } |
| 123743 | + if( p->nCol<=0xff ){ | |
| 123744 | + u8 h = pCol->hName % sizeof(p->aHx); | |
| 123745 | + p->aHx[h] = p->nCol; | |
| 123746 | + } | |
| 123710 | 123747 | p->nCol++; |
| 123711 | 123748 | p->nNVCol++; |
| 123712 | - pParse->constraintName.n = 0; | |
| 123749 | + assert( pParse->isCreate ); | |
| 123750 | + pParse->u1.cr.constraintName.n = 0; | |
| 123713 | 123751 | } |
| 123714 | 123752 | |
| 123715 | 123753 | /* |
| 123716 | 123754 | ** This routine is called by the parser while in the middle of |
| 123717 | 123755 | ** parsing a CREATE TABLE statement. A "NOT NULL" constraint has |
| @@ -123971,19 +124009,15 @@ | ||
| 123971 | 124009 | for(i=0; i<nTerm; i++){ |
| 123972 | 124010 | Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr); |
| 123973 | 124011 | assert( pCExpr!=0 ); |
| 123974 | 124012 | sqlite3StringToId(pCExpr); |
| 123975 | 124013 | if( pCExpr->op==TK_ID ){ |
| 123976 | - const char *zCName; | |
| 123977 | 124014 | 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); | |
| 123985 | 124019 | } |
| 123986 | 124020 | } |
| 123987 | 124021 | } |
| 123988 | 124022 | } |
| 123989 | 124023 | if( nTerm==1 |
| @@ -124031,12 +124065,14 @@ | ||
| 124031 | 124065 | sqlite3 *db = pParse->db; |
| 124032 | 124066 | if( pTab && !IN_DECLARE_VTAB |
| 124033 | 124067 | && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt) |
| 124034 | 124068 | ){ |
| 124035 | 124069 | 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); | |
| 124038 | 124074 | }else{ |
| 124039 | 124075 | Token t; |
| 124040 | 124076 | for(zStart++; sqlite3Isspace(zStart[0]); zStart++){} |
| 124041 | 124077 | while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; } |
| 124042 | 124078 | t.z = zStart; |
| @@ -124227,11 +124263,12 @@ | ||
| 124227 | 124263 | ** Generate a CREATE TABLE statement appropriate for the given |
| 124228 | 124264 | ** table. Memory to hold the text of the statement is obtained |
| 124229 | 124265 | ** from sqliteMalloc() and must be freed by the calling function. |
| 124230 | 124266 | */ |
| 124231 | 124267 | static char *createTableStmt(sqlite3 *db, Table *p){ |
| 124232 | - int i, k, n; | |
| 124268 | + int i, k, len; | |
| 124269 | + i64 n; | |
| 124233 | 124270 | char *zStmt; |
| 124234 | 124271 | char *zSep, *zSep2, *zEnd; |
| 124235 | 124272 | Column *pCol; |
| 124236 | 124273 | n = 0; |
| 124237 | 124274 | for(pCol = p->aCol, i=0; i<p->nCol; i++, pCol++){ |
| @@ -124251,12 +124288,13 @@ | ||
| 124251 | 124288 | zStmt = sqlite3DbMallocRaw(0, n); |
| 124252 | 124289 | if( zStmt==0 ){ |
| 124253 | 124290 | sqlite3OomFault(db); |
| 124254 | 124291 | return 0; |
| 124255 | 124292 | } |
| 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; | |
| 124258 | 124296 | identPut(zStmt, &k, p->zName); |
| 124259 | 124297 | zStmt[k++] = '('; |
| 124260 | 124298 | for(pCol=p->aCol, i=0; i<p->nCol; i++, pCol++){ |
| 124261 | 124299 | static const char * const azType[] = { |
| 124262 | 124300 | /* SQLITE_AFF_BLOB */ "", |
| @@ -124264,17 +124302,19 @@ | ||
| 124264 | 124302 | /* SQLITE_AFF_NUMERIC */ " NUM", |
| 124265 | 124303 | /* SQLITE_AFF_INTEGER */ " INT", |
| 124266 | 124304 | /* SQLITE_AFF_REAL */ " REAL", |
| 124267 | 124305 | /* SQLITE_AFF_FLEXNUM */ " NUM", |
| 124268 | 124306 | }; |
| 124269 | - int len; | |
| 124270 | 124307 | const char *zType; |
| 124271 | 124308 | |
| 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; | |
| 124274 | 124313 | zSep = zSep2; |
| 124275 | 124314 | identPut(zStmt, &k, pCol->zCnName); |
| 124315 | + assert( k<n ); | |
| 124276 | 124316 | assert( pCol->affinity-SQLITE_AFF_BLOB >= 0 ); |
| 124277 | 124317 | assert( pCol->affinity-SQLITE_AFF_BLOB < ArraySize(azType) ); |
| 124278 | 124318 | testcase( pCol->affinity==SQLITE_AFF_BLOB ); |
| 124279 | 124319 | testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 124280 | 124320 | testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); |
| @@ -124285,15 +124325,18 @@ | ||
| 124285 | 124325 | zType = azType[pCol->affinity - SQLITE_AFF_BLOB]; |
| 124286 | 124326 | len = sqlite3Strlen30(zType); |
| 124287 | 124327 | assert( pCol->affinity==SQLITE_AFF_BLOB |
| 124288 | 124328 | || pCol->affinity==SQLITE_AFF_FLEXNUM |
| 124289 | 124329 | || pCol->affinity==sqlite3AffinityType(zType, 0) ); |
| 124330 | + assert( k+len<n ); | |
| 124290 | 124331 | memcpy(&zStmt[k], zType, len); |
| 124291 | 124332 | k += len; |
| 124292 | 124333 | assert( k<=n ); |
| 124293 | 124334 | } |
| 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); | |
| 124295 | 124338 | return zStmt; |
| 124296 | 124339 | } |
| 124297 | 124340 | |
| 124298 | 124341 | /* |
| 124299 | 124342 | ** Resize an Index object to hold N columns total. Return SQLITE_OK |
| @@ -124482,13 +124525,13 @@ | ||
| 124482 | 124525 | |
| 124483 | 124526 | /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY |
| 124484 | 124527 | ** into BTREE_BLOBKEY. |
| 124485 | 124528 | */ |
| 124486 | 124529 | assert( !pParse->bReturning ); |
| 124487 | - if( pParse->u1.addrCrTab ){ | |
| 124530 | + if( pParse->u1.cr.addrCrTab ){ | |
| 124488 | 124531 | assert( v ); |
| 124489 | - sqlite3VdbeChangeP3(v, pParse->u1.addrCrTab, BTREE_BLOBKEY); | |
| 124532 | + sqlite3VdbeChangeP3(v, pParse->u1.cr.addrCrTab, BTREE_BLOBKEY); | |
| 124490 | 124533 | } |
| 124491 | 124534 | |
| 124492 | 124535 | /* Locate the PRIMARY KEY index. Or, if this table was originally |
| 124493 | 124536 | ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index. |
| 124494 | 124537 | */ |
| @@ -124924,11 +124967,11 @@ | ||
| 124924 | 124967 | #endif |
| 124925 | 124968 | } |
| 124926 | 124969 | |
| 124927 | 124970 | /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT |
| 124928 | 124971 | ** 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. | |
| 124930 | 124973 | ** |
| 124931 | 124974 | ** Once the SELECT has been coded by sqlite3Select(), it is in a |
| 124932 | 124975 | ** suitable state to query for the column names and types to be used |
| 124933 | 124976 | ** by the new table. |
| 124934 | 124977 | ** |
| @@ -124955,11 +124998,12 @@ | ||
| 124955 | 124998 | iCsr = pParse->nTab++; |
| 124956 | 124999 | regYield = ++pParse->nMem; |
| 124957 | 125000 | regRec = ++pParse->nMem; |
| 124958 | 125001 | regRowid = ++pParse->nMem; |
| 124959 | 125002 | 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); | |
| 124961 | 125005 | sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG); |
| 124962 | 125006 | addrTop = sqlite3VdbeCurrentAddr(v) + 1; |
| 124963 | 125007 | sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); |
| 124964 | 125008 | if( pParse->nErr ) return; |
| 124965 | 125009 | pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB); |
| @@ -125000,21 +125044,22 @@ | ||
| 125000 | 125044 | |
| 125001 | 125045 | /* A slot for the record has already been allocated in the |
| 125002 | 125046 | ** schema table. We just need to update that slot with all |
| 125003 | 125047 | ** the information we've collected. |
| 125004 | 125048 | */ |
| 125049 | + assert( pParse->isCreate ); | |
| 125005 | 125050 | sqlite3NestedParse(pParse, |
| 125006 | 125051 | "UPDATE %Q." LEGACY_SCHEMA_TABLE |
| 125007 | 125052 | " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q" |
| 125008 | 125053 | " WHERE rowid=#%d", |
| 125009 | 125054 | db->aDb[iDb].zDbSName, |
| 125010 | 125055 | zType, |
| 125011 | 125056 | p->zName, |
| 125012 | 125057 | p->zName, |
| 125013 | - pParse->regRoot, | |
| 125058 | + pParse->u1.cr.regRoot, | |
| 125014 | 125059 | zStmt, |
| 125015 | - pParse->regRowid | |
| 125060 | + pParse->u1.cr.regRowid | |
| 125016 | 125061 | ); |
| 125017 | 125062 | sqlite3DbFree(db, zStmt); |
| 125018 | 125063 | sqlite3ChangeCookie(pParse, iDb); |
| 125019 | 125064 | |
| 125020 | 125065 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| @@ -125981,11 +126026,11 @@ | ||
| 125981 | 126026 | i16 nCol, /* Total number of columns in the index */ |
| 125982 | 126027 | int nExtra, /* Number of bytes of extra space to alloc */ |
| 125983 | 126028 | char **ppExtra /* Pointer to the "extra" space */ |
| 125984 | 126029 | ){ |
| 125985 | 126030 | 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 */ | |
| 125987 | 126032 | |
| 125988 | 126033 | nByte = ROUND8(sizeof(Index)) + /* Index structure */ |
| 125989 | 126034 | ROUND8(sizeof(char*)*nCol) + /* Index.azColl */ |
| 125990 | 126035 | ROUND8(sizeof(LogEst)*(nCol+1) + /* Index.aiRowLogEst */ |
| 125991 | 126036 | sizeof(i16)*nCol + /* Index.aiColumn */ |
| @@ -129850,15 +129895,10 @@ | ||
| 129850 | 129895 | int len; |
| 129851 | 129896 | int p0type; |
| 129852 | 129897 | i64 p1, p2; |
| 129853 | 129898 | |
| 129854 | 129899 | 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 | 129900 | p0type = sqlite3_value_type(argv[0]); |
| 129861 | 129901 | p1 = sqlite3_value_int64(argv[1]); |
| 129862 | 129902 | if( p0type==SQLITE_BLOB ){ |
| 129863 | 129903 | len = sqlite3_value_bytes(argv[0]); |
| 129864 | 129904 | z = sqlite3_value_blob(argv[0]); |
| @@ -129872,23 +129912,27 @@ | ||
| 129872 | 129912 | for(z2=z; *z2; len++){ |
| 129873 | 129913 | SQLITE_SKIP_UTF8(z2); |
| 129874 | 129914 | } |
| 129875 | 129915 | } |
| 129876 | 129916 | } |
| 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 | 129917 | if( argc==3 ){ |
| 129886 | 129918 | p2 = sqlite3_value_int64(argv[2]); |
| 129919 | + if( p2==0 && sqlite3_value_type(argv[2])==SQLITE_NULL ) return; | |
| 129887 | 129920 | }else{ |
| 129888 | 129921 | p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH]; |
| 129889 | 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 | + } | |
| 129890 | 129934 | if( p1<0 ){ |
| 129891 | 129935 | p1 += len; |
| 129892 | 129936 | if( p1<0 ){ |
| 129893 | 129937 | if( p2<0 ){ |
| 129894 | 129938 | p2 = 0; |
| @@ -130915,11 +130959,11 @@ | ||
| 130915 | 130959 | if( zRep==0 ) return; |
| 130916 | 130960 | nRep = sqlite3_value_bytes(argv[2]); |
| 130917 | 130961 | assert( zRep==sqlite3_value_text(argv[2]) ); |
| 130918 | 130962 | nOut = nStr + 1; |
| 130919 | 130963 | assert( nOut<SQLITE_MAX_LENGTH ); |
| 130920 | - zOut = contextMalloc(context, (i64)nOut); | |
| 130964 | + zOut = contextMalloc(context, nOut); | |
| 130921 | 130965 | if( zOut==0 ){ |
| 130922 | 130966 | return; |
| 130923 | 130967 | } |
| 130924 | 130968 | loopLimit = nStr - nPattern; |
| 130925 | 130969 | cntExpand = 0; |
| @@ -131065,11 +131109,11 @@ | ||
| 131065 | 131109 | int i; |
| 131066 | 131110 | char *z; |
| 131067 | 131111 | for(i=0; i<argc; i++){ |
| 131068 | 131112 | n += sqlite3_value_bytes(argv[i]); |
| 131069 | 131113 | } |
| 131070 | - n += (argc-1)*nSep; | |
| 131114 | + n += (argc-1)*(i64)nSep; | |
| 131071 | 131115 | z = sqlite3_malloc64(n+1); |
| 131072 | 131116 | if( z==0 ){ |
| 131073 | 131117 | sqlite3_result_error_nomem(context); |
| 131074 | 131118 | return; |
| 131075 | 131119 | } |
| @@ -134900,32 +134944,26 @@ | ||
| 134900 | 134944 | bIdListInOrder = (pTab->tabFlags & (TF_OOOHidden|TF_HasStored))==0; |
| 134901 | 134945 | if( pColumn ){ |
| 134902 | 134946 | aTabColMap = sqlite3DbMallocZero(db, pTab->nCol*sizeof(int)); |
| 134903 | 134947 | if( aTabColMap==0 ) goto insert_cleanup; |
| 134904 | 134948 | 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 | + } | |
| 134915 | 134956 | #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 | + } | |
| 134922 | 134963 | #endif |
| 134923 | - break; | |
| 134924 | - } | |
| 134925 | - } | |
| 134926 | - if( j>=pTab->nCol ){ | |
| 134964 | + }else{ | |
| 134927 | 134965 | if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){ |
| 134928 | 134966 | ipkColumn = i; |
| 134929 | 134967 | bIdListInOrder = 0; |
| 134930 | 134968 | }else{ |
| 134931 | 134969 | sqlite3ErrorMsg(pParse, "table %S has no column named %s", |
| @@ -135219,11 +135257,11 @@ | ||
| 135219 | 135257 | sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore); |
| 135220 | 135258 | } |
| 135221 | 135259 | continue; |
| 135222 | 135260 | }else if( pColumn==0 ){ |
| 135223 | 135261 | /* Hidden columns that are not explicitly named in the INSERT |
| 135224 | - ** get there default value */ | |
| 135262 | + ** get their default value */ | |
| 135225 | 135263 | sqlite3ExprCodeFactorable(pParse, |
| 135226 | 135264 | sqlite3ColumnExpr(pTab, &pTab->aCol[i]), |
| 135227 | 135265 | iRegStore); |
| 135228 | 135266 | continue; |
| 135229 | 135267 | } |
| @@ -140832,11 +140870,14 @@ | ||
| 140832 | 140870 | ){ |
| 140833 | 140871 | db->flags |= mask; |
| 140834 | 140872 | } |
| 140835 | 140873 | }else{ |
| 140836 | 140874 | 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 | + } | |
| 140838 | 140879 | if( (mask & SQLITE_WriteSchema)!=0 |
| 140839 | 140880 | && sqlite3_stricmp(zRight, "reset")==0 |
| 140840 | 140881 | ){ |
| 140841 | 140882 | /* IMP: R-60817-01178 If the argument is "RESET" then schema |
| 140842 | 140883 | ** writing is disabled (as with "PRAGMA writable_schema=OFF") and, |
| @@ -144166,14 +144207,37 @@ | ||
| 144166 | 144207 | ** Return the index of a column in a table. Return -1 if the column |
| 144167 | 144208 | ** is not contained in the table. |
| 144168 | 144209 | */ |
| 144169 | 144210 | SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol){ |
| 144170 | 144211 | 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; | |
| 144175 | 144239 | } |
| 144176 | 144240 | return -1; |
| 144177 | 144241 | } |
| 144178 | 144242 | |
| 144179 | 144243 | /* |
| @@ -152891,11 +152955,12 @@ | ||
| 152891 | 152955 | }else if( pTrig->op==TK_RETURNING ){ |
| 152892 | 152956 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 152893 | 152957 | assert( pParse->db->pVtabCtx==0 ); |
| 152894 | 152958 | #endif |
| 152895 | 152959 | assert( pParse->bReturning ); |
| 152896 | - assert( &(pParse->u1.pReturning->retTrig) == pTrig ); | |
| 152960 | + assert( !pParse->isCreate ); | |
| 152961 | + assert( &(pParse->u1.d.pReturning->retTrig) == pTrig ); | |
| 152897 | 152962 | pTrig->table = pTab->zName; |
| 152898 | 152963 | pTrig->pTabSchema = pTab->pSchema; |
| 152899 | 152964 | pTrig->pNext = pList; |
| 152900 | 152965 | pList = pTrig; |
| 152901 | 152966 | } |
| @@ -153868,11 +153933,12 @@ | ||
| 153868 | 153933 | /* This RETURNING trigger must be for a different statement as |
| 153869 | 153934 | ** this statement lacks a RETURNING clause. */ |
| 153870 | 153935 | return; |
| 153871 | 153936 | } |
| 153872 | 153937 | assert( db->pParse==pParse ); |
| 153873 | - pReturning = pParse->u1.pReturning; | |
| 153938 | + assert( !pParse->isCreate ); | |
| 153939 | + pReturning = pParse->u1.d.pReturning; | |
| 153874 | 153940 | if( pTrigger != &(pReturning->retTrig) ){ |
| 153875 | 153941 | /* This RETURNING trigger is for a different statement */ |
| 153876 | 153942 | return; |
| 153877 | 153943 | } |
| 153878 | 153944 | memset(&sSelect, 0, sizeof(sSelect)); |
| @@ -154098,10 +154164,12 @@ | ||
| 154098 | 154164 | sSubParse.pToplevel = pTop; |
| 154099 | 154165 | sSubParse.zAuthContext = pTrigger->zName; |
| 154100 | 154166 | sSubParse.eTriggerOp = pTrigger->op; |
| 154101 | 154167 | sSubParse.nQueryLoop = pParse->nQueryLoop; |
| 154102 | 154168 | sSubParse.prepFlags = pParse->prepFlags; |
| 154169 | + sSubParse.oldmask = 0; | |
| 154170 | + sSubParse.newmask = 0; | |
| 154103 | 154171 | |
| 154104 | 154172 | v = sqlite3GetVdbe(&sSubParse); |
| 154105 | 154173 | if( v ){ |
| 154106 | 154174 | VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)", |
| 154107 | 154175 | pTrigger->zName, onErrorText(orconf), |
| @@ -154852,42 +154920,36 @@ | ||
| 154852 | 154920 | ** column to be updated, make sure we have authorization to change |
| 154853 | 154921 | ** that column. |
| 154854 | 154922 | */ |
| 154855 | 154923 | chngRowid = chngPk = 0; |
| 154856 | 154924 | for(i=0; i<pChanges->nExpr; i++){ |
| 154857 | - u8 hCol = sqlite3StrIHash(pChanges->a[i].zEName); | |
| 154858 | 154925 | /* If this is an UPDATE with a FROM clause, do not resolve expressions |
| 154859 | 154926 | ** here. The call to sqlite3Select() below will do that. */ |
| 154860 | 154927 | if( nChangeFrom==0 && sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){ |
| 154861 | 154928 | goto update_cleanup; |
| 154862 | 154929 | } |
| 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 | + } | |
| 154874 | 154939 | #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 | + } | |
| 154883 | 154948 | #endif |
| 154884 | - aXRef[j] = i; | |
| 154885 | - break; | |
| 154886 | - } | |
| 154887 | - } | |
| 154888 | - if( j>=pTab->nCol ){ | |
| 154949 | + aXRef[j] = i; | |
| 154950 | + }else{ | |
| 154889 | 154951 | if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){ |
| 154890 | 154952 | j = -1; |
| 154891 | 154953 | chngRowid = 1; |
| 154892 | 154954 | pRowidExpr = pChanges->a[i].pExpr; |
| 154893 | 154955 | iRowidExpr = i; |
| @@ -156990,24 +157052,25 @@ | ||
| 156990 | 157052 | |
| 156991 | 157053 | /* A slot for the record has already been allocated in the |
| 156992 | 157054 | ** schema table. We just need to update that slot with all |
| 156993 | 157055 | ** the information we've collected. |
| 156994 | 157056 | ** |
| 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 | |
| 156996 | 157058 | ** entry in the sqlite_schema table that was created for this vtab |
| 156997 | 157059 | ** by sqlite3StartTable(). |
| 156998 | 157060 | */ |
| 156999 | 157061 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 157062 | + assert( pParse->isCreate ); | |
| 157000 | 157063 | sqlite3NestedParse(pParse, |
| 157001 | 157064 | "UPDATE %Q." LEGACY_SCHEMA_TABLE " " |
| 157002 | 157065 | "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q " |
| 157003 | 157066 | "WHERE rowid=#%d", |
| 157004 | 157067 | db->aDb[iDb].zDbSName, |
| 157005 | 157068 | pTab->zName, |
| 157006 | 157069 | pTab->zName, |
| 157007 | 157070 | zStmt, |
| 157008 | - pParse->regRowid | |
| 157071 | + pParse->u1.cr.regRowid | |
| 157009 | 157072 | ); |
| 157010 | 157073 | v = sqlite3GetVdbe(pParse); |
| 157011 | 157074 | sqlite3ChangeCookie(pParse, iDb); |
| 157012 | 157075 | |
| 157013 | 157076 | sqlite3VdbeAddOp0(v, OP_Expire); |
| @@ -160161,10 +160224,13 @@ | ||
| 160161 | 160224 | } |
| 160162 | 160225 | } |
| 160163 | 160226 | } |
| 160164 | 160227 | sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg); |
| 160165 | 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. */ | |
| 160166 | 160232 | sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, |
| 160167 | 160233 | pLoop->u.vtab.idxStr, |
| 160168 | 160234 | pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC); |
| 160169 | 160235 | VdbeCoverage(v); |
| 160170 | 160236 | pLoop->u.vtab.needFree = 0; |
| @@ -174215,10 +174281,15 @@ | ||
| 174215 | 174281 | ** to the original parse.y sources. |
| 174216 | 174282 | */ |
| 174217 | 174283 | |
| 174218 | 174284 | /* #include "sqliteInt.h" */ |
| 174219 | 174285 | |
| 174286 | +/* | |
| 174287 | +** Verify that the pParse->isCreate field is set | |
| 174288 | +*/ | |
| 174289 | +#define ASSERT_IS_CREATE assert(pParse->isCreate) | |
| 174290 | + | |
| 174220 | 174291 | /* |
| 174221 | 174292 | ** Disable all error recovery processing in the parser push-down |
| 174222 | 174293 | ** automaton. |
| 174223 | 174294 | */ |
| 174224 | 174295 | #define YYNOERRORRECOVERY 1 |
| @@ -174278,10 +174349,14 @@ | ||
| 174278 | 174349 | ** shared across database connections. |
| 174279 | 174350 | */ |
| 174280 | 174351 | static void disableLookaside(Parse *pParse){ |
| 174281 | 174352 | sqlite3 *db = pParse->db; |
| 174282 | 174353 | pParse->disableLookaside++; |
| 174354 | +#ifdef SQLITE_DEBUG | |
| 174355 | + pParse->isCreate = 1; | |
| 174356 | +#endif | |
| 174357 | + memset(&pParse->u1.cr, 0, sizeof(pParse->u1.cr)); | |
| 174283 | 174358 | DisableLookaside; |
| 174284 | 174359 | } |
| 174285 | 174360 | |
| 174286 | 174361 | #if !defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) \ |
| 174287 | 174362 | && defined(SQLITE_UDL_CAPABLE_PARSER) |
| @@ -177914,11 +177989,13 @@ | ||
| 177914 | 177989 | { |
| 177915 | 177990 | sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy502,0,0,yymsp[-2].minor.yy502); |
| 177916 | 177991 | } |
| 177917 | 177992 | break; |
| 177918 | 177993 | case 14: /* createkw ::= CREATE */ |
| 177919 | -{disableLookaside(pParse);} | |
| 177994 | +{ | |
| 177995 | + disableLookaside(pParse); | |
| 177996 | +} | |
| 177920 | 177997 | break; |
| 177921 | 177998 | case 15: /* ifnotexists ::= */ |
| 177922 | 177999 | case 18: /* temp ::= */ yytestcase(yyruleno==18); |
| 177923 | 178000 | case 47: /* autoinc ::= */ yytestcase(yyruleno==47); |
| 177924 | 178001 | case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62); |
| @@ -178006,11 +178083,11 @@ | ||
| 178006 | 178083 | yymsp[1].minor.yy0 = yyLookaheadToken; |
| 178007 | 178084 | } |
| 178008 | 178085 | break; |
| 178009 | 178086 | case 32: /* ccons ::= CONSTRAINT nm */ |
| 178010 | 178087 | 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;} | |
| 178012 | 178089 | break; |
| 178013 | 178090 | case 33: /* ccons ::= DEFAULT scantok term */ |
| 178014 | 178091 | {sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy590,yymsp[-1].minor.yy0.z,&yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]);} |
| 178015 | 178092 | break; |
| 178016 | 178093 | case 34: /* ccons ::= DEFAULT LP expr RP */ |
| @@ -178116,11 +178193,11 @@ | ||
| 178116 | 178193 | break; |
| 178117 | 178194 | case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */ |
| 178118 | 178195 | {yymsp[-1].minor.yy502 = 0;} |
| 178119 | 178196 | break; |
| 178120 | 178197 | case 66: /* tconscomma ::= COMMA */ |
| 178121 | -{pParse->constraintName.n = 0;} | |
| 178198 | +{ASSERT_IS_CREATE; pParse->u1.cr.constraintName.n = 0;} | |
| 178122 | 178199 | break; |
| 178123 | 178200 | case 68: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */ |
| 178124 | 178201 | {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy402,yymsp[0].minor.yy502,yymsp[-2].minor.yy502,0);} |
| 178125 | 178202 | break; |
| 178126 | 178203 | case 69: /* tcons ::= UNIQUE LP sortlist RP onconf */ |
| @@ -179009,10 +179086,14 @@ | ||
| 179009 | 179086 | break; |
| 179010 | 179087 | case 261: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */ |
| 179011 | 179088 | { |
| 179012 | 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); |
| 179013 | 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 | |
| 179014 | 179095 | } |
| 179015 | 179096 | break; |
| 179016 | 179097 | case 262: /* trigger_time ::= BEFORE|AFTER */ |
| 179017 | 179098 | { yymsp[0].minor.yy502 = yymsp[0].major; /*A-overwrites-X*/ } |
| 179018 | 179099 | break; |
| @@ -182295,21 +182376,26 @@ | ||
| 182295 | 182376 | ** Set up the lookaside buffers for a database connection. |
| 182296 | 182377 | ** Return SQLITE_OK on success. |
| 182297 | 182378 | ** If lookaside is already active, return SQLITE_BUSY. |
| 182298 | 182379 | ** |
| 182299 | 182380 | ** 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. | |
| 182304 | 182385 | */ |
| 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 | +){ | |
| 182306 | 182392 | #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 */ | |
| 182311 | 182397 | |
| 182312 | 182398 | if( sqlite3LookasideUsed(db,0)>0 ){ |
| 182313 | 182399 | return SQLITE_BUSY; |
| 182314 | 182400 | } |
| 182315 | 182401 | /* Free any existing lookaside buffer for this handle before |
| @@ -182318,33 +182404,38 @@ | ||
| 182318 | 182404 | */ |
| 182319 | 182405 | if( db->lookaside.bMalloced ){ |
| 182320 | 182406 | sqlite3_free(db->lookaside.pStart); |
| 182321 | 182407 | } |
| 182322 | 182408 | /* 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. | |
| 182324 | 182410 | */ |
| 182325 | - sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */ | |
| 182411 | + sz = ROUNDDOWN8(sz); | |
| 182326 | 182412 | 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 ){ | |
| 182329 | 182420 | sz = 0; |
| 182330 | 182421 | pStart = 0; |
| 182331 | 182422 | }else if( pBuf==0 ){ |
| 182332 | 182423 | sqlite3BeginBenignMalloc(); |
| 182333 | - pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */ | |
| 182424 | + pStart = sqlite3Malloc( szAlloc ); | |
| 182334 | 182425 | sqlite3EndBenignMalloc(); |
| 182335 | 182426 | if( pStart ) szAlloc = sqlite3MallocSize(pStart); |
| 182336 | 182427 | }else{ |
| 182337 | 182428 | pStart = pBuf; |
| 182338 | 182429 | } |
| 182339 | 182430 | #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 182340 | 182431 | if( sz>=LOOKASIDE_SMALL*3 ){ |
| 182341 | 182432 | nBig = szAlloc/(3*LOOKASIDE_SMALL+sz); |
| 182342 | - nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL; | |
| 182433 | + nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL; | |
| 182343 | 182434 | }else if( sz>=LOOKASIDE_SMALL*2 ){ |
| 182344 | 182435 | nBig = szAlloc/(LOOKASIDE_SMALL+sz); |
| 182345 | - nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL; | |
| 182436 | + nSm = (szAlloc - (i64)sz*(i64)nBig)/LOOKASIDE_SMALL; | |
| 182346 | 182437 | }else |
| 182347 | 182438 | #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 182348 | 182439 | if( sz>0 ){ |
| 182349 | 182440 | nBig = szAlloc/sz; |
| 182350 | 182441 | nSm = 0; |
| @@ -185479,17 +185570,14 @@ | ||
| 185479 | 185570 | |
| 185480 | 185571 | /* Find the column for which info is requested */ |
| 185481 | 185572 | if( zColumnName==0 ){ |
| 185482 | 185573 | /* Query for existence of table only */ |
| 185483 | 185574 | }else{ |
| 185484 | - for(iCol=0; iCol<pTab->nCol; iCol++){ | |
| 185575 | + iCol = sqlite3ColumnIndex(pTab, zColumnName); | |
| 185576 | + if( iCol>=0 ){ | |
| 185485 | 185577 | pCol = &pTab->aCol[iCol]; |
| 185486 | - if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){ | |
| 185487 | - break; | |
| 185488 | - } | |
| 185489 | - } | |
| 185490 | - if( iCol==pTab->nCol ){ | |
| 185578 | + }else{ | |
| 185491 | 185579 | if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){ |
| 185492 | 185580 | iCol = pTab->iPKey; |
| 185493 | 185581 | pCol = iCol>=0 ? &pTab->aCol[iCol] : 0; |
| 185494 | 185582 | }else{ |
| 185495 | 185583 | pTab = 0; |
| @@ -192338,11 +192426,11 @@ | ||
| 192338 | 192426 | p1 = pPhrase->doclist.pList; |
| 192339 | 192427 | p2 = aPoslist; |
| 192340 | 192428 | nDistance = iPrev - nMaxUndeferred; |
| 192341 | 192429 | } |
| 192342 | 192430 | |
| 192343 | - aOut = (char *)sqlite3Fts3MallocZero(nPoslist+FTS3_BUFFER_PADDING); | |
| 192431 | + aOut = (char *)sqlite3Fts3MallocZero(((i64)nPoslist)+FTS3_BUFFER_PADDING); | |
| 192344 | 192432 | if( !aOut ){ |
| 192345 | 192433 | sqlite3_free(aPoslist); |
| 192346 | 192434 | return SQLITE_NOMEM; |
| 192347 | 192435 | } |
| 192348 | 192436 | |
| @@ -194958,11 +195046,11 @@ | ||
| 194958 | 195046 | sqlite3_tokenizer_module const *pModule = pTokenizer->pModule; |
| 194959 | 195047 | int rc; |
| 194960 | 195048 | Fts3Expr *p = 0; |
| 194961 | 195049 | sqlite3_tokenizer_cursor *pCursor = 0; |
| 194962 | 195050 | char *zTemp = 0; |
| 194963 | - int nTemp = 0; | |
| 195051 | + i64 nTemp = 0; | |
| 194964 | 195052 | |
| 194965 | 195053 | const int nSpace = sizeof(Fts3Expr) + sizeof(Fts3Phrase); |
| 194966 | 195054 | int nToken = 0; |
| 194967 | 195055 | |
| 194968 | 195056 | /* The final Fts3Expr data structure, including the Fts3Phrase, |
| @@ -207729,22 +207817,23 @@ | ||
| 207729 | 207817 | ** |
| 207730 | 207818 | ** Return the number of errors. |
| 207731 | 207819 | */ |
| 207732 | 207820 | static int jsonBlobExpand(JsonParse *pParse, u32 N){ |
| 207733 | 207821 | u8 *aNew; |
| 207734 | - u32 t; | |
| 207822 | + u64 t; | |
| 207735 | 207823 | assert( N>pParse->nBlobAlloc ); |
| 207736 | 207824 | if( pParse->nBlobAlloc==0 ){ |
| 207737 | 207825 | t = 100; |
| 207738 | 207826 | }else{ |
| 207739 | 207827 | t = pParse->nBlobAlloc*2; |
| 207740 | 207828 | } |
| 207741 | 207829 | if( t<N ) t = N+100; |
| 207742 | 207830 | aNew = sqlite3DbRealloc(pParse->db, pParse->aBlob, t); |
| 207743 | 207831 | if( aNew==0 ){ pParse->oom = 1; return 1; } |
| 207832 | + assert( t<0x7fffffff ); | |
| 207744 | 207833 | pParse->aBlob = aNew; |
| 207745 | - pParse->nBlobAlloc = t; | |
| 207834 | + pParse->nBlobAlloc = (u32)t; | |
| 207746 | 207835 | return 0; |
| 207747 | 207836 | } |
| 207748 | 207837 | |
| 207749 | 207838 | /* |
| 207750 | 207839 | ** If pParse->aBlob is not previously editable (because it is taken |
| @@ -208697,14 +208786,11 @@ | ||
| 208697 | 208786 | */ |
| 208698 | 208787 | static u32 jsonbPayloadSize(const JsonParse *pParse, u32 i, u32 *pSz){ |
| 208699 | 208788 | u8 x; |
| 208700 | 208789 | u32 sz; |
| 208701 | 208790 | u32 n; |
| 208702 | - if( NEVER(i>pParse->nBlob) ){ | |
| 208703 | - *pSz = 0; | |
| 208704 | - return 0; | |
| 208705 | - } | |
| 208791 | + assert( i<=pParse->nBlob ); | |
| 208706 | 208792 | x = pParse->aBlob[i]>>4; |
| 208707 | 208793 | if( x<=11 ){ |
| 208708 | 208794 | sz = x; |
| 208709 | 208795 | n = 1; |
| 208710 | 208796 | }else if( x==12 ){ |
| @@ -208744,12 +208830,12 @@ | ||
| 208744 | 208830 | n = 9; |
| 208745 | 208831 | } |
| 208746 | 208832 | if( (i64)i+sz+n > pParse->nBlob |
| 208747 | 208833 | && (i64)i+sz+n > pParse->nBlob-pParse->delta |
| 208748 | 208834 | ){ |
| 208749 | - sz = 0; | |
| 208750 | - n = 0; | |
| 208835 | + *pSz = 0; | |
| 208836 | + return 0; | |
| 208751 | 208837 | } |
| 208752 | 208838 | *pSz = sz; |
| 208753 | 208839 | return n; |
| 208754 | 208840 | } |
| 208755 | 208841 | |
| @@ -208842,13 +208928,16 @@ | ||
| 208842 | 208928 | } |
| 208843 | 208929 | break; |
| 208844 | 208930 | } |
| 208845 | 208931 | case JSONB_TEXT: |
| 208846 | 208932 | 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 | + } | |
| 208850 | 208939 | break; |
| 208851 | 208940 | } |
| 208852 | 208941 | case JSONB_TEXT5: { |
| 208853 | 208942 | const char *zIn; |
| 208854 | 208943 | u32 k; |
| @@ -209759,11 +209848,11 @@ | ||
| 209759 | 209848 | u32 iIn, iOut; |
| 209760 | 209849 | const char *z; |
| 209761 | 209850 | char *zOut; |
| 209762 | 209851 | u32 nOut = sz; |
| 209763 | 209852 | z = (const char*)&pParse->aBlob[i+n]; |
| 209764 | - zOut = sqlite3DbMallocRaw(db, nOut+1); | |
| 209853 | + zOut = sqlite3DbMallocRaw(db, ((u64)nOut)+1); | |
| 209765 | 209854 | if( zOut==0 ) goto returnfromblob_oom; |
| 209766 | 209855 | for(iIn=iOut=0; iIn<sz; iIn++){ |
| 209767 | 209856 | char c = z[iIn]; |
| 209768 | 209857 | if( c=='\\' ){ |
| 209769 | 209858 | u32 v; |
| @@ -248043,11 +248132,11 @@ | ||
| 248043 | 248132 | int iIdx = 0; |
| 248044 | 248133 | int iStart = 0; |
| 248045 | 248134 | int iDelKeyOff = 0; /* Offset of deleted key, if any */ |
| 248046 | 248135 | |
| 248047 | 248136 | nIdx = nPg-iPgIdx; |
| 248048 | - aIdx = sqlite3Fts5MallocZero(&p->rc, nIdx+16); | |
| 248137 | + aIdx = sqlite3Fts5MallocZero(&p->rc, ((i64)nIdx)+16); | |
| 248049 | 248138 | if( p->rc ) return; |
| 248050 | 248139 | memcpy(aIdx, &aPg[iPgIdx], nIdx); |
| 248051 | 248140 | |
| 248052 | 248141 | /* At this point segment iterator pSeg points to the entry |
| 248053 | 248142 | ** this function should remove from the b-tree segment. |
| @@ -248637,11 +248726,11 @@ | ||
| 248637 | 248726 | return pStruct; |
| 248638 | 248727 | } |
| 248639 | 248728 | assert( pStruct->aLevel[i].nMerge<=nThis ); |
| 248640 | 248729 | } |
| 248641 | 248730 | |
| 248642 | - nByte += (pStruct->nLevel+1) * sizeof(Fts5StructureLevel); | |
| 248731 | + nByte += (((i64)pStruct->nLevel)+1) * sizeof(Fts5StructureLevel); | |
| 248643 | 248732 | pNew = (Fts5Structure*)sqlite3Fts5MallocZero(&p->rc, nByte); |
| 248644 | 248733 | |
| 248645 | 248734 | if( pNew ){ |
| 248646 | 248735 | Fts5StructureLevel *pLvl; |
| 248647 | 248736 | nByte = nSeg * sizeof(Fts5StructureSegment); |
| @@ -249525,11 +249614,12 @@ | ||
| 249525 | 249614 | for(iFree=i; iFree<i+s.nMerge; iFree++){ |
| 249526 | 249615 | fts5BufferFree(&s.aBuf[iFree]); |
| 249527 | 249616 | } |
| 249528 | 249617 | } |
| 249529 | 249618 | |
| 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); | |
| 249531 | 249621 | assert( pData!=0 || p->rc!=SQLITE_OK ); |
| 249532 | 249622 | if( pData ){ |
| 249533 | 249623 | pData->p = (u8*)&pData[1]; |
| 249534 | 249624 | pData->nn = pData->szLeaf = s.doclist.n; |
| 249535 | 249625 | if( s.doclist.n ) memcpy(pData->p, s.doclist.p, s.doclist.n); |
| @@ -251749,11 +251839,11 @@ | ||
| 251749 | 251839 | /* Make a copy of the second argument (a blob) in aBlob[]. The aBlob[] |
| 251750 | 251840 | ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents |
| 251751 | 251841 | ** buffer overreads even if the record is corrupt. */ |
| 251752 | 251842 | n = sqlite3_value_bytes(apVal[1]); |
| 251753 | 251843 | aBlob = sqlite3_value_blob(apVal[1]); |
| 251754 | - nSpace = n + FTS5_DATA_ZERO_PADDING; | |
| 251844 | + nSpace = ((i64)n) + FTS5_DATA_ZERO_PADDING; | |
| 251755 | 251845 | a = (u8*)sqlite3Fts5MallocZero(&rc, nSpace); |
| 251756 | 251846 | if( a==0 ) goto decode_out; |
| 251757 | 251847 | if( n>0 ) memcpy(a, aBlob, n); |
| 251758 | 251848 | |
| 251759 | 251849 | fts5DecodeRowid(iRowid, &bTomb, &iSegid, &bDlidx, &iHeight, &iPgno); |
| @@ -255870,11 +255960,11 @@ | ||
| 255870 | 255960 | int nArg, /* Number of args */ |
| 255871 | 255961 | sqlite3_value **apUnused /* Function arguments */ |
| 255872 | 255962 | ){ |
| 255873 | 255963 | assert( nArg==0 ); |
| 255874 | 255964 | 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); | |
| 255876 | 255966 | } |
| 255877 | 255967 | |
| 255878 | 255968 | /* |
| 255879 | 255969 | ** Implementation of fts5_locale(LOCALE, TEXT) function. |
| 255880 | 255970 | ** |
| @@ -260475,16 +260565,16 @@ | ||
| 260475 | 260565 | |
| 260476 | 260566 | if( argc!=5 && bDb==0 ){ |
| 260477 | 260567 | *pzErr = sqlite3_mprintf("wrong number of vtable arguments"); |
| 260478 | 260568 | rc = SQLITE_ERROR; |
| 260479 | 260569 | }else{ |
| 260480 | - int nByte; /* Bytes of space to allocate */ | |
| 260570 | + i64 nByte; /* Bytes of space to allocate */ | |
| 260481 | 260571 | const char *zDb = bDb ? argv[3] : argv[1]; |
| 260482 | 260572 | const char *zTab = bDb ? argv[4] : argv[3]; |
| 260483 | 260573 | 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; | |
| 260486 | 260576 | int eType = 0; |
| 260487 | 260577 | |
| 260488 | 260578 | rc = fts5VocabTableType(zType, pzErr, &eType); |
| 260489 | 260579 | if( rc==SQLITE_OK ){ |
| 260490 | 260580 | assert( eType>=0 && eType<ArraySize(azSchema) ); |
| 260491 | 260581 |
| --- 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 @@ | ||
| 144 | 144 | ** |
| 145 | 145 | ** See also: [sqlite3_libversion()], |
| 146 | 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | 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" | |
| 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 | 152 | |
| 153 | 153 | /* |
| 154 | 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | 156 | ** |
| @@ -1987,17 +1987,20 @@ | ||
| 1987 | 1987 | ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will |
| 1988 | 1988 | ** return [SQLITE_ERROR].</dd> |
| 1989 | 1989 | ** |
| 1990 | 1990 | ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> |
| 1991 | 1991 | ** <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]. | |
| 1993 | 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> | |
| 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> | |
| 1999 | 2002 | ** |
| 2000 | 2003 | ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> |
| 2001 | 2004 | ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is |
| 2002 | 2005 | ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies |
| 2003 | 2006 | ** the interface to a custom page cache implementation.)^ |
| @@ -2230,35 +2233,54 @@ | ||
| 2230 | 2233 | ** |
| 2231 | 2234 | ** <dl> |
| 2232 | 2235 | ** [[SQLITE_DBCONFIG_LOOKASIDE]] |
| 2233 | 2236 | ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> |
| 2234 | 2237 | ** <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 | |
| 2236 | 2239 | ** connection. |
| 2237 | 2240 | ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i> |
| 2238 | 2241 | ** in the [DBCONFIG arguments|usual format]. |
| 2239 | 2242 | ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two, |
| 2240 | 2243 | ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE |
| 2241 | 2244 | ** 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 | |
| 2243 | 2247 | ** 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 | |
| 2253 | 2266 | ** configuration for a database connection can only be changed when that |
| 2254 | 2267 | ** 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. | |
| 2257 | 2269 | ** Any attempt to change the lookaside memory configuration when lookaside |
| 2258 | 2270 | ** 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> | |
| 2260 | 2282 | ** |
| 2261 | 2283 | ** [[SQLITE_DBCONFIG_ENABLE_FKEY]] |
| 2262 | 2284 | ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> |
| 2263 | 2285 | ** <dd> ^This option is used to enable or disable the enforcement of |
| 2264 | 2286 | ** [foreign key constraints]. This is the same setting that is |
| @@ -12008,23 +12030,10 @@ | ||
| 12008 | 12030 | int nB, /* Number of bytes in buffer pB */ |
| 12009 | 12031 | void *pB, /* Pointer to buffer containing changeset B */ |
| 12010 | 12032 | int *pnOut, /* OUT: Number of bytes in output changeset */ |
| 12011 | 12033 | void **ppOut /* OUT: Buffer containing output changeset */ |
| 12012 | 12034 | ); |
| 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 | 12035 | |
| 12027 | 12036 | /* |
| 12028 | 12037 | ** CAPI3REF: Changegroup Handle |
| 12029 | 12038 | ** |
| 12030 | 12039 | ** A changegroup is an object used to combine two or more |
| 12031 | 12040 |
| --- 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 |