Fossil SCM

Update the built-in SQLite to the latest version from the SQLite trunk.

drh 2012-08-25 01:48 trunk
Commit d7736649cdd05770f1d774dc673d343179f9b849
3 files changed +3 -3 +275 -80 +5 -2
+3 -3
--- src/shell.c
+++ src/shell.c
@@ -62,13 +62,11 @@
6262
6363
#if defined(_WIN32) || defined(WIN32)
6464
# include <io.h>
6565
#define isatty(h) _isatty(h)
6666
#define access(f,m) _access((f),(m))
67
-#undef popen
6867
#define popen(a,b) _popen((a),(b))
69
-#undef pclose
7068
#define pclose(x) _pclose(x)
7169
#else
7270
/* Make sure isatty() has a prototype.
7371
*/
7472
extern int isatty(int);
@@ -1449,10 +1447,11 @@
14491447
** Make sure the database is open. If it is not, then open it. If
14501448
** the database fails to open, print an error message and exit.
14511449
*/
14521450
static void open_db(struct callback_data *p){
14531451
if( p->db==0 ){
1452
+ sqlite3_initialize();
14541453
sqlite3_open(p->zDbFilename, &p->db);
14551454
db = p->db;
14561455
if( db && sqlite3_errcode(db)==SQLITE_OK ){
14571456
sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
14581457
shellstaticFunc, 0, 0);
@@ -2464,11 +2463,11 @@
24642463
24652464
if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
24662465
open_db(p);
24672466
output_file_close(p->traceOut);
24682467
p->traceOut = output_file_open(azArg[1]);
2469
-#ifndef SQLITE_OMIT_TRACE
2468
+#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
24702469
if( p->traceOut==0 ){
24712470
sqlite3_trace(p->db, 0, 0);
24722471
}else{
24732472
sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
24742473
}
@@ -2771,10 +2770,11 @@
27712770
#if !defined(__RTP__) && !defined(_WRS_KERNEL)
27722771
fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
27732772
#endif
27742773
return 1;
27752774
}
2775
+ sqlite3_initialize();
27762776
zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
27772777
sqliterc = zBuf;
27782778
}
27792779
in = fopen(sqliterc,"rb");
27802780
if( in ){
27812781
--- src/shell.c
+++ src/shell.c
@@ -62,13 +62,11 @@
62
63 #if defined(_WIN32) || defined(WIN32)
64 # include <io.h>
65 #define isatty(h) _isatty(h)
66 #define access(f,m) _access((f),(m))
67 #undef popen
68 #define popen(a,b) _popen((a),(b))
69 #undef pclose
70 #define pclose(x) _pclose(x)
71 #else
72 /* Make sure isatty() has a prototype.
73 */
74 extern int isatty(int);
@@ -1449,10 +1447,11 @@
1449 ** Make sure the database is open. If it is not, then open it. If
1450 ** the database fails to open, print an error message and exit.
1451 */
1452 static void open_db(struct callback_data *p){
1453 if( p->db==0 ){
 
1454 sqlite3_open(p->zDbFilename, &p->db);
1455 db = p->db;
1456 if( db && sqlite3_errcode(db)==SQLITE_OK ){
1457 sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
1458 shellstaticFunc, 0, 0);
@@ -2464,11 +2463,11 @@
2464
2465 if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
2466 open_db(p);
2467 output_file_close(p->traceOut);
2468 p->traceOut = output_file_open(azArg[1]);
2469 #ifndef SQLITE_OMIT_TRACE
2470 if( p->traceOut==0 ){
2471 sqlite3_trace(p->db, 0, 0);
2472 }else{
2473 sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
2474 }
@@ -2771,10 +2770,11 @@
2771 #if !defined(__RTP__) && !defined(_WRS_KERNEL)
2772 fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
2773 #endif
2774 return 1;
2775 }
 
2776 zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
2777 sqliterc = zBuf;
2778 }
2779 in = fopen(sqliterc,"rb");
2780 if( in ){
2781
--- src/shell.c
+++ src/shell.c
@@ -62,13 +62,11 @@
62
63 #if defined(_WIN32) || defined(WIN32)
64 # include <io.h>
65 #define isatty(h) _isatty(h)
66 #define access(f,m) _access((f),(m))
 
67 #define popen(a,b) _popen((a),(b))
 
68 #define pclose(x) _pclose(x)
69 #else
70 /* Make sure isatty() has a prototype.
71 */
72 extern int isatty(int);
@@ -1449,10 +1447,11 @@
1447 ** Make sure the database is open. If it is not, then open it. If
1448 ** the database fails to open, print an error message and exit.
1449 */
1450 static void open_db(struct callback_data *p){
1451 if( p->db==0 ){
1452 sqlite3_initialize();
1453 sqlite3_open(p->zDbFilename, &p->db);
1454 db = p->db;
1455 if( db && sqlite3_errcode(db)==SQLITE_OK ){
1456 sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
1457 shellstaticFunc, 0, 0);
@@ -2464,11 +2463,11 @@
2463
2464 if( c=='t' && strncmp(azArg[0], "trace", n)==0 && nArg>1 ){
2465 open_db(p);
2466 output_file_close(p->traceOut);
2467 p->traceOut = output_file_open(azArg[1]);
2468 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
2469 if( p->traceOut==0 ){
2470 sqlite3_trace(p->db, 0, 0);
2471 }else{
2472 sqlite3_trace(p->db, sql_trace_callback, p->traceOut);
2473 }
@@ -2771,10 +2770,11 @@
2770 #if !defined(__RTP__) && !defined(_WRS_KERNEL)
2771 fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
2772 #endif
2773 return 1;
2774 }
2775 sqlite3_initialize();
2776 zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
2777 sqliterc = zBuf;
2778 }
2779 in = fopen(sqliterc,"rb");
2780 if( in ){
2781
+275 -80
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673673
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674674
** [sqlite_version()] and [sqlite_source_id()].
675675
*/
676676
#define SQLITE_VERSION "3.7.14"
677677
#define SQLITE_VERSION_NUMBER 3007014
678
-#define SQLITE_SOURCE_ID "2012-08-14 17:29:27 6954fef006431d153de6e63e362b8d260ebeb1c6"
678
+#define SQLITE_SOURCE_ID "2012-08-24 23:56:19 62678be3df35cdcb09172ba8c860f7b73517f1ea"
679679
680680
/*
681681
** CAPI3REF: Run-Time Library Version Numbers
682682
** KEYWORDS: sqlite3_version, sqlite3_sourceid
683683
**
@@ -3723,12 +3723,15 @@
37233723
** ^The third argument is the value to bind to the parameter.
37243724
**
37253725
** ^(In those routines that have a fourth argument, its value is the
37263726
** number of bytes in the parameter. To be clear: the value is the
37273727
** number of <u>bytes</u> in the value, not the number of characters.)^
3728
-** ^If the fourth parameter is negative, the length of the string is
3728
+** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3729
+** is negative, then the length of the string is
37293730
** the number of bytes up to the first zero terminator.
3731
+** If the fourth parameter to sqlite3_bind_blob() is negative, then
3732
+** the behavior is undefined.
37303733
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
37313734
** or sqlite3_bind_text16() then that parameter must be the byte offset
37323735
** where the NUL terminator would occur assuming the string were NUL
37333736
** terminated. If any NUL characters occur at byte offsets less than
37343737
** the value of the fourth parameter then the resulting string value will
@@ -10663,12 +10666,13 @@
1066310666
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1066410667
** TK_VARIABLE: variable number (always >= 1). */
1066510668
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
1066610669
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
1066710670
u8 flags2; /* Second set of flags. EP2_... */
10668
- u8 op2; /* If a TK_REGISTER, the original value of Expr.op */
10669
- /* If TK_COLUMN, the value of p5 for OP_Column */
10671
+ u8 op2; /* TK_REGISTER: original value of Expr.op
10672
+ ** TK_COLUMN: the value of p5 for OP_Column
10673
+ ** TK_AGG_FUNCTION: nesting depth */
1067010674
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
1067110675
Table *pTab; /* Table for TK_COLUMN expressions. */
1067210676
#if SQLITE_MAX_EXPR_DEPTH>0
1067310677
int nHeight; /* Height of the tree headed by this node */
1067410678
#endif
@@ -10919,10 +10923,11 @@
1091910923
struct InLoop {
1092010924
int iCur; /* The VDBE cursor used by this IN operator */
1092110925
int addrInTop; /* Top of the IN loop */
1092210926
} *aInLoop; /* Information about each nested IN operator */
1092310927
} in; /* Used when plan.wsFlags&WHERE_IN_ABLE */
10928
+ Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
1092410929
} u;
1092510930
1092610931
/* The following field is really not part of the current level. But
1092710932
** we need a place to cache virtual table index information for each
1092810933
** virtual table in the FROM clause and the WhereLevel structure is
@@ -11471,14 +11476,16 @@
1147111476
*/
1147211477
struct Walker {
1147311478
int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
1147411479
int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
1147511480
Parse *pParse; /* Parser context. */
11481
+ int walkerDepth; /* Number of subqueries */
1147611482
union { /* Extra data for callback */
1147711483
NameContext *pNC; /* Naming context */
1147811484
int i; /* Integer value */
1147911485
SrcList *pSrcList; /* FROM clause */
11486
+ struct SrcCount *pSrcCount; /* Counting column references */
1148011487
} u;
1148111488
};
1148211489
1148311490
/* Forward declarations */
1148411491
SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -11776,11 +11783,12 @@
1177611783
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
1177711784
SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
1177811785
#endif
1177911786
SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
1178011787
SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
11781
-SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**,ExprList*,u16);
11788
+SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
11789
+ Parse*,SrcList*,Expr*,ExprList**,ExprList*,u16,int);
1178211790
SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
1178311791
SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
1178411792
SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
1178511793
SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
1178611794
SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int);
@@ -11808,10 +11816,11 @@
1180811816
SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
1180911817
SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*);
1181011818
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*);
1181111819
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
1181211820
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
11821
+SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
1181311822
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
1181411823
SQLITE_PRIVATE void sqlite3PrngSaveState(void);
1181511824
SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
1181611825
SQLITE_PRIVATE void sqlite3PrngResetState(void);
1181711826
SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
@@ -15513,18 +15522,18 @@
1551315522
/* defer MT decisions to system malloc */
1551415523
_sqliteZone_ = malloc_default_zone();
1551515524
}else{
1551615525
/* only 1 core, use our own zone to contention over global locks,
1551715526
** e.g. we have our own dedicated locks */
15518
- bool success;
15527
+ bool success;
1551915528
malloc_zone_t* newzone = malloc_create_zone(4096, 0);
1552015529
malloc_set_zone_name(newzone, "Sqlite_Heap");
1552115530
do{
1552215531
success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone,
1552315532
(void * volatile *)&_sqliteZone_);
1552415533
}while(!_sqliteZone_);
15525
- if( !success ){
15534
+ if( !success ){
1552615535
/* somebody registered a zone first */
1552715536
malloc_destroy_zone(newzone);
1552815537
}
1552915538
}
1553015539
#endif
@@ -23448,13 +23457,13 @@
2344823457
return SQLITE_BUSY;
2344923458
2345023459
case EACCES:
2345123460
/* EACCES is like EAGAIN during locking operations, but not any other time*/
2345223461
if( (sqliteIOErr == SQLITE_IOERR_LOCK) ||
23453
- (sqliteIOErr == SQLITE_IOERR_UNLOCK) ||
23454
- (sqliteIOErr == SQLITE_IOERR_RDLOCK) ||
23455
- (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){
23462
+ (sqliteIOErr == SQLITE_IOERR_UNLOCK) ||
23463
+ (sqliteIOErr == SQLITE_IOERR_RDLOCK) ||
23464
+ (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){
2345623465
return SQLITE_BUSY;
2345723466
}
2345823467
/* else fall through */
2345923468
case EPERM:
2346023469
return SQLITE_PERM;
@@ -24497,11 +24506,11 @@
2449724506
lock.l_start = lock.l_len = 0L;
2449824507
if( unixFileLock(pFile, &lock)==0 ){
2449924508
pInode->eFileLock = NO_LOCK;
2450024509
}else{
2450124510
rc = SQLITE_IOERR_UNLOCK;
24502
- pFile->lastErrno = errno;
24511
+ pFile->lastErrno = errno;
2450324512
pInode->eFileLock = NO_LOCK;
2450424513
pFile->eFileLock = NO_LOCK;
2450524514
}
2450624515
}
2450724516
@@ -24513,11 +24522,11 @@
2451324522
assert( pInode->nLock>=0 );
2451424523
if( pInode->nLock==0 ){
2451524524
closePendingFds(pFile);
2451624525
}
2451724526
}
24518
-
24527
+
2451924528
end_unlock:
2452024529
unixLeaveMutex();
2452124530
if( rc==SQLITE_OK ) pFile->eFileLock = eFileLock;
2452224531
return rc;
2452324532
}
@@ -24780,11 +24789,11 @@
2478024789
char *zLockFile = (char *)pFile->lockingContext;
2478124790
int rc;
2478224791
2478324792
assert( pFile );
2478424793
OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
24785
- pFile->eFileLock, getpid()));
24794
+ pFile->eFileLock, getpid()));
2478624795
assert( eFileLock<=SHARED_LOCK );
2478724796
2478824797
/* no-op if possible */
2478924798
if( pFile->eFileLock==eFileLock ){
2479024799
return SQLITE_OK;
@@ -25167,11 +25176,11 @@
2516725176
sem_t *pSem = pFile->pInode->pSem;
2516825177
2516925178
assert( pFile );
2517025179
assert( pSem );
2517125180
OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
25172
- pFile->eFileLock, getpid()));
25181
+ pFile->eFileLock, getpid()));
2517325182
assert( eFileLock<=SHARED_LOCK );
2517425183
2517525184
/* no-op if possible */
2517625185
if( pFile->eFileLock==eFileLock ){
2517725186
return SQLITE_OK;
@@ -25757,11 +25766,11 @@
2575725766
SimulateIOError( newOffset-- );
2575825767
if( newOffset!=offset ){
2575925768
if( newOffset == -1 ){
2576025769
((unixFile*)id)->lastErrno = errno;
2576125770
}else{
25762
- ((unixFile*)id)->lastErrno = 0;
25771
+ ((unixFile*)id)->lastErrno = 0;
2576325772
}
2576425773
return -1;
2576525774
}
2576625775
got = osRead(id->h, pBuf, cnt);
2576725776
#endif
@@ -25845,11 +25854,11 @@
2584525854
SimulateIOError( newOffset-- );
2584625855
if( newOffset!=offset ){
2584725856
if( newOffset == -1 ){
2584825857
((unixFile*)id)->lastErrno = errno;
2584925858
}else{
25850
- ((unixFile*)id)->lastErrno = 0;
25859
+ ((unixFile*)id)->lastErrno = 0;
2585125860
}
2585225861
return -1;
2585325862
}
2585425863
got = osWrite(id->h, pBuf, cnt);
2585525864
}while( got<0 && errno==EINTR );
@@ -28359,11 +28368,11 @@
2835928368
** with _IOWR('z', 23, struct ByteRangeLockPB2) to track the same 5 states.
2836028369
** To simulate a F_RDLCK on the shared range, on AFP a randomly selected
2836128370
** address in the shared range is taken for a SHARED lock, the entire
2836228371
** shared range is taken for an EXCLUSIVE lock):
2836328372
**
28364
-** PENDING_BYTE 0x40000000
28373
+** PENDING_BYTE 0x40000000
2836528374
** RESERVED_BYTE 0x40000001
2836628375
** SHARED_RANGE 0x40000002 -> 0x40000200
2836728376
**
2836828377
** This works well on the local file system, but shows a nearly 100x
2836928378
** slowdown in read performance on AFP because the AFP client disables
@@ -29879,13 +29888,15 @@
2987929888
2988029889
#ifndef FILE_ATTRIBUTE_MASK
2988129890
# define FILE_ATTRIBUTE_MASK (0x0003FFF7)
2988229891
#endif
2988329892
29893
+#ifndef SQLITE_OMIT_WAL
2988429894
/* Forward references */
2988529895
typedef struct winShm winShm; /* A connection to shared-memory */
2988629896
typedef struct winShmNode winShmNode; /* A region of shared-memory */
29897
+#endif
2988729898
2988829899
/*
2988929900
** WinCE lacks native support for file locking so we have to fake it
2989029901
** with some code of our own.
2989129902
*/
@@ -29909,11 +29920,13 @@
2990929920
HANDLE h; /* Handle for accessing the file */
2991029921
u8 locktype; /* Type of lock currently held on this file */
2991129922
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
2991229923
u8 ctrlFlags; /* Flags. See WINFILE_* below */
2991329924
DWORD lastErrno; /* The Windows errno from the last I/O error */
29925
+#ifndef SQLITE_OMIT_WAL
2991429926
winShm *pShm; /* Instance of shared memory on this file */
29927
+#endif
2991529928
const char *zPath; /* Full pathname of this file */
2991629929
int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
2991729930
#if SQLITE_OS_WINCE
2991829931
LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
2991929932
HANDLE hMutex; /* Mutex used to control access to shared lock */
@@ -29934,10 +29947,26 @@
2993429947
*/
2993529948
#ifndef SQLITE_WIN32_DBG_BUF_SIZE
2993629949
# define SQLITE_WIN32_DBG_BUF_SIZE ((int)(4096-sizeof(DWORD)))
2993729950
#endif
2993829951
29952
+/*
29953
+ * The value used with sqlite3_win32_set_directory() to specify that
29954
+ * the data directory should be changed.
29955
+ */
29956
+#ifndef SQLITE_WIN32_DATA_DIRECTORY_TYPE
29957
+# define SQLITE_WIN32_DATA_DIRECTORY_TYPE (1)
29958
+#endif
29959
+
29960
+/*
29961
+ * The value used with sqlite3_win32_set_directory() to specify that
29962
+ * the temporary directory should be changed.
29963
+ */
29964
+#ifndef SQLITE_WIN32_TEMP_DIRECTORY_TYPE
29965
+# define SQLITE_WIN32_TEMP_DIRECTORY_TYPE (2)
29966
+#endif
29967
+
2993929968
/*
2994029969
* If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
2994129970
* various Win32 API heap functions instead of our own.
2994229971
*/
2994329972
#ifdef SQLITE_WIN32_MALLOC
@@ -31147,10 +31176,46 @@
3114731176
zFilenameMbcs = unicodeToMbcs(zTmpWide);
3114831177
sqlite3_free(zTmpWide);
3114931178
return zFilenameMbcs;
3115031179
}
3115131180
31181
+/*
31182
+** This function sets the data directory or the temporary directory based on
31183
+** the provided arguments. The type argument must be 1 in order to set the
31184
+** data directory or 2 in order to set the temporary directory. The zValue
31185
+** argument is the name of the directory to use. The return value will be
31186
+** SQLITE_OK if successful.
31187
+*/
31188
+SQLITE_API int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
31189
+ char **ppDirectory = 0;
31190
+#ifndef SQLITE_OMIT_AUTOINIT
31191
+ int rc = sqlite3_initialize();
31192
+ if( rc ) return rc;
31193
+#endif
31194
+ if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
31195
+ ppDirectory = &sqlite3_data_directory;
31196
+ }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
31197
+ ppDirectory = &sqlite3_temp_directory;
31198
+ }
31199
+ assert( !ppDirectory || type==SQLITE_WIN32_DATA_DIRECTORY_TYPE
31200
+ || type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE
31201
+ );
31202
+ assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) );
31203
+ if( ppDirectory ){
31204
+ char *zValueUtf8 = 0;
31205
+ if( zValue && zValue[0] ){
31206
+ zValueUtf8 = unicodeToUtf8(zValue);
31207
+ if ( zValueUtf8==0 ){
31208
+ return SQLITE_NOMEM;
31209
+ }
31210
+ }
31211
+ sqlite3_free(*ppDirectory);
31212
+ *ppDirectory = zValueUtf8;
31213
+ return SQLITE_OK;
31214
+ }
31215
+ return SQLITE_ERROR;
31216
+}
3115231217
3115331218
/*
3115431219
** The return value of getLastErrorMsg
3115531220
** is zero if the error message fits in the buffer, or non-zero
3115631221
** otherwise (if the message was truncated).
@@ -31763,11 +31828,13 @@
3176331828
static int winClose(sqlite3_file *id){
3176431829
int rc, cnt = 0;
3176531830
winFile *pFile = (winFile*)id;
3176631831
3176731832
assert( id!=0 );
31833
+#ifndef SQLITE_OMIT_WAL
3176831834
assert( pFile->pShm==0 );
31835
+#endif
3176931836
OSTRACE(("CLOSE %d\n", pFile->h));
3177031837
do{
3177131838
rc = osCloseHandle(pFile->h);
3177231839
/* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
3177331840
}while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
@@ -33513,11 +33580,13 @@
3351333580
memset(pFile, 0, sizeof(*pFile));
3351433581
pFile->pMethod = &winIoMethod;
3351533582
pFile->h = h;
3351633583
pFile->lastErrno = NO_ERROR;
3351733584
pFile->pVfs = pVfs;
33585
+#ifndef SQLITE_OMIT_WAL
3351833586
pFile->pShm = 0;
33587
+#endif
3351933588
pFile->zPath = zName;
3352033589
if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
3352133590
pFile->ctrlFlags |= WINFILE_PSOW;
3352233591
}
3352333592
@@ -49289,11 +49358,11 @@
4928949358
}
4929049359
next = get2byte(&data[pc]);
4929149360
size = get2byte(&data[pc+2]);
4929249361
if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
4929349362
/* Free blocks must be in ascending order. And the last byte of
49294
- ** the free-block must lie on the database page. */
49363
+ ** the free-block must lie on the database page. */
4929549364
return SQLITE_CORRUPT_BKPT;
4929649365
}
4929749366
nFree = nFree + size;
4929849367
pc = next;
4929949368
}
@@ -50463,11 +50532,11 @@
5046350532
if( rc==SQLITE_OK ){
5046450533
if( p->inTrans==TRANS_NONE ){
5046550534
pBt->nTransaction++;
5046650535
#ifndef SQLITE_OMIT_SHARED_CACHE
5046750536
if( p->sharable ){
50468
- assert( p->lock.pBtree==p && p->lock.iTable==1 );
50537
+ assert( p->lock.pBtree==p && p->lock.iTable==1 );
5046950538
p->lock.eLock = READ_LOCK;
5047050539
p->lock.pNext = pBt->pLock;
5047150540
pBt->pLock = &p->lock;
5047250541
}
5047350542
#endif
@@ -54301,10 +54370,11 @@
5430154370
while( i==iNextOld ){
5430254371
/* Cell i is the cell immediately following the last cell on old
5430354372
** sibling page j. If the siblings are not leaf pages of an
5430454373
** intkey b-tree, then cell i was a divider cell. */
5430554374
assert( j+1 < ArraySize(apCopy) );
54375
+ assert( j+1 < nOld );
5430654376
pOld = apCopy[++j];
5430754377
iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
5430854378
if( pOld->nOverflow ){
5430954379
nOverflow = pOld->nOverflow;
5431054380
iOverflow = i + !leafData + pOld->aiOvfl[0];
@@ -56135,11 +56205,10 @@
5613556205
*/
5613656206
SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){
5613756207
assert( mask==BTREE_BULKLOAD || mask==0 );
5613856208
pCsr->hints = mask;
5613956209
}
56140
-
5614156210
5614256211
/************** End of btree.c ***********************************************/
5614356212
/************** Begin file backup.c ******************************************/
5614456213
/*
5614556214
** 2009 January 28
@@ -70367,11 +70436,11 @@
7036770436
if( iBuf==0 ){
7036870437
int nRead; /* Bytes to read from disk */
7036970438
int rc; /* sqlite3OsRead() return code */
7037070439
7037170440
/* Determine how many bytes of data to read. */
70372
- nRead = p->iEof - p->iReadOff;
70441
+ nRead = (int)(p->iEof - p->iReadOff);
7037370442
if( nRead>p->nBuffer ) nRead = p->nBuffer;
7037470443
assert( nRead>0 );
7037570444
7037670445
/* Read data from the file. Return early if an error occurs. */
7037770446
rc = sqlite3OsRead(p->pFile, p->aBuffer, nRead, p->iReadOff);
@@ -70472,11 +70541,11 @@
7047270541
}
7047370542
7047470543
rc = vdbeSorterIterVarint(db, pIter, &nRec);
7047570544
if( rc==SQLITE_OK ){
7047670545
pIter->nKey = (int)nRec;
70477
- rc = vdbeSorterIterRead(db, pIter, nRec, &pIter->aKey);
70546
+ rc = vdbeSorterIterRead(db, pIter, (int)nRec, &pIter->aKey);
7047870547
}
7047970548
7048070549
return rc;
7048170550
}
7048270551
@@ -70515,11 +70584,11 @@
7051570584
7051670585
iBuf = iStart % nBuf;
7051770586
if( iBuf ){
7051870587
int nRead = nBuf - iBuf;
7051970588
if( (iStart + nRead) > pSorter->iWriteOff ){
70520
- nRead = pSorter->iWriteOff - iStart;
70589
+ nRead = (int)(pSorter->iWriteOff - iStart);
7052170590
}
7052270591
rc = sqlite3OsRead(
7052370592
pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart
7052470593
);
7052570594
assert( rc!=SQLITE_IOERR_SHORT_READ );
@@ -71838,17 +71907,23 @@
7183871907
*/
7183971908
SQLITE_PRIVATE int sqlite3WalkSelect(Walker *pWalker, Select *p){
7184071909
int rc;
7184171910
if( p==0 || pWalker->xSelectCallback==0 ) return WRC_Continue;
7184271911
rc = WRC_Continue;
71843
- while( p ){
71912
+ pWalker->walkerDepth++;
71913
+ while( p ){
7184471914
rc = pWalker->xSelectCallback(pWalker, p);
7184571915
if( rc ) break;
71846
- if( sqlite3WalkSelectExpr(pWalker, p) ) return WRC_Abort;
71847
- if( sqlite3WalkSelectFrom(pWalker, p) ) return WRC_Abort;
71916
+ if( sqlite3WalkSelectExpr(pWalker, p)
71917
+ || sqlite3WalkSelectFrom(pWalker, p)
71918
+ ){
71919
+ pWalker->walkerDepth--;
71920
+ return WRC_Abort;
71921
+ }
7184871922
p = p->pPrior;
7184971923
}
71924
+ pWalker->walkerDepth--;
7185071925
return rc & WRC_Abort;
7185171926
}
7185271927
7185371928
/************** End of walker.c **********************************************/
7185471929
/************** Begin file resolve.c *****************************************/
@@ -71868,10 +71943,33 @@
7186871943
** resolve all identifiers by associating them with a particular
7186971944
** table and column.
7187071945
*/
7187171946
/* #include <stdlib.h> */
7187271947
/* #include <string.h> */
71948
+
71949
+/*
71950
+** Walk the expression tree pExpr and increase the aggregate function
71951
+** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node.
71952
+** This needs to occur when copying a TK_AGG_FUNCTION node from an
71953
+** outer query into an inner subquery.
71954
+**
71955
+** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
71956
+** is a helper function - a callback for the tree walker.
71957
+*/
71958
+static int incrAggDepth(Walker *pWalker, Expr *pExpr){
71959
+ if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i;
71960
+ return WRC_Continue;
71961
+}
71962
+static void incrAggFunctionDepth(Expr *pExpr, int N){
71963
+ if( N>0 ){
71964
+ Walker w;
71965
+ memset(&w, 0, sizeof(w));
71966
+ w.xExprCallback = incrAggDepth;
71967
+ w.u.i = N;
71968
+ sqlite3WalkExpr(&w, pExpr);
71969
+ }
71970
+}
7187371971
7187471972
/*
7187571973
** Turn the pExpr expression into an alias for the iCol-th column of the
7187671974
** result set in pEList.
7187771975
**
@@ -71895,17 +71993,24 @@
7189571993
** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
7189671994
**
7189771995
** The result of random()%5 in the GROUP BY clause is probably different
7189871996
** from the result in the result-set. We might fix this someday. Or
7189971997
** then again, we might not...
71998
+**
71999
+** The nSubquery parameter specifies how many levels of subquery the
72000
+** alias is removed from the original expression. The usually value is
72001
+** zero but it might be more if the alias is contained within a subquery
72002
+** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
72003
+** structures must be increased by the nSubquery amount.
7190072004
*/
7190172005
static void resolveAlias(
7190272006
Parse *pParse, /* Parsing context */
7190372007
ExprList *pEList, /* A result set */
7190472008
int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
7190572009
Expr *pExpr, /* Transform this into an alias to the result set */
71906
- const char *zType /* "GROUP" or "ORDER" or "" */
72010
+ const char *zType, /* "GROUP" or "ORDER" or "" */
72011
+ int nSubquery /* Number of subqueries that the label is moving */
7190772012
){
7190872013
Expr *pOrig; /* The iCol-th column of the result set */
7190972014
Expr *pDup; /* Copy of pOrig */
7191072015
sqlite3 *db; /* The database connection */
7191172016
@@ -71914,10 +72019,11 @@
7191472019
assert( pOrig!=0 );
7191572020
assert( pOrig->flags & EP_Resolved );
7191672021
db = pParse->db;
7191772022
if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
7191872023
pDup = sqlite3ExprDup(db, pOrig, 0);
72024
+ incrAggFunctionDepth(pDup, nSubquery);
7191972025
pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
7192072026
if( pDup==0 ) return;
7192172027
if( pEList->a[iCol].iAlias==0 ){
7192272028
pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
7192372029
}
@@ -72002,13 +72108,14 @@
7200272108
const char *zTab, /* Name of table containing column, or NULL */
7200372109
const char *zCol, /* Name of the column. */
7200472110
NameContext *pNC, /* The name context used to resolve the name */
7200572111
Expr *pExpr /* Make this EXPR node point to the selected column */
7200672112
){
72007
- int i, j; /* Loop counters */
72113
+ int i, j; /* Loop counters */
7200872114
int cnt = 0; /* Number of matching column names */
7200972115
int cntTab = 0; /* Number of matching table names */
72116
+ int nSubquery = 0; /* How many levels of subquery */
7201072117
sqlite3 *db = pParse->db; /* The database connection */
7201172118
struct SrcList_item *pItem; /* Use for looping over pSrcList items */
7201272119
struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
7201372120
NameContext *pTopNC = pNC; /* First namecontext in the list */
7201472121
Schema *pSchema = 0; /* Schema of the expression */
@@ -72166,11 +72273,11 @@
7216672273
pOrig = pEList->a[j].pExpr;
7216772274
if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
7216872275
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
7216972276
return WRC_Abort;
7217072277
}
72171
- resolveAlias(pParse, pEList, j, pExpr, "");
72278
+ resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
7217272279
cnt = 1;
7217372280
pMatch = 0;
7217472281
assert( zTab==0 && zDb==0 );
7217572282
goto lookupname_end;
7217672283
}
@@ -72180,10 +72287,11 @@
7218072287
/* Advance to the next name context. The loop will exit when either
7218172288
** we have a match (cnt>0) or when we run out of name contexts.
7218272289
*/
7218372290
if( cnt==0 ){
7218472291
pNC = pNC->pNext;
72292
+ nSubquery++;
7218572293
}
7218672294
}
7218772295
7218872296
/*
7218972297
** If X and Y are NULL (in other words if only the column name Z is
@@ -72419,17 +72527,23 @@
7241972527
}else if( wrong_num_args ){
7242072528
sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
7242172529
nId, zId);
7242272530
pNC->nErr++;
7242372531
}
72424
- if( is_agg ){
72425
- pExpr->op = TK_AGG_FUNCTION;
72426
- pNC->ncFlags |= NC_HasAgg;
72427
- }
7242872532
if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg;
7242972533
sqlite3WalkExprList(pWalker, pList);
72430
- if( is_agg ) pNC->ncFlags |= NC_AllowAgg;
72534
+ if( is_agg ){
72535
+ NameContext *pNC2 = pNC;
72536
+ pExpr->op = TK_AGG_FUNCTION;
72537
+ pExpr->op2 = 0;
72538
+ while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
72539
+ pExpr->op2++;
72540
+ pNC2 = pNC2->pNext;
72541
+ }
72542
+ if( pNC2 ) pNC2->ncFlags |= NC_HasAgg;
72543
+ pNC->ncFlags |= NC_AllowAgg;
72544
+ }
7243172545
/* FIX ME: Compute pExpr->affinity based on the expected return
7243272546
** type of the function
7243372547
*/
7243472548
return WRC_Prune;
7243572549
}
@@ -72704,11 +72818,11 @@
7270472818
if( pItem->iOrderByCol ){
7270572819
if( pItem->iOrderByCol>pEList->nExpr ){
7270672820
resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
7270772821
return 1;
7270872822
}
72709
- resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType);
72823
+ resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0);
7271072824
}
7271172825
}
7271272826
return 0;
7271372827
}
7271472828
@@ -76204,13 +76318,16 @@
7620476318
if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
7620576319
pFarg = 0;
7620676320
}else{
7620776321
pFarg = pExpr->x.pList;
7620876322
}
76209
- sqlite3ExplainPrintf(pOut, "%sFUNCTION:%s(",
76210
- op==TK_AGG_FUNCTION ? "AGG_" : "",
76211
- pExpr->u.zToken);
76323
+ if( op==TK_AGG_FUNCTION ){
76324
+ sqlite3ExplainPrintf(pOut, "AGG_FUNCTION%d:%s(",
76325
+ pExpr->op2, pExpr->u.zToken);
76326
+ }else{
76327
+ sqlite3ExplainPrintf(pOut, "FUNCTION:%s(", pExpr->u.zToken);
76328
+ }
7621276329
if( pFarg ){
7621376330
sqlite3ExplainExprList(pOut, pFarg);
7621476331
}
7621576332
sqlite3ExplainPrintf(pOut, ")");
7621676333
break;
@@ -76897,42 +77014,64 @@
7689777014
}
7689877015
return 0;
7689977016
}
7690077017
7690177018
/*
76902
-** This is the expression callback for sqlite3FunctionUsesOtherSrc().
76903
-**
76904
-** Determine if an expression references any table other than one of the
76905
-** tables in pWalker->u.pSrcList and abort if it does.
77019
+** An instance of the following structure is used by the tree walker
77020
+** to count references to table columns in the arguments of an
77021
+** aggregate function, in order to implement the
77022
+** sqlite3FunctionThisSrc() routine.
7690677023
*/
76907
-static int exprUsesOtherSrc(Walker *pWalker, Expr *pExpr){
76908
- if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){
77024
+struct SrcCount {
77025
+ SrcList *pSrc; /* One particular FROM clause in a nested query */
77026
+ int nThis; /* Number of references to columns in pSrcList */
77027
+ int nOther; /* Number of references to columns in other FROM clauses */
77028
+};
77029
+
77030
+/*
77031
+** Count the number of references to columns.
77032
+*/
77033
+static int exprSrcCount(Walker *pWalker, Expr *pExpr){
77034
+ /* The NEVER() on the second term is because sqlite3FunctionUsesThisSrc()
77035
+ ** is always called before sqlite3ExprAnalyzeAggregates() and so the
77036
+ ** TK_COLUMNs have not yet been converted into TK_AGG_COLUMN. If
77037
+ ** sqlite3FunctionUsesThisSrc() is used differently in the future, the
77038
+ ** NEVER() will need to be removed. */
77039
+ if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
7690977040
int i;
76910
- SrcList *pSrc = pWalker->u.pSrcList;
77041
+ struct SrcCount *p = pWalker->u.pSrcCount;
77042
+ SrcList *pSrc = p->pSrc;
7691177043
for(i=0; i<pSrc->nSrc; i++){
76912
- if( pExpr->iTable==pSrc->a[i].iCursor ) return WRC_Continue;
77044
+ if( pExpr->iTable==pSrc->a[i].iCursor ) break;
7691377045
}
76914
- return WRC_Abort;
76915
- }else{
76916
- return WRC_Continue;
77046
+ if( i<pSrc->nSrc ){
77047
+ p->nThis++;
77048
+ }else{
77049
+ p->nOther++;
77050
+ }
7691777051
}
77052
+ return WRC_Continue;
7691877053
}
7691977054
7692077055
/*
76921
-** Determine if any of the arguments to the pExpr Function references
76922
-** any SrcList other than pSrcList. Return true if they do. Return
76923
-** false if pExpr has no argument or has only constant arguments or
76924
-** only references tables named in pSrcList.
77056
+** Determine if any of the arguments to the pExpr Function reference
77057
+** pSrcList. Return true if they do. Also return true if the function
77058
+** has no arguments or has only constant arguments. Return false if pExpr
77059
+** references columns but not columns of tables found in pSrcList.
7692577060
*/
76926
-static int sqlite3FunctionUsesOtherSrc(Expr *pExpr, SrcList *pSrcList){
77061
+SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){
7692777062
Walker w;
77063
+ struct SrcCount cnt;
7692877064
assert( pExpr->op==TK_AGG_FUNCTION );
7692977065
memset(&w, 0, sizeof(w));
76930
- w.xExprCallback = exprUsesOtherSrc;
76931
- w.u.pSrcList = pSrcList;
76932
- if( sqlite3WalkExprList(&w, pExpr->x.pList)!=WRC_Continue ) return 1;
76933
- return 0;
77066
+ w.xExprCallback = exprSrcCount;
77067
+ w.u.pSrcCount = &cnt;
77068
+ cnt.pSrc = pSrcList;
77069
+ cnt.nThis = 0;
77070
+ cnt.nOther = 0;
77071
+ sqlite3WalkExprList(&w, pExpr->x.pList);
77072
+ return cnt.nThis>0 || cnt.nOther==0;
7693477073
}
7693577074
7693677075
/*
7693777076
** Add a new element to the pAggInfo->aCol[] array. Return the index of
7693877077
** the new element. Return a negative number if malloc fails.
@@ -77047,11 +77186,11 @@
7704777186
}
7704877187
return WRC_Prune;
7704977188
}
7705077189
case TK_AGG_FUNCTION: {
7705177190
if( (pNC->ncFlags & NC_InAggFunc)==0
77052
- && !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList)
77191
+ && pWalker->walkerDepth==pExpr->op2
7705377192
){
7705477193
/* Check to see if pExpr is a duplicate of another aggregate
7705577194
** function that is already in the pAggInfo structure
7705677195
*/
7705777196
struct AggInfo_func *pItem = pAggInfo->aFunc;
@@ -80497,11 +80636,11 @@
8049780636
pNext = pIndex->pNext;
8049880637
assert( pIndex->pSchema==pTable->pSchema );
8049980638
if( !db || db->pnBytesFreed==0 ){
8050080639
char *zName = pIndex->zName;
8050180640
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
80502
- &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
80641
+ &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
8050380642
);
8050480643
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
8050580644
assert( pOld==pIndex || pOld==0 );
8050680645
}
8050780646
freeIndex(db, pIndex);
@@ -84653,11 +84792,11 @@
8465384792
8465484793
/* Collect rowids of every row to be deleted.
8465584794
*/
8465684795
sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
8465784796
pWInfo = sqlite3WhereBegin(
84658
- pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK
84797
+ pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
8465984798
);
8466084799
if( pWInfo==0 ) goto delete_from_cleanup;
8466184800
regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0);
8466284801
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
8466384802
if( db->flags & SQLITE_CountRows ){
@@ -87121,11 +87260,11 @@
8712187260
8712287261
/* Create VDBE to loop through the entries in pSrc that match the WHERE
8712387262
** clause. If the constraint is not deferred, throw an exception for
8712487263
** each row found. Otherwise, for deferred constraints, increment the
8712587264
** deferred constraint counter by nIncr for each row selected. */
87126
- pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0);
87265
+ pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
8712787266
if( nIncr>0 && pFKey->isDeferred==0 ){
8712887267
sqlite3ParseToplevel(pParse)->mayAbort = 1;
8712987268
}
8713087269
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
8713187270
if( pWInfo ){
@@ -96539,11 +96678,11 @@
9653996678
pExpr = p->pEList->a[0].pExpr;
9654096679
assert( pTab && !pTab->pSelect && pExpr );
9654196680
9654296681
if( IsVirtual(pTab) ) return 0;
9654396682
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
96544
- if( pAggInfo->nFunc==0 ) return 0;
96683
+ if( NEVER(pAggInfo->nFunc==0) ) return 0;
9654596684
if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
9654696685
if( pExpr->flags&EP_Distinct ) return 0;
9654796686
9654896687
return pTab;
9654996688
}
@@ -96911,11 +97050,11 @@
9691197050
#endif
9691297051
}
9691397052
9691497053
9691597054
/*
96916
-** This routine sets of a SELECT statement for processing. The
97055
+** This routine sets up a SELECT statement for processing. The
9691797056
** following is accomplished:
9691897057
**
9691997058
** * VDBE Cursor numbers are assigned to all FROM-clause terms.
9692097059
** * Ephemeral Table objects are created for all FROM-clause subqueries.
9692197060
** * ON and USING clauses are shifted into WHERE statements
@@ -96943,11 +97082,12 @@
9694397082
/*
9694497083
** Reset the aggregate accumulator.
9694597084
**
9694697085
** The aggregate accumulator is a set of memory cells that hold
9694797086
** intermediate results while calculating an aggregate. This
96948
-** routine simply stores NULLs in all of those memory cells.
97087
+** routine generates code that stores NULLs in all of those memory
97088
+** cells.
9694997089
*/
9695097090
static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
9695197091
Vdbe *v = pParse->pVdbe;
9695297092
int i;
9695397093
struct AggInfo_func *pFunc;
@@ -97413,11 +97553,11 @@
9741397553
/* Aggregate and non-aggregate queries are handled differently */
9741497554
if( !isAgg && pGroupBy==0 ){
9741597555
ExprList *pDist = (isDistinct ? p->pEList : 0);
9741697556
9741797557
/* Begin the database scan. */
97418
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0);
97558
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0,0);
9741997559
if( pWInfo==0 ) goto select_end;
9742097560
if( pWInfo->nRowOut < p->nSelectRow ) p->nSelectRow = pWInfo->nRowOut;
9742197561
9742297562
/* If sorting index that was created by a prior OP_OpenEphemeral
9742397563
** instruction ended up not being needed, then change the OP_OpenEphemeral
@@ -97586,11 +97726,11 @@
9758697726
** This might involve two separate loops with an OP_Sort in between, or
9758797727
** it might be a single loop that uses an index to extract information
9758897728
** in the right order to begin with.
9758997729
*/
9759097730
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
97591
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0);
97731
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0, 0);
9759297732
if( pWInfo==0 ) goto select_end;
9759397733
if( pGroupBy==0 ){
9759497734
/* The optimizer is able to deliver rows in group by order so
9759597735
** we do not have to sort. The OP_OpenEphemeral table will be
9759697736
** cancelled later because we still need to use the pKeyInfo
@@ -97855,11 +97995,11 @@
9785597995
/* This case runs if the aggregate has no GROUP BY clause. The
9785697996
** processing is much simpler since there is only a single row
9785797997
** of output.
9785897998
*/
9785997999
resetAccumulator(pParse, &sAggInfo);
97860
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, 0, flag);
98000
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax,0,flag,0);
9786198001
if( pWInfo==0 ){
9786298002
sqlite3ExprListDelete(db, pDel);
9786398003
goto select_end;
9786498004
}
9786598005
updateAccumulator(pParse, &sAggInfo);
@@ -99655,11 +99795,11 @@
9965599795
9965699796
/* Begin the database scan
9965799797
*/
9965899798
sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
9965999799
pWInfo = sqlite3WhereBegin(
99660
- pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED
99800
+ pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, 0
9966199801
);
9966299802
if( pWInfo==0 ) goto update_cleanup;
9966399803
okOnePass = pWInfo->okOnePass;
9966499804
9966599805
/* Remember the rowid of every item to be updated.
@@ -105084,11 +105224,11 @@
105084105224
assert( pIdx->nColumn>=nEq );
105085105225
for(j=0; j<nEq; j++){
105086105226
int r1;
105087105227
int k = pIdx->aiColumn[j];
105088105228
pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
105089
- if( NEVER(pTerm==0) ) break;
105229
+ if( pTerm==0 ) break;
105090105230
/* The following true for indices with redundant columns.
105091105231
** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
105092105232
testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
105093105233
testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
105094105234
r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
@@ -105759,10 +105899,12 @@
105759105899
** B: <after the loop>
105760105900
**
105761105901
*/
105762105902
WhereClause *pOrWc; /* The OR-clause broken out into subterms */
105763105903
SrcList *pOrTab; /* Shortened table list or OR-clause generation */
105904
+ Index *pCov = 0; /* Potential covering index (or NULL) */
105905
+ int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */
105764105906
105765105907
int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */
105766105908
int regRowset = 0; /* Register for RowSet object */
105767105909
int regRowid = 0; /* Register holding rowid */
105768105910
int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
@@ -105777,11 +105919,11 @@
105777105919
assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
105778105920
pOrWc = &pTerm->u.pOrInfo->wc;
105779105921
pLevel->op = OP_Return;
105780105922
pLevel->p1 = regReturn;
105781105923
105782
- /* Set up a new SrcList ni pOrTab containing the table being scanned
105924
+ /* Set up a new SrcList in pOrTab containing the table being scanned
105783105925
** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
105784105926
** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
105785105927
*/
105786105928
if( pWInfo->nLevel>1 ){
105787105929
int nNotReady; /* The number of notReady tables */
@@ -105854,12 +105996,14 @@
105854105996
pOrExpr = pAndExpr;
105855105997
}
105856105998
/* Loop through table entries that match term pOrTerm. */
105857105999
pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
105858106000
WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
105859
- WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY);
106001
+ WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur);
106002
+ assert( pSubWInfo || pParse->nErr || pParse->db->mallocFailed );
105860106003
if( pSubWInfo ){
106004
+ WhereLevel *pLvl;
105861106005
explainOneScan(
105862106006
pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
105863106007
);
105864106008
if( (wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
105865106009
int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
@@ -105875,16 +106019,41 @@
105875106019
** contained one or more AND term from a notReady table. The
105876106020
** terms from the notReady table could not be tested and will
105877106021
** need to be tested later.
105878106022
*/
105879106023
if( pSubWInfo->untestedTerms ) untestedTerms = 1;
106024
+
106025
+ /* If all of the OR-connected terms are optimized using the same
106026
+ ** index, and the index is opened using the same cursor number
106027
+ ** by each call to sqlite3WhereBegin() made by this loop, it may
106028
+ ** be possible to use that index as a covering index.
106029
+ **
106030
+ ** If the call to sqlite3WhereBegin() above resulted in a scan that
106031
+ ** uses an index, and this is either the first OR-connected term
106032
+ ** processed or the index is the same as that used by all previous
106033
+ ** terms, set pCov to the candidate covering index. Otherwise, set
106034
+ ** pCov to NULL to indicate that no candidate covering index will
106035
+ ** be available.
106036
+ */
106037
+ pLvl = &pSubWInfo->a[0];
106038
+ if( (pLvl->plan.wsFlags & WHERE_INDEXED)!=0
106039
+ && (pLvl->plan.wsFlags & WHERE_TEMP_INDEX)==0
106040
+ && (ii==0 || pLvl->plan.u.pIdx==pCov)
106041
+ ){
106042
+ assert( pLvl->iIdxCur==iCovCur );
106043
+ pCov = pLvl->plan.u.pIdx;
106044
+ }else{
106045
+ pCov = 0;
106046
+ }
105880106047
105881106048
/* Finish the loop through table entries that match term pOrTerm. */
105882106049
sqlite3WhereEnd(pSubWInfo);
105883106050
}
105884106051
}
105885106052
}
106053
+ pLevel->u.pCovidx = pCov;
106054
+ pLevel->iIdxCur = iCovCur;
105886106055
if( pAndExpr ){
105887106056
pAndExpr->pLeft = 0;
105888106057
sqlite3ExprDelete(pParse->db, pAndExpr);
105889106058
}
105890106059
sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
@@ -106098,11 +106267,12 @@
106098106267
Parse *pParse, /* The parser context */
106099106268
SrcList *pTabList, /* A list of all tables to be scanned */
106100106269
Expr *pWhere, /* The WHERE clause */
106101106270
ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */
106102106271
ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */
106103
- u16 wctrlFlags /* One of the WHERE_* flags defined in sqliteInt.h */
106272
+ u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
106273
+ int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
106104106274
){
106105106275
int i; /* Loop counter */
106106106276
int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
106107106277
int nTabList; /* Number of elements in pTabList */
106108106278
WhereInfo *pWInfo; /* Will become the return value of this function */
@@ -106418,11 +106588,17 @@
106418106588
andFlags &= bestPlan.plan.wsFlags;
106419106589
pLevel->plan = bestPlan.plan;
106420106590
testcase( bestPlan.plan.wsFlags & WHERE_INDEXED );
106421106591
testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX );
106422106592
if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){
106423
- pLevel->iIdxCur = pParse->nTab++;
106593
+ if( (wctrlFlags & WHERE_ONETABLE_ONLY)
106594
+ && (bestPlan.plan.wsFlags & WHERE_TEMP_INDEX)==0
106595
+ ){
106596
+ pLevel->iIdxCur = iIdxCur;
106597
+ }else{
106598
+ pLevel->iIdxCur = pParse->nTab++;
106599
+ }
106424106600
}else{
106425106601
pLevel->iIdxCur = -1;
106426106602
}
106427106603
notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
106428106604
pLevel->iFrom = (u8)bestJ;
@@ -106670,10 +106846,11 @@
106670106846
106671106847
/* Close all of the cursors that were opened by sqlite3WhereBegin.
106672106848
*/
106673106849
assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
106674106850
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
106851
+ Index *pIdx = 0;
106675106852
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
106676106853
Table *pTab = pTabItem->pTab;
106677106854
assert( pTab!=0 );
106678106855
if( (pTab->tabFlags & TF_Ephemeral)==0
106679106856
&& pTab->pSelect==0
@@ -106699,16 +106876,19 @@
106699106876
** sqlite3WhereEnd will have created code that references the table
106700106877
** directly. This loop scans all that code looking for opcodes
106701106878
** that reference the table and converts them into opcodes that
106702106879
** reference the index.
106703106880
*/
106704
- if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){
106881
+ if( pLevel->plan.wsFlags & WHERE_INDEXED ){
106882
+ pIdx = pLevel->plan.u.pIdx;
106883
+ }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
106884
+ pIdx = pLevel->u.pCovidx;
106885
+ }
106886
+ if( pIdx && !db->mallocFailed){
106705106887
int k, j, last;
106706106888
VdbeOp *pOp;
106707
- Index *pIdx = pLevel->plan.u.pIdx;
106708106889
106709
- assert( pIdx!=0 );
106710106890
pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
106711106891
last = sqlite3VdbeCurrentAddr(v);
106712106892
for(k=pWInfo->iTop; k<last; k++, pOp++){
106713106893
if( pOp->p1!=pLevel->iTabCur ) continue;
106714106894
if( pOp->opcode==OP_Column ){
@@ -115878,14 +116058,24 @@
115878116058
SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
115879116059
115880116060
SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
115881116061
SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
115882116062
116063
+#ifndef SQLITE_DISABLE_FTS4_DEFERRED
115883116064
SQLITE_PRIVATE void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *);
115884116065
SQLITE_PRIVATE int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int);
115885116066
SQLITE_PRIVATE int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *);
115886116067
SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *);
116068
+SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
116069
+#else
116070
+# define sqlite3Fts3FreeDeferredTokens(x)
116071
+# define sqlite3Fts3DeferToken(x,y,z) SQLITE_OK
116072
+# define sqlite3Fts3CacheDeferredDoclists(x) SQLITE_OK
116073
+# define sqlite3Fts3FreeDeferredDoclists(x)
116074
+# define sqlite3Fts3DeferredTokenList(x,y,z) SQLITE_OK
116075
+#endif
116076
+
115887116077
SQLITE_PRIVATE void sqlite3Fts3SegmentsClose(Fts3Table *);
115888116078
SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *, int *);
115889116079
115890116080
/* Special values interpreted by sqlite3SegReaderCursor() */
115891116081
#define FTS3_SEGCURSOR_PENDING -1
@@ -115990,12 +116180,10 @@
115990116180
Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *);
115991116181
SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
115992116182
SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
115993116183
SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
115994116184
115995
-SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
115996
-
115997116185
/* fts3_unicode2.c (functions generated by parsing unicode text files) */
115998116186
#ifdef SQLITE_ENABLE_FTS4_UNICODE61
115999116187
SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int);
116000116188
SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int);
116001116189
SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
@@ -120149,10 +120337,11 @@
120149120337
120150120338
/* Allocate a MultiSegReader for each token in the expression. */
120151120339
fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc);
120152120340
120153120341
/* Determine which, if any, tokens in the expression should be deferred. */
120342
+#ifndef SQLITE_DISABLE_FTS4_DEFERRED
120154120343
if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
120155120344
Fts3TokenAndCost *aTC;
120156120345
Fts3Expr **apOr;
120157120346
aTC = (Fts3TokenAndCost *)sqlite3_malloc(
120158120347
sizeof(Fts3TokenAndCost) * nToken
@@ -120179,10 +120368,11 @@
120179120368
}
120180120369
120181120370
sqlite3_free(aTC);
120182120371
}
120183120372
}
120373
+#endif
120184120374
120185120375
fts3EvalStartReaders(pCsr, pCsr->pExpr, 1, &rc);
120186120376
return rc;
120187120377
}
120188120378
@@ -120562,10 +120752,11 @@
120562120752
&& !fts3EvalTestExpr(pCsr, pExpr->pRight, pRc)
120563120753
);
120564120754
break;
120565120755
120566120756
default: {
120757
+#ifndef SQLITE_DISABLE_FTS4_DEFERRED
120567120758
if( pCsr->pDeferred
120568120759
&& (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred)
120569120760
){
120570120761
Fts3Phrase *pPhrase = pExpr->pPhrase;
120571120762
assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
@@ -120573,11 +120764,13 @@
120573120764
fts3EvalInvalidatePoslist(pPhrase);
120574120765
}
120575120766
*pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
120576120767
bHit = (pPhrase->doclist.pList!=0);
120577120768
pExpr->iDocid = pCsr->iPrevId;
120578
- }else{
120769
+ }else
120770
+#endif
120771
+ {
120579120772
bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId);
120580120773
}
120581120774
break;
120582120775
}
120583120776
}
@@ -129349,10 +129542,11 @@
129349129542
}
129350129543
129351129544
return rc;
129352129545
}
129353129546
129547
+#ifndef SQLITE_DISABLE_FTS4_DEFERRED
129354129548
/*
129355129549
** Delete all cached deferred doclists. Deferred doclists are cached
129356129550
** (allocated) by the sqlite3Fts3CacheDeferredDoclists() function.
129357129551
*/
129358129552
SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *pCsr){
@@ -129486,10 +129680,11 @@
129486129680
assert( pToken->pDeferred==0 );
129487129681
pToken->pDeferred = pDeferred;
129488129682
129489129683
return SQLITE_OK;
129490129684
}
129685
+#endif
129491129686
129492129687
/*
129493129688
** SQLite value pRowid contains the rowid of a row that may or may not be
129494129689
** present in the FTS3 table. If it is, delete it and adjust the contents
129495129690
** of subsiduary data structures accordingly.
129496129691
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.14"
677 #define SQLITE_VERSION_NUMBER 3007014
678 #define SQLITE_SOURCE_ID "2012-08-14 17:29:27 6954fef006431d153de6e63e362b8d260ebeb1c6"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -3723,12 +3723,15 @@
3723 ** ^The third argument is the value to bind to the parameter.
3724 **
3725 ** ^(In those routines that have a fourth argument, its value is the
3726 ** number of bytes in the parameter. To be clear: the value is the
3727 ** number of <u>bytes</u> in the value, not the number of characters.)^
3728 ** ^If the fourth parameter is negative, the length of the string is
 
3729 ** the number of bytes up to the first zero terminator.
 
 
3730 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3731 ** or sqlite3_bind_text16() then that parameter must be the byte offset
3732 ** where the NUL terminator would occur assuming the string were NUL
3733 ** terminated. If any NUL characters occur at byte offsets less than
3734 ** the value of the fourth parameter then the resulting string value will
@@ -10663,12 +10666,13 @@
10663 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
10664 ** TK_VARIABLE: variable number (always >= 1). */
10665 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
10666 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
10667 u8 flags2; /* Second set of flags. EP2_... */
10668 u8 op2; /* If a TK_REGISTER, the original value of Expr.op */
10669 /* If TK_COLUMN, the value of p5 for OP_Column */
 
