Fossil SCM
Update the built-in SQLite to 3.8.6 beta2.
Commit
981e853f6c95923a38c2163d2e09e4a4d3fd853a
Parent
9d7d6775595aab7…
2 files changed
+179
-126
+21
-43
+179
-126
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -222,11 +222,11 @@ | ||
| 222 | 222 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 223 | 223 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 224 | 224 | */ |
| 225 | 225 | #define SQLITE_VERSION "3.8.6" |
| 226 | 226 | #define SQLITE_VERSION_NUMBER 3008006 |
| 227 | -#define SQLITE_SOURCE_ID "2014-08-06 11:58:40 5c6bb57d90bad32785d6d9cdf110a825bbc5ec73" | |
| 227 | +#define SQLITE_SOURCE_ID "2014-08-11 13:53:30 de27c742c0dcda20b51339598bf6094a8dcf5fb9" | |
| 228 | 228 | |
| 229 | 229 | /* |
| 230 | 230 | ** CAPI3REF: Run-Time Library Version Numbers |
| 231 | 231 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 232 | 232 | ** |
| @@ -382,11 +382,11 @@ | ||
| 382 | 382 | /* |
| 383 | 383 | ** CAPI3REF: Closing A Database Connection |
| 384 | 384 | ** |
| 385 | 385 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 386 | 386 | ** for the [sqlite3] object. |
| 387 | -** ^Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if | |
| 387 | +** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if | |
| 388 | 388 | ** the [sqlite3] object is successfully destroyed and all associated |
| 389 | 389 | ** resources are deallocated. |
| 390 | 390 | ** |
| 391 | 391 | ** ^If the database connection is associated with unfinalized prepared |
| 392 | 392 | ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| @@ -403,11 +403,11 @@ | ||
| 403 | 403 | ** [sqlite3_blob_close | close] all [BLOB handles], and |
| 404 | 404 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 405 | 405 | ** with the [sqlite3] object prior to attempting to close the object. ^If |
| 406 | 406 | ** sqlite3_close_v2() is called on a [database connection] that still has |
| 407 | 407 | ** outstanding [prepared statements], [BLOB handles], and/or |
| 408 | -** [sqlite3_backup] objects then it returns SQLITE_OK but the deallocation | |
| 408 | +** [sqlite3_backup] objects then it returns [SQLITE_OK] but the deallocation | |
| 409 | 409 | ** of resources is deferred until all [prepared statements], [BLOB handles], |
| 410 | 410 | ** and [sqlite3_backup] objects are also destroyed. |
| 411 | 411 | ** |
| 412 | 412 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 413 | 413 | ** the transaction is automatically rolled back. |
| @@ -499,20 +499,18 @@ | ||
| 499 | 499 | char **errmsg /* Error msg written here */ |
| 500 | 500 | ); |
| 501 | 501 | |
| 502 | 502 | /* |
| 503 | 503 | ** CAPI3REF: Result Codes |
| 504 | -** KEYWORDS: SQLITE_OK {error code} {error codes} | |
| 505 | -** KEYWORDS: {result code} {result codes} | |
| 504 | +** KEYWORDS: {result code definitions} | |
| 506 | 505 | ** |
| 507 | 506 | ** Many SQLite functions return an integer result code from the set shown |
| 508 | 507 | ** here in order to indicate success or failure. |
| 509 | 508 | ** |
| 510 | 509 | ** New error codes may be added in future versions of SQLite. |
| 511 | 510 | ** |
| 512 | -** See also: [SQLITE_IOERR_READ | extended result codes], | |
| 513 | -** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. | |
| 511 | +** See also: [extended result code definitions] | |
| 514 | 512 | */ |
| 515 | 513 | #define SQLITE_OK 0 /* Successful result */ |
| 516 | 514 | /* beginning-of-error-codes */ |
| 517 | 515 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 518 | 516 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -546,30 +544,23 @@ | ||
| 546 | 544 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
| 547 | 545 | /* end-of-error-codes */ |
| 548 | 546 | |
| 549 | 547 | /* |
| 550 | 548 | ** CAPI3REF: Extended Result Codes |
| 551 | -** KEYWORDS: {extended error code} {extended error codes} | |
| 552 | -** KEYWORDS: {extended result code} {extended result codes} | |
| 549 | +** KEYWORDS: {extended result code definitions} | |
| 553 | 550 | ** |
| 554 | -** In its default configuration, SQLite API routines return one of 26 integer | |
| 555 | -** [SQLITE_OK | result codes]. However, experience has shown that many of | |
| 551 | +** In its default configuration, SQLite API routines return one of 30 integer | |
| 552 | +** [result codes]. However, experience has shown that many of | |
| 556 | 553 | ** these result codes are too coarse-grained. They do not provide as |
| 557 | 554 | ** much information about problems as programmers might like. In an effort to |
| 558 | 555 | ** address this, newer versions of SQLite (version 3.3.8 and later) include |
| 559 | 556 | ** support for additional result codes that provide more detailed information |
| 560 | -** about errors. The extended result codes are enabled or disabled | |
| 557 | +** about errors. These [extended result codes] are enabled or disabled | |
| 561 | 558 | ** on a per database connection basis using the |
| 562 | -** [sqlite3_extended_result_codes()] API. | |
| 563 | -** | |
| 564 | -** Some of the available extended result codes are listed here. | |
| 565 | -** One may expect the number of extended result codes will increase | |
| 566 | -** over time. Software that uses extended result codes should expect | |
| 567 | -** to see new result codes in future releases of SQLite. | |
| 568 | -** | |
| 569 | -** The SQLITE_OK result code will never be extended. It will always | |
| 570 | -** be exactly zero. | |
| 559 | +** [sqlite3_extended_result_codes()] API. Or, the extended code for | |
| 560 | +** the most recent error can be obtained using | |
| 561 | +** [sqlite3_extended_errcode()]. | |
| 571 | 562 | */ |
| 572 | 563 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 573 | 564 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 574 | 565 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 575 | 566 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| @@ -798,11 +789,11 @@ | ||
| 798 | 789 | ** write return values. Potential uses for xFileControl() might be |
| 799 | 790 | ** functions to enable blocking locks with timeouts, to change the |
| 800 | 791 | ** locking strategy (for example to use dot-file locks), to inquire |
| 801 | 792 | ** about the status of a lock, or to break stale locks. The SQLite |
| 802 | 793 | ** core reserves all opcodes less than 100 for its own use. |
| 803 | -** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. | |
| 794 | +** A [file control opcodes | list of opcodes] less than 100 is available. | |
| 804 | 795 | ** Applications that define a custom xFileControl method should use opcodes |
| 805 | 796 | ** greater than 100 to avoid conflicts. VFS implementations should |
| 806 | 797 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
| 807 | 798 | ** recognize. |
| 808 | 799 | ** |
| @@ -871,10 +862,11 @@ | ||
| 871 | 862 | /* Additional methods may be added in future releases */ |
| 872 | 863 | }; |
| 873 | 864 | |
| 874 | 865 | /* |
| 875 | 866 | ** CAPI3REF: Standard File Control Opcodes |
| 867 | +** KEYWORDS: {file control opcodes} {file control opcode} | |
| 876 | 868 | ** |
| 877 | 869 | ** These integer constants are opcodes for the xFileControl method |
| 878 | 870 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
| 879 | 871 | ** interface. |
| 880 | 872 | ** |
| @@ -2158,28 +2150,28 @@ | ||
| 2158 | 2150 | ** [database connection] D when another thread |
| 2159 | 2151 | ** or process has the table locked. |
| 2160 | 2152 | ** The sqlite3_busy_handler() interface is used to implement |
| 2161 | 2153 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
| 2162 | 2154 | ** |
| 2163 | -** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] | |
| 2155 | +** ^If the busy callback is NULL, then [SQLITE_BUSY] | |
| 2164 | 2156 | ** is returned immediately upon encountering the lock. ^If the busy callback |
| 2165 | 2157 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2166 | 2158 | ** |
| 2167 | 2159 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2168 | 2160 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2169 | 2161 | ** the busy handler callback is the number of times that the busy handler has |
| 2170 | 2162 | ** been invoked for the same locking event. ^If the |
| 2171 | 2163 | ** busy callback returns 0, then no additional attempts are made to |
| 2172 | -** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned | |
| 2164 | +** access the database and [SQLITE_BUSY] is returned | |
| 2173 | 2165 | ** to the application. |
| 2174 | 2166 | ** ^If the callback returns non-zero, then another attempt |
| 2175 | 2167 | ** is made to access the database and the cycle repeats. |
| 2176 | 2168 | ** |
| 2177 | 2169 | ** The presence of a busy handler does not guarantee that it will be invoked |
| 2178 | 2170 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
| 2179 | 2171 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
| 2180 | -** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the | |
| 2172 | +** to the application instead of invoking the | |
| 2181 | 2173 | ** busy handler. |
| 2182 | 2174 | ** Consider a scenario where one process is holding a read lock that |
| 2183 | 2175 | ** it is trying to promote to a reserved lock and |
| 2184 | 2176 | ** a second process is holding a reserved lock that it is trying |
| 2185 | 2177 | ** to promote to an exclusive lock. The first process cannot proceed |
| @@ -2190,25 +2182,10 @@ | ||
| 2190 | 2182 | ** will induce the first process to release its read lock and allow |
| 2191 | 2183 | ** the second process to proceed. |
| 2192 | 2184 | ** |
| 2193 | 2185 | ** ^The default busy callback is NULL. |
| 2194 | 2186 | ** |
| 2195 | -** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] | |
| 2196 | -** when SQLite is in the middle of a large transaction where all the | |
| 2197 | -** changes will not fit into the in-memory cache. SQLite will | |
| 2198 | -** already hold a RESERVED lock on the database file, but it needs | |
| 2199 | -** to promote this lock to EXCLUSIVE so that it can spill cache | |
| 2200 | -** pages into the database file without harm to concurrent | |
| 2201 | -** readers. ^If it is unable to promote the lock, then the in-memory | |
| 2202 | -** cache will be left in an inconsistent state and so the error | |
| 2203 | -** code is promoted from the relatively benign [SQLITE_BUSY] to | |
| 2204 | -** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion | |
| 2205 | -** forces an automatic rollback of the changes. See the | |
| 2206 | -** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> | |
| 2207 | -** CorruptionFollowingBusyError</a> wiki page for a discussion of why | |
| 2208 | -** this is important. | |
| 2209 | -** | |
| 2210 | 2187 | ** ^(There can only be a single busy handler defined for each |
| 2211 | 2188 | ** [database connection]. Setting a new busy handler clears any |
| 2212 | 2189 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
| 2213 | 2190 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
| 2214 | 2191 | ** busy handler and thus clear any previously set busy handler. |
| @@ -2229,11 +2206,11 @@ | ||
| 2229 | 2206 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2230 | 2207 | ** for a specified amount of time when a table is locked. ^The handler |
| 2231 | 2208 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2232 | 2209 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| 2233 | 2210 | ** the handler returns 0 which causes [sqlite3_step()] to return |
| 2234 | -** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. | |
| 2211 | +** [SQLITE_BUSY]. | |
| 2235 | 2212 | ** |
| 2236 | 2213 | ** ^Calling this routine with an argument less than or equal to zero |
| 2237 | 2214 | ** turns off all busy handlers. |
| 2238 | 2215 | ** |
| 2239 | 2216 | ** ^(There can only be a single busy handler for a particular |
| @@ -2641,12 +2618,12 @@ | ||
| 2641 | 2618 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2642 | 2619 | ** to signal SQLite whether or not the action is permitted. See the |
| 2643 | 2620 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2644 | 2621 | ** information. |
| 2645 | 2622 | ** |
| 2646 | -** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] | |
| 2647 | -** from the [sqlite3_vtab_on_conflict()] interface. | |
| 2623 | +** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] | |
| 2624 | +** returned from the [sqlite3_vtab_on_conflict()] interface. | |
| 2648 | 2625 | */ |
| 2649 | 2626 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2650 | 2627 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2651 | 2628 | |
| 2652 | 2629 | /* |
| @@ -7482,10 +7459,11 @@ | ||
| 7482 | 7459 | */ |
| 7483 | 7460 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7484 | 7461 | |
| 7485 | 7462 | /* |
| 7486 | 7463 | ** CAPI3REF: Conflict resolution modes |
| 7464 | +** KEYWORDS: {conflict resolution mode} | |
| 7487 | 7465 | ** |
| 7488 | 7466 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 7489 | 7467 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 7490 | 7468 | ** is for the SQL statement being evaluated. |
| 7491 | 7469 | ** |
| @@ -24177,15 +24155,14 @@ | ||
| 24177 | 24155 | #include <unistd.h> |
| 24178 | 24156 | /* #include <time.h> */ |
| 24179 | 24157 | #include <sys/time.h> |
| 24180 | 24158 | #include <errno.h> |
| 24181 | 24159 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 24182 | -#include <sys/mman.h> | |
| 24160 | +# include <sys/mman.h> | |
| 24183 | 24161 | #endif |
| 24184 | 24162 | |
| 24185 | - | |
| 24186 | -#if SQLITE_ENABLE_LOCKING_STYLE | |
| 24163 | +#if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS | |
| 24187 | 24164 | # include <sys/ioctl.h> |
| 24188 | 24165 | # if OS_VXWORKS |
| 24189 | 24166 | # include <semaphore.h> |
| 24190 | 24167 | # include <limits.h> |
| 24191 | 24168 | # else |
| @@ -24609,11 +24586,15 @@ | ||
| 24609 | 24586 | ** On some systems, calls to fchown() will trigger a message in a security |
| 24610 | 24587 | ** log if they come from non-root processes. So avoid calling fchown() if |
| 24611 | 24588 | ** we are not running as root. |
| 24612 | 24589 | */ |
| 24613 | 24590 | static int posixFchown(int fd, uid_t uid, gid_t gid){ |
| 24591 | +#if OS_VXWORKS | |
| 24592 | + return 0; | |
| 24593 | +#else | |
| 24614 | 24594 | return geteuid() ? 0 : fchown(fd,uid,gid); |
| 24595 | +#endif | |
| 24615 | 24596 | } |
| 24616 | 24597 | |
| 24617 | 24598 | /* Forward reference */ |
| 24618 | 24599 | static int openDirectory(const char*, int*); |
| 24619 | 24600 | static int unixGetpagesize(void); |
| @@ -24665,11 +24646,11 @@ | ||
| 24665 | 24646 | #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) |
| 24666 | 24647 | |
| 24667 | 24648 | { "read", (sqlite3_syscall_ptr)read, 0 }, |
| 24668 | 24649 | #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) |
| 24669 | 24650 | |
| 24670 | -#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE | |
| 24651 | +#if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS) | |
| 24671 | 24652 | { "pread", (sqlite3_syscall_ptr)pread, 0 }, |
| 24672 | 24653 | #else |
| 24673 | 24654 | { "pread", (sqlite3_syscall_ptr)0, 0 }, |
| 24674 | 24655 | #endif |
| 24675 | 24656 | #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) |
| @@ -24682,11 +24663,11 @@ | ||
| 24682 | 24663 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) |
| 24683 | 24664 | |
| 24684 | 24665 | { "write", (sqlite3_syscall_ptr)write, 0 }, |
| 24685 | 24666 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) |
| 24686 | 24667 | |
| 24687 | -#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE | |
| 24668 | +#if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS) | |
| 24688 | 24669 | { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, |
| 24689 | 24670 | #else |
| 24690 | 24671 | { "pwrite", (sqlite3_syscall_ptr)0, 0 }, |
| 24691 | 24672 | #endif |
| 24692 | 24673 | #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| @@ -25052,20 +25033,10 @@ | ||
| 25052 | 25033 | } |
| 25053 | 25034 | /* else fall through */ |
| 25054 | 25035 | case EPERM: |
| 25055 | 25036 | return SQLITE_PERM; |
| 25056 | 25037 | |
| 25057 | - /* EDEADLK is only possible if a call to fcntl(F_SETLKW) is made. And | |
| 25058 | - ** this module never makes such a call. And the code in SQLite itself | |
| 25059 | - ** asserts that SQLITE_IOERR_BLOCKED is never returned. For these reasons | |
| 25060 | - ** this case is also commented out. If the system does set errno to EDEADLK, | |
| 25061 | - ** the default SQLITE_IOERR_XXX code will be returned. */ | |
| 25062 | -#if 0 | |
| 25063 | - case EDEADLK: | |
| 25064 | - return SQLITE_IOERR_BLOCKED; | |
| 25065 | -#endif | |
| 25066 | - | |
| 25067 | 25038 | #if EOPNOTSUPP!=ENOTSUP |
| 25068 | 25039 | case EOPNOTSUPP: |
| 25069 | 25040 | /* something went terribly awry, unless during file system support |
| 25070 | 25041 | * introspection, in which it actually means what it says */ |
| 25071 | 25042 | #endif |
| @@ -25596,11 +25567,15 @@ | ||
| 25596 | 25567 | ** Return TRUE if pFile has been renamed or unlinked since it was first opened. |
| 25597 | 25568 | */ |
| 25598 | 25569 | static int fileHasMoved(unixFile *pFile){ |
| 25599 | 25570 | struct stat buf; |
| 25600 | 25571 | return pFile->pInode!=0 && |
| 25572 | +#if OS_VXWORKS | |
| 25573 | + pFile->pId!=pFile->pInode->fileId.Pid; | |
| 25574 | +#else | |
| 25601 | 25575 | (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); |
| 25576 | +#endif | |
| 25602 | 25577 | } |
| 25603 | 25578 | |
| 25604 | 25579 | |
| 25605 | 25580 | /* |
| 25606 | 25581 | ** Check a unixFile that is a database. Verify the following: |
| @@ -26739,11 +26714,10 @@ | ||
| 26739 | 26714 | } |
| 26740 | 26715 | |
| 26741 | 26716 | /* Otherwise see if some other process holds it. */ |
| 26742 | 26717 | if( !reserved ){ |
| 26743 | 26718 | sem_t *pSem = pFile->pInode->pSem; |
| 26744 | - struct stat statBuf; | |
| 26745 | 26719 | |
| 26746 | 26720 | if( sem_trywait(pSem)==-1 ){ |
| 26747 | 26721 | int tErrno = errno; |
| 26748 | 26722 | if( EAGAIN != tErrno ){ |
| 26749 | 26723 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); |
| @@ -26792,11 +26766,10 @@ | ||
| 26792 | 26766 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() |
| 26793 | 26767 | ** routine to lower a locking level. |
| 26794 | 26768 | */ |
| 26795 | 26769 | static int semLock(sqlite3_file *id, int eFileLock) { |
| 26796 | 26770 | unixFile *pFile = (unixFile*)id; |
| 26797 | - int fd; | |
| 26798 | 26771 | sem_t *pSem = pFile->pInode->pSem; |
| 26799 | 26772 | int rc = SQLITE_OK; |
| 26800 | 26773 | |
| 26801 | 26774 | /* if we already have a lock, it is exclusive. |
| 26802 | 26775 | ** Just adjust level and punt on outta here. */ |
| @@ -64521,11 +64494,10 @@ | ||
| 64521 | 64494 | /* Lock all btrees used by the statement */ |
| 64522 | 64495 | sqlite3VdbeEnter(p); |
| 64523 | 64496 | |
| 64524 | 64497 | /* Check for one of the special errors */ |
| 64525 | 64498 | mrc = p->rc & 0xff; |
| 64526 | - assert( p->rc!=SQLITE_IOERR_BLOCKED ); /* This error no longer exists */ | |
| 64527 | 64499 | isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| 64528 | 64500 | || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL; |
| 64529 | 64501 | if( isSpecialError ){ |
| 64530 | 64502 | /* If the query was read-only and the error code is SQLITE_INTERRUPT, |
| 64531 | 64503 | ** no rollback is necessary. Otherwise, at least a savepoint |
| @@ -71247,11 +71219,11 @@ | ||
| 71247 | 71219 | VdbeCursor *pCur; |
| 71248 | 71220 | |
| 71249 | 71221 | assert( pOp->p5==0 ); |
| 71250 | 71222 | assert( pOp->p4type==P4_KEYINFO ); |
| 71251 | 71223 | pCur = p->apCsr[pOp->p1]; |
| 71252 | - if( pCur && pCur->pgnoRoot==pOp->p2 ){ | |
| 71224 | + if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){ | |
| 71253 | 71225 | assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ |
| 71254 | 71226 | break; |
| 71255 | 71227 | } |
| 71256 | 71228 | /* If the cursor is not currently open or is open on a different |
| 71257 | 71229 | ** index, then fall through into OP_OpenRead to force a reopen */ |
| @@ -77111,11 +77083,11 @@ | ||
| 77111 | 77083 | } |
| 77112 | 77084 | break; |
| 77113 | 77085 | } |
| 77114 | 77086 | } |
| 77115 | 77087 | if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){ |
| 77116 | - /* IMP: R-24309-18625 */ | |
| 77088 | + /* IMP: R-51414-32910 */ | |
| 77117 | 77089 | /* IMP: R-44911-55124 */ |
| 77118 | 77090 | iCol = -1; |
| 77119 | 77091 | } |
| 77120 | 77092 | if( iCol<pTab->nCol ){ |
| 77121 | 77093 | cnt++; |
| @@ -110616,10 +110588,11 @@ | ||
| 110616 | 110588 | struct WherePath { |
| 110617 | 110589 | Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */ |
| 110618 | 110590 | Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */ |
| 110619 | 110591 | LogEst nRow; /* Estimated number of rows generated by this path */ |
| 110620 | 110592 | LogEst rCost; /* Total cost of this path */ |
| 110593 | + LogEst rUnsorted; /* Total cost of this path ignoring sorting costs */ | |
| 110621 | 110594 | i8 isOrdered; /* No. of ORDER BY terms satisfied. -1 for unknown */ |
| 110622 | 110595 | WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */ |
| 110623 | 110596 | }; |
| 110624 | 110597 | |
| 110625 | 110598 | /* |
| @@ -116275,10 +116248,49 @@ | ||
| 116275 | 116248 | if( pLast ) zName[i++] = pLast->cId; |
| 116276 | 116249 | zName[i] = 0; |
| 116277 | 116250 | return zName; |
| 116278 | 116251 | } |
| 116279 | 116252 | #endif |
| 116253 | + | |
| 116254 | +/* | |
| 116255 | +** Return the cost of sorting nRow rows, assuming that the keys have | |
| 116256 | +** nOrderby columns and that the first nSorted columns are already in | |
| 116257 | +** order. | |
| 116258 | +*/ | |
| 116259 | +static LogEst whereSortingCost( | |
| 116260 | + WhereInfo *pWInfo, | |
| 116261 | + LogEst nRow, | |
| 116262 | + int nOrderBy, | |
| 116263 | + int nSorted | |
| 116264 | +){ | |
| 116265 | + /* TUNING: Estimated cost of a full external sort, where N is | |
| 116266 | + ** the number of rows to sort is: | |
| 116267 | + ** | |
| 116268 | + ** cost = (3.0 * N * log(N)). | |
| 116269 | + ** | |
| 116270 | + ** Or, if the order-by clause has X terms but only the last Y | |
| 116271 | + ** terms are out of order, then block-sorting will reduce the | |
| 116272 | + ** sorting cost to: | |
| 116273 | + ** | |
| 116274 | + ** cost = (3.0 * N * log(N)) * (Y/X) | |
| 116275 | + ** | |
| 116276 | + ** The (Y/X) term is implemented using stack variable rScale | |
| 116277 | + ** below. */ | |
| 116278 | + LogEst rScale, rSortCost; | |
| 116279 | + assert( nOrderBy>0 && 66==sqlite3LogEst(100) ); | |
| 116280 | + rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66; | |
| 116281 | + rSortCost = nRow + estLog(nRow) + rScale + 16; | |
| 116282 | + | |
| 116283 | + /* TUNING: The cost of implementing DISTINCT using a B-TREE is | |
| 116284 | + ** similar but with a larger constant of proportionality. | |
| 116285 | + ** Multiply by an additional factor of 3.0. */ | |
| 116286 | + if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){ | |
| 116287 | + rSortCost += 16; | |
| 116288 | + } | |
| 116289 | + | |
| 116290 | + return rSortCost; | |
| 116291 | +} | |
| 116280 | 116292 | |
| 116281 | 116293 | /* |
| 116282 | 116294 | ** Given the list of WhereLoop objects at pWInfo->pLoops, this routine |
| 116283 | 116295 | ** attempts to find the lowest cost path that visits each WhereLoop |
| 116284 | 116296 | ** once. This path is then loaded into the pWInfo->a[].pWLoop fields. |
| @@ -116297,139 +116309,170 @@ | ||
| 116297 | 116309 | sqlite3 *db; /* The database connection */ |
| 116298 | 116310 | int iLoop; /* Loop counter over the terms of the join */ |
| 116299 | 116311 | int ii, jj; /* Loop counters */ |
| 116300 | 116312 | int mxI = 0; /* Index of next entry to replace */ |
| 116301 | 116313 | int nOrderBy; /* Number of ORDER BY clause terms */ |
| 116302 | - LogEst rCost; /* Cost of a path */ | |
| 116303 | - LogEst nOut; /* Number of outputs */ | |
| 116304 | 116314 | LogEst mxCost = 0; /* Maximum cost of a set of paths */ |
| 116315 | + LogEst mxUnsorted = 0; /* Maximum unsorted cost of a set of path */ | |
| 116305 | 116316 | int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */ |
| 116306 | 116317 | WherePath *aFrom; /* All nFrom paths at the previous level */ |
| 116307 | 116318 | WherePath *aTo; /* The nTo best paths at the current level */ |
| 116308 | 116319 | WherePath *pFrom; /* An element of aFrom[] that we are working on */ |
| 116309 | 116320 | WherePath *pTo; /* An element of aTo[] that we are working on */ |
| 116310 | 116321 | WhereLoop *pWLoop; /* One of the WhereLoop objects */ |
| 116311 | 116322 | WhereLoop **pX; /* Used to divy up the pSpace memory */ |
| 116323 | + LogEst *aSortCost = 0; /* Sorting and partial sorting costs */ | |
| 116312 | 116324 | char *pSpace; /* Temporary memory used by this routine */ |
| 116325 | + int nSpace; /* Bytes of space allocated at pSpace */ | |
| 116313 | 116326 | |
| 116314 | 116327 | pParse = pWInfo->pParse; |
| 116315 | 116328 | db = pParse->db; |
| 116316 | 116329 | nLoop = pWInfo->nLevel; |
| 116317 | 116330 | /* TUNING: For simple queries, only the best path is tracked. |
| 116318 | 116331 | ** For 2-way joins, the 5 best paths are followed. |
| 116319 | 116332 | ** For joins of 3 or more tables, track the 10 best paths */ |
| 116320 | 116333 | mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10); |
| 116321 | 116334 | assert( nLoop<=pWInfo->pTabList->nSrc ); |
| 116322 | - WHERETRACE(0x002, ("---- begin solver\n")); | |
| 116335 | + WHERETRACE(0x002, ("---- begin solver. (nRowEst=%d)\n", nRowEst)); | |
| 116323 | 116336 | |
| 116324 | - /* Allocate and initialize space for aTo and aFrom */ | |
| 116325 | - ii = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2; | |
| 116326 | - pSpace = sqlite3DbMallocRaw(db, ii); | |
| 116337 | + /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this | |
| 116338 | + ** case the purpose of this call is to estimate the number of rows returned | |
| 116339 | + ** by the overall query. Once this estimate has been obtained, the caller | |
| 116340 | + ** will invoke this function a second time, passing the estimate as the | |
| 116341 | + ** nRowEst parameter. */ | |
| 116342 | + if( pWInfo->pOrderBy==0 || nRowEst==0 ){ | |
| 116343 | + nOrderBy = 0; | |
| 116344 | + }else{ | |
| 116345 | + nOrderBy = pWInfo->pOrderBy->nExpr; | |
| 116346 | + } | |
| 116347 | + | |
| 116348 | + /* Allocate and initialize space for aTo, aFrom and aSortCost[] */ | |
| 116349 | + nSpace = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2; | |
| 116350 | + nSpace += sizeof(LogEst) * nOrderBy; | |
| 116351 | + pSpace = sqlite3DbMallocRaw(db, nSpace); | |
| 116327 | 116352 | if( pSpace==0 ) return SQLITE_NOMEM; |
| 116328 | 116353 | aTo = (WherePath*)pSpace; |
| 116329 | 116354 | aFrom = aTo+mxChoice; |
| 116330 | 116355 | memset(aFrom, 0, sizeof(aFrom[0])); |
| 116331 | 116356 | pX = (WhereLoop**)(aFrom+mxChoice); |
| 116332 | 116357 | for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){ |
| 116333 | 116358 | pFrom->aLoop = pX; |
| 116334 | 116359 | } |
| 116360 | + if( nOrderBy ){ | |
| 116361 | + /* If there is an ORDER BY clause and it is not being ignored, set up | |
| 116362 | + ** space for the aSortCost[] array. Each element of the aSortCost array | |
| 116363 | + ** is either zero - meaning it has not yet been initialized - or the | |
| 116364 | + ** cost of sorting nRowEst rows of data where the first X terms of | |
| 116365 | + ** the ORDER BY clause are already in order, where X is the array | |
| 116366 | + ** index. */ | |
| 116367 | + aSortCost = (LogEst*)pX; | |
| 116368 | + memset(aSortCost, 0, sizeof(LogEst) * nOrderBy); | |
| 116369 | + } | |
| 116370 | + assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] ); | |
| 116371 | + assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX ); | |
| 116335 | 116372 | |
| 116336 | 116373 | /* Seed the search with a single WherePath containing zero WhereLoops. |
| 116337 | 116374 | ** |
| 116338 | 116375 | ** TUNING: Do not let the number of iterations go above 25. If the cost |
| 116339 | 116376 | ** of computing an automatic index is not paid back within the first 25 |
| 116340 | 116377 | ** rows, then do not use the automatic index. */ |
| 116341 | 116378 | aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) ); |
| 116342 | 116379 | nFrom = 1; |
| 116343 | - | |
| 116344 | - /* Precompute the cost of sorting the final result set, if the caller | |
| 116345 | - ** to sqlite3WhereBegin() was concerned about sorting */ | |
| 116346 | - if( pWInfo->pOrderBy==0 || nRowEst==0 ){ | |
| 116347 | - aFrom[0].isOrdered = 0; | |
| 116348 | - nOrderBy = 0; | |
| 116349 | - }else{ | |
| 116350 | - aFrom[0].isOrdered = nLoop>0 ? -1 : 1; | |
| 116351 | - nOrderBy = pWInfo->pOrderBy->nExpr; | |
| 116380 | + assert( aFrom[0].isOrdered==0 ); | |
| 116381 | + if( nOrderBy ){ | |
| 116382 | + /* If nLoop is zero, then there are no FROM terms in the query. Since | |
| 116383 | + ** in this case the query may return a maximum of one row, the results | |
| 116384 | + ** are already in the requested order. Set isOrdered to nOrderBy to | |
| 116385 | + ** indicate this. Or, if nLoop is greater than zero, set isOrdered to | |
| 116386 | + ** -1, indicating that the result set may or may not be ordered, | |
| 116387 | + ** depending on the loops added to the current plan. */ | |
| 116388 | + aFrom[0].isOrdered = nLoop>0 ? -1 : nOrderBy; | |
| 116352 | 116389 | } |
| 116353 | 116390 | |
| 116354 | 116391 | /* Compute successively longer WherePaths using the previous generation |
| 116355 | 116392 | ** of WherePaths as the basis for the next. Keep track of the mxChoice |
| 116356 | 116393 | ** best paths at each generation */ |
| 116357 | 116394 | for(iLoop=0; iLoop<nLoop; iLoop++){ |
| 116358 | 116395 | nTo = 0; |
| 116359 | 116396 | for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){ |
| 116360 | 116397 | for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){ |
| 116361 | - Bitmask maskNew; | |
| 116362 | - Bitmask revMask = 0; | |
| 116363 | - i8 isOrdered = pFrom->isOrdered; | |
| 116398 | + LogEst nOut; /* Rows visited by (pFrom+pWLoop) */ | |
| 116399 | + LogEst rCost; /* Cost of path (pFrom+pWLoop) */ | |
| 116400 | + LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */ | |
| 116401 | + i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */ | |
| 116402 | + Bitmask maskNew; /* Mask of src visited by (..) */ | |
| 116403 | + Bitmask revMask = 0; /* Mask of rev-order loops for (..) */ | |
| 116404 | + | |
| 116364 | 116405 | if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue; |
| 116365 | 116406 | if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue; |
| 116366 | 116407 | /* At this point, pWLoop is a candidate to be the next loop. |
| 116367 | 116408 | ** Compute its cost */ |
| 116368 | - rCost = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); | |
| 116369 | - rCost = sqlite3LogEstAdd(rCost, pFrom->rCost); | |
| 116409 | + rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); | |
| 116410 | + rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted); | |
| 116370 | 116411 | nOut = pFrom->nRow + pWLoop->nOut; |
| 116371 | 116412 | maskNew = pFrom->maskLoop | pWLoop->maskSelf; |
| 116372 | 116413 | if( isOrdered<0 ){ |
| 116373 | 116414 | isOrdered = wherePathSatisfiesOrderBy(pWInfo, |
| 116374 | 116415 | pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags, |
| 116375 | 116416 | iLoop, pWLoop, &revMask); |
| 116376 | - if( isOrdered>=0 && isOrdered<nOrderBy ){ | |
| 116377 | - /* TUNING: Estimated cost of a full external sort, where N is | |
| 116378 | - ** the number of rows to sort is: | |
| 116379 | - ** | |
| 116380 | - ** cost = (3.0 * N * log(N)). | |
| 116381 | - ** | |
| 116382 | - ** Or, if the order-by clause has X terms but only the last Y | |
| 116383 | - ** terms are out of order, then block-sorting will reduce the | |
| 116384 | - ** sorting cost to: | |
| 116385 | - ** | |
| 116386 | - ** cost = (3.0 * N * log(N)) * (Y/X) | |
| 116387 | - ** | |
| 116388 | - ** The (Y/X) term is implemented using stack variable rScale | |
| 116389 | - ** below. */ | |
| 116390 | - LogEst rScale, rSortCost; | |
| 116391 | - assert( nOrderBy>0 && 66==sqlite3LogEst(100) ); | |
| 116392 | - rScale = sqlite3LogEst((nOrderBy-isOrdered)*100/nOrderBy) - 66; | |
| 116393 | - rSortCost = nRowEst + estLog(nRowEst) + rScale + 16; | |
| 116394 | - | |
| 116395 | - /* TUNING: The cost of implementing DISTINCT using a B-TREE is | |
| 116396 | - ** similar but with a larger constant of proportionality. | |
| 116397 | - ** Multiply by an additional factor of 3.0. */ | |
| 116398 | - if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){ | |
| 116399 | - rSortCost += 16; | |
| 116400 | - } | |
| 116401 | - WHERETRACE(0x002, | |
| 116402 | - ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n", | |
| 116403 | - rSortCost, (nOrderBy-isOrdered), nOrderBy, rCost, | |
| 116404 | - sqlite3LogEstAdd(rCost,rSortCost))); | |
| 116405 | - rCost = sqlite3LogEstAdd(rCost, rSortCost); | |
| 116406 | - } | |
| 116407 | 116417 | }else{ |
| 116408 | 116418 | revMask = pFrom->revLoop; |
| 116409 | 116419 | } |
| 116410 | - /* Check to see if pWLoop should be added to the mxChoice best so far */ | |
| 116420 | + if( isOrdered>=0 && isOrdered<nOrderBy ){ | |
| 116421 | + if( aSortCost[isOrdered]==0 ){ | |
| 116422 | + aSortCost[isOrdered] = whereSortingCost( | |
| 116423 | + pWInfo, nRowEst, nOrderBy, isOrdered | |
| 116424 | + ); | |
| 116425 | + } | |
| 116426 | + rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]); | |
| 116427 | + | |
| 116428 | + WHERETRACE(0x002, | |
| 116429 | + ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n", | |
| 116430 | + aSortCost[isOrdered], (nOrderBy-isOrdered), nOrderBy, | |
| 116431 | + rUnsorted, rCost)); | |
| 116432 | + }else{ | |
| 116433 | + rCost = rUnsorted; | |
| 116434 | + } | |
| 116435 | + | |
| 116436 | + /* Check to see if pWLoop should be added to the set of | |
| 116437 | + ** mxChoice best-so-far paths. | |
| 116438 | + ** | |
| 116439 | + ** First look for an existing path among best-so-far paths | |
| 116440 | + ** that covers the same set of loops and has the same isOrdered | |
| 116441 | + ** setting as the current path candidate. | |
| 116442 | + ** | |
| 116443 | + ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent | |
| 116444 | + ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range | |
| 116445 | + ** of legal values for isOrdered, -1..64. | |
| 116446 | + */ | |
| 116411 | 116447 | for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){ |
| 116412 | 116448 | if( pTo->maskLoop==maskNew |
| 116413 | - && ((pTo->isOrdered^isOrdered)&80)==0 | |
| 116449 | + && ((pTo->isOrdered^isOrdered)&0x80)==0 | |
| 116414 | 116450 | ){ |
| 116415 | 116451 | testcase( jj==nTo-1 ); |
| 116416 | 116452 | break; |
| 116417 | 116453 | } |
| 116418 | 116454 | } |
| 116419 | 116455 | if( jj>=nTo ){ |
| 116420 | - if( nTo>=mxChoice && rCost>=mxCost ){ | |
| 116456 | + /* None of the existing best-so-far paths match the candidate. */ | |
| 116457 | + if( nTo>=mxChoice | |
| 116458 | + && (rCost>mxCost || (rCost==mxCost && rUnsorted>=mxUnsorted)) | |
| 116459 | + ){ | |
| 116460 | + /* The current candidate is no better than any of the mxChoice | |
| 116461 | + ** paths currently in the best-so-far buffer. So discard | |
| 116462 | + ** this candidate as not viable. */ | |
| 116421 | 116463 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116422 | 116464 | if( sqlite3WhereTrace&0x4 ){ |
| 116423 | 116465 | sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n", |
| 116424 | 116466 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| 116425 | 116467 | isOrdered>=0 ? isOrdered+'0' : '?'); |
| 116426 | 116468 | } |
| 116427 | 116469 | #endif |
| 116428 | 116470 | continue; |
| 116429 | 116471 | } |
| 116430 | - /* Add a new Path to the aTo[] set */ | |
| 116472 | + /* If we reach this points it means that the new candidate path | |
| 116473 | + ** needs to be added to the set of best-so-far paths. */ | |
| 116431 | 116474 | if( nTo<mxChoice ){ |
| 116432 | 116475 | /* Increase the size of the aTo set by one */ |
| 116433 | 116476 | jj = nTo++; |
| 116434 | 116477 | }else{ |
| 116435 | 116478 | /* New path replaces the prior worst to keep count below mxChoice */ |
| @@ -116442,11 +116485,15 @@ | ||
| 116442 | 116485 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| 116443 | 116486 | isOrdered>=0 ? isOrdered+'0' : '?'); |
| 116444 | 116487 | } |
| 116445 | 116488 | #endif |
| 116446 | 116489 | }else{ |
| 116447 | - if( pTo->rCost<=rCost ){ | |
| 116490 | + /* Control reaches here if best-so-far path pTo=aTo[jj] covers the | |
| 116491 | + ** same set of loops and has the sam isOrdered setting as the | |
| 116492 | + ** candidate path. Check to see if the candidate should replace | |
| 116493 | + ** pTo or if the candidate should be skipped */ | |
| 116494 | + if( pTo->rCost<rCost || (pTo->rCost==rCost && pTo->nRow<=nOut) ){ | |
| 116448 | 116495 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116449 | 116496 | if( sqlite3WhereTrace&0x4 ){ |
| 116450 | 116497 | sqlite3DebugPrintf( |
| 116451 | 116498 | "Skip %s cost=%-3d,%3d order=%c", |
| 116452 | 116499 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| @@ -116454,15 +116501,17 @@ | ||
| 116454 | 116501 | sqlite3DebugPrintf(" vs %s cost=%-3d,%d order=%c\n", |
| 116455 | 116502 | wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow, |
| 116456 | 116503 | pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?'); |
| 116457 | 116504 | } |
| 116458 | 116505 | #endif |
| 116506 | + /* Discard the candidate path from further consideration */ | |
| 116459 | 116507 | testcase( pTo->rCost==rCost ); |
| 116460 | 116508 | continue; |
| 116461 | 116509 | } |
| 116462 | 116510 | testcase( pTo->rCost==rCost+1 ); |
| 116463 | - /* A new and better score for a previously created equivalent path */ | |
| 116511 | + /* Control reaches here if the candidate path is better than the | |
| 116512 | + ** pTo path. Replace pTo with the candidate. */ | |
| 116464 | 116513 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116465 | 116514 | if( sqlite3WhereTrace&0x4 ){ |
| 116466 | 116515 | sqlite3DebugPrintf( |
| 116467 | 116516 | "Update %s cost=%-3d,%3d order=%c", |
| 116468 | 116517 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| @@ -116476,19 +116525,24 @@ | ||
| 116476 | 116525 | /* pWLoop is a winner. Add it to the set of best so far */ |
| 116477 | 116526 | pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf; |
| 116478 | 116527 | pTo->revLoop = revMask; |
| 116479 | 116528 | pTo->nRow = nOut; |
| 116480 | 116529 | pTo->rCost = rCost; |
| 116530 | + pTo->rUnsorted = rUnsorted; | |
| 116481 | 116531 | pTo->isOrdered = isOrdered; |
| 116482 | 116532 | memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop); |
| 116483 | 116533 | pTo->aLoop[iLoop] = pWLoop; |
| 116484 | 116534 | if( nTo>=mxChoice ){ |
| 116485 | 116535 | mxI = 0; |
| 116486 | 116536 | mxCost = aTo[0].rCost; |
| 116537 | + mxUnsorted = aTo[0].nRow; | |
| 116487 | 116538 | for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){ |
| 116488 | - if( pTo->rCost>mxCost ){ | |
| 116539 | + if( pTo->rCost>mxCost | |
| 116540 | + || (pTo->rCost==mxCost && pTo->rUnsorted>mxUnsorted) | |
| 116541 | + ){ | |
| 116489 | 116542 | mxCost = pTo->rCost; |
| 116543 | + mxUnsorted = pTo->rUnsorted; | |
| 116490 | 116544 | mxI = jj; |
| 116491 | 116545 | } |
| 116492 | 116546 | } |
| 116493 | 116547 | } |
| 116494 | 116548 | } |
| @@ -123119,11 +123173,11 @@ | ||
| 123119 | 123173 | |
| 123120 | 123174 | /* |
| 123121 | 123175 | ** Return a static string containing the name corresponding to the error code |
| 123122 | 123176 | ** specified in the argument. |
| 123123 | 123177 | */ |
| 123124 | -#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) | |
| 123178 | +#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST) | |
| 123125 | 123179 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 123126 | 123180 | const char *zName = 0; |
| 123127 | 123181 | int i, origRc = rc; |
| 123128 | 123182 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 123129 | 123183 | switch( rc ){ |
| @@ -123154,11 +123208,10 @@ | ||
| 123154 | 123208 | case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break; |
| 123155 | 123209 | case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break; |
| 123156 | 123210 | case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break; |
| 123157 | 123211 | case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break; |
| 123158 | 123212 | case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break; |
| 123159 | - case SQLITE_IOERR_BLOCKED: zName = "SQLITE_IOERR_BLOCKED"; break; | |
| 123160 | 123213 | case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break; |
| 123161 | 123214 | case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break; |
| 123162 | 123215 | case SQLITE_IOERR_CHECKRESERVEDLOCK: |
| 123163 | 123216 | zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break; |
| 123164 | 123217 | case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break; |
| @@ -144218,11 +144271,11 @@ | ||
| 144218 | 144271 | ** the size of the range (always at least 1). In other words, the value |
| 144219 | 144272 | ** ((C<<22) + N) represents a range of N codepoints starting with codepoint |
| 144220 | 144273 | ** C. It is not possible to represent a range larger than 1023 codepoints |
| 144221 | 144274 | ** using this format. |
| 144222 | 144275 | */ |
| 144223 | - const static unsigned int aEntry[] = { | |
| 144276 | + static const unsigned int aEntry[] = { | |
| 144224 | 144277 | 0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07, |
| 144225 | 144278 | 0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01, |
| 144226 | 144279 | 0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401, |
| 144227 | 144280 | 0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01, |
| 144228 | 144281 | 0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01, |
| @@ -144310,11 +144363,11 @@ | ||
| 144310 | 144363 | |
| 144311 | 144364 | if( c<128 ){ |
| 144312 | 144365 | return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); |
| 144313 | 144366 | }else if( c<(1<<22) ){ |
| 144314 | 144367 | unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; |
| 144315 | - int iRes; | |
| 144368 | + int iRes = 0; | |
| 144316 | 144369 | int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; |
| 144317 | 144370 | int iLo = 0; |
| 144318 | 144371 | while( iHi>=iLo ){ |
| 144319 | 144372 | int iTest = (iHi + iLo) / 2; |
| 144320 | 144373 | if( key >= aEntry[iTest] ){ |
| @@ -144381,11 +144434,11 @@ | ||
| 144381 | 144434 | iHi = iTest-1; |
| 144382 | 144435 | } |
| 144383 | 144436 | } |
| 144384 | 144437 | assert( key>=aDia[iRes] ); |
| 144385 | 144438 | return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]); |
| 144386 | -}; | |
| 144439 | +} | |
| 144387 | 144440 | |
| 144388 | 144441 | |
| 144389 | 144442 | /* |
| 144390 | 144443 | ** Return true if the argument interpreted as a unicode codepoint |
| 144391 | 144444 | ** is a diacritical modifier character. |
| 144392 | 144445 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -222,11 +222,11 @@ | |
| 222 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 223 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 224 | */ |
| 225 | #define SQLITE_VERSION "3.8.6" |
| 226 | #define SQLITE_VERSION_NUMBER 3008006 |
| 227 | #define SQLITE_SOURCE_ID "2014-08-06 11:58:40 5c6bb57d90bad32785d6d9cdf110a825bbc5ec73" |
| 228 | |
| 229 | /* |
| 230 | ** CAPI3REF: Run-Time Library Version Numbers |
| 231 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 232 | ** |
| @@ -382,11 +382,11 @@ | |
| 382 | /* |
| 383 | ** CAPI3REF: Closing A Database Connection |
| 384 | ** |
| 385 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 386 | ** for the [sqlite3] object. |
| 387 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if |
| 388 | ** the [sqlite3] object is successfully destroyed and all associated |
| 389 | ** resources are deallocated. |
| 390 | ** |
| 391 | ** ^If the database connection is associated with unfinalized prepared |
| 392 | ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| @@ -403,11 +403,11 @@ | |
| 403 | ** [sqlite3_blob_close | close] all [BLOB handles], and |
| 404 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 405 | ** with the [sqlite3] object prior to attempting to close the object. ^If |
| 406 | ** sqlite3_close_v2() is called on a [database connection] that still has |
| 407 | ** outstanding [prepared statements], [BLOB handles], and/or |
| 408 | ** [sqlite3_backup] objects then it returns SQLITE_OK but the deallocation |
| 409 | ** of resources is deferred until all [prepared statements], [BLOB handles], |
| 410 | ** and [sqlite3_backup] objects are also destroyed. |
| 411 | ** |
| 412 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 413 | ** the transaction is automatically rolled back. |
| @@ -499,20 +499,18 @@ | |
| 499 | char **errmsg /* Error msg written here */ |
| 500 | ); |
| 501 | |
| 502 | /* |
| 503 | ** CAPI3REF: Result Codes |
| 504 | ** KEYWORDS: SQLITE_OK {error code} {error codes} |
| 505 | ** KEYWORDS: {result code} {result codes} |
| 506 | ** |
| 507 | ** Many SQLite functions return an integer result code from the set shown |
| 508 | ** here in order to indicate success or failure. |
| 509 | ** |
| 510 | ** New error codes may be added in future versions of SQLite. |
| 511 | ** |
| 512 | ** See also: [SQLITE_IOERR_READ | extended result codes], |
| 513 | ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. |
| 514 | */ |
| 515 | #define SQLITE_OK 0 /* Successful result */ |
| 516 | /* beginning-of-error-codes */ |
| 517 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 518 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -546,30 +544,23 @@ | |
| 546 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
| 547 | /* end-of-error-codes */ |
| 548 | |
| 549 | /* |
| 550 | ** CAPI3REF: Extended Result Codes |
| 551 | ** KEYWORDS: {extended error code} {extended error codes} |
| 552 | ** KEYWORDS: {extended result code} {extended result codes} |
| 553 | ** |
| 554 | ** In its default configuration, SQLite API routines return one of 26 integer |
| 555 | ** [SQLITE_OK | result codes]. However, experience has shown that many of |
| 556 | ** these result codes are too coarse-grained. They do not provide as |
| 557 | ** much information about problems as programmers might like. In an effort to |
| 558 | ** address this, newer versions of SQLite (version 3.3.8 and later) include |
| 559 | ** support for additional result codes that provide more detailed information |
| 560 | ** about errors. The extended result codes are enabled or disabled |
| 561 | ** on a per database connection basis using the |
| 562 | ** [sqlite3_extended_result_codes()] API. |
| 563 | ** |
| 564 | ** Some of the available extended result codes are listed here. |
| 565 | ** One may expect the number of extended result codes will increase |
| 566 | ** over time. Software that uses extended result codes should expect |
| 567 | ** to see new result codes in future releases of SQLite. |
| 568 | ** |
| 569 | ** The SQLITE_OK result code will never be extended. It will always |
| 570 | ** be exactly zero. |
| 571 | */ |
| 572 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 573 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 574 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 575 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| @@ -798,11 +789,11 @@ | |
| 798 | ** write return values. Potential uses for xFileControl() might be |
| 799 | ** functions to enable blocking locks with timeouts, to change the |
| 800 | ** locking strategy (for example to use dot-file locks), to inquire |
| 801 | ** about the status of a lock, or to break stale locks. The SQLite |
| 802 | ** core reserves all opcodes less than 100 for its own use. |
| 803 | ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. |
| 804 | ** Applications that define a custom xFileControl method should use opcodes |
| 805 | ** greater than 100 to avoid conflicts. VFS implementations should |
| 806 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
| 807 | ** recognize. |
| 808 | ** |
| @@ -871,10 +862,11 @@ | |
| 871 | /* Additional methods may be added in future releases */ |
| 872 | }; |
| 873 | |
| 874 | /* |
| 875 | ** CAPI3REF: Standard File Control Opcodes |
| 876 | ** |
| 877 | ** These integer constants are opcodes for the xFileControl method |
| 878 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
| 879 | ** interface. |
| 880 | ** |
| @@ -2158,28 +2150,28 @@ | |
| 2158 | ** [database connection] D when another thread |
| 2159 | ** or process has the table locked. |
| 2160 | ** The sqlite3_busy_handler() interface is used to implement |
| 2161 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
| 2162 | ** |
| 2163 | ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] |
| 2164 | ** is returned immediately upon encountering the lock. ^If the busy callback |
| 2165 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2166 | ** |
| 2167 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2168 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2169 | ** the busy handler callback is the number of times that the busy handler has |
| 2170 | ** been invoked for the same locking event. ^If the |
| 2171 | ** busy callback returns 0, then no additional attempts are made to |
| 2172 | ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned |
| 2173 | ** to the application. |
| 2174 | ** ^If the callback returns non-zero, then another attempt |
| 2175 | ** is made to access the database and the cycle repeats. |
| 2176 | ** |
| 2177 | ** The presence of a busy handler does not guarantee that it will be invoked |
| 2178 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
| 2179 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
| 2180 | ** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the |
| 2181 | ** busy handler. |
| 2182 | ** Consider a scenario where one process is holding a read lock that |
| 2183 | ** it is trying to promote to a reserved lock and |
| 2184 | ** a second process is holding a reserved lock that it is trying |
| 2185 | ** to promote to an exclusive lock. The first process cannot proceed |
| @@ -2190,25 +2182,10 @@ | |
| 2190 | ** will induce the first process to release its read lock and allow |
| 2191 | ** the second process to proceed. |
| 2192 | ** |
| 2193 | ** ^The default busy callback is NULL. |
| 2194 | ** |
| 2195 | ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] |
| 2196 | ** when SQLite is in the middle of a large transaction where all the |
| 2197 | ** changes will not fit into the in-memory cache. SQLite will |
| 2198 | ** already hold a RESERVED lock on the database file, but it needs |
| 2199 | ** to promote this lock to EXCLUSIVE so that it can spill cache |
| 2200 | ** pages into the database file without harm to concurrent |
| 2201 | ** readers. ^If it is unable to promote the lock, then the in-memory |
| 2202 | ** cache will be left in an inconsistent state and so the error |
| 2203 | ** code is promoted from the relatively benign [SQLITE_BUSY] to |
| 2204 | ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion |
| 2205 | ** forces an automatic rollback of the changes. See the |
| 2206 | ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> |
| 2207 | ** CorruptionFollowingBusyError</a> wiki page for a discussion of why |
| 2208 | ** this is important. |
| 2209 | ** |
| 2210 | ** ^(There can only be a single busy handler defined for each |
| 2211 | ** [database connection]. Setting a new busy handler clears any |
| 2212 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
| 2213 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
| 2214 | ** busy handler and thus clear any previously set busy handler. |
| @@ -2229,11 +2206,11 @@ | |
| 2229 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2230 | ** for a specified amount of time when a table is locked. ^The handler |
| 2231 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2232 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| 2233 | ** the handler returns 0 which causes [sqlite3_step()] to return |
| 2234 | ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. |
| 2235 | ** |
| 2236 | ** ^Calling this routine with an argument less than or equal to zero |
| 2237 | ** turns off all busy handlers. |
| 2238 | ** |
| 2239 | ** ^(There can only be a single busy handler for a particular |
| @@ -2641,12 +2618,12 @@ | |
| 2641 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2642 | ** to signal SQLite whether or not the action is permitted. See the |
| 2643 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2644 | ** information. |
| 2645 | ** |
| 2646 | ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] |
| 2647 | ** from the [sqlite3_vtab_on_conflict()] interface. |
| 2648 | */ |
| 2649 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2650 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2651 | |
| 2652 | /* |
| @@ -7482,10 +7459,11 @@ | |
| 7482 | */ |
| 7483 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7484 | |
| 7485 | /* |
| 7486 | ** CAPI3REF: Conflict resolution modes |
| 7487 | ** |
| 7488 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 7489 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 7490 | ** is for the SQL statement being evaluated. |
| 7491 | ** |
| @@ -24177,15 +24155,14 @@ | |
| 24177 | #include <unistd.h> |
| 24178 | /* #include <time.h> */ |
| 24179 | #include <sys/time.h> |
| 24180 | #include <errno.h> |
| 24181 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 24182 | #include <sys/mman.h> |
| 24183 | #endif |
| 24184 | |
| 24185 | |
| 24186 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 24187 | # include <sys/ioctl.h> |
| 24188 | # if OS_VXWORKS |
| 24189 | # include <semaphore.h> |
| 24190 | # include <limits.h> |
| 24191 | # else |
| @@ -24609,11 +24586,15 @@ | |
| 24609 | ** On some systems, calls to fchown() will trigger a message in a security |
| 24610 | ** log if they come from non-root processes. So avoid calling fchown() if |
| 24611 | ** we are not running as root. |
| 24612 | */ |
| 24613 | static int posixFchown(int fd, uid_t uid, gid_t gid){ |
| 24614 | return geteuid() ? 0 : fchown(fd,uid,gid); |
| 24615 | } |
| 24616 | |
| 24617 | /* Forward reference */ |
| 24618 | static int openDirectory(const char*, int*); |
| 24619 | static int unixGetpagesize(void); |
| @@ -24665,11 +24646,11 @@ | |
| 24665 | #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) |
| 24666 | |
| 24667 | { "read", (sqlite3_syscall_ptr)read, 0 }, |
| 24668 | #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) |
| 24669 | |
| 24670 | #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE |
| 24671 | { "pread", (sqlite3_syscall_ptr)pread, 0 }, |
| 24672 | #else |
| 24673 | { "pread", (sqlite3_syscall_ptr)0, 0 }, |
| 24674 | #endif |
| 24675 | #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) |
| @@ -24682,11 +24663,11 @@ | |
| 24682 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) |
| 24683 | |
| 24684 | { "write", (sqlite3_syscall_ptr)write, 0 }, |
| 24685 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) |
| 24686 | |
| 24687 | #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE |
| 24688 | { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, |
| 24689 | #else |
| 24690 | { "pwrite", (sqlite3_syscall_ptr)0, 0 }, |
| 24691 | #endif |
| 24692 | #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| @@ -25052,20 +25033,10 @@ | |
| 25052 | } |
| 25053 | /* else fall through */ |
| 25054 | case EPERM: |
| 25055 | return SQLITE_PERM; |
| 25056 | |
| 25057 | /* EDEADLK is only possible if a call to fcntl(F_SETLKW) is made. And |
| 25058 | ** this module never makes such a call. And the code in SQLite itself |
| 25059 | ** asserts that SQLITE_IOERR_BLOCKED is never returned. For these reasons |
| 25060 | ** this case is also commented out. If the system does set errno to EDEADLK, |
| 25061 | ** the default SQLITE_IOERR_XXX code will be returned. */ |
| 25062 | #if 0 |
| 25063 | case EDEADLK: |
| 25064 | return SQLITE_IOERR_BLOCKED; |
| 25065 | #endif |
| 25066 | |
| 25067 | #if EOPNOTSUPP!=ENOTSUP |
| 25068 | case EOPNOTSUPP: |
| 25069 | /* something went terribly awry, unless during file system support |
| 25070 | * introspection, in which it actually means what it says */ |
| 25071 | #endif |
| @@ -25596,11 +25567,15 @@ | |
| 25596 | ** Return TRUE if pFile has been renamed or unlinked since it was first opened. |
| 25597 | */ |
| 25598 | static int fileHasMoved(unixFile *pFile){ |
| 25599 | struct stat buf; |
| 25600 | return pFile->pInode!=0 && |
| 25601 | (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); |
| 25602 | } |
| 25603 | |
| 25604 | |
| 25605 | /* |
| 25606 | ** Check a unixFile that is a database. Verify the following: |
| @@ -26739,11 +26714,10 @@ | |
| 26739 | } |
| 26740 | |
| 26741 | /* Otherwise see if some other process holds it. */ |
| 26742 | if( !reserved ){ |
| 26743 | sem_t *pSem = pFile->pInode->pSem; |
| 26744 | struct stat statBuf; |
| 26745 | |
| 26746 | if( sem_trywait(pSem)==-1 ){ |
| 26747 | int tErrno = errno; |
| 26748 | if( EAGAIN != tErrno ){ |
| 26749 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); |
| @@ -26792,11 +26766,10 @@ | |
| 26792 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() |
| 26793 | ** routine to lower a locking level. |
| 26794 | */ |
| 26795 | static int semLock(sqlite3_file *id, int eFileLock) { |
| 26796 | unixFile *pFile = (unixFile*)id; |
| 26797 | int fd; |
| 26798 | sem_t *pSem = pFile->pInode->pSem; |
| 26799 | int rc = SQLITE_OK; |
| 26800 | |
| 26801 | /* if we already have a lock, it is exclusive. |
| 26802 | ** Just adjust level and punt on outta here. */ |
| @@ -64521,11 +64494,10 @@ | |
| 64521 | /* Lock all btrees used by the statement */ |
| 64522 | sqlite3VdbeEnter(p); |
| 64523 | |
| 64524 | /* Check for one of the special errors */ |
| 64525 | mrc = p->rc & 0xff; |
| 64526 | assert( p->rc!=SQLITE_IOERR_BLOCKED ); /* This error no longer exists */ |
| 64527 | isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| 64528 | || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL; |
| 64529 | if( isSpecialError ){ |
| 64530 | /* If the query was read-only and the error code is SQLITE_INTERRUPT, |
| 64531 | ** no rollback is necessary. Otherwise, at least a savepoint |
| @@ -71247,11 +71219,11 @@ | |
| 71247 | VdbeCursor *pCur; |
| 71248 | |
| 71249 | assert( pOp->p5==0 ); |
| 71250 | assert( pOp->p4type==P4_KEYINFO ); |
| 71251 | pCur = p->apCsr[pOp->p1]; |
| 71252 | if( pCur && pCur->pgnoRoot==pOp->p2 ){ |
| 71253 | assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ |
| 71254 | break; |
| 71255 | } |
| 71256 | /* If the cursor is not currently open or is open on a different |
| 71257 | ** index, then fall through into OP_OpenRead to force a reopen */ |
| @@ -77111,11 +77083,11 @@ | |
| 77111 | } |
| 77112 | break; |
| 77113 | } |
| 77114 | } |
| 77115 | if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){ |
| 77116 | /* IMP: R-24309-18625 */ |
| 77117 | /* IMP: R-44911-55124 */ |
| 77118 | iCol = -1; |
| 77119 | } |
| 77120 | if( iCol<pTab->nCol ){ |
| 77121 | cnt++; |
| @@ -110616,10 +110588,11 @@ | |
| 110616 | struct WherePath { |
| 110617 | Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */ |
| 110618 | Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */ |
| 110619 | LogEst nRow; /* Estimated number of rows generated by this path */ |
| 110620 | LogEst rCost; /* Total cost of this path */ |
| 110621 | i8 isOrdered; /* No. of ORDER BY terms satisfied. -1 for unknown */ |
| 110622 | WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */ |
| 110623 | }; |
| 110624 | |
| 110625 | /* |
| @@ -116275,10 +116248,49 @@ | |
| 116275 | if( pLast ) zName[i++] = pLast->cId; |
| 116276 | zName[i] = 0; |
| 116277 | return zName; |
| 116278 | } |
| 116279 | #endif |
| 116280 | |
| 116281 | /* |
| 116282 | ** Given the list of WhereLoop objects at pWInfo->pLoops, this routine |
| 116283 | ** attempts to find the lowest cost path that visits each WhereLoop |
| 116284 | ** once. This path is then loaded into the pWInfo->a[].pWLoop fields. |
| @@ -116297,139 +116309,170 @@ | |
| 116297 | sqlite3 *db; /* The database connection */ |
| 116298 | int iLoop; /* Loop counter over the terms of the join */ |
| 116299 | int ii, jj; /* Loop counters */ |
| 116300 | int mxI = 0; /* Index of next entry to replace */ |
| 116301 | int nOrderBy; /* Number of ORDER BY clause terms */ |
| 116302 | LogEst rCost; /* Cost of a path */ |
| 116303 | LogEst nOut; /* Number of outputs */ |
| 116304 | LogEst mxCost = 0; /* Maximum cost of a set of paths */ |
| 116305 | int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */ |
| 116306 | WherePath *aFrom; /* All nFrom paths at the previous level */ |
| 116307 | WherePath *aTo; /* The nTo best paths at the current level */ |
| 116308 | WherePath *pFrom; /* An element of aFrom[] that we are working on */ |
| 116309 | WherePath *pTo; /* An element of aTo[] that we are working on */ |
| 116310 | WhereLoop *pWLoop; /* One of the WhereLoop objects */ |
| 116311 | WhereLoop **pX; /* Used to divy up the pSpace memory */ |
| 116312 | char *pSpace; /* Temporary memory used by this routine */ |
| 116313 | |
| 116314 | pParse = pWInfo->pParse; |
| 116315 | db = pParse->db; |
| 116316 | nLoop = pWInfo->nLevel; |
| 116317 | /* TUNING: For simple queries, only the best path is tracked. |
| 116318 | ** For 2-way joins, the 5 best paths are followed. |
| 116319 | ** For joins of 3 or more tables, track the 10 best paths */ |
| 116320 | mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10); |
| 116321 | assert( nLoop<=pWInfo->pTabList->nSrc ); |
| 116322 | WHERETRACE(0x002, ("---- begin solver\n")); |
| 116323 | |
| 116324 | /* Allocate and initialize space for aTo and aFrom */ |
| 116325 | ii = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2; |
| 116326 | pSpace = sqlite3DbMallocRaw(db, ii); |
| 116327 | if( pSpace==0 ) return SQLITE_NOMEM; |
| 116328 | aTo = (WherePath*)pSpace; |
| 116329 | aFrom = aTo+mxChoice; |
| 116330 | memset(aFrom, 0, sizeof(aFrom[0])); |
| 116331 | pX = (WhereLoop**)(aFrom+mxChoice); |
| 116332 | for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){ |
| 116333 | pFrom->aLoop = pX; |
| 116334 | } |
| 116335 | |
| 116336 | /* Seed the search with a single WherePath containing zero WhereLoops. |
| 116337 | ** |
| 116338 | ** TUNING: Do not let the number of iterations go above 25. If the cost |
| 116339 | ** of computing an automatic index is not paid back within the first 25 |
| 116340 | ** rows, then do not use the automatic index. */ |
| 116341 | aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) ); |
| 116342 | nFrom = 1; |
| 116343 | |
| 116344 | /* Precompute the cost of sorting the final result set, if the caller |
| 116345 | ** to sqlite3WhereBegin() was concerned about sorting */ |
| 116346 | if( pWInfo->pOrderBy==0 || nRowEst==0 ){ |
| 116347 | aFrom[0].isOrdered = 0; |
| 116348 | nOrderBy = 0; |
| 116349 | }else{ |
| 116350 | aFrom[0].isOrdered = nLoop>0 ? -1 : 1; |
| 116351 | nOrderBy = pWInfo->pOrderBy->nExpr; |
| 116352 | } |
| 116353 | |
| 116354 | /* Compute successively longer WherePaths using the previous generation |
| 116355 | ** of WherePaths as the basis for the next. Keep track of the mxChoice |
| 116356 | ** best paths at each generation */ |
| 116357 | for(iLoop=0; iLoop<nLoop; iLoop++){ |
| 116358 | nTo = 0; |
| 116359 | for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){ |
| 116360 | for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){ |
| 116361 | Bitmask maskNew; |
| 116362 | Bitmask revMask = 0; |
| 116363 | i8 isOrdered = pFrom->isOrdered; |
| 116364 | if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue; |
| 116365 | if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue; |
| 116366 | /* At this point, pWLoop is a candidate to be the next loop. |
| 116367 | ** Compute its cost */ |
| 116368 | rCost = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); |
| 116369 | rCost = sqlite3LogEstAdd(rCost, pFrom->rCost); |
| 116370 | nOut = pFrom->nRow + pWLoop->nOut; |
| 116371 | maskNew = pFrom->maskLoop | pWLoop->maskSelf; |
| 116372 | if( isOrdered<0 ){ |
| 116373 | isOrdered = wherePathSatisfiesOrderBy(pWInfo, |
| 116374 | pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags, |
| 116375 | iLoop, pWLoop, &revMask); |
| 116376 | if( isOrdered>=0 && isOrdered<nOrderBy ){ |
| 116377 | /* TUNING: Estimated cost of a full external sort, where N is |
| 116378 | ** the number of rows to sort is: |
| 116379 | ** |
| 116380 | ** cost = (3.0 * N * log(N)). |
| 116381 | ** |
| 116382 | ** Or, if the order-by clause has X terms but only the last Y |
| 116383 | ** terms are out of order, then block-sorting will reduce the |
| 116384 | ** sorting cost to: |
| 116385 | ** |
| 116386 | ** cost = (3.0 * N * log(N)) * (Y/X) |
| 116387 | ** |
| 116388 | ** The (Y/X) term is implemented using stack variable rScale |
| 116389 | ** below. */ |
| 116390 | LogEst rScale, rSortCost; |
| 116391 | assert( nOrderBy>0 && 66==sqlite3LogEst(100) ); |
| 116392 | rScale = sqlite3LogEst((nOrderBy-isOrdered)*100/nOrderBy) - 66; |
| 116393 | rSortCost = nRowEst + estLog(nRowEst) + rScale + 16; |
| 116394 | |
| 116395 | /* TUNING: The cost of implementing DISTINCT using a B-TREE is |
| 116396 | ** similar but with a larger constant of proportionality. |
| 116397 | ** Multiply by an additional factor of 3.0. */ |
| 116398 | if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 116399 | rSortCost += 16; |
| 116400 | } |
| 116401 | WHERETRACE(0x002, |
| 116402 | ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n", |
| 116403 | rSortCost, (nOrderBy-isOrdered), nOrderBy, rCost, |
| 116404 | sqlite3LogEstAdd(rCost,rSortCost))); |
| 116405 | rCost = sqlite3LogEstAdd(rCost, rSortCost); |
| 116406 | } |
| 116407 | }else{ |
| 116408 | revMask = pFrom->revLoop; |
| 116409 | } |
| 116410 | /* Check to see if pWLoop should be added to the mxChoice best so far */ |
| 116411 | for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){ |
| 116412 | if( pTo->maskLoop==maskNew |
| 116413 | && ((pTo->isOrdered^isOrdered)&80)==0 |
| 116414 | ){ |
| 116415 | testcase( jj==nTo-1 ); |
| 116416 | break; |
| 116417 | } |
| 116418 | } |
| 116419 | if( jj>=nTo ){ |
| 116420 | if( nTo>=mxChoice && rCost>=mxCost ){ |
| 116421 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116422 | if( sqlite3WhereTrace&0x4 ){ |
| 116423 | sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n", |
| 116424 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| 116425 | isOrdered>=0 ? isOrdered+'0' : '?'); |
| 116426 | } |
| 116427 | #endif |
| 116428 | continue; |
| 116429 | } |
| 116430 | /* Add a new Path to the aTo[] set */ |
| 116431 | if( nTo<mxChoice ){ |
| 116432 | /* Increase the size of the aTo set by one */ |
| 116433 | jj = nTo++; |
| 116434 | }else{ |
| 116435 | /* New path replaces the prior worst to keep count below mxChoice */ |
| @@ -116442,11 +116485,15 @@ | |
| 116442 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| 116443 | isOrdered>=0 ? isOrdered+'0' : '?'); |
| 116444 | } |
| 116445 | #endif |
| 116446 | }else{ |
| 116447 | if( pTo->rCost<=rCost ){ |
| 116448 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116449 | if( sqlite3WhereTrace&0x4 ){ |
| 116450 | sqlite3DebugPrintf( |
| 116451 | "Skip %s cost=%-3d,%3d order=%c", |
| 116452 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| @@ -116454,15 +116501,17 @@ | |
| 116454 | sqlite3DebugPrintf(" vs %s cost=%-3d,%d order=%c\n", |
| 116455 | wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow, |
| 116456 | pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?'); |
| 116457 | } |
| 116458 | #endif |
| 116459 | testcase( pTo->rCost==rCost ); |
| 116460 | continue; |
| 116461 | } |
| 116462 | testcase( pTo->rCost==rCost+1 ); |
| 116463 | /* A new and better score for a previously created equivalent path */ |
| 116464 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116465 | if( sqlite3WhereTrace&0x4 ){ |
| 116466 | sqlite3DebugPrintf( |
| 116467 | "Update %s cost=%-3d,%3d order=%c", |
| 116468 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| @@ -116476,19 +116525,24 @@ | |
| 116476 | /* pWLoop is a winner. Add it to the set of best so far */ |
| 116477 | pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf; |
| 116478 | pTo->revLoop = revMask; |
| 116479 | pTo->nRow = nOut; |
| 116480 | pTo->rCost = rCost; |
| 116481 | pTo->isOrdered = isOrdered; |
| 116482 | memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop); |
| 116483 | pTo->aLoop[iLoop] = pWLoop; |
| 116484 | if( nTo>=mxChoice ){ |
| 116485 | mxI = 0; |
| 116486 | mxCost = aTo[0].rCost; |
| 116487 | for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){ |
| 116488 | if( pTo->rCost>mxCost ){ |
| 116489 | mxCost = pTo->rCost; |
| 116490 | mxI = jj; |
| 116491 | } |
| 116492 | } |
| 116493 | } |
| 116494 | } |
| @@ -123119,11 +123173,11 @@ | |
| 123119 | |
| 123120 | /* |
| 123121 | ** Return a static string containing the name corresponding to the error code |
| 123122 | ** specified in the argument. |
| 123123 | */ |
| 123124 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 123125 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 123126 | const char *zName = 0; |
| 123127 | int i, origRc = rc; |
| 123128 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 123129 | switch( rc ){ |
| @@ -123154,11 +123208,10 @@ | |
| 123154 | case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break; |
| 123155 | case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break; |
| 123156 | case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break; |
| 123157 | case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break; |
| 123158 | case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break; |
| 123159 | case SQLITE_IOERR_BLOCKED: zName = "SQLITE_IOERR_BLOCKED"; break; |
| 123160 | case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break; |
| 123161 | case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break; |
| 123162 | case SQLITE_IOERR_CHECKRESERVEDLOCK: |
| 123163 | zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break; |
| 123164 | case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break; |
| @@ -144218,11 +144271,11 @@ | |
| 144218 | ** the size of the range (always at least 1). In other words, the value |
| 144219 | ** ((C<<22) + N) represents a range of N codepoints starting with codepoint |
| 144220 | ** C. It is not possible to represent a range larger than 1023 codepoints |
| 144221 | ** using this format. |
| 144222 | */ |
| 144223 | const static unsigned int aEntry[] = { |
| 144224 | 0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07, |
| 144225 | 0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01, |
| 144226 | 0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401, |
| 144227 | 0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01, |
| 144228 | 0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01, |
| @@ -144310,11 +144363,11 @@ | |
| 144310 | |
| 144311 | if( c<128 ){ |
| 144312 | return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); |
| 144313 | }else if( c<(1<<22) ){ |
| 144314 | unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; |
| 144315 | int iRes; |
| 144316 | int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; |
| 144317 | int iLo = 0; |
| 144318 | while( iHi>=iLo ){ |
| 144319 | int iTest = (iHi + iLo) / 2; |
| 144320 | if( key >= aEntry[iTest] ){ |
| @@ -144381,11 +144434,11 @@ | |
| 144381 | iHi = iTest-1; |
| 144382 | } |
| 144383 | } |
| 144384 | assert( key>=aDia[iRes] ); |
| 144385 | return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]); |
| 144386 | }; |
| 144387 | |
| 144388 | |
| 144389 | /* |
| 144390 | ** Return true if the argument interpreted as a unicode codepoint |
| 144391 | ** is a diacritical modifier character. |
| 144392 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -222,11 +222,11 @@ | |
| 222 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 223 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 224 | */ |
| 225 | #define SQLITE_VERSION "3.8.6" |
| 226 | #define SQLITE_VERSION_NUMBER 3008006 |
| 227 | #define SQLITE_SOURCE_ID "2014-08-11 13:53:30 de27c742c0dcda20b51339598bf6094a8dcf5fb9" |
| 228 | |
| 229 | /* |
| 230 | ** CAPI3REF: Run-Time Library Version Numbers |
| 231 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 232 | ** |
| @@ -382,11 +382,11 @@ | |
| 382 | /* |
| 383 | ** CAPI3REF: Closing A Database Connection |
| 384 | ** |
| 385 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 386 | ** for the [sqlite3] object. |
| 387 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 388 | ** the [sqlite3] object is successfully destroyed and all associated |
| 389 | ** resources are deallocated. |
| 390 | ** |
| 391 | ** ^If the database connection is associated with unfinalized prepared |
| 392 | ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| @@ -403,11 +403,11 @@ | |
| 403 | ** [sqlite3_blob_close | close] all [BLOB handles], and |
| 404 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 405 | ** with the [sqlite3] object prior to attempting to close the object. ^If |
| 406 | ** sqlite3_close_v2() is called on a [database connection] that still has |
| 407 | ** outstanding [prepared statements], [BLOB handles], and/or |
| 408 | ** [sqlite3_backup] objects then it returns [SQLITE_OK] but the deallocation |
| 409 | ** of resources is deferred until all [prepared statements], [BLOB handles], |
| 410 | ** and [sqlite3_backup] objects are also destroyed. |
| 411 | ** |
| 412 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 413 | ** the transaction is automatically rolled back. |
| @@ -499,20 +499,18 @@ | |
| 499 | char **errmsg /* Error msg written here */ |
| 500 | ); |
| 501 | |
| 502 | /* |
| 503 | ** CAPI3REF: Result Codes |
| 504 | ** KEYWORDS: {result code definitions} |
| 505 | ** |
| 506 | ** Many SQLite functions return an integer result code from the set shown |
| 507 | ** here in order to indicate success or failure. |
| 508 | ** |
| 509 | ** New error codes may be added in future versions of SQLite. |
| 510 | ** |
| 511 | ** See also: [extended result code definitions] |
| 512 | */ |
| 513 | #define SQLITE_OK 0 /* Successful result */ |
| 514 | /* beginning-of-error-codes */ |
| 515 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 516 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -546,30 +544,23 @@ | |
| 544 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
| 545 | /* end-of-error-codes */ |
| 546 | |
| 547 | /* |
| 548 | ** CAPI3REF: Extended Result Codes |
| 549 | ** KEYWORDS: {extended result code definitions} |
| 550 | ** |
| 551 | ** In its default configuration, SQLite API routines return one of 30 integer |
| 552 | ** [result codes]. However, experience has shown that many of |
| 553 | ** these result codes are too coarse-grained. They do not provide as |
| 554 | ** much information about problems as programmers might like. In an effort to |
| 555 | ** address this, newer versions of SQLite (version 3.3.8 and later) include |
| 556 | ** support for additional result codes that provide more detailed information |
| 557 | ** about errors. These [extended result codes] are enabled or disabled |
| 558 | ** on a per database connection basis using the |
| 559 | ** [sqlite3_extended_result_codes()] API. Or, the extended code for |
| 560 | ** the most recent error can be obtained using |
| 561 | ** [sqlite3_extended_errcode()]. |
| 562 | */ |
| 563 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 564 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 565 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 566 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| @@ -798,11 +789,11 @@ | |
| 789 | ** write return values. Potential uses for xFileControl() might be |
| 790 | ** functions to enable blocking locks with timeouts, to change the |
| 791 | ** locking strategy (for example to use dot-file locks), to inquire |
| 792 | ** about the status of a lock, or to break stale locks. The SQLite |
| 793 | ** core reserves all opcodes less than 100 for its own use. |
| 794 | ** A [file control opcodes | list of opcodes] less than 100 is available. |
| 795 | ** Applications that define a custom xFileControl method should use opcodes |
| 796 | ** greater than 100 to avoid conflicts. VFS implementations should |
| 797 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
| 798 | ** recognize. |
| 799 | ** |
| @@ -871,10 +862,11 @@ | |
| 862 | /* Additional methods may be added in future releases */ |
| 863 | }; |
| 864 | |
| 865 | /* |
| 866 | ** CAPI3REF: Standard File Control Opcodes |
| 867 | ** KEYWORDS: {file control opcodes} {file control opcode} |
| 868 | ** |
| 869 | ** These integer constants are opcodes for the xFileControl method |
| 870 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
| 871 | ** interface. |
| 872 | ** |
| @@ -2158,28 +2150,28 @@ | |
| 2150 | ** [database connection] D when another thread |
| 2151 | ** or process has the table locked. |
| 2152 | ** The sqlite3_busy_handler() interface is used to implement |
| 2153 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
| 2154 | ** |
| 2155 | ** ^If the busy callback is NULL, then [SQLITE_BUSY] |
| 2156 | ** is returned immediately upon encountering the lock. ^If the busy callback |
| 2157 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2158 | ** |
| 2159 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2160 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2161 | ** the busy handler callback is the number of times that the busy handler has |
| 2162 | ** been invoked for the same locking event. ^If the |
| 2163 | ** busy callback returns 0, then no additional attempts are made to |
| 2164 | ** access the database and [SQLITE_BUSY] is returned |
| 2165 | ** to the application. |
| 2166 | ** ^If the callback returns non-zero, then another attempt |
| 2167 | ** is made to access the database and the cycle repeats. |
| 2168 | ** |
| 2169 | ** The presence of a busy handler does not guarantee that it will be invoked |
| 2170 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
| 2171 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
| 2172 | ** to the application instead of invoking the |
| 2173 | ** busy handler. |
| 2174 | ** Consider a scenario where one process is holding a read lock that |
| 2175 | ** it is trying to promote to a reserved lock and |
| 2176 | ** a second process is holding a reserved lock that it is trying |
| 2177 | ** to promote to an exclusive lock. The first process cannot proceed |
| @@ -2190,25 +2182,10 @@ | |
| 2182 | ** will induce the first process to release its read lock and allow |
| 2183 | ** the second process to proceed. |
| 2184 | ** |
| 2185 | ** ^The default busy callback is NULL. |
| 2186 | ** |
| 2187 | ** ^(There can only be a single busy handler defined for each |
| 2188 | ** [database connection]. Setting a new busy handler clears any |
| 2189 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
| 2190 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
| 2191 | ** busy handler and thus clear any previously set busy handler. |
| @@ -2229,11 +2206,11 @@ | |
| 2206 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2207 | ** for a specified amount of time when a table is locked. ^The handler |
| 2208 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2209 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| 2210 | ** the handler returns 0 which causes [sqlite3_step()] to return |
| 2211 | ** [SQLITE_BUSY]. |
| 2212 | ** |
| 2213 | ** ^Calling this routine with an argument less than or equal to zero |
| 2214 | ** turns off all busy handlers. |
| 2215 | ** |
| 2216 | ** ^(There can only be a single busy handler for a particular |
| @@ -2641,12 +2618,12 @@ | |
| 2618 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2619 | ** to signal SQLite whether or not the action is permitted. See the |
| 2620 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2621 | ** information. |
| 2622 | ** |
| 2623 | ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] |
| 2624 | ** returned from the [sqlite3_vtab_on_conflict()] interface. |
| 2625 | */ |
| 2626 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2627 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2628 | |
| 2629 | /* |
| @@ -7482,10 +7459,11 @@ | |
| 7459 | */ |
| 7460 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7461 | |
| 7462 | /* |
| 7463 | ** CAPI3REF: Conflict resolution modes |
| 7464 | ** KEYWORDS: {conflict resolution mode} |
| 7465 | ** |
| 7466 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 7467 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 7468 | ** is for the SQL statement being evaluated. |
| 7469 | ** |
| @@ -24177,15 +24155,14 @@ | |
| 24155 | #include <unistd.h> |
| 24156 | /* #include <time.h> */ |
| 24157 | #include <sys/time.h> |
| 24158 | #include <errno.h> |
| 24159 | #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 |
| 24160 | # include <sys/mman.h> |
| 24161 | #endif |
| 24162 | |
| 24163 | #if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS |
| 24164 | # include <sys/ioctl.h> |
| 24165 | # if OS_VXWORKS |
| 24166 | # include <semaphore.h> |
| 24167 | # include <limits.h> |
| 24168 | # else |
| @@ -24609,11 +24586,15 @@ | |
| 24586 | ** On some systems, calls to fchown() will trigger a message in a security |
| 24587 | ** log if they come from non-root processes. So avoid calling fchown() if |
| 24588 | ** we are not running as root. |
| 24589 | */ |
| 24590 | static int posixFchown(int fd, uid_t uid, gid_t gid){ |
| 24591 | #if OS_VXWORKS |
| 24592 | return 0; |
| 24593 | #else |
| 24594 | return geteuid() ? 0 : fchown(fd,uid,gid); |
| 24595 | #endif |
| 24596 | } |
| 24597 | |
| 24598 | /* Forward reference */ |
| 24599 | static int openDirectory(const char*, int*); |
| 24600 | static int unixGetpagesize(void); |
| @@ -24665,11 +24646,11 @@ | |
| 24646 | #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent) |
| 24647 | |
| 24648 | { "read", (sqlite3_syscall_ptr)read, 0 }, |
| 24649 | #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent) |
| 24650 | |
| 24651 | #if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS) |
| 24652 | { "pread", (sqlite3_syscall_ptr)pread, 0 }, |
| 24653 | #else |
| 24654 | { "pread", (sqlite3_syscall_ptr)0, 0 }, |
| 24655 | #endif |
| 24656 | #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent) |
| @@ -24682,11 +24663,11 @@ | |
| 24663 | #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) |
| 24664 | |
| 24665 | { "write", (sqlite3_syscall_ptr)write, 0 }, |
| 24666 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) |
| 24667 | |
| 24668 | #if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS) |
| 24669 | { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 }, |
| 24670 | #else |
| 24671 | { "pwrite", (sqlite3_syscall_ptr)0, 0 }, |
| 24672 | #endif |
| 24673 | #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| @@ -25052,20 +25033,10 @@ | |
| 25033 | } |
| 25034 | /* else fall through */ |
| 25035 | case EPERM: |
| 25036 | return SQLITE_PERM; |
| 25037 | |
| 25038 | #if EOPNOTSUPP!=ENOTSUP |
| 25039 | case EOPNOTSUPP: |
| 25040 | /* something went terribly awry, unless during file system support |
| 25041 | * introspection, in which it actually means what it says */ |
| 25042 | #endif |
| @@ -25596,11 +25567,15 @@ | |
| 25567 | ** Return TRUE if pFile has been renamed or unlinked since it was first opened. |
| 25568 | */ |
| 25569 | static int fileHasMoved(unixFile *pFile){ |
| 25570 | struct stat buf; |
| 25571 | return pFile->pInode!=0 && |
| 25572 | #if OS_VXWORKS |
| 25573 | pFile->pId!=pFile->pInode->fileId.Pid; |
| 25574 | #else |
| 25575 | (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); |
| 25576 | #endif |
| 25577 | } |
| 25578 | |
| 25579 | |
| 25580 | /* |
| 25581 | ** Check a unixFile that is a database. Verify the following: |
| @@ -26739,11 +26714,10 @@ | |
| 26714 | } |
| 26715 | |
| 26716 | /* Otherwise see if some other process holds it. */ |
| 26717 | if( !reserved ){ |
| 26718 | sem_t *pSem = pFile->pInode->pSem; |
| 26719 | |
| 26720 | if( sem_trywait(pSem)==-1 ){ |
| 26721 | int tErrno = errno; |
| 26722 | if( EAGAIN != tErrno ){ |
| 26723 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK); |
| @@ -26792,11 +26766,10 @@ | |
| 26766 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() |
| 26767 | ** routine to lower a locking level. |
| 26768 | */ |
| 26769 | static int semLock(sqlite3_file *id, int eFileLock) { |
| 26770 | unixFile *pFile = (unixFile*)id; |
| 26771 | sem_t *pSem = pFile->pInode->pSem; |
| 26772 | int rc = SQLITE_OK; |
| 26773 | |
| 26774 | /* if we already have a lock, it is exclusive. |
| 26775 | ** Just adjust level and punt on outta here. */ |
| @@ -64521,11 +64494,10 @@ | |
| 64494 | /* Lock all btrees used by the statement */ |
| 64495 | sqlite3VdbeEnter(p); |
| 64496 | |
| 64497 | /* Check for one of the special errors */ |
| 64498 | mrc = p->rc & 0xff; |
| 64499 | isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR |
| 64500 | || mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL; |
| 64501 | if( isSpecialError ){ |
| 64502 | /* If the query was read-only and the error code is SQLITE_INTERRUPT, |
| 64503 | ** no rollback is necessary. Otherwise, at least a savepoint |
| @@ -71247,11 +71219,11 @@ | |
| 71219 | VdbeCursor *pCur; |
| 71220 | |
| 71221 | assert( pOp->p5==0 ); |
| 71222 | assert( pOp->p4type==P4_KEYINFO ); |
| 71223 | pCur = p->apCsr[pOp->p1]; |
| 71224 | if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){ |
| 71225 | assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ |
| 71226 | break; |
| 71227 | } |
| 71228 | /* If the cursor is not currently open or is open on a different |
| 71229 | ** index, then fall through into OP_OpenRead to force a reopen */ |
| @@ -77111,11 +77083,11 @@ | |
| 77083 | } |
| 77084 | break; |
| 77085 | } |
| 77086 | } |
| 77087 | if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){ |
| 77088 | /* IMP: R-51414-32910 */ |
| 77089 | /* IMP: R-44911-55124 */ |
| 77090 | iCol = -1; |
| 77091 | } |
| 77092 | if( iCol<pTab->nCol ){ |
| 77093 | cnt++; |
| @@ -110616,10 +110588,11 @@ | |
| 110588 | struct WherePath { |
| 110589 | Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */ |
| 110590 | Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */ |
| 110591 | LogEst nRow; /* Estimated number of rows generated by this path */ |
| 110592 | LogEst rCost; /* Total cost of this path */ |
| 110593 | LogEst rUnsorted; /* Total cost of this path ignoring sorting costs */ |
| 110594 | i8 isOrdered; /* No. of ORDER BY terms satisfied. -1 for unknown */ |
| 110595 | WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */ |
| 110596 | }; |
| 110597 | |
| 110598 | /* |
| @@ -116275,10 +116248,49 @@ | |
| 116248 | if( pLast ) zName[i++] = pLast->cId; |
| 116249 | zName[i] = 0; |
| 116250 | return zName; |
| 116251 | } |
| 116252 | #endif |
| 116253 | |
| 116254 | /* |
| 116255 | ** Return the cost of sorting nRow rows, assuming that the keys have |
| 116256 | ** nOrderby columns and that the first nSorted columns are already in |
| 116257 | ** order. |
| 116258 | */ |
| 116259 | static LogEst whereSortingCost( |
| 116260 | WhereInfo *pWInfo, |
| 116261 | LogEst nRow, |
| 116262 | int nOrderBy, |
| 116263 | int nSorted |
| 116264 | ){ |
| 116265 | /* TUNING: Estimated cost of a full external sort, where N is |
| 116266 | ** the number of rows to sort is: |
| 116267 | ** |
| 116268 | ** cost = (3.0 * N * log(N)). |
| 116269 | ** |
| 116270 | ** Or, if the order-by clause has X terms but only the last Y |
| 116271 | ** terms are out of order, then block-sorting will reduce the |
| 116272 | ** sorting cost to: |
| 116273 | ** |
| 116274 | ** cost = (3.0 * N * log(N)) * (Y/X) |
| 116275 | ** |
| 116276 | ** The (Y/X) term is implemented using stack variable rScale |
| 116277 | ** below. */ |
| 116278 | LogEst rScale, rSortCost; |
| 116279 | assert( nOrderBy>0 && 66==sqlite3LogEst(100) ); |
| 116280 | rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66; |
| 116281 | rSortCost = nRow + estLog(nRow) + rScale + 16; |
| 116282 | |
| 116283 | /* TUNING: The cost of implementing DISTINCT using a B-TREE is |
| 116284 | ** similar but with a larger constant of proportionality. |
| 116285 | ** Multiply by an additional factor of 3.0. */ |
| 116286 | if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 116287 | rSortCost += 16; |
| 116288 | } |
| 116289 | |
| 116290 | return rSortCost; |
| 116291 | } |
| 116292 | |
| 116293 | /* |
| 116294 | ** Given the list of WhereLoop objects at pWInfo->pLoops, this routine |
| 116295 | ** attempts to find the lowest cost path that visits each WhereLoop |
| 116296 | ** once. This path is then loaded into the pWInfo->a[].pWLoop fields. |
| @@ -116297,139 +116309,170 @@ | |
| 116309 | sqlite3 *db; /* The database connection */ |
| 116310 | int iLoop; /* Loop counter over the terms of the join */ |
| 116311 | int ii, jj; /* Loop counters */ |
| 116312 | int mxI = 0; /* Index of next entry to replace */ |
| 116313 | int nOrderBy; /* Number of ORDER BY clause terms */ |
| 116314 | LogEst mxCost = 0; /* Maximum cost of a set of paths */ |
| 116315 | LogEst mxUnsorted = 0; /* Maximum unsorted cost of a set of path */ |
| 116316 | int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */ |
| 116317 | WherePath *aFrom; /* All nFrom paths at the previous level */ |
| 116318 | WherePath *aTo; /* The nTo best paths at the current level */ |
| 116319 | WherePath *pFrom; /* An element of aFrom[] that we are working on */ |
| 116320 | WherePath *pTo; /* An element of aTo[] that we are working on */ |
| 116321 | WhereLoop *pWLoop; /* One of the WhereLoop objects */ |
| 116322 | WhereLoop **pX; /* Used to divy up the pSpace memory */ |
| 116323 | LogEst *aSortCost = 0; /* Sorting and partial sorting costs */ |
| 116324 | char *pSpace; /* Temporary memory used by this routine */ |
| 116325 | int nSpace; /* Bytes of space allocated at pSpace */ |
| 116326 | |
| 116327 | pParse = pWInfo->pParse; |
| 116328 | db = pParse->db; |
| 116329 | nLoop = pWInfo->nLevel; |
| 116330 | /* TUNING: For simple queries, only the best path is tracked. |
| 116331 | ** For 2-way joins, the 5 best paths are followed. |
| 116332 | ** For joins of 3 or more tables, track the 10 best paths */ |
| 116333 | mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10); |
| 116334 | assert( nLoop<=pWInfo->pTabList->nSrc ); |
| 116335 | WHERETRACE(0x002, ("---- begin solver. (nRowEst=%d)\n", nRowEst)); |
| 116336 | |
| 116337 | /* If nRowEst is zero and there is an ORDER BY clause, ignore it. In this |
| 116338 | ** case the purpose of this call is to estimate the number of rows returned |
| 116339 | ** by the overall query. Once this estimate has been obtained, the caller |
| 116340 | ** will invoke this function a second time, passing the estimate as the |
| 116341 | ** nRowEst parameter. */ |
| 116342 | if( pWInfo->pOrderBy==0 || nRowEst==0 ){ |
| 116343 | nOrderBy = 0; |
| 116344 | }else{ |
| 116345 | nOrderBy = pWInfo->pOrderBy->nExpr; |
| 116346 | } |
| 116347 | |
| 116348 | /* Allocate and initialize space for aTo, aFrom and aSortCost[] */ |
| 116349 | nSpace = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2; |
| 116350 | nSpace += sizeof(LogEst) * nOrderBy; |
| 116351 | pSpace = sqlite3DbMallocRaw(db, nSpace); |
| 116352 | if( pSpace==0 ) return SQLITE_NOMEM; |
| 116353 | aTo = (WherePath*)pSpace; |
| 116354 | aFrom = aTo+mxChoice; |
| 116355 | memset(aFrom, 0, sizeof(aFrom[0])); |
| 116356 | pX = (WhereLoop**)(aFrom+mxChoice); |
| 116357 | for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){ |
| 116358 | pFrom->aLoop = pX; |
| 116359 | } |
| 116360 | if( nOrderBy ){ |
| 116361 | /* If there is an ORDER BY clause and it is not being ignored, set up |
| 116362 | ** space for the aSortCost[] array. Each element of the aSortCost array |
| 116363 | ** is either zero - meaning it has not yet been initialized - or the |
| 116364 | ** cost of sorting nRowEst rows of data where the first X terms of |
| 116365 | ** the ORDER BY clause are already in order, where X is the array |
| 116366 | ** index. */ |
| 116367 | aSortCost = (LogEst*)pX; |
| 116368 | memset(aSortCost, 0, sizeof(LogEst) * nOrderBy); |
| 116369 | } |
| 116370 | assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] ); |
| 116371 | assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX ); |
| 116372 | |
| 116373 | /* Seed the search with a single WherePath containing zero WhereLoops. |
| 116374 | ** |
| 116375 | ** TUNING: Do not let the number of iterations go above 25. If the cost |
| 116376 | ** of computing an automatic index is not paid back within the first 25 |
| 116377 | ** rows, then do not use the automatic index. */ |
| 116378 | aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) ); |
| 116379 | nFrom = 1; |
| 116380 | assert( aFrom[0].isOrdered==0 ); |
| 116381 | if( nOrderBy ){ |
| 116382 | /* If nLoop is zero, then there are no FROM terms in the query. Since |
| 116383 | ** in this case the query may return a maximum of one row, the results |
| 116384 | ** are already in the requested order. Set isOrdered to nOrderBy to |
| 116385 | ** indicate this. Or, if nLoop is greater than zero, set isOrdered to |
| 116386 | ** -1, indicating that the result set may or may not be ordered, |
| 116387 | ** depending on the loops added to the current plan. */ |
| 116388 | aFrom[0].isOrdered = nLoop>0 ? -1 : nOrderBy; |
| 116389 | } |
| 116390 | |
| 116391 | /* Compute successively longer WherePaths using the previous generation |
| 116392 | ** of WherePaths as the basis for the next. Keep track of the mxChoice |
| 116393 | ** best paths at each generation */ |
| 116394 | for(iLoop=0; iLoop<nLoop; iLoop++){ |
| 116395 | nTo = 0; |
| 116396 | for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){ |
| 116397 | for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){ |
| 116398 | LogEst nOut; /* Rows visited by (pFrom+pWLoop) */ |
| 116399 | LogEst rCost; /* Cost of path (pFrom+pWLoop) */ |
| 116400 | LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */ |
| 116401 | i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */ |
| 116402 | Bitmask maskNew; /* Mask of src visited by (..) */ |
| 116403 | Bitmask revMask = 0; /* Mask of rev-order loops for (..) */ |
| 116404 | |
| 116405 | if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue; |
| 116406 | if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue; |
| 116407 | /* At this point, pWLoop is a candidate to be the next loop. |
| 116408 | ** Compute its cost */ |
| 116409 | rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow); |
| 116410 | rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted); |
| 116411 | nOut = pFrom->nRow + pWLoop->nOut; |
| 116412 | maskNew = pFrom->maskLoop | pWLoop->maskSelf; |
| 116413 | if( isOrdered<0 ){ |
| 116414 | isOrdered = wherePathSatisfiesOrderBy(pWInfo, |
| 116415 | pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags, |
| 116416 | iLoop, pWLoop, &revMask); |
| 116417 | }else{ |
| 116418 | revMask = pFrom->revLoop; |
| 116419 | } |
| 116420 | if( isOrdered>=0 && isOrdered<nOrderBy ){ |
| 116421 | if( aSortCost[isOrdered]==0 ){ |
| 116422 | aSortCost[isOrdered] = whereSortingCost( |
| 116423 | pWInfo, nRowEst, nOrderBy, isOrdered |
| 116424 | ); |
| 116425 | } |
| 116426 | rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]); |
| 116427 | |
| 116428 | WHERETRACE(0x002, |
| 116429 | ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n", |
| 116430 | aSortCost[isOrdered], (nOrderBy-isOrdered), nOrderBy, |
| 116431 | rUnsorted, rCost)); |
| 116432 | }else{ |
| 116433 | rCost = rUnsorted; |
| 116434 | } |
| 116435 | |
| 116436 | /* Check to see if pWLoop should be added to the set of |
| 116437 | ** mxChoice best-so-far paths. |
| 116438 | ** |
| 116439 | ** First look for an existing path among best-so-far paths |
| 116440 | ** that covers the same set of loops and has the same isOrdered |
| 116441 | ** setting as the current path candidate. |
| 116442 | ** |
| 116443 | ** The term "((pTo->isOrdered^isOrdered)&0x80)==0" is equivalent |
| 116444 | ** to (pTo->isOrdered==(-1))==(isOrdered==(-1))" for the range |
| 116445 | ** of legal values for isOrdered, -1..64. |
| 116446 | */ |
| 116447 | for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){ |
| 116448 | if( pTo->maskLoop==maskNew |
| 116449 | && ((pTo->isOrdered^isOrdered)&0x80)==0 |
| 116450 | ){ |
| 116451 | testcase( jj==nTo-1 ); |
| 116452 | break; |
| 116453 | } |
| 116454 | } |
| 116455 | if( jj>=nTo ){ |
| 116456 | /* None of the existing best-so-far paths match the candidate. */ |
| 116457 | if( nTo>=mxChoice |
| 116458 | && (rCost>mxCost || (rCost==mxCost && rUnsorted>=mxUnsorted)) |
| 116459 | ){ |
| 116460 | /* The current candidate is no better than any of the mxChoice |
| 116461 | ** paths currently in the best-so-far buffer. So discard |
| 116462 | ** this candidate as not viable. */ |
| 116463 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116464 | if( sqlite3WhereTrace&0x4 ){ |
| 116465 | sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n", |
| 116466 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| 116467 | isOrdered>=0 ? isOrdered+'0' : '?'); |
| 116468 | } |
| 116469 | #endif |
| 116470 | continue; |
| 116471 | } |
| 116472 | /* If we reach this points it means that the new candidate path |
| 116473 | ** needs to be added to the set of best-so-far paths. */ |
| 116474 | if( nTo<mxChoice ){ |
| 116475 | /* Increase the size of the aTo set by one */ |
| 116476 | jj = nTo++; |
| 116477 | }else{ |
| 116478 | /* New path replaces the prior worst to keep count below mxChoice */ |
| @@ -116442,11 +116485,15 @@ | |
| 116485 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| 116486 | isOrdered>=0 ? isOrdered+'0' : '?'); |
| 116487 | } |
| 116488 | #endif |
| 116489 | }else{ |
| 116490 | /* Control reaches here if best-so-far path pTo=aTo[jj] covers the |
| 116491 | ** same set of loops and has the sam isOrdered setting as the |
| 116492 | ** candidate path. Check to see if the candidate should replace |
| 116493 | ** pTo or if the candidate should be skipped */ |
| 116494 | if( pTo->rCost<rCost || (pTo->rCost==rCost && pTo->nRow<=nOut) ){ |
| 116495 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116496 | if( sqlite3WhereTrace&0x4 ){ |
| 116497 | sqlite3DebugPrintf( |
| 116498 | "Skip %s cost=%-3d,%3d order=%c", |
| 116499 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| @@ -116454,15 +116501,17 @@ | |
| 116501 | sqlite3DebugPrintf(" vs %s cost=%-3d,%d order=%c\n", |
| 116502 | wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow, |
| 116503 | pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?'); |
| 116504 | } |
| 116505 | #endif |
| 116506 | /* Discard the candidate path from further consideration */ |
| 116507 | testcase( pTo->rCost==rCost ); |
| 116508 | continue; |
| 116509 | } |
| 116510 | testcase( pTo->rCost==rCost+1 ); |
| 116511 | /* Control reaches here if the candidate path is better than the |
| 116512 | ** pTo path. Replace pTo with the candidate. */ |
| 116513 | #ifdef WHERETRACE_ENABLED /* 0x4 */ |
| 116514 | if( sqlite3WhereTrace&0x4 ){ |
| 116515 | sqlite3DebugPrintf( |
| 116516 | "Update %s cost=%-3d,%3d order=%c", |
| 116517 | wherePathName(pFrom, iLoop, pWLoop), rCost, nOut, |
| @@ -116476,19 +116525,24 @@ | |
| 116525 | /* pWLoop is a winner. Add it to the set of best so far */ |
| 116526 | pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf; |
| 116527 | pTo->revLoop = revMask; |
| 116528 | pTo->nRow = nOut; |
| 116529 | pTo->rCost = rCost; |
| 116530 | pTo->rUnsorted = rUnsorted; |
| 116531 | pTo->isOrdered = isOrdered; |
| 116532 | memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop); |
| 116533 | pTo->aLoop[iLoop] = pWLoop; |
| 116534 | if( nTo>=mxChoice ){ |
| 116535 | mxI = 0; |
| 116536 | mxCost = aTo[0].rCost; |
| 116537 | mxUnsorted = aTo[0].nRow; |
| 116538 | for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){ |
| 116539 | if( pTo->rCost>mxCost |
| 116540 | || (pTo->rCost==mxCost && pTo->rUnsorted>mxUnsorted) |
| 116541 | ){ |
| 116542 | mxCost = pTo->rCost; |
| 116543 | mxUnsorted = pTo->rUnsorted; |
| 116544 | mxI = jj; |
| 116545 | } |
| 116546 | } |
| 116547 | } |
| 116548 | } |
| @@ -123119,11 +123173,11 @@ | |
| 123173 | |
| 123174 | /* |
| 123175 | ** Return a static string containing the name corresponding to the error code |
| 123176 | ** specified in the argument. |
| 123177 | */ |
| 123178 | #if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST) |
| 123179 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 123180 | const char *zName = 0; |
| 123181 | int i, origRc = rc; |
| 123182 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 123183 | switch( rc ){ |
| @@ -123154,11 +123208,10 @@ | |
| 123208 | case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break; |
| 123209 | case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break; |
| 123210 | case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break; |
| 123211 | case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break; |
| 123212 | case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break; |
| 123213 | case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break; |
| 123214 | case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break; |
| 123215 | case SQLITE_IOERR_CHECKRESERVEDLOCK: |
| 123216 | zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break; |
| 123217 | case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break; |
| @@ -144218,11 +144271,11 @@ | |
| 144271 | ** the size of the range (always at least 1). In other words, the value |
| 144272 | ** ((C<<22) + N) represents a range of N codepoints starting with codepoint |
| 144273 | ** C. It is not possible to represent a range larger than 1023 codepoints |
| 144274 | ** using this format. |
| 144275 | */ |
| 144276 | static const unsigned int aEntry[] = { |
| 144277 | 0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07, |
| 144278 | 0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01, |
| 144279 | 0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401, |
| 144280 | 0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01, |
| 144281 | 0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01, |
| @@ -144310,11 +144363,11 @@ | |
| 144363 | |
| 144364 | if( c<128 ){ |
| 144365 | return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); |
| 144366 | }else if( c<(1<<22) ){ |
| 144367 | unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; |
| 144368 | int iRes = 0; |
| 144369 | int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; |
| 144370 | int iLo = 0; |
| 144371 | while( iHi>=iLo ){ |
| 144372 | int iTest = (iHi + iLo) / 2; |
| 144373 | if( key >= aEntry[iTest] ){ |
| @@ -144381,11 +144434,11 @@ | |
| 144434 | iHi = iTest-1; |
| 144435 | } |
| 144436 | } |
| 144437 | assert( key>=aDia[iRes] ); |
| 144438 | return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]); |
| 144439 | } |
| 144440 | |
| 144441 | |
| 144442 | /* |
| 144443 | ** Return true if the argument interpreted as a unicode codepoint |
| 144444 | ** is a diacritical modifier character. |
| 144445 |
+21
-43
| --- 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.8.6" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3008006 |
| 112 | -#define SQLITE_SOURCE_ID "2014-08-06 11:58:40 5c6bb57d90bad32785d6d9cdf110a825bbc5ec73" | |
| 112 | +#define SQLITE_SOURCE_ID "2014-08-11 13:53:30 de27c742c0dcda20b51339598bf6094a8dcf5fb9" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -267,11 +267,11 @@ | ||
| 267 | 267 | /* |
| 268 | 268 | ** CAPI3REF: Closing A Database Connection |
| 269 | 269 | ** |
| 270 | 270 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 271 | 271 | ** for the [sqlite3] object. |
| 272 | -** ^Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if | |
| 272 | +** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if | |
| 273 | 273 | ** the [sqlite3] object is successfully destroyed and all associated |
| 274 | 274 | ** resources are deallocated. |
| 275 | 275 | ** |
| 276 | 276 | ** ^If the database connection is associated with unfinalized prepared |
| 277 | 277 | ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| @@ -288,11 +288,11 @@ | ||
| 288 | 288 | ** [sqlite3_blob_close | close] all [BLOB handles], and |
| 289 | 289 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 290 | 290 | ** with the [sqlite3] object prior to attempting to close the object. ^If |
| 291 | 291 | ** sqlite3_close_v2() is called on a [database connection] that still has |
| 292 | 292 | ** outstanding [prepared statements], [BLOB handles], and/or |
| 293 | -** [sqlite3_backup] objects then it returns SQLITE_OK but the deallocation | |
| 293 | +** [sqlite3_backup] objects then it returns [SQLITE_OK] but the deallocation | |
| 294 | 294 | ** of resources is deferred until all [prepared statements], [BLOB handles], |
| 295 | 295 | ** and [sqlite3_backup] objects are also destroyed. |
| 296 | 296 | ** |
| 297 | 297 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 298 | 298 | ** the transaction is automatically rolled back. |
| @@ -384,20 +384,18 @@ | ||
| 384 | 384 | char **errmsg /* Error msg written here */ |
| 385 | 385 | ); |
| 386 | 386 | |
| 387 | 387 | /* |
| 388 | 388 | ** CAPI3REF: Result Codes |
| 389 | -** KEYWORDS: SQLITE_OK {error code} {error codes} | |
| 390 | -** KEYWORDS: {result code} {result codes} | |
| 389 | +** KEYWORDS: {result code definitions} | |
| 391 | 390 | ** |
| 392 | 391 | ** Many SQLite functions return an integer result code from the set shown |
| 393 | 392 | ** here in order to indicate success or failure. |
| 394 | 393 | ** |
| 395 | 394 | ** New error codes may be added in future versions of SQLite. |
| 396 | 395 | ** |
| 397 | -** See also: [SQLITE_IOERR_READ | extended result codes], | |
| 398 | -** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. | |
| 396 | +** See also: [extended result code definitions] | |
| 399 | 397 | */ |
| 400 | 398 | #define SQLITE_OK 0 /* Successful result */ |
| 401 | 399 | /* beginning-of-error-codes */ |
| 402 | 400 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 403 | 401 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -431,30 +429,23 @@ | ||
| 431 | 429 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
| 432 | 430 | /* end-of-error-codes */ |
| 433 | 431 | |
| 434 | 432 | /* |
| 435 | 433 | ** CAPI3REF: Extended Result Codes |
| 436 | -** KEYWORDS: {extended error code} {extended error codes} | |
| 437 | -** KEYWORDS: {extended result code} {extended result codes} | |
| 434 | +** KEYWORDS: {extended result code definitions} | |
| 438 | 435 | ** |
| 439 | -** In its default configuration, SQLite API routines return one of 26 integer | |
| 440 | -** [SQLITE_OK | result codes]. However, experience has shown that many of | |
| 436 | +** In its default configuration, SQLite API routines return one of 30 integer | |
| 437 | +** [result codes]. However, experience has shown that many of | |
| 441 | 438 | ** these result codes are too coarse-grained. They do not provide as |
| 442 | 439 | ** much information about problems as programmers might like. In an effort to |
| 443 | 440 | ** address this, newer versions of SQLite (version 3.3.8 and later) include |
| 444 | 441 | ** support for additional result codes that provide more detailed information |
| 445 | -** about errors. The extended result codes are enabled or disabled | |
| 442 | +** about errors. These [extended result codes] are enabled or disabled | |
| 446 | 443 | ** on a per database connection basis using the |
| 447 | -** [sqlite3_extended_result_codes()] API. | |
| 448 | -** | |
| 449 | -** Some of the available extended result codes are listed here. | |
| 450 | -** One may expect the number of extended result codes will increase | |
| 451 | -** over time. Software that uses extended result codes should expect | |
| 452 | -** to see new result codes in future releases of SQLite. | |
| 453 | -** | |
| 454 | -** The SQLITE_OK result code will never be extended. It will always | |
| 455 | -** be exactly zero. | |
| 444 | +** [sqlite3_extended_result_codes()] API. Or, the extended code for | |
| 445 | +** the most recent error can be obtained using | |
| 446 | +** [sqlite3_extended_errcode()]. | |
| 456 | 447 | */ |
| 457 | 448 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 458 | 449 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 459 | 450 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 460 | 451 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| @@ -683,11 +674,11 @@ | ||
| 683 | 674 | ** write return values. Potential uses for xFileControl() might be |
| 684 | 675 | ** functions to enable blocking locks with timeouts, to change the |
| 685 | 676 | ** locking strategy (for example to use dot-file locks), to inquire |
| 686 | 677 | ** about the status of a lock, or to break stale locks. The SQLite |
| 687 | 678 | ** core reserves all opcodes less than 100 for its own use. |
| 688 | -** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. | |
| 679 | +** A [file control opcodes | list of opcodes] less than 100 is available. | |
| 689 | 680 | ** Applications that define a custom xFileControl method should use opcodes |
| 690 | 681 | ** greater than 100 to avoid conflicts. VFS implementations should |
| 691 | 682 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
| 692 | 683 | ** recognize. |
| 693 | 684 | ** |
| @@ -756,10 +747,11 @@ | ||
| 756 | 747 | /* Additional methods may be added in future releases */ |
| 757 | 748 | }; |
| 758 | 749 | |
| 759 | 750 | /* |
| 760 | 751 | ** CAPI3REF: Standard File Control Opcodes |
| 752 | +** KEYWORDS: {file control opcodes} {file control opcode} | |
| 761 | 753 | ** |
| 762 | 754 | ** These integer constants are opcodes for the xFileControl method |
| 763 | 755 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
| 764 | 756 | ** interface. |
| 765 | 757 | ** |
| @@ -2043,28 +2035,28 @@ | ||
| 2043 | 2035 | ** [database connection] D when another thread |
| 2044 | 2036 | ** or process has the table locked. |
| 2045 | 2037 | ** The sqlite3_busy_handler() interface is used to implement |
| 2046 | 2038 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
| 2047 | 2039 | ** |
| 2048 | -** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] | |
| 2040 | +** ^If the busy callback is NULL, then [SQLITE_BUSY] | |
| 2049 | 2041 | ** is returned immediately upon encountering the lock. ^If the busy callback |
| 2050 | 2042 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2051 | 2043 | ** |
| 2052 | 2044 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2053 | 2045 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2054 | 2046 | ** the busy handler callback is the number of times that the busy handler has |
| 2055 | 2047 | ** been invoked for the same locking event. ^If the |
| 2056 | 2048 | ** busy callback returns 0, then no additional attempts are made to |
| 2057 | -** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned | |
| 2049 | +** access the database and [SQLITE_BUSY] is returned | |
| 2058 | 2050 | ** to the application. |
| 2059 | 2051 | ** ^If the callback returns non-zero, then another attempt |
| 2060 | 2052 | ** is made to access the database and the cycle repeats. |
| 2061 | 2053 | ** |
| 2062 | 2054 | ** The presence of a busy handler does not guarantee that it will be invoked |
| 2063 | 2055 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
| 2064 | 2056 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
| 2065 | -** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the | |
| 2057 | +** to the application instead of invoking the | |
| 2066 | 2058 | ** busy handler. |
| 2067 | 2059 | ** Consider a scenario where one process is holding a read lock that |
| 2068 | 2060 | ** it is trying to promote to a reserved lock and |
| 2069 | 2061 | ** a second process is holding a reserved lock that it is trying |
| 2070 | 2062 | ** to promote to an exclusive lock. The first process cannot proceed |
| @@ -2075,25 +2067,10 @@ | ||
| 2075 | 2067 | ** will induce the first process to release its read lock and allow |
| 2076 | 2068 | ** the second process to proceed. |
| 2077 | 2069 | ** |
| 2078 | 2070 | ** ^The default busy callback is NULL. |
| 2079 | 2071 | ** |
| 2080 | -** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] | |
| 2081 | -** when SQLite is in the middle of a large transaction where all the | |
| 2082 | -** changes will not fit into the in-memory cache. SQLite will | |
| 2083 | -** already hold a RESERVED lock on the database file, but it needs | |
| 2084 | -** to promote this lock to EXCLUSIVE so that it can spill cache | |
| 2085 | -** pages into the database file without harm to concurrent | |
| 2086 | -** readers. ^If it is unable to promote the lock, then the in-memory | |
| 2087 | -** cache will be left in an inconsistent state and so the error | |
| 2088 | -** code is promoted from the relatively benign [SQLITE_BUSY] to | |
| 2089 | -** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion | |
| 2090 | -** forces an automatic rollback of the changes. See the | |
| 2091 | -** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> | |
| 2092 | -** CorruptionFollowingBusyError</a> wiki page for a discussion of why | |
| 2093 | -** this is important. | |
| 2094 | -** | |
| 2095 | 2072 | ** ^(There can only be a single busy handler defined for each |
| 2096 | 2073 | ** [database connection]. Setting a new busy handler clears any |
| 2097 | 2074 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
| 2098 | 2075 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
| 2099 | 2076 | ** busy handler and thus clear any previously set busy handler. |
| @@ -2114,11 +2091,11 @@ | ||
| 2114 | 2091 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2115 | 2092 | ** for a specified amount of time when a table is locked. ^The handler |
| 2116 | 2093 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2117 | 2094 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| 2118 | 2095 | ** the handler returns 0 which causes [sqlite3_step()] to return |
| 2119 | -** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. | |
| 2096 | +** [SQLITE_BUSY]. | |
| 2120 | 2097 | ** |
| 2121 | 2098 | ** ^Calling this routine with an argument less than or equal to zero |
| 2122 | 2099 | ** turns off all busy handlers. |
| 2123 | 2100 | ** |
| 2124 | 2101 | ** ^(There can only be a single busy handler for a particular |
| @@ -2526,12 +2503,12 @@ | ||
| 2526 | 2503 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2527 | 2504 | ** to signal SQLite whether or not the action is permitted. See the |
| 2528 | 2505 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2529 | 2506 | ** information. |
| 2530 | 2507 | ** |
| 2531 | -** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] | |
| 2532 | -** from the [sqlite3_vtab_on_conflict()] interface. | |
| 2508 | +** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] | |
| 2509 | +** returned from the [sqlite3_vtab_on_conflict()] interface. | |
| 2533 | 2510 | */ |
| 2534 | 2511 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2535 | 2512 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2536 | 2513 | |
| 2537 | 2514 | /* |
| @@ -7367,10 +7344,11 @@ | ||
| 7367 | 7344 | */ |
| 7368 | 7345 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7369 | 7346 | |
| 7370 | 7347 | /* |
| 7371 | 7348 | ** CAPI3REF: Conflict resolution modes |
| 7349 | +** KEYWORDS: {conflict resolution mode} | |
| 7372 | 7350 | ** |
| 7373 | 7351 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 7374 | 7352 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 7375 | 7353 | ** is for the SQL statement being evaluated. |
| 7376 | 7354 | ** |
| 7377 | 7355 |
| --- 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.8.6" |
| 111 | #define SQLITE_VERSION_NUMBER 3008006 |
| 112 | #define SQLITE_SOURCE_ID "2014-08-06 11:58:40 5c6bb57d90bad32785d6d9cdf110a825bbc5ec73" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -267,11 +267,11 @@ | |
| 267 | /* |
| 268 | ** CAPI3REF: Closing A Database Connection |
| 269 | ** |
| 270 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 271 | ** for the [sqlite3] object. |
| 272 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if |
| 273 | ** the [sqlite3] object is successfully destroyed and all associated |
| 274 | ** resources are deallocated. |
| 275 | ** |
| 276 | ** ^If the database connection is associated with unfinalized prepared |
| 277 | ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| @@ -288,11 +288,11 @@ | |
| 288 | ** [sqlite3_blob_close | close] all [BLOB handles], and |
| 289 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 290 | ** with the [sqlite3] object prior to attempting to close the object. ^If |
| 291 | ** sqlite3_close_v2() is called on a [database connection] that still has |
| 292 | ** outstanding [prepared statements], [BLOB handles], and/or |
| 293 | ** [sqlite3_backup] objects then it returns SQLITE_OK but the deallocation |
| 294 | ** of resources is deferred until all [prepared statements], [BLOB handles], |
| 295 | ** and [sqlite3_backup] objects are also destroyed. |
| 296 | ** |
| 297 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 298 | ** the transaction is automatically rolled back. |
| @@ -384,20 +384,18 @@ | |
| 384 | char **errmsg /* Error msg written here */ |
| 385 | ); |
| 386 | |
| 387 | /* |
| 388 | ** CAPI3REF: Result Codes |
| 389 | ** KEYWORDS: SQLITE_OK {error code} {error codes} |
| 390 | ** KEYWORDS: {result code} {result codes} |
| 391 | ** |
| 392 | ** Many SQLite functions return an integer result code from the set shown |
| 393 | ** here in order to indicate success or failure. |
| 394 | ** |
| 395 | ** New error codes may be added in future versions of SQLite. |
| 396 | ** |
| 397 | ** See also: [SQLITE_IOERR_READ | extended result codes], |
| 398 | ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. |
| 399 | */ |
| 400 | #define SQLITE_OK 0 /* Successful result */ |
| 401 | /* beginning-of-error-codes */ |
| 402 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 403 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -431,30 +429,23 @@ | |
| 431 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
| 432 | /* end-of-error-codes */ |
| 433 | |
| 434 | /* |
| 435 | ** CAPI3REF: Extended Result Codes |
| 436 | ** KEYWORDS: {extended error code} {extended error codes} |
| 437 | ** KEYWORDS: {extended result code} {extended result codes} |
| 438 | ** |
| 439 | ** In its default configuration, SQLite API routines return one of 26 integer |
| 440 | ** [SQLITE_OK | result codes]. However, experience has shown that many of |
| 441 | ** these result codes are too coarse-grained. They do not provide as |
| 442 | ** much information about problems as programmers might like. In an effort to |
| 443 | ** address this, newer versions of SQLite (version 3.3.8 and later) include |
| 444 | ** support for additional result codes that provide more detailed information |
| 445 | ** about errors. The extended result codes are enabled or disabled |
| 446 | ** on a per database connection basis using the |
| 447 | ** [sqlite3_extended_result_codes()] API. |
| 448 | ** |
| 449 | ** Some of the available extended result codes are listed here. |
| 450 | ** One may expect the number of extended result codes will increase |
| 451 | ** over time. Software that uses extended result codes should expect |
| 452 | ** to see new result codes in future releases of SQLite. |
| 453 | ** |
| 454 | ** The SQLITE_OK result code will never be extended. It will always |
| 455 | ** be exactly zero. |
| 456 | */ |
| 457 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 458 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 459 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 460 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| @@ -683,11 +674,11 @@ | |
| 683 | ** write return values. Potential uses for xFileControl() might be |
| 684 | ** functions to enable blocking locks with timeouts, to change the |
| 685 | ** locking strategy (for example to use dot-file locks), to inquire |
| 686 | ** about the status of a lock, or to break stale locks. The SQLite |
| 687 | ** core reserves all opcodes less than 100 for its own use. |
| 688 | ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. |
| 689 | ** Applications that define a custom xFileControl method should use opcodes |
| 690 | ** greater than 100 to avoid conflicts. VFS implementations should |
| 691 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
| 692 | ** recognize. |
| 693 | ** |
| @@ -756,10 +747,11 @@ | |
| 756 | /* Additional methods may be added in future releases */ |
| 757 | }; |
| 758 | |
| 759 | /* |
| 760 | ** CAPI3REF: Standard File Control Opcodes |
| 761 | ** |
| 762 | ** These integer constants are opcodes for the xFileControl method |
| 763 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
| 764 | ** interface. |
| 765 | ** |
| @@ -2043,28 +2035,28 @@ | |
| 2043 | ** [database connection] D when another thread |
| 2044 | ** or process has the table locked. |
| 2045 | ** The sqlite3_busy_handler() interface is used to implement |
| 2046 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
| 2047 | ** |
| 2048 | ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] |
| 2049 | ** is returned immediately upon encountering the lock. ^If the busy callback |
| 2050 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2051 | ** |
| 2052 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2053 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2054 | ** the busy handler callback is the number of times that the busy handler has |
| 2055 | ** been invoked for the same locking event. ^If the |
| 2056 | ** busy callback returns 0, then no additional attempts are made to |
| 2057 | ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned |
| 2058 | ** to the application. |
| 2059 | ** ^If the callback returns non-zero, then another attempt |
| 2060 | ** is made to access the database and the cycle repeats. |
| 2061 | ** |
| 2062 | ** The presence of a busy handler does not guarantee that it will be invoked |
| 2063 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
| 2064 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
| 2065 | ** or [SQLITE_IOERR_BLOCKED] to the application instead of invoking the |
| 2066 | ** busy handler. |
| 2067 | ** Consider a scenario where one process is holding a read lock that |
| 2068 | ** it is trying to promote to a reserved lock and |
| 2069 | ** a second process is holding a reserved lock that it is trying |
| 2070 | ** to promote to an exclusive lock. The first process cannot proceed |
| @@ -2075,25 +2067,10 @@ | |
| 2075 | ** will induce the first process to release its read lock and allow |
| 2076 | ** the second process to proceed. |
| 2077 | ** |
| 2078 | ** ^The default busy callback is NULL. |
| 2079 | ** |
| 2080 | ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] |
| 2081 | ** when SQLite is in the middle of a large transaction where all the |
| 2082 | ** changes will not fit into the in-memory cache. SQLite will |
| 2083 | ** already hold a RESERVED lock on the database file, but it needs |
| 2084 | ** to promote this lock to EXCLUSIVE so that it can spill cache |
| 2085 | ** pages into the database file without harm to concurrent |
| 2086 | ** readers. ^If it is unable to promote the lock, then the in-memory |
| 2087 | ** cache will be left in an inconsistent state and so the error |
| 2088 | ** code is promoted from the relatively benign [SQLITE_BUSY] to |
| 2089 | ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion |
| 2090 | ** forces an automatic rollback of the changes. See the |
| 2091 | ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> |
| 2092 | ** CorruptionFollowingBusyError</a> wiki page for a discussion of why |
| 2093 | ** this is important. |
| 2094 | ** |
| 2095 | ** ^(There can only be a single busy handler defined for each |
| 2096 | ** [database connection]. Setting a new busy handler clears any |
| 2097 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
| 2098 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
| 2099 | ** busy handler and thus clear any previously set busy handler. |
| @@ -2114,11 +2091,11 @@ | |
| 2114 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2115 | ** for a specified amount of time when a table is locked. ^The handler |
| 2116 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2117 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| 2118 | ** the handler returns 0 which causes [sqlite3_step()] to return |
| 2119 | ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. |
| 2120 | ** |
| 2121 | ** ^Calling this routine with an argument less than or equal to zero |
| 2122 | ** turns off all busy handlers. |
| 2123 | ** |
| 2124 | ** ^(There can only be a single busy handler for a particular |
| @@ -2526,12 +2503,12 @@ | |
| 2526 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2527 | ** to signal SQLite whether or not the action is permitted. See the |
| 2528 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2529 | ** information. |
| 2530 | ** |
| 2531 | ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] |
| 2532 | ** from the [sqlite3_vtab_on_conflict()] interface. |
| 2533 | */ |
| 2534 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2535 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2536 | |
| 2537 | /* |
| @@ -7367,10 +7344,11 @@ | |
| 7367 | */ |
| 7368 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7369 | |
| 7370 | /* |
| 7371 | ** CAPI3REF: Conflict resolution modes |
| 7372 | ** |
| 7373 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 7374 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 7375 | ** is for the SQL statement being evaluated. |
| 7376 | ** |
| 7377 |
| --- 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.8.6" |
| 111 | #define SQLITE_VERSION_NUMBER 3008006 |
| 112 | #define SQLITE_SOURCE_ID "2014-08-11 13:53:30 de27c742c0dcda20b51339598bf6094a8dcf5fb9" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -267,11 +267,11 @@ | |
| 267 | /* |
| 268 | ** CAPI3REF: Closing A Database Connection |
| 269 | ** |
| 270 | ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors |
| 271 | ** for the [sqlite3] object. |
| 272 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 273 | ** the [sqlite3] object is successfully destroyed and all associated |
| 274 | ** resources are deallocated. |
| 275 | ** |
| 276 | ** ^If the database connection is associated with unfinalized prepared |
| 277 | ** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| @@ -288,11 +288,11 @@ | |
| 288 | ** [sqlite3_blob_close | close] all [BLOB handles], and |
| 289 | ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 290 | ** with the [sqlite3] object prior to attempting to close the object. ^If |
| 291 | ** sqlite3_close_v2() is called on a [database connection] that still has |
| 292 | ** outstanding [prepared statements], [BLOB handles], and/or |
| 293 | ** [sqlite3_backup] objects then it returns [SQLITE_OK] but the deallocation |
| 294 | ** of resources is deferred until all [prepared statements], [BLOB handles], |
| 295 | ** and [sqlite3_backup] objects are also destroyed. |
| 296 | ** |
| 297 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 298 | ** the transaction is automatically rolled back. |
| @@ -384,20 +384,18 @@ | |
| 384 | char **errmsg /* Error msg written here */ |
| 385 | ); |
| 386 | |
| 387 | /* |
| 388 | ** CAPI3REF: Result Codes |
| 389 | ** KEYWORDS: {result code definitions} |
| 390 | ** |
| 391 | ** Many SQLite functions return an integer result code from the set shown |
| 392 | ** here in order to indicate success or failure. |
| 393 | ** |
| 394 | ** New error codes may be added in future versions of SQLite. |
| 395 | ** |
| 396 | ** See also: [extended result code definitions] |
| 397 | */ |
| 398 | #define SQLITE_OK 0 /* Successful result */ |
| 399 | /* beginning-of-error-codes */ |
| 400 | #define SQLITE_ERROR 1 /* SQL error or missing database */ |
| 401 | #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ |
| @@ -431,30 +429,23 @@ | |
| 429 | #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ |
| 430 | /* end-of-error-codes */ |
| 431 | |
| 432 | /* |
| 433 | ** CAPI3REF: Extended Result Codes |
| 434 | ** KEYWORDS: {extended result code definitions} |
| 435 | ** |
| 436 | ** In its default configuration, SQLite API routines return one of 30 integer |
| 437 | ** [result codes]. However, experience has shown that many of |
| 438 | ** these result codes are too coarse-grained. They do not provide as |
| 439 | ** much information about problems as programmers might like. In an effort to |
| 440 | ** address this, newer versions of SQLite (version 3.3.8 and later) include |
| 441 | ** support for additional result codes that provide more detailed information |
| 442 | ** about errors. These [extended result codes] are enabled or disabled |
| 443 | ** on a per database connection basis using the |
| 444 | ** [sqlite3_extended_result_codes()] API. Or, the extended code for |
| 445 | ** the most recent error can be obtained using |
| 446 | ** [sqlite3_extended_errcode()]. |
| 447 | */ |
| 448 | #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) |
| 449 | #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) |
| 450 | #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) |
| 451 | #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) |
| @@ -683,11 +674,11 @@ | |
| 674 | ** write return values. Potential uses for xFileControl() might be |
| 675 | ** functions to enable blocking locks with timeouts, to change the |
| 676 | ** locking strategy (for example to use dot-file locks), to inquire |
| 677 | ** about the status of a lock, or to break stale locks. The SQLite |
| 678 | ** core reserves all opcodes less than 100 for its own use. |
| 679 | ** A [file control opcodes | list of opcodes] less than 100 is available. |
| 680 | ** Applications that define a custom xFileControl method should use opcodes |
| 681 | ** greater than 100 to avoid conflicts. VFS implementations should |
| 682 | ** return [SQLITE_NOTFOUND] for file control opcodes that they do not |
| 683 | ** recognize. |
| 684 | ** |
| @@ -756,10 +747,11 @@ | |
| 747 | /* Additional methods may be added in future releases */ |
| 748 | }; |
| 749 | |
| 750 | /* |
| 751 | ** CAPI3REF: Standard File Control Opcodes |
| 752 | ** KEYWORDS: {file control opcodes} {file control opcode} |
| 753 | ** |
| 754 | ** These integer constants are opcodes for the xFileControl method |
| 755 | ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] |
| 756 | ** interface. |
| 757 | ** |
| @@ -2043,28 +2035,28 @@ | |
| 2035 | ** [database connection] D when another thread |
| 2036 | ** or process has the table locked. |
| 2037 | ** The sqlite3_busy_handler() interface is used to implement |
| 2038 | ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout]. |
| 2039 | ** |
| 2040 | ** ^If the busy callback is NULL, then [SQLITE_BUSY] |
| 2041 | ** is returned immediately upon encountering the lock. ^If the busy callback |
| 2042 | ** is not NULL, then the callback might be invoked with two arguments. |
| 2043 | ** |
| 2044 | ** ^The first argument to the busy handler is a copy of the void* pointer which |
| 2045 | ** is the third argument to sqlite3_busy_handler(). ^The second argument to |
| 2046 | ** the busy handler callback is the number of times that the busy handler has |
| 2047 | ** been invoked for the same locking event. ^If the |
| 2048 | ** busy callback returns 0, then no additional attempts are made to |
| 2049 | ** access the database and [SQLITE_BUSY] is returned |
| 2050 | ** to the application. |
| 2051 | ** ^If the callback returns non-zero, then another attempt |
| 2052 | ** is made to access the database and the cycle repeats. |
| 2053 | ** |
| 2054 | ** The presence of a busy handler does not guarantee that it will be invoked |
| 2055 | ** when there is lock contention. ^If SQLite determines that invoking the busy |
| 2056 | ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] |
| 2057 | ** to the application instead of invoking the |
| 2058 | ** busy handler. |
| 2059 | ** Consider a scenario where one process is holding a read lock that |
| 2060 | ** it is trying to promote to a reserved lock and |
| 2061 | ** a second process is holding a reserved lock that it is trying |
| 2062 | ** to promote to an exclusive lock. The first process cannot proceed |
| @@ -2075,25 +2067,10 @@ | |
| 2067 | ** will induce the first process to release its read lock and allow |
| 2068 | ** the second process to proceed. |
| 2069 | ** |
| 2070 | ** ^The default busy callback is NULL. |
| 2071 | ** |
| 2072 | ** ^(There can only be a single busy handler defined for each |
| 2073 | ** [database connection]. Setting a new busy handler clears any |
| 2074 | ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] |
| 2075 | ** or evaluating [PRAGMA busy_timeout=N] will change the |
| 2076 | ** busy handler and thus clear any previously set busy handler. |
| @@ -2114,11 +2091,11 @@ | |
| 2091 | ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps |
| 2092 | ** for a specified amount of time when a table is locked. ^The handler |
| 2093 | ** will sleep multiple times until at least "ms" milliseconds of sleeping |
| 2094 | ** have accumulated. ^After at least "ms" milliseconds of sleeping, |
| 2095 | ** the handler returns 0 which causes [sqlite3_step()] to return |
| 2096 | ** [SQLITE_BUSY]. |
| 2097 | ** |
| 2098 | ** ^Calling this routine with an argument less than or equal to zero |
| 2099 | ** turns off all busy handlers. |
| 2100 | ** |
| 2101 | ** ^(There can only be a single busy handler for a particular |
| @@ -2526,12 +2503,12 @@ | |
| 2503 | ** return either [SQLITE_OK] or one of these two constants in order |
| 2504 | ** to signal SQLite whether or not the action is permitted. See the |
| 2505 | ** [sqlite3_set_authorizer | authorizer documentation] for additional |
| 2506 | ** information. |
| 2507 | ** |
| 2508 | ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode] |
| 2509 | ** returned from the [sqlite3_vtab_on_conflict()] interface. |
| 2510 | */ |
| 2511 | #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ |
| 2512 | #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ |
| 2513 | |
| 2514 | /* |
| @@ -7367,10 +7344,11 @@ | |
| 7344 | */ |
| 7345 | SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); |
| 7346 | |
| 7347 | /* |
| 7348 | ** CAPI3REF: Conflict resolution modes |
| 7349 | ** KEYWORDS: {conflict resolution mode} |
| 7350 | ** |
| 7351 | ** These constants are returned by [sqlite3_vtab_on_conflict()] to |
| 7352 | ** inform a [virtual table] implementation what the [ON CONFLICT] mode |
| 7353 | ** is for the SQL statement being evaluated. |
| 7354 | ** |
| 7355 |