Fossil SCM
Update the built-in SQLite to the latest beta for 3.7.6.
Commit
a74cfe0a14a203e77bb10d21fbc759b23f2c68cc
Parent
fa81575c8d8d212…
2 files changed
+502
-394
+7
-3
+502
-394
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | 3 | ** version 3.7.6. By combining all the individual C code files into this |
| 4 | -** single large file, the entire code can be compiled as a one translation | |
| 4 | +** single large file, the entire code can be compiled as a single translation | |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| 9 | 9 | ** |
| @@ -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-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8" | |
| 655 | +#define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906" | |
| 656 | 656 | |
| 657 | 657 | /* |
| 658 | 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 660 | ** |
| @@ -3521,11 +3521,13 @@ | ||
| 3521 | 3521 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
| 3522 | 3522 | ** that implements the [SELECT] statement. ^The second parameter is the |
| 3523 | 3523 | ** column number. ^The leftmost column is number 0. |
| 3524 | 3524 | ** |
| 3525 | 3525 | ** ^The returned string pointer is valid until either the [prepared statement] |
| 3526 | -** is destroyed by [sqlite3_finalize()] or until the next call to | |
| 3526 | +** is destroyed by [sqlite3_finalize()] or until the statement is automatically | |
| 3527 | +** reprepared by the first call to [sqlite3_step()] for a particular run | |
| 3528 | +** or until the next call to | |
| 3527 | 3529 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
| 3528 | 3530 | ** |
| 3529 | 3531 | ** ^If sqlite3_malloc() fails during the processing of either routine |
| 3530 | 3532 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
| 3531 | 3533 | ** NULL pointer is returned. |
| @@ -3547,11 +3549,13 @@ | ||
| 3547 | 3549 | ** ^The name of the database or table or column can be returned as |
| 3548 | 3550 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 3549 | 3551 | ** the database name, the _table_ routines return the table name, and |
| 3550 | 3552 | ** the origin_ routines return the column name. |
| 3551 | 3553 | ** ^The returned string is valid until the [prepared statement] is destroyed |
| 3552 | -** using [sqlite3_finalize()] or until the same information is requested | |
| 3554 | +** using [sqlite3_finalize()] or until the statement is automatically | |
| 3555 | +** reprepared by the first call to [sqlite3_step()] for a particular run | |
| 3556 | +** or until the same information is requested | |
| 3553 | 3557 | ** again in a different encoding. |
| 3554 | 3558 | ** |
| 3555 | 3559 | ** ^The names returned are the original un-aliased names of the |
| 3556 | 3560 | ** database, table, and column. |
| 3557 | 3561 | ** |
| @@ -7648,22 +7652,10 @@ | ||
| 7648 | 7652 | ** Forward declarations of structure |
| 7649 | 7653 | */ |
| 7650 | 7654 | typedef struct Btree Btree; |
| 7651 | 7655 | typedef struct BtCursor BtCursor; |
| 7652 | 7656 | typedef struct BtShared BtShared; |
| 7653 | -typedef struct BtreeMutexArray BtreeMutexArray; | |
| 7654 | - | |
| 7655 | -/* | |
| 7656 | -** This structure records all of the Btrees that need to hold | |
| 7657 | -** a mutex before we enter sqlite3VdbeExec(). The Btrees are | |
| 7658 | -** are placed in aBtree[] in order of aBtree[]->pBt. That way, | |
| 7659 | -** we can always lock and unlock them all quickly. | |
| 7660 | -*/ | |
| 7661 | -struct BtreeMutexArray { | |
| 7662 | - int nMutex; | |
| 7663 | - Btree *aBtree[SQLITE_MAX_ATTACHED+1]; | |
| 7664 | -}; | |
| 7665 | 7657 | |
| 7666 | 7658 | |
| 7667 | 7659 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 7668 | 7660 | const char *zFilename, /* Name of database file to open */ |
| 7669 | 7661 | sqlite3 *db, /* Associated database connection */ |
| @@ -7696,11 +7688,11 @@ | ||
| 7696 | 7688 | SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*); |
| 7697 | 7689 | SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int); |
| 7698 | 7690 | SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); |
| 7699 | 7691 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int); |
| 7700 | 7692 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); |
| 7701 | -SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*); | |
| 7693 | +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int); | |
| 7702 | 7694 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); |
| 7703 | 7695 | SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*); |
| 7704 | 7696 | SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); |
| 7705 | 7697 | SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
| 7706 | 7698 | SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*); |
| @@ -7837,27 +7829,23 @@ | ||
| 7837 | 7829 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE |
| 7838 | 7830 | SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*); |
| 7839 | 7831 | SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*); |
| 7840 | 7832 | SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*); |
| 7841 | 7833 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); |
| 7842 | -SQLITE_PRIVATE void sqlite3BtreeMutexArrayEnter(BtreeMutexArray*); | |
| 7843 | -SQLITE_PRIVATE void sqlite3BtreeMutexArrayLeave(BtreeMutexArray*); | |
| 7844 | -SQLITE_PRIVATE void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*); | |
| 7845 | 7834 | #ifndef NDEBUG |
| 7846 | 7835 | /* These routines are used inside assert() statements only. */ |
| 7847 | 7836 | SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); |
| 7848 | 7837 | SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); |
| 7838 | +SQLITE_PRIVATE u32 sqlite3BtreeMutexCounter(Btree*); | |
| 7849 | 7839 | #endif |
| 7850 | 7840 | #else |
| 7851 | 7841 | |
| 7852 | 7842 | # define sqlite3BtreeLeave(X) |
| 7843 | +# define sqlite3BtreeMutexCounter(X) 0 | |
| 7853 | 7844 | # define sqlite3BtreeEnterCursor(X) |
| 7854 | 7845 | # define sqlite3BtreeLeaveCursor(X) |
| 7855 | 7846 | # define sqlite3BtreeLeaveAll(X) |
| 7856 | -# define sqlite3BtreeMutexArrayEnter(X) | |
| 7857 | -# define sqlite3BtreeMutexArrayLeave(X) | |
| 7858 | -# define sqlite3BtreeMutexArrayInsert(X,Y) | |
| 7859 | 7847 | |
| 7860 | 7848 | # define sqlite3BtreeHoldsMutex(X) 1 |
| 7861 | 7849 | # define sqlite3BtreeHoldsAllMutexes(X) 1 |
| 7862 | 7850 | #endif |
| 7863 | 7851 | |
| @@ -10467,15 +10455,17 @@ | ||
| 10467 | 10455 | SubProgram *pProgram; /* Program implementing pTrigger/orconf */ |
| 10468 | 10456 | u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */ |
| 10469 | 10457 | TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */ |
| 10470 | 10458 | }; |
| 10471 | 10459 | |
| 10472 | -/* Datatype for the bitmask of all attached databases */ | |
| 10460 | +/* | |
| 10461 | +** The yDbMask datatype for the bitmask of all attached databases. | |
| 10462 | +*/ | |
| 10473 | 10463 | #if SQLITE_MAX_ATTACHED>30 |
| 10474 | - typedef sqlite3_uint64 tAttachMask; | |
| 10464 | + typedef sqlite3_uint64 yDbMask; | |
| 10475 | 10465 | #else |
| 10476 | - typedef unsigned int tAttachMask; | |
| 10466 | + typedef unsigned int yDbMask; | |
| 10477 | 10467 | #endif |
| 10478 | 10468 | |
| 10479 | 10469 | /* |
| 10480 | 10470 | ** An SQL parser context. A copy of this structure is passed through |
| 10481 | 10471 | ** the parser and down into all the parser action routine in order to |
| @@ -10522,12 +10512,12 @@ | ||
| 10522 | 10512 | u8 tempReg; /* iReg is a temp register that needs to be freed */ |
| 10523 | 10513 | int iLevel; /* Nesting level */ |
| 10524 | 10514 | int iReg; /* Reg with value of this column. 0 means none. */ |
| 10525 | 10515 | int lru; /* Least recently used entry has the smallest value */ |
| 10526 | 10516 | } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */ |
| 10527 | - tAttachMask writeMask; /* Start a write transaction on these databases */ | |
| 10528 | - tAttachMask cookieMask; /* Bitmask of schema verified databases */ | |
| 10517 | + yDbMask writeMask; /* Start a write transaction on these databases */ | |
| 10518 | + yDbMask cookieMask; /* Bitmask of schema verified databases */ | |
| 10529 | 10519 | u8 isMultiWrite; /* True if statement may affect/insert multiple rows */ |
| 10530 | 10520 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 10531 | 10521 | int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ |
| 10532 | 10522 | int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ |
| 10533 | 10523 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| @@ -12488,14 +12478,14 @@ | ||
| 12488 | 12478 | u8 inVtabMethod; /* See comments above */ |
| 12489 | 12479 | u8 usesStmtJournal; /* True if uses a statement journal */ |
| 12490 | 12480 | u8 readOnly; /* True for read-only statements */ |
| 12491 | 12481 | u8 isPrepareV2; /* True if prepared with prepare_v2() */ |
| 12492 | 12482 | int nChange; /* Number of db changes made since last reset */ |
| 12493 | - tAttachMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ | |
| 12483 | + yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ | |
| 12484 | + u32 iMutexCounter; /* Mutex counter upon sqlite3VdbeEnter() */ | |
| 12494 | 12485 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 12495 | 12486 | int aCounter[3]; /* Counters used by sqlite3_stmt_status() */ |
| 12496 | - BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */ | |
| 12497 | 12487 | #ifndef SQLITE_OMIT_TRACE |
| 12498 | 12488 | i64 startTime; /* Time when query started - used for profiling */ |
| 12499 | 12489 | #endif |
| 12500 | 12490 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 12501 | 12491 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| @@ -12573,10 +12563,13 @@ | ||
| 12573 | 12563 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 12574 | 12564 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 12575 | 12565 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 12576 | 12566 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 12577 | 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*); | |
| 12578 | 12571 | |
| 12579 | 12572 | #ifdef SQLITE_DEBUG |
| 12580 | 12573 | SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); |
| 12581 | 12574 | #endif |
| 12582 | 12575 | |
| @@ -12584,16 +12577,10 @@ | ||
| 12584 | 12577 | SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int); |
| 12585 | 12578 | #else |
| 12586 | 12579 | # define sqlite3VdbeCheckFk(p,i) 0 |
| 12587 | 12580 | #endif |
| 12588 | 12581 | |
| 12589 | -#ifndef SQLITE_OMIT_SHARED_CACHE | |
| 12590 | -SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p); | |
| 12591 | -#else | |
| 12592 | -# define sqlite3VdbeMutexArrayEnter(p) | |
| 12593 | -#endif | |
| 12594 | - | |
| 12595 | 12582 | SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8); |
| 12596 | 12583 | #ifdef SQLITE_DEBUG |
| 12597 | 12584 | SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*); |
| 12598 | 12585 | SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); |
| 12599 | 12586 | #endif |
| @@ -19794,11 +19781,11 @@ | ||
| 19794 | 19781 | } |
| 19795 | 19782 | SQLITE_PRIVATE int sqlite3Utf8Read( |
| 19796 | 19783 | const unsigned char *zIn, /* First byte of UTF-8 character */ |
| 19797 | 19784 | const unsigned char **pzNext /* Write first byte past UTF-8 char here */ |
| 19798 | 19785 | ){ |
| 19799 | - int c; | |
| 19786 | + unsigned int c; | |
| 19800 | 19787 | |
| 19801 | 19788 | /* Same as READ_UTF8() above but without the zTerm parameter. |
| 19802 | 19789 | ** For this routine, we assume the UTF8 string is always zero-terminated. |
| 19803 | 19790 | */ |
| 19804 | 19791 | c = *(zIn++); |
| @@ -20037,19 +20024,19 @@ | ||
| 20037 | 20024 | ** Translate UTF-8 to UTF-8. |
| 20038 | 20025 | ** |
| 20039 | 20026 | ** This has the effect of making sure that the string is well-formed |
| 20040 | 20027 | ** UTF-8. Miscoded characters are removed. |
| 20041 | 20028 | ** |
| 20042 | -** The translation is done in-place (since it is impossible for the | |
| 20043 | -** correct UTF-8 encoding to be longer than a malformed encoding). | |
| 20029 | +** The translation is done in-place and aborted if the output | |
| 20030 | +** overruns the input. | |
| 20044 | 20031 | */ |
| 20045 | 20032 | SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char *zIn){ |
| 20046 | 20033 | unsigned char *zOut = zIn; |
| 20047 | 20034 | unsigned char *zStart = zIn; |
| 20048 | 20035 | u32 c; |
| 20049 | 20036 | |
| 20050 | - while( zIn[0] ){ | |
| 20037 | + while( zIn[0] && zOut<=zIn ){ | |
| 20051 | 20038 | c = sqlite3Utf8Read(zIn, (const u8**)&zIn); |
| 20052 | 20039 | if( c!=0xfffd ){ |
| 20053 | 20040 | WRITE_UTF8(zOut, c); |
| 20054 | 20041 | } |
| 20055 | 20042 | } |
| @@ -23750,11 +23737,11 @@ | ||
| 23750 | 23737 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 23751 | 23738 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 23752 | 23739 | #else |
| 23753 | 23740 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, |
| 23754 | 23741 | #endif |
| 23755 | -#define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent) | |
| 23742 | +#define osFallocate ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent) | |
| 23756 | 23743 | |
| 23757 | 23744 | }; /* End of the overrideable system calls */ |
| 23758 | 23745 | |
| 23759 | 23746 | /* |
| 23760 | 23747 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| @@ -23773,14 +23760,14 @@ | ||
| 23773 | 23760 | UNUSED_PARAMETER(pNotUsed); |
| 23774 | 23761 | if( zName==0 ){ |
| 23775 | 23762 | /* If no zName is given, restore all system calls to their default |
| 23776 | 23763 | ** settings and return NULL |
| 23777 | 23764 | */ |
| 23765 | + rc = SQLITE_OK; | |
| 23778 | 23766 | for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ |
| 23779 | 23767 | if( aSyscall[i].pDefault ){ |
| 23780 | 23768 | aSyscall[i].pCurrent = aSyscall[i].pDefault; |
| 23781 | - rc = SQLITE_OK; | |
| 23782 | 23769 | } |
| 23783 | 23770 | } |
| 23784 | 23771 | }else{ |
| 23785 | 23772 | /* If zName is specified, operate on only the one system call |
| 23786 | 23773 | ** specified. |
| @@ -23823,22 +23810,20 @@ | ||
| 23823 | 23810 | ** then return the name of the first system call. Return NULL if zName |
| 23824 | 23811 | ** is the last system call or if zName is not the name of a valid |
| 23825 | 23812 | ** system call. |
| 23826 | 23813 | */ |
| 23827 | 23814 | static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ |
| 23828 | - unsigned int i; | |
| 23815 | + int i = -1; | |
| 23829 | 23816 | |
| 23830 | 23817 | UNUSED_PARAMETER(p); |
| 23831 | - if( zName==0 ){ | |
| 23832 | - i = -1; | |
| 23833 | - }else{ | |
| 23834 | - for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0])-1; i++){ | |
| 23835 | - if( strcmp(zName, aSyscall[0].zName)==0 ) break; | |
| 23818 | + if( zName ){ | |
| 23819 | + for(i=0; i<ArraySize(aSyscall)-1; i++){ | |
| 23820 | + if( strcmp(zName, aSyscall[i].zName)==0 ) break; | |
| 23836 | 23821 | } |
| 23837 | 23822 | } |
| 23838 | - for(i++; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ | |
| 23839 | - if( aSyscall[0].pCurrent!=0 ) return aSyscall[0].zName; | |
| 23823 | + for(i++; i<ArraySize(aSyscall); i++){ | |
| 23824 | + if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; | |
| 23840 | 23825 | } |
| 23841 | 23826 | return 0; |
| 23842 | 23827 | } |
| 23843 | 23828 | |
| 23844 | 23829 | /* |
| @@ -23974,13 +23959,26 @@ | ||
| 23974 | 23959 | ** Errors during initialization of locks, or file system support for locks, |
| 23975 | 23960 | ** should handle ENOLCK, ENOTSUP, EOPNOTSUPP separately. |
| 23976 | 23961 | */ |
| 23977 | 23962 | static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) { |
| 23978 | 23963 | switch (posixError) { |
| 23964 | +#if 0 | |
| 23965 | + /* At one point this code was not commented out. In theory, this branch | |
| 23966 | + ** should never be hit, as this function should only be called after | |
| 23967 | + ** a locking-related function (i.e. fcntl()) has returned non-zero with | |
| 23968 | + ** the value of errno as the first argument. Since a system call has failed, | |
| 23969 | + ** errno should be non-zero. | |
| 23970 | + ** | |
| 23971 | + ** Despite this, if errno really is zero, we still don't want to return | |
| 23972 | + ** SQLITE_OK. The system call failed, and *some* SQLite error should be | |
| 23973 | + ** propagated back to the caller. Commenting this branch out means errno==0 | |
| 23974 | + ** will be handled by the "default:" case below. | |
| 23975 | + */ | |
| 23979 | 23976 | case 0: |
| 23980 | 23977 | return SQLITE_OK; |
| 23981 | - | |
| 23978 | +#endif | |
| 23979 | + | |
| 23982 | 23980 | case EAGAIN: |
| 23983 | 23981 | case ETIMEDOUT: |
| 23984 | 23982 | case EBUSY: |
| 23985 | 23983 | case EINTR: |
| 23986 | 23984 | case ENOLCK: |
| @@ -23998,12 +23996,19 @@ | ||
| 23998 | 23996 | } |
| 23999 | 23997 | /* else fall through */ |
| 24000 | 23998 | case EPERM: |
| 24001 | 23999 | return SQLITE_PERM; |
| 24002 | 24000 | |
| 24001 | + /* EDEADLK is only possible if a call to fcntl(F_SETLKW) is made. And | |
| 24002 | + ** this module never makes such a call. And the code in SQLite itself | |
| 24003 | + ** asserts that SQLITE_IOERR_BLOCKED is never returned. For these reasons | |
| 24004 | + ** this case is also commented out. If the system does set errno to EDEADLK, | |
| 24005 | + ** the default SQLITE_IOERR_XXX code will be returned. */ | |
| 24006 | +#if 0 | |
| 24003 | 24007 | case EDEADLK: |
| 24004 | 24008 | return SQLITE_IOERR_BLOCKED; |
| 24009 | +#endif | |
| 24005 | 24010 | |
| 24006 | 24011 | #if EOPNOTSUPP!=ENOTSUP |
| 24007 | 24012 | case EOPNOTSUPP: |
| 24008 | 24013 | /* something went terribly awry, unless during file system support |
| 24009 | 24014 | * introspection, in which it actually means what it says */ |
| @@ -24418,11 +24423,11 @@ | ||
| 24418 | 24423 | ** when this function is called. |
| 24419 | 24424 | */ |
| 24420 | 24425 | static void releaseInodeInfo(unixFile *pFile){ |
| 24421 | 24426 | unixInodeInfo *pInode = pFile->pInode; |
| 24422 | 24427 | assert( unixMutexHeld() ); |
| 24423 | - if( pInode ){ | |
| 24428 | + if( ALWAYS(pInode) ){ | |
| 24424 | 24429 | pInode->nRef--; |
| 24425 | 24430 | if( pInode->nRef==0 ){ |
| 24426 | 24431 | assert( pInode->pShmNode==0 ); |
| 24427 | 24432 | closePendingFds(pFile); |
| 24428 | 24433 | if( pInode->pPrev ){ |
| @@ -24560,14 +24565,13 @@ | ||
| 24560 | 24565 | struct flock lock; |
| 24561 | 24566 | lock.l_whence = SEEK_SET; |
| 24562 | 24567 | lock.l_start = RESERVED_BYTE; |
| 24563 | 24568 | lock.l_len = 1; |
| 24564 | 24569 | lock.l_type = F_WRLCK; |
| 24565 | - if (-1 == osFcntl(pFile->h, F_GETLK, &lock)) { | |
| 24566 | - int tErrno = errno; | |
| 24567 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); | |
| 24568 | - pFile->lastErrno = tErrno; | |
| 24570 | + if( osFcntl(pFile->h, F_GETLK, &lock) ){ | |
| 24571 | + rc = SQLITE_IOERR_CHECKRESERVEDLOCK; | |
| 24572 | + pFile->lastErrno = errno; | |
| 24569 | 24573 | } else if( lock.l_type!=F_UNLCK ){ |
| 24570 | 24574 | reserved = 1; |
| 24571 | 24575 | } |
| 24572 | 24576 | } |
| 24573 | 24577 | #endif |
| @@ -24592,10 +24596,13 @@ | ||
| 24592 | 24596 | ** operating system does not participate. |
| 24593 | 24597 | ** |
| 24594 | 24598 | ** This function is a pass-through to fcntl(F_SETLK) if pFile is using |
| 24595 | 24599 | ** any VFS other than "unix-excl" or if pFile is opened on "unix-excl" |
| 24596 | 24600 | ** and is read-only. |
| 24601 | +** | |
| 24602 | +** Zero is returned if the call completes successfully, or -1 if a call | |
| 24603 | +** to fcntl() fails. In this case, errno is set appropriately (by fcntl()). | |
| 24597 | 24604 | */ |
| 24598 | 24605 | static int unixFileLock(unixFile *pFile, struct flock *pLock){ |
| 24599 | 24606 | int rc; |
| 24600 | 24607 | unixInodeInfo *pInode = pFile->pInode; |
| 24601 | 24608 | assert( unixMutexHeld() ); |
| @@ -24688,11 +24695,10 @@ | ||
| 24688 | 24695 | */ |
| 24689 | 24696 | int rc = SQLITE_OK; |
| 24690 | 24697 | unixFile *pFile = (unixFile*)id; |
| 24691 | 24698 | unixInodeInfo *pInode = pFile->pInode; |
| 24692 | 24699 | struct flock lock; |
| 24693 | - int s = 0; | |
| 24694 | 24700 | int tErrno = 0; |
| 24695 | 24701 | |
| 24696 | 24702 | assert( pFile ); |
| 24697 | 24703 | OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, |
| 24698 | 24704 | azFileLock(eFileLock), azFileLock(pFile->eFileLock), |
| @@ -24757,15 +24763,14 @@ | ||
| 24757 | 24763 | if( eFileLock==SHARED_LOCK |
| 24758 | 24764 | || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK) |
| 24759 | 24765 | ){ |
| 24760 | 24766 | lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK); |
| 24761 | 24767 | lock.l_start = PENDING_BYTE; |
| 24762 | - s = unixFileLock(pFile, &lock); | |
| 24763 | - if( s==(-1) ){ | |
| 24768 | + if( unixFileLock(pFile, &lock) ){ | |
| 24764 | 24769 | tErrno = errno; |
| 24765 | 24770 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24766 | - if( IS_LOCK_ERROR(rc) ){ | |
| 24771 | + if( rc!=SQLITE_BUSY ){ | |
| 24767 | 24772 | pFile->lastErrno = tErrno; |
| 24768 | 24773 | } |
| 24769 | 24774 | goto end_lock; |
| 24770 | 24775 | } |
| 24771 | 24776 | } |
| @@ -24775,37 +24780,35 @@ | ||
| 24775 | 24780 | ** operating system calls for the specified lock. |
| 24776 | 24781 | */ |
| 24777 | 24782 | if( eFileLock==SHARED_LOCK ){ |
| 24778 | 24783 | assert( pInode->nShared==0 ); |
| 24779 | 24784 | assert( pInode->eFileLock==0 ); |
| 24785 | + assert( rc==SQLITE_OK ); | |
| 24780 | 24786 | |
| 24781 | 24787 | /* Now get the read-lock */ |
| 24782 | 24788 | lock.l_start = SHARED_FIRST; |
| 24783 | 24789 | lock.l_len = SHARED_SIZE; |
| 24784 | - if( (s = unixFileLock(pFile, &lock))==(-1) ){ | |
| 24790 | + if( unixFileLock(pFile, &lock) ){ | |
| 24785 | 24791 | tErrno = errno; |
| 24792 | + rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | |
| 24786 | 24793 | } |
| 24794 | + | |
| 24787 | 24795 | /* Drop the temporary PENDING lock */ |
| 24788 | 24796 | lock.l_start = PENDING_BYTE; |
| 24789 | 24797 | lock.l_len = 1L; |
| 24790 | 24798 | lock.l_type = F_UNLCK; |
| 24791 | - if( unixFileLock(pFile, &lock)!=0 ){ | |
| 24792 | - if( s != -1 ){ | |
| 24793 | - /* This could happen with a network mount */ | |
| 24794 | - tErrno = errno; | |
| 24795 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 24796 | - if( IS_LOCK_ERROR(rc) ){ | |
| 24797 | - pFile->lastErrno = tErrno; | |
| 24798 | - } | |
| 24799 | - goto end_lock; | |
| 24800 | - } | |
| 24801 | - } | |
| 24802 | - if( s==(-1) ){ | |
| 24803 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); | |
| 24804 | - if( IS_LOCK_ERROR(rc) ){ | |
| 24805 | - pFile->lastErrno = tErrno; | |
| 24806 | - } | |
| 24799 | + if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){ | |
| 24800 | + /* This could happen with a network mount */ | |
| 24801 | + tErrno = errno; | |
| 24802 | + rc = SQLITE_IOERR_UNLOCK; | |
| 24803 | + } | |
| 24804 | + | |
| 24805 | + if( rc ){ | |
| 24806 | + if( rc!=SQLITE_BUSY ){ | |
| 24807 | + pFile->lastErrno = tErrno; | |
| 24808 | + } | |
| 24809 | + goto end_lock; | |
| 24807 | 24810 | }else{ |
| 24808 | 24811 | pFile->eFileLock = SHARED_LOCK; |
| 24809 | 24812 | pInode->nLock++; |
| 24810 | 24813 | pInode->nShared = 1; |
| 24811 | 24814 | } |
| @@ -24818,26 +24821,24 @@ | ||
| 24818 | 24821 | ** assumed that there is a SHARED or greater lock on the file |
| 24819 | 24822 | ** already. |
| 24820 | 24823 | */ |
| 24821 | 24824 | assert( 0!=pFile->eFileLock ); |
| 24822 | 24825 | lock.l_type = F_WRLCK; |
| 24823 | - switch( eFileLock ){ | |
| 24824 | - case RESERVED_LOCK: | |
| 24825 | - lock.l_start = RESERVED_BYTE; | |
| 24826 | - break; | |
| 24827 | - case EXCLUSIVE_LOCK: | |
| 24828 | - lock.l_start = SHARED_FIRST; | |
| 24829 | - lock.l_len = SHARED_SIZE; | |
| 24830 | - break; | |
| 24831 | - default: | |
| 24832 | - assert(0); | |
| 24833 | - } | |
| 24834 | - s = unixFileLock(pFile, &lock); | |
| 24835 | - if( s==(-1) ){ | |
| 24826 | + | |
| 24827 | + assert( eFileLock==RESERVED_LOCK || eFileLock==EXCLUSIVE_LOCK ); | |
| 24828 | + if( eFileLock==RESERVED_LOCK ){ | |
| 24829 | + lock.l_start = RESERVED_BYTE; | |
| 24830 | + lock.l_len = 1L; | |
| 24831 | + }else{ | |
| 24832 | + lock.l_start = SHARED_FIRST; | |
| 24833 | + lock.l_len = SHARED_SIZE; | |
| 24834 | + } | |
| 24835 | + | |
| 24836 | + if( unixFileLock(pFile, &lock) ){ | |
| 24836 | 24837 | tErrno = errno; |
| 24837 | 24838 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24838 | - if( IS_LOCK_ERROR(rc) ){ | |
| 24839 | + if( rc!=SQLITE_BUSY ){ | |
| 24839 | 24840 | pFile->lastErrno = tErrno; |
| 24840 | 24841 | } |
| 24841 | 24842 | } |
| 24842 | 24843 | } |
| 24843 | 24844 | |
| @@ -24904,11 +24905,10 @@ | ||
| 24904 | 24905 | unixFile *pFile = (unixFile*)id; |
| 24905 | 24906 | unixInodeInfo *pInode; |
| 24906 | 24907 | struct flock lock; |
| 24907 | 24908 | int rc = SQLITE_OK; |
| 24908 | 24909 | int h; |
| 24909 | - int tErrno; /* Error code from system call errors */ | |
| 24910 | 24910 | |
| 24911 | 24911 | assert( pFile ); |
| 24912 | 24912 | OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, |
| 24913 | 24913 | pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, |
| 24914 | 24914 | getpid())); |
| @@ -24959,19 +24959,20 @@ | ||
| 24959 | 24959 | (void)handleNFSUnlock; |
| 24960 | 24960 | assert( handleNFSUnlock==0 ); |
| 24961 | 24961 | #endif |
| 24962 | 24962 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE |
| 24963 | 24963 | if( handleNFSUnlock ){ |
| 24964 | + int tErrno; /* Error code from system call errors */ | |
| 24964 | 24965 | off_t divSize = SHARED_SIZE - 1; |
| 24965 | 24966 | |
| 24966 | 24967 | lock.l_type = F_UNLCK; |
| 24967 | 24968 | lock.l_whence = SEEK_SET; |
| 24968 | 24969 | lock.l_start = SHARED_FIRST; |
| 24969 | 24970 | lock.l_len = divSize; |
| 24970 | - if( unixFileLock(pFile,, &lock)==(-1) ){ | |
| 24971 | + if( unixFileLock(pFile, &lock)==(-1) ){ | |
| 24971 | 24972 | tErrno = errno; |
| 24972 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 24973 | + rc = SQLITE_IOERR_UNLOCK; | |
| 24973 | 24974 | if( IS_LOCK_ERROR(rc) ){ |
| 24974 | 24975 | pFile->lastErrno = tErrno; |
| 24975 | 24976 | } |
| 24976 | 24977 | goto end_unlock; |
| 24977 | 24978 | } |
| @@ -24991,11 +24992,11 @@ | ||
| 24991 | 24992 | lock.l_whence = SEEK_SET; |
| 24992 | 24993 | lock.l_start = SHARED_FIRST+divSize; |
| 24993 | 24994 | lock.l_len = SHARED_SIZE-divSize; |
| 24994 | 24995 | if( unixFileLock(pFile, &lock)==(-1) ){ |
| 24995 | 24996 | tErrno = errno; |
| 24996 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 24997 | + rc = SQLITE_IOERR_UNLOCK; | |
| 24997 | 24998 | if( IS_LOCK_ERROR(rc) ){ |
| 24998 | 24999 | pFile->lastErrno = tErrno; |
| 24999 | 25000 | } |
| 25000 | 25001 | goto end_unlock; |
| 25001 | 25002 | } |
| @@ -25004,32 +25005,32 @@ | ||
| 25004 | 25005 | { |
| 25005 | 25006 | lock.l_type = F_RDLCK; |
| 25006 | 25007 | lock.l_whence = SEEK_SET; |
| 25007 | 25008 | lock.l_start = SHARED_FIRST; |
| 25008 | 25009 | lock.l_len = SHARED_SIZE; |
| 25009 | - if( unixFileLock(pFile, &lock)==(-1) ){ | |
| 25010 | - tErrno = errno; | |
| 25011 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK); | |
| 25012 | - if( IS_LOCK_ERROR(rc) ){ | |
| 25013 | - pFile->lastErrno = tErrno; | |
| 25014 | - } | |
| 25010 | + if( unixFileLock(pFile, &lock) ){ | |
| 25011 | + /* In theory, the call to unixFileLock() cannot fail because another | |
| 25012 | + ** process is holding an incompatible lock. If it does, this | |
| 25013 | + ** indicates that the other process is not following the locking | |
| 25014 | + ** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning | |
| 25015 | + ** SQLITE_BUSY would confuse the upper layer (in practice it causes | |
| 25016 | + ** an assert to fail). */ | |
| 25017 | + rc = SQLITE_IOERR_RDLOCK; | |
| 25018 | + pFile->lastErrno = errno; | |
| 25015 | 25019 | goto end_unlock; |
| 25016 | 25020 | } |
| 25017 | 25021 | } |
| 25018 | 25022 | } |
| 25019 | 25023 | lock.l_type = F_UNLCK; |
| 25020 | 25024 | lock.l_whence = SEEK_SET; |
| 25021 | 25025 | lock.l_start = PENDING_BYTE; |
| 25022 | 25026 | lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); |
| 25023 | - if( unixFileLock(pFile, &lock)!=(-1) ){ | |
| 25027 | + if( unixFileLock(pFile, &lock)==0 ){ | |
| 25024 | 25028 | pInode->eFileLock = SHARED_LOCK; |
| 25025 | 25029 | }else{ |
| 25026 | - tErrno = errno; | |
| 25027 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 25028 | - if( IS_LOCK_ERROR(rc) ){ | |
| 25029 | - pFile->lastErrno = tErrno; | |
| 25030 | - } | |
| 25030 | + rc = SQLITE_IOERR_UNLOCK; | |
| 25031 | + pFile->lastErrno = errno; | |
| 25031 | 25032 | goto end_unlock; |
| 25032 | 25033 | } |
| 25033 | 25034 | } |
| 25034 | 25035 | if( eFileLock==NO_LOCK ){ |
| 25035 | 25036 | /* Decrement the shared lock counter. Release the lock using an |
| @@ -25042,18 +25043,15 @@ | ||
| 25042 | 25043 | lock.l_whence = SEEK_SET; |
| 25043 | 25044 | lock.l_start = lock.l_len = 0L; |
| 25044 | 25045 | SimulateIOErrorBenign(1); |
| 25045 | 25046 | SimulateIOError( h=(-1) ) |
| 25046 | 25047 | SimulateIOErrorBenign(0); |
| 25047 | - if( unixFileLock(pFile, &lock)!=(-1) ){ | |
| 25048 | + if( unixFileLock(pFile, &lock)==0 ){ | |
| 25048 | 25049 | pInode->eFileLock = NO_LOCK; |
| 25049 | 25050 | }else{ |
| 25050 | - tErrno = errno; | |
| 25051 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 25052 | - if( IS_LOCK_ERROR(rc) ){ | |
| 25053 | - pFile->lastErrno = tErrno; | |
| 25054 | - } | |
| 25051 | + rc = SQLITE_IOERR_UNLOCK; | |
| 25052 | + pFile->lastErrno = errno; | |
| 25055 | 25053 | pInode->eFileLock = NO_LOCK; |
| 25056 | 25054 | pFile->eFileLock = NO_LOCK; |
| 25057 | 25055 | } |
| 25058 | 25056 | } |
| 25059 | 25057 | |
| @@ -25095,59 +25093,58 @@ | ||
| 25095 | 25093 | ** even on VxWorks. A mutex will be acquired on VxWorks by the |
| 25096 | 25094 | ** vxworksReleaseFileId() routine. |
| 25097 | 25095 | */ |
| 25098 | 25096 | static int closeUnixFile(sqlite3_file *id){ |
| 25099 | 25097 | unixFile *pFile = (unixFile*)id; |
| 25100 | - if( pFile ){ | |
| 25101 | - if( pFile->dirfd>=0 ){ | |
| 25102 | - robust_close(pFile, pFile->dirfd, __LINE__); | |
| 25103 | - pFile->dirfd=-1; | |
| 25104 | - } | |
| 25105 | - if( pFile->h>=0 ){ | |
| 25106 | - robust_close(pFile, pFile->h, __LINE__); | |
| 25107 | - pFile->h = -1; | |
| 25108 | - } | |
| 25098 | + if( pFile->dirfd>=0 ){ | |
| 25099 | + robust_close(pFile, pFile->dirfd, __LINE__); | |
| 25100 | + pFile->dirfd=-1; | |
| 25101 | + } | |
| 25102 | + if( pFile->h>=0 ){ | |
| 25103 | + robust_close(pFile, pFile->h, __LINE__); | |
| 25104 | + pFile->h = -1; | |
| 25105 | + } | |
| 25109 | 25106 | #if OS_VXWORKS |
| 25110 | - if( pFile->pId ){ | |
| 25111 | - if( pFile->isDelete ){ | |
| 25112 | - unlink(pFile->pId->zCanonicalName); | |
| 25113 | - } | |
| 25114 | - vxworksReleaseFileId(pFile->pId); | |
| 25115 | - pFile->pId = 0; | |
| 25116 | - } | |
| 25117 | -#endif | |
| 25118 | - OSTRACE(("CLOSE %-3d\n", pFile->h)); | |
| 25119 | - OpenCounter(-1); | |
| 25120 | - sqlite3_free(pFile->pUnused); | |
| 25121 | - memset(pFile, 0, sizeof(unixFile)); | |
| 25122 | - } | |
| 25107 | + if( pFile->pId ){ | |
| 25108 | + if( pFile->isDelete ){ | |
| 25109 | + unlink(pFile->pId->zCanonicalName); | |
| 25110 | + } | |
| 25111 | + vxworksReleaseFileId(pFile->pId); | |
| 25112 | + pFile->pId = 0; | |
| 25113 | + } | |
| 25114 | +#endif | |
| 25115 | + OSTRACE(("CLOSE %-3d\n", pFile->h)); | |
| 25116 | + OpenCounter(-1); | |
| 25117 | + sqlite3_free(pFile->pUnused); | |
| 25118 | + memset(pFile, 0, sizeof(unixFile)); | |
| 25123 | 25119 | return SQLITE_OK; |
| 25124 | 25120 | } |
| 25125 | 25121 | |
| 25126 | 25122 | /* |
| 25127 | 25123 | ** Close a file. |
| 25128 | 25124 | */ |
| 25129 | 25125 | static int unixClose(sqlite3_file *id){ |
| 25130 | 25126 | int rc = SQLITE_OK; |
| 25131 | - if( id ){ | |
| 25132 | - unixFile *pFile = (unixFile *)id; | |
| 25133 | - unixUnlock(id, NO_LOCK); | |
| 25134 | - unixEnterMutex(); | |
| 25135 | - assert( pFile->pInode==0 || pFile->pInode->nLock>0 | |
| 25136 | - || pFile->pInode->bProcessLock==0 ); | |
| 25137 | - if( pFile->pInode && pFile->pInode->nLock ){ | |
| 25138 | - /* If there are outstanding locks, do not actually close the file just | |
| 25139 | - ** yet because that would clear those locks. Instead, add the file | |
| 25140 | - ** descriptor to pInode->pUnused list. It will be automatically closed | |
| 25141 | - ** when the last lock is cleared. | |
| 25142 | - */ | |
| 25143 | - setPendingFd(pFile); | |
| 25144 | - } | |
| 25145 | - releaseInodeInfo(pFile); | |
| 25146 | - rc = closeUnixFile(id); | |
| 25147 | - unixLeaveMutex(); | |
| 25148 | - } | |
| 25127 | + unixFile *pFile = (unixFile *)id; | |
| 25128 | + unixUnlock(id, NO_LOCK); | |
| 25129 | + unixEnterMutex(); | |
| 25130 | + | |
| 25131 | + /* unixFile.pInode is always valid here. Otherwise, a different close | |
| 25132 | + ** routine (e.g. nolockClose()) would be called instead. | |
| 25133 | + */ | |
| 25134 | + assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 ); | |
| 25135 | + if( ALWAYS(pFile->pInode) && pFile->pInode->nLock ){ | |
| 25136 | + /* If there are outstanding locks, do not actually close the file just | |
| 25137 | + ** yet because that would clear those locks. Instead, add the file | |
| 25138 | + ** descriptor to pInode->pUnused list. It will be automatically closed | |
| 25139 | + ** when the last lock is cleared. | |
| 25140 | + */ | |
| 25141 | + setPendingFd(pFile); | |
| 25142 | + } | |
| 25143 | + releaseInodeInfo(pFile); | |
| 25144 | + rc = closeUnixFile(id); | |
| 25145 | + unixLeaveMutex(); | |
| 25149 | 25146 | return rc; |
| 25150 | 25147 | } |
| 25151 | 25148 | |
| 25152 | 25149 | /************** End of the posix advisory lock implementation ***************** |
| 25153 | 25150 | ******************************************************************************/ |
| @@ -25358,11 +25355,11 @@ | ||
| 25358 | 25355 | assert( eFileLock==NO_LOCK ); |
| 25359 | 25356 | if( unlink(zLockFile) ){ |
| 25360 | 25357 | int rc = 0; |
| 25361 | 25358 | int tErrno = errno; |
| 25362 | 25359 | if( ENOENT != tErrno ){ |
| 25363 | - rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 25360 | + rc = SQLITE_IOERR_UNLOCK; | |
| 25364 | 25361 | } |
| 25365 | 25362 | if( IS_LOCK_ERROR(rc) ){ |
| 25366 | 25363 | pFile->lastErrno = tErrno; |
| 25367 | 25364 | } |
| 25368 | 25365 | return rc; |
| @@ -25446,11 +25443,11 @@ | ||
| 25446 | 25443 | /* got the lock, unlock it */ |
| 25447 | 25444 | lrc = robust_flock(pFile->h, LOCK_UN); |
| 25448 | 25445 | if ( lrc ) { |
| 25449 | 25446 | int tErrno = errno; |
| 25450 | 25447 | /* unlock failed with an error */ |
| 25451 | - lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 25448 | + lrc = SQLITE_IOERR_UNLOCK; | |
| 25452 | 25449 | if( IS_LOCK_ERROR(lrc) ){ |
| 25453 | 25450 | pFile->lastErrno = tErrno; |
| 25454 | 25451 | rc = lrc; |
| 25455 | 25452 | } |
| 25456 | 25453 | } |
| @@ -25568,25 +25565,16 @@ | ||
| 25568 | 25565 | pFile->eFileLock = eFileLock; |
| 25569 | 25566 | return SQLITE_OK; |
| 25570 | 25567 | } |
| 25571 | 25568 | |
| 25572 | 25569 | /* no, really, unlock. */ |
| 25573 | - int rc = robust_flock(pFile->h, LOCK_UN); | |
| 25574 | - if (rc) { | |
| 25575 | - int r, tErrno = errno; | |
| 25576 | - r = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); | |
| 25577 | - if( IS_LOCK_ERROR(r) ){ | |
| 25578 | - pFile->lastErrno = tErrno; | |
| 25579 | - } | |
| 25570 | + if( robust_flock(pFile->h, LOCK_UN) ){ | |
| 25580 | 25571 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 25581 | - if( (r & SQLITE_IOERR) == SQLITE_IOERR ){ | |
| 25582 | - r = SQLITE_BUSY; | |
| 25583 | - } | |
| 25572 | + return SQLITE_OK; | |
| 25584 | 25573 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ |
| 25585 | - | |
| 25586 | - return r; | |
| 25587 | - } else { | |
| 25574 | + return SQLITE_IOERR_UNLOCK; | |
| 25575 | + }else{ | |
| 25588 | 25576 | pFile->eFileLock = NO_LOCK; |
| 25589 | 25577 | return SQLITE_OK; |
| 25590 | 25578 | } |
| 25591 | 25579 | } |
| 25592 | 25580 | |
| @@ -26388,10 +26376,11 @@ | ||
| 26388 | 26376 | do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); |
| 26389 | 26377 | #elif defined(USE_PREAD64) |
| 26390 | 26378 | do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR); |
| 26391 | 26379 | #else |
| 26392 | 26380 | newOffset = lseek(id->h, offset, SEEK_SET); |
| 26381 | + SimulateIOError( newOffset-- ); | |
| 26393 | 26382 | if( newOffset!=offset ){ |
| 26394 | 26383 | if( newOffset == -1 ){ |
| 26395 | 26384 | ((unixFile*)id)->lastErrno = errno; |
| 26396 | 26385 | }else{ |
| 26397 | 26386 | ((unixFile*)id)->lastErrno = 0; |
| @@ -26756,16 +26745,20 @@ | ||
| 26756 | 26745 | |
| 26757 | 26746 | if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; |
| 26758 | 26747 | |
| 26759 | 26748 | nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; |
| 26760 | 26749 | if( nSize>(i64)buf.st_size ){ |
| 26750 | + | |
| 26761 | 26751 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 26762 | - int rc; | |
| 26752 | + /* The code below is handling the return value of osFallocate() | |
| 26753 | + ** correctly. posix_fallocate() is defined to "returns zero on success, | |
| 26754 | + ** or an error number on failure". See the manpage for details. */ | |
| 26755 | + int err; | |
| 26763 | 26756 | do{ |
| 26764 | - rc = osFallocate(pFile->.h, buf.st_size, nSize-buf.st_size; | |
| 26765 | - }while( rc<0 && errno=EINTR ); | |
| 26766 | - if( rc ) return SQLITE_IOERR_WRITE; | |
| 26757 | + err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size); | |
| 26758 | + }while( err==EINTR ); | |
| 26759 | + if( err ) return SQLITE_IOERR_WRITE; | |
| 26767 | 26760 | #else |
| 26768 | 26761 | /* If the OS does not have posix_fallocate(), fake it. First use |
| 26769 | 26762 | ** ftruncate() to set the file size, then write a single byte to |
| 26770 | 26763 | ** the last byte in each block within the extended region. This |
| 26771 | 26764 | ** is the same technique used by glibc to implement posix_fallocate() |
| @@ -29114,11 +29107,13 @@ | ||
| 29114 | 29107 | rc = SQLITE_NOMEM; |
| 29115 | 29108 | goto end_create_proxy; |
| 29116 | 29109 | } |
| 29117 | 29110 | memset(pNew, 0, sizeof(unixFile)); |
| 29118 | 29111 | pNew->openFlags = openFlags; |
| 29112 | + memset(&dummyVfs, 0, sizeof(dummyVfs)); | |
| 29119 | 29113 | dummyVfs.pAppData = (void*)&autolockIoFinder; |
| 29114 | + dummyVfs.zName = "dummy"; | |
| 29120 | 29115 | pUnused->fd = fd; |
| 29121 | 29116 | pUnused->flags = openFlags; |
| 29122 | 29117 | pNew->pUnused = pUnused; |
| 29123 | 29118 | |
| 29124 | 29119 | rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0, 0); |
| @@ -45633,11 +45628,11 @@ | ||
| 45633 | 45628 | ** the BtShared object. |
| 45634 | 45629 | ** |
| 45635 | 45630 | ** All fields in this structure are accessed under sqlite3.mutex. |
| 45636 | 45631 | ** The pBt pointer itself may not be changed while there exists cursors |
| 45637 | 45632 | ** in the referenced BtShared that point back to this Btree since those |
| 45638 | -** cursors have to do go through this Btree to find their BtShared and | |
| 45633 | +** cursors have to go through this Btree to find their BtShared and | |
| 45639 | 45634 | ** they often do so without holding sqlite3.mutex. |
| 45640 | 45635 | */ |
| 45641 | 45636 | struct Btree { |
| 45642 | 45637 | sqlite3 *db; /* The database connection holding this btree */ |
| 45643 | 45638 | BtShared *pBt; /* Sharable content of this btree */ |
| @@ -45723,19 +45718,20 @@ | ||
| 45723 | 45718 | u32 usableSize; /* Number of usable bytes on each page */ |
| 45724 | 45719 | int nTransaction; /* Number of open transactions (read + write) */ |
| 45725 | 45720 | u32 nPage; /* Number of pages in the database */ |
| 45726 | 45721 | void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */ |
| 45727 | 45722 | void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */ |
| 45728 | - sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */ | |
| 45723 | + sqlite3_mutex *mutex; /* Non-recursive mutex required to access this object */ | |
| 45729 | 45724 | Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */ |
| 45730 | 45725 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 45731 | 45726 | int nRef; /* Number of references to this structure */ |
| 45732 | 45727 | BtShared *pNext; /* Next on a list of sharable BtShared structs */ |
| 45733 | 45728 | BtLock *pLock; /* List of locks held on this shared-btree struct */ |
| 45734 | 45729 | Btree *pWriter; /* Btree with currently open write transaction */ |
| 45735 | 45730 | u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */ |
| 45736 | 45731 | u8 isPending; /* If waiting for read-locks to clear */ |
| 45732 | + u16 iMutexCounter; /* The number of mutex_leave(mutex) calls */ | |
| 45737 | 45733 | #endif |
| 45738 | 45734 | u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */ |
| 45739 | 45735 | }; |
| 45740 | 45736 | |
| 45741 | 45737 | /* |
| @@ -45964,18 +45960,37 @@ | ||
| 45964 | 45960 | /* |
| 45965 | 45961 | ** Release the BtShared mutex associated with B-Tree handle p and |
| 45966 | 45962 | ** clear the p->locked boolean. |
| 45967 | 45963 | */ |
| 45968 | 45964 | static void unlockBtreeMutex(Btree *p){ |
| 45965 | + BtShared *pBt = p->pBt; | |
| 45969 | 45966 | assert( p->locked==1 ); |
| 45970 | - assert( sqlite3_mutex_held(p->pBt->mutex) ); | |
| 45967 | + assert( sqlite3_mutex_held(pBt->mutex) ); | |
| 45971 | 45968 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 45972 | - assert( p->db==p->pBt->db ); | |
| 45969 | + assert( p->db==pBt->db ); | |
| 45973 | 45970 | |
| 45974 | - sqlite3_mutex_leave(p->pBt->mutex); | |
| 45971 | + pBt->iMutexCounter++; | |
| 45972 | + sqlite3_mutex_leave(pBt->mutex); | |
| 45975 | 45973 | p->locked = 0; |
| 45976 | 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 | |
| 45977 | 45992 | |
| 45978 | 45993 | /* |
| 45979 | 45994 | ** Enter a mutex on the given BTree object. |
| 45980 | 45995 | ** |
| 45981 | 45996 | ** If the object is not sharable, then no mutex is ever required |
| @@ -46016,10 +46031,28 @@ | ||
| 46016 | 46031 | assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db ); |
| 46017 | 46032 | |
| 46018 | 46033 | if( !p->sharable ) return; |
| 46019 | 46034 | p->wantToLock++; |
| 46020 | 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 | |
| 46021 | 46054 | |
| 46022 | 46055 | /* In most cases, we should be able to acquire the lock we |
| 46023 | 46056 | ** want without having to go throught the ascending lock |
| 46024 | 46057 | ** procedure that follows. Just be sure not to block. |
| 46025 | 46058 | */ |
| @@ -46120,11 +46153,11 @@ | ||
| 46120 | 46153 | if( p && p->sharable ){ |
| 46121 | 46154 | p->wantToLock++; |
| 46122 | 46155 | if( !p->locked ){ |
| 46123 | 46156 | assert( p->wantToLock==1 ); |
| 46124 | 46157 | while( p->pPrev ) p = p->pPrev; |
| 46125 | - /* Reason for ALWAYS: There must be at least on unlocked Btree in | |
| 46158 | + /* Reason for ALWAYS: There must be at least one unlocked Btree in | |
| 46126 | 46159 | ** the chain. Otherwise the !p->locked test above would have failed */ |
| 46127 | 46160 | while( p->locked && ALWAYS(p->pNext) ) p = p->pNext; |
| 46128 | 46161 | for(pLater = p->pNext; pLater; pLater=pLater->pNext){ |
| 46129 | 46162 | if( pLater->locked ){ |
| 46130 | 46163 | unlockBtreeMutex(pLater); |
| @@ -46176,101 +46209,21 @@ | ||
| 46176 | 46209 | } |
| 46177 | 46210 | return 1; |
| 46178 | 46211 | } |
| 46179 | 46212 | #endif /* NDEBUG */ |
| 46180 | 46213 | |
| 46181 | -/* | |
| 46182 | -** Add a new Btree pointer to a BtreeMutexArray. | |
| 46183 | -** if the pointer can possibly be shared with | |
| 46184 | -** another database connection. | |
| 46185 | -** | |
| 46186 | -** The pointers are kept in sorted order by pBtree->pBt. That | |
| 46187 | -** way when we go to enter all the mutexes, we can enter them | |
| 46188 | -** in order without every having to backup and retry and without | |
| 46189 | -** worrying about deadlock. | |
| 46190 | -** | |
| 46191 | -** The number of shared btrees will always be small (usually 0 or 1) | |
| 46192 | -** so an insertion sort is an adequate algorithm here. | |
| 46193 | -*/ | |
| 46194 | -SQLITE_PRIVATE void sqlite3BtreeMutexArrayInsert(BtreeMutexArray *pArray, Btree *pBtree){ | |
| 46195 | - int i, j; | |
| 46196 | - BtShared *pBt; | |
| 46197 | - if( pBtree==0 || pBtree->sharable==0 ) return; | |
| 46198 | -#ifndef NDEBUG | |
| 46199 | - { | |
| 46200 | - for(i=0; i<pArray->nMutex; i++){ | |
| 46201 | - assert( pArray->aBtree[i]!=pBtree ); | |
| 46202 | - } | |
| 46203 | - } | |
| 46204 | -#endif | |
| 46205 | - assert( pArray->nMutex>=0 ); | |
| 46206 | - assert( pArray->nMutex<ArraySize(pArray->aBtree)-1 ); | |
| 46207 | - pBt = pBtree->pBt; | |
| 46208 | - for(i=0; i<pArray->nMutex; i++){ | |
| 46209 | - assert( pArray->aBtree[i]!=pBtree ); | |
| 46210 | - if( pArray->aBtree[i]->pBt>pBt ){ | |
| 46211 | - for(j=pArray->nMutex; j>i; j--){ | |
| 46212 | - pArray->aBtree[j] = pArray->aBtree[j-1]; | |
| 46213 | - } | |
| 46214 | - pArray->aBtree[i] = pBtree; | |
| 46215 | - pArray->nMutex++; | |
| 46216 | - return; | |
| 46217 | - } | |
| 46218 | - } | |
| 46219 | - pArray->aBtree[pArray->nMutex++] = pBtree; | |
| 46220 | -} | |
| 46221 | - | |
| 46222 | -/* | |
| 46223 | -** Enter the mutex of every btree in the array. This routine is | |
| 46224 | -** called at the beginning of sqlite3VdbeExec(). The mutexes are | |
| 46225 | -** exited at the end of the same function. | |
| 46226 | -*/ | |
| 46227 | -SQLITE_PRIVATE void sqlite3BtreeMutexArrayEnter(BtreeMutexArray *pArray){ | |
| 46228 | - int i; | |
| 46229 | - for(i=0; i<pArray->nMutex; i++){ | |
| 46230 | - Btree *p = pArray->aBtree[i]; | |
| 46231 | - /* Some basic sanity checking */ | |
| 46232 | - assert( i==0 || pArray->aBtree[i-1]->pBt<p->pBt ); | |
| 46233 | - assert( !p->locked || p->wantToLock>0 ); | |
| 46234 | - | |
| 46235 | - /* We should already hold a lock on the database connection */ | |
| 46236 | - assert( sqlite3_mutex_held(p->db->mutex) ); | |
| 46237 | - | |
| 46238 | - /* The Btree is sharable because only sharable Btrees are entered | |
| 46239 | - ** into the array in the first place. */ | |
| 46240 | - assert( p->sharable ); | |
| 46241 | - | |
| 46242 | - p->wantToLock++; | |
| 46243 | - if( !p->locked ){ | |
| 46244 | - lockBtreeMutex(p); | |
| 46245 | - } | |
| 46246 | - } | |
| 46247 | -} | |
| 46248 | - | |
| 46249 | -/* | |
| 46250 | -** Leave the mutex of every btree in the group. | |
| 46251 | -*/ | |
| 46252 | -SQLITE_PRIVATE void sqlite3BtreeMutexArrayLeave(BtreeMutexArray *pArray){ | |
| 46253 | - int i; | |
| 46254 | - for(i=0; i<pArray->nMutex; i++){ | |
| 46255 | - Btree *p = pArray->aBtree[i]; | |
| 46256 | - /* Some basic sanity checking */ | |
| 46257 | - assert( i==0 || pArray->aBtree[i-1]->pBt<p->pBt ); | |
| 46258 | - assert( p->locked ); | |
| 46259 | - assert( p->wantToLock>0 ); | |
| 46260 | - | |
| 46261 | - /* We should already hold a lock on the database connection */ | |
| 46262 | - assert( sqlite3_mutex_held(p->db->mutex) ); | |
| 46263 | - | |
| 46264 | - p->wantToLock--; | |
| 46265 | - if( p->wantToLock==0 ){ | |
| 46266 | - unlockBtreeMutex(p); | |
| 46267 | - } | |
| 46268 | - } | |
| 46269 | -} | |
| 46270 | - | |
| 46271 | -#else | |
| 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 | |
| 46219 | +** are null #defines in btree.h. | |
| 46220 | +** | |
| 46221 | +** If shared cache is disabled, then all btree mutex routines, including | |
| 46222 | +** the ones below, are no-ops and are null #defines in btree.h. | |
| 46223 | +*/ | |
| 46224 | + | |
| 46272 | 46225 | SQLITE_PRIVATE void sqlite3BtreeEnter(Btree *p){ |
| 46273 | 46226 | p->pBt->db = p->db; |
| 46274 | 46227 | } |
| 46275 | 46228 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 46276 | 46229 | int i; |
| @@ -49444,15 +49397,26 @@ | ||
| 49444 | 49397 | ** routine did all the work of writing information out to disk and flushing the |
| 49445 | 49398 | ** contents so that they are written onto the disk platter. All this |
| 49446 | 49399 | ** routine has to do is delete or truncate or zero the header in the |
| 49447 | 49400 | ** the rollback journal (which causes the transaction to commit) and |
| 49448 | 49401 | ** drop locks. |
| 49402 | +** | |
| 49403 | +** Normally, if an error occurs while the pager layer is attempting to | |
| 49404 | +** finalize the underlying journal file, this function returns an error and | |
| 49405 | +** the upper layer will attempt a rollback. However, if the second argument | |
| 49406 | +** is non-zero then this b-tree transaction is part of a multi-file | |
| 49407 | +** transaction. In this case, the transaction has already been committed | |
| 49408 | +** (by deleting a master journal file) and the caller will ignore this | |
| 49409 | +** functions return code. So, even if an error occurs in the pager layer, | |
| 49410 | +** reset the b-tree objects internal state to indicate that the write | |
| 49411 | +** transaction has been closed. This is quite safe, as the pager will have | |
| 49412 | +** transitioned to the error state. | |
| 49449 | 49413 | ** |
| 49450 | 49414 | ** This will release the write lock on the database file. If there |
| 49451 | 49415 | ** are no active cursors, it also releases the read lock. |
| 49452 | 49416 | */ |
| 49453 | -SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *p){ | |
| 49417 | +SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *p, int bCleanup){ | |
| 49454 | 49418 | |
| 49455 | 49419 | if( p->inTrans==TRANS_NONE ) return SQLITE_OK; |
| 49456 | 49420 | sqlite3BtreeEnter(p); |
| 49457 | 49421 | btreeIntegrity(p); |
| 49458 | 49422 | |
| @@ -49463,11 +49427,11 @@ | ||
| 49463 | 49427 | int rc; |
| 49464 | 49428 | BtShared *pBt = p->pBt; |
| 49465 | 49429 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 49466 | 49430 | assert( pBt->nTransaction>0 ); |
| 49467 | 49431 | rc = sqlite3PagerCommitPhaseTwo(pBt->pPager); |
| 49468 | - if( rc!=SQLITE_OK ){ | |
| 49432 | + if( rc!=SQLITE_OK && bCleanup==0 ){ | |
| 49469 | 49433 | sqlite3BtreeLeave(p); |
| 49470 | 49434 | return rc; |
| 49471 | 49435 | } |
| 49472 | 49436 | pBt->inTransaction = TRANS_READ; |
| 49473 | 49437 | } |
| @@ -49483,11 +49447,11 @@ | ||
| 49483 | 49447 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree *p){ |
| 49484 | 49448 | int rc; |
| 49485 | 49449 | sqlite3BtreeEnter(p); |
| 49486 | 49450 | rc = sqlite3BtreeCommitPhaseOne(p, 0); |
| 49487 | 49451 | if( rc==SQLITE_OK ){ |
| 49488 | - rc = sqlite3BtreeCommitPhaseTwo(p); | |
| 49452 | + rc = sqlite3BtreeCommitPhaseTwo(p, 0); | |
| 49489 | 49453 | } |
| 49490 | 49454 | sqlite3BtreeLeave(p); |
| 49491 | 49455 | return rc; |
| 49492 | 49456 | } |
| 49493 | 49457 | |
| @@ -54264,11 +54228,11 @@ | ||
| 54264 | 54228 | ** allocated, a null pointer is returned. If the blob has already been |
| 54265 | 54229 | ** allocated, it is returned as normal. |
| 54266 | 54230 | ** |
| 54267 | 54231 | ** Just before the shared-btree is closed, the function passed as the |
| 54268 | 54232 | ** xFree argument when the memory allocation was made is invoked on the |
| 54269 | -** blob of allocated memory. This function should not call sqlite3_free() | |
| 54233 | +** blob of allocated memory. The xFree function should not call sqlite3_free() | |
| 54270 | 54234 | ** on the memory, the btree layer does that. |
| 54271 | 54235 | */ |
| 54272 | 54236 | SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){ |
| 54273 | 54237 | BtShared *pBt = p->pBt; |
| 54274 | 54238 | sqlite3BtreeEnter(p); |
| @@ -54907,11 +54871,11 @@ | ||
| 54907 | 54871 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 54908 | 54872 | } |
| 54909 | 54873 | |
| 54910 | 54874 | /* Finish committing the transaction to the destination database. */ |
| 54911 | 54875 | if( SQLITE_OK==rc |
| 54912 | - && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest)) | |
| 54876 | + && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0)) | |
| 54913 | 54877 | ){ |
| 54914 | 54878 | rc = SQLITE_DONE; |
| 54915 | 54879 | } |
| 54916 | 54880 | } |
| 54917 | 54881 | |
| @@ -54921,11 +54885,11 @@ | ||
| 54921 | 54885 | ** "committing" a read-only transaction cannot fail. |
| 54922 | 54886 | */ |
| 54923 | 54887 | if( bCloseTrans ){ |
| 54924 | 54888 | TESTONLY( int rc2 ); |
| 54925 | 54889 | TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0); |
| 54926 | - TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc); | |
| 54890 | + TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0); | |
| 54927 | 54891 | assert( rc2==SQLITE_OK ); |
| 54928 | 54892 | } |
| 54929 | 54893 | |
| 54930 | 54894 | if( rc==SQLITE_IOERR_NOMEM ){ |
| 54931 | 54895 | rc = SQLITE_NOMEM; |
| @@ -56419,10 +56383,15 @@ | ||
| 56419 | 56383 | pOp->p2 = p2; |
| 56420 | 56384 | pOp->p3 = p3; |
| 56421 | 56385 | pOp->p4.p = 0; |
| 56422 | 56386 | pOp->p4type = P4_NOTUSED; |
| 56423 | 56387 | p->expired = 0; |
| 56388 | + if( op==OP_ParseSchema ){ | |
| 56389 | + /* Any program that uses the OP_ParseSchema opcode needs to lock | |
| 56390 | + ** all btrees. */ | |
| 56391 | + p->btreeMask = ~(yDbMask)0; | |
| 56392 | + } | |
| 56424 | 56393 | #ifdef SQLITE_DEBUG |
| 56425 | 56394 | pOp->zComment = 0; |
| 56426 | 56395 | if( sqlite3VdbeAddopTrace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 56427 | 56396 | #endif |
| 56428 | 56397 | #ifdef VDBE_PROFILE |
| @@ -56719,11 +56688,11 @@ | ||
| 56719 | 56688 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe *p, int *pnOp, int *pnMaxArg){ |
| 56720 | 56689 | VdbeOp *aOp = p->aOp; |
| 56721 | 56690 | assert( aOp && !p->db->mallocFailed ); |
| 56722 | 56691 | |
| 56723 | 56692 | /* Check that sqlite3VdbeUsesBtree() was not called on this VM */ |
| 56724 | - assert( p->aMutex.nMutex==0 ); | |
| 56693 | + assert( p->btreeMask==0 ); | |
| 56725 | 56694 | |
| 56726 | 56695 | resolveP2Values(p, pnMaxArg); |
| 56727 | 56696 | *pnOp = p->nOp; |
| 56728 | 56697 | p->aOp = 0; |
| 56729 | 56698 | return aOp; |
| @@ -56821,10 +56790,11 @@ | ||
| 56821 | 56790 | /* |
| 56822 | 56791 | ** Change the P2 operand of instruction addr so that it points to |
| 56823 | 56792 | ** the address of the next instruction to be coded. |
| 56824 | 56793 | */ |
| 56825 | 56794 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 56795 | + assert( addr>=0 ); | |
| 56826 | 56796 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 56827 | 56797 | } |
| 56828 | 56798 | |
| 56829 | 56799 | |
| 56830 | 56800 | /* |
| @@ -57206,26 +57176,135 @@ | ||
| 57206 | 57176 | #endif |
| 57207 | 57177 | |
| 57208 | 57178 | /* |
| 57209 | 57179 | ** Declare to the Vdbe that the BTree object at db->aDb[i] is used. |
| 57210 | 57180 | ** |
| 57211 | -** The prepared statement has to know in advance which Btree objects | |
| 57212 | -** will be used so that it can acquire mutexes on them all in sorted | |
| 57213 | -** order (via sqlite3VdbeMutexArrayEnter(). Mutexes are acquired | |
| 57214 | -** in order (and released in reverse order) to avoid deadlocks. | |
| 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. | |
| 57215 | 57184 | */ |
| 57216 | 57185 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){ |
| 57217 | - tAttachMask mask; | |
| 57218 | - assert( i>=0 && i<p->db->nDb && i<sizeof(tAttachMask)*8 ); | |
| 57186 | + assert( i>=0 && i<p->db->nDb && i<sizeof(yDbMask)*8 ); | |
| 57219 | 57187 | assert( i<(int)sizeof(p->btreeMask)*8 ); |
| 57220 | - mask = ((u32)1)<<i; | |
| 57221 | - if( (p->btreeMask & mask)==0 ){ | |
| 57222 | - p->btreeMask |= mask; | |
| 57223 | - sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt); | |
| 57224 | - } | |
| 57188 | + p->btreeMask |= ((yDbMask)1)<<i; | |
| 57225 | 57189 | } |
| 57226 | 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 | |
| 57221 | +** that the correct busy-handler callback is invoked if required. | |
| 57222 | +** | |
| 57223 | +** If SQLite is not threadsafe but does support shared-cache mode, then | |
| 57224 | +** sqlite3BtreeEnter() is invoked to set the BtShared.db variables | |
| 57225 | +** of all of BtShared structures accessible via the database handle | |
| 57226 | +** associated with the VM. | |
| 57227 | +** | |
| 57228 | +** If SQLite is not threadsafe and does not support shared-cache mode, this | |
| 57229 | +** function is a no-op. | |
| 57230 | +** | |
| 57231 | +** The p->btreeMask field is a bitmask of all btrees that the prepared | |
| 57232 | +** statement p will ever use. Let N be the number of bits in p->btreeMask | |
| 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 | + 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 | +} | |
| 57227 | 57306 | |
| 57228 | 57307 | #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) |
| 57229 | 57308 | /* |
| 57230 | 57309 | ** Print a single opcode. This routine is used for debugging only. |
| 57231 | 57310 | */ |
| @@ -57965,11 +58044,11 @@ | ||
| 57965 | 58044 | ** but could happen. In this case abandon processing and return the error. |
| 57966 | 58045 | */ |
| 57967 | 58046 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 57968 | 58047 | Btree *pBt = db->aDb[i].pBt; |
| 57969 | 58048 | if( pBt ){ |
| 57970 | - rc = sqlite3BtreeCommitPhaseTwo(pBt); | |
| 58049 | + rc = sqlite3BtreeCommitPhaseTwo(pBt, 0); | |
| 57971 | 58050 | } |
| 57972 | 58051 | } |
| 57973 | 58052 | if( rc==SQLITE_OK ){ |
| 57974 | 58053 | sqlite3VtabCommit(db); |
| 57975 | 58054 | } |
| @@ -58097,11 +58176,11 @@ | ||
| 58097 | 58176 | disable_simulated_io_errors(); |
| 58098 | 58177 | sqlite3BeginBenignMalloc(); |
| 58099 | 58178 | for(i=0; i<db->nDb; i++){ |
| 58100 | 58179 | Btree *pBt = db->aDb[i].pBt; |
| 58101 | 58180 | if( pBt ){ |
| 58102 | - sqlite3BtreeCommitPhaseTwo(pBt); | |
| 58181 | + sqlite3BtreeCommitPhaseTwo(pBt, 1); | |
| 58103 | 58182 | } |
| 58104 | 58183 | } |
| 58105 | 58184 | sqlite3EndBenignMalloc(); |
| 58106 | 58185 | enable_simulated_io_errors(); |
| 58107 | 58186 | |
| @@ -58220,37 +58299,10 @@ | ||
| 58220 | 58299 | } |
| 58221 | 58300 | } |
| 58222 | 58301 | return rc; |
| 58223 | 58302 | } |
| 58224 | 58303 | |
| 58225 | -/* | |
| 58226 | -** If SQLite is compiled to support shared-cache mode and to be threadsafe, | |
| 58227 | -** this routine obtains the mutex associated with each BtShared structure | |
| 58228 | -** that may be accessed by the VM passed as an argument. In doing so it | |
| 58229 | -** sets the BtShared.db member of each of the BtShared structures, ensuring | |
| 58230 | -** that the correct busy-handler callback is invoked if required. | |
| 58231 | -** | |
| 58232 | -** If SQLite is not threadsafe but does support shared-cache mode, then | |
| 58233 | -** sqlite3BtreeEnterAll() is invoked to set the BtShared.db variables | |
| 58234 | -** of all of BtShared structures accessible via the database handle | |
| 58235 | -** associated with the VM. Of course only a subset of these structures | |
| 58236 | -** will be accessed by the VM, and we could use Vdbe.btreeMask to figure | |
| 58237 | -** that subset out, but there is no advantage to doing so. | |
| 58238 | -** | |
| 58239 | -** If SQLite is not threadsafe and does not support shared-cache mode, this | |
| 58240 | -** function is a no-op. | |
| 58241 | -*/ | |
| 58242 | -#ifndef SQLITE_OMIT_SHARED_CACHE | |
| 58243 | -SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p){ | |
| 58244 | -#if SQLITE_THREADSAFE | |
| 58245 | - sqlite3BtreeMutexArrayEnter(&p->aMutex); | |
| 58246 | -#else | |
| 58247 | - sqlite3BtreeEnterAll(p->db); | |
| 58248 | -#endif | |
| 58249 | -} | |
| 58250 | -#endif | |
| 58251 | - | |
| 58252 | 58304 | /* |
| 58253 | 58305 | ** This function is called when a transaction opened by the database |
| 58254 | 58306 | ** handle associated with the VM passed as an argument is about to be |
| 58255 | 58307 | ** committed. If there are outstanding deferred foreign key constraint |
| 58256 | 58308 | ** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK. |
| @@ -58319,11 +58371,11 @@ | ||
| 58319 | 58371 | int mrc; /* Primary error code from p->rc */ |
| 58320 | 58372 | int eStatementOp = 0; |
| 58321 | 58373 | int isSpecialError; /* Set to true if a 'special' error */ |
| 58322 | 58374 | |
| 58323 | 58375 | /* Lock all btrees used by the statement */ |
| 58324 | - sqlite3VdbeMutexArrayEnter(p); | |
| 58376 | + sqlite3VdbeEnter(p); | |
| 58325 | 58377 | |
| 58326 | 58378 | /* Check for one of the special errors */ |
| 58327 | 58379 | mrc = p->rc & 0xff; |
| 58328 | 58380 | assert( p->rc!=SQLITE_IOERR_BLOCKED ); /* This error no longer exists */ |
| 58329 | 58381 | isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| @@ -58373,11 +58425,11 @@ | ||
| 58373 | 58425 | ){ |
| 58374 | 58426 | if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ |
| 58375 | 58427 | rc = sqlite3VdbeCheckFk(p, 1); |
| 58376 | 58428 | if( rc!=SQLITE_OK ){ |
| 58377 | 58429 | if( NEVER(p->readOnly) ){ |
| 58378 | - sqlite3BtreeMutexArrayLeave(&p->aMutex); | |
| 58430 | + sqlite3VdbeLeave(p); | |
| 58379 | 58431 | return SQLITE_ERROR; |
| 58380 | 58432 | } |
| 58381 | 58433 | rc = SQLITE_CONSTRAINT; |
| 58382 | 58434 | }else{ |
| 58383 | 58435 | /* The auto-commit flag is true, the vdbe program was successful |
| @@ -58385,11 +58437,11 @@ | ||
| 58385 | 58437 | ** key constraints to hold up the transaction. This means a commit |
| 58386 | 58438 | ** is required. */ |
| 58387 | 58439 | rc = vdbeCommit(db, p); |
| 58388 | 58440 | } |
| 58389 | 58441 | if( rc==SQLITE_BUSY && p->readOnly ){ |
| 58390 | - sqlite3BtreeMutexArrayLeave(&p->aMutex); | |
| 58442 | + sqlite3VdbeLeave(p); | |
| 58391 | 58443 | return SQLITE_BUSY; |
| 58392 | 58444 | }else if( rc!=SQLITE_OK ){ |
| 58393 | 58445 | p->rc = rc; |
| 58394 | 58446 | sqlite3RollbackAll(db); |
| 58395 | 58447 | }else{ |
| @@ -58457,11 +58509,12 @@ | ||
| 58457 | 58509 | sqlite3ResetInternalSchema(db, 0); |
| 58458 | 58510 | db->flags = (db->flags | SQLITE_InternChanges); |
| 58459 | 58511 | } |
| 58460 | 58512 | |
| 58461 | 58513 | /* Release the locks */ |
| 58462 | - sqlite3BtreeMutexArrayLeave(&p->aMutex); | |
| 58514 | + sqlite3VdbeMutexResync(p); | |
| 58515 | + sqlite3VdbeLeave(p); | |
| 58463 | 58516 | } |
| 58464 | 58517 | |
| 58465 | 58518 | /* We have successfully halted and closed the VM. Record this fact. */ |
| 58466 | 58519 | if( p->pc>=0 ){ |
| 58467 | 58520 | db->activeVdbeCnt--; |
| @@ -61978,11 +62031,11 @@ | ||
| 61978 | 62031 | } u; |
| 61979 | 62032 | /* End automatically generated code |
| 61980 | 62033 | ********************************************************************/ |
| 61981 | 62034 | |
| 61982 | 62035 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 61983 | - sqlite3VdbeMutexArrayEnter(p); | |
| 62036 | + sqlite3VdbeEnter(p); | |
| 61984 | 62037 | if( p->rc==SQLITE_NOMEM ){ |
| 61985 | 62038 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| 61986 | 62039 | ** sqlite3_column_text16() failed. */ |
| 61987 | 62040 | goto no_mem; |
| 61988 | 62041 | } |
| @@ -62815,19 +62868,31 @@ | ||
| 62815 | 62868 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 62816 | 62869 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 62817 | 62870 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 62818 | 62871 | } |
| 62819 | 62872 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 62873 | + sqlite3VdbeMutexResync(p); | |
| 62820 | 62874 | if( db->mallocFailed ){ |
| 62821 | 62875 | /* Even though a malloc() has failed, the implementation of the |
| 62822 | 62876 | ** user function may have called an sqlite3_result_XXX() function |
| 62823 | 62877 | ** to return a value. The following call releases any resources |
| 62824 | 62878 | ** associated with such a value. |
| 62825 | 62879 | */ |
| 62826 | 62880 | sqlite3VdbeMemRelease(&u.ag.ctx.s); |
| 62827 | 62881 | goto no_mem; |
| 62828 | 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 | |
| 62829 | 62894 | |
| 62830 | 62895 | /* If any auxiliary data functions have been called by this user function, |
| 62831 | 62896 | ** immediately call the destructor for any non-static values. |
| 62832 | 62897 | */ |
| 62833 | 62898 | if( u.ag.ctx.pVdbeFunc ){ |
| @@ -64091,10 +64156,11 @@ | ||
| 64091 | 64156 | } |
| 64092 | 64157 | } |
| 64093 | 64158 | if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 64094 | 64159 | sqlite3ExpirePreparedStatements(db); |
| 64095 | 64160 | sqlite3ResetInternalSchema(db, 0); |
| 64161 | + sqlite3VdbeMutexResync(p); | |
| 64096 | 64162 | db->flags = (db->flags | SQLITE_InternChanges); |
| 64097 | 64163 | } |
| 64098 | 64164 | } |
| 64099 | 64165 | |
| 64100 | 64166 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| @@ -64234,11 +64300,11 @@ | ||
| 64234 | 64300 | #if 0 /* local variables moved into u.as */ |
| 64235 | 64301 | Btree *pBt; |
| 64236 | 64302 | #endif /* local variables moved into u.as */ |
| 64237 | 64303 | |
| 64238 | 64304 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64239 | - assert( (p->btreeMask & (1<<pOp->p1))!=0 ); | |
| 64305 | + assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); | |
| 64240 | 64306 | u.as.pBt = db->aDb[pOp->p1].pBt; |
| 64241 | 64307 | |
| 64242 | 64308 | if( u.as.pBt ){ |
| 64243 | 64309 | rc = sqlite3BtreeBeginTrans(u.as.pBt, pOp->p2); |
| 64244 | 64310 | if( rc==SQLITE_BUSY ){ |
| @@ -64292,11 +64358,11 @@ | ||
| 64292 | 64358 | u.at.iDb = pOp->p1; |
| 64293 | 64359 | u.at.iCookie = pOp->p3; |
| 64294 | 64360 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 64295 | 64361 | assert( u.at.iDb>=0 && u.at.iDb<db->nDb ); |
| 64296 | 64362 | assert( db->aDb[u.at.iDb].pBt!=0 ); |
| 64297 | - assert( (p->btreeMask & (1<<u.at.iDb))!=0 ); | |
| 64363 | + assert( (p->btreeMask & (((yDbMask)1)<<u.at.iDb))!=0 ); | |
| 64298 | 64364 | |
| 64299 | 64365 | sqlite3BtreeGetMeta(db->aDb[u.at.iDb].pBt, u.at.iCookie, (u32 *)&u.at.iMeta); |
| 64300 | 64366 | pOut->u.i = u.at.iMeta; |
| 64301 | 64367 | break; |
| 64302 | 64368 | } |
| @@ -64315,11 +64381,11 @@ | ||
| 64315 | 64381 | #if 0 /* local variables moved into u.au */ |
| 64316 | 64382 | Db *pDb; |
| 64317 | 64383 | #endif /* local variables moved into u.au */ |
| 64318 | 64384 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 64319 | 64385 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64320 | - assert( (p->btreeMask & (1<<pOp->p1))!=0 ); | |
| 64386 | + assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); | |
| 64321 | 64387 | u.au.pDb = &db->aDb[pOp->p1]; |
| 64322 | 64388 | assert( u.au.pDb->pBt!=0 ); |
| 64323 | 64389 | pIn3 = &aMem[pOp->p3]; |
| 64324 | 64390 | sqlite3VdbeMemIntegerify(pIn3); |
| 64325 | 64391 | /* See note about index shifting on OP_ReadCookie */ |
| @@ -64365,11 +64431,11 @@ | ||
| 64365 | 64431 | int iGen; |
| 64366 | 64432 | Btree *pBt; |
| 64367 | 64433 | #endif /* local variables moved into u.av */ |
| 64368 | 64434 | |
| 64369 | 64435 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64370 | - assert( (p->btreeMask & (1<<pOp->p1))!=0 ); | |
| 64436 | + assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); | |
| 64371 | 64437 | u.av.pBt = db->aDb[pOp->p1].pBt; |
| 64372 | 64438 | if( u.av.pBt ){ |
| 64373 | 64439 | sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta); |
| 64374 | 64440 | u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 64375 | 64441 | }else{ |
| @@ -64391,10 +64457,11 @@ | ||
| 64391 | 64457 | ** to be invalidated whenever sqlite3_step() is called from within |
| 64392 | 64458 | ** a v-table method. |
| 64393 | 64459 | */ |
| 64394 | 64460 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){ |
| 64395 | 64461 | sqlite3ResetInternalSchema(db, pOp->p1); |
| 64462 | + sqlite3VdbeMutexResync(p); | |
| 64396 | 64463 | } |
| 64397 | 64464 | |
| 64398 | 64465 | p->expired = 1; |
| 64399 | 64466 | rc = SQLITE_SCHEMA; |
| 64400 | 64467 | } |
| @@ -64471,11 +64538,11 @@ | ||
| 64471 | 64538 | u.aw.nField = 0; |
| 64472 | 64539 | u.aw.pKeyInfo = 0; |
| 64473 | 64540 | u.aw.p2 = pOp->p2; |
| 64474 | 64541 | u.aw.iDb = pOp->p3; |
| 64475 | 64542 | assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb ); |
| 64476 | - assert( (p->btreeMask & (1<<u.aw.iDb))!=0 ); | |
| 64543 | + assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 ); | |
| 64477 | 64544 | u.aw.pDb = &db->aDb[u.aw.iDb]; |
| 64478 | 64545 | u.aw.pX = u.aw.pDb->pBt; |
| 64479 | 64546 | assert( u.aw.pX!=0 ); |
| 64480 | 64547 | if( pOp->opcode==OP_OpenWrite ){ |
| 64481 | 64548 | u.aw.wrFlag = 1; |
| @@ -66008,11 +66075,11 @@ | ||
| 66008 | 66075 | rc = SQLITE_LOCKED; |
| 66009 | 66076 | p->errorAction = OE_Abort; |
| 66010 | 66077 | }else{ |
| 66011 | 66078 | u.br.iDb = pOp->p3; |
| 66012 | 66079 | assert( u.br.iCnt==1 ); |
| 66013 | - assert( (p->btreeMask & (1<<u.br.iDb))!=0 ); | |
| 66080 | + assert( (p->btreeMask & (((yDbMask)1)<<u.br.iDb))!=0 ); | |
| 66014 | 66081 | rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved); |
| 66015 | 66082 | pOut->flags = MEM_Int; |
| 66016 | 66083 | pOut->u.i = u.br.iMoved; |
| 66017 | 66084 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 66018 | 66085 | if( rc==SQLITE_OK && u.br.iMoved!=0 ){ |
| @@ -66046,11 +66113,11 @@ | ||
| 66046 | 66113 | #if 0 /* local variables moved into u.bs */ |
| 66047 | 66114 | int nChange; |
| 66048 | 66115 | #endif /* local variables moved into u.bs */ |
| 66049 | 66116 | |
| 66050 | 66117 | u.bs.nChange = 0; |
| 66051 | - assert( (p->btreeMask & (1<<pOp->p2))!=0 ); | |
| 66118 | + assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); | |
| 66052 | 66119 | rc = sqlite3BtreeClearTable( |
| 66053 | 66120 | db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0) |
| 66054 | 66121 | ); |
| 66055 | 66122 | if( pOp->p3 ){ |
| 66056 | 66123 | p->nChange += u.bs.nChange; |
| @@ -66093,11 +66160,11 @@ | ||
| 66093 | 66160 | Db *pDb; |
| 66094 | 66161 | #endif /* local variables moved into u.bt */ |
| 66095 | 66162 | |
| 66096 | 66163 | u.bt.pgno = 0; |
| 66097 | 66164 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66098 | - assert( (p->btreeMask & (1<<pOp->p1))!=0 ); | |
| 66165 | + assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); | |
| 66099 | 66166 | u.bt.pDb = &db->aDb[pOp->p1]; |
| 66100 | 66167 | assert( u.bt.pDb->pBt!=0 ); |
| 66101 | 66168 | if( pOp->opcode==OP_CreateTable ){ |
| 66102 | 66169 | /* u.bt.flags = BTREE_INTKEY; */ |
| 66103 | 66170 | u.bt.flags = BTREE_INTKEY; |
| @@ -66122,31 +66189,27 @@ | ||
| 66122 | 66189 | int iDb; |
| 66123 | 66190 | const char *zMaster; |
| 66124 | 66191 | char *zSql; |
| 66125 | 66192 | InitData initData; |
| 66126 | 66193 | #endif /* local variables moved into u.bu */ |
| 66194 | + | |
| 66195 | + /* Any prepared statement that invokes this opcode will hold mutexes | |
| 66196 | + ** on every btree. This is a prerequisite for invoking | |
| 66197 | + ** sqlite3InitCallback(). | |
| 66198 | + */ | |
| 66199 | +#ifdef SQLITE_DEBUG | |
| 66200 | + for(u.bu.iDb=0; u.bu.iDb<db->nDb; u.bu.iDb++){ | |
| 66201 | + assert( u.bu.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) ); | |
| 66202 | + } | |
| 66203 | +#endif | |
| 66204 | + assert( p->btreeMask == ~(yDbMask)0 ); | |
| 66205 | + | |
| 66127 | 66206 | |
| 66128 | 66207 | u.bu.iDb = pOp->p1; |
| 66129 | 66208 | assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb ); |
| 66130 | - | |
| 66131 | - /* Although the mutex on the BtShared object that corresponds to | |
| 66132 | - ** database u.bu.iDb (the database containing the sqlite_master table | |
| 66133 | - ** read by this instruction) is currently held, it is necessary to | |
| 66134 | - ** obtain the mutexes on all attached databases before checking if | |
| 66135 | - ** the schema of u.bu.iDb is loaded. This is because, at the start of | |
| 66136 | - ** the sqlite3_exec() call below, SQLite will invoke | |
| 66137 | - ** sqlite3BtreeEnterAll(). If all mutexes are not already held, the | |
| 66138 | - ** u.bu.iDb mutex may be temporarily released to avoid deadlock. If | |
| 66139 | - ** this happens, then some other thread may delete the in-memory | |
| 66140 | - ** schema of database u.bu.iDb before the SQL statement runs. The schema | |
| 66141 | - ** will not be reloaded becuase the db->init.busy flag is set. This | |
| 66142 | - ** can result in a "no such table: sqlite_master" or "malformed | |
| 66143 | - ** database schema" error being returned to the user. | |
| 66144 | - */ | |
| 66145 | - assert( sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) ); | |
| 66146 | - sqlite3BtreeEnterAll(db); | |
| 66147 | - if( ALWAYS(DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded)) ){ | |
| 66209 | + assert( DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded) ); | |
| 66210 | + /* Used to be a conditional */ { | |
| 66148 | 66211 | u.bu.zMaster = SCHEMA_TABLE(u.bu.iDb); |
| 66149 | 66212 | u.bu.initData.db = db; |
| 66150 | 66213 | u.bu.initData.iDb = pOp->p1; |
| 66151 | 66214 | u.bu.initData.pzErrMsg = &p->zErrMsg; |
| 66152 | 66215 | u.bu.zSql = sqlite3MPrintf(db, |
| @@ -66163,11 +66226,10 @@ | ||
| 66163 | 66226 | if( rc==SQLITE_OK ) rc = u.bu.initData.rc; |
| 66164 | 66227 | sqlite3DbFree(db, u.bu.zSql); |
| 66165 | 66228 | db->init.busy = 0; |
| 66166 | 66229 | } |
| 66167 | 66230 | } |
| 66168 | - sqlite3BtreeLeaveAll(db); | |
| 66169 | 66231 | if( rc==SQLITE_NOMEM ){ |
| 66170 | 66232 | goto no_mem; |
| 66171 | 66233 | } |
| 66172 | 66234 | break; |
| 66173 | 66235 | } |
| @@ -66266,11 +66328,11 @@ | ||
| 66266 | 66328 | for(u.bv.j=0; u.bv.j<u.bv.nRoot; u.bv.j++){ |
| 66267 | 66329 | u.bv.aRoot[u.bv.j] = (int)sqlite3VdbeIntValue(&pIn1[u.bv.j]); |
| 66268 | 66330 | } |
| 66269 | 66331 | u.bv.aRoot[u.bv.j] = 0; |
| 66270 | 66332 | assert( pOp->p5<db->nDb ); |
| 66271 | - assert( (p->btreeMask & (1<<pOp->p5))!=0 ); | |
| 66333 | + assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 ); | |
| 66272 | 66334 | u.bv.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bv.aRoot, u.bv.nRoot, |
| 66273 | 66335 | (int)u.bv.pnErr->u.i, &u.bv.nErr); |
| 66274 | 66336 | sqlite3DbFree(db, u.bv.aRoot); |
| 66275 | 66337 | u.bv.pnErr->u.i -= u.bv.nErr; |
| 66276 | 66338 | sqlite3VdbeMemSetNull(pIn1); |
| @@ -66702,15 +66764,29 @@ | ||
| 66702 | 66764 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66703 | 66765 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66704 | 66766 | u.cb.ctx.pColl = pOp[-1].p4.pColl; |
| 66705 | 66767 | } |
| 66706 | 66768 | (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */ |
| 66769 | + sqlite3VdbeMutexResync(p); | |
| 66707 | 66770 | if( u.cb.ctx.isError ){ |
| 66708 | 66771 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s)); |
| 66709 | 66772 | rc = u.cb.ctx.isError; |
| 66710 | 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 | + | |
| 66711 | 66786 | sqlite3VdbeMemRelease(&u.cb.ctx.s); |
| 66787 | + | |
| 66712 | 66788 | break; |
| 66713 | 66789 | } |
| 66714 | 66790 | |
| 66715 | 66791 | /* Opcode: AggFinal P1 P2 * P4 * |
| 66716 | 66792 | ** |
| @@ -66730,12 +66806,15 @@ | ||
| 66730 | 66806 | #endif /* local variables moved into u.cc */ |
| 66731 | 66807 | assert( pOp->p1>0 && pOp->p1<=p->nMem ); |
| 66732 | 66808 | u.cc.pMem = &aMem[pOp->p1]; |
| 66733 | 66809 | assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 66734 | 66810 | rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc); |
| 66811 | + sqlite3VdbeMutexResync(p); | |
| 66735 | 66812 | if( rc ){ |
| 66736 | 66813 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem)); |
| 66814 | + }else if( p->expired ){ | |
| 66815 | + rc = SQLITE_ABORT; | |
| 66737 | 66816 | } |
| 66738 | 66817 | sqlite3VdbeChangeEncoding(u.cc.pMem, encoding); |
| 66739 | 66818 | UPDATE_MAX_BLOBSIZE(u.cc.pMem); |
| 66740 | 66819 | if( sqlite3VdbeMemTooBig(u.cc.pMem) ){ |
| 66741 | 66820 | goto too_big; |
| @@ -66812,25 +66891,24 @@ | ||
| 66812 | 66891 | ); |
| 66813 | 66892 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66814 | 66893 | |
| 66815 | 66894 | /* This opcode is used in two places: PRAGMA journal_mode and ATTACH. |
| 66816 | 66895 | ** In PRAGMA journal_mode, the sqlite3VdbeUsesBtree() routine is called |
| 66817 | - ** when the statment is prepared and so p->aMutex.nMutex>0. All mutexes | |
| 66896 | + ** when the statement is prepared and so p->btreeMask!=0. All mutexes | |
| 66818 | 66897 | ** are already acquired. But when used in ATTACH, sqlite3VdbeUsesBtree() |
| 66819 | 66898 | ** is not called when the statement is prepared because it requires the |
| 66820 | 66899 | ** iDb index of the database as a parameter, and the database has not |
| 66821 | 66900 | ** yet been attached so that index is unavailable. We have to wait |
| 66822 | 66901 | ** until runtime (now) to get the mutex on the newly attached database. |
| 66823 | 66902 | ** No other mutexes are required by the ATTACH command so this is safe |
| 66824 | 66903 | ** to do. |
| 66825 | 66904 | */ |
| 66826 | - assert( (p->btreeMask & (1<<pOp->p1))!=0 || p->aMutex.nMutex==0 ); | |
| 66827 | - if( p->aMutex.nMutex==0 ){ | |
| 66905 | + if( p->btreeMask==0 ){ | |
| 66828 | 66906 | /* This occurs right after ATTACH. Get a mutex on the newly ATTACHed |
| 66829 | 66907 | ** database. */ |
| 66830 | 66908 | sqlite3VdbeUsesBtree(p, pOp->p1); |
| 66831 | - sqlite3VdbeMutexArrayEnter(p); | |
| 66909 | + sqlite3VdbeEnter(p); | |
| 66832 | 66910 | } |
| 66833 | 66911 | |
| 66834 | 66912 | u.ce.pBt = db->aDb[pOp->p1].pBt; |
| 66835 | 66913 | u.ce.pPager = sqlite3BtreePager(u.ce.pBt); |
| 66836 | 66914 | u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager); |
| @@ -66928,11 +67006,11 @@ | ||
| 66928 | 67006 | #if 0 /* local variables moved into u.cf */ |
| 66929 | 67007 | Btree *pBt; |
| 66930 | 67008 | #endif /* local variables moved into u.cf */ |
| 66931 | 67009 | |
| 66932 | 67010 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66933 | - assert( (p->btreeMask & (1<<pOp->p1))!=0 ); | |
| 67011 | + assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); | |
| 66934 | 67012 | u.cf.pBt = db->aDb[pOp->p1].pBt; |
| 66935 | 67013 | rc = sqlite3BtreeIncrVacuum(u.cf.pBt); |
| 66936 | 67014 | if( rc==SQLITE_DONE ){ |
| 66937 | 67015 | pc = pOp->p2 - 1; |
| 66938 | 67016 | rc = SQLITE_OK; |
| @@ -66977,11 +67055,11 @@ | ||
| 66977 | 67055 | case OP_TableLock: { |
| 66978 | 67056 | u8 isWriteLock = (u8)pOp->p3; |
| 66979 | 67057 | if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){ |
| 66980 | 67058 | int p1 = pOp->p1; |
| 66981 | 67059 | assert( p1>=0 && p1<db->nDb ); |
| 66982 | - assert( (p->btreeMask & (1<<p1))!=0 ); | |
| 67060 | + assert( (p->btreeMask & (((yDbMask)1)<<p1))!=0 ); | |
| 66983 | 67061 | assert( isWriteLock==0 || isWriteLock==1 ); |
| 66984 | 67062 | rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock); |
| 66985 | 67063 | if( (rc&0xFF)==SQLITE_LOCKED ){ |
| 66986 | 67064 | const char *z = pOp->p4.z; |
| 66987 | 67065 | sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z); |
| @@ -67482,17 +67560,20 @@ | ||
| 67482 | 67560 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 67483 | 67561 | pc, p->zSql, p->zErrMsg); |
| 67484 | 67562 | sqlite3VdbeHalt(p); |
| 67485 | 67563 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 67486 | 67564 | rc = SQLITE_ERROR; |
| 67487 | - if( resetSchemaOnFault ) sqlite3ResetInternalSchema(db, 0); | |
| 67565 | + if( resetSchemaOnFault ){ | |
| 67566 | + sqlite3ResetInternalSchema(db, 0); | |
| 67567 | + sqlite3VdbeMutexResync(p); | |
| 67568 | + } | |
| 67488 | 67569 | |
| 67489 | 67570 | /* This is the only way out of this procedure. We have to |
| 67490 | 67571 | ** release the mutexes on btrees that were acquired at the |
| 67491 | 67572 | ** top. */ |
| 67492 | 67573 | vdbe_return: |
| 67493 | - sqlite3BtreeMutexArrayLeave(&p->aMutex); | |
| 67574 | + sqlite3VdbeLeave(p); | |
| 67494 | 67575 | return rc; |
| 67495 | 67576 | |
| 67496 | 67577 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 67497 | 67578 | ** is encountered. |
| 67498 | 67579 | */ |
| @@ -73966,10 +74047,26 @@ | ||
| 73966 | 74047 | if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){ |
| 73967 | 74048 | sqlite3VdbeAddOp4(v, OP_ParseSchema, 1, 0, 0, zWhere, P4_DYNAMIC); |
| 73968 | 74049 | } |
| 73969 | 74050 | #endif |
| 73970 | 74051 | } |
| 74052 | + | |
| 74053 | +/* | |
| 74054 | +** Parameter zName is the name of a table that is about to be altered | |
| 74055 | +** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN). | |
| 74056 | +** If the table is a system table, this function leaves an error message | |
| 74057 | +** in pParse->zErr (system tables may not be altered) and returns non-zero. | |
| 74058 | +** | |
| 74059 | +** Or, if zName is not a system table, zero is returned. | |
| 74060 | +*/ | |
| 74061 | +static int isSystemTable(Parse *pParse, const char *zName){ | |
| 74062 | + if( sqlite3Strlen30(zName)>6 && 0==sqlite3StrNICmp(zName, "sqlite_", 7) ){ | |
| 74063 | + sqlite3ErrorMsg(pParse, "table %s may not be altered", zName); | |
| 74064 | + return 1; | |
| 74065 | + } | |
| 74066 | + return 0; | |
| 74067 | +} | |
| 73971 | 74068 | |
| 73972 | 74069 | /* |
| 73973 | 74070 | ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" |
| 73974 | 74071 | ** command. |
| 73975 | 74072 | */ |
| @@ -74017,18 +74114,15 @@ | ||
| 74017 | 74114 | } |
| 74018 | 74115 | |
| 74019 | 74116 | /* Make sure it is not a system table being altered, or a reserved name |
| 74020 | 74117 | ** that the table is being renamed to. |
| 74021 | 74118 | */ |
| 74022 | - if( sqlite3Strlen30(pTab->zName)>6 | |
| 74023 | - && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) | |
| 74024 | - ){ | |
| 74025 | - sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName); | |
| 74119 | + if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){ | |
| 74026 | 74120 | goto exit_rename_table; |
| 74027 | 74121 | } |
| 74028 | - if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ | |
| 74029 | - goto exit_rename_table; | |
| 74122 | + if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto | |
| 74123 | + exit_rename_table; | |
| 74030 | 74124 | } |
| 74031 | 74125 | |
| 74032 | 74126 | #ifndef SQLITE_OMIT_VIEW |
| 74033 | 74127 | if( pTab->pSelect ){ |
| 74034 | 74128 | sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName); |
| @@ -74356,10 +74450,13 @@ | ||
| 74356 | 74450 | /* Make sure this is not an attempt to ALTER a view. */ |
| 74357 | 74451 | if( pTab->pSelect ){ |
| 74358 | 74452 | sqlite3ErrorMsg(pParse, "Cannot add a column to a view"); |
| 74359 | 74453 | goto exit_begin_add_column; |
| 74360 | 74454 | } |
| 74455 | + if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){ | |
| 74456 | + goto exit_begin_add_column; | |
| 74457 | + } | |
| 74361 | 74458 | |
| 74362 | 74459 | assert( pTab->addColOffset>0 ); |
| 74363 | 74460 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 74364 | 74461 | |
| 74365 | 74462 | /* Put a copy of the Table struct in Parse.pNewTable for the |
| @@ -74443,11 +74540,12 @@ | ||
| 74443 | 74540 | */ |
| 74444 | 74541 | static void openStatTable( |
| 74445 | 74542 | Parse *pParse, /* Parsing context */ |
| 74446 | 74543 | int iDb, /* The database we are looking in */ |
| 74447 | 74544 | int iStatCur, /* Open the sqlite_stat1 table on this cursor */ |
| 74448 | - const char *zWhere /* Delete entries associated with this table */ | |
| 74545 | + const char *zWhere, /* Delete entries for this table or index */ | |
| 74546 | + const char *zWhereType /* Either "tbl" or "idx" */ | |
| 74449 | 74547 | ){ |
| 74450 | 74548 | static const struct { |
| 74451 | 74549 | const char *zName; |
| 74452 | 74550 | const char *zCols; |
| 74453 | 74551 | } aTable[] = { |
| @@ -74488,11 +74586,11 @@ | ||
| 74488 | 74586 | ** entire contents of the table. */ |
| 74489 | 74587 | aRoot[i] = pStat->tnum; |
| 74490 | 74588 | sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab); |
| 74491 | 74589 | if( zWhere ){ |
| 74492 | 74590 | sqlite3NestedParse(pParse, |
| 74493 | - "DELETE FROM %Q.%s WHERE tbl=%Q", pDb->zName, zTab, zWhere | |
| 74591 | + "DELETE FROM %Q.%s WHERE %s=%Q", pDb->zName, zTab, zWhereType, zWhere | |
| 74494 | 74592 | ); |
| 74495 | 74593 | }else{ |
| 74496 | 74594 | /* The sqlite_stat[12] table already exists. Delete all rows. */ |
| 74497 | 74595 | sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb); |
| 74498 | 74596 | } |
| @@ -74512,10 +74610,11 @@ | ||
| 74512 | 74610 | ** a single table. |
| 74513 | 74611 | */ |
| 74514 | 74612 | static void analyzeOneTable( |
| 74515 | 74613 | Parse *pParse, /* Parser context */ |
| 74516 | 74614 | Table *pTab, /* Table whose indices are to be analyzed */ |
| 74615 | + Index *pOnlyIdx, /* If not NULL, only analyze this one index */ | |
| 74517 | 74616 | int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */ |
| 74518 | 74617 | int iMem /* Available memory locations begin here */ |
| 74519 | 74618 | ){ |
| 74520 | 74619 | sqlite3 *db = pParse->db; /* Database handle */ |
| 74521 | 74620 | Index *pIdx; /* An index to being analyzed */ |
| @@ -74522,12 +74621,11 @@ | ||
| 74522 | 74621 | int iIdxCur; /* Cursor open on index being analyzed */ |
| 74523 | 74622 | Vdbe *v; /* The virtual machine being built up */ |
| 74524 | 74623 | int i; /* Loop counter */ |
| 74525 | 74624 | int topOfLoop; /* The top of the loop */ |
| 74526 | 74625 | int endOfLoop; /* The end of the loop */ |
| 74527 | - int addr = 0; /* The address of an instruction */ | |
| 74528 | - int jZeroRows = 0; /* Jump from here if number of rows is zero */ | |
| 74626 | + int jZeroRows = -1; /* Jump from here if number of rows is zero */ | |
| 74529 | 74627 | int iDb; /* Index of database containing pTab */ |
| 74530 | 74628 | int regTabname = iMem++; /* Register containing table name */ |
| 74531 | 74629 | int regIdxname = iMem++; /* Register containing index name */ |
| 74532 | 74630 | int regSampleno = iMem++; /* Register containing next sample number */ |
| 74533 | 74631 | int regCol = iMem++; /* Content of a column analyzed table */ |
| @@ -74534,10 +74632,11 @@ | ||
| 74534 | 74632 | int regRec = iMem++; /* Register holding completed record */ |
| 74535 | 74633 | int regTemp = iMem++; /* Temporary use register */ |
| 74536 | 74634 | int regRowid = iMem++; /* Rowid for the inserted record */ |
| 74537 | 74635 | |
| 74538 | 74636 | #ifdef SQLITE_ENABLE_STAT2 |
| 74637 | + int addr = 0; /* Instruction address */ | |
| 74539 | 74638 | int regTemp2 = iMem++; /* Temporary use register */ |
| 74540 | 74639 | int regSamplerecno = iMem++; /* Index of next sample to record */ |
| 74541 | 74640 | int regRecno = iMem++; /* Current sample index */ |
| 74542 | 74641 | int regLast = iMem++; /* Index of last sample to record */ |
| 74543 | 74642 | int regFirst = iMem++; /* Index of first sample to record */ |
| @@ -74569,13 +74668,16 @@ | ||
| 74569 | 74668 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 74570 | 74669 | |
| 74571 | 74670 | iIdxCur = pParse->nTab++; |
| 74572 | 74671 | sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0); |
| 74573 | 74672 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 74574 | - int nCol = pIdx->nColumn; | |
| 74575 | - KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx); | |
| 74673 | + int nCol; | |
| 74674 | + KeyInfo *pKey; | |
| 74576 | 74675 | |
| 74676 | + if( pOnlyIdx && pOnlyIdx!=pIdx ) continue; | |
| 74677 | + nCol = pIdx->nColumn; | |
| 74678 | + pKey = sqlite3IndexKeyinfo(pParse, pIdx); | |
| 74577 | 74679 | if( iMem+1+(nCol*2)>pParse->nMem ){ |
| 74578 | 74680 | pParse->nMem = iMem+1+(nCol*2); |
| 74579 | 74681 | } |
| 74580 | 74682 | |
| 74581 | 74683 | /* Open a cursor to the index to be analyzed. */ |
| @@ -74728,11 +74830,11 @@ | ||
| 74728 | 74830 | ** If K==0 then no entry is made into the sqlite_stat1 table. |
| 74729 | 74831 | ** If K>0 then it is always the case the D>0 so division by zero |
| 74730 | 74832 | ** is never possible. |
| 74731 | 74833 | */ |
| 74732 | 74834 | sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno); |
| 74733 | - if( jZeroRows==0 ){ | |
| 74835 | + if( jZeroRows<0 ){ | |
| 74734 | 74836 | jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem); |
| 74735 | 74837 | } |
| 74736 | 74838 | for(i=0; i<nCol; i++){ |
| 74737 | 74839 | sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0); |
| 74738 | 74840 | sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno); |
| @@ -74754,24 +74856,22 @@ | ||
| 74754 | 74856 | if( pTab->pIndex==0 ){ |
| 74755 | 74857 | sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb); |
| 74756 | 74858 | VdbeComment((v, "%s", pTab->zName)); |
| 74757 | 74859 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regSampleno); |
| 74758 | 74860 | sqlite3VdbeAddOp1(v, OP_Close, iIdxCur); |
| 74861 | + jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regSampleno); | |
| 74759 | 74862 | }else{ |
| 74760 | - assert( jZeroRows>0 ); | |
| 74761 | - addr = sqlite3VdbeAddOp0(v, OP_Goto); | |
| 74762 | 74863 | sqlite3VdbeJumpHere(v, jZeroRows); |
| 74864 | + jZeroRows = sqlite3VdbeAddOp0(v, OP_Goto); | |
| 74763 | 74865 | } |
| 74764 | 74866 | sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname); |
| 74765 | 74867 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0); |
| 74766 | 74868 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid); |
| 74767 | 74869 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid); |
| 74768 | 74870 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 74769 | 74871 | if( pParse->nMem<regRec ) pParse->nMem = regRec; |
| 74770 | - if( jZeroRows ){ | |
| 74771 | - sqlite3VdbeJumpHere(v, addr); | |
| 74772 | - } | |
| 74872 | + sqlite3VdbeJumpHere(v, jZeroRows); | |
| 74773 | 74873 | } |
| 74774 | 74874 | |
| 74775 | 74875 | /* |
| 74776 | 74876 | ** Generate code that will cause the most recent index analysis to |
| 74777 | 74877 | ** be loaded into internal hash tables where is can be used. |
| @@ -74794,35 +74894,40 @@ | ||
| 74794 | 74894 | int iMem; |
| 74795 | 74895 | |
| 74796 | 74896 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74797 | 74897 | iStatCur = pParse->nTab; |
| 74798 | 74898 | pParse->nTab += 2; |
| 74799 | - openStatTable(pParse, iDb, iStatCur, 0); | |
| 74899 | + openStatTable(pParse, iDb, iStatCur, 0, 0); | |
| 74800 | 74900 | iMem = pParse->nMem+1; |
| 74801 | 74901 | for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 74802 | 74902 | Table *pTab = (Table*)sqliteHashData(k); |
| 74803 | - analyzeOneTable(pParse, pTab, iStatCur, iMem); | |
| 74903 | + analyzeOneTable(pParse, pTab, 0, iStatCur, iMem); | |
| 74804 | 74904 | } |
| 74805 | 74905 | loadAnalysis(pParse, iDb); |
| 74806 | 74906 | } |
| 74807 | 74907 | |
| 74808 | 74908 | /* |
| 74809 | 74909 | ** Generate code that will do an analysis of a single table in |
| 74810 | -** a database. | |
| 74910 | +** a database. If pOnlyIdx is not NULL then it is a single index | |
| 74911 | +** in pTab that should be analyzed. | |
| 74811 | 74912 | */ |
| 74812 | -static void analyzeTable(Parse *pParse, Table *pTab){ | |
| 74913 | +static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){ | |
| 74813 | 74914 | int iDb; |
| 74814 | 74915 | int iStatCur; |
| 74815 | 74916 | |
| 74816 | 74917 | assert( pTab!=0 ); |
| 74817 | 74918 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| 74818 | 74919 | iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 74819 | 74920 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74820 | 74921 | iStatCur = pParse->nTab; |
| 74821 | 74922 | pParse->nTab += 2; |
| 74822 | - openStatTable(pParse, iDb, iStatCur, pTab->zName); | |
| 74823 | - analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem+1); | |
| 74923 | + if( pOnlyIdx ){ | |
| 74924 | + openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx"); | |
| 74925 | + }else{ | |
| 74926 | + openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl"); | |
| 74927 | + } | |
| 74928 | + analyzeOneTable(pParse, pTab, pOnlyIdx, iStatCur, pParse->nMem+1); | |
| 74824 | 74929 | loadAnalysis(pParse, iDb); |
| 74825 | 74930 | } |
| 74826 | 74931 | |
| 74827 | 74932 | /* |
| 74828 | 74933 | ** Generate code for the ANALYZE command. The parser calls this routine |
| @@ -74840,10 +74945,11 @@ | ||
| 74840 | 74945 | sqlite3 *db = pParse->db; |
| 74841 | 74946 | int iDb; |
| 74842 | 74947 | int i; |
| 74843 | 74948 | char *z, *zDb; |
| 74844 | 74949 | Table *pTab; |
| 74950 | + Index *pIdx; | |
| 74845 | 74951 | Token *pTableName; |
| 74846 | 74952 | |
| 74847 | 74953 | /* Read the database schema. If an error occurs, leave an error message |
| 74848 | 74954 | ** and code in pParse and return NULL. */ |
| 74849 | 74955 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| @@ -74864,29 +74970,31 @@ | ||
| 74864 | 74970 | if( iDb>=0 ){ |
| 74865 | 74971 | analyzeDatabase(pParse, iDb); |
| 74866 | 74972 | }else{ |
| 74867 | 74973 | z = sqlite3NameFromToken(db, pName1); |
| 74868 | 74974 | if( z ){ |
| 74869 | - pTab = sqlite3LocateTable(pParse, 0, z, 0); | |
| 74975 | + if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){ | |
| 74976 | + analyzeTable(pParse, pIdx->pTable, pIdx); | |
| 74977 | + }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){ | |
| 74978 | + analyzeTable(pParse, pTab, 0); | |
| 74979 | + } | |
| 74870 | 74980 | sqlite3DbFree(db, z); |
| 74871 | - if( pTab ){ | |
| 74872 | - analyzeTable(pParse, pTab); | |
| 74873 | - } | |
| 74874 | 74981 | } |
| 74875 | 74982 | } |
| 74876 | 74983 | }else{ |
| 74877 | 74984 | /* Form 3: Analyze the fully qualified table name */ |
| 74878 | 74985 | iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName); |
| 74879 | 74986 | if( iDb>=0 ){ |
| 74880 | 74987 | zDb = db->aDb[iDb].zName; |
| 74881 | 74988 | z = sqlite3NameFromToken(db, pTableName); |
| 74882 | 74989 | if( z ){ |
| 74883 | - pTab = sqlite3LocateTable(pParse, 0, z, zDb); | |
| 74990 | + if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){ | |
| 74991 | + analyzeTable(pParse, pIdx->pTable, pIdx); | |
| 74992 | + }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){ | |
| 74993 | + analyzeTable(pParse, pTab, 0); | |
| 74994 | + } | |
| 74884 | 74995 | sqlite3DbFree(db, z); |
| 74885 | - if( pTab ){ | |
| 74886 | - analyzeTable(pParse, pTab); | |
| 74887 | - } | |
| 74888 | 74996 | } |
| 74889 | 74997 | } |
| 74890 | 74998 | } |
| 74891 | 74999 | } |
| 74892 | 75000 | |
| @@ -76055,11 +76163,11 @@ | ||
| 76055 | 76163 | ** set for each database that is used. Generate code to start a |
| 76056 | 76164 | ** transaction on each used database and to verify the schema cookie |
| 76057 | 76165 | ** on each used database. |
| 76058 | 76166 | */ |
| 76059 | 76167 | if( pParse->cookieGoto>0 ){ |
| 76060 | - tAttachMask mask; | |
| 76168 | + yDbMask mask; | |
| 76061 | 76169 | int iDb; |
| 76062 | 76170 | sqlite3VdbeJumpHere(v, pParse->cookieGoto-1); |
| 76063 | 76171 | for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ |
| 76064 | 76172 | if( (mask & pParse->cookieMask)==0 ) continue; |
| 76065 | 76173 | sqlite3VdbeUsesBtree(v, iDb); |
| @@ -79351,16 +79459,16 @@ | ||
| 79351 | 79459 | if( v==0 ) return; /* This only happens if there was a prior error */ |
| 79352 | 79460 | pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; |
| 79353 | 79461 | } |
| 79354 | 79462 | if( iDb>=0 ){ |
| 79355 | 79463 | sqlite3 *db = pToplevel->db; |
| 79356 | - tAttachMask mask; | |
| 79464 | + yDbMask mask; | |
| 79357 | 79465 | |
| 79358 | 79466 | assert( iDb<db->nDb ); |
| 79359 | 79467 | assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 79360 | 79468 | assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 79361 | - mask = ((tAttachMask)1)<<iDb; | |
| 79469 | + mask = ((yDbMask)1)<<iDb; | |
| 79362 | 79470 | if( (pToplevel->cookieMask & mask)==0 ){ |
| 79363 | 79471 | pToplevel->cookieMask |= mask; |
| 79364 | 79472 | pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 79365 | 79473 | if( !OMIT_TEMPDB && iDb==1 ){ |
| 79366 | 79474 | sqlite3OpenTempDatabase(pToplevel); |
| @@ -79383,11 +79491,11 @@ | ||
| 79383 | 79491 | ** necessary to undo a write and the checkpoint should not be set. |
| 79384 | 79492 | */ |
| 79385 | 79493 | SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){ |
| 79386 | 79494 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 79387 | 79495 | sqlite3CodeVerifySchema(pParse, iDb); |
| 79388 | - pToplevel->writeMask |= ((tAttachMask)1)<<iDb; | |
| 79496 | + pToplevel->writeMask |= ((yDbMask)1)<<iDb; | |
| 79389 | 79497 | pToplevel->isMultiWrite |= setStatement; |
| 79390 | 79498 | } |
| 79391 | 79499 | |
| 79392 | 79500 | /* |
| 79393 | 79501 | ** Indicate that the statement currently under construction might write |
| @@ -99567,11 +99675,11 @@ | ||
| 99567 | 99675 | ** VALUE and how common that value is according to the histogram. |
| 99568 | 99676 | */ |
| 99569 | 99677 | if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 ){ |
| 99570 | 99678 | if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){ |
| 99571 | 99679 | testcase( pFirstTerm->eOperator==WO_EQ ); |
| 99572 | - testcase( pFirstTerm->pOperator==WO_ISNULL ); | |
| 99680 | + testcase( pFirstTerm->eOperator==WO_ISNULL ); | |
| 99573 | 99681 | whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow); |
| 99574 | 99682 | }else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){ |
| 99575 | 99683 | whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow); |
| 99576 | 99684 | } |
| 99577 | 99685 | } |
| 99578 | 99686 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,9 +1,9 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.7.6. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a one translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| 9 | ** |
| @@ -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-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -3521,11 +3521,13 @@ | |
| 3521 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
| 3522 | ** that implements the [SELECT] statement. ^The second parameter is the |
| 3523 | ** column number. ^The leftmost column is number 0. |
| 3524 | ** |
| 3525 | ** ^The returned string pointer is valid until either the [prepared statement] |
| 3526 | ** is destroyed by [sqlite3_finalize()] or until the next call to |
| 3527 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
| 3528 | ** |
| 3529 | ** ^If sqlite3_malloc() fails during the processing of either routine |
| 3530 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
| 3531 | ** NULL pointer is returned. |
| @@ -3547,11 +3549,13 @@ | |
| 3547 | ** ^The name of the database or table or column can be returned as |
| 3548 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 3549 | ** the database name, the _table_ routines return the table name, and |
| 3550 | ** the origin_ routines return the column name. |
| 3551 | ** ^The returned string is valid until the [prepared statement] is destroyed |
| 3552 | ** using [sqlite3_finalize()] or until the same information is requested |
| 3553 | ** again in a different encoding. |
| 3554 | ** |
| 3555 | ** ^The names returned are the original un-aliased names of the |
| 3556 | ** database, table, and column. |
| 3557 | ** |
| @@ -7648,22 +7652,10 @@ | |
| 7648 | ** Forward declarations of structure |
| 7649 | */ |
| 7650 | typedef struct Btree Btree; |
| 7651 | typedef struct BtCursor BtCursor; |
| 7652 | typedef struct BtShared BtShared; |
| 7653 | typedef struct BtreeMutexArray BtreeMutexArray; |
| 7654 | |
| 7655 | /* |
| 7656 | ** This structure records all of the Btrees that need to hold |
| 7657 | ** a mutex before we enter sqlite3VdbeExec(). The Btrees are |
| 7658 | ** are placed in aBtree[] in order of aBtree[]->pBt. That way, |
| 7659 | ** we can always lock and unlock them all quickly. |
| 7660 | */ |
| 7661 | struct BtreeMutexArray { |
| 7662 | int nMutex; |
| 7663 | Btree *aBtree[SQLITE_MAX_ATTACHED+1]; |
| 7664 | }; |
| 7665 | |
| 7666 | |
| 7667 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 7668 | const char *zFilename, /* Name of database file to open */ |
| 7669 | sqlite3 *db, /* Associated database connection */ |
| @@ -7696,11 +7688,11 @@ | |
| 7696 | SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*); |
| 7697 | SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int); |
| 7698 | SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); |
| 7699 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int); |
| 7700 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); |
| 7701 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*); |
| 7702 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); |
| 7703 | SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*); |
| 7704 | SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); |
| 7705 | SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
| 7706 | SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*); |
| @@ -7837,27 +7829,23 @@ | |
| 7837 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE |
| 7838 | SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*); |
| 7839 | SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*); |
| 7840 | SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*); |
| 7841 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); |
| 7842 | SQLITE_PRIVATE void sqlite3BtreeMutexArrayEnter(BtreeMutexArray*); |
| 7843 | SQLITE_PRIVATE void sqlite3BtreeMutexArrayLeave(BtreeMutexArray*); |
| 7844 | SQLITE_PRIVATE void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*); |
| 7845 | #ifndef NDEBUG |
| 7846 | /* These routines are used inside assert() statements only. */ |
| 7847 | SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); |
| 7848 | SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); |
| 7849 | #endif |
| 7850 | #else |
| 7851 | |
| 7852 | # define sqlite3BtreeLeave(X) |
| 7853 | # define sqlite3BtreeEnterCursor(X) |
| 7854 | # define sqlite3BtreeLeaveCursor(X) |
| 7855 | # define sqlite3BtreeLeaveAll(X) |
| 7856 | # define sqlite3BtreeMutexArrayEnter(X) |
| 7857 | # define sqlite3BtreeMutexArrayLeave(X) |
| 7858 | # define sqlite3BtreeMutexArrayInsert(X,Y) |
| 7859 | |
| 7860 | # define sqlite3BtreeHoldsMutex(X) 1 |
| 7861 | # define sqlite3BtreeHoldsAllMutexes(X) 1 |
| 7862 | #endif |
| 7863 | |
| @@ -10467,15 +10455,17 @@ | |
| 10467 | SubProgram *pProgram; /* Program implementing pTrigger/orconf */ |
| 10468 | u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */ |
| 10469 | TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */ |
| 10470 | }; |
| 10471 | |
| 10472 | /* Datatype for the bitmask of all attached databases */ |
| 10473 | #if SQLITE_MAX_ATTACHED>30 |
| 10474 | typedef sqlite3_uint64 tAttachMask; |
| 10475 | #else |
| 10476 | typedef unsigned int tAttachMask; |
| 10477 | #endif |
| 10478 | |
| 10479 | /* |
| 10480 | ** An SQL parser context. A copy of this structure is passed through |
| 10481 | ** the parser and down into all the parser action routine in order to |
| @@ -10522,12 +10512,12 @@ | |
| 10522 | u8 tempReg; /* iReg is a temp register that needs to be freed */ |
| 10523 | int iLevel; /* Nesting level */ |
| 10524 | int iReg; /* Reg with value of this column. 0 means none. */ |
| 10525 | int lru; /* Least recently used entry has the smallest value */ |
| 10526 | } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */ |
| 10527 | tAttachMask writeMask; /* Start a write transaction on these databases */ |
| 10528 | tAttachMask cookieMask; /* Bitmask of schema verified databases */ |
| 10529 | u8 isMultiWrite; /* True if statement may affect/insert multiple rows */ |
| 10530 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 10531 | int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ |
| 10532 | int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ |
| 10533 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| @@ -12488,14 +12478,14 @@ | |
| 12488 | u8 inVtabMethod; /* See comments above */ |
| 12489 | u8 usesStmtJournal; /* True if uses a statement journal */ |
| 12490 | u8 readOnly; /* True for read-only statements */ |
| 12491 | u8 isPrepareV2; /* True if prepared with prepare_v2() */ |
| 12492 | int nChange; /* Number of db changes made since last reset */ |
| 12493 | tAttachMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 12494 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 12495 | int aCounter[3]; /* Counters used by sqlite3_stmt_status() */ |
| 12496 | BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */ |
| 12497 | #ifndef SQLITE_OMIT_TRACE |
| 12498 | i64 startTime; /* Time when query started - used for profiling */ |
| 12499 | #endif |
| 12500 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 12501 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| @@ -12573,10 +12563,13 @@ | |
| 12573 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 12574 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| 12575 | SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); |
| 12576 | SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *); |
| 12577 | SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem); |
| 12578 | |
| 12579 | #ifdef SQLITE_DEBUG |
| 12580 | SQLITE_PRIVATE void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); |
| 12581 | #endif |
| 12582 | |
| @@ -12584,16 +12577,10 @@ | |
| 12584 | SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int); |
| 12585 | #else |
| 12586 | # define sqlite3VdbeCheckFk(p,i) 0 |
| 12587 | #endif |
| 12588 | |
| 12589 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 12590 | SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p); |
| 12591 | #else |
| 12592 | # define sqlite3VdbeMutexArrayEnter(p) |
| 12593 | #endif |
| 12594 | |
| 12595 | SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8); |
| 12596 | #ifdef SQLITE_DEBUG |
| 12597 | SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*); |
| 12598 | SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); |
| 12599 | #endif |
| @@ -19794,11 +19781,11 @@ | |
| 19794 | } |
| 19795 | SQLITE_PRIVATE int sqlite3Utf8Read( |
| 19796 | const unsigned char *zIn, /* First byte of UTF-8 character */ |
| 19797 | const unsigned char **pzNext /* Write first byte past UTF-8 char here */ |
| 19798 | ){ |
| 19799 | int c; |
| 19800 | |
| 19801 | /* Same as READ_UTF8() above but without the zTerm parameter. |
| 19802 | ** For this routine, we assume the UTF8 string is always zero-terminated. |
| 19803 | */ |
| 19804 | c = *(zIn++); |
| @@ -20037,19 +20024,19 @@ | |
| 20037 | ** Translate UTF-8 to UTF-8. |
| 20038 | ** |
| 20039 | ** This has the effect of making sure that the string is well-formed |
| 20040 | ** UTF-8. Miscoded characters are removed. |
| 20041 | ** |
| 20042 | ** The translation is done in-place (since it is impossible for the |
| 20043 | ** correct UTF-8 encoding to be longer than a malformed encoding). |
| 20044 | */ |
| 20045 | SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char *zIn){ |
| 20046 | unsigned char *zOut = zIn; |
| 20047 | unsigned char *zStart = zIn; |
| 20048 | u32 c; |
| 20049 | |
| 20050 | while( zIn[0] ){ |
| 20051 | c = sqlite3Utf8Read(zIn, (const u8**)&zIn); |
| 20052 | if( c!=0xfffd ){ |
| 20053 | WRITE_UTF8(zOut, c); |
| 20054 | } |
| 20055 | } |
| @@ -23750,11 +23737,11 @@ | |
| 23750 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 23751 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 23752 | #else |
| 23753 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, |
| 23754 | #endif |
| 23755 | #define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent) |
| 23756 | |
| 23757 | }; /* End of the overrideable system calls */ |
| 23758 | |
| 23759 | /* |
| 23760 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| @@ -23773,14 +23760,14 @@ | |
| 23773 | UNUSED_PARAMETER(pNotUsed); |
| 23774 | if( zName==0 ){ |
| 23775 | /* If no zName is given, restore all system calls to their default |
| 23776 | ** settings and return NULL |
| 23777 | */ |
| 23778 | for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ |
| 23779 | if( aSyscall[i].pDefault ){ |
| 23780 | aSyscall[i].pCurrent = aSyscall[i].pDefault; |
| 23781 | rc = SQLITE_OK; |
| 23782 | } |
| 23783 | } |
| 23784 | }else{ |
| 23785 | /* If zName is specified, operate on only the one system call |
| 23786 | ** specified. |
| @@ -23823,22 +23810,20 @@ | |
| 23823 | ** then return the name of the first system call. Return NULL if zName |
| 23824 | ** is the last system call or if zName is not the name of a valid |
| 23825 | ** system call. |
| 23826 | */ |
| 23827 | static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ |
| 23828 | unsigned int i; |
| 23829 | |
| 23830 | UNUSED_PARAMETER(p); |
| 23831 | if( zName==0 ){ |
| 23832 | i = -1; |
| 23833 | }else{ |
| 23834 | for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0])-1; i++){ |
| 23835 | if( strcmp(zName, aSyscall[0].zName)==0 ) break; |
| 23836 | } |
| 23837 | } |
| 23838 | for(i++; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ |
| 23839 | if( aSyscall[0].pCurrent!=0 ) return aSyscall[0].zName; |
| 23840 | } |
| 23841 | return 0; |
| 23842 | } |
| 23843 | |
| 23844 | /* |
| @@ -23974,13 +23959,26 @@ | |
| 23974 | ** Errors during initialization of locks, or file system support for locks, |
| 23975 | ** should handle ENOLCK, ENOTSUP, EOPNOTSUPP separately. |
| 23976 | */ |
| 23977 | static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) { |
| 23978 | switch (posixError) { |
| 23979 | case 0: |
| 23980 | return SQLITE_OK; |
| 23981 | |
| 23982 | case EAGAIN: |
| 23983 | case ETIMEDOUT: |
| 23984 | case EBUSY: |
| 23985 | case EINTR: |
| 23986 | case ENOLCK: |
| @@ -23998,12 +23996,19 @@ | |
| 23998 | } |
| 23999 | /* else fall through */ |
| 24000 | case EPERM: |
| 24001 | return SQLITE_PERM; |
| 24002 | |
| 24003 | case EDEADLK: |
| 24004 | return SQLITE_IOERR_BLOCKED; |
| 24005 | |
| 24006 | #if EOPNOTSUPP!=ENOTSUP |
| 24007 | case EOPNOTSUPP: |
| 24008 | /* something went terribly awry, unless during file system support |
| 24009 | * introspection, in which it actually means what it says */ |
| @@ -24418,11 +24423,11 @@ | |
| 24418 | ** when this function is called. |
| 24419 | */ |
| 24420 | static void releaseInodeInfo(unixFile *pFile){ |
| 24421 | unixInodeInfo *pInode = pFile->pInode; |
| 24422 | assert( unixMutexHeld() ); |
| 24423 | if( pInode ){ |
| 24424 | pInode->nRef--; |
| 24425 | if( pInode->nRef==0 ){ |
| 24426 | assert( pInode->pShmNode==0 ); |
| 24427 | closePendingFds(pFile); |
| 24428 | if( pInode->pPrev ){ |
| @@ -24560,14 +24565,13 @@ | |
| 24560 | struct flock lock; |
| 24561 | lock.l_whence = SEEK_SET; |
| 24562 | lock.l_start = RESERVED_BYTE; |
| 24563 | lock.l_len = 1; |
| 24564 | lock.l_type = F_WRLCK; |
| 24565 | if (-1 == osFcntl(pFile->h, F_GETLK, &lock)) { |
| 24566 | int tErrno = errno; |
| 24567 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); |
| 24568 | pFile->lastErrno = tErrno; |
| 24569 | } else if( lock.l_type!=F_UNLCK ){ |
| 24570 | reserved = 1; |
| 24571 | } |
| 24572 | } |
| 24573 | #endif |
| @@ -24592,10 +24596,13 @@ | |
| 24592 | ** operating system does not participate. |
| 24593 | ** |
| 24594 | ** This function is a pass-through to fcntl(F_SETLK) if pFile is using |
| 24595 | ** any VFS other than "unix-excl" or if pFile is opened on "unix-excl" |
| 24596 | ** and is read-only. |
| 24597 | */ |
| 24598 | static int unixFileLock(unixFile *pFile, struct flock *pLock){ |
| 24599 | int rc; |
| 24600 | unixInodeInfo *pInode = pFile->pInode; |
| 24601 | assert( unixMutexHeld() ); |
| @@ -24688,11 +24695,10 @@ | |
| 24688 | */ |
| 24689 | int rc = SQLITE_OK; |
| 24690 | unixFile *pFile = (unixFile*)id; |
| 24691 | unixInodeInfo *pInode = pFile->pInode; |
| 24692 | struct flock lock; |
| 24693 | int s = 0; |
| 24694 | int tErrno = 0; |
| 24695 | |
| 24696 | assert( pFile ); |
| 24697 | OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, |
| 24698 | azFileLock(eFileLock), azFileLock(pFile->eFileLock), |
| @@ -24757,15 +24763,14 @@ | |
| 24757 | if( eFileLock==SHARED_LOCK |
| 24758 | || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK) |
| 24759 | ){ |
| 24760 | lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK); |
| 24761 | lock.l_start = PENDING_BYTE; |
| 24762 | s = unixFileLock(pFile, &lock); |
| 24763 | if( s==(-1) ){ |
| 24764 | tErrno = errno; |
| 24765 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24766 | if( IS_LOCK_ERROR(rc) ){ |
| 24767 | pFile->lastErrno = tErrno; |
| 24768 | } |
| 24769 | goto end_lock; |
| 24770 | } |
| 24771 | } |
| @@ -24775,37 +24780,35 @@ | |
| 24775 | ** operating system calls for the specified lock. |
| 24776 | */ |
| 24777 | if( eFileLock==SHARED_LOCK ){ |
| 24778 | assert( pInode->nShared==0 ); |
| 24779 | assert( pInode->eFileLock==0 ); |
| 24780 | |
| 24781 | /* Now get the read-lock */ |
| 24782 | lock.l_start = SHARED_FIRST; |
| 24783 | lock.l_len = SHARED_SIZE; |
| 24784 | if( (s = unixFileLock(pFile, &lock))==(-1) ){ |
| 24785 | tErrno = errno; |
| 24786 | } |
| 24787 | /* Drop the temporary PENDING lock */ |
| 24788 | lock.l_start = PENDING_BYTE; |
| 24789 | lock.l_len = 1L; |
| 24790 | lock.l_type = F_UNLCK; |
| 24791 | if( unixFileLock(pFile, &lock)!=0 ){ |
| 24792 | if( s != -1 ){ |
| 24793 | /* This could happen with a network mount */ |
| 24794 | tErrno = errno; |
| 24795 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 24796 | if( IS_LOCK_ERROR(rc) ){ |
| 24797 | pFile->lastErrno = tErrno; |
| 24798 | } |
| 24799 | goto end_lock; |
| 24800 | } |
| 24801 | } |
| 24802 | if( s==(-1) ){ |
| 24803 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24804 | if( IS_LOCK_ERROR(rc) ){ |
| 24805 | pFile->lastErrno = tErrno; |
| 24806 | } |
| 24807 | }else{ |
| 24808 | pFile->eFileLock = SHARED_LOCK; |
| 24809 | pInode->nLock++; |
| 24810 | pInode->nShared = 1; |
| 24811 | } |
| @@ -24818,26 +24821,24 @@ | |
| 24818 | ** assumed that there is a SHARED or greater lock on the file |
| 24819 | ** already. |
| 24820 | */ |
| 24821 | assert( 0!=pFile->eFileLock ); |
| 24822 | lock.l_type = F_WRLCK; |
| 24823 | switch( eFileLock ){ |
| 24824 | case RESERVED_LOCK: |
| 24825 | lock.l_start = RESERVED_BYTE; |
| 24826 | break; |
| 24827 | case EXCLUSIVE_LOCK: |
| 24828 | lock.l_start = SHARED_FIRST; |
| 24829 | lock.l_len = SHARED_SIZE; |
| 24830 | break; |
| 24831 | default: |
| 24832 | assert(0); |
| 24833 | } |
| 24834 | s = unixFileLock(pFile, &lock); |
| 24835 | if( s==(-1) ){ |
| 24836 | tErrno = errno; |
| 24837 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24838 | if( IS_LOCK_ERROR(rc) ){ |
| 24839 | pFile->lastErrno = tErrno; |
| 24840 | } |
| 24841 | } |
| 24842 | } |
| 24843 | |
| @@ -24904,11 +24905,10 @@ | |
| 24904 | unixFile *pFile = (unixFile*)id; |
| 24905 | unixInodeInfo *pInode; |
| 24906 | struct flock lock; |
| 24907 | int rc = SQLITE_OK; |
| 24908 | int h; |
| 24909 | int tErrno; /* Error code from system call errors */ |
| 24910 | |
| 24911 | assert( pFile ); |
| 24912 | OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, |
| 24913 | pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, |
| 24914 | getpid())); |
| @@ -24959,19 +24959,20 @@ | |
| 24959 | (void)handleNFSUnlock; |
| 24960 | assert( handleNFSUnlock==0 ); |
| 24961 | #endif |
| 24962 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE |
| 24963 | if( handleNFSUnlock ){ |
| 24964 | off_t divSize = SHARED_SIZE - 1; |
| 24965 | |
| 24966 | lock.l_type = F_UNLCK; |
| 24967 | lock.l_whence = SEEK_SET; |
| 24968 | lock.l_start = SHARED_FIRST; |
| 24969 | lock.l_len = divSize; |
| 24970 | if( unixFileLock(pFile,, &lock)==(-1) ){ |
| 24971 | tErrno = errno; |
| 24972 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 24973 | if( IS_LOCK_ERROR(rc) ){ |
| 24974 | pFile->lastErrno = tErrno; |
| 24975 | } |
| 24976 | goto end_unlock; |
| 24977 | } |
| @@ -24991,11 +24992,11 @@ | |
| 24991 | lock.l_whence = SEEK_SET; |
| 24992 | lock.l_start = SHARED_FIRST+divSize; |
| 24993 | lock.l_len = SHARED_SIZE-divSize; |
| 24994 | if( unixFileLock(pFile, &lock)==(-1) ){ |
| 24995 | tErrno = errno; |
| 24996 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 24997 | if( IS_LOCK_ERROR(rc) ){ |
| 24998 | pFile->lastErrno = tErrno; |
| 24999 | } |
| 25000 | goto end_unlock; |
| 25001 | } |
| @@ -25004,32 +25005,32 @@ | |
| 25004 | { |
| 25005 | lock.l_type = F_RDLCK; |
| 25006 | lock.l_whence = SEEK_SET; |
| 25007 | lock.l_start = SHARED_FIRST; |
| 25008 | lock.l_len = SHARED_SIZE; |
| 25009 | if( unixFileLock(pFile, &lock)==(-1) ){ |
| 25010 | tErrno = errno; |
| 25011 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_RDLOCK); |
| 25012 | if( IS_LOCK_ERROR(rc) ){ |
| 25013 | pFile->lastErrno = tErrno; |
| 25014 | } |
| 25015 | goto end_unlock; |
| 25016 | } |
| 25017 | } |
| 25018 | } |
| 25019 | lock.l_type = F_UNLCK; |
| 25020 | lock.l_whence = SEEK_SET; |
| 25021 | lock.l_start = PENDING_BYTE; |
| 25022 | lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); |
| 25023 | if( unixFileLock(pFile, &lock)!=(-1) ){ |
| 25024 | pInode->eFileLock = SHARED_LOCK; |
| 25025 | }else{ |
| 25026 | tErrno = errno; |
| 25027 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 25028 | if( IS_LOCK_ERROR(rc) ){ |
| 25029 | pFile->lastErrno = tErrno; |
| 25030 | } |
| 25031 | goto end_unlock; |
| 25032 | } |
| 25033 | } |
| 25034 | if( eFileLock==NO_LOCK ){ |
| 25035 | /* Decrement the shared lock counter. Release the lock using an |
| @@ -25042,18 +25043,15 @@ | |
| 25042 | lock.l_whence = SEEK_SET; |
| 25043 | lock.l_start = lock.l_len = 0L; |
| 25044 | SimulateIOErrorBenign(1); |
| 25045 | SimulateIOError( h=(-1) ) |
| 25046 | SimulateIOErrorBenign(0); |
| 25047 | if( unixFileLock(pFile, &lock)!=(-1) ){ |
| 25048 | pInode->eFileLock = NO_LOCK; |
| 25049 | }else{ |
| 25050 | tErrno = errno; |
| 25051 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 25052 | if( IS_LOCK_ERROR(rc) ){ |
| 25053 | pFile->lastErrno = tErrno; |
| 25054 | } |
| 25055 | pInode->eFileLock = NO_LOCK; |
| 25056 | pFile->eFileLock = NO_LOCK; |
| 25057 | } |
| 25058 | } |
| 25059 | |
| @@ -25095,59 +25093,58 @@ | |
| 25095 | ** even on VxWorks. A mutex will be acquired on VxWorks by the |
| 25096 | ** vxworksReleaseFileId() routine. |
| 25097 | */ |
| 25098 | static int closeUnixFile(sqlite3_file *id){ |
| 25099 | unixFile *pFile = (unixFile*)id; |
| 25100 | if( pFile ){ |
| 25101 | if( pFile->dirfd>=0 ){ |
| 25102 | robust_close(pFile, pFile->dirfd, __LINE__); |
| 25103 | pFile->dirfd=-1; |
| 25104 | } |
| 25105 | if( pFile->h>=0 ){ |
| 25106 | robust_close(pFile, pFile->h, __LINE__); |
| 25107 | pFile->h = -1; |
| 25108 | } |
| 25109 | #if OS_VXWORKS |
| 25110 | if( pFile->pId ){ |
| 25111 | if( pFile->isDelete ){ |
| 25112 | unlink(pFile->pId->zCanonicalName); |
| 25113 | } |
| 25114 | vxworksReleaseFileId(pFile->pId); |
| 25115 | pFile->pId = 0; |
| 25116 | } |
| 25117 | #endif |
| 25118 | OSTRACE(("CLOSE %-3d\n", pFile->h)); |
| 25119 | OpenCounter(-1); |
| 25120 | sqlite3_free(pFile->pUnused); |
| 25121 | memset(pFile, 0, sizeof(unixFile)); |
| 25122 | } |
| 25123 | return SQLITE_OK; |
| 25124 | } |
| 25125 | |
| 25126 | /* |
| 25127 | ** Close a file. |
| 25128 | */ |
| 25129 | static int unixClose(sqlite3_file *id){ |
| 25130 | int rc = SQLITE_OK; |
| 25131 | if( id ){ |
| 25132 | unixFile *pFile = (unixFile *)id; |
| 25133 | unixUnlock(id, NO_LOCK); |
| 25134 | unixEnterMutex(); |
| 25135 | assert( pFile->pInode==0 || pFile->pInode->nLock>0 |
| 25136 | || pFile->pInode->bProcessLock==0 ); |
| 25137 | if( pFile->pInode && pFile->pInode->nLock ){ |
| 25138 | /* If there are outstanding locks, do not actually close the file just |
| 25139 | ** yet because that would clear those locks. Instead, add the file |
| 25140 | ** descriptor to pInode->pUnused list. It will be automatically closed |
| 25141 | ** when the last lock is cleared. |
| 25142 | */ |
| 25143 | setPendingFd(pFile); |
| 25144 | } |
| 25145 | releaseInodeInfo(pFile); |
| 25146 | rc = closeUnixFile(id); |
| 25147 | unixLeaveMutex(); |
| 25148 | } |
| 25149 | return rc; |
| 25150 | } |
| 25151 | |
| 25152 | /************** End of the posix advisory lock implementation ***************** |
| 25153 | ******************************************************************************/ |
| @@ -25358,11 +25355,11 @@ | |
| 25358 | assert( eFileLock==NO_LOCK ); |
| 25359 | if( unlink(zLockFile) ){ |
| 25360 | int rc = 0; |
| 25361 | int tErrno = errno; |
| 25362 | if( ENOENT != tErrno ){ |
| 25363 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 25364 | } |
| 25365 | if( IS_LOCK_ERROR(rc) ){ |
| 25366 | pFile->lastErrno = tErrno; |
| 25367 | } |
| 25368 | return rc; |
| @@ -25446,11 +25443,11 @@ | |
| 25446 | /* got the lock, unlock it */ |
| 25447 | lrc = robust_flock(pFile->h, LOCK_UN); |
| 25448 | if ( lrc ) { |
| 25449 | int tErrno = errno; |
| 25450 | /* unlock failed with an error */ |
| 25451 | lrc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 25452 | if( IS_LOCK_ERROR(lrc) ){ |
| 25453 | pFile->lastErrno = tErrno; |
| 25454 | rc = lrc; |
| 25455 | } |
| 25456 | } |
| @@ -25568,25 +25565,16 @@ | |
| 25568 | pFile->eFileLock = eFileLock; |
| 25569 | return SQLITE_OK; |
| 25570 | } |
| 25571 | |
| 25572 | /* no, really, unlock. */ |
| 25573 | int rc = robust_flock(pFile->h, LOCK_UN); |
| 25574 | if (rc) { |
| 25575 | int r, tErrno = errno; |
| 25576 | r = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK); |
| 25577 | if( IS_LOCK_ERROR(r) ){ |
| 25578 | pFile->lastErrno = tErrno; |
| 25579 | } |
| 25580 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 25581 | if( (r & SQLITE_IOERR) == SQLITE_IOERR ){ |
| 25582 | r = SQLITE_BUSY; |
| 25583 | } |
| 25584 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ |
| 25585 | |
| 25586 | return r; |
| 25587 | } else { |
| 25588 | pFile->eFileLock = NO_LOCK; |
| 25589 | return SQLITE_OK; |
| 25590 | } |
| 25591 | } |
| 25592 | |
| @@ -26388,10 +26376,11 @@ | |
| 26388 | do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); |
| 26389 | #elif defined(USE_PREAD64) |
| 26390 | do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR); |
| 26391 | #else |
| 26392 | newOffset = lseek(id->h, offset, SEEK_SET); |
| 26393 | if( newOffset!=offset ){ |
| 26394 | if( newOffset == -1 ){ |
| 26395 | ((unixFile*)id)->lastErrno = errno; |
| 26396 | }else{ |
| 26397 | ((unixFile*)id)->lastErrno = 0; |
| @@ -26756,16 +26745,20 @@ | |
| 26756 | |
| 26757 | if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; |
| 26758 | |
| 26759 | nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; |
| 26760 | if( nSize>(i64)buf.st_size ){ |
| 26761 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 26762 | int rc; |
| 26763 | do{ |
| 26764 | rc = osFallocate(pFile->.h, buf.st_size, nSize-buf.st_size; |
| 26765 | }while( rc<0 && errno=EINTR ); |
| 26766 | if( rc ) return SQLITE_IOERR_WRITE; |
| 26767 | #else |
| 26768 | /* If the OS does not have posix_fallocate(), fake it. First use |
| 26769 | ** ftruncate() to set the file size, then write a single byte to |
| 26770 | ** the last byte in each block within the extended region. This |
| 26771 | ** is the same technique used by glibc to implement posix_fallocate() |
| @@ -29114,11 +29107,13 @@ | |
| 29114 | rc = SQLITE_NOMEM; |
| 29115 | goto end_create_proxy; |
| 29116 | } |
| 29117 | memset(pNew, 0, sizeof(unixFile)); |
| 29118 | pNew->openFlags = openFlags; |
| 29119 | dummyVfs.pAppData = (void*)&autolockIoFinder; |
| 29120 | pUnused->fd = fd; |
| 29121 | pUnused->flags = openFlags; |
| 29122 | pNew->pUnused = pUnused; |
| 29123 | |
| 29124 | rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0, 0); |
| @@ -45633,11 +45628,11 @@ | |
| 45633 | ** the BtShared object. |
| 45634 | ** |
| 45635 | ** All fields in this structure are accessed under sqlite3.mutex. |
| 45636 | ** The pBt pointer itself may not be changed while there exists cursors |
| 45637 | ** in the referenced BtShared that point back to this Btree since those |
| 45638 | ** cursors have to do go through this Btree to find their BtShared and |
| 45639 | ** they often do so without holding sqlite3.mutex. |
| 45640 | */ |
| 45641 | struct Btree { |
| 45642 | sqlite3 *db; /* The database connection holding this btree */ |
| 45643 | BtShared *pBt; /* Sharable content of this btree */ |
| @@ -45723,19 +45718,20 @@ | |
| 45723 | u32 usableSize; /* Number of usable bytes on each page */ |
| 45724 | int nTransaction; /* Number of open transactions (read + write) */ |
| 45725 | u32 nPage; /* Number of pages in the database */ |
| 45726 | void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */ |
| 45727 | void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */ |
| 45728 | sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */ |
| 45729 | Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */ |
| 45730 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 45731 | int nRef; /* Number of references to this structure */ |
| 45732 | BtShared *pNext; /* Next on a list of sharable BtShared structs */ |
| 45733 | BtLock *pLock; /* List of locks held on this shared-btree struct */ |
| 45734 | Btree *pWriter; /* Btree with currently open write transaction */ |
| 45735 | u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */ |
| 45736 | u8 isPending; /* If waiting for read-locks to clear */ |
| 45737 | #endif |
| 45738 | u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */ |
| 45739 | }; |
| 45740 | |
| 45741 | /* |
| @@ -45964,18 +45960,37 @@ | |
| 45964 | /* |
| 45965 | ** Release the BtShared mutex associated with B-Tree handle p and |
| 45966 | ** clear the p->locked boolean. |
| 45967 | */ |
| 45968 | static void unlockBtreeMutex(Btree *p){ |
| 45969 | assert( p->locked==1 ); |
| 45970 | assert( sqlite3_mutex_held(p->pBt->mutex) ); |
| 45971 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 45972 | assert( p->db==p->pBt->db ); |
| 45973 | |
| 45974 | sqlite3_mutex_leave(p->pBt->mutex); |
| 45975 | p->locked = 0; |
| 45976 | } |
| 45977 | |
| 45978 | /* |
| 45979 | ** Enter a mutex on the given BTree object. |
| 45980 | ** |
| 45981 | ** If the object is not sharable, then no mutex is ever required |
| @@ -46016,10 +46031,28 @@ | |
| 46016 | assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db ); |
| 46017 | |
| 46018 | if( !p->sharable ) return; |
| 46019 | p->wantToLock++; |
| 46020 | if( p->locked ) return; |
| 46021 | |
| 46022 | /* In most cases, we should be able to acquire the lock we |
| 46023 | ** want without having to go throught the ascending lock |
| 46024 | ** procedure that follows. Just be sure not to block. |
| 46025 | */ |
| @@ -46120,11 +46153,11 @@ | |
| 46120 | if( p && p->sharable ){ |
| 46121 | p->wantToLock++; |
| 46122 | if( !p->locked ){ |
| 46123 | assert( p->wantToLock==1 ); |
| 46124 | while( p->pPrev ) p = p->pPrev; |
| 46125 | /* Reason for ALWAYS: There must be at least on unlocked Btree in |
| 46126 | ** the chain. Otherwise the !p->locked test above would have failed */ |
| 46127 | while( p->locked && ALWAYS(p->pNext) ) p = p->pNext; |
| 46128 | for(pLater = p->pNext; pLater; pLater=pLater->pNext){ |
| 46129 | if( pLater->locked ){ |
| 46130 | unlockBtreeMutex(pLater); |
| @@ -46176,101 +46209,21 @@ | |
| 46176 | } |
| 46177 | return 1; |
| 46178 | } |
| 46179 | #endif /* NDEBUG */ |
| 46180 | |
| 46181 | /* |
| 46182 | ** Add a new Btree pointer to a BtreeMutexArray. |
| 46183 | ** if the pointer can possibly be shared with |
| 46184 | ** another database connection. |
| 46185 | ** |
| 46186 | ** The pointers are kept in sorted order by pBtree->pBt. That |
| 46187 | ** way when we go to enter all the mutexes, we can enter them |
| 46188 | ** in order without every having to backup and retry and without |
| 46189 | ** worrying about deadlock. |
| 46190 | ** |
| 46191 | ** The number of shared btrees will always be small (usually 0 or 1) |
| 46192 | ** so an insertion sort is an adequate algorithm here. |
| 46193 | */ |
| 46194 | SQLITE_PRIVATE void sqlite3BtreeMutexArrayInsert(BtreeMutexArray *pArray, Btree *pBtree){ |
| 46195 | int i, j; |
| 46196 | BtShared *pBt; |
| 46197 | if( pBtree==0 || pBtree->sharable==0 ) return; |
| 46198 | #ifndef NDEBUG |
| 46199 | { |
| 46200 | for(i=0; i<pArray->nMutex; i++){ |
| 46201 | assert( pArray->aBtree[i]!=pBtree ); |
| 46202 | } |
| 46203 | } |
| 46204 | #endif |
| 46205 | assert( pArray->nMutex>=0 ); |
| 46206 | assert( pArray->nMutex<ArraySize(pArray->aBtree)-1 ); |
| 46207 | pBt = pBtree->pBt; |
| 46208 | for(i=0; i<pArray->nMutex; i++){ |
| 46209 | assert( pArray->aBtree[i]!=pBtree ); |
| 46210 | if( pArray->aBtree[i]->pBt>pBt ){ |
| 46211 | for(j=pArray->nMutex; j>i; j--){ |
| 46212 | pArray->aBtree[j] = pArray->aBtree[j-1]; |
| 46213 | } |
| 46214 | pArray->aBtree[i] = pBtree; |
| 46215 | pArray->nMutex++; |
| 46216 | return; |
| 46217 | } |
| 46218 | } |
| 46219 | pArray->aBtree[pArray->nMutex++] = pBtree; |
| 46220 | } |
| 46221 | |
| 46222 | /* |
| 46223 | ** Enter the mutex of every btree in the array. This routine is |
| 46224 | ** called at the beginning of sqlite3VdbeExec(). The mutexes are |
| 46225 | ** exited at the end of the same function. |
| 46226 | */ |
| 46227 | SQLITE_PRIVATE void sqlite3BtreeMutexArrayEnter(BtreeMutexArray *pArray){ |
| 46228 | int i; |
| 46229 | for(i=0; i<pArray->nMutex; i++){ |
| 46230 | Btree *p = pArray->aBtree[i]; |
| 46231 | /* Some basic sanity checking */ |
| 46232 | assert( i==0 || pArray->aBtree[i-1]->pBt<p->pBt ); |
| 46233 | assert( !p->locked || p->wantToLock>0 ); |
| 46234 | |
| 46235 | /* We should already hold a lock on the database connection */ |
| 46236 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 46237 | |
| 46238 | /* The Btree is sharable because only sharable Btrees are entered |
| 46239 | ** into the array in the first place. */ |
| 46240 | assert( p->sharable ); |
| 46241 | |
| 46242 | p->wantToLock++; |
| 46243 | if( !p->locked ){ |
| 46244 | lockBtreeMutex(p); |
| 46245 | } |
| 46246 | } |
| 46247 | } |
| 46248 | |
| 46249 | /* |
| 46250 | ** Leave the mutex of every btree in the group. |
| 46251 | */ |
| 46252 | SQLITE_PRIVATE void sqlite3BtreeMutexArrayLeave(BtreeMutexArray *pArray){ |
| 46253 | int i; |
| 46254 | for(i=0; i<pArray->nMutex; i++){ |
| 46255 | Btree *p = pArray->aBtree[i]; |
| 46256 | /* Some basic sanity checking */ |
| 46257 | assert( i==0 || pArray->aBtree[i-1]->pBt<p->pBt ); |
| 46258 | assert( p->locked ); |
| 46259 | assert( p->wantToLock>0 ); |
| 46260 | |
| 46261 | /* We should already hold a lock on the database connection */ |
| 46262 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 46263 | |
| 46264 | p->wantToLock--; |
| 46265 | if( p->wantToLock==0 ){ |
| 46266 | unlockBtreeMutex(p); |
| 46267 | } |
| 46268 | } |
| 46269 | } |
| 46270 | |
| 46271 | #else |
| 46272 | SQLITE_PRIVATE void sqlite3BtreeEnter(Btree *p){ |
| 46273 | p->pBt->db = p->db; |
| 46274 | } |
| 46275 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 46276 | int i; |
| @@ -49444,15 +49397,26 @@ | |
| 49444 | ** routine did all the work of writing information out to disk and flushing the |
| 49445 | ** contents so that they are written onto the disk platter. All this |
| 49446 | ** routine has to do is delete or truncate or zero the header in the |
| 49447 | ** the rollback journal (which causes the transaction to commit) and |
| 49448 | ** drop locks. |
| 49449 | ** |
| 49450 | ** This will release the write lock on the database file. If there |
| 49451 | ** are no active cursors, it also releases the read lock. |
| 49452 | */ |
| 49453 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *p){ |
| 49454 | |
| 49455 | if( p->inTrans==TRANS_NONE ) return SQLITE_OK; |
| 49456 | sqlite3BtreeEnter(p); |
| 49457 | btreeIntegrity(p); |
| 49458 | |
| @@ -49463,11 +49427,11 @@ | |
| 49463 | int rc; |
| 49464 | BtShared *pBt = p->pBt; |
| 49465 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 49466 | assert( pBt->nTransaction>0 ); |
| 49467 | rc = sqlite3PagerCommitPhaseTwo(pBt->pPager); |
| 49468 | if( rc!=SQLITE_OK ){ |
| 49469 | sqlite3BtreeLeave(p); |
| 49470 | return rc; |
| 49471 | } |
| 49472 | pBt->inTransaction = TRANS_READ; |
| 49473 | } |
| @@ -49483,11 +49447,11 @@ | |
| 49483 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree *p){ |
| 49484 | int rc; |
| 49485 | sqlite3BtreeEnter(p); |
| 49486 | rc = sqlite3BtreeCommitPhaseOne(p, 0); |
| 49487 | if( rc==SQLITE_OK ){ |
| 49488 | rc = sqlite3BtreeCommitPhaseTwo(p); |
| 49489 | } |
| 49490 | sqlite3BtreeLeave(p); |
| 49491 | return rc; |
| 49492 | } |
| 49493 | |
| @@ -54264,11 +54228,11 @@ | |
| 54264 | ** allocated, a null pointer is returned. If the blob has already been |
| 54265 | ** allocated, it is returned as normal. |
| 54266 | ** |
| 54267 | ** Just before the shared-btree is closed, the function passed as the |
| 54268 | ** xFree argument when the memory allocation was made is invoked on the |
| 54269 | ** blob of allocated memory. This function should not call sqlite3_free() |
| 54270 | ** on the memory, the btree layer does that. |
| 54271 | */ |
| 54272 | SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){ |
| 54273 | BtShared *pBt = p->pBt; |
| 54274 | sqlite3BtreeEnter(p); |
| @@ -54907,11 +54871,11 @@ | |
| 54907 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 54908 | } |
| 54909 | |
| 54910 | /* Finish committing the transaction to the destination database. */ |
| 54911 | if( SQLITE_OK==rc |
| 54912 | && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest)) |
| 54913 | ){ |
| 54914 | rc = SQLITE_DONE; |
| 54915 | } |
| 54916 | } |
| 54917 | |
| @@ -54921,11 +54885,11 @@ | |
| 54921 | ** "committing" a read-only transaction cannot fail. |
| 54922 | */ |
| 54923 | if( bCloseTrans ){ |
| 54924 | TESTONLY( int rc2 ); |
| 54925 | TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0); |
| 54926 | TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc); |
| 54927 | assert( rc2==SQLITE_OK ); |
| 54928 | } |
| 54929 | |
| 54930 | if( rc==SQLITE_IOERR_NOMEM ){ |
| 54931 | rc = SQLITE_NOMEM; |
| @@ -56419,10 +56383,15 @@ | |
| 56419 | pOp->p2 = p2; |
| 56420 | pOp->p3 = p3; |
| 56421 | pOp->p4.p = 0; |
| 56422 | pOp->p4type = P4_NOTUSED; |
| 56423 | p->expired = 0; |
| 56424 | #ifdef SQLITE_DEBUG |
| 56425 | pOp->zComment = 0; |
| 56426 | if( sqlite3VdbeAddopTrace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 56427 | #endif |
| 56428 | #ifdef VDBE_PROFILE |
| @@ -56719,11 +56688,11 @@ | |
| 56719 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe *p, int *pnOp, int *pnMaxArg){ |
| 56720 | VdbeOp *aOp = p->aOp; |
| 56721 | assert( aOp && !p->db->mallocFailed ); |
| 56722 | |
| 56723 | /* Check that sqlite3VdbeUsesBtree() was not called on this VM */ |
| 56724 | assert( p->aMutex.nMutex==0 ); |
| 56725 | |
| 56726 | resolveP2Values(p, pnMaxArg); |
| 56727 | *pnOp = p->nOp; |
| 56728 | p->aOp = 0; |
| 56729 | return aOp; |
| @@ -56821,10 +56790,11 @@ | |
| 56821 | /* |
| 56822 | ** Change the P2 operand of instruction addr so that it points to |
| 56823 | ** the address of the next instruction to be coded. |
| 56824 | */ |
| 56825 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 56826 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 56827 | } |
| 56828 | |
| 56829 | |
| 56830 | /* |
| @@ -57206,26 +57176,135 @@ | |
| 57206 | #endif |
| 57207 | |
| 57208 | /* |
| 57209 | ** Declare to the Vdbe that the BTree object at db->aDb[i] is used. |
| 57210 | ** |
| 57211 | ** The prepared statement has to know in advance which Btree objects |
| 57212 | ** will be used so that it can acquire mutexes on them all in sorted |
| 57213 | ** order (via sqlite3VdbeMutexArrayEnter(). Mutexes are acquired |
| 57214 | ** in order (and released in reverse order) to avoid deadlocks. |
| 57215 | */ |
| 57216 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe *p, int i){ |
| 57217 | tAttachMask mask; |
| 57218 | assert( i>=0 && i<p->db->nDb && i<sizeof(tAttachMask)*8 ); |
| 57219 | assert( i<(int)sizeof(p->btreeMask)*8 ); |
| 57220 | mask = ((u32)1)<<i; |
| 57221 | if( (p->btreeMask & mask)==0 ){ |
| 57222 | p->btreeMask |= mask; |
| 57223 | sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt); |
| 57224 | } |
| 57225 | } |
| 57226 | |
| 57227 | |
| 57228 | #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) |
| 57229 | /* |
| 57230 | ** Print a single opcode. This routine is used for debugging only. |
| 57231 | */ |
| @@ -57965,11 +58044,11 @@ | |
| 57965 | ** but could happen. In this case abandon processing and return the error. |
| 57966 | */ |
| 57967 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 57968 | Btree *pBt = db->aDb[i].pBt; |
| 57969 | if( pBt ){ |
| 57970 | rc = sqlite3BtreeCommitPhaseTwo(pBt); |
| 57971 | } |
| 57972 | } |
| 57973 | if( rc==SQLITE_OK ){ |
| 57974 | sqlite3VtabCommit(db); |
| 57975 | } |
| @@ -58097,11 +58176,11 @@ | |
| 58097 | disable_simulated_io_errors(); |
| 58098 | sqlite3BeginBenignMalloc(); |
| 58099 | for(i=0; i<db->nDb; i++){ |
| 58100 | Btree *pBt = db->aDb[i].pBt; |
| 58101 | if( pBt ){ |
| 58102 | sqlite3BtreeCommitPhaseTwo(pBt); |
| 58103 | } |
| 58104 | } |
| 58105 | sqlite3EndBenignMalloc(); |
| 58106 | enable_simulated_io_errors(); |
| 58107 | |
| @@ -58220,37 +58299,10 @@ | |
| 58220 | } |
| 58221 | } |
| 58222 | return rc; |
| 58223 | } |
| 58224 | |
| 58225 | /* |
| 58226 | ** If SQLite is compiled to support shared-cache mode and to be threadsafe, |
| 58227 | ** this routine obtains the mutex associated with each BtShared structure |
| 58228 | ** that may be accessed by the VM passed as an argument. In doing so it |
| 58229 | ** sets the BtShared.db member of each of the BtShared structures, ensuring |
| 58230 | ** that the correct busy-handler callback is invoked if required. |
| 58231 | ** |
| 58232 | ** If SQLite is not threadsafe but does support shared-cache mode, then |
| 58233 | ** sqlite3BtreeEnterAll() is invoked to set the BtShared.db variables |
| 58234 | ** of all of BtShared structures accessible via the database handle |
| 58235 | ** associated with the VM. Of course only a subset of these structures |
| 58236 | ** will be accessed by the VM, and we could use Vdbe.btreeMask to figure |
| 58237 | ** that subset out, but there is no advantage to doing so. |
| 58238 | ** |
| 58239 | ** If SQLite is not threadsafe and does not support shared-cache mode, this |
| 58240 | ** function is a no-op. |
| 58241 | */ |
| 58242 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 58243 | SQLITE_PRIVATE void sqlite3VdbeMutexArrayEnter(Vdbe *p){ |
| 58244 | #if SQLITE_THREADSAFE |
| 58245 | sqlite3BtreeMutexArrayEnter(&p->aMutex); |
| 58246 | #else |
| 58247 | sqlite3BtreeEnterAll(p->db); |
| 58248 | #endif |
| 58249 | } |
| 58250 | #endif |
| 58251 | |
| 58252 | /* |
| 58253 | ** This function is called when a transaction opened by the database |
| 58254 | ** handle associated with the VM passed as an argument is about to be |
| 58255 | ** committed. If there are outstanding deferred foreign key constraint |
| 58256 | ** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK. |
| @@ -58319,11 +58371,11 @@ | |
| 58319 | int mrc; /* Primary error code from p->rc */ |
| 58320 | int eStatementOp = 0; |
| 58321 | int isSpecialError; /* Set to true if a 'special' error */ |
| 58322 | |
| 58323 | /* Lock all btrees used by the statement */ |
| 58324 | sqlite3VdbeMutexArrayEnter(p); |
| 58325 | |
| 58326 | /* Check for one of the special errors */ |
| 58327 | mrc = p->rc & 0xff; |
| 58328 | assert( p->rc!=SQLITE_IOERR_BLOCKED ); /* This error no longer exists */ |
| 58329 | isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| @@ -58373,11 +58425,11 @@ | |
| 58373 | ){ |
| 58374 | if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ |
| 58375 | rc = sqlite3VdbeCheckFk(p, 1); |
| 58376 | if( rc!=SQLITE_OK ){ |
| 58377 | if( NEVER(p->readOnly) ){ |
| 58378 | sqlite3BtreeMutexArrayLeave(&p->aMutex); |
| 58379 | return SQLITE_ERROR; |
| 58380 | } |
| 58381 | rc = SQLITE_CONSTRAINT; |
| 58382 | }else{ |
| 58383 | /* The auto-commit flag is true, the vdbe program was successful |
| @@ -58385,11 +58437,11 @@ | |
| 58385 | ** key constraints to hold up the transaction. This means a commit |
| 58386 | ** is required. */ |
| 58387 | rc = vdbeCommit(db, p); |
| 58388 | } |
| 58389 | if( rc==SQLITE_BUSY && p->readOnly ){ |
| 58390 | sqlite3BtreeMutexArrayLeave(&p->aMutex); |
| 58391 | return SQLITE_BUSY; |
| 58392 | }else if( rc!=SQLITE_OK ){ |
| 58393 | p->rc = rc; |
| 58394 | sqlite3RollbackAll(db); |
| 58395 | }else{ |
| @@ -58457,11 +58509,12 @@ | |
| 58457 | sqlite3ResetInternalSchema(db, 0); |
| 58458 | db->flags = (db->flags | SQLITE_InternChanges); |
| 58459 | } |
| 58460 | |
| 58461 | /* Release the locks */ |
| 58462 | sqlite3BtreeMutexArrayLeave(&p->aMutex); |
| 58463 | } |
| 58464 | |
| 58465 | /* We have successfully halted and closed the VM. Record this fact. */ |
| 58466 | if( p->pc>=0 ){ |
| 58467 | db->activeVdbeCnt--; |
| @@ -61978,11 +62031,11 @@ | |
| 61978 | } u; |
| 61979 | /* End automatically generated code |
| 61980 | ********************************************************************/ |
| 61981 | |
| 61982 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 61983 | sqlite3VdbeMutexArrayEnter(p); |
| 61984 | if( p->rc==SQLITE_NOMEM ){ |
| 61985 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| 61986 | ** sqlite3_column_text16() failed. */ |
| 61987 | goto no_mem; |
| 61988 | } |
| @@ -62815,19 +62868,31 @@ | |
| 62815 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 62816 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 62817 | u.ag.ctx.pColl = pOp[-1].p4.pColl; |
| 62818 | } |
| 62819 | (*u.ag.ctx.pFunc->xFunc)(&u.ag.ctx, u.ag.n, u.ag.apVal); /* IMP: R-24505-23230 */ |
| 62820 | if( db->mallocFailed ){ |
| 62821 | /* Even though a malloc() has failed, the implementation of the |
| 62822 | ** user function may have called an sqlite3_result_XXX() function |
| 62823 | ** to return a value. The following call releases any resources |
| 62824 | ** associated with such a value. |
| 62825 | */ |
| 62826 | sqlite3VdbeMemRelease(&u.ag.ctx.s); |
| 62827 | goto no_mem; |
| 62828 | } |
| 62829 | |
| 62830 | /* If any auxiliary data functions have been called by this user function, |
| 62831 | ** immediately call the destructor for any non-static values. |
| 62832 | */ |
| 62833 | if( u.ag.ctx.pVdbeFunc ){ |
| @@ -64091,10 +64156,11 @@ | |
| 64091 | } |
| 64092 | } |
| 64093 | if( u.aq.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 64094 | sqlite3ExpirePreparedStatements(db); |
| 64095 | sqlite3ResetInternalSchema(db, 0); |
| 64096 | db->flags = (db->flags | SQLITE_InternChanges); |
| 64097 | } |
| 64098 | } |
| 64099 | |
| 64100 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| @@ -64234,11 +64300,11 @@ | |
| 64234 | #if 0 /* local variables moved into u.as */ |
| 64235 | Btree *pBt; |
| 64236 | #endif /* local variables moved into u.as */ |
| 64237 | |
| 64238 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64239 | assert( (p->btreeMask & (1<<pOp->p1))!=0 ); |
| 64240 | u.as.pBt = db->aDb[pOp->p1].pBt; |
| 64241 | |
| 64242 | if( u.as.pBt ){ |
| 64243 | rc = sqlite3BtreeBeginTrans(u.as.pBt, pOp->p2); |
| 64244 | if( rc==SQLITE_BUSY ){ |
| @@ -64292,11 +64358,11 @@ | |
| 64292 | u.at.iDb = pOp->p1; |
| 64293 | u.at.iCookie = pOp->p3; |
| 64294 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 64295 | assert( u.at.iDb>=0 && u.at.iDb<db->nDb ); |
| 64296 | assert( db->aDb[u.at.iDb].pBt!=0 ); |
| 64297 | assert( (p->btreeMask & (1<<u.at.iDb))!=0 ); |
| 64298 | |
| 64299 | sqlite3BtreeGetMeta(db->aDb[u.at.iDb].pBt, u.at.iCookie, (u32 *)&u.at.iMeta); |
| 64300 | pOut->u.i = u.at.iMeta; |
| 64301 | break; |
| 64302 | } |
| @@ -64315,11 +64381,11 @@ | |
| 64315 | #if 0 /* local variables moved into u.au */ |
| 64316 | Db *pDb; |
| 64317 | #endif /* local variables moved into u.au */ |
| 64318 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 64319 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64320 | assert( (p->btreeMask & (1<<pOp->p1))!=0 ); |
| 64321 | u.au.pDb = &db->aDb[pOp->p1]; |
| 64322 | assert( u.au.pDb->pBt!=0 ); |
| 64323 | pIn3 = &aMem[pOp->p3]; |
| 64324 | sqlite3VdbeMemIntegerify(pIn3); |
| 64325 | /* See note about index shifting on OP_ReadCookie */ |
| @@ -64365,11 +64431,11 @@ | |
| 64365 | int iGen; |
| 64366 | Btree *pBt; |
| 64367 | #endif /* local variables moved into u.av */ |
| 64368 | |
| 64369 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64370 | assert( (p->btreeMask & (1<<pOp->p1))!=0 ); |
| 64371 | u.av.pBt = db->aDb[pOp->p1].pBt; |
| 64372 | if( u.av.pBt ){ |
| 64373 | sqlite3BtreeGetMeta(u.av.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.av.iMeta); |
| 64374 | u.av.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 64375 | }else{ |
| @@ -64391,10 +64457,11 @@ | |
| 64391 | ** to be invalidated whenever sqlite3_step() is called from within |
| 64392 | ** a v-table method. |
| 64393 | */ |
| 64394 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.av.iMeta ){ |
| 64395 | sqlite3ResetInternalSchema(db, pOp->p1); |
| 64396 | } |
| 64397 | |
| 64398 | p->expired = 1; |
| 64399 | rc = SQLITE_SCHEMA; |
| 64400 | } |
| @@ -64471,11 +64538,11 @@ | |
| 64471 | u.aw.nField = 0; |
| 64472 | u.aw.pKeyInfo = 0; |
| 64473 | u.aw.p2 = pOp->p2; |
| 64474 | u.aw.iDb = pOp->p3; |
| 64475 | assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb ); |
| 64476 | assert( (p->btreeMask & (1<<u.aw.iDb))!=0 ); |
| 64477 | u.aw.pDb = &db->aDb[u.aw.iDb]; |
| 64478 | u.aw.pX = u.aw.pDb->pBt; |
| 64479 | assert( u.aw.pX!=0 ); |
| 64480 | if( pOp->opcode==OP_OpenWrite ){ |
| 64481 | u.aw.wrFlag = 1; |
| @@ -66008,11 +66075,11 @@ | |
| 66008 | rc = SQLITE_LOCKED; |
| 66009 | p->errorAction = OE_Abort; |
| 66010 | }else{ |
| 66011 | u.br.iDb = pOp->p3; |
| 66012 | assert( u.br.iCnt==1 ); |
| 66013 | assert( (p->btreeMask & (1<<u.br.iDb))!=0 ); |
| 66014 | rc = sqlite3BtreeDropTable(db->aDb[u.br.iDb].pBt, pOp->p1, &u.br.iMoved); |
| 66015 | pOut->flags = MEM_Int; |
| 66016 | pOut->u.i = u.br.iMoved; |
| 66017 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 66018 | if( rc==SQLITE_OK && u.br.iMoved!=0 ){ |
| @@ -66046,11 +66113,11 @@ | |
| 66046 | #if 0 /* local variables moved into u.bs */ |
| 66047 | int nChange; |
| 66048 | #endif /* local variables moved into u.bs */ |
| 66049 | |
| 66050 | u.bs.nChange = 0; |
| 66051 | assert( (p->btreeMask & (1<<pOp->p2))!=0 ); |
| 66052 | rc = sqlite3BtreeClearTable( |
| 66053 | db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0) |
| 66054 | ); |
| 66055 | if( pOp->p3 ){ |
| 66056 | p->nChange += u.bs.nChange; |
| @@ -66093,11 +66160,11 @@ | |
| 66093 | Db *pDb; |
| 66094 | #endif /* local variables moved into u.bt */ |
| 66095 | |
| 66096 | u.bt.pgno = 0; |
| 66097 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66098 | assert( (p->btreeMask & (1<<pOp->p1))!=0 ); |
| 66099 | u.bt.pDb = &db->aDb[pOp->p1]; |
| 66100 | assert( u.bt.pDb->pBt!=0 ); |
| 66101 | if( pOp->opcode==OP_CreateTable ){ |
| 66102 | /* u.bt.flags = BTREE_INTKEY; */ |
| 66103 | u.bt.flags = BTREE_INTKEY; |
| @@ -66122,31 +66189,27 @@ | |
| 66122 | int iDb; |
| 66123 | const char *zMaster; |
| 66124 | char *zSql; |
| 66125 | InitData initData; |
| 66126 | #endif /* local variables moved into u.bu */ |
| 66127 | |
| 66128 | u.bu.iDb = pOp->p1; |
| 66129 | assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb ); |
| 66130 | |
| 66131 | /* Although the mutex on the BtShared object that corresponds to |
| 66132 | ** database u.bu.iDb (the database containing the sqlite_master table |
| 66133 | ** read by this instruction) is currently held, it is necessary to |
| 66134 | ** obtain the mutexes on all attached databases before checking if |
| 66135 | ** the schema of u.bu.iDb is loaded. This is because, at the start of |
| 66136 | ** the sqlite3_exec() call below, SQLite will invoke |
| 66137 | ** sqlite3BtreeEnterAll(). If all mutexes are not already held, the |
| 66138 | ** u.bu.iDb mutex may be temporarily released to avoid deadlock. If |
| 66139 | ** this happens, then some other thread may delete the in-memory |
| 66140 | ** schema of database u.bu.iDb before the SQL statement runs. The schema |
| 66141 | ** will not be reloaded becuase the db->init.busy flag is set. This |
| 66142 | ** can result in a "no such table: sqlite_master" or "malformed |
| 66143 | ** database schema" error being returned to the user. |
| 66144 | */ |
| 66145 | assert( sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) ); |
| 66146 | sqlite3BtreeEnterAll(db); |
| 66147 | if( ALWAYS(DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded)) ){ |
| 66148 | u.bu.zMaster = SCHEMA_TABLE(u.bu.iDb); |
| 66149 | u.bu.initData.db = db; |
| 66150 | u.bu.initData.iDb = pOp->p1; |
| 66151 | u.bu.initData.pzErrMsg = &p->zErrMsg; |
| 66152 | u.bu.zSql = sqlite3MPrintf(db, |
| @@ -66163,11 +66226,10 @@ | |
| 66163 | if( rc==SQLITE_OK ) rc = u.bu.initData.rc; |
| 66164 | sqlite3DbFree(db, u.bu.zSql); |
| 66165 | db->init.busy = 0; |
| 66166 | } |
| 66167 | } |
| 66168 | sqlite3BtreeLeaveAll(db); |
| 66169 | if( rc==SQLITE_NOMEM ){ |
| 66170 | goto no_mem; |
| 66171 | } |
| 66172 | break; |
| 66173 | } |
| @@ -66266,11 +66328,11 @@ | |
| 66266 | for(u.bv.j=0; u.bv.j<u.bv.nRoot; u.bv.j++){ |
| 66267 | u.bv.aRoot[u.bv.j] = (int)sqlite3VdbeIntValue(&pIn1[u.bv.j]); |
| 66268 | } |
| 66269 | u.bv.aRoot[u.bv.j] = 0; |
| 66270 | assert( pOp->p5<db->nDb ); |
| 66271 | assert( (p->btreeMask & (1<<pOp->p5))!=0 ); |
| 66272 | u.bv.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bv.aRoot, u.bv.nRoot, |
| 66273 | (int)u.bv.pnErr->u.i, &u.bv.nErr); |
| 66274 | sqlite3DbFree(db, u.bv.aRoot); |
| 66275 | u.bv.pnErr->u.i -= u.bv.nErr; |
| 66276 | sqlite3VdbeMemSetNull(pIn1); |
| @@ -66702,15 +66764,29 @@ | |
| 66702 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66703 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66704 | u.cb.ctx.pColl = pOp[-1].p4.pColl; |
| 66705 | } |
| 66706 | (u.cb.ctx.pFunc->xStep)(&u.cb.ctx, u.cb.n, u.cb.apVal); /* IMP: R-24505-23230 */ |
| 66707 | if( u.cb.ctx.isError ){ |
| 66708 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cb.ctx.s)); |
| 66709 | rc = u.cb.ctx.isError; |
| 66710 | } |
| 66711 | sqlite3VdbeMemRelease(&u.cb.ctx.s); |
| 66712 | break; |
| 66713 | } |
| 66714 | |
| 66715 | /* Opcode: AggFinal P1 P2 * P4 * |
| 66716 | ** |
| @@ -66730,12 +66806,15 @@ | |
| 66730 | #endif /* local variables moved into u.cc */ |
| 66731 | assert( pOp->p1>0 && pOp->p1<=p->nMem ); |
| 66732 | u.cc.pMem = &aMem[pOp->p1]; |
| 66733 | assert( (u.cc.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 66734 | rc = sqlite3VdbeMemFinalize(u.cc.pMem, pOp->p4.pFunc); |
| 66735 | if( rc ){ |
| 66736 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.cc.pMem)); |
| 66737 | } |
| 66738 | sqlite3VdbeChangeEncoding(u.cc.pMem, encoding); |
| 66739 | UPDATE_MAX_BLOBSIZE(u.cc.pMem); |
| 66740 | if( sqlite3VdbeMemTooBig(u.cc.pMem) ){ |
| 66741 | goto too_big; |
| @@ -66812,25 +66891,24 @@ | |
| 66812 | ); |
| 66813 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66814 | |
| 66815 | /* This opcode is used in two places: PRAGMA journal_mode and ATTACH. |
| 66816 | ** In PRAGMA journal_mode, the sqlite3VdbeUsesBtree() routine is called |
| 66817 | ** when the statment is prepared and so p->aMutex.nMutex>0. All mutexes |
| 66818 | ** are already acquired. But when used in ATTACH, sqlite3VdbeUsesBtree() |
| 66819 | ** is not called when the statement is prepared because it requires the |
| 66820 | ** iDb index of the database as a parameter, and the database has not |
| 66821 | ** yet been attached so that index is unavailable. We have to wait |
| 66822 | ** until runtime (now) to get the mutex on the newly attached database. |
| 66823 | ** No other mutexes are required by the ATTACH command so this is safe |
| 66824 | ** to do. |
| 66825 | */ |
| 66826 | assert( (p->btreeMask & (1<<pOp->p1))!=0 || p->aMutex.nMutex==0 ); |
| 66827 | if( p->aMutex.nMutex==0 ){ |
| 66828 | /* This occurs right after ATTACH. Get a mutex on the newly ATTACHed |
| 66829 | ** database. */ |
| 66830 | sqlite3VdbeUsesBtree(p, pOp->p1); |
| 66831 | sqlite3VdbeMutexArrayEnter(p); |
| 66832 | } |
| 66833 | |
| 66834 | u.ce.pBt = db->aDb[pOp->p1].pBt; |
| 66835 | u.ce.pPager = sqlite3BtreePager(u.ce.pBt); |
| 66836 | u.ce.eOld = sqlite3PagerGetJournalMode(u.ce.pPager); |
| @@ -66928,11 +67006,11 @@ | |
| 66928 | #if 0 /* local variables moved into u.cf */ |
| 66929 | Btree *pBt; |
| 66930 | #endif /* local variables moved into u.cf */ |
| 66931 | |
| 66932 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66933 | assert( (p->btreeMask & (1<<pOp->p1))!=0 ); |
| 66934 | u.cf.pBt = db->aDb[pOp->p1].pBt; |
| 66935 | rc = sqlite3BtreeIncrVacuum(u.cf.pBt); |
| 66936 | if( rc==SQLITE_DONE ){ |
| 66937 | pc = pOp->p2 - 1; |
| 66938 | rc = SQLITE_OK; |
| @@ -66977,11 +67055,11 @@ | |
| 66977 | case OP_TableLock: { |
| 66978 | u8 isWriteLock = (u8)pOp->p3; |
| 66979 | if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){ |
| 66980 | int p1 = pOp->p1; |
| 66981 | assert( p1>=0 && p1<db->nDb ); |
| 66982 | assert( (p->btreeMask & (1<<p1))!=0 ); |
| 66983 | assert( isWriteLock==0 || isWriteLock==1 ); |
| 66984 | rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock); |
| 66985 | if( (rc&0xFF)==SQLITE_LOCKED ){ |
| 66986 | const char *z = pOp->p4.z; |
| 66987 | sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z); |
| @@ -67482,17 +67560,20 @@ | |
| 67482 | sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 67483 | pc, p->zSql, p->zErrMsg); |
| 67484 | sqlite3VdbeHalt(p); |
| 67485 | if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 67486 | rc = SQLITE_ERROR; |
| 67487 | if( resetSchemaOnFault ) sqlite3ResetInternalSchema(db, 0); |
| 67488 | |
| 67489 | /* This is the only way out of this procedure. We have to |
| 67490 | ** release the mutexes on btrees that were acquired at the |
| 67491 | ** top. */ |
| 67492 | vdbe_return: |
| 67493 | sqlite3BtreeMutexArrayLeave(&p->aMutex); |
| 67494 | return rc; |
| 67495 | |
| 67496 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 67497 | ** is encountered. |
| 67498 | */ |
| @@ -73966,10 +74047,26 @@ | |
| 73966 | if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){ |
| 73967 | sqlite3VdbeAddOp4(v, OP_ParseSchema, 1, 0, 0, zWhere, P4_DYNAMIC); |
| 73968 | } |
| 73969 | #endif |
| 73970 | } |
| 73971 | |
| 73972 | /* |
| 73973 | ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" |
| 73974 | ** command. |
| 73975 | */ |
| @@ -74017,18 +74114,15 @@ | |
| 74017 | } |
| 74018 | |
| 74019 | /* Make sure it is not a system table being altered, or a reserved name |
| 74020 | ** that the table is being renamed to. |
| 74021 | */ |
| 74022 | if( sqlite3Strlen30(pTab->zName)>6 |
| 74023 | && 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) |
| 74024 | ){ |
| 74025 | sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName); |
| 74026 | goto exit_rename_table; |
| 74027 | } |
| 74028 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ |
| 74029 | goto exit_rename_table; |
| 74030 | } |
| 74031 | |
| 74032 | #ifndef SQLITE_OMIT_VIEW |
| 74033 | if( pTab->pSelect ){ |
| 74034 | sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName); |
| @@ -74356,10 +74450,13 @@ | |
| 74356 | /* Make sure this is not an attempt to ALTER a view. */ |
| 74357 | if( pTab->pSelect ){ |
| 74358 | sqlite3ErrorMsg(pParse, "Cannot add a column to a view"); |
| 74359 | goto exit_begin_add_column; |
| 74360 | } |
| 74361 | |
| 74362 | assert( pTab->addColOffset>0 ); |
| 74363 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 74364 | |
| 74365 | /* Put a copy of the Table struct in Parse.pNewTable for the |
| @@ -74443,11 +74540,12 @@ | |
| 74443 | */ |
| 74444 | static void openStatTable( |
| 74445 | Parse *pParse, /* Parsing context */ |
| 74446 | int iDb, /* The database we are looking in */ |
| 74447 | int iStatCur, /* Open the sqlite_stat1 table on this cursor */ |
| 74448 | const char *zWhere /* Delete entries associated with this table */ |
| 74449 | ){ |
| 74450 | static const struct { |
| 74451 | const char *zName; |
| 74452 | const char *zCols; |
| 74453 | } aTable[] = { |
| @@ -74488,11 +74586,11 @@ | |
| 74488 | ** entire contents of the table. */ |
| 74489 | aRoot[i] = pStat->tnum; |
| 74490 | sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab); |
| 74491 | if( zWhere ){ |
| 74492 | sqlite3NestedParse(pParse, |
| 74493 | "DELETE FROM %Q.%s WHERE tbl=%Q", pDb->zName, zTab, zWhere |
| 74494 | ); |
| 74495 | }else{ |
| 74496 | /* The sqlite_stat[12] table already exists. Delete all rows. */ |
| 74497 | sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb); |
| 74498 | } |
| @@ -74512,10 +74610,11 @@ | |
| 74512 | ** a single table. |
| 74513 | */ |
| 74514 | static void analyzeOneTable( |
| 74515 | Parse *pParse, /* Parser context */ |
| 74516 | Table *pTab, /* Table whose indices are to be analyzed */ |
| 74517 | int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */ |
| 74518 | int iMem /* Available memory locations begin here */ |
| 74519 | ){ |
| 74520 | sqlite3 *db = pParse->db; /* Database handle */ |
| 74521 | Index *pIdx; /* An index to being analyzed */ |
| @@ -74522,12 +74621,11 @@ | |
| 74522 | int iIdxCur; /* Cursor open on index being analyzed */ |
| 74523 | Vdbe *v; /* The virtual machine being built up */ |
| 74524 | int i; /* Loop counter */ |
| 74525 | int topOfLoop; /* The top of the loop */ |
| 74526 | int endOfLoop; /* The end of the loop */ |
| 74527 | int addr = 0; /* The address of an instruction */ |
| 74528 | int jZeroRows = 0; /* Jump from here if number of rows is zero */ |
| 74529 | int iDb; /* Index of database containing pTab */ |
| 74530 | int regTabname = iMem++; /* Register containing table name */ |
| 74531 | int regIdxname = iMem++; /* Register containing index name */ |
| 74532 | int regSampleno = iMem++; /* Register containing next sample number */ |
| 74533 | int regCol = iMem++; /* Content of a column analyzed table */ |
| @@ -74534,10 +74632,11 @@ | |
| 74534 | int regRec = iMem++; /* Register holding completed record */ |
| 74535 | int regTemp = iMem++; /* Temporary use register */ |
| 74536 | int regRowid = iMem++; /* Rowid for the inserted record */ |
| 74537 | |
| 74538 | #ifdef SQLITE_ENABLE_STAT2 |
| 74539 | int regTemp2 = iMem++; /* Temporary use register */ |
| 74540 | int regSamplerecno = iMem++; /* Index of next sample to record */ |
| 74541 | int regRecno = iMem++; /* Current sample index */ |
| 74542 | int regLast = iMem++; /* Index of last sample to record */ |
| 74543 | int regFirst = iMem++; /* Index of first sample to record */ |
| @@ -74569,13 +74668,16 @@ | |
| 74569 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 74570 | |
| 74571 | iIdxCur = pParse->nTab++; |
| 74572 | sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0); |
| 74573 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 74574 | int nCol = pIdx->nColumn; |
| 74575 | KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx); |
| 74576 | |
| 74577 | if( iMem+1+(nCol*2)>pParse->nMem ){ |
| 74578 | pParse->nMem = iMem+1+(nCol*2); |
| 74579 | } |
| 74580 | |
| 74581 | /* Open a cursor to the index to be analyzed. */ |
| @@ -74728,11 +74830,11 @@ | |
| 74728 | ** If K==0 then no entry is made into the sqlite_stat1 table. |
| 74729 | ** If K>0 then it is always the case the D>0 so division by zero |
| 74730 | ** is never possible. |
| 74731 | */ |
| 74732 | sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno); |
| 74733 | if( jZeroRows==0 ){ |
| 74734 | jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem); |
| 74735 | } |
| 74736 | for(i=0; i<nCol; i++){ |
| 74737 | sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0); |
| 74738 | sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno); |
| @@ -74754,24 +74856,22 @@ | |
| 74754 | if( pTab->pIndex==0 ){ |
| 74755 | sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb); |
| 74756 | VdbeComment((v, "%s", pTab->zName)); |
| 74757 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regSampleno); |
| 74758 | sqlite3VdbeAddOp1(v, OP_Close, iIdxCur); |
| 74759 | }else{ |
| 74760 | assert( jZeroRows>0 ); |
| 74761 | addr = sqlite3VdbeAddOp0(v, OP_Goto); |
| 74762 | sqlite3VdbeJumpHere(v, jZeroRows); |
| 74763 | } |
| 74764 | sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname); |
| 74765 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0); |
| 74766 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid); |
| 74767 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid); |
| 74768 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 74769 | if( pParse->nMem<regRec ) pParse->nMem = regRec; |
| 74770 | if( jZeroRows ){ |
| 74771 | sqlite3VdbeJumpHere(v, addr); |
| 74772 | } |
| 74773 | } |
| 74774 | |
| 74775 | /* |
| 74776 | ** Generate code that will cause the most recent index analysis to |
| 74777 | ** be loaded into internal hash tables where is can be used. |
| @@ -74794,35 +74894,40 @@ | |
| 74794 | int iMem; |
| 74795 | |
| 74796 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74797 | iStatCur = pParse->nTab; |
| 74798 | pParse->nTab += 2; |
| 74799 | openStatTable(pParse, iDb, iStatCur, 0); |
| 74800 | iMem = pParse->nMem+1; |
| 74801 | for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 74802 | Table *pTab = (Table*)sqliteHashData(k); |
| 74803 | analyzeOneTable(pParse, pTab, iStatCur, iMem); |
| 74804 | } |
| 74805 | loadAnalysis(pParse, iDb); |
| 74806 | } |
| 74807 | |
| 74808 | /* |
| 74809 | ** Generate code that will do an analysis of a single table in |
| 74810 | ** a database. |
| 74811 | */ |
| 74812 | static void analyzeTable(Parse *pParse, Table *pTab){ |
| 74813 | int iDb; |
| 74814 | int iStatCur; |
| 74815 | |
| 74816 | assert( pTab!=0 ); |
| 74817 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| 74818 | iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 74819 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74820 | iStatCur = pParse->nTab; |
| 74821 | pParse->nTab += 2; |
| 74822 | openStatTable(pParse, iDb, iStatCur, pTab->zName); |
| 74823 | analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem+1); |
| 74824 | loadAnalysis(pParse, iDb); |
| 74825 | } |
| 74826 | |
| 74827 | /* |
| 74828 | ** Generate code for the ANALYZE command. The parser calls this routine |
| @@ -74840,10 +74945,11 @@ | |
| 74840 | sqlite3 *db = pParse->db; |
| 74841 | int iDb; |
| 74842 | int i; |
| 74843 | char *z, *zDb; |
| 74844 | Table *pTab; |
| 74845 | Token *pTableName; |
| 74846 | |
| 74847 | /* Read the database schema. If an error occurs, leave an error message |
| 74848 | ** and code in pParse and return NULL. */ |
| 74849 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| @@ -74864,29 +74970,31 @@ | |
| 74864 | if( iDb>=0 ){ |
| 74865 | analyzeDatabase(pParse, iDb); |
| 74866 | }else{ |
| 74867 | z = sqlite3NameFromToken(db, pName1); |
| 74868 | if( z ){ |
| 74869 | pTab = sqlite3LocateTable(pParse, 0, z, 0); |
| 74870 | sqlite3DbFree(db, z); |
| 74871 | if( pTab ){ |
| 74872 | analyzeTable(pParse, pTab); |
| 74873 | } |
| 74874 | } |
| 74875 | } |
| 74876 | }else{ |
| 74877 | /* Form 3: Analyze the fully qualified table name */ |
| 74878 | iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName); |
| 74879 | if( iDb>=0 ){ |
| 74880 | zDb = db->aDb[iDb].zName; |
| 74881 | z = sqlite3NameFromToken(db, pTableName); |
| 74882 | if( z ){ |
| 74883 | pTab = sqlite3LocateTable(pParse, 0, z, zDb); |
| 74884 | sqlite3DbFree(db, z); |
| 74885 | if( pTab ){ |
| 74886 | analyzeTable(pParse, pTab); |
| 74887 | } |
| 74888 | } |
| 74889 | } |
| 74890 | } |
| 74891 | } |
| 74892 | |
| @@ -76055,11 +76163,11 @@ | |
| 76055 | ** set for each database that is used. Generate code to start a |
| 76056 | ** transaction on each used database and to verify the schema cookie |
| 76057 | ** on each used database. |
| 76058 | */ |
| 76059 | if( pParse->cookieGoto>0 ){ |
| 76060 | tAttachMask mask; |
| 76061 | int iDb; |
| 76062 | sqlite3VdbeJumpHere(v, pParse->cookieGoto-1); |
| 76063 | for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ |
| 76064 | if( (mask & pParse->cookieMask)==0 ) continue; |
| 76065 | sqlite3VdbeUsesBtree(v, iDb); |
| @@ -79351,16 +79459,16 @@ | |
| 79351 | if( v==0 ) return; /* This only happens if there was a prior error */ |
| 79352 | pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; |
| 79353 | } |
| 79354 | if( iDb>=0 ){ |
| 79355 | sqlite3 *db = pToplevel->db; |
| 79356 | tAttachMask mask; |
| 79357 | |
| 79358 | assert( iDb<db->nDb ); |
| 79359 | assert( db->aDb[iDb].pBt!=0 || iDb==1 ); |
| 79360 | assert( iDb<SQLITE_MAX_ATTACHED+2 ); |
| 79361 | mask = ((tAttachMask)1)<<iDb; |
| 79362 | if( (pToplevel->cookieMask & mask)==0 ){ |
| 79363 | pToplevel->cookieMask |= mask; |
| 79364 | pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie; |
| 79365 | if( !OMIT_TEMPDB && iDb==1 ){ |
| 79366 | sqlite3OpenTempDatabase(pToplevel); |
| @@ -79383,11 +79491,11 @@ | |
| 79383 | ** necessary to undo a write and the checkpoint should not be set. |
| 79384 | */ |
| 79385 | SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){ |
| 79386 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 79387 | sqlite3CodeVerifySchema(pParse, iDb); |
| 79388 | pToplevel->writeMask |= ((tAttachMask)1)<<iDb; |
| 79389 | pToplevel->isMultiWrite |= setStatement; |
| 79390 | } |
| 79391 | |
| 79392 | /* |
| 79393 | ** Indicate that the statement currently under construction might write |
| @@ -99567,11 +99675,11 @@ | |
| 99567 | ** VALUE and how common that value is according to the histogram. |
| 99568 | */ |
| 99569 | if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 ){ |
| 99570 | if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){ |
| 99571 | testcase( pFirstTerm->eOperator==WO_EQ ); |
| 99572 | testcase( pFirstTerm->pOperator==WO_ISNULL ); |
| 99573 | whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow); |
| 99574 | }else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){ |
| 99575 | whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow); |
| 99576 | } |
| 99577 | } |
| 99578 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,9 +1,9 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.7.6. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| 9 | ** |
| @@ -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 | ** |
| @@ -3521,11 +3521,13 @@ | |
| 3521 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
| 3522 | ** that implements the [SELECT] statement. ^The second parameter is the |
| 3523 | ** column number. ^The leftmost column is number 0. |
| 3524 | ** |
| 3525 | ** ^The returned string pointer is valid until either the [prepared statement] |
| 3526 | ** is destroyed by [sqlite3_finalize()] or until the statement is automatically |
| 3527 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
| 3528 | ** or until the next call to |
| 3529 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
| 3530 | ** |
| 3531 | ** ^If sqlite3_malloc() fails during the processing of either routine |
| 3532 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
| 3533 | ** NULL pointer is returned. |
| @@ -3547,11 +3549,13 @@ | |
| 3549 | ** ^The name of the database or table or column can be returned as |
| 3550 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 3551 | ** the database name, the _table_ routines return the table name, and |
| 3552 | ** the origin_ routines return the column name. |
| 3553 | ** ^The returned string is valid until the [prepared statement] is destroyed |
| 3554 | ** using [sqlite3_finalize()] or until the statement is automatically |
| 3555 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
| 3556 | ** or until the same information is requested |
| 3557 | ** again in a different encoding. |
| 3558 | ** |
| 3559 | ** ^The names returned are the original un-aliased names of the |
| 3560 | ** database, table, and column. |
| 3561 | ** |
| @@ -7648,22 +7652,10 @@ | |
| 7652 | ** Forward declarations of structure |
| 7653 | */ |
| 7654 | typedef struct Btree Btree; |
| 7655 | typedef struct BtCursor BtCursor; |
| 7656 | typedef struct BtShared BtShared; |
| 7657 | |
| 7658 | |
| 7659 | SQLITE_PRIVATE int sqlite3BtreeOpen( |
| 7660 | const char *zFilename, /* Name of database file to open */ |
| 7661 | sqlite3 *db, /* Associated database connection */ |
| @@ -7696,11 +7688,11 @@ | |
| 7688 | SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*); |
| 7689 | SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int); |
| 7690 | SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); |
| 7691 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int); |
| 7692 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); |
| 7693 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int); |
| 7694 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); |
| 7695 | SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*); |
| 7696 | SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); |
| 7697 | SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
| 7698 | SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*); |
| @@ -7837,27 +7829,23 @@ | |
| 7829 | #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE |
| 7830 | SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*); |
| 7831 | SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*); |
| 7832 | SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*); |
| 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 | |
| @@ -10467,15 +10455,17 @@ | |
| 10455 | SubProgram *pProgram; /* Program implementing pTrigger/orconf */ |
| 10456 | u32 aColmask[2]; /* Masks of old.*, new.* columns accessed */ |
| 10457 | TriggerPrg *pNext; /* Next entry in Parse.pTriggerPrg list */ |
| 10458 | }; |
| 10459 | |
| 10460 | /* |
| 10461 | ** The yDbMask datatype for the bitmask of all attached databases. |
| 10462 | */ |
| 10463 | #if SQLITE_MAX_ATTACHED>30 |
| 10464 | typedef sqlite3_uint64 yDbMask; |
| 10465 | #else |
| 10466 | typedef unsigned int yDbMask; |
| 10467 | #endif |
| 10468 | |
| 10469 | /* |
| 10470 | ** An SQL parser context. A copy of this structure is passed through |
| 10471 | ** the parser and down into all the parser action routine in order to |
| @@ -10522,12 +10512,12 @@ | |
| 10512 | u8 tempReg; /* iReg is a temp register that needs to be freed */ |
| 10513 | int iLevel; /* Nesting level */ |
| 10514 | int iReg; /* Reg with value of this column. 0 means none. */ |
| 10515 | int lru; /* Least recently used entry has the smallest value */ |
| 10516 | } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */ |
| 10517 | yDbMask writeMask; /* Start a write transaction on these databases */ |
| 10518 | yDbMask cookieMask; /* Bitmask of schema verified databases */ |
| 10519 | u8 isMultiWrite; /* True if statement may affect/insert multiple rows */ |
| 10520 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 10521 | int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */ |
| 10522 | int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */ |
| 10523 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| @@ -12488,14 +12478,14 @@ | |
| 12478 | u8 inVtabMethod; /* See comments above */ |
| 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 |
| 12490 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 12491 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| @@ -12573,10 +12563,13 @@ | |
| 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 | |
| @@ -12584,16 +12577,10 @@ | |
| 12577 | SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *, int); |
| 12578 | #else |
| 12579 | # define sqlite3VdbeCheckFk(p,i) 0 |
| 12580 | #endif |
| 12581 | |
| 12582 | SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8); |
| 12583 | #ifdef SQLITE_DEBUG |
| 12584 | SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*); |
| 12585 | SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); |
| 12586 | #endif |
| @@ -19794,11 +19781,11 @@ | |
| 19781 | } |
| 19782 | SQLITE_PRIVATE int sqlite3Utf8Read( |
| 19783 | const unsigned char *zIn, /* First byte of UTF-8 character */ |
| 19784 | const unsigned char **pzNext /* Write first byte past UTF-8 char here */ |
| 19785 | ){ |
| 19786 | unsigned int c; |
| 19787 | |
| 19788 | /* Same as READ_UTF8() above but without the zTerm parameter. |
| 19789 | ** For this routine, we assume the UTF8 string is always zero-terminated. |
| 19790 | */ |
| 19791 | c = *(zIn++); |
| @@ -20037,19 +20024,19 @@ | |
| 20024 | ** Translate UTF-8 to UTF-8. |
| 20025 | ** |
| 20026 | ** This has the effect of making sure that the string is well-formed |
| 20027 | ** UTF-8. Miscoded characters are removed. |
| 20028 | ** |
| 20029 | ** The translation is done in-place and aborted if the output |
| 20030 | ** overruns the input. |
| 20031 | */ |
| 20032 | SQLITE_PRIVATE int sqlite3Utf8To8(unsigned char *zIn){ |
| 20033 | unsigned char *zOut = zIn; |
| 20034 | unsigned char *zStart = zIn; |
| 20035 | u32 c; |
| 20036 | |
| 20037 | while( zIn[0] && zOut<=zIn ){ |
| 20038 | c = sqlite3Utf8Read(zIn, (const u8**)&zIn); |
| 20039 | if( c!=0xfffd ){ |
| 20040 | WRITE_UTF8(zOut, c); |
| 20041 | } |
| 20042 | } |
| @@ -23750,11 +23737,11 @@ | |
| 23737 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 23738 | { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 }, |
| 23739 | #else |
| 23740 | { "fallocate", (sqlite3_syscall_ptr)0, 0 }, |
| 23741 | #endif |
| 23742 | #define osFallocate ((int(*)(int,off_t,off_t))aSyscall[15].pCurrent) |
| 23743 | |
| 23744 | }; /* End of the overrideable system calls */ |
| 23745 | |
| 23746 | /* |
| 23747 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| @@ -23773,14 +23760,14 @@ | |
| 23760 | UNUSED_PARAMETER(pNotUsed); |
| 23761 | if( zName==0 ){ |
| 23762 | /* If no zName is given, restore all system calls to their default |
| 23763 | ** settings and return NULL |
| 23764 | */ |
| 23765 | rc = SQLITE_OK; |
| 23766 | for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){ |
| 23767 | if( aSyscall[i].pDefault ){ |
| 23768 | aSyscall[i].pCurrent = aSyscall[i].pDefault; |
| 23769 | } |
| 23770 | } |
| 23771 | }else{ |
| 23772 | /* If zName is specified, operate on only the one system call |
| 23773 | ** specified. |
| @@ -23823,22 +23810,20 @@ | |
| 23810 | ** then return the name of the first system call. Return NULL if zName |
| 23811 | ** is the last system call or if zName is not the name of a valid |
| 23812 | ** system call. |
| 23813 | */ |
| 23814 | static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){ |
| 23815 | int i = -1; |
| 23816 | |
| 23817 | UNUSED_PARAMETER(p); |
| 23818 | if( zName ){ |
| 23819 | for(i=0; i<ArraySize(aSyscall)-1; i++){ |
| 23820 | if( strcmp(zName, aSyscall[i].zName)==0 ) break; |
| 23821 | } |
| 23822 | } |
| 23823 | for(i++; i<ArraySize(aSyscall); i++){ |
| 23824 | if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; |
| 23825 | } |
| 23826 | return 0; |
| 23827 | } |
| 23828 | |
| 23829 | /* |
| @@ -23974,13 +23959,26 @@ | |
| 23959 | ** Errors during initialization of locks, or file system support for locks, |
| 23960 | ** should handle ENOLCK, ENOTSUP, EOPNOTSUPP separately. |
| 23961 | */ |
| 23962 | static int sqliteErrorFromPosixError(int posixError, int sqliteIOErr) { |
| 23963 | switch (posixError) { |
| 23964 | #if 0 |
| 23965 | /* At one point this code was not commented out. In theory, this branch |
| 23966 | ** should never be hit, as this function should only be called after |
| 23967 | ** a locking-related function (i.e. fcntl()) has returned non-zero with |
| 23968 | ** the value of errno as the first argument. Since a system call has failed, |
| 23969 | ** errno should be non-zero. |
| 23970 | ** |
| 23971 | ** Despite this, if errno really is zero, we still don't want to return |
| 23972 | ** SQLITE_OK. The system call failed, and *some* SQLite error should be |
| 23973 | ** propagated back to the caller. Commenting this branch out means errno==0 |
| 23974 | ** will be handled by the "default:" case below. |
| 23975 | */ |
| 23976 | case 0: |
| 23977 | return SQLITE_OK; |
| 23978 | #endif |
| 23979 | |
| 23980 | case EAGAIN: |
| 23981 | case ETIMEDOUT: |
| 23982 | case EBUSY: |
| 23983 | case EINTR: |
| 23984 | case ENOLCK: |
| @@ -23998,12 +23996,19 @@ | |
| 23996 | } |
| 23997 | /* else fall through */ |
| 23998 | case EPERM: |
| 23999 | return SQLITE_PERM; |
| 24000 | |
| 24001 | /* EDEADLK is only possible if a call to fcntl(F_SETLKW) is made. And |
| 24002 | ** this module never makes such a call. And the code in SQLite itself |
| 24003 | ** asserts that SQLITE_IOERR_BLOCKED is never returned. For these reasons |
| 24004 | ** this case is also commented out. If the system does set errno to EDEADLK, |
| 24005 | ** the default SQLITE_IOERR_XXX code will be returned. */ |
| 24006 | #if 0 |
| 24007 | case EDEADLK: |
| 24008 | return SQLITE_IOERR_BLOCKED; |
| 24009 | #endif |
| 24010 | |
| 24011 | #if EOPNOTSUPP!=ENOTSUP |
| 24012 | case EOPNOTSUPP: |
| 24013 | /* something went terribly awry, unless during file system support |
| 24014 | * introspection, in which it actually means what it says */ |
| @@ -24418,11 +24423,11 @@ | |
| 24423 | ** when this function is called. |
| 24424 | */ |
| 24425 | static void releaseInodeInfo(unixFile *pFile){ |
| 24426 | unixInodeInfo *pInode = pFile->pInode; |
| 24427 | assert( unixMutexHeld() ); |
| 24428 | if( ALWAYS(pInode) ){ |
| 24429 | pInode->nRef--; |
| 24430 | if( pInode->nRef==0 ){ |
| 24431 | assert( pInode->pShmNode==0 ); |
| 24432 | closePendingFds(pFile); |
| 24433 | if( pInode->pPrev ){ |
| @@ -24560,14 +24565,13 @@ | |
| 24565 | struct flock lock; |
| 24566 | lock.l_whence = SEEK_SET; |
| 24567 | lock.l_start = RESERVED_BYTE; |
| 24568 | lock.l_len = 1; |
| 24569 | lock.l_type = F_WRLCK; |
| 24570 | if( osFcntl(pFile->h, F_GETLK, &lock) ){ |
| 24571 | rc = SQLITE_IOERR_CHECKRESERVEDLOCK; |
| 24572 | pFile->lastErrno = errno; |
| 24573 | } else if( lock.l_type!=F_UNLCK ){ |
| 24574 | reserved = 1; |
| 24575 | } |
| 24576 | } |
| 24577 | #endif |
| @@ -24592,10 +24596,13 @@ | |
| 24596 | ** operating system does not participate. |
| 24597 | ** |
| 24598 | ** This function is a pass-through to fcntl(F_SETLK) if pFile is using |
| 24599 | ** any VFS other than "unix-excl" or if pFile is opened on "unix-excl" |
| 24600 | ** and is read-only. |
| 24601 | ** |
| 24602 | ** Zero is returned if the call completes successfully, or -1 if a call |
| 24603 | ** to fcntl() fails. In this case, errno is set appropriately (by fcntl()). |
| 24604 | */ |
| 24605 | static int unixFileLock(unixFile *pFile, struct flock *pLock){ |
| 24606 | int rc; |
| 24607 | unixInodeInfo *pInode = pFile->pInode; |
| 24608 | assert( unixMutexHeld() ); |
| @@ -24688,11 +24695,10 @@ | |
| 24695 | */ |
| 24696 | int rc = SQLITE_OK; |
| 24697 | unixFile *pFile = (unixFile*)id; |
| 24698 | unixInodeInfo *pInode = pFile->pInode; |
| 24699 | struct flock lock; |
| 24700 | int tErrno = 0; |
| 24701 | |
| 24702 | assert( pFile ); |
| 24703 | OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h, |
| 24704 | azFileLock(eFileLock), azFileLock(pFile->eFileLock), |
| @@ -24757,15 +24763,14 @@ | |
| 24763 | if( eFileLock==SHARED_LOCK |
| 24764 | || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK) |
| 24765 | ){ |
| 24766 | lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK); |
| 24767 | lock.l_start = PENDING_BYTE; |
| 24768 | if( unixFileLock(pFile, &lock) ){ |
| 24769 | tErrno = errno; |
| 24770 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24771 | if( rc!=SQLITE_BUSY ){ |
| 24772 | pFile->lastErrno = tErrno; |
| 24773 | } |
| 24774 | goto end_lock; |
| 24775 | } |
| 24776 | } |
| @@ -24775,37 +24780,35 @@ | |
| 24780 | ** operating system calls for the specified lock. |
| 24781 | */ |
| 24782 | if( eFileLock==SHARED_LOCK ){ |
| 24783 | assert( pInode->nShared==0 ); |
| 24784 | assert( pInode->eFileLock==0 ); |
| 24785 | assert( rc==SQLITE_OK ); |
| 24786 | |
| 24787 | /* Now get the read-lock */ |
| 24788 | lock.l_start = SHARED_FIRST; |
| 24789 | lock.l_len = SHARED_SIZE; |
| 24790 | if( unixFileLock(pFile, &lock) ){ |
| 24791 | tErrno = errno; |
| 24792 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24793 | } |
| 24794 | |
| 24795 | /* Drop the temporary PENDING lock */ |
| 24796 | lock.l_start = PENDING_BYTE; |
| 24797 | lock.l_len = 1L; |
| 24798 | lock.l_type = F_UNLCK; |
| 24799 | if( unixFileLock(pFile, &lock) && rc==SQLITE_OK ){ |
| 24800 | /* This could happen with a network mount */ |
| 24801 | tErrno = errno; |
| 24802 | rc = SQLITE_IOERR_UNLOCK; |
| 24803 | } |
| 24804 | |
| 24805 | if( rc ){ |
| 24806 | if( rc!=SQLITE_BUSY ){ |
| 24807 | pFile->lastErrno = tErrno; |
| 24808 | } |
| 24809 | goto end_lock; |
| 24810 | }else{ |
| 24811 | pFile->eFileLock = SHARED_LOCK; |
| 24812 | pInode->nLock++; |
| 24813 | pInode->nShared = 1; |
| 24814 | } |
| @@ -24818,26 +24821,24 @@ | |
| 24821 | ** assumed that there is a SHARED or greater lock on the file |
| 24822 | ** already. |
| 24823 | */ |
| 24824 | assert( 0!=pFile->eFileLock ); |
| 24825 | lock.l_type = F_WRLCK; |
| 24826 | |
| 24827 | assert( eFileLock==RESERVED_LOCK || eFileLock==EXCLUSIVE_LOCK ); |
| 24828 | if( eFileLock==RESERVED_LOCK ){ |
| 24829 | lock.l_start = RESERVED_BYTE; |
| 24830 | lock.l_len = 1L; |
| 24831 | }else{ |
| 24832 | lock.l_start = SHARED_FIRST; |
| 24833 | lock.l_len = SHARED_SIZE; |
| 24834 | } |
| 24835 | |
| 24836 | if( unixFileLock(pFile, &lock) ){ |
| 24837 | tErrno = errno; |
| 24838 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 24839 | if( rc!=SQLITE_BUSY ){ |
| 24840 | pFile->lastErrno = tErrno; |
| 24841 | } |
| 24842 | } |
| 24843 | } |
| 24844 | |
| @@ -24904,11 +24905,10 @@ | |
| 24905 | unixFile *pFile = (unixFile*)id; |
| 24906 | unixInodeInfo *pInode; |
| 24907 | struct flock lock; |
| 24908 | int rc = SQLITE_OK; |
| 24909 | int h; |
| 24910 | |
| 24911 | assert( pFile ); |
| 24912 | OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock, |
| 24913 | pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared, |
| 24914 | getpid())); |
| @@ -24959,19 +24959,20 @@ | |
| 24959 | (void)handleNFSUnlock; |
| 24960 | assert( handleNFSUnlock==0 ); |
| 24961 | #endif |
| 24962 | #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE |
| 24963 | if( handleNFSUnlock ){ |
| 24964 | int tErrno; /* Error code from system call errors */ |
| 24965 | off_t divSize = SHARED_SIZE - 1; |
| 24966 | |
| 24967 | lock.l_type = F_UNLCK; |
| 24968 | lock.l_whence = SEEK_SET; |
| 24969 | lock.l_start = SHARED_FIRST; |
| 24970 | lock.l_len = divSize; |
| 24971 | if( unixFileLock(pFile, &lock)==(-1) ){ |
| 24972 | tErrno = errno; |
| 24973 | rc = SQLITE_IOERR_UNLOCK; |
| 24974 | if( IS_LOCK_ERROR(rc) ){ |
| 24975 | pFile->lastErrno = tErrno; |
| 24976 | } |
| 24977 | goto end_unlock; |
| 24978 | } |
| @@ -24991,11 +24992,11 @@ | |
| 24992 | lock.l_whence = SEEK_SET; |
| 24993 | lock.l_start = SHARED_FIRST+divSize; |
| 24994 | lock.l_len = SHARED_SIZE-divSize; |
| 24995 | if( unixFileLock(pFile, &lock)==(-1) ){ |
| 24996 | tErrno = errno; |
| 24997 | rc = SQLITE_IOERR_UNLOCK; |
| 24998 | if( IS_LOCK_ERROR(rc) ){ |
| 24999 | pFile->lastErrno = tErrno; |
| 25000 | } |
| 25001 | goto end_unlock; |
| 25002 | } |
| @@ -25004,32 +25005,32 @@ | |
| 25005 | { |
| 25006 | lock.l_type = F_RDLCK; |
| 25007 | lock.l_whence = SEEK_SET; |
| 25008 | lock.l_start = SHARED_FIRST; |
| 25009 | lock.l_len = SHARED_SIZE; |
| 25010 | if( unixFileLock(pFile, &lock) ){ |
| 25011 | /* In theory, the call to unixFileLock() cannot fail because another |
| 25012 | ** process is holding an incompatible lock. If it does, this |
| 25013 | ** indicates that the other process is not following the locking |
| 25014 | ** protocol. If this happens, return SQLITE_IOERR_RDLOCK. Returning |
| 25015 | ** SQLITE_BUSY would confuse the upper layer (in practice it causes |
| 25016 | ** an assert to fail). */ |
| 25017 | rc = SQLITE_IOERR_RDLOCK; |
| 25018 | pFile->lastErrno = errno; |
| 25019 | goto end_unlock; |
| 25020 | } |
| 25021 | } |
| 25022 | } |
| 25023 | lock.l_type = F_UNLCK; |
| 25024 | lock.l_whence = SEEK_SET; |
| 25025 | lock.l_start = PENDING_BYTE; |
| 25026 | lock.l_len = 2L; assert( PENDING_BYTE+1==RESERVED_BYTE ); |
| 25027 | if( unixFileLock(pFile, &lock)==0 ){ |
| 25028 | pInode->eFileLock = SHARED_LOCK; |
| 25029 | }else{ |
| 25030 | rc = SQLITE_IOERR_UNLOCK; |
| 25031 | pFile->lastErrno = errno; |
| 25032 | goto end_unlock; |
| 25033 | } |
| 25034 | } |
| 25035 | if( eFileLock==NO_LOCK ){ |
| 25036 | /* Decrement the shared lock counter. Release the lock using an |
| @@ -25042,18 +25043,15 @@ | |
| 25043 | lock.l_whence = SEEK_SET; |
| 25044 | lock.l_start = lock.l_len = 0L; |
| 25045 | SimulateIOErrorBenign(1); |
| 25046 | SimulateIOError( h=(-1) ) |
| 25047 | SimulateIOErrorBenign(0); |
| 25048 | if( unixFileLock(pFile, &lock)==0 ){ |
| 25049 | pInode->eFileLock = NO_LOCK; |
| 25050 | }else{ |
| 25051 | rc = SQLITE_IOERR_UNLOCK; |
| 25052 | pFile->lastErrno = errno; |
| 25053 | pInode->eFileLock = NO_LOCK; |
| 25054 | pFile->eFileLock = NO_LOCK; |
| 25055 | } |
| 25056 | } |
| 25057 | |
| @@ -25095,59 +25093,58 @@ | |
| 25093 | ** even on VxWorks. A mutex will be acquired on VxWorks by the |
| 25094 | ** vxworksReleaseFileId() routine. |
| 25095 | */ |
| 25096 | static int closeUnixFile(sqlite3_file *id){ |
| 25097 | unixFile *pFile = (unixFile*)id; |
| 25098 | if( pFile->dirfd>=0 ){ |
| 25099 | robust_close(pFile, pFile->dirfd, __LINE__); |
| 25100 | pFile->dirfd=-1; |
| 25101 | } |
| 25102 | if( pFile->h>=0 ){ |
| 25103 | robust_close(pFile, pFile->h, __LINE__); |
| 25104 | pFile->h = -1; |
| 25105 | } |
| 25106 | #if OS_VXWORKS |
| 25107 | if( pFile->pId ){ |
| 25108 | if( pFile->isDelete ){ |
| 25109 | unlink(pFile->pId->zCanonicalName); |
| 25110 | } |
| 25111 | vxworksReleaseFileId(pFile->pId); |
| 25112 | pFile->pId = 0; |
| 25113 | } |
| 25114 | #endif |
| 25115 | OSTRACE(("CLOSE %-3d\n", pFile->h)); |
| 25116 | OpenCounter(-1); |
| 25117 | sqlite3_free(pFile->pUnused); |
| 25118 | memset(pFile, 0, sizeof(unixFile)); |
| 25119 | return SQLITE_OK; |
| 25120 | } |
| 25121 | |
| 25122 | /* |
| 25123 | ** Close a file. |
| 25124 | */ |
| 25125 | static int unixClose(sqlite3_file *id){ |
| 25126 | int rc = SQLITE_OK; |
| 25127 | unixFile *pFile = (unixFile *)id; |
| 25128 | unixUnlock(id, NO_LOCK); |
| 25129 | unixEnterMutex(); |
| 25130 | |
| 25131 | /* unixFile.pInode is always valid here. Otherwise, a different close |
| 25132 | ** routine (e.g. nolockClose()) would be called instead. |
| 25133 | */ |
| 25134 | assert( pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 ); |
| 25135 | if( ALWAYS(pFile->pInode) && pFile->pInode->nLock ){ |
| 25136 | /* If there are outstanding locks, do not actually close the file just |
| 25137 | ** yet because that would clear those locks. Instead, add the file |
| 25138 | ** descriptor to pInode->pUnused list. It will be automatically closed |
| 25139 | ** when the last lock is cleared. |
| 25140 | */ |
| 25141 | setPendingFd(pFile); |
| 25142 | } |
| 25143 | releaseInodeInfo(pFile); |
| 25144 | rc = closeUnixFile(id); |
| 25145 | unixLeaveMutex(); |
| 25146 | return rc; |
| 25147 | } |
| 25148 | |
| 25149 | /************** End of the posix advisory lock implementation ***************** |
| 25150 | ******************************************************************************/ |
| @@ -25358,11 +25355,11 @@ | |
| 25355 | assert( eFileLock==NO_LOCK ); |
| 25356 | if( unlink(zLockFile) ){ |
| 25357 | int rc = 0; |
| 25358 | int tErrno = errno; |
| 25359 | if( ENOENT != tErrno ){ |
| 25360 | rc = SQLITE_IOERR_UNLOCK; |
| 25361 | } |
| 25362 | if( IS_LOCK_ERROR(rc) ){ |
| 25363 | pFile->lastErrno = tErrno; |
| 25364 | } |
| 25365 | return rc; |
| @@ -25446,11 +25443,11 @@ | |
| 25443 | /* got the lock, unlock it */ |
| 25444 | lrc = robust_flock(pFile->h, LOCK_UN); |
| 25445 | if ( lrc ) { |
| 25446 | int tErrno = errno; |
| 25447 | /* unlock failed with an error */ |
| 25448 | lrc = SQLITE_IOERR_UNLOCK; |
| 25449 | if( IS_LOCK_ERROR(lrc) ){ |
| 25450 | pFile->lastErrno = tErrno; |
| 25451 | rc = lrc; |
| 25452 | } |
| 25453 | } |
| @@ -25568,25 +25565,16 @@ | |
| 25565 | pFile->eFileLock = eFileLock; |
| 25566 | return SQLITE_OK; |
| 25567 | } |
| 25568 | |
| 25569 | /* no, really, unlock. */ |
| 25570 | if( robust_flock(pFile->h, LOCK_UN) ){ |
| 25571 | #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS |
| 25572 | return SQLITE_OK; |
| 25573 | #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */ |
| 25574 | return SQLITE_IOERR_UNLOCK; |
| 25575 | }else{ |
| 25576 | pFile->eFileLock = NO_LOCK; |
| 25577 | return SQLITE_OK; |
| 25578 | } |
| 25579 | } |
| 25580 | |
| @@ -26388,10 +26376,11 @@ | |
| 26376 | do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR ); |
| 26377 | #elif defined(USE_PREAD64) |
| 26378 | do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR); |
| 26379 | #else |
| 26380 | newOffset = lseek(id->h, offset, SEEK_SET); |
| 26381 | SimulateIOError( newOffset-- ); |
| 26382 | if( newOffset!=offset ){ |
| 26383 | if( newOffset == -1 ){ |
| 26384 | ((unixFile*)id)->lastErrno = errno; |
| 26385 | }else{ |
| 26386 | ((unixFile*)id)->lastErrno = 0; |
| @@ -26756,16 +26745,20 @@ | |
| 26745 | |
| 26746 | if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT; |
| 26747 | |
| 26748 | nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk; |
| 26749 | if( nSize>(i64)buf.st_size ){ |
| 26750 | |
| 26751 | #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 26752 | /* The code below is handling the return value of osFallocate() |
| 26753 | ** correctly. posix_fallocate() is defined to "returns zero on success, |
| 26754 | ** or an error number on failure". See the manpage for details. */ |
| 26755 | int err; |
| 26756 | do{ |
| 26757 | err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size); |
| 26758 | }while( err==EINTR ); |
| 26759 | if( err ) return SQLITE_IOERR_WRITE; |
| 26760 | #else |
| 26761 | /* If the OS does not have posix_fallocate(), fake it. First use |
| 26762 | ** ftruncate() to set the file size, then write a single byte to |
| 26763 | ** the last byte in each block within the extended region. This |
| 26764 | ** is the same technique used by glibc to implement posix_fallocate() |
| @@ -29114,11 +29107,13 @@ | |
| 29107 | rc = SQLITE_NOMEM; |
| 29108 | goto end_create_proxy; |
| 29109 | } |
| 29110 | memset(pNew, 0, sizeof(unixFile)); |
| 29111 | pNew->openFlags = openFlags; |
| 29112 | memset(&dummyVfs, 0, sizeof(dummyVfs)); |
| 29113 | dummyVfs.pAppData = (void*)&autolockIoFinder; |
| 29114 | dummyVfs.zName = "dummy"; |
| 29115 | pUnused->fd = fd; |
| 29116 | pUnused->flags = openFlags; |
| 29117 | pNew->pUnused = pUnused; |
| 29118 | |
| 29119 | rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0, 0); |
| @@ -45633,11 +45628,11 @@ | |
| 45628 | ** the BtShared object. |
| 45629 | ** |
| 45630 | ** All fields in this structure are accessed under sqlite3.mutex. |
| 45631 | ** The pBt pointer itself may not be changed while there exists cursors |
| 45632 | ** in the referenced BtShared that point back to this Btree since those |
| 45633 | ** cursors have to go through this Btree to find their BtShared and |
| 45634 | ** they often do so without holding sqlite3.mutex. |
| 45635 | */ |
| 45636 | struct Btree { |
| 45637 | sqlite3 *db; /* The database connection holding this btree */ |
| 45638 | BtShared *pBt; /* Sharable content of this btree */ |
| @@ -45723,19 +45718,20 @@ | |
| 45718 | u32 usableSize; /* Number of usable bytes on each page */ |
| 45719 | int nTransaction; /* Number of open transactions (read + write) */ |
| 45720 | u32 nPage; /* Number of pages in the database */ |
| 45721 | void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */ |
| 45722 | void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */ |
| 45723 | sqlite3_mutex *mutex; /* Non-recursive mutex required to access this object */ |
| 45724 | Bitvec *pHasContent; /* Set of pages moved to free-list this transaction */ |
| 45725 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 45726 | int nRef; /* Number of references to this structure */ |
| 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 | /* |
| @@ -45964,18 +45960,37 @@ | |
| 45960 | /* |
| 45961 | ** Release the BtShared mutex associated with B-Tree handle p and |
| 45962 | ** clear the p->locked boolean. |
| 45963 | */ |
| 45964 | static void unlockBtreeMutex(Btree *p){ |
| 45965 | BtShared *pBt = p->pBt; |
| 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 |
| @@ -46016,10 +46031,28 @@ | |
| 46031 | assert( (p->locked==0 && p->sharable) || p->pBt->db==p->db ); |
| 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 | */ |
| @@ -46120,11 +46153,11 @@ | |
| 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); |
| @@ -46176,101 +46209,21 @@ | |
| 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 |
| 46219 | ** are null #defines in btree.h. |
| 46220 | ** |
| 46221 | ** If shared cache is disabled, then all btree mutex routines, including |
| 46222 | ** the ones below, are no-ops and are null #defines in btree.h. |
| 46223 | */ |
| 46224 | |
| 46225 | SQLITE_PRIVATE void sqlite3BtreeEnter(Btree *p){ |
| 46226 | p->pBt->db = p->db; |
| 46227 | } |
| 46228 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 46229 | int i; |
| @@ -49444,15 +49397,26 @@ | |
| 49397 | ** routine did all the work of writing information out to disk and flushing the |
| 49398 | ** contents so that they are written onto the disk platter. All this |
| 49399 | ** routine has to do is delete or truncate or zero the header in the |
| 49400 | ** the rollback journal (which causes the transaction to commit) and |
| 49401 | ** drop locks. |
| 49402 | ** |
| 49403 | ** Normally, if an error occurs while the pager layer is attempting to |
| 49404 | ** finalize the underlying journal file, this function returns an error and |
| 49405 | ** the upper layer will attempt a rollback. However, if the second argument |
| 49406 | ** is non-zero then this b-tree transaction is part of a multi-file |
| 49407 | ** transaction. In this case, the transaction has already been committed |
| 49408 | ** (by deleting a master journal file) and the caller will ignore this |
| 49409 | ** functions return code. So, even if an error occurs in the pager layer, |
| 49410 | ** reset the b-tree objects internal state to indicate that the write |
| 49411 | ** transaction has been closed. This is quite safe, as the pager will have |
| 49412 | ** transitioned to the error state. |
| 49413 | ** |
| 49414 | ** This will release the write lock on the database file. If there |
| 49415 | ** are no active cursors, it also releases the read lock. |
| 49416 | */ |
| 49417 | SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *p, int bCleanup){ |
| 49418 | |
| 49419 | if( p->inTrans==TRANS_NONE ) return SQLITE_OK; |
| 49420 | sqlite3BtreeEnter(p); |
| 49421 | btreeIntegrity(p); |
| 49422 | |
| @@ -49463,11 +49427,11 @@ | |
| 49427 | int rc; |
| 49428 | BtShared *pBt = p->pBt; |
| 49429 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 49430 | assert( pBt->nTransaction>0 ); |
| 49431 | rc = sqlite3PagerCommitPhaseTwo(pBt->pPager); |
| 49432 | if( rc!=SQLITE_OK && bCleanup==0 ){ |
| 49433 | sqlite3BtreeLeave(p); |
| 49434 | return rc; |
| 49435 | } |
| 49436 | pBt->inTransaction = TRANS_READ; |
| 49437 | } |
| @@ -49483,11 +49447,11 @@ | |
| 49447 | SQLITE_PRIVATE int sqlite3BtreeCommit(Btree *p){ |
| 49448 | int rc; |
| 49449 | sqlite3BtreeEnter(p); |
| 49450 | rc = sqlite3BtreeCommitPhaseOne(p, 0); |
| 49451 | if( rc==SQLITE_OK ){ |
| 49452 | rc = sqlite3BtreeCommitPhaseTwo(p, 0); |
| 49453 | } |
| 49454 | sqlite3BtreeLeave(p); |
| 49455 | return rc; |
| 49456 | } |
| 49457 | |
| @@ -54264,11 +54228,11 @@ | |
| 54228 | ** allocated, a null pointer is returned. If the blob has already been |
| 54229 | ** allocated, it is returned as normal. |
| 54230 | ** |
| 54231 | ** Just before the shared-btree is closed, the function passed as the |
| 54232 | ** xFree argument when the memory allocation was made is invoked on the |
| 54233 | ** blob of allocated memory. The xFree function should not call sqlite3_free() |
| 54234 | ** on the memory, the btree layer does that. |
| 54235 | */ |
| 54236 | SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){ |
| 54237 | BtShared *pBt = p->pBt; |
| 54238 | sqlite3BtreeEnter(p); |
| @@ -54907,11 +54871,11 @@ | |
| 54871 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 54872 | } |
| 54873 | |
| 54874 | /* Finish committing the transaction to the destination database. */ |
| 54875 | if( SQLITE_OK==rc |
| 54876 | && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0)) |
| 54877 | ){ |
| 54878 | rc = SQLITE_DONE; |
| 54879 | } |
| 54880 | } |
| 54881 | |
| @@ -54921,11 +54885,11 @@ | |
| 54885 | ** "committing" a read-only transaction cannot fail. |
| 54886 | */ |
| 54887 | if( bCloseTrans ){ |
| 54888 | TESTONLY( int rc2 ); |
| 54889 | TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0); |
| 54890 | TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0); |
| 54891 | assert( rc2==SQLITE_OK ); |
| 54892 | } |
| 54893 | |
| 54894 | if( rc==SQLITE_IOERR_NOMEM ){ |
| 54895 | rc = SQLITE_NOMEM; |
| @@ -56419,10 +56383,15 @@ | |
| 56383 | pOp->p2 = p2; |
| 56384 | pOp->p3 = p3; |
| 56385 | pOp->p4.p = 0; |
| 56386 | pOp->p4type = P4_NOTUSED; |
| 56387 | p->expired = 0; |
| 56388 | if( op==OP_ParseSchema ){ |
| 56389 | /* Any program that uses the OP_ParseSchema opcode needs to lock |
| 56390 | ** all btrees. */ |
| 56391 | p->btreeMask = ~(yDbMask)0; |
| 56392 | } |
| 56393 | #ifdef SQLITE_DEBUG |
| 56394 | pOp->zComment = 0; |
| 56395 | if( sqlite3VdbeAddopTrace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 56396 | #endif |
| 56397 | #ifdef VDBE_PROFILE |
| @@ -56719,11 +56688,11 @@ | |
| 56688 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeTakeOpArray(Vdbe *p, int *pnOp, int *pnMaxArg){ |
| 56689 | VdbeOp *aOp = p->aOp; |
| 56690 | assert( aOp && !p->db->mallocFailed ); |
| 56691 | |
| 56692 | /* Check that sqlite3VdbeUsesBtree() was not called on this VM */ |
| 56693 | assert( p->btreeMask==0 ); |
| 56694 | |
| 56695 | resolveP2Values(p, pnMaxArg); |
| 56696 | *pnOp = p->nOp; |
| 56697 | p->aOp = 0; |
| 56698 | return aOp; |
| @@ -56821,10 +56790,11 @@ | |
| 56790 | /* |
| 56791 | ** Change the P2 operand of instruction addr so that it points to |
| 56792 | ** the address of the next instruction to be coded. |
| 56793 | */ |
| 56794 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe *p, int addr){ |
| 56795 | assert( addr>=0 ); |
| 56796 | sqlite3VdbeChangeP2(p, addr, p->nOp); |
| 56797 | } |
| 56798 | |
| 56799 | |
| 56800 | /* |
| @@ -57206,26 +57176,135 @@ | |
| 57176 | #endif |
| 57177 | |
| 57178 | /* |
| 57179 | ** Declare to the Vdbe that the BTree object at db->aDb[i] is used. |
| 57180 | ** |
| 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 |
| 57221 | ** that the correct busy-handler callback is invoked if required. |
| 57222 | ** |
| 57223 | ** If SQLite is not threadsafe but does support shared-cache mode, then |
| 57224 | ** sqlite3BtreeEnter() is invoked to set the BtShared.db variables |
| 57225 | ** of all of BtShared structures accessible via the database handle |
| 57226 | ** associated with the VM. |
| 57227 | ** |
| 57228 | ** If SQLite is not threadsafe and does not support shared-cache mode, this |
| 57229 | ** function is a no-op. |
| 57230 | ** |
| 57231 | ** The p->btreeMask field is a bitmask of all btrees that the prepared |
| 57232 | ** statement p will ever use. Let N be the number of bits in p->btreeMask |
| 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 | 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 | */ |
| @@ -57965,11 +58044,11 @@ | |
| 58044 | ** but could happen. In this case abandon processing and return the error. |
| 58045 | */ |
| 58046 | for(i=0; rc==SQLITE_OK && i<db->nDb; i++){ |
| 58047 | Btree *pBt = db->aDb[i].pBt; |
| 58048 | if( pBt ){ |
| 58049 | rc = sqlite3BtreeCommitPhaseTwo(pBt, 0); |
| 58050 | } |
| 58051 | } |
| 58052 | if( rc==SQLITE_OK ){ |
| 58053 | sqlite3VtabCommit(db); |
| 58054 | } |
| @@ -58097,11 +58176,11 @@ | |
| 58176 | disable_simulated_io_errors(); |
| 58177 | sqlite3BeginBenignMalloc(); |
| 58178 | for(i=0; i<db->nDb; i++){ |
| 58179 | Btree *pBt = db->aDb[i].pBt; |
| 58180 | if( pBt ){ |
| 58181 | sqlite3BtreeCommitPhaseTwo(pBt, 1); |
| 58182 | } |
| 58183 | } |
| 58184 | sqlite3EndBenignMalloc(); |
| 58185 | enable_simulated_io_errors(); |
| 58186 | |
| @@ -58220,37 +58299,10 @@ | |
| 58299 | } |
| 58300 | } |
| 58301 | return rc; |
| 58302 | } |
| 58303 | |
| 58304 | /* |
| 58305 | ** This function is called when a transaction opened by the database |
| 58306 | ** handle associated with the VM passed as an argument is about to be |
| 58307 | ** committed. If there are outstanding deferred foreign key constraint |
| 58308 | ** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK. |
| @@ -58319,11 +58371,11 @@ | |
| 58371 | int mrc; /* Primary error code from p->rc */ |
| 58372 | int eStatementOp = 0; |
| 58373 | int isSpecialError; /* Set to true if a 'special' error */ |
| 58374 | |
| 58375 | /* Lock all btrees used by the statement */ |
| 58376 | sqlite3VdbeEnter(p); |
| 58377 | |
| 58378 | /* Check for one of the special errors */ |
| 58379 | mrc = p->rc & 0xff; |
| 58380 | assert( p->rc!=SQLITE_IOERR_BLOCKED ); /* This error no longer exists */ |
| 58381 | isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| @@ -58373,11 +58425,11 @@ | |
| 58425 | ){ |
| 58426 | if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ |
| 58427 | rc = sqlite3VdbeCheckFk(p, 1); |
| 58428 | if( rc!=SQLITE_OK ){ |
| 58429 | if( NEVER(p->readOnly) ){ |
| 58430 | sqlite3VdbeLeave(p); |
| 58431 | return SQLITE_ERROR; |
| 58432 | } |
| 58433 | rc = SQLITE_CONSTRAINT; |
| 58434 | }else{ |
| 58435 | /* The auto-commit flag is true, the vdbe program was successful |
| @@ -58385,11 +58437,11 @@ | |
| 58437 | ** key constraints to hold up the transaction. This means a commit |
| 58438 | ** is required. */ |
| 58439 | rc = vdbeCommit(db, p); |
| 58440 | } |
| 58441 | if( rc==SQLITE_BUSY && p->readOnly ){ |
| 58442 | sqlite3VdbeLeave(p); |
| 58443 | return SQLITE_BUSY; |
| 58444 | }else if( rc!=SQLITE_OK ){ |
| 58445 | p->rc = rc; |
| 58446 | sqlite3RollbackAll(db); |
| 58447 | }else{ |
| @@ -58457,11 +58509,12 @@ | |
| 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 ){ |
| 58520 | db->activeVdbeCnt--; |
| @@ -61978,11 +62031,11 @@ | |
| 62031 | } u; |
| 62032 | /* End automatically generated code |
| 62033 | ********************************************************************/ |
| 62034 | |
| 62035 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 62036 | sqlite3VdbeEnter(p); |
| 62037 | if( p->rc==SQLITE_NOMEM ){ |
| 62038 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| 62039 | ** sqlite3_column_text16() failed. */ |
| 62040 | goto no_mem; |
| 62041 | } |
| @@ -62815,19 +62868,31 @@ | |
| 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 | */ |
| 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 ){ |
| @@ -64091,10 +64156,11 @@ | |
| 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 |
| @@ -64234,11 +64300,11 @@ | |
| 64300 | #if 0 /* local variables moved into u.as */ |
| 64301 | Btree *pBt; |
| 64302 | #endif /* local variables moved into u.as */ |
| 64303 | |
| 64304 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 64305 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 64306 | u.as.pBt = db->aDb[pOp->p1].pBt; |
| 64307 | |
| 64308 | if( u.as.pBt ){ |
| 64309 | rc = sqlite3BtreeBeginTrans(u.as.pBt, pOp->p2); |
| 64310 | if( rc==SQLITE_BUSY ){ |
| @@ -64292,11 +64358,11 @@ | |
| 64358 | u.at.iDb = pOp->p1; |
| 64359 | u.at.iCookie = pOp->p3; |
| 64360 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 64361 | assert( u.at.iDb>=0 && u.at.iDb<db->nDb ); |
| 64362 | assert( db->aDb[u.at.iDb].pBt!=0 ); |
| 64363 | assert( (p->btreeMask & (((yDbMask)1)<<u.at.iDb))!=0 ); |
| 64364 | |
| 64365 | sqlite3BtreeGetMeta(db->aDb[u.at.iDb].pBt, u.at.iCookie, (u32 *)&u.at.iMeta); |
| 64366 | pOut->u.i = u.at.iMeta; |
| 64367 | break; |
| 64368 | } |
| @@ -64315,11 +64381,11 @@ | |
| 64381 | #if 0 /* local variables moved into u.au */ |
| 64382 | Db *pDb; |
| 64383 | #endif /* local variables moved into u.au */ |
| 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 */ |
| @@ -64365,11 +64431,11 @@ | |
| 64431 | int iGen; |
| 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{ |
| @@ -64391,10 +64457,11 @@ | |
| 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 | } |
| @@ -64471,11 +64538,11 @@ | |
| 64538 | u.aw.nField = 0; |
| 64539 | u.aw.pKeyInfo = 0; |
| 64540 | u.aw.p2 = pOp->p2; |
| 64541 | u.aw.iDb = pOp->p3; |
| 64542 | assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb ); |
| 64543 | assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 ); |
| 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; |
| @@ -66008,11 +66075,11 @@ | |
| 66075 | rc = SQLITE_LOCKED; |
| 66076 | p->errorAction = OE_Abort; |
| 66077 | }else{ |
| 66078 | u.br.iDb = pOp->p3; |
| 66079 | assert( u.br.iCnt==1 ); |
| 66080 | assert( (p->btreeMask & (((yDbMask)1)<<u.br.iDb))!=0 ); |
| 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 ){ |
| @@ -66046,11 +66113,11 @@ | |
| 66113 | #if 0 /* local variables moved into u.bs */ |
| 66114 | int nChange; |
| 66115 | #endif /* local variables moved into u.bs */ |
| 66116 | |
| 66117 | u.bs.nChange = 0; |
| 66118 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); |
| 66119 | rc = sqlite3BtreeClearTable( |
| 66120 | db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bs.nChange : 0) |
| 66121 | ); |
| 66122 | if( pOp->p3 ){ |
| 66123 | p->nChange += u.bs.nChange; |
| @@ -66093,11 +66160,11 @@ | |
| 66160 | Db *pDb; |
| 66161 | #endif /* local variables moved into u.bt */ |
| 66162 | |
| 66163 | u.bt.pgno = 0; |
| 66164 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 66165 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 66166 | u.bt.pDb = &db->aDb[pOp->p1]; |
| 66167 | assert( u.bt.pDb->pBt!=0 ); |
| 66168 | if( pOp->opcode==OP_CreateTable ){ |
| 66169 | /* u.bt.flags = BTREE_INTKEY; */ |
| 66170 | u.bt.flags = BTREE_INTKEY; |
| @@ -66122,31 +66189,27 @@ | |
| 66189 | int iDb; |
| 66190 | const char *zMaster; |
| 66191 | char *zSql; |
| 66192 | InitData initData; |
| 66193 | #endif /* local variables moved into u.bu */ |
| 66194 | |
| 66195 | /* Any prepared statement that invokes this opcode will hold mutexes |
| 66196 | ** on every btree. This is a prerequisite for invoking |
| 66197 | ** sqlite3InitCallback(). |
| 66198 | */ |
| 66199 | #ifdef SQLITE_DEBUG |
| 66200 | for(u.bu.iDb=0; u.bu.iDb<db->nDb; u.bu.iDb++){ |
| 66201 | assert( u.bu.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bu.iDb].pBt) ); |
| 66202 | } |
| 66203 | #endif |
| 66204 | assert( p->btreeMask == ~(yDbMask)0 ); |
| 66205 | |
| 66206 | |
| 66207 | u.bu.iDb = pOp->p1; |
| 66208 | assert( u.bu.iDb>=0 && u.bu.iDb<db->nDb ); |
| 66209 | assert( DbHasProperty(db, u.bu.iDb, DB_SchemaLoaded) ); |
| 66210 | /* Used to be a conditional */ { |
| 66211 | u.bu.zMaster = SCHEMA_TABLE(u.bu.iDb); |
| 66212 | u.bu.initData.db = db; |
| 66213 | u.bu.initData.iDb = pOp->p1; |
| 66214 | u.bu.initData.pzErrMsg = &p->zErrMsg; |
| 66215 | u.bu.zSql = sqlite3MPrintf(db, |
| @@ -66163,11 +66226,10 @@ | |
| 66226 | if( rc==SQLITE_OK ) rc = u.bu.initData.rc; |
| 66227 | sqlite3DbFree(db, u.bu.zSql); |
| 66228 | db->init.busy = 0; |
| 66229 | } |
| 66230 | } |
| 66231 | if( rc==SQLITE_NOMEM ){ |
| 66232 | goto no_mem; |
| 66233 | } |
| 66234 | break; |
| 66235 | } |
| @@ -66266,11 +66328,11 @@ | |
| 66328 | for(u.bv.j=0; u.bv.j<u.bv.nRoot; u.bv.j++){ |
| 66329 | u.bv.aRoot[u.bv.j] = (int)sqlite3VdbeIntValue(&pIn1[u.bv.j]); |
| 66330 | } |
| 66331 | u.bv.aRoot[u.bv.j] = 0; |
| 66332 | assert( pOp->p5<db->nDb ); |
| 66333 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 ); |
| 66334 | u.bv.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.bv.aRoot, u.bv.nRoot, |
| 66335 | (int)u.bv.pnErr->u.i, &u.bv.nErr); |
| 66336 | sqlite3DbFree(db, u.bv.aRoot); |
| 66337 | u.bv.pnErr->u.i -= u.bv.nErr; |
| 66338 | sqlite3VdbeMemSetNull(pIn1); |
| @@ -66702,15 +66764,29 @@ | |
| 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 | |
| 66791 | /* Opcode: AggFinal P1 P2 * P4 * |
| 66792 | ** |
| @@ -66730,12 +66806,15 @@ | |
| 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; |
| @@ -66812,25 +66891,24 @@ | |
| 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); |
| @@ -66928,11 +67006,11 @@ | |
| 67006 | #if 0 /* local variables moved into u.cf */ |
| 67007 | Btree *pBt; |
| 67008 | #endif /* local variables moved into u.cf */ |
| 67009 | |
| 67010 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 67011 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 67012 | u.cf.pBt = db->aDb[pOp->p1].pBt; |
| 67013 | rc = sqlite3BtreeIncrVacuum(u.cf.pBt); |
| 67014 | if( rc==SQLITE_DONE ){ |
| 67015 | pc = pOp->p2 - 1; |
| 67016 | rc = SQLITE_OK; |
| @@ -66977,11 +67055,11 @@ | |
| 67055 | case OP_TableLock: { |
| 67056 | u8 isWriteLock = (u8)pOp->p3; |
| 67057 | if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){ |
| 67058 | int p1 = pOp->p1; |
| 67059 | assert( p1>=0 && p1<db->nDb ); |
| 67060 | assert( (p->btreeMask & (((yDbMask)1)<<p1))!=0 ); |
| 67061 | assert( isWriteLock==0 || isWriteLock==1 ); |
| 67062 | rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock); |
| 67063 | if( (rc&0xFF)==SQLITE_LOCKED ){ |
| 67064 | const char *z = pOp->p4.z; |
| 67065 | sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z); |
| @@ -67482,17 +67560,20 @@ | |
| 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. */ |
| 67573 | vdbe_return: |
| 67574 | sqlite3VdbeLeave(p); |
| 67575 | return rc; |
| 67576 | |
| 67577 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 67578 | ** is encountered. |
| 67579 | */ |
| @@ -73966,10 +74047,26 @@ | |
| 74047 | if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){ |
| 74048 | sqlite3VdbeAddOp4(v, OP_ParseSchema, 1, 0, 0, zWhere, P4_DYNAMIC); |
| 74049 | } |
| 74050 | #endif |
| 74051 | } |
| 74052 | |
| 74053 | /* |
| 74054 | ** Parameter zName is the name of a table that is about to be altered |
| 74055 | ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN). |
| 74056 | ** If the table is a system table, this function leaves an error message |
| 74057 | ** in pParse->zErr (system tables may not be altered) and returns non-zero. |
| 74058 | ** |
| 74059 | ** Or, if zName is not a system table, zero is returned. |
| 74060 | */ |
| 74061 | static int isSystemTable(Parse *pParse, const char *zName){ |
| 74062 | if( sqlite3Strlen30(zName)>6 && 0==sqlite3StrNICmp(zName, "sqlite_", 7) ){ |
| 74063 | sqlite3ErrorMsg(pParse, "table %s may not be altered", zName); |
| 74064 | return 1; |
| 74065 | } |
| 74066 | return 0; |
| 74067 | } |
| 74068 | |
| 74069 | /* |
| 74070 | ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" |
| 74071 | ** command. |
| 74072 | */ |
| @@ -74017,18 +74114,15 @@ | |
| 74114 | } |
| 74115 | |
| 74116 | /* Make sure it is not a system table being altered, or a reserved name |
| 74117 | ** that the table is being renamed to. |
| 74118 | */ |
| 74119 | if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){ |
| 74120 | goto exit_rename_table; |
| 74121 | } |
| 74122 | if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){ goto |
| 74123 | exit_rename_table; |
| 74124 | } |
| 74125 | |
| 74126 | #ifndef SQLITE_OMIT_VIEW |
| 74127 | if( pTab->pSelect ){ |
| 74128 | sqlite3ErrorMsg(pParse, "view %s may not be altered", pTab->zName); |
| @@ -74356,10 +74450,13 @@ | |
| 74450 | /* Make sure this is not an attempt to ALTER a view. */ |
| 74451 | if( pTab->pSelect ){ |
| 74452 | sqlite3ErrorMsg(pParse, "Cannot add a column to a view"); |
| 74453 | goto exit_begin_add_column; |
| 74454 | } |
| 74455 | if( SQLITE_OK!=isSystemTable(pParse, pTab->zName) ){ |
| 74456 | goto exit_begin_add_column; |
| 74457 | } |
| 74458 | |
| 74459 | assert( pTab->addColOffset>0 ); |
| 74460 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 74461 | |
| 74462 | /* Put a copy of the Table struct in Parse.pNewTable for the |
| @@ -74443,11 +74540,12 @@ | |
| 74540 | */ |
| 74541 | static void openStatTable( |
| 74542 | Parse *pParse, /* Parsing context */ |
| 74543 | int iDb, /* The database we are looking in */ |
| 74544 | int iStatCur, /* Open the sqlite_stat1 table on this cursor */ |
| 74545 | const char *zWhere, /* Delete entries for this table or index */ |
| 74546 | const char *zWhereType /* Either "tbl" or "idx" */ |
| 74547 | ){ |
| 74548 | static const struct { |
| 74549 | const char *zName; |
| 74550 | const char *zCols; |
| 74551 | } aTable[] = { |
| @@ -74488,11 +74586,11 @@ | |
| 74586 | ** entire contents of the table. */ |
| 74587 | aRoot[i] = pStat->tnum; |
| 74588 | sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab); |
| 74589 | if( zWhere ){ |
| 74590 | sqlite3NestedParse(pParse, |
| 74591 | "DELETE FROM %Q.%s WHERE %s=%Q", pDb->zName, zTab, zWhereType, zWhere |
| 74592 | ); |
| 74593 | }else{ |
| 74594 | /* The sqlite_stat[12] table already exists. Delete all rows. */ |
| 74595 | sqlite3VdbeAddOp2(v, OP_Clear, aRoot[i], iDb); |
| 74596 | } |
| @@ -74512,10 +74610,11 @@ | |
| 74610 | ** a single table. |
| 74611 | */ |
| 74612 | static void analyzeOneTable( |
| 74613 | Parse *pParse, /* Parser context */ |
| 74614 | Table *pTab, /* Table whose indices are to be analyzed */ |
| 74615 | Index *pOnlyIdx, /* If not NULL, only analyze this one index */ |
| 74616 | int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */ |
| 74617 | int iMem /* Available memory locations begin here */ |
| 74618 | ){ |
| 74619 | sqlite3 *db = pParse->db; /* Database handle */ |
| 74620 | Index *pIdx; /* An index to being analyzed */ |
| @@ -74522,12 +74621,11 @@ | |
| 74621 | int iIdxCur; /* Cursor open on index being analyzed */ |
| 74622 | Vdbe *v; /* The virtual machine being built up */ |
| 74623 | int i; /* Loop counter */ |
| 74624 | int topOfLoop; /* The top of the loop */ |
| 74625 | int endOfLoop; /* The end of the loop */ |
| 74626 | int jZeroRows = -1; /* Jump from here if number of rows is zero */ |
| 74627 | int iDb; /* Index of database containing pTab */ |
| 74628 | int regTabname = iMem++; /* Register containing table name */ |
| 74629 | int regIdxname = iMem++; /* Register containing index name */ |
| 74630 | int regSampleno = iMem++; /* Register containing next sample number */ |
| 74631 | int regCol = iMem++; /* Content of a column analyzed table */ |
| @@ -74534,10 +74632,11 @@ | |
| 74632 | int regRec = iMem++; /* Register holding completed record */ |
| 74633 | int regTemp = iMem++; /* Temporary use register */ |
| 74634 | int regRowid = iMem++; /* Rowid for the inserted record */ |
| 74635 | |
| 74636 | #ifdef SQLITE_ENABLE_STAT2 |
| 74637 | int addr = 0; /* Instruction address */ |
| 74638 | int regTemp2 = iMem++; /* Temporary use register */ |
| 74639 | int regSamplerecno = iMem++; /* Index of next sample to record */ |
| 74640 | int regRecno = iMem++; /* Current sample index */ |
| 74641 | int regLast = iMem++; /* Index of last sample to record */ |
| 74642 | int regFirst = iMem++; /* Index of first sample to record */ |
| @@ -74569,13 +74668,16 @@ | |
| 74668 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 74669 | |
| 74670 | iIdxCur = pParse->nTab++; |
| 74671 | sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0); |
| 74672 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 74673 | int nCol; |
| 74674 | KeyInfo *pKey; |
| 74675 | |
| 74676 | if( pOnlyIdx && pOnlyIdx!=pIdx ) continue; |
| 74677 | nCol = pIdx->nColumn; |
| 74678 | pKey = sqlite3IndexKeyinfo(pParse, pIdx); |
| 74679 | if( iMem+1+(nCol*2)>pParse->nMem ){ |
| 74680 | pParse->nMem = iMem+1+(nCol*2); |
| 74681 | } |
| 74682 | |
| 74683 | /* Open a cursor to the index to be analyzed. */ |
| @@ -74728,11 +74830,11 @@ | |
| 74830 | ** If K==0 then no entry is made into the sqlite_stat1 table. |
| 74831 | ** If K>0 then it is always the case the D>0 so division by zero |
| 74832 | ** is never possible. |
| 74833 | */ |
| 74834 | sqlite3VdbeAddOp2(v, OP_SCopy, iMem, regSampleno); |
| 74835 | if( jZeroRows<0 ){ |
| 74836 | jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, iMem); |
| 74837 | } |
| 74838 | for(i=0; i<nCol; i++){ |
| 74839 | sqlite3VdbeAddOp4(v, OP_String8, 0, regTemp, 0, " ", 0); |
| 74840 | sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regSampleno, regSampleno); |
| @@ -74754,24 +74856,22 @@ | |
| 74856 | if( pTab->pIndex==0 ){ |
| 74857 | sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pTab->tnum, iDb); |
| 74858 | VdbeComment((v, "%s", pTab->zName)); |
| 74859 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regSampleno); |
| 74860 | sqlite3VdbeAddOp1(v, OP_Close, iIdxCur); |
| 74861 | jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regSampleno); |
| 74862 | }else{ |
| 74863 | sqlite3VdbeJumpHere(v, jZeroRows); |
| 74864 | jZeroRows = sqlite3VdbeAddOp0(v, OP_Goto); |
| 74865 | } |
| 74866 | sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname); |
| 74867 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0); |
| 74868 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid); |
| 74869 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid); |
| 74870 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 74871 | if( pParse->nMem<regRec ) pParse->nMem = regRec; |
| 74872 | sqlite3VdbeJumpHere(v, jZeroRows); |
| 74873 | } |
| 74874 | |
| 74875 | /* |
| 74876 | ** Generate code that will cause the most recent index analysis to |
| 74877 | ** be loaded into internal hash tables where is can be used. |
| @@ -74794,35 +74894,40 @@ | |
| 74894 | int iMem; |
| 74895 | |
| 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); |
| 74906 | } |
| 74907 | |
| 74908 | /* |
| 74909 | ** Generate code that will do an analysis of a single table in |
| 74910 | ** a database. If pOnlyIdx is not NULL then it is a single index |
| 74911 | ** in pTab that should be analyzed. |
| 74912 | */ |
| 74913 | static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){ |
| 74914 | int iDb; |
| 74915 | int iStatCur; |
| 74916 | |
| 74917 | assert( pTab!=0 ); |
| 74918 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| 74919 | iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema); |
| 74920 | sqlite3BeginWriteOperation(pParse, 0, iDb); |
| 74921 | iStatCur = pParse->nTab; |
| 74922 | pParse->nTab += 2; |
| 74923 | if( pOnlyIdx ){ |
| 74924 | openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx"); |
| 74925 | }else{ |
| 74926 | openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl"); |
| 74927 | } |
| 74928 | analyzeOneTable(pParse, pTab, pOnlyIdx, iStatCur, pParse->nMem+1); |
| 74929 | loadAnalysis(pParse, iDb); |
| 74930 | } |
| 74931 | |
| 74932 | /* |
| 74933 | ** Generate code for the ANALYZE command. The parser calls this routine |
| @@ -74840,10 +74945,11 @@ | |
| 74945 | sqlite3 *db = pParse->db; |
| 74946 | int iDb; |
| 74947 | int i; |
| 74948 | char *z, *zDb; |
| 74949 | Table *pTab; |
| 74950 | Index *pIdx; |
| 74951 | Token *pTableName; |
| 74952 | |
| 74953 | /* Read the database schema. If an error occurs, leave an error message |
| 74954 | ** and code in pParse and return NULL. */ |
| 74955 | assert( sqlite3BtreeHoldsAllMutexes(pParse->db) ); |
| @@ -74864,29 +74970,31 @@ | |
| 74970 | if( iDb>=0 ){ |
| 74971 | analyzeDatabase(pParse, iDb); |
| 74972 | }else{ |
| 74973 | z = sqlite3NameFromToken(db, pName1); |
| 74974 | if( z ){ |
| 74975 | if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){ |
| 74976 | analyzeTable(pParse, pIdx->pTable, pIdx); |
| 74977 | }else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){ |
| 74978 | analyzeTable(pParse, pTab, 0); |
| 74979 | } |
| 74980 | sqlite3DbFree(db, z); |
| 74981 | } |
| 74982 | } |
| 74983 | }else{ |
| 74984 | /* Form 3: Analyze the fully qualified table name */ |
| 74985 | iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName); |
| 74986 | if( iDb>=0 ){ |
| 74987 | zDb = db->aDb[iDb].zName; |
| 74988 | z = sqlite3NameFromToken(db, pTableName); |
| 74989 | if( z ){ |
| 74990 | if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){ |
| 74991 | analyzeTable(pParse, pIdx->pTable, pIdx); |
| 74992 | }else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){ |
| 74993 | analyzeTable(pParse, pTab, 0); |
| 74994 | } |
| 74995 | sqlite3DbFree(db, z); |
| 74996 | } |
| 74997 | } |
| 74998 | } |
| 74999 | } |
| 75000 | |
| @@ -76055,11 +76163,11 @@ | |
| 76163 | ** set for each database that is used. Generate code to start a |
| 76164 | ** transaction on each used database and to verify the schema cookie |
| 76165 | ** on each used database. |
| 76166 | */ |
| 76167 | if( pParse->cookieGoto>0 ){ |
| 76168 | yDbMask mask; |
| 76169 | int iDb; |
| 76170 | sqlite3VdbeJumpHere(v, pParse->cookieGoto-1); |
| 76171 | for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){ |
| 76172 | if( (mask & pParse->cookieMask)==0 ) continue; |
| 76173 | sqlite3VdbeUsesBtree(v, iDb); |
| @@ -79351,16 +79459,16 @@ | |
| 79459 | if( v==0 ) return; /* This only happens if there was a prior error */ |
| 79460 | pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1; |
| 79461 | } |
| 79462 | if( iDb>=0 ){ |
| 79463 | sqlite3 *db = pToplevel->db; |
| 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 ){ |
| 79474 | sqlite3OpenTempDatabase(pToplevel); |
| @@ -79383,11 +79491,11 @@ | |
| 79491 | ** necessary to undo a write and the checkpoint should not be set. |
| 79492 | */ |
| 79493 | SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){ |
| 79494 | Parse *pToplevel = sqlite3ParseToplevel(pParse); |
| 79495 | sqlite3CodeVerifySchema(pParse, iDb); |
| 79496 | pToplevel->writeMask |= ((yDbMask)1)<<iDb; |
| 79497 | pToplevel->isMultiWrite |= setStatement; |
| 79498 | } |
| 79499 | |
| 79500 | /* |
| 79501 | ** Indicate that the statement currently under construction might write |
| @@ -99567,11 +99675,11 @@ | |
| 99675 | ** VALUE and how common that value is according to the histogram. |
| 99676 | */ |
| 99677 | if( nRow>(double)1 && nEq==1 && pFirstTerm!=0 ){ |
| 99678 | if( pFirstTerm->eOperator & (WO_EQ|WO_ISNULL) ){ |
| 99679 | testcase( pFirstTerm->eOperator==WO_EQ ); |
| 99680 | testcase( pFirstTerm->eOperator==WO_ISNULL ); |
| 99681 | whereEqualScanEst(pParse, pProbe, pFirstTerm->pExpr->pRight, &nRow); |
| 99682 | }else if( pFirstTerm->eOperator==WO_IN && bInEst==0 ){ |
| 99683 | whereInScanEst(pParse, pProbe, pFirstTerm->pExpr->x.pList, &nRow); |
| 99684 | } |
| 99685 | } |
| 99686 |
+7
-3
| --- 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-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8" | |
| 112 | +#define SQLITE_SOURCE_ID "2011-04-04 03:27:16 f8e98ab3062a6e56924a86e8f3204c30d0f3d906" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -2978,11 +2978,13 @@ | ||
| 2978 | 2978 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
| 2979 | 2979 | ** that implements the [SELECT] statement. ^The second parameter is the |
| 2980 | 2980 | ** column number. ^The leftmost column is number 0. |
| 2981 | 2981 | ** |
| 2982 | 2982 | ** ^The returned string pointer is valid until either the [prepared statement] |
| 2983 | -** is destroyed by [sqlite3_finalize()] or until the next call to | |
| 2983 | +** is destroyed by [sqlite3_finalize()] or until the statement is automatically | |
| 2984 | +** reprepared by the first call to [sqlite3_step()] for a particular run | |
| 2985 | +** or until the next call to | |
| 2984 | 2986 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
| 2985 | 2987 | ** |
| 2986 | 2988 | ** ^If sqlite3_malloc() fails during the processing of either routine |
| 2987 | 2989 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
| 2988 | 2990 | ** NULL pointer is returned. |
| @@ -3004,11 +3006,13 @@ | ||
| 3004 | 3006 | ** ^The name of the database or table or column can be returned as |
| 3005 | 3007 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 3006 | 3008 | ** the database name, the _table_ routines return the table name, and |
| 3007 | 3009 | ** the origin_ routines return the column name. |
| 3008 | 3010 | ** ^The returned string is valid until the [prepared statement] is destroyed |
| 3009 | -** using [sqlite3_finalize()] or until the same information is requested | |
| 3011 | +** using [sqlite3_finalize()] or until the statement is automatically | |
| 3012 | +** reprepared by the first call to [sqlite3_step()] for a particular run | |
| 3013 | +** or until the same information is requested | |
| 3010 | 3014 | ** again in a different encoding. |
| 3011 | 3015 | ** |
| 3012 | 3016 | ** ^The names returned are the original un-aliased names of the |
| 3013 | 3017 | ** database, table, and column. |
| 3014 | 3018 | ** |
| 3015 | 3019 |
| --- 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-03-24 01:34:03 b6e268fce12829f058f1dfa223731ec8479493f8" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -2978,11 +2978,13 @@ | |
| 2978 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
| 2979 | ** that implements the [SELECT] statement. ^The second parameter is the |
| 2980 | ** column number. ^The leftmost column is number 0. |
| 2981 | ** |
| 2982 | ** ^The returned string pointer is valid until either the [prepared statement] |
| 2983 | ** is destroyed by [sqlite3_finalize()] or until the next call to |
| 2984 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
| 2985 | ** |
| 2986 | ** ^If sqlite3_malloc() fails during the processing of either routine |
| 2987 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
| 2988 | ** NULL pointer is returned. |
| @@ -3004,11 +3006,13 @@ | |
| 3004 | ** ^The name of the database or table or column can be returned as |
| 3005 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 3006 | ** the database name, the _table_ routines return the table name, and |
| 3007 | ** the origin_ routines return the column name. |
| 3008 | ** ^The returned string is valid until the [prepared statement] is destroyed |
| 3009 | ** using [sqlite3_finalize()] or until the same information is requested |
| 3010 | ** again in a different encoding. |
| 3011 | ** |
| 3012 | ** ^The names returned are the original un-aliased names of the |
| 3013 | ** database, table, and column. |
| 3014 | ** |
| 3015 |
| --- 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 | ** |
| @@ -2978,11 +2978,13 @@ | |
| 2978 | ** UTF-16 string. ^The first parameter is the [prepared statement] |
| 2979 | ** that implements the [SELECT] statement. ^The second parameter is the |
| 2980 | ** column number. ^The leftmost column is number 0. |
| 2981 | ** |
| 2982 | ** ^The returned string pointer is valid until either the [prepared statement] |
| 2983 | ** is destroyed by [sqlite3_finalize()] or until the statement is automatically |
| 2984 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
| 2985 | ** or until the next call to |
| 2986 | ** sqlite3_column_name() or sqlite3_column_name16() on the same column. |
| 2987 | ** |
| 2988 | ** ^If sqlite3_malloc() fails during the processing of either routine |
| 2989 | ** (for example during a conversion from UTF-8 to UTF-16) then a |
| 2990 | ** NULL pointer is returned. |
| @@ -3004,11 +3006,13 @@ | |
| 3006 | ** ^The name of the database or table or column can be returned as |
| 3007 | ** either a UTF-8 or UTF-16 string. ^The _database_ routines return |
| 3008 | ** the database name, the _table_ routines return the table name, and |
| 3009 | ** the origin_ routines return the column name. |
| 3010 | ** ^The returned string is valid until the [prepared statement] is destroyed |
| 3011 | ** using [sqlite3_finalize()] or until the statement is automatically |
| 3012 | ** reprepared by the first call to [sqlite3_step()] for a particular run |
| 3013 | ** or until the same information is requested |
| 3014 | ** again in a different encoding. |
| 3015 | ** |
| 3016 | ** ^The names returned are the original un-aliased names of the |
| 3017 | ** database, table, and column. |
| 3018 | ** |
| 3019 |