10670 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
10671 Table *pTab; /* Table for TK_COLUMN expressions. */
10672 #if SQLITE_MAX_EXPR_DEPTH>0
10673 int nHeight; /* Height of the tree headed by this node */
10674 #endif
@@ -10919,10 +10923,11 @@
10919 struct InLoop {
10920 int iCur; /* The VDBE cursor used by this IN operator */
10921 int addrInTop; /* Top of the IN loop */
10922 } *aInLoop; /* Information about each nested IN operator */
10923 } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */
 
10924 } u;
10925
10926 /* The following field is really not part of the current level. But
10927 ** we need a place to cache virtual table index information for each
10928 ** virtual table in the FROM clause and the WhereLevel structure is
@@ -11471,14 +11476,16 @@
11471 */
11472 struct Walker {
11473 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
11474 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
11475 Parse *pParse; /* Parser context. */
 
11476 union { /* Extra data for callback */
11477 NameContext *pNC; /* Naming context */
11478 int i; /* Integer value */
11479 SrcList *pSrcList; /* FROM clause */
 
11480 } u;
11481 };
11482
11483 /* Forward declarations */
11484 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -11776,11 +11783,12 @@
11776 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
11777 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
11778 #endif
11779 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
11780 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
11781 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**,ExprList*,u16);
 
