Fossil SCM
Update the built-in SQLite to the latest 3.7.6 alpha.
Commit
c38a726932b625b0b54e66c5868e64143d237132
Parent
ba0852c9df6b3f8…
2 files changed
+238
-171
+1
-1
+238
-171
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -650,11 +650,11 @@ | ||
| 650 | 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | 652 | */ |
| 653 | 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | -#define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a" | |
| 655 | +#define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61" | |
| 656 | 656 | |
| 657 | 657 | /* |
| 658 | 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 660 | ** |
| @@ -11206,10 +11206,13 @@ | ||
| 11206 | 11206 | SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*); |
| 11207 | 11207 | SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*); |
| 11208 | 11208 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 11209 | 11209 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 11210 | 11210 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 11211 | +SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); | |
| 11212 | +SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); | |
| 11213 | +SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); | |
| 11211 | 11214 | |
| 11212 | 11215 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 11213 | 11216 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 11214 | 11217 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 11215 | 11218 | void(*)(void*)); |
| @@ -18792,11 +18795,15 @@ | ||
| 18792 | 18795 | v = va_arg(ap,long int); |
| 18793 | 18796 | }else{ |
| 18794 | 18797 | v = va_arg(ap,int); |
| 18795 | 18798 | } |
| 18796 | 18799 | if( v<0 ){ |
| 18797 | - longvalue = -v; | |
| 18800 | + if( v==SMALLEST_INT64 ){ | |
| 18801 | + longvalue = ((u64)1)<<63; | |
| 18802 | + }else{ | |
| 18803 | + longvalue = -v; | |
| 18804 | + } | |
| 18798 | 18805 | prefix = '-'; |
| 18799 | 18806 | }else{ |
| 18800 | 18807 | longvalue = v; |
| 18801 | 18808 | if( flag_plussign ) prefix = '+'; |
| 18802 | 18809 | else if( flag_blanksign ) prefix = ' '; |
| @@ -20566,64 +20573,84 @@ | ||
| 20566 | 20573 | return c; |
| 20567 | 20574 | } |
| 20568 | 20575 | |
| 20569 | 20576 | |
| 20570 | 20577 | /* |
| 20571 | -** Convert zNum to a 64-bit signed integer and write | |
| 20572 | -** the value of the integer into *pNum. | |
| 20573 | -** If zNum is exactly 9223372036854665808, return 2. | |
| 20574 | -** This is a special case as the context will determine | |
| 20575 | -** if it is too big (used as a negative). | |
| 20576 | -** If zNum is not an integer or is an integer that | |
| 20577 | -** is too large to be expressed with 64 bits, | |
| 20578 | -** then return 1. Otherwise return 0. | |
| 20578 | +** Convert zNum to a 64-bit signed integer. | |
| 20579 | +** | |
| 20580 | +** If the zNum value is representable as a 64-bit twos-complement | |
| 20581 | +** integer, then write that value into *pNum and return 0. | |
| 20582 | +** | |
| 20583 | +** If zNum is exactly 9223372036854665808, return 2. This special | |
| 20584 | +** case is broken out because while 9223372036854665808 cannot be a | |
| 20585 | +** signed 64-bit integer, its negative -9223372036854665808 can be. | |
| 20586 | +** | |
| 20587 | +** If zNum is too big for a 64-bit integer and is not | |
| 20588 | +** 9223372036854665808 then return 1. | |
| 20579 | 20589 | ** |
| 20580 | 20590 | ** length is the number of bytes in the string (bytes, not characters). |
| 20581 | 20591 | ** The string is not necessarily zero-terminated. The encoding is |
| 20582 | 20592 | ** given by enc. |
| 20583 | 20593 | */ |
| 20584 | 20594 | SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){ |
| 20585 | 20595 | int incr = (enc==SQLITE_UTF8?1:2); |
| 20586 | - i64 v = 0; | |
| 20596 | + u64 u = 0; | |
| 20587 | 20597 | int neg = 0; /* assume positive */ |
| 20588 | 20598 | int i; |
| 20589 | 20599 | int c = 0; |
| 20590 | 20600 | const char *zStart; |
| 20591 | 20601 | const char *zEnd = zNum + length; |
| 20592 | 20602 | if( enc==SQLITE_UTF16BE ) zNum++; |
| 20593 | 20603 | while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr; |
| 20594 | - if( zNum>=zEnd ) goto do_atoi_calc; | |
| 20595 | - if( *zNum=='-' ){ | |
| 20596 | - neg = 1; | |
| 20597 | - zNum+=incr; | |
| 20598 | - }else if( *zNum=='+' ){ | |
| 20599 | - zNum+=incr; | |
| 20600 | - } | |
| 20601 | -do_atoi_calc: | |
| 20604 | + if( zNum<zEnd ){ | |
| 20605 | + if( *zNum=='-' ){ | |
| 20606 | + neg = 1; | |
| 20607 | + zNum+=incr; | |
| 20608 | + }else if( *zNum=='+' ){ | |
| 20609 | + zNum+=incr; | |
| 20610 | + } | |
| 20611 | + } | |
| 20602 | 20612 | zStart = zNum; |
| 20603 | 20613 | while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */ |
| 20604 | 20614 | for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){ |
| 20605 | - v = v*10 + c - '0'; | |
| 20615 | + u = u*10 + c - '0'; | |
| 20606 | 20616 | } |
| 20607 | - *pNum = neg ? -v : v; | |
| 20617 | + if( u>LARGEST_INT64 ){ | |
| 20618 | + *pNum = SMALLEST_INT64; | |
| 20619 | + }else if( neg ){ | |
| 20620 | + *pNum = -(i64)u; | |
| 20621 | + }else{ | |
| 20622 | + *pNum = (i64)u; | |
| 20623 | + } | |
| 20608 | 20624 | testcase( i==18 ); |
| 20609 | 20625 | testcase( i==19 ); |
| 20610 | 20626 | testcase( i==20 ); |
| 20611 | 20627 | if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){ |
| 20612 | 20628 | /* zNum is empty or contains non-numeric text or is longer |
| 20613 | 20629 | ** than 19 digits (thus guaranteeing that it is too large) */ |
| 20614 | 20630 | return 1; |
| 20615 | 20631 | }else if( i<19*incr ){ |
| 20616 | 20632 | /* Less than 19 digits, so we know that it fits in 64 bits */ |
| 20633 | + assert( u<=LARGEST_INT64 ); | |
| 20617 | 20634 | return 0; |
| 20618 | 20635 | }else{ |
| 20619 | - /* 19-digit numbers must be no larger than 9223372036854775807 if positive | |
| 20620 | - ** or 9223372036854775808 if negative. Note that 9223372036854665808 | |
| 20621 | - ** is 2^63. Return 1 if to large */ | |
| 20622 | - c=compare2pow63(zNum, incr); | |
| 20623 | - if( c==0 && neg==0 ) return 2; /* too big, exactly 9223372036854665808 */ | |
| 20624 | - return c<neg ? 0 : 1; | |
| 20636 | + /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */ | |
| 20637 | + c = compare2pow63(zNum, incr); | |
| 20638 | + if( c<0 ){ | |
| 20639 | + /* zNum is less than 9223372036854775808 so it fits */ | |
| 20640 | + assert( u<=LARGEST_INT64 ); | |
| 20641 | + return 0; | |
| 20642 | + }else if( c>0 ){ | |
| 20643 | + /* zNum is greater than 9223372036854775808 so it overflows */ | |
| 20644 | + return 1; | |
| 20645 | + }else{ | |
| 20646 | + /* zNum is exactly 9223372036854775808. Fits if negative. The | |
| 20647 | + ** special case 2 overflow if positive */ | |
| 20648 | + assert( u-1==LARGEST_INT64 ); | |
| 20649 | + assert( (*pNum)==SMALLEST_INT64 ); | |
| 20650 | + return neg ? 0 : 2; | |
| 20651 | + } | |
| 20625 | 20652 | } |
| 20626 | 20653 | } |
| 20627 | 20654 | |
| 20628 | 20655 | /* |
| 20629 | 20656 | ** If zNum represents an integer that will fit in 32-bits, then set |
| @@ -21185,10 +21212,68 @@ | ||
| 21185 | 21212 | return 0; |
| 21186 | 21213 | }else{ |
| 21187 | 21214 | return 1; |
| 21188 | 21215 | } |
| 21189 | 21216 | } |
| 21217 | + | |
| 21218 | +/* | |
| 21219 | +** Attempt to add, substract, or multiply the 64-bit signed value iB against | |
| 21220 | +** the other 64-bit signed integer at *pA and store the result in *pA. | |
| 21221 | +** Return 0 on success. Or if the operation would have resulted in an | |
| 21222 | +** overflow, leave *pA unchanged and return 1. | |
| 21223 | +*/ | |
| 21224 | +SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ | |
| 21225 | + i64 iA = *pA; | |
| 21226 | + testcase( iA==0 ); testcase( iA==1 ); | |
| 21227 | + testcase( iB==-1 ); testcase( iB==0 ); | |
| 21228 | + if( iB>=0 ){ | |
| 21229 | + testcase( iA>0 && LARGEST_INT64 - iA == iB ); | |
| 21230 | + testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 ); | |
| 21231 | + if( iA>0 && LARGEST_INT64 - iA < iB ) return 1; | |
| 21232 | + *pA += iB; | |
| 21233 | + }else{ | |
| 21234 | + testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 ); | |
| 21235 | + testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); | |
| 21236 | + if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; | |
| 21237 | + *pA += iB; | |
| 21238 | + } | |
| 21239 | + return 0; | |
| 21240 | +} | |
| 21241 | +SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ | |
| 21242 | + testcase( iB==SMALLEST_INT64+1 ); | |
| 21243 | + if( iB==SMALLEST_INT64 ){ | |
| 21244 | + testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); | |
| 21245 | + if( (*pA)>=0 ) return 1; | |
| 21246 | + *pA -= iB; | |
| 21247 | + return 0; | |
| 21248 | + }else{ | |
| 21249 | + return sqlite3AddInt64(pA, -iB); | |
| 21250 | + } | |
| 21251 | +} | |
| 21252 | +#define TWOPOWER32 (((i64)1)<<32) | |
| 21253 | +#define TWOPOWER31 (((i64)1)<<31) | |
| 21254 | +SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ | |
| 21255 | + i64 iA = *pA; | |
| 21256 | + i64 iA1, iA0, iB1, iB0, r; | |
| 21257 | + | |
| 21258 | + iA1 = iA/TWOPOWER32; | |
| 21259 | + iA0 = iA % TWOPOWER32; | |
| 21260 | + iB1 = iB/TWOPOWER32; | |
| 21261 | + iB0 = iB % TWOPOWER32; | |
| 21262 | + if( iA1*iB1 != 0 ) return 1; | |
| 21263 | + assert( iA1*iB0==0 || iA0*iB1==0 ); | |
| 21264 | + r = iA1*iB0 + iA0*iB1; | |
| 21265 | + testcase( r==(-TWOPOWER31)-1 ); | |
| 21266 | + testcase( r==(-TWOPOWER31) ); | |
| 21267 | + testcase( r==TWOPOWER31 ); | |
| 21268 | + testcase( r==TWOPOWER31-1 ); | |
| 21269 | + if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1; | |
| 21270 | + r *= TWOPOWER32; | |
| 21271 | + if( sqlite3AddInt64(&r, iA0*iB0) ) return 1; | |
| 21272 | + *pA = r; | |
| 21273 | + return 0; | |
| 21274 | +} | |
| 21190 | 21275 | |
| 21191 | 21276 | /************** End of util.c ************************************************/ |
| 21192 | 21277 | /************** Begin file hash.c ********************************************/ |
| 21193 | 21278 | /* |
| 21194 | 21279 | ** 2001 September 22 |
| @@ -23930,18 +24015,19 @@ | ||
| 23930 | 24015 | ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). |
| 23931 | 24016 | ** The two subsequent arguments should be the name of the OS function that |
| 23932 | 24017 | ** failed (e.g. "unlink", "open") and the the associated file-system path, |
| 23933 | 24018 | ** if any. |
| 23934 | 24019 | */ |
| 23935 | -#define unixLogError(a,b,c) unixLogError_x(a,b,c,__LINE__) | |
| 23936 | -static int unixLogError_x( | |
| 24020 | +#define unixLogError(a,b,c) unixLogErrorAtLine(a,b,c,__LINE__) | |
| 24021 | +static int unixLogErrorAtLine( | |
| 23937 | 24022 | int errcode, /* SQLite error code */ |
| 23938 | 24023 | const char *zFunc, /* Name of OS function that failed */ |
| 23939 | 24024 | const char *zPath, /* File path associated with error */ |
| 23940 | 24025 | int iLine /* Source line number where error occurred */ |
| 23941 | 24026 | ){ |
| 23942 | 24027 | char *zErr; /* Message from strerror() or equivalent */ |
| 24028 | + int iErrno = errno; /* Saved syscall error number */ | |
| 23943 | 24029 | |
| 23944 | 24030 | /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use |
| 23945 | 24031 | ** the strerror() function to obtain the human-readable error message |
| 23946 | 24032 | ** equivalent to errno. Otherwise, use strerror_r(). |
| 23947 | 24033 | */ |
| @@ -23963,58 +24049,63 @@ | ||
| 23963 | 24049 | ** could lead to a segfault though. |
| 23964 | 24050 | */ |
| 23965 | 24051 | #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU) |
| 23966 | 24052 | zErr = |
| 23967 | 24053 | # endif |
| 23968 | - strerror_r(errno, aErr, sizeof(aErr)-1); | |
| 24054 | + strerror_r(iErrno, aErr, sizeof(aErr)-1); | |
| 23969 | 24055 | |
| 23970 | 24056 | #elif SQLITE_THREADSAFE |
| 23971 | 24057 | /* This is a threadsafe build, but strerror_r() is not available. */ |
| 23972 | 24058 | zErr = ""; |
| 23973 | 24059 | #else |
| 23974 | 24060 | /* Non-threadsafe build, use strerror(). */ |
| 23975 | - zErr = strerror(errno); | |
| 24061 | + zErr = strerror(iErrno); | |
| 23976 | 24062 | #endif |
| 23977 | 24063 | |
| 23978 | 24064 | assert( errcode!=SQLITE_OK ); |
| 24065 | + if( zPath==0 ) zPath = ""; | |
| 23979 | 24066 | sqlite3_log(errcode, |
| 23980 | - "os_unix.c: %s() at line %d - \"%s\" errno=%d path=%s", | |
| 23981 | - zFunc, iLine, zErr, errno, (zPath ? zPath : "n/a") | |
| 24067 | + "os_unix.c:%d: (%d) %s(%s) - %s", | |
| 24068 | + iLine, iErrno, zFunc, zPath, zErr | |
| 23982 | 24069 | ); |
| 23983 | 24070 | |
| 23984 | 24071 | return errcode; |
| 23985 | 24072 | } |
| 23986 | 24073 | |
| 24074 | +/* | |
| 24075 | +** Close a file descriptor. | |
| 24076 | +** | |
| 24077 | +** We assume that close() almost always works, since it is only in a | |
| 24078 | +** very sick application or on a very sick platform that it might fail. | |
| 24079 | +** If it does fail, simply leak the file descriptor, but do log the | |
| 24080 | +** error. | |
| 24081 | +** | |
| 24082 | +** Note that it is not safe to retry close() after EINTR since the | |
| 24083 | +** file descriptor might have already been reused by another thread. | |
| 24084 | +** So we don't even try to recover from an EINTR. Just log the error | |
| 24085 | +** and move on. | |
| 24086 | +*/ | |
| 24087 | +static void robust_close(unixFile *pFile, int h, int lineno){ | |
| 24088 | + if( close(h) ){ | |
| 24089 | + unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close", | |
| 24090 | + pFile ? pFile->zPath : 0, lineno); | |
| 24091 | + } | |
| 24092 | +} | |
| 23987 | 24093 | |
| 23988 | 24094 | /* |
| 23989 | 24095 | ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. |
| 23990 | -** If all such file descriptors are closed without error, the list is | |
| 23991 | -** cleared and SQLITE_OK returned. | |
| 23992 | -** | |
| 23993 | -** Otherwise, if an error occurs, then successfully closed file descriptor | |
| 23994 | -** entries are removed from the list, and SQLITE_IOERR_CLOSE returned. | |
| 23995 | -** not deleted and SQLITE_IOERR_CLOSE returned. | |
| 23996 | 24096 | */ |
| 23997 | -static int closePendingFds(unixFile *pFile){ | |
| 23998 | - int rc = SQLITE_OK; | |
| 24097 | +static void closePendingFds(unixFile *pFile){ | |
| 23999 | 24098 | unixInodeInfo *pInode = pFile->pInode; |
| 24000 | - UnixUnusedFd *pError = 0; | |
| 24001 | 24099 | UnixUnusedFd *p; |
| 24002 | 24100 | UnixUnusedFd *pNext; |
| 24003 | 24101 | for(p=pInode->pUnused; p; p=pNext){ |
| 24004 | 24102 | pNext = p->pNext; |
| 24005 | - if( close(p->fd) ){ | |
| 24006 | - pFile->lastErrno = errno; | |
| 24007 | - rc = unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath); | |
| 24008 | - p->pNext = pError; | |
| 24009 | - pError = p; | |
| 24010 | - }else{ | |
| 24011 | - sqlite3_free(p); | |
| 24012 | - } | |
| 24013 | - } | |
| 24014 | - pInode->pUnused = pError; | |
| 24015 | - return rc; | |
| 24103 | + robust_close(pFile, p->fd, __LINE__); | |
| 24104 | + sqlite3_free(p); | |
| 24105 | + } | |
| 24106 | + pInode->pUnused = 0; | |
| 24016 | 24107 | } |
| 24017 | 24108 | |
| 24018 | 24109 | /* |
| 24019 | 24110 | ** Release a unixInodeInfo structure previously allocated by findInodeInfo(). |
| 24020 | 24111 | ** |
| @@ -24621,14 +24712,11 @@ | ||
| 24621 | 24712 | ** was deferred because of outstanding locks. |
| 24622 | 24713 | */ |
| 24623 | 24714 | pInode->nLock--; |
| 24624 | 24715 | assert( pInode->nLock>=0 ); |
| 24625 | 24716 | if( pInode->nLock==0 ){ |
| 24626 | - int rc2 = closePendingFds(pFile); | |
| 24627 | - if( rc==SQLITE_OK ){ | |
| 24628 | - rc = rc2; | |
| 24629 | - } | |
| 24717 | + closePendingFds(pFile); | |
| 24630 | 24718 | } |
| 24631 | 24719 | } |
| 24632 | 24720 | |
| 24633 | 24721 | end_unlock: |
| 24634 | 24722 | unixLeaveMutex(); |
| @@ -24659,24 +24747,16 @@ | ||
| 24659 | 24747 | */ |
| 24660 | 24748 | static int closeUnixFile(sqlite3_file *id){ |
| 24661 | 24749 | unixFile *pFile = (unixFile*)id; |
| 24662 | 24750 | if( pFile ){ |
| 24663 | 24751 | if( pFile->dirfd>=0 ){ |
| 24664 | - int err = close(pFile->dirfd); | |
| 24665 | - if( err ){ | |
| 24666 | - pFile->lastErrno = errno; | |
| 24667 | - return unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath); | |
| 24668 | - }else{ | |
| 24669 | - pFile->dirfd=-1; | |
| 24670 | - } | |
| 24752 | + robust_close(pFile, pFile->dirfd, __LINE__); | |
| 24753 | + pFile->dirfd=-1; | |
| 24671 | 24754 | } |
| 24672 | 24755 | if( pFile->h>=0 ){ |
| 24673 | - int err = close(pFile->h); | |
| 24674 | - if( err ){ | |
| 24675 | - pFile->lastErrno = errno; | |
| 24676 | - return unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath); | |
| 24677 | - } | |
| 24756 | + robust_close(pFile, pFile->h, __LINE__); | |
| 24757 | + pFile->h = -1; | |
| 24678 | 24758 | } |
| 24679 | 24759 | #if OS_VXWORKS |
| 24680 | 24760 | if( pFile->pId ){ |
| 24681 | 24761 | if( pFile->isDelete ){ |
| 24682 | 24762 | unlink(pFile->pId->zCanonicalName); |
| @@ -24882,14 +24962,11 @@ | ||
| 24882 | 24962 | pFile->lastErrno = tErrno; |
| 24883 | 24963 | } |
| 24884 | 24964 | } |
| 24885 | 24965 | return rc; |
| 24886 | 24966 | } |
| 24887 | - if( close(fd) ){ | |
| 24888 | - pFile->lastErrno = errno; | |
| 24889 | - rc = SQLITE_IOERR_CLOSE; | |
| 24890 | - } | |
| 24967 | + robust_close(pFile, fd, __LINE__); | |
| 24891 | 24968 | |
| 24892 | 24969 | /* got it, set the type and return ok */ |
| 24893 | 24970 | pFile->eFileLock = eFileLock; |
| 24894 | 24971 | return rc; |
| 24895 | 24972 | } |
| @@ -25777,11 +25854,11 @@ | ||
| 25777 | 25854 | } |
| 25778 | 25855 | if( rc==SQLITE_OK ){ |
| 25779 | 25856 | pInode->nLock--; |
| 25780 | 25857 | assert( pInode->nLock>=0 ); |
| 25781 | 25858 | if( pInode->nLock==0 ){ |
| 25782 | - rc = closePendingFds(pFile); | |
| 25859 | + closePendingFds(pFile); | |
| 25783 | 25860 | } |
| 25784 | 25861 | } |
| 25785 | 25862 | } |
| 25786 | 25863 | |
| 25787 | 25864 | unixLeaveMutex(); |
| @@ -26210,11 +26287,10 @@ | ||
| 26210 | 26287 | if( rc ){ |
| 26211 | 26288 | pFile->lastErrno = errno; |
| 26212 | 26289 | return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath); |
| 26213 | 26290 | } |
| 26214 | 26291 | if( pFile->dirfd>=0 ){ |
| 26215 | - int err; | |
| 26216 | 26292 | OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, |
| 26217 | 26293 | HAVE_FULLFSYNC, isFullsync)); |
| 26218 | 26294 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 26219 | 26295 | /* The directory sync is only attempted if full_fsync is |
| 26220 | 26296 | ** turned off or unavailable. If a full_fsync occurred above, |
| @@ -26229,17 +26305,13 @@ | ||
| 26229 | 26305 | */ |
| 26230 | 26306 | /* pFile->lastErrno = errno; */ |
| 26231 | 26307 | /* return SQLITE_IOERR; */ |
| 26232 | 26308 | } |
| 26233 | 26309 | #endif |
| 26234 | - err = close(pFile->dirfd); /* Only need to sync once, so close the */ | |
| 26235 | - if( err==0 ){ /* directory when we are done */ | |
| 26236 | - pFile->dirfd = -1; | |
| 26237 | - }else{ | |
| 26238 | - pFile->lastErrno = errno; | |
| 26239 | - rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath); | |
| 26240 | - } | |
| 26310 | + /* Only need to sync once, so close the directory when we are done */ | |
| 26311 | + robust_close(pFile, pFile->dirfd, __LINE__); | |
| 26312 | + pFile->dirfd = -1; | |
| 26241 | 26313 | } |
| 26242 | 26314 | return rc; |
| 26243 | 26315 | } |
| 26244 | 26316 | |
| 26245 | 26317 | /* |
| @@ -26602,11 +26674,14 @@ | ||
| 26602 | 26674 | if( p->mutex ) sqlite3_mutex_free(p->mutex); |
| 26603 | 26675 | for(i=0; i<p->nRegion; i++){ |
| 26604 | 26676 | munmap(p->apRegion[i], p->szRegion); |
| 26605 | 26677 | } |
| 26606 | 26678 | sqlite3_free(p->apRegion); |
| 26607 | - if( p->h>=0 ) close(p->h); | |
| 26679 | + if( p->h>=0 ){ | |
| 26680 | + robust_close(pFd, p->h, __LINE__); | |
| 26681 | + p->h = -1; | |
| 26682 | + } | |
| 26608 | 26683 | p->pInode->pShmNode = 0; |
| 26609 | 26684 | sqlite3_free(p); |
| 26610 | 26685 | } |
| 26611 | 26686 | } |
| 26612 | 26687 | |
| @@ -27413,11 +27488,11 @@ | ||
| 27413 | 27488 | ** |
| 27414 | 27489 | ** If scenario (a) caused the error then things are not so safe. The |
| 27415 | 27490 | ** implicit assumption here is that if fstat() fails, things are in |
| 27416 | 27491 | ** such bad shape that dropping a lock or two doesn't matter much. |
| 27417 | 27492 | */ |
| 27418 | - close(h); | |
| 27493 | + robust_close(pNew, h, __LINE__); | |
| 27419 | 27494 | h = -1; |
| 27420 | 27495 | } |
| 27421 | 27496 | unixLeaveMutex(); |
| 27422 | 27497 | } |
| 27423 | 27498 | |
| @@ -27439,11 +27514,11 @@ | ||
| 27439 | 27514 | srandomdev(); |
| 27440 | 27515 | unixEnterMutex(); |
| 27441 | 27516 | rc = findInodeInfo(pNew, &pNew->pInode); |
| 27442 | 27517 | if( rc!=SQLITE_OK ){ |
| 27443 | 27518 | sqlite3_free(pNew->lockingContext); |
| 27444 | - close(h); | |
| 27519 | + robust_close(pNew, h, __LINE__); | |
| 27445 | 27520 | h = -1; |
| 27446 | 27521 | } |
| 27447 | 27522 | unixLeaveMutex(); |
| 27448 | 27523 | } |
| 27449 | 27524 | } |
| @@ -27490,20 +27565,20 @@ | ||
| 27490 | 27565 | #endif |
| 27491 | 27566 | |
| 27492 | 27567 | pNew->lastErrno = 0; |
| 27493 | 27568 | #if OS_VXWORKS |
| 27494 | 27569 | if( rc!=SQLITE_OK ){ |
| 27495 | - if( h>=0 ) close(h); | |
| 27570 | + if( h>=0 ) robust_close(pNew, h, __LINE__); | |
| 27496 | 27571 | h = -1; |
| 27497 | 27572 | unlink(zFilename); |
| 27498 | 27573 | isDelete = 0; |
| 27499 | 27574 | } |
| 27500 | 27575 | pNew->isDelete = isDelete; |
| 27501 | 27576 | #endif |
| 27502 | 27577 | if( rc!=SQLITE_OK ){ |
| 27503 | - if( dirfd>=0 ) close(dirfd); /* silent leak if fail, already in error */ | |
| 27504 | - if( h>=0 ) close(h); | |
| 27578 | + if( dirfd>=0 ) robust_close(pNew, dirfd, __LINE__); | |
| 27579 | + if( h>=0 ) robust_close(pNew, h, __LINE__); | |
| 27505 | 27580 | }else{ |
| 27506 | 27581 | pNew->pMethod = pLockingStyle; |
| 27507 | 27582 | OpenCounter(+1); |
| 27508 | 27583 | } |
| 27509 | 27584 | return rc; |
| @@ -27911,11 +27986,11 @@ | ||
| 27911 | 27986 | /* It is safe to close fd at this point, because it is guaranteed not |
| 27912 | 27987 | ** to be open on a database file. If it were open on a database file, |
| 27913 | 27988 | ** it would not be safe to close as this would release any locks held |
| 27914 | 27989 | ** on the file by this process. */ |
| 27915 | 27990 | assert( eType!=SQLITE_OPEN_MAIN_DB ); |
| 27916 | - close(fd); /* silently leak if fail, already in error */ | |
| 27991 | + robust_close(p, fd, __LINE__); | |
| 27917 | 27992 | goto open_finished; |
| 27918 | 27993 | } |
| 27919 | 27994 | } |
| 27920 | 27995 | |
| 27921 | 27996 | #ifdef FD_CLOEXEC |
| @@ -27927,12 +28002,12 @@ | ||
| 27927 | 28002 | |
| 27928 | 28003 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE |
| 27929 | 28004 | struct statfs fsInfo; |
| 27930 | 28005 | if( fstatfs(fd, &fsInfo) == -1 ){ |
| 27931 | 28006 | ((unixFile*)pFile)->lastErrno = errno; |
| 27932 | - if( dirfd>=0 ) close(dirfd); /* silently leak if fail, in error */ | |
| 27933 | - close(fd); /* silently leak if fail, in error */ | |
| 28007 | + if( dirfd>=0 ) robust_close(p, dirfd, __LINE__); | |
| 28008 | + robust_close(p, fd, __LINE__); | |
| 27934 | 28009 | return SQLITE_IOERR_ACCESS; |
| 27935 | 28010 | } |
| 27936 | 28011 | if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { |
| 27937 | 28012 | ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; |
| 27938 | 28013 | } |
| @@ -27960,13 +28035,13 @@ | ||
| 27960 | 28035 | ** we're assuming that statfs() doesn't fail very often. At least |
| 27961 | 28036 | ** not while other file descriptors opened by the same process on |
| 27962 | 28037 | ** the same file are working. */ |
| 27963 | 28038 | p->lastErrno = errno; |
| 27964 | 28039 | if( dirfd>=0 ){ |
| 27965 | - close(dirfd); /* silently leak if fail, in error */ | |
| 28040 | + robust_close(p, dirfd, __LINE__); | |
| 27966 | 28041 | } |
| 27967 | - close(fd); /* silently leak if fail, in error */ | |
| 28042 | + robust_close(p, fd, __LINE__); | |
| 27968 | 28043 | rc = SQLITE_IOERR_ACCESS; |
| 27969 | 28044 | goto open_finished; |
| 27970 | 28045 | } |
| 27971 | 28046 | useProxy = !(fsInfo.f_flags&MNT_LOCAL); |
| 27972 | 28047 | } |
| @@ -28023,13 +28098,11 @@ | ||
| 28023 | 28098 | if( fsync(fd) ) |
| 28024 | 28099 | #endif |
| 28025 | 28100 | { |
| 28026 | 28101 | rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); |
| 28027 | 28102 | } |
| 28028 | - if( close(fd)&&!rc ){ | |
| 28029 | - rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", zPath); | |
| 28030 | - } | |
| 28103 | + robust_close(0, fd, __LINE__); | |
| 28031 | 28104 | } |
| 28032 | 28105 | } |
| 28033 | 28106 | #endif |
| 28034 | 28107 | return rc; |
| 28035 | 28108 | } |
| @@ -28213,11 +28286,11 @@ | ||
| 28213 | 28286 | memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); |
| 28214 | 28287 | assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); |
| 28215 | 28288 | nBuf = sizeof(t) + sizeof(pid); |
| 28216 | 28289 | }else{ |
| 28217 | 28290 | do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR ); |
| 28218 | - close(fd); | |
| 28291 | + robust_close(0, fd, __LINE__); | |
| 28219 | 28292 | } |
| 28220 | 28293 | } |
| 28221 | 28294 | #endif |
| 28222 | 28295 | return nBuf; |
| 28223 | 28296 | } |
| @@ -28656,11 +28729,11 @@ | ||
| 28656 | 28729 | if( rc==SQLITE_OK ){ |
| 28657 | 28730 | *ppFile = pNew; |
| 28658 | 28731 | return SQLITE_OK; |
| 28659 | 28732 | } |
| 28660 | 28733 | end_create_proxy: |
| 28661 | - close(fd); /* silently leak fd if error, we're already in error */ | |
| 28734 | + robust_close(pNew, fd, __LINE__); | |
| 28662 | 28735 | sqlite3_free(pNew); |
| 28663 | 28736 | sqlite3_free(pUnused); |
| 28664 | 28737 | return rc; |
| 28665 | 28738 | } |
| 28666 | 28739 | |
| @@ -28756,19 +28829,19 @@ | ||
| 28756 | 28829 | sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno); |
| 28757 | 28830 | goto end_breaklock; |
| 28758 | 28831 | } |
| 28759 | 28832 | rc = 0; |
| 28760 | 28833 | fprintf(stderr, "broke stale lock on %s\n", cPath); |
| 28761 | - close(conchFile->h); | |
| 28834 | + robust_close(pFile, conchFile->h, __LINE__); | |
| 28762 | 28835 | conchFile->h = fd; |
| 28763 | 28836 | conchFile->openFlags = O_RDWR | O_CREAT; |
| 28764 | 28837 | |
| 28765 | 28838 | end_breaklock: |
| 28766 | 28839 | if( rc ){ |
| 28767 | 28840 | if( fd>=0 ){ |
| 28768 | 28841 | unlink(tPath); |
| 28769 | - close(fd); | |
| 28842 | + robust_close(pFile, fd, __LINE__); | |
| 28770 | 28843 | } |
| 28771 | 28844 | fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg); |
| 28772 | 28845 | } |
| 28773 | 28846 | return rc; |
| 28774 | 28847 | } |
| @@ -28981,11 +29054,10 @@ | ||
| 28981 | 29054 | /* If we created a new conch file (not just updated the contents of a |
| 28982 | 29055 | ** valid conch file), try to match the permissions of the database |
| 28983 | 29056 | */ |
| 28984 | 29057 | if( rc==SQLITE_OK && createConch ){ |
| 28985 | 29058 | struct stat buf; |
| 28986 | - int rc; | |
| 28987 | 29059 | int err = fstat(pFile->h, &buf); |
| 28988 | 29060 | if( err==0 ){ |
| 28989 | 29061 | mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | |
| 28990 | 29062 | S_IROTH|S_IWOTH); |
| 28991 | 29063 | /* try to match the database file R/W permissions, ignore failure */ |
| @@ -29014,18 +29086,11 @@ | ||
| 29014 | 29086 | |
| 29015 | 29087 | end_takeconch: |
| 29016 | 29088 | OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h)); |
| 29017 | 29089 | if( rc==SQLITE_OK && pFile->openFlags ){ |
| 29018 | 29090 | if( pFile->h>=0 ){ |
| 29019 | -#ifdef STRICT_CLOSE_ERROR | |
| 29020 | - if( close(pFile->h) ){ | |
| 29021 | - pFile->lastErrno = errno; | |
| 29022 | - return SQLITE_IOERR_CLOSE; | |
| 29023 | - } | |
| 29024 | -#else | |
| 29025 | - close(pFile->h); /* silently leak fd if fail */ | |
| 29026 | -#endif | |
| 29091 | + robust_close(pFile, pFile->h, __LINE__); | |
| 29027 | 29092 | } |
| 29028 | 29093 | pFile->h = -1; |
| 29029 | 29094 | int fd = open(pCtx->dbPath, pFile->openFlags, |
| 29030 | 29095 | SQLITE_DEFAULT_FILE_PERMISSIONS); |
| 29031 | 29096 | OSTRACE(("TRANSPROXY: OPEN %d\n", fd)); |
| @@ -43555,11 +43620,10 @@ | ||
| 43555 | 43620 | if( rc!=SQLITE_OK ){ |
| 43556 | 43621 | return rc; |
| 43557 | 43622 | } |
| 43558 | 43623 | assert( pIter ); |
| 43559 | 43624 | |
| 43560 | - mxPage = pWal->hdr.nPage; | |
| 43561 | 43625 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall; |
| 43562 | 43626 | |
| 43563 | 43627 | /* Compute in mxSafeFrame the index of the last frame of the WAL that is |
| 43564 | 43628 | ** safe to write into the database. Frames beyond mxSafeFrame might |
| 43565 | 43629 | ** overwrite database pages that are in use by active readers and thus |
| @@ -51996,13 +52060,11 @@ | ||
| 51996 | 52060 | minI = j; |
| 51997 | 52061 | minV = apNew[j]->pgno; |
| 51998 | 52062 | } |
| 51999 | 52063 | } |
| 52000 | 52064 | if( minI>i ){ |
| 52001 | - int t; | |
| 52002 | 52065 | MemPage *pT; |
| 52003 | - t = apNew[i]->pgno; | |
| 52004 | 52066 | pT = apNew[i]; |
| 52005 | 52067 | apNew[i] = apNew[minI]; |
| 52006 | 52068 | apNew[minI] = pT; |
| 52007 | 52069 | } |
| 52008 | 52070 | } |
| @@ -55005,11 +55067,11 @@ | ||
| 55005 | 55067 | if( flags & MEM_Int ){ |
| 55006 | 55068 | return pMem->u.i; |
| 55007 | 55069 | }else if( flags & MEM_Real ){ |
| 55008 | 55070 | return doubleToInt64(pMem->r); |
| 55009 | 55071 | }else if( flags & (MEM_Str|MEM_Blob) ){ |
| 55010 | - i64 value; | |
| 55072 | + i64 value = 0; | |
| 55011 | 55073 | assert( pMem->z || pMem->n==0 ); |
| 55012 | 55074 | testcase( pMem->z==0 ); |
| 55013 | 55075 | sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc); |
| 55014 | 55076 | return value; |
| 55015 | 55077 | }else{ |
| @@ -57310,11 +57372,11 @@ | ||
| 57310 | 57372 | ** pointers to VdbeFrame objects, which may in turn contain pointers to |
| 57311 | 57373 | ** open cursors. |
| 57312 | 57374 | */ |
| 57313 | 57375 | static void closeAllCursors(Vdbe *p){ |
| 57314 | 57376 | if( p->pFrame ){ |
| 57315 | - VdbeFrame *pFrame = p->pFrame; | |
| 57377 | + VdbeFrame *pFrame; | |
| 57316 | 57378 | for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 57317 | 57379 | sqlite3VdbeFrameRestore(pFrame); |
| 57318 | 57380 | } |
| 57319 | 57381 | p->pFrame = 0; |
| 57320 | 57382 | p->nFrame = 0; |
| @@ -58290,11 +58352,17 @@ | ||
| 58290 | 58352 | i64 i = pMem->u.i; |
| 58291 | 58353 | u64 u; |
| 58292 | 58354 | if( file_format>=4 && (i&1)==i ){ |
| 58293 | 58355 | return 8+(u32)i; |
| 58294 | 58356 | } |
| 58295 | - u = i<0 ? -i : i; | |
| 58357 | + if( i<0 ){ | |
| 58358 | + if( i<(-MAX_6BYTE) ) return 6; | |
| 58359 | + /* Previous test prevents: u = -(-9223372036854775808) */ | |
| 58360 | + u = -i; | |
| 58361 | + }else{ | |
| 58362 | + u = i; | |
| 58363 | + } | |
| 58296 | 58364 | if( u<=127 ) return 1; |
| 58297 | 58365 | if( u<=32767 ) return 2; |
| 58298 | 58366 | if( u<=8388607 ) return 3; |
| 58299 | 58367 | if( u<=2147483647 ) return 4; |
| 58300 | 58368 | if( u<=MAX_6BYTE ) return 5; |
| @@ -59640,17 +59708,15 @@ | ||
| 59640 | 59708 | ** If iCol is not valid, return a pointer to a Mem which has a value |
| 59641 | 59709 | ** of NULL. |
| 59642 | 59710 | */ |
| 59643 | 59711 | static Mem *columnMem(sqlite3_stmt *pStmt, int i){ |
| 59644 | 59712 | Vdbe *pVm; |
| 59645 | - int vals; | |
| 59646 | 59713 | Mem *pOut; |
| 59647 | 59714 | |
| 59648 | 59715 | pVm = (Vdbe *)pStmt; |
| 59649 | 59716 | if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){ |
| 59650 | 59717 | sqlite3_mutex_enter(pVm->db->mutex); |
| 59651 | - vals = sqlite3_data_count(pStmt); | |
| 59652 | 59718 | pOut = &pVm->pResultSet[i]; |
| 59653 | 59719 | }else{ |
| 59654 | 59720 | /* If the value passed as the second argument is out of range, return |
| 59655 | 59721 | ** a pointer to the following static Mem object which contains the |
| 59656 | 59722 | ** value SQL NULL. Even though the Mem structure contains an element |
| @@ -61138,12 +61204,14 @@ | ||
| 61138 | 61204 | sqlite3_context ctx; |
| 61139 | 61205 | sqlite3_value **apVal; |
| 61140 | 61206 | int n; |
| 61141 | 61207 | } ag; |
| 61142 | 61208 | struct OP_ShiftRight_stack_vars { |
| 61143 | - i64 a; | |
| 61144 | - i64 b; | |
| 61209 | + i64 iA; | |
| 61210 | + u64 uA; | |
| 61211 | + i64 iB; | |
| 61212 | + u8 op; | |
| 61145 | 61213 | } ah; |
| 61146 | 61214 | struct OP_Ge_stack_vars { |
| 61147 | 61215 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 61148 | 61216 | char affinity; /* Affinity to use for comparison */ |
| 61149 | 61217 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| @@ -62189,23 +62257,16 @@ | ||
| 62189 | 62257 | if( (u.af.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; |
| 62190 | 62258 | if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ |
| 62191 | 62259 | u.af.iA = pIn1->u.i; |
| 62192 | 62260 | u.af.iB = pIn2->u.i; |
| 62193 | 62261 | switch( pOp->opcode ){ |
| 62194 | - case OP_Add: u.af.iB += u.af.iA; break; | |
| 62195 | - case OP_Subtract: u.af.iB -= u.af.iA; break; | |
| 62196 | - case OP_Multiply: u.af.iB *= u.af.iA; break; | |
| 62262 | + case OP_Add: if( sqlite3AddInt64(&u.af.iB,u.af.iA) ) goto fp_math; break; | |
| 62263 | + case OP_Subtract: if( sqlite3SubInt64(&u.af.iB,u.af.iA) ) goto fp_math; break; | |
| 62264 | + case OP_Multiply: if( sqlite3MulInt64(&u.af.iB,u.af.iA) ) goto fp_math; break; | |
| 62197 | 62265 | case OP_Divide: { |
| 62198 | 62266 | if( u.af.iA==0 ) goto arithmetic_result_is_null; |
| 62199 | - /* Dividing the largest possible negative 64-bit integer (1<<63) by | |
| 62200 | - ** -1 returns an integer too large to store in a 64-bit data-type. On | |
| 62201 | - ** some architectures, the value overflows to (1<<63). On others, | |
| 62202 | - ** a SIGFPE is issued. The following statement normalizes this | |
| 62203 | - ** behavior so that all architectures behave as if integer | |
| 62204 | - ** overflow occurred. | |
| 62205 | - */ | |
| 62206 | - if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) u.af.iA = 1; | |
| 62267 | + if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) goto fp_math; | |
| 62207 | 62268 | u.af.iB /= u.af.iA; |
| 62208 | 62269 | break; |
| 62209 | 62270 | } |
| 62210 | 62271 | default: { |
| 62211 | 62272 | if( u.af.iA==0 ) goto arithmetic_result_is_null; |
| @@ -62215,10 +62276,11 @@ | ||
| 62215 | 62276 | } |
| 62216 | 62277 | } |
| 62217 | 62278 | pOut->u.i = u.af.iB; |
| 62218 | 62279 | MemSetTypeFlag(pOut, MEM_Int); |
| 62219 | 62280 | }else{ |
| 62281 | +fp_math: | |
| 62220 | 62282 | u.af.rA = sqlite3VdbeRealValue(pIn1); |
| 62221 | 62283 | u.af.rB = sqlite3VdbeRealValue(pIn2); |
| 62222 | 62284 | switch( pOp->opcode ){ |
| 62223 | 62285 | case OP_Add: u.af.rB += u.af.rA; break; |
| 62224 | 62286 | case OP_Subtract: u.af.rB -= u.af.rA; break; |
| @@ -62412,31 +62474,55 @@ | ||
| 62412 | 62474 | case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */ |
| 62413 | 62475 | case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */ |
| 62414 | 62476 | case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */ |
| 62415 | 62477 | case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */ |
| 62416 | 62478 | #if 0 /* local variables moved into u.ah */ |
| 62417 | - i64 a; | |
| 62418 | - i64 b; | |
| 62479 | + i64 iA; | |
| 62480 | + u64 uA; | |
| 62481 | + i64 iB; | |
| 62482 | + u8 op; | |
| 62419 | 62483 | #endif /* local variables moved into u.ah */ |
| 62420 | 62484 | |
| 62421 | 62485 | pIn1 = &aMem[pOp->p1]; |
| 62422 | 62486 | pIn2 = &aMem[pOp->p2]; |
| 62423 | 62487 | pOut = &aMem[pOp->p3]; |
| 62424 | 62488 | if( (pIn1->flags | pIn2->flags) & MEM_Null ){ |
| 62425 | 62489 | sqlite3VdbeMemSetNull(pOut); |
| 62426 | 62490 | break; |
| 62427 | 62491 | } |
| 62428 | - u.ah.a = sqlite3VdbeIntValue(pIn2); | |
| 62429 | - u.ah.b = sqlite3VdbeIntValue(pIn1); | |
| 62430 | - switch( pOp->opcode ){ | |
| 62431 | - case OP_BitAnd: u.ah.a &= u.ah.b; break; | |
| 62432 | - case OP_BitOr: u.ah.a |= u.ah.b; break; | |
| 62433 | - case OP_ShiftLeft: u.ah.a <<= u.ah.b; break; | |
| 62434 | - default: assert( pOp->opcode==OP_ShiftRight ); | |
| 62435 | - u.ah.a >>= u.ah.b; break; | |
| 62436 | - } | |
| 62437 | - pOut->u.i = u.ah.a; | |
| 62492 | + u.ah.iA = sqlite3VdbeIntValue(pIn2); | |
| 62493 | + u.ah.iB = sqlite3VdbeIntValue(pIn1); | |
| 62494 | + u.ah.op = pOp->opcode; | |
| 62495 | + if( u.ah.op==OP_BitAnd ){ | |
| 62496 | + u.ah.iA &= u.ah.iB; | |
| 62497 | + }else if( u.ah.op==OP_BitOr ){ | |
| 62498 | + u.ah.iA |= u.ah.iB; | |
| 62499 | + }else if( u.ah.iB!=0 ){ | |
| 62500 | + assert( u.ah.op==OP_ShiftRight || u.ah.op==OP_ShiftLeft ); | |
| 62501 | + | |
| 62502 | + /* If shifting by a negative amount, shift in the other direction */ | |
| 62503 | + if( u.ah.iB<0 ){ | |
| 62504 | + assert( OP_ShiftRight==OP_ShiftLeft+1 ); | |
| 62505 | + u.ah.op = 2*OP_ShiftLeft + 1 - u.ah.op; | |
| 62506 | + u.ah.iB = u.ah.iB>(-64) ? -u.ah.iB : 64; | |
| 62507 | + } | |
| 62508 | + | |
| 62509 | + if( u.ah.iB>=64 ){ | |
| 62510 | + u.ah.iA = (u.ah.iA>=0 || u.ah.op==OP_ShiftLeft) ? 0 : -1; | |
| 62511 | + }else{ | |
| 62512 | + memcpy(&u.ah.uA, &u.ah.iA, sizeof(u.ah.uA)); | |
| 62513 | + if( u.ah.op==OP_ShiftLeft ){ | |
| 62514 | + u.ah.uA <<= u.ah.iB; | |
| 62515 | + }else{ | |
| 62516 | + u.ah.uA >>= u.ah.iB; | |
| 62517 | + /* Sign-extend on a right shift of a negative number */ | |
| 62518 | + if( u.ah.iA<0 ) u.ah.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ah.iB); | |
| 62519 | + } | |
| 62520 | + memcpy(&u.ah.iA, &u.ah.uA, sizeof(u.ah.iA)); | |
| 62521 | + } | |
| 62522 | + } | |
| 62523 | + pOut->u.i = u.ah.iA; | |
| 62438 | 62524 | MemSetTypeFlag(pOut, MEM_Int); |
| 62439 | 62525 | break; |
| 62440 | 62526 | } |
| 62441 | 62527 | |
| 62442 | 62528 | /* Opcode: AddImm P1 P2 * * * |
| @@ -63372,11 +63458,10 @@ | ||
| 63372 | 63458 | ** hdr-size field is also a varint which is the offset from the beginning |
| 63373 | 63459 | ** of the record to data0. |
| 63374 | 63460 | */ |
| 63375 | 63461 | u.ao.nData = 0; /* Number of bytes of data space */ |
| 63376 | 63462 | u.ao.nHdr = 0; /* Number of bytes of header space */ |
| 63377 | - u.ao.nByte = 0; /* Data space required for this record */ | |
| 63378 | 63463 | u.ao.nZero = 0; /* Number of zero bytes at the end of the record */ |
| 63379 | 63464 | u.ao.nField = pOp->p1; |
| 63380 | 63465 | u.ao.zAffinity = pOp->p4.z; |
| 63381 | 63466 | assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 ); |
| 63382 | 63467 | u.ao.pData0 = &aMem[u.ao.nField]; |
| @@ -64678,11 +64763,10 @@ | ||
| 64678 | 64763 | ** it already exists in the table. If it does not exist, we have |
| 64679 | 64764 | ** succeeded. If the random rowid does exist, we select a new one |
| 64680 | 64765 | ** and try again, up to 100 times. |
| 64681 | 64766 | */ |
| 64682 | 64767 | assert( u.be.pC->isTable ); |
| 64683 | - u.be.cnt = 0; | |
| 64684 | 64768 | |
| 64685 | 64769 | #ifdef SQLITE_32BIT_ROWID |
| 64686 | 64770 | # define MAX_ROWID 0x7fffffff |
| 64687 | 64771 | #else |
| 64688 | 64772 | /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| @@ -71317,11 +71401,11 @@ | ||
| 71317 | 71401 | const char *z = pExpr->u.zToken; |
| 71318 | 71402 | assert( z!=0 ); |
| 71319 | 71403 | c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8); |
| 71320 | 71404 | if( c==0 || (c==2 && negFlag) ){ |
| 71321 | 71405 | char *zV; |
| 71322 | - if( negFlag ){ value = -value; } | |
| 71406 | + if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; } | |
| 71323 | 71407 | zV = dup8bytes(v, (char*)&value); |
| 71324 | 71408 | sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64); |
| 71325 | 71409 | }else{ |
| 71326 | 71410 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 71327 | 71411 | sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); |
| @@ -81443,17 +81527,12 @@ | ||
| 81443 | 81527 | if( p && type!=SQLITE_NULL ){ |
| 81444 | 81528 | p->cnt++; |
| 81445 | 81529 | if( type==SQLITE_INTEGER ){ |
| 81446 | 81530 | i64 v = sqlite3_value_int64(argv[0]); |
| 81447 | 81531 | p->rSum += v; |
| 81448 | - if( (p->approx|p->overflow)==0 ){ | |
| 81449 | - i64 iNewSum = p->iSum + v; | |
| 81450 | - int s1 = (int)(p->iSum >> (sizeof(i64)*8-1)); | |
| 81451 | - int s2 = (int)(v >> (sizeof(i64)*8-1)); | |
| 81452 | - int s3 = (int)(iNewSum >> (sizeof(i64)*8-1)); | |
| 81453 | - p->overflow = ((s1&s2&~s3) | (~s1&~s2&s3))?1:0; | |
| 81454 | - p->iSum = iNewSum; | |
| 81532 | + if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, v) ){ | |
| 81533 | + p->overflow = 1; | |
| 81455 | 81534 | } |
| 81456 | 81535 | }else{ |
| 81457 | 81536 | p->rSum += sqlite3_value_double(argv[0]); |
| 81458 | 81537 | p->approx = 1; |
| 81459 | 81538 | } |
| @@ -82489,11 +82568,10 @@ | ||
| 82489 | 82568 | Table *pTab, /* Row is being deleted from this table */ |
| 82490 | 82569 | int regOld, /* Previous row data is stored here */ |
| 82491 | 82570 | int regNew /* New row data is stored here */ |
| 82492 | 82571 | ){ |
| 82493 | 82572 | sqlite3 *db = pParse->db; /* Database handle */ |
| 82494 | - Vdbe *v; /* VM to write code to */ | |
| 82495 | 82573 | FKey *pFKey; /* Used to iterate through FKs */ |
| 82496 | 82574 | int iDb; /* Index of database containing pTab */ |
| 82497 | 82575 | const char *zDb; /* Name of database containing pTab */ |
| 82498 | 82576 | int isIgnoreErrors = pParse->disableTriggers; |
| 82499 | 82577 | |
| @@ -82501,11 +82579,10 @@ | ||
| 82501 | 82579 | assert( (regOld==0)!=(regNew==0) ); |
| 82502 | 82580 | |
| 82503 | 82581 | /* If foreign-keys are disabled, this function is a no-op. */ |
| 82504 | 82582 | if( (db->flags&SQLITE_ForeignKeys)==0 ) return; |
| 82505 | 82583 | |
| 82506 | - v = sqlite3GetVdbe(pParse); | |
| 82507 | 82584 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 82508 | 82585 | zDb = db->aDb[iDb].zName; |
| 82509 | 82586 | |
| 82510 | 82587 | /* Loop through all the foreign key constraints for which pTab is the |
| 82511 | 82588 | ** child table (the table that the foreign key definition is part of). */ |
| @@ -83459,11 +83536,10 @@ | ||
| 83459 | 83536 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| 83460 | 83537 | int regRowCount = 0; /* Memory cell used for the row counter */ |
| 83461 | 83538 | int regIns; /* Block of regs holding rowid+data being inserted */ |
| 83462 | 83539 | int regRowid; /* registers holding insert rowid */ |
| 83463 | 83540 | int regData; /* register holding first column to insert */ |
| 83464 | - int regRecord; /* Holds the assemblied row record */ | |
| 83465 | 83541 | int regEof = 0; /* Register recording end of SELECT data */ |
| 83466 | 83542 | int *aRegIdx = 0; /* One register allocated to each index */ |
| 83467 | 83543 | |
| 83468 | 83544 | #ifndef SQLITE_OMIT_TRIGGER |
| 83469 | 83545 | int isView; /* True if attempting to insert into a view */ |
| @@ -83788,11 +83864,10 @@ | ||
| 83788 | 83864 | } |
| 83789 | 83865 | |
| 83790 | 83866 | /* Allocate registers for holding the rowid of the new row, |
| 83791 | 83867 | ** the content of the new row, and the assemblied row record. |
| 83792 | 83868 | */ |
| 83793 | - regRecord = ++pParse->nMem; | |
| 83794 | 83869 | regRowid = regIns = pParse->nMem+1; |
| 83795 | 83870 | pParse->nMem += pTab->nCol + 1; |
| 83796 | 83871 | if( IsVirtual(pTab) ){ |
| 83797 | 83872 | regRowid++; |
| 83798 | 83873 | pParse->nMem++; |
| @@ -84182,11 +84257,11 @@ | ||
| 84182 | 84257 | case OE_Abort: |
| 84183 | 84258 | sqlite3MayAbort(pParse); |
| 84184 | 84259 | case OE_Rollback: |
| 84185 | 84260 | case OE_Fail: { |
| 84186 | 84261 | char *zMsg; |
| 84187 | - j1 = sqlite3VdbeAddOp3(v, OP_HaltIfNull, | |
| 84262 | + sqlite3VdbeAddOp3(v, OP_HaltIfNull, | |
| 84188 | 84263 | SQLITE_CONSTRAINT, onError, regData+i); |
| 84189 | 84264 | zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL", |
| 84190 | 84265 | pTab->zName, pTab->aCol[i].zName); |
| 84191 | 84266 | sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); |
| 84192 | 84267 | break; |
| @@ -87708,11 +87783,11 @@ | ||
| 87708 | 87783 | Db *pDb; |
| 87709 | 87784 | char const *azArg[4]; |
| 87710 | 87785 | int meta[5]; |
| 87711 | 87786 | InitData initData; |
| 87712 | 87787 | char const *zMasterSchema; |
| 87713 | - char const *zMasterName = SCHEMA_TABLE(iDb); | |
| 87788 | + char const *zMasterName; | |
| 87714 | 87789 | int openedTransaction = 0; |
| 87715 | 87790 | |
| 87716 | 87791 | /* |
| 87717 | 87792 | ** The master database table has a structure like this |
| 87718 | 87793 | */ |
| @@ -93351,11 +93426,10 @@ | ||
| 93351 | 93426 | sqlite3 *db = pParse->db; /* The database */ |
| 93352 | 93427 | DbFixer sFix; /* Fixer object */ |
| 93353 | 93428 | int iDb; /* Database containing the trigger */ |
| 93354 | 93429 | Token nameToken; /* Trigger name for error reporting */ |
| 93355 | 93430 | |
| 93356 | - pTrig = pParse->pNewTrigger; | |
| 93357 | 93431 | pParse->pNewTrigger = 0; |
| 93358 | 93432 | if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup; |
| 93359 | 93433 | zName = pTrig->zName; |
| 93360 | 93434 | iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema); |
| 93361 | 93435 | pTrig->step_list = pStepList; |
| @@ -94314,11 +94388,10 @@ | ||
| 94314 | 94388 | int regOldRowid; /* The old rowid */ |
| 94315 | 94389 | int regNewRowid; /* The new rowid */ |
| 94316 | 94390 | int regNew; |
| 94317 | 94391 | int regOld = 0; |
| 94318 | 94392 | int regRowSet = 0; /* Rowset of rows to be updated */ |
| 94319 | - int regRec; /* Register used for new table record to insert */ | |
| 94320 | 94393 | |
| 94321 | 94394 | memset(&sContext, 0, sizeof(sContext)); |
| 94322 | 94395 | db = pParse->db; |
| 94323 | 94396 | if( pParse->nErr || db->mallocFailed ){ |
| 94324 | 94397 | goto update_cleanup; |
| @@ -94472,11 +94545,10 @@ | ||
| 94472 | 94545 | if( chngRowid || pTrigger || hasFK ){ |
| 94473 | 94546 | regNewRowid = ++pParse->nMem; |
| 94474 | 94547 | } |
| 94475 | 94548 | regNew = pParse->nMem + 1; |
| 94476 | 94549 | pParse->nMem += pTab->nCol; |
| 94477 | - regRec = ++pParse->nMem; | |
| 94478 | 94550 | |
| 94479 | 94551 | /* Start the view context. */ |
| 94480 | 94552 | if( isView ){ |
| 94481 | 94553 | sqlite3AuthContextPush(pParse, &sContext, pTab->zName); |
| 94482 | 94554 | } |
| @@ -94582,11 +94654,11 @@ | ||
| 94582 | 94654 | u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0); |
| 94583 | 94655 | oldmask |= sqlite3TriggerColmask(pParse, |
| 94584 | 94656 | pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError |
| 94585 | 94657 | ); |
| 94586 | 94658 | for(i=0; i<pTab->nCol; i++){ |
| 94587 | - if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){ | |
| 94659 | + if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){ | |
| 94588 | 94660 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i); |
| 94589 | 94661 | }else{ |
| 94590 | 94662 | sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i); |
| 94591 | 94663 | } |
| 94592 | 94664 | } |
| @@ -100187,11 +100259,10 @@ | ||
| 100187 | 100259 | ** |
| 100188 | 100260 | ** B: <after the loop> |
| 100189 | 100261 | ** |
| 100190 | 100262 | */ |
| 100191 | 100263 | WhereClause *pOrWc; /* The OR-clause broken out into subterms */ |
| 100192 | - WhereTerm *pFinal; /* Final subterm within the OR-clause. */ | |
| 100193 | 100264 | SrcList *pOrTab; /* Shortened table list or OR-clause generation */ |
| 100194 | 100265 | |
| 100195 | 100266 | int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */ |
| 100196 | 100267 | int regRowset = 0; /* Register for RowSet object */ |
| 100197 | 100268 | int regRowid = 0; /* Register holding rowid */ |
| @@ -100203,11 +100274,10 @@ | ||
| 100203 | 100274 | pTerm = pLevel->plan.u.pTerm; |
| 100204 | 100275 | assert( pTerm!=0 ); |
| 100205 | 100276 | assert( pTerm->eOperator==WO_OR ); |
| 100206 | 100277 | assert( (pTerm->wtFlags & TERM_ORINFO)!=0 ); |
| 100207 | 100278 | pOrWc = &pTerm->u.pOrInfo->wc; |
| 100208 | - pFinal = &pOrWc->a[pOrWc->nTerm-1]; | |
| 100209 | 100279 | pLevel->op = OP_Return; |
| 100210 | 100280 | pLevel->p1 = regReturn; |
| 100211 | 100281 | |
| 100212 | 100282 | /* Set up a new SrcList ni pOrTab containing the table being scanned |
| 100213 | 100283 | ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. |
| @@ -100312,11 +100382,10 @@ | ||
| 100312 | 100382 | ** |
| 100313 | 100383 | ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through |
| 100314 | 100384 | ** the use of indices become tests that are evaluated against each row of |
| 100315 | 100385 | ** the relevant input tables. |
| 100316 | 100386 | */ |
| 100317 | - k = 0; | |
| 100318 | 100387 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 100319 | 100388 | Expr *pE; |
| 100320 | 100389 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */ |
| 100321 | 100390 | testcase( pTerm->wtFlags & TERM_CODED ); |
| 100322 | 100391 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| @@ -100330,11 +100399,10 @@ | ||
| 100330 | 100399 | assert( pE!=0 ); |
| 100331 | 100400 | if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){ |
| 100332 | 100401 | continue; |
| 100333 | 100402 | } |
| 100334 | 100403 | sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL); |
| 100335 | - k = 1; | |
| 100336 | 100404 | pTerm->wtFlags |= TERM_CODED; |
| 100337 | 100405 | } |
| 100338 | 100406 | |
| 100339 | 100407 | /* For a LEFT OUTER JOIN, generate code that will record the fact that |
| 100340 | 100408 | ** at least one row of the right table has matched the left table. |
| @@ -100638,12 +100706,10 @@ | ||
| 100638 | 100706 | ** |
| 100639 | 100707 | ** This loop also figures out the nesting order of tables in the FROM |
| 100640 | 100708 | ** clause. |
| 100641 | 100709 | */ |
| 100642 | 100710 | notReady = ~(Bitmask)0; |
| 100643 | - pTabItem = pTabList->a; | |
| 100644 | - pLevel = pWInfo->a; | |
| 100645 | 100711 | andFlags = ~0; |
| 100646 | 100712 | WHERETRACE(("*** Optimizer Start ***\n")); |
| 100647 | 100713 | for(i=iFrom=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){ |
| 100648 | 100714 | WhereCost bestPlan; /* Most efficient plan seen so far */ |
| 100649 | 100715 | Index *pIdx; /* Index for FROM table at pTabItem */ |
| @@ -100750,12 +100816,12 @@ | ||
| 100750 | 100816 | /* Conditions under which this table becomes the best so far: |
| 100751 | 100817 | ** |
| 100752 | 100818 | ** (1) The table must not depend on other tables that have not |
| 100753 | 100819 | ** yet run. |
| 100754 | 100820 | ** |
| 100755 | - ** (2) A full-table-scan plan cannot supercede another plan unless | |
| 100756 | - ** it is an "optimal" plan as defined above. | |
| 100821 | + ** (2) A full-table-scan plan cannot supercede indexed plan unless | |
| 100822 | + ** the full-table-scan is an "optimal" plan as defined above. | |
| 100757 | 100823 | ** |
| 100758 | 100824 | ** (3) All tables have an INDEXED BY clause or this table lacks an |
| 100759 | 100825 | ** INDEXED BY clause or this table uses the specific |
| 100760 | 100826 | ** index specified by its INDEXED BY clause. This rule ensures |
| 100761 | 100827 | ** that a best-so-far is always selected even if an impossible |
| @@ -100767,10 +100833,11 @@ | ||
| 100767 | 100833 | ** (4) The plan cost must be lower than prior plans or else the |
| 100768 | 100834 | ** cost must be the same and the number of rows must be lower. |
| 100769 | 100835 | */ |
| 100770 | 100836 | if( (sCost.used¬Ready)==0 /* (1) */ |
| 100771 | 100837 | && (bestJ<0 || (notIndexed&m)!=0 /* (2) */ |
| 100838 | + || (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 | |
| 100772 | 100839 | || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0) |
| 100773 | 100840 | && (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */ |
| 100774 | 100841 | || NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)) |
| 100775 | 100842 | && (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */ |
| 100776 | 100843 | || (sCost.rCost<=bestPlan.rCost |
| @@ -123657,11 +123724,11 @@ | ||
| 123657 | 123724 | int nCell = 0; |
| 123658 | 123725 | RtreeCell cell; |
| 123659 | 123726 | int jj; |
| 123660 | 123727 | |
| 123661 | 123728 | nodeGetCell(&tree, &node, ii, &cell); |
| 123662 | - sqlite3_snprintf(512-nCell,&zCell[nCell],"%d", cell.iRowid); | |
| 123729 | + sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid); | |
| 123663 | 123730 | nCell = strlen(zCell); |
| 123664 | 123731 | for(jj=0; jj<tree.nDim*2; jj++){ |
| 123665 | 123732 | sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f); |
| 123666 | 123733 | nCell = strlen(zCell); |
| 123667 | 123734 | } |
| 123668 | 123735 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -650,11 +650,11 @@ | |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | #define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -11206,10 +11206,13 @@ | |
| 11206 | SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*); |
| 11207 | SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*); |
| 11208 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 11209 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 11210 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 11211 | |
| 11212 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 11213 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 11214 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 11215 | void(*)(void*)); |
| @@ -18792,11 +18795,15 @@ | |
| 18792 | v = va_arg(ap,long int); |
| 18793 | }else{ |
| 18794 | v = va_arg(ap,int); |
| 18795 | } |
| 18796 | if( v<0 ){ |
| 18797 | longvalue = -v; |
| 18798 | prefix = '-'; |
| 18799 | }else{ |
| 18800 | longvalue = v; |
| 18801 | if( flag_plussign ) prefix = '+'; |
| 18802 | else if( flag_blanksign ) prefix = ' '; |
| @@ -20566,64 +20573,84 @@ | |
| 20566 | return c; |
| 20567 | } |
| 20568 | |
| 20569 | |
| 20570 | /* |
| 20571 | ** Convert zNum to a 64-bit signed integer and write |
| 20572 | ** the value of the integer into *pNum. |
| 20573 | ** If zNum is exactly 9223372036854665808, return 2. |
| 20574 | ** This is a special case as the context will determine |
| 20575 | ** if it is too big (used as a negative). |
| 20576 | ** If zNum is not an integer or is an integer that |
| 20577 | ** is too large to be expressed with 64 bits, |
| 20578 | ** then return 1. Otherwise return 0. |
| 20579 | ** |
| 20580 | ** length is the number of bytes in the string (bytes, not characters). |
| 20581 | ** The string is not necessarily zero-terminated. The encoding is |
| 20582 | ** given by enc. |
| 20583 | */ |
| 20584 | SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){ |
| 20585 | int incr = (enc==SQLITE_UTF8?1:2); |
| 20586 | i64 v = 0; |
| 20587 | int neg = 0; /* assume positive */ |
| 20588 | int i; |
| 20589 | int c = 0; |
| 20590 | const char *zStart; |
| 20591 | const char *zEnd = zNum + length; |
| 20592 | if( enc==SQLITE_UTF16BE ) zNum++; |
| 20593 | while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr; |
| 20594 | if( zNum>=zEnd ) goto do_atoi_calc; |
| 20595 | if( *zNum=='-' ){ |
| 20596 | neg = 1; |
| 20597 | zNum+=incr; |
| 20598 | }else if( *zNum=='+' ){ |
| 20599 | zNum+=incr; |
| 20600 | } |
| 20601 | do_atoi_calc: |
| 20602 | zStart = zNum; |
| 20603 | while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */ |
| 20604 | for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){ |
| 20605 | v = v*10 + c - '0'; |
| 20606 | } |
| 20607 | *pNum = neg ? -v : v; |
| 20608 | testcase( i==18 ); |
| 20609 | testcase( i==19 ); |
| 20610 | testcase( i==20 ); |
| 20611 | if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){ |
| 20612 | /* zNum is empty or contains non-numeric text or is longer |
| 20613 | ** than 19 digits (thus guaranteeing that it is too large) */ |
| 20614 | return 1; |
| 20615 | }else if( i<19*incr ){ |
| 20616 | /* Less than 19 digits, so we know that it fits in 64 bits */ |
| 20617 | return 0; |
| 20618 | }else{ |
| 20619 | /* 19-digit numbers must be no larger than 9223372036854775807 if positive |
| 20620 | ** or 9223372036854775808 if negative. Note that 9223372036854665808 |
| 20621 | ** is 2^63. Return 1 if to large */ |
| 20622 | c=compare2pow63(zNum, incr); |
| 20623 | if( c==0 && neg==0 ) return 2; /* too big, exactly 9223372036854665808 */ |
| 20624 | return c<neg ? 0 : 1; |
| 20625 | } |
| 20626 | } |
| 20627 | |
| 20628 | /* |
| 20629 | ** If zNum represents an integer that will fit in 32-bits, then set |
| @@ -21185,10 +21212,68 @@ | |
| 21185 | return 0; |
| 21186 | }else{ |
| 21187 | return 1; |
| 21188 | } |
| 21189 | } |
| 21190 | |
| 21191 | /************** End of util.c ************************************************/ |
| 21192 | /************** Begin file hash.c ********************************************/ |
| 21193 | /* |
| 21194 | ** 2001 September 22 |
| @@ -23930,18 +24015,19 @@ | |
| 23930 | ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). |
| 23931 | ** The two subsequent arguments should be the name of the OS function that |
| 23932 | ** failed (e.g. "unlink", "open") and the the associated file-system path, |
| 23933 | ** if any. |
| 23934 | */ |
| 23935 | #define unixLogError(a,b,c) unixLogError_x(a,b,c,__LINE__) |
| 23936 | static int unixLogError_x( |
| 23937 | int errcode, /* SQLite error code */ |
| 23938 | const char *zFunc, /* Name of OS function that failed */ |
| 23939 | const char *zPath, /* File path associated with error */ |
| 23940 | int iLine /* Source line number where error occurred */ |
| 23941 | ){ |
| 23942 | char *zErr; /* Message from strerror() or equivalent */ |
| 23943 | |
| 23944 | /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use |
| 23945 | ** the strerror() function to obtain the human-readable error message |
| 23946 | ** equivalent to errno. Otherwise, use strerror_r(). |
| 23947 | */ |
| @@ -23963,58 +24049,63 @@ | |
| 23963 | ** could lead to a segfault though. |
| 23964 | */ |
| 23965 | #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU) |
| 23966 | zErr = |
| 23967 | # endif |
| 23968 | strerror_r(errno, aErr, sizeof(aErr)-1); |
| 23969 | |
| 23970 | #elif SQLITE_THREADSAFE |
| 23971 | /* This is a threadsafe build, but strerror_r() is not available. */ |
| 23972 | zErr = ""; |
| 23973 | #else |
| 23974 | /* Non-threadsafe build, use strerror(). */ |
| 23975 | zErr = strerror(errno); |
| 23976 | #endif |
| 23977 | |
| 23978 | assert( errcode!=SQLITE_OK ); |
| 23979 | sqlite3_log(errcode, |
| 23980 | "os_unix.c: %s() at line %d - \"%s\" errno=%d path=%s", |
| 23981 | zFunc, iLine, zErr, errno, (zPath ? zPath : "n/a") |
| 23982 | ); |
| 23983 | |
| 23984 | return errcode; |
| 23985 | } |
| 23986 | |
| 23987 | |
| 23988 | /* |
| 23989 | ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. |
| 23990 | ** If all such file descriptors are closed without error, the list is |
| 23991 | ** cleared and SQLITE_OK returned. |
| 23992 | ** |
| 23993 | ** Otherwise, if an error occurs, then successfully closed file descriptor |
| 23994 | ** entries are removed from the list, and SQLITE_IOERR_CLOSE returned. |
| 23995 | ** not deleted and SQLITE_IOERR_CLOSE returned. |
| 23996 | */ |
| 23997 | static int closePendingFds(unixFile *pFile){ |
| 23998 | int rc = SQLITE_OK; |
| 23999 | unixInodeInfo *pInode = pFile->pInode; |
| 24000 | UnixUnusedFd *pError = 0; |
| 24001 | UnixUnusedFd *p; |
| 24002 | UnixUnusedFd *pNext; |
| 24003 | for(p=pInode->pUnused; p; p=pNext){ |
| 24004 | pNext = p->pNext; |
| 24005 | if( close(p->fd) ){ |
| 24006 | pFile->lastErrno = errno; |
| 24007 | rc = unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath); |
| 24008 | p->pNext = pError; |
| 24009 | pError = p; |
| 24010 | }else{ |
| 24011 | sqlite3_free(p); |
| 24012 | } |
| 24013 | } |
| 24014 | pInode->pUnused = pError; |
| 24015 | return rc; |
| 24016 | } |
| 24017 | |
| 24018 | /* |
| 24019 | ** Release a unixInodeInfo structure previously allocated by findInodeInfo(). |
| 24020 | ** |
| @@ -24621,14 +24712,11 @@ | |
| 24621 | ** was deferred because of outstanding locks. |
| 24622 | */ |
| 24623 | pInode->nLock--; |
| 24624 | assert( pInode->nLock>=0 ); |
| 24625 | if( pInode->nLock==0 ){ |
| 24626 | int rc2 = closePendingFds(pFile); |
| 24627 | if( rc==SQLITE_OK ){ |
| 24628 | rc = rc2; |
| 24629 | } |
| 24630 | } |
| 24631 | } |
| 24632 | |
| 24633 | end_unlock: |
| 24634 | unixLeaveMutex(); |
| @@ -24659,24 +24747,16 @@ | |
| 24659 | */ |
| 24660 | static int closeUnixFile(sqlite3_file *id){ |
| 24661 | unixFile *pFile = (unixFile*)id; |
| 24662 | if( pFile ){ |
| 24663 | if( pFile->dirfd>=0 ){ |
| 24664 | int err = close(pFile->dirfd); |
| 24665 | if( err ){ |
| 24666 | pFile->lastErrno = errno; |
| 24667 | return unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath); |
| 24668 | }else{ |
| 24669 | pFile->dirfd=-1; |
| 24670 | } |
| 24671 | } |
| 24672 | if( pFile->h>=0 ){ |
| 24673 | int err = close(pFile->h); |
| 24674 | if( err ){ |
| 24675 | pFile->lastErrno = errno; |
| 24676 | return unixLogError(SQLITE_IOERR_CLOSE, "close", pFile->zPath); |
| 24677 | } |
| 24678 | } |
| 24679 | #if OS_VXWORKS |
| 24680 | if( pFile->pId ){ |
| 24681 | if( pFile->isDelete ){ |
| 24682 | unlink(pFile->pId->zCanonicalName); |
| @@ -24882,14 +24962,11 @@ | |
| 24882 | pFile->lastErrno = tErrno; |
| 24883 | } |
| 24884 | } |
| 24885 | return rc; |
| 24886 | } |
| 24887 | if( close(fd) ){ |
| 24888 | pFile->lastErrno = errno; |
| 24889 | rc = SQLITE_IOERR_CLOSE; |
| 24890 | } |
| 24891 | |
| 24892 | /* got it, set the type and return ok */ |
| 24893 | pFile->eFileLock = eFileLock; |
| 24894 | return rc; |
| 24895 | } |
| @@ -25777,11 +25854,11 @@ | |
| 25777 | } |
| 25778 | if( rc==SQLITE_OK ){ |
| 25779 | pInode->nLock--; |
| 25780 | assert( pInode->nLock>=0 ); |
| 25781 | if( pInode->nLock==0 ){ |
| 25782 | rc = closePendingFds(pFile); |
| 25783 | } |
| 25784 | } |
| 25785 | } |
| 25786 | |
| 25787 | unixLeaveMutex(); |
| @@ -26210,11 +26287,10 @@ | |
| 26210 | if( rc ){ |
| 26211 | pFile->lastErrno = errno; |
| 26212 | return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath); |
| 26213 | } |
| 26214 | if( pFile->dirfd>=0 ){ |
| 26215 | int err; |
| 26216 | OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, |
| 26217 | HAVE_FULLFSYNC, isFullsync)); |
| 26218 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 26219 | /* The directory sync is only attempted if full_fsync is |
| 26220 | ** turned off or unavailable. If a full_fsync occurred above, |
| @@ -26229,17 +26305,13 @@ | |
| 26229 | */ |
| 26230 | /* pFile->lastErrno = errno; */ |
| 26231 | /* return SQLITE_IOERR; */ |
| 26232 | } |
| 26233 | #endif |
| 26234 | err = close(pFile->dirfd); /* Only need to sync once, so close the */ |
| 26235 | if( err==0 ){ /* directory when we are done */ |
| 26236 | pFile->dirfd = -1; |
| 26237 | }else{ |
| 26238 | pFile->lastErrno = errno; |
| 26239 | rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", pFile->zPath); |
| 26240 | } |
| 26241 | } |
| 26242 | return rc; |
| 26243 | } |
| 26244 | |
| 26245 | /* |
| @@ -26602,11 +26674,14 @@ | |
| 26602 | if( p->mutex ) sqlite3_mutex_free(p->mutex); |
| 26603 | for(i=0; i<p->nRegion; i++){ |
| 26604 | munmap(p->apRegion[i], p->szRegion); |
| 26605 | } |
| 26606 | sqlite3_free(p->apRegion); |
| 26607 | if( p->h>=0 ) close(p->h); |
| 26608 | p->pInode->pShmNode = 0; |
| 26609 | sqlite3_free(p); |
| 26610 | } |
| 26611 | } |
| 26612 | |
| @@ -27413,11 +27488,11 @@ | |
| 27413 | ** |
| 27414 | ** If scenario (a) caused the error then things are not so safe. The |
| 27415 | ** implicit assumption here is that if fstat() fails, things are in |
| 27416 | ** such bad shape that dropping a lock or two doesn't matter much. |
| 27417 | */ |
| 27418 | close(h); |
| 27419 | h = -1; |
| 27420 | } |
| 27421 | unixLeaveMutex(); |
| 27422 | } |
| 27423 | |
| @@ -27439,11 +27514,11 @@ | |
| 27439 | srandomdev(); |
| 27440 | unixEnterMutex(); |
| 27441 | rc = findInodeInfo(pNew, &pNew->pInode); |
| 27442 | if( rc!=SQLITE_OK ){ |
| 27443 | sqlite3_free(pNew->lockingContext); |
| 27444 | close(h); |
| 27445 | h = -1; |
| 27446 | } |
| 27447 | unixLeaveMutex(); |
| 27448 | } |
| 27449 | } |
| @@ -27490,20 +27565,20 @@ | |
| 27490 | #endif |
| 27491 | |
| 27492 | pNew->lastErrno = 0; |
| 27493 | #if OS_VXWORKS |
| 27494 | if( rc!=SQLITE_OK ){ |
| 27495 | if( h>=0 ) close(h); |
| 27496 | h = -1; |
| 27497 | unlink(zFilename); |
| 27498 | isDelete = 0; |
| 27499 | } |
| 27500 | pNew->isDelete = isDelete; |
| 27501 | #endif |
| 27502 | if( rc!=SQLITE_OK ){ |
| 27503 | if( dirfd>=0 ) close(dirfd); /* silent leak if fail, already in error */ |
| 27504 | if( h>=0 ) close(h); |
| 27505 | }else{ |
| 27506 | pNew->pMethod = pLockingStyle; |
| 27507 | OpenCounter(+1); |
| 27508 | } |
| 27509 | return rc; |
| @@ -27911,11 +27986,11 @@ | |
| 27911 | /* It is safe to close fd at this point, because it is guaranteed not |
| 27912 | ** to be open on a database file. If it were open on a database file, |
| 27913 | ** it would not be safe to close as this would release any locks held |
| 27914 | ** on the file by this process. */ |
| 27915 | assert( eType!=SQLITE_OPEN_MAIN_DB ); |
| 27916 | close(fd); /* silently leak if fail, already in error */ |
| 27917 | goto open_finished; |
| 27918 | } |
| 27919 | } |
| 27920 | |
| 27921 | #ifdef FD_CLOEXEC |
| @@ -27927,12 +28002,12 @@ | |
| 27927 | |
| 27928 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE |
| 27929 | struct statfs fsInfo; |
| 27930 | if( fstatfs(fd, &fsInfo) == -1 ){ |
| 27931 | ((unixFile*)pFile)->lastErrno = errno; |
| 27932 | if( dirfd>=0 ) close(dirfd); /* silently leak if fail, in error */ |
| 27933 | close(fd); /* silently leak if fail, in error */ |
| 27934 | return SQLITE_IOERR_ACCESS; |
| 27935 | } |
| 27936 | if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { |
| 27937 | ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; |
| 27938 | } |
| @@ -27960,13 +28035,13 @@ | |
| 27960 | ** we're assuming that statfs() doesn't fail very often. At least |
| 27961 | ** not while other file descriptors opened by the same process on |
| 27962 | ** the same file are working. */ |
| 27963 | p->lastErrno = errno; |
| 27964 | if( dirfd>=0 ){ |
| 27965 | close(dirfd); /* silently leak if fail, in error */ |
| 27966 | } |
| 27967 | close(fd); /* silently leak if fail, in error */ |
| 27968 | rc = SQLITE_IOERR_ACCESS; |
| 27969 | goto open_finished; |
| 27970 | } |
| 27971 | useProxy = !(fsInfo.f_flags&MNT_LOCAL); |
| 27972 | } |
| @@ -28023,13 +28098,11 @@ | |
| 28023 | if( fsync(fd) ) |
| 28024 | #endif |
| 28025 | { |
| 28026 | rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); |
| 28027 | } |
| 28028 | if( close(fd)&&!rc ){ |
| 28029 | rc = unixLogError(SQLITE_IOERR_DIR_CLOSE, "close", zPath); |
| 28030 | } |
| 28031 | } |
| 28032 | } |
| 28033 | #endif |
| 28034 | return rc; |
| 28035 | } |
| @@ -28213,11 +28286,11 @@ | |
| 28213 | memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); |
| 28214 | assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); |
| 28215 | nBuf = sizeof(t) + sizeof(pid); |
| 28216 | }else{ |
| 28217 | do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR ); |
| 28218 | close(fd); |
| 28219 | } |
| 28220 | } |
| 28221 | #endif |
| 28222 | return nBuf; |
| 28223 | } |
| @@ -28656,11 +28729,11 @@ | |
| 28656 | if( rc==SQLITE_OK ){ |
| 28657 | *ppFile = pNew; |
| 28658 | return SQLITE_OK; |
| 28659 | } |
| 28660 | end_create_proxy: |
| 28661 | close(fd); /* silently leak fd if error, we're already in error */ |
| 28662 | sqlite3_free(pNew); |
| 28663 | sqlite3_free(pUnused); |
| 28664 | return rc; |
| 28665 | } |
| 28666 | |
| @@ -28756,19 +28829,19 @@ | |
| 28756 | sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno); |
| 28757 | goto end_breaklock; |
| 28758 | } |
| 28759 | rc = 0; |
| 28760 | fprintf(stderr, "broke stale lock on %s\n", cPath); |
| 28761 | close(conchFile->h); |
| 28762 | conchFile->h = fd; |
| 28763 | conchFile->openFlags = O_RDWR | O_CREAT; |
| 28764 | |
| 28765 | end_breaklock: |
| 28766 | if( rc ){ |
| 28767 | if( fd>=0 ){ |
| 28768 | unlink(tPath); |
| 28769 | close(fd); |
| 28770 | } |
| 28771 | fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg); |
| 28772 | } |
| 28773 | return rc; |
| 28774 | } |
| @@ -28981,11 +29054,10 @@ | |
| 28981 | /* If we created a new conch file (not just updated the contents of a |
| 28982 | ** valid conch file), try to match the permissions of the database |
| 28983 | */ |
| 28984 | if( rc==SQLITE_OK && createConch ){ |
| 28985 | struct stat buf; |
| 28986 | int rc; |
| 28987 | int err = fstat(pFile->h, &buf); |
| 28988 | if( err==0 ){ |
| 28989 | mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | |
| 28990 | S_IROTH|S_IWOTH); |
| 28991 | /* try to match the database file R/W permissions, ignore failure */ |
| @@ -29014,18 +29086,11 @@ | |
| 29014 | |
| 29015 | end_takeconch: |
| 29016 | OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h)); |
| 29017 | if( rc==SQLITE_OK && pFile->openFlags ){ |
| 29018 | if( pFile->h>=0 ){ |
| 29019 | #ifdef STRICT_CLOSE_ERROR |
| 29020 | if( close(pFile->h) ){ |
| 29021 | pFile->lastErrno = errno; |
| 29022 | return SQLITE_IOERR_CLOSE; |
| 29023 | } |
| 29024 | #else |
| 29025 | close(pFile->h); /* silently leak fd if fail */ |
| 29026 | #endif |
| 29027 | } |
| 29028 | pFile->h = -1; |
| 29029 | int fd = open(pCtx->dbPath, pFile->openFlags, |
| 29030 | SQLITE_DEFAULT_FILE_PERMISSIONS); |
| 29031 | OSTRACE(("TRANSPROXY: OPEN %d\n", fd)); |
| @@ -43555,11 +43620,10 @@ | |
| 43555 | if( rc!=SQLITE_OK ){ |
| 43556 | return rc; |
| 43557 | } |
| 43558 | assert( pIter ); |
| 43559 | |
| 43560 | mxPage = pWal->hdr.nPage; |
| 43561 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall; |
| 43562 | |
| 43563 | /* Compute in mxSafeFrame the index of the last frame of the WAL that is |
| 43564 | ** safe to write into the database. Frames beyond mxSafeFrame might |
| 43565 | ** overwrite database pages that are in use by active readers and thus |
| @@ -51996,13 +52060,11 @@ | |
| 51996 | minI = j; |
| 51997 | minV = apNew[j]->pgno; |
| 51998 | } |
| 51999 | } |
| 52000 | if( minI>i ){ |
| 52001 | int t; |
| 52002 | MemPage *pT; |
| 52003 | t = apNew[i]->pgno; |
| 52004 | pT = apNew[i]; |
| 52005 | apNew[i] = apNew[minI]; |
| 52006 | apNew[minI] = pT; |
| 52007 | } |
| 52008 | } |
| @@ -55005,11 +55067,11 @@ | |
| 55005 | if( flags & MEM_Int ){ |
| 55006 | return pMem->u.i; |
| 55007 | }else if( flags & MEM_Real ){ |
| 55008 | return doubleToInt64(pMem->r); |
| 55009 | }else if( flags & (MEM_Str|MEM_Blob) ){ |
| 55010 | i64 value; |
| 55011 | assert( pMem->z || pMem->n==0 ); |
| 55012 | testcase( pMem->z==0 ); |
| 55013 | sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc); |
| 55014 | return value; |
| 55015 | }else{ |
| @@ -57310,11 +57372,11 @@ | |
| 57310 | ** pointers to VdbeFrame objects, which may in turn contain pointers to |
| 57311 | ** open cursors. |
| 57312 | */ |
| 57313 | static void closeAllCursors(Vdbe *p){ |
| 57314 | if( p->pFrame ){ |
| 57315 | VdbeFrame *pFrame = p->pFrame; |
| 57316 | for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 57317 | sqlite3VdbeFrameRestore(pFrame); |
| 57318 | } |
| 57319 | p->pFrame = 0; |
| 57320 | p->nFrame = 0; |
| @@ -58290,11 +58352,17 @@ | |
| 58290 | i64 i = pMem->u.i; |
| 58291 | u64 u; |
| 58292 | if( file_format>=4 && (i&1)==i ){ |
| 58293 | return 8+(u32)i; |
| 58294 | } |
| 58295 | u = i<0 ? -i : i; |
| 58296 | if( u<=127 ) return 1; |
| 58297 | if( u<=32767 ) return 2; |
| 58298 | if( u<=8388607 ) return 3; |
| 58299 | if( u<=2147483647 ) return 4; |
| 58300 | if( u<=MAX_6BYTE ) return 5; |
| @@ -59640,17 +59708,15 @@ | |
| 59640 | ** If iCol is not valid, return a pointer to a Mem which has a value |
| 59641 | ** of NULL. |
| 59642 | */ |
| 59643 | static Mem *columnMem(sqlite3_stmt *pStmt, int i){ |
| 59644 | Vdbe *pVm; |
| 59645 | int vals; |
| 59646 | Mem *pOut; |
| 59647 | |
| 59648 | pVm = (Vdbe *)pStmt; |
| 59649 | if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){ |
| 59650 | sqlite3_mutex_enter(pVm->db->mutex); |
| 59651 | vals = sqlite3_data_count(pStmt); |
| 59652 | pOut = &pVm->pResultSet[i]; |
| 59653 | }else{ |
| 59654 | /* If the value passed as the second argument is out of range, return |
| 59655 | ** a pointer to the following static Mem object which contains the |
| 59656 | ** value SQL NULL. Even though the Mem structure contains an element |
| @@ -61138,12 +61204,14 @@ | |
| 61138 | sqlite3_context ctx; |
| 61139 | sqlite3_value **apVal; |
| 61140 | int n; |
| 61141 | } ag; |
| 61142 | struct OP_ShiftRight_stack_vars { |
| 61143 | i64 a; |
| 61144 | i64 b; |
| 61145 | } ah; |
| 61146 | struct OP_Ge_stack_vars { |
| 61147 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 61148 | char affinity; /* Affinity to use for comparison */ |
| 61149 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| @@ -62189,23 +62257,16 @@ | |
| 62189 | if( (u.af.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; |
| 62190 | if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ |
| 62191 | u.af.iA = pIn1->u.i; |
| 62192 | u.af.iB = pIn2->u.i; |
| 62193 | switch( pOp->opcode ){ |
| 62194 | case OP_Add: u.af.iB += u.af.iA; break; |
| 62195 | case OP_Subtract: u.af.iB -= u.af.iA; break; |
| 62196 | case OP_Multiply: u.af.iB *= u.af.iA; break; |
| 62197 | case OP_Divide: { |
| 62198 | if( u.af.iA==0 ) goto arithmetic_result_is_null; |
| 62199 | /* Dividing the largest possible negative 64-bit integer (1<<63) by |
| 62200 | ** -1 returns an integer too large to store in a 64-bit data-type. On |
| 62201 | ** some architectures, the value overflows to (1<<63). On others, |
| 62202 | ** a SIGFPE is issued. The following statement normalizes this |
| 62203 | ** behavior so that all architectures behave as if integer |
| 62204 | ** overflow occurred. |
| 62205 | */ |
| 62206 | if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) u.af.iA = 1; |
| 62207 | u.af.iB /= u.af.iA; |
| 62208 | break; |
| 62209 | } |
| 62210 | default: { |
| 62211 | if( u.af.iA==0 ) goto arithmetic_result_is_null; |
| @@ -62215,10 +62276,11 @@ | |
| 62215 | } |
| 62216 | } |
| 62217 | pOut->u.i = u.af.iB; |
| 62218 | MemSetTypeFlag(pOut, MEM_Int); |
| 62219 | }else{ |
| 62220 | u.af.rA = sqlite3VdbeRealValue(pIn1); |
| 62221 | u.af.rB = sqlite3VdbeRealValue(pIn2); |
| 62222 | switch( pOp->opcode ){ |
| 62223 | case OP_Add: u.af.rB += u.af.rA; break; |
| 62224 | case OP_Subtract: u.af.rB -= u.af.rA; break; |
| @@ -62412,31 +62474,55 @@ | |
| 62412 | case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */ |
| 62413 | case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */ |
| 62414 | case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */ |
| 62415 | case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */ |
| 62416 | #if 0 /* local variables moved into u.ah */ |
| 62417 | i64 a; |
| 62418 | i64 b; |
| 62419 | #endif /* local variables moved into u.ah */ |
| 62420 | |
| 62421 | pIn1 = &aMem[pOp->p1]; |
| 62422 | pIn2 = &aMem[pOp->p2]; |
| 62423 | pOut = &aMem[pOp->p3]; |
| 62424 | if( (pIn1->flags | pIn2->flags) & MEM_Null ){ |
| 62425 | sqlite3VdbeMemSetNull(pOut); |
| 62426 | break; |
| 62427 | } |
| 62428 | u.ah.a = sqlite3VdbeIntValue(pIn2); |
| 62429 | u.ah.b = sqlite3VdbeIntValue(pIn1); |
| 62430 | switch( pOp->opcode ){ |
| 62431 | case OP_BitAnd: u.ah.a &= u.ah.b; break; |
| 62432 | case OP_BitOr: u.ah.a |= u.ah.b; break; |
| 62433 | case OP_ShiftLeft: u.ah.a <<= u.ah.b; break; |
| 62434 | default: assert( pOp->opcode==OP_ShiftRight ); |
| 62435 | u.ah.a >>= u.ah.b; break; |
| 62436 | } |
| 62437 | pOut->u.i = u.ah.a; |
| 62438 | MemSetTypeFlag(pOut, MEM_Int); |
| 62439 | break; |
| 62440 | } |
| 62441 | |
| 62442 | /* Opcode: AddImm P1 P2 * * * |
| @@ -63372,11 +63458,10 @@ | |
| 63372 | ** hdr-size field is also a varint which is the offset from the beginning |
| 63373 | ** of the record to data0. |
| 63374 | */ |
| 63375 | u.ao.nData = 0; /* Number of bytes of data space */ |
| 63376 | u.ao.nHdr = 0; /* Number of bytes of header space */ |
| 63377 | u.ao.nByte = 0; /* Data space required for this record */ |
| 63378 | u.ao.nZero = 0; /* Number of zero bytes at the end of the record */ |
| 63379 | u.ao.nField = pOp->p1; |
| 63380 | u.ao.zAffinity = pOp->p4.z; |
| 63381 | assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 ); |
| 63382 | u.ao.pData0 = &aMem[u.ao.nField]; |
| @@ -64678,11 +64763,10 @@ | |
| 64678 | ** it already exists in the table. If it does not exist, we have |
| 64679 | ** succeeded. If the random rowid does exist, we select a new one |
| 64680 | ** and try again, up to 100 times. |
| 64681 | */ |
| 64682 | assert( u.be.pC->isTable ); |
| 64683 | u.be.cnt = 0; |
| 64684 | |
| 64685 | #ifdef SQLITE_32BIT_ROWID |
| 64686 | # define MAX_ROWID 0x7fffffff |
| 64687 | #else |
| 64688 | /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| @@ -71317,11 +71401,11 @@ | |
| 71317 | const char *z = pExpr->u.zToken; |
| 71318 | assert( z!=0 ); |
| 71319 | c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8); |
| 71320 | if( c==0 || (c==2 && negFlag) ){ |
| 71321 | char *zV; |
| 71322 | if( negFlag ){ value = -value; } |
| 71323 | zV = dup8bytes(v, (char*)&value); |
| 71324 | sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64); |
| 71325 | }else{ |
| 71326 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 71327 | sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); |
| @@ -81443,17 +81527,12 @@ | |
| 81443 | if( p && type!=SQLITE_NULL ){ |
| 81444 | p->cnt++; |
| 81445 | if( type==SQLITE_INTEGER ){ |
| 81446 | i64 v = sqlite3_value_int64(argv[0]); |
| 81447 | p->rSum += v; |
| 81448 | if( (p->approx|p->overflow)==0 ){ |
| 81449 | i64 iNewSum = p->iSum + v; |
| 81450 | int s1 = (int)(p->iSum >> (sizeof(i64)*8-1)); |
| 81451 | int s2 = (int)(v >> (sizeof(i64)*8-1)); |
| 81452 | int s3 = (int)(iNewSum >> (sizeof(i64)*8-1)); |
| 81453 | p->overflow = ((s1&s2&~s3) | (~s1&~s2&s3))?1:0; |
| 81454 | p->iSum = iNewSum; |
| 81455 | } |
| 81456 | }else{ |
| 81457 | p->rSum += sqlite3_value_double(argv[0]); |
| 81458 | p->approx = 1; |
| 81459 | } |
| @@ -82489,11 +82568,10 @@ | |
| 82489 | Table *pTab, /* Row is being deleted from this table */ |
| 82490 | int regOld, /* Previous row data is stored here */ |
| 82491 | int regNew /* New row data is stored here */ |
| 82492 | ){ |
| 82493 | sqlite3 *db = pParse->db; /* Database handle */ |
| 82494 | Vdbe *v; /* VM to write code to */ |
| 82495 | FKey *pFKey; /* Used to iterate through FKs */ |
| 82496 | int iDb; /* Index of database containing pTab */ |
| 82497 | const char *zDb; /* Name of database containing pTab */ |
| 82498 | int isIgnoreErrors = pParse->disableTriggers; |
| 82499 | |
| @@ -82501,11 +82579,10 @@ | |
| 82501 | assert( (regOld==0)!=(regNew==0) ); |
| 82502 | |
| 82503 | /* If foreign-keys are disabled, this function is a no-op. */ |
| 82504 | if( (db->flags&SQLITE_ForeignKeys)==0 ) return; |
| 82505 | |
| 82506 | v = sqlite3GetVdbe(pParse); |
| 82507 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 82508 | zDb = db->aDb[iDb].zName; |
| 82509 | |
| 82510 | /* Loop through all the foreign key constraints for which pTab is the |
| 82511 | ** child table (the table that the foreign key definition is part of). */ |
| @@ -83459,11 +83536,10 @@ | |
| 83459 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| 83460 | int regRowCount = 0; /* Memory cell used for the row counter */ |
| 83461 | int regIns; /* Block of regs holding rowid+data being inserted */ |
| 83462 | int regRowid; /* registers holding insert rowid */ |
| 83463 | int regData; /* register holding first column to insert */ |
| 83464 | int regRecord; /* Holds the assemblied row record */ |
| 83465 | int regEof = 0; /* Register recording end of SELECT data */ |
| 83466 | int *aRegIdx = 0; /* One register allocated to each index */ |
| 83467 | |
| 83468 | #ifndef SQLITE_OMIT_TRIGGER |
| 83469 | int isView; /* True if attempting to insert into a view */ |
| @@ -83788,11 +83864,10 @@ | |
| 83788 | } |
| 83789 | |
| 83790 | /* Allocate registers for holding the rowid of the new row, |
| 83791 | ** the content of the new row, and the assemblied row record. |
| 83792 | */ |
| 83793 | regRecord = ++pParse->nMem; |
| 83794 | regRowid = regIns = pParse->nMem+1; |
| 83795 | pParse->nMem += pTab->nCol + 1; |
| 83796 | if( IsVirtual(pTab) ){ |
| 83797 | regRowid++; |
| 83798 | pParse->nMem++; |
| @@ -84182,11 +84257,11 @@ | |
| 84182 | case OE_Abort: |
| 84183 | sqlite3MayAbort(pParse); |
| 84184 | case OE_Rollback: |
| 84185 | case OE_Fail: { |
| 84186 | char *zMsg; |
| 84187 | j1 = sqlite3VdbeAddOp3(v, OP_HaltIfNull, |
| 84188 | SQLITE_CONSTRAINT, onError, regData+i); |
| 84189 | zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL", |
| 84190 | pTab->zName, pTab->aCol[i].zName); |
| 84191 | sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); |
| 84192 | break; |
| @@ -87708,11 +87783,11 @@ | |
| 87708 | Db *pDb; |
| 87709 | char const *azArg[4]; |
| 87710 | int meta[5]; |
| 87711 | InitData initData; |
| 87712 | char const *zMasterSchema; |
| 87713 | char const *zMasterName = SCHEMA_TABLE(iDb); |
| 87714 | int openedTransaction = 0; |
| 87715 | |
| 87716 | /* |
| 87717 | ** The master database table has a structure like this |
| 87718 | */ |
| @@ -93351,11 +93426,10 @@ | |
| 93351 | sqlite3 *db = pParse->db; /* The database */ |
| 93352 | DbFixer sFix; /* Fixer object */ |
| 93353 | int iDb; /* Database containing the trigger */ |
| 93354 | Token nameToken; /* Trigger name for error reporting */ |
| 93355 | |
| 93356 | pTrig = pParse->pNewTrigger; |
| 93357 | pParse->pNewTrigger = 0; |
| 93358 | if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup; |
| 93359 | zName = pTrig->zName; |
| 93360 | iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema); |
| 93361 | pTrig->step_list = pStepList; |
| @@ -94314,11 +94388,10 @@ | |
| 94314 | int regOldRowid; /* The old rowid */ |
| 94315 | int regNewRowid; /* The new rowid */ |
| 94316 | int regNew; |
| 94317 | int regOld = 0; |
| 94318 | int regRowSet = 0; /* Rowset of rows to be updated */ |
| 94319 | int regRec; /* Register used for new table record to insert */ |
| 94320 | |
| 94321 | memset(&sContext, 0, sizeof(sContext)); |
| 94322 | db = pParse->db; |
| 94323 | if( pParse->nErr || db->mallocFailed ){ |
| 94324 | goto update_cleanup; |
| @@ -94472,11 +94545,10 @@ | |
| 94472 | if( chngRowid || pTrigger || hasFK ){ |
| 94473 | regNewRowid = ++pParse->nMem; |
| 94474 | } |
| 94475 | regNew = pParse->nMem + 1; |
| 94476 | pParse->nMem += pTab->nCol; |
| 94477 | regRec = ++pParse->nMem; |
| 94478 | |
| 94479 | /* Start the view context. */ |
| 94480 | if( isView ){ |
| 94481 | sqlite3AuthContextPush(pParse, &sContext, pTab->zName); |
| 94482 | } |
| @@ -94582,11 +94654,11 @@ | |
| 94582 | u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0); |
| 94583 | oldmask |= sqlite3TriggerColmask(pParse, |
| 94584 | pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError |
| 94585 | ); |
| 94586 | for(i=0; i<pTab->nCol; i++){ |
| 94587 | if( aXRef[i]<0 || oldmask==0xffffffff || (oldmask & (1<<i)) ){ |
| 94588 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i); |
| 94589 | }else{ |
| 94590 | sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i); |
| 94591 | } |
| 94592 | } |
| @@ -100187,11 +100259,10 @@ | |
| 100187 | ** |
| 100188 | ** B: <after the loop> |
| 100189 | ** |
| 100190 | */ |
| 100191 | WhereClause *pOrWc; /* The OR-clause broken out into subterms */ |
| 100192 | WhereTerm *pFinal; /* Final subterm within the OR-clause. */ |
| 100193 | SrcList *pOrTab; /* Shortened table list or OR-clause generation */ |
| 100194 | |
| 100195 | int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */ |
| 100196 | int regRowset = 0; /* Register for RowSet object */ |
| 100197 | int regRowid = 0; /* Register holding rowid */ |
| @@ -100203,11 +100274,10 @@ | |
| 100203 | pTerm = pLevel->plan.u.pTerm; |
| 100204 | assert( pTerm!=0 ); |
| 100205 | assert( pTerm->eOperator==WO_OR ); |
| 100206 | assert( (pTerm->wtFlags & TERM_ORINFO)!=0 ); |
| 100207 | pOrWc = &pTerm->u.pOrInfo->wc; |
| 100208 | pFinal = &pOrWc->a[pOrWc->nTerm-1]; |
| 100209 | pLevel->op = OP_Return; |
| 100210 | pLevel->p1 = regReturn; |
| 100211 | |
| 100212 | /* Set up a new SrcList ni pOrTab containing the table being scanned |
| 100213 | ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. |
| @@ -100312,11 +100382,10 @@ | |
| 100312 | ** |
| 100313 | ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through |
| 100314 | ** the use of indices become tests that are evaluated against each row of |
| 100315 | ** the relevant input tables. |
| 100316 | */ |
| 100317 | k = 0; |
| 100318 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 100319 | Expr *pE; |
| 100320 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */ |
| 100321 | testcase( pTerm->wtFlags & TERM_CODED ); |
| 100322 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| @@ -100330,11 +100399,10 @@ | |
| 100330 | assert( pE!=0 ); |
| 100331 | if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){ |
| 100332 | continue; |
| 100333 | } |
| 100334 | sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL); |
| 100335 | k = 1; |
| 100336 | pTerm->wtFlags |= TERM_CODED; |
| 100337 | } |
| 100338 | |
| 100339 | /* For a LEFT OUTER JOIN, generate code that will record the fact that |
| 100340 | ** at least one row of the right table has matched the left table. |
| @@ -100638,12 +100706,10 @@ | |
| 100638 | ** |
| 100639 | ** This loop also figures out the nesting order of tables in the FROM |
| 100640 | ** clause. |
| 100641 | */ |
| 100642 | notReady = ~(Bitmask)0; |
| 100643 | pTabItem = pTabList->a; |
| 100644 | pLevel = pWInfo->a; |
| 100645 | andFlags = ~0; |
| 100646 | WHERETRACE(("*** Optimizer Start ***\n")); |
| 100647 | for(i=iFrom=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){ |
| 100648 | WhereCost bestPlan; /* Most efficient plan seen so far */ |
| 100649 | Index *pIdx; /* Index for FROM table at pTabItem */ |
| @@ -100750,12 +100816,12 @@ | |
| 100750 | /* Conditions under which this table becomes the best so far: |
| 100751 | ** |
| 100752 | ** (1) The table must not depend on other tables that have not |
| 100753 | ** yet run. |
| 100754 | ** |
| 100755 | ** (2) A full-table-scan plan cannot supercede another plan unless |
| 100756 | ** it is an "optimal" plan as defined above. |
| 100757 | ** |
| 100758 | ** (3) All tables have an INDEXED BY clause or this table lacks an |
| 100759 | ** INDEXED BY clause or this table uses the specific |
| 100760 | ** index specified by its INDEXED BY clause. This rule ensures |
| 100761 | ** that a best-so-far is always selected even if an impossible |
| @@ -100767,10 +100833,11 @@ | |
| 100767 | ** (4) The plan cost must be lower than prior plans or else the |
| 100768 | ** cost must be the same and the number of rows must be lower. |
| 100769 | */ |
| 100770 | if( (sCost.used¬Ready)==0 /* (1) */ |
| 100771 | && (bestJ<0 || (notIndexed&m)!=0 /* (2) */ |
| 100772 | || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0) |
| 100773 | && (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */ |
| 100774 | || NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)) |
| 100775 | && (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */ |
| 100776 | || (sCost.rCost<=bestPlan.rCost |
| @@ -123657,11 +123724,11 @@ | |
| 123657 | int nCell = 0; |
| 123658 | RtreeCell cell; |
| 123659 | int jj; |
| 123660 | |
| 123661 | nodeGetCell(&tree, &node, ii, &cell); |
| 123662 | sqlite3_snprintf(512-nCell,&zCell[nCell],"%d", cell.iRowid); |
| 123663 | nCell = strlen(zCell); |
| 123664 | for(jj=0; jj<tree.nDim*2; jj++){ |
| 123665 | sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f); |
| 123666 | nCell = strlen(zCell); |
| 123667 | } |
| 123668 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -650,11 +650,11 @@ | |
| 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | */ |
| 653 | #define SQLITE_VERSION "3.7.6" |
| 654 | #define SQLITE_VERSION_NUMBER 3007006 |
| 655 | #define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61" |
| 656 | |
| 657 | /* |
| 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | ** |
| @@ -11206,10 +11206,13 @@ | |
| 11206 | SQLITE_PRIVATE Expr *sqlite3ExprSetColl(Expr*, CollSeq*); |
| 11207 | SQLITE_PRIVATE Expr *sqlite3ExprSetCollByToken(Parse *pParse, Expr*, Token*); |
| 11208 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 11209 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 11210 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 11211 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 11212 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| 11213 | SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); |
| 11214 | |
| 11215 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 11216 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 11217 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 11218 | void(*)(void*)); |
| @@ -18792,11 +18795,15 @@ | |
| 18795 | v = va_arg(ap,long int); |
| 18796 | }else{ |
| 18797 | v = va_arg(ap,int); |
| 18798 | } |
| 18799 | if( v<0 ){ |
| 18800 | if( v==SMALLEST_INT64 ){ |
| 18801 | longvalue = ((u64)1)<<63; |
| 18802 | }else{ |
| 18803 | longvalue = -v; |
| 18804 | } |
| 18805 | prefix = '-'; |
| 18806 | }else{ |
| 18807 | longvalue = v; |
| 18808 | if( flag_plussign ) prefix = '+'; |
| 18809 | else if( flag_blanksign ) prefix = ' '; |
| @@ -20566,64 +20573,84 @@ | |
| 20573 | return c; |
| 20574 | } |
| 20575 | |
| 20576 | |
| 20577 | /* |
| 20578 | ** Convert zNum to a 64-bit signed integer. |
| 20579 | ** |
| 20580 | ** If the zNum value is representable as a 64-bit twos-complement |
| 20581 | ** integer, then write that value into *pNum and return 0. |
| 20582 | ** |
| 20583 | ** If zNum is exactly 9223372036854665808, return 2. This special |
| 20584 | ** case is broken out because while 9223372036854665808 cannot be a |
| 20585 | ** signed 64-bit integer, its negative -9223372036854665808 can be. |
| 20586 | ** |
| 20587 | ** If zNum is too big for a 64-bit integer and is not |
| 20588 | ** 9223372036854665808 then return 1. |
| 20589 | ** |
| 20590 | ** length is the number of bytes in the string (bytes, not characters). |
| 20591 | ** The string is not necessarily zero-terminated. The encoding is |
| 20592 | ** given by enc. |
| 20593 | */ |
| 20594 | SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){ |
| 20595 | int incr = (enc==SQLITE_UTF8?1:2); |
| 20596 | u64 u = 0; |
| 20597 | int neg = 0; /* assume positive */ |
| 20598 | int i; |
| 20599 | int c = 0; |
| 20600 | const char *zStart; |
| 20601 | const char *zEnd = zNum + length; |
| 20602 | if( enc==SQLITE_UTF16BE ) zNum++; |
| 20603 | while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr; |
| 20604 | if( zNum<zEnd ){ |
| 20605 | if( *zNum=='-' ){ |
| 20606 | neg = 1; |
| 20607 | zNum+=incr; |
| 20608 | }else if( *zNum=='+' ){ |
| 20609 | zNum+=incr; |
| 20610 | } |
| 20611 | } |
| 20612 | zStart = zNum; |
| 20613 | while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */ |
| 20614 | for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){ |
| 20615 | u = u*10 + c - '0'; |
| 20616 | } |
| 20617 | if( u>LARGEST_INT64 ){ |
| 20618 | *pNum = SMALLEST_INT64; |
| 20619 | }else if( neg ){ |
| 20620 | *pNum = -(i64)u; |
| 20621 | }else{ |
| 20622 | *pNum = (i64)u; |
| 20623 | } |
| 20624 | testcase( i==18 ); |
| 20625 | testcase( i==19 ); |
| 20626 | testcase( i==20 ); |
| 20627 | if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr ){ |
| 20628 | /* zNum is empty or contains non-numeric text or is longer |
| 20629 | ** than 19 digits (thus guaranteeing that it is too large) */ |
| 20630 | return 1; |
| 20631 | }else if( i<19*incr ){ |
| 20632 | /* Less than 19 digits, so we know that it fits in 64 bits */ |
| 20633 | assert( u<=LARGEST_INT64 ); |
| 20634 | return 0; |
| 20635 | }else{ |
| 20636 | /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */ |
| 20637 | c = compare2pow63(zNum, incr); |
| 20638 | if( c<0 ){ |
| 20639 | /* zNum is less than 9223372036854775808 so it fits */ |
| 20640 | assert( u<=LARGEST_INT64 ); |
| 20641 | return 0; |
| 20642 | }else if( c>0 ){ |
| 20643 | /* zNum is greater than 9223372036854775808 so it overflows */ |
| 20644 | return 1; |
| 20645 | }else{ |
| 20646 | /* zNum is exactly 9223372036854775808. Fits if negative. The |
| 20647 | ** special case 2 overflow if positive */ |
| 20648 | assert( u-1==LARGEST_INT64 ); |
| 20649 | assert( (*pNum)==SMALLEST_INT64 ); |
| 20650 | return neg ? 0 : 2; |
| 20651 | } |
| 20652 | } |
| 20653 | } |
| 20654 | |
| 20655 | /* |
| 20656 | ** If zNum represents an integer that will fit in 32-bits, then set |
| @@ -21185,10 +21212,68 @@ | |
| 21212 | return 0; |
| 21213 | }else{ |
| 21214 | return 1; |
| 21215 | } |
| 21216 | } |
| 21217 | |
| 21218 | /* |
| 21219 | ** Attempt to add, substract, or multiply the 64-bit signed value iB against |
| 21220 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 21221 | ** Return 0 on success. Or if the operation would have resulted in an |
| 21222 | ** overflow, leave *pA unchanged and return 1. |
| 21223 | */ |
| 21224 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 21225 | i64 iA = *pA; |
| 21226 | testcase( iA==0 ); testcase( iA==1 ); |
| 21227 | testcase( iB==-1 ); testcase( iB==0 ); |
| 21228 | if( iB>=0 ){ |
| 21229 | testcase( iA>0 && LARGEST_INT64 - iA == iB ); |
| 21230 | testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 ); |
| 21231 | if( iA>0 && LARGEST_INT64 - iA < iB ) return 1; |
| 21232 | *pA += iB; |
| 21233 | }else{ |
| 21234 | testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 ); |
| 21235 | testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); |
| 21236 | if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; |
| 21237 | *pA += iB; |
| 21238 | } |
| 21239 | return 0; |
| 21240 | } |
| 21241 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 21242 | testcase( iB==SMALLEST_INT64+1 ); |
| 21243 | if( iB==SMALLEST_INT64 ){ |
| 21244 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| 21245 | if( (*pA)>=0 ) return 1; |
| 21246 | *pA -= iB; |
| 21247 | return 0; |
| 21248 | }else{ |
| 21249 | return sqlite3AddInt64(pA, -iB); |
| 21250 | } |
| 21251 | } |
| 21252 | #define TWOPOWER32 (((i64)1)<<32) |
| 21253 | #define TWOPOWER31 (((i64)1)<<31) |
| 21254 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 21255 | i64 iA = *pA; |
| 21256 | i64 iA1, iA0, iB1, iB0, r; |
| 21257 | |
| 21258 | iA1 = iA/TWOPOWER32; |
| 21259 | iA0 = iA % TWOPOWER32; |
| 21260 | iB1 = iB/TWOPOWER32; |
| 21261 | iB0 = iB % TWOPOWER32; |
| 21262 | if( iA1*iB1 != 0 ) return 1; |
| 21263 | assert( iA1*iB0==0 || iA0*iB1==0 ); |
| 21264 | r = iA1*iB0 + iA0*iB1; |
| 21265 | testcase( r==(-TWOPOWER31)-1 ); |
| 21266 | testcase( r==(-TWOPOWER31) ); |
| 21267 | testcase( r==TWOPOWER31 ); |
| 21268 | testcase( r==TWOPOWER31-1 ); |
| 21269 | if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1; |
| 21270 | r *= TWOPOWER32; |
| 21271 | if( sqlite3AddInt64(&r, iA0*iB0) ) return 1; |
| 21272 | *pA = r; |
| 21273 | return 0; |
| 21274 | } |
| 21275 | |
| 21276 | /************** End of util.c ************************************************/ |
| 21277 | /************** Begin file hash.c ********************************************/ |
| 21278 | /* |
| 21279 | ** 2001 September 22 |
| @@ -23930,18 +24015,19 @@ | |
| 24015 | ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). |
| 24016 | ** The two subsequent arguments should be the name of the OS function that |
| 24017 | ** failed (e.g. "unlink", "open") and the the associated file-system path, |
| 24018 | ** if any. |
| 24019 | */ |
| 24020 | #define unixLogError(a,b,c) unixLogErrorAtLine(a,b,c,__LINE__) |
| 24021 | static int unixLogErrorAtLine( |
| 24022 | int errcode, /* SQLite error code */ |
| 24023 | const char *zFunc, /* Name of OS function that failed */ |
| 24024 | const char *zPath, /* File path associated with error */ |
| 24025 | int iLine /* Source line number where error occurred */ |
| 24026 | ){ |
| 24027 | char *zErr; /* Message from strerror() or equivalent */ |
| 24028 | int iErrno = errno; /* Saved syscall error number */ |
| 24029 | |
| 24030 | /* If this is not a threadsafe build (SQLITE_THREADSAFE==0), then use |
| 24031 | ** the strerror() function to obtain the human-readable error message |
| 24032 | ** equivalent to errno. Otherwise, use strerror_r(). |
| 24033 | */ |
| @@ -23963,58 +24049,63 @@ | |
| 24049 | ** could lead to a segfault though. |
| 24050 | */ |
| 24051 | #if defined(STRERROR_R_CHAR_P) || defined(__USE_GNU) |
| 24052 | zErr = |
| 24053 | # endif |
| 24054 | strerror_r(iErrno, aErr, sizeof(aErr)-1); |
| 24055 | |
| 24056 | #elif SQLITE_THREADSAFE |
| 24057 | /* This is a threadsafe build, but strerror_r() is not available. */ |
| 24058 | zErr = ""; |
| 24059 | #else |
| 24060 | /* Non-threadsafe build, use strerror(). */ |
| 24061 | zErr = strerror(iErrno); |
| 24062 | #endif |
| 24063 | |
| 24064 | assert( errcode!=SQLITE_OK ); |
| 24065 | if( zPath==0 ) zPath = ""; |
| 24066 | sqlite3_log(errcode, |
| 24067 | "os_unix.c:%d: (%d) %s(%s) - %s", |
| 24068 | iLine, iErrno, zFunc, zPath, zErr |
| 24069 | ); |
| 24070 | |
| 24071 | return errcode; |
| 24072 | } |
| 24073 | |
| 24074 | /* |
| 24075 | ** Close a file descriptor. |
| 24076 | ** |
| 24077 | ** We assume that close() almost always works, since it is only in a |
| 24078 | ** very sick application or on a very sick platform that it might fail. |
| 24079 | ** If it does fail, simply leak the file descriptor, but do log the |
| 24080 | ** error. |
| 24081 | ** |
| 24082 | ** Note that it is not safe to retry close() after EINTR since the |
| 24083 | ** file descriptor might have already been reused by another thread. |
| 24084 | ** So we don't even try to recover from an EINTR. Just log the error |
| 24085 | ** and move on. |
| 24086 | */ |
| 24087 | static void robust_close(unixFile *pFile, int h, int lineno){ |
| 24088 | if( close(h) ){ |
| 24089 | unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close", |
| 24090 | pFile ? pFile->zPath : 0, lineno); |
| 24091 | } |
| 24092 | } |
| 24093 | |
| 24094 | /* |
| 24095 | ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. |
| 24096 | */ |
| 24097 | static void closePendingFds(unixFile *pFile){ |
| 24098 | unixInodeInfo *pInode = pFile->pInode; |
| 24099 | UnixUnusedFd *p; |
| 24100 | UnixUnusedFd *pNext; |
| 24101 | for(p=pInode->pUnused; p; p=pNext){ |
| 24102 | pNext = p->pNext; |
| 24103 | robust_close(pFile, p->fd, __LINE__); |
| 24104 | sqlite3_free(p); |
| 24105 | } |
| 24106 | pInode->pUnused = 0; |
| 24107 | } |
| 24108 | |
| 24109 | /* |
| 24110 | ** Release a unixInodeInfo structure previously allocated by findInodeInfo(). |
| 24111 | ** |
| @@ -24621,14 +24712,11 @@ | |
| 24712 | ** was deferred because of outstanding locks. |
| 24713 | */ |
| 24714 | pInode->nLock--; |
| 24715 | assert( pInode->nLock>=0 ); |
| 24716 | if( pInode->nLock==0 ){ |
| 24717 | closePendingFds(pFile); |
| 24718 | } |
| 24719 | } |
| 24720 | |
| 24721 | end_unlock: |
| 24722 | unixLeaveMutex(); |
| @@ -24659,24 +24747,16 @@ | |
| 24747 | */ |
| 24748 | static int closeUnixFile(sqlite3_file *id){ |
| 24749 | unixFile *pFile = (unixFile*)id; |
| 24750 | if( pFile ){ |
| 24751 | if( pFile->dirfd>=0 ){ |
| 24752 | robust_close(pFile, pFile->dirfd, __LINE__); |
| 24753 | pFile->dirfd=-1; |
| 24754 | } |
| 24755 | if( pFile->h>=0 ){ |
| 24756 | robust_close(pFile, pFile->h, __LINE__); |
| 24757 | pFile->h = -1; |
| 24758 | } |
| 24759 | #if OS_VXWORKS |
| 24760 | if( pFile->pId ){ |
| 24761 | if( pFile->isDelete ){ |
| 24762 | unlink(pFile->pId->zCanonicalName); |
| @@ -24882,14 +24962,11 @@ | |
| 24962 | pFile->lastErrno = tErrno; |
| 24963 | } |
| 24964 | } |
| 24965 | return rc; |
| 24966 | } |
| 24967 | robust_close(pFile, fd, __LINE__); |
| 24968 | |
| 24969 | /* got it, set the type and return ok */ |
| 24970 | pFile->eFileLock = eFileLock; |
| 24971 | return rc; |
| 24972 | } |
| @@ -25777,11 +25854,11 @@ | |
| 25854 | } |
| 25855 | if( rc==SQLITE_OK ){ |
| 25856 | pInode->nLock--; |
| 25857 | assert( pInode->nLock>=0 ); |
| 25858 | if( pInode->nLock==0 ){ |
| 25859 | closePendingFds(pFile); |
| 25860 | } |
| 25861 | } |
| 25862 | } |
| 25863 | |
| 25864 | unixLeaveMutex(); |
| @@ -26210,11 +26287,10 @@ | |
| 26287 | if( rc ){ |
| 26288 | pFile->lastErrno = errno; |
| 26289 | return unixLogError(SQLITE_IOERR_FSYNC, "full_fsync", pFile->zPath); |
| 26290 | } |
| 26291 | if( pFile->dirfd>=0 ){ |
| 26292 | OSTRACE(("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd, |
| 26293 | HAVE_FULLFSYNC, isFullsync)); |
| 26294 | #ifndef SQLITE_DISABLE_DIRSYNC |
| 26295 | /* The directory sync is only attempted if full_fsync is |
| 26296 | ** turned off or unavailable. If a full_fsync occurred above, |
| @@ -26229,17 +26305,13 @@ | |
| 26305 | */ |
| 26306 | /* pFile->lastErrno = errno; */ |
| 26307 | /* return SQLITE_IOERR; */ |
| 26308 | } |
| 26309 | #endif |
| 26310 | /* Only need to sync once, so close the directory when we are done */ |
| 26311 | robust_close(pFile, pFile->dirfd, __LINE__); |
| 26312 | pFile->dirfd = -1; |
| 26313 | } |
| 26314 | return rc; |
| 26315 | } |
| 26316 | |
| 26317 | /* |
| @@ -26602,11 +26674,14 @@ | |
| 26674 | if( p->mutex ) sqlite3_mutex_free(p->mutex); |
| 26675 | for(i=0; i<p->nRegion; i++){ |
| 26676 | munmap(p->apRegion[i], p->szRegion); |
| 26677 | } |
| 26678 | sqlite3_free(p->apRegion); |
| 26679 | if( p->h>=0 ){ |
| 26680 | robust_close(pFd, p->h, __LINE__); |
| 26681 | p->h = -1; |
| 26682 | } |
| 26683 | p->pInode->pShmNode = 0; |
| 26684 | sqlite3_free(p); |
| 26685 | } |
| 26686 | } |
| 26687 | |
| @@ -27413,11 +27488,11 @@ | |
| 27488 | ** |
| 27489 | ** If scenario (a) caused the error then things are not so safe. The |
| 27490 | ** implicit assumption here is that if fstat() fails, things are in |
| 27491 | ** such bad shape that dropping a lock or two doesn't matter much. |
| 27492 | */ |
| 27493 | robust_close(pNew, h, __LINE__); |
| 27494 | h = -1; |
| 27495 | } |
| 27496 | unixLeaveMutex(); |
| 27497 | } |
| 27498 | |
| @@ -27439,11 +27514,11 @@ | |
| 27514 | srandomdev(); |
| 27515 | unixEnterMutex(); |
| 27516 | rc = findInodeInfo(pNew, &pNew->pInode); |
| 27517 | if( rc!=SQLITE_OK ){ |
| 27518 | sqlite3_free(pNew->lockingContext); |
| 27519 | robust_close(pNew, h, __LINE__); |
| 27520 | h = -1; |
| 27521 | } |
| 27522 | unixLeaveMutex(); |
| 27523 | } |
| 27524 | } |
| @@ -27490,20 +27565,20 @@ | |
| 27565 | #endif |
| 27566 | |
| 27567 | pNew->lastErrno = 0; |
| 27568 | #if OS_VXWORKS |
| 27569 | if( rc!=SQLITE_OK ){ |
| 27570 | if( h>=0 ) robust_close(pNew, h, __LINE__); |
| 27571 | h = -1; |
| 27572 | unlink(zFilename); |
| 27573 | isDelete = 0; |
| 27574 | } |
| 27575 | pNew->isDelete = isDelete; |
| 27576 | #endif |
| 27577 | if( rc!=SQLITE_OK ){ |
| 27578 | if( dirfd>=0 ) robust_close(pNew, dirfd, __LINE__); |
| 27579 | if( h>=0 ) robust_close(pNew, h, __LINE__); |
| 27580 | }else{ |
| 27581 | pNew->pMethod = pLockingStyle; |
| 27582 | OpenCounter(+1); |
| 27583 | } |
| 27584 | return rc; |
| @@ -27911,11 +27986,11 @@ | |
| 27986 | /* It is safe to close fd at this point, because it is guaranteed not |
| 27987 | ** to be open on a database file. If it were open on a database file, |
| 27988 | ** it would not be safe to close as this would release any locks held |
| 27989 | ** on the file by this process. */ |
| 27990 | assert( eType!=SQLITE_OPEN_MAIN_DB ); |
| 27991 | robust_close(p, fd, __LINE__); |
| 27992 | goto open_finished; |
| 27993 | } |
| 27994 | } |
| 27995 | |
| 27996 | #ifdef FD_CLOEXEC |
| @@ -27927,12 +28002,12 @@ | |
| 28002 | |
| 28003 | #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE |
| 28004 | struct statfs fsInfo; |
| 28005 | if( fstatfs(fd, &fsInfo) == -1 ){ |
| 28006 | ((unixFile*)pFile)->lastErrno = errno; |
| 28007 | if( dirfd>=0 ) robust_close(p, dirfd, __LINE__); |
| 28008 | robust_close(p, fd, __LINE__); |
| 28009 | return SQLITE_IOERR_ACCESS; |
| 28010 | } |
| 28011 | if (0 == strncmp("msdos", fsInfo.f_fstypename, 5)) { |
| 28012 | ((unixFile*)pFile)->fsFlags |= SQLITE_FSFLAGS_IS_MSDOS; |
| 28013 | } |
| @@ -27960,13 +28035,13 @@ | |
| 28035 | ** we're assuming that statfs() doesn't fail very often. At least |
| 28036 | ** not while other file descriptors opened by the same process on |
| 28037 | ** the same file are working. */ |
| 28038 | p->lastErrno = errno; |
| 28039 | if( dirfd>=0 ){ |
| 28040 | robust_close(p, dirfd, __LINE__); |
| 28041 | } |
| 28042 | robust_close(p, fd, __LINE__); |
| 28043 | rc = SQLITE_IOERR_ACCESS; |
| 28044 | goto open_finished; |
| 28045 | } |
| 28046 | useProxy = !(fsInfo.f_flags&MNT_LOCAL); |
| 28047 | } |
| @@ -28023,13 +28098,11 @@ | |
| 28098 | if( fsync(fd) ) |
| 28099 | #endif |
| 28100 | { |
| 28101 | rc = unixLogError(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath); |
| 28102 | } |
| 28103 | robust_close(0, fd, __LINE__); |
| 28104 | } |
| 28105 | } |
| 28106 | #endif |
| 28107 | return rc; |
| 28108 | } |
| @@ -28213,11 +28286,11 @@ | |
| 28286 | memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); |
| 28287 | assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); |
| 28288 | nBuf = sizeof(t) + sizeof(pid); |
| 28289 | }else{ |
| 28290 | do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR ); |
| 28291 | robust_close(0, fd, __LINE__); |
| 28292 | } |
| 28293 | } |
| 28294 | #endif |
| 28295 | return nBuf; |
| 28296 | } |
| @@ -28656,11 +28729,11 @@ | |
| 28729 | if( rc==SQLITE_OK ){ |
| 28730 | *ppFile = pNew; |
| 28731 | return SQLITE_OK; |
| 28732 | } |
| 28733 | end_create_proxy: |
| 28734 | robust_close(pNew, fd, __LINE__); |
| 28735 | sqlite3_free(pNew); |
| 28736 | sqlite3_free(pUnused); |
| 28737 | return rc; |
| 28738 | } |
| 28739 | |
| @@ -28756,19 +28829,19 @@ | |
| 28829 | sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno); |
| 28830 | goto end_breaklock; |
| 28831 | } |
| 28832 | rc = 0; |
| 28833 | fprintf(stderr, "broke stale lock on %s\n", cPath); |
| 28834 | robust_close(pFile, conchFile->h, __LINE__); |
| 28835 | conchFile->h = fd; |
| 28836 | conchFile->openFlags = O_RDWR | O_CREAT; |
| 28837 | |
| 28838 | end_breaklock: |
| 28839 | if( rc ){ |
| 28840 | if( fd>=0 ){ |
| 28841 | unlink(tPath); |
| 28842 | robust_close(pFile, fd, __LINE__); |
| 28843 | } |
| 28844 | fprintf(stderr, "failed to break stale lock on %s, %s\n", cPath, errmsg); |
| 28845 | } |
| 28846 | return rc; |
| 28847 | } |
| @@ -28981,11 +29054,10 @@ | |
| 29054 | /* If we created a new conch file (not just updated the contents of a |
| 29055 | ** valid conch file), try to match the permissions of the database |
| 29056 | */ |
| 29057 | if( rc==SQLITE_OK && createConch ){ |
| 29058 | struct stat buf; |
| 29059 | int err = fstat(pFile->h, &buf); |
| 29060 | if( err==0 ){ |
| 29061 | mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | |
| 29062 | S_IROTH|S_IWOTH); |
| 29063 | /* try to match the database file R/W permissions, ignore failure */ |
| @@ -29014,18 +29086,11 @@ | |
| 29086 | |
| 29087 | end_takeconch: |
| 29088 | OSTRACE(("TRANSPROXY: CLOSE %d\n", pFile->h)); |
| 29089 | if( rc==SQLITE_OK && pFile->openFlags ){ |
| 29090 | if( pFile->h>=0 ){ |
| 29091 | robust_close(pFile, pFile->h, __LINE__); |
| 29092 | } |
| 29093 | pFile->h = -1; |
| 29094 | int fd = open(pCtx->dbPath, pFile->openFlags, |
| 29095 | SQLITE_DEFAULT_FILE_PERMISSIONS); |
| 29096 | OSTRACE(("TRANSPROXY: OPEN %d\n", fd)); |
| @@ -43555,11 +43620,10 @@ | |
| 43620 | if( rc!=SQLITE_OK ){ |
| 43621 | return rc; |
| 43622 | } |
| 43623 | assert( pIter ); |
| 43624 | |
| 43625 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall; |
| 43626 | |
| 43627 | /* Compute in mxSafeFrame the index of the last frame of the WAL that is |
| 43628 | ** safe to write into the database. Frames beyond mxSafeFrame might |
| 43629 | ** overwrite database pages that are in use by active readers and thus |
| @@ -51996,13 +52060,11 @@ | |
| 52060 | minI = j; |
| 52061 | minV = apNew[j]->pgno; |
| 52062 | } |
| 52063 | } |
| 52064 | if( minI>i ){ |
| 52065 | MemPage *pT; |
| 52066 | pT = apNew[i]; |
| 52067 | apNew[i] = apNew[minI]; |
| 52068 | apNew[minI] = pT; |
| 52069 | } |
| 52070 | } |
| @@ -55005,11 +55067,11 @@ | |
| 55067 | if( flags & MEM_Int ){ |
| 55068 | return pMem->u.i; |
| 55069 | }else if( flags & MEM_Real ){ |
| 55070 | return doubleToInt64(pMem->r); |
| 55071 | }else if( flags & (MEM_Str|MEM_Blob) ){ |
| 55072 | i64 value = 0; |
| 55073 | assert( pMem->z || pMem->n==0 ); |
| 55074 | testcase( pMem->z==0 ); |
| 55075 | sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc); |
| 55076 | return value; |
| 55077 | }else{ |
| @@ -57310,11 +57372,11 @@ | |
| 57372 | ** pointers to VdbeFrame objects, which may in turn contain pointers to |
| 57373 | ** open cursors. |
| 57374 | */ |
| 57375 | static void closeAllCursors(Vdbe *p){ |
| 57376 | if( p->pFrame ){ |
| 57377 | VdbeFrame *pFrame; |
| 57378 | for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 57379 | sqlite3VdbeFrameRestore(pFrame); |
| 57380 | } |
| 57381 | p->pFrame = 0; |
| 57382 | p->nFrame = 0; |
| @@ -58290,11 +58352,17 @@ | |
| 58352 | i64 i = pMem->u.i; |
| 58353 | u64 u; |
| 58354 | if( file_format>=4 && (i&1)==i ){ |
| 58355 | return 8+(u32)i; |
| 58356 | } |
| 58357 | if( i<0 ){ |
| 58358 | if( i<(-MAX_6BYTE) ) return 6; |
| 58359 | /* Previous test prevents: u = -(-9223372036854775808) */ |
| 58360 | u = -i; |
| 58361 | }else{ |
| 58362 | u = i; |
| 58363 | } |
| 58364 | if( u<=127 ) return 1; |
| 58365 | if( u<=32767 ) return 2; |
| 58366 | if( u<=8388607 ) return 3; |
| 58367 | if( u<=2147483647 ) return 4; |
| 58368 | if( u<=MAX_6BYTE ) return 5; |
| @@ -59640,17 +59708,15 @@ | |
| 59708 | ** If iCol is not valid, return a pointer to a Mem which has a value |
| 59709 | ** of NULL. |
| 59710 | */ |
| 59711 | static Mem *columnMem(sqlite3_stmt *pStmt, int i){ |
| 59712 | Vdbe *pVm; |
| 59713 | Mem *pOut; |
| 59714 | |
| 59715 | pVm = (Vdbe *)pStmt; |
| 59716 | if( pVm && pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){ |
| 59717 | sqlite3_mutex_enter(pVm->db->mutex); |
| 59718 | pOut = &pVm->pResultSet[i]; |
| 59719 | }else{ |
| 59720 | /* If the value passed as the second argument is out of range, return |
| 59721 | ** a pointer to the following static Mem object which contains the |
| 59722 | ** value SQL NULL. Even though the Mem structure contains an element |
| @@ -61138,12 +61204,14 @@ | |
| 61204 | sqlite3_context ctx; |
| 61205 | sqlite3_value **apVal; |
| 61206 | int n; |
| 61207 | } ag; |
| 61208 | struct OP_ShiftRight_stack_vars { |
| 61209 | i64 iA; |
| 61210 | u64 uA; |
| 61211 | i64 iB; |
| 61212 | u8 op; |
| 61213 | } ah; |
| 61214 | struct OP_Ge_stack_vars { |
| 61215 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 61216 | char affinity; /* Affinity to use for comparison */ |
| 61217 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| @@ -62189,23 +62257,16 @@ | |
| 62257 | if( (u.af.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; |
| 62258 | if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ |
| 62259 | u.af.iA = pIn1->u.i; |
| 62260 | u.af.iB = pIn2->u.i; |
| 62261 | switch( pOp->opcode ){ |
| 62262 | case OP_Add: if( sqlite3AddInt64(&u.af.iB,u.af.iA) ) goto fp_math; break; |
| 62263 | case OP_Subtract: if( sqlite3SubInt64(&u.af.iB,u.af.iA) ) goto fp_math; break; |
| 62264 | case OP_Multiply: if( sqlite3MulInt64(&u.af.iB,u.af.iA) ) goto fp_math; break; |
| 62265 | case OP_Divide: { |
| 62266 | if( u.af.iA==0 ) goto arithmetic_result_is_null; |
| 62267 | if( u.af.iA==-1 && u.af.iB==SMALLEST_INT64 ) goto fp_math; |
| 62268 | u.af.iB /= u.af.iA; |
| 62269 | break; |
| 62270 | } |
| 62271 | default: { |
| 62272 | if( u.af.iA==0 ) goto arithmetic_result_is_null; |
| @@ -62215,10 +62276,11 @@ | |
| 62276 | } |
| 62277 | } |
| 62278 | pOut->u.i = u.af.iB; |
| 62279 | MemSetTypeFlag(pOut, MEM_Int); |
| 62280 | }else{ |
| 62281 | fp_math: |
| 62282 | u.af.rA = sqlite3VdbeRealValue(pIn1); |
| 62283 | u.af.rB = sqlite3VdbeRealValue(pIn2); |
| 62284 | switch( pOp->opcode ){ |
| 62285 | case OP_Add: u.af.rB += u.af.rA; break; |
| 62286 | case OP_Subtract: u.af.rB -= u.af.rA; break; |
| @@ -62412,31 +62474,55 @@ | |
| 62474 | case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */ |
| 62475 | case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */ |
| 62476 | case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */ |
| 62477 | case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */ |
| 62478 | #if 0 /* local variables moved into u.ah */ |
| 62479 | i64 iA; |
| 62480 | u64 uA; |
| 62481 | i64 iB; |
| 62482 | u8 op; |
| 62483 | #endif /* local variables moved into u.ah */ |
| 62484 | |
| 62485 | pIn1 = &aMem[pOp->p1]; |
| 62486 | pIn2 = &aMem[pOp->p2]; |
| 62487 | pOut = &aMem[pOp->p3]; |
| 62488 | if( (pIn1->flags | pIn2->flags) & MEM_Null ){ |
| 62489 | sqlite3VdbeMemSetNull(pOut); |
| 62490 | break; |
| 62491 | } |
| 62492 | u.ah.iA = sqlite3VdbeIntValue(pIn2); |
| 62493 | u.ah.iB = sqlite3VdbeIntValue(pIn1); |
| 62494 | u.ah.op = pOp->opcode; |
| 62495 | if( u.ah.op==OP_BitAnd ){ |
| 62496 | u.ah.iA &= u.ah.iB; |
| 62497 | }else if( u.ah.op==OP_BitOr ){ |
| 62498 | u.ah.iA |= u.ah.iB; |
| 62499 | }else if( u.ah.iB!=0 ){ |
| 62500 | assert( u.ah.op==OP_ShiftRight || u.ah.op==OP_ShiftLeft ); |
| 62501 | |
| 62502 | /* If shifting by a negative amount, shift in the other direction */ |
| 62503 | if( u.ah.iB<0 ){ |
| 62504 | assert( OP_ShiftRight==OP_ShiftLeft+1 ); |
| 62505 | u.ah.op = 2*OP_ShiftLeft + 1 - u.ah.op; |
| 62506 | u.ah.iB = u.ah.iB>(-64) ? -u.ah.iB : 64; |
| 62507 | } |
| 62508 | |
| 62509 | if( u.ah.iB>=64 ){ |
| 62510 | u.ah.iA = (u.ah.iA>=0 || u.ah.op==OP_ShiftLeft) ? 0 : -1; |
| 62511 | }else{ |
| 62512 | memcpy(&u.ah.uA, &u.ah.iA, sizeof(u.ah.uA)); |
| 62513 | if( u.ah.op==OP_ShiftLeft ){ |
| 62514 | u.ah.uA <<= u.ah.iB; |
| 62515 | }else{ |
| 62516 | u.ah.uA >>= u.ah.iB; |
| 62517 | /* Sign-extend on a right shift of a negative number */ |
| 62518 | if( u.ah.iA<0 ) u.ah.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ah.iB); |
| 62519 | } |
| 62520 | memcpy(&u.ah.iA, &u.ah.uA, sizeof(u.ah.iA)); |
| 62521 | } |
| 62522 | } |
| 62523 | pOut->u.i = u.ah.iA; |
| 62524 | MemSetTypeFlag(pOut, MEM_Int); |
| 62525 | break; |
| 62526 | } |
| 62527 | |
| 62528 | /* Opcode: AddImm P1 P2 * * * |
| @@ -63372,11 +63458,10 @@ | |
| 63458 | ** hdr-size field is also a varint which is the offset from the beginning |
| 63459 | ** of the record to data0. |
| 63460 | */ |
| 63461 | u.ao.nData = 0; /* Number of bytes of data space */ |
| 63462 | u.ao.nHdr = 0; /* Number of bytes of header space */ |
| 63463 | u.ao.nZero = 0; /* Number of zero bytes at the end of the record */ |
| 63464 | u.ao.nField = pOp->p1; |
| 63465 | u.ao.zAffinity = pOp->p4.z; |
| 63466 | assert( u.ao.nField>0 && pOp->p2>0 && pOp->p2+u.ao.nField<=p->nMem+1 ); |
| 63467 | u.ao.pData0 = &aMem[u.ao.nField]; |
| @@ -64678,11 +64763,10 @@ | |
| 64763 | ** it already exists in the table. If it does not exist, we have |
| 64764 | ** succeeded. If the random rowid does exist, we select a new one |
| 64765 | ** and try again, up to 100 times. |
| 64766 | */ |
| 64767 | assert( u.be.pC->isTable ); |
| 64768 | |
| 64769 | #ifdef SQLITE_32BIT_ROWID |
| 64770 | # define MAX_ROWID 0x7fffffff |
| 64771 | #else |
| 64772 | /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| @@ -71317,11 +71401,11 @@ | |
| 71401 | const char *z = pExpr->u.zToken; |
| 71402 | assert( z!=0 ); |
| 71403 | c = sqlite3Atoi64(z, &value, sqlite3Strlen30(z), SQLITE_UTF8); |
| 71404 | if( c==0 || (c==2 && negFlag) ){ |
| 71405 | char *zV; |
| 71406 | if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; } |
| 71407 | zV = dup8bytes(v, (char*)&value); |
| 71408 | sqlite3VdbeAddOp4(v, OP_Int64, 0, iMem, 0, zV, P4_INT64); |
| 71409 | }else{ |
| 71410 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 71411 | sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); |
| @@ -81443,17 +81527,12 @@ | |
| 81527 | if( p && type!=SQLITE_NULL ){ |
| 81528 | p->cnt++; |
| 81529 | if( type==SQLITE_INTEGER ){ |
| 81530 | i64 v = sqlite3_value_int64(argv[0]); |
| 81531 | p->rSum += v; |
| 81532 | if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, v) ){ |
| 81533 | p->overflow = 1; |
| 81534 | } |
| 81535 | }else{ |
| 81536 | p->rSum += sqlite3_value_double(argv[0]); |
| 81537 | p->approx = 1; |
| 81538 | } |
| @@ -82489,11 +82568,10 @@ | |
| 82568 | Table *pTab, /* Row is being deleted from this table */ |
| 82569 | int regOld, /* Previous row data is stored here */ |
| 82570 | int regNew /* New row data is stored here */ |
| 82571 | ){ |
| 82572 | sqlite3 *db = pParse->db; /* Database handle */ |
| 82573 | FKey *pFKey; /* Used to iterate through FKs */ |
| 82574 | int iDb; /* Index of database containing pTab */ |
| 82575 | const char *zDb; /* Name of database containing pTab */ |
| 82576 | int isIgnoreErrors = pParse->disableTriggers; |
| 82577 | |
| @@ -82501,11 +82579,10 @@ | |
| 82579 | assert( (regOld==0)!=(regNew==0) ); |
| 82580 | |
| 82581 | /* If foreign-keys are disabled, this function is a no-op. */ |
| 82582 | if( (db->flags&SQLITE_ForeignKeys)==0 ) return; |
| 82583 | |
| 82584 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 82585 | zDb = db->aDb[iDb].zName; |
| 82586 | |
| 82587 | /* Loop through all the foreign key constraints for which pTab is the |
| 82588 | ** child table (the table that the foreign key definition is part of). */ |
| @@ -83459,11 +83536,10 @@ | |
| 83536 | int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */ |
| 83537 | int regRowCount = 0; /* Memory cell used for the row counter */ |
| 83538 | int regIns; /* Block of regs holding rowid+data being inserted */ |
| 83539 | int regRowid; /* registers holding insert rowid */ |
| 83540 | int regData; /* register holding first column to insert */ |
| 83541 | int regEof = 0; /* Register recording end of SELECT data */ |
| 83542 | int *aRegIdx = 0; /* One register allocated to each index */ |
| 83543 | |
| 83544 | #ifndef SQLITE_OMIT_TRIGGER |
| 83545 | int isView; /* True if attempting to insert into a view */ |
| @@ -83788,11 +83864,10 @@ | |
| 83864 | } |
| 83865 | |
| 83866 | /* Allocate registers for holding the rowid of the new row, |
| 83867 | ** the content of the new row, and the assemblied row record. |
| 83868 | */ |
| 83869 | regRowid = regIns = pParse->nMem+1; |
| 83870 | pParse->nMem += pTab->nCol + 1; |
| 83871 | if( IsVirtual(pTab) ){ |
| 83872 | regRowid++; |
| 83873 | pParse->nMem++; |
| @@ -84182,11 +84257,11 @@ | |
| 84257 | case OE_Abort: |
| 84258 | sqlite3MayAbort(pParse); |
| 84259 | case OE_Rollback: |
| 84260 | case OE_Fail: { |
| 84261 | char *zMsg; |
| 84262 | sqlite3VdbeAddOp3(v, OP_HaltIfNull, |
| 84263 | SQLITE_CONSTRAINT, onError, regData+i); |
| 84264 | zMsg = sqlite3MPrintf(pParse->db, "%s.%s may not be NULL", |
| 84265 | pTab->zName, pTab->aCol[i].zName); |
| 84266 | sqlite3VdbeChangeP4(v, -1, zMsg, P4_DYNAMIC); |
| 84267 | break; |
| @@ -87708,11 +87783,11 @@ | |
| 87783 | Db *pDb; |
| 87784 | char const *azArg[4]; |
| 87785 | int meta[5]; |
| 87786 | InitData initData; |
| 87787 | char const *zMasterSchema; |
| 87788 | char const *zMasterName; |
| 87789 | int openedTransaction = 0; |
| 87790 | |
| 87791 | /* |
| 87792 | ** The master database table has a structure like this |
| 87793 | */ |
| @@ -93351,11 +93426,10 @@ | |
| 93426 | sqlite3 *db = pParse->db; /* The database */ |
| 93427 | DbFixer sFix; /* Fixer object */ |
| 93428 | int iDb; /* Database containing the trigger */ |
| 93429 | Token nameToken; /* Trigger name for error reporting */ |
| 93430 | |
| 93431 | pParse->pNewTrigger = 0; |
| 93432 | if( NEVER(pParse->nErr) || !pTrig ) goto triggerfinish_cleanup; |
| 93433 | zName = pTrig->zName; |
| 93434 | iDb = sqlite3SchemaToIndex(pParse->db, pTrig->pSchema); |
| 93435 | pTrig->step_list = pStepList; |
| @@ -94314,11 +94388,10 @@ | |
| 94388 | int regOldRowid; /* The old rowid */ |
| 94389 | int regNewRowid; /* The new rowid */ |
| 94390 | int regNew; |
| 94391 | int regOld = 0; |
| 94392 | int regRowSet = 0; /* Rowset of rows to be updated */ |
| 94393 | |
| 94394 | memset(&sContext, 0, sizeof(sContext)); |
| 94395 | db = pParse->db; |
| 94396 | if( pParse->nErr || db->mallocFailed ){ |
| 94397 | goto update_cleanup; |
| @@ -94472,11 +94545,10 @@ | |
| 94545 | if( chngRowid || pTrigger || hasFK ){ |
| 94546 | regNewRowid = ++pParse->nMem; |
| 94547 | } |
| 94548 | regNew = pParse->nMem + 1; |
| 94549 | pParse->nMem += pTab->nCol; |
| 94550 | |
| 94551 | /* Start the view context. */ |
| 94552 | if( isView ){ |
| 94553 | sqlite3AuthContextPush(pParse, &sContext, pTab->zName); |
| 94554 | } |
| @@ -94582,11 +94654,11 @@ | |
| 94654 | u32 oldmask = (hasFK ? sqlite3FkOldmask(pParse, pTab) : 0); |
| 94655 | oldmask |= sqlite3TriggerColmask(pParse, |
| 94656 | pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError |
| 94657 | ); |
| 94658 | for(i=0; i<pTab->nCol; i++){ |
| 94659 | if( aXRef[i]<0 || oldmask==0xffffffff || (i<32 && (oldmask & (1<<i))) ){ |
| 94660 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, i, regOld+i); |
| 94661 | }else{ |
| 94662 | sqlite3VdbeAddOp2(v, OP_Null, 0, regOld+i); |
| 94663 | } |
| 94664 | } |
| @@ -100187,11 +100259,10 @@ | |
| 100259 | ** |
| 100260 | ** B: <after the loop> |
| 100261 | ** |
| 100262 | */ |
| 100263 | WhereClause *pOrWc; /* The OR-clause broken out into subterms */ |
| 100264 | SrcList *pOrTab; /* Shortened table list or OR-clause generation */ |
| 100265 | |
| 100266 | int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */ |
| 100267 | int regRowset = 0; /* Register for RowSet object */ |
| 100268 | int regRowid = 0; /* Register holding rowid */ |
| @@ -100203,11 +100274,10 @@ | |
| 100274 | pTerm = pLevel->plan.u.pTerm; |
| 100275 | assert( pTerm!=0 ); |
| 100276 | assert( pTerm->eOperator==WO_OR ); |
| 100277 | assert( (pTerm->wtFlags & TERM_ORINFO)!=0 ); |
| 100278 | pOrWc = &pTerm->u.pOrInfo->wc; |
| 100279 | pLevel->op = OP_Return; |
| 100280 | pLevel->p1 = regReturn; |
| 100281 | |
| 100282 | /* Set up a new SrcList ni pOrTab containing the table being scanned |
| 100283 | ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. |
| @@ -100312,11 +100382,10 @@ | |
| 100382 | ** |
| 100383 | ** IMPLEMENTATION-OF: R-49525-50935 Terms that cannot be satisfied through |
| 100384 | ** the use of indices become tests that are evaluated against each row of |
| 100385 | ** the relevant input tables. |
| 100386 | */ |
| 100387 | for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){ |
| 100388 | Expr *pE; |
| 100389 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* IMP: R-30575-11662 */ |
| 100390 | testcase( pTerm->wtFlags & TERM_CODED ); |
| 100391 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| @@ -100330,11 +100399,10 @@ | |
| 100399 | assert( pE!=0 ); |
| 100400 | if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){ |
| 100401 | continue; |
| 100402 | } |
| 100403 | sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL); |
| 100404 | pTerm->wtFlags |= TERM_CODED; |
| 100405 | } |
| 100406 | |
| 100407 | /* For a LEFT OUTER JOIN, generate code that will record the fact that |
| 100408 | ** at least one row of the right table has matched the left table. |
| @@ -100638,12 +100706,10 @@ | |
| 100706 | ** |
| 100707 | ** This loop also figures out the nesting order of tables in the FROM |
| 100708 | ** clause. |
| 100709 | */ |
| 100710 | notReady = ~(Bitmask)0; |
| 100711 | andFlags = ~0; |
| 100712 | WHERETRACE(("*** Optimizer Start ***\n")); |
| 100713 | for(i=iFrom=0, pLevel=pWInfo->a; i<nTabList; i++, pLevel++){ |
| 100714 | WhereCost bestPlan; /* Most efficient plan seen so far */ |
| 100715 | Index *pIdx; /* Index for FROM table at pTabItem */ |
| @@ -100750,12 +100816,12 @@ | |
| 100816 | /* Conditions under which this table becomes the best so far: |
| 100817 | ** |
| 100818 | ** (1) The table must not depend on other tables that have not |
| 100819 | ** yet run. |
| 100820 | ** |
| 100821 | ** (2) A full-table-scan plan cannot supercede indexed plan unless |
| 100822 | ** the full-table-scan is an "optimal" plan as defined above. |
| 100823 | ** |
| 100824 | ** (3) All tables have an INDEXED BY clause or this table lacks an |
| 100825 | ** INDEXED BY clause or this table uses the specific |
| 100826 | ** index specified by its INDEXED BY clause. This rule ensures |
| 100827 | ** that a best-so-far is always selected even if an impossible |
| @@ -100767,10 +100833,11 @@ | |
| 100833 | ** (4) The plan cost must be lower than prior plans or else the |
| 100834 | ** cost must be the same and the number of rows must be lower. |
| 100835 | */ |
| 100836 | if( (sCost.used¬Ready)==0 /* (1) */ |
| 100837 | && (bestJ<0 || (notIndexed&m)!=0 /* (2) */ |
| 100838 | || (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0 |
| 100839 | || (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0) |
| 100840 | && (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */ |
| 100841 | || NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)) |
| 100842 | && (bestJ<0 || sCost.rCost<bestPlan.rCost /* (4) */ |
| 100843 | || (sCost.rCost<=bestPlan.rCost |
| @@ -123657,11 +123724,11 @@ | |
| 123724 | int nCell = 0; |
| 123725 | RtreeCell cell; |
| 123726 | int jj; |
| 123727 | |
| 123728 | nodeGetCell(&tree, &node, ii, &cell); |
| 123729 | sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid); |
| 123730 | nCell = strlen(zCell); |
| 123731 | for(jj=0; jj<tree.nDim*2; jj++){ |
| 123732 | sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f); |
| 123733 | nCell = strlen(zCell); |
| 123734 | } |
| 123735 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | -#define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a" | |
| 112 | +#define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| 118 | 118 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | #define SQLITE_SOURCE_ID "2011-02-25 03:25:07 4e50b0362ab6604a4b6c9f4ad849ec1733d6ce1a" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| 118 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.6" |
| 111 | #define SQLITE_VERSION_NUMBER 3007006 |
| 112 | #define SQLITE_SOURCE_ID "2011-03-06 21:54:33 3bfbf026dd6a0eeef07f8f5f1ebf74c9cfebcd61" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| 118 |