diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index eb5442ed2f..7d4f5e9870 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -2148,10 +2148,10 @@ static int spellfix1BestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ pIdxInfo->aConstraintUsage[iDistTerm].argvIndex = idx++; pIdxInfo->aConstraintUsage[iDistTerm].omit = 1; } - pIdxInfo->estimatedCost = (double)10000; + pIdxInfo->estimatedCost = 1e5; }else{ pIdxInfo->idxNum = 0; - pIdxInfo->estimatedCost = (double)10000000; + pIdxInfo->estimatedCost = 1e50; } return SQLITE_OK; } diff --git a/manifest b/manifest index d549fe0174..6a85c4db62 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\sundocumented\ssqlite3_foreign_key_check()\sAPI\sand\sreplace\sit\swith\nsqlite3_db_status(db,\sSQLITE_DBSTATUS_DEFERRED_FKS,\s...).\s\sAdd\stest\scases\nfor\sthe\snew\sfunctionality. -D 2013-07-11T13:49:59.348 +C Merge\srecent\strunk\schanges\s(such\sas\sthe\squery_only\sPRAGMA,\sthe\ndefer_foreign_keys\sPRAGMA,\sand\sthe\sSQLITE_DBSTATUS_DEFERRED_FKS\sparameter\nto\ssqlite3_db_status())\sinto\sthe\ssessions\sbranch. +D 2013-07-11T15:31:57.120 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in aff38bc64c582dd147f18739532198372587b0f0 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -114,7 +114,7 @@ F ext/misc/nextchar.c 80ba262d23238efcfcb3d72d71aa4513098e26a6 F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63 F ext/misc/regexp.c c25c65fe775f5d9801fb8573e36ebe73f2c0c2e0 F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a -F ext/misc/spellfix.c 6d7ce6105a4b7729f6c44ccdf1ab7e80d9707c02 +F ext/misc/spellfix.c 5e1d547e9a2aed13897fa91bac924333f62fd2d9 F ext/misc/vtshim.c 5fb6be7fe37659a8cbd1e16982d74cceacbc4543 F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 @@ -198,7 +198,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c c48f7f3f170e502fe0cc20748e03c6e0b5a016c2 -F src/main.c 93407bb51024f962ed9cf1c3e525e63484ebbdb9 +F src/main.c e974ea9db6214a5f7cb4c1765b49d3aba1e3409f F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -223,7 +223,7 @@ F src/parse.y 9acfcc83ddbf0cf82f0ed9582ccf0ad6c366ff37 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c d23d07716de96c7c0c2503ec5051a4384c3fb938 -F src/pragma.c c87581d93a7518cba656b7919e32ded5d331b76a +F src/pragma.c 2790c5175bc3f95d2a0cf39283d144b9b012fec7 F src/prepare.c 2306be166bbeddf454e18bf8b21dba8388d05328 F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 @@ -234,7 +234,7 @@ F src/shell.c c8cd06e6b66250a3ea0149c4edec30de14f57b6f F src/sqlite.h.in 17c84f6a2296a33a16141f4cff4b176278f3d1cc F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 62b11aa829ab51446a52dfea93f14b8e1e5d5862 +F src/sqliteInt.h b25c57bb70c098aa05548ecde1948f4106cba472 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -290,7 +290,7 @@ F src/update.c 19daebf6a0a67af5524913e93498d08388792128 F src/utf.c 8d819e2e5104a430fc2005f018db14347c95a38f F src/util.c f566b5138099a2df8533b190d0dcc74b7dfbe0c9 F src/vacuum.c d9c5759f4c5a438bb43c2086f72c5d2edabc36c8 -F src/vdbe.c 26f19a439806efdd9fb93b1874a4a7029a885142 +F src/vdbe.c 4a9d00a91da42f6540203fc4e694235fd21347c9 F src/vdbe.h 1223e2548e0970cf96f573ff6b99f804a36ad683 F src/vdbeInt.h 11feb11eb49d8b312741011d30d91c9c50b59de0 F src/vdbeapi.c bca51b6ea254af3a1bbfd2a58522f6d6db214334 @@ -729,8 +729,9 @@ F test/permutations.test 742b8005bb3c782797a20beccdbe213ef52531fb F test/pragma.test 5e7de6c32a5d764f09437d2025f07e4917b9e178 F test/pragma2.test 3a55f82b954242c642f8342b17dffc8b47472947 F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552 -F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 +F test/progress.test 552dc1edc37333a8d3098b8c26a2b7f06f5799d7 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc +F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 F test/quota-glob.test 32901e9eed6705d68ca3faee2a06b73b57cb3c26 F test/quota.test b5b3eec55a059e0fe493c66c6e27bd2c07676cfd @@ -1116,7 +1117,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 3a2ab74c85a40e0e7ef2d6aef6ec23837cb788e6 -R 4b05e08ec28ee8fbe45f517a6910194e +P d39e65fe702a2e11477f2d996f77404f45763368 6557c407983b067449deb76bc4c5248de64e07dc +R a7fbb947af42ffbd616de92443f86cbe U drh -Z 8f1a9fcd771ae153ffef09cc214c7392 +Z a9673e579f51d102bcb297135146bef6 diff --git a/manifest.uuid b/manifest.uuid index 89b033640c..8073d518de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d39e65fe702a2e11477f2d996f77404f45763368 \ No newline at end of file +8dfc0b78c38e519b64a796243ff7c0aff688ff36 \ No newline at end of file diff --git a/src/main.c b/src/main.c index b25c43be3d..263921abad 100644 --- a/src/main.c +++ b/src/main.c @@ -1300,7 +1300,7 @@ void sqlite3_progress_handler( sqlite3_mutex_enter(db->mutex); if( nOps>0 ){ db->xProgress = xProgress; - db->nProgressOps = nOps; + db->nProgressOps = (unsigned)nOps; db->pProgressArg = pArg; }else{ db->xProgress = 0; diff --git a/src/pragma.c b/src/pragma.c index fd0ebc727c..9bbbfa8aa1 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -177,6 +177,7 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){ { "fullfsync", SQLITE_FullFSync }, { "checkpoint_fullfsync", SQLITE_CkptFullFSync }, { "reverse_unordered_selects", SQLITE_ReverseOrder }, + { "query_only", SQLITE_QueryOnly }, #ifndef SQLITE_OMIT_AUTOMATIC_INDEX { "automatic_index", SQLITE_AutoIndex }, #endif diff --git a/src/sqliteInt.h b/src/sqliteInt.h index f989c3a30b..86d0804fa0 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -944,7 +944,7 @@ struct sqlite3 { #ifndef SQLITE_OMIT_PROGRESS_CALLBACK int (*xProgress)(void *); /* The progress callback */ void *pProgressArg; /* Argument to the progress callback */ - int nProgressOps; /* Number of opcodes for progress callback */ + unsigned nProgressOps; /* Number of opcodes for progress callback */ #endif #ifndef SQLITE_OMIT_VIRTUALTABLE int nVTrans; /* Allocated size of aVTrans */ @@ -1019,6 +1019,8 @@ struct sqlite3 { #define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */ #define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */ #define SQLITE_DeferFKs 0x00800000 /* Defer all FK constraints */ +#define SQLITE_QueryOnly 0x01000000 /* Disable database changes */ + /* ** Bits of the sqlite3.dbOptFlags field that are used by the diff --git a/src/vdbe.c b/src/vdbe.c index b957212e34..c354d3e274 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -562,12 +562,11 @@ int sqlite3VdbeExec( sqlite3 *db = p->db; /* The database */ u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ u8 encoding = ENC(db); /* The database encoding */ -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK - int checkProgress; /* True if progress callbacks are enabled */ - int nProgressOps = 0; /* Opcodes executed since progress callback. */ -#endif int iCompare = 0; /* Result of last OP_Compare operation */ unsigned nVmStep = 0; /* Number of virtual machine steps */ +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK + unsigned nProgressOps = 0; /* nVmStep at last progress callback. */ +#endif Mem *aMem = p->aMem; /* Copy of p->aMem */ Mem *pIn1 = 0; /* 1st input operand */ Mem *pIn2 = 0; /* 2nd input operand */ @@ -596,9 +595,6 @@ int sqlite3VdbeExec( db->busyHandler.nBusy = 0; CHECK_FOR_INTERRUPT; sqlite3VdbeIOTraceSql(p); -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK - checkProgress = db->xProgress!=0; -#endif #ifdef SQLITE_DEBUG sqlite3BeginBenignMalloc(); if( p->pc==0 && (p->db->flags & SQLITE_VdbeListing)!=0 ){ @@ -646,27 +642,6 @@ int sqlite3VdbeExec( } #endif -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK - /* Call the progress callback if it is configured and the required number - ** of VDBE ops have been executed (either since this invocation of - ** sqlite3VdbeExec() or since last time the progress callback was called). - ** If the progress callback returns non-zero, exit the virtual machine with - ** a return code SQLITE_ABORT. - */ - if( checkProgress ){ - if( db->nProgressOps==nProgressOps ){ - int prc; - prc = db->xProgress(db->pProgressArg); - if( prc!=0 ){ - rc = SQLITE_INTERRUPT; - goto vdbe_error_halt; - } - nProgressOps = 0; - } - nProgressOps++; - } -#endif - /* On any opcode with the "out2-prerelease" tag, free any ** external allocations out of mem[p2] and set mem[p2] to be ** an undefined integer. Opcodes will either fill in the integer @@ -759,8 +734,38 @@ int sqlite3VdbeExec( ** the program. */ case OP_Goto: { /* jump */ - CHECK_FOR_INTERRUPT; pc = pOp->p2 - 1; + + /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, + ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon + ** completion. Check to see if sqlite3_interrupt() has been called + ** or if the progress callback needs to be invoked. + ** + ** This code uses unstructured "goto" statements and does not look clean. + ** But that is not due to sloppy coding habits. The code is written this + ** way for performance, to avoid having to run the interrupt and progress + ** checks on every opcode. This helps sqlite3_step() to run about 1.5% + ** faster according to "valgrind --tool=cachegrind" */ +check_for_interrupt: + CHECK_FOR_INTERRUPT; +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK + /* Call the progress callback if it is configured and the required number + ** of VDBE ops have been executed (either since this invocation of + ** sqlite3VdbeExec() or since last time the progress callback was called). + ** If the progress callback returns non-zero, exit the virtual machine with + ** a return code SQLITE_ABORT. + */ + if( db->xProgress!=0 && (nVmStep - nProgressOps)>=db->nProgressOps ){ + int prc; + prc = db->xProgress(db->pProgressArg); + if( prc!=0 ){ + rc = SQLITE_INTERRUPT; + goto vdbe_error_halt; + } + nProgressOps = nVmStep; + } +#endif + break; } @@ -2953,6 +2958,10 @@ case OP_Transaction: { assert( p->readOnly==0 || pOp->p2==0 ); assert( pOp->p1>=0 && pOp->p1nDb ); assert( (p->btreeMask & (((yDbMask)1)<p1))!=0 ); + if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ + rc = SQLITE_READONLY; + goto abort_due_to_error; + } pBt = db->aDb[pOp->p1].pBt; if( pBt ){ @@ -4557,7 +4566,6 @@ case OP_Next: { /* jump */ VdbeCursor *pC; int res; - CHECK_FOR_INTERRUPT; assert( pOp->p1>=0 && pOp->p1nCursor ); assert( pOp->p5<=ArraySize(p->aCounter) ); pC = p->apCsr[pOp->p1]; @@ -4586,7 +4594,7 @@ case OP_Next: { /* jump */ #endif } pC->rowidIsValid = 0; - break; + goto check_for_interrupt; } /* Opcode: IdxInsert P1 P2 P3 * P5 @@ -5112,7 +5120,7 @@ case OP_RowSetAdd: { /* in1, in2 */ */ case OP_RowSetRead: { /* jump, in1, out3 */ i64 val; - CHECK_FOR_INTERRUPT; + pIn1 = &aMem[pOp->p1]; if( (pIn1->flags & MEM_RowSet)==0 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 @@ -5124,7 +5132,7 @@ case OP_RowSetRead: { /* jump, in1, out3 */ /* A value was pulled from the index */ sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); } - break; + goto check_for_interrupt; } /* Opcode: RowSetTest P1 P2 P3 P4 @@ -6027,7 +6035,7 @@ case OP_VNext: { /* jump */ /* If there is data, jump to P2 */ pc = pOp->p2 - 1; } - break; + goto check_for_interrupt; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ diff --git a/test/progress.test b/test/progress.test index b25a100530..381f4826c8 100644 --- a/test/progress.test +++ b/test/progress.test @@ -166,7 +166,7 @@ do_test progress-1.7 { set ::res [list] db eval {SELECT a, b, c FROM abc} { lappend ::res $a $b $c - db progress 10 "expr 1" + db progress 5 "expr 1" catch {db eval {SELECT a, b, c FROM abc} { }} msg lappend ::res $msg } diff --git a/test/queryonly.test b/test/queryonly.test new file mode 100644 index 0000000000..2774e5d436 --- /dev/null +++ b/test/queryonly.test @@ -0,0 +1,72 @@ +# 2013-07-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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file tests the "query_only" pragma. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test queryonly-1.1 { + CREATE TABLE t1(a); + INSERT INTO t1 VALUES(123),(456); + SELECT a FROM t1 ORDER BY a; +} {123 456} +do_execsql_test queryonly-1.2 { + PRAGMA query_only; +} {0} +do_execsql_test queryonly-1.3 { + PRAGMA query_only=ON; + PRAGMA query_only; +} {1} +do_test queryonly-1.4 { + catchsql {INSERT INTO t1 VALUES(789);} +} {1 {attempt to write a readonly database}} +do_test queryonly-1.5 { + catchsql {DELETE FROM t1;} +} {1 {attempt to write a readonly database}} +do_test queryonly-1.6 { + catchsql {UPDATE t1 SET a=a+1;} +} {1 {attempt to write a readonly database}} +do_test queryonly-1.7 { + catchsql {CREATE TABLE t2(b);} +} {1 {attempt to write a readonly database}} +do_test queryonly-1.8 { + catchsql {CREATE INDEX t1a ON t1(a);} +} {1 {attempt to write a readonly database}} +do_test queryonly-1.9 { + catchsql {DROP TABLE t1;} +} {1 {attempt to write a readonly database}} +do_test queryonly-1.10 { + catchsql {ANALYZE;} +} {1 {attempt to write a readonly database}} +do_execsql_test queryonly-1.11 { + SELECT a FROM t1 ORDER BY a; +} {123 456} + +do_execsql_test queryonly-2.2 { + PRAGMA query_only; +} {1} +do_execsql_test queryonly-2.3 { + PRAGMA query_only=OFF; + PRAGMA query_only; +} {0} +do_execsql_test queryonly-2.4 { + INSERT INTO t1 VALUES(789); + SELECT a FROM t1 ORDER BY a; +} {123 456 789} +do_execsql_test queryonly-2.5 { + UPDATE t1 SET a=a+1; + SELECT a FROM t1 ORDER BY a; +} {124 457 790} + +finish_test