11782 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
11783 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
11784 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
11785 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
11786 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int);
@@ -11808,10 +11816,11 @@
11808 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
11809 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*);
11810 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*);
11811 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
11812 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
 
11813 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
11814 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
11815 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
11816 SQLITE_PRIVATE void sqlite3PrngResetState(void);
11817 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
@@ -15513,18 +15522,18 @@
15513 /* defer MT decisions to system malloc */
15514 _sqliteZone_ = malloc_default_zone();
15515 }else{
15516 /* only 1 core, use our own zone to contention over global locks,
15517 ** e.g. we have our own dedicated locks */
15518 bool success;
15519 malloc_zone_t* newzone = malloc_create_zone(4096, 0);
15520 malloc_set_zone_name(newzone, "Sqlite_Heap");
15521 do{
15522 success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone,
15523 (void * volatile *)&_sqliteZone_);
15524 }while(!_sqliteZone_);
15525 if( !success ){
15526 /* somebody registered a zone first */
15527 malloc_destroy_zone(newzone);
15528 }
15529 }
15530 #endif
@@ -23448,13 +23457,13 @@
23448 return SQLITE_BUSY;
23449
23450 case EACCES:
23451 /* EACCES is like EAGAIN during locking operations, but not any other time*/
23452 if( (sqliteIOErr == SQLITE_IOERR_LOCK) ||
23453 (sqliteIOErr == SQLITE_IOERR_UNLOCK) ||
23454 (sqliteIOErr == SQLITE_IOERR_RDLOCK) ||
23455 (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){
23456 return SQLITE_BUSY;
23457 }
23458 /* else fall through */
23459 case EPERM:
23460 return SQLITE_PERM;
@@ -24497,11 +24506,11 @@
24497 lock.l_start = lock.l_len = 0L;
24498 if( unixFileLock(pFile, &lock)==0 ){
24499 pInode->eFileLock = NO_LOCK;
24500 }else{
24501 rc = SQLITE_IOERR_UNLOCK;
24502 pFile->lastErrno = errno;
24503 pInode->eFileLock = NO_LOCK;
24504 pFile->eFileLock = NO_LOCK;
24505 }
24506 }
24507
@@ -24513,11 +24522,11 @@
24513 assert( pInode->nLock>=0 );
24514 if( pInode->nLock==0 ){
24515 closePendingFds(pFile);
24516 }
24517 }
24518
24519 end_unlock:
24520 unixLeaveMutex();
24521 if( rc==SQLITE_OK ) pFile->eFileLock = eFileLock;
24522 return rc;
24523 }
@@ -24780,11 +24789,11 @@
24780 char *zLockFile = (char *)pFile->lockingContext;
24781 int rc;
24782
24783 assert( pFile );
24784 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
24785 pFile->eFileLock, getpid()));
24786 assert( eFileLock<=SHARED_LOCK );
24787
24788 /* no-op if possible */
24789 if( pFile->eFileLock==eFileLock ){
24790 return SQLITE_OK;
@@ -25167,11 +25176,11 @@
25167 sem_t *pSem = pFile->pInode->pSem;
25168
25169 assert( pFile );
25170 assert( pSem );
25171 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
25172 pFile->eFileLock, getpid()));
25173 assert( eFileLock<=SHARED_LOCK );
25174
25175 /* no-op if possible */
25176 if( pFile->eFileLock==eFileLock ){
25177 return SQLITE_OK;
@@ -25757,11 +25766,11 @@
25757 SimulateIOError( newOffset-- );
25758 if( newOffset!=offset ){
25759 if( newOffset == -1 ){
25760 ((unixFile*)id)->lastErrno = errno;
25761 }else{
25762 ((unixFile*)id)->lastErrno = 0;
25763 }
25764 return -1;
25765 }
25766 got = osRead(id->h, pBuf, cnt);
25767 #endif
@@ -25845,11 +25854,11 @@
25845 SimulateIOError( newOffset-- );
25846 if( newOffset!=offset ){
25847 if( newOffset == -1 ){
25848 ((unixFile*)id)->lastErrno = errno;
25849 }else{
25850 ((unixFile*)id)->lastErrno = 0;
25851 }
25852 return -1;
25853 }
25854 got = osWrite(id->h, pBuf, cnt);
25855 }while( got<0 && errno==EINTR );
@@ -28359,11 +28368,11 @@
28359 ** with _IOWR('z', 23, struct ByteRangeLockPB2) to track the same 5 states.
28360 ** To simulate a F_RDLCK on the shared range, on AFP a randomly selected
28361 ** address in the shared range is taken for a SHARED lock, the entire
28362 ** shared range is taken for an EXCLUSIVE lock):
28363 **
28364 ** PENDING_BYTE 0x40000000
28365 ** RESERVED_BYTE 0x40000001
28366 ** SHARED_RANGE 0x40000002 -> 0x40000200
28367 **
28368 ** This works well on the local file system, but shows a nearly 100x
28369 ** slowdown in read performance on AFP because the AFP client disables
@@ -29879,13 +29888,15 @@
29879
29880 #ifndef FILE_ATTRIBUTE_MASK
29881 # define FILE_ATTRIBUTE_MASK (0x0003FFF7)
29882 #endif
29883
 
