Fossil SCM

Pull in the latest SQLite from upstream. This enables the Application_ID feature, so make sure application IDs are set appropriately.

drh 2013-05-03 16:04 trunk
Commit 5a936f984cfe314268b64a75169b46fbeb9ff8bd
3 files changed +2 +417 -103 +13 -4
--- src/checkin.c
+++ src/checkin.c
@@ -1609,10 +1609,12 @@
16091609
/* Clear the undo/redo stack */
16101610
undo_reset();
16111611
16121612
/* Commit */
16131613
db_multi_exec("DELETE FROM vvar WHERE name='ci-comment'");
1614
+ db_multi_exec("PRAGMA %s.application_id=252006673;", db_name("repository"));
1615
+ db_multi_exec("PRAGMA %s.application_id=252006674;", db_name("localdb"));
16141616
if( dryRunFlag ){
16151617
db_end_transaction(1);
16161618
exit(1);
16171619
}
16181620
db_end_transaction(0);
16191621
--- src/checkin.c
+++ src/checkin.c
@@ -1609,10 +1609,12 @@
1609 /* Clear the undo/redo stack */
1610 undo_reset();
1611
1612 /* Commit */
1613 db_multi_exec("DELETE FROM vvar WHERE name='ci-comment'");
 
 
1614 if( dryRunFlag ){
1615 db_end_transaction(1);
1616 exit(1);
1617 }
1618 db_end_transaction(0);
1619
--- src/checkin.c
+++ src/checkin.c
@@ -1609,10 +1609,12 @@
1609 /* Clear the undo/redo stack */
1610 undo_reset();
1611
1612 /* Commit */
1613 db_multi_exec("DELETE FROM vvar WHERE name='ci-comment'");
1614 db_multi_exec("PRAGMA %s.application_id=252006673;", db_name("repository"));
1615 db_multi_exec("PRAGMA %s.application_id=252006674;", db_name("localdb"));
1616 if( dryRunFlag ){
1617 db_end_transaction(1);
1618 exit(1);
1619 }
1620 db_end_transaction(0);
1621
+417 -103
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -678,11 +678,11 @@
678678
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
679679
** [sqlite_version()] and [sqlite_source_id()].
680680
*/
681681
#define SQLITE_VERSION "3.7.17"
682682
#define SQLITE_VERSION_NUMBER 3007017
683
-#define SQLITE_SOURCE_ID "2013-04-25 17:27:08 aabeea98f53edde68f484f1794ae70789dac3889"
683
+#define SQLITE_SOURCE_ID "2013-05-03 15:23:24 b2efe4f225adc5f4c2e3080bf459cc52fff82e18"
684684
685685
/*
686686
** CAPI3REF: Run-Time Library Version Numbers
687687
** KEYWORDS: sqlite3_version, sqlite3_sourceid
688688
**
@@ -2161,11 +2161,13 @@
21612161
** <dd> ^(This option takes a single argument which is a pointer to an
21622162
** [sqlite3_pcache_methods2] object. SQLite copies of the current
21632163
** page cache implementation into that object.)^ </dd>
21642164
**
21652165
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2166
-** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
2166
+** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2167
+** global [error log].
2168
+** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
21672169
** function with a call signature of void(*)(void*,int,const char*),
21682170
** and a pointer to void. ^If the function pointer is not NULL, it is
21692171
** invoked by [sqlite3_log()] to process each logging event. ^If the
21702172
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
21712173
** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
@@ -3096,10 +3098,13 @@
30963098
** SQL statement text as the statement first begins executing.
30973099
** ^(Additional sqlite3_trace() callbacks might occur
30983100
** as each triggered subprogram is entered. The callbacks for triggers
30993101
** contain a UTF-8 SQL comment that identifies the trigger.)^
31003102
**
3103
+** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
3104
+** the length of [bound parameter] expansion in the output of sqlite3_trace().
3105
+**
31013106
** ^The callback function registered by sqlite3_profile() is invoked
31023107
** as each SQL statement finishes. ^The profile callback contains
31033108
** the original statement text and an estimate of wall-clock time
31043109
** of how long that statement took to run. ^The profile callback
31053110
** time is in units of nanoseconds, however the current implementation
@@ -3634,11 +3639,12 @@
36343639
**
36353640
** <ol>
36363641
** <li>
36373642
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
36383643
** always used to do, [sqlite3_step()] will automatically recompile the SQL
3639
-** statement and try to run it again.
3644
+** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
3645
+** retries will occur before sqlite3_step() gives up and returns an error.
36403646
** </li>
36413647
**
36423648
** <li>
36433649
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
36443650
** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3838,10 +3844,13 @@
38383844
** for "?NNN" parameters is the value of NNN.
38393845
** ^The NNN value must be between 1 and the [sqlite3_limit()]
38403846
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
38413847
**
38423848
** ^The third argument is the value to bind to the parameter.
3849
+** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3850
+** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
3851
+** is ignored and the end result is the same as sqlite3_bind_null().
38433852
**
38443853
** ^(In those routines that have a fourth argument, its value is the
38453854
** number of bytes in the parameter. To be clear: the value is the
38463855
** number of <u>bytes</u> in the value, not the number of characters.)^
38473856
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -7446,11 +7455,11 @@
74467455
SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
74477456
74487457
/*
74497458
** CAPI3REF: Error Logging Interface
74507459
**
7451
-** ^The [sqlite3_log()] interface writes a message into the error log
7460
+** ^The [sqlite3_log()] interface writes a message into the [error log]
74527461
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
74537462
** ^If logging is enabled, the zFormat string and subsequent arguments are
74547463
** used with [sqlite3_snprintf()] to generate the final output string.
74557464
**
74567465
** The sqlite3_log() interface is intended for use by extensions such as
@@ -8302,11 +8311,11 @@
83028311
#ifndef SQLITE_MAX_MMAP_SIZE
83038312
# if defined(__linux__) \
83048313
|| defined(_WIN32) \
83058314
|| (defined(__APPLE__) && defined(__MACH__)) \
83068315
|| defined(__sun)
8307
-# define SQLITE_MAX_MMAP_SIZE 2147483648
8316
+# define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
83088317
# else
83098318
# define SQLITE_MAX_MMAP_SIZE 0
83108319
# endif
83118320
# define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */
83128321
#endif
@@ -8620,10 +8629,11 @@
86208629
#define BTREE_DEFAULT_CACHE_SIZE 3
86218630
#define BTREE_LARGEST_ROOT_PAGE 4
86228631
#define BTREE_TEXT_ENCODING 5
86238632
#define BTREE_USER_VERSION 6
86248633
#define BTREE_INCR_VACUUM 7
8634
+#define BTREE_APPLICATION_ID 8
86258635
86268636
/*
86278637
** Values that may be OR'd together to form the second argument of an
86288638
** sqlite3BtreeCursorHints() call.
86298639
*/
@@ -22993,11 +23003,11 @@
2299323003
#include <fcntl.h>
2299423004
#include <unistd.h>
2299523005
/* #include <time.h> */
2299623006
#include <sys/time.h>
2299723007
#include <errno.h>
22998
-#ifndef SQLITE_OMIT_WAL
23008
+#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
2299923009
#include <sys/mman.h>
2300023010
#endif
2300123011
2300223012
2300323013
#if SQLITE_ENABLE_LOCKING_STYLE
@@ -26267,52 +26277,65 @@
2626726277
/* Unread parts of the buffer must be zero-filled */
2626826278
memset(&((char*)pBuf)[got], 0, amt-got);
2626926279
return SQLITE_IOERR_SHORT_READ;
2627026280
}
2627126281
}
26282
+
26283
+/*
26284
+** Attempt to seek the file-descriptor passed as the first argument to
26285
+** absolute offset iOff, then attempt to write nBuf bytes of data from
26286
+** pBuf to it. If an error occurs, return -1 and set *piErrno. Otherwise,
26287
+** return the actual number of bytes written (which may be less than
26288
+** nBuf).
26289
+*/
26290
+static int seekAndWriteFd(
26291
+ int fd, /* File descriptor to write to */
26292
+ i64 iOff, /* File offset to begin writing at */
26293
+ const void *pBuf, /* Copy data from this buffer to the file */
26294
+ int nBuf, /* Size of buffer pBuf in bytes */
26295
+ int *piErrno /* OUT: Error number if error occurs */
26296
+){
26297
+ int rc = 0; /* Value returned by system call */
26298
+
26299
+ assert( nBuf==(nBuf&0x1ffff) );
26300
+ nBuf &= 0x1ffff;
26301
+ TIMER_START;
26302
+
26303
+#if defined(USE_PREAD)
26304
+ do{ rc = osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
26305
+#elif defined(USE_PREAD64)
26306
+ do{ rc = osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
26307
+#else
26308
+ do{
26309
+ i64 iSeek = lseek(fd, iOff, SEEK_SET);
26310
+ SimulateIOError( iSeek-- );
26311
+
26312
+ if( iSeek!=iOff ){
26313
+ if( piErrno ) *piErrno = (iSeek==-1 ? errno : 0);
26314
+ return -1;
26315
+ }
26316
+ rc = osWrite(fd, pBuf, nBuf);
26317
+ }while( rc<0 && errno==EINTR );
26318
+#endif
26319
+
26320
+ TIMER_END;
26321
+ OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED));
26322
+
26323
+ if( rc<0 && piErrno ) *piErrno = errno;
26324
+ return rc;
26325
+}
26326
+
2627226327
2627326328
/*
2627426329
** Seek to the offset in id->offset then read cnt bytes into pBuf.
2627526330
** Return the number of bytes actually read. Update the offset.
2627626331
**
2627726332
** To avoid stomping the errno value on a failed write the lastErrno value
2627826333
** is set before returning.
2627926334
*/
2628026335
static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
26281
- int got;
26282
-#if (!defined(USE_PREAD) && !defined(USE_PREAD64))
26283
- i64 newOffset;
26284
-#endif
26285
- assert( cnt==(cnt&0x1ffff) );
26286
- cnt &= 0x1ffff;
26287
- TIMER_START;
26288
-#if defined(USE_PREAD)
26289
- do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26290
-#elif defined(USE_PREAD64)
26291
- do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR);
26292
-#else
26293
- do{
26294
- newOffset = lseek(id->h, offset, SEEK_SET);
26295
- SimulateIOError( newOffset-- );
26296
- if( newOffset!=offset ){
26297
- if( newOffset == -1 ){
26298
- ((unixFile*)id)->lastErrno = errno;
26299
- }else{
26300
- ((unixFile*)id)->lastErrno = 0;
26301
- }
26302
- return -1;
26303
- }
26304
- got = osWrite(id->h, pBuf, cnt);
26305
- }while( got<0 && errno==EINTR );
26306
-#endif
26307
- TIMER_END;
26308
- if( got<0 ){
26309
- ((unixFile*)id)->lastErrno = errno;
26310
- }
26311
-
26312
- OSTRACE(("WRITE %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED));
26313
- return got;
26336
+ return seekAndWriteFd(id->h, offset, pBuf, cnt, &id->lastErrno);
2631426337
}
2631526338
2631626339
2631726340
/*
2631826341
** Write data from a buffer into a file. Return SQLITE_OK on success
@@ -27397,28 +27420,36 @@
2739727420
}
2739827421
2739927422
if( sStat.st_size<nByte ){
2740027423
/* The requested memory region does not exist. If bExtend is set to
2740127424
** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
27402
- **
27403
- ** Alternatively, if bExtend is true, use ftruncate() to allocate
27404
- ** the requested memory region.
27405
- */
27406
- if( !bExtend ) goto shmpage_out;
27407
-#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
27408
- if( osFallocate(pShmNode->h, sStat.st_size, nByte)!=0 ){
27409
- rc = unixLogError(SQLITE_IOERR_SHMSIZE, "fallocate",
27410
- pShmNode->zFilename);
27411
- goto shmpage_out;
27412
- }
27413
-#else
27414
- if( robust_ftruncate(pShmNode->h, nByte) ){
27415
- rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate",
27416
- pShmNode->zFilename);
27417
- goto shmpage_out;
27418
- }
27419
-#endif
27425
+ */
27426
+ if( !bExtend ){
27427
+ goto shmpage_out;
27428
+ }
27429
+
27430
+ /* Alternatively, if bExtend is true, extend the file. Do this by
27431
+ ** writing a single byte to the end of each (OS) page being
27432
+ ** allocated or extended. Technically, we need only write to the
27433
+ ** last page in order to extend the file. But writing to all new
27434
+ ** pages forces the OS to allocate them immediately, which reduces
27435
+ ** the chances of SIGBUS while accessing the mapped region later on.
27436
+ */
27437
+ else{
27438
+ static const int pgsz = 4096;
27439
+ int iPg;
27440
+
27441
+ /* Write to the last byte of each newly allocated or extended page */
27442
+ assert( (nByte % pgsz)==0 );
27443
+ for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){
27444
+ if( seekAndWriteFd(pShmNode->h, iPg*pgsz + pgsz-1, "", 1, 0)!=1 ){
27445
+ const char *zFile = pShmNode->zFilename;
27446
+ rc = unixLogError(SQLITE_IOERR_SHMSIZE, "write", zFile);
27447
+ goto shmpage_out;
27448
+ }
27449
+ }
27450
+ }
2742027451
}
2742127452
}
2742227453
2742327454
/* Map the requested memory region into this processes address space. */
2742427455
apNew = (char **)sqlite3_realloc(
@@ -28341,13 +28372,12 @@
2834128372
#if OS_VXWORKS
2834228373
if( rc!=SQLITE_OK ){
2834328374
if( h>=0 ) robust_close(pNew, h, __LINE__);
2834428375
h = -1;
2834528376
osUnlink(zFilename);
28346
- isDelete = 0;
28377
+ pNew->ctrlFlags |= UNIXFILE_DELETE;
2834728378
}
28348
- if( isDelete ) pNew->ctrlFlags |= UNIXFILE_DELETE;
2834928379
#endif
2835028380
if( rc!=SQLITE_OK ){
2835128381
if( h>=0 ) robust_close(pNew, h, __LINE__);
2835228382
}else{
2835328383
pNew->pMethod = pLockingStyle;
@@ -38108,10 +38138,11 @@
3810838138
# define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0
3810938139
# define sqlite3WalCallback(z) 0
3811038140
# define sqlite3WalExclusiveMode(y,z) 0
3811138141
# define sqlite3WalHeapMemory(z) 0
3811238142
# define sqlite3WalFramesize(z) 0
38143
+# define sqlite3WalFindFrame(x,y,z) 0
3811338144
#else
3811438145
3811538146
#define WAL_SAVEPOINT_NDATA 4
3811638147
3811738148
/* Connection to a write-ahead log (WAL) file.
@@ -41052,14 +41083,17 @@
4105241083
assert( pPager->tempFile );
4105341084
memset(pPg->pData, 0, pPager->pageSize);
4105441085
return SQLITE_OK;
4105541086
}
4105641087
41088
+#ifndef SQLITE_OMIT_WAL
4105741089
if( iFrame ){
4105841090
/* Try to pull the page from the write-ahead log. */
4105941091
rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
41060
- }else{
41092
+ }else
41093
+#endif
41094
+ {
4106141095
i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
4106241096
rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
4106341097
if( rc==SQLITE_IOERR_SHORT_READ ){
4106441098
rc = SQLITE_OK;
4106541099
}
@@ -44108,10 +44142,15 @@
4410844142
if( rc==SQLITE_OK ){
4410944143
rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
4411044144
pPager->aStat[PAGER_STAT_WRITE]++;
4411144145
}
4411244146
if( rc==SQLITE_OK ){
44147
+ /* Update the pager's copy of the change-counter. Otherwise, the
44148
+ ** next time a read transaction is opened the cache will be
44149
+ ** flushed (as the change-counter values will not match). */
44150
+ const void *pCopy = (const void *)&((const char *)zBuf)[24];
44151
+ memcpy(&pPager->dbFileVers, pCopy, sizeof(pPager->dbFileVers));
4411344152
pPager->changeCountDone = 1;
4411444153
}
4411544154
}else{
4411644155
pPager->changeCountDone = 1;
4411744156
}
@@ -94790,10 +94829,15 @@
9479094829
** PRAGMA [database.]schema_version
9479194830
** PRAGMA [database.]schema_version = <integer>
9479294831
**
9479394832
** PRAGMA [database.]user_version
9479494833
** PRAGMA [database.]user_version = <integer>
94834
+ **
94835
+ ** PRAGMA [database.]freelist_count = <integer>
94836
+ **
94837
+ ** PRAGMA [database.]application_id
94838
+ ** PRAGMA [database.]application_id = <integer>
9479594839
**
9479694840
** The pragma's schema_version and user_version are used to set or get
9479794841
** the value of the schema-version and user-version, respectively. Both
9479894842
** the schema-version and the user-version are 32-bit signed integers
9479994843
** stored in the database header.
@@ -94812,14 +94856,18 @@
9481294856
** applications for any purpose.
9481394857
*/
9481494858
if( sqlite3StrICmp(zLeft, "schema_version")==0
9481594859
|| sqlite3StrICmp(zLeft, "user_version")==0
9481694860
|| sqlite3StrICmp(zLeft, "freelist_count")==0
94861
+ || sqlite3StrICmp(zLeft, "application_id")==0
9481794862
){
9481894863
int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
9481994864
sqlite3VdbeUsesBtree(v, iDb);
9482094865
switch( zLeft[0] ){
94866
+ case 'a': case 'A':
94867
+ iCookie = BTREE_APPLICATION_ID;
94868
+ break;
9482194869
case 'f': case 'F':
9482294870
iCookie = BTREE_FREE_PAGE_COUNT;
9482394871
break;
9482494872
case 's': case 'S':
9482594873
iCookie = BTREE_SCHEMA_VERSION;
@@ -102982,10 +103030,11 @@
102982103030
static const unsigned char aCopy[] = {
102983103031
BTREE_SCHEMA_VERSION, 1, /* Add one to the old schema cookie */
102984103032
BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
102985103033
BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
102986103034
BTREE_USER_VERSION, 0, /* Preserve the user version */
103035
+ BTREE_APPLICATION_ID, 0, /* Preserve the application id */
102987103036
};
102988103037
102989103038
assert( 1==sqlite3BtreeIsInTrans(pTemp) );
102990103039
assert( 1==sqlite3BtreeIsInTrans(pMain) );
102991103040
@@ -104849,11 +104898,11 @@
104849104898
}
104850104899
if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ){
104851104900
continue;
104852104901
}
104853104902
}
104854
- if( pTerm->prereqRight==0 ){
104903
+ if( pTerm->prereqRight==0 && (pTerm->eOperator&WO_EQ)!=0 ){
104855104904
pResult = pTerm;
104856104905
goto findTerm_success;
104857104906
}else if( pResult==0 ){
104858104907
pResult = pTerm;
104859104908
}
@@ -109027,10 +109076,11 @@
109027109076
pE = pTerm->pExpr;
109028109077
assert( !ExprHasProperty(pE, EP_FromJoin) );
109029109078
assert( (pTerm->prereqRight & newNotReady)!=0 );
109030109079
pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
109031109080
if( pAlt==0 ) continue;
109081
+ if( pAlt->wtFlags & (TERM_CODED) ) continue;
109032109082
VdbeNoopComment((v, "begin transitive constraint"));
109033109083
sEq = *pAlt->pExpr;
109034109084
sEq.pLeft = pE->pLeft;
109035109085
sqlite3ExprIfFalse(pParse, &sEq, addrCont, SQLITE_JUMPIFNULL);
109036109086
}
@@ -112374,11 +112424,13 @@
112374112424
if( yygotominor.yy347 ){
112375112425
struct SrcList_item *pNew = &yygotominor.yy347->a[yygotominor.yy347->nSrc-1];
112376112426
struct SrcList_item *pOld = yymsp[-4].minor.yy347->a;
112377112427
pNew->zName = pOld->zName;
112378112428
pNew->zDatabase = pOld->zDatabase;
112429
+ pNew->pSelect = pOld->pSelect;
112379112430
pOld->zName = pOld->zDatabase = 0;
112431
+ pOld->pSelect = 0;
112380112432
}
112381112433
sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy347);
112382112434
}else{
112383112435
Select *pSubquery;
112384112436
sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
@@ -119192,11 +119244,11 @@
119192119244
);
119193119245
SQLITE_PRIVATE void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *);
119194119246
119195119247
/* fts3_expr.c */
119196119248
SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int,
119197
- char **, int, int, int, const char *, int, Fts3Expr **
119249
+ char **, int, int, int, const char *, int, Fts3Expr **, char **
119198119250
);
119199119251
SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
119200119252
#ifdef SQLITE_TEST
119201119253
SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
119202119254
SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
@@ -121916,18 +121968,16 @@
121916121968
}
121917121969
121918121970
pCsr->iLangid = 0;
121919121971
if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]);
121920121972
121973
+ assert( p->base.zErrMsg==0 );
121921121974
rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid,
121922
- p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr
121975
+ p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr,
121976
+ &p->base.zErrMsg
121923121977
);
121924121978
if( rc!=SQLITE_OK ){
121925
- if( rc==SQLITE_ERROR ){
121926
- static const char *zErr = "malformed MATCH expression: [%s]";
121927
- p->base.zErrMsg = sqlite3_mprintf(zErr, zQuery);
121928
- }
121929121979
return rc;
121930121980
}
121931121981
121932121982
rc = sqlite3Fts3ReadLock(p);
121933121983
if( rc!=SQLITE_OK ) return rc;
@@ -125425,12 +125475,14 @@
125425125475
rc = SQLITE_NOMEM;
125426125476
goto exprparse_out;
125427125477
}
125428125478
pNot->eType = FTSQUERY_NOT;
125429125479
pNot->pRight = p;
125480
+ p->pParent = pNot;
125430125481
if( pNotBranch ){
125431125482
pNot->pLeft = pNotBranch;
125483
+ pNotBranch->pParent = pNot;
125432125484
}
125433125485
pNotBranch = pNot;
125434125486
p = pPrev;
125435125487
}else{
125436125488
int eType = p->eType;
@@ -125514,10 +125566,11 @@
125514125566
Fts3Expr *pIter = pNotBranch;
125515125567
while( pIter->pLeft ){
125516125568
pIter = pIter->pLeft;
125517125569
}
125518125570
pIter->pLeft = pRet;
125571
+ pRet->pParent = pIter;
125519125572
pRet = pNotBranch;
125520125573
}
125521125574
}
125522125575
}
125523125576
*pnConsumed = n - nIn;
@@ -125529,10 +125582,226 @@
125529125582
pRet = 0;
125530125583
}
125531125584
*ppExpr = pRet;
125532125585
return rc;
125533125586
}
125587
+
125588
+/*
125589
+** Return SQLITE_ERROR if the maximum depth of the expression tree passed
125590
+** as the only argument is more than nMaxDepth.
125591
+*/
125592
+static int fts3ExprCheckDepth(Fts3Expr *p, int nMaxDepth){
125593
+ int rc = SQLITE_OK;
125594
+ if( p ){
125595
+ if( nMaxDepth<0 ){
125596
+ rc = SQLITE_TOOBIG;
125597
+ }else{
125598
+ rc = fts3ExprCheckDepth(p->pLeft, nMaxDepth-1);
125599
+ if( rc==SQLITE_OK ){
125600
+ rc = fts3ExprCheckDepth(p->pRight, nMaxDepth-1);
125601
+ }
125602
+ }
125603
+ }
125604
+ return rc;
125605
+}
125606
+
125607
+/*
125608
+** This function attempts to transform the expression tree at (*pp) to
125609
+** an equivalent but more balanced form. The tree is modified in place.
125610
+** If successful, SQLITE_OK is returned and (*pp) set to point to the
125611
+** new root expression node.
125612
+**
125613
+** nMaxDepth is the maximum allowable depth of the balanced sub-tree.
125614
+**
125615
+** Otherwise, if an error occurs, an SQLite error code is returned and
125616
+** expression (*pp) freed.
125617
+*/
125618
+static int fts3ExprBalance(Fts3Expr **pp, int nMaxDepth){
125619
+ int rc = SQLITE_OK; /* Return code */
125620
+ Fts3Expr *pRoot = *pp; /* Initial root node */
125621
+ Fts3Expr *pFree = 0; /* List of free nodes. Linked by pParent. */
125622
+ int eType = pRoot->eType; /* Type of node in this tree */
125623
+
125624
+ if( nMaxDepth==0 ){
125625
+ rc = SQLITE_ERROR;
125626
+ }
125627
+
125628
+ if( rc==SQLITE_OK && (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
125629
+ Fts3Expr **apLeaf;
125630
+ apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
125631
+ if( 0==apLeaf ){
125632
+ rc = SQLITE_NOMEM;
125633
+ }else{
125634
+ memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
125635
+ }
125636
+
125637
+ if( rc==SQLITE_OK ){
125638
+ int i;
125639
+ Fts3Expr *p;
125640
+
125641
+ /* Set $p to point to the left-most leaf in the tree of eType nodes. */
125642
+ for(p=pRoot; p->eType==eType; p=p->pLeft){
125643
+ assert( p->pParent==0 || p->pParent->pLeft==p );
125644
+ assert( p->pLeft && p->pRight );
125645
+ }
125646
+
125647
+ /* This loop runs once for each leaf in the tree of eType nodes. */
125648
+ while( 1 ){
125649
+ int iLvl;
125650
+ Fts3Expr *pParent = p->pParent; /* Current parent of p */
125651
+
125652
+ assert( pParent==0 || pParent->pLeft==p );
125653
+ p->pParent = 0;
125654
+ if( pParent ){
125655
+ pParent->pLeft = 0;
125656
+ }else{
125657
+ pRoot = 0;
125658
+ }
125659
+ rc = fts3ExprBalance(&p, nMaxDepth-1);
125660
+ if( rc!=SQLITE_OK ) break;
125661
+
125662
+ for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
125663
+ if( apLeaf[iLvl]==0 ){
125664
+ apLeaf[iLvl] = p;
125665
+ p = 0;
125666
+ }else{
125667
+ assert( pFree );
125668
+ pFree->pLeft = apLeaf[iLvl];
125669
+ pFree->pRight = p;
125670
+ pFree->pLeft->pParent = pFree;
125671
+ pFree->pRight->pParent = pFree;
125672
+
125673
+ p = pFree;
125674
+ pFree = pFree->pParent;
125675
+ p->pParent = 0;
125676
+ apLeaf[iLvl] = 0;
125677
+ }
125678
+ }
125679
+ if( p ){
125680
+ sqlite3Fts3ExprFree(p);
125681
+ rc = SQLITE_TOOBIG;
125682
+ break;
125683
+ }
125684
+
125685
+ /* If that was the last leaf node, break out of the loop */
125686
+ if( pParent==0 ) break;
125687
+
125688
+ /* Set $p to point to the next leaf in the tree of eType nodes */
125689
+ for(p=pParent->pRight; p->eType==eType; p=p->pLeft);
125690
+
125691
+ /* Remove pParent from the original tree. */
125692
+ assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
125693
+ pParent->pRight->pParent = pParent->pParent;
125694
+ if( pParent->pParent ){
125695
+ pParent->pParent->pLeft = pParent->pRight;
125696
+ }else{
125697
+ assert( pParent==pRoot );
125698
+ pRoot = pParent->pRight;
125699
+ }
125700
+
125701
+ /* Link pParent into the free node list. It will be used as an
125702
+ ** internal node of the new tree. */
125703
+ pParent->pParent = pFree;
125704
+ pFree = pParent;
125705
+ }
125706
+
125707
+ if( rc==SQLITE_OK ){
125708
+ p = 0;
125709
+ for(i=0; i<nMaxDepth; i++){
125710
+ if( apLeaf[i] ){
125711
+ if( p==0 ){
125712
+ p = apLeaf[i];
125713
+ p->pParent = 0;
125714
+ }else{
125715
+ pFree->pRight = p;
125716
+ pFree->pLeft = apLeaf[i];
125717
+ pFree->pLeft->pParent = pFree;
125718
+ pFree->pRight->pParent = pFree;
125719
+
125720
+ p = pFree;
125721
+ pFree = pFree->pParent;
125722
+ p->pParent = 0;
125723
+ }
125724
+ }
125725
+ }
125726
+ pRoot = p;
125727
+ }else{
125728
+ /* An error occurred. Delete the contents of the apLeaf[] array
125729
+ ** and pFree list. Everything else is cleaned up by the call to
125730
+ ** sqlite3Fts3ExprFree(pRoot) below. */
125731
+ Fts3Expr *pDel;
125732
+ for(i=0; i<nMaxDepth; i++){
125733
+ sqlite3Fts3ExprFree(apLeaf[i]);
125734
+ }
125735
+ while( (pDel=pFree)!=0 ){
125736
+ pFree = pDel->pParent;
125737
+ sqlite3_free(pDel);
125738
+ }
125739
+ }
125740
+
125741
+ assert( pFree==0 );
125742
+ sqlite3_free( apLeaf );
125743
+ }
125744
+ }
125745
+
125746
+ if( rc!=SQLITE_OK ){
125747
+ sqlite3Fts3ExprFree(pRoot);
125748
+ pRoot = 0;
125749
+ }
125750
+ *pp = pRoot;
125751
+ return rc;
125752
+}
125753
+
125754
+/*
125755
+** This function is similar to sqlite3Fts3ExprParse(), with the following
125756
+** differences:
125757
+**
125758
+** 1. It does not do expression rebalancing.
125759
+** 2. It does not check that the expression does not exceed the
125760
+** maximum allowable depth.
125761
+** 3. Even if it fails, *ppExpr may still be set to point to an
125762
+** expression tree. It should be deleted using sqlite3Fts3ExprFree()
125763
+** in this case.
125764
+*/
125765
+static int fts3ExprParseUnbalanced(
125766
+ sqlite3_tokenizer *pTokenizer, /* Tokenizer module */
125767
+ int iLangid, /* Language id for tokenizer */
125768
+ char **azCol, /* Array of column names for fts3 table */
125769
+ int bFts4, /* True to allow FTS4-only syntax */
125770
+ int nCol, /* Number of entries in azCol[] */
125771
+ int iDefaultCol, /* Default column to query */
125772
+ const char *z, int n, /* Text of MATCH query */
125773
+ Fts3Expr **ppExpr /* OUT: Parsed query structure */
125774
+){
125775
+ int nParsed;
125776
+ int rc;
125777
+ ParseContext sParse;
125778
+
125779
+ memset(&sParse, 0, sizeof(ParseContext));
125780
+ sParse.pTokenizer = pTokenizer;
125781
+ sParse.iLangid = iLangid;
125782
+ sParse.azCol = (const char **)azCol;
125783
+ sParse.nCol = nCol;
125784
+ sParse.iDefaultCol = iDefaultCol;
125785
+ sParse.bFts4 = bFts4;
125786
+ if( z==0 ){
125787
+ *ppExpr = 0;
125788
+ return SQLITE_OK;
125789
+ }
125790
+ if( n<0 ){
125791
+ n = (int)strlen(z);
125792
+ }
125793
+ rc = fts3ExprParse(&sParse, z, n, ppExpr, &nParsed);
125794
+ assert( rc==SQLITE_OK || *ppExpr==0 );
125795
+
125796
+ /* Check for mismatched parenthesis */
125797
+ if( rc==SQLITE_OK && sParse.nNest ){
125798
+ rc = SQLITE_ERROR;
125799
+ }
125800
+
125801
+ return rc;
125802
+}
125534125803
125535125804
/*
125536125805
** Parameters z and n contain a pointer to and length of a buffer containing
125537125806
** an fts3 query expression, respectively. This function attempts to parse the
125538125807
** query expression and create a tree of Fts3Expr structures representing the
@@ -125562,53 +125831,78 @@
125562125831
char **azCol, /* Array of column names for fts3 table */
125563125832
int bFts4, /* True to allow FTS4-only syntax */
125564125833
int nCol, /* Number of entries in azCol[] */
125565125834
int iDefaultCol, /* Default column to query */
125566125835
const char *z, int n, /* Text of MATCH query */
125567
- Fts3Expr **ppExpr /* OUT: Parsed query structure */
125836
+ Fts3Expr **ppExpr, /* OUT: Parsed query structure */
125837
+ char **pzErr /* OUT: Error message (sqlite3_malloc) */
125568125838
){
125569
- int nParsed;
125570
- int rc;
125571
- ParseContext sParse;
125572
-
125573
- memset(&sParse, 0, sizeof(ParseContext));
125574
- sParse.pTokenizer = pTokenizer;
125575
- sParse.iLangid = iLangid;
125576
- sParse.azCol = (const char **)azCol;
125577
- sParse.nCol = nCol;
125578
- sParse.iDefaultCol = iDefaultCol;
125579
- sParse.bFts4 = bFts4;
125580
- if( z==0 ){
125581
- *ppExpr = 0;
125582
- return SQLITE_OK;
125583
- }
125584
- if( n<0 ){
125585
- n = (int)strlen(z);
125586
- }
125587
- rc = fts3ExprParse(&sParse, z, n, ppExpr, &nParsed);
125588
-
125589
- /* Check for mismatched parenthesis */
125590
- if( rc==SQLITE_OK && sParse.nNest ){
125591
- rc = SQLITE_ERROR;
125839
+ static const int MAX_EXPR_DEPTH = 12;
125840
+ int rc = fts3ExprParseUnbalanced(
125841
+ pTokenizer, iLangid, azCol, bFts4, nCol, iDefaultCol, z, n, ppExpr
125842
+ );
125843
+
125844
+ /* Rebalance the expression. And check that its depth does not exceed
125845
+ ** MAX_EXPR_DEPTH. */
125846
+ if( rc==SQLITE_OK && *ppExpr ){
125847
+ rc = fts3ExprBalance(ppExpr, MAX_EXPR_DEPTH);
125848
+ if( rc==SQLITE_OK ){
125849
+ rc = fts3ExprCheckDepth(*ppExpr, MAX_EXPR_DEPTH);
125850
+ }
125851
+ }
125852
+
125853
+ if( rc!=SQLITE_OK ){
125592125854
sqlite3Fts3ExprFree(*ppExpr);
125593125855
*ppExpr = 0;
125856
+ if( rc==SQLITE_TOOBIG ){
125857
+ *pzErr = sqlite3_mprintf(
125858
+ "FTS expression tree is too large (maximum depth %d)", MAX_EXPR_DEPTH
125859
+ );
125860
+ rc = SQLITE_ERROR;
125861
+ }else if( rc==SQLITE_ERROR ){
125862
+ *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
125863
+ }
125594125864
}
125595125865
125596125866
return rc;
125597125867
}
125868
+
125869
+/*
125870
+** Free a single node of an expression tree.
125871
+*/
125872
+static void fts3FreeExprNode(Fts3Expr *p){
125873
+ assert( p->eType==FTSQUERY_PHRASE || p->pPhrase==0 );
125874
+ sqlite3Fts3EvalPhraseCleanup(p->pPhrase);
125875
+ sqlite3_free(p->aMI);
125876
+ sqlite3_free(p);
125877
+}
125598125878
125599125879
/*
125600125880
** Free a parsed fts3 query expression allocated by sqlite3Fts3ExprParse().
125881
+**
125882
+** This function would be simpler if it recursively called itself. But
125883
+** that would mean passing a sufficiently large expression to ExprParse()
125884
+** could cause a stack overflow.
125601125885
*/
125602
-SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *p){
125603
- if( p ){
125604
- assert( p->eType==FTSQUERY_PHRASE || p->pPhrase==0 );
125605
- sqlite3Fts3ExprFree(p->pLeft);
125606
- sqlite3Fts3ExprFree(p->pRight);
125607
- sqlite3Fts3EvalPhraseCleanup(p->pPhrase);
125608
- sqlite3_free(p->aMI);
125609
- sqlite3_free(p);
125886
+SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *pDel){
125887
+ Fts3Expr *p;
125888
+ assert( pDel==0 || pDel->pParent==0 );
125889
+ for(p=pDel; p && (p->pLeft||p->pRight); p=(p->pLeft ? p->pLeft : p->pRight)){
125890
+ assert( p->pParent==0 || p==p->pParent->pRight || p==p->pParent->pLeft );
125891
+ }
125892
+ while( p ){
125893
+ Fts3Expr *pParent = p->pParent;
125894
+ fts3FreeExprNode(p);
125895
+ if( pParent && p==pParent->pLeft && pParent->pRight ){
125896
+ p = pParent->pRight;
125897
+ while( p && (p->pLeft || p->pRight) ){
125898
+ assert( p==p->pParent->pRight || p==p->pParent->pLeft );
125899
+ p = (p->pLeft ? p->pLeft : p->pRight);
125900
+ }
125901
+ }else{
125902
+ p = pParent;
125903
+ }
125610125904
}
125611125905
}
125612125906
125613125907
/****************************************************************************
125614125908
*****************************************************************************
@@ -125656,10 +125950,13 @@
125656125950
**
125657125951
** If the second argument is not NULL, then its contents are prepended to
125658125952
** the returned expression text and then freed using sqlite3_free().
125659125953
*/
125660125954
static char *exprToString(Fts3Expr *pExpr, char *zBuf){
125955
+ if( pExpr==0 ){
125956
+ return sqlite3_mprintf("");
125957
+ }
125661125958
switch( pExpr->eType ){
125662125959
case FTSQUERY_PHRASE: {
125663125960
Fts3Phrase *pPhrase = pExpr->pPhrase;
125664125961
int i;
125665125962
zBuf = sqlite3_mprintf(
@@ -125763,14 +126060,25 @@
125763126060
}
125764126061
for(ii=0; ii<nCol; ii++){
125765126062
azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
125766126063
}
125767126064
125768
- rc = sqlite3Fts3ExprParse(
125769
- pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
125770
- );
126065
+ if( sqlite3_user_data(context) ){
126066
+ char *zDummy = 0;
126067
+ rc = sqlite3Fts3ExprParse(
126068
+ pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr, &zDummy
126069
+ );
126070
+ assert( rc==SQLITE_OK || pExpr==0 );
126071
+ sqlite3_free(zDummy);
126072
+ }else{
126073
+ rc = fts3ExprParseUnbalanced(
126074
+ pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
126075
+ );
126076
+ }
126077
+
125771126078
if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){
126079
+ sqlite3Fts3ExprFree(pExpr);
125772126080
sqlite3_result_error(context, "Error parsing expression", -1);
125773126081
}else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
125774126082
sqlite3_result_error_nomem(context);
125775126083
}else{
125776126084
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
@@ -125789,13 +126097,19 @@
125789126097
/*
125790126098
** Register the query expression parser test function fts3_exprtest()
125791126099
** with database connection db.
125792126100
*/
125793126101
SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
125794
- return sqlite3_create_function(
126102
+ int rc = sqlite3_create_function(
125795126103
db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
125796126104
);
126105
+ if( rc==SQLITE_OK ){
126106
+ rc = sqlite3_create_function(db, "fts3_exprtest_rebalance",
126107
+ -1, SQLITE_UTF8, (void *)1, fts3ExprTest, 0, 0
126108
+ );
126109
+ }
126110
+ return rc;
125797126111
}
125798126112
125799126113
#endif
125800126114
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
125801126115
125802126116
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -678,11 +678,11 @@
678 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
679 ** [sqlite_version()] and [sqlite_source_id()].
680 */
681 #define SQLITE_VERSION "3.7.17"
682 #define SQLITE_VERSION_NUMBER 3007017
683 #define SQLITE_SOURCE_ID "2013-04-25 17:27:08 aabeea98f53edde68f484f1794ae70789dac3889"
684
685 /*
686 ** CAPI3REF: Run-Time Library Version Numbers
687 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
688 **
@@ -2161,11 +2161,13 @@
2161 ** <dd> ^(This option takes a single argument which is a pointer to an
2162 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
2163 ** page cache implementation into that object.)^ </dd>
2164 **
2165 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2166 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
 
 
2167 ** function with a call signature of void(*)(void*,int,const char*),
2168 ** and a pointer to void. ^If the function pointer is not NULL, it is
2169 ** invoked by [sqlite3_log()] to process each logging event. ^If the
2170 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
2171 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
@@ -3096,10 +3098,13 @@
3096 ** SQL statement text as the statement first begins executing.
3097 ** ^(Additional sqlite3_trace() callbacks might occur
3098 ** as each triggered subprogram is entered. The callbacks for triggers
3099 ** contain a UTF-8 SQL comment that identifies the trigger.)^
3100 **
 
 
 
3101 ** ^The callback function registered by sqlite3_profile() is invoked
3102 ** as each SQL statement finishes. ^The profile callback contains
3103 ** the original statement text and an estimate of wall-clock time
3104 ** of how long that statement took to run. ^The profile callback
3105 ** time is in units of nanoseconds, however the current implementation
@@ -3634,11 +3639,12 @@
3634 **
3635 ** <ol>
3636 ** <li>
3637 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3638 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3639 ** statement and try to run it again.
 
3640 ** </li>
3641 **
3642 ** <li>
3643 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3644 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3838,10 +3844,13 @@
3838 ** for "?NNN" parameters is the value of NNN.
3839 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
3840 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
3841 **
3842 ** ^The third argument is the value to bind to the parameter.
 
 
 
3843 **
3844 ** ^(In those routines that have a fourth argument, its value is the
3845 ** number of bytes in the parameter. To be clear: the value is the
3846 ** number of <u>bytes</u> in the value, not the number of characters.)^
3847 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -7446,11 +7455,11 @@
7446 SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
7447
7448 /*
7449 ** CAPI3REF: Error Logging Interface
7450 **
7451 ** ^The [sqlite3_log()] interface writes a message into the error log
7452 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
7453 ** ^If logging is enabled, the zFormat string and subsequent arguments are
7454 ** used with [sqlite3_snprintf()] to generate the final output string.
7455 **
7456 ** The sqlite3_log() interface is intended for use by extensions such as
@@ -8302,11 +8311,11 @@
8302 #ifndef SQLITE_MAX_MMAP_SIZE
8303 # if defined(__linux__) \
8304 || defined(_WIN32) \
8305 || (defined(__APPLE__) && defined(__MACH__)) \
8306 || defined(__sun)
8307 # define SQLITE_MAX_MMAP_SIZE 2147483648
8308 # else
8309 # define SQLITE_MAX_MMAP_SIZE 0
8310 # endif
8311 # define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */
8312 #endif
@@ -8620,10 +8629,11 @@
8620 #define BTREE_DEFAULT_CACHE_SIZE 3
8621 #define BTREE_LARGEST_ROOT_PAGE 4
8622 #define BTREE_TEXT_ENCODING 5
8623 #define BTREE_USER_VERSION 6
8624 #define BTREE_INCR_VACUUM 7
 
8625
8626 /*
8627 ** Values that may be OR'd together to form the second argument of an
8628 ** sqlite3BtreeCursorHints() call.
8629 */
@@ -22993,11 +23003,11 @@
22993 #include <fcntl.h>
22994 #include <unistd.h>
22995 /* #include <time.h> */
22996 #include <sys/time.h>
22997 #include <errno.h>
22998 #ifndef SQLITE_OMIT_WAL
22999 #include <sys/mman.h>
23000 #endif
23001
23002
23003 #if SQLITE_ENABLE_LOCKING_STYLE
@@ -26267,52 +26277,65 @@
26267 /* Unread parts of the buffer must be zero-filled */
26268 memset(&((char*)pBuf)[got], 0, amt-got);
26269 return SQLITE_IOERR_SHORT_READ;
26270 }
26271 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26272
26273 /*
26274 ** Seek to the offset in id->offset then read cnt bytes into pBuf.
26275 ** Return the number of bytes actually read. Update the offset.
26276 **
26277 ** To avoid stomping the errno value on a failed write the lastErrno value
26278 ** is set before returning.
26279 */
26280 static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
26281 int got;
26282 #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
26283 i64 newOffset;
26284 #endif
26285 assert( cnt==(cnt&0x1ffff) );
26286 cnt &= 0x1ffff;
26287 TIMER_START;
26288 #if defined(USE_PREAD)
26289 do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
26290 #elif defined(USE_PREAD64)
26291 do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR);
26292 #else
26293 do{
26294 newOffset = lseek(id->h, offset, SEEK_SET);
26295 SimulateIOError( newOffset-- );
26296 if( newOffset!=offset ){
26297 if( newOffset == -1 ){
26298 ((unixFile*)id)->lastErrno = errno;
26299 }else{
26300 ((unixFile*)id)->lastErrno = 0;
26301 }
26302 return -1;
26303 }
26304 got = osWrite(id->h, pBuf, cnt);
26305 }while( got<0 && errno==EINTR );
26306 #endif
26307 TIMER_END;
26308 if( got<0 ){
26309 ((unixFile*)id)->lastErrno = errno;
26310 }
26311
26312 OSTRACE(("WRITE %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED));
26313 return got;
26314 }
26315
26316
26317 /*
26318 ** Write data from a buffer into a file. Return SQLITE_OK on success
@@ -27397,28 +27420,36 @@
27397 }
27398
27399 if( sStat.st_size<nByte ){
27400 /* The requested memory region does not exist. If bExtend is set to
27401 ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
27402 **
27403 ** Alternatively, if bExtend is true, use ftruncate() to allocate
27404 ** the requested memory region.
27405 */
27406 if( !bExtend ) goto shmpage_out;
27407 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
27408 if( osFallocate(pShmNode->h, sStat.st_size, nByte)!=0 ){
27409 rc = unixLogError(SQLITE_IOERR_SHMSIZE, "fallocate",
27410 pShmNode->zFilename);
27411 goto shmpage_out;
27412 }
27413 #else
27414 if( robust_ftruncate(pShmNode->h, nByte) ){
27415 rc = unixLogError(SQLITE_IOERR_SHMSIZE, "ftruncate",
27416 pShmNode->zFilename);
27417 goto shmpage_out;
27418 }
27419 #endif
 
 
 
 
 
 
 
 
27420 }
27421 }
27422
27423 /* Map the requested memory region into this processes address space. */
27424 apNew = (char **)sqlite3_realloc(
@@ -28341,13 +28372,12 @@
28341 #if OS_VXWORKS
28342 if( rc!=SQLITE_OK ){
28343 if( h>=0 ) robust_close(pNew, h, __LINE__);
28344 h = -1;
28345 osUnlink(zFilename);
28346 isDelete = 0;
28347 }
28348 if( isDelete ) pNew->ctrlFlags |= UNIXFILE_DELETE;
28349 #endif
28350 if( rc!=SQLITE_OK ){
28351 if( h>=0 ) robust_close(pNew, h, __LINE__);
28352 }else{
28353 pNew->pMethod = pLockingStyle;
@@ -38108,10 +38138,11 @@
38108 # define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0
38109 # define sqlite3WalCallback(z) 0
38110 # define sqlite3WalExclusiveMode(y,z) 0
38111 # define sqlite3WalHeapMemory(z) 0
38112 # define sqlite3WalFramesize(z) 0
 
38113 #else
38114
38115 #define WAL_SAVEPOINT_NDATA 4
38116
38117 /* Connection to a write-ahead log (WAL) file.
@@ -41052,14 +41083,17 @@
41052 assert( pPager->tempFile );
41053 memset(pPg->pData, 0, pPager->pageSize);
41054 return SQLITE_OK;
41055 }
41056
 
41057 if( iFrame ){
41058 /* Try to pull the page from the write-ahead log. */
41059 rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
41060 }else{
 
 
41061 i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
41062 rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
41063 if( rc==SQLITE_IOERR_SHORT_READ ){
41064 rc = SQLITE_OK;
41065 }
@@ -44108,10 +44142,15 @@
44108 if( rc==SQLITE_OK ){
44109 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
44110 pPager->aStat[PAGER_STAT_WRITE]++;
44111 }
44112 if( rc==SQLITE_OK ){
 
 
 
 
 
44113 pPager->changeCountDone = 1;
44114 }
44115 }else{
44116 pPager->changeCountDone = 1;
44117 }
@@ -94790,10 +94829,15 @@
94790 ** PRAGMA [database.]schema_version
94791 ** PRAGMA [database.]schema_version = <integer>
94792 **
94793 ** PRAGMA [database.]user_version
94794 ** PRAGMA [database.]user_version = <integer>
 
 
 
 
 
94795 **
94796 ** The pragma's schema_version and user_version are used to set or get
94797 ** the value of the schema-version and user-version, respectively. Both
94798 ** the schema-version and the user-version are 32-bit signed integers
94799 ** stored in the database header.
@@ -94812,14 +94856,18 @@
94812 ** applications for any purpose.
94813 */
94814 if( sqlite3StrICmp(zLeft, "schema_version")==0
94815 || sqlite3StrICmp(zLeft, "user_version")==0
94816 || sqlite3StrICmp(zLeft, "freelist_count")==0
 
94817 ){
94818 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
94819 sqlite3VdbeUsesBtree(v, iDb);
94820 switch( zLeft[0] ){
 
 
 
94821 case 'f': case 'F':
94822 iCookie = BTREE_FREE_PAGE_COUNT;
94823 break;
94824 case 's': case 'S':
94825 iCookie = BTREE_SCHEMA_VERSION;
@@ -102982,10 +103030,11 @@
102982 static const unsigned char aCopy[] = {
102983 BTREE_SCHEMA_VERSION, 1, /* Add one to the old schema cookie */
102984 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
102985 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
102986 BTREE_USER_VERSION, 0, /* Preserve the user version */
 
102987 };
102988
102989 assert( 1==sqlite3BtreeIsInTrans(pTemp) );
102990 assert( 1==sqlite3BtreeIsInTrans(pMain) );
102991
@@ -104849,11 +104898,11 @@
104849 }
104850 if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ){
104851 continue;
104852 }
104853 }
104854 if( pTerm->prereqRight==0 ){
104855 pResult = pTerm;
104856 goto findTerm_success;
104857 }else if( pResult==0 ){
104858 pResult = pTerm;
104859 }
@@ -109027,10 +109076,11 @@
109027 pE = pTerm->pExpr;
109028 assert( !ExprHasProperty(pE, EP_FromJoin) );
109029 assert( (pTerm->prereqRight & newNotReady)!=0 );
109030 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
109031 if( pAlt==0 ) continue;
 
