| | @@ -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.16" |
| 677 | 677 | #define SQLITE_VERSION_NUMBER 3007016 |
| 678 | | -#define SQLITE_SOURCE_ID "2013-01-17 17:20:49 38852f158ab20bb4d7b264af987ec1538052bec3" |
| 678 | +#define SQLITE_SOURCE_ID "2013-02-13 14:04:28 7e10a62d0eb1cb2bdafb6752b78a9d368e9f21f5" |
| 679 | 679 | |
| 680 | 680 | /* |
| 681 | 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | 683 | ** |
| | @@ -1048,10 +1048,19 @@ |
| 1048 | 1048 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1049 | 1049 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1050 | 1050 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1051 | 1051 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1052 | 1052 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 1053 | +#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 1054 | +#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 1055 | +#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 1056 | +#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| 1057 | +#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) |
| 1058 | +#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) |
| 1059 | +#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) |
| 1060 | +#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) |
| 1061 | +#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) |
| 1053 | 1062 | |
| 1054 | 1063 | /* |
| 1055 | 1064 | ** CAPI3REF: Flags For File Open Operations |
| 1056 | 1065 | ** |
| 1057 | 1066 | ** These bit values are intended for use in the |
| | @@ -10018,11 +10027,11 @@ |
| 10018 | 10027 | #define SQLITE_NullCallback 0x00000020 /* Invoke the callback once if the */ |
| 10019 | 10028 | /* result set is empty */ |
| 10020 | 10029 | #define SQLITE_SqlTrace 0x00000040 /* Debug print SQL as it executes */ |
| 10021 | 10030 | #define SQLITE_VdbeListing 0x00000080 /* Debug listings of VDBE programs */ |
| 10022 | 10031 | #define SQLITE_WriteSchema 0x00000100 /* OK to update SQLITE_MASTER */ |
| 10023 | | - /* 0x00000200 Unused */ |
| 10032 | +#define SQLITE_VdbeAddopTrace 0x00000200 /* Trace sqlite3VdbeAddOp() calls */ |
| 10024 | 10033 | #define SQLITE_IgnoreChecks 0x00000400 /* Do not enforce check constraints */ |
| 10025 | 10034 | #define SQLITE_ReadUncommitted 0x0000800 /* For shared-cache mode */ |
| 10026 | 10035 | #define SQLITE_LegacyFileFmt 0x00001000 /* Create new databases in format 1 */ |
| 10027 | 10036 | #define SQLITE_FullFSync 0x00002000 /* Use full fsync on the backend */ |
| 10028 | 10037 | #define SQLITE_CkptFullFSync 0x00004000 /* Use full fsync for checkpoint */ |
| | @@ -11034,10 +11043,11 @@ |
| 11034 | 11043 | struct { |
| 11035 | 11044 | int nIn; /* Number of entries in aInLoop[] */ |
| 11036 | 11045 | struct InLoop { |
| 11037 | 11046 | int iCur; /* The VDBE cursor used by this IN operator */ |
| 11038 | 11047 | int addrInTop; /* Top of the IN loop */ |
| 11048 | + u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */ |
| 11039 | 11049 | } *aInLoop; /* Information about each nested IN operator */ |
| 11040 | 11050 | } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */ |
| 11041 | 11051 | Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 11042 | 11052 | } u; |
| 11043 | 11053 | double rOptCost; /* "Optimal" cost for this level */ |
| | @@ -11973,11 +11983,11 @@ |
| 11973 | 11983 | SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*, Table*, int, int, int*, int, int, int); |
| 11974 | 11984 | SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, int); |
| 11975 | 11985 | SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int); |
| 11976 | 11986 | SQLITE_PRIVATE void sqlite3MultiWrite(Parse*); |
| 11977 | 11987 | SQLITE_PRIVATE void sqlite3MayAbort(Parse*); |
| 11978 | | -SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, char*, int); |
| 11988 | +SQLITE_PRIVATE void sqlite3HaltConstraint(Parse*, int, int, char*, int); |
| 11979 | 11989 | SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int); |
| 11980 | 11990 | SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); |
| 11981 | 11991 | SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); |
| 11982 | 11992 | SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*); |
| 11983 | 11993 | SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int); |
| | @@ -13208,11 +13218,11 @@ |
| 13208 | 13218 | Mem *aMem; /* Array of memory cells for parent frame */ |
| 13209 | 13219 | u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */ |
| 13210 | 13220 | VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */ |
| 13211 | 13221 | void *token; /* Copy of SubProgram.token */ |
| 13212 | 13222 | i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ |
| 13213 | | - u16 nCursor; /* Number of entries in apCsr */ |
| 13223 | + int nCursor; /* Number of entries in apCsr */ |
| 13214 | 13224 | int pc; /* Program Counter in parent (calling) frame */ |
| 13215 | 13225 | int nOp; /* Size of aOp array */ |
| 13216 | 13226 | int nMem; /* Number of entries in aMem */ |
| 13217 | 13227 | int nOnceFlag; /* Number of entries in aOnceFlag */ |
| 13218 | 13228 | int nChildMem; /* Number of memory cells for child frame */ |
| | @@ -13394,11 +13404,11 @@ |
| 13394 | 13404 | int nOp; /* Number of instructions in the program */ |
| 13395 | 13405 | int nOpAlloc; /* Number of slots allocated for aOp[] */ |
| 13396 | 13406 | int nLabel; /* Number of labels used */ |
| 13397 | 13407 | int *aLabel; /* Space to hold the labels */ |
| 13398 | 13408 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 13399 | | - u16 nCursor; /* Number of slots in apCsr[] */ |
| 13409 | + int nCursor; /* Number of slots in apCsr[] */ |
| 13400 | 13410 | u32 magic; /* Magic number for sanity checking */ |
| 13401 | 13411 | char *zErrMsg; /* Error message written here */ |
| 13402 | 13412 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 13403 | 13413 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| 13404 | 13414 | Mem *aVar; /* Values for the OP_Variable opcode. */ |
| | @@ -31099,11 +31109,11 @@ |
| 31099 | 31109 | /* |
| 31100 | 31110 | ** This function outputs the specified (ANSI) string to the Win32 debugger |
| 31101 | 31111 | ** (if available). |
| 31102 | 31112 | */ |
| 31103 | 31113 | |
| 31104 | | -SQLITE_API void sqlite3_win32_write_debug(char *zBuf, int nBuf){ |
| 31114 | +SQLITE_API void sqlite3_win32_write_debug(const char *zBuf, int nBuf){ |
| 31105 | 31115 | char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE]; |
| 31106 | 31116 | int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */ |
| 31107 | 31117 | if( nMin<-1 ) nMin = -1; /* all negative values become -1. */ |
| 31108 | 31118 | assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE ); |
| 31109 | 31119 | #if defined(SQLITE_WIN32_HAS_ANSI) |
| | @@ -31732,13 +31742,14 @@ |
| 31732 | 31742 | |
| 31733 | 31743 | #if SQLITE_OS_WINCE |
| 31734 | 31744 | /************************************************************************* |
| 31735 | 31745 | ** This section contains code for WinCE only. |
| 31736 | 31746 | */ |
| 31747 | +#if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API |
| 31737 | 31748 | /* |
| 31738 | | -** Windows CE does not have a localtime() function. So create a |
| 31739 | | -** substitute. |
| 31749 | +** The MSVC CRT on Windows CE may not have a localtime() function. So |
| 31750 | +** create a substitute. |
| 31740 | 31751 | */ |
| 31741 | 31752 | /* #include <time.h> */ |
| 31742 | 31753 | struct tm *__cdecl localtime(const time_t *t) |
| 31743 | 31754 | { |
| 31744 | 31755 | static struct tm y; |
| | @@ -31758,10 +31769,11 @@ |
| 31758 | 31769 | y.tm_hour = pTm.wHour; |
| 31759 | 31770 | y.tm_min = pTm.wMinute; |
| 31760 | 31771 | y.tm_sec = pTm.wSecond; |
| 31761 | 31772 | return &y; |
| 31762 | 31773 | } |
| 31774 | +#endif |
| 31763 | 31775 | |
| 31764 | 31776 | #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] |
| 31765 | 31777 | |
| 31766 | 31778 | /* |
| 31767 | 31779 | ** Acquire a lock on the handle h |
| | @@ -31779,19 +31791,21 @@ |
| 31779 | 31791 | |
| 31780 | 31792 | /* |
| 31781 | 31793 | ** Create the mutex and shared memory used for locking in the file |
| 31782 | 31794 | ** descriptor pFile |
| 31783 | 31795 | */ |
| 31784 | | -static BOOL winceCreateLock(const char *zFilename, winFile *pFile){ |
| 31796 | +static int winceCreateLock(const char *zFilename, winFile *pFile){ |
| 31785 | 31797 | LPWSTR zTok; |
| 31786 | 31798 | LPWSTR zName; |
| 31799 | + DWORD lastErrno; |
| 31800 | + BOOL bLogged = FALSE; |
| 31787 | 31801 | BOOL bInit = TRUE; |
| 31788 | 31802 | |
| 31789 | 31803 | zName = utf8ToUnicode(zFilename); |
| 31790 | 31804 | if( zName==0 ){ |
| 31791 | 31805 | /* out of memory */ |
| 31792 | | - return FALSE; |
| 31806 | + return SQLITE_IOERR_NOMEM; |
| 31793 | 31807 | } |
| 31794 | 31808 | |
| 31795 | 31809 | /* Initialize the local lockdata */ |
| 31796 | 31810 | memset(&pFile->local, 0, sizeof(pFile->local)); |
| 31797 | 31811 | |
| | @@ -31804,13 +31818,14 @@ |
| 31804 | 31818 | |
| 31805 | 31819 | /* Create/open the named mutex */ |
| 31806 | 31820 | pFile->hMutex = osCreateMutexW(NULL, FALSE, zName); |
| 31807 | 31821 | if (!pFile->hMutex){ |
| 31808 | 31822 | pFile->lastErrno = osGetLastError(); |
| 31809 | | - winLogError(SQLITE_ERROR, pFile->lastErrno, "winceCreateLock1", zFilename); |
| 31823 | + winLogError(SQLITE_IOERR, pFile->lastErrno, |
| 31824 | + "winceCreateLock1", zFilename); |
| 31810 | 31825 | sqlite3_free(zName); |
| 31811 | | - return FALSE; |
| 31826 | + return SQLITE_IOERR; |
| 31812 | 31827 | } |
| 31813 | 31828 | |
| 31814 | 31829 | /* Acquire the mutex before continuing */ |
| 31815 | 31830 | winceMutexAcquire(pFile->hMutex); |
| 31816 | 31831 | |
| | @@ -31823,45 +31838,53 @@ |
| 31823 | 31838 | PAGE_READWRITE, 0, sizeof(winceLock), |
| 31824 | 31839 | zName); |
| 31825 | 31840 | |
| 31826 | 31841 | /* Set a flag that indicates we're the first to create the memory so it |
| 31827 | 31842 | ** must be zero-initialized */ |
| 31828 | | - if (osGetLastError() == ERROR_ALREADY_EXISTS){ |
| 31843 | + lastErrno = osGetLastError(); |
| 31844 | + if (lastErrno == ERROR_ALREADY_EXISTS){ |
| 31829 | 31845 | bInit = FALSE; |
| 31830 | 31846 | } |
| 31831 | 31847 | |
| 31832 | 31848 | sqlite3_free(zName); |
| 31833 | 31849 | |
| 31834 | 31850 | /* If we succeeded in making the shared memory handle, map it. */ |
| 31835 | | - if (pFile->hShared){ |
| 31851 | + if( pFile->hShared ){ |
| 31836 | 31852 | pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared, |
| 31837 | 31853 | FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock)); |
| 31838 | 31854 | /* If mapping failed, close the shared memory handle and erase it */ |
| 31839 | | - if (!pFile->shared){ |
| 31855 | + if( !pFile->shared ){ |
| 31840 | 31856 | pFile->lastErrno = osGetLastError(); |
| 31841 | | - winLogError(SQLITE_ERROR, pFile->lastErrno, |
| 31842 | | - "winceCreateLock2", zFilename); |
| 31857 | + winLogError(SQLITE_IOERR, pFile->lastErrno, |
| 31858 | + "winceCreateLock2", zFilename); |
| 31859 | + bLogged = TRUE; |
| 31843 | 31860 | osCloseHandle(pFile->hShared); |
| 31844 | 31861 | pFile->hShared = NULL; |
| 31845 | 31862 | } |
| 31846 | 31863 | } |
| 31847 | 31864 | |
| 31848 | 31865 | /* If shared memory could not be created, then close the mutex and fail */ |
| 31849 | | - if (pFile->hShared == NULL){ |
| 31866 | + if( pFile->hShared==NULL ){ |
| 31867 | + if( !bLogged ){ |
| 31868 | + pFile->lastErrno = lastErrno; |
| 31869 | + winLogError(SQLITE_IOERR, pFile->lastErrno, |
| 31870 | + "winceCreateLock3", zFilename); |
| 31871 | + bLogged = TRUE; |
| 31872 | + } |
| 31850 | 31873 | winceMutexRelease(pFile->hMutex); |
| 31851 | 31874 | osCloseHandle(pFile->hMutex); |
| 31852 | 31875 | pFile->hMutex = NULL; |
| 31853 | | - return FALSE; |
| 31876 | + return SQLITE_IOERR; |
| 31854 | 31877 | } |
| 31855 | 31878 | |
| 31856 | 31879 | /* Initialize the shared memory if we're supposed to */ |
| 31857 | | - if (bInit) { |
| 31880 | + if( bInit ){ |
| 31858 | 31881 | memset(pFile->shared, 0, sizeof(winceLock)); |
| 31859 | 31882 | } |
| 31860 | 31883 | |
| 31861 | 31884 | winceMutexRelease(pFile->hMutex); |
| 31862 | | - return TRUE; |
| 31885 | + return SQLITE_OK; |
| 31863 | 31886 | } |
| 31864 | 31887 | |
| 31865 | 31888 | /* |
| 31866 | 31889 | ** Destroy the part of winFile that deals with wince locks |
| 31867 | 31890 | */ |
| | @@ -32866,11 +32889,11 @@ |
| 32866 | 32889 | a[1] = win32IoerrRetryDelay; |
| 32867 | 32890 | } |
| 32868 | 32891 | return SQLITE_OK; |
| 32869 | 32892 | } |
| 32870 | 32893 | case SQLITE_FCNTL_TEMPFILENAME: { |
| 32871 | | - char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname ); |
| 32894 | + char *zTFile = sqlite3MallocZero( pFile->pVfs->mxPathname ); |
| 32872 | 32895 | if( zTFile ){ |
| 32873 | 32896 | getTempname(pFile->pVfs->mxPathname, zTFile); |
| 32874 | 32897 | *(char**)pArg = zTFile; |
| 32875 | 32898 | } |
| 32876 | 32899 | return SQLITE_OK; |
| | @@ -33802,10 +33825,11 @@ |
| 33802 | 33825 | /* If the second argument to this function is NULL, generate a |
| 33803 | 33826 | ** temporary file name to use |
| 33804 | 33827 | */ |
| 33805 | 33828 | if( !zUtf8Name ){ |
| 33806 | 33829 | assert(isDelete && !isOpenJournal); |
| 33830 | + memset(zTmpname, 0, MAX_PATH+2); |
| 33807 | 33831 | rc = getTempname(MAX_PATH+2, zTmpname); |
| 33808 | 33832 | if( rc!=SQLITE_OK ){ |
| 33809 | 33833 | return rc; |
| 33810 | 33834 | } |
| 33811 | 33835 | zUtf8Name = zTmpname; |
| | @@ -33953,15 +33977,15 @@ |
| 33953 | 33977 | pFile->ctrlFlags |= WINFILE_PSOW; |
| 33954 | 33978 | } |
| 33955 | 33979 | |
| 33956 | 33980 | #if SQLITE_OS_WINCE |
| 33957 | 33981 | if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB |
| 33958 | | - && !winceCreateLock(zName, pFile) |
| 33982 | + && (rc = winceCreateLock(zName, pFile))!=SQLITE_OK |
| 33959 | 33983 | ){ |
| 33960 | 33984 | osCloseHandle(h); |
| 33961 | 33985 | sqlite3_free(zConverted); |
| 33962 | | - return SQLITE_CANTOPEN_BKPT; |
| 33986 | + return rc; |
| 33963 | 33987 | } |
| 33964 | 33988 | if( isTemp ){ |
| 33965 | 33989 | pFile->zDeleteOnClose = zConverted; |
| 33966 | 33990 | }else |
| 33967 | 33991 | #endif |
| | @@ -58582,22 +58606,10 @@ |
| 58582 | 58606 | ** a VDBE (or an "sqlite3_stmt" as it is known to the outside world.) Prior |
| 58583 | 58607 | ** to version 2.8.7, all this code was combined into the vdbe.c source file. |
| 58584 | 58608 | ** But that file was getting too big so this subroutines were split out. |
| 58585 | 58609 | */ |
| 58586 | 58610 | |
| 58587 | | - |
| 58588 | | - |
| 58589 | | -/* |
| 58590 | | -** When debugging the code generator in a symbolic debugger, one can |
| 58591 | | -** set the sqlite3VdbeAddopTrace to 1 and all opcodes will be printed |
| 58592 | | -** as they are added to the instruction stream. |
| 58593 | | -*/ |
| 58594 | | -#ifdef SQLITE_DEBUG |
| 58595 | | -SQLITE_PRIVATE int sqlite3VdbeAddopTrace = 0; |
| 58596 | | -#endif |
| 58597 | | - |
| 58598 | | - |
| 58599 | 58611 | /* |
| 58600 | 58612 | ** Create a new virtual database engine. |
| 58601 | 58613 | */ |
| 58602 | 58614 | SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){ |
| 58603 | 58615 | Vdbe *p; |
| | @@ -58723,11 +58735,13 @@ |
| 58723 | 58735 | pOp->p3 = p3; |
| 58724 | 58736 | pOp->p4.p = 0; |
| 58725 | 58737 | pOp->p4type = P4_NOTUSED; |
| 58726 | 58738 | #ifdef SQLITE_DEBUG |
| 58727 | 58739 | pOp->zComment = 0; |
| 58728 | | - if( sqlite3VdbeAddopTrace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 58740 | + if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 58741 | + sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 58742 | + } |
| 58729 | 58743 | #endif |
| 58730 | 58744 | #ifdef VDBE_PROFILE |
| 58731 | 58745 | pOp->cycles = 0; |
| 58732 | 58746 | pOp->cnt = 0; |
| 58733 | 58747 | #endif |
| | @@ -58942,11 +58956,11 @@ |
| 58942 | 58956 | if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename |
| 58943 | 58957 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 58944 | 58958 | || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1) |
| 58945 | 58959 | #endif |
| 58946 | 58960 | || ((opcode==OP_Halt || opcode==OP_HaltIfNull) |
| 58947 | | - && (pOp->p1==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) |
| 58961 | + && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort)) |
| 58948 | 58962 | ){ |
| 58949 | 58963 | hasAbort = 1; |
| 58950 | 58964 | break; |
| 58951 | 58965 | } |
| 58952 | 58966 | } |
| | @@ -59077,11 +59091,11 @@ |
| 59077 | 59091 | pOut->p4type = P4_NOTUSED; |
| 59078 | 59092 | pOut->p4.p = 0; |
| 59079 | 59093 | pOut->p5 = 0; |
| 59080 | 59094 | #ifdef SQLITE_DEBUG |
| 59081 | 59095 | pOut->zComment = 0; |
| 59082 | | - if( sqlite3VdbeAddopTrace ){ |
| 59096 | + if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 59083 | 59097 | sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]); |
| 59084 | 59098 | } |
| 59085 | 59099 | #endif |
| 59086 | 59100 | } |
| 59087 | 59101 | p->nOp += nOp; |
| | @@ -60103,11 +60117,11 @@ |
| 60103 | 60117 | } |
| 60104 | 60118 | zCsr = p->pFree; |
| 60105 | 60119 | zEnd = &zCsr[nByte]; |
| 60106 | 60120 | }while( nByte && !db->mallocFailed ); |
| 60107 | 60121 | |
| 60108 | | - p->nCursor = (u16)nCursor; |
| 60122 | + p->nCursor = nCursor; |
| 60109 | 60123 | p->nOnceFlag = nOnce; |
| 60110 | 60124 | if( p->aVar ){ |
| 60111 | 60125 | p->nVar = (ynVar)nVar; |
| 60112 | 60126 | for(n=0; n<nVar; n++){ |
| 60113 | 60127 | p->aVar[n].flags = MEM_Null; |
| | @@ -60345,11 +60359,11 @@ |
| 60345 | 60359 | |
| 60346 | 60360 | /* If there are any write-transactions at all, invoke the commit hook */ |
| 60347 | 60361 | if( needXcommit && db->xCommitCallback ){ |
| 60348 | 60362 | rc = db->xCommitCallback(db->pCommitArg); |
| 60349 | 60363 | if( rc ){ |
| 60350 | | - return SQLITE_CONSTRAINT; |
| 60364 | + return SQLITE_CONSTRAINT_COMMITHOOK; |
| 60351 | 60365 | } |
| 60352 | 60366 | } |
| 60353 | 60367 | |
| 60354 | 60368 | /* The simple case - no more than one database file (not counting the |
| 60355 | 60369 | ** TEMP database) has a transaction active. There is no need for the |
| | @@ -60637,18 +60651,18 @@ |
| 60637 | 60651 | ** handle associated with the VM passed as an argument is about to be |
| 60638 | 60652 | ** committed. If there are outstanding deferred foreign key constraint |
| 60639 | 60653 | ** violations, return SQLITE_ERROR. Otherwise, SQLITE_OK. |
| 60640 | 60654 | ** |
| 60641 | 60655 | ** If there are outstanding FK violations and this function returns |
| 60642 | | -** SQLITE_ERROR, set the result of the VM to SQLITE_CONSTRAINT and write |
| 60643 | | -** an error message to it. Then return SQLITE_ERROR. |
| 60656 | +** SQLITE_ERROR, set the result of the VM to SQLITE_CONSTRAINT_FOREIGNKEY |
| 60657 | +** and write an error message to it. Then return SQLITE_ERROR. |
| 60644 | 60658 | */ |
| 60645 | 60659 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 60646 | 60660 | SQLITE_PRIVATE int sqlite3VdbeCheckFk(Vdbe *p, int deferred){ |
| 60647 | 60661 | sqlite3 *db = p->db; |
| 60648 | 60662 | if( (deferred && db->nDeferredCons>0) || (!deferred && p->nFkConstraint>0) ){ |
| 60649 | | - p->rc = SQLITE_CONSTRAINT; |
| 60663 | + p->rc = SQLITE_CONSTRAINT_FOREIGNKEY; |
| 60650 | 60664 | p->errorAction = OE_Abort; |
| 60651 | 60665 | sqlite3SetString(&p->zErrMsg, db, "foreign key constraint failed"); |
| 60652 | 60666 | return SQLITE_ERROR; |
| 60653 | 60667 | } |
| 60654 | 60668 | return SQLITE_OK; |
| | @@ -60759,11 +60773,11 @@ |
| 60759 | 60773 | if( rc!=SQLITE_OK ){ |
| 60760 | 60774 | if( NEVER(p->readOnly) ){ |
| 60761 | 60775 | sqlite3VdbeLeave(p); |
| 60762 | 60776 | return SQLITE_ERROR; |
| 60763 | 60777 | } |
| 60764 | | - rc = SQLITE_CONSTRAINT; |
| 60778 | + rc = SQLITE_CONSTRAINT_FOREIGNKEY; |
| 60765 | 60779 | }else{ |
| 60766 | 60780 | /* The auto-commit flag is true, the vdbe program was successful |
| 60767 | 60781 | ** or hit an 'OR FAIL' constraint and there are no deferred foreign |
| 60768 | 60782 | ** key constraints to hold up the transaction. This means a commit |
| 60769 | 60783 | ** is required. */ |
| | @@ -60802,11 +60816,11 @@ |
| 60802 | 60816 | ** current statement error code. |
| 60803 | 60817 | */ |
| 60804 | 60818 | if( eStatementOp ){ |
| 60805 | 60819 | rc = sqlite3VdbeCloseStatement(p, eStatementOp); |
| 60806 | 60820 | if( rc ){ |
| 60807 | | - if( p->rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ){ |
| 60821 | + if( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ){ |
| 60808 | 60822 | p->rc = rc; |
| 60809 | 60823 | sqlite3DbFree(db, p->zErrMsg); |
| 60810 | 60824 | p->zErrMsg = 0; |
| 60811 | 60825 | } |
| 60812 | 60826 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| | @@ -61043,11 +61057,11 @@ |
| 61043 | 61057 | sqlite3DbFree(db, p->aLabel); |
| 61044 | 61058 | sqlite3DbFree(db, p->aColName); |
| 61045 | 61059 | sqlite3DbFree(db, p->zSql); |
| 61046 | 61060 | sqlite3DbFree(db, p->pFree); |
| 61047 | 61061 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 61048 | | - sqlite3_free(p->zExplain); |
| 61062 | + sqlite3DbFree(db, p->zExplain); |
| 61049 | 61063 | sqlite3DbFree(db, p->pExplain); |
| 61050 | 61064 | #endif |
| 61051 | 61065 | } |
| 61052 | 61066 | |
| 61053 | 61067 | /* |
| | @@ -64799,11 +64813,11 @@ |
| 64799 | 64813 | rc = sqlite3VdbeHalt(p); |
| 64800 | 64814 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 64801 | 64815 | if( rc==SQLITE_BUSY ){ |
| 64802 | 64816 | p->rc = rc = SQLITE_BUSY; |
| 64803 | 64817 | }else{ |
| 64804 | | - assert( rc==SQLITE_OK || p->rc==SQLITE_CONSTRAINT ); |
| 64818 | + assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); |
| 64805 | 64819 | assert( rc==SQLITE_OK || db->nDeferredCons>0 ); |
| 64806 | 64820 | rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; |
| 64807 | 64821 | } |
| 64808 | 64822 | goto vdbe_return; |
| 64809 | 64823 | } |
| | @@ -70131,11 +70145,11 @@ |
| 70131 | 70145 | importVtabErrMsg(p, u.cr.pVtab); |
| 70132 | 70146 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 70133 | 70147 | assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) ); |
| 70134 | 70148 | db->lastRowid = lastRowid = u.cr.rowid; |
| 70135 | 70149 | } |
| 70136 | | - if( rc==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 70150 | + if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 70137 | 70151 | if( pOp->p5==OE_Ignore ){ |
| 70138 | 70152 | rc = SQLITE_OK; |
| 70139 | 70153 | }else{ |
| 70140 | 70154 | p->errorAction = ((pOp->p5==OE_Replace) ? OE_Abort : pOp->p5); |
| 70141 | 70155 | } |
| | @@ -72775,12 +72789,12 @@ |
| 72775 | 72789 | |
| 72776 | 72790 | pTab = pItem->pTab; |
| 72777 | 72791 | assert( pTab!=0 && pTab->zName!=0 ); |
| 72778 | 72792 | assert( pTab->nCol>0 ); |
| 72779 | 72793 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){ |
| 72780 | | - ExprList *pEList = pItem->pSelect->pEList; |
| 72781 | 72794 | int hit = 0; |
| 72795 | + pEList = pItem->pSelect->pEList; |
| 72782 | 72796 | for(j=0; j<pEList->nExpr; j++){ |
| 72783 | 72797 | if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){ |
| 72784 | 72798 | cnt++; |
| 72785 | 72799 | cntTab = 2; |
| 72786 | 72800 | pMatch = pItem; |
| | @@ -76776,11 +76790,12 @@ |
| 76776 | 76790 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 76777 | 76791 | if( pExpr->affinity==OE_Ignore ){ |
| 76778 | 76792 | sqlite3VdbeAddOp4( |
| 76779 | 76793 | v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0); |
| 76780 | 76794 | }else{ |
| 76781 | | - sqlite3HaltConstraint(pParse, pExpr->affinity, pExpr->u.zToken, 0); |
| 76795 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER, |
| 76796 | + pExpr->affinity, pExpr->u.zToken, 0); |
| 76782 | 76797 | } |
| 76783 | 76798 | |
| 76784 | 76799 | break; |
| 76785 | 76800 | } |
| 76786 | 76801 | #endif |
| | @@ -83247,12 +83262,12 @@ |
| 83247 | 83262 | if( pIndex->onError!=OE_None ){ |
| 83248 | 83263 | int j2 = sqlite3VdbeCurrentAddr(v) + 3; |
| 83249 | 83264 | sqlite3VdbeAddOp2(v, OP_Goto, 0, j2); |
| 83250 | 83265 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 83251 | 83266 | sqlite3VdbeAddOp3(v, OP_SorterCompare, iSorter, j2, regRecord); |
| 83252 | | - sqlite3HaltConstraint( |
| 83253 | | - pParse, OE_Abort, "indexed columns are not unique", P4_STATIC |
| 83267 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE, |
| 83268 | + OE_Abort, "indexed columns are not unique", P4_STATIC |
| 83254 | 83269 | ); |
| 83255 | 83270 | }else{ |
| 83256 | 83271 | addr2 = sqlite3VdbeCurrentAddr(v); |
| 83257 | 83272 | } |
| 83258 | 83273 | sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord); |
| | @@ -83274,12 +83289,12 @@ |
| 83274 | 83289 | ** opcode use the values stored within seems dangerous. However, since |
| 83275 | 83290 | ** we can be sure that no other temp registers have been allocated |
| 83276 | 83291 | ** since sqlite3ReleaseTempRange() was called, it is safe to do so. |
| 83277 | 83292 | */ |
| 83278 | 83293 | sqlite3VdbeAddOp4(v, OP_IsUnique, iIdx, j2, regRowid, pRegKey, P4_INT32); |
| 83279 | | - sqlite3HaltConstraint( |
| 83280 | | - pParse, OE_Abort, "indexed columns are not unique", P4_STATIC); |
| 83294 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE, |
| 83295 | + "indexed columns are not unique", P4_STATIC); |
| 83281 | 83296 | } |
| 83282 | 83297 | sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0); |
| 83283 | 83298 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 83284 | 83299 | #endif |
| 83285 | 83300 | sqlite3ReleaseTempReg(pParse, regRecord); |
| | @@ -84492,16 +84507,23 @@ |
| 84492 | 84507 | /* |
| 84493 | 84508 | ** Code an OP_Halt that causes the vdbe to return an SQLITE_CONSTRAINT |
| 84494 | 84509 | ** error. The onError parameter determines which (if any) of the statement |
| 84495 | 84510 | ** and/or current transaction is rolled back. |
| 84496 | 84511 | */ |
| 84497 | | -SQLITE_PRIVATE void sqlite3HaltConstraint(Parse *pParse, int onError, char *p4, int p4type){ |
| 84512 | +SQLITE_PRIVATE void sqlite3HaltConstraint( |
| 84513 | + Parse *pParse, /* Parsing context */ |
| 84514 | + int errCode, /* extended error code */ |
| 84515 | + int onError, /* Constraint type */ |
| 84516 | + char *p4, /* Error message */ |
| 84517 | + int p4type /* P4_STATIC or P4_TRANSIENT */ |
| 84518 | +){ |
| 84498 | 84519 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 84520 | + assert( (errCode&0xff)==SQLITE_CONSTRAINT ); |
| 84499 | 84521 | if( onError==OE_Abort ){ |
| 84500 | 84522 | sqlite3MayAbort(pParse); |
| 84501 | 84523 | } |
| 84502 | | - sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CONSTRAINT, onError, 0, p4, p4type); |
| 84524 | + sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); |
| 84503 | 84525 | } |
| 84504 | 84526 | |
| 84505 | 84527 | /* |
| 84506 | 84528 | ** Check to see if pIndex uses the collating sequence pColl. Return |
| 84507 | 84529 | ** true if it does and false if it does not. |
| | @@ -87484,12 +87506,13 @@ |
| 87484 | 87506 | /* |
| 87485 | 87507 | ** Deferred and Immediate FKs |
| 87486 | 87508 | ** -------------------------- |
| 87487 | 87509 | ** |
| 87488 | 87510 | ** Foreign keys in SQLite come in two flavours: deferred and immediate. |
| 87489 | | -** If an immediate foreign key constraint is violated, SQLITE_CONSTRAINT |
| 87490 | | -** is returned and the current statement transaction rolled back. If a |
| 87511 | +** If an immediate foreign key constraint is violated, |
| 87512 | +** SQLITE_CONSTRAINT_FOREIGNKEY is returned and the current |
| 87513 | +** statement transaction rolled back. If a |
| 87491 | 87514 | ** deferred foreign key constraint is violated, no action is taken |
| 87492 | 87515 | ** immediately. However if the application attempts to commit the |
| 87493 | 87516 | ** transaction before fixing the constraint violation, the attempt fails. |
| 87494 | 87517 | ** |
| 87495 | 87518 | ** Deferred constraints are implemented using a simple counter associated |
| | @@ -87549,11 +87572,12 @@ |
| 87549 | 87572 | ** row is inserted. |
| 87550 | 87573 | ** |
| 87551 | 87574 | ** Immediate constraints are usually handled similarly. The only difference |
| 87552 | 87575 | ** is that the counter used is stored as part of each individual statement |
| 87553 | 87576 | ** object (struct Vdbe). If, after the statement has run, its immediate |
| 87554 | | -** constraint counter is greater than zero, it returns SQLITE_CONSTRAINT |
| 87577 | +** constraint counter is greater than zero, |
| 87578 | +** it returns SQLITE_CONSTRAINT_FOREIGNKEY |
| 87555 | 87579 | ** and the statement transaction is rolled back. An exception is an INSERT |
| 87556 | 87580 | ** statement that inserts a single row only (no triggers). In this case, |
| 87557 | 87581 | ** instead of using a counter, an exception is thrown immediately if the |
| 87558 | 87582 | ** INSERT violates a foreign key constraint. This is necessary as such |
| 87559 | 87583 | ** an INSERT does not open a statement transaction. |
| | @@ -87889,12 +87913,12 @@ |
| 87889 | 87913 | /* Special case: If this is an INSERT statement that will insert exactly |
| 87890 | 87914 | ** one row into the table, raise a constraint immediately instead of |
| 87891 | 87915 | ** incrementing a counter. This is necessary as the VM code is being |
| 87892 | 87916 | ** generated for will not open a statement transaction. */ |
| 87893 | 87917 | assert( nIncr==1 ); |
| 87894 | | - sqlite3HaltConstraint( |
| 87895 | | - pParse, OE_Abort, "foreign key constraint failed", P4_STATIC |
| 87918 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 87919 | + OE_Abort, "foreign key constraint failed", P4_STATIC |
| 87896 | 87920 | ); |
| 87897 | 87921 | }else{ |
| 87898 | 87922 | if( nIncr>0 && pFKey->isDeferred==0 ){ |
| 87899 | 87923 | sqlite3ParseToplevel(pParse)->mayAbort = 1; |
| 87900 | 87924 | } |
| | @@ -88130,12 +88154,12 @@ |
| 88130 | 88154 | /* If the DELETE has generated immediate foreign key constraint |
| 88131 | 88155 | ** violations, halt the VDBE and return an error at this point, before |
| 88132 | 88156 | ** any modifications to the schema are made. This is because statement |
| 88133 | 88157 | ** transactions are not able to rollback schema changes. */ |
| 88134 | 88158 | sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2); |
| 88135 | | - sqlite3HaltConstraint( |
| 88136 | | - pParse, OE_Abort, "foreign key constraint failed", P4_STATIC |
| 88159 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY, |
| 88160 | + OE_Abort, "foreign key constraint failed", P4_STATIC |
| 88137 | 88161 | ); |
| 88138 | 88162 | |
| 88139 | 88163 | if( iSkip ){ |
| 88140 | 88164 | sqlite3VdbeResolveLabel(v, iSkip); |
| 88141 | 88165 | } |
| | @@ -89935,11 +89959,11 @@ |
| 89935 | 89959 | sqlite3MayAbort(pParse); |
| 89936 | 89960 | case OE_Rollback: |
| 89937 | 89961 | case OE_Fail: { |
| 89938 | 89962 | char *zMsg; |
| 89939 | 89963 | sqlite3VdbeAddOp3(v, OP_HaltIfNull, |
| 89940 | | - SQLITE_CONSTRAINT, onError, regData+i); |
| 89964 | + SQLITE_CONSTRAINT_NOTNULL, onError, regData+i); |
| 89941 | 89965 | zMsg = sqlite3MPrintf(db, "%s.%s may not be NULL", |
| 89942 | 89966 | pTab->zName, pTab->aCol[i].zName); |
| 89943 | 89967 | sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); |
| 89944 | 89968 | break; |
| 89945 | 89969 | } |
| | @@ -89975,11 +89999,12 @@ |
| 89975 | 89999 | if( zConsName ){ |
| 89976 | 90000 | zConsName = sqlite3MPrintf(db, "constraint %s failed", zConsName); |
| 89977 | 90001 | }else{ |
| 89978 | 90002 | zConsName = 0; |
| 89979 | 90003 | } |
| 89980 | | - sqlite3HaltConstraint(pParse, onError, zConsName, P4_DYNAMIC); |
| 90004 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK, |
| 90005 | + onError, zConsName, P4_DYNAMIC); |
| 89981 | 90006 | } |
| 89982 | 90007 | sqlite3VdbeResolveLabel(v, allOk); |
| 89983 | 90008 | } |
| 89984 | 90009 | } |
| 89985 | 90010 | #endif /* !defined(SQLITE_OMIT_CHECK) */ |
| | @@ -90006,12 +90031,12 @@ |
| 90006 | 90031 | /* Fall thru into the next case */ |
| 90007 | 90032 | } |
| 90008 | 90033 | case OE_Rollback: |
| 90009 | 90034 | case OE_Abort: |
| 90010 | 90035 | case OE_Fail: { |
| 90011 | | - sqlite3HaltConstraint( |
| 90012 | | - pParse, onError, "PRIMARY KEY must be unique", P4_STATIC); |
| 90036 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY, |
| 90037 | + onError, "PRIMARY KEY must be unique", P4_STATIC); |
| 90013 | 90038 | break; |
| 90014 | 90039 | } |
| 90015 | 90040 | case OE_Replace: { |
| 90016 | 90041 | /* If there are DELETE triggers on this table and the |
| 90017 | 90042 | ** recursive-triggers flag is set, call GenerateRowDelete() to |
| | @@ -90134,11 +90159,12 @@ |
| 90134 | 90159 | sqlite3StrAccumAppend(&errMsg, zCol, -1); |
| 90135 | 90160 | } |
| 90136 | 90161 | sqlite3StrAccumAppend(&errMsg, |
| 90137 | 90162 | pIdx->nColumn>1 ? " are not unique" : " is not unique", -1); |
| 90138 | 90163 | zErr = sqlite3StrAccumFinish(&errMsg); |
| 90139 | | - sqlite3HaltConstraint(pParse, onError, zErr, 0); |
| 90164 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE, |
| 90165 | + onError, zErr, 0); |
| 90140 | 90166 | sqlite3DbFree(errMsg.db, zErr); |
| 90141 | 90167 | break; |
| 90142 | 90168 | } |
| 90143 | 90169 | case OE_Ignore: { |
| 90144 | 90170 | assert( seenReplace==0 ); |
| | @@ -90542,12 +90568,12 @@ |
| 90542 | 90568 | regData = sqlite3GetTempReg(pParse); |
| 90543 | 90569 | regRowid = sqlite3GetTempReg(pParse); |
| 90544 | 90570 | if( pDest->iPKey>=0 ){ |
| 90545 | 90571 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 90546 | 90572 | addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid); |
| 90547 | | - sqlite3HaltConstraint( |
| 90548 | | - pParse, onError, "PRIMARY KEY must be unique", P4_STATIC); |
| 90573 | + sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_PRIMARYKEY, |
| 90574 | + onError, "PRIMARY KEY must be unique", P4_STATIC); |
| 90549 | 90575 | sqlite3VdbeJumpHere(v, addr2); |
| 90550 | 90576 | autoIncStep(pParse, regAutoinc, regRowid); |
| 90551 | 90577 | }else if( pDest->pIndex==0 ){ |
| 90552 | 90578 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| 90553 | 90579 | }else{ |
| | @@ -91000,10 +91026,24 @@ |
| 91000 | 91026 | int (*wal_checkpoint)(sqlite3*,const char*); |
| 91001 | 91027 | void *(*wal_hook)(sqlite3*,int(*)(void*,sqlite3*,const char*,int),void*); |
| 91002 | 91028 | int (*blob_reopen)(sqlite3_blob*,sqlite3_int64); |
| 91003 | 91029 | int (*vtab_config)(sqlite3*,int op,...); |
| 91004 | 91030 | int (*vtab_on_conflict)(sqlite3*); |
| 91031 | + /* Version 3.7.16 and later */ |
| 91032 | + int (*close_v2)(sqlite3*); |
| 91033 | + const char *(*db_filename)(sqlite3*,const char*); |
| 91034 | + int (*db_readonly)(sqlite3*,const char*); |
| 91035 | + int (*db_release_memory)(sqlite3*); |
| 91036 | + const char *(*errstr)(int); |
| 91037 | + int (*stmt_busy)(sqlite3_stmt*); |
| 91038 | + int (*stmt_readonly)(sqlite3_stmt*); |
| 91039 | + int (*stricmp)(const char*,const char*); |
| 91040 | + int (*uri_boolean)(const char*,const char*,int); |
| 91041 | + sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64); |
| 91042 | + const char *(*uri_parameter)(const char*,const char*); |
| 91043 | + char *(*vsnprintf)(int,char*,const char*,va_list); |
| 91044 | + int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*); |
| 91005 | 91045 | }; |
| 91006 | 91046 | |
| 91007 | 91047 | /* |
| 91008 | 91048 | ** The following macros redefine the API routines so that they are |
| 91009 | 91049 | ** redirected throught the global sqlite3_api structure. |
| | @@ -91203,10 +91243,24 @@ |
| 91203 | 91243 | #define sqlite3_wal_checkpoint sqlite3_api->wal_checkpoint |
| 91204 | 91244 | #define sqlite3_wal_hook sqlite3_api->wal_hook |
| 91205 | 91245 | #define sqlite3_blob_reopen sqlite3_api->blob_reopen |
| 91206 | 91246 | #define sqlite3_vtab_config sqlite3_api->vtab_config |
| 91207 | 91247 | #define sqlite3_vtab_on_conflict sqlite3_api->vtab_on_conflict |
| 91248 | +/* Version 3.7.16 and later */ |
| 91249 | +#define sqlite3_close_v2 sqlite3_api->close_v2 |
| 91250 | +#define sqlite3_db_filename sqlite3_api->db_filename |
| 91251 | +#define sqlite3_db_readonly sqlite3_api->db_readonly |
| 91252 | +#define sqlite3_db_release_memory sqlite3_api->db_release_memory |
| 91253 | +#define sqlite3_errstr sqlite3_api->errstr |
| 91254 | +#define sqlite3_stmt_busy sqlite3_api->stmt_busy |
| 91255 | +#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly |
| 91256 | +#define sqlite3_stricmp sqlite3_api->stricmp |
| 91257 | +#define sqlite3_uri_boolean sqlite3_api->uri_boolean |
| 91258 | +#define sqlite3_uri_int64 sqlite3_api->uri_int64 |
| 91259 | +#define sqlite3_uri_parameter sqlite3_api->uri_parameter |
| 91260 | +#define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf |
| 91261 | +#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2 |
| 91208 | 91262 | #endif /* SQLITE_CORE */ |
| 91209 | 91263 | |
| 91210 | 91264 | #define SQLITE_EXTENSION_INIT1 const sqlite3_api_routines *sqlite3_api = 0; |
| 91211 | 91265 | #define SQLITE_EXTENSION_INIT2(v) sqlite3_api = v; |
| 91212 | 91266 | |
| | @@ -92038,10 +92092,13 @@ |
| 92038 | 92092 | #endif |
| 92039 | 92093 | #ifdef SQLITE_DEBUG |
| 92040 | 92094 | { "sql_trace", SQLITE_SqlTrace }, |
| 92041 | 92095 | { "vdbe_listing", SQLITE_VdbeListing }, |
| 92042 | 92096 | { "vdbe_trace", SQLITE_VdbeTrace }, |
| 92097 | + { "vdbe_addoptrace", SQLITE_VdbeAddopTrace}, |
| 92098 | + { "vdbe_debug", SQLITE_SqlTrace | SQLITE_VdbeListing |
| 92099 | + | SQLITE_VdbeTrace }, |
| 92043 | 92100 | #endif |
| 92044 | 92101 | #ifndef SQLITE_OMIT_CHECK |
| 92045 | 92102 | { "ignore_check_constraints", SQLITE_IgnoreChecks }, |
| 92046 | 92103 | #endif |
| 92047 | 92104 | /* The following is VERY experimental */ |
| | @@ -96198,10 +96255,12 @@ |
| 96198 | 96255 | switch( p->op ){ |
| 96199 | 96256 | case TK_ALL: { |
| 96200 | 96257 | int addr = 0; |
| 96201 | 96258 | int nLimit; |
| 96202 | 96259 | assert( !pPrior->pLimit ); |
| 96260 | + pPrior->iLimit = p->iLimit; |
| 96261 | + pPrior->iOffset = p->iOffset; |
| 96203 | 96262 | pPrior->pLimit = p->pLimit; |
| 96204 | 96263 | pPrior->pOffset = p->pOffset; |
| 96205 | 96264 | explainSetInteger(iSub1, pParse->iNextSelectId); |
| 96206 | 96265 | rc = sqlite3Select(pParse, pPrior, &dest); |
| 96207 | 96266 | p->pLimit = 0; |
| | @@ -97454,16 +97513,19 @@ |
| 97454 | 97513 | */ |
| 97455 | 97514 | for(pSub=pSub->pPrior; pSub; pSub=pSub->pPrior){ |
| 97456 | 97515 | Select *pNew; |
| 97457 | 97516 | ExprList *pOrderBy = p->pOrderBy; |
| 97458 | 97517 | Expr *pLimit = p->pLimit; |
| 97518 | + Expr *pOffset = p->pOffset; |
| 97459 | 97519 | Select *pPrior = p->pPrior; |
| 97460 | 97520 | p->pOrderBy = 0; |
| 97461 | 97521 | p->pSrc = 0; |
| 97462 | 97522 | p->pPrior = 0; |
| 97463 | 97523 | p->pLimit = 0; |
| 97524 | + p->pOffset = 0; |
| 97464 | 97525 | pNew = sqlite3SelectDup(db, p, 0); |
| 97526 | + p->pOffset = pOffset; |
| 97465 | 97527 | p->pLimit = pLimit; |
| 97466 | 97528 | p->pOrderBy = pOrderBy; |
| 97467 | 97529 | p->pSrc = pSrc; |
| 97468 | 97530 | p->op = TK_ALL; |
| 97469 | 97531 | p->pRightmost = 0; |
| | @@ -97784,18 +97846,19 @@ |
| 97784 | 97846 | SrcList *pTabList; |
| 97785 | 97847 | ExprList *pEList; |
| 97786 | 97848 | struct SrcList_item *pFrom; |
| 97787 | 97849 | sqlite3 *db = pParse->db; |
| 97788 | 97850 | Expr *pE, *pRight, *pExpr; |
| 97851 | + u16 selFlags = p->selFlags; |
| 97789 | 97852 | |
| 97853 | + p->selFlags |= SF_Expanded; |
| 97790 | 97854 | if( db->mallocFailed ){ |
| 97791 | 97855 | return WRC_Abort; |
| 97792 | 97856 | } |
| 97793 | | - if( NEVER(p->pSrc==0) || (p->selFlags & SF_Expanded)!=0 ){ |
| 97857 | + if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){ |
| 97794 | 97858 | return WRC_Prune; |
| 97795 | 97859 | } |
| 97796 | | - p->selFlags |= SF_Expanded; |
| 97797 | 97860 | pTabList = p->pSrc; |
| 97798 | 97861 | pEList = p->pEList; |
| 97799 | 97862 | |
| 97800 | 97863 | /* Make sure cursor numbers have been assigned to all entries in |
| 97801 | 97864 | ** the FROM clause of the SELECT statement. |
| | @@ -97834,10 +97897,16 @@ |
| 97834 | 97897 | }else{ |
| 97835 | 97898 | /* An ordinary table or view name in the FROM clause */ |
| 97836 | 97899 | assert( pFrom->pTab==0 ); |
| 97837 | 97900 | pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom); |
| 97838 | 97901 | if( pTab==0 ) return WRC_Abort; |
| 97902 | + if( pTab->nRef==0xffff ){ |
| 97903 | + sqlite3ErrorMsg(pParse, "too many references to \"%s\": max 65535", |
| 97904 | + pTab->zName); |
| 97905 | + pFrom->pTab = 0; |
| 97906 | + return WRC_Abort; |
| 97907 | + } |
| 97839 | 97908 | pTab->nRef++; |
| 97840 | 97909 | #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) |
| 97841 | 97910 | if( pTab->pSelect || IsVirtual(pTab) ){ |
| 97842 | 97911 | /* We reach here if the named table is a really a view */ |
| 97843 | 97912 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| | @@ -98146,10 +98215,11 @@ |
| 98146 | 98215 | NameContext *pOuterNC /* Name context for container */ |
| 98147 | 98216 | ){ |
| 98148 | 98217 | sqlite3 *db; |
| 98149 | 98218 | if( NEVER(p==0) ) return; |
| 98150 | 98219 | db = pParse->db; |
| 98220 | + if( db->mallocFailed ) return; |
| 98151 | 98221 | if( p->selFlags & SF_HasTypeInfo ) return; |
| 98152 | 98222 | sqlite3SelectExpand(pParse, p); |
| 98153 | 98223 | if( pParse->nErr || db->mallocFailed ) return; |
| 98154 | 98224 | sqlite3ResolveSelectNames(pParse, p, pOuterNC); |
| 98155 | 98225 | if( pParse->nErr || db->mallocFailed ) return; |
| | @@ -99231,11 +99301,14 @@ |
| 99231 | 99301 | SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){ |
| 99232 | 99302 | if( p==0 ){ |
| 99233 | 99303 | sqlite3ExplainPrintf(pVdbe, "(null-select)"); |
| 99234 | 99304 | return; |
| 99235 | 99305 | } |
| 99236 | | - while( p->pPrior ) p = p->pPrior; |
| 99306 | + while( p->pPrior ){ |
| 99307 | + p->pPrior->pNext = p; |
| 99308 | + p = p->pPrior; |
| 99309 | + } |
| 99237 | 99310 | sqlite3ExplainPush(pVdbe); |
| 99238 | 99311 | while( p ){ |
| 99239 | 99312 | explainOneSelect(pVdbe, p); |
| 99240 | 99313 | p = p->pNext; |
| 99241 | 99314 | if( p==0 ) break; |
| | @@ -102850,11 +102923,10 @@ |
| 102850 | 102923 | ** subclauses points to the WhereClause object for the whole clause. |
| 102851 | 102924 | */ |
| 102852 | 102925 | struct WhereClause { |
| 102853 | 102926 | Parse *pParse; /* The parser context */ |
| 102854 | 102927 | WhereMaskSet *pMaskSet; /* Mapping of table cursor numbers to bitmasks */ |
| 102855 | | - Bitmask vmask; /* Bitmask identifying virtual table cursors */ |
| 102856 | 102928 | WhereClause *pOuter; /* Outer conjunction */ |
| 102857 | 102929 | u8 op; /* Split operator. TK_AND or TK_OR */ |
| 102858 | 102930 | u16 wctrlFlags; /* Might include WHERE_AND_ONLY */ |
| 102859 | 102931 | int nTerm; /* Number of terms */ |
| 102860 | 102932 | int nSlot; /* Number of entries in a[] */ |
| | @@ -103027,11 +103099,10 @@ |
| 103027 | 103099 | pWC->pMaskSet = pMaskSet; |
| 103028 | 103100 | pWC->pOuter = 0; |
| 103029 | 103101 | pWC->nTerm = 0; |
| 103030 | 103102 | pWC->nSlot = ArraySize(pWC->aStatic); |
| 103031 | 103103 | pWC->a = pWC->aStatic; |
| 103032 | | - pWC->vmask = 0; |
| 103033 | 103104 | pWC->wctrlFlags = wctrlFlags; |
| 103034 | 103105 | } |
| 103035 | 103106 | |
| 103036 | 103107 | /* Forward reference */ |
| 103037 | 103108 | static void whereClauseClear(WhereClause*); |
| | @@ -103627,11 +103698,11 @@ |
| 103627 | 103698 | ** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*') |
| 103628 | 103699 | ** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6) |
| 103629 | 103700 | ** |
| 103630 | 103701 | ** CASE 1: |
| 103631 | 103702 | ** |
| 103632 | | -** If all subterms are of the form T.C=expr for some single column of C |
| 103703 | +** If all subterms are of the form T.C=expr for some single column of C and |
| 103633 | 103704 | ** a single table T (as shown in example B above) then create a new virtual |
| 103634 | 103705 | ** term that is an equivalent IN expression. In other words, if the term |
| 103635 | 103706 | ** being analyzed is: |
| 103636 | 103707 | ** |
| 103637 | 103708 | ** x = expr1 OR expr2 = x OR x = expr3 |
| | @@ -103715,11 +103786,11 @@ |
| 103715 | 103786 | |
| 103716 | 103787 | /* |
| 103717 | 103788 | ** Compute the set of tables that might satisfy cases 1 or 2. |
| 103718 | 103789 | */ |
| 103719 | 103790 | indexable = ~(Bitmask)0; |
| 103720 | | - chngToIN = ~(pWC->vmask); |
| 103791 | + chngToIN = ~(Bitmask)0; |
| 103721 | 103792 | for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0 && indexable; i--, pOrTerm++){ |
| 103722 | 103793 | if( (pOrTerm->eOperator & WO_SINGLE)==0 ){ |
| 103723 | 103794 | WhereAndInfo *pAndInfo; |
| 103724 | 103795 | assert( (pOrTerm->wtFlags & (TERM_ANDINFO|TERM_ORINFO))==0 ); |
| 103725 | 103796 | chngToIN = 0; |
| | @@ -104982,12 +105053,13 @@ |
| 104982 | 105053 | Table *pTab = pSrc->pTab; |
| 104983 | 105054 | sqlite3_index_info *pIdxInfo; |
| 104984 | 105055 | struct sqlite3_index_constraint *pIdxCons; |
| 104985 | 105056 | struct sqlite3_index_constraint_usage *pUsage; |
| 104986 | 105057 | WhereTerm *pTerm; |
| 104987 | | - int i, j; |
| 105058 | + int i, j, k; |
| 104988 | 105059 | int nOrderBy; |
| 105060 | + int sortOrder; /* Sort order for IN clauses */ |
| 104989 | 105061 | int bAllowIN; /* Allow IN optimizations */ |
| 104990 | 105062 | double rCost; |
| 104991 | 105063 | |
| 104992 | 105064 | /* Make sure wsFlags is initialized to some sane value. Otherwise, if the |
| 104993 | 105065 | ** malloc in allocateIndexInfo() fails and this function returns leaving |
| | @@ -105082,22 +105154,31 @@ |
| 105082 | 105154 | |
| 105083 | 105155 | if( vtabBestIndex(pParse, pTab, pIdxInfo) ){ |
| 105084 | 105156 | return; |
| 105085 | 105157 | } |
| 105086 | 105158 | |
| 105159 | + sortOrder = SQLITE_SO_ASC; |
| 105087 | 105160 | pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint; |
| 105088 | 105161 | for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){ |
| 105089 | 105162 | if( pUsage[i].argvIndex>0 ){ |
| 105090 | 105163 | j = pIdxCons->iTermOffset; |
| 105091 | 105164 | pTerm = &pWC->a[j]; |
| 105092 | 105165 | p->cost.used |= pTerm->prereqRight; |
| 105093 | | - if( (pTerm->eOperator & WO_IN)!=0 && pUsage[i].omit==0 ){ |
| 105094 | | - /* Do not attempt to use an IN constraint if the virtual table |
| 105095 | | - ** says that the equivalent EQ constraint cannot be safely omitted. |
| 105096 | | - ** If we do attempt to use such a constraint, some rows might be |
| 105097 | | - ** repeated in the output. */ |
| 105098 | | - break; |
| 105166 | + if( (pTerm->eOperator & WO_IN)!=0 ){ |
| 105167 | + if( pUsage[i].omit==0 ){ |
| 105168 | + /* Do not attempt to use an IN constraint if the virtual table |
| 105169 | + ** says that the equivalent EQ constraint cannot be safely omitted. |
| 105170 | + ** If we do attempt to use such a constraint, some rows might be |
| 105171 | + ** repeated in the output. */ |
| 105172 | + break; |
| 105173 | + } |
| 105174 | + for(k=0; k<pIdxInfo->nOrderBy; k++){ |
| 105175 | + if( pIdxInfo->aOrderBy[k].iColumn==pIdxCons->iColumn ){ |
| 105176 | + sortOrder = pIdxInfo->aOrderBy[k].desc; |
| 105177 | + break; |
| 105178 | + } |
| 105179 | + } |
| 105099 | 105180 | } |
| 105100 | 105181 | } |
| 105101 | 105182 | } |
| 105102 | 105183 | if( i>=pIdxInfo->nConstraint ) break; |
| 105103 | 105184 | } |
| | @@ -105123,11 +105204,12 @@ |
| 105123 | 105204 | }else{ |
| 105124 | 105205 | p->cost.rCost = rCost; |
| 105125 | 105206 | } |
| 105126 | 105207 | p->cost.plan.u.pVtabIdx = pIdxInfo; |
| 105127 | 105208 | if( pIdxInfo->orderByConsumed ){ |
| 105128 | | - p->cost.plan.wsFlags |= WHERE_ORDERED; |
| 105209 | + assert( sortOrder==0 || sortOrder==1 ); |
| 105210 | + p->cost.plan.wsFlags |= WHERE_ORDERED + sortOrder*WHERE_REVERSE; |
| 105129 | 105211 | p->cost.plan.nOBSat = nOrderBy; |
| 105130 | 105212 | }else{ |
| 105131 | 105213 | p->cost.plan.nOBSat = p->i ? p->aLevel[p->i-1].plan.nOBSat : 0; |
| 105132 | 105214 | } |
| 105133 | 105215 | p->cost.plan.nEq = 0; |
| | @@ -105720,14 +105802,11 @@ |
| 105720 | 105802 | pConstraint = findTerm(p->pWC, base, iColumn, p->notReady, |
| 105721 | 105803 | WO_EQ|WO_ISNULL|WO_IN, pIdx); |
| 105722 | 105804 | if( pConstraint==0 ){ |
| 105723 | 105805 | isEq = 0; |
| 105724 | 105806 | }else if( (pConstraint->eOperator & WO_IN)!=0 ){ |
| 105725 | | - /* Constraints of the form: "X IN ..." cannot be used with an ORDER BY |
| 105726 | | - ** because we do not know in what order the values on the RHS of the IN |
| 105727 | | - ** operator will occur. */ |
| 105728 | | - break; |
| 105807 | + isEq = 0; |
| 105729 | 105808 | }else if( (pConstraint->eOperator & WO_ISNULL)!=0 ){ |
| 105730 | 105809 | uniqueNotNull = 0; |
| 105731 | 105810 | isEq = 1; /* "X IS NULL" means X has only a single value */ |
| 105732 | 105811 | }else if( pConstraint->prereqRight==0 ){ |
| 105733 | 105812 | isEq = 1; /* Constraint "X=constant" means X has only a single value */ |
| | @@ -106027,12 +106106,12 @@ |
| 106027 | 106106 | ** constraint for all columns in the index, then this search will find |
| 106028 | 106107 | ** at most a single row. In this case set the WHERE_UNIQUE flag to |
| 106029 | 106108 | ** indicate this to the caller. |
| 106030 | 106109 | ** |
| 106031 | 106110 | ** Otherwise, if the search may find more than one row, test to see if |
| 106032 | | - ** there is a range constraint on indexed column (pc.plan.nEq+1) that can be |
| 106033 | | - ** optimized using the index. |
| 106111 | + ** there is a range constraint on indexed column (pc.plan.nEq+1) that |
| 106112 | + ** can be optimized using the index. |
| 106034 | 106113 | */ |
| 106035 | 106114 | if( pc.plan.nEq==pProbe->nColumn && pProbe->onError!=OE_None ){ |
| 106036 | 106115 | testcase( pc.plan.wsFlags & WHERE_COLUMN_IN ); |
| 106037 | 106116 | testcase( pc.plan.wsFlags & WHERE_COLUMN_NULL ); |
| 106038 | 106117 | if( (pc.plan.wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_NULL))==0 ){ |
| | @@ -106369,11 +106448,12 @@ |
| 106369 | 106448 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 106370 | 106449 | if( IsVirtual(p->pSrc->pTab) ){ |
| 106371 | 106450 | sqlite3_index_info *pIdxInfo = 0; |
| 106372 | 106451 | p->ppIdxInfo = &pIdxInfo; |
| 106373 | 106452 | bestVirtualIndex(p); |
| 106374 | | - if( pIdxInfo->needToFreeIdxStr ){ |
| 106453 | + assert( pIdxInfo!=0 || p->pParse->db->mallocFailed ); |
| 106454 | + if( pIdxInfo && pIdxInfo->needToFreeIdxStr ){ |
| 106375 | 106455 | sqlite3_free(pIdxInfo->idxStr); |
| 106376 | 106456 | } |
| 106377 | 106457 | sqlite3DbFree(p->pParse->db, pIdxInfo); |
| 106378 | 106458 | }else |
| 106379 | 106459 | #endif |
| | @@ -106493,16 +106573,17 @@ |
| 106493 | 106573 | #ifndef SQLITE_OMIT_SUBQUERY |
| 106494 | 106574 | }else{ |
| 106495 | 106575 | int eType; |
| 106496 | 106576 | int iTab; |
| 106497 | 106577 | struct InLoop *pIn; |
| 106578 | + u8 bRev = (pLevel->plan.wsFlags & WHERE_REVERSE)!=0; |
| 106498 | 106579 | |
| 106499 | 106580 | assert( pX->op==TK_IN ); |
| 106500 | 106581 | iReg = iTarget; |
| 106501 | 106582 | eType = sqlite3FindInIndex(pParse, pX, 0); |
| 106502 | 106583 | iTab = pX->iTable; |
| 106503 | | - sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); |
| 106584 | + sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0); |
| 106504 | 106585 | assert( pLevel->plan.wsFlags & WHERE_IN_ABLE ); |
| 106505 | 106586 | if( pLevel->u.in.nIn==0 ){ |
| 106506 | 106587 | pLevel->addrNxt = sqlite3VdbeMakeLabel(v); |
| 106507 | 106588 | } |
| 106508 | 106589 | pLevel->u.in.nIn++; |
| | @@ -106516,10 +106597,11 @@ |
| 106516 | 106597 | if( eType==IN_INDEX_ROWID ){ |
| 106517 | 106598 | pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg); |
| 106518 | 106599 | }else{ |
| 106519 | 106600 | pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg); |
| 106520 | 106601 | } |
| 106602 | + pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next; |
| 106521 | 106603 | sqlite3VdbeAddOp1(v, OP_IsNull, iReg); |
| 106522 | 106604 | }else{ |
| 106523 | 106605 | pLevel->u.in.nIn = 0; |
| 106524 | 106606 | } |
| 106525 | 106607 | #endif |
| | @@ -106884,12 +106966,12 @@ |
| 106884 | 106966 | iReg = sqlite3GetTempRange(pParse, nConstraint+2); |
| 106885 | 106967 | addrNotFound = pLevel->addrBrk; |
| 106886 | 106968 | for(j=1; j<=nConstraint; j++){ |
| 106887 | 106969 | for(k=0; k<nConstraint; k++){ |
| 106888 | 106970 | if( aUsage[k].argvIndex==j ){ |
| 106889 | | - WhereTerm *pTerm = &pWC->a[aConstraint[k].iTermOffset]; |
| 106890 | 106971 | int iTarget = iReg+j+1; |
| 106972 | + pTerm = &pWC->a[aConstraint[k].iTermOffset]; |
| 106891 | 106973 | if( pTerm->eOperator & WO_IN ){ |
| 106892 | 106974 | codeEqualityTerm(pParse, pTerm, pLevel, iTarget); |
| 106893 | 106975 | addrNotFound = pLevel->addrNxt; |
| 106894 | 106976 | }else{ |
| 106895 | 106977 | sqlite3ExprCode(pParse, pTerm->pExpr->pRight, iTarget); |
| | @@ -107767,28 +107849,17 @@ |
| 107767 | 107849 | ** its Expr.iRightJoinTable value to find the bitmask of the right table |
| 107768 | 107850 | ** of the join. Subtracting one from the right table bitmask gives a |
| 107769 | 107851 | ** bitmask for all tables to the left of the join. Knowing the bitmask |
| 107770 | 107852 | ** for all tables to the left of a left join is important. Ticket #3015. |
| 107771 | 107853 | ** |
| 107772 | | - ** Configure the WhereClause.vmask variable so that bits that correspond |
| 107773 | | - ** to virtual table cursors are set. This is used to selectively disable |
| 107774 | | - ** the OR-to-IN transformation in exprAnalyzeOrTerm(). It is not helpful |
| 107775 | | - ** with virtual tables. |
| 107776 | | - ** |
| 107777 | 107854 | ** Note that bitmasks are created for all pTabList->nSrc tables in |
| 107778 | 107855 | ** pTabList, not just the first nTabList tables. nTabList is normally |
| 107779 | 107856 | ** equal to pTabList->nSrc but might be shortened to 1 if the |
| 107780 | 107857 | ** WHERE_ONETABLE_ONLY flag is set. |
| 107781 | 107858 | */ |
| 107782 | | - assert( sWBI.pWC->vmask==0 && pMaskSet->n==0 ); |
| 107783 | 107859 | for(ii=0; ii<pTabList->nSrc; ii++){ |
| 107784 | 107860 | createMask(pMaskSet, pTabList->a[ii].iCursor); |
| 107785 | | -#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 107786 | | - if( ALWAYS(pTabList->a[ii].pTab) && IsVirtual(pTabList->a[ii].pTab) ){ |
| 107787 | | - sWBI.pWC->vmask |= ((Bitmask)1 << ii); |
| 107788 | | - } |
| 107789 | | -#endif |
| 107790 | 107861 | } |
| 107791 | 107862 | #ifndef NDEBUG |
| 107792 | 107863 | { |
| 107793 | 107864 | Bitmask toTheLeft = 0; |
| 107794 | 107865 | for(ii=0; ii<pTabList->nSrc; ii++){ |
| | @@ -108268,11 +108339,11 @@ |
| 108268 | 108339 | struct InLoop *pIn; |
| 108269 | 108340 | int j; |
| 108270 | 108341 | sqlite3VdbeResolveLabel(v, pLevel->addrNxt); |
| 108271 | 108342 | for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){ |
| 108272 | 108343 | sqlite3VdbeJumpHere(v, pIn->addrInTop+1); |
| 108273 | | - sqlite3VdbeAddOp2(v, OP_Next, pIn->iCur, pIn->addrInTop); |
| 108344 | + sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop); |
| 108274 | 108345 | sqlite3VdbeJumpHere(v, pIn->addrInTop-1); |
| 108275 | 108346 | } |
| 108276 | 108347 | sqlite3DbFree(db, pLevel->u.in.aInLoop); |
| 108277 | 108348 | } |
| 108278 | 108349 | sqlite3VdbeResolveLabel(v, pLevel->addrBrk); |
| 108279 | 108350 | |