29884 /* Forward references */
29885 typedef struct winShm winShm; /* A connection to shared-memory */
29886 typedef struct winShmNode winShmNode; /* A region of shared-memory */
 
29887
29888 /*
29889 ** WinCE lacks native support for file locking so we have to fake it
29890 ** with some code of our own.
29891 */
@@ -29909,11 +29920,13 @@
29909 HANDLE h; /* Handle for accessing the file */
29910 u8 locktype; /* Type of lock currently held on this file */
29911 short sharedLockByte; /* Randomly chosen byte used as a shared lock */
29912 u8 ctrlFlags; /* Flags. See WINFILE_* below */
29913 DWORD lastErrno; /* The Windows errno from the last I/O error */
 
29914 winShm *pShm; /* Instance of shared memory on this file */
 
29915 const char *zPath; /* Full pathname of this file */
29916 int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
29917 #if SQLITE_OS_WINCE
29918 LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
29919 HANDLE hMutex; /* Mutex used to control access to shared lock */
@@ -29934,10 +29947,26 @@
29934 */
29935 #ifndef SQLITE_WIN32_DBG_BUF_SIZE
29936 # define SQLITE_WIN32_DBG_BUF_SIZE ((int)(4096-sizeof(DWORD)))
29937 #endif
29938
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29939 /*
29940 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
29941 * various Win32 API heap functions instead of our own.
29942 */
29943 #ifdef SQLITE_WIN32_MALLOC
@@ -31147,10 +31176,46 @@
31147 zFilenameMbcs = unicodeToMbcs(zTmpWide);
31148 sqlite3_free(zTmpWide);
31149 return zFilenameMbcs;
31150 }
31151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31152
31153 /*
31154 ** The return value of getLastErrorMsg
31155 ** is zero if the error message fits in the buffer, or non-zero
31156 ** otherwise (if the message was truncated).
@@ -31763,11 +31828,13 @@
31763 static int winClose(sqlite3_file *id){
31764 int rc, cnt = 0;
31765 winFile *pFile = (winFile*)id;
31766
31767 assert( id!=0 );
 
31768 assert( pFile->pShm==0 );
 
31769 OSTRACE(("CLOSE %d\n", pFile->h));
31770 do{
31771 rc = osCloseHandle(pFile->h);
31772 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
31773 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
@@ -33513,11 +33580,13 @@
33513 memset(pFile, 0, sizeof(*pFile));
33514 pFile->pMethod = &winIoMethod;
33515 pFile->h = h;
33516 pFile->lastErrno = NO_ERROR;
33517 pFile->pVfs = pVfs;
 
33518 pFile->pShm = 0;
 
33519 pFile->zPath = zName;
33520 if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
33521 pFile->ctrlFlags |= WINFILE_PSOW;
33522 }
33523
@@ -49289,11 +49358,11 @@
49289 }
49290 next = get2byte(&data[pc]);
49291 size = get2byte(&data[pc+2]);
49292 if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
49293 /* Free blocks must be in ascending order. And the last byte of
49294 ** the free-block must lie on the database page. */
49295 return SQLITE_CORRUPT_BKPT;
49296 }
49297 nFree = nFree + size;
49298 pc = next;
49299 }
@@ -50463,11 +50532,11 @@
50463 if( rc==SQLITE_OK ){
50464 if( p->inTrans==TRANS_NONE ){
50465 pBt->nTransaction++;
50466 #ifndef SQLITE_OMIT_SHARED_CACHE
50467 if( p->sharable ){
50468 assert( p->lock.pBtree==p && p->lock.iTable==1 );
50469 p->lock.eLock = READ_LOCK;
50470 p->lock.pNext = pBt->pLock;
50471 pBt->pLock = &p->lock;
50472 }
50473 #endif
@@ -54301,10 +54370,11 @@
54301 while( i==iNextOld ){
54302 /* Cell i is the cell immediately following the last cell on old
54303 ** sibling page j. If the siblings are not leaf pages of an
54304 ** intkey b-tree, then cell i was a divider cell. */
54305 assert( j+1 < ArraySize(apCopy) );
 
54306 pOld = apCopy[++j];
54307 iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
54308 if( pOld->nOverflow ){
54309 nOverflow = pOld->nOverflow;
54310 iOverflow = i + !leafData + pOld->aiOvfl[0];
@@ -56135,11 +56205,10 @@
56135 */
56136 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){
56137 assert( mask==BTREE_BULKLOAD || mask==0 );
56138 pCsr->hints = mask;
56139 }
56140
56141
56142 /************** End of btree.c ***********************************************/
56143 /************** Begin file backup.c ******************************************/
56144 /*
56145 ** 2009 January 28
@@ -70367,11 +70436,11 @@
70367 if( iBuf==0 ){
70368 int nRead; /* Bytes to read from disk */
70369 int rc; /* sqlite3OsRead() return code */
70370
70371 /* Determine how many bytes of data to read. */
70372 nRead = p->iEof - p->iReadOff;
70373 if( nRead>p->nBuffer ) nRead = p->nBuffer;
70374 assert( nRead>0 );
70375
70376 /* Read data from the file. Return early if an error occurs. */
70377 rc = sqlite3OsRead(p->pFile, p->aBuffer, nRead, p->iReadOff);
@@ -70472,11 +70541,11 @@
70472 }
70473
70474 rc = vdbeSorterIterVarint(db, pIter, &nRec);
70475 if( rc==SQLITE_OK ){
70476 pIter->nKey = (int)nRec;
70477 rc = vdbeSorterIterRead(db, pIter, nRec, &pIter->aKey);
70478 }
70479
70480 return rc;
70481 }
70482
@@ -70515,11 +70584,11 @@
70515
70516 iBuf = iStart % nBuf;
70517 if( iBuf ){
70518 int nRead = nBuf - iBuf;
70519 if( (iStart + nRead) > pSorter->iWriteOff ){
70520 nRead = pSorter->iWriteOff - iStart;
70521 }
70522 rc = sqlite3OsRead(
70523 pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart
70524 );
70525 assert( rc!=SQLITE_IOERR_SHORT_READ );
@@ -71838,17 +71907,23 @@
71838 */
71839 SQLITE_PRIVATE int sqlite3WalkSelect(Walker *pWalker, Select *p){
71840 int rc;
71841 if( p==0 || pWalker->xSelectCallback==0 ) return WRC_Continue;
71842 rc = WRC_Continue;
71843 while( p ){
 
71844 rc = pWalker->xSelectCallback(pWalker, p);
71845 if( rc ) break;
71846 if( sqlite3WalkSelectExpr(pWalker, p) ) return WRC_Abort;
71847 if( sqlite3WalkSelectFrom(pWalker, p) ) return WRC_Abort;
 
 
 
 
71848 p = p->pPrior;
71849 }
 
71850 return rc & WRC_Abort;
71851 }
71852
71853 /************** End of walker.c **********************************************/
71854 /************** Begin file resolve.c *****************************************/
@@ -71868,10 +71943,33 @@
71868 ** resolve all identifiers by associating them with a particular
71869 ** table and column.
71870 */
71871 /* #include <stdlib.h> */
71872 /* #include <string.h> */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71873
71874 /*
71875 ** Turn the pExpr expression into an alias for the iCol-th column of the
71876 ** result set in pEList.
71877 **
@@ -71895,17 +71993,24 @@
71895 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
71896 **
71897 ** The result of random()%5 in the GROUP BY clause is probably different
71898 ** from the result in the result-set. We might fix this someday. Or
71899 ** then again, we might not...
 
 
 
 
 
 
71900 */
71901 static void resolveAlias(
71902 Parse *pParse, /* Parsing context */
71903 ExprList *pEList, /* A result set */
71904 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
71905 Expr *pExpr, /* Transform this into an alias to the result set */
71906 const char *zType /* "GROUP" or "ORDER" or "" */
 
71907 ){
71908 Expr *pOrig; /* The iCol-th column of the result set */
71909 Expr *pDup; /* Copy of pOrig */
71910 sqlite3 *db; /* The database connection */
71911
@@ -71914,10 +72019,11 @@
71914 assert( pOrig!=0 );
71915 assert( pOrig->flags & EP_Resolved );
71916 db = pParse->db;
71917 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
71918 pDup = sqlite3ExprDup(db, pOrig, 0);
 
71919 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
71920 if( pDup==0 ) return;
71921 if( pEList->a[iCol].iAlias==0 ){
71922 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
71923 }
@@ -72002,13 +72108,14 @@
72002 const char *zTab, /* Name of table containing column, or NULL */
72003 const char *zCol, /* Name of the column. */
72004 NameContext *pNC, /* The name context used to resolve the name */
72005 Expr *pExpr /* Make this EXPR node point to the selected column */
72006 ){
72007 int i, j; /* Loop counters */
72008 int cnt = 0; /* Number of matching column names */
72009 int cntTab = 0; /* Number of matching table names */
 
72010 sqlite3 *db = pParse->db; /* The database connection */
72011 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
72012 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
72013 NameContext *pTopNC = pNC; /* First namecontext in the list */
72014 Schema *pSchema = 0; /* Schema of the expression */
@@ -72166,11 +72273,11 @@
72166 pOrig = pEList->a[j].pExpr;
72167 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
72168 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
72169 return WRC_Abort;
72170 }
72171 resolveAlias(pParse, pEList, j, pExpr, "");
72172 cnt = 1;
72173 pMatch = 0;
72174 assert( zTab==0 && zDb==0 );
72175 goto lookupname_end;
72176 }
@@ -72180,10 +72287,11 @@
72180 /* Advance to the next name context. The loop will exit when either
72181 ** we have a match (cnt>0) or when we run out of name contexts.
72182 */
72183 if( cnt==0 ){
72184 pNC = pNC->pNext;
 
72185 }
72186 }
72187
72188 /*
72189 ** If X and Y are NULL (in other words if only the column name Z is
@@ -72419,17 +72527,23 @@
72419 }else if( wrong_num_args ){
72420 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
72421 nId, zId);
72422 pNC->nErr++;
72423 }
72424 if( is_agg ){
72425 pExpr->op = TK_AGG_FUNCTION;
72426 pNC->ncFlags |= NC_HasAgg;
72427 }
72428 if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg;
72429 sqlite3WalkExprList(pWalker, pList);
72430 if( is_agg ) pNC->ncFlags |= NC_AllowAgg;
 
 
 
 
 
 
 
 
 
 
72431 /* FIX ME: Compute pExpr->affinity based on the expected return
72432 ** type of the function
72433 */
72434 return WRC_Prune;
72435 }
@@ -72704,11 +72818,11 @@
72704 if( pItem->iOrderByCol ){
72705 if( pItem->iOrderByCol>pEList->nExpr ){
72706 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
72707 return 1;
72708 }
72709 resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType);
72710 }
72711 }
72712 return 0;
72713 }
72714
@@ -76204,13 +76318,16 @@
76204 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
76205 pFarg = 0;
76206 }else{
76207 pFarg = pExpr->x.pList;
76208 }
76209 sqlite3ExplainPrintf(pOut, "%sFUNCTION:%s(",
76210 op==TK_AGG_FUNCTION ? "AGG_" : "",
76211 pExpr->u.zToken);
 
 
 