109032 VdbeNoopComment((v, "begin transitive constraint"));
109033 sEq = *pAlt->pExpr;
109034 sEq.pLeft = pE->pLeft;
109035 sqlite3ExprIfFalse(pParse, &sEq, addrCont, SQLITE_JUMPIFNULL);
109036 }
@@ -112374,11 +112424,13 @@
112374 if( yygotominor.yy347 ){
112375 struct SrcList_item *pNew = &yygotominor.yy347->a[yygotominor.yy347->nSrc-1];
112376 struct SrcList_item *pOld = yymsp[-4].minor.yy347->a;
112377 pNew->zName = pOld->zName;
112378 pNew->zDatabase = pOld->zDatabase;
 
112379 pOld->zName = pOld->zDatabase = 0;
 
112380 }
112381 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy347);
112382 }else{
112383 Select *pSubquery;
112384 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
@@ -119192,11 +119244,11 @@
119192 );
119193 SQLITE_PRIVATE void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *);
119194
119195 /* fts3_expr.c */
119196 SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int,
119197 char **, int, int, int, const char *, int, Fts3Expr **
119198 );
119199 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
119200 #ifdef SQLITE_TEST
119201 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
119202 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
@@ -121916,18 +121968,16 @@
121916 }
121917
121918 pCsr->iLangid = 0;
121919 if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]);
121920
 
