| | @@ -381,11 +381,11 @@ |
| 381 | 381 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 382 | 382 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 383 | 383 | */ |
| 384 | 384 | #define SQLITE_VERSION "3.15.0" |
| 385 | 385 | #define SQLITE_VERSION_NUMBER 3015000 |
| 386 | | -#define SQLITE_SOURCE_ID "2016-09-28 16:05:53 40c0fb0af678797c39a99853f9f4102464c16f4b" |
| 386 | +#define SQLITE_SOURCE_ID "2016-10-12 15:15:30 61f0526978af667781c57bcc87510e4524efd0d8" |
| 387 | 387 | |
| 388 | 388 | /* |
| 389 | 389 | ** CAPI3REF: Run-Time Library Version Numbers |
| 390 | 390 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 391 | 391 | ** |
| | @@ -15515,39 +15515,27 @@ |
| 15515 | 15515 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 15516 | 15516 | u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ |
| 15517 | 15517 | u8 okConstFactor; /* OK to factor out constants */ |
| 15518 | 15518 | u8 disableLookaside; /* Number of times lookaside has been disabled */ |
| 15519 | 15519 | u8 nColCache; /* Number of entries in aColCache[] */ |
| 15520 | | - int aTempReg[8]; /* Holding area for temporary registers */ |
| 15521 | 15520 | int nRangeReg; /* Size of the temporary register block */ |
| 15522 | 15521 | int iRangeReg; /* First register in temporary register block */ |
| 15523 | 15522 | int nErr; /* Number of errors seen */ |
| 15524 | 15523 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 15525 | 15524 | int nMem; /* Number of memory cells used so far */ |
| 15526 | | - int nSet; /* Number of sets used so far */ |
| 15527 | 15525 | int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ |
| 15528 | 15526 | int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ |
| 15529 | | - int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */ |
| 15530 | 15527 | int ckBase; /* Base register of data during check constraints */ |
| 15531 | 15528 | int iSelfTab; /* Table of an index whose exprs are being coded */ |
| 15532 | 15529 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 15533 | 15530 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 15534 | 15531 | int nLabel; /* Number of labels used */ |
| 15535 | 15532 | int *aLabel; /* Space to hold the labels */ |
| 15536 | | - struct yColCache { |
| 15537 | | - int iTable; /* Table cursor number */ |
| 15538 | | - i16 iColumn; /* Table column number */ |
| 15539 | | - u8 tempReg; /* iReg is a temp register that needs to be freed */ |
| 15540 | | - int iLevel; /* Nesting level */ |
| 15541 | | - int iReg; /* Reg with value of this column. 0 means none. */ |
| 15542 | | - int lru; /* Least recently used entry has the smallest value */ |
| 15543 | | - } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */ |
| 15544 | 15533 | ExprList *pConstExpr;/* Constant expressions */ |
| 15545 | 15534 | Token constraintName;/* Name of the constraint currently being parsed */ |
| 15546 | 15535 | yDbMask writeMask; /* Start a write transaction on these databases */ |
| 15547 | 15536 | yDbMask cookieMask; /* Bitmask of schema verified databases */ |
| 15548 | | - int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ |
| 15549 | 15537 | int regRowid; /* Register holding rowid of CREATE TABLE entry */ |
| 15550 | 15538 | int regRoot; /* Register holding root page number for new objects */ |
| 15551 | 15539 | int nMaxArg; /* Max args passed to user function by sub-program */ |
| 15552 | 15540 | #if SELECTTRACE_ENABLED |
| 15553 | 15541 | int nSelect; /* Number of SELECT statements seen */ |
| | @@ -15556,21 +15544,38 @@ |
| 15556 | 15544 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 15557 | 15545 | int nTableLock; /* Number of locks in aTableLock */ |
| 15558 | 15546 | TableLock *aTableLock; /* Required table locks for shared-cache mode */ |
| 15559 | 15547 | #endif |
| 15560 | 15548 | AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */ |
| 15561 | | - |
| 15562 | | - /* Information used while coding trigger programs. */ |
| 15563 | 15549 | Parse *pToplevel; /* Parse structure for main program (or NULL) */ |
| 15564 | 15550 | Table *pTriggerTab; /* Table triggers are being coded for */ |
| 15565 | 15551 | int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */ |
| 15566 | 15552 | u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */ |
| 15567 | 15553 | u32 oldmask; /* Mask of old.* columns referenced */ |
| 15568 | 15554 | u32 newmask; /* Mask of new.* columns referenced */ |
| 15569 | 15555 | u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */ |
| 15570 | 15556 | u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ |
| 15571 | 15557 | u8 disableTriggers; /* True to disable triggers */ |
| 15558 | + |
| 15559 | + /************************************************************************** |
| 15560 | + ** Fields above must be initialized to zero. The fields that follow, |
| 15561 | + ** down to the beginning of the recursive section, do not need to be |
| 15562 | + ** initialized as they will be set before being used. The boundary is |
| 15563 | + ** determined by offsetof(Parse,aColCache). |
| 15564 | + **************************************************************************/ |
| 15565 | + |
| 15566 | + struct yColCache { |
| 15567 | + int iTable; /* Table cursor number */ |
| 15568 | + i16 iColumn; /* Table column number */ |
| 15569 | + u8 tempReg; /* iReg is a temp register that needs to be freed */ |
| 15570 | + int iLevel; /* Nesting level */ |
| 15571 | + int iReg; /* Reg with value of this column. 0 means none. */ |
| 15572 | + int lru; /* Least recently used entry has the smallest value */ |
| 15573 | + } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */ |
| 15574 | + int aTempReg[8]; /* Holding area for temporary registers */ |
| 15575 | + Token sNameToken; /* Token with unqualified schema object name */ |
| 15576 | + Token sLastToken; /* The last token parsed */ |
| 15572 | 15577 | |
| 15573 | 15578 | /************************************************************************ |
| 15574 | 15579 | ** Above is constant between recursions. Below is reset before and after |
| 15575 | 15580 | ** each recursion. The boundary between these two regions is determined |
| 15576 | 15581 | ** using offsetof(Parse,nVar) so the nVar field must be the first field |
| | @@ -15583,11 +15588,10 @@ |
| 15583 | 15588 | u8 explain; /* True if the EXPLAIN flag is found on the query */ |
| 15584 | 15589 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 15585 | 15590 | u8 declareVtab; /* True if inside sqlite3_declare_vtab() */ |
| 15586 | 15591 | int nVtabLock; /* Number of virtual tables to lock */ |
| 15587 | 15592 | #endif |
| 15588 | | - int nAlias; /* Number of aliased result set columns */ |
| 15589 | 15593 | int nHeight; /* Expression tree height of current sub-select */ |
| 15590 | 15594 | #ifndef SQLITE_OMIT_EXPLAIN |
| 15591 | 15595 | int iSelectId; /* ID of current select for EXPLAIN output */ |
| 15592 | 15596 | int iNextSelectId; /* Next available select ID for EXPLAIN output */ |
| 15593 | 15597 | #endif |
| | @@ -15595,12 +15599,10 @@ |
| 15595 | 15599 | Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */ |
| 15596 | 15600 | const char *zTail; /* All SQL text past the last semicolon parsed */ |
| 15597 | 15601 | Table *pNewTable; /* A table being constructed by CREATE TABLE */ |
| 15598 | 15602 | Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */ |
| 15599 | 15603 | const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */ |
| 15600 | | - Token sNameToken; /* Token with unqualified schema object name */ |
| 15601 | | - Token sLastToken; /* The last token parsed */ |
| 15602 | 15604 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 15603 | 15605 | Token sArg; /* Complete text of a module argument */ |
| 15604 | 15606 | Table **apVtabLock; /* Pointer to virtual tables needing locking */ |
| 15605 | 15607 | #endif |
| 15606 | 15608 | Table *pZombieTab; /* List of Table objects to delete after code gen */ |
| | @@ -15607,10 +15609,18 @@ |
| 15607 | 15609 | TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */ |
| 15608 | 15610 | With *pWith; /* Current WITH clause, or NULL */ |
| 15609 | 15611 | With *pWithToFree; /* Free this WITH object at the end of the parse */ |
| 15610 | 15612 | }; |
| 15611 | 15613 | |
| 15614 | +/* |
| 15615 | +** Sizes and pointers of various parts of the Parse object. |
| 15616 | +*/ |
| 15617 | +#define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/ |
| 15618 | +#define PARSE_RECURSE_SZ offsetof(Parse,nVar) /* Recursive part */ |
| 15619 | +#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */ |
| 15620 | +#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */ |
| 15621 | + |
| 15612 | 15622 | /* |
| 15613 | 15623 | ** Return true if currently inside an sqlite3_declare_vtab() call. |
| 15614 | 15624 | */ |
| 15615 | 15625 | #ifdef SQLITE_OMIT_VIRTUALTABLE |
| 15616 | 15626 | #define IN_DECLARE_VTAB 0 |
| | @@ -16170,11 +16180,11 @@ |
| 16170 | 16180 | SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); |
| 16171 | 16181 | SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); |
| 16172 | 16182 | SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*); |
| 16173 | 16183 | SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); |
| 16174 | 16184 | SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); |
| 16175 | | -SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*); |
| 16185 | +SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32); |
| 16176 | 16186 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*); |
| 16177 | 16187 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); |
| 16178 | 16188 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*); |
| 16179 | 16189 | SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int); |
| 16180 | 16190 | SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int); |
| | @@ -16990,20 +17000,17 @@ |
| 16990 | 17000 | ** If x is a lower-case ASCII character, then its upper-case equivalent |
| 16991 | 17001 | ** is (x - 0x20). Therefore toupper() can be implemented as: |
| 16992 | 17002 | ** |
| 16993 | 17003 | ** (x & ~(map[x]&0x20)) |
| 16994 | 17004 | ** |
| 16995 | | -** Standard function tolower() is implemented using the sqlite3UpperToLower[] |
| 17005 | +** The equivalent of tolower() is implemented using the sqlite3UpperToLower[] |
| 16996 | 17006 | ** array. tolower() is used more often than toupper() by SQLite. |
| 16997 | 17007 | ** |
| 16998 | | -** Bit 0x40 is set if the character non-alphanumeric and can be used in an |
| 17008 | +** Bit 0x40 is set if the character is non-alphanumeric and can be used in an |
| 16999 | 17009 | ** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any |
| 17000 | 17010 | ** non-ASCII UTF character. Hence the test for whether or not a character is |
| 17001 | 17011 | ** part of an identifier is 0x46. |
| 17002 | | -** |
| 17003 | | -** SQLite's versions are identical to the standard versions assuming a |
| 17004 | | -** locale of "C". They are implemented as macros in sqliteInt.h. |
| 17005 | 17012 | */ |
| 17006 | 17013 | #ifdef SQLITE_ASCII |
| 17007 | 17014 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = { |
| 17008 | 17015 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */ |
| 17009 | 17016 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */ |
| | @@ -17072,11 +17079,11 @@ |
| 17072 | 17079 | #ifndef SQLITE_SORTER_PMASZ |
| 17073 | 17080 | # define SQLITE_SORTER_PMASZ 250 |
| 17074 | 17081 | #endif |
| 17075 | 17082 | |
| 17076 | 17083 | /* Statement journals spill to disk when their size exceeds the following |
| 17077 | | -** threashold (in bytes). 0 means that statement journals are created and |
| 17084 | +** threshold (in bytes). 0 means that statement journals are created and |
| 17078 | 17085 | ** written to disk immediately (the default behavior for SQLite versions |
| 17079 | 17086 | ** before 3.12.0). -1 means always keep the entire statement journal in |
| 17080 | 17087 | ** memory. (The statement journal is also always held entirely in memory |
| 17081 | 17088 | ** if journal_mode=MEMORY or if temp_store=MEMORY, regardless of this |
| 17082 | 17089 | ** setting.) |
| | @@ -17160,11 +17167,11 @@ |
| 17160 | 17167 | |
| 17161 | 17168 | /* |
| 17162 | 17169 | ** The value of the "pending" byte must be 0x40000000 (1 byte past the |
| 17163 | 17170 | ** 1-gibabyte boundary) in a compatible database. SQLite never uses |
| 17164 | 17171 | ** the database page that contains the pending byte. It never attempts |
| 17165 | | -** to read or write that page. The pending byte page is set assign |
| 17172 | +** to read or write that page. The pending byte page is set aside |
| 17166 | 17173 | ** for use by the VFS layers as space for managing file locks. |
| 17167 | 17174 | ** |
| 17168 | 17175 | ** During testing, it is often desirable to move the pending byte to |
| 17169 | 17176 | ** a different position in the file. This allows code that has to |
| 17170 | 17177 | ** deal with the pending byte to run on files that are much smaller |
| | @@ -17720,13 +17727,10 @@ |
| 17720 | 17727 | typedef unsigned Bool; |
| 17721 | 17728 | |
| 17722 | 17729 | /* Opaque type used by code in vdbesort.c */ |
| 17723 | 17730 | typedef struct VdbeSorter VdbeSorter; |
| 17724 | 17731 | |
| 17725 | | -/* Opaque type used by the explainer */ |
| 17726 | | -typedef struct Explain Explain; |
| 17727 | | - |
| 17728 | 17732 | /* Elements of the linked list at Vdbe.pAuxData */ |
| 17729 | 17733 | typedef struct AuxData AuxData; |
| 17730 | 17734 | |
| 17731 | 17735 | /* Types of VDBE cursors */ |
| 17732 | 17736 | #define CURTYPE_BTREE 0 |
| | @@ -17797,10 +17801,16 @@ |
| 17797 | 17801 | /* 2*nField extra array elements allocated for aType[], beyond the one |
| 17798 | 17802 | ** static element declared in the structure. nField total array slots for |
| 17799 | 17803 | ** aType[] and nField+1 array slots for aOffset[] */ |
| 17800 | 17804 | }; |
| 17801 | 17805 | |
| 17806 | + |
| 17807 | +/* |
| 17808 | +** A value for VdbeCursor.cacheStatus that means the cache is always invalid. |
| 17809 | +*/ |
| 17810 | +#define CACHE_STALE 0 |
| 17811 | + |
| 17802 | 17812 | /* |
| 17803 | 17813 | ** When a sub-program is executed (OP_Program), a structure of this type |
| 17804 | 17814 | ** is allocated to store the current value of the program counter, as |
| 17805 | 17815 | ** well as the current memory cell array and various other frame specific |
| 17806 | 17816 | ** values stored in the Vdbe struct. When the sub-program is finished, |
| | @@ -17841,15 +17851,10 @@ |
| 17841 | 17851 | int nDbChange; /* Value of db->nChange */ |
| 17842 | 17852 | }; |
| 17843 | 17853 | |
| 17844 | 17854 | #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) |
| 17845 | 17855 | |
| 17846 | | -/* |
| 17847 | | -** A value for VdbeCursor.cacheValid that means the cache is always invalid. |
| 17848 | | -*/ |
| 17849 | | -#define CACHE_STALE 0 |
| 17850 | | - |
| 17851 | 17856 | /* |
| 17852 | 17857 | ** Internally, the vdbe manipulates nearly all SQL values as Mem |
| 17853 | 17858 | ** structures. Each Mem struct may cache multiple representations (string, |
| 17854 | 17859 | ** integer etc.) of the same value. |
| 17855 | 17860 | */ |
| | @@ -17986,22 +17991,10 @@ |
| 17986 | 17991 | u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ |
| 17987 | 17992 | u8 argc; /* Number of arguments */ |
| 17988 | 17993 | sqlite3_value *argv[1]; /* Argument set */ |
| 17989 | 17994 | }; |
| 17990 | 17995 | |
| 17991 | | -/* |
| 17992 | | -** An Explain object accumulates indented output which is helpful |
| 17993 | | -** in describing recursive data structures. |
| 17994 | | -*/ |
| 17995 | | -struct Explain { |
| 17996 | | - Vdbe *pVdbe; /* Attach the explanation to this Vdbe */ |
| 17997 | | - StrAccum str; /* The string being accumulated */ |
| 17998 | | - int nIndent; /* Number of elements in aIndent */ |
| 17999 | | - u16 aIndent[100]; /* Levels of indentation */ |
| 18000 | | - char zBase[100]; /* Initial space */ |
| 18001 | | -}; |
| 18002 | | - |
| 18003 | 17996 | /* A bitfield type for use inside of structures. Always follow with :N where |
| 18004 | 17997 | ** N is the number of bits. |
| 18005 | 17998 | */ |
| 18006 | 17999 | typedef unsigned bft; /* Bit Field Type */ |
| 18007 | 18000 | |
| | @@ -18022,57 +18015,61 @@ |
| 18022 | 18015 | ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() |
| 18023 | 18016 | ** is really a pointer to an instance of this structure. |
| 18024 | 18017 | */ |
| 18025 | 18018 | struct Vdbe { |
| 18026 | 18019 | sqlite3 *db; /* The database connection that owns this statement */ |
| 18020 | + Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 18021 | + Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 18022 | + ynVar nVar; /* Number of entries in aVar[] */ |
| 18023 | + ynVar nzVar; /* Number of entries in azVar[] */ |
| 18024 | + u32 magic; /* Magic number for sanity checking */ |
| 18025 | + int nMem; /* Number of memory locations currently allocated */ |
| 18026 | + int nCursor; /* Number of slots in apCsr[] */ |
| 18027 | + u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 18028 | + int pc; /* The program counter */ |
| 18029 | + int rc; /* Value to return */ |
| 18030 | + int nChange; /* Number of db changes made since last reset */ |
| 18031 | + int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 18032 | + i64 iCurrentTime; /* Value of julianday('now') for this statement */ |
| 18033 | + i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 18034 | + i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| 18035 | + i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */ |
| 18036 | + |
| 18037 | + /* When allocating a new Vdbe object, all of the fields below should be |
| 18038 | + ** initialized to zero or NULL */ |
| 18039 | + |
| 18027 | 18040 | Op *aOp; /* Space to hold the virtual machine's program */ |
| 18028 | 18041 | Mem *aMem; /* The memory locations */ |
| 18029 | 18042 | Mem **apArg; /* Arguments to currently executing user function */ |
| 18030 | 18043 | Mem *aColName; /* Column names to return */ |
| 18031 | 18044 | Mem *pResultSet; /* Pointer to an array of results */ |
| 18032 | | - Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 18033 | | - int nMem; /* Number of memory locations currently allocated */ |
| 18034 | | - int nOp; /* Number of instructions in the program */ |
| 18035 | | - int nCursor; /* Number of slots in apCsr[] */ |
| 18036 | | - u32 magic; /* Magic number for sanity checking */ |
| 18037 | 18045 | char *zErrMsg; /* Error message written here */ |
| 18038 | | - Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 18039 | 18046 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| 18040 | 18047 | Mem *aVar; /* Values for the OP_Variable opcode. */ |
| 18041 | 18048 | char **azVar; /* Name of variables */ |
| 18042 | | - ynVar nVar; /* Number of entries in aVar[] */ |
| 18043 | | - ynVar nzVar; /* Number of entries in azVar[] */ |
| 18044 | | - u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 18045 | | - int pc; /* The program counter */ |
| 18046 | | - int rc; /* Value to return */ |
| 18049 | +#ifndef SQLITE_OMIT_TRACE |
| 18050 | + i64 startTime; /* Time when query started - used for profiling */ |
| 18051 | +#endif |
| 18052 | + int nOp; /* Number of instructions in the program */ |
| 18047 | 18053 | #ifdef SQLITE_DEBUG |
| 18048 | 18054 | int rcApp; /* errcode set by sqlite3_result_error_code() */ |
| 18049 | 18055 | #endif |
| 18050 | 18056 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 18051 | 18057 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 18058 | + u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 18052 | 18059 | bft expired:1; /* True if the VM needs to be recompiled */ |
| 18053 | 18060 | bft doingRerun:1; /* True if rerunning after an auto-reprepare */ |
| 18054 | | - u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 18055 | 18061 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 18056 | 18062 | bft changeCntOn:1; /* True to update the change-counter */ |
| 18057 | 18063 | bft runOnlyOnce:1; /* Automatically expire on reset */ |
| 18058 | 18064 | bft usesStmtJournal:1; /* True if uses a statement journal */ |
| 18059 | 18065 | bft readOnly:1; /* True for statements that do not write */ |
| 18060 | 18066 | bft bIsReader:1; /* True for statements that read */ |
| 18061 | 18067 | bft isPrepareV2:1; /* True if prepared with prepare_v2() */ |
| 18062 | | - int nChange; /* Number of db changes made since last reset */ |
| 18063 | 18068 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 18064 | 18069 | yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| 18065 | | - int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 18066 | 18070 | u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */ |
| 18067 | | -#ifndef SQLITE_OMIT_TRACE |
| 18068 | | - i64 startTime; /* Time when query started - used for profiling */ |
| 18069 | | -#endif |
| 18070 | | - i64 iCurrentTime; /* Value of julianday('now') for this statement */ |
| 18071 | | - i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 18072 | | - i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| 18073 | | - i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */ |
| 18074 | 18071 | char *zSql; /* Text of the SQL statement that generated this */ |
| 18075 | 18072 | void *pFree; /* Free this when deleting the vdbe */ |
| 18076 | 18073 | VdbeFrame *pFrame; /* Parent frame */ |
| 18077 | 18074 | VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */ |
| 18078 | 18075 | int nFrame; /* Number of frames in pFrame list */ |
| | @@ -18087,14 +18084,15 @@ |
| 18087 | 18084 | }; |
| 18088 | 18085 | |
| 18089 | 18086 | /* |
| 18090 | 18087 | ** The following are allowed values for Vdbe.magic |
| 18091 | 18088 | */ |
| 18092 | | -#define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */ |
| 18093 | | -#define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */ |
| 18094 | | -#define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */ |
| 18095 | | -#define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */ |
| 18089 | +#define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */ |
| 18090 | +#define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */ |
| 18091 | +#define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */ |
| 18092 | +#define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */ |
| 18093 | +#define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */ |
| 18096 | 18094 | |
| 18097 | 18095 | /* |
| 18098 | 18096 | ** Structure used to store the context required by the |
| 18099 | 18097 | ** sqlite3_preupdate_*() API functions. |
| 18100 | 18098 | */ |
| | @@ -28776,11 +28774,15 @@ |
| 28776 | 28774 | */ |
| 28777 | 28775 | static unsigned int strHash(const char *z){ |
| 28778 | 28776 | unsigned int h = 0; |
| 28779 | 28777 | unsigned char c; |
| 28780 | 28778 | while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 28781 | | - h = (h<<3) ^ h ^ sqlite3UpperToLower[c]; |
| 28779 | + /* Knuth multiplicative hashing. (Sorting & Searching, p. 510). |
| 28780 | + ** 0x9e3779b1 is 2654435761 which is the closest prime number to |
| 28781 | + ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */ |
| 28782 | + h += sqlite3UpperToLower[c]; |
| 28783 | + h *= 0x9e3779b1; |
| 28782 | 28784 | } |
| 28783 | 28785 | return h; |
| 28784 | 28786 | } |
| 28785 | 28787 | |
| 28786 | 28788 | |
| | @@ -44019,11 +44021,11 @@ |
| 44019 | 44021 | ){ |
| 44020 | 44022 | PgHdr *pPgHdr; |
| 44021 | 44023 | assert( pPage!=0 ); |
| 44022 | 44024 | pPgHdr = (PgHdr*)pPage->pExtra; |
| 44023 | 44025 | assert( pPgHdr->pPage==0 ); |
| 44024 | | - memset(pPgHdr, 0, sizeof(PgHdr)); |
| 44026 | + memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty)); |
| 44025 | 44027 | pPgHdr->pPage = pPage; |
| 44026 | 44028 | pPgHdr->pData = pPage->pBuf; |
| 44027 | 44029 | pPgHdr->pExtra = (void *)&pPgHdr[1]; |
| 44028 | 44030 | memset(pPgHdr->pExtra, 0, pCache->szExtra); |
| 44029 | 44031 | pPgHdr->pCache = pCache; |
| | @@ -58985,11 +58987,11 @@ |
| 58985 | 58987 | int bias, /* Bias search to the high end */ |
| 58986 | 58988 | int *pRes /* Write search results here */ |
| 58987 | 58989 | ){ |
| 58988 | 58990 | int rc; /* Status code */ |
| 58989 | 58991 | UnpackedRecord *pIdxKey; /* Unpacked index key */ |
| 58990 | | - char aSpace[200]; /* Temp space for pIdxKey - to avoid a malloc */ |
| 58992 | + char aSpace[384]; /* Temp space for pIdxKey - to avoid a malloc */ |
| 58991 | 58993 | char *pFree = 0; |
| 58992 | 58994 | |
| 58993 | 58995 | if( pKey ){ |
| 58994 | 58996 | assert( nKey==(i64)(int)nKey ); |
| 58995 | 58997 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| | @@ -64322,12 +64324,10 @@ |
| 64322 | 64324 | nSrc = pX->nData; |
| 64323 | 64325 | assert( pPage->intKeyLeaf ); /* fillInCell() only called for leaves */ |
| 64324 | 64326 | nHeader += putVarint32(&pCell[nHeader], nPayload); |
| 64325 | 64327 | nHeader += putVarint(&pCell[nHeader], *(u64*)&pX->nKey); |
| 64326 | 64328 | }else{ |
| 64327 | | - assert( pX->nData==0 ); |
| 64328 | | - assert( pX->nZero==0 ); |
| 64329 | 64329 | assert( pX->nKey<=0x7fffffff && pX->pKey!=0 ); |
| 64330 | 64330 | nSrc = nPayload = (int)pX->nKey; |
| 64331 | 64331 | pSrc = pX->pKey; |
| 64332 | 64332 | nHeader += putVarint32(&pCell[nHeader], nPayload); |
| 64333 | 64333 | } |
| | @@ -68023,26 +68023,20 @@ |
| 68023 | 68023 | */ |
| 68024 | 68024 | static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){ |
| 68025 | 68025 | int i = sqlite3FindDbName(pDb, zDb); |
| 68026 | 68026 | |
| 68027 | 68027 | if( i==1 ){ |
| 68028 | | - Parse *pParse; |
| 68028 | + Parse sParse; |
| 68029 | 68029 | int rc = 0; |
| 68030 | | - pParse = sqlite3StackAllocZero(pErrorDb, sizeof(*pParse)); |
| 68031 | | - if( pParse==0 ){ |
| 68032 | | - sqlite3ErrorWithMsg(pErrorDb, SQLITE_NOMEM, "out of memory"); |
| 68033 | | - rc = SQLITE_NOMEM_BKPT; |
| 68034 | | - }else{ |
| 68035 | | - pParse->db = pDb; |
| 68036 | | - if( sqlite3OpenTempDatabase(pParse) ){ |
| 68037 | | - sqlite3ErrorWithMsg(pErrorDb, pParse->rc, "%s", pParse->zErrMsg); |
| 68038 | | - rc = SQLITE_ERROR; |
| 68039 | | - } |
| 68040 | | - sqlite3DbFree(pErrorDb, pParse->zErrMsg); |
| 68041 | | - sqlite3ParserReset(pParse); |
| 68042 | | - sqlite3StackFree(pErrorDb, pParse); |
| 68043 | | - } |
| 68030 | + memset(&sParse, 0, sizeof(sParse)); |
| 68031 | + sParse.db = pDb; |
| 68032 | + if( sqlite3OpenTempDatabase(&sParse) ){ |
| 68033 | + sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg); |
| 68034 | + rc = SQLITE_ERROR; |
| 68035 | + } |
| 68036 | + sqlite3DbFree(pErrorDb, sParse.zErrMsg); |
| 68037 | + sqlite3ParserReset(&sParse); |
| 68044 | 68038 | if( rc ){ |
| 68045 | 68039 | return 0; |
| 68046 | 68040 | } |
| 68047 | 68041 | } |
| 68048 | 68042 | |
| | @@ -69042,10 +69036,11 @@ |
| 69042 | 69036 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 69043 | 69037 | assert( EIGHT_BYTE_ALIGNMENT(pMem) ); |
| 69044 | 69038 | |
| 69045 | 69039 | |
| 69046 | 69040 | if( sqlite3VdbeMemClearAndResize(pMem, nByte) ){ |
| 69041 | + pMem->enc = 0; |
| 69047 | 69042 | return SQLITE_NOMEM_BKPT; |
| 69048 | 69043 | } |
| 69049 | 69044 | |
| 69050 | 69045 | /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8 |
| 69051 | 69046 | ** string representation of the value. Then, if the required encoding |
| | @@ -69341,11 +69336,11 @@ |
| 69341 | 69336 | switch( aff ){ |
| 69342 | 69337 | case SQLITE_AFF_BLOB: { /* Really a cast to BLOB */ |
| 69343 | 69338 | if( (pMem->flags & MEM_Blob)==0 ){ |
| 69344 | 69339 | sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding); |
| 69345 | 69340 | assert( pMem->flags & MEM_Str || pMem->db->mallocFailed ); |
| 69346 | | - MemSetTypeFlag(pMem, MEM_Blob); |
| 69341 | + if( pMem->flags & MEM_Str ) MemSetTypeFlag(pMem, MEM_Blob); |
| 69347 | 69342 | }else{ |
| 69348 | 69343 | pMem->flags &= ~(MEM_TypeMask&~MEM_Blob); |
| 69349 | 69344 | } |
| 69350 | 69345 | break; |
| 69351 | 69346 | } |
| | @@ -70018,14 +70013,11 @@ |
| 70018 | 70013 | sqlite3_value *pVal = 0; |
| 70019 | 70014 | int negInt = 1; |
| 70020 | 70015 | const char *zNeg = ""; |
| 70021 | 70016 | int rc = SQLITE_OK; |
| 70022 | 70017 | |
| 70023 | | - if( !pExpr ){ |
| 70024 | | - *ppVal = 0; |
| 70025 | | - return SQLITE_OK; |
| 70026 | | - } |
| 70018 | + assert( pExpr!=0 ); |
| 70027 | 70019 | while( (op = pExpr->op)==TK_UPLUS || op==TK_SPAN ) pExpr = pExpr->pLeft; |
| 70028 | 70020 | if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; |
| 70029 | 70021 | |
| 70030 | 70022 | /* Compressed expressions only appear when parsing the DEFAULT clause |
| 70031 | 70023 | ** on a table column definition, and hence only when pCtx==0. This |
| | @@ -70145,11 +70137,11 @@ |
| 70145 | 70137 | Expr *pExpr, /* The expression to evaluate */ |
| 70146 | 70138 | u8 enc, /* Encoding to use */ |
| 70147 | 70139 | u8 affinity, /* Affinity to use */ |
| 70148 | 70140 | sqlite3_value **ppVal /* Write the new value here */ |
| 70149 | 70141 | ){ |
| 70150 | | - return valueFromExpr(db, pExpr, enc, affinity, ppVal, 0); |
| 70142 | + return pExpr ? valueFromExpr(db, pExpr, enc, affinity, ppVal, 0) : 0; |
| 70151 | 70143 | } |
| 70152 | 70144 | |
| 70153 | 70145 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 70154 | 70146 | /* |
| 70155 | 70147 | ** The implementation of the sqlite_record() function. This function accepts |
| | @@ -70488,12 +70480,13 @@ |
| 70488 | 70480 | ** Create a new virtual database engine. |
| 70489 | 70481 | */ |
| 70490 | 70482 | SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){ |
| 70491 | 70483 | sqlite3 *db = pParse->db; |
| 70492 | 70484 | Vdbe *p; |
| 70493 | | - p = sqlite3DbMallocZero(db, sizeof(Vdbe) ); |
| 70485 | + p = sqlite3DbMallocRawNN(db, sizeof(Vdbe) ); |
| 70494 | 70486 | if( p==0 ) return 0; |
| 70487 | + memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp)); |
| 70495 | 70488 | p->db = db; |
| 70496 | 70489 | if( db->pVdbe ){ |
| 70497 | 70490 | db->pVdbe->pPrev = p; |
| 70498 | 70491 | } |
| 70499 | 70492 | p->pNext = db->pVdbe; |
| | @@ -70651,13 +70644,12 @@ |
| 70651 | 70644 | #endif |
| 70652 | 70645 | #ifdef SQLITE_DEBUG |
| 70653 | 70646 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 70654 | 70647 | int jj, kk; |
| 70655 | 70648 | Parse *pParse = p->pParse; |
| 70656 | | - for(jj=kk=0; jj<SQLITE_N_COLCACHE; jj++){ |
| 70649 | + for(jj=kk=0; jj<pParse->nColCache; jj++){ |
| 70657 | 70650 | struct yColCache *x = pParse->aColCache + jj; |
| 70658 | | - if( x->iLevel>pParse->iCacheLevel || x->iReg==0 ) continue; |
| 70659 | 70651 | printf(" r[%d]={%d:%d}", x->iReg, x->iTable, x->iColumn); |
| 70660 | 70652 | kk++; |
| 70661 | 70653 | } |
| 70662 | 70654 | if( kk ) printf("\n"); |
| 70663 | 70655 | sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| | @@ -70841,11 +70833,10 @@ |
| 70841 | 70833 | assert( j<p->nLabel ); |
| 70842 | 70834 | assert( j>=0 ); |
| 70843 | 70835 | if( p->aLabel ){ |
| 70844 | 70836 | p->aLabel[j] = v->nOp; |
| 70845 | 70837 | } |
| 70846 | | - p->iFixedOp = v->nOp - 1; |
| 70847 | 70838 | } |
| 70848 | 70839 | |
| 70849 | 70840 | /* |
| 70850 | 70841 | ** Mark the VDBE as one that can only be run one time. |
| 70851 | 70842 | */ |
| | @@ -71232,19 +71223,19 @@ |
| 71232 | 71223 | } |
| 71233 | 71224 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 71234 | 71225 | sqlite3VdbeGetOp(p,addr)->p3 = val; |
| 71235 | 71226 | } |
| 71236 | 71227 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){ |
| 71237 | | - if( !p->db->mallocFailed ) p->aOp[p->nOp-1].p5 = p5; |
| 71228 | + assert( p->nOp>0 || p->db->mallocFailed ); |
| 71229 | + if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5; |
| 71238 | 71230 | } |
| 71239 | 71231 | |
| 71240 | 71232 | /* |
| 71241 | 71233 | ** Change the P2 operand of instruction addr so that it points to |
| 71242 | 71234 | ** the address of the next instruction to be coded. |
| 71243 | 71235 | */ |
| 71244 | 71236 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 71245 | | - p->pParse->iFixedOp = p->nOp - 1; |
| 71246 | 71237 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 71247 | 71238 | } |
| 71248 | 71239 | |
| 71249 | 71240 | |
| 71250 | 71241 | /* |
| | @@ -71363,11 +71354,11 @@ |
| 71363 | 71354 | /* |
| 71364 | 71355 | ** If the last opcode is "op" and it is not a jump destination, |
| 71365 | 71356 | ** then remove it. Return true if and only if an opcode was removed. |
| 71366 | 71357 | */ |
| 71367 | 71358 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe *p, u8 op){ |
| 71368 | | - if( (p->nOp-1)>(p->pParse->iFixedOp) && p->aOp[p->nOp-1].opcode==op ){ |
| 71359 | + if( p->nOp>0 && p->aOp[p->nOp-1].opcode==op ){ |
| 71369 | 71360 | return sqlite3VdbeChangeToNoop(p, p->nOp-1); |
| 71370 | 71361 | }else{ |
| 71371 | 71362 | return 0; |
| 71372 | 71363 | } |
| 71373 | 71364 | } |
| | @@ -71925,10 +71916,25 @@ |
| 71925 | 71916 | zCom |
| 71926 | 71917 | ); |
| 71927 | 71918 | fflush(pOut); |
| 71928 | 71919 | } |
| 71929 | 71920 | #endif |
| 71921 | + |
| 71922 | +/* |
| 71923 | +** Initialize an array of N Mem element. |
| 71924 | +*/ |
| 71925 | +static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ |
| 71926 | + while( (N--)>0 ){ |
| 71927 | + p->db = db; |
| 71928 | + p->flags = flags; |
| 71929 | + p->szMalloc = 0; |
| 71930 | +#ifdef SQLITE_DEBUG |
| 71931 | + p->pScopyFrom = 0; |
| 71932 | +#endif |
| 71933 | + p++; |
| 71934 | + } |
| 71935 | +} |
| 71930 | 71936 | |
| 71931 | 71937 | /* |
| 71932 | 71938 | ** Release an array of N Mem elements |
| 71933 | 71939 | */ |
| 71934 | 71940 | static void releaseMemArray(Mem *p, int N){ |
| | @@ -72137,10 +72143,11 @@ |
| 72137 | 72143 | return SQLITE_ERROR; |
| 72138 | 72144 | } |
| 72139 | 72145 | pMem->flags = MEM_Str|MEM_Term; |
| 72140 | 72146 | zP4 = displayP4(pOp, pMem->z, pMem->szMalloc); |
| 72141 | 72147 | if( zP4!=pMem->z ){ |
| 72148 | + pMem->n = 0; |
| 72142 | 72149 | sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0); |
| 72143 | 72150 | }else{ |
| 72144 | 72151 | assert( pMem->z!=0 ); |
| 72145 | 72152 | pMem->n = sqlite3Strlen30(pMem->z); |
| 72146 | 72153 | pMem->enc = SQLITE_UTF8; |
| | @@ -72279,11 +72286,11 @@ |
| 72279 | 72286 | SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){ |
| 72280 | 72287 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 72281 | 72288 | int i; |
| 72282 | 72289 | #endif |
| 72283 | 72290 | assert( p!=0 ); |
| 72284 | | - assert( p->magic==VDBE_MAGIC_INIT ); |
| 72291 | + assert( p->magic==VDBE_MAGIC_INIT || p->magic==VDBE_MAGIC_RESET ); |
| 72285 | 72292 | |
| 72286 | 72293 | /* There should be at least one opcode. |
| 72287 | 72294 | */ |
| 72288 | 72295 | assert( p->nOp>0 ); |
| 72289 | 72296 | |
| | @@ -72368,14 +72375,11 @@ |
| 72368 | 72375 | n = ROUND8(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */ |
| 72369 | 72376 | x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */ |
| 72370 | 72377 | assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) ); |
| 72371 | 72378 | x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused memory */ |
| 72372 | 72379 | assert( x.nFree>=0 ); |
| 72373 | | - if( x.nFree>0 ){ |
| 72374 | | - memset(x.pSpace, 0, x.nFree); |
| 72375 | | - assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) ); |
| 72376 | | - } |
| 72380 | + assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) ); |
| 72377 | 72381 | |
| 72378 | 72382 | resolveP2Values(p, &nArg); |
| 72379 | 72383 | p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); |
| 72380 | 72384 | if( pParse->explain && nMem<10 ){ |
| 72381 | 72385 | nMem = 10; |
| | @@ -72400,34 +72404,34 @@ |
| 72400 | 72404 | p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*)); |
| 72401 | 72405 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 72402 | 72406 | p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64)); |
| 72403 | 72407 | #endif |
| 72404 | 72408 | if( x.nNeeded==0 ) break; |
| 72405 | | - x.pSpace = p->pFree = sqlite3DbMallocZero(db, x.nNeeded); |
| 72409 | + x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded); |
| 72406 | 72410 | x.nFree = x.nNeeded; |
| 72407 | 72411 | }while( !db->mallocFailed ); |
| 72408 | 72412 | |
| 72409 | | - p->nCursor = nCursor; |
| 72410 | | - if( p->aVar ){ |
| 72411 | | - p->nVar = (ynVar)nVar; |
| 72412 | | - for(n=0; n<nVar; n++){ |
| 72413 | | - p->aVar[n].flags = MEM_Null; |
| 72414 | | - p->aVar[n].db = db; |
| 72415 | | - } |
| 72416 | | - } |
| 72417 | 72413 | p->nzVar = pParse->nzVar; |
| 72418 | 72414 | p->azVar = pParse->azVar; |
| 72419 | 72415 | pParse->nzVar = 0; |
| 72420 | 72416 | pParse->azVar = 0; |
| 72421 | | - if( p->aMem ){ |
| 72422 | | - p->nMem = nMem; |
| 72423 | | - for(n=0; n<nMem; n++){ |
| 72424 | | - p->aMem[n].flags = MEM_Undefined; |
| 72425 | | - p->aMem[n].db = db; |
| 72426 | | - } |
| 72427 | | - } |
| 72428 | 72417 | p->explain = pParse->explain; |
| 72418 | + if( db->mallocFailed ){ |
| 72419 | + p->nVar = 0; |
| 72420 | + p->nCursor = 0; |
| 72421 | + p->nMem = 0; |
| 72422 | + }else{ |
| 72423 | + p->nCursor = nCursor; |
| 72424 | + p->nVar = (ynVar)nVar; |
| 72425 | + initMemArray(p->aVar, nVar, db, MEM_Null); |
| 72426 | + p->nMem = nMem; |
| 72427 | + initMemArray(p->aMem, nMem, db, MEM_Undefined); |
| 72428 | + memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*)); |
| 72429 | +#ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 72430 | + memset(p->anExec, 0, p->nOp*sizeof(i64)); |
| 72431 | +#endif |
| 72432 | + } |
| 72429 | 72433 | sqlite3VdbeRewind(p); |
| 72430 | 72434 | } |
| 72431 | 72435 | |
| 72432 | 72436 | /* |
| 72433 | 72437 | ** Close a VDBE cursor and release all the resources that cursor |
| | @@ -72575,17 +72579,13 @@ |
| 72575 | 72579 | |
| 72576 | 72580 | releaseMemArray(p->aColName, p->nResColumn*COLNAME_N); |
| 72577 | 72581 | sqlite3DbFree(db, p->aColName); |
| 72578 | 72582 | n = nResColumn*COLNAME_N; |
| 72579 | 72583 | p->nResColumn = (u16)nResColumn; |
| 72580 | | - p->aColName = pColName = (Mem*)sqlite3DbMallocZero(db, sizeof(Mem)*n ); |
| 72584 | + p->aColName = pColName = (Mem*)sqlite3DbMallocRawNN(db, sizeof(Mem)*n ); |
| 72581 | 72585 | if( p->aColName==0 ) return; |
| 72582 | | - while( n-- > 0 ){ |
| 72583 | | - pColName->flags = MEM_Null; |
| 72584 | | - pColName->db = p->db; |
| 72585 | | - pColName++; |
| 72586 | | - } |
| 72586 | + initMemArray(p->aColName, n, p->db, MEM_Null); |
| 72587 | 72587 | } |
| 72588 | 72588 | |
| 72589 | 72589 | /* |
| 72590 | 72590 | ** Set the name of the idx'th column to be returned by the SQL statement. |
| 72591 | 72591 | ** zName must be a pointer to a nul terminated string. |
| | @@ -73343,11 +73343,11 @@ |
| 73343 | 73343 | fclose(out); |
| 73344 | 73344 | } |
| 73345 | 73345 | } |
| 73346 | 73346 | #endif |
| 73347 | 73347 | p->iCurrentTime = 0; |
| 73348 | | - p->magic = VDBE_MAGIC_INIT; |
| 73348 | + p->magic = VDBE_MAGIC_RESET; |
| 73349 | 73349 | return p->rc & db->errMask; |
| 73350 | 73350 | } |
| 73351 | 73351 | |
| 73352 | 73352 | /* |
| 73353 | 73353 | ** Clean up and delete a VDBE after execution. Return an integer which is |
| | @@ -73407,23 +73407,25 @@ |
| 73407 | 73407 | */ |
| 73408 | 73408 | SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){ |
| 73409 | 73409 | SubProgram *pSub, *pNext; |
| 73410 | 73410 | int i; |
| 73411 | 73411 | assert( p->db==0 || p->db==db ); |
| 73412 | | - releaseMemArray(p->aVar, p->nVar); |
| 73413 | 73412 | releaseMemArray(p->aColName, p->nResColumn*COLNAME_N); |
| 73414 | 73413 | for(pSub=p->pProgram; pSub; pSub=pNext){ |
| 73415 | 73414 | pNext = pSub->pNext; |
| 73416 | 73415 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 73417 | 73416 | sqlite3DbFree(db, pSub); |
| 73418 | 73417 | } |
| 73419 | | - for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 73420 | | - sqlite3DbFree(db, p->azVar); |
| 73418 | + if( p->magic!=VDBE_MAGIC_INIT ){ |
| 73419 | + releaseMemArray(p->aVar, p->nVar); |
| 73420 | + for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 73421 | + sqlite3DbFree(db, p->azVar); |
| 73422 | + sqlite3DbFree(db, p->pFree); |
| 73423 | + } |
| 73421 | 73424 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 73422 | 73425 | sqlite3DbFree(db, p->aColName); |
| 73423 | 73426 | sqlite3DbFree(db, p->zSql); |
| 73424 | | - sqlite3DbFree(db, p->pFree); |
| 73425 | 73427 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 73426 | 73428 | for(i=0; i<p->nScan; i++){ |
| 73427 | 73429 | sqlite3DbFree(db, p->aScan[i].zName); |
| 73428 | 73430 | } |
| 73429 | 73431 | sqlite3DbFree(db, p->aScan); |
| | @@ -76665,11 +76667,11 @@ |
| 76665 | 76667 | /* |
| 76666 | 76668 | ** Return true if the prepared statement is in need of being reset. |
| 76667 | 76669 | */ |
| 76668 | 76670 | SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){ |
| 76669 | 76671 | Vdbe *v = (Vdbe*)pStmt; |
| 76670 | | - return v!=0 && v->pc>=0 && v->magic==VDBE_MAGIC_RUN; |
| 76672 | + return v!=0 && v->magic==VDBE_MAGIC_RUN && v->pc>=0; |
| 76671 | 76673 | } |
| 76672 | 76674 | |
| 76673 | 76675 | /* |
| 76674 | 76676 | ** Return a pointer to the next prepared statement after pStmt associated |
| 76675 | 76677 | ** with database connection pDb. If pStmt is NULL, return the first |
| | @@ -78417,15 +78419,17 @@ |
| 78417 | 78419 | u16 nullFlag; |
| 78418 | 78420 | pOut = out2Prerelease(p, pOp); |
| 78419 | 78421 | cnt = pOp->p3-pOp->p2; |
| 78420 | 78422 | assert( pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 78421 | 78423 | pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 78424 | + pOut->n = 0; |
| 78422 | 78425 | while( cnt>0 ){ |
| 78423 | 78426 | pOut++; |
| 78424 | 78427 | memAboutToChange(p, pOut); |
| 78425 | 78428 | sqlite3VdbeMemSetNull(pOut); |
| 78426 | 78429 | pOut->flags = nullFlag; |
| 78430 | + pOut->n = 0; |
| 78427 | 78431 | cnt--; |
| 78428 | 78432 | } |
| 78429 | 78433 | break; |
| 78430 | 78434 | } |
| 78431 | 78435 | |
| | @@ -82338,13 +82342,10 @@ |
| 82338 | 82342 | if( pOp->opcode==OP_SorterInsert ){ |
| 82339 | 82343 | rc = sqlite3VdbeSorterWrite(pC, pIn2); |
| 82340 | 82344 | }else{ |
| 82341 | 82345 | x.nKey = pIn2->n; |
| 82342 | 82346 | x.pKey = pIn2->z; |
| 82343 | | - x.nData = 0; |
| 82344 | | - x.nZero = 0; |
| 82345 | | - x.pData = 0; |
| 82346 | 82347 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, pOp->p3, |
| 82347 | 82348 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 82348 | 82349 | ); |
| 82349 | 82350 | assert( pC->deferredMoveto==0 ); |
| 82350 | 82351 | pC->cacheStatus = CACHE_STALE; |
| | @@ -88783,11 +88784,10 @@ |
| 88783 | 88784 | const char *zDb; |
| 88784 | 88785 | Expr *pRight; |
| 88785 | 88786 | |
| 88786 | 88787 | /* if( pSrcList==0 ) break; */ |
| 88787 | 88788 | notValid(pParse, pNC, "the \".\" operator", NC_IdxExpr); |
| 88788 | | - /*notValid(pParse, pNC, "the \".\" operator", NC_PartIdx|NC_IsCheck, 1);*/ |
| 88789 | 88789 | pRight = pExpr->pRight; |
| 88790 | 88790 | if( pRight->op==TK_ID ){ |
| 88791 | 88791 | zDb = 0; |
| 88792 | 88792 | zTable = pExpr->pLeft->u.zToken; |
| 88793 | 88793 | zColumn = pRight->u.zToken; |
| | @@ -88812,11 +88812,10 @@ |
| 88812 | 88812 | const char *zId; /* The function name. */ |
| 88813 | 88813 | FuncDef *pDef; /* Information about the function */ |
| 88814 | 88814 | u8 enc = ENC(pParse->db); /* The database encoding */ |
| 88815 | 88815 | |
| 88816 | 88816 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 88817 | | - notValid(pParse, pNC, "functions", NC_PartIdx); |
| 88818 | 88817 | zId = pExpr->u.zToken; |
| 88819 | 88818 | nId = sqlite3Strlen30(zId); |
| 88820 | 88819 | pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0); |
| 88821 | 88820 | if( pDef==0 ){ |
| 88822 | 88821 | pDef = sqlite3FindFunction(pParse->db, zId, -2, enc, 0); |
| | @@ -88872,11 +88871,12 @@ |
| 88872 | 88871 | } |
| 88873 | 88872 | if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){ |
| 88874 | 88873 | /* Date/time functions that use 'now', and other functions like |
| 88875 | 88874 | ** sqlite_version() that might change over time cannot be used |
| 88876 | 88875 | ** in an index. */ |
| 88877 | | - notValid(pParse, pNC, "non-deterministic functions", NC_IdxExpr); |
| 88876 | + notValid(pParse, pNC, "non-deterministic functions", |
| 88877 | + NC_IdxExpr|NC_PartIdx); |
| 88878 | 88878 | } |
| 88879 | 88879 | } |
| 88880 | 88880 | if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ |
| 88881 | 88881 | sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); |
| 88882 | 88882 | pNC->nErr++; |
| | @@ -90412,11 +90412,11 @@ |
| 90412 | 90412 | ** stored in u.zToken. Instead, the integer values is written |
| 90413 | 90413 | ** into u.iValue and the EP_IntValue flag is set. No extra storage |
| 90414 | 90414 | ** is allocated to hold the integer text and the dequote flag is ignored. |
| 90415 | 90415 | */ |
| 90416 | 90416 | SQLITE_PRIVATE Expr *sqlite3ExprAlloc( |
| 90417 | | - sqlite3 *db, /* Handle for sqlite3DbMallocZero() (may be null) */ |
| 90417 | + sqlite3 *db, /* Handle for sqlite3DbMallocRawNN() */ |
| 90418 | 90418 | int op, /* Expression opcode */ |
| 90419 | 90419 | const Token *pToken, /* Token argument. Might be NULL */ |
| 90420 | 90420 | int dequote /* True to dequote */ |
| 90421 | 90421 | ){ |
| 90422 | 90422 | Expr *pNew; |
| | @@ -90630,40 +90630,40 @@ |
| 90630 | 90630 | ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number |
| 90631 | 90631 | ** as the previous instance of the same wildcard. Or if this is the first |
| 90632 | 90632 | ** instance of the wildcard, the next sequential variable number is |
| 90633 | 90633 | ** assigned. |
| 90634 | 90634 | */ |
| 90635 | | -SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){ |
| 90635 | +SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){ |
| 90636 | 90636 | sqlite3 *db = pParse->db; |
| 90637 | 90637 | const char *z; |
| 90638 | 90638 | |
| 90639 | 90639 | if( pExpr==0 ) return; |
| 90640 | 90640 | assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) ); |
| 90641 | 90641 | z = pExpr->u.zToken; |
| 90642 | 90642 | assert( z!=0 ); |
| 90643 | 90643 | assert( z[0]!=0 ); |
| 90644 | + assert( n==sqlite3Strlen30(z) ); |
| 90644 | 90645 | if( z[1]==0 ){ |
| 90645 | 90646 | /* Wildcard of the form "?". Assign the next variable number */ |
| 90646 | 90647 | assert( z[0]=='?' ); |
| 90647 | 90648 | pExpr->iColumn = (ynVar)(++pParse->nVar); |
| 90648 | 90649 | }else{ |
| 90649 | | - ynVar x = 0; |
| 90650 | | - u32 n = sqlite3Strlen30(z); |
| 90650 | + ynVar x; |
| 90651 | 90651 | if( z[0]=='?' ){ |
| 90652 | 90652 | /* Wildcard of the form "?nnn". Convert "nnn" to an integer and |
| 90653 | 90653 | ** use it as the variable number */ |
| 90654 | 90654 | i64 i; |
| 90655 | 90655 | int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8); |
| 90656 | | - pExpr->iColumn = x = (ynVar)i; |
| 90656 | + x = (ynVar)i; |
| 90657 | 90657 | testcase( i==0 ); |
| 90658 | 90658 | testcase( i==1 ); |
| 90659 | 90659 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 ); |
| 90660 | 90660 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ); |
| 90661 | 90661 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 90662 | 90662 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 90663 | 90663 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 90664 | | - x = 0; |
| 90664 | + return; |
| 90665 | 90665 | } |
| 90666 | 90666 | if( i>pParse->nVar ){ |
| 90667 | 90667 | pParse->nVar = (int)i; |
| 90668 | 90668 | } |
| 90669 | 90669 | }else{ |
| | @@ -90670,37 +90670,35 @@ |
| 90670 | 90670 | /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable |
| 90671 | 90671 | ** number as the prior appearance of the same name, or if the name |
| 90672 | 90672 | ** has never appeared before, reuse the same variable number |
| 90673 | 90673 | */ |
| 90674 | 90674 | ynVar i; |
| 90675 | | - for(i=0; i<pParse->nzVar; i++){ |
| 90675 | + for(i=x=0; i<pParse->nzVar; i++){ |
| 90676 | 90676 | if( pParse->azVar[i] && strcmp(pParse->azVar[i],z)==0 ){ |
| 90677 | | - pExpr->iColumn = x = (ynVar)i+1; |
| 90678 | | - break; |
| 90679 | | - } |
| 90680 | | - } |
| 90681 | | - if( x==0 ) x = pExpr->iColumn = (ynVar)(++pParse->nVar); |
| 90682 | | - } |
| 90683 | | - if( x>0 ){ |
| 90684 | | - if( x>pParse->nzVar ){ |
| 90685 | | - char **a; |
| 90686 | | - a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0])); |
| 90687 | | - if( a==0 ){ |
| 90688 | | - assert( db->mallocFailed ); /* Error reported through mallocFailed */ |
| 90689 | | - return; |
| 90690 | | - } |
| 90691 | | - pParse->azVar = a; |
| 90692 | | - memset(&a[pParse->nzVar], 0, (x-pParse->nzVar)*sizeof(a[0])); |
| 90693 | | - pParse->nzVar = x; |
| 90694 | | - } |
| 90695 | | - if( z[0]!='?' || pParse->azVar[x-1]==0 ){ |
| 90696 | | - sqlite3DbFree(db, pParse->azVar[x-1]); |
| 90697 | | - pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n); |
| 90698 | | - } |
| 90699 | | - } |
| 90700 | | - } |
| 90701 | | - if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 90677 | + x = (ynVar)i+1; |
| 90678 | + break; |
| 90679 | + } |
| 90680 | + } |
| 90681 | + if( x==0 ) x = (ynVar)(++pParse->nVar); |
| 90682 | + } |
| 90683 | + pExpr->iColumn = x; |
| 90684 | + if( x>pParse->nzVar ){ |
| 90685 | + char **a; |
| 90686 | + a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0])); |
| 90687 | + if( a==0 ){ |
| 90688 | + assert( db->mallocFailed ); /* Error reported through mallocFailed */ |
| 90689 | + return; |
| 90690 | + } |
| 90691 | + pParse->azVar = a; |
| 90692 | + memset(&a[pParse->nzVar], 0, (x-pParse->nzVar)*sizeof(a[0])); |
| 90693 | + pParse->nzVar = x; |
| 90694 | + } |
| 90695 | + if( pParse->azVar[x-1]==0 ){ |
| 90696 | + pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n); |
| 90697 | + } |
| 90698 | + } |
| 90699 | + if( pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 90702 | 90700 | sqlite3ErrorMsg(pParse, "too many SQL variables"); |
| 90703 | 90701 | } |
| 90704 | 90702 | } |
| 90705 | 90703 | |
| 90706 | 90704 | /* |
| | @@ -92656,36 +92654,23 @@ |
| 92656 | 92654 | #endif |
| 92657 | 92655 | } |
| 92658 | 92656 | } |
| 92659 | 92657 | } |
| 92660 | 92658 | |
| 92661 | | -#if defined(SQLITE_DEBUG) |
| 92662 | | -/* |
| 92663 | | -** Verify the consistency of the column cache |
| 92664 | | -*/ |
| 92665 | | -static int cacheIsValid(Parse *pParse){ |
| 92666 | | - int i, n; |
| 92667 | | - for(i=n=0; i<SQLITE_N_COLCACHE; i++){ |
| 92668 | | - if( pParse->aColCache[i].iReg>0 ) n++; |
| 92669 | | - } |
| 92670 | | - return n==pParse->nColCache; |
| 92671 | | -} |
| 92672 | | -#endif |
| 92673 | | - |
| 92674 | | -/* |
| 92675 | | -** Clear a cache entry. |
| 92676 | | -*/ |
| 92677 | | -static void cacheEntryClear(Parse *pParse, struct yColCache *p){ |
| 92678 | | - if( p->tempReg ){ |
| 92659 | +/* |
| 92660 | +** Erase column-cache entry number i |
| 92661 | +*/ |
| 92662 | +static void cacheEntryClear(Parse *pParse, int i){ |
| 92663 | + if( pParse->aColCache[i].tempReg ){ |
| 92679 | 92664 | if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){ |
| 92680 | | - pParse->aTempReg[pParse->nTempReg++] = p->iReg; |
| 92665 | + pParse->aTempReg[pParse->nTempReg++] = pParse->aColCache[i].iReg; |
| 92681 | 92666 | } |
| 92682 | | - p->tempReg = 0; |
| 92683 | 92667 | } |
| 92684 | | - p->iReg = 0; |
| 92685 | 92668 | pParse->nColCache--; |
| 92686 | | - assert( pParse->db->mallocFailed || cacheIsValid(pParse) ); |
| 92669 | + if( i<pParse->nColCache ){ |
| 92670 | + pParse->aColCache[i] = pParse->aColCache[pParse->nColCache]; |
| 92671 | + } |
| 92687 | 92672 | } |
| 92688 | 92673 | |
| 92689 | 92674 | |
| 92690 | 92675 | /* |
| 92691 | 92676 | ** Record in the column cache that a particular column from a |
| | @@ -92711,64 +92696,52 @@ |
| 92711 | 92696 | ** |
| 92712 | 92697 | ** Actually, the way the column cache is currently used, we are guaranteed |
| 92713 | 92698 | ** that the object will never already be in cache. Verify this guarantee. |
| 92714 | 92699 | */ |
| 92715 | 92700 | #ifndef NDEBUG |
| 92716 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92717 | | - assert( p->iReg==0 || p->iTable!=iTab || p->iColumn!=iCol ); |
| 92701 | + for(i=0, p=pParse->aColCache; i<pParse->nColCache; i++, p++){ |
| 92702 | + assert( p->iTable!=iTab || p->iColumn!=iCol ); |
| 92718 | 92703 | } |
| 92719 | 92704 | #endif |
| 92720 | 92705 | |
| 92721 | | - /* Find an empty slot and replace it */ |
| 92722 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92723 | | - if( p->iReg==0 ){ |
| 92724 | | - p->iLevel = pParse->iCacheLevel; |
| 92725 | | - p->iTable = iTab; |
| 92726 | | - p->iColumn = iCol; |
| 92727 | | - p->iReg = iReg; |
| 92728 | | - p->tempReg = 0; |
| 92729 | | - p->lru = pParse->iCacheCnt++; |
| 92730 | | - pParse->nColCache++; |
| 92731 | | - assert( pParse->db->mallocFailed || cacheIsValid(pParse) ); |
| 92732 | | - return; |
| 92733 | | - } |
| 92734 | | - } |
| 92735 | | - |
| 92736 | | - /* Replace the last recently used */ |
| 92737 | | - minLru = 0x7fffffff; |
| 92738 | | - idxLru = -1; |
| 92739 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92740 | | - if( p->lru<minLru ){ |
| 92741 | | - idxLru = i; |
| 92742 | | - minLru = p->lru; |
| 92743 | | - } |
| 92744 | | - } |
| 92745 | | - if( ALWAYS(idxLru>=0) ){ |
| 92706 | + /* If the cache is already full, delete the least recently used entry */ |
| 92707 | + if( pParse->nColCache>=SQLITE_N_COLCACHE ){ |
| 92708 | + minLru = 0x7fffffff; |
| 92709 | + idxLru = -1; |
| 92710 | + for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92711 | + if( p->lru<minLru ){ |
| 92712 | + idxLru = i; |
| 92713 | + minLru = p->lru; |
| 92714 | + } |
| 92715 | + } |
| 92746 | 92716 | p = &pParse->aColCache[idxLru]; |
| 92747 | | - p->iLevel = pParse->iCacheLevel; |
| 92748 | | - p->iTable = iTab; |
| 92749 | | - p->iColumn = iCol; |
| 92750 | | - p->iReg = iReg; |
| 92751 | | - p->tempReg = 0; |
| 92752 | | - p->lru = pParse->iCacheCnt++; |
| 92753 | | - assert( cacheIsValid(pParse) ); |
| 92754 | | - return; |
| 92755 | | - } |
| 92717 | + }else{ |
| 92718 | + p = &pParse->aColCache[pParse->nColCache++]; |
| 92719 | + } |
| 92720 | + |
| 92721 | + /* Add the new entry to the end of the cache */ |
| 92722 | + p->iLevel = pParse->iCacheLevel; |
| 92723 | + p->iTable = iTab; |
| 92724 | + p->iColumn = iCol; |
| 92725 | + p->iReg = iReg; |
| 92726 | + p->tempReg = 0; |
| 92727 | + p->lru = pParse->iCacheCnt++; |
| 92756 | 92728 | } |
| 92757 | 92729 | |
| 92758 | 92730 | /* |
| 92759 | 92731 | ** Indicate that registers between iReg..iReg+nReg-1 are being overwritten. |
| 92760 | 92732 | ** Purge the range of registers from the column cache. |
| 92761 | 92733 | */ |
| 92762 | 92734 | SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){ |
| 92763 | | - struct yColCache *p; |
| 92764 | | - if( iReg<=0 || pParse->nColCache==0 ) return; |
| 92765 | | - p = &pParse->aColCache[SQLITE_N_COLCACHE-1]; |
| 92766 | | - while(1){ |
| 92767 | | - if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p); |
| 92768 | | - if( p==pParse->aColCache ) break; |
| 92769 | | - p--; |
| 92735 | + int i = 0; |
| 92736 | + while( i<pParse->nColCache ){ |
| 92737 | + struct yColCache *p = &pParse->aColCache[i]; |
| 92738 | + if( p->iReg >= iReg && p->iReg < iReg+nReg ){ |
| 92739 | + cacheEntryClear(pParse, i); |
| 92740 | + }else{ |
| 92741 | + i++; |
| 92742 | + } |
| 92770 | 92743 | } |
| 92771 | 92744 | } |
| 92772 | 92745 | |
| 92773 | 92746 | /* |
| 92774 | 92747 | ** Remember the current column cache context. Any new entries added |
| | @@ -92788,22 +92761,23 @@ |
| 92788 | 92761 | ** Remove from the column cache any entries that were added since the |
| 92789 | 92762 | ** the previous sqlite3ExprCachePush operation. In other words, restore |
| 92790 | 92763 | ** the cache to the state it was in prior the most recent Push. |
| 92791 | 92764 | */ |
| 92792 | 92765 | SQLITE_PRIVATE void sqlite3ExprCachePop(Parse *pParse){ |
| 92793 | | - int i; |
| 92794 | | - struct yColCache *p; |
| 92766 | + int i = 0; |
| 92795 | 92767 | assert( pParse->iCacheLevel>=1 ); |
| 92796 | 92768 | pParse->iCacheLevel--; |
| 92797 | 92769 | #ifdef SQLITE_DEBUG |
| 92798 | 92770 | if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ |
| 92799 | 92771 | printf("POP to %d\n", pParse->iCacheLevel); |
| 92800 | 92772 | } |
| 92801 | 92773 | #endif |
| 92802 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92803 | | - if( p->iReg && p->iLevel>pParse->iCacheLevel ){ |
| 92804 | | - cacheEntryClear(pParse, p); |
| 92774 | + while( i<pParse->nColCache ){ |
| 92775 | + if( pParse->aColCache[i].iLevel>pParse->iCacheLevel ){ |
| 92776 | + cacheEntryClear(pParse, i); |
| 92777 | + }else{ |
| 92778 | + i++; |
| 92805 | 92779 | } |
| 92806 | 92780 | } |
| 92807 | 92781 | } |
| 92808 | 92782 | |
| 92809 | 92783 | /* |
| | @@ -92813,11 +92787,11 @@ |
| 92813 | 92787 | ** get them all. |
| 92814 | 92788 | */ |
| 92815 | 92789 | static void sqlite3ExprCachePinRegister(Parse *pParse, int iReg){ |
| 92816 | 92790 | int i; |
| 92817 | 92791 | struct yColCache *p; |
| 92818 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92792 | + for(i=0, p=pParse->aColCache; i<pParse->nColCache; i++, p++){ |
| 92819 | 92793 | if( p->iReg==iReg ){ |
| 92820 | 92794 | p->tempReg = 0; |
| 92821 | 92795 | } |
| 92822 | 92796 | } |
| 92823 | 92797 | } |
| | @@ -92891,12 +92865,12 @@ |
| 92891 | 92865 | ){ |
| 92892 | 92866 | Vdbe *v = pParse->pVdbe; |
| 92893 | 92867 | int i; |
| 92894 | 92868 | struct yColCache *p; |
| 92895 | 92869 | |
| 92896 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92897 | | - if( p->iReg>0 && p->iTable==iTable && p->iColumn==iColumn ){ |
| 92870 | + for(i=0, p=pParse->aColCache; i<pParse->nColCache; i++, p++){ |
| 92871 | + if( p->iTable==iTable && p->iColumn==iColumn ){ |
| 92898 | 92872 | p->lru = pParse->iCacheCnt++; |
| 92899 | 92873 | sqlite3ExprCachePinRegister(pParse, p->iReg); |
| 92900 | 92874 | return p->iReg; |
| 92901 | 92875 | } |
| 92902 | 92876 | } |
| | @@ -92924,22 +92898,24 @@ |
| 92924 | 92898 | /* |
| 92925 | 92899 | ** Clear all column cache entries. |
| 92926 | 92900 | */ |
| 92927 | 92901 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){ |
| 92928 | 92902 | int i; |
| 92929 | | - struct yColCache *p; |
| 92930 | 92903 | |
| 92931 | 92904 | #if SQLITE_DEBUG |
| 92932 | 92905 | if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ |
| 92933 | 92906 | printf("CLEAR\n"); |
| 92934 | 92907 | } |
| 92935 | 92908 | #endif |
| 92936 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92937 | | - if( p->iReg ){ |
| 92938 | | - cacheEntryClear(pParse, p); |
| 92909 | + for(i=0; i<pParse->nColCache; i++){ |
| 92910 | + if( pParse->aColCache[i].tempReg |
| 92911 | + && pParse->nTempReg<ArraySize(pParse->aTempReg) |
| 92912 | + ){ |
| 92913 | + pParse->aTempReg[pParse->nTempReg++] = pParse->aColCache[i].iReg; |
| 92939 | 92914 | } |
| 92940 | 92915 | } |
| 92916 | + pParse->nColCache = 0; |
| 92941 | 92917 | } |
| 92942 | 92918 | |
| 92943 | 92919 | /* |
| 92944 | 92920 | ** Record the fact that an affinity change has occurred on iCount |
| 92945 | 92921 | ** registers starting with iStart. |
| | @@ -92967,11 +92943,11 @@ |
| 92967 | 92943 | ** and does not appear in a normal build. |
| 92968 | 92944 | */ |
| 92969 | 92945 | static int usedAsColumnCache(Parse *pParse, int iFrom, int iTo){ |
| 92970 | 92946 | int i; |
| 92971 | 92947 | struct yColCache *p; |
| 92972 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 92948 | + for(i=0, p=pParse->aColCache; i<pParse->nColCache; i++, p++){ |
| 92973 | 92949 | int r = p->iReg; |
| 92974 | 92950 | if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/ |
| 92975 | 92951 | } |
| 92976 | 92952 | return 0; |
| 92977 | 92953 | } |
| | @@ -94663,11 +94639,11 @@ |
| 94663 | 94639 | */ |
| 94664 | 94640 | SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){ |
| 94665 | 94641 | if( iReg && pParse->nTempReg<ArraySize(pParse->aTempReg) ){ |
| 94666 | 94642 | int i; |
| 94667 | 94643 | struct yColCache *p; |
| 94668 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 94644 | + for(i=0, p=pParse->aColCache; i<pParse->nColCache; i++, p++){ |
| 94669 | 94645 | if( p->iReg==iReg ){ |
| 94670 | 94646 | p->tempReg = 1; |
| 94671 | 94647 | return; |
| 94672 | 94648 | } |
| 94673 | 94649 | } |
| | @@ -98433,11 +98409,10 @@ |
| 98433 | 98409 | */ |
| 98434 | 98410 | v = sqlite3GetVdbe(pParse); |
| 98435 | 98411 | assert( !pParse->isMultiWrite |
| 98436 | 98412 | || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort)); |
| 98437 | 98413 | if( v ){ |
| 98438 | | - while( sqlite3VdbeDeletePriorOpcode(v, OP_Close) ){} |
| 98439 | 98414 | sqlite3VdbeAddOp0(v, OP_Halt); |
| 98440 | 98415 | |
| 98441 | 98416 | #if SQLITE_USER_AUTHENTICATION |
| 98442 | 98417 | if( pParse->nTableLock>0 && db->init.busy==0 ){ |
| 98443 | 98418 | sqlite3UserAuthInit(db); |
| | @@ -98460,18 +98435,20 @@ |
| 98460 | 98435 | ){ |
| 98461 | 98436 | int iDb, i; |
| 98462 | 98437 | assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init ); |
| 98463 | 98438 | sqlite3VdbeJumpHere(v, 0); |
| 98464 | 98439 | for(iDb=0; iDb<db->nDb; iDb++){ |
| 98440 | + Schema *pSchema; |
| 98465 | 98441 | if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue; |
| 98466 | 98442 | sqlite3VdbeUsesBtree(v, iDb); |
| 98443 | + pSchema = db->aDb[iDb].pSchema; |
| 98467 | 98444 | sqlite3VdbeAddOp4Int(v, |
| 98468 | 98445 | OP_Transaction, /* Opcode */ |
| 98469 | 98446 | iDb, /* P1 */ |
| 98470 | 98447 | DbMaskTest(pParse->writeMask,iDb), /* P2 */ |
| 98471 | | - pParse->cookieValue[iDb], /* P3 */ |
| 98472 | | - db->aDb[iDb].pSchema->iGeneration /* P4 */ |
| 98448 | + pSchema->schema_cookie, /* P3 */ |
| 98449 | + pSchema->iGeneration /* P4 */ |
| 98473 | 98450 | ); |
| 98474 | 98451 | if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1); |
| 98475 | 98452 | VdbeComment((v, |
| 98476 | 98453 | "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite)); |
| 98477 | 98454 | } |
| | @@ -98518,20 +98495,10 @@ |
| 98518 | 98495 | sqlite3VdbeMakeReady(v, pParse); |
| 98519 | 98496 | pParse->rc = SQLITE_DONE; |
| 98520 | 98497 | }else{ |
| 98521 | 98498 | pParse->rc = SQLITE_ERROR; |
| 98522 | 98499 | } |
| 98523 | | - |
| 98524 | | - /* We are done with this Parse object. There is no need to de-initialize it */ |
| 98525 | | -#if 0 |
| 98526 | | - pParse->colNamesSet = 0; |
| 98527 | | - pParse->nTab = 0; |
| 98528 | | - pParse->nMem = 0; |
| 98529 | | - pParse->nSet = 0; |
| 98530 | | - pParse->nVar = 0; |
| 98531 | | - DbMaskZero(pParse->cookieMask); |
| 98532 | | -#endif |
| 98533 | 98500 | } |
| 98534 | 98501 | |
| 98535 | 98502 | /* |
| 98536 | 98503 | ** Run the parser and code generator recursively in order to generate |
| 98537 | 98504 | ** code for the SQL statement given onto the end of the pParse context |
| | @@ -98547,12 +98514,11 @@ |
| 98547 | 98514 | SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){ |
| 98548 | 98515 | va_list ap; |
| 98549 | 98516 | char *zSql; |
| 98550 | 98517 | char *zErrMsg = 0; |
| 98551 | 98518 | sqlite3 *db = pParse->db; |
| 98552 | | -# define SAVE_SZ (sizeof(Parse) - offsetof(Parse,nVar)) |
| 98553 | | - char saveBuf[SAVE_SZ]; |
| 98519 | + char saveBuf[PARSE_TAIL_SZ]; |
| 98554 | 98520 | |
| 98555 | 98521 | if( pParse->nErr ) return; |
| 98556 | 98522 | assert( pParse->nested<10 ); /* Nesting should only be of limited depth */ |
| 98557 | 98523 | va_start(ap, zFormat); |
| 98558 | 98524 | zSql = sqlite3VMPrintf(db, zFormat, ap); |
| | @@ -98559,16 +98525,16 @@ |
| 98559 | 98525 | va_end(ap); |
| 98560 | 98526 | if( zSql==0 ){ |
| 98561 | 98527 | return; /* A malloc must have failed */ |
| 98562 | 98528 | } |
| 98563 | 98529 | pParse->nested++; |
| 98564 | | - memcpy(saveBuf, &pParse->nVar, SAVE_SZ); |
| 98565 | | - memset(&pParse->nVar, 0, SAVE_SZ); |
| 98530 | + memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ); |
| 98531 | + memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ); |
| 98566 | 98532 | sqlite3RunParser(pParse, zSql, &zErrMsg); |
| 98567 | 98533 | sqlite3DbFree(db, zErrMsg); |
| 98568 | 98534 | sqlite3DbFree(db, zSql); |
| 98569 | | - memcpy(&pParse->nVar, saveBuf, SAVE_SZ); |
| 98535 | + memcpy(PARSE_TAIL(pParse), saveBuf, PARSE_TAIL_SZ); |
| 98570 | 98536 | pParse->nested--; |
| 98571 | 98537 | } |
| 98572 | 98538 | |
| 98573 | 98539 | #if SQLITE_USER_AUTHENTICATION |
| 98574 | 98540 | /* |
| | @@ -102331,19 +102297,17 @@ |
| 102331 | 102297 | ** will occur at the end of the top-level VDBE and will be generated |
| 102332 | 102298 | ** later, by sqlite3FinishCoding(). |
| 102333 | 102299 | */ |
| 102334 | 102300 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){ |
| 102335 | 102301 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 102336 | | - sqlite3 *db = pToplevel->db; |
| 102337 | 102302 | |
| 102338 | | - assert( iDb>=0 && iDb<db->nDb ); |
| 102339 | | - assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 102303 | + assert( iDb>=0 && iDb<pParse->db->nDb ); |
| 102304 | + assert( pParse->db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 102340 | 102305 | assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 102341 | | - assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 102306 | + assert( sqlite3SchemaMutexHeld(pParse->db, iDb, 0) ); |
| 102342 | 102307 | if( DbMaskTest(pToplevel->cookieMask, iDb)==0 ){ |
| 102343 | 102308 | DbMaskSet(pToplevel->cookieMask, iDb); |
| 102344 | | - pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 102345 | 102309 | if( !OMIT_TEMPDB && iDb==1 ){ |
| 102346 | 102310 | sqlite3OpenTempDatabase(pToplevel); |
| 102347 | 102311 | } |
| 102348 | 102312 | } |
| 102349 | 102313 | } |
| | @@ -109551,10 +109515,11 @@ |
| 109551 | 109515 | } |
| 109552 | 109516 | if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest); |
| 109553 | 109517 | sqlite3ReleaseTempReg(pParse, regRowid); |
| 109554 | 109518 | sqlite3ReleaseTempReg(pParse, regData); |
| 109555 | 109519 | if( emptyDestTest ){ |
| 109520 | + sqlite3AutoincrementEnd(pParse); |
| 109556 | 109521 | sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0); |
| 109557 | 109522 | sqlite3VdbeJumpHere(v, emptyDestTest); |
| 109558 | 109523 | sqlite3VdbeAddOp2(v, OP_Close, iDest, 0); |
| 109559 | 109524 | return 0; |
| 109560 | 109525 | }else{ |
| | @@ -114047,22 +114012,18 @@ |
| 114047 | 114012 | int saveSqlFlag, /* True to copy SQL text into the sqlite3_stmt */ |
| 114048 | 114013 | Vdbe *pReprepare, /* VM being reprepared */ |
| 114049 | 114014 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 114050 | 114015 | const char **pzTail /* OUT: End of parsed string */ |
| 114051 | 114016 | ){ |
| 114052 | | - Parse *pParse; /* Parsing context */ |
| 114053 | 114017 | char *zErrMsg = 0; /* Error message */ |
| 114054 | 114018 | int rc = SQLITE_OK; /* Result code */ |
| 114055 | 114019 | int i; /* Loop counter */ |
| 114056 | | - |
| 114057 | | - /* Allocate the parsing context */ |
| 114058 | | - pParse = sqlite3StackAllocZero(db, sizeof(*pParse)); |
| 114059 | | - if( pParse==0 ){ |
| 114060 | | - rc = SQLITE_NOMEM_BKPT; |
| 114061 | | - goto end_prepare; |
| 114062 | | - } |
| 114063 | | - pParse->pReprepare = pReprepare; |
| 114020 | + Parse sParse; /* Parsing context */ |
| 114021 | + |
| 114022 | + memset(&sParse, 0, PARSE_HDR_SZ); |
| 114023 | + memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ); |
| 114024 | + sParse.pReprepare = pReprepare; |
| 114064 | 114025 | assert( ppStmt && *ppStmt==0 ); |
| 114065 | 114026 | /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */ |
| 114066 | 114027 | assert( sqlite3_mutex_held(db->mutex) ); |
| 114067 | 114028 | |
| 114068 | 114029 | /* Check to verify that it is possible to get a read lock on all |
| | @@ -114102,12 +114063,11 @@ |
| 114102 | 114063 | } |
| 114103 | 114064 | } |
| 114104 | 114065 | |
| 114105 | 114066 | sqlite3VtabUnlockList(db); |
| 114106 | 114067 | |
| 114107 | | - pParse->db = db; |
| 114108 | | - pParse->nQueryLoop = 0; /* Logarithmic, so 0 really means 1 */ |
| 114068 | + sParse.db = db; |
| 114109 | 114069 | if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){ |
| 114110 | 114070 | char *zSqlCopy; |
| 114111 | 114071 | int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 114112 | 114072 | testcase( nBytes==mxLen ); |
| 114113 | 114073 | testcase( nBytes==mxLen+1 ); |
| | @@ -114116,65 +114076,65 @@ |
| 114116 | 114076 | rc = sqlite3ApiExit(db, SQLITE_TOOBIG); |
| 114117 | 114077 | goto end_prepare; |
| 114118 | 114078 | } |
| 114119 | 114079 | zSqlCopy = sqlite3DbStrNDup(db, zSql, nBytes); |
| 114120 | 114080 | if( zSqlCopy ){ |
| 114121 | | - sqlite3RunParser(pParse, zSqlCopy, &zErrMsg); |
| 114122 | | - pParse->zTail = &zSql[pParse->zTail-zSqlCopy]; |
| 114081 | + sqlite3RunParser(&sParse, zSqlCopy, &zErrMsg); |
| 114082 | + sParse.zTail = &zSql[sParse.zTail-zSqlCopy]; |
| 114123 | 114083 | sqlite3DbFree(db, zSqlCopy); |
| 114124 | 114084 | }else{ |
| 114125 | | - pParse->zTail = &zSql[nBytes]; |
| 114085 | + sParse.zTail = &zSql[nBytes]; |
| 114126 | 114086 | } |
| 114127 | 114087 | }else{ |
| 114128 | | - sqlite3RunParser(pParse, zSql, &zErrMsg); |
| 114088 | + sqlite3RunParser(&sParse, zSql, &zErrMsg); |
| 114129 | 114089 | } |
| 114130 | | - assert( 0==pParse->nQueryLoop ); |
| 114090 | + assert( 0==sParse.nQueryLoop ); |
| 114131 | 114091 | |
| 114132 | | - if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK; |
| 114133 | | - if( pParse->checkSchema ){ |
| 114134 | | - schemaIsValid(pParse); |
| 114092 | + if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK; |
| 114093 | + if( sParse.checkSchema ){ |
| 114094 | + schemaIsValid(&sParse); |
| 114135 | 114095 | } |
| 114136 | 114096 | if( db->mallocFailed ){ |
| 114137 | | - pParse->rc = SQLITE_NOMEM_BKPT; |
| 114097 | + sParse.rc = SQLITE_NOMEM_BKPT; |
| 114138 | 114098 | } |
| 114139 | 114099 | if( pzTail ){ |
| 114140 | | - *pzTail = pParse->zTail; |
| 114100 | + *pzTail = sParse.zTail; |
| 114141 | 114101 | } |
| 114142 | | - rc = pParse->rc; |
| 114102 | + rc = sParse.rc; |
| 114143 | 114103 | |
| 114144 | 114104 | #ifndef SQLITE_OMIT_EXPLAIN |
| 114145 | | - if( rc==SQLITE_OK && pParse->pVdbe && pParse->explain ){ |
| 114105 | + if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){ |
| 114146 | 114106 | static const char * const azColName[] = { |
| 114147 | 114107 | "addr", "opcode", "p1", "p2", "p3", "p4", "p5", "comment", |
| 114148 | 114108 | "selectid", "order", "from", "detail" |
| 114149 | 114109 | }; |
| 114150 | 114110 | int iFirst, mx; |
| 114151 | | - if( pParse->explain==2 ){ |
| 114152 | | - sqlite3VdbeSetNumCols(pParse->pVdbe, 4); |
| 114111 | + if( sParse.explain==2 ){ |
| 114112 | + sqlite3VdbeSetNumCols(sParse.pVdbe, 4); |
| 114153 | 114113 | iFirst = 8; |
| 114154 | 114114 | mx = 12; |
| 114155 | 114115 | }else{ |
| 114156 | | - sqlite3VdbeSetNumCols(pParse->pVdbe, 8); |
| 114116 | + sqlite3VdbeSetNumCols(sParse.pVdbe, 8); |
| 114157 | 114117 | iFirst = 0; |
| 114158 | 114118 | mx = 8; |
| 114159 | 114119 | } |
| 114160 | 114120 | for(i=iFirst; i<mx; i++){ |
| 114161 | | - sqlite3VdbeSetColName(pParse->pVdbe, i-iFirst, COLNAME_NAME, |
| 114121 | + sqlite3VdbeSetColName(sParse.pVdbe, i-iFirst, COLNAME_NAME, |
| 114162 | 114122 | azColName[i], SQLITE_STATIC); |
| 114163 | 114123 | } |
| 114164 | 114124 | } |
| 114165 | 114125 | #endif |
| 114166 | 114126 | |
| 114167 | 114127 | if( db->init.busy==0 ){ |
| 114168 | | - Vdbe *pVdbe = pParse->pVdbe; |
| 114169 | | - sqlite3VdbeSetSql(pVdbe, zSql, (int)(pParse->zTail-zSql), saveSqlFlag); |
| 114128 | + Vdbe *pVdbe = sParse.pVdbe; |
| 114129 | + sqlite3VdbeSetSql(pVdbe, zSql, (int)(sParse.zTail-zSql), saveSqlFlag); |
| 114170 | 114130 | } |
| 114171 | | - if( pParse->pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){ |
| 114172 | | - sqlite3VdbeFinalize(pParse->pVdbe); |
| 114131 | + if( sParse.pVdbe && (rc!=SQLITE_OK || db->mallocFailed) ){ |
| 114132 | + sqlite3VdbeFinalize(sParse.pVdbe); |
| 114173 | 114133 | assert(!(*ppStmt)); |
| 114174 | 114134 | }else{ |
| 114175 | | - *ppStmt = (sqlite3_stmt*)pParse->pVdbe; |
| 114135 | + *ppStmt = (sqlite3_stmt*)sParse.pVdbe; |
| 114176 | 114136 | } |
| 114177 | 114137 | |
| 114178 | 114138 | if( zErrMsg ){ |
| 114179 | 114139 | sqlite3ErrorWithMsg(db, rc, "%s", zErrMsg); |
| 114180 | 114140 | sqlite3DbFree(db, zErrMsg); |
| | @@ -114181,20 +114141,19 @@ |
| 114181 | 114141 | }else{ |
| 114182 | 114142 | sqlite3Error(db, rc); |
| 114183 | 114143 | } |
| 114184 | 114144 | |
| 114185 | 114145 | /* Delete any TriggerPrg structures allocated while parsing this statement. */ |
| 114186 | | - while( pParse->pTriggerPrg ){ |
| 114187 | | - TriggerPrg *pT = pParse->pTriggerPrg; |
| 114188 | | - pParse->pTriggerPrg = pT->pNext; |
| 114146 | + while( sParse.pTriggerPrg ){ |
| 114147 | + TriggerPrg *pT = sParse.pTriggerPrg; |
| 114148 | + sParse.pTriggerPrg = pT->pNext; |
| 114189 | 114149 | sqlite3DbFree(db, pT); |
| 114190 | 114150 | } |
| 114191 | 114151 | |
| 114192 | 114152 | end_prepare: |
| 114193 | 114153 | |
| 114194 | | - sqlite3ParserReset(pParse); |
| 114195 | | - sqlite3StackFree(db, pParse); |
| 114154 | + sqlite3ParserReset(&sParse); |
| 114196 | 114155 | rc = sqlite3ApiExit(db, rc); |
| 114197 | 114156 | assert( (rc&db->errMask)==rc ); |
| 114198 | 114157 | return rc; |
| 114199 | 114158 | } |
| 114200 | 114159 | static int sqlite3LockAndPrepare( |
| | @@ -115395,11 +115354,11 @@ |
| 115395 | 115354 | ** Allocate a KeyInfo object sufficient for an index of N key columns and |
| 115396 | 115355 | ** X extra columns. |
| 115397 | 115356 | */ |
| 115398 | 115357 | SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){ |
| 115399 | 115358 | int nExtra = (N+X)*(sizeof(CollSeq*)+1); |
| 115400 | | - KeyInfo *p = sqlite3DbMallocRaw(db, sizeof(KeyInfo) + nExtra); |
| 115359 | + KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra); |
| 115401 | 115360 | if( p ){ |
| 115402 | 115361 | p->aSortOrder = (u8*)&p->aColl[N+X]; |
| 115403 | 115362 | p->nField = (u16)N; |
| 115404 | 115363 | p->nXField = (u16)X; |
| 115405 | 115364 | p->enc = ENC(db); |
| | @@ -124055,24 +124014,24 @@ |
| 124055 | 124014 | ** in prereqRight and prereqAll. The default is 64 bits, hence SQLite |
| 124056 | 124015 | ** is only able to process joins with 64 or fewer tables. |
| 124057 | 124016 | */ |
| 124058 | 124017 | struct WhereTerm { |
| 124059 | 124018 | Expr *pExpr; /* Pointer to the subexpression that is this term */ |
| 124019 | + WhereClause *pWC; /* The clause this term is part of */ |
| 124020 | + LogEst truthProb; /* Probability of truth for this expression */ |
| 124021 | + u16 wtFlags; /* TERM_xxx bit flags. See below */ |
| 124022 | + u16 eOperator; /* A WO_xx value describing <op> */ |
| 124023 | + u8 nChild; /* Number of children that must disable us */ |
| 124024 | + u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */ |
| 124060 | 124025 | int iParent; /* Disable pWC->a[iParent] when this term disabled */ |
| 124061 | 124026 | int leftCursor; /* Cursor number of X in "X <op> <expr>" */ |
| 124062 | 124027 | int iField; /* Field in (?,?,?) IN (SELECT...) vector */ |
| 124063 | 124028 | union { |
| 124064 | 124029 | int leftColumn; /* Column number of X in "X <op> <expr>" */ |
| 124065 | 124030 | WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */ |
| 124066 | 124031 | WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */ |
| 124067 | 124032 | } u; |
| 124068 | | - LogEst truthProb; /* Probability of truth for this expression */ |
| 124069 | | - u16 eOperator; /* A WO_xx value describing <op> */ |
| 124070 | | - u16 wtFlags; /* TERM_xxx bit flags. See below */ |
| 124071 | | - u8 nChild; /* Number of children that must disable us */ |
| 124072 | | - u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */ |
| 124073 | | - WhereClause *pWC; /* The clause this term is part of */ |
| 124074 | 124033 | Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */ |
| 124075 | 124034 | Bitmask prereqAll; /* Bitmask of tables referenced by pExpr */ |
| 124076 | 124035 | }; |
| 124077 | 124036 | |
| 124078 | 124037 | /* |
| | @@ -124221,29 +124180,29 @@ |
| 124221 | 124180 | struct WhereInfo { |
| 124222 | 124181 | Parse *pParse; /* Parsing and code generating context */ |
| 124223 | 124182 | SrcList *pTabList; /* List of tables in the join */ |
| 124224 | 124183 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 124225 | 124184 | ExprList *pDistinctSet; /* DISTINCT over all these values */ |
| 124226 | | - WhereLoop *pLoops; /* List of all WhereLoop objects */ |
| 124227 | | - Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 124228 | | - LogEst nRowOut; /* Estimated number of output rows */ |
| 124229 | 124185 | LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */ |
| 124186 | + int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ |
| 124187 | + int iContinue; /* Jump here to continue with next record */ |
| 124188 | + int iBreak; /* Jump here to break out of the loop */ |
| 124189 | + int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ |
| 124230 | 124190 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| 124191 | + u8 nLevel; /* Number of nested loop */ |
| 124231 | 124192 | i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */ |
| 124232 | 124193 | u8 sorted; /* True if really sorted (not just grouped) */ |
| 124233 | 124194 | u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */ |
| 124234 | 124195 | u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ |
| 124235 | 124196 | u8 eDistinct; /* One of the WHERE_DISTINCT_* values */ |
| 124236 | | - u8 nLevel; /* Number of nested loop */ |
| 124237 | 124197 | u8 bOrderedInnerLoop; /* True if only the inner-most loop is ordered */ |
| 124238 | 124198 | int iTop; /* The very beginning of the WHERE loop */ |
| 124239 | | - int iContinue; /* Jump here to continue with next record */ |
| 124240 | | - int iBreak; /* Jump here to break out of the loop */ |
| 124241 | | - int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ |
| 124242 | | - int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ |
| 124243 | | - WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */ |
| 124199 | + WhereLoop *pLoops; /* List of all WhereLoop objects */ |
| 124200 | + Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 124201 | + LogEst nRowOut; /* Estimated number of output rows */ |
| 124244 | 124202 | WhereClause sWC; /* Decomposition of the WHERE clause */ |
| 124203 | + WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */ |
| 124245 | 124204 | WhereLevel a[1]; /* Information about each nest loop in WHERE */ |
| 124246 | 124205 | }; |
| 124247 | 124206 | |
| 124248 | 124207 | /* |
| 124249 | 124208 | ** Private interfaces - callable only by other where.c routines. |
| | @@ -124703,11 +124662,10 @@ |
| 124703 | 124662 | ** |
| 124704 | 124663 | ** * the comparison will be performed with no affinity, or |
| 124705 | 124664 | ** * the affinity change in zAff is guaranteed not to change the value. |
| 124706 | 124665 | */ |
| 124707 | 124666 | static void updateRangeAffinityStr( |
| 124708 | | - Parse *pParse, /* Parse context */ |
| 124709 | 124667 | Expr *pRight, /* RHS of comparison */ |
| 124710 | 124668 | int n, /* Number of vector elements in comparison */ |
| 124711 | 124669 | char *zAff /* Affinity string to modify */ |
| 124712 | 124670 | ){ |
| 124713 | 124671 | int i; |
| | @@ -125789,15 +125747,15 @@ |
| 125789 | 125747 | assert( (bRev & ~1)==0 ); |
| 125790 | 125748 | pLevel->iLikeRepCntr <<=1; |
| 125791 | 125749 | pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC); |
| 125792 | 125750 | } |
| 125793 | 125751 | #endif |
| 125794 | | - if( pRangeStart==0 |
| 125795 | | - && (j = pIdx->aiColumn[nEq])>=0 |
| 125796 | | - && pIdx->pTable->aCol[j].notNull==0 |
| 125797 | | - ){ |
| 125798 | | - bSeekPastNull = 1; |
| 125752 | + if( pRangeStart==0 ){ |
| 125753 | + j = pIdx->aiColumn[nEq]; |
| 125754 | + if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){ |
| 125755 | + bSeekPastNull = 1; |
| 125756 | + } |
| 125799 | 125757 | } |
| 125800 | 125758 | } |
| 125801 | 125759 | assert( pRangeEnd==0 || (pRangeEnd->wtFlags & TERM_VNULL)==0 ); |
| 125802 | 125760 | |
| 125803 | 125761 | /* If we are doing a reverse order scan on an ascending index, or |
| | @@ -125843,11 +125801,11 @@ |
| 125843 | 125801 | ){ |
| 125844 | 125802 | sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt); |
| 125845 | 125803 | VdbeCoverage(v); |
| 125846 | 125804 | } |
| 125847 | 125805 | if( zStartAff ){ |
| 125848 | | - updateRangeAffinityStr(pParse, pRight, nBtm, &zStartAff[nEq]); |
| 125806 | + updateRangeAffinityStr(pRight, nBtm, &zStartAff[nEq]); |
| 125849 | 125807 | } |
| 125850 | 125808 | nConstraint += nBtm; |
| 125851 | 125809 | testcase( pRangeStart->wtFlags & TERM_VIRTUAL ); |
| 125852 | 125810 | if( sqlite3ExprIsVector(pRight)==0 ){ |
| 125853 | 125811 | disableTerm(pLevel, pRangeStart); |
| | @@ -125893,11 +125851,11 @@ |
| 125893 | 125851 | ){ |
| 125894 | 125852 | sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt); |
| 125895 | 125853 | VdbeCoverage(v); |
| 125896 | 125854 | } |
| 125897 | 125855 | if( zEndAff ){ |
| 125898 | | - updateRangeAffinityStr(pParse, pRight, nTop, zEndAff); |
| 125856 | + updateRangeAffinityStr(pRight, nTop, zEndAff); |
| 125899 | 125857 | codeApplyAffinity(pParse, regBase+nEq, nTop, zEndAff); |
| 125900 | 125858 | }else{ |
| 125901 | 125859 | assert( pParse->db->mallocFailed ); |
| 125902 | 125860 | } |
| 125903 | 125861 | nConstraint += nTop; |
| | @@ -126329,11 +126287,11 @@ |
| 126329 | 126287 | ** and we are coding the t1 loop and the t2 loop has not yet coded, |
| 126330 | 126288 | ** then we cannot use the "t1.a=t2.b" constraint, but we can code |
| 126331 | 126289 | ** the implied "t1.a=123" constraint. |
| 126332 | 126290 | */ |
| 126333 | 126291 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 126334 | | - Expr *pE, *pEAlt; |
| 126292 | + Expr *pE, sEAlt; |
| 126335 | 126293 | WhereTerm *pAlt; |
| 126336 | 126294 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| 126337 | 126295 | if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue; |
| 126338 | 126296 | if( (pTerm->eOperator & WO_EQUIV)==0 ) continue; |
| 126339 | 126297 | if( pTerm->leftCursor!=iCur ) continue; |
| | @@ -126347,17 +126305,13 @@ |
| 126347 | 126305 | if( pAlt->wtFlags & (TERM_CODED) ) continue; |
| 126348 | 126306 | testcase( pAlt->eOperator & WO_EQ ); |
| 126349 | 126307 | testcase( pAlt->eOperator & WO_IS ); |
| 126350 | 126308 | testcase( pAlt->eOperator & WO_IN ); |
| 126351 | 126309 | VdbeModuleComment((v, "begin transitive constraint")); |
| 126352 | | - pEAlt = sqlite3StackAllocRaw(db, sizeof(*pEAlt)); |
| 126353 | | - if( pEAlt ){ |
| 126354 | | - *pEAlt = *pAlt->pExpr; |
| 126355 | | - pEAlt->pLeft = pE->pLeft; |
| 126356 | | - sqlite3ExprIfFalse(pParse, pEAlt, addrCont, SQLITE_JUMPIFNULL); |
| 126357 | | - sqlite3StackFree(db, pEAlt); |
| 126358 | | - } |
| 126310 | + sEAlt = *pAlt->pExpr; |
| 126311 | + sEAlt.pLeft = pE->pLeft; |
| 126312 | + sqlite3ExprIfFalse(pParse, &sEAlt, addrCont, SQLITE_JUMPIFNULL); |
| 126359 | 126313 | } |
| 126360 | 126314 | |
| 126361 | 126315 | /* For a LEFT OUTER JOIN, generate code that will record the fact that |
| 126362 | 126316 | ** at least one row of the right table has matched the left table. |
| 126363 | 126317 | */ |
| | @@ -126462,11 +126416,10 @@ |
| 126462 | 126416 | memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm); |
| 126463 | 126417 | if( pOld!=pWC->aStatic ){ |
| 126464 | 126418 | sqlite3DbFree(db, pOld); |
| 126465 | 126419 | } |
| 126466 | 126420 | pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]); |
| 126467 | | - memset(&pWC->a[pWC->nTerm], 0, sizeof(pWC->a[0])*(pWC->nSlot-pWC->nTerm)); |
| 126468 | 126421 | } |
| 126469 | 126422 | pTerm = &pWC->a[idx = pWC->nTerm++]; |
| 126470 | 126423 | if( p && ExprHasProperty(p, EP_Unlikely) ){ |
| 126471 | 126424 | pTerm->truthProb = sqlite3LogEst(p->iTable) - 270; |
| 126472 | 126425 | }else{ |
| | @@ -126474,10 +126427,12 @@ |
| 126474 | 126427 | } |
| 126475 | 126428 | pTerm->pExpr = sqlite3ExprSkipCollate(p); |
| 126476 | 126429 | pTerm->wtFlags = wtFlags; |
| 126477 | 126430 | pTerm->pWC = pWC; |
| 126478 | 126431 | pTerm->iParent = -1; |
| 126432 | + memset(&pTerm->eOperator, 0, |
| 126433 | + sizeof(WhereTerm) - offsetof(WhereTerm,eOperator)); |
| 126479 | 126434 | return idx; |
| 126480 | 126435 | } |
| 126481 | 126436 | |
| 126482 | 126437 | /* |
| 126483 | 126438 | ** Return TRUE if the given operator is one of the operators that is |
| | @@ -130048,11 +130003,11 @@ |
| 130048 | 130003 | ** CREATE INDEX ... ON (a, b, c, d, e) |
| 130049 | 130004 | ** |
| 130050 | 130005 | ** then this function would be invoked with nEq=1. The value returned in |
| 130051 | 130006 | ** this case is 3. |
| 130052 | 130007 | */ |
| 130053 | | -int whereRangeVectorLen( |
| 130008 | +static int whereRangeVectorLen( |
| 130054 | 130009 | Parse *pParse, /* Parsing context */ |
| 130055 | 130010 | int iCur, /* Cursor open on pIdx */ |
| 130056 | 130011 | Index *pIdx, /* The index to be used for a inequality constraint */ |
| 130057 | 130012 | int nEq, /* Number of prior equality constraints on same index */ |
| 130058 | 130013 | WhereTerm *pTerm /* The vector inequality constraint */ |
| | @@ -131494,11 +131449,11 @@ |
| 131494 | 131449 | if( rev ) *pRevMask |= MASKBIT(iLoop); |
| 131495 | 131450 | revSet = 1; |
| 131496 | 131451 | } |
| 131497 | 131452 | } |
| 131498 | 131453 | if( isMatch ){ |
| 131499 | | - if( iColumn<0 ){ |
| 131454 | + if( iColumn==XN_ROWID ){ |
| 131500 | 131455 | testcase( distinctColumns==0 ); |
| 131501 | 131456 | distinctColumns = 1; |
| 131502 | 131457 | } |
| 131503 | 131458 | obSat |= MASKBIT(i); |
| 131504 | 131459 | }else{ |
| | @@ -131948,15 +131903,20 @@ |
| 131948 | 131903 | } |
| 131949 | 131904 | }else{ |
| 131950 | 131905 | pWInfo->nOBSat = pFrom->isOrdered; |
| 131951 | 131906 | pWInfo->revMask = pFrom->revLoop; |
| 131952 | 131907 | if( pWInfo->nOBSat<=0 ){ |
| 131908 | + u32 wsFlags = pFrom->aLoop[nLoop-1]->wsFlags; |
| 131953 | 131909 | pWInfo->nOBSat = 0; |
| 131954 | | - if( nLoop>0 && (pFrom->aLoop[nLoop-1]->wsFlags & WHERE_ONEROW)==0 ){ |
| 131910 | + if( nLoop>0 && (wsFlags & WHERE_ONEROW)==0 |
| 131911 | + && (wsFlags & (WHERE_IPK|WHERE_COLUMN_IN))!=(WHERE_IPK|WHERE_COLUMN_IN) |
| 131912 | + ){ |
| 131955 | 131913 | Bitmask m = 0; |
| 131956 | 131914 | int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, pFrom, |
| 131957 | 131915 | WHERE_ORDERBY_LIMIT, nLoop-1, pFrom->aLoop[nLoop-1], &m); |
| 131916 | + testcase( wsFlags & WHERE_IPK ); |
| 131917 | + testcase( wsFlags & WHERE_COLUMN_IN ); |
| 131958 | 131918 | if( rc==pWInfo->pOrderBy->nExpr ){ |
| 131959 | 131919 | pWInfo->bOrderedInnerLoop = 1; |
| 131960 | 131920 | pWInfo->revMask = m; |
| 131961 | 131921 | } |
| 131962 | 131922 | } |
| | @@ -132232,26 +132192,29 @@ |
| 132232 | 132192 | ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte |
| 132233 | 132193 | ** field (type Bitmask) it must be aligned on an 8-byte boundary on |
| 132234 | 132194 | ** some architectures. Hence the ROUND8() below. |
| 132235 | 132195 | */ |
| 132236 | 132196 | nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel)); |
| 132237 | | - pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop)); |
| 132197 | + pWInfo = sqlite3DbMallocRawNN(db, nByteWInfo + sizeof(WhereLoop)); |
| 132238 | 132198 | if( db->mallocFailed ){ |
| 132239 | 132199 | sqlite3DbFree(db, pWInfo); |
| 132240 | 132200 | pWInfo = 0; |
| 132241 | 132201 | goto whereBeginError; |
| 132242 | 132202 | } |
| 132243 | | - pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1; |
| 132244 | | - pWInfo->nLevel = nTabList; |
| 132245 | 132203 | pWInfo->pParse = pParse; |
| 132246 | 132204 | pWInfo->pTabList = pTabList; |
| 132247 | 132205 | pWInfo->pOrderBy = pOrderBy; |
| 132248 | 132206 | pWInfo->pDistinctSet = pDistinctSet; |
| 132207 | + pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1; |
| 132208 | + pWInfo->nLevel = nTabList; |
| 132249 | 132209 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v); |
| 132250 | 132210 | pWInfo->wctrlFlags = wctrlFlags; |
| 132251 | 132211 | pWInfo->iLimit = iAuxArg; |
| 132252 | 132212 | pWInfo->savedNQueryLoop = pParse->nQueryLoop; |
| 132213 | + memset(&pWInfo->nOBSat, 0, |
| 132214 | + offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat)); |
| 132215 | + memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel)); |
| 132253 | 132216 | assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ |
| 132254 | 132217 | pMaskSet = &pWInfo->sMaskSet; |
| 132255 | 132218 | sWLB.pWInfo = pWInfo; |
| 132256 | 132219 | sWLB.pWC = &pWInfo->sWC; |
| 132257 | 132220 | sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo); |
| | @@ -135704,12 +135667,13 @@ |
| 135704 | 135667 | yymsp[0].minor.yy190 = yylhsminor.yy190; |
| 135705 | 135668 | break; |
| 135706 | 135669 | case 159: /* expr ::= VARIABLE */ |
| 135707 | 135670 | { |
| 135708 | 135671 | if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){ |
| 135672 | + u32 n = yymsp[0].minor.yy0.n; |
| 135709 | 135673 | spanExpr(&yymsp[0].minor.yy190, pParse, TK_VARIABLE, yymsp[0].minor.yy0); |
| 135710 | | - sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy190.pExpr); |
| 135674 | + sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy190.pExpr, n); |
| 135711 | 135675 | }else{ |
| 135712 | 135676 | /* When doing a nested parse, one can include terms in an expression |
| 135713 | 135677 | ** that look like this: #1 #2 ... These terms refer to registers |
| 135714 | 135678 | ** in the virtual machine. #N is the N-th register. */ |
| 135715 | 135679 | Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/ |
| | @@ -136478,11 +136442,11 @@ |
| 136478 | 136442 | } |
| 136479 | 136443 | #endif |
| 136480 | 136444 | yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); |
| 136481 | 136445 | yymajor = YYNOCODE; |
| 136482 | 136446 | }else{ |
| 136483 | | - while( yypParser->yytos >= &yypParser->yystack |
| 136447 | + while( yypParser->yytos >= yypParser->yystack |
| 136484 | 136448 | && yymx != YYERRORSYMBOL |
| 136485 | 136449 | && (yyact = yy_find_reduce_action( |
| 136486 | 136450 | yypParser->yytos->stateno, |
| 136487 | 136451 | YYERRORSYMBOL)) >= YY_MIN_REDUCE |
| 136488 | 136452 | ){ |
| | @@ -164335,14 +164299,16 @@ |
| 164335 | 164299 | char *zSql; |
| 164336 | 164300 | sqlite3_stmt *p; |
| 164337 | 164301 | int rc; |
| 164338 | 164302 | i64 nRow = 0; |
| 164339 | 164303 | |
| 164340 | | - if( sqlite3_table_column_metadata(db,pRtree->zDb,"sqlite_stat1", |
| 164341 | | - 0,0,0,0,0,0)==SQLITE_ERROR ){ |
| 164304 | + rc = sqlite3_table_column_metadata( |
| 164305 | + db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0 |
| 164306 | + ); |
| 164307 | + if( rc!=SQLITE_OK ){ |
| 164342 | 164308 | pRtree->nRowEst = RTREE_DEFAULT_ROWEST; |
| 164343 | | - return SQLITE_OK; |
| 164309 | + return rc==SQLITE_ERROR ? SQLITE_OK : rc; |
| 164344 | 164310 | } |
| 164345 | 164311 | zSql = sqlite3_mprintf(zFmt, pRtree->zDb, pRtree->zName); |
| 164346 | 164312 | if( zSql==0 ){ |
| 164347 | 164313 | rc = SQLITE_NOMEM; |
| 164348 | 164314 | }else{ |
| | @@ -181169,11 +181135,11 @@ |
| 181169 | 181135 | } |
| 181170 | 181136 | #endif |
| 181171 | 181137 | fts5yy_destructor(fts5yypParser, (fts5YYCODETYPE)fts5yymajor, &fts5yyminorunion); |
| 181172 | 181138 | fts5yymajor = fts5YYNOCODE; |
| 181173 | 181139 | }else{ |
| 181174 | | - while( fts5yypParser->fts5yytos >= &fts5yypParser->fts5yystack |
| 181140 | + while( fts5yypParser->fts5yytos >= fts5yypParser->fts5yystack |
| 181175 | 181141 | && fts5yymx != fts5YYERRORSYMBOL |
| 181176 | 181142 | && (fts5yyact = fts5yy_find_reduce_action( |
| 181177 | 181143 | fts5yypParser->fts5yytos->stateno, |
| 181178 | 181144 | fts5YYERRORSYMBOL)) >= fts5YY_MIN_REDUCE |
| 181179 | 181145 | ){ |
| | @@ -181535,10 +181501,13 @@ |
| 181535 | 181501 | int nToken, /* Size of token in bytes */ |
| 181536 | 181502 | int iStartOff, /* Start offset of token */ |
| 181537 | 181503 | int iEndOff /* End offset of token */ |
| 181538 | 181504 | ){ |
| 181539 | 181505 | int rc = SQLITE_OK; |
| 181506 | + |
| 181507 | + UNUSED_PARAM2(pToken, nToken); |
| 181508 | + UNUSED_PARAM(iEndOff); |
| 181540 | 181509 | |
| 181541 | 181510 | if( (tflags & FTS5_TOKEN_COLOCATED)==0 ){ |
| 181542 | 181511 | Fts5SFinder *p = (Fts5SFinder*)pContext; |
| 181543 | 181512 | if( p->iPos>0 ){ |
| 181544 | 181513 | int i; |
| | @@ -181691,11 +181660,10 @@ |
| 181691 | 181660 | for(jj=0; jj<(sFinder.nFirst-1); jj++){ |
| 181692 | 181661 | if( sFinder.aFirst[jj+1]>io ) break; |
| 181693 | 181662 | } |
| 181694 | 181663 | |
| 181695 | 181664 | if( sFinder.aFirst[jj]<io ){ |
| 181696 | | - int nScore; |
| 181697 | 181665 | memset(aSeen, 0, nPhrase); |
| 181698 | 181666 | rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i, |
| 181699 | 181667 | sFinder.aFirst[jj], nToken, &nScore, 0 |
| 181700 | 181668 | ); |
| 181701 | 181669 | |
| | @@ -195626,11 +195594,11 @@ |
| 195626 | 195594 | int nArg, /* Number of args */ |
| 195627 | 195595 | sqlite3_value **apUnused /* Function arguments */ |
| 195628 | 195596 | ){ |
| 195629 | 195597 | assert( nArg==0 ); |
| 195630 | 195598 | UNUSED_PARAM2(nArg, apUnused); |
| 195631 | | - sqlite3_result_text(pCtx, "fts5: 2016-09-16 17:50:57 e3d9efa2770cd789ece3f4db4941b901c8b805ad", -1, SQLITE_TRANSIENT); |
| 195599 | + sqlite3_result_text(pCtx, "fts5: 2016-10-10 14:48:36 6624c4964b63e259d5ee006eaa7ec79ddadbd6a6", -1, SQLITE_TRANSIENT); |
| 195632 | 195600 | } |
| 195633 | 195601 | |
| 195634 | 195602 | static int fts5Init(sqlite3 *db){ |
| 195635 | 195603 | static const sqlite3_module fts5Mod = { |
| 195636 | 195604 | /* iVersion */ 2, |
| 195637 | 195605 | |