Fossil SCM
Another update to the built-in SQLite code. The last one is working fine, but SQLite is nearing release and so we want to give it a good shake-out.
Commit
5d699b625e7c3d5466127ac293cac03e8d5d2674
Parent
a74cfe0a14a203e…
2 files changed
+254
-269
+2
-2
+254
-269
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -650,11 +650,11 @@ | ||
| 650 | 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | 652 | */ |
| 653 | 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | -#define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906" | |
| 655 | +#define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81" | |
| 656 | 656 | |
| 657 | 657 | /* |
| 658 | 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 660 | ** |
| @@ -1675,11 +1675,11 @@ | ||
| 1675 | 1675 | ** changes to a [database connection]. The interface is similar to |
| 1676 | 1676 | ** [sqlite3_config()] except that the changes apply to a single |
| 1677 | 1677 | ** [database connection] (specified in the first argument). |
| 1678 | 1678 | ** |
| 1679 | 1679 | ** The second argument to sqlite3_db_config(D,V,...) is the |
| 1680 | -** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code | |
| 1680 | +** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code | |
| 1681 | 1681 | ** that indicates what aspect of the [database connection] is being configured. |
| 1682 | 1682 | ** Subsequent arguments vary depending on the configuration verb. |
| 1683 | 1683 | ** |
| 1684 | 1684 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1685 | 1685 | ** the call is considered successful. |
| @@ -7833,22 +7833,22 @@ | ||
| 7833 | 7833 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); |
| 7834 | 7834 | #ifndef NDEBUG |
| 7835 | 7835 | /* These routines are used inside assert() statements only. */ |
| 7836 | 7836 | SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); |
| 7837 | 7837 | SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); |
| 7838 | -SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree*); | |
| 7838 | +SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); | |
| 7839 | 7839 | #endif |
| 7840 | 7840 | #else |
| 7841 | 7841 | |
| 7842 | 7842 | # define sqlite3BtreeLeave(X) |
| 7843 | -# define sqlite3BtreeMutexCounter(X) 0 | |
| 7844 | 7843 | # define sqlite3BtreeEnterCursor(X) |
| 7845 | 7844 | # define sqlite3BtreeLeaveCursor(X) |
| 7846 | 7845 | # define sqlite3BtreeLeaveAll(X) |
| 7847 | 7846 | |
| 7848 | 7847 | # define sqlite3BtreeHoldsMutex(X) 1 |
| 7849 | 7848 | # define sqlite3BtreeHoldsAllMutexes(X) 1 |
| 7849 | +# define sqlite3SchemaMutexHeld(X,Y,Z) 1 | |
| 7850 | 7850 | #endif |
| 7851 | 7851 | |
| 7852 | 7852 | |
| 7853 | 7853 | #endif /* _BTREE_H_ */ |
| 7854 | 7854 | |
| @@ -7963,11 +7963,11 @@ | ||
| 7963 | 7963 | #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ |
| 7964 | 7964 | #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ |
| 7965 | 7965 | #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */ |
| 7966 | 7966 | #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */ |
| 7967 | 7967 | #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ |
| 7968 | -#define P4_TRANSIENT (-9) /* P4 is a pointer to a transient string */ | |
| 7968 | +#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ | |
| 7969 | 7969 | #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 7970 | 7970 | #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ |
| 7971 | 7971 | #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| 7972 | 7972 | #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ |
| 7973 | 7973 | #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ |
| @@ -8998,10 +8998,24 @@ | ||
| 8998 | 8998 | Schema *pSchema; /* Pointer to database schema (possibly shared) */ |
| 8999 | 8999 | }; |
| 9000 | 9000 | |
| 9001 | 9001 | /* |
| 9002 | 9002 | ** An instance of the following structure stores a database schema. |
| 9003 | +** | |
| 9004 | +** Most Schema objects are associated with a Btree. The exception is | |
| 9005 | +** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing. | |
| 9006 | +** In shared cache mode, a single Schema object can be shared by multiple | |
| 9007 | +** Btrees that refer to the same underlying BtShared object. | |
| 9008 | +** | |
| 9009 | +** Schema objects are automatically deallocated when the last Btree that | |
| 9010 | +** references them is destroyed. The TEMP Schema is manually freed by | |
| 9011 | +** sqlite3_close(). | |
| 9012 | +* | |
| 9013 | +** A thread must be holding a mutex on the corresponding Btree in order | |
| 9014 | +** to access Schema content. This implies that the thread must also be | |
| 9015 | +** holding a mutex on the sqlite3 connection pointer that owns the Btree. | |
| 9016 | +** For a TEMP Schema, on the connection mutex is required. | |
| 9003 | 9017 | */ |
| 9004 | 9018 | struct Schema { |
| 9005 | 9019 | int schema_cookie; /* Database schema version number for this file */ |
| 9006 | 9020 | int iGeneration; /* Generation counter. Incremented with each change */ |
| 9007 | 9021 | Hash tblHash; /* All tables indexed by name */ |
| @@ -9514,11 +9528,11 @@ | ||
| 9514 | 9528 | ** implementation. sqlite3_vtab* handles can not be shared between |
| 9515 | 9529 | ** database connections, even when the rest of the in-memory database |
| 9516 | 9530 | ** schema is shared, as the implementation often stores the database |
| 9517 | 9531 | ** connection handle passed to it via the xConnect() or xCreate() method |
| 9518 | 9532 | ** during initialization internally. This database connection handle may |
| 9519 | -** then used by the virtual table implementation to access real tables | |
| 9533 | +** then be used by the virtual table implementation to access real tables | |
| 9520 | 9534 | ** within the database. So that they appear as part of the callers |
| 9521 | 9535 | ** transaction, these accesses need to be made via the same database |
| 9522 | 9536 | ** connection as that used to execute SQL operations on the virtual table. |
| 9523 | 9537 | ** |
| 9524 | 9538 | ** All VTable objects that correspond to a single table in a shared |
| @@ -11272,11 +11286,11 @@ | ||
| 11272 | 11286 | SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions; |
| 11273 | 11287 | #ifndef SQLITE_OMIT_WSD |
| 11274 | 11288 | SQLITE_PRIVATE int sqlite3PendingByte; |
| 11275 | 11289 | #endif |
| 11276 | 11290 | #endif |
| 11277 | -SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int); | |
| 11291 | +SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int); | |
| 11278 | 11292 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 11279 | 11293 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 11280 | 11294 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 11281 | 11295 | SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *); |
| 11282 | 11296 | SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| @@ -11299,11 +11313,11 @@ | ||
| 11299 | 11313 | SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*); |
| 11300 | 11314 | SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*); |
| 11301 | 11315 | SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int); |
| 11302 | 11316 | SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); |
| 11303 | 11317 | SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int); |
| 11304 | -SQLITE_PRIVATE void sqlite3SchemaFree(void *); | |
| 11318 | +SQLITE_PRIVATE void sqlite3SchemaClear(void *); | |
| 11305 | 11319 | SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *); |
| 11306 | 11320 | SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *); |
| 11307 | 11321 | SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *); |
| 11308 | 11322 | SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, |
| 11309 | 11323 | void (*)(sqlite3_context*,int,sqlite3_value **), |
| @@ -12479,11 +12493,10 @@ | ||
| 12479 | 12493 | u8 usesStmtJournal; /* True if uses a statement journal */ |
| 12480 | 12494 | u8 readOnly; /* True for read-only statements */ |
| 12481 | 12495 | u8 isPrepareV2; /* True if prepared with prepare_v2() */ |
| 12482 | 12496 | int nChange; /* Number of db changes made since last reset */ |
| 12483 | 12497 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 12484 | - u32 iMutexCounter; /* Mutex counter upon sqlite3VdbeEnter() */ | |
| 12485 | 12498 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 12486 | 12499 | int aCounter[3]; /* Counters used by sqlite3_stmt_status() */ |
| 12487 | 12500 | #ifndef SQLITE_OMIT_TRACE |
| 12488 | 12501 | i64 startTime; /* Time when query started - used for profiling */ |
| 12489 | 12502 | #endif |
| @@ -12563,13 +12576,18 @@ | ||
| 12563 | 12576 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 12564 | 12577 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 12565 | 12578 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 12566 | 12579 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 12567 | 12580 | SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem); |
| 12568 | -SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*); | |
| 12569 | -SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); | |
| 12570 | -SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe*); | |
| 12581 | + | |
| 12582 | +#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 | |
| 12583 | +SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*); | |
| 12584 | +SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); | |
| 12585 | +#else | |
| 12586 | +# define sqlite3VdbeEnter(X) | |
| 12587 | +# define sqlite3VdbeLeave(X) | |
| 12588 | +#endif | |
| 12571 | 12589 | |
| 12572 | 12590 | #ifdef SQLITE_DEBUG |
| 12573 | 12591 | SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); |
| 12574 | 12592 | #endif |
| 12575 | 12593 | |
| @@ -12742,10 +12760,11 @@ | ||
| 12742 | 12760 | */ |
| 12743 | 12761 | case SQLITE_DBSTATUS_SCHEMA_USED: { |
| 12744 | 12762 | int i; /* Used to iterate through schemas */ |
| 12745 | 12763 | int nByte = 0; /* Used to accumulate return value */ |
| 12746 | 12764 | |
| 12765 | + sqlite3BtreeEnterAll(db); | |
| 12747 | 12766 | db->pnBytesFreed = &nByte; |
| 12748 | 12767 | for(i=0; i<db->nDb; i++){ |
| 12749 | 12768 | Schema *pSchema = db->aDb[i].pSchema; |
| 12750 | 12769 | if( ALWAYS(pSchema!=0) ){ |
| 12751 | 12770 | HashElem *p; |
| @@ -12768,10 +12787,11 @@ | ||
| 12768 | 12787 | sqlite3DeleteTable(db, (Table *)sqliteHashData(p)); |
| 12769 | 12788 | } |
| 12770 | 12789 | } |
| 12771 | 12790 | } |
| 12772 | 12791 | db->pnBytesFreed = 0; |
| 12792 | + sqlite3BtreeLeaveAll(db); | |
| 12773 | 12793 | |
| 12774 | 12794 | *pHighwater = 0; |
| 12775 | 12795 | *pCurrent = nByte; |
| 12776 | 12796 | break; |
| 12777 | 12797 | } |
| @@ -15879,11 +15899,11 @@ | ||
| 15879 | 15899 | ** Space for tracking which blocks are checked out and the size |
| 15880 | 15900 | ** of each block. One byte per block. |
| 15881 | 15901 | */ |
| 15882 | 15902 | u8 *aCtrl; |
| 15883 | 15903 | |
| 15884 | -} mem5 = { 0 }; | |
| 15904 | +} mem5; | |
| 15885 | 15905 | |
| 15886 | 15906 | /* |
| 15887 | 15907 | ** Access the static variable through a macro for SQLITE_OMIT_WSD |
| 15888 | 15908 | */ |
| 15889 | 15909 | #define mem5 GLOBAL(struct Mem5Global, mem5) |
| @@ -16194,11 +16214,11 @@ | ||
| 16194 | 16214 | ** memsys5Log(8) -> 3 |
| 16195 | 16215 | ** memsys5Log(9) -> 4 |
| 16196 | 16216 | */ |
| 16197 | 16217 | static int memsys5Log(int iValue){ |
| 16198 | 16218 | int iLog; |
| 16199 | - for(iLog=0; (iLog<((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++); | |
| 16219 | + for(iLog=0; (iLog<(int)((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++); | |
| 16200 | 16220 | return iLog; |
| 16201 | 16221 | } |
| 16202 | 16222 | |
| 16203 | 16223 | /* |
| 16204 | 16224 | ** Initialize the memory allocator. |
| @@ -18064,11 +18084,11 @@ | ||
| 18064 | 18084 | pSlot = (ScratchFreeslot*)p; |
| 18065 | 18085 | sqlite3_mutex_enter(mem0.mutex); |
| 18066 | 18086 | pSlot->pNext = mem0.pScratchFree; |
| 18067 | 18087 | mem0.pScratchFree = pSlot; |
| 18068 | 18088 | mem0.nScratchFree++; |
| 18069 | - assert( mem0.nScratchFree<=sqlite3GlobalConfig.nScratch ); | |
| 18089 | + assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch ); | |
| 18070 | 18090 | sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1); |
| 18071 | 18091 | sqlite3_mutex_leave(mem0.mutex); |
| 18072 | 18092 | }else{ |
| 18073 | 18093 | /* Release memory back to the heap */ |
| 18074 | 18094 | assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) ); |
| @@ -38547,10 +38567,23 @@ | ||
| 38547 | 38567 | /* Verify that the page list is in accending order */ |
| 38548 | 38568 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 38549 | 38569 | assert( p->pgno < p->pDirty->pgno ); |
| 38550 | 38570 | } |
| 38551 | 38571 | #endif |
| 38572 | + | |
| 38573 | + if( isCommit ){ | |
| 38574 | + /* If a WAL transaction is being committed, there is no point in writing | |
| 38575 | + ** any pages with page numbers greater than nTruncate into the WAL file. | |
| 38576 | + ** They will never be read by any client. So remove them from the pDirty | |
| 38577 | + ** list here. */ | |
| 38578 | + PgHdr *p; | |
| 38579 | + PgHdr **ppNext = &pList; | |
| 38580 | + for(p=pList; (*ppNext = p); p=p->pDirty){ | |
| 38581 | + if( p->pgno<=nTruncate ) ppNext = &p->pDirty; | |
| 38582 | + } | |
| 38583 | + assert( pList ); | |
| 38584 | + } | |
| 38552 | 38585 | |
| 38553 | 38586 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 38554 | 38587 | rc = sqlite3WalFrames(pPager->pWal, |
| 38555 | 38588 | pPager->pageSize, pList, nTruncate, isCommit, syncFlags |
| 38556 | 38589 | ); |
| @@ -38560,10 +38593,11 @@ | ||
| 38560 | 38593 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 38561 | 38594 | } |
| 38562 | 38595 | } |
| 38563 | 38596 | |
| 38564 | 38597 | #ifdef SQLITE_CHECK_PAGES |
| 38598 | + pList = sqlite3PcacheDirtyList(pPager->pPCache); | |
| 38565 | 38599 | for(p=pList; p; p=p->pDirty){ |
| 38566 | 38600 | pager_set_pagehash(p); |
| 38567 | 38601 | } |
| 38568 | 38602 | #endif |
| 38569 | 38603 | |
| @@ -45510,11 +45544,11 @@ | ||
| 45510 | 45544 | |
| 45511 | 45545 | |
| 45512 | 45546 | /* The following value is the maximum cell size assuming a maximum page |
| 45513 | 45547 | ** size give above. |
| 45514 | 45548 | */ |
| 45515 | -#define MX_CELL_SIZE(pBt) (pBt->pageSize-8) | |
| 45549 | +#define MX_CELL_SIZE(pBt) ((int)(pBt->pageSize-8)) | |
| 45516 | 45550 | |
| 45517 | 45551 | /* The maximum number of cells on a single page of the database. This |
| 45518 | 45552 | ** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself |
| 45519 | 45553 | ** plus 2 bytes for the index to the cell in the page header). Such |
| 45520 | 45554 | ** small cells will be rare, but they are possible. |
| @@ -45727,11 +45761,10 @@ | ||
| 45727 | 45761 | BtShared *pNext; /* Next on a list of sharable BtShared structs */ |
| 45728 | 45762 | BtLock *pLock; /* List of locks held on this shared-btree struct */ |
| 45729 | 45763 | Btree *pWriter; /* Btree with currently open write transaction */ |
| 45730 | 45764 | u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */ |
| 45731 | 45765 | u8 isPending; /* If waiting for read-locks to clear */ |
| 45732 | - u16 iMutexCounter; /* The number of mutex_leave(mutex) calls */ | |
| 45733 | 45766 | #endif |
| 45734 | 45767 | u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */ |
| 45735 | 45768 | }; |
| 45736 | 45769 | |
| 45737 | 45770 | /* |
| @@ -45966,32 +45999,14 @@ | ||
| 45966 | 45999 | assert( p->locked==1 ); |
| 45967 | 46000 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 45968 | 46001 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 45969 | 46002 | assert( p->db==pBt->db ); |
| 45970 | 46003 | |
| 45971 | - pBt->iMutexCounter++; | |
| 45972 | 46004 | sqlite3_mutex_leave(pBt->mutex); |
| 45973 | 46005 | p->locked = 0; |
| 45974 | 46006 | } |
| 45975 | 46007 | |
| 45976 | -#ifdef SQLITE_DEBUG | |
| 45977 | -/* | |
| 45978 | -** Return the number of times that the mutex has been exited for | |
| 45979 | -** the given btree. | |
| 45980 | -** | |
| 45981 | -** This is a small circular counter that wraps around to zero on | |
| 45982 | -** overflow. It is used only for sanity checking - to verify that | |
| 45983 | -** mutexes are held continously by asserting that the value of | |
| 45984 | -** this counter at the beginning of a region is the same as at | |
| 45985 | -** the end. | |
| 45986 | -*/ | |
| 45987 | -SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree *p){ | |
| 45988 | - assert( p->locked==1 || p->sharable==0 ); | |
| 45989 | - return p->pBt->iMutexCounter; | |
| 45990 | -} | |
| 45991 | -#endif | |
| 45992 | - | |
| 45993 | 46008 | /* |
| 45994 | 46009 | ** Enter a mutex on the given BTree object. |
| 45995 | 46010 | ** |
| 45996 | 46011 | ** If the object is not sharable, then no mutex is ever required |
| 45997 | 46012 | ** and this routine is a no-op. The underlying mutex is non-recursive. |
| @@ -46032,28 +46047,10 @@ | ||
| 46032 | 46047 | |
| 46033 | 46048 | if( !p->sharable ) return; |
| 46034 | 46049 | p->wantToLock++; |
| 46035 | 46050 | if( p->locked ) return; |
| 46036 | 46051 | |
| 46037 | - /* Increment the mutex counter on all locked btrees in the same | |
| 46038 | - ** database connection. This simulates the unlocking that would | |
| 46039 | - ** occur on a worst-case mutex dead-lock avoidance scenario. | |
| 46040 | - */ | |
| 46041 | -#ifdef SQLITE_DEBUG | |
| 46042 | - { | |
| 46043 | - int ii; | |
| 46044 | - sqlite3 *db = p->db; | |
| 46045 | - Btree *pOther; | |
| 46046 | - for(ii=0; ii<db->nDb; ii++){ | |
| 46047 | - if( ii==1 ) continue; | |
| 46048 | - pOther = db->aDb[ii].pBt; | |
| 46049 | - if( pOther==0 || pOther->sharable==0 || pOther->locked==0 ) continue; | |
| 46050 | - pOther->pBt->iMutexCounter++; | |
| 46051 | - } | |
| 46052 | - } | |
| 46053 | -#endif | |
| 46054 | - | |
| 46055 | 46052 | /* In most cases, we should be able to acquire the lock we |
| 46056 | 46053 | ** want without having to go throught the ascending lock |
| 46057 | 46054 | ** procedure that follows. Just be sure not to block. |
| 46058 | 46055 | */ |
| 46059 | 46056 | if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){ |
| @@ -46143,49 +46140,24 @@ | ||
| 46143 | 46140 | ** two or more btrees in common both try to lock all their btrees |
| 46144 | 46141 | ** at the same instant. |
| 46145 | 46142 | */ |
| 46146 | 46143 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 46147 | 46144 | int i; |
| 46148 | - Btree *p, *pLater; | |
| 46145 | + Btree *p; | |
| 46149 | 46146 | assert( sqlite3_mutex_held(db->mutex) ); |
| 46150 | 46147 | for(i=0; i<db->nDb; i++){ |
| 46151 | 46148 | p = db->aDb[i].pBt; |
| 46152 | - assert( !p || (p->locked==0 && p->sharable) || p->pBt->db==p->db ); | |
| 46153 | - if( p && p->sharable ){ | |
| 46154 | - p->wantToLock++; | |
| 46155 | - if( !p->locked ){ | |
| 46156 | - assert( p->wantToLock==1 ); | |
| 46157 | - while( p->pPrev ) p = p->pPrev; | |
| 46158 | - /* Reason for ALWAYS: There must be at least one unlocked Btree in | |
| 46159 | - ** the chain. Otherwise the !p->locked test above would have failed */ | |
| 46160 | - while( p->locked && ALWAYS(p->pNext) ) p = p->pNext; | |
| 46161 | - for(pLater = p->pNext; pLater; pLater=pLater->pNext){ | |
| 46162 | - if( pLater->locked ){ | |
| 46163 | - unlockBtreeMutex(pLater); | |
| 46164 | - } | |
| 46165 | - } | |
| 46166 | - while( p ){ | |
| 46167 | - lockBtreeMutex(p); | |
| 46168 | - p = p->pNext; | |
| 46169 | - } | |
| 46170 | - } | |
| 46171 | - } | |
| 46149 | + if( p ) sqlite3BtreeEnter(p); | |
| 46172 | 46150 | } |
| 46173 | 46151 | } |
| 46174 | 46152 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){ |
| 46175 | 46153 | int i; |
| 46176 | 46154 | Btree *p; |
| 46177 | 46155 | assert( sqlite3_mutex_held(db->mutex) ); |
| 46178 | 46156 | for(i=0; i<db->nDb; i++){ |
| 46179 | 46157 | p = db->aDb[i].pBt; |
| 46180 | - if( p && p->sharable ){ | |
| 46181 | - assert( p->wantToLock>0 ); | |
| 46182 | - p->wantToLock--; | |
| 46183 | - if( p->wantToLock==0 ){ | |
| 46184 | - unlockBtreeMutex(p); | |
| 46185 | - } | |
| 46186 | - } | |
| 46158 | + if( p ) sqlite3BtreeLeave(p); | |
| 46187 | 46159 | } |
| 46188 | 46160 | } |
| 46189 | 46161 | |
| 46190 | 46162 | #ifndef NDEBUG |
| 46191 | 46163 | /* |
| @@ -46209,10 +46181,35 @@ | ||
| 46209 | 46181 | } |
| 46210 | 46182 | return 1; |
| 46211 | 46183 | } |
| 46212 | 46184 | #endif /* NDEBUG */ |
| 46213 | 46185 | |
| 46186 | +#ifndef NDEBUG | |
| 46187 | +/* | |
| 46188 | +** Return true if the correct mutexes are held for accessing the | |
| 46189 | +** db->aDb[iDb].pSchema structure. The mutexes required for schema | |
| 46190 | +** access are: | |
| 46191 | +** | |
| 46192 | +** (1) The mutex on db | |
| 46193 | +** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt. | |
| 46194 | +** | |
| 46195 | +** If pSchema is not NULL, then iDb is computed from pSchema and | |
| 46196 | +** db using sqlite3SchemaToIndex(). | |
| 46197 | +*/ | |
| 46198 | +SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){ | |
| 46199 | + Btree *p; | |
| 46200 | + assert( db!=0 ); | |
| 46201 | + if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema); | |
| 46202 | + assert( iDb>=0 && iDb<db->nDb ); | |
| 46203 | + if( !sqlite3_mutex_held(db->mutex) ) return 0; | |
| 46204 | + if( iDb==1 ) return 1; | |
| 46205 | + p = db->aDb[iDb].pBt; | |
| 46206 | + assert( p!=0 ); | |
| 46207 | + return p->sharable==0 || p->locked==1; | |
| 46208 | +} | |
| 46209 | +#endif /* NDEBUG */ | |
| 46210 | + | |
| 46214 | 46211 | #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */ |
| 46215 | 46212 | /* |
| 46216 | 46213 | ** The following are special cases for mutex enter routines for use |
| 46217 | 46214 | ** in single threaded applications that use shared cache. Except for |
| 46218 | 46215 | ** these two routines, all mutex operations are no-ops in that case and |
| @@ -47466,11 +47463,11 @@ | ||
| 47466 | 47463 | ** is no way that the allocation can extend off the end of the page. |
| 47467 | 47464 | ** The assert() below verifies the previous sentence. |
| 47468 | 47465 | */ |
| 47469 | 47466 | top -= nByte; |
| 47470 | 47467 | put2byte(&data[hdr+5], top); |
| 47471 | - assert( top+nByte <= pPage->pBt->usableSize ); | |
| 47468 | + assert( top+nByte <= (int)pPage->pBt->usableSize ); | |
| 47472 | 47469 | *pIdx = top; |
| 47473 | 47470 | return SQLITE_OK; |
| 47474 | 47471 | } |
| 47475 | 47472 | |
| 47476 | 47473 | /* |
| @@ -47487,11 +47484,11 @@ | ||
| 47487 | 47484 | unsigned char *data = pPage->aData; |
| 47488 | 47485 | |
| 47489 | 47486 | assert( pPage->pBt!=0 ); |
| 47490 | 47487 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 47491 | 47488 | assert( start>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 47492 | - assert( (start + size)<=pPage->pBt->usableSize ); | |
| 47489 | + assert( (start + size) <= (int)pPage->pBt->usableSize ); | |
| 47493 | 47490 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 47494 | 47491 | assert( size>=0 ); /* Minimum cell size is 4 */ |
| 47495 | 47492 | |
| 47496 | 47493 | if( pPage->pBt->secureDelete ){ |
| 47497 | 47494 | /* Overwrite deleted information with zeros when the secure_delete |
| @@ -47530,11 +47527,11 @@ | ||
| 47530 | 47527 | /* Coalesce adjacent free blocks */ |
| 47531 | 47528 | addr = hdr + 1; |
| 47532 | 47529 | while( (pbegin = get2byte(&data[addr]))>0 ){ |
| 47533 | 47530 | int pnext, psize, x; |
| 47534 | 47531 | assert( pbegin>addr ); |
| 47535 | - assert( pbegin<=pPage->pBt->usableSize-4 ); | |
| 47532 | + assert( pbegin <= (int)pPage->pBt->usableSize-4 ); | |
| 47536 | 47533 | pnext = get2byte(&data[pbegin]); |
| 47537 | 47534 | psize = get2byte(&data[pbegin+2]); |
| 47538 | 47535 | if( pbegin + psize + 3 >= pnext && pnext>0 ){ |
| 47539 | 47536 | int frag = pnext - (pbegin+psize); |
| 47540 | 47537 | if( (frag<0) || (frag>(int)data[hdr+7]) ){ |
| @@ -51737,11 +51734,11 @@ | ||
| 51737 | 51734 | rc = allocateSpace(pPage, sz, &idx); |
| 51738 | 51735 | if( rc ){ *pRC = rc; return; } |
| 51739 | 51736 | /* The allocateSpace() routine guarantees the following two properties |
| 51740 | 51737 | ** if it returns success */ |
| 51741 | 51738 | assert( idx >= end+2 ); |
| 51742 | - assert( idx+sz <= pPage->pBt->usableSize ); | |
| 51739 | + assert( idx+sz <= (int)pPage->pBt->usableSize ); | |
| 51743 | 51740 | pPage->nCell++; |
| 51744 | 51741 | pPage->nFree -= (u16)(2 + sz); |
| 51745 | 51742 | memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip); |
| 51746 | 51743 | if( iChild ){ |
| 51747 | 51744 | put4byte(&data[idx], iChild); |
| @@ -51780,11 +51777,12 @@ | ||
| 51780 | 51777 | const int hdr = pPage->hdrOffset; /* Offset of header on pPage */ |
| 51781 | 51778 | const int nUsable = pPage->pBt->usableSize; /* Usable size of page */ |
| 51782 | 51779 | |
| 51783 | 51780 | assert( pPage->nOverflow==0 ); |
| 51784 | 51781 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 51785 | - assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921); | |
| 51782 | + assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt) | |
| 51783 | + && (int)MX_CELL(pPage->pBt)<=10921); | |
| 51786 | 51784 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 51787 | 51785 | |
| 51788 | 51786 | /* Check that the page has just been zeroed by zeroPage() */ |
| 51789 | 51787 | assert( pPage->nCell==0 ); |
| 51790 | 51788 | assert( get2byteNotZero(&data[hdr+5])==nUsable ); |
| @@ -51994,11 +51992,11 @@ | ||
| 51994 | 51992 | int iData; |
| 51995 | 51993 | |
| 51996 | 51994 | |
| 51997 | 51995 | assert( pFrom->isInit ); |
| 51998 | 51996 | assert( pFrom->nFree>=iToHdr ); |
| 51999 | - assert( get2byte(&aFrom[iFromHdr+5])<=pBt->usableSize ); | |
| 51997 | + assert( get2byte(&aFrom[iFromHdr+5]) <= (int)pBt->usableSize ); | |
| 52000 | 51998 | |
| 52001 | 51999 | /* Copy the b-tree node content from page pFrom to page pTo. */ |
| 52002 | 52000 | iData = get2byte(&aFrom[iFromHdr+5]); |
| 52003 | 52001 | memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData); |
| 52004 | 52002 | memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell); |
| @@ -52261,11 +52259,11 @@ | ||
| 52261 | 52259 | assert( nCell<nMaxCells ); |
| 52262 | 52260 | szCell[nCell] = sz; |
| 52263 | 52261 | pTemp = &aSpace1[iSpace1]; |
| 52264 | 52262 | iSpace1 += sz; |
| 52265 | 52263 | assert( sz<=pBt->maxLocal+23 ); |
| 52266 | - assert( iSpace1<=pBt->pageSize ); | |
| 52264 | + assert( iSpace1 <= (int)pBt->pageSize ); | |
| 52267 | 52265 | memcpy(pTemp, apDiv[i], sz); |
| 52268 | 52266 | apCell[nCell] = pTemp+leafCorrection; |
| 52269 | 52267 | assert( leafCorrection==0 || leafCorrection==4 ); |
| 52270 | 52268 | szCell[nCell] = szCell[nCell] - leafCorrection; |
| 52271 | 52269 | if( !pOld->leaf ){ |
| @@ -52505,11 +52503,11 @@ | ||
| 52505 | 52503 | sz = cellSizePtr(pParent, pCell); |
| 52506 | 52504 | } |
| 52507 | 52505 | } |
| 52508 | 52506 | iOvflSpace += sz; |
| 52509 | 52507 | assert( sz<=pBt->maxLocal+23 ); |
| 52510 | - assert( iOvflSpace<=pBt->pageSize ); | |
| 52508 | + assert( iOvflSpace <= (int)pBt->pageSize ); | |
| 52511 | 52509 | insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc); |
| 52512 | 52510 | if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 52513 | 52511 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 52514 | 52512 | |
| 52515 | 52513 | j++; |
| @@ -52950,11 +52948,11 @@ | ||
| 52950 | 52948 | newCell = pBt->pTmpSpace; |
| 52951 | 52949 | if( newCell==0 ) return SQLITE_NOMEM; |
| 52952 | 52950 | rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew); |
| 52953 | 52951 | if( rc ) goto end_insert; |
| 52954 | 52952 | assert( szNew==cellSizePtr(pPage, newCell) ); |
| 52955 | - assert( szNew<=MX_CELL_SIZE(pBt) ); | |
| 52953 | + assert( szNew <= MX_CELL_SIZE(pBt) ); | |
| 52956 | 52954 | idx = pCur->aiIdx[pCur->iPage]; |
| 52957 | 52955 | if( loc==0 ){ |
| 52958 | 52956 | u16 szOld; |
| 52959 | 52957 | assert( idx<pPage->nCell ); |
| 52960 | 52958 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| @@ -53090,11 +53088,11 @@ | ||
| 53090 | 53088 | Pgno n = pCur->apPage[iCellDepth+1]->pgno; |
| 53091 | 53089 | unsigned char *pTmp; |
| 53092 | 53090 | |
| 53093 | 53091 | pCell = findCell(pLeaf, pLeaf->nCell-1); |
| 53094 | 53092 | nCell = cellSizePtr(pLeaf, pCell); |
| 53095 | - assert( MX_CELL_SIZE(pBt)>=nCell ); | |
| 53093 | + assert( MX_CELL_SIZE(pBt) >= nCell ); | |
| 53096 | 53094 | |
| 53097 | 53095 | allocateTempSpace(pBt); |
| 53098 | 53096 | pTmp = pBt->pTmpSpace; |
| 53099 | 53097 | |
| 53100 | 53098 | rc = sqlite3PagerWrite(pLeaf->pDbPage); |
| @@ -54784,11 +54782,11 @@ | ||
| 54784 | 54782 | && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK |
| 54785 | 54783 | ){ |
| 54786 | 54784 | int nDestTruncate; |
| 54787 | 54785 | |
| 54788 | 54786 | if( p->pDestDb ){ |
| 54789 | - sqlite3ResetInternalSchema(p->pDestDb, 0); | |
| 54787 | + sqlite3ResetInternalSchema(p->pDestDb, -1); | |
| 54790 | 54788 | } |
| 54791 | 54789 | |
| 54792 | 54790 | /* Set nDestTruncate to the final number of pages in the destination |
| 54793 | 54791 | ** database. The complication here is that the destination page |
| 54794 | 54792 | ** size may be different to the source page size. |
| @@ -57181,40 +57179,16 @@ | ||
| 57181 | 57179 | ** The prepared statements need to know in advance the complete set of |
| 57182 | 57180 | ** attached databases that they will be using. A mask of these databases |
| 57183 | 57181 | ** is maintained in p->btreeMask and is used for locking and other purposes. |
| 57184 | 57182 | */ |
| 57185 | 57183 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){ |
| 57186 | - assert( i>=0 && i<p->db->nDb && i<sizeof(yDbMask)*8 ); | |
| 57184 | + assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 ); | |
| 57187 | 57185 | assert( i<(int)sizeof(p->btreeMask)*8 ); |
| 57188 | 57186 | p->btreeMask |= ((yDbMask)1)<<i; |
| 57189 | 57187 | } |
| 57190 | 57188 | |
| 57191 | -/* | |
| 57192 | -** Compute the sum of all mutex counters for all btrees in the | |
| 57193 | -** given prepared statement. | |
| 57194 | -*/ | |
| 57195 | -#ifndef SQLITE_OMIT_SHARED_CACHE | |
| 57196 | -static u32 mutexCounterSum(Vdbe *p){ | |
| 57197 | - u32 cntSum = 0; | |
| 57198 | -#ifdef SQLITE_DEBUG | |
| 57199 | - int i; | |
| 57200 | - yDbMask mask; | |
| 57201 | - sqlite3 *db = p->db; | |
| 57202 | - Db *aDb = db->aDb; | |
| 57203 | - int nDb = db->nDb; | |
| 57204 | - for(i=0, mask=1; i<nDb; i++, mask += mask){ | |
| 57205 | - if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ | |
| 57206 | - cntSum += sqlite3BtreeMutexCounter(aDb[i].pBt); | |
| 57207 | - } | |
| 57208 | - } | |
| 57209 | -#else | |
| 57210 | - UNUSED_PARAMETER(p); | |
| 57211 | -#endif | |
| 57212 | - return cntSum; | |
| 57213 | -} | |
| 57214 | -#endif | |
| 57215 | - | |
| 57189 | +#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 | |
| 57216 | 57190 | /* |
| 57217 | 57191 | ** If SQLite is compiled to support shared-cache mode and to be threadsafe, |
| 57218 | 57192 | ** this routine obtains the mutex associated with each BtShared structure |
| 57219 | 57193 | ** that may be accessed by the VM passed as an argument. In doing so it also |
| 57220 | 57194 | ** sets the BtShared.db member of each of the BtShared structures, ensuring |
| @@ -57233,11 +57207,10 @@ | ||
| 57233 | 57207 | ** corresponding to btrees that use shared cache. Then the runtime of |
| 57234 | 57208 | ** this routine is N*N. But as N is rarely more than 1, this should not |
| 57235 | 57209 | ** be a problem. |
| 57236 | 57210 | */ |
| 57237 | 57211 | SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){ |
| 57238 | -#ifndef SQLITE_OMIT_SHARED_CACHE | |
| 57239 | 57212 | int i; |
| 57240 | 57213 | yDbMask mask; |
| 57241 | 57214 | sqlite3 *db = p->db; |
| 57242 | 57215 | Db *aDb = db->aDb; |
| 57243 | 57216 | int nDb = db->nDb; |
| @@ -57244,67 +57217,31 @@ | ||
| 57244 | 57217 | for(i=0, mask=1; i<nDb; i++, mask += mask){ |
| 57245 | 57218 | if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ |
| 57246 | 57219 | sqlite3BtreeEnter(aDb[i].pBt); |
| 57247 | 57220 | } |
| 57248 | 57221 | } |
| 57249 | - p->iMutexCounter = mutexCounterSum(p); | |
| 57250 | -#else | |
| 57251 | - UNUSED_PARAMETER(p); | |
| 57222 | +} | |
| 57252 | 57223 | #endif |
| 57253 | -} | |
| 57254 | 57224 | |
| 57225 | +#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 | |
| 57255 | 57226 | /* |
| 57256 | 57227 | ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter(). |
| 57257 | 57228 | */ |
| 57258 | 57229 | SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){ |
| 57259 | -#ifndef SQLITE_OMIT_SHARED_CACHE | |
| 57260 | 57230 | int i; |
| 57261 | 57231 | yDbMask mask; |
| 57262 | 57232 | sqlite3 *db = p->db; |
| 57263 | 57233 | Db *aDb = db->aDb; |
| 57264 | 57234 | int nDb = db->nDb; |
| 57265 | 57235 | |
| 57266 | - /* Assert that the all mutexes have been held continously since | |
| 57267 | - ** the most recent sqlite3VdbeEnter() or sqlite3VdbeMutexResync(). | |
| 57268 | - */ | |
| 57269 | - assert( mutexCounterSum(p) == p->iMutexCounter ); | |
| 57270 | - | |
| 57271 | 57236 | for(i=0, mask=1; i<nDb; i++, mask += mask){ |
| 57272 | 57237 | if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ |
| 57273 | 57238 | sqlite3BtreeLeave(aDb[i].pBt); |
| 57274 | 57239 | } |
| 57275 | 57240 | } |
| 57276 | -#else | |
| 57277 | - UNUSED_PARAMETER(p); | |
| 57278 | -#endif | |
| 57279 | -} | |
| 57280 | - | |
| 57281 | -/* | |
| 57282 | -** Recompute the sum of the mutex counters on all btrees used by the | |
| 57283 | -** prepared statement p. | |
| 57284 | -** | |
| 57285 | -** Call this routine while holding a sqlite3VdbeEnter() after doing something | |
| 57286 | -** that might cause one or more of the individual mutexes held by the | |
| 57287 | -** prepared statement to be released. Calling sqlite3BtreeEnter() on | |
| 57288 | -** any BtShared mutex which is not used by the prepared statement is one | |
| 57289 | -** way to cause one or more of the mutexes in the prepared statement | |
| 57290 | -** to be temporarily released. The anti-deadlocking logic in | |
| 57291 | -** sqlite3BtreeEnter() can cause mutexes to be released temporarily then | |
| 57292 | -** reacquired. | |
| 57293 | -** | |
| 57294 | -** Calling this routine is an acknowledgement that some of the individual | |
| 57295 | -** mutexes in the prepared statement might have been released and reacquired. | |
| 57296 | -** So checks to verify that mutex-protected content did not change | |
| 57297 | -** unexpectedly should accompany any call to this routine. | |
| 57298 | -*/ | |
| 57299 | -SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe *p){ | |
| 57300 | -#if !defined(SQLITE_OMIT_SHARED_CACHE) && defined(SQLITE_DEBUG) | |
| 57301 | - p->iMutexCounter = mutexCounterSum(p); | |
| 57302 | -#else | |
| 57303 | - UNUSED_PARAMETER(p); | |
| 57304 | -#endif | |
| 57305 | -} | |
| 57241 | +} | |
| 57242 | +#endif | |
| 57306 | 57243 | |
| 57307 | 57244 | #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) |
| 57308 | 57245 | /* |
| 57309 | 57246 | ** Print a single opcode. This routine is used for debugging only. |
| 57310 | 57247 | */ |
| @@ -58504,16 +58441,15 @@ | ||
| 58504 | 58441 | p->nChange = 0; |
| 58505 | 58442 | } |
| 58506 | 58443 | |
| 58507 | 58444 | /* Rollback or commit any schema changes that occurred. */ |
| 58508 | 58445 | if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){ |
| 58509 | - sqlite3ResetInternalSchema(db, 0); | |
| 58446 | + sqlite3ResetInternalSchema(db, -1); | |
| 58510 | 58447 | db->flags = (db->flags | SQLITE_InternChanges); |
| 58511 | 58448 | } |
| 58512 | 58449 | |
| 58513 | 58450 | /* Release the locks */ |
| 58514 | - sqlite3VdbeMutexResync(p); | |
| 58515 | 58451 | sqlite3VdbeLeave(p); |
| 58516 | 58452 | } |
| 58517 | 58453 | |
| 58518 | 58454 | /* We have successfully halted and closed the VM. Record this fact. */ |
| 58519 | 58455 | if( p->pc>=0 ){ |
| @@ -60190,11 +60126,15 @@ | ||
| 60190 | 60126 | ** __attribute__((aligned(8))) macro. */ |
| 60191 | 60127 | static const Mem nullMem |
| 60192 | 60128 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 60193 | 60129 | __attribute__((aligned(8))) |
| 60194 | 60130 | #endif |
| 60195 | - = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 }; | |
| 60131 | + = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, | |
| 60132 | +#ifdef SQLITE_DEBUG | |
| 60133 | + 0, 0, /* pScopyFrom, pFiller */ | |
| 60134 | +#endif | |
| 60135 | + 0, 0 }; | |
| 60196 | 60136 | |
| 60197 | 60137 | if( pVm && ALWAYS(pVm->db) ){ |
| 60198 | 60138 | sqlite3_mutex_enter(pVm->db->mutex); |
| 60199 | 60139 | sqlite3Error(pVm->db, SQLITE_RANGE, 0); |
| 60200 | 60140 | } |
| @@ -61604,11 +61544,11 @@ | ||
| 61604 | 61544 | int pc=0; /* The program counter */ |
| 61605 | 61545 | Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 61606 | 61546 | Op *pOp; /* Current operation */ |
| 61607 | 61547 | int rc = SQLITE_OK; /* Value to return */ |
| 61608 | 61548 | sqlite3 *db = p->db; /* The database */ |
| 61609 | - u8 resetSchemaOnFault = 0; /* Reset schema after an error if true */ | |
| 61549 | + u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ | |
| 61610 | 61550 | u8 encoding = ENC(db); /* The database encoding */ |
| 61611 | 61551 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 61612 | 61552 | int checkProgress; /* True if progress callbacks are enabled */ |
| 61613 | 61553 | int nProgressOps = 0; /* Opcodes executed since progress callback. */ |
| 61614 | 61554 | #endif |
| @@ -62868,11 +62808,10 @@ | ||
| 62868 | 62808 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 62869 | 62809 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 62870 | 62810 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 62871 | 62811 | } |
| 62872 | 62812 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 62873 | - sqlite3VdbeMutexResync(p); | |
| 62874 | 62813 | if( db->mallocFailed ){ |
| 62875 | 62814 | /* Even though a malloc() has failed, the implementation of the |
| 62876 | 62815 | ** user function may have called an sqlite3_result_XXX() function |
| 62877 | 62816 | ** to return a value. The following call releases any resources |
| 62878 | 62817 | ** associated with such a value. |
| @@ -62879,21 +62818,10 @@ | ||
| 62879 | 62818 | */ |
| 62880 | 62819 | sqlite3VdbeMemRelease(&u.ag.ctx.s); |
| 62881 | 62820 | goto no_mem; |
| 62882 | 62821 | } |
| 62883 | 62822 | |
| 62884 | - /* The app-defined function has done something that as caused this | |
| 62885 | - ** statement to expire. (Perhaps the function called sqlite3_exec() | |
| 62886 | - ** with a CREATE TABLE statement.) | |
| 62887 | - */ | |
| 62888 | -#if 0 | |
| 62889 | - if( p->expired ){ | |
| 62890 | - rc = SQLITE_ABORT; | |
| 62891 | - break; | |
| 62892 | - } | |
| 62893 | -#endif | |
| 62894 | - | |
| 62895 | 62823 | /* If any auxiliary data functions have been called by this user function, |
| 62896 | 62824 | ** immediately call the destructor for any non-static values. |
| 62897 | 62825 | */ |
| 62898 | 62826 | if( u.ag.ctx.pVdbeFunc ){ |
| 62899 | 62827 | sqlite3VdbeDeleteAuxData(u.ag.ctx.pVdbeFunc, pOp->p1); |
| @@ -62911,10 +62839,19 @@ | ||
| 62911 | 62839 | sqlite3VdbeChangeEncoding(&u.ag.ctx.s, encoding); |
| 62912 | 62840 | sqlite3VdbeMemMove(pOut, &u.ag.ctx.s); |
| 62913 | 62841 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 62914 | 62842 | goto too_big; |
| 62915 | 62843 | } |
| 62844 | + | |
| 62845 | +#if 0 | |
| 62846 | + /* The app-defined function has done something that as caused this | |
| 62847 | + ** statement to expire. (Perhaps the function called sqlite3_exec() | |
| 62848 | + ** with a CREATE TABLE statement.) | |
| 62849 | + */ | |
| 62850 | + if( p->expired ) rc = SQLITE_ABORT; | |
| 62851 | +#endif | |
| 62852 | + | |
| 62916 | 62853 | REGISTER_TRACE(pOp->p3, pOut); |
| 62917 | 62854 | UPDATE_MAX_BLOBSIZE(pOut); |
| 62918 | 62855 | break; |
| 62919 | 62856 | } |
| 62920 | 62857 | |
| @@ -64155,12 +64092,11 @@ | ||
| 64155 | 64092 | goto abort_due_to_error; |
| 64156 | 64093 | } |
| 64157 | 64094 | } |
| 64158 | 64095 | if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 64159 | 64096 | sqlite3ExpirePreparedStatements(db); |
| 64160 | - sqlite3ResetInternalSchema(db, 0); | |
| 64161 | - sqlite3VdbeMutexResync(p); | |
| 64097 | + sqlite3ResetInternalSchema(db, -1); | |
| 64162 | 64098 | db->flags = (db->flags | SQLITE_InternChanges); |
| 64163 | 64099 | } |
| 64164 | 64100 | } |
| 64165 | 64101 | |
| 64166 | 64102 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| @@ -64384,10 +64320,11 @@ | ||
| 64384 | 64320 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 64385 | 64321 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64386 | 64322 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 64387 | 64323 | u.au.pDb = &db->aDb[pOp->p1]; |
| 64388 | 64324 | assert( u.au.pDb->pBt!=0 ); |
| 64325 | + assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); | |
| 64389 | 64326 | pIn3 = &aMem[pOp->p3]; |
| 64390 | 64327 | sqlite3VdbeMemIntegerify(pIn3); |
| 64391 | 64328 | /* See note about index shifting on OP_ReadCookie */ |
| 64392 | 64329 | rc = sqlite3BtreeUpdateMeta(u.au.pDb->pBt, pOp->p2, (int)pIn3->u.i); |
| 64393 | 64330 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| @@ -64432,16 +64369,17 @@ | ||
| 64432 | 64369 | Btree *pBt; |
| 64433 | 64370 | #endif /* local variables moved into u.av */ |
| 64434 | 64371 | |
| 64435 | 64372 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64436 | 64373 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 64374 | + assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); | |
| 64437 | 64375 | u.av.pBt = db->aDb[pOp->p1].pBt; |
| 64438 | 64376 | if( u.av.pBt ){ |
| 64439 | 64377 | sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta); |
| 64440 | 64378 | u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 64441 | 64379 | }else{ |
| 64442 | - u.av.iMeta = 0; | |
| 64380 | + u.av.iGen = u.av.iMeta = 0; | |
| 64443 | 64381 | } |
| 64444 | 64382 | if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){ |
| 64445 | 64383 | sqlite3DbFree(db, p->zErrMsg); |
| 64446 | 64384 | p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 64447 | 64385 | /* If the schema-cookie from the database file matches the cookie |
| @@ -64457,11 +64395,10 @@ | ||
| 64457 | 64395 | ** to be invalidated whenever sqlite3_step() is called from within |
| 64458 | 64396 | ** a v-table method. |
| 64459 | 64397 | */ |
| 64460 | 64398 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){ |
| 64461 | 64399 | sqlite3ResetInternalSchema(db, pOp->p1); |
| 64462 | - sqlite3VdbeMutexResync(p); | |
| 64463 | 64400 | } |
| 64464 | 64401 | |
| 64465 | 64402 | p->expired = 1; |
| 64466 | 64403 | rc = SQLITE_SCHEMA; |
| 64467 | 64404 | } |
| @@ -64544,10 +64481,11 @@ | ||
| 64544 | 64481 | u.aw.pDb = &db->aDb[u.aw.iDb]; |
| 64545 | 64482 | u.aw.pX = u.aw.pDb->pBt; |
| 64546 | 64483 | assert( u.aw.pX!=0 ); |
| 64547 | 64484 | if( pOp->opcode==OP_OpenWrite ){ |
| 64548 | 64485 | u.aw.wrFlag = 1; |
| 64486 | + assert( sqlite3SchemaMutexHeld(db, u.aw.iDb, 0) ); | |
| 64549 | 64487 | if( u.aw.pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 64550 | 64488 | p->minWriteFileFormat = u.aw.pDb->pSchema->file_format; |
| 64551 | 64489 | } |
| 64552 | 64490 | }else{ |
| 64553 | 64491 | u.aw.wrFlag = 0; |
| @@ -66081,12 +66019,14 @@ | ||
| 66081 | 66019 | rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved); |
| 66082 | 66020 | pOut->flags = MEM_Int; |
| 66083 | 66021 | pOut->u.i = u.br.iMoved; |
| 66084 | 66022 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 66085 | 66023 | if( rc==SQLITE_OK && u.br.iMoved!=0 ){ |
| 66086 | - sqlite3RootPageMoved(&db->aDb[u.br.iDb], u.br.iMoved, pOp->p1); | |
| 66087 | - resetSchemaOnFault = 1; | |
| 66024 | + sqlite3RootPageMoved(db, u.br.iDb, u.br.iMoved, pOp->p1); | |
| 66025 | + /* All OP_Destroy operations occur on the same btree */ | |
| 66026 | + assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.br.iDb+1 ); | |
| 66027 | + resetSchemaOnFault = u.br.iDb+1; | |
| 66088 | 66028 | } |
| 66089 | 66029 | #endif |
| 66090 | 66030 | } |
| 66091 | 66031 | break; |
| 66092 | 66032 | } |
| @@ -66764,27 +66704,15 @@ | ||
| 66764 | 66704 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66765 | 66705 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66766 | 66706 | u.cb.ctx.pColl = pOp[-1].p4.pColl; |
| 66767 | 66707 | } |
| 66768 | 66708 | (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */ |
| 66769 | - sqlite3VdbeMutexResync(p); | |
| 66770 | 66709 | if( u.cb.ctx.isError ){ |
| 66771 | 66710 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s)); |
| 66772 | 66711 | rc = u.cb.ctx.isError; |
| 66773 | 66712 | } |
| 66774 | 66713 | |
| 66775 | - /* The app-defined function has done something that as caused this | |
| 66776 | - ** statement to expire. (Perhaps the function called sqlite3_exec() | |
| 66777 | - ** with a CREATE TABLE statement.) | |
| 66778 | - */ | |
| 66779 | -#if 0 | |
| 66780 | - if( p->expired ){ | |
| 66781 | - rc = SQLITE_ABORT; | |
| 66782 | - break; | |
| 66783 | - } | |
| 66784 | -#endif | |
| 66785 | - | |
| 66786 | 66714 | sqlite3VdbeMemRelease(&u.cb.ctx.s); |
| 66787 | 66715 | |
| 66788 | 66716 | break; |
| 66789 | 66717 | } |
| 66790 | 66718 | |
| @@ -66806,15 +66734,12 @@ | ||
| 66806 | 66734 | #endif /* local variables moved into u.cc */ |
| 66807 | 66735 | assert( pOp->p1>0 && pOp->p1<=p->nMem ); |
| 66808 | 66736 | u.cc.pMem = &aMem[pOp->p1]; |
| 66809 | 66737 | assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 66810 | 66738 | rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc); |
| 66811 | - sqlite3VdbeMutexResync(p); | |
| 66812 | 66739 | if( rc ){ |
| 66813 | 66740 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem)); |
| 66814 | - }else if( p->expired ){ | |
| 66815 | - rc = SQLITE_ABORT; | |
| 66816 | 66741 | } |
| 66817 | 66742 | sqlite3VdbeChangeEncoding(u.cc.pMem, encoding); |
| 66818 | 66743 | UPDATE_MAX_BLOBSIZE(u.cc.pMem); |
| 66819 | 66744 | if( sqlite3VdbeMemTooBig(u.cc.pMem) ){ |
| 66820 | 66745 | goto too_big; |
| @@ -66889,28 +66814,10 @@ | ||
| 66889 | 66814 | || u.ce.eNew==PAGER_JOURNALMODE_WAL |
| 66890 | 66815 | || u.ce.eNew==PAGER_JOURNALMODE_QUERY |
| 66891 | 66816 | ); |
| 66892 | 66817 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66893 | 66818 | |
| 66894 | - /* This opcode is used in two places: PRAGMA journal_mode and ATTACH. | |
| 66895 | - ** In PRAGMA journal_mode, the sqlite3VdbeUsesBtree() routine is called | |
| 66896 | - ** when the statement is prepared and so p->btreeMask!=0. All mutexes | |
| 66897 | - ** are already acquired. But when used in ATTACH, sqlite3VdbeUsesBtree() | |
| 66898 | - ** is not called when the statement is prepared because it requires the | |
| 66899 | - ** iDb index of the database as a parameter, and the database has not | |
| 66900 | - ** yet been attached so that index is unavailable. We have to wait | |
| 66901 | - ** until runtime (now) to get the mutex on the newly attached database. | |
| 66902 | - ** No other mutexes are required by the ATTACH command so this is safe | |
| 66903 | - ** to do. | |
| 66904 | - */ | |
| 66905 | - if( p->btreeMask==0 ){ | |
| 66906 | - /* This occurs right after ATTACH. Get a mutex on the newly ATTACHed | |
| 66907 | - ** database. */ | |
| 66908 | - sqlite3VdbeUsesBtree(p, pOp->p1); | |
| 66909 | - sqlite3VdbeEnter(p); | |
| 66910 | - } | |
| 66911 | - | |
| 66912 | 66819 | u.ce.pBt = db->aDb[pOp->p1].pBt; |
| 66913 | 66820 | u.ce.pPager = sqlite3BtreePager(u.ce.pBt); |
| 66914 | 66821 | u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager); |
| 66915 | 66822 | if( u.ce.eNew==PAGER_JOURNALMODE_QUERY ) u.ce.eNew = u.ce.eOld; |
| 66916 | 66823 | if( !sqlite3PagerOkToChangeJournalMode(u.ce.pPager) ) u.ce.eNew = u.ce.eOld; |
| @@ -67560,13 +67467,12 @@ | ||
| 67560 | 67467 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 67561 | 67468 | pc, p->zSql, p->zErrMsg); |
| 67562 | 67469 | sqlite3VdbeHalt(p); |
| 67563 | 67470 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 67564 | 67471 | rc = SQLITE_ERROR; |
| 67565 | - if( resetSchemaOnFault ){ | |
| 67566 | - sqlite3ResetInternalSchema(db, 0); | |
| 67567 | - sqlite3VdbeMutexResync(p); | |
| 67472 | + if( resetSchemaOnFault>0 ){ | |
| 67473 | + sqlite3ResetInternalSchema(db, resetSchemaOnFault-1); | |
| 67568 | 67474 | } |
| 67569 | 67475 | |
| 67570 | 67476 | /* This is the only way out of this procedure. We have to |
| 67571 | 67477 | ** release the mutexes on btrees that were acquired at the |
| 67572 | 67478 | ** top. */ |
| @@ -72266,11 +72172,11 @@ | ||
| 72266 | 72172 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 72267 | 72173 | assert( pExpr->u.zToken!=0 ); |
| 72268 | 72174 | assert( pExpr->u.zToken[0]!=0 ); |
| 72269 | 72175 | sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target); |
| 72270 | 72176 | if( pExpr->u.zToken[1]!=0 ){ |
| 72271 | - sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, 0); | |
| 72177 | + sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, P4_TRANSIENT); | |
| 72272 | 72178 | } |
| 72273 | 72179 | break; |
| 72274 | 72180 | } |
| 72275 | 72181 | case TK_REGISTER: { |
| 72276 | 72182 | inReg = pExpr->iTable; |
| @@ -74655,10 +74561,11 @@ | ||
| 74655 | 74561 | return; |
| 74656 | 74562 | } |
| 74657 | 74563 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 74658 | 74564 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 74659 | 74565 | assert( iDb>=0 ); |
| 74566 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 74660 | 74567 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 74661 | 74568 | if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0, |
| 74662 | 74569 | db->aDb[iDb].zName ) ){ |
| 74663 | 74570 | return; |
| 74664 | 74571 | } |
| @@ -74896,10 +74803,11 @@ | ||
| 74896 | 74803 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74897 | 74804 | iStatCur = pParse->nTab; |
| 74898 | 74805 | pParse->nTab += 2; |
| 74899 | 74806 | openStatTable(pParse, iDb, iStatCur, 0, 0); |
| 74900 | 74807 | iMem = pParse->nMem+1; |
| 74808 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 74901 | 74809 | for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 74902 | 74810 | Table *pTab = (Table*)sqliteHashData(k); |
| 74903 | 74811 | analyzeOneTable(pParse, pTab, 0, iStatCur, iMem); |
| 74904 | 74812 | } |
| 74905 | 74813 | loadAnalysis(pParse, iDb); |
| @@ -75106,13 +75014,13 @@ | ||
| 75106 | 75014 | char *zSql; |
| 75107 | 75015 | int rc; |
| 75108 | 75016 | |
| 75109 | 75017 | assert( iDb>=0 && iDb<db->nDb ); |
| 75110 | 75018 | assert( db->aDb[iDb].pBt!=0 ); |
| 75111 | - assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); | |
| 75112 | 75019 | |
| 75113 | 75020 | /* Clear any prior statistics */ |
| 75021 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 75114 | 75022 | for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ |
| 75115 | 75023 | Index *pIdx = sqliteHashData(i); |
| 75116 | 75024 | sqlite3DefaultRowEst(pIdx); |
| 75117 | 75025 | sqlite3DeleteIndexSamples(db, pIdx); |
| 75118 | 75026 | pIdx->aSample = 0; |
| @@ -75421,11 +75329,11 @@ | ||
| 75421 | 75329 | if( db->aDb[iDb].pBt ){ |
| 75422 | 75330 | sqlite3BtreeClose(db->aDb[iDb].pBt); |
| 75423 | 75331 | db->aDb[iDb].pBt = 0; |
| 75424 | 75332 | db->aDb[iDb].pSchema = 0; |
| 75425 | 75333 | } |
| 75426 | - sqlite3ResetInternalSchema(db, 0); | |
| 75334 | + sqlite3ResetInternalSchema(db, -1); | |
| 75427 | 75335 | db->nDb = iDb; |
| 75428 | 75336 | if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 75429 | 75337 | db->mallocFailed = 1; |
| 75430 | 75338 | sqlite3DbFree(db, zErrDyn); |
| 75431 | 75339 | zErrDyn = sqlite3MPrintf(db, "out of memory"); |
| @@ -75493,11 +75401,11 @@ | ||
| 75493 | 75401 | } |
| 75494 | 75402 | |
| 75495 | 75403 | sqlite3BtreeClose(pDb->pBt); |
| 75496 | 75404 | pDb->pBt = 0; |
| 75497 | 75405 | pDb->pSchema = 0; |
| 75498 | - sqlite3ResetInternalSchema(db, 0); | |
| 75406 | + sqlite3ResetInternalSchema(db, -1); | |
| 75499 | 75407 | return; |
| 75500 | 75408 | |
| 75501 | 75409 | detach_error: |
| 75502 | 75410 | sqlite3_result_error(context, zErr, -1); |
| 75503 | 75411 | } |
| @@ -76171,10 +76079,11 @@ | ||
| 76171 | 76079 | for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ |
| 76172 | 76080 | if( (mask & pParse->cookieMask)==0 ) continue; |
| 76173 | 76081 | sqlite3VdbeUsesBtree(v, iDb); |
| 76174 | 76082 | sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0); |
| 76175 | 76083 | if( db->init.busy==0 ){ |
| 76084 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 76176 | 76085 | sqlite3VdbeAddOp3(v, OP_VerifyCookie, |
| 76177 | 76086 | iDb, pParse->cookieValue[iDb], |
| 76178 | 76087 | db->aDb[iDb].pSchema->iGeneration); |
| 76179 | 76088 | } |
| 76180 | 76089 | } |
| @@ -76286,13 +76195,16 @@ | ||
| 76286 | 76195 | Table *p = 0; |
| 76287 | 76196 | int i; |
| 76288 | 76197 | int nName; |
| 76289 | 76198 | assert( zName!=0 ); |
| 76290 | 76199 | nName = sqlite3Strlen30(zName); |
| 76200 | + /* All mutexes are required for schema access. Make sure we hold them. */ | |
| 76201 | + assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); | |
| 76291 | 76202 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 76292 | 76203 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 76293 | 76204 | if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; |
| 76205 | + assert( sqlite3SchemaMutexHeld(db, j, 0) ); | |
| 76294 | 76206 | p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName); |
| 76295 | 76207 | if( p ) break; |
| 76296 | 76208 | } |
| 76297 | 76209 | return p; |
| 76298 | 76210 | } |
| @@ -76348,15 +76260,18 @@ | ||
| 76348 | 76260 | */ |
| 76349 | 76261 | SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ |
| 76350 | 76262 | Index *p = 0; |
| 76351 | 76263 | int i; |
| 76352 | 76264 | int nName = sqlite3Strlen30(zName); |
| 76265 | + /* All mutexes are required for schema access. Make sure we hold them. */ | |
| 76266 | + assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) ); | |
| 76353 | 76267 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 76354 | 76268 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 76355 | 76269 | Schema *pSchema = db->aDb[j].pSchema; |
| 76356 | 76270 | assert( pSchema ); |
| 76357 | 76271 | if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue; |
| 76272 | + assert( sqlite3SchemaMutexHeld(db, j, 0) ); | |
| 76358 | 76273 | p = sqlite3HashFind(&pSchema->idxHash, zName, nName); |
| 76359 | 76274 | if( p ) break; |
| 76360 | 76275 | } |
| 76361 | 76276 | return p; |
| 76362 | 76277 | } |
| @@ -76379,12 +76294,14 @@ | ||
| 76379 | 76294 | ** with the index. |
| 76380 | 76295 | */ |
| 76381 | 76296 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){ |
| 76382 | 76297 | Index *pIndex; |
| 76383 | 76298 | int len; |
| 76384 | - Hash *pHash = &db->aDb[iDb].pSchema->idxHash; | |
| 76299 | + Hash *pHash; | |
| 76385 | 76300 | |
| 76301 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 76302 | + pHash = &db->aDb[iDb].pSchema->idxHash; | |
| 76386 | 76303 | len = sqlite3Strlen30(zIdxName); |
| 76387 | 76304 | pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0); |
| 76388 | 76305 | if( ALWAYS(pIndex) ){ |
| 76389 | 76306 | if( pIndex->pTable->pIndex==pIndex ){ |
| 76390 | 76307 | pIndex->pTable->pIndex = pIndex->pNext; |
| @@ -76408,30 +76325,46 @@ | ||
| 76408 | 76325 | ** a single database. This routine is called to reclaim memory |
| 76409 | 76326 | ** before the database closes. It is also called during a rollback |
| 76410 | 76327 | ** if there were schema changes during the transaction or if a |
| 76411 | 76328 | ** schema-cookie mismatch occurs. |
| 76412 | 76329 | ** |
| 76413 | -** If iDb==0 then reset the internal schema tables for all database | |
| 76414 | -** files. If iDb>=1 then reset the internal schema for only the | |
| 76330 | +** If iDb<0 then reset the internal schema tables for all database | |
| 76331 | +** files. If iDb>=0 then reset the internal schema for only the | |
| 76415 | 76332 | ** single file indicated. |
| 76416 | 76333 | */ |
| 76417 | 76334 | SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){ |
| 76418 | 76335 | int i, j; |
| 76419 | - assert( iDb>=0 && iDb<db->nDb ); | |
| 76336 | + assert( iDb<db->nDb ); | |
| 76420 | 76337 | |
| 76421 | - if( iDb==0 ){ | |
| 76422 | - sqlite3BtreeEnterAll(db); | |
| 76338 | + if( iDb>=0 ){ | |
| 76339 | + /* Case 1: Reset the single schema identified by iDb */ | |
| 76340 | + Db *pDb = &db->aDb[iDb]; | |
| 76341 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 76342 | + assert( pDb->pSchema!=0 ); | |
| 76343 | + sqlite3SchemaClear(pDb->pSchema); | |
| 76344 | + | |
| 76345 | + /* If any database other than TEMP is reset, then also reset TEMP | |
| 76346 | + ** since TEMP might be holding triggers that reference tables in the | |
| 76347 | + ** other database. | |
| 76348 | + */ | |
| 76349 | + if( iDb!=1 ){ | |
| 76350 | + pDb = &db->aDb[1]; | |
| 76351 | + assert( pDb->pSchema!=0 ); | |
| 76352 | + sqlite3SchemaClear(pDb->pSchema); | |
| 76353 | + } | |
| 76354 | + return; | |
| 76423 | 76355 | } |
| 76424 | - for(i=iDb; i<db->nDb; i++){ | |
| 76356 | + /* Case 2 (from here to the end): Reset all schemas for all attached | |
| 76357 | + ** databases. */ | |
| 76358 | + assert( iDb<0 ); | |
| 76359 | + sqlite3BtreeEnterAll(db); | |
| 76360 | + for(i=0; i<db->nDb; i++){ | |
| 76425 | 76361 | Db *pDb = &db->aDb[i]; |
| 76426 | 76362 | if( pDb->pSchema ){ |
| 76427 | - assert(i==1 || (pDb->pBt && sqlite3BtreeHoldsMutex(pDb->pBt))); | |
| 76428 | - sqlite3SchemaFree(pDb->pSchema); | |
| 76363 | + sqlite3SchemaClear(pDb->pSchema); | |
| 76429 | 76364 | } |
| 76430 | - if( iDb>0 ) return; | |
| 76431 | 76365 | } |
| 76432 | - assert( iDb==0 ); | |
| 76433 | 76366 | db->flags &= ~SQLITE_InternChanges; |
| 76434 | 76367 | sqlite3VtabUnlockList(db); |
| 76435 | 76368 | sqlite3BtreeLeaveAll(db); |
| 76436 | 76369 | |
| 76437 | 76370 | /* If one or more of the auxiliary database files has been closed, |
| @@ -76513,10 +76446,11 @@ | ||
| 76513 | 76446 | if( !db || db->pnBytesFreed==0 ){ |
| 76514 | 76447 | char *zName = pIndex->zName; |
| 76515 | 76448 | TESTONLY ( Index *pOld = ) sqlite3HashInsert( |
| 76516 | 76449 | &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0 |
| 76517 | 76450 | ); |
| 76451 | + assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); | |
| 76518 | 76452 | assert( pOld==pIndex || pOld==0 ); |
| 76519 | 76453 | } |
| 76520 | 76454 | freeIndex(db, pIndex); |
| 76521 | 76455 | } |
| 76522 | 76456 | |
| @@ -76547,10 +76481,11 @@ | ||
| 76547 | 76481 | Db *pDb; |
| 76548 | 76482 | |
| 76549 | 76483 | assert( db!=0 ); |
| 76550 | 76484 | assert( iDb>=0 && iDb<db->nDb ); |
| 76551 | 76485 | assert( zTabName ); |
| 76486 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 76552 | 76487 | testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */ |
| 76553 | 76488 | pDb = &db->aDb[iDb]; |
| 76554 | 76489 | p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, |
| 76555 | 76490 | sqlite3Strlen30(zTabName),0); |
| 76556 | 76491 | sqlite3DeleteTable(db, p); |
| @@ -76831,10 +76766,11 @@ | ||
| 76831 | 76766 | ** then record a pointer to this table in the main database structure |
| 76832 | 76767 | ** so that INSERT can find the table easily. |
| 76833 | 76768 | */ |
| 76834 | 76769 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 76835 | 76770 | if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){ |
| 76771 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 76836 | 76772 | pTable->pSchema->pSeqTab = pTable; |
| 76837 | 76773 | } |
| 76838 | 76774 | #endif |
| 76839 | 76775 | |
| 76840 | 76776 | /* Begin generating the code that will insert the table record into |
| @@ -77291,10 +77227,11 @@ | ||
| 77291 | 77227 | */ |
| 77292 | 77228 | SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){ |
| 77293 | 77229 | int r1 = sqlite3GetTempReg(pParse); |
| 77294 | 77230 | sqlite3 *db = pParse->db; |
| 77295 | 77231 | Vdbe *v = pParse->pVdbe; |
| 77232 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 77296 | 77233 | sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1); |
| 77297 | 77234 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1); |
| 77298 | 77235 | sqlite3ReleaseTempReg(pParse, r1); |
| 77299 | 77236 | } |
| 77300 | 77237 | |
| @@ -77398,11 +77335,11 @@ | ||
| 77398 | 77335 | sqlite3_snprintf(n-k, &zStmt[k], zSep); |
| 77399 | 77336 | k += sqlite3Strlen30(&zStmt[k]); |
| 77400 | 77337 | zSep = zSep2; |
| 77401 | 77338 | identPut(zStmt, &k, pCol->zName); |
| 77402 | 77339 | assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 ); |
| 77403 | - assert( pCol->affinity-SQLITE_AFF_TEXT < sizeof(azType)/sizeof(azType[0]) ); | |
| 77340 | + assert( pCol->affinity-SQLITE_AFF_TEXT < ArraySize(azType) ); | |
| 77404 | 77341 | testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 77405 | 77342 | testcase( pCol->affinity==SQLITE_AFF_NONE ); |
| 77406 | 77343 | testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); |
| 77407 | 77344 | testcase( pCol->affinity==SQLITE_AFF_INTEGER ); |
| 77408 | 77345 | testcase( pCol->affinity==SQLITE_AFF_REAL ); |
| @@ -77593,10 +77530,11 @@ | ||
| 77593 | 77530 | /* Check to see if we need to create an sqlite_sequence table for |
| 77594 | 77531 | ** keeping track of autoincrement keys. |
| 77595 | 77532 | */ |
| 77596 | 77533 | if( p->tabFlags & TF_Autoincrement ){ |
| 77597 | 77534 | Db *pDb = &db->aDb[iDb]; |
| 77535 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 77598 | 77536 | if( pDb->pSchema->pSeqTab==0 ){ |
| 77599 | 77537 | sqlite3NestedParse(pParse, |
| 77600 | 77538 | "CREATE TABLE %Q.sqlite_sequence(name,seq)", |
| 77601 | 77539 | pDb->zName |
| 77602 | 77540 | ); |
| @@ -77613,10 +77551,11 @@ | ||
| 77613 | 77551 | /* Add the table to the in-memory representation of the database. |
| 77614 | 77552 | */ |
| 77615 | 77553 | if( db->init.busy ){ |
| 77616 | 77554 | Table *pOld; |
| 77617 | 77555 | Schema *pSchema = p->pSchema; |
| 77556 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 77618 | 77557 | pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, |
| 77619 | 77558 | sqlite3Strlen30(p->zName),p); |
| 77620 | 77559 | if( pOld ){ |
| 77621 | 77560 | assert( p==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 77622 | 77561 | db->mallocFailed = 1; |
| @@ -77797,10 +77736,11 @@ | ||
| 77797 | 77736 | pTable->nCol = pSelTab->nCol; |
| 77798 | 77737 | pTable->aCol = pSelTab->aCol; |
| 77799 | 77738 | pSelTab->nCol = 0; |
| 77800 | 77739 | pSelTab->aCol = 0; |
| 77801 | 77740 | sqlite3DeleteTable(db, pSelTab); |
| 77741 | + assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); | |
| 77802 | 77742 | pTable->pSchema->flags |= DB_UnresetViews; |
| 77803 | 77743 | }else{ |
| 77804 | 77744 | pTable->nCol = 0; |
| 77805 | 77745 | nErr++; |
| 77806 | 77746 | } |
| @@ -77817,10 +77757,11 @@ | ||
| 77817 | 77757 | /* |
| 77818 | 77758 | ** Clear the column names from every VIEW in database idx. |
| 77819 | 77759 | */ |
| 77820 | 77760 | static void sqliteViewResetAll(sqlite3 *db, int idx){ |
| 77821 | 77761 | HashElem *i; |
| 77762 | + assert( sqlite3SchemaMutexHeld(db, idx, 0) ); | |
| 77822 | 77763 | if( !DbHasProperty(db, idx, DB_UnresetViews) ) return; |
| 77823 | 77764 | for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){ |
| 77824 | 77765 | Table *pTab = sqliteHashData(i); |
| 77825 | 77766 | if( pTab->pSelect ){ |
| 77826 | 77767 | sqliteDeleteColumnNames(db, pTab); |
| @@ -77850,14 +77791,17 @@ | ||
| 77850 | 77791 | ** We must continue looping until all tables and indices with |
| 77851 | 77792 | ** rootpage==iFrom have been converted to have a rootpage of iTo |
| 77852 | 77793 | ** in order to be certain that we got the right one. |
| 77853 | 77794 | */ |
| 77854 | 77795 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 77855 | -SQLITE_PRIVATE void sqlite3RootPageMoved(Db *pDb, int iFrom, int iTo){ | |
| 77796 | +SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){ | |
| 77856 | 77797 | HashElem *pElem; |
| 77857 | 77798 | Hash *pHash; |
| 77799 | + Db *pDb; | |
| 77858 | 77800 | |
| 77801 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 77802 | + pDb = &db->aDb[iDb]; | |
| 77859 | 77803 | pHash = &pDb->pSchema->tblHash; |
| 77860 | 77804 | for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){ |
| 77861 | 77805 | Table *pTab = sqliteHashData(pElem); |
| 77862 | 77806 | if( pTab->tnum==iFrom ){ |
| 77863 | 77807 | pTab->tnum = iTo; |
| @@ -78227,10 +78171,11 @@ | ||
| 78227 | 78171 | } |
| 78228 | 78172 | pFKey->isDeferred = 0; |
| 78229 | 78173 | pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */ |
| 78230 | 78174 | pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */ |
| 78231 | 78175 | |
| 78176 | + assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) ); | |
| 78232 | 78177 | pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash, |
| 78233 | 78178 | pFKey->zTo, sqlite3Strlen30(pFKey->zTo), (void *)pFKey |
| 78234 | 78179 | ); |
| 78235 | 78180 | if( pNextTo==pFKey ){ |
| 78236 | 78181 | db->mallocFailed = 1; |
| @@ -78582,10 +78527,11 @@ | ||
| 78582 | 78527 | pIndex->pTable = pTab; |
| 78583 | 78528 | pIndex->nColumn = pList->nExpr; |
| 78584 | 78529 | pIndex->onError = (u8)onError; |
| 78585 | 78530 | pIndex->autoIndex = (u8)(pName==0); |
| 78586 | 78531 | pIndex->pSchema = db->aDb[iDb].pSchema; |
| 78532 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 78587 | 78533 | |
| 78588 | 78534 | /* Check to see if we should honor DESC requests on index columns |
| 78589 | 78535 | */ |
| 78590 | 78536 | if( pDb->pSchema->file_format>=4 ){ |
| 78591 | 78537 | sortOrderMask = -1; /* Honor DESC */ |
| @@ -78711,10 +78657,11 @@ | ||
| 78711 | 78657 | /* Link the new Index structure to its table and to the other |
| 78712 | 78658 | ** in-memory database structures. |
| 78713 | 78659 | */ |
| 78714 | 78660 | if( db->init.busy ){ |
| 78715 | 78661 | Index *p; |
| 78662 | + assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); | |
| 78716 | 78663 | p = sqlite3HashInsert(&pIndex->pSchema->idxHash, |
| 78717 | 78664 | pIndex->zName, sqlite3Strlen30(pIndex->zName), |
| 78718 | 78665 | pIndex); |
| 78719 | 78666 | if( p ){ |
| 78720 | 78667 | assert( p==pIndex ); /* Malloc must have failed */ |
| @@ -79464,10 +79411,11 @@ | ||
| 79464 | 79411 | yDbMask mask; |
| 79465 | 79412 | |
| 79466 | 79413 | assert( iDb<db->nDb ); |
| 79467 | 79414 | assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 79468 | 79415 | assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 79416 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 79469 | 79417 | mask = ((yDbMask)1)<<iDb; |
| 79470 | 79418 | if( (pToplevel->cookieMask & mask)==0 ){ |
| 79471 | 79419 | pToplevel->cookieMask |= mask; |
| 79472 | 79420 | pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 79473 | 79421 | if( !OMIT_TEMPDB && iDb==1 ){ |
| @@ -79591,10 +79539,11 @@ | ||
| 79591 | 79539 | int iDb; /* The database index number */ |
| 79592 | 79540 | sqlite3 *db = pParse->db; /* The database connection */ |
| 79593 | 79541 | HashElem *k; /* For looping over tables in pDb */ |
| 79594 | 79542 | Table *pTab; /* A table in the database */ |
| 79595 | 79543 | |
| 79544 | + assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */ | |
| 79596 | 79545 | for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){ |
| 79597 | 79546 | assert( pDb!=0 ); |
| 79598 | 79547 | for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 79599 | 79548 | pTab = (Table*)sqliteHashData(k); |
| 79600 | 79549 | reindexTable(pParse, pTab, zColl); |
| @@ -80109,16 +80058,16 @@ | ||
| 80109 | 80058 | } |
| 80110 | 80059 | |
| 80111 | 80060 | /* |
| 80112 | 80061 | ** Free all resources held by the schema structure. The void* argument points |
| 80113 | 80062 | ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the |
| 80114 | -** pointer itself, it just cleans up subsiduary resources (i.e. the contents | |
| 80063 | +** pointer itself, it just cleans up subsidiary resources (i.e. the contents | |
| 80115 | 80064 | ** of the schema hash tables). |
| 80116 | 80065 | ** |
| 80117 | 80066 | ** The Schema.cache_size variable is not cleared. |
| 80118 | 80067 | */ |
| 80119 | -SQLITE_PRIVATE void sqlite3SchemaFree(void *p){ | |
| 80068 | +SQLITE_PRIVATE void sqlite3SchemaClear(void *p){ | |
| 80120 | 80069 | Hash temp1; |
| 80121 | 80070 | Hash temp2; |
| 80122 | 80071 | HashElem *pElem; |
| 80123 | 80072 | Schema *pSchema = (Schema *)p; |
| 80124 | 80073 | |
| @@ -80149,11 +80098,11 @@ | ||
| 80149 | 80098 | ** a new one if necessary. |
| 80150 | 80099 | */ |
| 80151 | 80100 | SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ |
| 80152 | 80101 | Schema * p; |
| 80153 | 80102 | if( pBt ){ |
| 80154 | - p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree); | |
| 80103 | + p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear); | |
| 80155 | 80104 | }else{ |
| 80156 | 80105 | p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema)); |
| 80157 | 80106 | } |
| 80158 | 80107 | if( !p ){ |
| 80159 | 80108 | db->mallocFailed = 1; |
| @@ -80183,13 +80132,22 @@ | ||
| 80183 | 80132 | ** This file contains C code routines that are called by the parser |
| 80184 | 80133 | ** in order to generate code for DELETE FROM statements. |
| 80185 | 80134 | */ |
| 80186 | 80135 | |
| 80187 | 80136 | /* |
| 80188 | -** Look up every table that is named in pSrc. If any table is not found, | |
| 80189 | -** add an error message to pParse->zErrMsg and return NULL. If all tables | |
| 80190 | -** are found, return a pointer to the last table. | |
| 80137 | +** While a SrcList can in general represent multiple tables and subqueries | |
| 80138 | +** (as in the FROM clause of a SELECT statement) in this case it contains | |
| 80139 | +** the name of a single table, as one might find in an INSERT, DELETE, | |
| 80140 | +** or UPDATE statement. Look up that table in the symbol table and | |
| 80141 | +** return a pointer. Set an error message and return NULL if the table | |
| 80142 | +** name is not found or if any other error occurs. | |
| 80143 | +** | |
| 80144 | +** The following fields are initialized appropriate in pSrc: | |
| 80145 | +** | |
| 80146 | +** pSrc->a[0].pTab Pointer to the Table object | |
| 80147 | +** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one | |
| 80148 | +** | |
| 80191 | 80149 | */ |
| 80192 | 80150 | SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ |
| 80193 | 80151 | struct SrcList_item *pItem = pSrc->a; |
| 80194 | 80152 | Table *pTab; |
| 80195 | 80153 | assert( pItem && pSrc->nSrc==1 ); |
| @@ -80704,11 +80662,11 @@ | ||
| 80704 | 80662 | ** fire the INSTEAD OF triggers). */ |
| 80705 | 80663 | if( pTab->pSelect==0 ){ |
| 80706 | 80664 | sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0); |
| 80707 | 80665 | sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0)); |
| 80708 | 80666 | if( count ){ |
| 80709 | - sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC); | |
| 80667 | + sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); | |
| 80710 | 80668 | } |
| 80711 | 80669 | } |
| 80712 | 80670 | |
| 80713 | 80671 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 80714 | 80672 | ** handle rows (possibly in other tables) that refer via a foreign key |
| @@ -80795,11 +80753,11 @@ | ||
| 80795 | 80753 | sqlite3ColumnDefault(v, pTab, idx, -1); |
| 80796 | 80754 | } |
| 80797 | 80755 | } |
| 80798 | 80756 | if( doMakeRec ){ |
| 80799 | 80757 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut); |
| 80800 | - sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0); | |
| 80758 | + sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT); | |
| 80801 | 80759 | } |
| 80802 | 80760 | sqlite3ReleaseTempRange(pParse, regBase, nCol+1); |
| 80803 | 80761 | return regBase; |
| 80804 | 80762 | } |
| 80805 | 80763 | |
| @@ -82792,11 +82750,11 @@ | ||
| 82792 | 82750 | } |
| 82793 | 82751 | sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk); |
| 82794 | 82752 | } |
| 82795 | 82753 | |
| 82796 | 82754 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec); |
| 82797 | - sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0); | |
| 82755 | + sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT); | |
| 82798 | 82756 | sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); |
| 82799 | 82757 | |
| 82800 | 82758 | sqlite3ReleaseTempReg(pParse, regRec); |
| 82801 | 82759 | sqlite3ReleaseTempRange(pParse, regTemp, nCol); |
| 82802 | 82760 | } |
| @@ -83548,10 +83506,11 @@ | ||
| 83548 | 83506 | */ |
| 83549 | 83507 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ |
| 83550 | 83508 | FKey *pFKey; /* Iterator variable */ |
| 83551 | 83509 | FKey *pNext; /* Copy of pFKey->pNextFrom */ |
| 83552 | 83510 | |
| 83511 | + assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); | |
| 83553 | 83512 | for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){ |
| 83554 | 83513 | |
| 83555 | 83514 | /* Remove the FK from the fkeyHash hash table. */ |
| 83556 | 83515 | if( !db || db->pnBytesFreed==0 ){ |
| 83557 | 83516 | if( pFKey->pPrevTo ){ |
| @@ -83707,11 +83666,11 @@ | ||
| 83707 | 83666 | zColAff[pTab->nCol] = '\0'; |
| 83708 | 83667 | |
| 83709 | 83668 | pTab->zColAff = zColAff; |
| 83710 | 83669 | } |
| 83711 | 83670 | |
| 83712 | - sqlite3VdbeChangeP4(v, -1, pTab->zColAff, 0); | |
| 83671 | + sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT); | |
| 83713 | 83672 | } |
| 83714 | 83673 | |
| 83715 | 83674 | /* |
| 83716 | 83675 | ** Return non-zero if the table pTab in database iDb or any of its indices |
| 83717 | 83676 | ** have been opened at any point in the VDBE program beginning at location |
| @@ -83821,10 +83780,11 @@ | ||
| 83821 | 83780 | |
| 83822 | 83781 | assert( v ); /* We failed long ago if this is not so */ |
| 83823 | 83782 | for(p = pParse->pAinc; p; p = p->pNext){ |
| 83824 | 83783 | pDb = &db->aDb[p->iDb]; |
| 83825 | 83784 | memId = p->regCtr; |
| 83785 | + assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); | |
| 83826 | 83786 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead); |
| 83827 | 83787 | addr = sqlite3VdbeCurrentAddr(v); |
| 83828 | 83788 | sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0); |
| 83829 | 83789 | sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); |
| 83830 | 83790 | sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId); |
| @@ -83871,10 +83831,11 @@ | ||
| 83871 | 83831 | int j1, j2, j3, j4, j5; |
| 83872 | 83832 | int iRec; |
| 83873 | 83833 | int memId = p->regCtr; |
| 83874 | 83834 | |
| 83875 | 83835 | iRec = sqlite3GetTempReg(pParse); |
| 83836 | + assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); | |
| 83876 | 83837 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite); |
| 83877 | 83838 | j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); |
| 83878 | 83839 | j2 = sqlite3VdbeAddOp0(v, OP_Rewind); |
| 83879 | 83840 | j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec); |
| 83880 | 83841 | j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec); |
| @@ -84911,11 +84872,11 @@ | ||
| 84911 | 84872 | sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i); |
| 84912 | 84873 | } |
| 84913 | 84874 | } |
| 84914 | 84875 | sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i); |
| 84915 | 84876 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]); |
| 84916 | - sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0); | |
| 84877 | + sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT); | |
| 84917 | 84878 | sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1); |
| 84918 | 84879 | |
| 84919 | 84880 | #ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT |
| 84920 | 84881 | sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1); |
| 84921 | 84882 | continue; /* Treat pIdx as if it is not a UNIQUE index */ |
| @@ -85057,11 +85018,11 @@ | ||
| 85057 | 85018 | if( useSeekResult ){ |
| 85058 | 85019 | pik_flags |= OPFLAG_USESEEKRESULT; |
| 85059 | 85020 | } |
| 85060 | 85021 | sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid); |
| 85061 | 85022 | if( !pParse->nested ){ |
| 85062 | - sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC); | |
| 85023 | + sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); | |
| 85063 | 85024 | } |
| 85064 | 85025 | sqlite3VdbeChangeP5(v, pik_flags); |
| 85065 | 85026 | } |
| 85066 | 85027 | |
| 85067 | 85028 | /* |
| @@ -86752,11 +86713,11 @@ | ||
| 86752 | 86713 | "from within a transaction"); |
| 86753 | 86714 | return SQLITE_ERROR; |
| 86754 | 86715 | } |
| 86755 | 86716 | sqlite3BtreeClose(db->aDb[1].pBt); |
| 86756 | 86717 | db->aDb[1].pBt = 0; |
| 86757 | - sqlite3ResetInternalSchema(db, 0); | |
| 86718 | + sqlite3ResetInternalSchema(db, -1); | |
| 86758 | 86719 | } |
| 86759 | 86720 | return SQLITE_OK; |
| 86760 | 86721 | } |
| 86761 | 86722 | #endif /* SQLITE_PAGER_PRAGMAS */ |
| 86762 | 86723 | |
| @@ -87025,10 +86986,11 @@ | ||
| 87025 | 86986 | }else{ |
| 87026 | 86987 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 87027 | 86988 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 87028 | 86989 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
| 87029 | 86990 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
| 86991 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 87030 | 86992 | pDb->pSchema->cache_size = size; |
| 87031 | 86993 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
| 87032 | 86994 | } |
| 87033 | 86995 | }else |
| 87034 | 86996 | |
| @@ -87327,10 +87289,11 @@ | ||
| 87327 | 87289 | ** to its default value when the database is closed and reopened. |
| 87328 | 87290 | ** N should be a positive integer. |
| 87329 | 87291 | */ |
| 87330 | 87292 | if( sqlite3StrICmp(zLeft,"cache_size")==0 ){ |
| 87331 | 87293 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 87294 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 87332 | 87295 | if( !zRight ){ |
| 87333 | 87296 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
| 87334 | 87297 | }else{ |
| 87335 | 87298 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 87336 | 87299 | pDb->pSchema->cache_size = size; |
| @@ -87747,10 +87710,11 @@ | ||
| 87747 | 87710 | /* Do an integrity check of the B-Tree |
| 87748 | 87711 | ** |
| 87749 | 87712 | ** Begin by filling registers 2, 3, ... with the root pages numbers |
| 87750 | 87713 | ** for all tables and indices in the database. |
| 87751 | 87714 | */ |
| 87715 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 87752 | 87716 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 87753 | 87717 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
| 87754 | 87718 | Table *pTab = sqliteHashData(x); |
| 87755 | 87719 | Index *pIdx; |
| 87756 | 87720 | sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt); |
| @@ -87812,11 +87776,11 @@ | ||
| 87812 | 87776 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0); |
| 87813 | 87777 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1); |
| 87814 | 87778 | addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr); |
| 87815 | 87779 | sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC); |
| 87816 | 87780 | sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC); |
| 87817 | - sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC); | |
| 87781 | + sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_TRANSIENT); | |
| 87818 | 87782 | sqlite3VdbeJumpHere(v, addr+9); |
| 87819 | 87783 | sqlite3VdbeJumpHere(v, jmp2); |
| 87820 | 87784 | } |
| 87821 | 87785 | sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1); |
| 87822 | 87786 | sqlite3VdbeJumpHere(v, loopTop); |
| @@ -87842,11 +87806,11 @@ | ||
| 87842 | 87806 | sqlite3VdbeChangeP1(v, addr+3, j+2); |
| 87843 | 87807 | sqlite3VdbeChangeP2(v, addr+3, addr+2); |
| 87844 | 87808 | sqlite3VdbeJumpHere(v, addr+4); |
| 87845 | 87809 | sqlite3VdbeChangeP4(v, addr+6, |
| 87846 | 87810 | "wrong # of entries in index ", P4_STATIC); |
| 87847 | - sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_STATIC); | |
| 87811 | + sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_TRANSIENT); | |
| 87848 | 87812 | } |
| 87849 | 87813 | } |
| 87850 | 87814 | } |
| 87851 | 87815 | addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode); |
| 87852 | 87816 | sqlite3VdbeChangeP2(v, addr, -mxErr); |
| @@ -88498,11 +88462,11 @@ | ||
| 88498 | 88462 | } |
| 88499 | 88463 | #endif |
| 88500 | 88464 | } |
| 88501 | 88465 | if( db->mallocFailed ){ |
| 88502 | 88466 | rc = SQLITE_NOMEM; |
| 88503 | - sqlite3ResetInternalSchema(db, 0); | |
| 88467 | + sqlite3ResetInternalSchema(db, -1); | |
| 88504 | 88468 | } |
| 88505 | 88469 | if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){ |
| 88506 | 88470 | /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider |
| 88507 | 88471 | ** the schema loaded, even if errors occurred. In this situation the |
| 88508 | 88472 | ** current sqlite3_prepare() operation will fail, but the following one |
| @@ -88630,11 +88594,13 @@ | ||
| 88630 | 88594 | |
| 88631 | 88595 | /* Read the schema cookie from the database. If it does not match the |
| 88632 | 88596 | ** value stored as part of the in-memory schema representation, |
| 88633 | 88597 | ** set Parse.rc to SQLITE_SCHEMA. */ |
| 88634 | 88598 | sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie); |
| 88599 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 88635 | 88600 | if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){ |
| 88601 | + sqlite3ResetInternalSchema(db, iDb); | |
| 88636 | 88602 | pParse->rc = SQLITE_SCHEMA; |
| 88637 | 88603 | } |
| 88638 | 88604 | |
| 88639 | 88605 | /* Close the transaction, if one was opened. */ |
| 88640 | 88606 | if( openedTransaction ){ |
| @@ -88772,13 +88738,10 @@ | ||
| 88772 | 88738 | } |
| 88773 | 88739 | if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK; |
| 88774 | 88740 | if( pParse->checkSchema ){ |
| 88775 | 88741 | schemaIsValid(pParse); |
| 88776 | 88742 | } |
| 88777 | - if( pParse->rc==SQLITE_SCHEMA ){ | |
| 88778 | - sqlite3ResetInternalSchema(db, 0); | |
| 88779 | - } | |
| 88780 | 88743 | if( db->mallocFailed ){ |
| 88781 | 88744 | pParse->rc = SQLITE_NOMEM; |
| 88782 | 88745 | } |
| 88783 | 88746 | if( pzTail ){ |
| 88784 | 88747 | *pzTail = pParse->zTail; |
| @@ -93735,10 +93698,11 @@ | ||
| 93735 | 93698 | return 0; |
| 93736 | 93699 | } |
| 93737 | 93700 | |
| 93738 | 93701 | if( pTmpSchema!=pTab->pSchema ){ |
| 93739 | 93702 | HashElem *p; |
| 93703 | + assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) ); | |
| 93740 | 93704 | for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){ |
| 93741 | 93705 | Trigger *pTrig = (Trigger *)sqliteHashData(p); |
| 93742 | 93706 | if( pTrig->pTabSchema==pTab->pSchema |
| 93743 | 93707 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 93744 | 93708 | ){ |
| @@ -93846,10 +93810,11 @@ | ||
| 93846 | 93810 | ** specified name exists */ |
| 93847 | 93811 | zName = sqlite3NameFromToken(db, pName); |
| 93848 | 93812 | if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 93849 | 93813 | goto trigger_cleanup; |
| 93850 | 93814 | } |
| 93815 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 93851 | 93816 | if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash), |
| 93852 | 93817 | zName, sqlite3Strlen30(zName)) ){ |
| 93853 | 93818 | if( !noErr ){ |
| 93854 | 93819 | sqlite3ErrorMsg(pParse, "trigger %T already exists", pName); |
| 93855 | 93820 | } |
| @@ -93985,10 +93950,11 @@ | ||
| 93985 | 93950 | } |
| 93986 | 93951 | |
| 93987 | 93952 | if( db->init.busy ){ |
| 93988 | 93953 | Trigger *pLink = pTrig; |
| 93989 | 93954 | Hash *pHash = &db->aDb[iDb].pSchema->trigHash; |
| 93955 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 93990 | 93956 | pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig); |
| 93991 | 93957 | if( pTrig ){ |
| 93992 | 93958 | db->mallocFailed = 1; |
| 93993 | 93959 | }else if( pLink->pSchema==pLink->pTabSchema ){ |
| 93994 | 93960 | Table *pTab; |
| @@ -94166,13 +94132,15 @@ | ||
| 94166 | 94132 | |
| 94167 | 94133 | assert( pName->nSrc==1 ); |
| 94168 | 94134 | zDb = pName->a[0].zDatabase; |
| 94169 | 94135 | zName = pName->a[0].zName; |
| 94170 | 94136 | nName = sqlite3Strlen30(zName); |
| 94137 | + assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) ); | |
| 94171 | 94138 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 94172 | 94139 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 94173 | 94140 | if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue; |
| 94141 | + assert( sqlite3SchemaMutexHeld(db, j, 0) ); | |
| 94174 | 94142 | pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName); |
| 94175 | 94143 | if( pTrigger ) break; |
| 94176 | 94144 | } |
| 94177 | 94145 | if( !pTrigger ){ |
| 94178 | 94146 | if( !noErr ){ |
| @@ -94242,11 +94210,11 @@ | ||
| 94242 | 94210 | }; |
| 94243 | 94211 | |
| 94244 | 94212 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 94245 | 94213 | sqlite3OpenMasterTable(pParse, iDb); |
| 94246 | 94214 | base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger); |
| 94247 | - sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, 0); | |
| 94215 | + sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT); | |
| 94248 | 94216 | sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC); |
| 94249 | 94217 | sqlite3ChangeCookie(pParse, iDb); |
| 94250 | 94218 | sqlite3VdbeAddOp2(v, OP_Close, 0, 0); |
| 94251 | 94219 | sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0); |
| 94252 | 94220 | if( pParse->nMem<3 ){ |
| @@ -94257,12 +94225,15 @@ | ||
| 94257 | 94225 | |
| 94258 | 94226 | /* |
| 94259 | 94227 | ** Remove a trigger from the hash tables of the sqlite* pointer. |
| 94260 | 94228 | */ |
| 94261 | 94229 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){ |
| 94262 | - Hash *pHash = &(db->aDb[iDb].pSchema->trigHash); | |
| 94263 | 94230 | Trigger *pTrigger; |
| 94231 | + Hash *pHash; | |
| 94232 | + | |
| 94233 | + assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 94234 | + pHash = &(db->aDb[iDb].pSchema->trigHash); | |
| 94264 | 94235 | pTrigger = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), 0); |
| 94265 | 94236 | if( ALWAYS(pTrigger) ){ |
| 94266 | 94237 | if( pTrigger->pSchema==pTrigger->pTabSchema ){ |
| 94267 | 94238 | Table *pTab = tableOfTrigger(pTrigger); |
| 94268 | 94239 | Trigger **pp; |
| @@ -95782,14 +95753,17 @@ | ||
| 95782 | 95753 | sqlite3BtreeClose(pDb->pBt); |
| 95783 | 95754 | pDb->pBt = 0; |
| 95784 | 95755 | pDb->pSchema = 0; |
| 95785 | 95756 | } |
| 95786 | 95757 | |
| 95787 | - sqlite3ResetInternalSchema(db, 0); | |
| 95758 | + /* This both clears the schemas and reduces the size of the db->aDb[] | |
| 95759 | + ** array. */ | |
| 95760 | + sqlite3ResetInternalSchema(db, -1); | |
| 95788 | 95761 | |
| 95789 | 95762 | return rc; |
| 95790 | 95763 | } |
| 95764 | + | |
| 95791 | 95765 | #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */ |
| 95792 | 95766 | |
| 95793 | 95767 | /************** End of vacuum.c **********************************************/ |
| 95794 | 95768 | /************** Begin file vtab.c ********************************************/ |
| 95795 | 95769 | /* |
| @@ -95839,11 +95813,11 @@ | ||
| 95839 | 95813 | } |
| 95840 | 95814 | sqlite3DbFree(db, pDel); |
| 95841 | 95815 | if( pDel==pMod ){ |
| 95842 | 95816 | db->mallocFailed = 1; |
| 95843 | 95817 | } |
| 95844 | - sqlite3ResetInternalSchema(db, 0); | |
| 95818 | + sqlite3ResetInternalSchema(db, -1); | |
| 95845 | 95819 | }else if( xDestroy ){ |
| 95846 | 95820 | xDestroy(pAux); |
| 95847 | 95821 | } |
| 95848 | 95822 | rc = sqlite3ApiExit(db, SQLITE_OK); |
| 95849 | 95823 | sqlite3_mutex_leave(db->mutex); |
| @@ -95936,14 +95910,13 @@ | ||
| 95936 | 95910 | |
| 95937 | 95911 | /* Assert that the mutex (if any) associated with the BtShared database |
| 95938 | 95912 | ** that contains table p is held by the caller. See header comments |
| 95939 | 95913 | ** above function sqlite3VtabUnlockList() for an explanation of why |
| 95940 | 95914 | ** this makes it safe to access the sqlite3.pDisconnect list of any |
| 95941 | - ** database connection that may have an entry in the p->pVTable list. */ | |
| 95942 | - assert( db==0 || | |
| 95943 | - sqlite3BtreeHoldsMutex(db->aDb[sqlite3SchemaToIndex(db, p->pSchema)].pBt) | |
| 95944 | - ); | |
| 95915 | + ** database connection that may have an entry in the p->pVTable list. | |
| 95916 | + */ | |
| 95917 | + assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) ); | |
| 95945 | 95918 | |
| 95946 | 95919 | while( pVTable ){ |
| 95947 | 95920 | sqlite3 *db2 = pVTable->db; |
| 95948 | 95921 | VTable *pNext = pVTable->pNext; |
| 95949 | 95922 | assert( db2 ); |
| @@ -96178,10 +96151,11 @@ | ||
| 96178 | 96151 | else { |
| 96179 | 96152 | Table *pOld; |
| 96180 | 96153 | Schema *pSchema = pTab->pSchema; |
| 96181 | 96154 | const char *zName = pTab->zName; |
| 96182 | 96155 | int nName = sqlite3Strlen30(zName); |
| 96156 | + assert( sqlite3SchemaMutexHeld(db, 0, pSchema) ); | |
| 96183 | 96157 | pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab); |
| 96184 | 96158 | if( pOld ){ |
| 96185 | 96159 | db->mallocFailed = 1; |
| 96186 | 96160 | assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 96187 | 96161 | return; |
| @@ -97132,11 +97106,11 @@ | ||
| 97132 | 97106 | ** Return the bitmask for the given cursor number. Return 0 if |
| 97133 | 97107 | ** iCursor is not in the set. |
| 97134 | 97108 | */ |
| 97135 | 97109 | static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){ |
| 97136 | 97110 | int i; |
| 97137 | - assert( pMaskSet->n<=sizeof(Bitmask)*8 ); | |
| 97111 | + assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 ); | |
| 97138 | 97112 | for(i=0; i<pMaskSet->n; i++){ |
| 97139 | 97113 | if( pMaskSet->ix[i]==iCursor ){ |
| 97140 | 97114 | return ((Bitmask)1)<<i; |
| 97141 | 97115 | } |
| 97142 | 97116 | } |
| @@ -107007,11 +106981,12 @@ | ||
| 107007 | 106981 | if( !sqlite3SafetyCheckSickOrOk(db) ){ |
| 107008 | 106982 | return SQLITE_MISUSE_BKPT; |
| 107009 | 106983 | } |
| 107010 | 106984 | sqlite3_mutex_enter(db->mutex); |
| 107011 | 106985 | |
| 107012 | - sqlite3ResetInternalSchema(db, 0); | |
| 106986 | + /* Force xDestroy calls on all virtual tables */ | |
| 106987 | + sqlite3ResetInternalSchema(db, -1); | |
| 107013 | 106988 | |
| 107014 | 106989 | /* If a transaction is open, the ResetInternalSchema() call above |
| 107015 | 106990 | ** will not have called the xDisconnect() method on any virtual |
| 107016 | 106991 | ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() |
| 107017 | 106992 | ** call will do so. We need to do this before the check for active |
| @@ -107050,11 +107025,11 @@ | ||
| 107050 | 107025 | if( j!=1 ){ |
| 107051 | 107026 | pDb->pSchema = 0; |
| 107052 | 107027 | } |
| 107053 | 107028 | } |
| 107054 | 107029 | } |
| 107055 | - sqlite3ResetInternalSchema(db, 0); | |
| 107030 | + sqlite3ResetInternalSchema(db, -1); | |
| 107056 | 107031 | |
| 107057 | 107032 | /* Tell the code in notify.c that the connection no longer holds any |
| 107058 | 107033 | ** locks and does not require any further unlock-notify callbacks. |
| 107059 | 107034 | */ |
| 107060 | 107035 | sqlite3ConnectionClosed(db); |
| @@ -107141,11 +107116,11 @@ | ||
| 107141 | 107116 | sqlite3VtabRollback(db); |
| 107142 | 107117 | sqlite3EndBenignMalloc(); |
| 107143 | 107118 | |
| 107144 | 107119 | if( db->flags&SQLITE_InternChanges ){ |
| 107145 | 107120 | sqlite3ExpirePreparedStatements(db); |
| 107146 | - sqlite3ResetInternalSchema(db, 0); | |
| 107121 | + sqlite3ResetInternalSchema(db, -1); | |
| 107147 | 107122 | } |
| 107148 | 107123 | |
| 107149 | 107124 | /* Any deferred constraint violations have now been resolved. */ |
| 107150 | 107125 | db->nDeferredCons = 0; |
| 107151 | 107126 | |
| @@ -107210,11 +107185,11 @@ | ||
| 107210 | 107185 | #if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP) |
| 107211 | 107186 | static const u8 delays[] = |
| 107212 | 107187 | { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 }; |
| 107213 | 107188 | static const u8 totals[] = |
| 107214 | 107189 | { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 }; |
| 107215 | -# define NDELAY (sizeof(delays)/sizeof(delays[0])) | |
| 107190 | +# define NDELAY ArraySize(delays) | |
| 107216 | 107191 | sqlite3 *db = (sqlite3 *)ptr; |
| 107217 | 107192 | int timeout = db->busyTimeout; |
| 107218 | 107193 | int delay, prior; |
| 107219 | 107194 | |
| 107220 | 107195 | assert( count>=0 ); |
| @@ -113734,10 +113709,12 @@ | ||
| 113734 | 113709 | int nDb; /* Result of strlen(zDb) */ |
| 113735 | 113710 | int nFts3; /* Result of strlen(zFts3) */ |
| 113736 | 113711 | int nByte; /* Bytes of space to allocate here */ |
| 113737 | 113712 | int rc; /* value returned by declare_vtab() */ |
| 113738 | 113713 | Fts3auxTable *p; /* Virtual table object to return */ |
| 113714 | + | |
| 113715 | + UNUSED_PARAMETER(pUnused); | |
| 113739 | 113716 | |
| 113740 | 113717 | /* The user should specify a single argument - the name of an fts3 table. */ |
| 113741 | 113718 | if( argc!=4 ){ |
| 113742 | 113719 | *pzErr = sqlite3_mprintf( |
| 113743 | 113720 | "wrong number of arguments to fts4aux constructor" |
| @@ -113803,10 +113780,12 @@ | ||
| 113803 | 113780 | ){ |
| 113804 | 113781 | int i; |
| 113805 | 113782 | int iEq = -1; |
| 113806 | 113783 | int iGe = -1; |
| 113807 | 113784 | int iLe = -1; |
| 113785 | + | |
| 113786 | + UNUSED_PARAMETER(pVTab); | |
| 113808 | 113787 | |
| 113809 | 113788 | /* This vtab delivers always results in "ORDER BY term ASC" order. */ |
| 113810 | 113789 | if( pInfo->nOrderBy==1 |
| 113811 | 113790 | && pInfo->aOrderBy[0].iColumn==0 |
| 113812 | 113791 | && pInfo->aOrderBy[0].desc==0 |
| @@ -113851,10 +113830,12 @@ | ||
| 113851 | 113830 | /* |
| 113852 | 113831 | ** xOpen - Open a cursor. |
| 113853 | 113832 | */ |
| 113854 | 113833 | static int fts3auxOpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){ |
| 113855 | 113834 | Fts3auxCursor *pCsr; /* Pointer to cursor object to return */ |
| 113835 | + | |
| 113836 | + UNUSED_PARAMETER(pVTab); | |
| 113856 | 113837 | |
| 113857 | 113838 | pCsr = (Fts3auxCursor *)sqlite3_malloc(sizeof(Fts3auxCursor)); |
| 113858 | 113839 | if( !pCsr ) return SQLITE_NOMEM; |
| 113859 | 113840 | memset(pCsr, 0, sizeof(Fts3auxCursor)); |
| 113860 | 113841 | |
| @@ -114000,10 +113981,12 @@ | ||
| 114000 | 113981 | ){ |
| 114001 | 113982 | Fts3auxCursor *pCsr = (Fts3auxCursor *)pCursor; |
| 114002 | 113983 | Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab; |
| 114003 | 113984 | int rc; |
| 114004 | 113985 | int isScan; |
| 113986 | + | |
| 113987 | + UNUSED_PARAMETER(nVal); | |
| 114005 | 113988 | |
| 114006 | 113989 | assert( idxStr==0 ); |
| 114007 | 113990 | assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0 |
| 114008 | 113991 | || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT |
| 114009 | 113992 | || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT) |
| @@ -122428,11 +122411,11 @@ | ||
| 122428 | 122411 | pCsr->nConstraint = argc; |
| 122429 | 122412 | if( !pCsr->aConstraint ){ |
| 122430 | 122413 | rc = SQLITE_NOMEM; |
| 122431 | 122414 | }else{ |
| 122432 | 122415 | memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc); |
| 122433 | - assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 ); | |
| 122416 | + assert( (idxStr==0 && argc==0) || (int)strlen(idxStr)==argc*2 ); | |
| 122434 | 122417 | for(ii=0; ii<argc; ii++){ |
| 122435 | 122418 | RtreeConstraint *p = &pCsr->aConstraint[ii]; |
| 122436 | 122419 | p->op = idxStr[ii*2]; |
| 122437 | 122420 | p->iCoord = idxStr[ii*2+1]-'a'; |
| 122438 | 122421 | if( p->op==RTREE_MATCH ){ |
| @@ -122521,11 +122504,11 @@ | ||
| 122521 | 122504 | char zIdxStr[RTREE_MAX_DIMENSIONS*8+1]; |
| 122522 | 122505 | memset(zIdxStr, 0, sizeof(zIdxStr)); |
| 122523 | 122506 | UNUSED_PARAMETER(tab); |
| 122524 | 122507 | |
| 122525 | 122508 | assert( pIdxInfo->idxStr==0 ); |
| 122526 | - for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(sizeof(zIdxStr)-1); ii++){ | |
| 122509 | + for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){ | |
| 122527 | 122510 | struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii]; |
| 122528 | 122511 | |
| 122529 | 122512 | if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ |
| 122530 | 122513 | /* We have an equality constraint on the rowid. Use strategy 1. */ |
| 122531 | 122514 | int jj; |
| @@ -124644,10 +124627,12 @@ | ||
| 124644 | 124627 | static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 124645 | 124628 | UErrorCode status = U_ZERO_ERROR; |
| 124646 | 124629 | URegularExpression *pExpr; |
| 124647 | 124630 | UBool res; |
| 124648 | 124631 | const UChar *zString = sqlite3_value_text16(apArg[1]); |
| 124632 | + | |
| 124633 | + (void)nArg; /* Unused parameter */ | |
| 124649 | 124634 | |
| 124650 | 124635 | /* If the left hand side of the regexp operator is NULL, |
| 124651 | 124636 | ** then the result is also NULL. |
| 124652 | 124637 | */ |
| 124653 | 124638 | if( !zString ){ |
| @@ -124873,11 +124858,11 @@ | ||
| 124873 | 124858 | }; |
| 124874 | 124859 | |
| 124875 | 124860 | int rc = SQLITE_OK; |
| 124876 | 124861 | int i; |
| 124877 | 124862 | |
| 124878 | - for(i=0; rc==SQLITE_OK && i<(sizeof(scalars)/sizeof(struct IcuScalar)); i++){ | |
| 124863 | + for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){ | |
| 124879 | 124864 | struct IcuScalar *p = &scalars[i]; |
| 124880 | 124865 | rc = sqlite3_create_function( |
| 124881 | 124866 | db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0 |
| 124882 | 124867 | ); |
| 124883 | 124868 | } |
| 124884 | 124869 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -650,11 +650,11 @@ | |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | #define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -1675,11 +1675,11 @@ | |
| 1675 | ** changes to a [database connection]. The interface is similar to |
| 1676 | ** [sqlite3_config()] except that the changes apply to a single |
| 1677 | ** [database connection] (specified in the first argument). |
| 1678 | ** |
| 1679 | ** The second argument to sqlite3_db_config(D,V,...) is the |
| 1680 | ** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code |
| 1681 | ** that indicates what aspect of the [database connection] is being configured. |
| 1682 | ** Subsequent arguments vary depending on the configuration verb. |
| 1683 | ** |
| 1684 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1685 | ** the call is considered successful. |
| @@ -7833,22 +7833,22 @@ | |
| 7833 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); |
| 7834 | #ifndef NDEBUG |
| 7835 | /* These routines are used inside assert() statements only. */ |
| 7836 | SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); |
| 7837 | SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); |
| 7838 | SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree*); |
| 7839 | #endif |
| 7840 | #else |
| 7841 | |
| 7842 | # define sqlite3BtreeLeave(X) |
| 7843 | # define sqlite3BtreeMutexCounter(X) 0 |
| 7844 | # define sqlite3BtreeEnterCursor(X) |
| 7845 | # define sqlite3BtreeLeaveCursor(X) |
| 7846 | # define sqlite3BtreeLeaveAll(X) |
| 7847 | |
| 7848 | # define sqlite3BtreeHoldsMutex(X) 1 |
| 7849 | # define sqlite3BtreeHoldsAllMutexes(X) 1 |
| 7850 | #endif |
| 7851 | |
| 7852 | |
| 7853 | #endif /* _BTREE_H_ */ |
| 7854 | |
| @@ -7963,11 +7963,11 @@ | |
| 7963 | #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ |
| 7964 | #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ |
| 7965 | #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */ |
| 7966 | #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */ |
| 7967 | #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ |
| 7968 | #define P4_TRANSIENT (-9) /* P4 is a pointer to a transient string */ |
| 7969 | #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 7970 | #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ |
| 7971 | #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| 7972 | #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ |
| 7973 | #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ |
| @@ -8998,10 +8998,24 @@ | |
| 8998 | Schema *pSchema; /* Pointer to database schema (possibly shared) */ |
| 8999 | }; |
| 9000 | |
| 9001 | /* |
| 9002 | ** An instance of the following structure stores a database schema. |
| 9003 | */ |
| 9004 | struct Schema { |
| 9005 | int schema_cookie; /* Database schema version number for this file */ |
| 9006 | int iGeneration; /* Generation counter. Incremented with each change */ |
| 9007 | Hash tblHash; /* All tables indexed by name */ |
| @@ -9514,11 +9528,11 @@ | |
| 9514 | ** implementation. sqlite3_vtab* handles can not be shared between |
| 9515 | ** database connections, even when the rest of the in-memory database |
| 9516 | ** schema is shared, as the implementation often stores the database |
| 9517 | ** connection handle passed to it via the xConnect() or xCreate() method |
| 9518 | ** during initialization internally. This database connection handle may |
| 9519 | ** then used by the virtual table implementation to access real tables |
| 9520 | ** within the database. So that they appear as part of the callers |
| 9521 | ** transaction, these accesses need to be made via the same database |
| 9522 | ** connection as that used to execute SQL operations on the virtual table. |
| 9523 | ** |
| 9524 | ** All VTable objects that correspond to a single table in a shared |
| @@ -11272,11 +11286,11 @@ | |
| 11272 | SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions; |
| 11273 | #ifndef SQLITE_OMIT_WSD |
| 11274 | SQLITE_PRIVATE int sqlite3PendingByte; |
| 11275 | #endif |
| 11276 | #endif |
| 11277 | SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int); |
| 11278 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 11279 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 11280 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 11281 | SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *); |
| 11282 | SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| @@ -11299,11 +11313,11 @@ | |
| 11299 | SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*); |
| 11300 | SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*); |
| 11301 | SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int); |
| 11302 | SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); |
| 11303 | SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int); |
| 11304 | SQLITE_PRIVATE void sqlite3SchemaFree(void *); |
| 11305 | SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *); |
| 11306 | SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *); |
| 11307 | SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *); |
| 11308 | SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, |
| 11309 | void (*)(sqlite3_context*,int,sqlite3_value **), |
| @@ -12479,11 +12493,10 @@ | |
| 12479 | u8 usesStmtJournal; /* True if uses a statement journal */ |
| 12480 | u8 readOnly; /* True for read-only statements */ |
| 12481 | u8 isPrepareV2; /* True if prepared with prepare_v2() */ |
| 12482 | int nChange; /* Number of db changes made since last reset */ |
| 12483 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 12484 | u32 iMutexCounter; /* Mutex counter upon sqlite3VdbeEnter() */ |
| 12485 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 12486 | int aCounter[3]; /* Counters used by sqlite3_stmt_status() */ |
| 12487 | #ifndef SQLITE_OMIT_TRACE |
| 12488 | i64 startTime; /* Time when query started - used for profiling */ |
| 12489 | #endif |
| @@ -12563,13 +12576,18 @@ | |
| 12563 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 12564 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 12565 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 12566 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 12567 | SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem); |
| 12568 | SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*); |
| 12569 | SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); |
| 12570 | SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe*); |
| 12571 | |
| 12572 | #ifdef SQLITE_DEBUG |
| 12573 | SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); |
| 12574 | #endif |
| 12575 | |
| @@ -12742,10 +12760,11 @@ | |
| 12742 | */ |
| 12743 | case SQLITE_DBSTATUS_SCHEMA_USED: { |
| 12744 | int i; /* Used to iterate through schemas */ |
| 12745 | int nByte = 0; /* Used to accumulate return value */ |
| 12746 | |
| 12747 | db->pnBytesFreed = &nByte; |
| 12748 | for(i=0; i<db->nDb; i++){ |
| 12749 | Schema *pSchema = db->aDb[i].pSchema; |
| 12750 | if( ALWAYS(pSchema!=0) ){ |
| 12751 | HashElem *p; |
| @@ -12768,10 +12787,11 @@ | |
| 12768 | sqlite3DeleteTable(db, (Table *)sqliteHashData(p)); |
| 12769 | } |
| 12770 | } |
| 12771 | } |
| 12772 | db->pnBytesFreed = 0; |
| 12773 | |
| 12774 | *pHighwater = 0; |
| 12775 | *pCurrent = nByte; |
| 12776 | break; |
| 12777 | } |
| @@ -15879,11 +15899,11 @@ | |
| 15879 | ** Space for tracking which blocks are checked out and the size |
| 15880 | ** of each block. One byte per block. |
| 15881 | */ |
| 15882 | u8 *aCtrl; |
| 15883 | |
| 15884 | } mem5 = { 0 }; |
| 15885 | |
| 15886 | /* |
| 15887 | ** Access the static variable through a macro for SQLITE_OMIT_WSD |
| 15888 | */ |
| 15889 | #define mem5 GLOBAL(struct Mem5Global, mem5) |
| @@ -16194,11 +16214,11 @@ | |
| 16194 | ** memsys5Log(8) -> 3 |
| 16195 | ** memsys5Log(9) -> 4 |
| 16196 | */ |
| 16197 | static int memsys5Log(int iValue){ |
| 16198 | int iLog; |
| 16199 | for(iLog=0; (iLog<((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++); |
| 16200 | return iLog; |
| 16201 | } |
| 16202 | |
| 16203 | /* |
| 16204 | ** Initialize the memory allocator. |
| @@ -18064,11 +18084,11 @@ | |
| 18064 | pSlot = (ScratchFreeslot*)p; |
| 18065 | sqlite3_mutex_enter(mem0.mutex); |
| 18066 | pSlot->pNext = mem0.pScratchFree; |
| 18067 | mem0.pScratchFree = pSlot; |
| 18068 | mem0.nScratchFree++; |
| 18069 | assert( mem0.nScratchFree<=sqlite3GlobalConfig.nScratch ); |
| 18070 | sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1); |
| 18071 | sqlite3_mutex_leave(mem0.mutex); |
| 18072 | }else{ |
| 18073 | /* Release memory back to the heap */ |
| 18074 | assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) ); |
| @@ -38547,10 +38567,23 @@ | |
| 38547 | /* Verify that the page list is in accending order */ |
| 38548 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 38549 | assert( p->pgno < p->pDirty->pgno ); |
| 38550 | } |
| 38551 | #endif |
| 38552 | |
| 38553 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 38554 | rc = sqlite3WalFrames(pPager->pWal, |
| 38555 | pPager->pageSize, pList, nTruncate, isCommit, syncFlags |
| 38556 | ); |
| @@ -38560,10 +38593,11 @@ | |
| 38560 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 38561 | } |
| 38562 | } |
| 38563 | |
| 38564 | #ifdef SQLITE_CHECK_PAGES |
| 38565 | for(p=pList; p; p=p->pDirty){ |
| 38566 | pager_set_pagehash(p); |
| 38567 | } |
| 38568 | #endif |
| 38569 | |
| @@ -45510,11 +45544,11 @@ | |
| 45510 | |
| 45511 | |
| 45512 | /* The following value is the maximum cell size assuming a maximum page |
| 45513 | ** size give above. |
| 45514 | */ |
| 45515 | #define MX_CELL_SIZE(pBt) (pBt->pageSize-8) |
| 45516 | |
| 45517 | /* The maximum number of cells on a single page of the database. This |
| 45518 | ** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself |
| 45519 | ** plus 2 bytes for the index to the cell in the page header). Such |
| 45520 | ** small cells will be rare, but they are possible. |
| @@ -45727,11 +45761,10 @@ | |
| 45727 | BtShared *pNext; /* Next on a list of sharable BtShared structs */ |
| 45728 | BtLock *pLock; /* List of locks held on this shared-btree struct */ |
| 45729 | Btree *pWriter; /* Btree with currently open write transaction */ |
| 45730 | u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */ |
| 45731 | u8 isPending; /* If waiting for read-locks to clear */ |
| 45732 | u16 iMutexCounter; /* The number of mutex_leave(mutex) calls */ |
| 45733 | #endif |
| 45734 | u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */ |
| 45735 | }; |
| 45736 | |
| 45737 | /* |
| @@ -45966,32 +45999,14 @@ | |
| 45966 | assert( p->locked==1 ); |
| 45967 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 45968 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 45969 | assert( p->db==pBt->db ); |
| 45970 | |
| 45971 | pBt->iMutexCounter++; |
| 45972 | sqlite3_mutex_leave(pBt->mutex); |
| 45973 | p->locked = 0; |
| 45974 | } |
| 45975 | |
| 45976 | #ifdef SQLITE_DEBUG |
| 45977 | /* |
| 45978 | ** Return the number of times that the mutex has been exited for |
| 45979 | ** the given btree. |
| 45980 | ** |
| 45981 | ** This is a small circular counter that wraps around to zero on |
| 45982 | ** overflow. It is used only for sanity checking - to verify that |
| 45983 | ** mutexes are held continously by asserting that the value of |
| 45984 | ** this counter at the beginning of a region is the same as at |
| 45985 | ** the end. |
| 45986 | */ |
| 45987 | SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree *p){ |
| 45988 | assert( p->locked==1 || p->sharable==0 ); |
| 45989 | return p->pBt->iMutexCounter; |
| 45990 | } |
| 45991 | #endif |
| 45992 | |
| 45993 | /* |
| 45994 | ** Enter a mutex on the given BTree object. |
| 45995 | ** |
| 45996 | ** If the object is not sharable, then no mutex is ever required |
| 45997 | ** and this routine is a no-op. The underlying mutex is non-recursive. |
| @@ -46032,28 +46047,10 @@ | |
| 46032 | |
| 46033 | if( !p->sharable ) return; |
| 46034 | p->wantToLock++; |
| 46035 | if( p->locked ) return; |
| 46036 | |
| 46037 | /* Increment the mutex counter on all locked btrees in the same |
| 46038 | ** database connection. This simulates the unlocking that would |
| 46039 | ** occur on a worst-case mutex dead-lock avoidance scenario. |
| 46040 | */ |
| 46041 | #ifdef SQLITE_DEBUG |
| 46042 | { |
| 46043 | int ii; |
| 46044 | sqlite3 *db = p->db; |
| 46045 | Btree *pOther; |
| 46046 | for(ii=0; ii<db->nDb; ii++){ |
| 46047 | if( ii==1 ) continue; |
| 46048 | pOther = db->aDb[ii].pBt; |
| 46049 | if( pOther==0 || pOther->sharable==0 || pOther->locked==0 ) continue; |
| 46050 | pOther->pBt->iMutexCounter++; |
| 46051 | } |
| 46052 | } |
| 46053 | #endif |
| 46054 | |
| 46055 | /* In most cases, we should be able to acquire the lock we |
| 46056 | ** want without having to go throught the ascending lock |
| 46057 | ** procedure that follows. Just be sure not to block. |
| 46058 | */ |
| 46059 | if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){ |
| @@ -46143,49 +46140,24 @@ | |
| 46143 | ** two or more btrees in common both try to lock all their btrees |
| 46144 | ** at the same instant. |
| 46145 | */ |
| 46146 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 46147 | int i; |
| 46148 | Btree *p, *pLater; |
| 46149 | assert( sqlite3_mutex_held(db->mutex) ); |
| 46150 | for(i=0; i<db->nDb; i++){ |
| 46151 | p = db->aDb[i].pBt; |
| 46152 | assert( !p || (p->locked==0 && p->sharable) || p->pBt->db==p->db ); |
| 46153 | if( p && p->sharable ){ |
| 46154 | p->wantToLock++; |
| 46155 | if( !p->locked ){ |
| 46156 | assert( p->wantToLock==1 ); |
| 46157 | while( p->pPrev ) p = p->pPrev; |
| 46158 | /* Reason for ALWAYS: There must be at least one unlocked Btree in |
| 46159 | ** the chain. Otherwise the !p->locked test above would have failed */ |
| 46160 | while( p->locked && ALWAYS(p->pNext) ) p = p->pNext; |
| 46161 | for(pLater = p->pNext; pLater; pLater=pLater->pNext){ |
| 46162 | if( pLater->locked ){ |
| 46163 | unlockBtreeMutex(pLater); |
| 46164 | } |
| 46165 | } |
| 46166 | while( p ){ |
| 46167 | lockBtreeMutex(p); |
| 46168 | p = p->pNext; |
| 46169 | } |
| 46170 | } |
| 46171 | } |
| 46172 | } |
| 46173 | } |
| 46174 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){ |
| 46175 | int i; |
| 46176 | Btree *p; |
| 46177 | assert( sqlite3_mutex_held(db->mutex) ); |
| 46178 | for(i=0; i<db->nDb; i++){ |
| 46179 | p = db->aDb[i].pBt; |
| 46180 | if( p && p->sharable ){ |
| 46181 | assert( p->wantToLock>0 ); |
| 46182 | p->wantToLock--; |
| 46183 | if( p->wantToLock==0 ){ |
| 46184 | unlockBtreeMutex(p); |
| 46185 | } |
| 46186 | } |
| 46187 | } |
| 46188 | } |
| 46189 | |
| 46190 | #ifndef NDEBUG |
| 46191 | /* |
| @@ -46209,10 +46181,35 @@ | |
| 46209 | } |
| 46210 | return 1; |
| 46211 | } |
| 46212 | #endif /* NDEBUG */ |
| 46213 | |
| 46214 | #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */ |
| 46215 | /* |
| 46216 | ** The following are special cases for mutex enter routines for use |
| 46217 | ** in single threaded applications that use shared cache. Except for |
| 46218 | ** these two routines, all mutex operations are no-ops in that case and |
| @@ -47466,11 +47463,11 @@ | |
| 47466 | ** is no way that the allocation can extend off the end of the page. |
| 47467 | ** The assert() below verifies the previous sentence. |
| 47468 | */ |
| 47469 | top -= nByte; |
| 47470 | put2byte(&data[hdr+5], top); |
| 47471 | assert( top+nByte <= pPage->pBt->usableSize ); |
| 47472 | *pIdx = top; |
| 47473 | return SQLITE_OK; |
| 47474 | } |
| 47475 | |
| 47476 | /* |
| @@ -47487,11 +47484,11 @@ | |
| 47487 | unsigned char *data = pPage->aData; |
| 47488 | |
| 47489 | assert( pPage->pBt!=0 ); |
| 47490 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 47491 | assert( start>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 47492 | assert( (start + size)<=pPage->pBt->usableSize ); |
| 47493 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 47494 | assert( size>=0 ); /* Minimum cell size is 4 */ |
| 47495 | |
| 47496 | if( pPage->pBt->secureDelete ){ |
| 47497 | /* Overwrite deleted information with zeros when the secure_delete |
| @@ -47530,11 +47527,11 @@ | |
| 47530 | /* Coalesce adjacent free blocks */ |
| 47531 | addr = hdr + 1; |
| 47532 | while( (pbegin = get2byte(&data[addr]))>0 ){ |
| 47533 | int pnext, psize, x; |
| 47534 | assert( pbegin>addr ); |
| 47535 | assert( pbegin<=pPage->pBt->usableSize-4 ); |
| 47536 | pnext = get2byte(&data[pbegin]); |
| 47537 | psize = get2byte(&data[pbegin+2]); |
| 47538 | if( pbegin + psize + 3 >= pnext && pnext>0 ){ |
| 47539 | int frag = pnext - (pbegin+psize); |
| 47540 | if( (frag<0) || (frag>(int)data[hdr+7]) ){ |
| @@ -51737,11 +51734,11 @@ | |
| 51737 | rc = allocateSpace(pPage, sz, &idx); |
| 51738 | if( rc ){ *pRC = rc; return; } |
| 51739 | /* The allocateSpace() routine guarantees the following two properties |
| 51740 | ** if it returns success */ |
| 51741 | assert( idx >= end+2 ); |
| 51742 | assert( idx+sz <= pPage->pBt->usableSize ); |
| 51743 | pPage->nCell++; |
| 51744 | pPage->nFree -= (u16)(2 + sz); |
| 51745 | memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip); |
| 51746 | if( iChild ){ |
| 51747 | put4byte(&data[idx], iChild); |
| @@ -51780,11 +51777,12 @@ | |
| 51780 | const int hdr = pPage->hdrOffset; /* Offset of header on pPage */ |
| 51781 | const int nUsable = pPage->pBt->usableSize; /* Usable size of page */ |
| 51782 | |
| 51783 | assert( pPage->nOverflow==0 ); |
| 51784 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 51785 | assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921); |
| 51786 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 51787 | |
| 51788 | /* Check that the page has just been zeroed by zeroPage() */ |
| 51789 | assert( pPage->nCell==0 ); |
| 51790 | assert( get2byteNotZero(&data[hdr+5])==nUsable ); |
| @@ -51994,11 +51992,11 @@ | |
| 51994 | int iData; |
| 51995 | |
| 51996 | |
| 51997 | assert( pFrom->isInit ); |
| 51998 | assert( pFrom->nFree>=iToHdr ); |
| 51999 | assert( get2byte(&aFrom[iFromHdr+5])<=pBt->usableSize ); |
| 52000 | |
| 52001 | /* Copy the b-tree node content from page pFrom to page pTo. */ |
| 52002 | iData = get2byte(&aFrom[iFromHdr+5]); |
| 52003 | memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData); |
| 52004 | memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell); |
| @@ -52261,11 +52259,11 @@ | |
| 52261 | assert( nCell<nMaxCells ); |
| 52262 | szCell[nCell] = sz; |
| 52263 | pTemp = &aSpace1[iSpace1]; |
| 52264 | iSpace1 += sz; |
| 52265 | assert( sz<=pBt->maxLocal+23 ); |
| 52266 | assert( iSpace1<=pBt->pageSize ); |
| 52267 | memcpy(pTemp, apDiv[i], sz); |
| 52268 | apCell[nCell] = pTemp+leafCorrection; |
| 52269 | assert( leafCorrection==0 || leafCorrection==4 ); |
| 52270 | szCell[nCell] = szCell[nCell] - leafCorrection; |
| 52271 | if( !pOld->leaf ){ |
| @@ -52505,11 +52503,11 @@ | |
| 52505 | sz = cellSizePtr(pParent, pCell); |
| 52506 | } |
| 52507 | } |
| 52508 | iOvflSpace += sz; |
| 52509 | assert( sz<=pBt->maxLocal+23 ); |
| 52510 | assert( iOvflSpace<=pBt->pageSize ); |
| 52511 | insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc); |
| 52512 | if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 52513 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 52514 | |
| 52515 | j++; |
| @@ -52950,11 +52948,11 @@ | |
| 52950 | newCell = pBt->pTmpSpace; |
| 52951 | if( newCell==0 ) return SQLITE_NOMEM; |
| 52952 | rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew); |
| 52953 | if( rc ) goto end_insert; |
| 52954 | assert( szNew==cellSizePtr(pPage, newCell) ); |
| 52955 | assert( szNew<=MX_CELL_SIZE(pBt) ); |
| 52956 | idx = pCur->aiIdx[pCur->iPage]; |
| 52957 | if( loc==0 ){ |
| 52958 | u16 szOld; |
| 52959 | assert( idx<pPage->nCell ); |
| 52960 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| @@ -53090,11 +53088,11 @@ | |
| 53090 | Pgno n = pCur->apPage[iCellDepth+1]->pgno; |
| 53091 | unsigned char *pTmp; |
| 53092 | |
| 53093 | pCell = findCell(pLeaf, pLeaf->nCell-1); |
| 53094 | nCell = cellSizePtr(pLeaf, pCell); |
| 53095 | assert( MX_CELL_SIZE(pBt)>=nCell ); |
| 53096 | |
| 53097 | allocateTempSpace(pBt); |
| 53098 | pTmp = pBt->pTmpSpace; |
| 53099 | |
| 53100 | rc = sqlite3PagerWrite(pLeaf->pDbPage); |
| @@ -54784,11 +54782,11 @@ | |
| 54784 | && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK |
| 54785 | ){ |
| 54786 | int nDestTruncate; |
| 54787 | |
| 54788 | if( p->pDestDb ){ |
| 54789 | sqlite3ResetInternalSchema(p->pDestDb, 0); |
| 54790 | } |
| 54791 | |
| 54792 | /* Set nDestTruncate to the final number of pages in the destination |
| 54793 | ** database. The complication here is that the destination page |
| 54794 | ** size may be different to the source page size. |
| @@ -57181,40 +57179,16 @@ | |
| 57181 | ** The prepared statements need to know in advance the complete set of |
| 57182 | ** attached databases that they will be using. A mask of these databases |
| 57183 | ** is maintained in p->btreeMask and is used for locking and other purposes. |
| 57184 | */ |
| 57185 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){ |
| 57186 | assert( i>=0 && i<p->db->nDb && i<sizeof(yDbMask)*8 ); |
| 57187 | assert( i<(int)sizeof(p->btreeMask)*8 ); |
| 57188 | p->btreeMask |= ((yDbMask)1)<<i; |
| 57189 | } |
| 57190 | |
| 57191 | /* |
| 57192 | ** Compute the sum of all mutex counters for all btrees in the |
| 57193 | ** given prepared statement. |
| 57194 | */ |
| 57195 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 57196 | static u32 mutexCounterSum(Vdbe *p){ |
| 57197 | u32 cntSum = 0; |
| 57198 | #ifdef SQLITE_DEBUG |
| 57199 | int i; |
| 57200 | yDbMask mask; |
| 57201 | sqlite3 *db = p->db; |
| 57202 | Db *aDb = db->aDb; |
| 57203 | int nDb = db->nDb; |
| 57204 | for(i=0, mask=1; i<nDb; i++, mask += mask){ |
| 57205 | if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ |
| 57206 | cntSum += sqlite3BtreeMutexCounter(aDb[i].pBt); |
| 57207 | } |
| 57208 | } |
| 57209 | #else |
| 57210 | UNUSED_PARAMETER(p); |
| 57211 | #endif |
| 57212 | return cntSum; |
| 57213 | } |
| 57214 | #endif |
| 57215 | |
| 57216 | /* |
| 57217 | ** If SQLite is compiled to support shared-cache mode and to be threadsafe, |
| 57218 | ** this routine obtains the mutex associated with each BtShared structure |
| 57219 | ** that may be accessed by the VM passed as an argument. In doing so it also |
| 57220 | ** sets the BtShared.db member of each of the BtShared structures, ensuring |
| @@ -57233,11 +57207,10 @@ | |
| 57233 | ** corresponding to btrees that use shared cache. Then the runtime of |
| 57234 | ** this routine is N*N. But as N is rarely more than 1, this should not |
| 57235 | ** be a problem. |
| 57236 | */ |
| 57237 | SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){ |
| 57238 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 57239 | int i; |
| 57240 | yDbMask mask; |
| 57241 | sqlite3 *db = p->db; |
| 57242 | Db *aDb = db->aDb; |
| 57243 | int nDb = db->nDb; |
| @@ -57244,67 +57217,31 @@ | |
| 57244 | for(i=0, mask=1; i<nDb; i++, mask += mask){ |
| 57245 | if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ |
| 57246 | sqlite3BtreeEnter(aDb[i].pBt); |
| 57247 | } |
| 57248 | } |
| 57249 | p->iMutexCounter = mutexCounterSum(p); |
| 57250 | #else |
| 57251 | UNUSED_PARAMETER(p); |
| 57252 | #endif |
| 57253 | } |
| 57254 | |
| 57255 | /* |
| 57256 | ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter(). |
| 57257 | */ |
| 57258 | SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){ |
| 57259 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 57260 | int i; |
| 57261 | yDbMask mask; |
| 57262 | sqlite3 *db = p->db; |
| 57263 | Db *aDb = db->aDb; |
| 57264 | int nDb = db->nDb; |
| 57265 | |
| 57266 | /* Assert that the all mutexes have been held continously since |
| 57267 | ** the most recent sqlite3VdbeEnter() or sqlite3VdbeMutexResync(). |
| 57268 | */ |
| 57269 | assert( mutexCounterSum(p) == p->iMutexCounter ); |
| 57270 | |
| 57271 | for(i=0, mask=1; i<nDb; i++, mask += mask){ |
| 57272 | if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ |
| 57273 | sqlite3BtreeLeave(aDb[i].pBt); |
| 57274 | } |
| 57275 | } |
| 57276 | #else |
| 57277 | UNUSED_PARAMETER(p); |
| 57278 | #endif |
| 57279 | } |
| 57280 | |
| 57281 | /* |
| 57282 | ** Recompute the sum of the mutex counters on all btrees used by the |
| 57283 | ** prepared statement p. |
| 57284 | ** |
| 57285 | ** Call this routine while holding a sqlite3VdbeEnter() after doing something |
| 57286 | ** that might cause one or more of the individual mutexes held by the |
| 57287 | ** prepared statement to be released. Calling sqlite3BtreeEnter() on |
| 57288 | ** any BtShared mutex which is not used by the prepared statement is one |
| 57289 | ** way to cause one or more of the mutexes in the prepared statement |
| 57290 | ** to be temporarily released. The anti-deadlocking logic in |
| 57291 | ** sqlite3BtreeEnter() can cause mutexes to be released temporarily then |
| 57292 | ** reacquired. |
| 57293 | ** |
| 57294 | ** Calling this routine is an acknowledgement that some of the individual |
| 57295 | ** mutexes in the prepared statement might have been released and reacquired. |
| 57296 | ** So checks to verify that mutex-protected content did not change |
| 57297 | ** unexpectedly should accompany any call to this routine. |
| 57298 | */ |
| 57299 | SQLITE_PRIVATE void sqlite3VdbeMutexResync(Vdbe *p){ |
| 57300 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && defined(SQLITE_DEBUG) |
| 57301 | p->iMutexCounter = mutexCounterSum(p); |
| 57302 | #else |
| 57303 | UNUSED_PARAMETER(p); |
| 57304 | #endif |
| 57305 | } |
| 57306 | |
| 57307 | #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) |
| 57308 | /* |
| 57309 | ** Print a single opcode. This routine is used for debugging only. |
| 57310 | */ |
| @@ -58504,16 +58441,15 @@ | |
| 58504 | p->nChange = 0; |
| 58505 | } |
| 58506 | |
| 58507 | /* Rollback or commit any schema changes that occurred. */ |
| 58508 | if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){ |
| 58509 | sqlite3ResetInternalSchema(db, 0); |
| 58510 | db->flags = (db->flags | SQLITE_InternChanges); |
| 58511 | } |
| 58512 | |
| 58513 | /* Release the locks */ |
| 58514 | sqlite3VdbeMutexResync(p); |
| 58515 | sqlite3VdbeLeave(p); |
| 58516 | } |
| 58517 | |
| 58518 | /* We have successfully halted and closed the VM. Record this fact. */ |
| 58519 | if( p->pc>=0 ){ |
| @@ -60190,11 +60126,15 @@ | |
| 60190 | ** __attribute__((aligned(8))) macro. */ |
| 60191 | static const Mem nullMem |
| 60192 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 60193 | __attribute__((aligned(8))) |
| 60194 | #endif |
| 60195 | = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 }; |
| 60196 | |
| 60197 | if( pVm && ALWAYS(pVm->db) ){ |
| 60198 | sqlite3_mutex_enter(pVm->db->mutex); |
| 60199 | sqlite3Error(pVm->db, SQLITE_RANGE, 0); |
| 60200 | } |
| @@ -61604,11 +61544,11 @@ | |
| 61604 | int pc=0; /* The program counter */ |
| 61605 | Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 61606 | Op *pOp; /* Current operation */ |
| 61607 | int rc = SQLITE_OK; /* Value to return */ |
| 61608 | sqlite3 *db = p->db; /* The database */ |
| 61609 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if true */ |
| 61610 | u8 encoding = ENC(db); /* The database encoding */ |
| 61611 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 61612 | int checkProgress; /* True if progress callbacks are enabled */ |
| 61613 | int nProgressOps = 0; /* Opcodes executed since progress callback. */ |
| 61614 | #endif |
| @@ -62868,11 +62808,10 @@ | |
| 62868 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 62869 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 62870 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 62871 | } |
| 62872 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 62873 | sqlite3VdbeMutexResync(p); |
| 62874 | if( db->mallocFailed ){ |
| 62875 | /* Even though a malloc() has failed, the implementation of the |
| 62876 | ** user function may have called an sqlite3_result_XXX() function |
| 62877 | ** to return a value. The following call releases any resources |
| 62878 | ** associated with such a value. |
| @@ -62879,21 +62818,10 @@ | |
| 62879 | */ |
| 62880 | sqlite3VdbeMemRelease(&u.ag.ctx.s); |
| 62881 | goto no_mem; |
| 62882 | } |
| 62883 | |
| 62884 | /* The app-defined function has done something that as caused this |
| 62885 | ** statement to expire. (Perhaps the function called sqlite3_exec() |
| 62886 | ** with a CREATE TABLE statement.) |
| 62887 | */ |
| 62888 | #if 0 |
| 62889 | if( p->expired ){ |
| 62890 | rc = SQLITE_ABORT; |
| 62891 | break; |
| 62892 | } |
| 62893 | #endif |
| 62894 | |
| 62895 | /* If any auxiliary data functions have been called by this user function, |
| 62896 | ** immediately call the destructor for any non-static values. |
| 62897 | */ |
| 62898 | if( u.ag.ctx.pVdbeFunc ){ |
| 62899 | sqlite3VdbeDeleteAuxData(u.ag.ctx.pVdbeFunc, pOp->p1); |
| @@ -62911,10 +62839,19 @@ | |
| 62911 | sqlite3VdbeChangeEncoding(&u.ag.ctx.s, encoding); |
| 62912 | sqlite3VdbeMemMove(pOut, &u.ag.ctx.s); |
| 62913 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 62914 | goto too_big; |
| 62915 | } |
| 62916 | REGISTER_TRACE(pOp->p3, pOut); |
| 62917 | UPDATE_MAX_BLOBSIZE(pOut); |
| 62918 | break; |
| 62919 | } |
| 62920 | |
| @@ -64155,12 +64092,11 @@ | |
| 64155 | goto abort_due_to_error; |
| 64156 | } |
| 64157 | } |
| 64158 | if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 64159 | sqlite3ExpirePreparedStatements(db); |
| 64160 | sqlite3ResetInternalSchema(db, 0); |
| 64161 | sqlite3VdbeMutexResync(p); |
| 64162 | db->flags = (db->flags | SQLITE_InternChanges); |
| 64163 | } |
| 64164 | } |
| 64165 | |
| 64166 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| @@ -64384,10 +64320,11 @@ | |
| 64384 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 64385 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64386 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 64387 | u.au.pDb = &db->aDb[pOp->p1]; |
| 64388 | assert( u.au.pDb->pBt!=0 ); |
| 64389 | pIn3 = &aMem[pOp->p3]; |
| 64390 | sqlite3VdbeMemIntegerify(pIn3); |
| 64391 | /* See note about index shifting on OP_ReadCookie */ |
| 64392 | rc = sqlite3BtreeUpdateMeta(u.au.pDb->pBt, pOp->p2, (int)pIn3->u.i); |
| 64393 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| @@ -64432,16 +64369,17 @@ | |
| 64432 | Btree *pBt; |
| 64433 | #endif /* local variables moved into u.av */ |
| 64434 | |
| 64435 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64436 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 64437 | u.av.pBt = db->aDb[pOp->p1].pBt; |
| 64438 | if( u.av.pBt ){ |
| 64439 | sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta); |
| 64440 | u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 64441 | }else{ |
| 64442 | u.av.iMeta = 0; |
| 64443 | } |
| 64444 | if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){ |
| 64445 | sqlite3DbFree(db, p->zErrMsg); |
| 64446 | p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 64447 | /* If the schema-cookie from the database file matches the cookie |
| @@ -64457,11 +64395,10 @@ | |
| 64457 | ** to be invalidated whenever sqlite3_step() is called from within |
| 64458 | ** a v-table method. |
| 64459 | */ |
| 64460 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){ |
| 64461 | sqlite3ResetInternalSchema(db, pOp->p1); |
| 64462 | sqlite3VdbeMutexResync(p); |
| 64463 | } |
| 64464 | |
| 64465 | p->expired = 1; |
| 64466 | rc = SQLITE_SCHEMA; |
| 64467 | } |
| @@ -64544,10 +64481,11 @@ | |
| 64544 | u.aw.pDb = &db->aDb[u.aw.iDb]; |
| 64545 | u.aw.pX = u.aw.pDb->pBt; |
| 64546 | assert( u.aw.pX!=0 ); |
| 64547 | if( pOp->opcode==OP_OpenWrite ){ |
| 64548 | u.aw.wrFlag = 1; |
| 64549 | if( u.aw.pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 64550 | p->minWriteFileFormat = u.aw.pDb->pSchema->file_format; |
| 64551 | } |
| 64552 | }else{ |
| 64553 | u.aw.wrFlag = 0; |
| @@ -66081,12 +66019,14 @@ | |
| 66081 | rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved); |
| 66082 | pOut->flags = MEM_Int; |
| 66083 | pOut->u.i = u.br.iMoved; |
| 66084 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 66085 | if( rc==SQLITE_OK && u.br.iMoved!=0 ){ |
| 66086 | sqlite3RootPageMoved(&db->aDb[u.br.iDb], u.br.iMoved, pOp->p1); |
| 66087 | resetSchemaOnFault = 1; |
| 66088 | } |
| 66089 | #endif |
| 66090 | } |
| 66091 | break; |
| 66092 | } |
| @@ -66764,27 +66704,15 @@ | |
| 66764 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66765 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66766 | u.cb.ctx.pColl = pOp[-1].p4.pColl; |
| 66767 | } |
| 66768 | (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */ |
| 66769 | sqlite3VdbeMutexResync(p); |
| 66770 | if( u.cb.ctx.isError ){ |
| 66771 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s)); |
| 66772 | rc = u.cb.ctx.isError; |
| 66773 | } |
| 66774 | |
| 66775 | /* The app-defined function has done something that as caused this |
| 66776 | ** statement to expire. (Perhaps the function called sqlite3_exec() |
| 66777 | ** with a CREATE TABLE statement.) |
| 66778 | */ |
| 66779 | #if 0 |
| 66780 | if( p->expired ){ |
| 66781 | rc = SQLITE_ABORT; |
| 66782 | break; |
| 66783 | } |
| 66784 | #endif |
| 66785 | |
| 66786 | sqlite3VdbeMemRelease(&u.cb.ctx.s); |
| 66787 | |
| 66788 | break; |
| 66789 | } |
| 66790 | |
| @@ -66806,15 +66734,12 @@ | |
| 66806 | #endif /* local variables moved into u.cc */ |
| 66807 | assert( pOp->p1>0 && pOp->p1<=p->nMem ); |
| 66808 | u.cc.pMem = &aMem[pOp->p1]; |
| 66809 | assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 66810 | rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc); |
| 66811 | sqlite3VdbeMutexResync(p); |
| 66812 | if( rc ){ |
| 66813 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem)); |
| 66814 | }else if( p->expired ){ |
| 66815 | rc = SQLITE_ABORT; |
| 66816 | } |
| 66817 | sqlite3VdbeChangeEncoding(u.cc.pMem, encoding); |
| 66818 | UPDATE_MAX_BLOBSIZE(u.cc.pMem); |
| 66819 | if( sqlite3VdbeMemTooBig(u.cc.pMem) ){ |
| 66820 | goto too_big; |
| @@ -66889,28 +66814,10 @@ | |
| 66889 | || u.ce.eNew==PAGER_JOURNALMODE_WAL |
| 66890 | || u.ce.eNew==PAGER_JOURNALMODE_QUERY |
| 66891 | ); |
| 66892 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66893 | |
| 66894 | /* This opcode is used in two places: PRAGMA journal_mode and ATTACH. |
| 66895 | ** In PRAGMA journal_mode, the sqlite3VdbeUsesBtree() routine is called |
| 66896 | ** when the statement is prepared and so p->btreeMask!=0. All mutexes |
| 66897 | ** are already acquired. But when used in ATTACH, sqlite3VdbeUsesBtree() |
| 66898 | ** is not called when the statement is prepared because it requires the |
| 66899 | ** iDb index of the database as a parameter, and the database has not |
| 66900 | ** yet been attached so that index is unavailable. We have to wait |
| 66901 | ** until runtime (now) to get the mutex on the newly attached database. |
| 66902 | ** No other mutexes are required by the ATTACH command so this is safe |
| 66903 | ** to do. |
| 66904 | */ |
| 66905 | if( p->btreeMask==0 ){ |
| 66906 | /* This occurs right after ATTACH. Get a mutex on the newly ATTACHed |
| 66907 | ** database. */ |
| 66908 | sqlite3VdbeUsesBtree(p, pOp->p1); |
| 66909 | sqlite3VdbeEnter(p); |
| 66910 | } |
| 66911 | |
| 66912 | u.ce.pBt = db->aDb[pOp->p1].pBt; |
| 66913 | u.ce.pPager = sqlite3BtreePager(u.ce.pBt); |
| 66914 | u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager); |
| 66915 | if( u.ce.eNew==PAGER_JOURNALMODE_QUERY ) u.ce.eNew = u.ce.eOld; |
| 66916 | if( !sqlite3PagerOkToChangeJournalMode(u.ce.pPager) ) u.ce.eNew = u.ce.eOld; |
| @@ -67560,13 +67467,12 @@ | |
| 67560 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 67561 | pc, p->zSql, p->zErrMsg); |
| 67562 | sqlite3VdbeHalt(p); |
| 67563 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 67564 | rc = SQLITE_ERROR; |
| 67565 | if( resetSchemaOnFault ){ |
| 67566 | sqlite3ResetInternalSchema(db, 0); |
| 67567 | sqlite3VdbeMutexResync(p); |
| 67568 | } |
| 67569 | |
| 67570 | /* This is the only way out of this procedure. We have to |
| 67571 | ** release the mutexes on btrees that were acquired at the |
| 67572 | ** top. */ |
| @@ -72266,11 +72172,11 @@ | |
| 72266 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 72267 | assert( pExpr->u.zToken!=0 ); |
| 72268 | assert( pExpr->u.zToken[0]!=0 ); |
| 72269 | sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target); |
| 72270 | if( pExpr->u.zToken[1]!=0 ){ |
| 72271 | sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, 0); |
| 72272 | } |
| 72273 | break; |
| 72274 | } |
| 72275 | case TK_REGISTER: { |
| 72276 | inReg = pExpr->iTable; |
| @@ -74655,10 +74561,11 @@ | |
| 74655 | return; |
| 74656 | } |
| 74657 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 74658 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 74659 | assert( iDb>=0 ); |
| 74660 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 74661 | if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0, |
| 74662 | db->aDb[iDb].zName ) ){ |
| 74663 | return; |
| 74664 | } |
| @@ -74896,10 +74803,11 @@ | |
| 74896 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74897 | iStatCur = pParse->nTab; |
| 74898 | pParse->nTab += 2; |
| 74899 | openStatTable(pParse, iDb, iStatCur, 0, 0); |
| 74900 | iMem = pParse->nMem+1; |
| 74901 | for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 74902 | Table *pTab = (Table*)sqliteHashData(k); |
| 74903 | analyzeOneTable(pParse, pTab, 0, iStatCur, iMem); |
| 74904 | } |
| 74905 | loadAnalysis(pParse, iDb); |
| @@ -75106,13 +75014,13 @@ | |
| 75106 | char *zSql; |
| 75107 | int rc; |
| 75108 | |
| 75109 | assert( iDb>=0 && iDb<db->nDb ); |
| 75110 | assert( db->aDb[iDb].pBt!=0 ); |
| 75111 | assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 75112 | |
| 75113 | /* Clear any prior statistics */ |
| 75114 | for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ |
| 75115 | Index *pIdx = sqliteHashData(i); |
| 75116 | sqlite3DefaultRowEst(pIdx); |
| 75117 | sqlite3DeleteIndexSamples(db, pIdx); |
| 75118 | pIdx->aSample = 0; |
| @@ -75421,11 +75329,11 @@ | |
| 75421 | if( db->aDb[iDb].pBt ){ |
| 75422 | sqlite3BtreeClose(db->aDb[iDb].pBt); |
| 75423 | db->aDb[iDb].pBt = 0; |
| 75424 | db->aDb[iDb].pSchema = 0; |
| 75425 | } |
| 75426 | sqlite3ResetInternalSchema(db, 0); |
| 75427 | db->nDb = iDb; |
| 75428 | if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 75429 | db->mallocFailed = 1; |
| 75430 | sqlite3DbFree(db, zErrDyn); |
| 75431 | zErrDyn = sqlite3MPrintf(db, "out of memory"); |
| @@ -75493,11 +75401,11 @@ | |
| 75493 | } |
| 75494 | |
| 75495 | sqlite3BtreeClose(pDb->pBt); |
| 75496 | pDb->pBt = 0; |
| 75497 | pDb->pSchema = 0; |
| 75498 | sqlite3ResetInternalSchema(db, 0); |
| 75499 | return; |
| 75500 | |
| 75501 | detach_error: |
| 75502 | sqlite3_result_error(context, zErr, -1); |
| 75503 | } |
| @@ -76171,10 +76079,11 @@ | |
| 76171 | for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ |
| 76172 | if( (mask & pParse->cookieMask)==0 ) continue; |
| 76173 | sqlite3VdbeUsesBtree(v, iDb); |
| 76174 | sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0); |
| 76175 | if( db->init.busy==0 ){ |
| 76176 | sqlite3VdbeAddOp3(v, OP_VerifyCookie, |
| 76177 | iDb, pParse->cookieValue[iDb], |
| 76178 | db->aDb[iDb].pSchema->iGeneration); |
| 76179 | } |
| 76180 | } |
| @@ -76286,13 +76195,16 @@ | |
| 76286 | Table *p = 0; |
| 76287 | int i; |
| 76288 | int nName; |
| 76289 | assert( zName!=0 ); |
| 76290 | nName = sqlite3Strlen30(zName); |
| 76291 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 76292 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 76293 | if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; |
| 76294 | p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName); |
| 76295 | if( p ) break; |
| 76296 | } |
| 76297 | return p; |
| 76298 | } |
| @@ -76348,15 +76260,18 @@ | |
| 76348 | */ |
| 76349 | SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ |
| 76350 | Index *p = 0; |
| 76351 | int i; |
| 76352 | int nName = sqlite3Strlen30(zName); |
| 76353 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 76354 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 76355 | Schema *pSchema = db->aDb[j].pSchema; |
| 76356 | assert( pSchema ); |
| 76357 | if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue; |
| 76358 | p = sqlite3HashFind(&pSchema->idxHash, zName, nName); |
| 76359 | if( p ) break; |
| 76360 | } |
| 76361 | return p; |
| 76362 | } |
| @@ -76379,12 +76294,14 @@ | |
| 76379 | ** with the index. |
| 76380 | */ |
| 76381 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){ |
| 76382 | Index *pIndex; |
| 76383 | int len; |
| 76384 | Hash *pHash = &db->aDb[iDb].pSchema->idxHash; |
| 76385 | |
| 76386 | len = sqlite3Strlen30(zIdxName); |
| 76387 | pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0); |
| 76388 | if( ALWAYS(pIndex) ){ |
| 76389 | if( pIndex->pTable->pIndex==pIndex ){ |
| 76390 | pIndex->pTable->pIndex = pIndex->pNext; |
| @@ -76408,30 +76325,46 @@ | |
| 76408 | ** a single database. This routine is called to reclaim memory |
| 76409 | ** before the database closes. It is also called during a rollback |
| 76410 | ** if there were schema changes during the transaction or if a |
| 76411 | ** schema-cookie mismatch occurs. |
| 76412 | ** |
| 76413 | ** If iDb==0 then reset the internal schema tables for all database |
| 76414 | ** files. If iDb>=1 then reset the internal schema for only the |
| 76415 | ** single file indicated. |
| 76416 | */ |
| 76417 | SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){ |
| 76418 | int i, j; |
| 76419 | assert( iDb>=0 && iDb<db->nDb ); |
| 76420 | |
| 76421 | if( iDb==0 ){ |
| 76422 | sqlite3BtreeEnterAll(db); |
| 76423 | } |
| 76424 | for(i=iDb; i<db->nDb; i++){ |
| 76425 | Db *pDb = &db->aDb[i]; |
| 76426 | if( pDb->pSchema ){ |
| 76427 | assert(i==1 || (pDb->pBt && sqlite3BtreeHoldsMutex(pDb->pBt))); |
| 76428 | sqlite3SchemaFree(pDb->pSchema); |
| 76429 | } |
| 76430 | if( iDb>0 ) return; |
| 76431 | } |
| 76432 | assert( iDb==0 ); |
| 76433 | db->flags &= ~SQLITE_InternChanges; |
| 76434 | sqlite3VtabUnlockList(db); |
| 76435 | sqlite3BtreeLeaveAll(db); |
| 76436 | |
| 76437 | /* If one or more of the auxiliary database files has been closed, |
| @@ -76513,10 +76446,11 @@ | |
| 76513 | if( !db || db->pnBytesFreed==0 ){ |
| 76514 | char *zName = pIndex->zName; |
| 76515 | TESTONLY ( Index *pOld = ) sqlite3HashInsert( |
| 76516 | &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0 |
| 76517 | ); |
| 76518 | assert( pOld==pIndex || pOld==0 ); |
| 76519 | } |
| 76520 | freeIndex(db, pIndex); |
| 76521 | } |
| 76522 | |
| @@ -76547,10 +76481,11 @@ | |
| 76547 | Db *pDb; |
| 76548 | |
| 76549 | assert( db!=0 ); |
| 76550 | assert( iDb>=0 && iDb<db->nDb ); |
| 76551 | assert( zTabName ); |
| 76552 | testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */ |
| 76553 | pDb = &db->aDb[iDb]; |
| 76554 | p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, |
| 76555 | sqlite3Strlen30(zTabName),0); |
| 76556 | sqlite3DeleteTable(db, p); |
| @@ -76831,10 +76766,11 @@ | |
| 76831 | ** then record a pointer to this table in the main database structure |
| 76832 | ** so that INSERT can find the table easily. |
| 76833 | */ |
| 76834 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 76835 | if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){ |
| 76836 | pTable->pSchema->pSeqTab = pTable; |
| 76837 | } |
| 76838 | #endif |
| 76839 | |
| 76840 | /* Begin generating the code that will insert the table record into |
| @@ -77291,10 +77227,11 @@ | |
| 77291 | */ |
| 77292 | SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){ |
| 77293 | int r1 = sqlite3GetTempReg(pParse); |
| 77294 | sqlite3 *db = pParse->db; |
| 77295 | Vdbe *v = pParse->pVdbe; |
| 77296 | sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1); |
| 77297 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1); |
| 77298 | sqlite3ReleaseTempReg(pParse, r1); |
| 77299 | } |
| 77300 | |
| @@ -77398,11 +77335,11 @@ | |
| 77398 | sqlite3_snprintf(n-k, &zStmt[k], zSep); |
| 77399 | k += sqlite3Strlen30(&zStmt[k]); |
| 77400 | zSep = zSep2; |
| 77401 | identPut(zStmt, &k, pCol->zName); |
| 77402 | assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 ); |
| 77403 | assert( pCol->affinity-SQLITE_AFF_TEXT < sizeof(azType)/sizeof(azType[0]) ); |
| 77404 | testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 77405 | testcase( pCol->affinity==SQLITE_AFF_NONE ); |
| 77406 | testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); |
| 77407 | testcase( pCol->affinity==SQLITE_AFF_INTEGER ); |
| 77408 | testcase( pCol->affinity==SQLITE_AFF_REAL ); |
| @@ -77593,10 +77530,11 @@ | |
| 77593 | /* Check to see if we need to create an sqlite_sequence table for |
| 77594 | ** keeping track of autoincrement keys. |
| 77595 | */ |
| 77596 | if( p->tabFlags & TF_Autoincrement ){ |
| 77597 | Db *pDb = &db->aDb[iDb]; |
| 77598 | if( pDb->pSchema->pSeqTab==0 ){ |
| 77599 | sqlite3NestedParse(pParse, |
| 77600 | "CREATE TABLE %Q.sqlite_sequence(name,seq)", |
| 77601 | pDb->zName |
| 77602 | ); |
| @@ -77613,10 +77551,11 @@ | |
| 77613 | /* Add the table to the in-memory representation of the database. |
| 77614 | */ |
| 77615 | if( db->init.busy ){ |
| 77616 | Table *pOld; |
| 77617 | Schema *pSchema = p->pSchema; |
| 77618 | pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, |
| 77619 | sqlite3Strlen30(p->zName),p); |
| 77620 | if( pOld ){ |
| 77621 | assert( p==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 77622 | db->mallocFailed = 1; |
| @@ -77797,10 +77736,11 @@ | |
| 77797 | pTable->nCol = pSelTab->nCol; |
| 77798 | pTable->aCol = pSelTab->aCol; |
| 77799 | pSelTab->nCol = 0; |
| 77800 | pSelTab->aCol = 0; |
| 77801 | sqlite3DeleteTable(db, pSelTab); |
| 77802 | pTable->pSchema->flags |= DB_UnresetViews; |
| 77803 | }else{ |
| 77804 | pTable->nCol = 0; |
| 77805 | nErr++; |
| 77806 | } |
| @@ -77817,10 +77757,11 @@ | |
| 77817 | /* |
| 77818 | ** Clear the column names from every VIEW in database idx. |
| 77819 | */ |
| 77820 | static void sqliteViewResetAll(sqlite3 *db, int idx){ |
| 77821 | HashElem *i; |
| 77822 | if( !DbHasProperty(db, idx, DB_UnresetViews) ) return; |
| 77823 | for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){ |
| 77824 | Table *pTab = sqliteHashData(i); |
| 77825 | if( pTab->pSelect ){ |
| 77826 | sqliteDeleteColumnNames(db, pTab); |
| @@ -77850,14 +77791,17 @@ | |
| 77850 | ** We must continue looping until all tables and indices with |
| 77851 | ** rootpage==iFrom have been converted to have a rootpage of iTo |
| 77852 | ** in order to be certain that we got the right one. |
| 77853 | */ |
| 77854 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 77855 | SQLITE_PRIVATE void sqlite3RootPageMoved(Db *pDb, int iFrom, int iTo){ |
| 77856 | HashElem *pElem; |
| 77857 | Hash *pHash; |
| 77858 | |
| 77859 | pHash = &pDb->pSchema->tblHash; |
| 77860 | for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){ |
| 77861 | Table *pTab = sqliteHashData(pElem); |
| 77862 | if( pTab->tnum==iFrom ){ |
| 77863 | pTab->tnum = iTo; |
| @@ -78227,10 +78171,11 @@ | |
| 78227 | } |
| 78228 | pFKey->isDeferred = 0; |
| 78229 | pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */ |
| 78230 | pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */ |
| 78231 | |
| 78232 | pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash, |
| 78233 | pFKey->zTo, sqlite3Strlen30(pFKey->zTo), (void *)pFKey |
| 78234 | ); |
| 78235 | if( pNextTo==pFKey ){ |
| 78236 | db->mallocFailed = 1; |
| @@ -78582,10 +78527,11 @@ | |
| 78582 | pIndex->pTable = pTab; |
| 78583 | pIndex->nColumn = pList->nExpr; |
| 78584 | pIndex->onError = (u8)onError; |
| 78585 | pIndex->autoIndex = (u8)(pName==0); |
| 78586 | pIndex->pSchema = db->aDb[iDb].pSchema; |
| 78587 | |
| 78588 | /* Check to see if we should honor DESC requests on index columns |
| 78589 | */ |
| 78590 | if( pDb->pSchema->file_format>=4 ){ |
| 78591 | sortOrderMask = -1; /* Honor DESC */ |
| @@ -78711,10 +78657,11 @@ | |
| 78711 | /* Link the new Index structure to its table and to the other |
| 78712 | ** in-memory database structures. |
| 78713 | */ |
| 78714 | if( db->init.busy ){ |
| 78715 | Index *p; |
| 78716 | p = sqlite3HashInsert(&pIndex->pSchema->idxHash, |
| 78717 | pIndex->zName, sqlite3Strlen30(pIndex->zName), |
| 78718 | pIndex); |
| 78719 | if( p ){ |
| 78720 | assert( p==pIndex ); /* Malloc must have failed */ |
| @@ -79464,10 +79411,11 @@ | |
| 79464 | yDbMask mask; |
| 79465 | |
| 79466 | assert( iDb<db->nDb ); |
| 79467 | assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 79468 | assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 79469 | mask = ((yDbMask)1)<<iDb; |
| 79470 | if( (pToplevel->cookieMask & mask)==0 ){ |
| 79471 | pToplevel->cookieMask |= mask; |
| 79472 | pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 79473 | if( !OMIT_TEMPDB && iDb==1 ){ |
| @@ -79591,10 +79539,11 @@ | |
| 79591 | int iDb; /* The database index number */ |
| 79592 | sqlite3 *db = pParse->db; /* The database connection */ |
| 79593 | HashElem *k; /* For looping over tables in pDb */ |
| 79594 | Table *pTab; /* A table in the database */ |
| 79595 | |
| 79596 | for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){ |
| 79597 | assert( pDb!=0 ); |
| 79598 | for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 79599 | pTab = (Table*)sqliteHashData(k); |
| 79600 | reindexTable(pParse, pTab, zColl); |
| @@ -80109,16 +80058,16 @@ | |
| 80109 | } |
| 80110 | |
| 80111 | /* |
| 80112 | ** Free all resources held by the schema structure. The void* argument points |
| 80113 | ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the |
| 80114 | ** pointer itself, it just cleans up subsiduary resources (i.e. the contents |
| 80115 | ** of the schema hash tables). |
| 80116 | ** |
| 80117 | ** The Schema.cache_size variable is not cleared. |
| 80118 | */ |
| 80119 | SQLITE_PRIVATE void sqlite3SchemaFree(void *p){ |
| 80120 | Hash temp1; |
| 80121 | Hash temp2; |
| 80122 | HashElem *pElem; |
| 80123 | Schema *pSchema = (Schema *)p; |
| 80124 | |
| @@ -80149,11 +80098,11 @@ | |
| 80149 | ** a new one if necessary. |
| 80150 | */ |
| 80151 | SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ |
| 80152 | Schema * p; |
| 80153 | if( pBt ){ |
| 80154 | p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree); |
| 80155 | }else{ |
| 80156 | p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema)); |
| 80157 | } |
| 80158 | if( !p ){ |
| 80159 | db->mallocFailed = 1; |
| @@ -80183,13 +80132,22 @@ | |
| 80183 | ** This file contains C code routines that are called by the parser |
| 80184 | ** in order to generate code for DELETE FROM statements. |
| 80185 | */ |
| 80186 | |
| 80187 | /* |
| 80188 | ** Look up every table that is named in pSrc. If any table is not found, |
| 80189 | ** add an error message to pParse->zErrMsg and return NULL. If all tables |
| 80190 | ** are found, return a pointer to the last table. |
| 80191 | */ |
| 80192 | SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ |
| 80193 | struct SrcList_item *pItem = pSrc->a; |
| 80194 | Table *pTab; |
| 80195 | assert( pItem && pSrc->nSrc==1 ); |
| @@ -80704,11 +80662,11 @@ | |
| 80704 | ** fire the INSTEAD OF triggers). */ |
| 80705 | if( pTab->pSelect==0 ){ |
| 80706 | sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0); |
| 80707 | sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0)); |
| 80708 | if( count ){ |
| 80709 | sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC); |
| 80710 | } |
| 80711 | } |
| 80712 | |
| 80713 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 80714 | ** handle rows (possibly in other tables) that refer via a foreign key |
| @@ -80795,11 +80753,11 @@ | |
| 80795 | sqlite3ColumnDefault(v, pTab, idx, -1); |
| 80796 | } |
| 80797 | } |
| 80798 | if( doMakeRec ){ |
| 80799 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut); |
| 80800 | sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0); |
| 80801 | } |
| 80802 | sqlite3ReleaseTempRange(pParse, regBase, nCol+1); |
| 80803 | return regBase; |
| 80804 | } |
| 80805 | |
| @@ -82792,11 +82750,11 @@ | |
| 82792 | } |
| 82793 | sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk); |
| 82794 | } |
| 82795 | |
| 82796 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec); |
| 82797 | sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0); |
| 82798 | sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); |
| 82799 | |
| 82800 | sqlite3ReleaseTempReg(pParse, regRec); |
| 82801 | sqlite3ReleaseTempRange(pParse, regTemp, nCol); |
| 82802 | } |
| @@ -83548,10 +83506,11 @@ | |
| 83548 | */ |
| 83549 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ |
| 83550 | FKey *pFKey; /* Iterator variable */ |
| 83551 | FKey *pNext; /* Copy of pFKey->pNextFrom */ |
| 83552 | |
| 83553 | for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){ |
| 83554 | |
| 83555 | /* Remove the FK from the fkeyHash hash table. */ |
| 83556 | if( !db || db->pnBytesFreed==0 ){ |
| 83557 | if( pFKey->pPrevTo ){ |
| @@ -83707,11 +83666,11 @@ | |
| 83707 | zColAff[pTab->nCol] = '\0'; |
| 83708 | |
| 83709 | pTab->zColAff = zColAff; |
| 83710 | } |
| 83711 | |
| 83712 | sqlite3VdbeChangeP4(v, -1, pTab->zColAff, 0); |
| 83713 | } |
| 83714 | |
| 83715 | /* |
| 83716 | ** Return non-zero if the table pTab in database iDb or any of its indices |
| 83717 | ** have been opened at any point in the VDBE program beginning at location |
| @@ -83821,10 +83780,11 @@ | |
| 83821 | |
| 83822 | assert( v ); /* We failed long ago if this is not so */ |
| 83823 | for(p = pParse->pAinc; p; p = p->pNext){ |
| 83824 | pDb = &db->aDb[p->iDb]; |
| 83825 | memId = p->regCtr; |
| 83826 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead); |
| 83827 | addr = sqlite3VdbeCurrentAddr(v); |
| 83828 | sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0); |
| 83829 | sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); |
| 83830 | sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId); |
| @@ -83871,10 +83831,11 @@ | |
| 83871 | int j1, j2, j3, j4, j5; |
| 83872 | int iRec; |
| 83873 | int memId = p->regCtr; |
| 83874 | |
| 83875 | iRec = sqlite3GetTempReg(pParse); |
| 83876 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite); |
| 83877 | j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); |
| 83878 | j2 = sqlite3VdbeAddOp0(v, OP_Rewind); |
| 83879 | j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec); |
| 83880 | j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec); |
| @@ -84911,11 +84872,11 @@ | |
| 84911 | sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i); |
| 84912 | } |
| 84913 | } |
| 84914 | sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i); |
| 84915 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]); |
| 84916 | sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), 0); |
| 84917 | sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1); |
| 84918 | |
| 84919 | #ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT |
| 84920 | sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1); |
| 84921 | continue; /* Treat pIdx as if it is not a UNIQUE index */ |
| @@ -85057,11 +85018,11 @@ | |
| 85057 | if( useSeekResult ){ |
| 85058 | pik_flags |= OPFLAG_USESEEKRESULT; |
| 85059 | } |
| 85060 | sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid); |
| 85061 | if( !pParse->nested ){ |
| 85062 | sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC); |
| 85063 | } |
| 85064 | sqlite3VdbeChangeP5(v, pik_flags); |
| 85065 | } |
| 85066 | |
| 85067 | /* |
| @@ -86752,11 +86713,11 @@ | |
| 86752 | "from within a transaction"); |
| 86753 | return SQLITE_ERROR; |
| 86754 | } |
| 86755 | sqlite3BtreeClose(db->aDb[1].pBt); |
| 86756 | db->aDb[1].pBt = 0; |
| 86757 | sqlite3ResetInternalSchema(db, 0); |
| 86758 | } |
| 86759 | return SQLITE_OK; |
| 86760 | } |
| 86761 | #endif /* SQLITE_PAGER_PRAGMAS */ |
| 86762 | |
| @@ -87025,10 +86986,11 @@ | |
| 87025 | }else{ |
| 87026 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 87027 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 87028 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
| 87029 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
| 87030 | pDb->pSchema->cache_size = size; |
| 87031 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
| 87032 | } |
| 87033 | }else |
| 87034 | |
| @@ -87327,10 +87289,11 @@ | |
| 87327 | ** to its default value when the database is closed and reopened. |
| 87328 | ** N should be a positive integer. |
| 87329 | */ |
| 87330 | if( sqlite3StrICmp(zLeft,"cache_size")==0 ){ |
| 87331 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 87332 | if( !zRight ){ |
| 87333 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
| 87334 | }else{ |
| 87335 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 87336 | pDb->pSchema->cache_size = size; |
| @@ -87747,10 +87710,11 @@ | |
| 87747 | /* Do an integrity check of the B-Tree |
| 87748 | ** |
| 87749 | ** Begin by filling registers 2, 3, ... with the root pages numbers |
| 87750 | ** for all tables and indices in the database. |
| 87751 | */ |
| 87752 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 87753 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
| 87754 | Table *pTab = sqliteHashData(x); |
| 87755 | Index *pIdx; |
| 87756 | sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt); |
| @@ -87812,11 +87776,11 @@ | |
| 87812 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0); |
| 87813 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1); |
| 87814 | addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr); |
| 87815 | sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC); |
| 87816 | sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC); |
| 87817 | sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC); |
| 87818 | sqlite3VdbeJumpHere(v, addr+9); |
| 87819 | sqlite3VdbeJumpHere(v, jmp2); |
| 87820 | } |
| 87821 | sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1); |
| 87822 | sqlite3VdbeJumpHere(v, loopTop); |
| @@ -87842,11 +87806,11 @@ | |
| 87842 | sqlite3VdbeChangeP1(v, addr+3, j+2); |
| 87843 | sqlite3VdbeChangeP2(v, addr+3, addr+2); |
| 87844 | sqlite3VdbeJumpHere(v, addr+4); |
| 87845 | sqlite3VdbeChangeP4(v, addr+6, |
| 87846 | "wrong # of entries in index ", P4_STATIC); |
| 87847 | sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_STATIC); |
| 87848 | } |
| 87849 | } |
| 87850 | } |
| 87851 | addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode); |
| 87852 | sqlite3VdbeChangeP2(v, addr, -mxErr); |
| @@ -88498,11 +88462,11 @@ | |
| 88498 | } |
| 88499 | #endif |
| 88500 | } |
| 88501 | if( db->mallocFailed ){ |
| 88502 | rc = SQLITE_NOMEM; |
| 88503 | sqlite3ResetInternalSchema(db, 0); |
| 88504 | } |
| 88505 | if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){ |
| 88506 | /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider |
| 88507 | ** the schema loaded, even if errors occurred. In this situation the |
| 88508 | ** current sqlite3_prepare() operation will fail, but the following one |
| @@ -88630,11 +88594,13 @@ | |
| 88630 | |
| 88631 | /* Read the schema cookie from the database. If it does not match the |
| 88632 | ** value stored as part of the in-memory schema representation, |
| 88633 | ** set Parse.rc to SQLITE_SCHEMA. */ |
| 88634 | sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie); |
| 88635 | if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){ |
| 88636 | pParse->rc = SQLITE_SCHEMA; |
| 88637 | } |
| 88638 | |
| 88639 | /* Close the transaction, if one was opened. */ |
| 88640 | if( openedTransaction ){ |
| @@ -88772,13 +88738,10 @@ | |
| 88772 | } |
| 88773 | if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK; |
| 88774 | if( pParse->checkSchema ){ |
| 88775 | schemaIsValid(pParse); |
| 88776 | } |
| 88777 | if( pParse->rc==SQLITE_SCHEMA ){ |
| 88778 | sqlite3ResetInternalSchema(db, 0); |
| 88779 | } |
| 88780 | if( db->mallocFailed ){ |
| 88781 | pParse->rc = SQLITE_NOMEM; |
| 88782 | } |
| 88783 | if( pzTail ){ |
| 88784 | *pzTail = pParse->zTail; |
| @@ -93735,10 +93698,11 @@ | |
| 93735 | return 0; |
| 93736 | } |
| 93737 | |
| 93738 | if( pTmpSchema!=pTab->pSchema ){ |
| 93739 | HashElem *p; |
| 93740 | for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){ |
| 93741 | Trigger *pTrig = (Trigger *)sqliteHashData(p); |
| 93742 | if( pTrig->pTabSchema==pTab->pSchema |
| 93743 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 93744 | ){ |
| @@ -93846,10 +93810,11 @@ | |
| 93846 | ** specified name exists */ |
| 93847 | zName = sqlite3NameFromToken(db, pName); |
| 93848 | if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 93849 | goto trigger_cleanup; |
| 93850 | } |
| 93851 | if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash), |
| 93852 | zName, sqlite3Strlen30(zName)) ){ |
| 93853 | if( !noErr ){ |
| 93854 | sqlite3ErrorMsg(pParse, "trigger %T already exists", pName); |
| 93855 | } |
| @@ -93985,10 +93950,11 @@ | |
| 93985 | } |
| 93986 | |
| 93987 | if( db->init.busy ){ |
| 93988 | Trigger *pLink = pTrig; |
| 93989 | Hash *pHash = &db->aDb[iDb].pSchema->trigHash; |
| 93990 | pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig); |
| 93991 | if( pTrig ){ |
| 93992 | db->mallocFailed = 1; |
| 93993 | }else if( pLink->pSchema==pLink->pTabSchema ){ |
| 93994 | Table *pTab; |
| @@ -94166,13 +94132,15 @@ | |
| 94166 | |
| 94167 | assert( pName->nSrc==1 ); |
| 94168 | zDb = pName->a[0].zDatabase; |
| 94169 | zName = pName->a[0].zName; |
| 94170 | nName = sqlite3Strlen30(zName); |
| 94171 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 94172 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 94173 | if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue; |
| 94174 | pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName); |
| 94175 | if( pTrigger ) break; |
| 94176 | } |
| 94177 | if( !pTrigger ){ |
| 94178 | if( !noErr ){ |
| @@ -94242,11 +94210,11 @@ | |
| 94242 | }; |
| 94243 | |
| 94244 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 94245 | sqlite3OpenMasterTable(pParse, iDb); |
| 94246 | base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger); |
| 94247 | sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, 0); |
| 94248 | sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC); |
| 94249 | sqlite3ChangeCookie(pParse, iDb); |
| 94250 | sqlite3VdbeAddOp2(v, OP_Close, 0, 0); |
| 94251 | sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0); |
| 94252 | if( pParse->nMem<3 ){ |
| @@ -94257,12 +94225,15 @@ | |
| 94257 | |
| 94258 | /* |
| 94259 | ** Remove a trigger from the hash tables of the sqlite* pointer. |
| 94260 | */ |
| 94261 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){ |
| 94262 | Hash *pHash = &(db->aDb[iDb].pSchema->trigHash); |
| 94263 | Trigger *pTrigger; |
| 94264 | pTrigger = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), 0); |
| 94265 | if( ALWAYS(pTrigger) ){ |
| 94266 | if( pTrigger->pSchema==pTrigger->pTabSchema ){ |
| 94267 | Table *pTab = tableOfTrigger(pTrigger); |
| 94268 | Trigger **pp; |
| @@ -95782,14 +95753,17 @@ | |
| 95782 | sqlite3BtreeClose(pDb->pBt); |
| 95783 | pDb->pBt = 0; |
| 95784 | pDb->pSchema = 0; |
| 95785 | } |
| 95786 | |
| 95787 | sqlite3ResetInternalSchema(db, 0); |
| 95788 | |
| 95789 | return rc; |
| 95790 | } |
| 95791 | #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */ |
| 95792 | |
| 95793 | /************** End of vacuum.c **********************************************/ |
| 95794 | /************** Begin file vtab.c ********************************************/ |
| 95795 | /* |
| @@ -95839,11 +95813,11 @@ | |
| 95839 | } |
| 95840 | sqlite3DbFree(db, pDel); |
| 95841 | if( pDel==pMod ){ |
| 95842 | db->mallocFailed = 1; |
| 95843 | } |
| 95844 | sqlite3ResetInternalSchema(db, 0); |
| 95845 | }else if( xDestroy ){ |
| 95846 | xDestroy(pAux); |
| 95847 | } |
| 95848 | rc = sqlite3ApiExit(db, SQLITE_OK); |
| 95849 | sqlite3_mutex_leave(db->mutex); |
| @@ -95936,14 +95910,13 @@ | |
| 95936 | |
| 95937 | /* Assert that the mutex (if any) associated with the BtShared database |
| 95938 | ** that contains table p is held by the caller. See header comments |
| 95939 | ** above function sqlite3VtabUnlockList() for an explanation of why |
| 95940 | ** this makes it safe to access the sqlite3.pDisconnect list of any |
| 95941 | ** database connection that may have an entry in the p->pVTable list. */ |
| 95942 | assert( db==0 || |
| 95943 | sqlite3BtreeHoldsMutex(db->aDb[sqlite3SchemaToIndex(db, p->pSchema)].pBt) |
| 95944 | ); |
| 95945 | |
| 95946 | while( pVTable ){ |
| 95947 | sqlite3 *db2 = pVTable->db; |
| 95948 | VTable *pNext = pVTable->pNext; |
| 95949 | assert( db2 ); |
| @@ -96178,10 +96151,11 @@ | |
| 96178 | else { |
| 96179 | Table *pOld; |
| 96180 | Schema *pSchema = pTab->pSchema; |
| 96181 | const char *zName = pTab->zName; |
| 96182 | int nName = sqlite3Strlen30(zName); |
| 96183 | pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab); |
| 96184 | if( pOld ){ |
| 96185 | db->mallocFailed = 1; |
| 96186 | assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 96187 | return; |
| @@ -97132,11 +97106,11 @@ | |
| 97132 | ** Return the bitmask for the given cursor number. Return 0 if |
| 97133 | ** iCursor is not in the set. |
| 97134 | */ |
| 97135 | static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){ |
| 97136 | int i; |
| 97137 | assert( pMaskSet->n<=sizeof(Bitmask)*8 ); |
| 97138 | for(i=0; i<pMaskSet->n; i++){ |
| 97139 | if( pMaskSet->ix[i]==iCursor ){ |
| 97140 | return ((Bitmask)1)<<i; |
| 97141 | } |
| 97142 | } |
| @@ -107007,11 +106981,12 @@ | |
| 107007 | if( !sqlite3SafetyCheckSickOrOk(db) ){ |
| 107008 | return SQLITE_MISUSE_BKPT; |
| 107009 | } |
| 107010 | sqlite3_mutex_enter(db->mutex); |
| 107011 | |
| 107012 | sqlite3ResetInternalSchema(db, 0); |
| 107013 | |
| 107014 | /* If a transaction is open, the ResetInternalSchema() call above |
| 107015 | ** will not have called the xDisconnect() method on any virtual |
| 107016 | ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() |
| 107017 | ** call will do so. We need to do this before the check for active |
| @@ -107050,11 +107025,11 @@ | |
| 107050 | if( j!=1 ){ |
| 107051 | pDb->pSchema = 0; |
| 107052 | } |
| 107053 | } |
| 107054 | } |
| 107055 | sqlite3ResetInternalSchema(db, 0); |
| 107056 | |
| 107057 | /* Tell the code in notify.c that the connection no longer holds any |
| 107058 | ** locks and does not require any further unlock-notify callbacks. |
| 107059 | */ |
| 107060 | sqlite3ConnectionClosed(db); |
| @@ -107141,11 +107116,11 @@ | |
| 107141 | sqlite3VtabRollback(db); |
| 107142 | sqlite3EndBenignMalloc(); |
| 107143 | |
| 107144 | if( db->flags&SQLITE_InternChanges ){ |
| 107145 | sqlite3ExpirePreparedStatements(db); |
| 107146 | sqlite3ResetInternalSchema(db, 0); |
| 107147 | } |
| 107148 | |
| 107149 | /* Any deferred constraint violations have now been resolved. */ |
| 107150 | db->nDeferredCons = 0; |
| 107151 | |
| @@ -107210,11 +107185,11 @@ | |
| 107210 | #if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP) |
| 107211 | static const u8 delays[] = |
| 107212 | { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 }; |
| 107213 | static const u8 totals[] = |
| 107214 | { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 }; |
| 107215 | # define NDELAY (sizeof(delays)/sizeof(delays[0])) |
| 107216 | sqlite3 *db = (sqlite3 *)ptr; |
| 107217 | int timeout = db->busyTimeout; |
| 107218 | int delay, prior; |
| 107219 | |
| 107220 | assert( count>=0 ); |
| @@ -113734,10 +113709,12 @@ | |
| 113734 | int nDb; /* Result of strlen(zDb) */ |
| 113735 | int nFts3; /* Result of strlen(zFts3) */ |
| 113736 | int nByte; /* Bytes of space to allocate here */ |
| 113737 | int rc; /* value returned by declare_vtab() */ |
| 113738 | Fts3auxTable *p; /* Virtual table object to return */ |
| 113739 | |
| 113740 | /* The user should specify a single argument - the name of an fts3 table. */ |
| 113741 | if( argc!=4 ){ |
| 113742 | *pzErr = sqlite3_mprintf( |
| 113743 | "wrong number of arguments to fts4aux constructor" |
| @@ -113803,10 +113780,12 @@ | |
| 113803 | ){ |
| 113804 | int i; |
| 113805 | int iEq = -1; |
| 113806 | int iGe = -1; |
| 113807 | int iLe = -1; |
| 113808 | |
| 113809 | /* This vtab delivers always results in "ORDER BY term ASC" order. */ |
| 113810 | if( pInfo->nOrderBy==1 |
| 113811 | && pInfo->aOrderBy[0].iColumn==0 |
| 113812 | && pInfo->aOrderBy[0].desc==0 |
| @@ -113851,10 +113830,12 @@ | |
| 113851 | /* |
| 113852 | ** xOpen - Open a cursor. |
| 113853 | */ |
| 113854 | static int fts3auxOpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){ |
| 113855 | Fts3auxCursor *pCsr; /* Pointer to cursor object to return */ |
| 113856 | |
| 113857 | pCsr = (Fts3auxCursor *)sqlite3_malloc(sizeof(Fts3auxCursor)); |
| 113858 | if( !pCsr ) return SQLITE_NOMEM; |
| 113859 | memset(pCsr, 0, sizeof(Fts3auxCursor)); |
| 113860 | |
| @@ -114000,10 +113981,12 @@ | |
| 114000 | ){ |
| 114001 | Fts3auxCursor *pCsr = (Fts3auxCursor *)pCursor; |
| 114002 | Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab; |
| 114003 | int rc; |
| 114004 | int isScan; |
| 114005 | |
| 114006 | assert( idxStr==0 ); |
| 114007 | assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0 |
| 114008 | || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT |
| 114009 | || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT) |
| @@ -122428,11 +122411,11 @@ | |
| 122428 | pCsr->nConstraint = argc; |
| 122429 | if( !pCsr->aConstraint ){ |
| 122430 | rc = SQLITE_NOMEM; |
| 122431 | }else{ |
| 122432 | memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc); |
| 122433 | assert( (idxStr==0 && argc==0) || strlen(idxStr)==argc*2 ); |
| 122434 | for(ii=0; ii<argc; ii++){ |
| 122435 | RtreeConstraint *p = &pCsr->aConstraint[ii]; |
| 122436 | p->op = idxStr[ii*2]; |
| 122437 | p->iCoord = idxStr[ii*2+1]-'a'; |
| 122438 | if( p->op==RTREE_MATCH ){ |
| @@ -122521,11 +122504,11 @@ | |
| 122521 | char zIdxStr[RTREE_MAX_DIMENSIONS*8+1]; |
| 122522 | memset(zIdxStr, 0, sizeof(zIdxStr)); |
| 122523 | UNUSED_PARAMETER(tab); |
| 122524 | |
| 122525 | assert( pIdxInfo->idxStr==0 ); |
| 122526 | for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(sizeof(zIdxStr)-1); ii++){ |
| 122527 | struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii]; |
| 122528 | |
| 122529 | if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ |
| 122530 | /* We have an equality constraint on the rowid. Use strategy 1. */ |
| 122531 | int jj; |
| @@ -124644,10 +124627,12 @@ | |
| 124644 | static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 124645 | UErrorCode status = U_ZERO_ERROR; |
| 124646 | URegularExpression *pExpr; |
| 124647 | UBool res; |
| 124648 | const UChar *zString = sqlite3_value_text16(apArg[1]); |
| 124649 | |
| 124650 | /* If the left hand side of the regexp operator is NULL, |
| 124651 | ** then the result is also NULL. |
| 124652 | */ |
| 124653 | if( !zString ){ |
| @@ -124873,11 +124858,11 @@ | |
| 124873 | }; |
| 124874 | |
| 124875 | int rc = SQLITE_OK; |
| 124876 | int i; |
| 124877 | |
| 124878 | for(i=0; rc==SQLITE_OK && i<(sizeof(scalars)/sizeof(struct IcuScalar)); i++){ |
| 124879 | struct IcuScalar *p = &scalars[i]; |
| 124880 | rc = sqlite3_create_function( |
| 124881 | db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0 |
| 124882 | ); |
| 124883 | } |
| 124884 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -650,11 +650,11 @@ | |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | #define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -1675,11 +1675,11 @@ | |
| 1675 | ** changes to a [database connection]. The interface is similar to |
| 1676 | ** [sqlite3_config()] except that the changes apply to a single |
| 1677 | ** [database connection] (specified in the first argument). |
| 1678 | ** |
| 1679 | ** The second argument to sqlite3_db_config(D,V,...) is the |
| 1680 | ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code |
| 1681 | ** that indicates what aspect of the [database connection] is being configured. |
| 1682 | ** Subsequent arguments vary depending on the configuration verb. |
| 1683 | ** |
| 1684 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1685 | ** the call is considered successful. |
| @@ -7833,22 +7833,22 @@ | |
| 7833 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); |
| 7834 | #ifndef NDEBUG |
| 7835 | /* These routines are used inside assert() statements only. */ |
| 7836 | SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); |
| 7837 | SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); |
| 7838 | SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); |
| 7839 | #endif |
| 7840 | #else |
| 7841 | |
| 7842 | # define sqlite3BtreeLeave(X) |
| 7843 | # define sqlite3BtreeEnterCursor(X) |
| 7844 | # define sqlite3BtreeLeaveCursor(X) |
| 7845 | # define sqlite3BtreeLeaveAll(X) |
| 7846 | |
| 7847 | # define sqlite3BtreeHoldsMutex(X) 1 |
| 7848 | # define sqlite3BtreeHoldsAllMutexes(X) 1 |
| 7849 | # define sqlite3SchemaMutexHeld(X,Y,Z) 1 |
| 7850 | #endif |
| 7851 | |
| 7852 | |
| 7853 | #endif /* _BTREE_H_ */ |
| 7854 | |
| @@ -7963,11 +7963,11 @@ | |
| 7963 | #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ |
| 7964 | #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ |
| 7965 | #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */ |
| 7966 | #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */ |
| 7967 | #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ |
| 7968 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 7969 | #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 7970 | #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ |
| 7971 | #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| 7972 | #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ |
| 7973 | #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ |
| @@ -8998,10 +8998,24 @@ | |
| 8998 | Schema *pSchema; /* Pointer to database schema (possibly shared) */ |
| 8999 | }; |
| 9000 | |
| 9001 | /* |
| 9002 | ** An instance of the following structure stores a database schema. |
| 9003 | ** |
| 9004 | ** Most Schema objects are associated with a Btree. The exception is |
| 9005 | ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing. |
| 9006 | ** In shared cache mode, a single Schema object can be shared by multiple |
| 9007 | ** Btrees that refer to the same underlying BtShared object. |
| 9008 | ** |
| 9009 | ** Schema objects are automatically deallocated when the last Btree that |
| 9010 | ** references them is destroyed. The TEMP Schema is manually freed by |
| 9011 | ** sqlite3_close(). |
| 9012 | * |
| 9013 | ** A thread must be holding a mutex on the corresponding Btree in order |
| 9014 | ** to access Schema content. This implies that the thread must also be |
| 9015 | ** holding a mutex on the sqlite3 connection pointer that owns the Btree. |
| 9016 | ** For a TEMP Schema, on the connection mutex is required. |
| 9017 | */ |
| 9018 | struct Schema { |
| 9019 | int schema_cookie; /* Database schema version number for this file */ |
| 9020 | int iGeneration; /* Generation counter. Incremented with each change */ |
| 9021 | Hash tblHash; /* All tables indexed by name */ |
| @@ -9514,11 +9528,11 @@ | |
| 9528 | ** implementation. sqlite3_vtab* handles can not be shared between |
| 9529 | ** database connections, even when the rest of the in-memory database |
| 9530 | ** schema is shared, as the implementation often stores the database |
| 9531 | ** connection handle passed to it via the xConnect() or xCreate() method |
| 9532 | ** during initialization internally. This database connection handle may |
| 9533 | ** then be used by the virtual table implementation to access real tables |
| 9534 | ** within the database. So that they appear as part of the callers |
| 9535 | ** transaction, these accesses need to be made via the same database |
| 9536 | ** connection as that used to execute SQL operations on the virtual table. |
| 9537 | ** |
| 9538 | ** All VTable objects that correspond to a single table in a shared |
| @@ -11272,11 +11286,11 @@ | |
| 11286 | SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions; |
| 11287 | #ifndef SQLITE_OMIT_WSD |
| 11288 | SQLITE_PRIVATE int sqlite3PendingByte; |
| 11289 | #endif |
| 11290 | #endif |
| 11291 | SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int); |
| 11292 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 11293 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 11294 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 11295 | SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *); |
| 11296 | SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| @@ -11299,11 +11313,11 @@ | |
| 11313 | SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*); |
| 11314 | SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*); |
| 11315 | SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int); |
| 11316 | SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3*,Expr*,int*,char*); |
| 11317 | SQLITE_PRIVATE void sqlite3MinimumFileFormat(Parse*, int, int); |
| 11318 | SQLITE_PRIVATE void sqlite3SchemaClear(void *); |
| 11319 | SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *, Btree *); |
| 11320 | SQLITE_PRIVATE int sqlite3SchemaToIndex(sqlite3 *db, Schema *); |
| 11321 | SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *); |
| 11322 | SQLITE_PRIVATE int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, |
| 11323 | void (*)(sqlite3_context*,int,sqlite3_value **), |
| @@ -12479,11 +12493,10 @@ | |
| 12493 | u8 usesStmtJournal; /* True if uses a statement journal */ |
| 12494 | u8 readOnly; /* True for read-only statements */ |
| 12495 | u8 isPrepareV2; /* True if prepared with prepare_v2() */ |
| 12496 | int nChange; /* Number of db changes made since last reset */ |
| 12497 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 12498 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 12499 | int aCounter[3]; /* Counters used by sqlite3_stmt_status() */ |
| 12500 | #ifndef SQLITE_OMIT_TRACE |
| 12501 | i64 startTime; /* Time when query started - used for profiling */ |
| 12502 | #endif |
| @@ -12563,13 +12576,18 @@ | |
| 12576 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 12577 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 12578 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 12579 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 12580 | SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem); |
| 12581 | |
| 12582 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 |
| 12583 | SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe*); |
| 12584 | SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe*); |
| 12585 | #else |
| 12586 | # define sqlite3VdbeEnter(X) |
| 12587 | # define sqlite3VdbeLeave(X) |
| 12588 | #endif |
| 12589 | |
| 12590 | #ifdef SQLITE_DEBUG |
| 12591 | SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); |
| 12592 | #endif |
| 12593 | |
| @@ -12742,10 +12760,11 @@ | |
| 12760 | */ |
| 12761 | case SQLITE_DBSTATUS_SCHEMA_USED: { |
| 12762 | int i; /* Used to iterate through schemas */ |
| 12763 | int nByte = 0; /* Used to accumulate return value */ |
| 12764 | |
| 12765 | sqlite3BtreeEnterAll(db); |
| 12766 | db->pnBytesFreed = &nByte; |
| 12767 | for(i=0; i<db->nDb; i++){ |
| 12768 | Schema *pSchema = db->aDb[i].pSchema; |
| 12769 | if( ALWAYS(pSchema!=0) ){ |
| 12770 | HashElem *p; |
| @@ -12768,10 +12787,11 @@ | |
| 12787 | sqlite3DeleteTable(db, (Table *)sqliteHashData(p)); |
| 12788 | } |
| 12789 | } |
| 12790 | } |
| 12791 | db->pnBytesFreed = 0; |
| 12792 | sqlite3BtreeLeaveAll(db); |
| 12793 | |
| 12794 | *pHighwater = 0; |
| 12795 | *pCurrent = nByte; |
| 12796 | break; |
| 12797 | } |
| @@ -15879,11 +15899,11 @@ | |
| 15899 | ** Space for tracking which blocks are checked out and the size |
| 15900 | ** of each block. One byte per block. |
| 15901 | */ |
| 15902 | u8 *aCtrl; |
| 15903 | |
| 15904 | } mem5; |
| 15905 | |
| 15906 | /* |
| 15907 | ** Access the static variable through a macro for SQLITE_OMIT_WSD |
| 15908 | */ |
| 15909 | #define mem5 GLOBAL(struct Mem5Global, mem5) |
| @@ -16194,11 +16214,11 @@ | |
| 16214 | ** memsys5Log(8) -> 3 |
| 16215 | ** memsys5Log(9) -> 4 |
| 16216 | */ |
| 16217 | static int memsys5Log(int iValue){ |
| 16218 | int iLog; |
| 16219 | for(iLog=0; (iLog<(int)((sizeof(int)*8)-1)) && (1<<iLog)<iValue; iLog++); |
| 16220 | return iLog; |
| 16221 | } |
| 16222 | |
| 16223 | /* |
| 16224 | ** Initialize the memory allocator. |
| @@ -18064,11 +18084,11 @@ | |
| 18084 | pSlot = (ScratchFreeslot*)p; |
| 18085 | sqlite3_mutex_enter(mem0.mutex); |
| 18086 | pSlot->pNext = mem0.pScratchFree; |
| 18087 | mem0.pScratchFree = pSlot; |
| 18088 | mem0.nScratchFree++; |
| 18089 | assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch ); |
| 18090 | sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1); |
| 18091 | sqlite3_mutex_leave(mem0.mutex); |
| 18092 | }else{ |
| 18093 | /* Release memory back to the heap */ |
| 18094 | assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) ); |
| @@ -38547,10 +38567,23 @@ | |
| 38567 | /* Verify that the page list is in accending order */ |
| 38568 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 38569 | assert( p->pgno < p->pDirty->pgno ); |
| 38570 | } |
| 38571 | #endif |
| 38572 | |
| 38573 | if( isCommit ){ |
| 38574 | /* If a WAL transaction is being committed, there is no point in writing |
| 38575 | ** any pages with page numbers greater than nTruncate into the WAL file. |
| 38576 | ** They will never be read by any client. So remove them from the pDirty |
| 38577 | ** list here. */ |
| 38578 | PgHdr *p; |
| 38579 | PgHdr **ppNext = &pList; |
| 38580 | for(p=pList; (*ppNext = p); p=p->pDirty){ |
| 38581 | if( p->pgno<=nTruncate ) ppNext = &p->pDirty; |
| 38582 | } |
| 38583 | assert( pList ); |
| 38584 | } |
| 38585 | |
| 38586 | if( pList->pgno==1 ) pager_write_changecounter(pList); |
| 38587 | rc = sqlite3WalFrames(pPager->pWal, |
| 38588 | pPager->pageSize, pList, nTruncate, isCommit, syncFlags |
| 38589 | ); |
| @@ -38560,10 +38593,11 @@ | |
| 38593 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 38594 | } |
| 38595 | } |
| 38596 | |
| 38597 | #ifdef SQLITE_CHECK_PAGES |
| 38598 | pList = sqlite3PcacheDirtyList(pPager->pPCache); |
| 38599 | for(p=pList; p; p=p->pDirty){ |
| 38600 | pager_set_pagehash(p); |
| 38601 | } |
| 38602 | #endif |
| 38603 | |
| @@ -45510,11 +45544,11 @@ | |
| 45544 | |
| 45545 | |
| 45546 | /* The following value is the maximum cell size assuming a maximum page |
| 45547 | ** size give above. |
| 45548 | */ |
| 45549 | #define MX_CELL_SIZE(pBt) ((int)(pBt->pageSize-8)) |
| 45550 | |
| 45551 | /* The maximum number of cells on a single page of the database. This |
| 45552 | ** assumes a minimum cell size of 6 bytes (4 bytes for the cell itself |
| 45553 | ** plus 2 bytes for the index to the cell in the page header). Such |
| 45554 | ** small cells will be rare, but they are possible. |
| @@ -45727,11 +45761,10 @@ | |
| 45761 | BtShared *pNext; /* Next on a list of sharable BtShared structs */ |
| 45762 | BtLock *pLock; /* List of locks held on this shared-btree struct */ |
| 45763 | Btree *pWriter; /* Btree with currently open write transaction */ |
| 45764 | u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */ |
| 45765 | u8 isPending; /* If waiting for read-locks to clear */ |
| 45766 | #endif |
| 45767 | u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */ |
| 45768 | }; |
| 45769 | |
| 45770 | /* |
| @@ -45966,32 +45999,14 @@ | |
| 45999 | assert( p->locked==1 ); |
| 46000 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 46001 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 46002 | assert( p->db==pBt->db ); |
| 46003 | |
| 46004 | sqlite3_mutex_leave(pBt->mutex); |
| 46005 | p->locked = 0; |
| 46006 | } |
| 46007 | |
| 46008 | /* |
| 46009 | ** Enter a mutex on the given BTree object. |
| 46010 | ** |
| 46011 | ** If the object is not sharable, then no mutex is ever required |
| 46012 | ** and this routine is a no-op. The underlying mutex is non-recursive. |
| @@ -46032,28 +46047,10 @@ | |
| 46047 | |
| 46048 | if( !p->sharable ) return; |
| 46049 | p->wantToLock++; |
| 46050 | if( p->locked ) return; |
| 46051 | |
| 46052 | /* In most cases, we should be able to acquire the lock we |
| 46053 | ** want without having to go throught the ascending lock |
| 46054 | ** procedure that follows. Just be sure not to block. |
| 46055 | */ |
| 46056 | if( sqlite3_mutex_try(p->pBt->mutex)==SQLITE_OK ){ |
| @@ -46143,49 +46140,24 @@ | |
| 46140 | ** two or more btrees in common both try to lock all their btrees |
| 46141 | ** at the same instant. |
| 46142 | */ |
| 46143 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 46144 | int i; |
| 46145 | Btree *p; |
| 46146 | assert( sqlite3_mutex_held(db->mutex) ); |
| 46147 | for(i=0; i<db->nDb; i++){ |
| 46148 | p = db->aDb[i].pBt; |
| 46149 | if( p ) sqlite3BtreeEnter(p); |
| 46150 | } |
| 46151 | } |
| 46152 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){ |
| 46153 | int i; |
| 46154 | Btree *p; |
| 46155 | assert( sqlite3_mutex_held(db->mutex) ); |
| 46156 | for(i=0; i<db->nDb; i++){ |
| 46157 | p = db->aDb[i].pBt; |
| 46158 | if( p ) sqlite3BtreeLeave(p); |
| 46159 | } |
| 46160 | } |
| 46161 | |
| 46162 | #ifndef NDEBUG |
| 46163 | /* |
| @@ -46209,10 +46181,35 @@ | |
| 46181 | } |
| 46182 | return 1; |
| 46183 | } |
| 46184 | #endif /* NDEBUG */ |
| 46185 | |
| 46186 | #ifndef NDEBUG |
| 46187 | /* |
| 46188 | ** Return true if the correct mutexes are held for accessing the |
| 46189 | ** db->aDb[iDb].pSchema structure. The mutexes required for schema |
| 46190 | ** access are: |
| 46191 | ** |
| 46192 | ** (1) The mutex on db |
| 46193 | ** (2) if iDb!=1, then the mutex on db->aDb[iDb].pBt. |
| 46194 | ** |
| 46195 | ** If pSchema is not NULL, then iDb is computed from pSchema and |
| 46196 | ** db using sqlite3SchemaToIndex(). |
| 46197 | */ |
| 46198 | SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){ |
| 46199 | Btree *p; |
| 46200 | assert( db!=0 ); |
| 46201 | if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema); |
| 46202 | assert( iDb>=0 && iDb<db->nDb ); |
| 46203 | if( !sqlite3_mutex_held(db->mutex) ) return 0; |
| 46204 | if( iDb==1 ) return 1; |
| 46205 | p = db->aDb[iDb].pBt; |
| 46206 | assert( p!=0 ); |
| 46207 | return p->sharable==0 || p->locked==1; |
| 46208 | } |
| 46209 | #endif /* NDEBUG */ |
| 46210 | |
| 46211 | #else /* SQLITE_THREADSAFE>0 above. SQLITE_THREADSAFE==0 below */ |
| 46212 | /* |
| 46213 | ** The following are special cases for mutex enter routines for use |
| 46214 | ** in single threaded applications that use shared cache. Except for |
| 46215 | ** these two routines, all mutex operations are no-ops in that case and |
| @@ -47466,11 +47463,11 @@ | |
| 47463 | ** is no way that the allocation can extend off the end of the page. |
| 47464 | ** The assert() below verifies the previous sentence. |
| 47465 | */ |
| 47466 | top -= nByte; |
| 47467 | put2byte(&data[hdr+5], top); |
| 47468 | assert( top+nByte <= (int)pPage->pBt->usableSize ); |
| 47469 | *pIdx = top; |
| 47470 | return SQLITE_OK; |
| 47471 | } |
| 47472 | |
| 47473 | /* |
| @@ -47487,11 +47484,11 @@ | |
| 47484 | unsigned char *data = pPage->aData; |
| 47485 | |
| 47486 | assert( pPage->pBt!=0 ); |
| 47487 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 47488 | assert( start>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 47489 | assert( (start + size) <= (int)pPage->pBt->usableSize ); |
| 47490 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 47491 | assert( size>=0 ); /* Minimum cell size is 4 */ |
| 47492 | |
| 47493 | if( pPage->pBt->secureDelete ){ |
| 47494 | /* Overwrite deleted information with zeros when the secure_delete |
| @@ -47530,11 +47527,11 @@ | |
| 47527 | /* Coalesce adjacent free blocks */ |
| 47528 | addr = hdr + 1; |
| 47529 | while( (pbegin = get2byte(&data[addr]))>0 ){ |
| 47530 | int pnext, psize, x; |
| 47531 | assert( pbegin>addr ); |
| 47532 | assert( pbegin <= (int)pPage->pBt->usableSize-4 ); |
| 47533 | pnext = get2byte(&data[pbegin]); |
| 47534 | psize = get2byte(&data[pbegin+2]); |
| 47535 | if( pbegin + psize + 3 >= pnext && pnext>0 ){ |
| 47536 | int frag = pnext - (pbegin+psize); |
| 47537 | if( (frag<0) || (frag>(int)data[hdr+7]) ){ |
| @@ -51737,11 +51734,11 @@ | |
| 51734 | rc = allocateSpace(pPage, sz, &idx); |
| 51735 | if( rc ){ *pRC = rc; return; } |
| 51736 | /* The allocateSpace() routine guarantees the following two properties |
| 51737 | ** if it returns success */ |
| 51738 | assert( idx >= end+2 ); |
| 51739 | assert( idx+sz <= (int)pPage->pBt->usableSize ); |
| 51740 | pPage->nCell++; |
| 51741 | pPage->nFree -= (u16)(2 + sz); |
| 51742 | memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip); |
| 51743 | if( iChild ){ |
| 51744 | put4byte(&data[idx], iChild); |
| @@ -51780,11 +51777,12 @@ | |
| 51777 | const int hdr = pPage->hdrOffset; /* Offset of header on pPage */ |
| 51778 | const int nUsable = pPage->pBt->usableSize; /* Usable size of page */ |
| 51779 | |
| 51780 | assert( pPage->nOverflow==0 ); |
| 51781 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 51782 | assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt) |
| 51783 | && (int)MX_CELL(pPage->pBt)<=10921); |
| 51784 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 51785 | |
| 51786 | /* Check that the page has just been zeroed by zeroPage() */ |
| 51787 | assert( pPage->nCell==0 ); |
| 51788 | assert( get2byteNotZero(&data[hdr+5])==nUsable ); |
| @@ -51994,11 +51992,11 @@ | |
| 51992 | int iData; |
| 51993 | |
| 51994 | |
| 51995 | assert( pFrom->isInit ); |
| 51996 | assert( pFrom->nFree>=iToHdr ); |
| 51997 | assert( get2byte(&aFrom[iFromHdr+5]) <= (int)pBt->usableSize ); |
| 51998 | |
| 51999 | /* Copy the b-tree node content from page pFrom to page pTo. */ |
| 52000 | iData = get2byte(&aFrom[iFromHdr+5]); |
| 52001 | memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData); |
| 52002 | memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell); |
| @@ -52261,11 +52259,11 @@ | |
| 52259 | assert( nCell<nMaxCells ); |
| 52260 | szCell[nCell] = sz; |
| 52261 | pTemp = &aSpace1[iSpace1]; |
| 52262 | iSpace1 += sz; |
| 52263 | assert( sz<=pBt->maxLocal+23 ); |
| 52264 | assert( iSpace1 <= (int)pBt->pageSize ); |
| 52265 | memcpy(pTemp, apDiv[i], sz); |
| 52266 | apCell[nCell] = pTemp+leafCorrection; |
| 52267 | assert( leafCorrection==0 || leafCorrection==4 ); |
| 52268 | szCell[nCell] = szCell[nCell] - leafCorrection; |
| 52269 | if( !pOld->leaf ){ |
| @@ -52505,11 +52503,11 @@ | |
| 52503 | sz = cellSizePtr(pParent, pCell); |
| 52504 | } |
| 52505 | } |
| 52506 | iOvflSpace += sz; |
| 52507 | assert( sz<=pBt->maxLocal+23 ); |
| 52508 | assert( iOvflSpace <= (int)pBt->pageSize ); |
| 52509 | insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc); |
| 52510 | if( rc!=SQLITE_OK ) goto balance_cleanup; |
| 52511 | assert( sqlite3PagerIswriteable(pParent->pDbPage) ); |
| 52512 | |
| 52513 | j++; |
| @@ -52950,11 +52948,11 @@ | |
| 52948 | newCell = pBt->pTmpSpace; |
| 52949 | if( newCell==0 ) return SQLITE_NOMEM; |
| 52950 | rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew); |
| 52951 | if( rc ) goto end_insert; |
| 52952 | assert( szNew==cellSizePtr(pPage, newCell) ); |
| 52953 | assert( szNew <= MX_CELL_SIZE(pBt) ); |
| 52954 | idx = pCur->aiIdx[pCur->iPage]; |
| 52955 | if( loc==0 ){ |
| 52956 | u16 szOld; |
| 52957 | assert( idx<pPage->nCell ); |
| 52958 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| @@ -53090,11 +53088,11 @@ | |
| 53088 | Pgno n = pCur->apPage[iCellDepth+1]->pgno; |
| 53089 | unsigned char *pTmp; |
| 53090 | |
| 53091 | pCell = findCell(pLeaf, pLeaf->nCell-1); |
| 53092 | nCell = cellSizePtr(pLeaf, pCell); |
| 53093 | assert( MX_CELL_SIZE(pBt) >= nCell ); |
| 53094 | |
| 53095 | allocateTempSpace(pBt); |
| 53096 | pTmp = pBt->pTmpSpace; |
| 53097 | |
| 53098 | rc = sqlite3PagerWrite(pLeaf->pDbPage); |
| @@ -54784,11 +54782,11 @@ | |
| 54782 | && (rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1))==SQLITE_OK |
| 54783 | ){ |
| 54784 | int nDestTruncate; |
| 54785 | |
| 54786 | if( p->pDestDb ){ |
| 54787 | sqlite3ResetInternalSchema(p->pDestDb, -1); |
| 54788 | } |
| 54789 | |
| 54790 | /* Set nDestTruncate to the final number of pages in the destination |
| 54791 | ** database. The complication here is that the destination page |
| 54792 | ** size may be different to the source page size. |
| @@ -57181,40 +57179,16 @@ | |
| 57179 | ** The prepared statements need to know in advance the complete set of |
| 57180 | ** attached databases that they will be using. A mask of these databases |
| 57181 | ** is maintained in p->btreeMask and is used for locking and other purposes. |
| 57182 | */ |
| 57183 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){ |
| 57184 | assert( i>=0 && i<p->db->nDb && i<(int)sizeof(yDbMask)*8 ); |
| 57185 | assert( i<(int)sizeof(p->btreeMask)*8 ); |
| 57186 | p->btreeMask |= ((yDbMask)1)<<i; |
| 57187 | } |
| 57188 | |
| 57189 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 |
| 57190 | /* |
| 57191 | ** If SQLite is compiled to support shared-cache mode and to be threadsafe, |
| 57192 | ** this routine obtains the mutex associated with each BtShared structure |
| 57193 | ** that may be accessed by the VM passed as an argument. In doing so it also |
| 57194 | ** sets the BtShared.db member of each of the BtShared structures, ensuring |
| @@ -57233,11 +57207,10 @@ | |
| 57207 | ** corresponding to btrees that use shared cache. Then the runtime of |
| 57208 | ** this routine is N*N. But as N is rarely more than 1, this should not |
| 57209 | ** be a problem. |
| 57210 | */ |
| 57211 | SQLITE_PRIVATE void sqlite3VdbeEnter(Vdbe *p){ |
| 57212 | int i; |
| 57213 | yDbMask mask; |
| 57214 | sqlite3 *db = p->db; |
| 57215 | Db *aDb = db->aDb; |
| 57216 | int nDb = db->nDb; |
| @@ -57244,67 +57217,31 @@ | |
| 57217 | for(i=0, mask=1; i<nDb; i++, mask += mask){ |
| 57218 | if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ |
| 57219 | sqlite3BtreeEnter(aDb[i].pBt); |
| 57220 | } |
| 57221 | } |
| 57222 | } |
| 57223 | #endif |
| 57224 | |
| 57225 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 |
| 57226 | /* |
| 57227 | ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter(). |
| 57228 | */ |
| 57229 | SQLITE_PRIVATE void sqlite3VdbeLeave(Vdbe *p){ |
| 57230 | int i; |
| 57231 | yDbMask mask; |
| 57232 | sqlite3 *db = p->db; |
| 57233 | Db *aDb = db->aDb; |
| 57234 | int nDb = db->nDb; |
| 57235 | |
| 57236 | for(i=0, mask=1; i<nDb; i++, mask += mask){ |
| 57237 | if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ |
| 57238 | sqlite3BtreeLeave(aDb[i].pBt); |
| 57239 | } |
| 57240 | } |
| 57241 | } |
| 57242 | #endif |
| 57243 | |
| 57244 | #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) |
| 57245 | /* |
| 57246 | ** Print a single opcode. This routine is used for debugging only. |
| 57247 | */ |
| @@ -58504,16 +58441,15 @@ | |
| 58441 | p->nChange = 0; |
| 58442 | } |
| 58443 | |
| 58444 | /* Rollback or commit any schema changes that occurred. */ |
| 58445 | if( p->rc!=SQLITE_OK && db->flags&SQLITE_InternChanges ){ |
| 58446 | sqlite3ResetInternalSchema(db, -1); |
| 58447 | db->flags = (db->flags | SQLITE_InternChanges); |
| 58448 | } |
| 58449 | |
| 58450 | /* Release the locks */ |
| 58451 | sqlite3VdbeLeave(p); |
| 58452 | } |
| 58453 | |
| 58454 | /* We have successfully halted and closed the VM. Record this fact. */ |
| 58455 | if( p->pc>=0 ){ |
| @@ -60190,11 +60126,15 @@ | |
| 60126 | ** __attribute__((aligned(8))) macro. */ |
| 60127 | static const Mem nullMem |
| 60128 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 60129 | __attribute__((aligned(8))) |
| 60130 | #endif |
| 60131 | = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, |
| 60132 | #ifdef SQLITE_DEBUG |
| 60133 | 0, 0, /* pScopyFrom, pFiller */ |
| 60134 | #endif |
| 60135 | 0, 0 }; |
| 60136 | |
| 60137 | if( pVm && ALWAYS(pVm->db) ){ |
| 60138 | sqlite3_mutex_enter(pVm->db->mutex); |
| 60139 | sqlite3Error(pVm->db, SQLITE_RANGE, 0); |
| 60140 | } |
| @@ -61604,11 +61544,11 @@ | |
| 61544 | int pc=0; /* The program counter */ |
| 61545 | Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 61546 | Op *pOp; /* Current operation */ |
| 61547 | int rc = SQLITE_OK; /* Value to return */ |
| 61548 | sqlite3 *db = p->db; /* The database */ |
| 61549 | u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 61550 | u8 encoding = ENC(db); /* The database encoding */ |
| 61551 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 61552 | int checkProgress; /* True if progress callbacks are enabled */ |
| 61553 | int nProgressOps = 0; /* Opcodes executed since progress callback. */ |
| 61554 | #endif |
| @@ -62868,11 +62808,10 @@ | |
| 62808 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 62809 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 62810 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 62811 | } |
| 62812 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 62813 | if( db->mallocFailed ){ |
| 62814 | /* Even though a malloc() has failed, the implementation of the |
| 62815 | ** user function may have called an sqlite3_result_XXX() function |
| 62816 | ** to return a value. The following call releases any resources |
| 62817 | ** associated with such a value. |
| @@ -62879,21 +62818,10 @@ | |
| 62818 | */ |
| 62819 | sqlite3VdbeMemRelease(&u.ag.ctx.s); |
| 62820 | goto no_mem; |
| 62821 | } |
| 62822 | |
| 62823 | /* If any auxiliary data functions have been called by this user function, |
| 62824 | ** immediately call the destructor for any non-static values. |
| 62825 | */ |
| 62826 | if( u.ag.ctx.pVdbeFunc ){ |
| 62827 | sqlite3VdbeDeleteAuxData(u.ag.ctx.pVdbeFunc, pOp->p1); |
| @@ -62911,10 +62839,19 @@ | |
| 62839 | sqlite3VdbeChangeEncoding(&u.ag.ctx.s, encoding); |
| 62840 | sqlite3VdbeMemMove(pOut, &u.ag.ctx.s); |
| 62841 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 62842 | goto too_big; |
| 62843 | } |
| 62844 | |
| 62845 | #if 0 |
| 62846 | /* The app-defined function has done something that as caused this |
| 62847 | ** statement to expire. (Perhaps the function called sqlite3_exec() |
| 62848 | ** with a CREATE TABLE statement.) |
| 62849 | */ |
| 62850 | if( p->expired ) rc = SQLITE_ABORT; |
| 62851 | #endif |
| 62852 | |
| 62853 | REGISTER_TRACE(pOp->p3, pOut); |
| 62854 | UPDATE_MAX_BLOBSIZE(pOut); |
| 62855 | break; |
| 62856 | } |
| 62857 | |
| @@ -64155,12 +64092,11 @@ | |
| 64092 | goto abort_due_to_error; |
| 64093 | } |
| 64094 | } |
| 64095 | if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 64096 | sqlite3ExpirePreparedStatements(db); |
| 64097 | sqlite3ResetInternalSchema(db, -1); |
| 64098 | db->flags = (db->flags | SQLITE_InternChanges); |
| 64099 | } |
| 64100 | } |
| 64101 | |
| 64102 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| @@ -64384,10 +64320,11 @@ | |
| 64320 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 64321 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64322 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 64323 | u.au.pDb = &db->aDb[pOp->p1]; |
| 64324 | assert( u.au.pDb->pBt!=0 ); |
| 64325 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 64326 | pIn3 = &aMem[pOp->p3]; |
| 64327 | sqlite3VdbeMemIntegerify(pIn3); |
| 64328 | /* See note about index shifting on OP_ReadCookie */ |
| 64329 | rc = sqlite3BtreeUpdateMeta(u.au.pDb->pBt, pOp->p2, (int)pIn3->u.i); |
| 64330 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| @@ -64432,16 +64369,17 @@ | |
| 64369 | Btree *pBt; |
| 64370 | #endif /* local variables moved into u.av */ |
| 64371 | |
| 64372 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64373 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 64374 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 64375 | u.av.pBt = db->aDb[pOp->p1].pBt; |
| 64376 | if( u.av.pBt ){ |
| 64377 | sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta); |
| 64378 | u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 64379 | }else{ |
| 64380 | u.av.iGen = u.av.iMeta = 0; |
| 64381 | } |
| 64382 | if( u.av.iMeta!=pOp->p2 || u.av.iGen!=pOp->p3 ){ |
| 64383 | sqlite3DbFree(db, p->zErrMsg); |
| 64384 | p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 64385 | /* If the schema-cookie from the database file matches the cookie |
| @@ -64457,11 +64395,10 @@ | |
| 64395 | ** to be invalidated whenever sqlite3_step() is called from within |
| 64396 | ** a v-table method. |
| 64397 | */ |
| 64398 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){ |
| 64399 | sqlite3ResetInternalSchema(db, pOp->p1); |
| 64400 | } |
| 64401 | |
| 64402 | p->expired = 1; |
| 64403 | rc = SQLITE_SCHEMA; |
| 64404 | } |
| @@ -64544,10 +64481,11 @@ | |
| 64481 | u.aw.pDb = &db->aDb[u.aw.iDb]; |
| 64482 | u.aw.pX = u.aw.pDb->pBt; |
| 64483 | assert( u.aw.pX!=0 ); |
| 64484 | if( pOp->opcode==OP_OpenWrite ){ |
| 64485 | u.aw.wrFlag = 1; |
| 64486 | assert( sqlite3SchemaMutexHeld(db, u.aw.iDb, 0) ); |
| 64487 | if( u.aw.pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 64488 | p->minWriteFileFormat = u.aw.pDb->pSchema->file_format; |
| 64489 | } |
| 64490 | }else{ |
| 64491 | u.aw.wrFlag = 0; |
| @@ -66081,12 +66019,14 @@ | |
| 66019 | rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved); |
| 66020 | pOut->flags = MEM_Int; |
| 66021 | pOut->u.i = u.br.iMoved; |
| 66022 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 66023 | if( rc==SQLITE_OK && u.br.iMoved!=0 ){ |
| 66024 | sqlite3RootPageMoved(db, u.br.iDb, u.br.iMoved, pOp->p1); |
| 66025 | /* All OP_Destroy operations occur on the same btree */ |
| 66026 | assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.br.iDb+1 ); |
| 66027 | resetSchemaOnFault = u.br.iDb+1; |
| 66028 | } |
| 66029 | #endif |
| 66030 | } |
| 66031 | break; |
| 66032 | } |
| @@ -66764,27 +66704,15 @@ | |
| 66704 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66705 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66706 | u.cb.ctx.pColl = pOp[-1].p4.pColl; |
| 66707 | } |
| 66708 | (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */ |
| 66709 | if( u.cb.ctx.isError ){ |
| 66710 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s)); |
| 66711 | rc = u.cb.ctx.isError; |
| 66712 | } |
| 66713 | |
| 66714 | sqlite3VdbeMemRelease(&u.cb.ctx.s); |
| 66715 | |
| 66716 | break; |
| 66717 | } |
| 66718 | |
| @@ -66806,15 +66734,12 @@ | |
| 66734 | #endif /* local variables moved into u.cc */ |
| 66735 | assert( pOp->p1>0 && pOp->p1<=p->nMem ); |
| 66736 | u.cc.pMem = &aMem[pOp->p1]; |
| 66737 | assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 66738 | rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc); |
| 66739 | if( rc ){ |
| 66740 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem)); |
| 66741 | } |
| 66742 | sqlite3VdbeChangeEncoding(u.cc.pMem, encoding); |
| 66743 | UPDATE_MAX_BLOBSIZE(u.cc.pMem); |
| 66744 | if( sqlite3VdbeMemTooBig(u.cc.pMem) ){ |
| 66745 | goto too_big; |
| @@ -66889,28 +66814,10 @@ | |
| 66814 | || u.ce.eNew==PAGER_JOURNALMODE_WAL |
| 66815 | || u.ce.eNew==PAGER_JOURNALMODE_QUERY |
| 66816 | ); |
| 66817 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66818 | |
| 66819 | u.ce.pBt = db->aDb[pOp->p1].pBt; |
| 66820 | u.ce.pPager = sqlite3BtreePager(u.ce.pBt); |
| 66821 | u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager); |
| 66822 | if( u.ce.eNew==PAGER_JOURNALMODE_QUERY ) u.ce.eNew = u.ce.eOld; |
| 66823 | if( !sqlite3PagerOkToChangeJournalMode(u.ce.pPager) ) u.ce.eNew = u.ce.eOld; |
| @@ -67560,13 +67467,12 @@ | |
| 67467 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 67468 | pc, p->zSql, p->zErrMsg); |
| 67469 | sqlite3VdbeHalt(p); |
| 67470 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 67471 | rc = SQLITE_ERROR; |
| 67472 | if( resetSchemaOnFault>0 ){ |
| 67473 | sqlite3ResetInternalSchema(db, resetSchemaOnFault-1); |
| 67474 | } |
| 67475 | |
| 67476 | /* This is the only way out of this procedure. We have to |
| 67477 | ** release the mutexes on btrees that were acquired at the |
| 67478 | ** top. */ |
| @@ -72266,11 +72172,11 @@ | |
| 72172 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 72173 | assert( pExpr->u.zToken!=0 ); |
| 72174 | assert( pExpr->u.zToken[0]!=0 ); |
| 72175 | sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target); |
| 72176 | if( pExpr->u.zToken[1]!=0 ){ |
| 72177 | sqlite3VdbeChangeP4(v, -1, pExpr->u.zToken, P4_TRANSIENT); |
| 72178 | } |
| 72179 | break; |
| 72180 | } |
| 72181 | case TK_REGISTER: { |
| 72182 | inReg = pExpr->iTable; |
| @@ -74655,10 +74561,11 @@ | |
| 74561 | return; |
| 74562 | } |
| 74563 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 74564 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 74565 | assert( iDb>=0 ); |
| 74566 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 74567 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 74568 | if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0, |
| 74569 | db->aDb[iDb].zName ) ){ |
| 74570 | return; |
| 74571 | } |
| @@ -74896,10 +74803,11 @@ | |
| 74803 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74804 | iStatCur = pParse->nTab; |
| 74805 | pParse->nTab += 2; |
| 74806 | openStatTable(pParse, iDb, iStatCur, 0, 0); |
| 74807 | iMem = pParse->nMem+1; |
| 74808 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 74809 | for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 74810 | Table *pTab = (Table*)sqliteHashData(k); |
| 74811 | analyzeOneTable(pParse, pTab, 0, iStatCur, iMem); |
| 74812 | } |
| 74813 | loadAnalysis(pParse, iDb); |
| @@ -75106,13 +75014,13 @@ | |
| 75014 | char *zSql; |
| 75015 | int rc; |
| 75016 | |
| 75017 | assert( iDb>=0 && iDb<db->nDb ); |
| 75018 | assert( db->aDb[iDb].pBt!=0 ); |
| 75019 | |
| 75020 | /* Clear any prior statistics */ |
| 75021 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 75022 | for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){ |
| 75023 | Index *pIdx = sqliteHashData(i); |
| 75024 | sqlite3DefaultRowEst(pIdx); |
| 75025 | sqlite3DeleteIndexSamples(db, pIdx); |
| 75026 | pIdx->aSample = 0; |
| @@ -75421,11 +75329,11 @@ | |
| 75329 | if( db->aDb[iDb].pBt ){ |
| 75330 | sqlite3BtreeClose(db->aDb[iDb].pBt); |
| 75331 | db->aDb[iDb].pBt = 0; |
| 75332 | db->aDb[iDb].pSchema = 0; |
| 75333 | } |
| 75334 | sqlite3ResetInternalSchema(db, -1); |
| 75335 | db->nDb = iDb; |
| 75336 | if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){ |
| 75337 | db->mallocFailed = 1; |
| 75338 | sqlite3DbFree(db, zErrDyn); |
| 75339 | zErrDyn = sqlite3MPrintf(db, "out of memory"); |
| @@ -75493,11 +75401,11 @@ | |
| 75401 | } |
| 75402 | |
| 75403 | sqlite3BtreeClose(pDb->pBt); |
| 75404 | pDb->pBt = 0; |
| 75405 | pDb->pSchema = 0; |
| 75406 | sqlite3ResetInternalSchema(db, -1); |
| 75407 | return; |
| 75408 | |
| 75409 | detach_error: |
| 75410 | sqlite3_result_error(context, zErr, -1); |
| 75411 | } |
| @@ -76171,10 +76079,11 @@ | |
| 76079 | for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ |
| 76080 | if( (mask & pParse->cookieMask)==0 ) continue; |
| 76081 | sqlite3VdbeUsesBtree(v, iDb); |
| 76082 | sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0); |
| 76083 | if( db->init.busy==0 ){ |
| 76084 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 76085 | sqlite3VdbeAddOp3(v, OP_VerifyCookie, |
| 76086 | iDb, pParse->cookieValue[iDb], |
| 76087 | db->aDb[iDb].pSchema->iGeneration); |
| 76088 | } |
| 76089 | } |
| @@ -76286,13 +76195,16 @@ | |
| 76195 | Table *p = 0; |
| 76196 | int i; |
| 76197 | int nName; |
| 76198 | assert( zName!=0 ); |
| 76199 | nName = sqlite3Strlen30(zName); |
| 76200 | /* All mutexes are required for schema access. Make sure we hold them. */ |
| 76201 | assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 76202 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 76203 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 76204 | if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue; |
| 76205 | assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 76206 | p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName); |
| 76207 | if( p ) break; |
| 76208 | } |
| 76209 | return p; |
| 76210 | } |
| @@ -76348,15 +76260,18 @@ | |
| 76260 | */ |
| 76261 | SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ |
| 76262 | Index *p = 0; |
| 76263 | int i; |
| 76264 | int nName = sqlite3Strlen30(zName); |
| 76265 | /* All mutexes are required for schema access. Make sure we hold them. */ |
| 76266 | assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 76267 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 76268 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 76269 | Schema *pSchema = db->aDb[j].pSchema; |
| 76270 | assert( pSchema ); |
| 76271 | if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue; |
| 76272 | assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 76273 | p = sqlite3HashFind(&pSchema->idxHash, zName, nName); |
| 76274 | if( p ) break; |
| 76275 | } |
| 76276 | return p; |
| 76277 | } |
| @@ -76379,12 +76294,14 @@ | |
| 76294 | ** with the index. |
| 76295 | */ |
| 76296 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){ |
| 76297 | Index *pIndex; |
| 76298 | int len; |
| 76299 | Hash *pHash; |
| 76300 | |
| 76301 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 76302 | pHash = &db->aDb[iDb].pSchema->idxHash; |
| 76303 | len = sqlite3Strlen30(zIdxName); |
| 76304 | pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0); |
| 76305 | if( ALWAYS(pIndex) ){ |
| 76306 | if( pIndex->pTable->pIndex==pIndex ){ |
| 76307 | pIndex->pTable->pIndex = pIndex->pNext; |
| @@ -76408,30 +76325,46 @@ | |
| 76325 | ** a single database. This routine is called to reclaim memory |
| 76326 | ** before the database closes. It is also called during a rollback |
| 76327 | ** if there were schema changes during the transaction or if a |
| 76328 | ** schema-cookie mismatch occurs. |
| 76329 | ** |
| 76330 | ** If iDb<0 then reset the internal schema tables for all database |
| 76331 | ** files. If iDb>=0 then reset the internal schema for only the |
| 76332 | ** single file indicated. |
| 76333 | */ |
| 76334 | SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){ |
| 76335 | int i, j; |
| 76336 | assert( iDb<db->nDb ); |
| 76337 | |
| 76338 | if( iDb>=0 ){ |
| 76339 | /* Case 1: Reset the single schema identified by iDb */ |
| 76340 | Db *pDb = &db->aDb[iDb]; |
| 76341 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 76342 | assert( pDb->pSchema!=0 ); |
| 76343 | sqlite3SchemaClear(pDb->pSchema); |
| 76344 | |
| 76345 | /* If any database other than TEMP is reset, then also reset TEMP |
| 76346 | ** since TEMP might be holding triggers that reference tables in the |
| 76347 | ** other database. |
| 76348 | */ |
| 76349 | if( iDb!=1 ){ |
| 76350 | pDb = &db->aDb[1]; |
| 76351 | assert( pDb->pSchema!=0 ); |
| 76352 | sqlite3SchemaClear(pDb->pSchema); |
| 76353 | } |
| 76354 | return; |
| 76355 | } |
| 76356 | /* Case 2 (from here to the end): Reset all schemas for all attached |
| 76357 | ** databases. */ |
| 76358 | assert( iDb<0 ); |
| 76359 | sqlite3BtreeEnterAll(db); |
| 76360 | for(i=0; i<db->nDb; i++){ |
| 76361 | Db *pDb = &db->aDb[i]; |
| 76362 | if( pDb->pSchema ){ |
| 76363 | sqlite3SchemaClear(pDb->pSchema); |
| 76364 | } |
| 76365 | } |
| 76366 | db->flags &= ~SQLITE_InternChanges; |
| 76367 | sqlite3VtabUnlockList(db); |
| 76368 | sqlite3BtreeLeaveAll(db); |
| 76369 | |
| 76370 | /* If one or more of the auxiliary database files has been closed, |
| @@ -76513,10 +76446,11 @@ | |
| 76446 | if( !db || db->pnBytesFreed==0 ){ |
| 76447 | char *zName = pIndex->zName; |
| 76448 | TESTONLY ( Index *pOld = ) sqlite3HashInsert( |
| 76449 | &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0 |
| 76450 | ); |
| 76451 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); |
| 76452 | assert( pOld==pIndex || pOld==0 ); |
| 76453 | } |
| 76454 | freeIndex(db, pIndex); |
| 76455 | } |
| 76456 | |
| @@ -76547,10 +76481,11 @@ | |
| 76481 | Db *pDb; |
| 76482 | |
| 76483 | assert( db!=0 ); |
| 76484 | assert( iDb>=0 && iDb<db->nDb ); |
| 76485 | assert( zTabName ); |
| 76486 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 76487 | testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */ |
| 76488 | pDb = &db->aDb[iDb]; |
| 76489 | p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, |
| 76490 | sqlite3Strlen30(zTabName),0); |
| 76491 | sqlite3DeleteTable(db, p); |
| @@ -76831,10 +76766,11 @@ | |
| 76766 | ** then record a pointer to this table in the main database structure |
| 76767 | ** so that INSERT can find the table easily. |
| 76768 | */ |
| 76769 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 76770 | if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){ |
| 76771 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 76772 | pTable->pSchema->pSeqTab = pTable; |
| 76773 | } |
| 76774 | #endif |
| 76775 | |
| 76776 | /* Begin generating the code that will insert the table record into |
| @@ -77291,10 +77227,11 @@ | |
| 77227 | */ |
| 77228 | SQLITE_PRIVATE void sqlite3ChangeCookie(Parse *pParse, int iDb){ |
| 77229 | int r1 = sqlite3GetTempReg(pParse); |
| 77230 | sqlite3 *db = pParse->db; |
| 77231 | Vdbe *v = pParse->pVdbe; |
| 77232 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 77233 | sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1); |
| 77234 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1); |
| 77235 | sqlite3ReleaseTempReg(pParse, r1); |
| 77236 | } |
| 77237 | |
| @@ -77398,11 +77335,11 @@ | |
| 77335 | sqlite3_snprintf(n-k, &zStmt[k], zSep); |
| 77336 | k += sqlite3Strlen30(&zStmt[k]); |
| 77337 | zSep = zSep2; |
| 77338 | identPut(zStmt, &k, pCol->zName); |
| 77339 | assert( pCol->affinity-SQLITE_AFF_TEXT >= 0 ); |
| 77340 | assert( pCol->affinity-SQLITE_AFF_TEXT < ArraySize(azType) ); |
| 77341 | testcase( pCol->affinity==SQLITE_AFF_TEXT ); |
| 77342 | testcase( pCol->affinity==SQLITE_AFF_NONE ); |
| 77343 | testcase( pCol->affinity==SQLITE_AFF_NUMERIC ); |
| 77344 | testcase( pCol->affinity==SQLITE_AFF_INTEGER ); |
| 77345 | testcase( pCol->affinity==SQLITE_AFF_REAL ); |
| @@ -77593,10 +77530,11 @@ | |
| 77530 | /* Check to see if we need to create an sqlite_sequence table for |
| 77531 | ** keeping track of autoincrement keys. |
| 77532 | */ |
| 77533 | if( p->tabFlags & TF_Autoincrement ){ |
| 77534 | Db *pDb = &db->aDb[iDb]; |
| 77535 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 77536 | if( pDb->pSchema->pSeqTab==0 ){ |
| 77537 | sqlite3NestedParse(pParse, |
| 77538 | "CREATE TABLE %Q.sqlite_sequence(name,seq)", |
| 77539 | pDb->zName |
| 77540 | ); |
| @@ -77613,10 +77551,11 @@ | |
| 77551 | /* Add the table to the in-memory representation of the database. |
| 77552 | */ |
| 77553 | if( db->init.busy ){ |
| 77554 | Table *pOld; |
| 77555 | Schema *pSchema = p->pSchema; |
| 77556 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 77557 | pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, |
| 77558 | sqlite3Strlen30(p->zName),p); |
| 77559 | if( pOld ){ |
| 77560 | assert( p==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 77561 | db->mallocFailed = 1; |
| @@ -77797,10 +77736,11 @@ | |
| 77736 | pTable->nCol = pSelTab->nCol; |
| 77737 | pTable->aCol = pSelTab->aCol; |
| 77738 | pSelTab->nCol = 0; |
| 77739 | pSelTab->aCol = 0; |
| 77740 | sqlite3DeleteTable(db, pSelTab); |
| 77741 | assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); |
| 77742 | pTable->pSchema->flags |= DB_UnresetViews; |
| 77743 | }else{ |
| 77744 | pTable->nCol = 0; |
| 77745 | nErr++; |
| 77746 | } |
| @@ -77817,10 +77757,11 @@ | |
| 77757 | /* |
| 77758 | ** Clear the column names from every VIEW in database idx. |
| 77759 | */ |
| 77760 | static void sqliteViewResetAll(sqlite3 *db, int idx){ |
| 77761 | HashElem *i; |
| 77762 | assert( sqlite3SchemaMutexHeld(db, idx, 0) ); |
| 77763 | if( !DbHasProperty(db, idx, DB_UnresetViews) ) return; |
| 77764 | for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){ |
| 77765 | Table *pTab = sqliteHashData(i); |
| 77766 | if( pTab->pSelect ){ |
| 77767 | sqliteDeleteColumnNames(db, pTab); |
| @@ -77850,14 +77791,17 @@ | |
| 77791 | ** We must continue looping until all tables and indices with |
| 77792 | ** rootpage==iFrom have been converted to have a rootpage of iTo |
| 77793 | ** in order to be certain that we got the right one. |
| 77794 | */ |
| 77795 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 77796 | SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3 *db, int iDb, int iFrom, int iTo){ |
| 77797 | HashElem *pElem; |
| 77798 | Hash *pHash; |
| 77799 | Db *pDb; |
| 77800 | |
| 77801 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 77802 | pDb = &db->aDb[iDb]; |
| 77803 | pHash = &pDb->pSchema->tblHash; |
| 77804 | for(pElem=sqliteHashFirst(pHash); pElem; pElem=sqliteHashNext(pElem)){ |
| 77805 | Table *pTab = sqliteHashData(pElem); |
| 77806 | if( pTab->tnum==iFrom ){ |
| 77807 | pTab->tnum = iTo; |
| @@ -78227,10 +78171,11 @@ | |
| 78171 | } |
| 78172 | pFKey->isDeferred = 0; |
| 78173 | pFKey->aAction[0] = (u8)(flags & 0xff); /* ON DELETE action */ |
| 78174 | pFKey->aAction[1] = (u8)((flags >> 8 ) & 0xff); /* ON UPDATE action */ |
| 78175 | |
| 78176 | assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) ); |
| 78177 | pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash, |
| 78178 | pFKey->zTo, sqlite3Strlen30(pFKey->zTo), (void *)pFKey |
| 78179 | ); |
| 78180 | if( pNextTo==pFKey ){ |
| 78181 | db->mallocFailed = 1; |
| @@ -78582,10 +78527,11 @@ | |
| 78527 | pIndex->pTable = pTab; |
| 78528 | pIndex->nColumn = pList->nExpr; |
| 78529 | pIndex->onError = (u8)onError; |
| 78530 | pIndex->autoIndex = (u8)(pName==0); |
| 78531 | pIndex->pSchema = db->aDb[iDb].pSchema; |
| 78532 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 78533 | |
| 78534 | /* Check to see if we should honor DESC requests on index columns |
| 78535 | */ |
| 78536 | if( pDb->pSchema->file_format>=4 ){ |
| 78537 | sortOrderMask = -1; /* Honor DESC */ |
| @@ -78711,10 +78657,11 @@ | |
| 78657 | /* Link the new Index structure to its table and to the other |
| 78658 | ** in-memory database structures. |
| 78659 | */ |
| 78660 | if( db->init.busy ){ |
| 78661 | Index *p; |
| 78662 | assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); |
| 78663 | p = sqlite3HashInsert(&pIndex->pSchema->idxHash, |
| 78664 | pIndex->zName, sqlite3Strlen30(pIndex->zName), |
| 78665 | pIndex); |
| 78666 | if( p ){ |
| 78667 | assert( p==pIndex ); /* Malloc must have failed */ |
| @@ -79464,10 +79411,11 @@ | |
| 79411 | yDbMask mask; |
| 79412 | |
| 79413 | assert( iDb<db->nDb ); |
| 79414 | assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 79415 | assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 79416 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 79417 | mask = ((yDbMask)1)<<iDb; |
| 79418 | if( (pToplevel->cookieMask & mask)==0 ){ |
| 79419 | pToplevel->cookieMask |= mask; |
| 79420 | pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 79421 | if( !OMIT_TEMPDB && iDb==1 ){ |
| @@ -79591,10 +79539,11 @@ | |
| 79539 | int iDb; /* The database index number */ |
| 79540 | sqlite3 *db = pParse->db; /* The database connection */ |
| 79541 | HashElem *k; /* For looping over tables in pDb */ |
| 79542 | Table *pTab; /* A table in the database */ |
| 79543 | |
| 79544 | assert( sqlite3BtreeHoldsAllMutexes(db) ); /* Needed for schema access */ |
| 79545 | for(iDb=0, pDb=db->aDb; iDb<db->nDb; iDb++, pDb++){ |
| 79546 | assert( pDb!=0 ); |
| 79547 | for(k=sqliteHashFirst(&pDb->pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 79548 | pTab = (Table*)sqliteHashData(k); |
| 79549 | reindexTable(pParse, pTab, zColl); |
| @@ -80109,16 +80058,16 @@ | |
| 80058 | } |
| 80059 | |
| 80060 | /* |
| 80061 | ** Free all resources held by the schema structure. The void* argument points |
| 80062 | ** at a Schema struct. This function does not call sqlite3DbFree(db, ) on the |
| 80063 | ** pointer itself, it just cleans up subsidiary resources (i.e. the contents |
| 80064 | ** of the schema hash tables). |
| 80065 | ** |
| 80066 | ** The Schema.cache_size variable is not cleared. |
| 80067 | */ |
| 80068 | SQLITE_PRIVATE void sqlite3SchemaClear(void *p){ |
| 80069 | Hash temp1; |
| 80070 | Hash temp2; |
| 80071 | HashElem *pElem; |
| 80072 | Schema *pSchema = (Schema *)p; |
| 80073 | |
| @@ -80149,11 +80098,11 @@ | |
| 80098 | ** a new one if necessary. |
| 80099 | */ |
| 80100 | SQLITE_PRIVATE Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){ |
| 80101 | Schema * p; |
| 80102 | if( pBt ){ |
| 80103 | p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaClear); |
| 80104 | }else{ |
| 80105 | p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema)); |
| 80106 | } |
| 80107 | if( !p ){ |
| 80108 | db->mallocFailed = 1; |
| @@ -80183,13 +80132,22 @@ | |
| 80132 | ** This file contains C code routines that are called by the parser |
| 80133 | ** in order to generate code for DELETE FROM statements. |
| 80134 | */ |
| 80135 | |
| 80136 | /* |
| 80137 | ** While a SrcList can in general represent multiple tables and subqueries |
| 80138 | ** (as in the FROM clause of a SELECT statement) in this case it contains |
| 80139 | ** the name of a single table, as one might find in an INSERT, DELETE, |
| 80140 | ** or UPDATE statement. Look up that table in the symbol table and |
| 80141 | ** return a pointer. Set an error message and return NULL if the table |
| 80142 | ** name is not found or if any other error occurs. |
| 80143 | ** |
| 80144 | ** The following fields are initialized appropriate in pSrc: |
| 80145 | ** |
| 80146 | ** pSrc->a[0].pTab Pointer to the Table object |
| 80147 | ** pSrc->a[0].pIndex Pointer to the INDEXED BY index, if there is one |
| 80148 | ** |
| 80149 | */ |
| 80150 | SQLITE_PRIVATE Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ |
| 80151 | struct SrcList_item *pItem = pSrc->a; |
| 80152 | Table *pTab; |
| 80153 | assert( pItem && pSrc->nSrc==1 ); |
| @@ -80704,11 +80662,11 @@ | |
| 80662 | ** fire the INSTEAD OF triggers). */ |
| 80663 | if( pTab->pSelect==0 ){ |
| 80664 | sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0); |
| 80665 | sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0)); |
| 80666 | if( count ){ |
| 80667 | sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); |
| 80668 | } |
| 80669 | } |
| 80670 | |
| 80671 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 80672 | ** handle rows (possibly in other tables) that refer via a foreign key |
| @@ -80795,11 +80753,11 @@ | |
| 80753 | sqlite3ColumnDefault(v, pTab, idx, -1); |
| 80754 | } |
| 80755 | } |
| 80756 | if( doMakeRec ){ |
| 80757 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut); |
| 80758 | sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT); |
| 80759 | } |
| 80760 | sqlite3ReleaseTempRange(pParse, regBase, nCol+1); |
| 80761 | return regBase; |
| 80762 | } |
| 80763 | |
| @@ -82792,11 +82750,11 @@ | |
| 82750 | } |
| 82751 | sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk); |
| 82752 | } |
| 82753 | |
| 82754 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec); |
| 82755 | sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT); |
| 82756 | sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); |
| 82757 | |
| 82758 | sqlite3ReleaseTempReg(pParse, regRec); |
| 82759 | sqlite3ReleaseTempRange(pParse, regTemp, nCol); |
| 82760 | } |
| @@ -83548,10 +83506,11 @@ | |
| 83506 | */ |
| 83507 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){ |
| 83508 | FKey *pFKey; /* Iterator variable */ |
| 83509 | FKey *pNext; /* Copy of pFKey->pNextFrom */ |
| 83510 | |
| 83511 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) ); |
| 83512 | for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){ |
| 83513 | |
| 83514 | /* Remove the FK from the fkeyHash hash table. */ |
| 83515 | if( !db || db->pnBytesFreed==0 ){ |
| 83516 | if( pFKey->pPrevTo ){ |
| @@ -83707,11 +83666,11 @@ | |
| 83666 | zColAff[pTab->nCol] = '\0'; |
| 83667 | |
| 83668 | pTab->zColAff = zColAff; |
| 83669 | } |
| 83670 | |
| 83671 | sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT); |
| 83672 | } |
| 83673 | |
| 83674 | /* |
| 83675 | ** Return non-zero if the table pTab in database iDb or any of its indices |
| 83676 | ** have been opened at any point in the VDBE program beginning at location |
| @@ -83821,10 +83780,11 @@ | |
| 83780 | |
| 83781 | assert( v ); /* We failed long ago if this is not so */ |
| 83782 | for(p = pParse->pAinc; p; p = p->pNext){ |
| 83783 | pDb = &db->aDb[p->iDb]; |
| 83784 | memId = p->regCtr; |
| 83785 | assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); |
| 83786 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead); |
| 83787 | addr = sqlite3VdbeCurrentAddr(v); |
| 83788 | sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0); |
| 83789 | sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); |
| 83790 | sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId); |
| @@ -83871,10 +83831,11 @@ | |
| 83831 | int j1, j2, j3, j4, j5; |
| 83832 | int iRec; |
| 83833 | int memId = p->regCtr; |
| 83834 | |
| 83835 | iRec = sqlite3GetTempReg(pParse); |
| 83836 | assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) ); |
| 83837 | sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite); |
| 83838 | j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); |
| 83839 | j2 = sqlite3VdbeAddOp0(v, OP_Rewind); |
| 83840 | j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec); |
| 83841 | j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec); |
| @@ -84911,11 +84872,11 @@ | |
| 84872 | sqlite3VdbeAddOp2(v, OP_SCopy, regData+idx, regIdx+i); |
| 84873 | } |
| 84874 | } |
| 84875 | sqlite3VdbeAddOp2(v, OP_SCopy, regRowid, regIdx+i); |
| 84876 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn+1, aRegIdx[iCur]); |
| 84877 | sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT); |
| 84878 | sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1); |
| 84879 | |
| 84880 | #ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT |
| 84881 | sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1); |
| 84882 | continue; /* Treat pIdx as if it is not a UNIQUE index */ |
| @@ -85057,11 +85018,11 @@ | |
| 85018 | if( useSeekResult ){ |
| 85019 | pik_flags |= OPFLAG_USESEEKRESULT; |
| 85020 | } |
| 85021 | sqlite3VdbeAddOp3(v, OP_Insert, baseCur, regRec, regRowid); |
| 85022 | if( !pParse->nested ){ |
| 85023 | sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT); |
| 85024 | } |
| 85025 | sqlite3VdbeChangeP5(v, pik_flags); |
| 85026 | } |
| 85027 | |
| 85028 | /* |
| @@ -86752,11 +86713,11 @@ | |
| 86713 | "from within a transaction"); |
| 86714 | return SQLITE_ERROR; |
| 86715 | } |
| 86716 | sqlite3BtreeClose(db->aDb[1].pBt); |
| 86717 | db->aDb[1].pBt = 0; |
| 86718 | sqlite3ResetInternalSchema(db, -1); |
| 86719 | } |
| 86720 | return SQLITE_OK; |
| 86721 | } |
| 86722 | #endif /* SQLITE_PAGER_PRAGMAS */ |
| 86723 | |
| @@ -87025,10 +86986,11 @@ | |
| 86986 | }else{ |
| 86987 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 86988 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 86989 | sqlite3VdbeAddOp2(v, OP_Integer, size, 1); |
| 86990 | sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1); |
| 86991 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 86992 | pDb->pSchema->cache_size = size; |
| 86993 | sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size); |
| 86994 | } |
| 86995 | }else |
| 86996 | |
| @@ -87327,10 +87289,11 @@ | |
| 87289 | ** to its default value when the database is closed and reopened. |
| 87290 | ** N should be a positive integer. |
| 87291 | */ |
| 87292 | if( sqlite3StrICmp(zLeft,"cache_size")==0 ){ |
| 87293 | if( sqlite3ReadSchema(pParse) ) goto pragma_out; |
| 87294 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 87295 | if( !zRight ){ |
| 87296 | returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size); |
| 87297 | }else{ |
| 87298 | int size = sqlite3AbsInt32(sqlite3Atoi(zRight)); |
| 87299 | pDb->pSchema->cache_size = size; |
| @@ -87747,10 +87710,11 @@ | |
| 87710 | /* Do an integrity check of the B-Tree |
| 87711 | ** |
| 87712 | ** Begin by filling registers 2, 3, ... with the root pages numbers |
| 87713 | ** for all tables and indices in the database. |
| 87714 | */ |
| 87715 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 87716 | pTbls = &db->aDb[i].pSchema->tblHash; |
| 87717 | for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){ |
| 87718 | Table *pTab = sqliteHashData(x); |
| 87719 | Index *pIdx; |
| 87720 | sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt); |
| @@ -87812,11 +87776,11 @@ | |
| 87776 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, 1, 3, 0); |
| 87777 | jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, j+2, 0, r1, pIdx->nColumn+1); |
| 87778 | addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr); |
| 87779 | sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC); |
| 87780 | sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC); |
| 87781 | sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_TRANSIENT); |
| 87782 | sqlite3VdbeJumpHere(v, addr+9); |
| 87783 | sqlite3VdbeJumpHere(v, jmp2); |
| 87784 | } |
| 87785 | sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1); |
| 87786 | sqlite3VdbeJumpHere(v, loopTop); |
| @@ -87842,11 +87806,11 @@ | |
| 87806 | sqlite3VdbeChangeP1(v, addr+3, j+2); |
| 87807 | sqlite3VdbeChangeP2(v, addr+3, addr+2); |
| 87808 | sqlite3VdbeJumpHere(v, addr+4); |
| 87809 | sqlite3VdbeChangeP4(v, addr+6, |
| 87810 | "wrong # of entries in index ", P4_STATIC); |
| 87811 | sqlite3VdbeChangeP4(v, addr+7, pIdx->zName, P4_TRANSIENT); |
| 87812 | } |
| 87813 | } |
| 87814 | } |
| 87815 | addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode); |
| 87816 | sqlite3VdbeChangeP2(v, addr, -mxErr); |
| @@ -88498,11 +88462,11 @@ | |
| 88462 | } |
| 88463 | #endif |
| 88464 | } |
| 88465 | if( db->mallocFailed ){ |
| 88466 | rc = SQLITE_NOMEM; |
| 88467 | sqlite3ResetInternalSchema(db, -1); |
| 88468 | } |
| 88469 | if( rc==SQLITE_OK || (db->flags&SQLITE_RecoveryMode)){ |
| 88470 | /* Black magic: If the SQLITE_RecoveryMode flag is set, then consider |
| 88471 | ** the schema loaded, even if errors occurred. In this situation the |
| 88472 | ** current sqlite3_prepare() operation will fail, but the following one |
| @@ -88630,11 +88594,13 @@ | |
| 88594 | |
| 88595 | /* Read the schema cookie from the database. If it does not match the |
| 88596 | ** value stored as part of the in-memory schema representation, |
| 88597 | ** set Parse.rc to SQLITE_SCHEMA. */ |
| 88598 | sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie); |
| 88599 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 88600 | if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){ |
| 88601 | sqlite3ResetInternalSchema(db, iDb); |
| 88602 | pParse->rc = SQLITE_SCHEMA; |
| 88603 | } |
| 88604 | |
| 88605 | /* Close the transaction, if one was opened. */ |
| 88606 | if( openedTransaction ){ |
| @@ -88772,13 +88738,10 @@ | |
| 88738 | } |
| 88739 | if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK; |
| 88740 | if( pParse->checkSchema ){ |
| 88741 | schemaIsValid(pParse); |
| 88742 | } |
| 88743 | if( db->mallocFailed ){ |
| 88744 | pParse->rc = SQLITE_NOMEM; |
| 88745 | } |
| 88746 | if( pzTail ){ |
| 88747 | *pzTail = pParse->zTail; |
| @@ -93735,10 +93698,11 @@ | |
| 93698 | return 0; |
| 93699 | } |
| 93700 | |
| 93701 | if( pTmpSchema!=pTab->pSchema ){ |
| 93702 | HashElem *p; |
| 93703 | assert( sqlite3SchemaMutexHeld(pParse->db, 0, pTmpSchema) ); |
| 93704 | for(p=sqliteHashFirst(&pTmpSchema->trigHash); p; p=sqliteHashNext(p)){ |
| 93705 | Trigger *pTrig = (Trigger *)sqliteHashData(p); |
| 93706 | if( pTrig->pTabSchema==pTab->pSchema |
| 93707 | && 0==sqlite3StrICmp(pTrig->table, pTab->zName) |
| 93708 | ){ |
| @@ -93846,10 +93810,11 @@ | |
| 93810 | ** specified name exists */ |
| 93811 | zName = sqlite3NameFromToken(db, pName); |
| 93812 | if( !zName || SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 93813 | goto trigger_cleanup; |
| 93814 | } |
| 93815 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 93816 | if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash), |
| 93817 | zName, sqlite3Strlen30(zName)) ){ |
| 93818 | if( !noErr ){ |
| 93819 | sqlite3ErrorMsg(pParse, "trigger %T already exists", pName); |
| 93820 | } |
| @@ -93985,10 +93950,11 @@ | |
| 93950 | } |
| 93951 | |
| 93952 | if( db->init.busy ){ |
| 93953 | Trigger *pLink = pTrig; |
| 93954 | Hash *pHash = &db->aDb[iDb].pSchema->trigHash; |
| 93955 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 93956 | pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig); |
| 93957 | if( pTrig ){ |
| 93958 | db->mallocFailed = 1; |
| 93959 | }else if( pLink->pSchema==pLink->pTabSchema ){ |
| 93960 | Table *pTab; |
| @@ -94166,13 +94132,15 @@ | |
| 94132 | |
| 94133 | assert( pName->nSrc==1 ); |
| 94134 | zDb = pName->a[0].zDatabase; |
| 94135 | zName = pName->a[0].zName; |
| 94136 | nName = sqlite3Strlen30(zName); |
| 94137 | assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) ); |
| 94138 | for(i=OMIT_TEMPDB; i<db->nDb; i++){ |
| 94139 | int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */ |
| 94140 | if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue; |
| 94141 | assert( sqlite3SchemaMutexHeld(db, j, 0) ); |
| 94142 | pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName); |
| 94143 | if( pTrigger ) break; |
| 94144 | } |
| 94145 | if( !pTrigger ){ |
| 94146 | if( !noErr ){ |
| @@ -94242,11 +94210,11 @@ | |
| 94210 | }; |
| 94211 | |
| 94212 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 94213 | sqlite3OpenMasterTable(pParse, iDb); |
| 94214 | base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger); |
| 94215 | sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT); |
| 94216 | sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC); |
| 94217 | sqlite3ChangeCookie(pParse, iDb); |
| 94218 | sqlite3VdbeAddOp2(v, OP_Close, 0, 0); |
| 94219 | sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0); |
| 94220 | if( pParse->nMem<3 ){ |
| @@ -94257,12 +94225,15 @@ | |
| 94225 | |
| 94226 | /* |
| 94227 | ** Remove a trigger from the hash tables of the sqlite* pointer. |
| 94228 | */ |
| 94229 | SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){ |
| 94230 | Trigger *pTrigger; |
| 94231 | Hash *pHash; |
| 94232 | |
| 94233 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 94234 | pHash = &(db->aDb[iDb].pSchema->trigHash); |
| 94235 | pTrigger = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), 0); |
| 94236 | if( ALWAYS(pTrigger) ){ |
| 94237 | if( pTrigger->pSchema==pTrigger->pTabSchema ){ |
| 94238 | Table *pTab = tableOfTrigger(pTrigger); |
| 94239 | Trigger **pp; |
| @@ -95782,14 +95753,17 @@ | |
| 95753 | sqlite3BtreeClose(pDb->pBt); |
| 95754 | pDb->pBt = 0; |
| 95755 | pDb->pSchema = 0; |
| 95756 | } |
| 95757 | |
| 95758 | /* This both clears the schemas and reduces the size of the db->aDb[] |
| 95759 | ** array. */ |
| 95760 | sqlite3ResetInternalSchema(db, -1); |
| 95761 | |
| 95762 | return rc; |
| 95763 | } |
| 95764 | |
| 95765 | #endif /* SQLITE_OMIT_VACUUM && SQLITE_OMIT_ATTACH */ |
| 95766 | |
| 95767 | /************** End of vacuum.c **********************************************/ |
| 95768 | /************** Begin file vtab.c ********************************************/ |
| 95769 | /* |
| @@ -95839,11 +95813,11 @@ | |
| 95813 | } |
| 95814 | sqlite3DbFree(db, pDel); |
| 95815 | if( pDel==pMod ){ |
| 95816 | db->mallocFailed = 1; |
| 95817 | } |
| 95818 | sqlite3ResetInternalSchema(db, -1); |
| 95819 | }else if( xDestroy ){ |
| 95820 | xDestroy(pAux); |
| 95821 | } |
| 95822 | rc = sqlite3ApiExit(db, SQLITE_OK); |
| 95823 | sqlite3_mutex_leave(db->mutex); |
| @@ -95936,14 +95910,13 @@ | |
| 95910 | |
| 95911 | /* Assert that the mutex (if any) associated with the BtShared database |
| 95912 | ** that contains table p is held by the caller. See header comments |
| 95913 | ** above function sqlite3VtabUnlockList() for an explanation of why |
| 95914 | ** this makes it safe to access the sqlite3.pDisconnect list of any |
| 95915 | ** database connection that may have an entry in the p->pVTable list. |
| 95916 | */ |
| 95917 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, p->pSchema) ); |
| 95918 | |
| 95919 | while( pVTable ){ |
| 95920 | sqlite3 *db2 = pVTable->db; |
| 95921 | VTable *pNext = pVTable->pNext; |
| 95922 | assert( db2 ); |
| @@ -96178,10 +96151,11 @@ | |
| 96151 | else { |
| 96152 | Table *pOld; |
| 96153 | Schema *pSchema = pTab->pSchema; |
| 96154 | const char *zName = pTab->zName; |
| 96155 | int nName = sqlite3Strlen30(zName); |
| 96156 | assert( sqlite3SchemaMutexHeld(db, 0, pSchema) ); |
| 96157 | pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab); |
| 96158 | if( pOld ){ |
| 96159 | db->mallocFailed = 1; |
| 96160 | assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */ |
| 96161 | return; |
| @@ -97132,11 +97106,11 @@ | |
| 97106 | ** Return the bitmask for the given cursor number. Return 0 if |
| 97107 | ** iCursor is not in the set. |
| 97108 | */ |
| 97109 | static Bitmask getMask(WhereMaskSet *pMaskSet, int iCursor){ |
| 97110 | int i; |
| 97111 | assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 ); |
| 97112 | for(i=0; i<pMaskSet->n; i++){ |
| 97113 | if( pMaskSet->ix[i]==iCursor ){ |
| 97114 | return ((Bitmask)1)<<i; |
| 97115 | } |
| 97116 | } |
| @@ -107007,11 +106981,12 @@ | |
| 106981 | if( !sqlite3SafetyCheckSickOrOk(db) ){ |
| 106982 | return SQLITE_MISUSE_BKPT; |
| 106983 | } |
| 106984 | sqlite3_mutex_enter(db->mutex); |
| 106985 | |
| 106986 | /* Force xDestroy calls on all virtual tables */ |
| 106987 | sqlite3ResetInternalSchema(db, -1); |
| 106988 | |
| 106989 | /* If a transaction is open, the ResetInternalSchema() call above |
| 106990 | ** will not have called the xDisconnect() method on any virtual |
| 106991 | ** tables in the db->aVTrans[] array. The following sqlite3VtabRollback() |
| 106992 | ** call will do so. We need to do this before the check for active |
| @@ -107050,11 +107025,11 @@ | |
| 107025 | if( j!=1 ){ |
| 107026 | pDb->pSchema = 0; |
| 107027 | } |
| 107028 | } |
| 107029 | } |
| 107030 | sqlite3ResetInternalSchema(db, -1); |
| 107031 | |
| 107032 | /* Tell the code in notify.c that the connection no longer holds any |
| 107033 | ** locks and does not require any further unlock-notify callbacks. |
| 107034 | */ |
| 107035 | sqlite3ConnectionClosed(db); |
| @@ -107141,11 +107116,11 @@ | |
| 107116 | sqlite3VtabRollback(db); |
| 107117 | sqlite3EndBenignMalloc(); |
| 107118 | |
| 107119 | if( db->flags&SQLITE_InternChanges ){ |
| 107120 | sqlite3ExpirePreparedStatements(db); |
| 107121 | sqlite3ResetInternalSchema(db, -1); |
| 107122 | } |
| 107123 | |
| 107124 | /* Any deferred constraint violations have now been resolved. */ |
| 107125 | db->nDeferredCons = 0; |
| 107126 | |
| @@ -107210,11 +107185,11 @@ | |
| 107185 | #if SQLITE_OS_WIN || (defined(HAVE_USLEEP) && HAVE_USLEEP) |
| 107186 | static const u8 delays[] = |
| 107187 | { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 100 }; |
| 107188 | static const u8 totals[] = |
| 107189 | { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228 }; |
| 107190 | # define NDELAY ArraySize(delays) |
| 107191 | sqlite3 *db = (sqlite3 *)ptr; |
| 107192 | int timeout = db->busyTimeout; |
| 107193 | int delay, prior; |
| 107194 | |
| 107195 | assert( count>=0 ); |
| @@ -113734,10 +113709,12 @@ | |
| 113709 | int nDb; /* Result of strlen(zDb) */ |
| 113710 | int nFts3; /* Result of strlen(zFts3) */ |
| 113711 | int nByte; /* Bytes of space to allocate here */ |
| 113712 | int rc; /* value returned by declare_vtab() */ |
| 113713 | Fts3auxTable *p; /* Virtual table object to return */ |
| 113714 | |
| 113715 | UNUSED_PARAMETER(pUnused); |
| 113716 | |
| 113717 | /* The user should specify a single argument - the name of an fts3 table. */ |
| 113718 | if( argc!=4 ){ |
| 113719 | *pzErr = sqlite3_mprintf( |
| 113720 | "wrong number of arguments to fts4aux constructor" |
| @@ -113803,10 +113780,12 @@ | |
| 113780 | ){ |
| 113781 | int i; |
| 113782 | int iEq = -1; |
| 113783 | int iGe = -1; |
| 113784 | int iLe = -1; |
| 113785 | |
| 113786 | UNUSED_PARAMETER(pVTab); |
| 113787 | |
| 113788 | /* This vtab delivers always results in "ORDER BY term ASC" order. */ |
| 113789 | if( pInfo->nOrderBy==1 |
| 113790 | && pInfo->aOrderBy[0].iColumn==0 |
| 113791 | && pInfo->aOrderBy[0].desc==0 |
| @@ -113851,10 +113830,12 @@ | |
| 113830 | /* |
| 113831 | ** xOpen - Open a cursor. |
| 113832 | */ |
| 113833 | static int fts3auxOpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){ |
| 113834 | Fts3auxCursor *pCsr; /* Pointer to cursor object to return */ |
| 113835 | |
| 113836 | UNUSED_PARAMETER(pVTab); |
| 113837 | |
| 113838 | pCsr = (Fts3auxCursor *)sqlite3_malloc(sizeof(Fts3auxCursor)); |
| 113839 | if( !pCsr ) return SQLITE_NOMEM; |
| 113840 | memset(pCsr, 0, sizeof(Fts3auxCursor)); |
| 113841 | |
| @@ -114000,10 +113981,12 @@ | |
| 113981 | ){ |
| 113982 | Fts3auxCursor *pCsr = (Fts3auxCursor *)pCursor; |
| 113983 | Fts3Table *pFts3 = ((Fts3auxTable *)pCursor->pVtab)->pFts3Tab; |
| 113984 | int rc; |
| 113985 | int isScan; |
| 113986 | |
| 113987 | UNUSED_PARAMETER(nVal); |
| 113988 | |
| 113989 | assert( idxStr==0 ); |
| 113990 | assert( idxNum==FTS4AUX_EQ_CONSTRAINT || idxNum==0 |
| 113991 | || idxNum==FTS4AUX_LE_CONSTRAINT || idxNum==FTS4AUX_GE_CONSTRAINT |
| 113992 | || idxNum==(FTS4AUX_LE_CONSTRAINT|FTS4AUX_GE_CONSTRAINT) |
| @@ -122428,11 +122411,11 @@ | |
| 122411 | pCsr->nConstraint = argc; |
| 122412 | if( !pCsr->aConstraint ){ |
| 122413 | rc = SQLITE_NOMEM; |
| 122414 | }else{ |
| 122415 | memset(pCsr->aConstraint, 0, sizeof(RtreeConstraint)*argc); |
| 122416 | assert( (idxStr==0 && argc==0) || (int)strlen(idxStr)==argc*2 ); |
| 122417 | for(ii=0; ii<argc; ii++){ |
| 122418 | RtreeConstraint *p = &pCsr->aConstraint[ii]; |
| 122419 | p->op = idxStr[ii*2]; |
| 122420 | p->iCoord = idxStr[ii*2+1]-'a'; |
| 122421 | if( p->op==RTREE_MATCH ){ |
| @@ -122521,11 +122504,11 @@ | |
| 122504 | char zIdxStr[RTREE_MAX_DIMENSIONS*8+1]; |
| 122505 | memset(zIdxStr, 0, sizeof(zIdxStr)); |
| 122506 | UNUSED_PARAMETER(tab); |
| 122507 | |
| 122508 | assert( pIdxInfo->idxStr==0 ); |
| 122509 | for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){ |
| 122510 | struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii]; |
| 122511 | |
| 122512 | if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ |
| 122513 | /* We have an equality constraint on the rowid. Use strategy 1. */ |
| 122514 | int jj; |
| @@ -124644,10 +124627,12 @@ | |
| 124627 | static void icuRegexpFunc(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 124628 | UErrorCode status = U_ZERO_ERROR; |
| 124629 | URegularExpression *pExpr; |
| 124630 | UBool res; |
| 124631 | const UChar *zString = sqlite3_value_text16(apArg[1]); |
| 124632 | |
| 124633 | (void)nArg; /* Unused parameter */ |
| 124634 | |
| 124635 | /* If the left hand side of the regexp operator is NULL, |
| 124636 | ** then the result is also NULL. |
| 124637 | */ |
| 124638 | if( !zString ){ |
| @@ -124873,11 +124858,11 @@ | |
| 124858 | }; |
| 124859 | |
| 124860 | int rc = SQLITE_OK; |
| 124861 | int i; |
| 124862 | |
| 124863 | for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){ |
| 124864 | struct IcuScalar *p = &scalars[i]; |
| 124865 | rc = sqlite3_create_function( |
| 124866 | db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0 |
| 124867 | ); |
| 124868 | } |
| 124869 |
+2
-2
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | -#define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906" | |
| 112 | +#define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -1132,11 +1132,11 @@ | ||
| 1132 | 1132 | ** changes to a [database connection]. The interface is similar to |
| 1133 | 1133 | ** [sqlite3_config()] except that the changes apply to a single |
| 1134 | 1134 | ** [database connection] (specified in the first argument). |
| 1135 | 1135 | ** |
| 1136 | 1136 | ** The second argument to sqlite3_db_config(D,V,...) is the |
| 1137 | -** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code | |
| 1137 | +** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code | |
| 1138 | 1138 | ** that indicates what aspect of the [database connection] is being configured. |
| 1139 | 1139 | ** Subsequent arguments vary depending on the configuration verb. |
| 1140 | 1140 | ** |
| 1141 | 1141 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1142 | 1142 | ** the call is considered successful. |
| 1143 | 1143 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | #define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -1132,11 +1132,11 @@ | |
| 1132 | ** changes to a [database connection]. The interface is similar to |
| 1133 | ** [sqlite3_config()] except that the changes apply to a single |
| 1134 | ** [database connection] (specified in the first argument). |
| 1135 | ** |
| 1136 | ** The second argument to sqlite3_db_config(D,V,...) is the |
| 1137 | ** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code |
| 1138 | ** that indicates what aspect of the [database connection] is being configured. |
| 1139 | ** Subsequent arguments vary depending on the configuration verb. |
| 1140 | ** |
| 1141 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1142 | ** the call is considered successful. |
| 1143 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | #define SQLITE_SOURCE_ID "2011-04-05 22:08:24 3eeb0ff78d04891b5fd1a3d99a9fb8cfbed77a81" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -1132,11 +1132,11 @@ | |
| 1132 | ** changes to a [database connection]. The interface is similar to |
| 1133 | ** [sqlite3_config()] except that the changes apply to a single |
| 1134 | ** [database connection] (specified in the first argument). |
| 1135 | ** |
| 1136 | ** The second argument to sqlite3_db_config(D,V,...) is the |
| 1137 | ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code |
| 1138 | ** that indicates what aspect of the [database connection] is being configured. |
| 1139 | ** Subsequent arguments vary depending on the configuration verb. |
| 1140 | ** |
| 1141 | ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if |
| 1142 | ** the call is considered successful. |
| 1143 |