Fossil SCM

Update the built-in SQLite to 3.8.6 beta2.

drh 2014-08-11 13:57 trunk
Commit 981e853f6c95923a38c2163d2e09e4a4d3fd853a
2 files changed +179 -126 +21 -43
+179 -126
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -222,11 +222,11 @@
222222
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
223223
** [sqlite_version()] and [sqlite_source_id()].
224224
*/
225225
#define SQLITE_VERSION "3.8.6"
226226
#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"
228228
229229
/*
230230
** CAPI3REF: Run-Time Library Version Numbers
231231
** KEYWORDS: sqlite3_version, sqlite3_sourceid
232232
**
@@ -382,11 +382,11 @@
382382
/*
383383
** CAPI3REF: Closing A Database Connection
384384
**
385385
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
386386
** 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
388388
** the [sqlite3] object is successfully destroyed and all associated
389389
** resources are deallocated.
390390
**
391391
** ^If the database connection is associated with unfinalized prepared
392392
** statements or unfinished sqlite3_backup objects then sqlite3_close()
@@ -403,11 +403,11 @@
403403
** [sqlite3_blob_close | close] all [BLOB handles], and
404404
** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
405405
** with the [sqlite3] object prior to attempting to close the object. ^If
406406
** sqlite3_close_v2() is called on a [database connection] that still has
407407
** 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
409409
** of resources is deferred until all [prepared statements], [BLOB handles],
410410
** and [sqlite3_backup] objects are also destroyed.
411411
**
412412
** ^If an [sqlite3] object is destroyed while a transaction is open,
413413
** the transaction is automatically rolled back.
@@ -499,20 +499,18 @@
499499
char **errmsg /* Error msg written here */
500500
);
501501
502502
/*
503503
** CAPI3REF: Result Codes
504
-** KEYWORDS: SQLITE_OK {error code} {error codes}
505
-** KEYWORDS: {result code} {result codes}
504
+** KEYWORDS: {result code definitions}
506505
**
507506
** Many SQLite functions return an integer result code from the set shown
508507
** here in order to indicate success or failure.
509508
**
510509
** New error codes may be added in future versions of SQLite.
511510
**
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]
514512
*/
515513
#define SQLITE_OK 0 /* Successful result */
516514
/* beginning-of-error-codes */
517515
#define SQLITE_ERROR 1 /* SQL error or missing database */
518516
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -546,30 +544,23 @@
546544
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
547545
/* end-of-error-codes */
548546
549547
/*
550548
** 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}
553550
**
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
556553
** these result codes are too coarse-grained. They do not provide as
557554
** much information about problems as programmers might like. In an effort to
558555
** address this, newer versions of SQLite (version 3.3.8 and later) include
559556
** 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
561558
** 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()].
571562
*/
572563
#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
573564
#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
574565
#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
575566
#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
@@ -798,11 +789,11 @@
798789
** write return values. Potential uses for xFileControl() might be
799790
** functions to enable blocking locks with timeouts, to change the
800791
** locking strategy (for example to use dot-file locks), to inquire
801792
** about the status of a lock, or to break stale locks. The SQLite
802793
** 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.
804795
** Applications that define a custom xFileControl method should use opcodes
805796
** greater than 100 to avoid conflicts. VFS implementations should
806797
** return [SQLITE_NOTFOUND] for file control opcodes that they do not
807798
** recognize.
808799
**
@@ -871,10 +862,11 @@
871862
/* Additional methods may be added in future releases */
872863
};
873864
874865
/*
875866
** CAPI3REF: Standard File Control Opcodes
867
+** KEYWORDS: {file control opcodes} {file control opcode}
876868
**
877869
** These integer constants are opcodes for the xFileControl method
878870
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
879871
** interface.
880872
**
@@ -2158,28 +2150,28 @@
21582150
** [database connection] D when another thread
21592151
** or process has the table locked.
21602152
** The sqlite3_busy_handler() interface is used to implement
21612153
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
21622154
**
2163
-** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2155
+** ^If the busy callback is NULL, then [SQLITE_BUSY]
21642156
** is returned immediately upon encountering the lock. ^If the busy callback
21652157
** is not NULL, then the callback might be invoked with two arguments.
21662158
**
21672159
** ^The first argument to the busy handler is a copy of the void* pointer which
21682160
** is the third argument to sqlite3_busy_handler(). ^The second argument to
21692161
** the busy handler callback is the number of times that the busy handler has
21702162
** been invoked for the same locking event. ^If the
21712163
** 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
21732165
** to the application.
21742166
** ^If the callback returns non-zero, then another attempt
21752167
** is made to access the database and the cycle repeats.
21762168
**
21772169
** The presence of a busy handler does not guarantee that it will be invoked
21782170
** when there is lock contention. ^If SQLite determines that invoking the busy
21792171
** 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
21812173
** busy handler.
21822174
** Consider a scenario where one process is holding a read lock that
21832175
** it is trying to promote to a reserved lock and
21842176
** a second process is holding a reserved lock that it is trying
21852177
** to promote to an exclusive lock. The first process cannot proceed
@@ -2190,25 +2182,10 @@
21902182
** will induce the first process to release its read lock and allow
21912183
** the second process to proceed.
21922184
**
21932185
** ^The default busy callback is NULL.
21942186
**
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
-**
22102187
** ^(There can only be a single busy handler defined for each
22112188
** [database connection]. Setting a new busy handler clears any
22122189
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
22132190
** or evaluating [PRAGMA busy_timeout=N] will change the
22142191
** busy handler and thus clear any previously set busy handler.
@@ -2229,11 +2206,11 @@
22292206
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
22302207
** for a specified amount of time when a table is locked. ^The handler
22312208
** will sleep multiple times until at least "ms" milliseconds of sleeping
22322209
** have accumulated. ^After at least "ms" milliseconds of sleeping,
22332210
** the handler returns 0 which causes [sqlite3_step()] to return
2234
-** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
2211
+** [SQLITE_BUSY].
22352212
**
22362213
** ^Calling this routine with an argument less than or equal to zero
22372214
** turns off all busy handlers.
22382215
**
22392216
** ^(There can only be a single busy handler for a particular
@@ -2641,12 +2618,12 @@
26412618
** return either [SQLITE_OK] or one of these two constants in order
26422619
** to signal SQLite whether or not the action is permitted. See the
26432620
** [sqlite3_set_authorizer | authorizer documentation] for additional
26442621
** information.
26452622
**
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.
26482625
*/
26492626
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
26502627
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
26512628
26522629
/*
@@ -7482,10 +7459,11 @@
74827459
*/
74837460
SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
74847461
74857462
/*
74867463
** CAPI3REF: Conflict resolution modes
7464
+** KEYWORDS: {conflict resolution mode}
74877465
**
74887466
** These constants are returned by [sqlite3_vtab_on_conflict()] to
74897467
** inform a [virtual table] implementation what the [ON CONFLICT] mode
74907468
** is for the SQL statement being evaluated.
74917469
**
@@ -24177,15 +24155,14 @@
2417724155
#include <unistd.h>
2417824156
/* #include <time.h> */
2417924157
#include <sys/time.h>
2418024158
#include <errno.h>
2418124159
#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
24182
-#include <sys/mman.h>
24160
+# include <sys/mman.h>
2418324161
#endif
2418424162
24185
-
24186
-#if SQLITE_ENABLE_LOCKING_STYLE
24163
+#if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS
2418724164
# include <sys/ioctl.h>
2418824165
# if OS_VXWORKS
2418924166
# include <semaphore.h>
2419024167
# include <limits.h>
2419124168
# else
@@ -24609,11 +24586,15 @@
2460924586
** On some systems, calls to fchown() will trigger a message in a security
2461024587
** log if they come from non-root processes. So avoid calling fchown() if
2461124588
** we are not running as root.
2461224589
*/
2461324590
static int posixFchown(int fd, uid_t uid, gid_t gid){
24591
+#if OS_VXWORKS
24592
+ return 0;
24593
+#else
2461424594
return geteuid() ? 0 : fchown(fd,uid,gid);
24595
+#endif
2461524596
}
2461624597
2461724598
/* Forward reference */
2461824599
static int openDirectory(const char*, int*);
2461924600
static int unixGetpagesize(void);
@@ -24665,11 +24646,11 @@
2466524646
#define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
2466624647
2466724648
{ "read", (sqlite3_syscall_ptr)read, 0 },
2466824649
#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
2466924650
24670
-#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
24651
+#if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
2467124652
{ "pread", (sqlite3_syscall_ptr)pread, 0 },
2467224653
#else
2467324654
{ "pread", (sqlite3_syscall_ptr)0, 0 },
2467424655
#endif
2467524656
#define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
@@ -24682,11 +24663,11 @@
2468224663
#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
2468324664
2468424665
{ "write", (sqlite3_syscall_ptr)write, 0 },
2468524666
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
2468624667
24687
-#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
24668
+#if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
2468824669
{ "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
2468924670
#else
2469024671
{ "pwrite", (sqlite3_syscall_ptr)0, 0 },
2469124672
#endif
2469224673
#define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
@@ -25052,20 +25033,10 @@
2505225033
}
2505325034
/* else fall through */
2505425035
case EPERM:
2505525036
return SQLITE_PERM;
2505625037
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
-
2506725038
#if EOPNOTSUPP!=ENOTSUP
2506825039
case EOPNOTSUPP:
2506925040
/* something went terribly awry, unless during file system support
2507025041
* introspection, in which it actually means what it says */
2507125042
#endif
@@ -25596,11 +25567,15 @@
2559625567
** Return TRUE if pFile has been renamed or unlinked since it was first opened.
2559725568
*/
2559825569
static int fileHasMoved(unixFile *pFile){
2559925570
struct stat buf;
2560025571
return pFile->pInode!=0 &&
25572
+#if OS_VXWORKS
25573
+ pFile->pId!=pFile->pInode->fileId.Pid;
25574
+#else
2560125575
(osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino);
25576
+#endif
2560225577
}
2560325578
2560425579
2560525580
/*
2560625581
** Check a unixFile that is a database. Verify the following:
@@ -26739,11 +26714,10 @@
2673926714
}
2674026715
2674126716
/* Otherwise see if some other process holds it. */
2674226717
if( !reserved ){
2674326718
sem_t *pSem = pFile->pInode->pSem;
26744
- struct stat statBuf;
2674526719
2674626720
if( sem_trywait(pSem)==-1 ){
2674726721
int tErrno = errno;
2674826722
if( EAGAIN != tErrno ){
2674926723
rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_CHECKRESERVEDLOCK);
@@ -26792,11 +26766,10 @@
2679226766
** This routine will only increase a lock. Use the sqlite3OsUnlock()
2679326767
** routine to lower a locking level.
2679426768
*/
2679526769
static int semLock(sqlite3_file *id, int eFileLock) {
2679626770
unixFile *pFile = (unixFile*)id;
26797
- int fd;
2679826771
sem_t *pSem = pFile->pInode->pSem;
2679926772
int rc = SQLITE_OK;
2680026773
2680126774
/* if we already have a lock, it is exclusive.
2680226775
** Just adjust level and punt on outta here. */
@@ -64521,11 +64494,10 @@
6452164494
/* Lock all btrees used by the statement */
6452264495
sqlite3VdbeEnter(p);
6452364496
6452464497
/* Check for one of the special errors */
6452564498
mrc = p->rc & 0xff;
64526
- assert( p->rc!=SQLITE_IOERR_BLOCKED ); /* This error no longer exists */
6452764499
isSpecialError = mrc==SQLITE_NOMEM || mrc==SQLITE_IOERR
6452864500
|| mrc==SQLITE_INTERRUPT || mrc==SQLITE_FULL;
6452964501
if( isSpecialError ){
6453064502
/* If the query was read-only and the error code is SQLITE_INTERRUPT,
6453164503
** no rollback is necessary. Otherwise, at least a savepoint
@@ -71247,11 +71219,11 @@
7124771219
VdbeCursor *pCur;
7124871220
7124971221
assert( pOp->p5==0 );
7125071222
assert( pOp->p4type==P4_KEYINFO );
7125171223
pCur = p->apCsr[pOp->p1];
71252
- if( pCur && pCur->pgnoRoot==pOp->p2 ){
71224
+ if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
7125371225
assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
7125471226
break;
7125571227
}
7125671228
/* If the cursor is not currently open or is open on a different
7125771229
** index, then fall through into OP_OpenRead to force a reopen */
@@ -77111,11 +77083,11 @@
7711177083
}
7711277084
break;
7711377085
}
7711477086
}
7711577087
if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
77116
- /* IMP: R-24309-18625 */
77088
+ /* IMP: R-51414-32910 */
7711777089
/* IMP: R-44911-55124 */
7711877090
iCol = -1;
7711977091
}
7712077092
if( iCol<pTab->nCol ){
7712177093
cnt++;
@@ -110616,10 +110588,11 @@
110616110588
struct WherePath {
110617110589
Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
110618110590
Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
110619110591
LogEst nRow; /* Estimated number of rows generated by this path */
110620110592
LogEst rCost; /* Total cost of this path */
110593
+ LogEst rUnsorted; /* Total cost of this path ignoring sorting costs */
110621110594
i8 isOrdered; /* No. of ORDER BY terms satisfied. -1 for unknown */
110622110595
WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */
110623110596
};
110624110597
110625110598
/*
@@ -116275,10 +116248,49 @@
116275116248
if( pLast ) zName[i++] = pLast->cId;
116276116249
zName[i] = 0;
116277116250
return zName;
116278116251
}
116279116252
#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
+}
116280116292
116281116293
/*
116282116294
** Given the list of WhereLoop objects at pWInfo->pLoops, this routine
116283116295
** attempts to find the lowest cost path that visits each WhereLoop
116284116296
** once. This path is then loaded into the pWInfo->a[].pWLoop fields.
@@ -116297,139 +116309,170 @@
116297116309
sqlite3 *db; /* The database connection */
116298116310
int iLoop; /* Loop counter over the terms of the join */
116299116311
int ii, jj; /* Loop counters */
116300116312
int mxI = 0; /* Index of next entry to replace */
116301116313
int nOrderBy; /* Number of ORDER BY clause terms */
116302
- LogEst rCost; /* Cost of a path */
116303
- LogEst nOut; /* Number of outputs */
116304116314
LogEst mxCost = 0; /* Maximum cost of a set of paths */
116315
+ LogEst mxUnsorted = 0; /* Maximum unsorted cost of a set of path */
116305116316
int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
116306116317
WherePath *aFrom; /* All nFrom paths at the previous level */
116307116318
WherePath *aTo; /* The nTo best paths at the current level */
116308116319
WherePath *pFrom; /* An element of aFrom[] that we are working on */
116309116320
WherePath *pTo; /* An element of aTo[] that we are working on */
116310116321
WhereLoop *pWLoop; /* One of the WhereLoop objects */
116311116322
WhereLoop **pX; /* Used to divy up the pSpace memory */
116323
+ LogEst *aSortCost = 0; /* Sorting and partial sorting costs */
116312116324
char *pSpace; /* Temporary memory used by this routine */
116325
+ int nSpace; /* Bytes of space allocated at pSpace */
116313116326
116314116327
pParse = pWInfo->pParse;
116315116328
db = pParse->db;
116316116329
nLoop = pWInfo->nLevel;
116317116330
/* TUNING: For simple queries, only the best path is tracked.
116318116331
** For 2-way joins, the 5 best paths are followed.
116319116332
** For joins of 3 or more tables, track the 10 best paths */
116320116333
mxChoice = (nLoop<=1) ? 1 : (nLoop==2 ? 5 : 10);
116321116334
assert( nLoop<=pWInfo->pTabList->nSrc );
116322
- WHERETRACE(0x002, ("---- begin solver\n"));
116335
+ WHERETRACE(0x002, ("---- begin solver. (nRowEst=%d)\n", nRowEst));
116323116336
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);
116327116352
if( pSpace==0 ) return SQLITE_NOMEM;
116328116353
aTo = (WherePath*)pSpace;
116329116354
aFrom = aTo+mxChoice;
116330116355
memset(aFrom, 0, sizeof(aFrom[0]));
116331116356
pX = (WhereLoop**)(aFrom+mxChoice);
116332116357
for(ii=mxChoice*2, pFrom=aTo; ii>0; ii--, pFrom++, pX += nLoop){
116333116358
pFrom->aLoop = pX;
116334116359
}
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 );
116335116372
116336116373
/* Seed the search with a single WherePath containing zero WhereLoops.
116337116374
**
116338116375
** TUNING: Do not let the number of iterations go above 25. If the cost
116339116376
** of computing an automatic index is not paid back within the first 25
116340116377
** rows, then do not use the automatic index. */
116341116378
aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) );
116342116379
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;
116352116389
}
116353116390
116354116391
/* Compute successively longer WherePaths using the previous generation
116355116392
** of WherePaths as the basis for the next. Keep track of the mxChoice
116356116393
** best paths at each generation */
116357116394
for(iLoop=0; iLoop<nLoop; iLoop++){
116358116395
nTo = 0;
116359116396
for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
116360116397
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
+
116364116405
if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
116365116406
if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
116366116407
/* At this point, pWLoop is a candidate to be the next loop.
116367116408
** 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);
116370116411
nOut = pFrom->nRow + pWLoop->nOut;
116371116412
maskNew = pFrom->maskLoop | pWLoop->maskSelf;
116372116413
if( isOrdered<0 ){
116373116414
isOrdered = wherePathSatisfiesOrderBy(pWInfo,
116374116415
pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
116375116416
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
- }
116407116417
}else{
116408116418
revMask = pFrom->revLoop;
116409116419
}
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
+ */
116411116447
for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
116412116448
if( pTo->maskLoop==maskNew
116413
- && ((pTo->isOrdered^isOrdered)&80)==0
116449
+ && ((pTo->isOrdered^isOrdered)&0x80)==0
116414116450
){
116415116451
testcase( jj==nTo-1 );
116416116452
break;
116417116453
}
116418116454
}
116419116455
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. */
116421116463
#ifdef WHERETRACE_ENABLED /* 0x4 */
116422116464
if( sqlite3WhereTrace&0x4 ){
116423116465
sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
116424116466
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
116425116467
isOrdered>=0 ? isOrdered+'0' : '?');
116426116468
}
116427116469
#endif
116428116470
continue;
116429116471
}
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. */
116431116474
if( nTo<mxChoice ){
116432116475
/* Increase the size of the aTo set by one */
116433116476
jj = nTo++;
116434116477
}else{
116435116478
/* New path replaces the prior worst to keep count below mxChoice */
@@ -116442,11 +116485,15 @@
116442116485
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
116443116486
isOrdered>=0 ? isOrdered+'0' : '?');
116444116487
}
116445116488
#endif
116446116489
}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) ){
116448116495
#ifdef WHERETRACE_ENABLED /* 0x4 */
116449116496
if( sqlite3WhereTrace&0x4 ){
116450116497
sqlite3DebugPrintf(
116451116498
"Skip %s cost=%-3d,%3d order=%c",
116452116499
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
@@ -116454,15 +116501,17 @@
116454116501
sqlite3DebugPrintf(" vs %s cost=%-3d,%d order=%c\n",
116455116502
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
116456116503
pTo->isOrdered>=0 ? pTo->isOrdered+'0' : '?');
116457116504
}
116458116505
#endif
116506
+ /* Discard the candidate path from further consideration */
116459116507
testcase( pTo->rCost==rCost );
116460116508
continue;
116461116509
}
116462116510
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. */
116464116513
#ifdef WHERETRACE_ENABLED /* 0x4 */
116465116514
if( sqlite3WhereTrace&0x4 ){
116466116515
sqlite3DebugPrintf(
116467116516
"Update %s cost=%-3d,%3d order=%c",
116468116517
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
@@ -116476,19 +116525,24 @@
116476116525
/* pWLoop is a winner. Add it to the set of best so far */
116477116526
pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
116478116527
pTo->revLoop = revMask;
116479116528
pTo->nRow = nOut;
116480116529
pTo->rCost = rCost;
116530
+ pTo->rUnsorted = rUnsorted;
116481116531
pTo->isOrdered = isOrdered;
116482116532
memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
116483116533
pTo->aLoop[iLoop] = pWLoop;
116484116534
if( nTo>=mxChoice ){
116485116535
mxI = 0;
116486116536
mxCost = aTo[0].rCost;
116537
+ mxUnsorted = aTo[0].nRow;
116487116538
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
+ ){
116489116542
mxCost = pTo->rCost;
116543
+ mxUnsorted = pTo->rUnsorted;
116490116544
mxI = jj;
116491116545
}
116492116546
}
116493116547
}
116494116548
}
@@ -123119,11 +123173,11 @@
123119123173
123120123174
/*
123121123175
** Return a static string containing the name corresponding to the error code
123122123176
** specified in the argument.
123123123177
*/
123124
-#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
123178
+#if (defined(SQLITE_DEBUG) && SQLITE_OS_WIN) || defined(SQLITE_TEST)
123125123179
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
123126123180
const char *zName = 0;
123127123181
int i, origRc = rc;
123128123182
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
123129123183
switch( rc ){
@@ -123154,11 +123208,10 @@
123154123208
case SQLITE_IOERR_TRUNCATE: zName = "SQLITE_IOERR_TRUNCATE"; break;
123155123209
case SQLITE_IOERR_FSTAT: zName = "SQLITE_IOERR_FSTAT"; break;
123156123210
case SQLITE_IOERR_UNLOCK: zName = "SQLITE_IOERR_UNLOCK"; break;
123157123211
case SQLITE_IOERR_RDLOCK: zName = "SQLITE_IOERR_RDLOCK"; break;
123158123212
case SQLITE_IOERR_DELETE: zName = "SQLITE_IOERR_DELETE"; break;
123159
- case SQLITE_IOERR_BLOCKED: zName = "SQLITE_IOERR_BLOCKED"; break;
123160123213
case SQLITE_IOERR_NOMEM: zName = "SQLITE_IOERR_NOMEM"; break;
123161123214
case SQLITE_IOERR_ACCESS: zName = "SQLITE_IOERR_ACCESS"; break;
123162123215
case SQLITE_IOERR_CHECKRESERVEDLOCK:
123163123216
zName = "SQLITE_IOERR_CHECKRESERVEDLOCK"; break;
123164123217
case SQLITE_IOERR_LOCK: zName = "SQLITE_IOERR_LOCK"; break;
@@ -144218,11 +144271,11 @@
144218144271
** the size of the range (always at least 1). In other words, the value
144219144272
** ((C<<22) + N) represents a range of N codepoints starting with codepoint
144220144273
** C. It is not possible to represent a range larger than 1023 codepoints
144221144274
** using this format.
144222144275
*/
144223
- const static unsigned int aEntry[] = {
144276
+ static const unsigned int aEntry[] = {
144224144277
0x00000030, 0x0000E807, 0x00016C06, 0x0001EC2F, 0x0002AC07,
144225144278
0x0002D001, 0x0002D803, 0x0002EC01, 0x0002FC01, 0x00035C01,
144226144279
0x0003DC01, 0x000B0804, 0x000B480E, 0x000B9407, 0x000BB401,
144227144280
0x000BBC81, 0x000DD401, 0x000DF801, 0x000E1002, 0x000E1C01,
144228144281
0x000FD801, 0x00120808, 0x00156806, 0x00162402, 0x00163C01,
@@ -144310,11 +144363,11 @@
144310144363
144311144364
if( c<128 ){
144312144365
return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 );
144313144366
}else if( c<(1<<22) ){
144314144367
unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
144315
- int iRes;
144368
+ int iRes = 0;
144316144369
int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
144317144370
int iLo = 0;
144318144371
while( iHi>=iLo ){
144319144372
int iTest = (iHi + iLo) / 2;
144320144373
if( key >= aEntry[iTest] ){
@@ -144381,11 +144434,11 @@
144381144434
iHi = iTest-1;
144382144435
}
144383144436
}
144384144437
assert( key>=aDia[iRes] );
144385144438
return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]);
144386
-};
144439
+}
144387144440
144388144441
144389144442
/*
144390144443
** Return true if the argument interpreted as a unicode codepoint
144391144444
** is a diacritical modifier character.
144392144445
--- 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 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.6"
111111
#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"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -267,11 +267,11 @@
267267
/*
268268
** CAPI3REF: Closing A Database Connection
269269
**
270270
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
271271
** 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
273273
** the [sqlite3] object is successfully destroyed and all associated
274274
** resources are deallocated.
275275
**
276276
** ^If the database connection is associated with unfinalized prepared
277277
** statements or unfinished sqlite3_backup objects then sqlite3_close()
@@ -288,11 +288,11 @@
288288
** [sqlite3_blob_close | close] all [BLOB handles], and
289289
** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
290290
** with the [sqlite3] object prior to attempting to close the object. ^If
291291
** sqlite3_close_v2() is called on a [database connection] that still has
292292
** 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
294294
** of resources is deferred until all [prepared statements], [BLOB handles],
295295
** and [sqlite3_backup] objects are also destroyed.
296296
**
297297
** ^If an [sqlite3] object is destroyed while a transaction is open,
298298
** the transaction is automatically rolled back.
@@ -384,20 +384,18 @@
384384
char **errmsg /* Error msg written here */
385385
);
386386
387387
/*
388388
** CAPI3REF: Result Codes
389
-** KEYWORDS: SQLITE_OK {error code} {error codes}
390
-** KEYWORDS: {result code} {result codes}
389
+** KEYWORDS: {result code definitions}
391390
**
392391
** Many SQLite functions return an integer result code from the set shown
393392
** here in order to indicate success or failure.
394393
**
395394
** New error codes may be added in future versions of SQLite.
396395
**
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]
399397
*/
400398
#define SQLITE_OK 0 /* Successful result */
401399
/* beginning-of-error-codes */
402400
#define SQLITE_ERROR 1 /* SQL error or missing database */
403401
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
@@ -431,30 +429,23 @@
431429
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
432430
/* end-of-error-codes */
433431
434432
/*
435433
** 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}
438435
**
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
441438
** these result codes are too coarse-grained. They do not provide as
442439
** much information about problems as programmers might like. In an effort to
443440
** address this, newer versions of SQLite (version 3.3.8 and later) include
444441
** 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
446443
** 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()].
456447
*/
457448
#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
458449
#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
459450
#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
460451
#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
@@ -683,11 +674,11 @@
683674
** write return values. Potential uses for xFileControl() might be
684675
** functions to enable blocking locks with timeouts, to change the
685676
** locking strategy (for example to use dot-file locks), to inquire
686677
** about the status of a lock, or to break stale locks. The SQLite
687678
** 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.
689680
** Applications that define a custom xFileControl method should use opcodes
690681
** greater than 100 to avoid conflicts. VFS implementations should
691682
** return [SQLITE_NOTFOUND] for file control opcodes that they do not
692683
** recognize.
693684
**
@@ -756,10 +747,11 @@
756747
/* Additional methods may be added in future releases */
757748
};
758749
759750
/*
760751
** CAPI3REF: Standard File Control Opcodes
752
+** KEYWORDS: {file control opcodes} {file control opcode}
761753
**
762754
** These integer constants are opcodes for the xFileControl method
763755
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
764756
** interface.
765757
**
@@ -2043,28 +2035,28 @@
20432035
** [database connection] D when another thread
20442036
** or process has the table locked.
20452037
** The sqlite3_busy_handler() interface is used to implement
20462038
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
20472039
**
2048
-** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
2040
+** ^If the busy callback is NULL, then [SQLITE_BUSY]
20492041
** is returned immediately upon encountering the lock. ^If the busy callback
20502042
** is not NULL, then the callback might be invoked with two arguments.
20512043
**
20522044
** ^The first argument to the busy handler is a copy of the void* pointer which
20532045
** is the third argument to sqlite3_busy_handler(). ^The second argument to
20542046
** the busy handler callback is the number of times that the busy handler has
20552047
** been invoked for the same locking event. ^If the
20562048
** 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
20582050
** to the application.
20592051
** ^If the callback returns non-zero, then another attempt
20602052
** is made to access the database and the cycle repeats.
20612053
**
20622054
** The presence of a busy handler does not guarantee that it will be invoked
20632055
** when there is lock contention. ^If SQLite determines that invoking the busy
20642056
** 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
20662058
** busy handler.
20672059
** Consider a scenario where one process is holding a read lock that
20682060
** it is trying to promote to a reserved lock and
20692061
** a second process is holding a reserved lock that it is trying
20702062
** to promote to an exclusive lock. The first process cannot proceed
@@ -2075,25 +2067,10 @@
20752067
** will induce the first process to release its read lock and allow
20762068
** the second process to proceed.
20772069
**
20782070
** ^The default busy callback is NULL.
20792071
**
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
-**
20952072
** ^(There can only be a single busy handler defined for each
20962073
** [database connection]. Setting a new busy handler clears any
20972074
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
20982075
** or evaluating [PRAGMA busy_timeout=N] will change the
20992076
** busy handler and thus clear any previously set busy handler.
@@ -2114,11 +2091,11 @@
21142091
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
21152092
** for a specified amount of time when a table is locked. ^The handler
21162093
** will sleep multiple times until at least "ms" milliseconds of sleeping
21172094
** have accumulated. ^After at least "ms" milliseconds of sleeping,
21182095
** the handler returns 0 which causes [sqlite3_step()] to return
2119
-** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
2096
+** [SQLITE_BUSY].
21202097
**
21212098
** ^Calling this routine with an argument less than or equal to zero
21222099
** turns off all busy handlers.
21232100
**
21242101
** ^(There can only be a single busy handler for a particular
@@ -2526,12 +2503,12 @@
25262503
** return either [SQLITE_OK] or one of these two constants in order
25272504
** to signal SQLite whether or not the action is permitted. See the
25282505
** [sqlite3_set_authorizer | authorizer documentation] for additional
25292506
** information.
25302507
**
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.
25332510
*/
25342511
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
25352512
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
25362513
25372514
/*
@@ -7367,10 +7344,11 @@
73677344
*/
73687345
SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
73697346
73707347
/*
73717348
** CAPI3REF: Conflict resolution modes
7349
+** KEYWORDS: {conflict resolution mode}
73727350
**
73737351
** These constants are returned by [sqlite3_vtab_on_conflict()] to
73747352
** inform a [virtual table] implementation what the [ON CONFLICT] mode
73757353
** is for the SQL statement being evaluated.
73767354
**
73777355
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button