Experimental sqlite_db_config() setting to disable writing to all btrees
except for one btree with a particular root page. FossilOrigin-Name: 2305411097c4985b61c5faf4361c4da8414101f2
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
C Fix\sharmless\scompiler\swarnings.
|
||||
D 2015-01-27T21:24:33.191
|
||||
C Experimental\ssqlite_db_config()\ssetting\sto\sdisable\swriting\sto\sall\sbtrees\s\nexcept\sfor\sone\sbtree\swith\sa\sparticular\sroot\spage.
|
||||
D 2015-01-29T02:26:40.456
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@@ -181,7 +181,7 @@ F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
|
||||
F src/complete.c 198a0066ba60ab06fc00fba1998d870a4d575463
|
||||
F src/ctime.c 98f89724adc891a1a4c655bee04e33e716e05887
|
||||
F src/date.c e4d50b3283696836ec1036b695ead9a19e37a5ac
|
||||
F src/delete.c bd1a91ddd247ce13004075251e0b7fe2bf9925ef
|
||||
F src/delete.c 250aa3cfd37efd5e660abf0ed061356c1f97acea
|
||||
F src/expr.c abe930897ccafae3819fd2855cbc1b00c262fd12
|
||||
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
||||
F src/fkey.c e0444b61bed271a76840cbe6182df93a9baa3f12
|
||||
@@ -190,12 +190,12 @@ F src/global.c 12561d70a1b25f67b21154622bb1723426724f75
|
||||
F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5
|
||||
F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094
|
||||
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
|
||||
F src/insert.c 5b9243a33726008cc4132897d2be371db12a13be
|
||||
F src/insert.c 57b087ad5c7580bd62b807dcdbd70c54b2bb4228
|
||||
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
|
||||
F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e
|
||||
F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770
|
||||
F src/loadext.c 86bd4e2fccd520b748cba52492ab60c4a770f660
|
||||
F src/main.c 05bf368c934cc73d02906030846eb4d1818c10f7
|
||||
F src/main.c 6a6688cf02372c744f8a67e7b396d53f378e49a2
|
||||
F src/malloc.c 740db54387204c9a2eb67c6d98e68b08e9ef4eab
|
||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||
F src/mem1.c abe6ee469b6c5a35c7f22bfeb9c9bac664a1c987
|
||||
@@ -230,11 +230,11 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
|
||||
F src/resolve.c f6c46d3434439ab2084618d603e6d6dbeb0d6ada
|
||||
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
|
||||
F src/select.c 1f2087523007c42900ffcbdeaef06a23ad9329fc
|
||||
F src/shell.c efd35900484377d2159189968c3445afefee3e41
|
||||
F src/sqlite.h.in 9dfc99d6533d36d6a549c4f3f01cacc8be956ada
|
||||
F src/shell.c ff4dafe42c9d282b06cbcaf0c285c553d7d5daa1
|
||||
F src/sqlite.h.in 7e7ce8ea342d59f109dcf3185374ebe1a6c0e4dd
|
||||
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
|
||||
F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d
|
||||
F src/sqliteInt.h eaf210295b551d4e40e622aec1b2261c0b28f844
|
||||
F src/sqliteInt.h d70bca4e33ee931a545172679a3013e15528c3bd
|
||||
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
|
||||
F src/status.c 81712116e826b0089bb221b018929536b2b5406f
|
||||
F src/table.c e7a09215315a978057fb42c640f890160dbcc45e
|
||||
@@ -1237,7 +1237,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P adc9283dd9bc3a6463f8c4fe23dd58a3712c349d
|
||||
R 57729c2b510493b06603a65c6ea41133
|
||||
U mistachkin
|
||||
Z 7155fc25674fe331bcb8023f01301b6b
|
||||
P e7d2ec048c88237c124fbe598f8f7e950d43d90f
|
||||
R 32287aaaa29e1c7ae3cede33e9d09a0f
|
||||
T *branch * one-writable-btree
|
||||
T *sym-one-writable-btree *
|
||||
T -sym-trunk *
|
||||
U drh
|
||||
Z f4cb1a3bf874e800356effffac85d8d8
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
e7d2ec048c88237c124fbe598f8f7e950d43d90f
|
||||
2305411097c4985b61c5faf4361c4da8414101f2
|
||||
+6
-3
@@ -674,9 +674,11 @@ void sqlite3GenerateRowDelete(
|
||||
** fire the INSTEAD OF triggers). */
|
||||
if( pTab->pSelect==0 ){
|
||||
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, 0);
|
||||
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
|
||||
if( count ){
|
||||
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
|
||||
if( !WRITE_RESTRICT(pParse->db, pTab->tnum) ){
|
||||
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
|
||||
if( count ){
|
||||
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,6 +738,7 @@ void sqlite3GenerateRowIndexDelete(
|
||||
assert( iIdxCur+i!=iDataCur || pPk==pIdx );
|
||||
if( aRegIdx!=0 && aRegIdx[i]==0 ) continue;
|
||||
if( pIdx==pPk ) continue;
|
||||
if( WRITE_RESTRICT(pParse->db, pIdx->tnum) ) continue;
|
||||
VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));
|
||||
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
|
||||
&iPartIdxLabel, pPrior, r1);
|
||||
|
||||
@@ -1366,6 +1366,7 @@ void sqlite3GenerateConstraintChecks(
|
||||
int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
|
||||
|
||||
if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
|
||||
if( WRITE_RESTRICT(db, pIdx->tnum) ) continue;
|
||||
if( bAffinityDone==0 ){
|
||||
sqlite3TableAffinity(v, pTab, regNewData+1);
|
||||
bAffinityDone = 1;
|
||||
@@ -1545,6 +1546,7 @@ void sqlite3CompleteInsertion(
|
||||
){
|
||||
Vdbe *v; /* Prepared statements under construction */
|
||||
Index *pIdx; /* An index being inserted or updated */
|
||||
sqlite3 *db;
|
||||
u8 pik_flags; /* flag values passed to the btree insert */
|
||||
int regData; /* Content registers (after the rowid) */
|
||||
int regRec; /* Register holding assembled record for the table */
|
||||
@@ -1554,8 +1556,10 @@ void sqlite3CompleteInsertion(
|
||||
v = sqlite3GetVdbe(pParse);
|
||||
assert( v!=0 );
|
||||
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
|
||||
db = pParse->db;
|
||||
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
|
||||
if( aRegIdx[i]==0 ) continue;
|
||||
if( WRITE_RESTRICT(db, pIdx->tnum) ) continue;
|
||||
bAffinityDone = 1;
|
||||
if( pIdx->pPartIdxWhere ){
|
||||
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
|
||||
@@ -1571,6 +1575,7 @@ void sqlite3CompleteInsertion(
|
||||
if( pik_flags ) sqlite3VdbeChangeP5(v, pik_flags);
|
||||
}
|
||||
if( !HasRowid(pTab) ) return;
|
||||
if( WRITE_RESTRICT(db, pTab->tnum) ) return;
|
||||
regData = regNewData + 1;
|
||||
regRec = sqlite3GetTempReg(pParse);
|
||||
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
|
||||
|
||||
@@ -725,6 +725,11 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
|
||||
rc = setupLookaside(db, pBuf, sz, cnt);
|
||||
break;
|
||||
}
|
||||
case SQLITE_DBCONFIG_WRITABLE_BTREE: {
|
||||
db->onlyWritableBtree = va_arg(ap,int);
|
||||
rc = SQLITE_OK;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
static const struct {
|
||||
int op; /* The opcode */
|
||||
|
||||
+46
@@ -2568,6 +2568,52 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
}
|
||||
}else
|
||||
|
||||
if( c=='d' && n>1 && strncmp(azArg[0], "dbconfig", n)==0 ){
|
||||
int nHit = 0, x;
|
||||
open_db(p, 0);
|
||||
if( nArg>=2 ){
|
||||
n = (int)strlen(azArg[1]);
|
||||
if( strncmp(azArg[1], "writable_btree",n)==0 ){
|
||||
if( nArg!=3 ){
|
||||
fprintf(stderr, "Usage: .dbconfig writable_btree N\n");
|
||||
rc = 1;
|
||||
}else{
|
||||
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_BTREE,
|
||||
integerValue(azArg[2]));
|
||||
}
|
||||
nHit = 1;
|
||||
}else
|
||||
if( strncmp(azArg[1], "enable_fkey",n)==0 ){
|
||||
if( nArg!=3 ){
|
||||
fprintf(stderr, "Usage: .dbconfig enable_fkey (1|0|-1)\n");
|
||||
rc = 1;
|
||||
}else{
|
||||
sqlite3_db_config(p->db, SQLITE_DBCONFIG_ENABLE_FKEY,
|
||||
integerValue(azArg[2]), &x);
|
||||
printf("result: %d\n", x);
|
||||
}
|
||||
nHit = 1;
|
||||
}else
|
||||
if( strncmp(azArg[1], "enable_trigger",n)==0 ){
|
||||
if( nArg!=3 ){
|
||||
fprintf(stderr, "Usage: .dbconfig enable_trigger (1|0|-1)\n");
|
||||
rc = 1;
|
||||
}else{
|
||||
sqlite3_db_config(p->db, SQLITE_DBCONFIG_ENABLE_TRIGGER,
|
||||
integerValue(azArg[2]), &x);
|
||||
printf("result: %d\n", x);
|
||||
}
|
||||
nHit = 1;
|
||||
}
|
||||
}
|
||||
if( nHit==0 ){
|
||||
fprintf(stderr, "Usage: .dbconfig COMMAND ARGS...\n");
|
||||
fprintf(stderr,
|
||||
"COMMAND is one of: writable_btree enable_fkey enable_trigger\n");
|
||||
rc = 1;
|
||||
}
|
||||
}else
|
||||
|
||||
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
|
||||
open_db(p, 0);
|
||||
/* When playing back a "dump", the content might appear in an order
|
||||
|
||||
@@ -1840,11 +1840,20 @@ struct sqlite3_mem_methods {
|
||||
** following this call. The second parameter may be a NULL pointer, in
|
||||
** which case the trigger setting is not reported back. </dd>
|
||||
**
|
||||
** <dt>SQLITE_DBCONFIG_WRITABLE_BTREE</dt>
|
||||
** <dd> ^This option is used to disable INSERT and DELETE operations
|
||||
** against all attached b-trees, except for b-trees that have a
|
||||
** particular root page.
|
||||
** There must be one additional integer argument which is the root page
|
||||
** that is allowed to be written. If the argument is zero, then
|
||||
** writing is allowed to all b-trees, as is normally the case.
|
||||
**
|
||||
** </dl>
|
||||
*/
|
||||
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
|
||||
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
|
||||
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
|
||||
#define SQLITE_DBCONFIG_WRITABLE_BTREE 1004 /* int */
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -1077,6 +1077,7 @@ struct sqlite3 {
|
||||
u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
|
||||
u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
|
||||
int nextPagesize; /* Pagesize after VACUUM if >0 */
|
||||
int onlyWritableBtree; /* Do not write to any other b-tree */
|
||||
u32 magic; /* Magic number for detect library misuse */
|
||||
int nChange; /* Value returned by sqlite3_changes() */
|
||||
int nTotalChange; /* Value returned by sqlite3_total_changes() */
|
||||
@@ -1166,6 +1167,13 @@ struct sqlite3 {
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** This macro returns true if the only_writable_btree pragma is turned
|
||||
** on and is set to a btree root node other than N.
|
||||
*/
|
||||
#define WRITE_RESTRICT(db,N) ((db)->onlyWritableBtree>0 && \
|
||||
(db)->onlyWritableBtree!=(N))
|
||||
|
||||
/*
|
||||
** A macro to discover the encoding of a database.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user