Compare commits

...

2 Commits

Author SHA1 Message Date
drh 36a687deee Fix SQLITE_DBCONFIG_REQUIRE_TXN so that it allows BEGIN IMMEDAITE and
BEGIN EXCLUSIVE to run outside of a transaction.

FossilOrigin-Name: 29997f797f8b0201f022df5817a8690e2dfc4fd7
2016-10-17 23:44:22 +00:00
drh 600e9ca40a Add the SQLITE_DBCONFIG_REQUIRE_TXN argument for sqlite3_dbconfig() which when
set requires an explicit transaction before updating the database.

FossilOrigin-Name: b7570ac14df0b799569070c7400904040d30d4cc
2016-04-05 17:50:36 +00:00
7 changed files with 36 additions and 21 deletions
+10 -10
View File
@@ -1,5 +1,5 @@
C Incorrect\sversion\sof\sbuild.c\schecked\sin\sat\s[87e5f5a6c60e3]\s(because\sI\nneglected\sto\spress\sthe\s"Save"\sbutton\son\sthe\stext\seditor).\s\sThere\sis\sno\schange\nto\sthe\slogic,\sjust\simproved\spresentation.
D 2016-04-05T15:59:23.006
C Fix\sSQLITE_DBCONFIG_REQUIRE_TXN\sso\sthat\sit\sallows\sBEGIN\sIMMEDAITE\sand\nBEGIN\sEXCLUSIVE\sto\srun\soutside\sof\sa\stransaction.
D 2016-10-17T23:44:22.316
F Makefile.in e812bb732d7af01baa09f1278bd4f4a2e3a09449
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc fe57d7e3e74fa383fd01ced796c0ffd966fc094a
@@ -322,7 +322,7 @@ F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73
F src/btree.c 556203aab543e91f4e20cc273a507ed712c8da26
F src/btree.h a5008b9afe56e8e54ade6c436a910f112defcca9
F src/btreeInt.h c18b7d2a3494695133e4e60ee36061d37f45d9a5
F src/build.c c5cf206191880f88142352629d53fed174fc10bd
F src/build.c 2f9da95e68df7a47b5afe4a6c3d16805f22a8e06
F src/callback.c 2e76147783386374bf01b227f752c81ec872d730
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 60e135af364d777a9ab41c97e5e89cd224da6198
@@ -340,7 +340,7 @@ F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
F src/insert.c 8f4e9fcbd8e95e85f15647ba8b413b18d556ec2b
F src/legacy.c 75d3023be8f0d2b99d60f905090341a03358c58e
F src/loadext.c e70f8f9e97624a232870ea5486e682c813ac3002
F src/main.c 5ac9dccc03faadd6f867f67b9018ff41eeeadb46
F src/main.c 1e93cbb15727492cfa1f3d4a8b66b76fa2b7d998
F src/malloc.c 1443d1ad95d67c21d77af7ae3f44678252f0efec
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 6919bcf12f221868ea066eec27e579fed95ce98b
@@ -377,10 +377,10 @@ F src/resolve.c b8f7174e5f8c33c44ded3a25a973d0bb89228c20
F src/rowset.c 9fe4b3ad7cc00944386bb600233d8f523de07a6e
F src/select.c 7849cee0a01952a9c93cd28989daedfa57731143
F src/shell.c b7922fa264f8c8d72a5ec6dd0b091e15a93c4de5
F src/sqlite.h.in 7f437b068314f053e6417d452c59f08d05092591
F src/sqlite.h.in a3577257d45892fa2799ae9996ba24705f5a8b21
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 98f72cbfe00169c39089115427d06ea05fe4b4a2
F src/sqliteInt.h 594bf31a7a0cc788688ca947e562576e23bd7904
F src/sqliteInt.h f0814546248fcee52268339bbeac964eb8b6c4b9
F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247
F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba
F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
@@ -441,7 +441,7 @@ F src/update.c 3e67ab3c0814635f355fb1f8ab010a2b9e016e7d
F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c
F src/util.c 8873d696c9ccc4206058c402e09e101f1b81561a
F src/vacuum.c feb1eabb20987983d9350cad98299b21fa811f52
F src/vdbe.c 936166d3dc5aa00364877603f545707896c1519e
F src/vdbe.c 4cddfd428cca725d466809f23ea86f0e2d47082d
F src/vdbe.h c16ba943d407baa1c7085eefea73a063fc631863
F src/vdbeInt.h ddb157974436d87652de7dc641f7191496d9a8cd
F src/vdbeapi.c ba85b78fe08dc4a9ce747e62c89a2b4a4547e74c
@@ -1482,7 +1482,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 ed128e8b826cd9620b7146d01d461ed28b9a672d
R 27e5e4c2995b5324778005dedfa90fe5
P b7570ac14df0b799569070c7400904040d30d4cc
R c8593da974c677005278c9eab4064b65
U drh
Z ed5acb084f4d8b134ae4eeee3cdc81ad
Z 7b5f4748a18910c904c188f2b1beb1c1
+1 -1
View File
@@ -1 +1 @@
cf569f9f2fab1828e4bfced111fd9a6ee23ea8c0
29997f797f8b0201f022df5817a8690e2dfc4fd7
+1 -1
View File
@@ -3908,7 +3908,7 @@ void sqlite3BeginTransaction(Parse *pParse, int type){
if( !v ) return;
if( type!=TK_DEFERRED ){
for(i=0; i<db->nDb; i++){
sqlite3VdbeAddOp2(v, OP_Transaction, i, (type==TK_EXCLUSIVE)+1);
sqlite3VdbeAddOp3(v, OP_Transaction, i, (type==TK_EXCLUSIVE)+1, 1);
sqlite3VdbeUsesBtree(v, i);
}
}
+1
View File
@@ -804,6 +804,7 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
{ SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
{ SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
{ SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
{ SQLITE_DBCONFIG_REQUIRE_TXN, SQLITE_RequireTxn },
};
unsigned int i;
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
+1
View File
@@ -1938,6 +1938,7 @@ struct sqlite3_mem_methods {
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
#define SQLITE_DBCONFIG_REQUIRE_TXN 1005 /* int int* */
/*
+1 -1
View File
@@ -1384,7 +1384,7 @@ struct sqlite3 {
#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
#define SQLITE_CellSizeCk 0x10000000 /* Check btree cell sizes on load */
#define SQLITE_Fts3Tokenizer 0x20000000 /* Enable fts3_tokenizer(2) */
#define SQLITE_RequireTxn 0x40000000 /* BEGIN required to write */
/*
** Bits of the sqlite3.dbOptFlags field that are used by the
+21 -8
View File
@@ -3086,7 +3086,8 @@ case OP_AutoCommit: {
** active.
** If P2 is non-zero, then a write-transaction is started, or if a
** read-transaction is already active, it is upgraded to a write-transaction.
** If P2 is zero, then a read-transaction is started.
** If P2 is zero, then a read-transaction is started. The 0x02 bit of P2
** is set for an exclusive transaction.
**
** P1 is the index of the database file on which the transaction is
** started. Index 0 is the main database file and index 1 is the
@@ -3103,7 +3104,7 @@ case OP_AutoCommit: {
** entire transaction. If no error is encountered, the statement transaction
** will automatically commit when the VDBE halts.
**
** If P5!=0 then this opcode also checks the schema cookie against P3
** If P5==1 then this opcode also checks the schema cookie against P3
** and the schema generation counter against P4.
** The cookie changes its value whenever the database schema changes.
** This operation is used to detect when that the cookie has changed
@@ -3113,6 +3114,9 @@ case OP_AutoCommit: {
** generation counter, then an SQLITE_SCHEMA error is raised and execution
** halts. The sqlite3_step() wrapper function might then reprepare the
** statement and rerun it from the beginning.
**
** If P5==0 and P3==1 this is the transaction started by a BEGIN
** IMMEDIATE or BEGIN EXCLUSIVE command.
*/
case OP_Transaction: {
Btree *pBt;
@@ -3123,9 +3127,19 @@ case OP_Transaction: {
assert( p->readOnly==0 || pOp->p2==0 );
assert( pOp->p1>=0 && pOp->p1<db->nDb );
assert( DbMaskTest(p->btreeMask, pOp->p1) );
if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){
rc = SQLITE_READONLY;
goto abort_due_to_error;
if( pOp->p2 ){
if( (db->flags & SQLITE_QueryOnly)!=0 ){
rc = SQLITE_READONLY;
goto abort_due_to_error;
}
if( (db->flags & SQLITE_RequireTxn)!=0
&& db->autoCommit
&& (pOp->p5!=0 || pOp->p3!=1)
){
sqlite3VdbeError(p, "cannot write outside of a transaction");
rc = SQLITE_ERROR;
goto abort_due_to_error;
}
}
pBt = db->aDb[pOp->p1].pBt;
@@ -3176,9 +3190,8 @@ case OP_Transaction: {
iGen = iMeta = 0;
}
assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){
sqlite3DbFree(db, p->zErrMsg);
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
if( pOp->p5==1 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){
sqlite3VdbeError(p, "database schema has changed");
/* If the schema-cookie from the database file matches the cookie
** stored with the in-memory representation of the schema, do
** not reload the schema from the database file.