121921 rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid,
121922 p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr
 
121923 );
121924 if( rc!=SQLITE_OK ){
121925 if( rc==SQLITE_ERROR ){
121926 static const char *zErr = "malformed MATCH expression: [%s]";
121927 p->base.zErrMsg = sqlite3_mprintf(zErr, zQuery);
121928 }
121929 return rc;
121930 }
121931
121932 rc = sqlite3Fts3ReadLock(p);
121933 if( rc!=SQLITE_OK ) return rc;
@@ -125425,12 +125475,14 @@
125425 rc = SQLITE_NOMEM;
125426 goto exprparse_out;
125427 }
125428 pNot->eType = FTSQUERY_NOT;
125429 pNot->pRight = p;
 
125430 if( pNotBranch ){
125431 pNot->pLeft = pNotBranch;
 
125432 }
125433 pNotBranch = pNot;
125434 p = pPrev;
125435 }else{
125436 int eType = p->eType;
@@ -125514,10 +125566,11 @@
125514 Fts3Expr *pIter = pNotBranch;
125515 while( pIter->pLeft ){
125516 pIter = pIter->pLeft;
125517 }
125518 pIter->pLeft = pRet;
 
125519 pRet = pNotBranch;
125520 }
125521 }
125522 }
125523 *pnConsumed = n - nIn;
@@ -125529,10 +125582,226 @@
125529 pRet = 0;
125530 }
125531 *ppExpr = pRet;
125532 return rc;
125533 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125534
125535 /*
125536 ** Parameters z and n contain a pointer to and length of a buffer containing
125537 ** an fts3 query expression, respectively. This function attempts to parse the
125538 ** query expression and create a tree of Fts3Expr structures representing the
@@ -125562,53 +125831,78 @@
125562 char **azCol, /* Array of column names for fts3 table */
125563 int bFts4, /* True to allow FTS4-only syntax */
125564 int nCol, /* Number of entries in azCol[] */
125565 int iDefaultCol, /* Default column to query */
125566 const char *z, int n, /* Text of MATCH query */
125567 Fts3Expr **ppExpr /* OUT: Parsed query structure */
 
