| | @@ -673,11 +673,11 @@ |
| 673 | 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | 675 | */ |
| 676 | 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | 677 | #define SQLITE_VERSION_NUMBER 3007015 |
| 678 | | -#define SQLITE_SOURCE_ID "2012-11-09 21:40:02 5a3b07f0f5dfae7eea870303f52f37d6a17f1da2" |
| 678 | +#define SQLITE_SOURCE_ID "2012-12-05 14:31:13 9f6c68856b694373b7ffb124abd996e519ba5921" |
| 679 | 679 | |
| 680 | 680 | /* |
| 681 | 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | 683 | ** |
| | @@ -2162,10 +2162,26 @@ |
| 2162 | 2162 | ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] |
| 2163 | 2163 | ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE |
| 2164 | 2164 | ** <dd> These options are obsolete and should not be used by new code. |
| 2165 | 2165 | ** They are retained for backwards compatibility but are now no-ops. |
| 2166 | 2166 | ** </dl> |
| 2167 | +** |
| 2168 | +** [[SQLITE_CONFIG_SQLLOG]] |
| 2169 | +** <dt>SQLITE_CONFIG_SQLLOG |
| 2170 | +** <dd>This option is only available if sqlite is compiled with the |
| 2171 | +** SQLITE_ENABLE_SQLLOG pre-processor macro defined. The first argument should |
| 2172 | +** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int). |
| 2173 | +** The second should be of type (void*). The callback is invoked by the library |
| 2174 | +** in three separate circumstances, identified by the value passed as the |
| 2175 | +** fourth parameter. If the fourth parameter is 0, then the database connection |
| 2176 | +** passed as the second argument has just been opened. The third argument |
| 2177 | +** points to a buffer containing the name of the main database file. If the |
| 2178 | +** fourth parameter is 1, then the SQL statement that the third parameter |
| 2179 | +** points to has just been executed. Or, if the fourth parameter is 2, then |
| 2180 | +** the connection being passed as the second parameter is being closed. The |
| 2181 | +** third parameter is passed NULL In this case. |
| 2182 | +** </dl> |
| 2167 | 2183 | */ |
| 2168 | 2184 | #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ |
| 2169 | 2185 | #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ |
| 2170 | 2186 | #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ |
| 2171 | 2187 | #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ |
| | @@ -2183,10 +2199,11 @@ |
| 2183 | 2199 | #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ |
| 2184 | 2200 | #define SQLITE_CONFIG_URI 17 /* int */ |
| 2185 | 2201 | #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ |
| 2186 | 2202 | #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ |
| 2187 | 2203 | #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ |
| 2204 | +#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ |
| 2188 | 2205 | |
| 2189 | 2206 | /* |
| 2190 | 2207 | ** CAPI3REF: Database Connection Configuration Options |
| 2191 | 2208 | ** |
| 2192 | 2209 | ** These constants are the available integer configuration options that |
| | @@ -11557,10 +11574,14 @@ |
| 11557 | 11574 | sqlite3_mutex *pInitMutex; /* Mutex used by sqlite3_initialize() */ |
| 11558 | 11575 | int nRefInitMutex; /* Number of users of pInitMutex */ |
| 11559 | 11576 | void (*xLog)(void*,int,const char*); /* Function for logging */ |
| 11560 | 11577 | void *pLogArg; /* First argument to xLog() */ |
| 11561 | 11578 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 11579 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 11580 | + void(*xSqllog)(void*,sqlite3*,const char*, int); |
| 11581 | + void *pSqllogArg; |
| 11582 | +#endif |
| 11562 | 11583 | }; |
| 11563 | 11584 | |
| 11564 | 11585 | /* |
| 11565 | 11586 | ** Context pointer passed down through the tree-walk. |
| 11566 | 11587 | */ |
| | @@ -12291,12 +12312,14 @@ |
| 12291 | 12312 | |
| 12292 | 12313 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 12293 | 12314 | SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); |
| 12294 | 12315 | SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *); |
| 12295 | 12316 | SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *); |
| 12317 | +SQLITE_PRIVATE int sqlite3JournalExists(sqlite3_file *p); |
| 12296 | 12318 | #else |
| 12297 | 12319 | #define sqlite3JournalSize(pVfs) ((pVfs)->szOsFile) |
| 12320 | + #define sqlite3JournalExists(p) 1 |
| 12298 | 12321 | #endif |
| 12299 | 12322 | |
| 12300 | 12323 | SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *); |
| 12301 | 12324 | SQLITE_PRIVATE int sqlite3MemJournalSize(void); |
| 12302 | 12325 | SQLITE_PRIVATE int sqlite3IsMemJournal(sqlite3_file *); |
| | @@ -12563,10 +12586,14 @@ |
| 12563 | 12586 | 0, /* pInitMutex */ |
| 12564 | 12587 | 0, /* nRefInitMutex */ |
| 12565 | 12588 | 0, /* xLog */ |
| 12566 | 12589 | 0, /* pLogArg */ |
| 12567 | 12590 | 0, /* bLocaltimeFault */ |
| 12591 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 12592 | + 0, /* xSqllog */ |
| 12593 | + 0 /* pSqllogArg */ |
| 12594 | +#endif |
| 12568 | 12595 | }; |
| 12569 | 12596 | |
| 12570 | 12597 | |
| 12571 | 12598 | /* |
| 12572 | 12599 | ** Hash table for global functions - functions common to all |
| | @@ -22686,10 +22713,17 @@ |
| 22686 | 22713 | ** * Definitions of sqlite3_vfs objects for all locking methods |
| 22687 | 22714 | ** plus implementations of sqlite3_os_init() and sqlite3_os_end(). |
| 22688 | 22715 | */ |
| 22689 | 22716 | #if SQLITE_OS_UNIX /* This file is used on unix only */ |
| 22690 | 22717 | |
| 22718 | +/* Use posix_fallocate() if it is available |
| 22719 | +*/ |
| 22720 | +#if !defined(HAVE_POSIX_FALLOCATE) \ |
| 22721 | + && (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L) |
| 22722 | +# define HAVE_POSIX_FALLOCATE 1 |
| 22723 | +#endif |
| 22724 | + |
| 22691 | 22725 | /* |
| 22692 | 22726 | ** There are various methods for file locking used for concurrency |
| 22693 | 22727 | ** control: |
| 22694 | 22728 | ** |
| 22695 | 22729 | ** 1. POSIX locking (the default), |
| | @@ -27016,15 +27050,23 @@ |
| 27016 | 27050 | ** |
| 27017 | 27051 | ** Alternatively, if bExtend is true, use ftruncate() to allocate |
| 27018 | 27052 | ** the requested memory region. |
| 27019 | 27053 | */ |
| 27020 | 27054 | if( !bExtend ) goto shmpage_out; |
| 27055 | +#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE |
| 27056 | + if( osFallocate(pShmNode->h, sStat.st_size, nByte)!=0 ){ |
| 27057 | + rc = unixLogError(SQLITE_IOERR_SHMSIZE, "fallocate", |
| 27058 | + pShmNode->zFilename); |
| 27059 | + goto shmpage_out; |
| 27060 | + } |
| 27061 | +#else |
| 27021 | 27062 | if( robust_ftruncate(pShmNode->h, nByte) ){ |
| 27022 | 27063 | rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate", |
| 27023 | 27064 | pShmNode->zFilename); |
| 27024 | 27065 | goto shmpage_out; |
| 27025 | 27066 | } |
| 27067 | +#endif |
| 27026 | 27068 | } |
| 27027 | 27069 | } |
| 27028 | 27070 | |
| 27029 | 27071 | /* Map the requested memory region into this processes address space. */ |
| 27030 | 27072 | apNew = (char **)sqlite3_realloc( |
| | @@ -33937,18 +33979,28 @@ |
| 33937 | 33979 | memset(&sAttrData, 0, sizeof(sAttrData)); |
| 33938 | 33980 | if ( osGetFileAttributesExW(zConverted, GetFileExInfoStandard, |
| 33939 | 33981 | &sAttrData) ){ |
| 33940 | 33982 | attr = sAttrData.dwFileAttributes; |
| 33941 | 33983 | }else{ |
| 33942 | | - rc = SQLITE_OK; /* Already gone? */ |
| 33984 | + lastErrno = osGetLastError(); |
| 33985 | + if( lastErrno==ERROR_FILE_NOT_FOUND || lastErrno==ERROR_PATH_NOT_FOUND ){ |
| 33986 | + rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */ |
| 33987 | + }else{ |
| 33988 | + rc = SQLITE_ERROR; |
| 33989 | + } |
| 33943 | 33990 | break; |
| 33944 | 33991 | } |
| 33945 | 33992 | #else |
| 33946 | 33993 | attr = osGetFileAttributesW(zConverted); |
| 33947 | 33994 | #endif |
| 33948 | 33995 | if ( attr==INVALID_FILE_ATTRIBUTES ){ |
| 33949 | | - rc = SQLITE_OK; /* Already gone? */ |
| 33996 | + lastErrno = osGetLastError(); |
| 33997 | + if( lastErrno==ERROR_FILE_NOT_FOUND || lastErrno==ERROR_PATH_NOT_FOUND ){ |
| 33998 | + rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */ |
| 33999 | + }else{ |
| 34000 | + rc = SQLITE_ERROR; |
| 34001 | + } |
| 33950 | 34002 | break; |
| 33951 | 34003 | } |
| 33952 | 34004 | if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ |
| 33953 | 34005 | rc = SQLITE_ERROR; /* Files only. */ |
| 33954 | 34006 | break; |
| | @@ -33966,11 +34018,16 @@ |
| 33966 | 34018 | #ifdef SQLITE_WIN32_HAS_ANSI |
| 33967 | 34019 | else{ |
| 33968 | 34020 | do { |
| 33969 | 34021 | attr = osGetFileAttributesA(zConverted); |
| 33970 | 34022 | if ( attr==INVALID_FILE_ATTRIBUTES ){ |
| 33971 | | - rc = SQLITE_OK; /* Already gone? */ |
| 34023 | + lastErrno = osGetLastError(); |
| 34024 | + if( lastErrno==ERROR_FILE_NOT_FOUND || lastErrno==ERROR_PATH_NOT_FOUND ){ |
| 34025 | + rc = SQLITE_IOERR_DELETE_NOENT; /* Already gone? */ |
| 34026 | + }else{ |
| 34027 | + rc = SQLITE_ERROR; |
| 34028 | + } |
| 33972 | 34029 | break; |
| 33973 | 34030 | } |
| 33974 | 34031 | if ( attr&FILE_ATTRIBUTE_DIRECTORY ){ |
| 33975 | 34032 | rc = SQLITE_ERROR; /* Files only. */ |
| 33976 | 34033 | break; |
| | @@ -33984,11 +34041,11 @@ |
| 33984 | 34041 | break; |
| 33985 | 34042 | } |
| 33986 | 34043 | } while(1); |
| 33987 | 34044 | } |
| 33988 | 34045 | #endif |
| 33989 | | - if( rc ){ |
| 34046 | + if( rc && rc!=SQLITE_IOERR_DELETE_NOENT ){ |
| 33990 | 34047 | rc = winLogError(SQLITE_IOERR_DELETE, lastErrno, |
| 33991 | 34048 | "winDelete", zFilename); |
| 33992 | 34049 | }else{ |
| 33993 | 34050 | logIoerr(cnt); |
| 33994 | 34051 | } |
| | @@ -39178,16 +39235,17 @@ |
| 39178 | 39235 | /* This branch may be executed with Pager.journalMode==MEMORY if |
| 39179 | 39236 | ** a hot-journal was just rolled back. In this case the journal |
| 39180 | 39237 | ** file should be closed and deleted. If this connection writes to |
| 39181 | 39238 | ** the database file, it will do so using an in-memory journal. |
| 39182 | 39239 | */ |
| 39240 | + int bDelete = (!pPager->tempFile && sqlite3JournalExists(pPager->jfd)); |
| 39183 | 39241 | assert( pPager->journalMode==PAGER_JOURNALMODE_DELETE |
| 39184 | 39242 | || pPager->journalMode==PAGER_JOURNALMODE_MEMORY |
| 39185 | 39243 | || pPager->journalMode==PAGER_JOURNALMODE_WAL |
| 39186 | 39244 | ); |
| 39187 | 39245 | sqlite3OsClose(pPager->jfd); |
| 39188 | | - if( !pPager->tempFile ){ |
| 39246 | + if( bDelete ){ |
| 39189 | 39247 | rc = sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0); |
| 39190 | 39248 | } |
| 39191 | 39249 | } |
| 39192 | 39250 | } |
| 39193 | 39251 | |
| | @@ -40722,11 +40780,11 @@ |
| 40722 | 40780 | |
| 40723 | 40781 | if( isOpen(pPager->fd) ){ |
| 40724 | 40782 | void **ap = (void **)&pPager->xBusyHandler; |
| 40725 | 40783 | assert( ((int(*)(void *))(ap[0]))==xBusyHandler ); |
| 40726 | 40784 | assert( ap[1]==pBusyHandlerArg ); |
| 40727 | | - sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_BUSYHANDLER, (void *)ap); |
| 40785 | + sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_BUSYHANDLER, (void *)ap); |
| 40728 | 40786 | } |
| 40729 | 40787 | } |
| 40730 | 40788 | |
| 40731 | 40789 | /* |
| 40732 | 40790 | ** Change the page size used by the Pager object. The new page size |
| | @@ -58521,11 +58579,11 @@ |
| 58521 | 58579 | ** Remember the SQL string for a prepared statement. |
| 58522 | 58580 | */ |
| 58523 | 58581 | SQLITE_PRIVATE void sqlite3VdbeSetSql(Vdbe *p, const char *z, int n, int isPrepareV2){ |
| 58524 | 58582 | assert( isPrepareV2==1 || isPrepareV2==0 ); |
| 58525 | 58583 | if( p==0 ) return; |
| 58526 | | -#ifdef SQLITE_OMIT_TRACE |
| 58584 | +#if defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_ENABLE_SQLLOG) |
| 58527 | 58585 | if( !isPrepareV2 ) return; |
| 58528 | 58586 | #endif |
| 58529 | 58587 | assert( p->zSql==0 ); |
| 58530 | 58588 | p->zSql = sqlite3DbStrNDup(p->db, z, n); |
| 58531 | 58589 | p->isPrepareV2 = (u8)isPrepareV2; |
| | @@ -59191,10 +59249,11 @@ |
| 59191 | 59249 | assert( addr<p->nOp ); |
| 59192 | 59250 | if( addr<0 ){ |
| 59193 | 59251 | addr = p->nOp - 1; |
| 59194 | 59252 | } |
| 59195 | 59253 | pOp = &p->aOp[addr]; |
| 59254 | + assert( pOp->p4type==P4_NOTUSED || pOp->p4type==P4_INT32 ); |
| 59196 | 59255 | freeP4(db, pOp->p4type, pOp->p4.p); |
| 59197 | 59256 | pOp->p4.p = 0; |
| 59198 | 59257 | if( n==P4_INT32 ){ |
| 59199 | 59258 | /* Note: this cast is safe, because the origin data point was an int |
| 59200 | 59259 | ** that was cast to a (const char *). */ |
| | @@ -60794,10 +60853,31 @@ |
| 60794 | 60853 | sqlite3Error(db, rc, 0); |
| 60795 | 60854 | } |
| 60796 | 60855 | return rc; |
| 60797 | 60856 | } |
| 60798 | 60857 | |
| 60858 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 60859 | +/* |
| 60860 | +** If an SQLITE_CONFIG_SQLLOG hook is registered and the VM has been run, |
| 60861 | +** invoke it. |
| 60862 | +*/ |
| 60863 | +static void vdbeInvokeSqllog(Vdbe *v){ |
| 60864 | + if( sqlite3GlobalConfig.xSqllog && v->rc==SQLITE_OK && v->zSql && v->pc>=0 ){ |
| 60865 | + char *zExpanded = sqlite3VdbeExpandSql(v, v->zSql); |
| 60866 | + assert( v->db->init.busy==0 ); |
| 60867 | + if( zExpanded ){ |
| 60868 | + sqlite3GlobalConfig.xSqllog( |
| 60869 | + sqlite3GlobalConfig.pSqllogArg, v->db, zExpanded, 1 |
| 60870 | + ); |
| 60871 | + sqlite3DbFree(v->db, zExpanded); |
| 60872 | + } |
| 60873 | + } |
| 60874 | +} |
| 60875 | +#else |
| 60876 | +# define vdbeInvokeSqllog(x) |
| 60877 | +#endif |
| 60878 | + |
| 60799 | 60879 | /* |
| 60800 | 60880 | ** Clean up a VDBE after execution but do not delete the VDBE just yet. |
| 60801 | 60881 | ** Write any error messages into *pzErrMsg. Return the result code. |
| 60802 | 60882 | ** |
| 60803 | 60883 | ** After this routine is run, the VDBE should be ready to be executed |
| | @@ -60821,10 +60901,11 @@ |
| 60821 | 60901 | ** and error message from the VDBE into the main database structure. But |
| 60822 | 60902 | ** if the VDBE has just been set to run but has not actually executed any |
| 60823 | 60903 | ** instructions yet, leave the main database error information unchanged. |
| 60824 | 60904 | */ |
| 60825 | 60905 | if( p->pc>=0 ){ |
| 60906 | + vdbeInvokeSqllog(p); |
| 60826 | 60907 | sqlite3VdbeTransferError(p); |
| 60827 | 60908 | sqlite3DbFree(db, p->zErrMsg); |
| 60828 | 60909 | p->zErrMsg = 0; |
| 60829 | 60910 | if( p->runOnlyOnce ) p->expired = 1; |
| 60830 | 60911 | }else if( p->rc && p->expired ){ |
| | @@ -60927,11 +61008,11 @@ |
| 60927 | 61008 | sqlite3DbFree(db, p->aLabel); |
| 60928 | 61009 | sqlite3DbFree(db, p->aColName); |
| 60929 | 61010 | sqlite3DbFree(db, p->zSql); |
| 60930 | 61011 | sqlite3DbFree(db, p->pFree); |
| 60931 | 61012 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 60932 | | - sqlite3DbFree(db, p->zExplain); |
| 61013 | + sqlite3_free(p->zExplain); |
| 60933 | 61014 | sqlite3DbFree(db, p->pExplain); |
| 60934 | 61015 | #endif |
| 60935 | 61016 | } |
| 60936 | 61017 | |
| 60937 | 61018 | /* |
| | @@ -67163,11 +67244,11 @@ |
| 67163 | 67244 | u.az.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 67164 | 67245 | u.az.pCx->isIndex = !u.az.pCx->isTable; |
| 67165 | 67246 | break; |
| 67166 | 67247 | } |
| 67167 | 67248 | |
| 67168 | | -/* Opcode: OpenSorter P1 P2 * P4 * |
| 67249 | +/* Opcode: SorterOpen P1 P2 * P4 * |
| 67169 | 67250 | ** |
| 67170 | 67251 | ** This opcode works like OP_OpenEphemeral except that it opens |
| 67171 | 67252 | ** a transient index that is specifically designed to sort large |
| 67172 | 67253 | ** tables using an external merge-sort algorithm. |
| 67173 | 67254 | */ |
| | @@ -71947,10 +72028,20 @@ |
| 71947 | 72028 | if( p->pMethods!=&JournalFileMethods ){ |
| 71948 | 72029 | return SQLITE_OK; |
| 71949 | 72030 | } |
| 71950 | 72031 | return createFile((JournalFile *)p); |
| 71951 | 72032 | } |
| 72033 | + |
| 72034 | +/* |
| 72035 | +** The file-handle passed as the only argument is guaranteed to be an open |
| 72036 | +** file. It may or may not be of class JournalFile. If the file is a |
| 72037 | +** JournalFile, and the underlying file on disk has not yet been opened, |
| 72038 | +** return 0. Otherwise, return 1. |
| 72039 | +*/ |
| 72040 | +SQLITE_PRIVATE int sqlite3JournalExists(sqlite3_file *p){ |
| 72041 | + return (p->pMethods!=&JournalFileMethods || ((JournalFile *)p)->pReal!=0); |
| 72042 | +} |
| 71952 | 72043 | |
| 71953 | 72044 | /* |
| 71954 | 72045 | ** Return the number of bytes required to store a JournalFile that uses vfs |
| 71955 | 72046 | ** pVfs to create the underlying on-disk files. |
| 71956 | 72047 | */ |
| | @@ -80206,11 +80297,11 @@ |
| 80206 | 80297 | sqlite3ErrorMsg(pFix->pParse, |
| 80207 | 80298 | "%s %T cannot reference objects in database %s", |
| 80208 | 80299 | pFix->zType, pFix->pName, pItem->zDatabase); |
| 80209 | 80300 | return 1; |
| 80210 | 80301 | } |
| 80211 | | - sqlite3_free(pItem->zDatabase); |
| 80302 | + sqlite3DbFree(pFix->pParse->db, pItem->zDatabase); |
| 80212 | 80303 | pItem->zDatabase = 0; |
| 80213 | 80304 | pItem->pSchema = pFix->pSchema; |
| 80214 | 80305 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) |
| 80215 | 80306 | if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; |
| 80216 | 80307 | if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; |
| | @@ -85737,10 +85828,11 @@ |
| 85737 | 85828 | int nNeedle; |
| 85738 | 85829 | int typeHaystack, typeNeedle; |
| 85739 | 85830 | int N = 1; |
| 85740 | 85831 | int isText; |
| 85741 | 85832 | |
| 85833 | + UNUSED_PARAMETER(argc); |
| 85742 | 85834 | typeHaystack = sqlite3_value_type(argv[0]); |
| 85743 | 85835 | typeNeedle = sqlite3_value_type(argv[1]); |
| 85744 | 85836 | if( typeHaystack==SQLITE_NULL || typeNeedle==SQLITE_NULL ) return; |
| 85745 | 85837 | nHaystack = sqlite3_value_bytes(argv[0]); |
| 85746 | 85838 | nNeedle = sqlite3_value_bytes(argv[1]); |
| | @@ -88450,11 +88542,11 @@ |
| 88450 | 88542 | int iDb, /* The database index in sqlite3.aDb[] */ |
| 88451 | 88543 | Table *pTab, /* The table to be opened */ |
| 88452 | 88544 | int opcode /* OP_OpenRead or OP_OpenWrite */ |
| 88453 | 88545 | ){ |
| 88454 | 88546 | Vdbe *v; |
| 88455 | | - if( IsVirtual(pTab) ) return; |
| 88547 | + assert( !IsVirtual(pTab) ); |
| 88456 | 88548 | v = sqlite3GetVdbe(p); |
| 88457 | 88549 | assert( opcode==OP_OpenWrite || opcode==OP_OpenRead ); |
| 88458 | 88550 | sqlite3TableLock(p, iDb, pTab->tnum, (opcode==OP_OpenWrite)?1:0, pTab->zName); |
| 88459 | 88551 | sqlite3VdbeAddOp3(v, opcode, iCur, pTab->tnum, iDb); |
| 88460 | 88552 | sqlite3VdbeChangeP4(v, -1, SQLITE_INT_TO_PTR(pTab->nCol), P4_INT32); |
| | @@ -107515,10 +107607,12 @@ |
| 107515 | 107607 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 107516 | 107608 | if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){ |
| 107517 | 107609 | const char *pVTab = (const char *)sqlite3GetVTable(db, pTab); |
| 107518 | 107610 | int iCur = pTabItem->iCursor; |
| 107519 | 107611 | sqlite3VdbeAddOp4(v, OP_VOpen, iCur, 0, 0, pVTab, P4_VTAB); |
| 107612 | + }else if( IsVirtual(pTab) ){ |
| 107613 | + /* noop */ |
| 107520 | 107614 | }else |
| 107521 | 107615 | #endif |
| 107522 | 107616 | if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 |
| 107523 | 107617 | && (wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0 ){ |
| 107524 | 107618 | int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead; |
| | @@ -112550,10 +112644,17 @@ |
| 112550 | 112644 | ** to sqlite3_initialize() should be a no-op. But the initialization |
| 112551 | 112645 | ** must be complete. So isInit must not be set until the very end |
| 112552 | 112646 | ** of this routine. |
| 112553 | 112647 | */ |
| 112554 | 112648 | if( sqlite3GlobalConfig.isInit ) return SQLITE_OK; |
| 112649 | + |
| 112650 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 112651 | + { |
| 112652 | + extern void sqlite3_init_sqllog(void); |
| 112653 | + sqlite3_init_sqllog(); |
| 112654 | + } |
| 112655 | +#endif |
| 112555 | 112656 | |
| 112556 | 112657 | /* Make sure the mutex subsystem is initialized. If unable to |
| 112557 | 112658 | ** initialize the mutex subsystem, return early with the error. |
| 112558 | 112659 | ** If the system is so sick that we are unable to allocate a mutex, |
| 112559 | 112660 | ** there is not much SQLite is going to be able to do. |
| | @@ -112898,10 +112999,19 @@ |
| 112898 | 112999 | |
| 112899 | 113000 | case SQLITE_CONFIG_COVERING_INDEX_SCAN: { |
| 112900 | 113001 | sqlite3GlobalConfig.bUseCis = va_arg(ap, int); |
| 112901 | 113002 | break; |
| 112902 | 113003 | } |
| 113004 | + |
| 113005 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 113006 | + case SQLITE_CONFIG_SQLLOG: { |
| 113007 | + typedef void(*SQLLOGFUNC_t)(void*, sqlite3*, const char*, int); |
| 113008 | + sqlite3GlobalConfig.xSqllog = va_arg(ap, SQLLOGFUNC_t); |
| 113009 | + sqlite3GlobalConfig.pSqllogArg = va_arg(ap, void *); |
| 113010 | + break; |
| 113011 | + } |
| 113012 | +#endif |
| 112903 | 113013 | |
| 112904 | 113014 | default: { |
| 112905 | 113015 | rc = SQLITE_ERROR; |
| 112906 | 113016 | break; |
| 112907 | 113017 | } |
| | @@ -113237,10 +113347,17 @@ |
| 113237 | 113347 | sqlite3Error(db, SQLITE_BUSY, "unable to close due to unfinalized " |
| 113238 | 113348 | "statements or unfinished backups"); |
| 113239 | 113349 | sqlite3_mutex_leave(db->mutex); |
| 113240 | 113350 | return SQLITE_BUSY; |
| 113241 | 113351 | } |
| 113352 | + |
| 113353 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 113354 | + if( sqlite3GlobalConfig.xSqllog ){ |
| 113355 | + /* Closing the handle. Fourth parameter is passed the value 2. */ |
| 113356 | + sqlite3GlobalConfig.xSqllog(sqlite3GlobalConfig.pSqllogArg, db, 0, 2); |
| 113357 | + } |
| 113358 | +#endif |
| 113242 | 113359 | |
| 113243 | 113360 | /* Convert the connection into a zombie and then close it. |
| 113244 | 113361 | */ |
| 113245 | 113362 | db->magic = SQLITE_MAGIC_ZOMBIE; |
| 113246 | 113363 | sqlite3LeaveMutexAndCloseZombie(db); |
| | @@ -114870,10 +114987,17 @@ |
| 114870 | 114987 | db = 0; |
| 114871 | 114988 | }else if( rc!=SQLITE_OK ){ |
| 114872 | 114989 | db->magic = SQLITE_MAGIC_SICK; |
| 114873 | 114990 | } |
| 114874 | 114991 | *ppDb = db; |
| 114992 | +#ifdef SQLITE_ENABLE_SQLLOG |
| 114993 | + if( sqlite3GlobalConfig.xSqllog ){ |
| 114994 | + /* Opening a db handle. Fourth parameter is passed 0. */ |
| 114995 | + void *pArg = sqlite3GlobalConfig.pSqllogArg; |
| 114996 | + sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 114997 | + } |
| 114998 | +#endif |
| 114875 | 114999 | return sqlite3ApiExit(0, rc); |
| 114876 | 115000 | } |
| 114877 | 115001 | |
| 114878 | 115002 | /* |
| 114879 | 115003 | ** Open a new database handle. |
| | @@ -126142,11 +126266,11 @@ |
| 126142 | 126266 | static int fts3PendingTermsAdd( |
| 126143 | 126267 | Fts3Table *p, /* Table into which text will be inserted */ |
| 126144 | 126268 | int iLangid, /* Language id to use */ |
| 126145 | 126269 | const char *zText, /* Text of document to be inserted */ |
| 126146 | 126270 | int iCol, /* Column into which text is being inserted */ |
| 126147 | | - u32 *pnWord /* OUT: Number of tokens inserted */ |
| 126271 | + u32 *pnWord /* IN/OUT: Incr. by number tokens inserted */ |
| 126148 | 126272 | ){ |
| 126149 | 126273 | int rc; |
| 126150 | 126274 | int iStart = 0; |
| 126151 | 126275 | int iEnd = 0; |
| 126152 | 126276 | int iPos = 0; |
| | @@ -126206,11 +126330,11 @@ |
| 126206 | 126330 | ); |
| 126207 | 126331 | } |
| 126208 | 126332 | } |
| 126209 | 126333 | |
| 126210 | 126334 | pModule->xClose(pCsr); |
| 126211 | | - *pnWord = nWord; |
| 126335 | + *pnWord += nWord; |
| 126212 | 126336 | return (rc==SQLITE_DONE ? SQLITE_OK : rc); |
| 126213 | 126337 | } |
| 126214 | 126338 | |
| 126215 | 126339 | /* |
| 126216 | 126340 | ** Calling this function indicates that subsequent calls to |
| | @@ -126410,15 +126534,17 @@ |
| 126410 | 126534 | */ |
| 126411 | 126535 | static void fts3DeleteTerms( |
| 126412 | 126536 | int *pRC, /* Result code */ |
| 126413 | 126537 | Fts3Table *p, /* The FTS table to delete from */ |
| 126414 | 126538 | sqlite3_value *pRowid, /* The docid to be deleted */ |
| 126415 | | - u32 *aSz /* Sizes of deleted document written here */ |
| 126539 | + u32 *aSz, /* Sizes of deleted document written here */ |
| 126540 | + int *pbFound /* OUT: Set to true if row really does exist */ |
| 126416 | 126541 | ){ |
| 126417 | 126542 | int rc; |
| 126418 | 126543 | sqlite3_stmt *pSelect; |
| 126419 | 126544 | |
| 126545 | + assert( *pbFound==0 ); |
| 126420 | 126546 | if( *pRC ) return; |
| 126421 | 126547 | rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid); |
| 126422 | 126548 | if( rc==SQLITE_OK ){ |
| 126423 | 126549 | if( SQLITE_ROW==sqlite3_step(pSelect) ){ |
| 126424 | 126550 | int i; |
| | @@ -126432,10 +126558,11 @@ |
| 126432 | 126558 | if( rc!=SQLITE_OK ){ |
| 126433 | 126559 | sqlite3_reset(pSelect); |
| 126434 | 126560 | *pRC = rc; |
| 126435 | 126561 | return; |
| 126436 | 126562 | } |
| 126563 | + *pbFound = 1; |
| 126437 | 126564 | } |
| 126438 | 126565 | rc = sqlite3_reset(pSelect); |
| 126439 | 126566 | }else{ |
| 126440 | 126567 | sqlite3_reset(pSelect); |
| 126441 | 126568 | } |
| | @@ -128656,11 +128783,11 @@ |
| 128656 | 128783 | |
| 128657 | 128784 | while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 128658 | 128785 | int iCol; |
| 128659 | 128786 | int iLangid = langidFromSelect(p, pStmt); |
| 128660 | 128787 | rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0)); |
| 128661 | | - aSz[p->nColumn] = 0; |
| 128788 | + memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1)); |
| 128662 | 128789 | for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){ |
| 128663 | 128790 | const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1); |
| 128664 | 128791 | rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]); |
| 128665 | 128792 | aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1); |
| 128666 | 128793 | } |
| | @@ -130560,32 +130687,36 @@ |
| 130560 | 130687 | ** of subsiduary data structures accordingly. |
| 130561 | 130688 | */ |
| 130562 | 130689 | static int fts3DeleteByRowid( |
| 130563 | 130690 | Fts3Table *p, |
| 130564 | 130691 | sqlite3_value *pRowid, |
| 130565 | | - int *pnDoc, |
| 130692 | + int *pnChng, /* IN/OUT: Decrement if row is deleted */ |
| 130566 | 130693 | u32 *aSzDel |
| 130567 | 130694 | ){ |
| 130568 | | - int isEmpty = 0; |
| 130569 | | - int rc = fts3IsEmpty(p, pRowid, &isEmpty); |
| 130570 | | - if( rc==SQLITE_OK ){ |
| 130571 | | - if( isEmpty ){ |
| 130572 | | - /* Deleting this row means the whole table is empty. In this case |
| 130573 | | - ** delete the contents of all three tables and throw away any |
| 130574 | | - ** data in the pendingTerms hash table. */ |
| 130575 | | - rc = fts3DeleteAll(p, 1); |
| 130576 | | - *pnDoc = *pnDoc - 1; |
| 130577 | | - }else{ |
| 130578 | | - fts3DeleteTerms(&rc, p, pRowid, aSzDel); |
| 130579 | | - if( p->zContentTbl==0 ){ |
| 130580 | | - fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid); |
| 130581 | | - if( sqlite3_changes(p->db) ) *pnDoc = *pnDoc - 1; |
| 130582 | | - }else{ |
| 130583 | | - *pnDoc = *pnDoc - 1; |
| 130584 | | - } |
| 130585 | | - if( p->bHasDocsize ){ |
| 130586 | | - fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, &pRowid); |
| 130695 | + int rc = SQLITE_OK; /* Return code */ |
| 130696 | + int bFound = 0; /* True if *pRowid really is in the table */ |
| 130697 | + |
| 130698 | + fts3DeleteTerms(&rc, p, pRowid, aSzDel, &bFound); |
| 130699 | + if( bFound && rc==SQLITE_OK ){ |
| 130700 | + int isEmpty = 0; /* Deleting *pRowid leaves the table empty */ |
| 130701 | + rc = fts3IsEmpty(p, pRowid, &isEmpty); |
| 130702 | + if( rc==SQLITE_OK ){ |
| 130703 | + if( isEmpty ){ |
| 130704 | + /* Deleting this row means the whole table is empty. In this case |
| 130705 | + ** delete the contents of all three tables and throw away any |
| 130706 | + ** data in the pendingTerms hash table. */ |
| 130707 | + rc = fts3DeleteAll(p, 1); |
| 130708 | + *pnChng = 0; |
| 130709 | + memset(aSzDel, 0, sizeof(u32) * (p->nColumn+1) * 2); |
| 130710 | + }else{ |
| 130711 | + *pnChng = *pnChng - 1; |
| 130712 | + if( p->zContentTbl==0 ){ |
| 130713 | + fts3SqlExec(&rc, p, SQL_DELETE_CONTENT, &pRowid); |
| 130714 | + } |
| 130715 | + if( p->bHasDocsize ){ |
| 130716 | + fts3SqlExec(&rc, p, SQL_DELETE_DOCSIZE, &pRowid); |
| 130717 | + } |
| 130587 | 130718 | } |
| 130588 | 130719 | } |
| 130589 | 130720 | } |
| 130590 | 130721 | |
| 130591 | 130722 | return rc; |
| | @@ -130612,11 +130743,11 @@ |
| 130612 | 130743 | ){ |
| 130613 | 130744 | Fts3Table *p = (Fts3Table *)pVtab; |
| 130614 | 130745 | int rc = SQLITE_OK; /* Return Code */ |
| 130615 | 130746 | int isRemove = 0; /* True for an UPDATE or DELETE */ |
| 130616 | 130747 | u32 *aSzIns = 0; /* Sizes of inserted documents */ |
| 130617 | | - u32 *aSzDel; /* Sizes of deleted documents */ |
| 130748 | + u32 *aSzDel = 0; /* Sizes of deleted documents */ |
| 130618 | 130749 | int nChng = 0; /* Net change in number of documents */ |
| 130619 | 130750 | int bInsertDone = 0; |
| 130620 | 130751 | |
| 130621 | 130752 | assert( p->pSegments==0 ); |
| 130622 | 130753 | assert( |
| | @@ -130640,17 +130771,17 @@ |
| 130640 | 130771 | rc = SQLITE_CONSTRAINT; |
| 130641 | 130772 | goto update_out; |
| 130642 | 130773 | } |
| 130643 | 130774 | |
| 130644 | 130775 | /* Allocate space to hold the change in document sizes */ |
| 130645 | | - aSzIns = sqlite3_malloc( sizeof(aSzIns[0])*(p->nColumn+1)*2 ); |
| 130646 | | - if( aSzIns==0 ){ |
| 130776 | + aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 ); |
| 130777 | + if( aSzDel==0 ){ |
| 130647 | 130778 | rc = SQLITE_NOMEM; |
| 130648 | 130779 | goto update_out; |
| 130649 | 130780 | } |
| 130650 | | - aSzDel = &aSzIns[p->nColumn+1]; |
| 130651 | | - memset(aSzIns, 0, sizeof(aSzIns[0])*(p->nColumn+1)*2); |
| 130781 | + aSzIns = &aSzDel[p->nColumn+1]; |
| 130782 | + memset(aSzDel, 0, sizeof(aSzDel[0])*(p->nColumn+1)*2); |
| 130652 | 130783 | |
| 130653 | 130784 | /* If this is an INSERT operation, or an UPDATE that modifies the rowid |
| 130654 | 130785 | ** value, then this operation requires constraint handling. |
| 130655 | 130786 | ** |
| 130656 | 130787 | ** If the on-conflict mode is REPLACE, this means that the existing row |
| | @@ -130731,11 +130862,11 @@ |
| 130731 | 130862 | if( p->bFts4 ){ |
| 130732 | 130863 | fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nChng); |
| 130733 | 130864 | } |
| 130734 | 130865 | |
| 130735 | 130866 | update_out: |
| 130736 | | - sqlite3_free(aSzIns); |
| 130867 | + sqlite3_free(aSzDel); |
| 130737 | 130868 | sqlite3Fts3SegmentsClose(p); |
| 130738 | 130869 | return rc; |
| 130739 | 130870 | } |
| 130740 | 130871 | |
| 130741 | 130872 | /* |
| 130742 | 130873 | |