| | @@ -1171,11 +1171,11 @@ |
| 1171 | 1171 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1172 | 1172 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1173 | 1173 | */ |
| 1174 | 1174 | #define SQLITE_VERSION "3.34.0" |
| 1175 | 1175 | #define SQLITE_VERSION_NUMBER 3034000 |
| 1176 | | -#define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492" |
| 1176 | +#define SQLITE_SOURCE_ID "2020-09-15 20:48:30 3d35fa0be866213274fc09250225b345f6b08a9b4ec373d53d95e627e24512be" |
| 1177 | 1177 | |
| 1178 | 1178 | /* |
| 1179 | 1179 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1180 | 1180 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1181 | 1181 | ** |
| | @@ -7245,11 +7245,11 @@ |
| 7245 | 7245 | ** <ol> |
| 7246 | 7246 | ** <li value="0"> SQLITE_TXN_NONE |
| 7247 | 7247 | ** <li value="1"> SQLITE_TXN_READ |
| 7248 | 7248 | ** <li value="2"> SQLITE_TXN_WRITE |
| 7249 | 7249 | ** </ol> |
| 7250 | | -** ^If the S argument to sqlite3_txn_state(D,S) is in the name of |
| 7250 | +** ^If the S argument to sqlite3_txn_state(D,S) is not the name of |
| 7251 | 7251 | ** a valid schema, then -1 is returned. |
| 7252 | 7252 | */ |
| 7253 | 7253 | SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema); |
| 7254 | 7254 | |
| 7255 | 7255 | /* |
| | @@ -8785,10 +8785,11 @@ |
| 8785 | 8785 | */ |
| 8786 | 8786 | #define SQLITE_TESTCTRL_FIRST 5 |
| 8787 | 8787 | #define SQLITE_TESTCTRL_PRNG_SAVE 5 |
| 8788 | 8788 | #define SQLITE_TESTCTRL_PRNG_RESTORE 6 |
| 8789 | 8789 | #define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */ |
| 8790 | +#define SQLITE_TESTCTRL_SEEK_COUNT 7 |
| 8790 | 8791 | #define SQLITE_TESTCTRL_BITVEC_TEST 8 |
| 8791 | 8792 | #define SQLITE_TESTCTRL_FAULT_INSTALL 9 |
| 8792 | 8793 | #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 |
| 8793 | 8794 | #define SQLITE_TESTCTRL_PENDING_BYTE 11 |
| 8794 | 8795 | #define SQLITE_TESTCTRL_ASSERT 12 |
| | @@ -15374,10 +15375,16 @@ |
| 15374 | 15375 | SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); |
| 15375 | 15376 | SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); |
| 15376 | 15377 | SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask); |
| 15377 | 15378 | SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt); |
| 15378 | 15379 | SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void); |
| 15380 | + |
| 15381 | +#ifdef SQLITE_DEBUG |
| 15382 | +SQLITE_PRIVATE sqlite3_uint64 sqlite3BtreeSeekCount(Btree*); |
| 15383 | +#else |
| 15384 | +# define sqlite3BtreeSeekCount(X) 0 |
| 15385 | +#endif |
| 15379 | 15386 | |
| 15380 | 15387 | #ifndef NDEBUG |
| 15381 | 15388 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); |
| 15382 | 15389 | #endif |
| 15383 | 15390 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*); |
| | @@ -15728,11 +15735,11 @@ |
| 15728 | 15735 | #define OP_SequenceTest 113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15729 | 15736 | #define OP_OpenPseudo 114 /* synopsis: P3 columns in r[P2] */ |
| 15730 | 15737 | #define OP_String8 115 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 15731 | 15738 | #define OP_Close 116 |
| 15732 | 15739 | #define OP_ColumnsUsed 117 |
| 15733 | | -#define OP_SeekHit 118 /* synopsis: seekHit=P2 */ |
| 15740 | +#define OP_SeekHit 118 /* synopsis: set P2<=seekHit<=P3 */ |
| 15734 | 15741 | #define OP_Sequence 119 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15735 | 15742 | #define OP_NewRowid 120 /* synopsis: r[P2]=rowid */ |
| 15736 | 15743 | #define OP_Insert 121 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15737 | 15744 | #define OP_Delete 122 |
| 15738 | 15745 | #define OP_ResetCount 123 |
| | @@ -19594,11 +19601,11 @@ |
| 19594 | 19601 | # define sqlite3ColumnPropertiesFromName(T,C) /* no-op */ |
| 19595 | 19602 | #endif |
| 19596 | 19603 | SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*); |
| 19597 | 19604 | SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int); |
| 19598 | 19605 | SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int); |
| 19599 | | -SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); |
| 19606 | +SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*); |
| 19600 | 19607 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*); |
| 19601 | 19608 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 19602 | 19609 | SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*); |
| 19603 | 19610 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 19604 | 19611 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| | @@ -20842,11 +20849,11 @@ |
| 20842 | 20849 | u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */ |
| 20843 | 20850 | #endif |
| 20844 | 20851 | Bool isEphemeral:1; /* True for an ephemeral table */ |
| 20845 | 20852 | Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */ |
| 20846 | 20853 | Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */ |
| 20847 | | - Bool seekHit:1; /* See the OP_SeekHit and OP_IfNoHope opcodes */ |
| 20854 | + u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */ |
| 20848 | 20855 | Btree *pBtx; /* Separate file holding temporary table */ |
| 20849 | 20856 | i64 seqCount; /* Sequence counter */ |
| 20850 | 20857 | u32 *aAltMap; /* Mapping from table to index column numbers */ |
| 20851 | 20858 | |
| 20852 | 20859 | /* Cached OP_Column parse information is only valid if cacheStatus matches |
| | @@ -28614,15 +28621,14 @@ |
| 28614 | 28621 | } |
| 28615 | 28622 | }else{ |
| 28616 | 28623 | v = va_arg(ap,int); |
| 28617 | 28624 | } |
| 28618 | 28625 | if( v<0 ){ |
| 28619 | | - if( v==SMALLEST_INT64 ){ |
| 28620 | | - longvalue = ((u64)1)<<63; |
| 28621 | | - }else{ |
| 28622 | | - longvalue = -v; |
| 28623 | | - } |
| 28626 | + testcase( v==SMALLEST_INT64 ); |
| 28627 | + testcase( v==(-1) ); |
| 28628 | + longvalue = ~v; |
| 28629 | + longvalue++; |
| 28624 | 28630 | prefix = '-'; |
| 28625 | 28631 | }else{ |
| 28626 | 28632 | longvalue = v; |
| 28627 | 28633 | prefix = flag_prefix; |
| 28628 | 28634 | } |
| | @@ -31914,10 +31920,11 @@ |
| 31914 | 31920 | assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 31915 | 31921 | if( enc==SQLITE_UTF8 ){ |
| 31916 | 31922 | incr = 1; |
| 31917 | 31923 | }else{ |
| 31918 | 31924 | incr = 2; |
| 31925 | + length &= ~1; |
| 31919 | 31926 | assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); |
| 31920 | 31927 | for(i=3-enc; i<length && zNum[i]==0; i+=2){} |
| 31921 | 31928 | nonNum = i<length; |
| 31922 | 31929 | zEnd = &zNum[i^1]; |
| 31923 | 31930 | zNum += (enc&1); |
| | @@ -33330,11 +33337,11 @@ |
| 33330 | 33337 | /* 113 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 33331 | 33338 | /* 114 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 33332 | 33339 | /* 115 */ "String8" OpHelp("r[P2]='P4'"), |
| 33333 | 33340 | /* 116 */ "Close" OpHelp(""), |
| 33334 | 33341 | /* 117 */ "ColumnsUsed" OpHelp(""), |
| 33335 | | - /* 118 */ "SeekHit" OpHelp("seekHit=P2"), |
| 33342 | + /* 118 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"), |
| 33336 | 33343 | /* 119 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 33337 | 33344 | /* 120 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 33338 | 33345 | /* 121 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 33339 | 33346 | /* 122 */ "Delete" OpHelp(""), |
| 33340 | 33347 | /* 123 */ "ResetCount" OpHelp(""), |
| | @@ -35140,10 +35147,13 @@ |
| 35140 | 35147 | |
| 35141 | 35148 | *pResOut = reserved; |
| 35142 | 35149 | return rc; |
| 35143 | 35150 | } |
| 35144 | 35151 | |
| 35152 | +/* Forward declaration*/ |
| 35153 | +static int unixSleep(sqlite3_vfs*,int); |
| 35154 | + |
| 35145 | 35155 | /* |
| 35146 | 35156 | ** Set a posix-advisory-lock. |
| 35147 | 35157 | ** |
| 35148 | 35158 | ** There are two versions of this routine. If compiled with |
| 35149 | 35159 | ** SQLITE_ENABLE_SETLK_TIMEOUT then the routine has an extra parameter |
| | @@ -35169,11 +35179,11 @@ |
| 35169 | 35179 | /* On systems that support some kind of blocking file lock with a timeout, |
| 35170 | 35180 | ** make appropriate changes here to invoke that blocking file lock. On |
| 35171 | 35181 | ** generic posix, however, there is no such API. So we simply try the |
| 35172 | 35182 | ** lock once every millisecond until either the timeout expires, or until |
| 35173 | 35183 | ** the lock is obtained. */ |
| 35174 | | - usleep(1000); |
| 35184 | + unixSleep(0,1000); |
| 35175 | 35185 | rc = osFcntl(h,F_SETLK,pLock); |
| 35176 | 35186 | tm--; |
| 35177 | 35187 | } |
| 35178 | 35188 | return rc; |
| 35179 | 35189 | } |
| | @@ -35740,10 +35750,11 @@ |
| 35740 | 35750 | */ |
| 35741 | 35751 | setPendingFd(pFile); |
| 35742 | 35752 | } |
| 35743 | 35753 | sqlite3_mutex_leave(pInode->pLockMutex); |
| 35744 | 35754 | releaseInodeInfo(pFile); |
| 35755 | + assert( pFile->pShm==0 ); |
| 35745 | 35756 | rc = closeUnixFile(id); |
| 35746 | 35757 | unixLeaveMutex(); |
| 35747 | 35758 | return rc; |
| 35748 | 35759 | } |
| 35749 | 35760 | |
| | @@ -37850,10 +37861,11 @@ |
| 37850 | 37861 | u8 isReadonly; /* True if read-only */ |
| 37851 | 37862 | u8 isUnlocked; /* True if no DMS lock held */ |
| 37852 | 37863 | char **apRegion; /* Array of mapped shared-memory regions */ |
| 37853 | 37864 | int nRef; /* Number of unixShm objects pointing to this */ |
| 37854 | 37865 | unixShm *pFirst; /* All unixShm objects pointing to this */ |
| 37866 | + int aLock[SQLITE_SHM_NLOCK]; /* # shared locks on slot, -1==excl lock */ |
| 37855 | 37867 | #ifdef SQLITE_DEBUG |
| 37856 | 37868 | u8 exclMask; /* Mask of exclusive locks held */ |
| 37857 | 37869 | u8 sharedMask; /* Mask of shared locks held */ |
| 37858 | 37870 | u8 nextShmId; /* Next available unixShm.id value */ |
| 37859 | 37871 | #endif |
| | @@ -38390,10 +38402,42 @@ |
| 38390 | 38402 | if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY; |
| 38391 | 38403 | sqlite3_mutex_leave(pShmNode->pShmMutex); |
| 38392 | 38404 | return rc; |
| 38393 | 38405 | } |
| 38394 | 38406 | |
| 38407 | +/* |
| 38408 | +** Check that the pShmNode->aLock[] array comports with the locking bitmasks |
| 38409 | +** held by each client. Return true if it does, or false otherwise. This |
| 38410 | +** is to be used in an assert(). e.g. |
| 38411 | +** |
| 38412 | +** assert( assertLockingArrayOk(pShmNode) ); |
| 38413 | +*/ |
| 38414 | +#ifdef SQLITE_DEBUG |
| 38415 | +static int assertLockingArrayOk(unixShmNode *pShmNode){ |
| 38416 | + unixShm *pX; |
| 38417 | + int aLock[SQLITE_SHM_NLOCK]; |
| 38418 | + assert( sqlite3_mutex_held(pShmNode->pShmMutex) ); |
| 38419 | + |
| 38420 | + memset(aLock, 0, sizeof(aLock)); |
| 38421 | + for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
| 38422 | + int i; |
| 38423 | + for(i=0; i<SQLITE_SHM_NLOCK; i++){ |
| 38424 | + if( pX->exclMask & (1<<i) ){ |
| 38425 | + assert( aLock[i]==0 ); |
| 38426 | + aLock[i] = -1; |
| 38427 | + }else if( pX->sharedMask & (1<<i) ){ |
| 38428 | + assert( aLock[i]>=0 ); |
| 38429 | + aLock[i]++; |
| 38430 | + } |
| 38431 | + } |
| 38432 | + } |
| 38433 | + |
| 38434 | + assert( 0==memcmp(pShmNode->aLock, aLock, sizeof(aLock)) ); |
| 38435 | + return (memcmp(pShmNode->aLock, aLock, sizeof(aLock))==0); |
| 38436 | +} |
| 38437 | +#endif |
| 38438 | + |
| 38395 | 38439 | /* |
| 38396 | 38440 | ** Change the lock state for a shared-memory segment. |
| 38397 | 38441 | ** |
| 38398 | 38442 | ** Note that the relationship between SHAREd and EXCLUSIVE locks is a little |
| 38399 | 38443 | ** different here than in posix. In xShmLock(), one can go from unlocked |
| | @@ -38406,14 +38450,14 @@ |
| 38406 | 38450 | int n, /* Number of locks to acquire or release */ |
| 38407 | 38451 | int flags /* What to do with the lock */ |
| 38408 | 38452 | ){ |
| 38409 | 38453 | unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */ |
| 38410 | 38454 | unixShm *p = pDbFd->pShm; /* The shared memory being locked */ |
| 38411 | | - unixShm *pX; /* For looping over all siblings */ |
| 38412 | 38455 | unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */ |
| 38413 | 38456 | int rc = SQLITE_OK; /* Result code */ |
| 38414 | 38457 | u16 mask; /* Mask of locks to take or release */ |
| 38458 | + int *aLock = pShmNode->aLock; |
| 38415 | 38459 | |
| 38416 | 38460 | assert( pShmNode==pDbFd->pInode->pShmNode ); |
| 38417 | 38461 | assert( pShmNode->pInode==pDbFd->pInode ); |
| 38418 | 38462 | assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); |
| 38419 | 38463 | assert( n>=1 ); |
| | @@ -38448,82 +38492,80 @@ |
| 38448 | 38492 | #endif |
| 38449 | 38493 | |
| 38450 | 38494 | mask = (1<<(ofst+n)) - (1<<ofst); |
| 38451 | 38495 | assert( n>1 || mask==(1<<ofst) ); |
| 38452 | 38496 | sqlite3_mutex_enter(pShmNode->pShmMutex); |
| 38453 | | - if( flags & SQLITE_SHM_UNLOCK ){ |
| 38454 | | - u16 allMask = 0; /* Mask of locks held by siblings */ |
| 38455 | | - |
| 38456 | | - /* See if any siblings hold this same lock */ |
| 38457 | | - for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
| 38458 | | - if( pX==p ) continue; |
| 38459 | | - assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 ); |
| 38460 | | - allMask |= pX->sharedMask; |
| 38461 | | - } |
| 38462 | | - |
| 38463 | | - /* Unlock the system-level locks */ |
| 38464 | | - if( (mask & allMask)==0 ){ |
| 38465 | | - rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n); |
| 38466 | | - }else{ |
| 38467 | | - rc = SQLITE_OK; |
| 38468 | | - } |
| 38469 | | - |
| 38470 | | - /* Undo the local locks */ |
| 38471 | | - if( rc==SQLITE_OK ){ |
| 38472 | | - p->exclMask &= ~mask; |
| 38473 | | - p->sharedMask &= ~mask; |
| 38474 | | - } |
| 38475 | | - }else if( flags & SQLITE_SHM_SHARED ){ |
| 38476 | | - u16 allShared = 0; /* Union of locks held by connections other than "p" */ |
| 38477 | | - |
| 38478 | | - /* Find out which shared locks are already held by sibling connections. |
| 38479 | | - ** If any sibling already holds an exclusive lock, go ahead and return |
| 38480 | | - ** SQLITE_BUSY. |
| 38481 | | - */ |
| 38482 | | - for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
| 38483 | | - if( (pX->exclMask & mask)!=0 ){ |
| 38484 | | - rc = SQLITE_BUSY; |
| 38485 | | - break; |
| 38486 | | - } |
| 38487 | | - allShared |= pX->sharedMask; |
| 38488 | | - } |
| 38489 | | - |
| 38490 | | - /* Get shared locks at the system level, if necessary */ |
| 38491 | | - if( rc==SQLITE_OK ){ |
| 38492 | | - if( (allShared & mask)==0 ){ |
| 38493 | | - rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n); |
| 38494 | | - }else{ |
| 38495 | | - rc = SQLITE_OK; |
| 38496 | | - } |
| 38497 | | - } |
| 38498 | | - |
| 38499 | | - /* Get the local shared locks */ |
| 38500 | | - if( rc==SQLITE_OK ){ |
| 38501 | | - p->sharedMask |= mask; |
| 38502 | | - } |
| 38503 | | - }else{ |
| 38504 | | - /* Make sure no sibling connections hold locks that will block this |
| 38505 | | - ** lock. If any do, return SQLITE_BUSY right away. |
| 38506 | | - */ |
| 38507 | | - for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
| 38508 | | - if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){ |
| 38509 | | - rc = SQLITE_BUSY; |
| 38510 | | - break; |
| 38511 | | - } |
| 38512 | | - } |
| 38513 | | - |
| 38514 | | - /* Get the exclusive locks at the system level. Then if successful |
| 38515 | | - ** also mark the local connection as being locked. |
| 38516 | | - */ |
| 38517 | | - if( rc==SQLITE_OK ){ |
| 38518 | | - rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n); |
| 38519 | | - if( rc==SQLITE_OK ){ |
| 38520 | | - assert( (p->sharedMask & mask)==0 ); |
| 38521 | | - p->exclMask |= mask; |
| 38522 | | - } |
| 38523 | | - } |
| 38524 | | - } |
| 38497 | + assert( assertLockingArrayOk(pShmNode) ); |
| 38498 | + if( flags & SQLITE_SHM_UNLOCK ){ |
| 38499 | + if( (p->exclMask|p->sharedMask) & mask ){ |
| 38500 | + int ii; |
| 38501 | + int bUnlock = 1; |
| 38502 | + |
| 38503 | + for(ii=ofst; ii<ofst+n; ii++){ |
| 38504 | + if( aLock[ii]>((p->sharedMask & (1<<ii)) ? 1 : 0) ){ |
| 38505 | + bUnlock = 0; |
| 38506 | + } |
| 38507 | + } |
| 38508 | + |
| 38509 | + if( bUnlock ){ |
| 38510 | + rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n); |
| 38511 | + if( rc==SQLITE_OK ){ |
| 38512 | + memset(&aLock[ofst], 0, sizeof(int)*n); |
| 38513 | + } |
| 38514 | + }else if( p->sharedMask & (1<<ofst) ){ |
| 38515 | + assert( n==1 && aLock[ofst]>1 ); |
| 38516 | + aLock[ofst]--; |
| 38517 | + } |
| 38518 | + |
| 38519 | + /* Undo the local locks */ |
| 38520 | + if( rc==SQLITE_OK ){ |
| 38521 | + p->exclMask &= ~mask; |
| 38522 | + p->sharedMask &= ~mask; |
| 38523 | + } |
| 38524 | + } |
| 38525 | + }else if( flags & SQLITE_SHM_SHARED ){ |
| 38526 | + assert( n==1 ); |
| 38527 | + assert( (p->exclMask & (1<<ofst))==0 ); |
| 38528 | + if( (p->sharedMask & mask)==0 ){ |
| 38529 | + if( aLock[ofst]<0 ){ |
| 38530 | + rc = SQLITE_BUSY; |
| 38531 | + }else if( aLock[ofst]==0 ){ |
| 38532 | + rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n); |
| 38533 | + } |
| 38534 | + |
| 38535 | + /* Get the local shared locks */ |
| 38536 | + if( rc==SQLITE_OK ){ |
| 38537 | + p->sharedMask |= mask; |
| 38538 | + aLock[ofst]++; |
| 38539 | + } |
| 38540 | + } |
| 38541 | + }else{ |
| 38542 | + /* Make sure no sibling connections hold locks that will block this |
| 38543 | + ** lock. If any do, return SQLITE_BUSY right away. */ |
| 38544 | + int ii; |
| 38545 | + for(ii=ofst; ii<ofst+n; ii++){ |
| 38546 | + assert( (p->sharedMask & mask)==0 ); |
| 38547 | + if( (p->exclMask & (1<<ii))==0 && aLock[ii] ){ |
| 38548 | + rc = SQLITE_BUSY; |
| 38549 | + break; |
| 38550 | + } |
| 38551 | + } |
| 38552 | + |
| 38553 | + /* Get the exclusive locks at the system level. Then if successful |
| 38554 | + ** also update the in-memory values. */ |
| 38555 | + if( rc==SQLITE_OK ){ |
| 38556 | + rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n); |
| 38557 | + if( rc==SQLITE_OK ){ |
| 38558 | + assert( (p->sharedMask & mask)==0 ); |
| 38559 | + p->exclMask |= mask; |
| 38560 | + for(ii=ofst; ii<ofst+n; ii++){ |
| 38561 | + aLock[ii] = -1; |
| 38562 | + } |
| 38563 | + } |
| 38564 | + } |
| 38565 | + } |
| 38566 | + assert( assertLockingArrayOk(pShmNode) ); |
| 38525 | 38567 | sqlite3_mutex_leave(pShmNode->pShmMutex); |
| 38526 | 38568 | OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", |
| 38527 | 38569 | p->id, osGetpid(0), p->sharedMask, p->exclMask)); |
| 38528 | 38570 | return rc; |
| 38529 | 38571 | } |
| | @@ -40139,11 +40181,12 @@ |
| 40139 | 40181 | sp.tv_nsec = (microseconds % 1000000) * 1000; |
| 40140 | 40182 | nanosleep(&sp, NULL); |
| 40141 | 40183 | UNUSED_PARAMETER(NotUsed); |
| 40142 | 40184 | return microseconds; |
| 40143 | 40185 | #elif defined(HAVE_USLEEP) && HAVE_USLEEP |
| 40144 | | - usleep(microseconds); |
| 40186 | + if( microseconds>=1000000 ) sleep(microseconds/1000000); |
| 40187 | + if( microseconds%1000000 ) usleep(microseconds%1000000); |
| 40145 | 40188 | UNUSED_PARAMETER(NotUsed); |
| 40146 | 40189 | return microseconds; |
| 40147 | 40190 | #else |
| 40148 | 40191 | int seconds = (microseconds+999999)/1000000; |
| 40149 | 40192 | sleep(seconds); |
| | @@ -40712,11 +40755,11 @@ |
| 40712 | 40755 | return SQLITE_IOERR_LOCK; |
| 40713 | 40756 | } |
| 40714 | 40757 | |
| 40715 | 40758 | if( nTries==1 ){ |
| 40716 | 40759 | conchModTime = buf.st_mtimespec; |
| 40717 | | - usleep(500000); /* wait 0.5 sec and try the lock again*/ |
| 40760 | + unixSleep(0,500000); /* wait 0.5 sec and try the lock again*/ |
| 40718 | 40761 | continue; |
| 40719 | 40762 | } |
| 40720 | 40763 | |
| 40721 | 40764 | assert( nTries>1 ); |
| 40722 | 40765 | if( conchModTime.tv_sec != buf.st_mtimespec.tv_sec || |
| | @@ -40738,11 +40781,11 @@ |
| 40738 | 40781 | } |
| 40739 | 40782 | }else{ |
| 40740 | 40783 | /* don't break the lock on short read or a version mismatch */ |
| 40741 | 40784 | return SQLITE_BUSY; |
| 40742 | 40785 | } |
| 40743 | | - usleep(10000000); /* wait 10 sec and try the lock again */ |
| 40786 | + unixSleep(0,10000000); /* wait 10 sec and try the lock again */ |
| 40744 | 40787 | continue; |
| 40745 | 40788 | } |
| 40746 | 40789 | |
| 40747 | 40790 | assert( nTries==3 ); |
| 40748 | 40791 | if( 0==proxyBreakConchLock(pFile, myHostID) ){ |
| | @@ -63876,10 +63919,13 @@ |
| 63876 | 63919 | int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */ |
| 63877 | 63920 | int nBackup; /* Number of backup operations reading this btree */ |
| 63878 | 63921 | u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */ |
| 63879 | 63922 | Btree *pNext; /* List of other sharable Btrees from the same db */ |
| 63880 | 63923 | Btree *pPrev; /* Back pointer of the same list */ |
| 63924 | +#ifdef SQLITE_DEBUG |
| 63925 | + u64 nSeek; /* Calls to sqlite3BtreeMovetoUnpacked() */ |
| 63926 | +#endif |
| 63881 | 63927 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 63882 | 63928 | BtLock lock; /* Object used to lock page 1 */ |
| 63883 | 63929 | #endif |
| 63884 | 63930 | }; |
| 63885 | 63931 | |
| | @@ -64656,10 +64702,21 @@ |
| 64656 | 64702 | #define clearAllSharedCacheTableLocks(a) |
| 64657 | 64703 | #define downgradeAllSharedCacheTableLocks(a) |
| 64658 | 64704 | #define hasSharedCacheTableLock(a,b,c,d) 1 |
| 64659 | 64705 | #define hasReadConflicts(a, b) 0 |
| 64660 | 64706 | #endif |
| 64707 | + |
| 64708 | +#ifdef SQLITE_DEBUG |
| 64709 | +/* |
| 64710 | +** Return an reset the seek counter for a Btree object. |
| 64711 | +*/ |
| 64712 | +SQLITE_PRIVATE sqlite3_uint64 sqlite3BtreeSeekCount(Btree *pBt){ |
| 64713 | + u64 n = pBt->nSeek; |
| 64714 | + pBt->nSeek = 0; |
| 64715 | + return n; |
| 64716 | +} |
| 64717 | +#endif |
| 64661 | 64718 | |
| 64662 | 64719 | /* |
| 64663 | 64720 | ** Implementation of the SQLITE_CORRUPT_PAGE() macro. Takes a single |
| 64664 | 64721 | ** (MemPage*) as an argument. The (MemPage*) must not be NULL. |
| 64665 | 64722 | ** |
| | @@ -67150,11 +67207,11 @@ |
| 67150 | 67207 | /* If the B-Tree was successfully opened, set the pager-cache size to the |
| 67151 | 67208 | ** default value. Except, when opening on an existing shared pager-cache, |
| 67152 | 67209 | ** do not change the pager-cache size. |
| 67153 | 67210 | */ |
| 67154 | 67211 | if( sqlite3BtreeSchema(p, 0, 0)==0 ){ |
| 67155 | | - sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE); |
| 67212 | + sqlite3BtreeSetCacheSize(p, SQLITE_DEFAULT_CACHE_SIZE); |
| 67156 | 67213 | } |
| 67157 | 67214 | |
| 67158 | 67215 | pFile = sqlite3PagerFile(pBt->pPager); |
| 67159 | 67216 | if( pFile->pMethods ){ |
| 67160 | 67217 | sqlite3OsFileControlHint(pFile, SQLITE_FCNTL_PDB, (void*)&pBt->db); |
| | @@ -70003,10 +70060,14 @@ |
| 70003 | 70060 | return rc; |
| 70004 | 70061 | } |
| 70005 | 70062 | } |
| 70006 | 70063 | } |
| 70007 | 70064 | } |
| 70065 | + |
| 70066 | +#ifdef SQLITE_DEBUG |
| 70067 | + pCur->pBtree->nSeek++; /* Performance measurement during testing */ |
| 70068 | +#endif |
| 70008 | 70069 | |
| 70009 | 70070 | if( pIdxKey ){ |
| 70010 | 70071 | xRecordCompare = sqlite3VdbeFindCompare(pIdxKey); |
| 70011 | 70072 | pIdxKey->errCode = 0; |
| 70012 | 70073 | assert( pIdxKey->default_rc==1 |
| | @@ -89767,26 +89828,35 @@ |
| 89767 | 89828 | pOp++; /* Skip the OP_IdxLt or OP_IdxGT that follows */ |
| 89768 | 89829 | } |
| 89769 | 89830 | break; |
| 89770 | 89831 | } |
| 89771 | 89832 | |
| 89772 | | -/* Opcode: SeekHit P1 P2 * * * |
| 89773 | | -** Synopsis: seekHit=P2 |
| 89774 | | -** |
| 89775 | | -** Set the seekHit flag on cursor P1 to the value in P2. |
| 89776 | | -** The seekHit flag is used by the IfNoHope opcode. |
| 89777 | | -** |
| 89778 | | -** P1 must be a valid b-tree cursor. P2 must be a boolean value, |
| 89779 | | -** either 0 or 1. |
| 89833 | +/* Opcode: SeekHit P1 P2 P3 * * |
| 89834 | +** Synopsis: set P2<=seekHit<=P3 |
| 89835 | +** |
| 89836 | +** Increase or decrease the seekHit value for cursor P1, if necessary, |
| 89837 | +** so that it is no less than P2 and no greater than P3. |
| 89838 | +** |
| 89839 | +** The seekHit integer represents the maximum of terms in an index for which |
| 89840 | +** there is known to be at least one match. If the seekHit value is smaller |
| 89841 | +** than the total number of equality terms in an index lookup, then the |
| 89842 | +** OP_IfNoHope opcode might run to see if the IN loop can be abandoned |
| 89843 | +** early, thus saving work. This is part of the IN-early-out optimization. |
| 89844 | +** |
| 89845 | +** P1 must be a valid b-tree cursor. |
| 89780 | 89846 | */ |
| 89781 | 89847 | case OP_SeekHit: { |
| 89782 | 89848 | VdbeCursor *pC; |
| 89783 | 89849 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 89784 | 89850 | pC = p->apCsr[pOp->p1]; |
| 89785 | 89851 | assert( pC!=0 ); |
| 89786 | | - assert( pOp->p2==0 || pOp->p2==1 ); |
| 89787 | | - pC->seekHit = pOp->p2 & 1; |
| 89852 | + assert( pOp->p3>=pOp->p2 ); |
| 89853 | + if( pC->seekHit<pOp->p2 ){ |
| 89854 | + pC->seekHit = pOp->p2; |
| 89855 | + }else if( pC->seekHit>pOp->p3 ){ |
| 89856 | + pC->seekHit = pOp->p3; |
| 89857 | + } |
| 89788 | 89858 | break; |
| 89789 | 89859 | } |
| 89790 | 89860 | |
| 89791 | 89861 | /* Opcode: IfNotOpen P1 P2 * * * |
| 89792 | 89862 | ** Synopsis: if( !csr[P1] ) goto P2 |
| | @@ -89840,20 +89910,24 @@ |
| 89840 | 89910 | */ |
| 89841 | 89911 | /* Opcode: IfNoHope P1 P2 P3 P4 * |
| 89842 | 89912 | ** Synopsis: key=r[P3@P4] |
| 89843 | 89913 | ** |
| 89844 | 89914 | ** Register P3 is the first of P4 registers that form an unpacked |
| 89845 | | -** record. |
| 89846 | | -** |
| 89847 | | -** Cursor P1 is on an index btree. If the seekHit flag is set on P1, then |
| 89848 | | -** this opcode is a no-op. But if the seekHit flag of P1 is clear, then |
| 89849 | | -** check to see if there is any entry in P1 that matches the |
| 89850 | | -** prefix identified by P3 and P4. If no entry matches the prefix, |
| 89851 | | -** jump to P2. Otherwise fall through. |
| 89852 | | -** |
| 89853 | | -** This opcode behaves like OP_NotFound if the seekHit |
| 89854 | | -** flag is clear and it behaves like OP_Noop if the seekHit flag is set. |
| 89915 | +** record. Cursor P1 is an index btree. P2 is a jump destination. |
| 89916 | +** In other words, the operands to this opcode are the same as the |
| 89917 | +** operands to OP_NotFound and OP_IdxGT. |
| 89918 | +** |
| 89919 | +** This opcode is an optimization attempt only. If this opcode always |
| 89920 | +** falls through, the correct answer is still obtained, but extra works |
| 89921 | +** is performed. |
| 89922 | +** |
| 89923 | +** A value of N in the seekHit flag of cursor P1 means that there exists |
| 89924 | +** a key P3:N that will match some record in the index. We want to know |
| 89925 | +** if it is possible for a record P3:P4 to match some record in the |
| 89926 | +** index. If it is not possible, we can skips some work. So if seekHit |
| 89927 | +** is less than P4, attempt to find out if a match is possible by running |
| 89928 | +** OP_NotFound. |
| 89855 | 89929 | ** |
| 89856 | 89930 | ** This opcode is used in IN clause processing for a multi-column key. |
| 89857 | 89931 | ** If an IN clause is attached to an element of the key other than the |
| 89858 | 89932 | ** left-most element, and if there are no matches on the most recent |
| 89859 | 89933 | ** seek over the whole key, then it might be that one of the key element |
| | @@ -89891,11 +89965,11 @@ |
| 89891 | 89965 | case OP_IfNoHope: { /* jump, in3 */ |
| 89892 | 89966 | VdbeCursor *pC; |
| 89893 | 89967 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 89894 | 89968 | pC = p->apCsr[pOp->p1]; |
| 89895 | 89969 | assert( pC!=0 ); |
| 89896 | | - if( pC->seekHit ) break; |
| 89970 | + if( pC->seekHit>=pOp->p4.i ) break; |
| 89897 | 89971 | /* Fall through into OP_NotFound */ |
| 89898 | 89972 | /* no break */ deliberate_fall_through |
| 89899 | 89973 | } |
| 89900 | 89974 | case OP_NoConflict: /* jump, in3 */ |
| 89901 | 89975 | case OP_NotFound: /* jump, in3 */ |
| | @@ -89973,10 +90047,11 @@ |
| 89973 | 90047 | VdbeBranchTaken(alreadyExists!=0,2); |
| 89974 | 90048 | if( alreadyExists ) goto jump_to_p2; |
| 89975 | 90049 | }else{ |
| 89976 | 90050 | VdbeBranchTaken(takeJump||alreadyExists==0,2); |
| 89977 | 90051 | if( takeJump || !alreadyExists ) goto jump_to_p2; |
| 90052 | + if( pOp->opcode==OP_IfNoHope ) pC->seekHit = pOp->p4.i; |
| 89978 | 90053 | } |
| 89979 | 90054 | break; |
| 89980 | 90055 | } |
| 89981 | 90056 | |
| 89982 | 90057 | /* Opcode: SeekRowid P1 P2 P3 * * |
| | @@ -91205,11 +91280,11 @@ |
| 91205 | 91280 | if( rc ) goto abort_due_to_error; |
| 91206 | 91281 | } |
| 91207 | 91282 | break; |
| 91208 | 91283 | } |
| 91209 | 91284 | |
| 91210 | | -/* Opcode: IdxGE P1 P2 P3 P4 P5 |
| 91285 | +/* Opcode: IdxGE P1 P2 P3 P4 * |
| 91211 | 91286 | ** Synopsis: key=r[P3@P4] |
| 91212 | 91287 | ** |
| 91213 | 91288 | ** The P4 register values beginning with P3 form an unpacked index |
| 91214 | 91289 | ** key that omits the PRIMARY KEY. Compare this key value against the index |
| 91215 | 91290 | ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID |
| | @@ -91216,11 +91291,11 @@ |
| 91216 | 91291 | ** fields at the end. |
| 91217 | 91292 | ** |
| 91218 | 91293 | ** If the P1 index entry is greater than or equal to the key value |
| 91219 | 91294 | ** then jump to P2. Otherwise fall through to the next instruction. |
| 91220 | 91295 | */ |
| 91221 | | -/* Opcode: IdxGT P1 P2 P3 P4 P5 |
| 91296 | +/* Opcode: IdxGT P1 P2 P3 P4 * |
| 91222 | 91297 | ** Synopsis: key=r[P3@P4] |
| 91223 | 91298 | ** |
| 91224 | 91299 | ** The P4 register values beginning with P3 form an unpacked index |
| 91225 | 91300 | ** key that omits the PRIMARY KEY. Compare this key value against the index |
| 91226 | 91301 | ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID |
| | @@ -91227,11 +91302,11 @@ |
| 91227 | 91302 | ** fields at the end. |
| 91228 | 91303 | ** |
| 91229 | 91304 | ** If the P1 index entry is greater than the key value |
| 91230 | 91305 | ** then jump to P2. Otherwise fall through to the next instruction. |
| 91231 | 91306 | */ |
| 91232 | | -/* Opcode: IdxLT P1 P2 P3 P4 P5 |
| 91307 | +/* Opcode: IdxLT P1 P2 P3 P4 * |
| 91233 | 91308 | ** Synopsis: key=r[P3@P4] |
| 91234 | 91309 | ** |
| 91235 | 91310 | ** The P4 register values beginning with P3 form an unpacked index |
| 91236 | 91311 | ** key that omits the PRIMARY KEY or ROWID. Compare this key value against |
| 91237 | 91312 | ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or |
| | @@ -91238,11 +91313,11 @@ |
| 91238 | 91313 | ** ROWID on the P1 index. |
| 91239 | 91314 | ** |
| 91240 | 91315 | ** If the P1 index entry is less than the key value then jump to P2. |
| 91241 | 91316 | ** Otherwise fall through to the next instruction. |
| 91242 | 91317 | */ |
| 91243 | | -/* Opcode: IdxLE P1 P2 P3 P4 P5 |
| 91318 | +/* Opcode: IdxLE P1 P2 P3 P4 * |
| 91244 | 91319 | ** Synopsis: key=r[P3@P4] |
| 91245 | 91320 | ** |
| 91246 | 91321 | ** The P4 register values beginning with P3 form an unpacked index |
| 91247 | 91322 | ** key that omits the PRIMARY KEY or ROWID. Compare this key value against |
| 91248 | 91323 | ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or |
| | @@ -91264,11 +91339,10 @@ |
| 91264 | 91339 | assert( pC!=0 ); |
| 91265 | 91340 | assert( pC->isOrdered ); |
| 91266 | 91341 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 91267 | 91342 | assert( pC->uc.pCursor!=0); |
| 91268 | 91343 | assert( pC->deferredMoveto==0 ); |
| 91269 | | - assert( pOp->p5==0 || pOp->p5==1 ); |
| 91270 | 91344 | assert( pOp->p4type==P4_INT32 ); |
| 91271 | 91345 | r.pKeyInfo = pC->pKeyInfo; |
| 91272 | 91346 | r.nField = (u16)pOp->p4.i; |
| 91273 | 91347 | if( pOp->opcode<OP_IdxLT ){ |
| 91274 | 91348 | assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT ); |
| | @@ -94911,17 +94985,20 @@ |
| 94911 | 94985 | pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo); |
| 94912 | 94986 | pCsr->uc.pSorter = pSorter; |
| 94913 | 94987 | if( pSorter==0 ){ |
| 94914 | 94988 | rc = SQLITE_NOMEM_BKPT; |
| 94915 | 94989 | }else{ |
| 94990 | + Btree *pBt = db->aDb[0].pBt; |
| 94916 | 94991 | pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz); |
| 94917 | 94992 | memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo); |
| 94918 | 94993 | pKeyInfo->db = 0; |
| 94919 | 94994 | if( nField && nWorker==0 ){ |
| 94920 | 94995 | pKeyInfo->nKeyField = nField; |
| 94921 | 94996 | } |
| 94922 | | - pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt); |
| 94997 | + sqlite3BtreeEnter(pBt); |
| 94998 | + pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(pBt); |
| 94999 | + sqlite3BtreeLeave(pBt); |
| 94923 | 95000 | pSorter->nTask = nWorker + 1; |
| 94924 | 95001 | pSorter->iPrev = (u8)(nWorker - 1); |
| 94925 | 95002 | pSorter->bUseThreads = (pSorter->nTask>1); |
| 94926 | 95003 | pSorter->db = db; |
| 94927 | 95004 | for(i=0; i<pSorter->nTask; i++){ |
| | @@ -112071,12 +112148,14 @@ |
| 112071 | 112148 | |
| 112072 | 112149 | /* |
| 112073 | 112150 | ** Add a new CHECK constraint to the table currently under construction. |
| 112074 | 112151 | */ |
| 112075 | 112152 | SQLITE_PRIVATE void sqlite3AddCheckConstraint( |
| 112076 | | - Parse *pParse, /* Parsing context */ |
| 112077 | | - Expr *pCheckExpr /* The check expression */ |
| 112153 | + Parse *pParse, /* Parsing context */ |
| 112154 | + Expr *pCheckExpr, /* The check expression */ |
| 112155 | + const char *zStart, /* Opening "(" */ |
| 112156 | + const char *zEnd /* Closing ")" */ |
| 112078 | 112157 | ){ |
| 112079 | 112158 | #ifndef SQLITE_OMIT_CHECK |
| 112080 | 112159 | Table *pTab = pParse->pNewTable; |
| 112081 | 112160 | sqlite3 *db = pParse->db; |
| 112082 | 112161 | if( pTab && !IN_DECLARE_VTAB |
| | @@ -112083,10 +112162,17 @@ |
| 112083 | 112162 | && !sqlite3BtreeIsReadonly(db->aDb[db->init.iDb].pBt) |
| 112084 | 112163 | ){ |
| 112085 | 112164 | pTab->pCheck = sqlite3ExprListAppend(pParse, pTab->pCheck, pCheckExpr); |
| 112086 | 112165 | if( pParse->constraintName.n ){ |
| 112087 | 112166 | sqlite3ExprListSetName(pParse, pTab->pCheck, &pParse->constraintName, 1); |
| 112167 | + }else{ |
| 112168 | + Token t; |
| 112169 | + for(zStart++; sqlite3Isspace(zStart[0]); zStart++){} |
| 112170 | + while( sqlite3Isspace(zEnd[-1]) ){ zEnd--; } |
| 112171 | + t.z = zStart; |
| 112172 | + t.n = (int)(zEnd - t.z); |
| 112173 | + sqlite3ExprListSetName(pParse, pTab->pCheck, &t, 1); |
| 112088 | 112174 | } |
| 112089 | 112175 | }else |
| 112090 | 112176 | #endif |
| 112091 | 112177 | { |
| 112092 | 112178 | sqlite3ExprDelete(pParse->db, pCheckExpr); |
| | @@ -112336,16 +112422,19 @@ |
| 112336 | 112422 | static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){ |
| 112337 | 112423 | char *zExtra; |
| 112338 | 112424 | int nByte; |
| 112339 | 112425 | if( pIdx->nColumn>=N ) return SQLITE_OK; |
| 112340 | 112426 | assert( pIdx->isResized==0 ); |
| 112341 | | - nByte = (sizeof(char*) + sizeof(i16) + 1)*N; |
| 112427 | + nByte = (sizeof(char*) + sizeof(LogEst) + sizeof(i16) + 1)*N; |
| 112342 | 112428 | zExtra = sqlite3DbMallocZero(db, nByte); |
| 112343 | 112429 | if( zExtra==0 ) return SQLITE_NOMEM_BKPT; |
| 112344 | 112430 | memcpy(zExtra, pIdx->azColl, sizeof(char*)*pIdx->nColumn); |
| 112345 | 112431 | pIdx->azColl = (const char**)zExtra; |
| 112346 | 112432 | zExtra += sizeof(char*)*N; |
| 112433 | + memcpy(zExtra, pIdx->aiRowLogEst, sizeof(LogEst)*(pIdx->nKeyCol+1)); |
| 112434 | + pIdx->aiRowLogEst = (LogEst*)zExtra; |
| 112435 | + zExtra += sizeof(LogEst)*N; |
| 112347 | 112436 | memcpy(zExtra, pIdx->aiColumn, sizeof(i16)*pIdx->nColumn); |
| 112348 | 112437 | pIdx->aiColumn = (i16*)zExtra; |
| 112349 | 112438 | zExtra += sizeof(i16)*N; |
| 112350 | 112439 | memcpy(zExtra, pIdx->aSortOrder, pIdx->nColumn); |
| 112351 | 112440 | pIdx->aSortOrder = (u8*)zExtra; |
| | @@ -122299,11 +122388,11 @@ |
| 122299 | 122388 | sqlite3ExprDelete(db, pCopy); |
| 122300 | 122389 | if( onError==OE_Ignore ){ |
| 122301 | 122390 | sqlite3VdbeGoto(v, ignoreDest); |
| 122302 | 122391 | }else{ |
| 122303 | 122392 | char *zName = pCheck->a[i].zEName; |
| 122304 | | - if( zName==0 ) zName = pTab->zName; |
| 122393 | + assert( zName!=0 || pParse->db->mallocFailed ); |
| 122305 | 122394 | if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-26383-51744 */ |
| 122306 | 122395 | sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK, |
| 122307 | 122396 | onError, zName, P4_TRANSIENT, |
| 122308 | 122397 | P5_ConstraintCheck); |
| 122309 | 122398 | } |
| | @@ -129148,10 +129237,11 @@ |
| 129148 | 129237 | }while( rc==SQLITE_ERROR_RETRY |
| 129149 | 129238 | || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) ); |
| 129150 | 129239 | sqlite3BtreeLeaveAll(db); |
| 129151 | 129240 | rc = sqlite3ApiExit(db, rc); |
| 129152 | 129241 | assert( (rc&db->errMask)==rc ); |
| 129242 | + db->busyHandler.nBusy = 0; |
| 129153 | 129243 | sqlite3_mutex_leave(db->mutex); |
| 129154 | 129244 | return rc; |
| 129155 | 129245 | } |
| 129156 | 129246 | |
| 129157 | 129247 | |
| | @@ -142156,10 +142246,13 @@ |
| 142156 | 142246 | |
| 142157 | 142247 | pLoop->wsFlags |= WHERE_IN_ABLE; |
| 142158 | 142248 | if( pLevel->u.in.nIn==0 ){ |
| 142159 | 142249 | pLevel->addrNxt = sqlite3VdbeMakeLabel(pParse); |
| 142160 | 142250 | } |
| 142251 | + if( iEq>0 ){ |
| 142252 | + pLoop->wsFlags |= WHERE_IN_EARLYOUT; |
| 142253 | + } |
| 142161 | 142254 | |
| 142162 | 142255 | i = pLevel->u.in.nIn; |
| 142163 | 142256 | pLevel->u.in.nIn += nEq; |
| 142164 | 142257 | pLevel->u.in.aInLoop = |
| 142165 | 142258 | sqlite3DbReallocOrFree(pParse->db, pLevel->u.in.aInLoop, |
| | @@ -142182,20 +142275,22 @@ |
| 142182 | 142275 | pIn->iCur = iTab; |
| 142183 | 142276 | pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next; |
| 142184 | 142277 | if( iEq>0 ){ |
| 142185 | 142278 | pIn->iBase = iReg - i; |
| 142186 | 142279 | pIn->nPrefix = i; |
| 142187 | | - pLoop->wsFlags |= WHERE_IN_EARLYOUT; |
| 142188 | 142280 | }else{ |
| 142189 | 142281 | pIn->nPrefix = 0; |
| 142190 | 142282 | } |
| 142191 | 142283 | }else{ |
| 142192 | 142284 | pIn->eEndLoopOp = OP_Noop; |
| 142193 | 142285 | } |
| 142194 | 142286 | pIn++; |
| 142195 | 142287 | } |
| 142196 | 142288 | } |
| 142289 | + if( iEq>0 ){ |
| 142290 | + sqlite3VdbeAddOp3(v, OP_SeekHit, pLevel->iIdxCur, 0, iEq); |
| 142291 | + } |
| 142197 | 142292 | }else{ |
| 142198 | 142293 | pLevel->u.in.nIn = 0; |
| 142199 | 142294 | } |
| 142200 | 142295 | sqlite3DbFree(pParse->db, aiMap); |
| 142201 | 142296 | #endif |
| | @@ -143375,13 +143470,10 @@ |
| 143375 | 143470 | if( pLoop->nSkip>0 && nConstraint==pLoop->nSkip ){ |
| 143376 | 143471 | /* The skip-scan logic inside the call to codeAllEqualityConstraints() |
| 143377 | 143472 | ** above has already left the cursor sitting on the correct row, |
| 143378 | 143473 | ** so no further seeking is needed */ |
| 143379 | 143474 | }else{ |
| 143380 | | - if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){ |
| 143381 | | - sqlite3VdbeAddOp1(v, OP_SeekHit, iIdxCur); |
| 143382 | | - } |
| 143383 | 143475 | if( regBignull ){ |
| 143384 | 143476 | sqlite3VdbeAddOp2(v, OP_Integer, 1, regBignull); |
| 143385 | 143477 | VdbeComment((v, "NULL-scan pass ctr")); |
| 143386 | 143478 | } |
| 143387 | 143479 | |
| | @@ -143488,11 +143580,11 @@ |
| 143488 | 143580 | testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT ); |
| 143489 | 143581 | testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE ); |
| 143490 | 143582 | } |
| 143491 | 143583 | |
| 143492 | 143584 | if( pLoop->wsFlags & WHERE_IN_EARLYOUT ){ |
| 143493 | | - sqlite3VdbeAddOp2(v, OP_SeekHit, iIdxCur, 1); |
| 143585 | + sqlite3VdbeAddOp3(v, OP_SeekHit, iIdxCur, nEq, nEq); |
| 143494 | 143586 | } |
| 143495 | 143587 | |
| 143496 | 143588 | /* Seek the table cursor, if required */ |
| 143497 | 143589 | omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0 |
| 143498 | 143590 | && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0; |
| | @@ -154289,37 +154381,32 @@ |
| 154289 | 154381 | |
| 154290 | 154382 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 154291 | 154383 | |
| 154292 | 154384 | /************** End of window.c **********************************************/ |
| 154293 | 154385 | /************** Begin file parse.c *******************************************/ |
| 154386 | +/* This file is automatically generated by Lemon from input grammar |
| 154387 | +** source file "parse.y". */ |
| 154294 | 154388 | /* |
| 154295 | | -** 2000-05-29 |
| 154389 | +** 2001-09-15 |
| 154296 | 154390 | ** |
| 154297 | 154391 | ** The author disclaims copyright to this source code. In place of |
| 154298 | 154392 | ** a legal notice, here is a blessing: |
| 154299 | 154393 | ** |
| 154300 | 154394 | ** May you do good and not evil. |
| 154301 | 154395 | ** May you find forgiveness for yourself and forgive others. |
| 154302 | 154396 | ** May you share freely, never taking more than you give. |
| 154303 | 154397 | ** |
| 154304 | 154398 | ************************************************************************* |
| 154305 | | -** Driver template for the LEMON parser generator. |
| 154306 | | -** |
| 154307 | | -** The "lemon" program processes an LALR(1) input grammar file, then uses |
| 154308 | | -** this template to construct a parser. The "lemon" program inserts text |
| 154309 | | -** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the |
| 154310 | | -** interstitial "-" characters) contained in this template is changed into |
| 154311 | | -** the value of the %name directive from the grammar. Otherwise, the content |
| 154312 | | -** of this template is copied straight through into the generate parser |
| 154313 | | -** source file. |
| 154314 | | -** |
| 154315 | | -** The following is the concatenation of all %include directives from the |
| 154316 | | -** input grammar file: |
| 154317 | | -*/ |
| 154318 | | -/* #include <stdio.h> */ |
| 154319 | | -/* #include <assert.h> */ |
| 154320 | | -/************ Begin %include sections from the grammar ************************/ |
| 154399 | +** This file contains SQLite's SQL parser. |
| 154400 | +** |
| 154401 | +** The canonical source code to this file ("parse.y") is a Lemon grammar |
| 154402 | +** file that specifies the input grammar and actions to take while parsing. |
| 154403 | +** That input file is processed by Lemon to generate a C-language |
| 154404 | +** implementation of a parser for the given grammer. You might be reading |
| 154405 | +** this comment as part of the translated C-code. Edits should be made |
| 154406 | +** to the original parse.y sources. |
| 154407 | +*/ |
| 154321 | 154408 | |
| 154322 | 154409 | /* #include "sqliteInt.h" */ |
| 154323 | 154410 | |
| 154324 | 154411 | /* |
| 154325 | 154412 | ** Disable all error recovery processing in the parser push-down |
| | @@ -154499,15 +154586,195 @@ |
| 154499 | 154586 | |
| 154500 | 154587 | #if TK_SPAN>255 |
| 154501 | 154588 | # error too many tokens in the grammar |
| 154502 | 154589 | #endif |
| 154503 | 154590 | /**************** End of %include directives **********************************/ |
| 154504 | | -/* These constants specify the various numeric values for terminal symbols |
| 154505 | | -** in a format understandable to "makeheaders". This section is blank unless |
| 154506 | | -** "lemon" is run with the "-m" command-line option. |
| 154507 | | -***************** Begin makeheaders token definitions *************************/ |
| 154508 | | -/**************** End makeheaders token definitions ***************************/ |
| 154591 | +/* These constants specify the various numeric values for terminal symbols. |
| 154592 | +***************** Begin token definitions *************************************/ |
| 154593 | +#ifndef TK_SEMI |
| 154594 | +#define TK_SEMI 1 |
| 154595 | +#define TK_EXPLAIN 2 |
| 154596 | +#define TK_QUERY 3 |
| 154597 | +#define TK_PLAN 4 |
| 154598 | +#define TK_BEGIN 5 |
| 154599 | +#define TK_TRANSACTION 6 |
| 154600 | +#define TK_DEFERRED 7 |
| 154601 | +#define TK_IMMEDIATE 8 |
| 154602 | +#define TK_EXCLUSIVE 9 |
| 154603 | +#define TK_COMMIT 10 |
| 154604 | +#define TK_END 11 |
| 154605 | +#define TK_ROLLBACK 12 |
| 154606 | +#define TK_SAVEPOINT 13 |
| 154607 | +#define TK_RELEASE 14 |
| 154608 | +#define TK_TO 15 |
| 154609 | +#define TK_TABLE 16 |
| 154610 | +#define TK_CREATE 17 |
| 154611 | +#define TK_IF 18 |
| 154612 | +#define TK_NOT 19 |
| 154613 | +#define TK_EXISTS 20 |
| 154614 | +#define TK_TEMP 21 |
| 154615 | +#define TK_LP 22 |
| 154616 | +#define TK_RP 23 |
| 154617 | +#define TK_AS 24 |
| 154618 | +#define TK_WITHOUT 25 |
| 154619 | +#define TK_COMMA 26 |
| 154620 | +#define TK_ABORT 27 |
| 154621 | +#define TK_ACTION 28 |
| 154622 | +#define TK_AFTER 29 |
| 154623 | +#define TK_ANALYZE 30 |
| 154624 | +#define TK_ASC 31 |
| 154625 | +#define TK_ATTACH 32 |
| 154626 | +#define TK_BEFORE 33 |
| 154627 | +#define TK_BY 34 |
| 154628 | +#define TK_CASCADE 35 |
| 154629 | +#define TK_CAST 36 |
| 154630 | +#define TK_CONFLICT 37 |
| 154631 | +#define TK_DATABASE 38 |
| 154632 | +#define TK_DESC 39 |
| 154633 | +#define TK_DETACH 40 |
| 154634 | +#define TK_EACH 41 |
| 154635 | +#define TK_FAIL 42 |
| 154636 | +#define TK_OR 43 |
| 154637 | +#define TK_AND 44 |
| 154638 | +#define TK_IS 45 |
| 154639 | +#define TK_MATCH 46 |
| 154640 | +#define TK_LIKE_KW 47 |
| 154641 | +#define TK_BETWEEN 48 |
| 154642 | +#define TK_IN 49 |
| 154643 | +#define TK_ISNULL 50 |
| 154644 | +#define TK_NOTNULL 51 |
| 154645 | +#define TK_NE 52 |
| 154646 | +#define TK_EQ 53 |
| 154647 | +#define TK_GT 54 |
| 154648 | +#define TK_LE 55 |
| 154649 | +#define TK_LT 56 |
| 154650 | +#define TK_GE 57 |
| 154651 | +#define TK_ESCAPE 58 |
| 154652 | +#define TK_ID 59 |
| 154653 | +#define TK_COLUMNKW 60 |
| 154654 | +#define TK_DO 61 |
| 154655 | +#define TK_FOR 62 |
| 154656 | +#define TK_IGNORE 63 |
| 154657 | +#define TK_INITIALLY 64 |
| 154658 | +#define TK_INSTEAD 65 |
| 154659 | +#define TK_NO 66 |
| 154660 | +#define TK_KEY 67 |
| 154661 | +#define TK_OF 68 |
| 154662 | +#define TK_OFFSET 69 |
| 154663 | +#define TK_PRAGMA 70 |
| 154664 | +#define TK_RAISE 71 |
| 154665 | +#define TK_RECURSIVE 72 |
| 154666 | +#define TK_REPLACE 73 |
| 154667 | +#define TK_RESTRICT 74 |
| 154668 | +#define TK_ROW 75 |
| 154669 | +#define TK_ROWS 76 |
| 154670 | +#define TK_TRIGGER 77 |
| 154671 | +#define TK_VACUUM 78 |
| 154672 | +#define TK_VIEW 79 |
| 154673 | +#define TK_VIRTUAL 80 |
| 154674 | +#define TK_WITH 81 |
| 154675 | +#define TK_NULLS 82 |
| 154676 | +#define TK_FIRST 83 |
| 154677 | +#define TK_LAST 84 |
| 154678 | +#define TK_CURRENT 85 |
| 154679 | +#define TK_FOLLOWING 86 |
| 154680 | +#define TK_PARTITION 87 |
| 154681 | +#define TK_PRECEDING 88 |
| 154682 | +#define TK_RANGE 89 |
| 154683 | +#define TK_UNBOUNDED 90 |
| 154684 | +#define TK_EXCLUDE 91 |
| 154685 | +#define TK_GROUPS 92 |
| 154686 | +#define TK_OTHERS 93 |
| 154687 | +#define TK_TIES 94 |
| 154688 | +#define TK_GENERATED 95 |
| 154689 | +#define TK_ALWAYS 96 |
| 154690 | +#define TK_REINDEX 97 |
| 154691 | +#define TK_RENAME 98 |
| 154692 | +#define TK_CTIME_KW 99 |
| 154693 | +#define TK_ANY 100 |
| 154694 | +#define TK_BITAND 101 |
| 154695 | +#define TK_BITOR 102 |
| 154696 | +#define TK_LSHIFT 103 |
| 154697 | +#define TK_RSHIFT 104 |
| 154698 | +#define TK_PLUS 105 |
| 154699 | +#define TK_MINUS 106 |
| 154700 | +#define TK_STAR 107 |
| 154701 | +#define TK_SLASH 108 |
| 154702 | +#define TK_REM 109 |
| 154703 | +#define TK_CONCAT 110 |
| 154704 | +#define TK_COLLATE 111 |
| 154705 | +#define TK_BITNOT 112 |
| 154706 | +#define TK_ON 113 |
| 154707 | +#define TK_INDEXED 114 |
| 154708 | +#define TK_STRING 115 |
| 154709 | +#define TK_JOIN_KW 116 |
| 154710 | +#define TK_CONSTRAINT 117 |
| 154711 | +#define TK_DEFAULT 118 |
| 154712 | +#define TK_NULL 119 |
| 154713 | +#define TK_PRIMARY 120 |
| 154714 | +#define TK_UNIQUE 121 |
| 154715 | +#define TK_CHECK 122 |
| 154716 | +#define TK_REFERENCES 123 |
| 154717 | +#define TK_AUTOINCR 124 |
| 154718 | +#define TK_INSERT 125 |
| 154719 | +#define TK_DELETE 126 |
| 154720 | +#define TK_UPDATE 127 |
| 154721 | +#define TK_SET 128 |
| 154722 | +#define TK_DEFERRABLE 129 |
| 154723 | +#define TK_FOREIGN 130 |
| 154724 | +#define TK_DROP 131 |
| 154725 | +#define TK_UNION 132 |
| 154726 | +#define TK_ALL 133 |
| 154727 | +#define TK_EXCEPT 134 |
| 154728 | +#define TK_INTERSECT 135 |
| 154729 | +#define TK_SELECT 136 |
| 154730 | +#define TK_VALUES 137 |
| 154731 | +#define TK_DISTINCT 138 |
| 154732 | +#define TK_DOT 139 |
| 154733 | +#define TK_FROM 140 |
| 154734 | +#define TK_JOIN 141 |
| 154735 | +#define TK_USING 142 |
| 154736 | +#define TK_ORDER 143 |
| 154737 | +#define TK_GROUP 144 |
| 154738 | +#define TK_HAVING 145 |
| 154739 | +#define TK_LIMIT 146 |
| 154740 | +#define TK_WHERE 147 |
| 154741 | +#define TK_INTO 148 |
| 154742 | +#define TK_NOTHING 149 |
| 154743 | +#define TK_FLOAT 150 |
| 154744 | +#define TK_BLOB 151 |
| 154745 | +#define TK_INTEGER 152 |
| 154746 | +#define TK_VARIABLE 153 |
| 154747 | +#define TK_CASE 154 |
| 154748 | +#define TK_WHEN 155 |
| 154749 | +#define TK_THEN 156 |
| 154750 | +#define TK_ELSE 157 |
| 154751 | +#define TK_INDEX 158 |
| 154752 | +#define TK_ALTER 159 |
| 154753 | +#define TK_ADD 160 |
| 154754 | +#define TK_WINDOW 161 |
| 154755 | +#define TK_OVER 162 |
| 154756 | +#define TK_FILTER 163 |
| 154757 | +#define TK_COLUMN 164 |
| 154758 | +#define TK_AGG_FUNCTION 165 |
| 154759 | +#define TK_AGG_COLUMN 166 |
| 154760 | +#define TK_TRUEFALSE 167 |
| 154761 | +#define TK_ISNOT 168 |
| 154762 | +#define TK_FUNCTION 169 |
| 154763 | +#define TK_UMINUS 170 |
| 154764 | +#define TK_UPLUS 171 |
| 154765 | +#define TK_TRUTH 172 |
| 154766 | +#define TK_REGISTER 173 |
| 154767 | +#define TK_VECTOR 174 |
| 154768 | +#define TK_SELECT_COLUMN 175 |
| 154769 | +#define TK_IF_NULL_ROW 176 |
| 154770 | +#define TK_ASTERISK 177 |
| 154771 | +#define TK_SPAN 178 |
| 154772 | +#define TK_SPACE 179 |
| 154773 | +#define TK_ILLEGAL 180 |
| 154774 | +#endif |
| 154775 | +/**************** End token definitions ***************************************/ |
| 154509 | 154776 | |
| 154510 | 154777 | /* The next sections is a series of control #defines. |
| 154511 | 154778 | ** various aspects of the generated parser. |
| 154512 | 154779 | ** YYCODETYPE is the data type used to store the integer codes |
| 154513 | 154780 | ** that represent terminal and non-terminal symbols. |
| | @@ -155509,10 +155776,11 @@ |
| 155509 | 155776 | }; |
| 155510 | 155777 | typedef struct yyParser yyParser; |
| 155511 | 155778 | |
| 155512 | 155779 | #ifndef NDEBUG |
| 155513 | 155780 | /* #include <stdio.h> */ |
| 155781 | +/* #include <assert.h> */ |
| 155514 | 155782 | static FILE *yyTraceFILE = 0; |
| 155515 | 155783 | static char *yyTracePrompt = 0; |
| 155516 | 155784 | #endif /* NDEBUG */ |
| 155517 | 155785 | |
| 155518 | 155786 | #ifndef NDEBUG |
| | @@ -157776,11 +158044,11 @@ |
| 157776 | 158044 | case 38: /* ccons ::= UNIQUE onconf */ |
| 157777 | 158045 | {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy192,0,0,0,0, |
| 157778 | 158046 | SQLITE_IDXTYPE_UNIQUE);} |
| 157779 | 158047 | break; |
| 157780 | 158048 | case 39: /* ccons ::= CHECK LP expr RP */ |
| 157781 | | -{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy202);} |
| 158049 | +{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy202,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy0.z);} |
| 157782 | 158050 | break; |
| 157783 | 158051 | case 40: /* ccons ::= REFERENCES nm eidlist_opt refargs */ |
| 157784 | 158052 | {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy242,yymsp[0].minor.yy192);} |
| 157785 | 158053 | break; |
| 157786 | 158054 | case 41: /* ccons ::= defer_subclause */ |
| | @@ -157855,11 +158123,11 @@ |
| 157855 | 158123 | case 67: /* tcons ::= UNIQUE LP sortlist RP onconf */ |
| 157856 | 158124 | {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy242,yymsp[0].minor.yy192,0,0,0,0, |
| 157857 | 158125 | SQLITE_IDXTYPE_UNIQUE);} |
| 157858 | 158126 | break; |
| 157859 | 158127 | case 68: /* tcons ::= CHECK LP expr RP onconf */ |
| 157860 | | -{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy202);} |
| 158128 | +{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy202,yymsp[-3].minor.yy0.z,yymsp[-1].minor.yy0.z);} |
| 157861 | 158129 | break; |
| 157862 | 158130 | case 69: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */ |
| 157863 | 158131 | { |
| 157864 | 158132 | sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy242, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy242, yymsp[-1].minor.yy192); |
| 157865 | 158133 | sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy192); |
| | @@ -164932,11 +165200,13 @@ |
| 164932 | 165200 | if( iNew>=0 && iNew<=255 ){ |
| 164933 | 165201 | sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0); |
| 164934 | 165202 | } |
| 164935 | 165203 | rc = SQLITE_OK; |
| 164936 | 165204 | }else{ |
| 165205 | + int nSave = db->busyHandler.nBusy; |
| 164937 | 165206 | rc = sqlite3OsFileControl(fd, op, pArg); |
| 165207 | + db->busyHandler.nBusy = nSave; |
| 164938 | 165208 | } |
| 164939 | 165209 | sqlite3BtreeLeave(pBtree); |
| 164940 | 165210 | } |
| 164941 | 165211 | sqlite3_mutex_leave(db->mutex); |
| 164942 | 165212 | return rc; |
| | @@ -165315,10 +165585,29 @@ |
| 165315 | 165585 | case SQLITE_TESTCTRL_RESULT_INTREAL: { |
| 165316 | 165586 | sqlite3_context *pCtx = va_arg(ap, sqlite3_context*); |
| 165317 | 165587 | sqlite3ResultIntReal(pCtx); |
| 165318 | 165588 | break; |
| 165319 | 165589 | } |
| 165590 | + |
| 165591 | + /* sqlite3_test_control(SQLITE_TESTCTRL_SEEK_COUNT, |
| 165592 | + ** sqlite3 *db, // Database connection |
| 165593 | + ** u64 *pnSeek // Write seek count here |
| 165594 | + ** ); |
| 165595 | + ** |
| 165596 | + ** This test-control queries the seek-counter on the "main" database |
| 165597 | + ** file. The seek-counter is written into *pnSeek and is then reset. |
| 165598 | + ** The seek-count is only available if compiled with SQLITE_DEBUG. |
| 165599 | + */ |
| 165600 | + case SQLITE_TESTCTRL_SEEK_COUNT: { |
| 165601 | + sqlite3 *db = va_arg(ap, sqlite3*); |
| 165602 | + u64 *pn = va_arg(ap, sqlite3_uint64*); |
| 165603 | + *pn = sqlite3BtreeSeekCount(db->aDb->pBt); |
| 165604 | + (void)db; /* Silence harmless unused variable warning */ |
| 165605 | + break; |
| 165606 | + } |
| 165607 | + |
| 165608 | + |
| 165320 | 165609 | } |
| 165321 | 165610 | va_end(ap); |
| 165322 | 165611 | #endif /* SQLITE_UNTESTABLE */ |
| 165323 | 165612 | return rc; |
| 165324 | 165613 | } |
| | @@ -209457,10 +209746,12 @@ |
| 209457 | 209746 | #define FTS5_CARET 12 |
| 209458 | 209747 | #define FTS5_COMMA 13 |
| 209459 | 209748 | #define FTS5_PLUS 14 |
| 209460 | 209749 | #define FTS5_STAR 15 |
| 209461 | 209750 | |
| 209751 | +/* This file is automatically generated by Lemon from input grammar |
| 209752 | +** source file "fts5parse.y". */ |
| 209462 | 209753 | /* |
| 209463 | 209754 | ** 2000-05-29 |
| 209464 | 209755 | ** |
| 209465 | 209756 | ** The author disclaims copyright to this source code. In place of |
| 209466 | 209757 | ** a legal notice, here is a blessing: |
| | @@ -209481,12 +209772,10 @@ |
| 209481 | 209772 | ** source file. |
| 209482 | 209773 | ** |
| 209483 | 209774 | ** The following is the concatenation of all %include directives from the |
| 209484 | 209775 | ** input grammar file: |
| 209485 | 209776 | */ |
| 209486 | | -/* #include <stdio.h> */ |
| 209487 | | -/* #include <assert.h> */ |
| 209488 | 209777 | /************ Begin %include sections from the grammar ************************/ |
| 209489 | 209778 | |
| 209490 | 209779 | /* #include "fts5Int.h" */ |
| 209491 | 209780 | /* #include "fts5parse.h" */ |
| 209492 | 209781 | |
| | @@ -209512,15 +209801,30 @@ |
| 209512 | 209801 | ** into sqlite3ParserAlloc(). The default is size_t. |
| 209513 | 209802 | */ |
| 209514 | 209803 | #define fts5YYMALLOCARGTYPE u64 |
| 209515 | 209804 | |
| 209516 | 209805 | /**************** End of %include directives **********************************/ |
| 209517 | | -/* These constants specify the various numeric values for terminal symbols |
| 209518 | | -** in a format understandable to "makeheaders". This section is blank unless |
| 209519 | | -** "lemon" is run with the "-m" command-line option. |
| 209520 | | -***************** Begin makeheaders token definitions *************************/ |
| 209521 | | -/**************** End makeheaders token definitions ***************************/ |
| 209806 | +/* These constants specify the various numeric values for terminal symbols. |
| 209807 | +***************** Begin token definitions *************************************/ |
| 209808 | +#ifndef FTS5_OR |
| 209809 | +#define FTS5_OR 1 |
| 209810 | +#define FTS5_AND 2 |
| 209811 | +#define FTS5_NOT 3 |
| 209812 | +#define FTS5_TERM 4 |
| 209813 | +#define FTS5_COLON 5 |
| 209814 | +#define FTS5_MINUS 6 |
| 209815 | +#define FTS5_LCP 7 |
| 209816 | +#define FTS5_RCP 8 |
| 209817 | +#define FTS5_STRING 9 |
| 209818 | +#define FTS5_LP 10 |
| 209819 | +#define FTS5_RP 11 |
| 209820 | +#define FTS5_CARET 12 |
| 209821 | +#define FTS5_COMMA 13 |
| 209822 | +#define FTS5_PLUS 14 |
| 209823 | +#define FTS5_STAR 15 |
| 209824 | +#endif |
| 209825 | +/**************** End token definitions ***************************************/ |
| 209522 | 209826 | |
| 209523 | 209827 | /* The next sections is a series of control #defines. |
| 209524 | 209828 | ** various aspects of the generated parser. |
| 209525 | 209829 | ** fts5YYCODETYPE is the data type used to store the integer codes |
| 209526 | 209830 | ** that represent terminal and non-terminal symbols. |
| | @@ -209799,10 +210103,11 @@ |
| 209799 | 210103 | }; |
| 209800 | 210104 | typedef struct fts5yyParser fts5yyParser; |
| 209801 | 210105 | |
| 209802 | 210106 | #ifndef NDEBUG |
| 209803 | 210107 | /* #include <stdio.h> */ |
| 210108 | +/* #include <assert.h> */ |
| 209804 | 210109 | static FILE *fts5yyTraceFILE = 0; |
| 209805 | 210110 | static char *fts5yyTracePrompt = 0; |
| 209806 | 210111 | #endif /* NDEBUG */ |
| 209807 | 210112 | |
| 209808 | 210113 | #ifndef NDEBUG |
| | @@ -215412,12 +215717,21 @@ |
| 215412 | 215717 | Fts5ExprNearset *pNear = pExpr->pNear; |
| 215413 | 215718 | int i; |
| 215414 | 215719 | int iTerm; |
| 215415 | 215720 | |
| 215416 | 215721 | if( pNear->pColset ){ |
| 215417 | | - int iCol = pNear->pColset->aiCol[0]; |
| 215418 | | - zRet = fts5PrintfAppend(zRet, "%s : ", pConfig->azCol[iCol]); |
| 215722 | + int ii; |
| 215723 | + Fts5Colset *pColset = pNear->pColset; |
| 215724 | + if( pColset->nCol>1 ) zRet = fts5PrintfAppend(zRet, "{"); |
| 215725 | + for(ii=0; ii<pColset->nCol; ii++){ |
| 215726 | + zRet = fts5PrintfAppend(zRet, "%s%s", |
| 215727 | + pConfig->azCol[pColset->aiCol[ii]], ii==pColset->nCol-1 ? "" : " " |
| 215728 | + ); |
| 215729 | + } |
| 215730 | + if( zRet ){ |
| 215731 | + zRet = fts5PrintfAppend(zRet, "%s : ", pColset->nCol>1 ? "}" : ""); |
| 215732 | + } |
| 215419 | 215733 | if( zRet==0 ) return 0; |
| 215420 | 215734 | } |
| 215421 | 215735 | |
| 215422 | 215736 | if( pNear->nPhrase>1 ){ |
| 215423 | 215737 | zRet = fts5PrintfAppend(zRet, "NEAR("); |
| | @@ -225836,11 +226150,11 @@ |
| 225836 | 226150 | int nArg, /* Number of args */ |
| 225837 | 226151 | sqlite3_value **apUnused /* Function arguments */ |
| 225838 | 226152 | ){ |
| 225839 | 226153 | assert( nArg==0 ); |
| 225840 | 226154 | UNUSED_PARAM2(nArg, apUnused); |
| 225841 | | - sqlite3_result_text(pCtx, "fts5: 2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36e492", -1, SQLITE_TRANSIENT); |
| 226155 | + sqlite3_result_text(pCtx, "fts5: 2020-09-11 15:01:49 b79f19edfd33c2a75f936c352668e14e81f35acf4f07edc27a21f941a7304b38", -1, SQLITE_TRANSIENT); |
| 225842 | 226156 | } |
| 225843 | 226157 | |
| 225844 | 226158 | /* |
| 225845 | 226159 | ** Return true if zName is the extension on one of the shadow tables used |
| 225846 | 226160 | ** by this module. |
| | @@ -226399,13 +226713,20 @@ |
| 226399 | 226713 | ctx.szCol = 0; |
| 226400 | 226714 | rc = sqlite3Fts5Tokenize(pConfig, FTS5_TOKENIZE_DOCUMENT, |
| 226401 | 226715 | zText, nText, (void*)&ctx, fts5StorageInsertCallback |
| 226402 | 226716 | ); |
| 226403 | 226717 | p->aTotalSize[iCol-1] -= (i64)ctx.szCol; |
| 226718 | + if( p->aTotalSize[iCol-1]<0 ){ |
| 226719 | + rc = FTS5_CORRUPT; |
| 226720 | + } |
| 226404 | 226721 | } |
| 226405 | 226722 | } |
| 226406 | | - p->nTotalRow--; |
| 226723 | + if( rc==SQLITE_OK && p->nTotalRow<1 ){ |
| 226724 | + rc = FTS5_CORRUPT; |
| 226725 | + }else{ |
| 226726 | + p->nTotalRow--; |
| 226727 | + } |
| 226407 | 226728 | |
| 226408 | 226729 | rc2 = sqlite3_reset(pSeek); |
| 226409 | 226730 | if( rc==SQLITE_OK ) rc = rc2; |
| 226410 | 226731 | return rc; |
| 226411 | 226732 | } |
| | @@ -230619,12 +230940,12 @@ |
| 230619 | 230940 | } |
| 230620 | 230941 | #endif /* SQLITE_CORE */ |
| 230621 | 230942 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 230622 | 230943 | |
| 230623 | 230944 | /************** End of stmt.c ************************************************/ |
| 230624 | | -#if __LINE__!=230624 |
| 230945 | +#if __LINE__!=230945 |
| 230625 | 230946 | #undef SQLITE_SOURCE_ID |
| 230626 | | -#define SQLITE_SOURCE_ID "2020-08-26 10:50:48 6c716f4b556ea8f9c9f15cffd81cb970488eadf1d5da2ba6b366d3bdeb36alt2" |
| 230947 | +#define SQLITE_SOURCE_ID "2020-09-15 20:48:30 3d35fa0be866213274fc09250225b345f6b08a9b4ec373d53d95e627e245alt2" |
| 230627 | 230948 | #endif |
| 230628 | 230949 | /* Return the source-id for this library */ |
| 230629 | 230950 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 230630 | 230951 | /************************** End of sqlite3.c ******************************/ |
| 230631 | 230952 | |