125568 ){
125569 int nParsed;
125570 int rc;
125571 ParseContext sParse;
125572
125573 memset(&sParse, 0, sizeof(ParseContext));
125574 sParse.pTokenizer = pTokenizer;
125575 sParse.iLangid = iLangid;
125576 sParse.azCol = (const char **)azCol;
125577 sParse.nCol = nCol;
125578 sParse.iDefaultCol = iDefaultCol;
125579 sParse.bFts4 = bFts4;
125580 if( z==0 ){
125581 *ppExpr = 0;
125582 return SQLITE_OK;
125583 }
125584 if( n<0 ){
125585 n = (int)strlen(z);
125586 }
125587 rc = fts3ExprParse(&sParse, z, n, ppExpr, &nParsed);
125588
125589 /* Check for mismatched parenthesis */
125590 if( rc==SQLITE_OK && sParse.nNest ){
125591 rc = SQLITE_ERROR;
125592 sqlite3Fts3ExprFree(*ppExpr);
125593 *ppExpr = 0;
 
 
 
 
 
 
 
 
125594 }
125595
125596 return rc;
125597 }
 
 
 
 
 
 
 
 
 
 
125598
125599 /*
125600 ** Free a parsed fts3 query expression allocated by sqlite3Fts3ExprParse().
 
 
 
 
125601 */
125602 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *p){
125603 if( p ){
125604 assert( p->eType==FTSQUERY_PHRASE || p->pPhrase==0 );
125605 sqlite3Fts3ExprFree(p->pLeft);
125606 sqlite3Fts3ExprFree(p->pRight);
125607 sqlite3Fts3EvalPhraseCleanup(p->pPhrase);
125608 sqlite3_free(p->aMI);
125609 sqlite3_free(p);
 
 
 
 
 
 
 
 
 
 
125610 }
125611 }
125612
125613 /****************************************************************************
125614 *****************************************************************************
@@ -125656,10 +125950,13 @@
125656 **
125657 ** If the second argument is not NULL, then its contents are prepended to
125658 ** the returned expression text and then freed using sqlite3_free().
125659 */
125660 static char *exprToString(Fts3Expr *pExpr, char *zBuf){
 
 
 
125661 switch( pExpr->eType ){
125662 case FTSQUERY_PHRASE: {
125663 Fts3Phrase *pPhrase = pExpr->pPhrase;
125664 int i;
125665 zBuf = sqlite3_mprintf(
@@ -125763,14 +126060,25 @@
125763 }
125764 for(ii=0; ii<nCol; ii++){
125765 azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
125766 }
125767
125768 rc = sqlite3Fts3ExprParse(
125769 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
125770 );
 
 
 
 
 
 
 
 
 
 
125771 if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){
 
125772 sqlite3_result_error(context, "Error parsing expression", -1);
125773 }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
125774 sqlite3_result_error_nomem(context);
125775 }else{
125776 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
@@ -125789,13 +126097,19 @@
125789 /*
125790 ** Register the query expression parser test function fts3_exprtest()
125791 ** with database connection db.
125792 */
125793 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
125794 return sqlite3_create_function(
125795 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
125796 );
 
 
 
 
 
 
125797 }
125798
125799 #endif
125800 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
125801
125802
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -678,11 +678,11 @@
678 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
679 ** [sqlite_version()] and [sqlite_source_id()].
680 */
681 #define SQLITE_VERSION "3.7.17"
682 #define SQLITE_VERSION_NUMBER 3007017
683 #define SQLITE_SOURCE_ID "2013-05-03 15:23:24 b2efe4f225adc5f4c2e3080bf459cc52fff82e18"
684
685 /*
686 ** CAPI3REF: Run-Time Library Version Numbers
687 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
688 **
@@ -2161,11 +2161,13 @@
2161 ** <dd> ^(This option takes a single argument which is a pointer to an
2162 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
2163 ** page cache implementation into that object.)^ </dd>
2164 **
2165 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2166 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2167 ** global [error log].
2168 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
2169 ** function with a call signature of void(*)(void*,int,const char*),
2170 ** and a pointer to void. ^If the function pointer is not NULL, it is
2171 ** invoked by [sqlite3_log()] to process each logging event. ^If the
2172 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
2173 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
@@ -3096,10 +3098,13 @@
3098 ** SQL statement text as the statement first begins executing.
3099 ** ^(Additional sqlite3_trace() callbacks might occur
3100 ** as each triggered subprogram is entered. The callbacks for triggers
3101 ** contain a UTF-8 SQL comment that identifies the trigger.)^
3102 **
3103 ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
3104 ** the length of [bound parameter] expansion in the output of sqlite3_trace().
3105 **
3106 ** ^The callback function registered by sqlite3_profile() is invoked
3107 ** as each SQL statement finishes. ^The profile callback contains
3108 ** the original statement text and an estimate of wall-clock time
3109 ** of how long that statement took to run. ^The profile callback
3110 ** time is in units of nanoseconds, however the current implementation
@@ -3634,11 +3639,12 @@
3639 **
3640 ** <ol>
3641 ** <li>
3642 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3643 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3644 ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
3645 ** retries will occur before sqlite3_step() gives up and returns an error.
3646 ** </li>
3647 **
3648 ** <li>
3649 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3650 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3838,10 +3844,13 @@
3844 ** for "?NNN" parameters is the value of NNN.
3845 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
3846 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
3847 **
3848 ** ^The third argument is the value to bind to the parameter.
3849 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3850 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
3851 ** is ignored and the end result is the same as sqlite3_bind_null().
3852 **
3853 ** ^(In those routines that have a fourth argument, its value is the
3854 ** number of bytes in the parameter. To be clear: the value is the
3855 ** number of <u>bytes</u> in the value, not the number of characters.)^
3856 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -7446,11 +7455,11 @@
7455 SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
7456
7457 /*
7458 ** CAPI3REF: Error Logging Interface
7459 **
7460 ** ^The [sqlite3_log()] interface writes a message into the [error log]
7461 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
7462 ** ^If logging is enabled, the zFormat string and subsequent arguments are
7463 ** used with [sqlite3_snprintf()] to generate the final output string.
7464 **
7465 ** The sqlite3_log() interface is intended for use by extensions such as
@@ -8302,11 +8311,11 @@
8311 #ifndef SQLITE_MAX_MMAP_SIZE
8312 # if defined(__linux__) \
8313 || defined(_WIN32) \
8314 || (defined(__APPLE__) && defined(__MACH__)) \
8315 || defined(__sun)
8316 # define SQLITE_MAX_MMAP_SIZE 0x7fff0000 /* 2147418112 */
8317 # else
8318 # define SQLITE_MAX_MMAP_SIZE 0
8319 # endif
8320 # define SQLITE_MAX_MMAP_SIZE_xc 1 /* exclude from ctime.c */
8321 #endif
@@ -8620,10 +8629,11 @@
8629 #define BTREE_DEFAULT_CACHE_SIZE 3
8630 #define BTREE_LARGEST_ROOT_PAGE 4
8631 #define BTREE_TEXT_ENCODING 5
8632 #define BTREE_USER_VERSION 6
8633 #define BTREE_INCR_VACUUM 7
8634 #define BTREE_APPLICATION_ID 8
8635
8636 /*
8637 ** Values that may be OR'd together to form the second argument of an
8638 ** sqlite3BtreeCursorHints() call.
8639 */
@@ -22993,11 +23003,11 @@
23003 #include <fcntl.h>
23004 #include <unistd.h>
23005 /* #include <time.h> */
23006 #include <sys/time.h>
23007 #include <errno.h>
23008 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
23009 #include <sys/mman.h>
23010 #endif
23011
23012
23013 #if SQLITE_ENABLE_LOCKING_STYLE
@@ -26267,52 +26277,65 @@
26277 /* Unread parts of the buffer must be zero-filled */
26278 memset(&((char*)pBuf)[got], 0, amt-got);
26279 return SQLITE_IOERR_SHORT_READ;
26280 }
26281 }
26282
26283 /*
26284 ** Attempt to seek the file-descriptor passed as the first argument to
26285 ** absolute offset iOff, then attempt to write nBuf bytes of data from
26286 ** pBuf to it. If an error occurs, return -1 and set *piErrno. Otherwise,
26287 ** return the actual number of bytes written (which may be less than
26288 ** nBuf).
26289 */
26290 static int seekAndWriteFd(
26291 int fd, /* File descriptor to write to */
26292 i64 iOff, /* File offset to begin writing at */
26293 const void *pBuf, /* Copy data from this buffer to the file */
26294 int nBuf, /* Size of buffer pBuf in bytes */
26295 int *piErrno /* OUT: Error number if error occurs */
26296 ){
26297 int rc = 0; /* Value returned by system call */
26298
26299 assert( nBuf==(nBuf&0x1ffff) );
26300 nBuf &= 0x1ffff;
26301 TIMER_START;
26302
26303 #if defined(USE_PREAD)
26304 do{ rc = osPwrite(fd, pBuf, nBuf, iOff); }while( rc<0 && errno==EINTR );
26305 #elif defined(USE_PREAD64)
26306 do{ rc = osPwrite64(fd, pBuf, nBuf, iOff);}while( rc<0 && errno==EINTR);
26307 #else
26308 do{
26309 i64 iSeek = lseek(fd, iOff, SEEK_SET);
26310 SimulateIOError( iSeek-- );
26311
26312 if( iSeek!=iOff ){
26313 if( piErrno ) *piErrno = (iSeek==-1 ? errno : 0);
26314 return -1;
26315 }
26316 rc = osWrite(fd, pBuf, nBuf);
26317 }while( rc<0 && errno==EINTR );
26318 #endif
26319
26320 TIMER_END;
26321 OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED));
26322
26323 if( rc<0 && piErrno ) *piErrno = errno;
26324 return rc;
26325 }
26326
26327
26328 /*
26329 ** Seek to the offset in id->offset then read cnt bytes into pBuf.
26330 ** Return the number of bytes actually read. Update the offset.
26331 **
26332 ** To avoid stomping the errno value on a failed write the lastErrno value
26333 ** is set before returning.
26334 */
26335 static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
26336 return seekAndWriteFd(id->h, offset, pBuf, cnt, &id->lastErrno);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26337 }
26338
26339
26340 /*
26341 ** Write data from a buffer into a file. Return SQLITE_OK on success
@@ -27397,28 +27420,36 @@
27420 }
27421
27422 if( sStat.st_size<nByte ){
27423 /* The requested memory region does not exist. If bExtend is set to
27424 ** false, exit early. *pp will be set to NULL and SQLITE_OK returned.
27425 */
27426 if( !bExtend ){
27427 goto shmpage_out;
27428 }
27429
27430 /* Alternatively, if bExtend is true, extend the file. Do this by
27431 ** writing a single byte to the end of each (OS) page being
27432 ** allocated or extended. Technically, we need only write to the
27433 ** last page in order to extend the file. But writing to all new
27434 ** pages forces the OS to allocate them immediately, which reduces
27435 ** the chances of SIGBUS while accessing the mapped region later on.
27436 */
27437 else{
27438 static const int pgsz = 4096;
27439 int iPg;
27440
27441 /* Write to the last byte of each newly allocated or extended page */
27442 assert( (nByte % pgsz)==0 );
27443 for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){
27444 if( seekAndWriteFd(pShmNode->h, iPg*pgsz + pgsz-1, "", 1, 0)!=1 ){
27445 const char *zFile = pShmNode->zFilename;
27446 rc = unixLogError(SQLITE_IOERR_SHMSIZE, "write", zFile);
27447 goto shmpage_out;
27448 }
27449 }
27450 }
27451 }
27452 }
27453
27454 /* Map the requested memory region into this processes address space. */
27455 apNew = (char **)sqlite3_realloc(
@@ -28341,13 +28372,12 @@
28372 #if OS_VXWORKS
28373 if( rc!=SQLITE_OK ){
28374 if( h>=0 ) robust_close(pNew, h, __LINE__);
28375 h = -1;
28376 osUnlink(zFilename);
28377 pNew->ctrlFlags |= UNIXFILE_DELETE;
28378 }
 
28379 #endif
28380 if( rc!=SQLITE_OK ){
28381 if( h>=0 ) robust_close(pNew, h, __LINE__);
28382 }else{
28383 pNew->pMethod = pLockingStyle;
@@ -38108,10 +38138,11 @@
38138 # define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0
38139 # define sqlite3WalCallback(z) 0
38140 # define sqlite3WalExclusiveMode(y,z) 0
38141 # define sqlite3WalHeapMemory(z) 0
38142 # define sqlite3WalFramesize(z) 0
38143 # define sqlite3WalFindFrame(x,y,z) 0
38144 #else
38145
38146 #define WAL_SAVEPOINT_NDATA 4
38147
38148 /* Connection to a write-ahead log (WAL) file.
@@ -41052,14 +41083,17 @@
41083 assert( pPager->tempFile );
41084 memset(pPg->pData, 0, pPager->pageSize);
41085 return SQLITE_OK;
41086 }
41087
41088 #ifndef SQLITE_OMIT_WAL
41089 if( iFrame ){
41090 /* Try to pull the page from the write-ahead log. */
41091 rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
41092 }else
41093 #endif
41094 {
41095 i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
41096 rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
41097 if( rc==SQLITE_IOERR_SHORT_READ ){
41098 rc = SQLITE_OK;
41099 }
@@ -44108,10 +44142,15 @@
44142 if( rc==SQLITE_OK ){
44143 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
44144 pPager->aStat[PAGER_STAT_WRITE]++;
44145 }
44146 if( rc==SQLITE_OK ){
44147 /* Update the pager's copy of the change-counter. Otherwise, the
44148 ** next time a read transaction is opened the cache will be
44149 ** flushed (as the change-counter values will not match). */
44150 const void *pCopy = (const void *)&((const char *)zBuf)[24];
44151 memcpy(&pPager->dbFileVers, pCopy, sizeof(pPager->dbFileVers));
44152 pPager->changeCountDone = 1;
44153 }
44154 }else{
44155 pPager->changeCountDone = 1;
44156 }
@@ -94790,10 +94829,15 @@
94829 ** PRAGMA [database.]schema_version
94830 ** PRAGMA [database.]schema_version = <integer>
94831 **
94832 ** PRAGMA [database.]user_version
94833 ** PRAGMA [database.]user_version = <integer>
94834 **
94835 ** PRAGMA [database.]freelist_count = <integer>
94836 **
94837 ** PRAGMA [database.]application_id
94838 ** PRAGMA [database.]application_id = <integer>
94839 **
94840 ** The pragma's schema_version and user_version are used to set or get
94841 ** the value of the schema-version and user-version, respectively. Both
94842 ** the schema-version and the user-version are 32-bit signed integers
94843 ** stored in the database header.
@@ -94812,14 +94856,18 @@
94856 ** applications for any purpose.
94857 */
94858 if( sqlite3StrICmp(zLeft, "schema_version")==0
94859 || sqlite3StrICmp(zLeft, "user_version")==0
94860 || sqlite3StrICmp(zLeft, "freelist_count")==0
94861 || sqlite3StrICmp(zLeft, "application_id")==0
94862 ){
94863 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
94864 sqlite3VdbeUsesBtree(v, iDb);
94865 switch( zLeft[0] ){
94866 case 'a': case 'A':
94867 iCookie = BTREE_APPLICATION_ID;
94868 break;
94869 case 'f': case 'F':
94870 iCookie = BTREE_FREE_PAGE_COUNT;
94871 break;
94872 case 's': case 'S':
94873 iCookie = BTREE_SCHEMA_VERSION;
@@ -102982,10 +103030,11 @@
103030 static const unsigned char aCopy[] = {
103031 BTREE_SCHEMA_VERSION, 1, /* Add one to the old schema cookie */
103032 BTREE_DEFAULT_CACHE_SIZE, 0, /* Preserve the default page cache size */
103033 BTREE_TEXT_ENCODING, 0, /* Preserve the text encoding */
103034 BTREE_USER_VERSION, 0, /* Preserve the user version */
103035 BTREE_APPLICATION_ID, 0, /* Preserve the application id */
103036 };
103037
103038 assert( 1==sqlite3BtreeIsInTrans(pTemp) );
103039 assert( 1==sqlite3BtreeIsInTrans(pMain) );
103040
@@ -104849,11 +104898,11 @@
104898 }
104899 if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ){
104900 continue;
104901 }
104902 }
104903 if( pTerm->prereqRight==0 && (pTerm->eOperator&WO_EQ)!=0 ){
104904 pResult = pTerm;
104905 goto findTerm_success;
104906 }else if( pResult==0 ){
104907 pResult = pTerm;
104908 }
@@ -109027,10 +109076,11 @@
109076 pE = pTerm->pExpr;
109077 assert( !ExprHasProperty(pE, EP_FromJoin) );
109078 assert( (pTerm->prereqRight & newNotReady)!=0 );
109079 pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
109080 if( pAlt==0 ) continue;
109081 if( pAlt->wtFlags & (TERM_CODED) ) continue;
109082 VdbeNoopComment((v, "begin transitive constraint"));
109083 sEq = *pAlt->pExpr;
109084 sEq.pLeft = pE->pLeft;
109085 sqlite3ExprIfFalse(pParse, &sEq, addrCont, SQLITE_JUMPIFNULL);
109086 }
@@ -112374,11 +112424,13 @@
112424 if( yygotominor.yy347 ){
112425 struct SrcList_item *pNew = &yygotominor.yy347->a[yygotominor.yy347->nSrc-1];
112426 struct SrcList_item *pOld = yymsp[-4].minor.yy347->a;
112427 pNew->zName = pOld->zName;
112428 pNew->zDatabase = pOld->zDatabase;
112429 pNew->pSelect = pOld->pSelect;
112430 pOld->zName = pOld->zDatabase = 0;
112431 pOld->pSelect = 0;
112432 }
112433 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy347);
112434 }else{
112435 Select *pSubquery;
112436 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy347);
@@ -119192,11 +119244,11 @@
119244 );
119245 SQLITE_PRIVATE void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *);
119246
119247 /* fts3_expr.c */
119248 SQLITE_PRIVATE int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int,
119249 char **, int, int, int, const char *, int, Fts3Expr **, char **
119250 );
119251 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *);
119252 #ifdef SQLITE_TEST
119253 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
119254 SQLITE_PRIVATE int sqlite3Fts3InitTerm(sqlite3 *db);
@@ -121916,18 +121968,16 @@
121968 }
121969
121970 pCsr->iLangid = 0;
121971 if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]);
121972
121973 assert( p->base.zErrMsg==0 );
121974 rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid,
121975 p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr,
121976 &p->base.zErrMsg
121977 );
121978 if( rc!=SQLITE_OK ){
 
 
 
 
121979 return rc;
121980 }
121981
121982 rc = sqlite3Fts3ReadLock(p);
121983 if( rc!=SQLITE_OK ) return rc;
@@ -125425,12 +125475,14 @@
125475 rc = SQLITE_NOMEM;
125476 goto exprparse_out;
125477 }
125478 pNot->eType = FTSQUERY_NOT;
125479 pNot->pRight = p;
125480 p->pParent = pNot;
125481 if( pNotBranch ){
125482 pNot->pLeft = pNotBranch;
125483 pNotBranch->pParent = pNot;
125484 }
125485 pNotBranch = pNot;
125486 p = pPrev;
125487 }else{
125488 int eType = p->eType;
@@ -125514,10 +125566,11 @@
125566 Fts3Expr *pIter = pNotBranch;
125567 while( pIter->pLeft ){
125568 pIter = pIter->pLeft;
125569 }
125570 pIter->pLeft = pRet;
125571 pRet->pParent = pIter;
125572 pRet = pNotBranch;
125573 }
125574 }
125575 }
125576 *pnConsumed = n - nIn;
@@ -125529,10 +125582,226 @@
125582 pRet = 0;
125583 }
125584 *ppExpr = pRet;
125585 return rc;
125586 }
125587
125588 /*
125589 ** Return SQLITE_ERROR if the maximum depth of the expression tree passed
125590 ** as the only argument is more than nMaxDepth.
125591 */
125592 static int fts3ExprCheckDepth(Fts3Expr *p, int nMaxDepth){
125593 int rc = SQLITE_OK;
125594 if( p ){
125595 if( nMaxDepth<0 ){
125596 rc = SQLITE_TOOBIG;
125597 }else{
125598 rc = fts3ExprCheckDepth(p->pLeft, nMaxDepth-1);
125599 if( rc==SQLITE_OK ){
125600 rc = fts3ExprCheckDepth(p->pRight, nMaxDepth-1);
125601 }
125602 }
125603 }
125604 return rc;
125605 }
125606
125607 /*
125608 ** This function attempts to transform the expression tree at (*pp) to
125609 ** an equivalent but more balanced form. The tree is modified in place.
125610 ** If successful, SQLITE_OK is returned and (*pp) set to point to the
125611 ** new root expression node.
125612 **
125613 ** nMaxDepth is the maximum allowable depth of the balanced sub-tree.
125614 **
125615 ** Otherwise, if an error occurs, an SQLite error code is returned and
125616 ** expression (*pp) freed.
125617 */
125618 static int fts3ExprBalance(Fts3Expr **pp, int nMaxDepth){
125619 int rc = SQLITE_OK; /* Return code */
125620 Fts3Expr *pRoot = *pp; /* Initial root node */
125621 Fts3Expr *pFree = 0; /* List of free nodes. Linked by pParent. */
125622 int eType = pRoot->eType; /* Type of node in this tree */
125623
125624 if( nMaxDepth==0 ){
125625 rc = SQLITE_ERROR;
125626 }
125627
125628 if( rc==SQLITE_OK && (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
125629 Fts3Expr **apLeaf;
125630 apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
125631 if( 0==apLeaf ){
125632 rc = SQLITE_NOMEM;
125633 }else{
125634 memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
125635 }
125636
125637 if( rc==SQLITE_OK ){
125638 int i;
125639 Fts3Expr *p;
125640
125641 /* Set $p to point to the left-most leaf in the tree of eType nodes. */
125642 for(p=pRoot; p->eType==eType; p=p->pLeft){
125643 assert( p->pParent==0 || p->pParent->pLeft==p );
125644 assert( p->pLeft && p->pRight );
125645 }
125646
125647 /* This loop runs once for each leaf in the tree of eType nodes. */
125648 while( 1 ){
125649 int iLvl;
125650 Fts3Expr *pParent = p->pParent; /* Current parent of p */
125651
125652 assert( pParent==0 || pParent->pLeft==p );
125653 p->pParent = 0;
125654 if( pParent ){
125655 pParent->pLeft = 0;
125656 }else{
125657 pRoot = 0;
125658 }
125659 rc = fts3ExprBalance(&p, nMaxDepth-1);
125660 if( rc!=SQLITE_OK ) break;
125661
125662 for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
125663 if( apLeaf[iLvl]==0 ){
125664 apLeaf[iLvl] = p;
125665 p = 0;
125666 }else{
125667 assert( pFree );
125668 pFree->pLeft = apLeaf[iLvl];
125669 pFree->pRight = p;
125670 pFree->pLeft->pParent = pFree;
125671 pFree->pRight->pParent = pFree;
125672
125673 p = pFree;
125674 pFree = pFree->pParent;
125675 p->pParent = 0;
125676 apLeaf[iLvl] = 0;
125677 }
125678 }
125679 if( p ){
125680 sqlite3Fts3ExprFree(p);
125681 rc = SQLITE_TOOBIG;
125682 break;
125683 }
125684
125685 /* If that was the last leaf node, break out of the loop */
125686 if( pParent==0 ) break;
125687
125688 /* Set $p to point to the next leaf in the tree of eType nodes */
125689 for(p=pParent->pRight; p->eType==eType; p=p->pLeft);
125690
125691 /* Remove pParent from the original tree. */
125692 assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
125693 pParent->pRight->pParent = pParent->pParent;
125694 if( pParent->pParent ){
125695 pParent->pParent->pLeft = pParent->pRight;
125696 }else{
125697 assert( pParent==pRoot );
125698 pRoot = pParent->pRight;
125699 }
125700
125701 /* Link pParent into the free node list. It will be used as an
125702 ** internal node of the new tree. */
125703 pParent->pParent = pFree;
125704 pFree = pParent;
125705 }
125706
125707 if( rc==SQLITE_OK ){
125708 p = 0;
125709 for(i=0; i<nMaxDepth; i++){
125710 if( apLeaf[i] ){
125711 if( p==0 ){
125712 p = apLeaf[i];
125713 p->pParent = 0;
125714 }else{
125715 pFree->pRight = p;
125716 pFree->pLeft = apLeaf[i];
125717 pFree->pLeft->pParent = pFree;
125718 pFree->pRight->pParent = pFree;
125719
125720 p = pFree;
125721 pFree = pFree->pParent;
125722 p->pParent = 0;
125723 }
125724 }
125725 }
125726 pRoot = p;
125727 }else{
125728 /* An error occurred. Delete the contents of the apLeaf[] array
125729 ** and pFree list. Everything else is cleaned up by the call to
125730 ** sqlite3Fts3ExprFree(pRoot) below. */
125731 Fts3Expr *pDel;
125732 for(i=0; i<nMaxDepth; i++){
125733 sqlite3Fts3ExprFree(apLeaf[i]);
125734 }
125735 while( (pDel=pFree)!=0 ){
125736 pFree = pDel->pParent;
125737 sqlite3_free(pDel);
125738 }
125739 }
125740
125741 assert( pFree==0 );
125742 sqlite3_free( apLeaf );
125743 }
125744 }
125745
125746 if( rc!=SQLITE_OK ){
125747 sqlite3Fts3ExprFree(pRoot);
125748 pRoot = 0;
125749 }
125750 *pp = pRoot;
125751 return rc;
125752 }
125753
125754 /*
125755 ** This function is similar to sqlite3Fts3ExprParse(), with the following
125756 ** differences:
125757 **
125758 ** 1. It does not do expression rebalancing.
125759 ** 2. It does not check that the expression does not exceed the
125760 ** maximum allowable depth.
125761 ** 3. Even if it fails, *ppExpr may still be set to point to an
125762 ** expression tree. It should be deleted using sqlite3Fts3ExprFree()
125763 ** in this case.
125764 */
125765 static int fts3ExprParseUnbalanced(
125766 sqlite3_tokenizer *pTokenizer, /* Tokenizer module */
125767 int iLangid, /* Language id for tokenizer */
125768 char **azCol, /* Array of column names for fts3 table */
125769 int bFts4, /* True to allow FTS4-only syntax */
125770 int nCol, /* Number of entries in azCol[] */
125771 int iDefaultCol, /* Default column to query */
125772 const char *z, int n, /* Text of MATCH query */
125773 Fts3Expr **ppExpr /* OUT: Parsed query structure */
125774 ){
125775 int nParsed;
125776 int rc;
125777 ParseContext sParse;
125778
125779 memset(&sParse, 0, sizeof(ParseContext));
125780 sParse.pTokenizer = pTokenizer;
125781 sParse.iLangid = iLangid;
125782 sParse.azCol = (const char **)azCol;
125783 sParse.nCol = nCol;
125784 sParse.iDefaultCol = iDefaultCol;
125785 sParse.bFts4 = bFts4;
125786 if( z==0 ){
125787 *ppExpr = 0;
125788 return SQLITE_OK;
125789 }
125790 if( n<0 ){
125791 n = (int)strlen(z);
125792 }
125793 rc = fts3ExprParse(&sParse, z, n, ppExpr, &nParsed);
125794 assert( rc==SQLITE_OK || *ppExpr==0 );
125795
125796 /* Check for mismatched parenthesis */
125797 if( rc==SQLITE_OK && sParse.nNest ){
125798 rc = SQLITE_ERROR;
125799 }
125800
125801 return rc;
125802 }
125803
125804 /*
125805 ** Parameters z and n contain a pointer to and length of a buffer containing
125806 ** an fts3 query expression, respectively. This function attempts to parse the
125807 ** query expression and create a tree of Fts3Expr structures representing the
@@ -125562,53 +125831,78 @@
125831 char **azCol, /* Array of column names for fts3 table */
125832 int bFts4, /* True to allow FTS4-only syntax */
125833 int nCol, /* Number of entries in azCol[] */
125834 int iDefaultCol, /* Default column to query */
125835 const char *z, int n, /* Text of MATCH query */
125836 Fts3Expr **ppExpr, /* OUT: Parsed query structure */
125837 char **pzErr /* OUT: Error message (sqlite3_malloc) */
125838 ){
125839 static const int MAX_EXPR_DEPTH = 12;
125840 int rc = fts3ExprParseUnbalanced(
125841 pTokenizer, iLangid, azCol, bFts4, nCol, iDefaultCol, z, n, ppExpr
125842 );
125843
125844 /* Rebalance the expression. And check that its depth does not exceed
125845 ** MAX_EXPR_DEPTH. */
125846 if( rc==SQLITE_OK && *ppExpr ){
125847 rc = fts3ExprBalance(ppExpr, MAX_EXPR_DEPTH);
125848 if( rc==SQLITE_OK ){
125849 rc = fts3ExprCheckDepth(*ppExpr, MAX_EXPR_DEPTH);
125850 }
125851 }
125852
125853 if( rc!=SQLITE_OK ){
 
 
 
 
 
 
 
 
125854 sqlite3Fts3ExprFree(*ppExpr);
125855 *ppExpr = 0;
125856 if( rc==SQLITE_TOOBIG ){
125857 *pzErr = sqlite3_mprintf(
125858 "FTS expression tree is too large (maximum depth %d)", MAX_EXPR_DEPTH
125859 );
125860 rc = SQLITE_ERROR;
125861 }else if( rc==SQLITE_ERROR ){
125862 *pzErr = sqlite3_mprintf("malformed MATCH expression: [%s]", z);
125863 }
125864 }
125865
125866 return rc;
125867 }
125868
125869 /*
125870 ** Free a single node of an expression tree.
125871 */
125872 static void fts3FreeExprNode(Fts3Expr *p){
125873 assert( p->eType==FTSQUERY_PHRASE || p->pPhrase==0 );
125874 sqlite3Fts3EvalPhraseCleanup(p->pPhrase);
125875 sqlite3_free(p->aMI);
125876 sqlite3_free(p);
125877 }
125878
125879 /*
125880 ** Free a parsed fts3 query expression allocated by sqlite3Fts3ExprParse().
125881 **
125882 ** This function would be simpler if it recursively called itself. But
125883 ** that would mean passing a sufficiently large expression to ExprParse()
125884 ** could cause a stack overflow.
125885 */
125886 SQLITE_PRIVATE void sqlite3Fts3ExprFree(Fts3Expr *pDel){
125887 Fts3Expr *p;
125888 assert( pDel==0 || pDel->pParent==0 );
125889 for(p=pDel; p && (p->pLeft||p->pRight); p=(p->pLeft ? p->pLeft : p->pRight)){
125890 assert( p->pParent==0 || p==p->pParent->pRight || p==p->pParent->pLeft );
125891 }
125892 while( p ){
125893 Fts3Expr *pParent = p->pParent;
125894 fts3FreeExprNode(p);
125895 if( pParent && p==pParent->pLeft && pParent->pRight ){
125896 p = pParent->pRight;
125897 while( p && (p->pLeft || p->pRight) ){
125898 assert( p==p->pParent->pRight || p==p->pParent->pLeft );
125899 p = (p->pLeft ? p->pLeft : p->pRight);
125900 }
125901 }else{
125902 p = pParent;
125903 }
125904 }
125905 }
125906
125907 /****************************************************************************
125908 *****************************************************************************
@@ -125656,10 +125950,13 @@
125950 **
125951 ** If the second argument is not NULL, then its contents are prepended to
125952 ** the returned expression text and then freed using sqlite3_free().
125953 */
125954 static char *exprToString(Fts3Expr *pExpr, char *zBuf){
125955 if( pExpr==0 ){
125956 return sqlite3_mprintf("");
125957 }
125958 switch( pExpr->eType ){
125959 case FTSQUERY_PHRASE: {
125960 Fts3Phrase *pPhrase = pExpr->pPhrase;
125961 int i;
125962 zBuf = sqlite3_mprintf(
@@ -125763,14 +126060,25 @@
126060 }
126061 for(ii=0; ii<nCol; ii++){
126062 azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
126063 }
126064
126065 if( sqlite3_user_data(context) ){
126066 char *zDummy = 0;
126067 rc = sqlite3Fts3ExprParse(
126068 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr, &zDummy
126069 );
126070 assert( rc==SQLITE_OK || pExpr==0 );
126071 sqlite3_free(zDummy);
126072 }else{
126073 rc = fts3ExprParseUnbalanced(
126074 pTokenizer, 0, azCol, 0, nCol, nCol, zExpr, nExpr, &pExpr
126075 );
126076 }
126077
126078 if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){
126079 sqlite3Fts3ExprFree(pExpr);
126080 sqlite3_result_error(context, "Error parsing expression", -1);
126081 }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
126082 sqlite3_result_error_nomem(context);
126083 }else{
126084 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
@@ -125789,13 +126097,19 @@
126097 /*
126098 ** Register the query expression parser test function fts3_exprtest()
126099 ** with database connection db.
126100 */
126101 SQLITE_PRIVATE int sqlite3Fts3ExprInitTestInterface(sqlite3* db){
126102 int rc = sqlite3_create_function(
126103 db, "fts3_exprtest", -1, SQLITE_UTF8, 0, fts3ExprTest, 0, 0
126104 );
126105 if( rc==SQLITE_OK ){
126106 rc = sqlite3_create_function(db, "fts3_exprtest_rebalance",
126107 -1, SQLITE_UTF8, (void *)1, fts3ExprTest, 0, 0
126108 );
126109 }
126110 return rc;
126111 }
126112
126113 #endif
126114 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */
126115
126116
+13 -4
--- 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.17"
111111
#define SQLITE_VERSION_NUMBER 3007017
112
-#define SQLITE_SOURCE_ID "2013-04-25 17:27:08 aabeea98f53edde68f484f1794ae70789dac3889"
112
+#define SQLITE_SOURCE_ID "2013-05-03 15:23:24 b2efe4f225adc5f4c2e3080bf459cc52fff82e18"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -1590,11 +1590,13 @@
15901590
** <dd> ^(This option takes a single argument which is a pointer to an
15911591
** [sqlite3_pcache_methods2] object. SQLite copies of the current
15921592
** page cache implementation into that object.)^ </dd>
15931593
**
15941594
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1595
-** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1595
+** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1596
+** global [error log].
1597
+** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
15961598
** function with a call signature of void(*)(void*,int,const char*),
15971599
** and a pointer to void. ^If the function pointer is not NULL, it is
15981600
** invoked by [sqlite3_log()] to process each logging event. ^If the
15991601
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
16001602
** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
@@ -2525,10 +2527,13 @@
25252527
** SQL statement text as the statement first begins executing.
25262528
** ^(Additional sqlite3_trace() callbacks might occur
25272529
** as each triggered subprogram is entered. The callbacks for triggers
25282530
** contain a UTF-8 SQL comment that identifies the trigger.)^
25292531
**
2532
+** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
2533
+** the length of [bound parameter] expansion in the output of sqlite3_trace().
2534
+**
25302535
** ^The callback function registered by sqlite3_profile() is invoked
25312536
** as each SQL statement finishes. ^The profile callback contains
25322537
** the original statement text and an estimate of wall-clock time
25332538
** of how long that statement took to run. ^The profile callback
25342539
** time is in units of nanoseconds, however the current implementation
@@ -3063,11 +3068,12 @@
30633068
**
30643069
** <ol>
30653070
** <li>
30663071
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
30673072
** always used to do, [sqlite3_step()] will automatically recompile the SQL
3068
-** statement and try to run it again.
3073
+** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
3074
+** retries will occur before sqlite3_step() gives up and returns an error.
30693075
** </li>
30703076
**
30713077
** <li>
30723078
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
30733079
** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3267,10 +3273,13 @@
32673273
** for "?NNN" parameters is the value of NNN.
32683274
** ^The NNN value must be between 1 and the [sqlite3_limit()]
32693275
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
32703276
**
32713277
** ^The third argument is the value to bind to the parameter.
3278
+** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3279
+** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
3280
+** is ignored and the end result is the same as sqlite3_bind_null().
32723281
**
32733282
** ^(In those routines that have a fourth argument, its value is the
32743283
** number of bytes in the parameter. To be clear: the value is the
32753284
** number of <u>bytes</u> in the value, not the number of characters.)^
32763285
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -6875,11 +6884,11 @@
68756884
SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
68766885
68776886
/*
68786887
** CAPI3REF: Error Logging Interface
68796888
**
6880
-** ^The [sqlite3_log()] interface writes a message into the error log
6889
+** ^The [sqlite3_log()] interface writes a message into the [error log]
68816890
** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
68826891
** ^If logging is enabled, the zFormat string and subsequent arguments are
68836892
** used with [sqlite3_snprintf()] to generate the final output string.
68846893
**
68856894
** The sqlite3_log() interface is intended for use by extensions such as
68866895
--- 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.17"
111 #define SQLITE_VERSION_NUMBER 3007017
112 #define SQLITE_SOURCE_ID "2013-04-25 17:27:08 aabeea98f53edde68f484f1794ae70789dac3889"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1590,11 +1590,13 @@
1590 ** <dd> ^(This option takes a single argument which is a pointer to an
1591 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1592 ** page cache implementation into that object.)^ </dd>
1593 **
1594 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1595 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
 
 
1596 ** function with a call signature of void(*)(void*,int,const char*),
1597 ** and a pointer to void. ^If the function pointer is not NULL, it is
1598 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1599 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1600 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
@@ -2525,10 +2527,13 @@
2525 ** SQL statement text as the statement first begins executing.
2526 ** ^(Additional sqlite3_trace() callbacks might occur
2527 ** as each triggered subprogram is entered. The callbacks for triggers
2528 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2529 **
 
 
 
2530 ** ^The callback function registered by sqlite3_profile() is invoked
2531 ** as each SQL statement finishes. ^The profile callback contains
2532 ** the original statement text and an estimate of wall-clock time
2533 ** of how long that statement took to run. ^The profile callback
2534 ** time is in units of nanoseconds, however the current implementation
@@ -3063,11 +3068,12 @@
3063 **
3064 ** <ol>
3065 ** <li>
3066 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3067 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3068 ** statement and try to run it again.
 
3069 ** </li>
3070 **
3071 ** <li>
3072 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3073 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3267,10 +3273,13 @@
3267 ** for "?NNN" parameters is the value of NNN.
3268 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
3269 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
3270 **
3271 ** ^The third argument is the value to bind to the parameter.
 
 
 
3272 **
3273 ** ^(In those routines that have a fourth argument, its value is the
3274 ** number of bytes in the parameter. To be clear: the value is the
3275 ** number of <u>bytes</u> in the value, not the number of characters.)^
3276 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -6875,11 +6884,11 @@
6875 SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
6876
6877 /*
6878 ** CAPI3REF: Error Logging Interface
6879 **
6880 ** ^The [sqlite3_log()] interface writes a message into the error log
6881 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6882 ** ^If logging is enabled, the zFormat string and subsequent arguments are
6883 ** used with [sqlite3_snprintf()] to generate the final output string.
6884 **
6885 ** The sqlite3_log() interface is intended for use by extensions such as
6886
--- 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.17"
111 #define SQLITE_VERSION_NUMBER 3007017
112 #define SQLITE_SOURCE_ID "2013-05-03 15:23:24 b2efe4f225adc5f4c2e3080bf459cc52fff82e18"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1590,11 +1590,13 @@
1590 ** <dd> ^(This option takes a single argument which is a pointer to an
1591 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1592 ** page cache implementation into that object.)^ </dd>
1593 **
1594 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1595 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1596 ** global [error log].
1597 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1598 ** function with a call signature of void(*)(void*,int,const char*),
1599 ** and a pointer to void. ^If the function pointer is not NULL, it is
1600 ** invoked by [sqlite3_log()] to process each logging event. ^If the
1601 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1602 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
@@ -2525,10 +2527,13 @@
2527 ** SQL statement text as the statement first begins executing.
2528 ** ^(Additional sqlite3_trace() callbacks might occur
2529 ** as each triggered subprogram is entered. The callbacks for triggers
2530 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2531 **
2532 ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
2533 ** the length of [bound parameter] expansion in the output of sqlite3_trace().
2534 **
2535 ** ^The callback function registered by sqlite3_profile() is invoked
2536 ** as each SQL statement finishes. ^The profile callback contains
2537 ** the original statement text and an estimate of wall-clock time
2538 ** of how long that statement took to run. ^The profile callback
2539 ** time is in units of nanoseconds, however the current implementation
@@ -3063,11 +3068,12 @@
3068 **
3069 ** <ol>
3070 ** <li>
3071 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3072 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3073 ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
3074 ** retries will occur before sqlite3_step() gives up and returns an error.
3075 ** </li>
3076 **
3077 ** <li>
3078 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3079 ** [error codes] or [extended error codes]. ^The legacy behavior was that
@@ -3267,10 +3273,13 @@
3273 ** for "?NNN" parameters is the value of NNN.
3274 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
3275 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
3276 **
3277 ** ^The third argument is the value to bind to the parameter.
3278 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3279 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
3280 ** is ignored and the end result is the same as sqlite3_bind_null().
3281 **
3282 ** ^(In those routines that have a fourth argument, its value is the
3283 ** number of bytes in the parameter. To be clear: the value is the
3284 ** number of <u>bytes</u> in the value, not the number of characters.)^
3285 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
@@ -6875,11 +6884,11 @@
6884 SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
6885
6886 /*
6887 ** CAPI3REF: Error Logging Interface
6888 **
6889 ** ^The [sqlite3_log()] interface writes a message into the [error log]
6890 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
6891 ** ^If logging is enabled, the zFormat string and subsequent arguments are
6892 ** used with [sqlite3_snprintf()] to generate the final output string.
6893 **
6894 ** The sqlite3_log() interface is intended for use by extensions such as
6895

Keyboard Shortcuts

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