76212 if( pFarg ){
76213 sqlite3ExplainExprList(pOut, pFarg);
76214 }
76215 sqlite3ExplainPrintf(pOut, ")");
76216 break;
@@ -76897,42 +77014,64 @@
76897 }
76898 return 0;
76899 }
76900
76901 /*
76902 ** This is the expression callback for sqlite3FunctionUsesOtherSrc().
76903 **
76904 ** Determine if an expression references any table other than one of the
76905 ** tables in pWalker->u.pSrcList and abort if it does.
76906 */
76907 static int exprUsesOtherSrc(Walker *pWalker, Expr *pExpr){
76908 if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76909 int i;
76910 SrcList *pSrc = pWalker->u.pSrcList;
 
76911 for(i=0; i<pSrc->nSrc; i++){
76912 if( pExpr->iTable==pSrc->a[i].iCursor ) return WRC_Continue;
76913 }
76914 return WRC_Abort;
76915 }else{
76916 return WRC_Continue;
 
 
76917 }
 
76918 }
76919
76920 /*
76921 ** Determine if any of the arguments to the pExpr Function references
76922 ** any SrcList other than pSrcList. Return true if they do. Return
76923 ** false if pExpr has no argument or has only constant arguments or
76924 ** only references tables named in pSrcList.
76925 */
76926 static int sqlite3FunctionUsesOtherSrc(Expr *pExpr, SrcList *pSrcList){
76927 Walker w;
 
76928 assert( pExpr->op==TK_AGG_FUNCTION );
76929 memset(&w, 0, sizeof(w));
76930 w.xExprCallback = exprUsesOtherSrc;
76931 w.u.pSrcList = pSrcList;
76932 if( sqlite3WalkExprList(&w, pExpr->x.pList)!=WRC_Continue ) return 1;
76933 return 0;
 
 
 
76934 }
76935
76936 /*
76937 ** Add a new element to the pAggInfo->aCol[] array. Return the index of
76938 ** the new element. Return a negative number if malloc fails.
@@ -77047,11 +77186,11 @@
77047 }
77048 return WRC_Prune;
77049 }
77050 case TK_AGG_FUNCTION: {
77051 if( (pNC->ncFlags & NC_InAggFunc)==0
77052 && !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList)
77053 ){
77054 /* Check to see if pExpr is a duplicate of another aggregate
77055 ** function that is already in the pAggInfo structure
77056 */
77057 struct AggInfo_func *pItem = pAggInfo->aFunc;
@@ -80497,11 +80636,11 @@
80497 pNext = pIndex->pNext;
80498 assert( pIndex->pSchema==pTable->pSchema );
80499 if( !db || db->pnBytesFreed==0 ){
80500 char *zName = pIndex->zName;
80501 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
80502 &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
80503 );
80504 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
80505 assert( pOld==pIndex || pOld==0 );
80506 }
80507 freeIndex(db, pIndex);
@@ -84653,11 +84792,11 @@
84653
84654 /* Collect rowids of every row to be deleted.
84655 */
84656 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
84657 pWInfo = sqlite3WhereBegin(
84658 pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK
84659 );
84660 if( pWInfo==0 ) goto delete_from_cleanup;
84661 regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0);
84662 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
84663 if( db->flags & SQLITE_CountRows ){
@@ -87121,11 +87260,11 @@
87121
87122 /* Create VDBE to loop through the entries in pSrc that match the WHERE
87123 ** clause. If the constraint is not deferred, throw an exception for
87124 ** each row found. Otherwise, for deferred constraints, increment the
87125 ** deferred constraint counter by nIncr for each row selected. */
87126 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0);
87127 if( nIncr>0 && pFKey->isDeferred==0 ){
87128 sqlite3ParseToplevel(pParse)->mayAbort = 1;
87129 }
87130 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
87131 if( pWInfo ){
@@ -96539,11 +96678,11 @@
96539 pExpr = p->pEList->a[0].pExpr;
96540 assert( pTab && !pTab->pSelect && pExpr );
96541
96542 if( IsVirtual(pTab) ) return 0;
96543 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
96544 if( pAggInfo->nFunc==0 ) return 0;
96545 if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
96546 if( pExpr->flags&EP_Distinct ) return 0;
96547
96548 return pTab;
96549 }
@@ -96911,11 +97050,11 @@
96911 #endif
96912 }
96913
96914
96915 /*
96916 ** This routine sets of a SELECT statement for processing. The
96917 ** following is accomplished:
96918 **
96919 ** * VDBE Cursor numbers are assigned to all FROM-clause terms.
96920 ** * Ephemeral Table objects are created for all FROM-clause subqueries.
96921 ** * ON and USING clauses are shifted into WHERE statements
@@ -96943,11 +97082,12 @@
96943 /*
96944 ** Reset the aggregate accumulator.
96945 **
96946 ** The aggregate accumulator is a set of memory cells that hold
96947 ** intermediate results while calculating an aggregate. This
96948 ** routine simply stores NULLs in all of those memory cells.
 
96949 */
96950 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
96951 Vdbe *v = pParse->pVdbe;
96952 int i;
96953 struct AggInfo_func *pFunc;
@@ -97413,11 +97553,11 @@
97413 /* Aggregate and non-aggregate queries are handled differently */
97414 if( !isAgg && pGroupBy==0 ){
97415 ExprList *pDist = (isDistinct ? p->pEList : 0);
97416
97417 /* Begin the database scan. */
97418 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0);
97419 if( pWInfo==0 ) goto select_end;
97420 if( pWInfo->nRowOut < p->nSelectRow ) p->nSelectRow = pWInfo->nRowOut;
97421
97422 /* If sorting index that was created by a prior OP_OpenEphemeral
97423 ** instruction ended up not being needed, then change the OP_OpenEphemeral
@@ -97586,11 +97726,11 @@
97586 ** This might involve two separate loops with an OP_Sort in between, or
97587 ** it might be a single loop that uses an index to extract information
97588 ** in the right order to begin with.
97589 */
97590 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
97591 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0);
97592 if( pWInfo==0 ) goto select_end;
97593 if( pGroupBy==0 ){
97594 /* The optimizer is able to deliver rows in group by order so
97595 ** we do not have to sort. The OP_OpenEphemeral table will be
97596 ** cancelled later because we still need to use the pKeyInfo
@@ -97855,11 +97995,11 @@
97855 /* This case runs if the aggregate has no GROUP BY clause. The
97856 ** processing is much simpler since there is only a single row
97857 ** of output.
97858 */
97859 resetAccumulator(pParse, &sAggInfo);
97860 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, 0, flag);
97861 if( pWInfo==0 ){
97862 sqlite3ExprListDelete(db, pDel);
97863 goto select_end;
97864 }
97865 updateAccumulator(pParse, &sAggInfo);
@@ -99655,11 +99795,11 @@
99655
99656 /* Begin the database scan
99657 */
99658 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
99659 pWInfo = sqlite3WhereBegin(
99660 pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED
99661 );
99662 if( pWInfo==0 ) goto update_cleanup;
99663 okOnePass = pWInfo->okOnePass;
99664
99665 /* Remember the rowid of every item to be updated.
@@ -105084,11 +105224,11 @@
105084 assert( pIdx->nColumn>=nEq );
105085 for(j=0; j<nEq; j++){
105086 int r1;
105087 int k = pIdx->aiColumn[j];
105088 pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
105089 if( NEVER(pTerm==0) ) break;
105090 /* The following true for indices with redundant columns.
105091 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
105092 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
105093 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
105094 r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
@@ -105759,10 +105899,12 @@
105759 ** B: <after the loop>
105760 **
105761 */
105762 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
105763 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
 
 
105764
105765 int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */
105766 int regRowset = 0; /* Register for RowSet object */
105767 int regRowid = 0; /* Register holding rowid */
105768 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
@@ -105777,11 +105919,11 @@
105777 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
105778 pOrWc = &pTerm->u.pOrInfo->wc;
105779 pLevel->op = OP_Return;
105780 pLevel->p1 = regReturn;
105781
105782 /* Set up a new SrcList ni pOrTab containing the table being scanned
105783 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
105784 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
105785 */
105786 if( pWInfo->nLevel>1 ){
105787 int nNotReady; /* The number of notReady tables */
@@ -105854,12 +105996,14 @@
105854 pOrExpr = pAndExpr;
105855 }
105856 /* Loop through table entries that match term pOrTerm. */
105857 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
105858 WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
105859 WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY);
 
