| | @@ -1147,11 +1147,11 @@ |
| 1147 | 1147 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1148 | 1148 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1149 | 1149 | */ |
| 1150 | 1150 | #define SQLITE_VERSION "3.22.0" |
| 1151 | 1151 | #define SQLITE_VERSION_NUMBER 3022000 |
| 1152 | | -#define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbcc71" |
| 1152 | +#define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b429b15" |
| 1153 | 1153 | |
| 1154 | 1154 | /* |
| 1155 | 1155 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1156 | 1156 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1157 | 1157 | ** |
| | @@ -1492,10 +1492,12 @@ |
| 1492 | 1492 | ** on a per database connection basis using the |
| 1493 | 1493 | ** [sqlite3_extended_result_codes()] API. Or, the extended code for |
| 1494 | 1494 | ** the most recent error can be obtained using |
| 1495 | 1495 | ** [sqlite3_extended_errcode()]. |
| 1496 | 1496 | */ |
| 1497 | +#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8)) |
| 1498 | +#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8)) |
| 1497 | 1499 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 1498 | 1500 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 1499 | 1501 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 1500 | 1502 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| 1501 | 1503 | #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) |
| | @@ -1537,10 +1539,11 @@ |
| 1537 | 1539 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1538 | 1540 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1539 | 1541 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 1540 | 1542 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 1541 | 1543 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
| 1544 | +#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8)) |
| 1542 | 1545 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 1543 | 1546 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 1544 | 1547 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 1545 | 1548 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 1546 | 1549 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| | @@ -15955,10 +15958,11 @@ |
| 15955 | 15958 | unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */ |
| 15956 | 15959 | unsigned isResized:1; /* True if resizeIndexObject() has been called */ |
| 15957 | 15960 | unsigned isCovering:1; /* True if this is a covering index */ |
| 15958 | 15961 | unsigned noSkipScan:1; /* Do not try to use skip-scan if true */ |
| 15959 | 15962 | unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */ |
| 15963 | + unsigned bNoQuery:1; /* Do not use this index to optimize queries */ |
| 15960 | 15964 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 15961 | 15965 | int nSample; /* Number of elements in aSample[] */ |
| 15962 | 15966 | int nSampleCol; /* Size of IndexSample.anEq[] and so on */ |
| 15963 | 15967 | tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */ |
| 15964 | 15968 | IndexSample *aSample; /* Samples of the left-most key */ |
| | @@ -16767,11 +16771,11 @@ |
| 16767 | 16771 | int nErr; /* Number of errors seen */ |
| 16768 | 16772 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 16769 | 16773 | int nMem; /* Number of memory cells used so far */ |
| 16770 | 16774 | int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ |
| 16771 | 16775 | int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */ |
| 16772 | | - int iSelfTab; /* Table for associated with an index on expr, or negative |
| 16776 | + int iSelfTab; /* Table associated with an index on expr, or negative |
| 16773 | 16777 | ** of the base register during check-constraint eval */ |
| 16774 | 16778 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 16775 | 16779 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 16776 | 16780 | int nLabel; /* Number of labels used */ |
| 16777 | 16781 | int *aLabel; /* Space to hold the labels */ |
| | @@ -19494,11 +19498,11 @@ |
| 19494 | 19498 | ** The conversion algorithms are implemented based on descriptions |
| 19495 | 19499 | ** in the following text: |
| 19496 | 19500 | ** |
| 19497 | 19501 | ** Jean Meeus |
| 19498 | 19502 | ** Astronomical Algorithms, 2nd Edition, 1998 |
| 19499 | | -** ISBM 0-943396-61-1 |
| 19503 | +** ISBN 0-943396-61-1 |
| 19500 | 19504 | ** Willmann-Bell, Inc |
| 19501 | 19505 | ** Richmond, Virginia (USA) |
| 19502 | 19506 | */ |
| 19503 | 19507 | /* #include "sqliteInt.h" */ |
| 19504 | 19508 | /* #include <stdlib.h> */ |
| | @@ -31066,11 +31070,11 @@ |
| 31066 | 31070 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 31067 | 31071 | { "munmap", (sqlite3_syscall_ptr)munmap, 0 }, |
| 31068 | 31072 | #else |
| 31069 | 31073 | { "munmap", (sqlite3_syscall_ptr)0, 0 }, |
| 31070 | 31074 | #endif |
| 31071 | | -#define osMunmap ((void*(*)(void*,size_t))aSyscall[23].pCurrent) |
| 31075 | +#define osMunmap ((int(*)(void*,size_t))aSyscall[23].pCurrent) |
| 31072 | 31076 | |
| 31073 | 31077 | #if HAVE_MREMAP && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) |
| 31074 | 31078 | { "mremap", (sqlite3_syscall_ptr)mremap, 0 }, |
| 31075 | 31079 | #else |
| 31076 | 31080 | { "mremap", (sqlite3_syscall_ptr)0, 0 }, |
| | @@ -34748,11 +34752,11 @@ |
| 34748 | 34752 | struct flock f; /* The posix advisory locking structure */ |
| 34749 | 34753 | int rc = SQLITE_OK; /* Result code form fcntl() */ |
| 34750 | 34754 | |
| 34751 | 34755 | /* Access to the unixShmNode object is serialized by the caller */ |
| 34752 | 34756 | pShmNode = pFile->pInode->pShmNode; |
| 34753 | | - assert( sqlite3_mutex_held(pShmNode->mutex) || pShmNode->nRef==0 ); |
| 34757 | + assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->mutex) ); |
| 34754 | 34758 | |
| 34755 | 34759 | /* Shared locks never span more than one byte */ |
| 34756 | 34760 | assert( n==1 || lockType!=F_RDLCK ); |
| 34757 | 34761 | |
| 34758 | 34762 | /* Locks are within range */ |
| | @@ -36382,11 +36386,11 @@ |
| 36382 | 36386 | |
| 36383 | 36387 | /* If creating a master or main-file journal, this function will open |
| 36384 | 36388 | ** a file-descriptor on the directory too. The first time unixSync() |
| 36385 | 36389 | ** is called the directory file descriptor will be fsync()ed and close()d. |
| 36386 | 36390 | */ |
| 36387 | | - int syncDir = (isCreate && ( |
| 36391 | + int isNewJrnl = (isCreate && ( |
| 36388 | 36392 | eType==SQLITE_OPEN_MASTER_JOURNAL |
| 36389 | 36393 | || eType==SQLITE_OPEN_MAIN_JOURNAL |
| 36390 | 36394 | || eType==SQLITE_OPEN_WAL |
| 36391 | 36395 | )); |
| 36392 | 36396 | |
| | @@ -36452,11 +36456,11 @@ |
| 36452 | 36456 | ** sqlite3_uri_parameter(). */ |
| 36453 | 36457 | assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 ); |
| 36454 | 36458 | |
| 36455 | 36459 | }else if( !zName ){ |
| 36456 | 36460 | /* If zName is NULL, the upper layer is requesting a temp file. */ |
| 36457 | | - assert(isDelete && !syncDir); |
| 36461 | + assert(isDelete && !isNewJrnl); |
| 36458 | 36462 | rc = unixGetTempname(pVfs->mxPathname, zTmpname); |
| 36459 | 36463 | if( rc!=SQLITE_OK ){ |
| 36460 | 36464 | return rc; |
| 36461 | 36465 | } |
| 36462 | 36466 | zName = zTmpname; |
| | @@ -36498,10 +36502,13 @@ |
| 36498 | 36502 | isReadonly = 1; |
| 36499 | 36503 | fd = robust_open(zName, openFlags, openMode); |
| 36500 | 36504 | } |
| 36501 | 36505 | if( fd<0 ){ |
| 36502 | 36506 | rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zName); |
| 36507 | + /* If unable to create a journal, change the error code to |
| 36508 | + ** indicate that the directory permissions are wrong. */ |
| 36509 | + if( isNewJrnl && osAccess(zName, F_OK) ) rc = SQLITE_READONLY_DIRECTORY; |
| 36503 | 36510 | goto open_finished; |
| 36504 | 36511 | } |
| 36505 | 36512 | |
| 36506 | 36513 | /* If this process is running as root and if creating a new rollback |
| 36507 | 36514 | ** journal or WAL file, set the ownership of the journal or WAL to be |
| | @@ -36557,11 +36564,11 @@ |
| 36557 | 36564 | /* Set up appropriate ctrlFlags */ |
| 36558 | 36565 | if( isDelete ) ctrlFlags |= UNIXFILE_DELETE; |
| 36559 | 36566 | if( isReadonly ) ctrlFlags |= UNIXFILE_RDONLY; |
| 36560 | 36567 | noLock = eType!=SQLITE_OPEN_MAIN_DB; |
| 36561 | 36568 | if( noLock ) ctrlFlags |= UNIXFILE_NOLOCK; |
| 36562 | | - if( syncDir ) ctrlFlags |= UNIXFILE_DIRSYNC; |
| 36569 | + if( isNewJrnl ) ctrlFlags |= UNIXFILE_DIRSYNC; |
| 36563 | 36570 | if( flags & SQLITE_OPEN_URI ) ctrlFlags |= UNIXFILE_URI; |
| 36564 | 36571 | |
| 36565 | 36572 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 36566 | 36573 | #if SQLITE_PREFER_PROXY_LOCKING |
| 36567 | 36574 | isAutoProxy = 1; |
| | @@ -42257,11 +42264,11 @@ |
| 42257 | 42264 | int nByte /* Number of bytes to lock or unlock */ |
| 42258 | 42265 | ){ |
| 42259 | 42266 | int rc = 0; /* Result code form Lock/UnlockFileEx() */ |
| 42260 | 42267 | |
| 42261 | 42268 | /* Access to the winShmNode object is serialized by the caller */ |
| 42262 | | - assert( sqlite3_mutex_held(pFile->mutex) || pFile->nRef==0 ); |
| 42269 | + assert( pFile->nRef==0 || sqlite3_mutex_held(pFile->mutex) ); |
| 42263 | 42270 | |
| 42264 | 42271 | OSTRACE(("SHM-LOCK file=%p, lock=%d, offset=%d, size=%d\n", |
| 42265 | 42272 | pFile->hFile.h, lockType, ofst, nByte)); |
| 42266 | 42273 | |
| 42267 | 42274 | /* Release/Acquire the system-level lock */ |
| | @@ -105647,10 +105654,22 @@ |
| 105647 | 105654 | pKey->aColl[i] = zColl==sqlite3StrBINARY ? 0 : |
| 105648 | 105655 | sqlite3LocateCollSeq(pParse, zColl); |
| 105649 | 105656 | pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 105650 | 105657 | } |
| 105651 | 105658 | if( pParse->nErr ){ |
| 105659 | + assert( pParse->rc==SQLITE_ERROR_MISSING_COLLSEQ ); |
| 105660 | + if( pIdx->bNoQuery==0 ){ |
| 105661 | + /* Deactivate the index because it contains an unknown collating |
| 105662 | + ** sequence. The only way to reactive the index is to reload the |
| 105663 | + ** schema. Adding the missing collating sequence later does not |
| 105664 | + ** reactive the index. The application had the chance to register |
| 105665 | + ** the missing index using the collation-needed callback. For |
| 105666 | + ** simplicity, SQLite will not give the application a second chance. |
| 105667 | + */ |
| 105668 | + pIdx->bNoQuery = 1; |
| 105669 | + pParse->rc = SQLITE_ERROR_RETRY; |
| 105670 | + } |
| 105652 | 105671 | sqlite3KeyInfoUnref(pKey); |
| 105653 | 105672 | pKey = 0; |
| 105654 | 105673 | } |
| 105655 | 105674 | } |
| 105656 | 105675 | return pKey; |
| | @@ -105832,10 +105851,11 @@ |
| 105832 | 105851 | p = 0; |
| 105833 | 105852 | } |
| 105834 | 105853 | assert( !p || p->xCmp ); |
| 105835 | 105854 | if( p==0 ){ |
| 105836 | 105855 | sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName); |
| 105856 | + pParse->rc = SQLITE_ERROR_MISSING_COLLSEQ; |
| 105837 | 105857 | } |
| 105838 | 105858 | return p; |
| 105839 | 105859 | } |
| 105840 | 105860 | |
| 105841 | 105861 | /* |
| | @@ -106498,15 +106518,15 @@ |
| 106498 | 106518 | ** deleted from is a view |
| 106499 | 106519 | */ |
| 106500 | 106520 | #ifndef SQLITE_OMIT_TRIGGER |
| 106501 | 106521 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 106502 | 106522 | isView = pTab->pSelect!=0; |
| 106503 | | - bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); |
| 106504 | 106523 | #else |
| 106505 | 106524 | # define pTrigger 0 |
| 106506 | 106525 | # define isView 0 |
| 106507 | 106526 | #endif |
| 106527 | + bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); |
| 106508 | 106528 | #ifdef SQLITE_OMIT_VIEW |
| 106509 | 106529 | # undef isView |
| 106510 | 106530 | # define isView 0 |
| 106511 | 106531 | #endif |
| 106512 | 106532 | |
| | @@ -118067,12 +118087,10 @@ |
| 118067 | 118087 | } |
| 118068 | 118088 | |
| 118069 | 118089 | end_prepare: |
| 118070 | 118090 | |
| 118071 | 118091 | sqlite3ParserReset(&sParse); |
| 118072 | | - rc = sqlite3ApiExit(db, rc); |
| 118073 | | - assert( (rc&db->errMask)==rc ); |
| 118074 | 118092 | return rc; |
| 118075 | 118093 | } |
| 118076 | 118094 | static int sqlite3LockAndPrepare( |
| 118077 | 118095 | sqlite3 *db, /* Database handle. */ |
| 118078 | 118096 | const char *zSql, /* UTF-8 encoded SQL statement. */ |
| | @@ -118081,10 +118099,11 @@ |
| 118081 | 118099 | Vdbe *pOld, /* VM being reprepared */ |
| 118082 | 118100 | sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */ |
| 118083 | 118101 | const char **pzTail /* OUT: End of parsed string */ |
| 118084 | 118102 | ){ |
| 118085 | 118103 | int rc; |
| 118104 | + int cnt = 0; |
| 118086 | 118105 | |
| 118087 | 118106 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 118088 | 118107 | if( ppStmt==0 ) return SQLITE_MISUSE_BKPT; |
| 118089 | 118108 | #endif |
| 118090 | 118109 | *ppStmt = 0; |
| | @@ -118091,19 +118110,22 @@ |
| 118091 | 118110 | if( !sqlite3SafetyCheckOk(db)||zSql==0 ){ |
| 118092 | 118111 | return SQLITE_MISUSE_BKPT; |
| 118093 | 118112 | } |
| 118094 | 118113 | sqlite3_mutex_enter(db->mutex); |
| 118095 | 118114 | sqlite3BtreeEnterAll(db); |
| 118096 | | - rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 118097 | | - if( rc==SQLITE_SCHEMA ){ |
| 118098 | | - sqlite3ResetOneSchema(db, -1); |
| 118099 | | - sqlite3_finalize(*ppStmt); |
| 118100 | | - rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 118101 | | - } |
| 118102 | | - sqlite3BtreeLeaveAll(db); |
| 118103 | | - sqlite3_mutex_leave(db->mutex); |
| 118104 | | - assert( rc==SQLITE_OK || *ppStmt==0 ); |
| 118115 | + do{ |
| 118116 | + /* Make multiple attempts to compile the SQL, until it either succeeds |
| 118117 | + ** or encounters a permanent error. A schema problem after one schema |
| 118118 | + ** reset is considered a permanent error. */ |
| 118119 | + rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 118120 | + assert( rc==SQLITE_OK || *ppStmt==0 ); |
| 118121 | + }while( rc==SQLITE_ERROR_RETRY |
| 118122 | + || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) ); |
| 118123 | + sqlite3BtreeLeaveAll(db); |
| 118124 | + rc = sqlite3ApiExit(db, rc); |
| 118125 | + assert( (rc&db->errMask)==rc ); |
| 118126 | + sqlite3_mutex_leave(db->mutex); |
| 118105 | 118127 | return rc; |
| 118106 | 118128 | } |
| 118107 | 118129 | |
| 118108 | 118130 | /* |
| 118109 | 118131 | ** Rerun the compilation of a statement after a schema change. |
| | @@ -121628,11 +121650,11 @@ |
| 121628 | 121650 | ** (8) If the subquery uses LIMIT then the outer query may not be a join. |
| 121629 | 121651 | ** |
| 121630 | 121652 | ** (9) If the subquery uses LIMIT then the outer query may not be aggregate. |
| 121631 | 121653 | ** |
| 121632 | 121654 | ** (**) Restriction (10) was removed from the code on 2005-02-05 but we |
| 121633 | | -** accidentally carried the comment forward until 2014-09-15. Original |
| 121655 | +** accidently carried the comment forward until 2014-09-15. Original |
| 121634 | 121656 | ** constraint: "If the subquery is aggregate then the outer query |
| 121635 | 121657 | ** may not use LIMIT." |
| 121636 | 121658 | ** |
| 121637 | 121659 | ** (11) The subquery and the outer query may not both have ORDER BY clauses. |
| 121638 | 121660 | ** |
| | @@ -130436,10 +130458,11 @@ |
| 130436 | 130458 | }else{ |
| 130437 | 130459 | endEq = 1; |
| 130438 | 130460 | } |
| 130439 | 130461 | }else if( bStopAtNull ){ |
| 130440 | 130462 | sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq); |
| 130463 | + sqlite3ExprCacheRemove(pParse, regBase+nEq, 1); |
| 130441 | 130464 | endEq = 0; |
| 130442 | 130465 | nConstraint++; |
| 130443 | 130466 | } |
| 130444 | 130467 | sqlite3DbFree(db, zStartAff); |
| 130445 | 130468 | sqlite3DbFree(db, zEndAff); |
| | @@ -135364,10 +135387,11 @@ |
| 135364 | 135387 | if( pProbe->pPartIdxWhere!=0 |
| 135365 | 135388 | && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){ |
| 135366 | 135389 | testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */ |
| 135367 | 135390 | continue; /* Partial index inappropriate for this query */ |
| 135368 | 135391 | } |
| 135392 | + if( pProbe->bNoQuery ) continue; |
| 135369 | 135393 | rSize = pProbe->aiRowLogEst[0]; |
| 135370 | 135394 | pNew->u.btree.nEq = 0; |
| 135371 | 135395 | pNew->u.btree.nBtm = 0; |
| 135372 | 135396 | pNew->u.btree.nTop = 0; |
| 135373 | 135397 | pNew->nSkip = 0; |
| | @@ -142677,11 +142701,11 @@ |
| 142677 | 142701 | #endif /* __cplusplus */ |
| 142678 | 142702 | |
| 142679 | 142703 | /************** End of rtree.h ***********************************************/ |
| 142680 | 142704 | /************** Continuing where we left off in main.c ***********************/ |
| 142681 | 142705 | #endif |
| 142682 | | -#ifdef SQLITE_ENABLE_ICU |
| 142706 | +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) |
| 142683 | 142707 | /************** Include sqliteicu.h in the middle of main.c ******************/ |
| 142684 | 142708 | /************** Begin file sqliteicu.h ***************************************/ |
| 142685 | 142709 | /* |
| 142686 | 142710 | ** 2008 May 26 |
| 142687 | 142711 | ** |
| | @@ -145736,11 +145760,11 @@ |
| 145736 | 145760 | if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 145737 | 145761 | rc = sqlite3Fts3Init(db); |
| 145738 | 145762 | } |
| 145739 | 145763 | #endif |
| 145740 | 145764 | |
| 145741 | | -#ifdef SQLITE_ENABLE_ICU |
| 145765 | +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) |
| 145742 | 145766 | if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 145743 | 145767 | rc = sqlite3IcuInit(db); |
| 145744 | 145768 | } |
| 145745 | 145769 | #endif |
| 145746 | 145770 | |
| | @@ -170615,11 +170639,13 @@ |
| 170615 | 170639 | ** |
| 170616 | 170640 | ** * An implementation of the LIKE operator that uses ICU to |
| 170617 | 170641 | ** provide case-independent matching. |
| 170618 | 170642 | */ |
| 170619 | 170643 | |
| 170620 | | -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) |
| 170644 | +#if !defined(SQLITE_CORE) \ |
| 170645 | + || defined(SQLITE_ENABLE_ICU) \ |
| 170646 | + || defined(SQLITE_ENABLE_ICU_COLLATIONS) |
| 170621 | 170647 | |
| 170622 | 170648 | /* Include ICU headers */ |
| 170623 | 170649 | #include <unicode/utypes.h> |
| 170624 | 170650 | #include <unicode/uregex.h> |
| 170625 | 170651 | #include <unicode/ustring.h> |
| | @@ -170632,10 +170658,30 @@ |
| 170632 | 170658 | SQLITE_EXTENSION_INIT1 |
| 170633 | 170659 | #else |
| 170634 | 170660 | /* #include "sqlite3.h" */ |
| 170635 | 170661 | #endif |
| 170636 | 170662 | |
| 170663 | +/* |
| 170664 | +** This function is called when an ICU function called from within |
| 170665 | +** the implementation of an SQL scalar function returns an error. |
| 170666 | +** |
| 170667 | +** The scalar function context passed as the first argument is |
| 170668 | +** loaded with an error message based on the following two args. |
| 170669 | +*/ |
| 170670 | +static void icuFunctionError( |
| 170671 | + sqlite3_context *pCtx, /* SQLite scalar function context */ |
| 170672 | + const char *zName, /* Name of ICU function that failed */ |
| 170673 | + UErrorCode e /* Error code returned by ICU function */ |
| 170674 | +){ |
| 170675 | + char zBuf[128]; |
| 170676 | + sqlite3_snprintf(128, zBuf, "ICU error: %s(): %s", zName, u_errorName(e)); |
| 170677 | + zBuf[127] = '\0'; |
| 170678 | + sqlite3_result_error(pCtx, zBuf, -1); |
| 170679 | +} |
| 170680 | + |
| 170681 | +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) |
| 170682 | + |
| 170637 | 170683 | /* |
| 170638 | 170684 | ** Maximum length (in bytes) of the pattern in a LIKE or GLOB |
| 170639 | 170685 | ** operator. |
| 170640 | 170686 | */ |
| 170641 | 170687 | #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH |
| | @@ -170811,28 +170857,10 @@ |
| 170811 | 170857 | if( zA && zB ){ |
| 170812 | 170858 | sqlite3_result_int(context, icuLikeCompare(zA, zB, uEsc)); |
| 170813 | 170859 | } |
| 170814 | 170860 | } |
| 170815 | 170861 | |
| 170816 | | -/* |
| 170817 | | -** This function is called when an ICU function called from within |
| 170818 | | -** the implementation of an SQL scalar function returns an error. |
| 170819 | | -** |
| 170820 | | -** The scalar function context passed as the first argument is |
| 170821 | | -** loaded with an error message based on the following two args. |
| 170822 | | -*/ |
| 170823 | | -static void icuFunctionError( |
| 170824 | | - sqlite3_context *pCtx, /* SQLite scalar function context */ |
| 170825 | | - const char *zName, /* Name of ICU function that failed */ |
| 170826 | | - UErrorCode e /* Error code returned by ICU function */ |
| 170827 | | -){ |
| 170828 | | - char zBuf[128]; |
| 170829 | | - sqlite3_snprintf(128, zBuf, "ICU error: %s(): %s", zName, u_errorName(e)); |
| 170830 | | - zBuf[127] = '\0'; |
| 170831 | | - sqlite3_result_error(pCtx, zBuf, -1); |
| 170832 | | -} |
| 170833 | | - |
| 170834 | 170862 | /* |
| 170835 | 170863 | ** Function to delete compiled regexp objects. Registered as |
| 170836 | 170864 | ** a destructor function with sqlite3_set_auxdata(). |
| 170837 | 170865 | */ |
| 170838 | 170866 | static void icuRegexpDelete(void *p){ |
| | @@ -170994,10 +171022,12 @@ |
| 170994 | 171022 | return; |
| 170995 | 171023 | } |
| 170996 | 171024 | assert( 0 ); /* Unreachable */ |
| 170997 | 171025 | } |
| 170998 | 171026 | |
| 171027 | +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */ |
| 171028 | + |
| 170999 | 171029 | /* |
| 171000 | 171030 | ** Collation sequence destructor function. The pCtx argument points to |
| 171001 | 171031 | ** a UCollator structure previously allocated using ucol_open(). |
| 171002 | 171032 | */ |
| 171003 | 171033 | static void icuCollationDel(void *pCtx){ |
| | @@ -171088,10 +171118,11 @@ |
| 171088 | 171118 | unsigned short enc; /* Optimal text encoding */ |
| 171089 | 171119 | unsigned char iContext; /* sqlite3_user_data() context */ |
| 171090 | 171120 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); |
| 171091 | 171121 | } scalars[] = { |
| 171092 | 171122 | {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation}, |
| 171123 | +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) |
| 171093 | 171124 | {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc}, |
| 171094 | 171125 | {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 171095 | 171126 | {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 171096 | 171127 | {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 171097 | 171128 | {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| | @@ -171099,14 +171130,14 @@ |
| 171099 | 171130 | {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 171100 | 171131 | {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 171101 | 171132 | {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 171102 | 171133 | {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 171103 | 171134 | {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 171135 | +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */ |
| 171104 | 171136 | }; |
| 171105 | 171137 | int rc = SQLITE_OK; |
| 171106 | 171138 | int i; |
| 171107 | | - |
| 171108 | 171139 | |
| 171109 | 171140 | for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){ |
| 171110 | 171141 | const struct IcuScalar *p = &scalars[i]; |
| 171111 | 171142 | rc = sqlite3_create_function( |
| 171112 | 171143 | db, p->zName, p->nArg, p->enc, |
| | @@ -184999,11 +185030,11 @@ |
| 184999 | 185030 | 0 /* xRollbackTo */ |
| 185000 | 185031 | }; |
| 185001 | 185032 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 185002 | 185033 | |
| 185003 | 185034 | /**************************************************************************** |
| 185004 | | -** The following routines are the only publicly visible identifiers in this |
| 185035 | +** The following routines are the only publically visible identifiers in this |
| 185005 | 185036 | ** file. Call the following routines in order to register the various SQL |
| 185006 | 185037 | ** functions and the virtual table implemented by this file. |
| 185007 | 185038 | ****************************************************************************/ |
| 185008 | 185039 | |
| 185009 | 185040 | SQLITE_PRIVATE int sqlite3Json1Init(sqlite3 *db){ |
| | @@ -198157,11 +198188,17 @@ |
| 198157 | 198188 | Fts5DoclistIter i1; |
| 198158 | 198189 | Fts5DoclistIter i2; |
| 198159 | 198190 | Fts5Buffer out = {0, 0, 0}; |
| 198160 | 198191 | Fts5Buffer tmp = {0, 0, 0}; |
| 198161 | 198192 | |
| 198162 | | - if( sqlite3Fts5BufferSize(&p->rc, &out, p1->n + p2->n) ) return; |
| 198193 | + /* The maximum size of the output is equal to the sum of the two |
| 198194 | + ** input sizes + 1 varint (9 bytes). The extra varint is because if the |
| 198195 | + ** first rowid in one input is a large negative number, and the first in |
| 198196 | + ** the other a non-negative number, the delta for the non-negative |
| 198197 | + ** number will be larger on disk than the literal integer value |
| 198198 | + ** was. */ |
| 198199 | + if( sqlite3Fts5BufferSize(&p->rc, &out, p1->n + p2->n + 9) ) return; |
| 198163 | 198200 | fts5DoclistIterInit(p1, &i1); |
| 198164 | 198201 | fts5DoclistIterInit(p2, &i2); |
| 198165 | 198202 | |
| 198166 | 198203 | while( 1 ){ |
| 198167 | 198204 | if( i1.iRowid<i2.iRowid ){ |
| | @@ -198251,10 +198288,11 @@ |
| 198251 | 198288 | } |
| 198252 | 198289 | else if( i2.aPoslist ){ |
| 198253 | 198290 | fts5MergeAppendDocid(&out, iLastRowid, i2.iRowid); |
| 198254 | 198291 | fts5BufferSafeAppendBlob(&out, i2.aPoslist, i2.aEof - i2.aPoslist); |
| 198255 | 198292 | } |
| 198293 | + assert( out.n<=(p1->n+p2->n+9) ); |
| 198256 | 198294 | |
| 198257 | 198295 | fts5BufferSet(&p->rc, p1, out.n, out.p); |
| 198258 | 198296 | fts5BufferFree(&tmp); |
| 198259 | 198297 | fts5BufferFree(&out); |
| 198260 | 198298 | } |
| | @@ -202372,11 +202410,11 @@ |
| 202372 | 202410 | int nArg, /* Number of args */ |
| 202373 | 202411 | sqlite3_value **apUnused /* Function arguments */ |
| 202374 | 202412 | ){ |
| 202375 | 202413 | assert( nArg==0 ); |
| 202376 | 202414 | UNUSED_PARAM2(nArg, apUnused); |
| 202377 | | - sqlite3_result_text(pCtx, "fts5: 2017-12-01 18:40:18 5771b1d611b3562ea6c040f3f893073c4d0ee58c35b37ae211520d9aee8ed547", -1, SQLITE_TRANSIENT); |
| 202415 | + sqlite3_result_text(pCtx, "fts5: 2017-12-13 15:32:33 30bf38d589adf0b2eb613e184ffb03ed7e625736cb04fd5c341328f72bc5ef4d", -1, SQLITE_TRANSIENT); |
| 202378 | 202416 | } |
| 202379 | 202417 | |
| 202380 | 202418 | static int fts5Init(sqlite3 *db){ |
| 202381 | 202419 | static const sqlite3_module fts5Mod = { |
| 202382 | 202420 | /* iVersion */ 2, |
| | @@ -205632,11 +205670,11 @@ |
| 205632 | 205670 | |
| 205633 | 205671 | int bEof; /* True if this cursor is at EOF */ |
| 205634 | 205672 | Fts5IndexIter *pIter; /* Term/rowid iterator object */ |
| 205635 | 205673 | |
| 205636 | 205674 | int nLeTerm; /* Size of zLeTerm in bytes */ |
| 205637 | | - char *zLeTerm; /* (term <= $zLeTerm) parameter, or NULL */ |
| 205675 | + char *zLeTerm; /* (term <= $zLeTerm) paramater, or NULL */ |
| 205638 | 205676 | |
| 205639 | 205677 | /* These are used by 'col' tables only */ |
| 205640 | 205678 | Fts5Config *pConfig; /* Fts5 table configuration */ |
| 205641 | 205679 | int iCol; |
| 205642 | 205680 | i64 *aCnt; |
| | @@ -206640,12 +206678,12 @@ |
| 206640 | 206678 | } |
| 206641 | 206679 | #endif /* SQLITE_CORE */ |
| 206642 | 206680 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 206643 | 206681 | |
| 206644 | 206682 | /************** End of stmt.c ************************************************/ |
| 206645 | | -#if __LINE__!=206645 |
| 206683 | +#if __LINE__!=206683 |
| 206646 | 206684 | #undef SQLITE_SOURCE_ID |
| 206647 | | -#define SQLITE_SOURCE_ID "2017-12-06 20:50:08 6a55bd67720451cdf316155cf348103bfce1056a78bcddf0029b45ff0fdbalt2" |
| 206685 | +#define SQLITE_SOURCE_ID "2017-12-13 20:35:34 1c0aa919ee429cd194820ec9c54084563f39e63fd399b23f859fc6703b42alt2" |
| 206648 | 206686 | #endif |
| 206649 | 206687 | /* Return the source-id for this library */ |
| 206650 | 206688 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 206651 | 206689 | /************************** End of sqlite3.c ******************************/ |
| 206652 | 206690 | |