aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordan <dan@noemail.net>2016-11-11 18:45:55 +0000
committerdan <dan@noemail.net>2016-11-11 18:45:55 +0000
commit04cd7aa373d0218a766aa24987a99d16bcdcbac2 (patch)
treef44e1af007c5bd8eb814cac3bec1bea0476ec781
parent9af90b7231660b5c5670e41ad58c755d95d0fbaa (diff)
parent4a5bad572ae669f2c6da3299303840bf3852d5b3 (diff)
downloadsqlite-04cd7aa373d0218a766aa24987a99d16bcdcbac2.tar.gz
sqlite-04cd7aa373d0218a766aa24987a99d16bcdcbac2.zip
Merge trunk with this branch.
FossilOrigin-Name: dd62d2de6eb12dc1902d6df050c395b1dcac01b4
-rw-r--r--main.mk6
-rw-r--r--manifest34
-rw-r--r--manifest.uuid2
-rw-r--r--src/attach.c1
-rw-r--r--src/pager.c5
-rw-r--r--src/resolve.c17
-rw-r--r--src/shell.c81
-rw-r--r--src/wal.c2
-rw-r--r--test/bestindex4.test121
-rw-r--r--test/fuzz-oss1.test4
-rw-r--r--test/fuzzcheck.c53
-rw-r--r--test/nockpt.test6
-rw-r--r--test/ossfuzz.c80
-rw-r--r--test/rowvalue.test13
-rw-r--r--test/shell3.test2
15 files changed, 348 insertions, 79 deletions
diff --git a/main.mk b/main.mk
index a5a50d205..51f9b5a6d 100644
--- a/main.mk
+++ b/main.mk
@@ -511,10 +511,10 @@ fuzzershell$(EXE): $(TOP)/tool/fuzzershell.c sqlite3.c sqlite3.h
$(FUZZERSHELL_OPT) $(TOP)/tool/fuzzershell.c sqlite3.c \
$(TLIBS) $(THREADLIB)
-fuzzcheck$(EXE): $(TOP)/test/fuzzcheck.c sqlite3.c sqlite3.h
+fuzzcheck$(EXE): $(TOP)/test/fuzzcheck.c sqlite3.c sqlite3.h $(TOP)/test/ossfuzz.c
$(TCCX) -o fuzzcheck$(EXE) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
- -DSQLITE_ENABLE_MEMSYS5 $(FUZZCHECK_OPT) \
- $(TOP)/test/fuzzcheck.c sqlite3.c $(TLIBS) $(THREADLIB)
+ -DSQLITE_ENABLE_MEMSYS5 $(FUZZCHECK_OPT) -DSQLITE_OSS_FUZZ \
+ $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c sqlite3.c $(TLIBS) $(THREADLIB)
mptester$(EXE): sqlite3.c $(TOP)/mptest/mptest.c
$(TCCX) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \
diff --git a/manifest b/manifest
index fb20daadb..e4616e5ad 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Reenable\sthe\sSQLITE_EXPR_REF\soptimization\sfor\s"SELECT\sDISTINCT\s...\sORDER\sBY"\nqueries.
-D 2016-11-11T18:08:59.063
+C Merge\strunk\swith\sthis\sbranch.
+D 2016-11-11T18:45:55.817
F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc e0217f2d35a0448abbe4b066132ae20136e8b408
@@ -311,7 +311,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
-F main.mk 06dc0b1a9c9e2d05c9275937dd5b894bfe7d17d8
+F main.mk 4b5c097e286a7b57023547b674c508f14e51dd9d
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
@@ -325,7 +325,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
F src/alter.c 299117695b1f21ac62dfc5b608588810ba22ed0d
F src/analyze.c 8b62b2cf4da85451534ac0af82cafc418d837f68
-F src/attach.c 8c19066b4b5357b5d66154e856c61df01e71203a
+F src/attach.c f6725410c184a80d8141b294fdf98a854c8a52b5
F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792
F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b
F src/bitvec.c 3ee4c8b2c94ed3a7377256e18199e6ff5cf33f63
@@ -374,7 +374,7 @@ F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
F src/os_unix.c be9ca0f901a2b6c1bc93dc338f4863675180c189
F src/os_win.c cf90abd4e50d9f56d2c20ce8e005aff55d7bd8e9
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
-F src/pager.c 549ed86833b484fa3cd4799e3289c83b3ace8859
+F src/pager.c a31e2c25563065ebfc9308f2ba3a061901fd60a8
F src/pager.h 07d6938df0b74e4abe8f57807a8b0e1084321d8b
F src/parse.y 0338f906b61e311c2b7e11a3f89b0092c780b664
F src/pcache.c 5ff2a08f76a9c1b22f43eb063b7068fb085465ac
@@ -385,10 +385,10 @@ F src/pragma.h 64c78a648751b9f4f297276c4eb7507b14b4628c
F src/prepare.c b1140c3d0cf59bc85ace00ce363153041b424b7a
F src/printf.c a5f0ca08ddede803c241266abb46356ec748ded1
F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
-F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b
+F src/resolve.c bb070cf5f23611c44ab7e4788803684e385fc3fb
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c 04fd717fb99aea2110b752e2b6186b966fa13cb4
-F src/shell.c 63e54cfa1c7ec5b70a4c9a86502bc10280c3d5a3
+F src/shell.c f04e4af75c5517735397d060ed0b4a874104bb41
F src/sqlite.h.in 803f7050f69b2eea573fac219f3c92582c096027
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
@@ -465,7 +465,7 @@ F src/vdbesort.c 91fda3909326860382b0ca8aa251e609c6a9d62c
F src/vdbetrace.c 41963d5376f0349842b5fc4aaaaacd7d9cdc0834
F src/vtab.c e02cacb5c7ae742631edeb9ae9f53d399f093fd8
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
-F src/wal.c 358ab4d296a12bc9dcb6f8974dd155ba8a9b10c4
+F src/wal.c 7e8557314bcf867ffe3fff1d8ef2d207ace8e065
F src/wal.h bf03a23da3100ab25e5c0363450233cfee09cfc2
F src/walker.c 91a6df7435827e41cff6bb7df50ea00934ee78b0
F src/where.c 952f76e7a03727480b274b66ca6641b1657cd591
@@ -535,6 +535,7 @@ F test/bc_common.tcl b5e42d80305be95697e6370e015af571e5333a1c
F test/bestindex1.test 0cf1bd2d7b97d3a3a8c10736125274f64765c4ee
F test/bestindex2.test 4a06b8922ab2fd09434870da8d1cdf525aaf7060
F test/bestindex3.test dd5fa4f483cd0356549203c4522f8c9e21cb1fc0
+F test/bestindex4.test e6ef2ffe5787e6dbacb5f934ee3f32cf106474a1
F test/between.test 34d375fb5ce1ae283ffe82b6b233e9f38e84fc6c
F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59
F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc
@@ -807,13 +808,13 @@ F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
F test/func3.test d202a7606d23f90988a664e88e268aed1087c11c
F test/func4.test 6beacdfcb0e18c358e6c2dcacf1b65d1fa80955f
F test/func5.test cdd224400bc3e48d891827cc913a57051a426fa4
-F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74
+F test/fuzz-oss1.test e58330d01cbbd8215ee636b17a03fe220b37dbfa
F test/fuzz.test 96083052bf5765e4518c1ba686ce2bab785670d1
F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1
F test/fuzz3.test b47377143f0c80f91ed29d722861077ff34415d5
F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b
F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26
-F test/fuzzcheck.c f2e8102f7829f7b946ebdb6f1a16c6f942d9de66
+F test/fuzzcheck.c 984470cee0a35b893ad0377a7de75f0c9a758392
F test/fuzzdata1.db 7ee3227bad0e7ccdeb08a9e6822916777073c664
F test/fuzzdata2.db f03a420d3b822cc82e4f894ca957618fbe9c4973
F test/fuzzdata3.db c6586d3e3cef0fbc18108f9bb649aa77bfc38aba
@@ -963,7 +964,7 @@ F test/multiplex4.test e8ae4c4bd70606a5727743241f13b5701990abe4
F test/mutex1.test ea2cc74d97f077b9e74c84cbd024f14d79a8126f
F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
F test/nan.test dacc57f80859c06a433d30839336fe227d2038b3
-F test/nockpt.test faeeb1daa357d634103fd0a1d54f449e4a5b3ef1
+F test/nockpt.test c65fc1c921d48805dcfca2dca5d1302839a5a1de
F test/nolock.test f196cf8b8fbea4e2ca345140a2b3f3b0da45c76e
F test/notify1.test 669b2b743618efdc18ca4b02f45423d5d2304abf
F test/notify2.test 2ecabaa1305083856b7c39cf32816b612740c161
@@ -984,6 +985,7 @@ F test/orderby7.test 3d1383d52ade5b9eb3a173b3147fdd296f0202da
F test/orderby8.test 23ef1a5d72bd3adcc2f65561c654295d1b8047bd
F test/orderby9.test 87fb9548debcc2cd141c5299002dd94672fa76a3
F test/oserror.test b32dc34f2363ef18532e3a0a7358e3e7e321974f
+F test/ossfuzz.c 2d64a0e38ec35fb29c09f8474b64c43605e00ce4
F test/ovfl.test 199c482696defceacee8c8e0e0ef36da62726b2f
F test/pager1.test 841868017e9dd3cb459b8d78862091a7d9cff21d
F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71
@@ -1027,7 +1029,7 @@ F test/rollbackfault.test 0e646aeab8840c399cfbfa43daab46fd609cf04a
F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc
F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81
F test/rowid.test 5b7509f384f4f6fae1af3c8c104c8ca299fea18d
-F test/rowvalue.test bcd78c91fe2aadade6fd00d2616546650b9ebc9e
+F test/rowvalue.test b5a9c0fa347a763c558da2397499df51da3cdf6b
F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b
F test/rowvalue3.test 01399b7bf150b0d41abce76c18072da777c2500c
F test/rowvalue4.test 4b556d7de161a0dd8cff095c336e913986398bea
@@ -1086,7 +1088,7 @@ F test/shared_err.test 2f2aee20db294b9924e81f6ccbe60f19e21e8506
F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
F test/shell1.test 65b10cd8a90cda9b5af9100a45689a57dcc01a31
F test/shell2.test e242a9912f44f4c23c3d1d802a83e934e84c853b
-F test/shell3.test da513d522ef6f01cee8475dcf8332bff8982b3dd
+F test/shell3.test 9b95ba643eaa228376f06a898fb410ee9b6e57c1
F test/shell4.test 89ad573879a745974ff2df20ff97c5d6ffffbd5d
F test/shell5.test 50a732c1c2158b1cd62cf53975ce1ea7ce6b9dc9
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
@@ -1530,7 +1532,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 0af62fdbd8e2aab14718ff8bcb5934f05463c176
-R dccdf5cb21f8816d64d778a9f6efd1e8
+P 6e2e9d383f5fc4a0cbf05fe83ec7425812c0f556 46e0016207b8e7df2ae6c7491fd0f3c2926eed21
+R 26a0853ee10a2e1398c5cc3ecf04db09
U dan
-Z 74767a1cb4eda88af63e605e54888e92
+Z 0ff63d3cd68908d9e7f9837c3ad40428
diff --git a/manifest.uuid b/manifest.uuid
index ee5ae85ad..ed2e3fd5e 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-6e2e9d383f5fc4a0cbf05fe83ec7425812c0f556 \ No newline at end of file
+dd62d2de6eb12dc1902d6df050c395b1dcac01b4 \ No newline at end of file
diff --git a/src/attach.c b/src/attach.c
index 507b9c123..4fe97bace 100644
--- a/src/attach.c
+++ b/src/attach.c
@@ -325,6 +325,7 @@ static void codeAttach(
sqlite3* db = pParse->db;
int regArgs;
+ if( pParse->nErr ) goto attach_end;
memset(&sName, 0, sizeof(NameContext));
sName.pParse = pParse;
diff --git a/src/pager.c b/src/pager.c
index 71c4acdb9..04ce19547 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -4033,7 +4033,10 @@ int sqlite3PagerClose(Pager *pPager, sqlite3 *db){
/* pPager->errCode = 0; */
pPager->exclusiveMode = 0;
#ifndef SQLITE_OMIT_WAL
- sqlite3WalClose(pPager->pWal,db,pPager->ckptSyncFlags,pPager->pageSize,pTmp);
+ assert( db || pPager->pWal==0 );
+ sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize,
+ (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp)
+ );
pPager->pWal = 0;
#endif
pager_reset(pPager);
diff --git a/src/resolve.c b/src/resolve.c
index f464b657f..dac73e5fa 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -400,6 +400,10 @@ static int lookupName(
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
return WRC_Abort;
}
+ if( sqlite3ExprVectorSize(pOrig)!=1 ){
+ sqlite3ErrorMsg(pParse, "row value misused");
+ return WRC_Abort;
+ }
resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
cnt = 1;
pMatch = 0;
@@ -776,6 +780,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
break;
}
+ case TK_BETWEEN:
case TK_EQ:
case TK_NE:
case TK_LT:
@@ -786,10 +791,17 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
case TK_ISNOT: {
int nLeft, nRight;
if( pParse->db->mallocFailed ) break;
- assert( pExpr->pRight!=0 );
assert( pExpr->pLeft!=0 );
nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
- nRight = sqlite3ExprVectorSize(pExpr->pRight);
+ if( pExpr->op==TK_BETWEEN ){
+ nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
+ if( nRight==nLeft ){
+ nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
+ }
+ }else{
+ assert( pExpr->pRight!=0 );
+ nRight = sqlite3ExprVectorSize(pExpr->pRight);
+ }
if( nLeft!=nRight ){
testcase( pExpr->op==TK_EQ );
testcase( pExpr->op==TK_NE );
@@ -799,6 +811,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
testcase( pExpr->op==TK_GE );
testcase( pExpr->op==TK_IS );
testcase( pExpr->op==TK_ISNOT );
+ testcase( pExpr->op==TK_BETWEEN );
sqlite3ErrorMsg(pParse, "row value misused");
}
break;
diff --git a/src/shell.c b/src/shell.c
index 6a7bee142..aaba1080e 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1216,10 +1216,10 @@ static int shell_callback(
raw_printf(p->out," VALUES(");
}else if( p->cnt==0 && p->showHeader ){
for(i=0; i<nArg; i++){
- if( i>0 ) utf8_printf(p->out, ",");
+ if( i>0 ) raw_printf(p->out, ",");
output_quoted_string(p->out, azCol[i]);
}
- utf8_printf(p->out,"\n");
+ raw_printf(p->out,"\n");
}
p->cnt++;
for(i=0; i<nArg; i++){
@@ -3916,12 +3916,12 @@ static int do_meta_command(char *zLine, ShellState *p){
utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
}else{
utf8_printf(stdout, "%s;\n", zSql);
- utf8_printf(stdout,
+ raw_printf(stdout,
"WARNING: writing to an imposter table will corrupt the index!\n"
);
}
}else{
- utf8_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
+ raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
rc = 1;
}
sqlite3_free(zSql);
@@ -4782,7 +4782,7 @@ static int do_meta_command(char *zLine, ShellState *p){
output_reset(p);
p->out = output_file_open("testcase-out.txt");
if( p->out==0 ){
- utf8_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
+ raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
}
if( nArg>=2 ){
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
@@ -5177,6 +5177,42 @@ static int line_is_complete(char *zSql, int nSql){
}
/*
+** Run a single line of SQL
+*/
+static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
+ int rc;
+ char *zErrMsg = 0;
+
+ open_db(p, 0);
+ if( p->backslashOn ) resolve_backslashes(zSql);
+ BEGIN_TIMER;
+ rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
+ END_TIMER;
+ if( rc || zErrMsg ){
+ char zPrefix[100];
+ if( in!=0 || !stdin_is_interactive ){
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix,
+ "Error: near line %d:", startline);
+ }else{
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
+ }
+ if( zErrMsg!=0 ){
+ utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
+ sqlite3_free(zErrMsg);
+ zErrMsg = 0;
+ }else{
+ utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
+ }
+ return 1;
+ }else if( p->countChanges ){
+ raw_printf(p->out, "changes: %3d total_changes: %d\n",
+ sqlite3_changes(p->db), sqlite3_total_changes(p->db));
+ }
+ return 0;
+}
+
+
+/*
** Read input from *in and process it. If *in==0 then input
** is interactive - the user is typing it it. Otherwise, input
** is coming from a file or device. A prompt is issued and history
@@ -5192,7 +5228,6 @@ static int process_input(ShellState *p, FILE *in){
int nSql = 0; /* Bytes of zSql[] used */
int nAlloc = 0; /* Allocated zSql[] space */
int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
- char *zErrMsg; /* Error message returned */
int rc; /* Error code */
int errCnt = 0; /* Number of errors seen */
int lineno = 0; /* Current line number */
@@ -5252,32 +5287,7 @@ static int process_input(ShellState *p, FILE *in){
}
if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
&& sqlite3_complete(zSql) ){
- p->cnt = 0;
- open_db(p, 0);
- if( p->backslashOn ) resolve_backslashes(zSql);
- BEGIN_TIMER;
- rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
- END_TIMER;
- if( rc || zErrMsg ){
- char zPrefix[100];
- if( in!=0 || !stdin_is_interactive ){
- sqlite3_snprintf(sizeof(zPrefix), zPrefix,
- "Error: near line %d:", startline);
- }else{
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
- }
- if( zErrMsg!=0 ){
- utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
- sqlite3_free(zErrMsg);
- zErrMsg = 0;
- }else{
- utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
- }
- errCnt++;
- }else if( p->countChanges ){
- raw_printf(p->out, "changes: %3d total_changes: %d\n",
- sqlite3_changes(p->db), sqlite3_total_changes(p->db));
- }
+ errCnt += runOneSqlLine(p, zSql, in, startline);
nSql = 0;
if( p->outCount ){
output_reset(p);
@@ -5288,11 +5298,8 @@ static int process_input(ShellState *p, FILE *in){
nSql = 0;
}
}
- if( nSql ){
- if( !_all_whitespace(zSql) ){
- utf8_printf(stderr, "Error: incomplete SQL: %s\n", zSql);
- errCnt++;
- }
+ if( nSql && !_all_whitespace(zSql) ){
+ runOneSqlLine(p, zSql, in, startline);
}
free(zSql);
free(zLine);
diff --git a/src/wal.c b/src/wal.c
index 50b95e416..d71ee81a5 100644
--- a/src/wal.c
+++ b/src/wal.c
@@ -1943,7 +1943,7 @@ int sqlite3WalClose(
**
** The EXCLUSIVE lock is not released before returning.
*/
- if( (db->flags & SQLITE_NoCkptOnClose)==0
+ if( zBuf!=0
&& SQLITE_OK==(rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE))
){
if( pWal->exclusiveMode==WAL_NORMAL_MODE ){
diff --git a/test/bestindex4.test b/test/bestindex4.test
new file mode 100644
index 000000000..836701f6b
--- /dev/null
+++ b/test/bestindex4.test
@@ -0,0 +1,121 @@
+# 2016 November 11
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# Test the virtual table interface. In particular the xBestIndex
+# method.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix bestindex4
+
+ifcapable !vtab {
+ finish_test
+ return
+}
+
+#-------------------------------------------------------------------------
+# Virtual table callback for a virtual table named $tbl.
+#
+# The table created is:
+#
+# "CREATE TABLE t1 (id, host, class)"
+#
+# The virtual table supports == operators on a subset of its columns. The
+# exact subset depends on the value of bitmask paramater $param.
+#
+# 0x01 - == on "id" supported
+# 0x02 - == on "host" supported
+# 0x04 - == on "class" supported
+#
+# $param also supports the following bits:
+#
+# 0x08 - ignore the "usable" flag (malfunction)
+#
+#
+#
+proc vtab_cmd {param method args} {
+ switch -- $method {
+ xConnect {
+ return "CREATE TABLE t1(id TEXT, host TEXT, class TEXT)"
+ }
+
+ xBestIndex {
+ foreach {clist orderby mask} $args {}
+
+ set ret [list]
+
+ set use use
+
+
+ for {set i 0} {$i < [llength $clist]} {incr i} {
+ array unset C
+ array set C [lindex $clist $i]
+ if { ($C(usable) || ($param & 0x08))
+ && $C(op)=="eq" && ($param & 1<<$C(column))
+ } {
+ lappend ret $use $i
+ break
+ }
+ }
+
+ set score 1000000
+ if {$ret!=""} {
+ set score [expr $score / [llength $ret]]
+ }
+ lappend ret cost $score rows $score
+
+ return $ret
+ }
+
+ xFilter {
+ }
+ }
+ return ""
+}
+
+register_tcl_module db
+
+for {set param1 0} {$param1<16} {incr param1} {
+ for {set param2 0} {$param2<16} {incr param2} {
+ reset_db
+ register_tcl_module db
+ do_execsql_test 1.$param1.$param2.1 "
+ CREATE VIRTUAL TABLE t1 USING tcl('vtab_cmd $param1');
+ CREATE VIRTUAL TABLE t2 USING tcl('vtab_cmd $param2');
+ "
+
+ foreach {tn sql} {
+ 2 "select t1.id as ID from t1, t2 where t1.id=t2.host and t2.class='xx'"
+ 3 {
+ select t1.id as ID from t1, t2 where t2.class ='xx' and t2.id = t1.host
+ }
+ 4 {
+ select t1.id as ID from t1, t2 where t1.host = t2.id and t2. class ='xx'
+ }
+ } {
+
+ if {($param1 & 0x08)==0 && ($param2 & 0x08)==0} {
+
+ do_execsql_test 1.$param1.$param2.$tn.a $sql {}
+
+ } else {
+ do_test 1.$param1.$param2.$tn.b {
+ catchsql $sql
+ set {} {}
+ } {}
+ }
+ }
+
+ }
+}
+
+finish_test
+
diff --git a/test/fuzz-oss1.test b/test/fuzz-oss1.test
index 08bc67084..e77b7ed0f 100644
--- a/test/fuzz-oss1.test
+++ b/test/fuzz-oss1.test
@@ -1997,5 +1997,9 @@ NULL AND ("9_u" COLLATE NOCASE = ? COLLATE NOCASE))) FROM (SELECT
}
} {/.* Goto .*/}
+# Crash reported by OSS-FUZZ on 2016-11-10
+do_catchsql_test fuzz-oss1-detach {
+ DETACH x IS #1;
+} {1 {near "#1": syntax error}}
finish_test
diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c
index fec65881c..442bcc6e4 100644
--- a/test/fuzzcheck.c
+++ b/test/fuzzcheck.c
@@ -80,6 +80,11 @@
# include <unistd.h>
#endif
+#ifdef SQLITE_OSS_FUZZ
+# include <stddef.h>
+# include <stdint.h>
+#endif
+
/*
** Files in the virtual file system.
*/
@@ -794,6 +799,7 @@ static void showHelp(void){
" --load-db ARGS... Load template databases from files into SOURCE_DB\n"
" -m TEXT Add a description to the database\n"
" --native-vfs Use the native VFS for initially empty database files\n"
+" --oss-fuzz Enable OSS-FUZZ testing\n"
" --rebuild Rebuild and vacuum the database file\n"
" --result-trace Show the results of each SQL command\n"
" --sqlid N Use only SQL where sqlid=N\n"
@@ -835,6 +841,7 @@ int main(int argc, char **argv){
char *zExpDb = 0; /* Write Databases to files in this directory */
char *zExpSql = 0; /* Write SQL to files in this directory */
void *pHeap = 0; /* Heap for use by SQLite */
+ int ossFuzz = 0; /* enable OSS-FUZZ testing */
iBegin = timeOfDay();
#ifdef __unix__
@@ -895,6 +902,9 @@ int main(int argc, char **argv){
if( strcmp(z,"native-vfs")==0 ){
nativeFlag = 1;
}else
+ if( strcmp(z,"oss-fuzz")==0 ){
+ ossFuzz = 1;
+ }else
if( strcmp(z,"quiet")==0 || strcmp(z,"q")==0 ){
quietFlag = 1;
verboseFlag = 0;
@@ -1123,25 +1133,34 @@ int main(int argc, char **argv){
}
}
createVFile("main.db", pDb->sz, pDb->a);
- openFlags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE;
- if( nativeFlag && pDb->sz==0 ){
- openFlags |= SQLITE_OPEN_MEMORY;
- zVfs = 0;
- }
- rc = sqlite3_open_v2("main.db", &db, openFlags, zVfs);
- if( rc ) fatalError("cannot open inmem database");
- if( cellSzCkFlag ) runSql(db, "PRAGMA cell_size_check=ON", runFlags);
- setAlarm(iTimeout);
+ if( ossFuzz ){
+#ifndef SQLITE_OSS_FUZZ
+ fatalError("--oss-fuzz not supported: recompile with -DSQLITE_OSS_FUZZ");
+#else
+ extern int LLVMFuzzerTestOneInput(const uint8_t*, size_t);
+ LLVMFuzzerTestOneInput((const uint8_t*)pSql->a, (size_t)pSql->sz);
+#endif
+ }else{
+ openFlags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE;
+ if( nativeFlag && pDb->sz==0 ){
+ openFlags |= SQLITE_OPEN_MEMORY;
+ zVfs = 0;
+ }
+ rc = sqlite3_open_v2("main.db", &db, openFlags, zVfs);
+ if( rc ) fatalError("cannot open inmem database");
+ if( cellSzCkFlag ) runSql(db, "PRAGMA cell_size_check=ON", runFlags);
+ setAlarm(iTimeout);
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
- if( sqlFuzz || vdbeLimitFlag ){
- sqlite3_progress_handler(db, 100000, progressHandler, &vdbeLimitFlag);
- }
+ if( sqlFuzz || vdbeLimitFlag ){
+ sqlite3_progress_handler(db, 100000, progressHandler, &vdbeLimitFlag);
+ }
#endif
- do{
- runSql(db, (char*)pSql->a, runFlags);
- }while( timeoutTest );
- setAlarm(0);
- sqlite3_close(db);
+ do{
+ runSql(db, (char*)pSql->a, runFlags);
+ }while( timeoutTest );
+ setAlarm(0);
+ sqlite3_close(db);
+ }
if( sqlite3_memory_used()>0 ) fatalError("memory leak");
reformatVfs();
nTest++;
diff --git a/test/nockpt.test b/test/nockpt.test
index f24fcaa98..cf350c3e1 100644
--- a/test/nockpt.test
+++ b/test/nockpt.test
@@ -51,5 +51,11 @@ do_execsql_test 1.12 {
SELECT * FROM c1
} {1 2 3 4 5 6 7 8 9}
+do_execsql_test 1.13 { PRAGMA main.journal_mode } {wal}
+do_test 1.14 { sqlite3_db_config db NO_CKPT_ON_CLOSE 1 } {1}
+do_execsql_test 1.14 { PRAGMA main.journal_mode = delete } {delete}
+do_test 1.15 { file exists test.db-wal } {0}
+
+
finish_test
diff --git a/test/ossfuzz.c b/test/ossfuzz.c
new file mode 100644
index 000000000..ae07bebc3
--- /dev/null
+++ b/test/ossfuzz.c
@@ -0,0 +1,80 @@
+/*
+** This module interfaces SQLite to the Google OSS-Fuzz, fuzzer as a service.
+** (https://github.com/google/oss-fuzz)
+*/
+#include <stddef.h>
+#include <stdint.h>
+#include "sqlite3.h"
+
+/*
+** Progress handler callback
+*/
+static int progress_handler(void *pReturn) {
+ return *(int*)pReturn;
+}
+
+/*
+** Callback for sqlite3_exec().
+*/
+static int exec_handler(void *pCnt, int argc, char **argv, char **namev){
+ int i;
+ for(i=0; i<argc; i++) sqlite3_free(sqlite3_mprintf("%s", argv[i]));
+ return ((*(int*)pCnt)--)<=0;
+}
+
+/*
+** Main entry point. The fuzzer invokes this function with each
+** fuzzed input.
+*/
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ int progressArg = 0; /* 1 causes progress handler abort */
+ int execCnt = 0; /* Abort row callback when count reaches zero */
+ char *zErrMsg = 0; /* Error message returned by sqlite_exec() */
+ sqlite3 *db; /* The database connection */
+ uint8_t uSelector; /* First byte of input data[] */
+ int rc; /* Return code from various interfaces */
+ char *zSql; /* Zero-terminated copy of data[] */
+
+ if( size<3 ) return 0; /* Early out if unsufficient data */
+
+ /* Extract the selector byte from the beginning of the input. But only
+ ** do this if the second byte is a \n. If the second byte is not \n,
+ ** then use a default selector */
+ if( data[1]=='\n' ){
+ uSelector = data[0]; data += 2; size -= 2;
+ }else{
+ uSelector = 0xfd;
+ }
+
+ /* Open the database connection. Only use an in-memory database. */
+ rc = sqlite3_open_v2("fuzz.db", &db,
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY, 0);
+ if( rc ) return 0;
+
+ /* Bit 0 of the selector enables progress callbacks. Bit 1 is the
+ ** return code from progress callbacks */
+ if( uSelector & 1 ){
+ sqlite3_progress_handler(db, 4, progress_handler, (void*)&progressArg);
+ }
+ uSelector >>= 1;
+ progressArg = uSelector & 1; uSelector >>= 1;
+
+ /* Bit 2 of the selector enables foreign key constraints */
+ sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, uSelector&1, &rc);
+ uSelector >>= 1;
+
+ /* Remaining bits of the selector determine a limit on the number of
+ ** output rows */
+ execCnt = uSelector + 1;
+
+ /* Run the SQL. The sqlite_exec() interface expects a zero-terminated
+ ** string, so make a copy. */
+ zSql = sqlite3_mprintf("%.*s", (int)size, data);
+ sqlite3_exec(db, zSql, exec_handler, (void*)&execCnt, &zErrMsg);
+
+ /* Cleanup and return */
+ sqlite3_free(zErrMsg);
+ sqlite3_free(zSql);
+ sqlite3_close(db);
+ return 0;
+}
diff --git a/test/rowvalue.test b/test/rowvalue.test
index 6ab1154b5..231565a4b 100644
--- a/test/rowvalue.test
+++ b/test/rowvalue.test
@@ -266,4 +266,17 @@ do_execsql_test 12.1 {
SELECT *,'x' FROM t1 LEFT JOIN t2 ON (a,b)=(x,y);
} {1 2 {} {} x}
+
+foreach {tn sql} {
+ 0 "SELECT (1,2) AS x WHERE x=3"
+ 1 "SELECT (1,2) BETWEEN 1 AND 2"
+ 2 "SELECT 1 BETWEEN (1,2) AND 2"
+ 3 "SELECT 2 BETWEEN 1 AND (1,2)"
+ 4 "SELECT (1,2) FROM (SELECT 1) ORDER BY 1"
+ 5 "SELECT (1,2) FROM (SELECT 1) GROUP BY 1"
+} {
+ do_catchsql_test 13.$tn $sql {1 {row value misused}}
+}
+
+
finish_test
diff --git a/test/shell3.test b/test/shell3.test
index 6e38021d0..bb2524c1c 100644
--- a/test/shell3.test
+++ b/test/shell3.test
@@ -96,6 +96,6 @@ do_test shell3-2.6 {
} {0 {}}
do_test shell3-2.7 {
catchcmd "foo.db" "CREATE TABLE"
-} {1 {Error: incomplete SQL: CREATE TABLE}}
+} {1 {Error: near line 1: near "TABLE": syntax error}}
finish_test