105860 if( pSubWInfo ){
 
105861 explainOneScan(
105862 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
105863 );
105864 if( (wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
105865 int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
@@ -105875,16 +106019,41 @@
105875 ** contained one or more AND term from a notReady table. The
105876 ** terms from the notReady table could not be tested and will
105877 ** need to be tested later.
105878 */
105879 if( pSubWInfo->untestedTerms ) untestedTerms = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105880
105881 /* Finish the loop through table entries that match term pOrTerm. */
105882 sqlite3WhereEnd(pSubWInfo);
105883 }
105884 }
105885 }
 
 
105886 if( pAndExpr ){
105887 pAndExpr->pLeft = 0;
105888 sqlite3ExprDelete(pParse->db, pAndExpr);
105889 }
105890 sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
@@ -106098,11 +106267,12 @@
106098 Parse *pParse, /* The parser context */
106099 SrcList *pTabList, /* A list of all tables to be scanned */
106100 Expr *pWhere, /* The WHERE clause */
106101 ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */
106102 ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */
106103 u16 wctrlFlags /* One of the WHERE_* flags defined in sqliteInt.h */
 
106104 ){
106105 int i; /* Loop counter */
106106 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
106107 int nTabList; /* Number of elements in pTabList */
106108 WhereInfo *pWInfo; /* Will become the return value of this function */
@@ -106418,11 +106588,17 @@
106418 andFlags &= bestPlan.plan.wsFlags;
106419 pLevel->plan = bestPlan.plan;
106420 testcase( bestPlan.plan.wsFlags & WHERE_INDEXED );
106421 testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX );
106422 if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){
106423 pLevel->iIdxCur = pParse->nTab++;
 
 
 
 
 
 
106424 }else{
106425 pLevel->iIdxCur = -1;
106426 }
106427 notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
106428 pLevel->iFrom = (u8)bestJ;
@@ -106670,10 +106846,11 @@
106670
106671 /* Close all of the cursors that were opened by sqlite3WhereBegin.
106672 */
106673 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
106674 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
 
106675 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
106676 Table *pTab = pTabItem->pTab;
106677 assert( pTab!=0 );
106678 if( (pTab->tabFlags & TF_Ephemeral)==0
106679 && pTab->pSelect==0
@@ -106699,16 +106876,19 @@
106699 ** sqlite3WhereEnd will have created code that references the table
106700 ** directly. This loop scans all that code looking for opcodes
106701 ** that reference the table and converts them into opcodes that
106702 ** reference the index.
106703 */
106704 if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){
 
 
 
 
 
106705 int k, j, last;
106706 VdbeOp *pOp;
106707 Index *pIdx = pLevel->plan.u.pIdx;
106708
106709 assert( pIdx!=0 );
106710 pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
106711 last = sqlite3VdbeCurrentAddr(v);
106712 for(k=pWInfo->iTop; k<last; k++, pOp++){
106713 if( pOp->p1!=pLevel->iTabCur ) continue;
106714 if( pOp->opcode==OP_Column ){
@@ -115878,14 +116058,24 @@
115878 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
115879
115880 SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
115881 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
115882
 
115883 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *);
115884 SQLITE_PRIVATE int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int);
115885 SQLITE_PRIVATE int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *);
115886 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *);
 
 
 
 
 
 
 
 
 
115887 SQLITE_PRIVATE void sqlite3Fts3SegmentsClose(Fts3Table *);
115888 SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *, int *);
115889
115890 /* Special values interpreted by sqlite3SegReaderCursor() */
115891 #define FTS3_SEGCURSOR_PENDING -1
@@ -115990,12 +116180,10 @@
115990 Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *);
115991 SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
115992 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
115993 SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
115994
115995 SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
115996
115997 /* fts3_unicode2.c (functions generated by parsing unicode text files) */
115998 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
115999 SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int);
116000 SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int);
116001 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
@@ -120149,10 +120337,11 @@
120149
120150 /* Allocate a MultiSegReader for each token in the expression. */
120151 fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc);
120152
120153 /* Determine which, if any, tokens in the expression should be deferred. */
 
120154 if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
120155 Fts3TokenAndCost *aTC;
120156 Fts3Expr **apOr;
120157 aTC = (Fts3TokenAndCost *)sqlite3_malloc(
120158 sizeof(Fts3TokenAndCost) * nToken
@@ -120179,10 +120368,11 @@
120179 }
120180
120181 sqlite3_free(aTC);
120182 }
120183 }
 
120184
120185 fts3EvalStartReaders(pCsr, pCsr->pExpr, 1, &rc);
120186 return rc;
120187 }
120188
@@ -120562,10 +120752,11 @@
120562 && !fts3EvalTestExpr(pCsr, pExpr->pRight, pRc)
120563 );
120564 break;
120565
120566 default: {
 
120567 if( pCsr->pDeferred
120568 && (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred)
120569 ){
120570 Fts3Phrase *pPhrase = pExpr->pPhrase;
120571 assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
@@ -120573,11 +120764,13 @@
120573 fts3EvalInvalidatePoslist(pPhrase);
120574 }
120575 *pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
120576 bHit = (pPhrase->doclist.pList!=0);
120577 pExpr->iDocid = pCsr->iPrevId;
120578 }else{
 
 
120579 bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId);
120580 }
120581 break;
120582 }
120583 }
@@ -129349,10 +129542,11 @@
129349 }
129350
129351 return rc;
129352 }
129353
 
129354 /*
129355 ** Delete all cached deferred doclists. Deferred doclists are cached
129356 ** (allocated) by the sqlite3Fts3CacheDeferredDoclists() function.
129357 */
129358 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *pCsr){
@@ -129486,10 +129680,11 @@
129486 assert( pToken->pDeferred==0 );
129487 pToken->pDeferred = pDeferred;
129488
129489 return SQLITE_OK;
129490 }
 
129491
129492 /*
129493 ** SQLite value pRowid contains the rowid of a row that may or may not be
129494 ** present in the FTS3 table. If it is, delete it and adjust the contents
129495 ** of subsiduary data structures accordingly.
129496
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.14"
677 #define SQLITE_VERSION_NUMBER 3007014
678 #define SQLITE_SOURCE_ID "2012-08-24 23:56:19 62678be3df35cdcb09172ba8c860f7b73517f1ea"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -3723,12 +3723,15 @@
3723 ** ^The third argument is the value to bind to the parameter.
3724 **
3725 ** ^(In those routines that have a fourth argument, its value is the
3726 ** number of bytes in the parameter. To be clear: the value is the
3727 ** number of <u>bytes</u> in the value, not the number of characters.)^
3728 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3729 ** is negative, then the length of the string is
3730 ** the number of bytes up to the first zero terminator.
3731 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3732 ** the behavior is undefined.
3733 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3734 ** or sqlite3_bind_text16() then that parameter must be the byte offset
3735 ** where the NUL terminator would occur assuming the string were NUL
3736 ** terminated. If any NUL characters occur at byte offsets less than
3737 ** the value of the fourth parameter then the resulting string value will
@@ -10663,12 +10666,13 @@
10666 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
10667 ** TK_VARIABLE: variable number (always >= 1). */
10668 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
10669 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
10670 u8 flags2; /* Second set of flags. EP2_... */
10671 u8 op2; /* TK_REGISTER: original value of Expr.op
10672 ** TK_COLUMN: the value of p5 for OP_Column
10673 ** TK_AGG_FUNCTION: nesting depth */
10674 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
10675 Table *pTab; /* Table for TK_COLUMN expressions. */
10676 #if SQLITE_MAX_EXPR_DEPTH>0
10677 int nHeight; /* Height of the tree headed by this node */
10678 #endif
@@ -10919,10 +10923,11 @@
10923 struct InLoop {
10924 int iCur; /* The VDBE cursor used by this IN operator */
10925 int addrInTop; /* Top of the IN loop */
10926 } *aInLoop; /* Information about each nested IN operator */
10927 } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */
10928 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
10929 } u;
10930
10931 /* The following field is really not part of the current level. But
10932 ** we need a place to cache virtual table index information for each
10933 ** virtual table in the FROM clause and the WhereLevel structure is
@@ -11471,14 +11476,16 @@
11476 */
11477 struct Walker {
11478 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
11479 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
11480 Parse *pParse; /* Parser context. */
11481 int walkerDepth; /* Number of subqueries */
11482 union { /* Extra data for callback */
11483 NameContext *pNC; /* Naming context */
11484 int i; /* Integer value */
11485 SrcList *pSrcList; /* FROM clause */
11486 struct SrcCount *pSrcCount; /* Counting column references */
11487 } u;
11488 };
11489
11490 /* Forward declarations */
11491 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -11776,11 +11783,12 @@
11783 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
11784 SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *);
11785 #endif
11786 SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
11787 SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
11788 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
11789 Parse*,SrcList*,Expr*,ExprList**,ExprList*,u16,int);
11790 SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*);
11791 SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8);
11792 SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int);
11793 SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int);
11794 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int);
@@ -11808,10 +11816,11 @@
11816 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
11817 SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*);
11818 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*);
11819 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
11820 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
11821 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
11822 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
11823 SQLITE_PRIVATE void sqlite3PrngSaveState(void);
11824 SQLITE_PRIVATE void sqlite3PrngRestoreState(void);
11825 SQLITE_PRIVATE void sqlite3PrngResetState(void);
11826 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int);
@@ -15513,18 +15522,18 @@
15522 /* defer MT decisions to system malloc */
15523 _sqliteZone_ = malloc_default_zone();
15524 }else{
15525 /* only 1 core, use our own zone to contention over global locks,
15526 ** e.g. we have our own dedicated locks */
15527 bool success;
15528 malloc_zone_t* newzone = malloc_create_zone(4096, 0);
15529 malloc_set_zone_name(newzone, "Sqlite_Heap");
15530 do{
15531 success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone,
15532 (void * volatile *)&_sqliteZone_);
15533 }while(!_sqliteZone_);
15534 if( !success ){
15535 /* somebody registered a zone first */
15536 malloc_destroy_zone(newzone);
15537 }
15538 }
15539 #endif
@@ -23448,13 +23457,13 @@
23457 return SQLITE_BUSY;
23458
23459 case EACCES:
23460 /* EACCES is like EAGAIN during locking operations, but not any other time*/
23461 if( (sqliteIOErr == SQLITE_IOERR_LOCK) ||
23462 (sqliteIOErr == SQLITE_IOERR_UNLOCK) ||
23463 (sqliteIOErr == SQLITE_IOERR_RDLOCK) ||
23464 (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){
23465 return SQLITE_BUSY;
23466 }
23467 /* else fall through */
23468 case EPERM:
23469 return SQLITE_PERM;
@@ -24497,11 +24506,11 @@
24506 lock.l_start = lock.l_len = 0L;
24507 if( unixFileLock(pFile, &lock)==0 ){
24508 pInode->eFileLock = NO_LOCK;
24509 }else{
24510 rc = SQLITE_IOERR_UNLOCK;
24511 pFile->lastErrno = errno;
24512 pInode->eFileLock = NO_LOCK;
24513 pFile->eFileLock = NO_LOCK;
24514 }
24515 }
24516
@@ -24513,11 +24522,11 @@
24522 assert( pInode->nLock>=0 );
24523 if( pInode->nLock==0 ){
24524 closePendingFds(pFile);
24525 }
24526 }
24527
24528 end_unlock:
24529 unixLeaveMutex();
24530 if( rc==SQLITE_OK ) pFile->eFileLock = eFileLock;
24531 return rc;
24532 }
@@ -24780,11 +24789,11 @@
24789 char *zLockFile = (char *)pFile->lockingContext;
24790 int rc;
24791
24792 assert( pFile );
24793 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
24794 pFile->eFileLock, getpid()));
24795 assert( eFileLock<=SHARED_LOCK );
24796
24797 /* no-op if possible */
24798 if( pFile->eFileLock==eFileLock ){
24799 return SQLITE_OK;
@@ -25167,11 +25176,11 @@
25176 sem_t *pSem = pFile->pInode->pSem;
25177
25178 assert( pFile );
25179 assert( pSem );
25180 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
25181 pFile->eFileLock, getpid()));
25182 assert( eFileLock<=SHARED_LOCK );
25183
25184 /* no-op if possible */
25185 if( pFile->eFileLock==eFileLock ){
25186 return SQLITE_OK;
@@ -25757,11 +25766,11 @@
25766 SimulateIOError( newOffset-- );
25767 if( newOffset!=offset ){
25768 if( newOffset == -1 ){
25769 ((unixFile*)id)->lastErrno = errno;
25770 }else{
25771 ((unixFile*)id)->lastErrno = 0;
25772 }
25773 return -1;
25774 }
25775 got = osRead(id->h, pBuf, cnt);
25776 #endif
@@ -25845,11 +25854,11 @@
25854 SimulateIOError( newOffset-- );
25855 if( newOffset!=offset ){
25856 if( newOffset == -1 ){
25857 ((unixFile*)id)->lastErrno = errno;
25858 }else{
25859 ((unixFile*)id)->lastErrno = 0;
25860 }
25861 return -1;
25862 }
25863 got = osWrite(id->h, pBuf, cnt);
25864 }while( got<0 && errno==EINTR );
@@ -28359,11 +28368,11 @@
28368 ** with _IOWR('z', 23, struct ByteRangeLockPB2) to track the same 5 states.
28369 ** To simulate a F_RDLCK on the shared range, on AFP a randomly selected
28370 ** address in the shared range is taken for a SHARED lock, the entire
28371 ** shared range is taken for an EXCLUSIVE lock):
28372 **
28373 ** PENDING_BYTE 0x40000000
28374 ** RESERVED_BYTE 0x40000001
28375 ** SHARED_RANGE 0x40000002 -> 0x40000200
28376 **
28377 ** This works well on the local file system, but shows a nearly 100x
28378 ** slowdown in read performance on AFP because the AFP client disables
@@ -29879,13 +29888,15 @@
29888
29889 #ifndef FILE_ATTRIBUTE_MASK
29890 # define FILE_ATTRIBUTE_MASK (0x0003FFF7)
29891 #endif
29892
29893 #ifndef SQLITE_OMIT_WAL
29894 /* Forward references */
29895 typedef struct winShm winShm; /* A connection to shared-memory */
29896 typedef struct winShmNode winShmNode; /* A region of shared-memory */
29897 #endif
29898
29899 /*
29900 ** WinCE lacks native support for file locking so we have to fake it
29901 ** with some code of our own.
29902 */
@@ -29909,11 +29920,13 @@
29920 HANDLE h; /* Handle for accessing the file */
29921 u8 locktype; /* Type of lock currently held on this file */
29922 short sharedLockByte; /* Randomly chosen byte used as a shared lock */
29923 u8 ctrlFlags; /* Flags. See WINFILE_* below */
29924 DWORD lastErrno; /* The Windows errno from the last I/O error */
29925 #ifndef SQLITE_OMIT_WAL
29926 winShm *pShm; /* Instance of shared memory on this file */
29927 #endif
29928 const char *zPath; /* Full pathname of this file */
29929 int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */
29930 #if SQLITE_OS_WINCE
29931 LPWSTR zDeleteOnClose; /* Name of file to delete when closing */
29932 HANDLE hMutex; /* Mutex used to control access to shared lock */
@@ -29934,10 +29947,26 @@
29947 */
29948 #ifndef SQLITE_WIN32_DBG_BUF_SIZE
29949 # define SQLITE_WIN32_DBG_BUF_SIZE ((int)(4096-sizeof(DWORD)))
29950 #endif
29951
29952 /*
29953 * The value used with sqlite3_win32_set_directory() to specify that
29954 * the data directory should be changed.
29955 */
29956 #ifndef SQLITE_WIN32_DATA_DIRECTORY_TYPE
29957 # define SQLITE_WIN32_DATA_DIRECTORY_TYPE (1)
29958 #endif
29959
29960 /*
29961 * The value used with sqlite3_win32_set_directory() to specify that
29962 * the temporary directory should be changed.
29963 */
29964 #ifndef SQLITE_WIN32_TEMP_DIRECTORY_TYPE
29965 # define SQLITE_WIN32_TEMP_DIRECTORY_TYPE (2)
29966 #endif
29967
29968 /*
29969 * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
29970 * various Win32 API heap functions instead of our own.
29971 */
29972 #ifdef SQLITE_WIN32_MALLOC
@@ -31147,10 +31176,46 @@
31176 zFilenameMbcs = unicodeToMbcs(zTmpWide);
31177 sqlite3_free(zTmpWide);
31178 return zFilenameMbcs;
31179 }
31180
31181 /*
31182 ** This function sets the data directory or the temporary directory based on
31183 ** the provided arguments. The type argument must be 1 in order to set the
31184 ** data directory or 2 in order to set the temporary directory. The zValue
31185 ** argument is the name of the directory to use. The return value will be
31186 ** SQLITE_OK if successful.
31187 */
31188 SQLITE_API int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
31189 char **ppDirectory = 0;
31190 #ifndef SQLITE_OMIT_AUTOINIT
31191 int rc = sqlite3_initialize();
31192 if( rc ) return rc;
31193 #endif
31194 if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
31195 ppDirectory = &sqlite3_data_directory;
31196 }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
31197 ppDirectory = &sqlite3_temp_directory;
31198 }
31199 assert( !ppDirectory || type==SQLITE_WIN32_DATA_DIRECTORY_TYPE
31200 || type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE
31201 );
31202 assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) );
31203 if( ppDirectory ){
31204 char *zValueUtf8 = 0;
31205 if( zValue && zValue[0] ){
31206 zValueUtf8 = unicodeToUtf8(zValue);
31207 if ( zValueUtf8==0 ){
31208 return SQLITE_NOMEM;
31209 }
31210 }
31211 sqlite3_free(*ppDirectory);
31212 *ppDirectory = zValueUtf8;
31213 return SQLITE_OK;
31214 }
31215 return SQLITE_ERROR;
31216 }
31217
31218 /*
31219 ** The return value of getLastErrorMsg
31220 ** is zero if the error message fits in the buffer, or non-zero
31221 ** otherwise (if the message was truncated).
@@ -31763,11 +31828,13 @@
31828 static int winClose(sqlite3_file *id){
31829 int rc, cnt = 0;
31830 winFile *pFile = (winFile*)id;
31831
31832 assert( id!=0 );
31833 #ifndef SQLITE_OMIT_WAL
31834 assert( pFile->pShm==0 );
31835 #endif
31836 OSTRACE(("CLOSE %d\n", pFile->h));
31837 do{
31838 rc = osCloseHandle(pFile->h);
31839 /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
31840 }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
@@ -33513,11 +33580,13 @@
33580 memset(pFile, 0, sizeof(*pFile));
33581 pFile->pMethod = &winIoMethod;
33582 pFile->h = h;
33583 pFile->lastErrno = NO_ERROR;
33584 pFile->pVfs = pVfs;
33585 #ifndef SQLITE_OMIT_WAL
33586 pFile->pShm = 0;
33587 #endif
33588 pFile->zPath = zName;
33589 if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
33590 pFile->ctrlFlags |= WINFILE_PSOW;
33591 }
33592
@@ -49289,11 +49358,11 @@
49358 }
49359 next = get2byte(&data[pc]);
49360 size = get2byte(&data[pc+2]);
49361 if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
49362 /* Free blocks must be in ascending order. And the last byte of
49363 ** the free-block must lie on the database page. */
49364 return SQLITE_CORRUPT_BKPT;
49365 }
49366 nFree = nFree + size;
49367 pc = next;
49368 }
@@ -50463,11 +50532,11 @@
50532 if( rc==SQLITE_OK ){
50533 if( p->inTrans==TRANS_NONE ){
50534 pBt->nTransaction++;
50535 #ifndef SQLITE_OMIT_SHARED_CACHE
50536 if( p->sharable ){
50537 assert( p->lock.pBtree==p && p->lock.iTable==1 );
50538 p->lock.eLock = READ_LOCK;
50539 p->lock.pNext = pBt->pLock;
50540 pBt->pLock = &p->lock;
50541 }
50542 #endif
@@ -54301,10 +54370,11 @@
54370 while( i==iNextOld ){
54371 /* Cell i is the cell immediately following the last cell on old
54372 ** sibling page j. If the siblings are not leaf pages of an
54373 ** intkey b-tree, then cell i was a divider cell. */
54374 assert( j+1 < ArraySize(apCopy) );
54375 assert( j+1 < nOld );
54376 pOld = apCopy[++j];
54377 iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
54378 if( pOld->nOverflow ){
54379 nOverflow = pOld->nOverflow;
54380 iOverflow = i + !leafData + pOld->aiOvfl[0];
@@ -56135,11 +56205,10 @@
56205 */
56206 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){
56207 assert( mask==BTREE_BULKLOAD || mask==0 );
56208 pCsr->hints = mask;
56209 }
 
56210
56211 /************** End of btree.c ***********************************************/
56212 /************** Begin file backup.c ******************************************/
56213 /*
56214 ** 2009 January 28
@@ -70367,11 +70436,11 @@
70436 if( iBuf==0 ){
70437 int nRead; /* Bytes to read from disk */
70438 int rc; /* sqlite3OsRead() return code */
70439
70440 /* Determine how many bytes of data to read. */
70441 nRead = (int)(p->iEof - p->iReadOff);
70442 if( nRead>p->nBuffer ) nRead = p->nBuffer;
70443 assert( nRead>0 );
70444
70445 /* Read data from the file. Return early if an error occurs. */
70446 rc = sqlite3OsRead(p->pFile, p->aBuffer, nRead, p->iReadOff);
@@ -70472,11 +70541,11 @@
70541 }
70542
70543 rc = vdbeSorterIterVarint(db, pIter, &nRec);
70544 if( rc==SQLITE_OK ){
70545 pIter->nKey = (int)nRec;
70546 rc = vdbeSorterIterRead(db, pIter, (int)nRec, &pIter->aKey);
70547 }
70548
70549 return rc;
70550 }
70551
@@ -70515,11 +70584,11 @@
70584
70585 iBuf = iStart % nBuf;
70586 if( iBuf ){
70587 int nRead = nBuf - iBuf;
70588 if( (iStart + nRead) > pSorter->iWriteOff ){
70589 nRead = (int)(pSorter->iWriteOff - iStart);
70590 }
70591 rc = sqlite3OsRead(
70592 pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart
70593 );
70594 assert( rc!=SQLITE_IOERR_SHORT_READ );
@@ -71838,17 +71907,23 @@
71907 */
71908 SQLITE_PRIVATE int sqlite3WalkSelect(Walker *pWalker, Select *p){
71909 int rc;
71910 if( p==0 || pWalker->xSelectCallback==0 ) return WRC_Continue;
71911 rc = WRC_Continue;
71912 pWalker->walkerDepth++;
71913 while( p ){
71914 rc = pWalker->xSelectCallback(pWalker, p);
71915 if( rc ) break;
71916 if( sqlite3WalkSelectExpr(pWalker, p)
71917 || sqlite3WalkSelectFrom(pWalker, p)
71918 ){
71919 pWalker->walkerDepth--;
71920 return WRC_Abort;
71921 }
71922 p = p->pPrior;
71923 }
71924 pWalker->walkerDepth--;
71925 return rc & WRC_Abort;
71926 }
71927
71928 /************** End of walker.c **********************************************/
71929 /************** Begin file resolve.c *****************************************/
@@ -71868,10 +71943,33 @@
71943 ** resolve all identifiers by associating them with a particular
71944 ** table and column.
71945 */
71946 /* #include <stdlib.h> */
71947 /* #include <string.h> */
71948
71949 /*
71950 ** Walk the expression tree pExpr and increase the aggregate function
71951 ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node.
71952 ** This needs to occur when copying a TK_AGG_FUNCTION node from an
71953 ** outer query into an inner subquery.
71954 **
71955 ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
71956 ** is a helper function - a callback for the tree walker.
71957 */
71958 static int incrAggDepth(Walker *pWalker, Expr *pExpr){
71959 if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i;
71960 return WRC_Continue;
71961 }
71962 static void incrAggFunctionDepth(Expr *pExpr, int N){
71963 if( N>0 ){
71964 Walker w;
71965 memset(&w, 0, sizeof(w));
71966 w.xExprCallback = incrAggDepth;
71967 w.u.i = N;
71968 sqlite3WalkExpr(&w, pExpr);
71969 }
71970 }
71971
71972 /*
71973 ** Turn the pExpr expression into an alias for the iCol-th column of the
71974 ** result set in pEList.
71975 **
@@ -71895,17 +71993,24 @@
71993 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
71994 **
71995 ** The result of random()%5 in the GROUP BY clause is probably different
71996 ** from the result in the result-set. We might fix this someday. Or
71997 ** then again, we might not...
71998 **
71999 ** The nSubquery parameter specifies how many levels of subquery the
72000 ** alias is removed from the original expression. The usually value is
72001 ** zero but it might be more if the alias is contained within a subquery
72002 ** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION
72003 ** structures must be increased by the nSubquery amount.
72004 */
72005 static void resolveAlias(
72006 Parse *pParse, /* Parsing context */
72007 ExprList *pEList, /* A result set */
72008 int iCol, /* A column in the result set. 0..pEList->nExpr-1 */
72009 Expr *pExpr, /* Transform this into an alias to the result set */
72010 const char *zType, /* "GROUP" or "ORDER" or "" */
72011 int nSubquery /* Number of subqueries that the label is moving */
72012 ){
72013 Expr *pOrig; /* The iCol-th column of the result set */
72014 Expr *pDup; /* Copy of pOrig */
72015 sqlite3 *db; /* The database connection */
72016
@@ -71914,10 +72019,11 @@
72019 assert( pOrig!=0 );
72020 assert( pOrig->flags & EP_Resolved );
72021 db = pParse->db;
72022 if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){
72023 pDup = sqlite3ExprDup(db, pOrig, 0);
72024 incrAggFunctionDepth(pDup, nSubquery);
72025 pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
72026 if( pDup==0 ) return;
72027 if( pEList->a[iCol].iAlias==0 ){
72028 pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
72029 }
@@ -72002,13 +72108,14 @@
72108 const char *zTab, /* Name of table containing column, or NULL */
72109 const char *zCol, /* Name of the column. */
72110 NameContext *pNC, /* The name context used to resolve the name */
72111 Expr *pExpr /* Make this EXPR node point to the selected column */
72112 ){
72113 int i, j; /* Loop counters */
72114 int cnt = 0; /* Number of matching column names */
72115 int cntTab = 0; /* Number of matching table names */
72116 int nSubquery = 0; /* How many levels of subquery */
72117 sqlite3 *db = pParse->db; /* The database connection */
72118 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
72119 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
72120 NameContext *pTopNC = pNC; /* First namecontext in the list */
72121 Schema *pSchema = 0; /* Schema of the expression */
@@ -72166,11 +72273,11 @@
72273 pOrig = pEList->a[j].pExpr;
72274 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
72275 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
72276 return WRC_Abort;
72277 }
72278 resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
72279 cnt = 1;
72280 pMatch = 0;
72281 assert( zTab==0 && zDb==0 );
72282 goto lookupname_end;
72283 }
@@ -72180,10 +72287,11 @@
72287 /* Advance to the next name context. The loop will exit when either
72288 ** we have a match (cnt>0) or when we run out of name contexts.
72289 */
72290 if( cnt==0 ){
72291 pNC = pNC->pNext;
72292 nSubquery++;
72293 }
72294 }
72295
72296 /*
72297 ** If X and Y are NULL (in other words if only the column name Z is
@@ -72419,17 +72527,23 @@
72527 }else if( wrong_num_args ){
72528 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
72529 nId, zId);
72530 pNC->nErr++;
72531 }
 
 
 
 
72532 if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg;
72533 sqlite3WalkExprList(pWalker, pList);
72534 if( is_agg ){
72535 NameContext *pNC2 = pNC;
72536 pExpr->op = TK_AGG_FUNCTION;
72537 pExpr->op2 = 0;
72538 while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){
72539 pExpr->op2++;
72540 pNC2 = pNC2->pNext;
72541 }
72542 if( pNC2 ) pNC2->ncFlags |= NC_HasAgg;
72543 pNC->ncFlags |= NC_AllowAgg;
72544 }
72545 /* FIX ME: Compute pExpr->affinity based on the expected return
72546 ** type of the function
72547 */
72548 return WRC_Prune;
72549 }
@@ -72704,11 +72818,11 @@
72818 if( pItem->iOrderByCol ){
72819 if( pItem->iOrderByCol>pEList->nExpr ){
72820 resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
72821 return 1;
72822 }
72823 resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0);
72824 }
72825 }
72826 return 0;
72827 }
72828
@@ -76204,13 +76318,16 @@
76318 if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
76319 pFarg = 0;
76320 }else{
76321 pFarg = pExpr->x.pList;
76322 }
76323 if( op==TK_AGG_FUNCTION ){
76324 sqlite3ExplainPrintf(pOut, "AGG_FUNCTION%d:%s(",
76325 pExpr->op2, pExpr->u.zToken);
76326 }else{
76327 sqlite3ExplainPrintf(pOut, "FUNCTION:%s(", pExpr->u.zToken);
76328 }
76329 if( pFarg ){
76330 sqlite3ExplainExprList(pOut, pFarg);
76331 }
76332 sqlite3ExplainPrintf(pOut, ")");
76333 break;
@@ -76897,42 +77014,64 @@
77014 }
77015 return 0;
77016 }
77017
77018 /*
77019 ** An instance of the following structure is used by the tree walker
77020 ** to count references to table columns in the arguments of an
77021 ** aggregate function, in order to implement the
77022 ** sqlite3FunctionThisSrc() routine.
77023 */
77024 struct SrcCount {
77025 SrcList *pSrc; /* One particular FROM clause in a nested query */
77026 int nThis; /* Number of references to columns in pSrcList */
77027 int nOther; /* Number of references to columns in other FROM clauses */
77028 };
77029
77030 /*
77031 ** Count the number of references to columns.
77032 */
77033 static int exprSrcCount(Walker *pWalker, Expr *pExpr){
77034 /* The NEVER() on the second term is because sqlite3FunctionUsesThisSrc()
77035 ** is always called before sqlite3ExprAnalyzeAggregates() and so the
77036 ** TK_COLUMNs have not yet been converted into TK_AGG_COLUMN. If
77037 ** sqlite3FunctionUsesThisSrc() is used differently in the future, the
77038 ** NEVER() will need to be removed. */
77039 if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){
77040 int i;
77041 struct SrcCount *p = pWalker->u.pSrcCount;
77042 SrcList *pSrc = p->pSrc;
77043 for(i=0; i<pSrc->nSrc; i++){
77044 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
77045 }
77046 if( i<pSrc->nSrc ){
77047 p->nThis++;
77048 }else{
77049 p->nOther++;
77050 }
77051 }
77052 return WRC_Continue;
77053 }
77054
77055 /*
77056 ** Determine if any of the arguments to the pExpr Function reference
77057 ** pSrcList. Return true if they do. Also return true if the function
77058 ** has no arguments or has only constant arguments. Return false if pExpr
77059 ** references columns but not columns of tables found in pSrcList.
77060 */
77061 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){
77062 Walker w;
77063 struct SrcCount cnt;
77064 assert( pExpr->op==TK_AGG_FUNCTION );
77065 memset(&w, 0, sizeof(w));
77066 w.xExprCallback = exprSrcCount;
77067 w.u.pSrcCount = &cnt;
77068 cnt.pSrc = pSrcList;
77069 cnt.nThis = 0;
77070 cnt.nOther = 0;
77071 sqlite3WalkExprList(&w, pExpr->x.pList);
77072 return cnt.nThis>0 || cnt.nOther==0;
77073 }
77074
77075 /*
77076 ** Add a new element to the pAggInfo->aCol[] array. Return the index of
77077 ** the new element. Return a negative number if malloc fails.
@@ -77047,11 +77186,11 @@
77186 }
77187 return WRC_Prune;
77188 }
77189 case TK_AGG_FUNCTION: {
77190 if( (pNC->ncFlags & NC_InAggFunc)==0
77191 && pWalker->walkerDepth==pExpr->op2
77192 ){
77193 /* Check to see if pExpr is a duplicate of another aggregate
77194 ** function that is already in the pAggInfo structure
77195 */
77196 struct AggInfo_func *pItem = pAggInfo->aFunc;
@@ -80497,11 +80636,11 @@
80636 pNext = pIndex->pNext;
80637 assert( pIndex->pSchema==pTable->pSchema );
80638 if( !db || db->pnBytesFreed==0 ){
80639 char *zName = pIndex->zName;
80640 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
80641 &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
80642 );
80643 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
80644 assert( pOld==pIndex || pOld==0 );
80645 }
80646 freeIndex(db, pIndex);
@@ -84653,11 +84792,11 @@
84792
84793 /* Collect rowids of every row to be deleted.
84794 */
84795 sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
84796 pWInfo = sqlite3WhereBegin(
84797 pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
84798 );
84799 if( pWInfo==0 ) goto delete_from_cleanup;
84800 regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0);
84801 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
84802 if( db->flags & SQLITE_CountRows ){
@@ -87121,11 +87260,11 @@
87260
87261 /* Create VDBE to loop through the entries in pSrc that match the WHERE
87262 ** clause. If the constraint is not deferred, throw an exception for
87263 ** each row found. Otherwise, for deferred constraints, increment the
87264 ** deferred constraint counter by nIncr for each row selected. */
87265 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
87266 if( nIncr>0 && pFKey->isDeferred==0 ){
87267 sqlite3ParseToplevel(pParse)->mayAbort = 1;
87268 }
87269 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
87270 if( pWInfo ){
@@ -96539,11 +96678,11 @@
96678 pExpr = p->pEList->a[0].pExpr;
96679 assert( pTab && !pTab->pSelect && pExpr );
96680
96681 if( IsVirtual(pTab) ) return 0;
96682 if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
96683 if( NEVER(pAggInfo->nFunc==0) ) return 0;
96684 if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
96685 if( pExpr->flags&EP_Distinct ) return 0;
96686
96687 return pTab;
96688 }
@@ -96911,11 +97050,11 @@
97050 #endif
97051 }
97052
97053
97054 /*
97055 ** This routine sets up a SELECT statement for processing. The
97056 ** following is accomplished:
97057 **
97058 ** * VDBE Cursor numbers are assigned to all FROM-clause terms.
97059 ** * Ephemeral Table objects are created for all FROM-clause subqueries.
97060 ** * ON and USING clauses are shifted into WHERE statements
@@ -96943,11 +97082,12 @@
97082 /*
97083 ** Reset the aggregate accumulator.
97084 **
97085 ** The aggregate accumulator is a set of memory cells that hold
97086 ** intermediate results while calculating an aggregate. This
97087 ** routine generates code that stores NULLs in all of those memory
97088 ** cells.
97089 */
97090 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
97091 Vdbe *v = pParse->pVdbe;
97092 int i;
97093 struct AggInfo_func *pFunc;
@@ -97413,11 +97553,11 @@
97553 /* Aggregate and non-aggregate queries are handled differently */
97554 if( !isAgg && pGroupBy==0 ){
97555 ExprList *pDist = (isDistinct ? p->pEList : 0);
97556
97557 /* Begin the database scan. */
97558 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0,0);
97559 if( pWInfo==0 ) goto select_end;
97560 if( pWInfo->nRowOut < p->nSelectRow ) p->nSelectRow = pWInfo->nRowOut;
97561
97562 /* If sorting index that was created by a prior OP_OpenEphemeral
97563 ** instruction ended up not being needed, then change the OP_OpenEphemeral
@@ -97586,11 +97726,11 @@
97726 ** This might involve two separate loops with an OP_Sort in between, or
97727 ** it might be a single loop that uses an index to extract information
97728 ** in the right order to begin with.
97729 */
97730 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
97731 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0, 0);
97732 if( pWInfo==0 ) goto select_end;
97733 if( pGroupBy==0 ){
97734 /* The optimizer is able to deliver rows in group by order so
97735 ** we do not have to sort. The OP_OpenEphemeral table will be
97736 ** cancelled later because we still need to use the pKeyInfo
@@ -97855,11 +97995,11 @@
97995 /* This case runs if the aggregate has no GROUP BY clause. The
97996 ** processing is much simpler since there is only a single row
97997 ** of output.
97998 */
97999 resetAccumulator(pParse, &sAggInfo);
98000 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax,0,flag,0);
98001 if( pWInfo==0 ){
98002 sqlite3ExprListDelete(db, pDel);
98003 goto select_end;
98004 }
98005 updateAccumulator(pParse, &sAggInfo);
@@ -99655,11 +99795,11 @@
99795
99796 /* Begin the database scan
99797 */
99798 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
99799 pWInfo = sqlite3WhereBegin(
99800 pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, 0
99801 );
99802 if( pWInfo==0 ) goto update_cleanup;
99803 okOnePass = pWInfo->okOnePass;
99804
99805 /* Remember the rowid of every item to be updated.
@@ -105084,11 +105224,11 @@
105224 assert( pIdx->nColumn>=nEq );
105225 for(j=0; j<nEq; j++){
105226 int r1;
105227 int k = pIdx->aiColumn[j];
105228 pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx);
105229 if( pTerm==0 ) break;
105230 /* The following true for indices with redundant columns.
105231 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
105232 testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
105233 testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
105234 r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
@@ -105759,10 +105899,12 @@
105899 ** B: <after the loop>
105900 **
105901 */
105902 WhereClause *pOrWc; /* The OR-clause broken out into subterms */
105903 SrcList *pOrTab; /* Shortened table list or OR-clause generation */
105904 Index *pCov = 0; /* Potential covering index (or NULL) */
105905 int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */
105906
105907 int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */
105908 int regRowset = 0; /* Register for RowSet object */
105909 int regRowid = 0; /* Register holding rowid */
105910 int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */
@@ -105777,11 +105919,11 @@
105919 assert( (pTerm->wtFlags & TERM_ORINFO)!=0 );
105920 pOrWc = &pTerm->u.pOrInfo->wc;
105921 pLevel->op = OP_Return;
105922 pLevel->p1 = regReturn;
105923
105924 /* Set up a new SrcList in pOrTab containing the table being scanned
105925 ** by this loop in the a[0] slot and all notReady tables in a[1..] slots.
105926 ** This becomes the SrcList in the recursive call to sqlite3WhereBegin().
105927 */
105928 if( pWInfo->nLevel>1 ){
105929 int nNotReady; /* The number of notReady tables */
@@ -105854,12 +105996,14 @@
105996 pOrExpr = pAndExpr;
105997 }
105998 /* Loop through table entries that match term pOrTerm. */
105999 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
106000 WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY |
106001 WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur);
106002 assert( pSubWInfo || pParse->nErr || pParse->db->mallocFailed );
106003 if( pSubWInfo ){
106004 WhereLevel *pLvl;
106005 explainOneScan(
106006 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
106007 );
106008 if( (wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
106009 int iSet = ((ii==pOrWc->nTerm-1)?-1:ii);
@@ -105875,16 +106019,41 @@
106019 ** contained one or more AND term from a notReady table. The
106020 ** terms from the notReady table could not be tested and will
106021 ** need to be tested later.
106022 */
106023 if( pSubWInfo->untestedTerms ) untestedTerms = 1;
106024
106025 /* If all of the OR-connected terms are optimized using the same
106026 ** index, and the index is opened using the same cursor number
106027 ** by each call to sqlite3WhereBegin() made by this loop, it may
106028 ** be possible to use that index as a covering index.
106029 **
106030 ** If the call to sqlite3WhereBegin() above resulted in a scan that
106031 ** uses an index, and this is either the first OR-connected term
106032 ** processed or the index is the same as that used by all previous
106033 ** terms, set pCov to the candidate covering index. Otherwise, set
106034 ** pCov to NULL to indicate that no candidate covering index will
106035 ** be available.
106036 */
106037 pLvl = &pSubWInfo->a[0];
106038 if( (pLvl->plan.wsFlags & WHERE_INDEXED)!=0
106039 && (pLvl->plan.wsFlags & WHERE_TEMP_INDEX)==0
106040 && (ii==0 || pLvl->plan.u.pIdx==pCov)
106041 ){
106042 assert( pLvl->iIdxCur==iCovCur );
106043 pCov = pLvl->plan.u.pIdx;
106044 }else{
106045 pCov = 0;
106046 }
106047
106048 /* Finish the loop through table entries that match term pOrTerm. */
106049 sqlite3WhereEnd(pSubWInfo);
106050 }
106051 }
106052 }
106053 pLevel->u.pCovidx = pCov;
106054 pLevel->iIdxCur = iCovCur;
106055 if( pAndExpr ){
106056 pAndExpr->pLeft = 0;
106057 sqlite3ExprDelete(pParse->db, pAndExpr);
106058 }
106059 sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v));
@@ -106098,11 +106267,12 @@
106267 Parse *pParse, /* The parser context */
106268 SrcList *pTabList, /* A list of all tables to be scanned */
106269 Expr *pWhere, /* The WHERE clause */
106270 ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */
106271 ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */
106272 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
106273 int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
106274 ){
106275 int i; /* Loop counter */
106276 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
106277 int nTabList; /* Number of elements in pTabList */
106278 WhereInfo *pWInfo; /* Will become the return value of this function */
@@ -106418,11 +106588,17 @@
106588 andFlags &= bestPlan.plan.wsFlags;
106589 pLevel->plan = bestPlan.plan;
106590 testcase( bestPlan.plan.wsFlags & WHERE_INDEXED );
106591 testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX );
106592 if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){
106593 if( (wctrlFlags & WHERE_ONETABLE_ONLY)
106594 && (bestPlan.plan.wsFlags & WHERE_TEMP_INDEX)==0
106595 ){
106596 pLevel->iIdxCur = iIdxCur;
106597 }else{
106598 pLevel->iIdxCur = pParse->nTab++;
106599 }
106600 }else{
106601 pLevel->iIdxCur = -1;
106602 }
106603 notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor);
106604 pLevel->iFrom = (u8)bestJ;
@@ -106670,10 +106846,11 @@
106846
106847 /* Close all of the cursors that were opened by sqlite3WhereBegin.
106848 */
106849 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
106850 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
106851 Index *pIdx = 0;
106852 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
106853 Table *pTab = pTabItem->pTab;
106854 assert( pTab!=0 );
106855 if( (pTab->tabFlags & TF_Ephemeral)==0
106856 && pTab->pSelect==0
@@ -106699,16 +106876,19 @@
106876 ** sqlite3WhereEnd will have created code that references the table
106877 ** directly. This loop scans all that code looking for opcodes
106878 ** that reference the table and converts them into opcodes that
106879 ** reference the index.
106880 */
106881 if( pLevel->plan.wsFlags & WHERE_INDEXED ){
106882 pIdx = pLevel->plan.u.pIdx;
106883 }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
106884 pIdx = pLevel->u.pCovidx;
106885 }
106886 if( pIdx && !db->mallocFailed){
106887 int k, j, last;
106888 VdbeOp *pOp;
 
106889
 
106890 pOp = sqlite3VdbeGetOp(v, pWInfo->iTop);
106891 last = sqlite3VdbeCurrentAddr(v);
106892 for(k=pWInfo->iTop; k<last; k++, pOp++){
106893 if( pOp->p1!=pLevel->iTabCur ) continue;
106894 if( pOp->opcode==OP_Column ){
@@ -115878,14 +116058,24 @@
116058 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
116059
116060 SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
116061 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
116062
116063 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
116064 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *);
116065 SQLITE_PRIVATE int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int);
116066 SQLITE_PRIVATE int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *);
116067 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *);
116068 SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
116069 #else
116070 # define sqlite3Fts3FreeDeferredTokens(x)
116071 # define sqlite3Fts3DeferToken(x,y,z) SQLITE_OK
116072 # define sqlite3Fts3CacheDeferredDoclists(x) SQLITE_OK
116073 # define sqlite3Fts3FreeDeferredDoclists(x)
116074 # define sqlite3Fts3DeferredTokenList(x,y,z) SQLITE_OK
116075 #endif
116076
116077 SQLITE_PRIVATE void sqlite3Fts3SegmentsClose(Fts3Table *);
116078 SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *, int *);
116079
116080 /* Special values interpreted by sqlite3SegReaderCursor() */
116081 #define FTS3_SEGCURSOR_PENDING -1
@@ -115990,12 +116180,10 @@
116180 Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *);
116181 SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **);
116182 SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
116183 SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
116184
 
 
116185 /* fts3_unicode2.c (functions generated by parsing unicode text files) */
116186 #ifdef SQLITE_ENABLE_FTS4_UNICODE61
116187 SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int);
116188 SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int);
116189 SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int);
@@ -120149,10 +120337,11 @@
120337
120338 /* Allocate a MultiSegReader for each token in the expression. */
120339 fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc);
120340
120341 /* Determine which, if any, tokens in the expression should be deferred. */
120342 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
120343 if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
120344 Fts3TokenAndCost *aTC;
120345 Fts3Expr **apOr;
120346 aTC = (Fts3TokenAndCost *)sqlite3_malloc(
120347 sizeof(Fts3TokenAndCost) * nToken
@@ -120179,10 +120368,11 @@
120368 }
120369
120370 sqlite3_free(aTC);
120371 }
120372 }
120373 #endif
120374
120375 fts3EvalStartReaders(pCsr, pCsr->pExpr, 1, &rc);
120376 return rc;
120377 }
120378
@@ -120562,10 +120752,11 @@
120752 && !fts3EvalTestExpr(pCsr, pExpr->pRight, pRc)
120753 );
120754 break;
120755
120756 default: {
120757 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
120758 if( pCsr->pDeferred
120759 && (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred)
120760 ){
120761 Fts3Phrase *pPhrase = pExpr->pPhrase;
120762 assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 );
@@ -120573,11 +120764,13 @@
120764 fts3EvalInvalidatePoslist(pPhrase);
120765 }
120766 *pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
120767 bHit = (pPhrase->doclist.pList!=0);
120768 pExpr->iDocid = pCsr->iPrevId;
120769 }else
120770 #endif
120771 {
120772 bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId);
120773 }
120774 break;
120775 }
120776 }
@@ -129349,10 +129542,11 @@
129542 }
129543
129544 return rc;
129545 }
129546
129547 #ifndef SQLITE_DISABLE_FTS4_DEFERRED
129548 /*
129549 ** Delete all cached deferred doclists. Deferred doclists are cached
129550 ** (allocated) by the sqlite3Fts3CacheDeferredDoclists() function.
129551 */
129552 SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *pCsr){
@@ -129486,10 +129680,11 @@
129680 assert( pToken->pDeferred==0 );
129681 pToken->pDeferred = pDeferred;
129682
129683 return SQLITE_OK;
129684 }
129685 #endif
129686
129687 /*
129688 ** SQLite value pRowid contains the rowid of a row that may or may not be
129689 ** present in the FTS3 table. If it is, delete it and adjust the contents
129690 ** of subsiduary data structures accordingly.
129691
+5 -2
--- 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.7.14"
111111
#define SQLITE_VERSION_NUMBER 3007014
112
-#define SQLITE_SOURCE_ID "2012-08-14 17:29:27 6954fef006431d153de6e63e362b8d260ebeb1c6"
112
+#define SQLITE_SOURCE_ID "2012-08-24 23:56:19 62678be3df35cdcb09172ba8c860f7b73517f1ea"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -3157,12 +3157,15 @@
31573157
** ^The third argument is the value to bind to the parameter.
31583158
**
31593159
** ^(In those routines that have a fourth argument, its value is the
31603160
** number of bytes in the parameter. To be clear: the value is the
31613161
** number of <u>bytes</u> in the value, not the number of characters.)^
3162
-** ^If the fourth parameter is negative, the length of the string is
3162
+** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3163
+** is negative, then the length of the string is
31633164
** the number of bytes up to the first zero terminator.
3165
+** If the fourth parameter to sqlite3_bind_blob() is negative, then
3166
+** the behavior is undefined.
31643167
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
31653168
** or sqlite3_bind_text16() then that parameter must be the byte offset
31663169
** where the NUL terminator would occur assuming the string were NUL
31673170
** terminated. If any NUL characters occur at byte offsets less than
31683171
** the value of the fourth parameter then the resulting string value will
31693172
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.14"
111 #define SQLITE_VERSION_NUMBER 3007014
112 #define SQLITE_SOURCE_ID "2012-08-14 17:29:27 6954fef006431d153de6e63e362b8d260ebeb1c6"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -3157,12 +3157,15 @@
3157 ** ^The third argument is the value to bind to the parameter.
3158 **
3159 ** ^(In those routines that have a fourth argument, its value is the
3160 ** number of bytes in the parameter. To be clear: the value is the
3161 ** number of <u>bytes</u> in the value, not the number of characters.)^
3162 ** ^If the fourth parameter is negative, the length of the string is
 
3163 ** the number of bytes up to the first zero terminator.
 
 
3164 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3165 ** or sqlite3_bind_text16() then that parameter must be the byte offset
3166 ** where the NUL terminator would occur assuming the string were NUL
3167 ** terminated. If any NUL characters occur at byte offsets less than
3168 ** the value of the fourth parameter then the resulting string value will
3169
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.14"
111 #define SQLITE_VERSION_NUMBER 3007014
112 #define SQLITE_SOURCE_ID "2012-08-24 23:56:19 62678be3df35cdcb09172ba8c860f7b73517f1ea"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -3157,12 +3157,15 @@
3157 ** ^The third argument is the value to bind to the parameter.
3158 **
3159 ** ^(In those routines that have a fourth argument, its value is the
3160 ** number of bytes in the parameter. To be clear: the value is the
3161 ** number of <u>bytes</u> in the value, not the number of characters.)^
3162 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3163 ** is negative, then the length of the string is
3164 ** the number of bytes up to the first zero terminator.
3165 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3166 ** the behavior is undefined.
3167 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3168 ** or sqlite3_bind_text16() then that parameter must be the byte offset
3169 ** where the NUL terminator would occur assuming the string were NUL
3170 ** terminated. If any NUL characters occur at byte offsets less than
3171 ** the value of the fourth parameter then the resulting string value will
3172

Keyboard Shortcuts

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