1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

This is a cherry-pick of version [b5df5ac052].

FossilOrigin-Name: d4b2d5d066891e06f2bf4337902b44b000fa9fd2
This commit is contained in:
drh
2014-11-11 22:55:26 +00:00
parent 7abfe9d0c6
commit 85fabf1444
15 changed files with 81 additions and 66 deletions

View File

@ -1,5 +1,5 @@
C Version\s3.8.7.1
D 2014-10-29T13:59:56.070
C This\sis\sa\scherry-pick\sof\sversion\s[b5df5ac052].
D 2014-11-11T22:55:26.891
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -169,11 +169,11 @@ F src/alter.c ba266a779bc7ce10e52e59e7d3dc79fa342e8fdb
F src/analyze.c 8c322e1ecc08909526dbd5ab4421889d05f2263d
F src/attach.c f4e94df2d1826feda65eb0939f7f6f5f923a0ad9
F src/auth.c d8abcde53426275dab6243b441256fcd8ccbebb2
F src/backup.c a31809c65623cc41849b94d368917f8bb66e6a7e
F src/backup.c 8cdfeb0c8a6d8bdad3faefae418eb3dc767051b6
F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
F src/btmutex.c 49ca66250c7dfa844a4d4cb8272b87420d27d3a5
F src/btree.c 1b1123cba0c65caa0baa51e71b8c089e3167c3ed
F src/btree.h a79aa6a71e7f1055f01052b7f821bd1c2dce95c8
F src/btree.c 944b84f72fd9048acde31400d89439976bf766b0
F src/btree.h 97c4d0ef860f151e096e97eef78b87f7b4a8d899
F src/btreeInt.h 026d0129724e8f265fdc60d44ec240cf5a4e6179
F src/build.c 9dc2bd94347b878c89627000c92b0c8d97ec2919
F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
@ -194,7 +194,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e
F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770
F src/loadext.c de741e66e5ddc1598d904d7289239696e40ed994
F src/main.c bbe872b0ac0007bed0ebe1936fc493b039ad4f51
F src/main.c 1bdabb62205af168498a17460bdb7533b2a4a915
F src/malloc.c 3c3ac67969612493d435e14b6832793209afd2ec
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c faf615aafd8be74a71494dfa027c113ea5c6615f
@ -289,7 +289,7 @@ F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13
F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c
F src/util.c 4006c01772bd8d8ac4306d523bbcee41d3e392d8
F src/vacuum.c 59f03f92bcff57faa6a8ca256eb29ccddfb0614a
F src/vdbe.c 5a1afb571853ddb911d698ac996bc4fd8ddf1eed
F src/vdbe.c 4c77cdf16be330bd5227691919332b42d557e211
F src/vdbe.h 09f5b4e3719fa454f252322b1cdab5cf1f361327
F src/vdbeInt.h e2a060a55ee18a6ab973353a5e2ec7ee569bf787
F src/vdbeapi.c 37a6c6ae284a97bcace365f2f0a225680c0499d9
@ -299,7 +299,7 @@ F src/vdbemem.c 31d8eabb0cd78bfeab4e5124c7363c3e9e54db9f
F src/vdbesort.c 975aeffa99acb0991b2f288d30294756bff41438
F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010
F src/vtab.c cb0c194303fea276b48d7d4b6d970b5a96bde8de
F src/wal.c 10e7de7ce90865a68153f001a61f1d985cd17983
F src/wal.c 73051f1222321712fa4280c495780ba81d302dad
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
F src/where.c 2947912f1f3d6a7766fe087fd532a5d688d745b1
@ -378,9 +378,9 @@ F test/btreefault.test c2bcb542685eea44621275cfedbd8a13f65201e3
F test/busy.test 76b4887f8b9160ba903c1ac22e8ff406ad6ae2f0
F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de
F test/capi2.test 011c16da245fdc0106a2785035de6b242c05e738
F test/capi3.test 71bcf2fbd36a9732f617766dfd752552c8e491b5
F test/capi3.test f0718f4f90d0efdc980119bfbdf1d7f1541ee5ef
F test/capi3b.test efb2b9cfd127efa84433cd7a2d72ce0454ae0dc4
F test/capi3c.test a21869e4d50d5dbb7e566e328fc0bc7c2efa6a32
F test/capi3c.test fdc0d67a2cb8e8fc400d5b7735e330161ea057a2
F test/capi3d.test c84af0c49267f9c3fbf4c1c46aa647646023811e
F test/capi3e.test 3d49c01ef2a1a55f41d73cba2b23b5059ec460fe
F test/cast.test 4c275cbdc8202d6f9c54a3596701719868ac7dc3
@ -785,18 +785,18 @@ F test/reindex.test 44edd3966b474468b823d481eafef0c305022254
F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a
F test/releasetest.tcl a4279c890698584feb2ffc86735857a4e4474180
F test/resolver01.test 33abf37ff8335e6bf98f2b45a0af3e06996ccd9a
F test/rollback.test e9504a009a202c3ed711da2e6879ff60c5a4669c
F test/rollback.test 458fe73eb3ffdfdf9f6ba3e9b7350a6220414dea
F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81
F test/rowid.test 742b5741584a8a44fd83e856cc2896688401d645
F test/rtree.test 0c8d9dd458d6824e59683c19ab2ffa9ef946f798
F test/run-wordcount.sh 891e89c4c2d16e629cd45951d4ed899ad12afc09
F test/savepoint.test 51d3900dc071a7c2ad4248578a5925631b476313
F test/savepoint.test c671fdbd34cd3bfe1518a777526ada595180cf8d
F test/savepoint2.test 9b8543940572a2f01a18298c3135ad0c9f4f67d7
F test/savepoint3.test e328085853b14898d78ceea00dfe7db18bb6a9ec
F test/savepoint4.test c8f8159ade6d2acd9128be61e1230f1c1edc6cc0
F test/savepoint5.test 0735db177e0ebbaedc39812c8d065075d563c4fd
F test/savepoint6.test f41279c5e137139fa5c21485773332c7adb98cd7
F test/savepoint7.test fbf319a7b2dda089ec5be30a424a0e95f121d423
F test/savepoint7.test 1c8f26b1e2a4221b0214e222ce12a97a59918eb2
F test/schema.test 8f7999be894260f151adf15c2c7540f1c6d6a481
F test/schema2.test 906408621ea881fdb496d878b1822572a34e32c5
F test/schema3.test 1bc1008e1f8cb5654b248c55f27249366eb7ed38
@ -943,7 +943,7 @@ F test/tkt-d635236375.test 9d37e988b47d87505bc9445be0ca447002df5d09
F test/tkt-d82e3f3721.test bcc0dfba658d15bab30fd4a9320c9e35d214ce30
F test/tkt-f3e5abed55.test d5a0126118142d13e27f6ce9f4c47096e9321c00
F test/tkt-f67b41381a.test a23bc124c981662db712167bacd0ed8ad11abac9
F test/tkt-f777251dc7a.test af6531446c64bfd268416f07b4df7be7f9c749d2
F test/tkt-f777251dc7a.test 6295d235a03c82160549da4841a83dc8e758932f
F test/tkt-f7b4edec.test d998a08ff2b18b7f62edce8e3044317c45efe6c7
F test/tkt-f973c7ac31.test 28ef85c7f015477916795246d8286aeda39d4ead
F test/tkt-fa7bf5ec.test 9102dfea58aa371d78969da735f9392c57e2e035
@ -1038,7 +1038,7 @@ F test/trace.test 73a5508100f7fccfbc3f8018d5f6963ed478eea0
F test/trace2.test 93b47ca6996c66b47f57224cfb146f34e07df382
F test/trans.test 6e1b4c6a42dba31bd65f8fa5e61a2708e08ddde6
F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76
F test/trans3.test 373ac5183cc56be69f48ae44090e7f672939f732
F test/trans3.test 91a100e5412b488e22a655fe423a14c26403ab94
F test/transitive1.test 03f532954f46cdf5608f7766bff0b0c52bf2a7cd
F test/trigger1.test dc47573ac79ffe0ee3eecaa517d70d8dacbccd03
F test/trigger2.test 5cd7d69a7ba1143ee045e4ae2963ff32ae4c87a6
@ -1204,10 +1204,8 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 83afe23e553e802c0947c80d0ffdd120423e7c52
R 5381895dceb9bc7ad4d425f399561cb7
T +bgcolor * #d0c0ff
T +sym-release *
T +sym-version-3.8.7.1 *
P 3b7b72c4685aa5cf5e675c2c47ebec10d9704221
Q +b5df5ac0529f7b0d1e880a7f4a307e7d77b7fa6c
R 27a95de33658c36b59b93f043d249813
U drh
Z e5ce942eb65e60b92fcaefcb5b84039b
Z ea313ee60fabf91291f912ad6dcdc285

View File

@ -1 +1 @@
3b7b72c4685aa5cf5e675c2c47ebec10d9704221
d4b2d5d066891e06f2bf4337902b44b000fa9fd2

View File

@ -597,7 +597,7 @@ int sqlite3_backup_finish(sqlite3_backup *p){
}
/* If a transaction is still open on the Btree, roll it back. */
sqlite3BtreeRollback(p->pDest, SQLITE_OK);
sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
/* Set the error code of the destination database handle. */
rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;

View File

@ -2171,7 +2171,7 @@ int sqlite3BtreeClose(Btree *p){
** The call to sqlite3BtreeRollback() drops any table-locks held by
** this handle.
*/
sqlite3BtreeRollback(p, SQLITE_OK);
sqlite3BtreeRollback(p, SQLITE_OK, 0);
sqlite3BtreeLeave(p);
/* If there are still other outstanding references to the shared-btree
@ -3464,27 +3464,28 @@ int sqlite3BtreeCommit(Btree *p){
/*
** This routine sets the state to CURSOR_FAULT and the error
** code to errCode for every cursor on BtShared that pBtree
** references.
** code to errCode for every cursor on any BtShared that pBtree
** references. Or if the writeOnly flag is set to 1, then only
** trip write cursors and leave read cursors unchanged.
**
** Every cursor is tripped, including cursors that belong
** to other database connections that happen to be sharing
** the cache with pBtree.
** Every cursor is a candidate to be tripped, including cursors
** that belong to other database connections that happen to be
** sharing the cache with pBtree.
**
** This routine gets called when a rollback occurs.
** All cursors using the same cache must be tripped
** to prevent them from trying to use the btree after
** the rollback. The rollback may have deleted tables
** or moved root pages, so it is not sufficient to
** save the state of the cursor. The cursor must be
** invalidated.
** This routine gets called when a rollback occurs. The writeOnly
** flag is set to 1 if the transaction did not make any schema
** changes, in which case the read cursors can continue operating.
** If schema changes did occur in the transaction, then both read
** and write cursors must both be tripped.
*/
void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode){
void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
BtCursor *p;
assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
if( pBtree==0 ) return;
sqlite3BtreeEnter(pBtree);
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
int i;
if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ) continue;
sqlite3BtreeClearCursor(p);
p->eState = CURSOR_FAULT;
p->skipNext = errCode;
@ -3497,27 +3498,32 @@ void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode){
}
/*
** Rollback the transaction in progress. All cursors will be
** invalided by this operation. Any attempt to use a cursor
** that was open at the beginning of this operation will result
** in an error.
** Rollback the transaction in progress.
**
** If tripCode is not SQLITE_OK then cursors will be invalidated (tripped).
** Only write cursors are tripped if writeOnly is true but all cursors are
** tripped if writeOnly is false. Any attempt to use
** a tripped cursor will result in an error.
**
** This will release the write lock on the database file. If there
** are no active cursors, it also releases the read lock.
*/
int sqlite3BtreeRollback(Btree *p, int tripCode){
int sqlite3BtreeRollback(Btree *p, int tripCode, int writeOnly){
int rc;
BtShared *pBt = p->pBt;
MemPage *pPage1;
assert( writeOnly==1 || writeOnly==0 );
assert( tripCode==SQLITE_ABORT_ROLLBACK || tripCode==SQLITE_OK );
sqlite3BtreeEnter(p);
if( tripCode==SQLITE_OK ){
rc = tripCode = saveAllCursors(pBt, 0, 0);
if( rc ) writeOnly = 0;
}else{
rc = SQLITE_OK;
}
if( tripCode ){
sqlite3BtreeTripAllCursors(p, tripCode);
sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
}
btreeIntegrity(p);

View File

@ -83,7 +83,7 @@ int sqlite3BtreeBeginTrans(Btree*,int);
int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
int sqlite3BtreeCommitPhaseTwo(Btree*, int);
int sqlite3BtreeCommit(Btree*);
int sqlite3BtreeRollback(Btree*,int);
int sqlite3BtreeRollback(Btree*,int,int);
int sqlite3BtreeBeginStmt(Btree*,int);
int sqlite3BtreeCreateTable(Btree*, int*, int flags);
int sqlite3BtreeIsInTrans(Btree*);
@ -116,7 +116,7 @@ int sqlite3BtreeIncrVacuum(Btree *);
int sqlite3BtreeDropTable(Btree*, int, int*);
int sqlite3BtreeClearTable(Btree*, int, int*);
int sqlite3BtreeClearTableOfCursor(BtCursor*);
void sqlite3BtreeTripAllCursors(Btree*, int);
void sqlite3BtreeTripAllCursors(Btree*, int, int);
void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);

View File

@ -1016,13 +1016,15 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
/*
** Rollback all database files. If tripCode is not SQLITE_OK, then
** any open cursors are invalidated ("tripped" - as in "tripping a circuit
** any write cursors are invalidated ("tripped" - as in "tripping a circuit
** breaker") and made to return tripCode if there are any further
** attempts to use that cursor.
** attempts to use that cursor. Read cursors remain open and valid
** but are "saved" in case the table pages are moved around.
*/
void sqlite3RollbackAll(sqlite3 *db, int tripCode){
int i;
int inTrans = 0;
int schemaChange;
assert( sqlite3_mutex_held(db->mutex) );
sqlite3BeginBenignMalloc();
@ -1033,6 +1035,7 @@ void sqlite3RollbackAll(sqlite3 *db, int tripCode){
** the database rollback and schema reset, which can cause false
** corruption reports in some cases. */
sqlite3BtreeEnterAll(db);
schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
for(i=0; i<db->nDb; i++){
Btree *p = db->aDb[i].pBt;
@ -1040,7 +1043,7 @@ void sqlite3RollbackAll(sqlite3 *db, int tripCode){
if( sqlite3BtreeIsInTrans(p) ){
inTrans = 1;
}
sqlite3BtreeRollback(p, tripCode);
sqlite3BtreeRollback(p, tripCode, !schemaChange);
}
}
sqlite3VtabRollback(db);

View File

@ -2822,11 +2822,16 @@ case OP_Savepoint: {
db->isTransactionSavepoint = 0;
rc = p->rc;
}else{
int isSchemaChange;
iSavepoint = db->nSavepoint - iSavepoint - 1;
if( p1==SAVEPOINT_ROLLBACK ){
isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
for(ii=0; ii<db->nDb; ii++){
sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT,
isSchemaChange==0);
}
}else{
isSchemaChange = 0;
}
for(ii=0; ii<db->nDb; ii++){
rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
@ -2834,7 +2839,7 @@ case OP_Savepoint: {
goto abort_due_to_error;
}
}
if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
if( isSchemaChange ){
sqlite3ExpirePreparedStatements(db);
sqlite3ResetAllSchemasOfConnection(db);
db->flags = (db->flags | SQLITE_InternChanges);
@ -3231,7 +3236,7 @@ case OP_OpenWrite: {
|| p->readOnly==0 );
if( p->expired ){
rc = SQLITE_ABORT;
rc = SQLITE_ABORT_ROLLBACK;
break;
}

View File

@ -2506,7 +2506,7 @@ int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
memcpy(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr));
for(iFrame=pWal->hdr.mxFrame+1;
ALWAYS(rc==SQLITE_OK) && iFrame<=iMax;
rc==SQLITE_OK && iFrame<=iMax;
iFrame++
){
/* This call cannot fail. Unless the page for which the page number
@ -2525,7 +2525,6 @@ int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx){
}
if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
}
assert( rc==SQLITE_OK );
return rc;
}

View File

@ -912,7 +912,7 @@ do_test capi3-11.9.3 {
} 1
do_test capi3-11.10 {
sqlite3_step $STMT
} {SQLITE_ERROR}
} {SQLITE_ROW}
ifcapable !autoreset {
# If SQLITE_OMIT_AUTORESET is defined, then the statement must be
# reset() before it can be passed to step() again.
@ -921,11 +921,11 @@ ifcapable !autoreset {
}
do_test capi3-11.11 {
sqlite3_step $STMT
} {SQLITE_ROW}
} {SQLITE_DONE}
do_test capi3-11.12 {
sqlite3_step $STMT
sqlite3_step $STMT
} {SQLITE_DONE}
} {SQLITE_ROW}
do_test capi3-11.13 {
sqlite3_finalize $STMT
} {SQLITE_OK}

View File

@ -863,7 +863,7 @@ do_test capi3c-11.9.3 {
} 1
do_test capi3c-11.10 {
sqlite3_step $STMT
} {SQLITE_ABORT}
} {SQLITE_ROW}
ifcapable !autoreset {
# If SQLITE_OMIT_AUTORESET is defined, then the statement must be
# reset() before it can be passed to step() again.
@ -872,11 +872,11 @@ ifcapable !autoreset {
}
do_test capi3c-11.11 {
sqlite3_step $STMT
} {SQLITE_ROW}
} {SQLITE_DONE}
do_test capi3c-11.12 {
sqlite3_step $STMT
sqlite3_step $STMT
} {SQLITE_DONE}
} {SQLITE_ROW}
do_test capi3c-11.13 {
sqlite3_finalize $STMT
} {SQLITE_OK}

View File

@ -60,11 +60,11 @@ ifcapable conflict {
#
do_test rollback-1.5 {
sqlite3_step $STMT
} {SQLITE_ERROR}
} {SQLITE_ROW}
# Restart the SELECT statement
#
do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_ABORT}
do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_OK}
} else {
do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_OK}
}

View File

@ -315,7 +315,7 @@ ifcapable incrblob {
do_test savepoint-5.3.2.3 {
set rc [catch {seek $fd 0; read $fd} res]
set rc
} {1}
} {0}
do_test savepoint-5.3.3 {
catchsql {RELEASE def}
} {0 {}}

View File

@ -30,6 +30,7 @@ do_test savepoint7-1.1 {
db eval {SELECT * FROM t1} {
db eval {
SAVEPOINT x2;
CREATE TABLE IF NOT EXISTS t3(xyz);
INSERT INTO t2 VALUES($a,$b,$c);
RELEASE x2;
}
@ -46,7 +47,7 @@ do_test savepoint7-1.2 {
RELEASE x2;
}
}
db eval {SELECT * FROM t2}
db eval {SELECT * FROM t2;}
} {1 2 3 4 5 6 7 8 9}
do_test savepoint7-1.3 {
@ -65,7 +66,7 @@ do_test savepoint7-1.3 {
# queries in outer contexts.
#
do_test savepoint7-2.1 {
db eval {DELETE FROM t2; SAVEPOINT x1;}
db eval {DELETE FROM t2; SAVEPOINT x1; CREATE TABLE t4(abc);}
set rc [catch {
db eval {SELECT * FROM t1} {
db eval {
@ -85,6 +86,7 @@ do_test savepoint7-2.2 {
db eval {SELECT * FROM t1} {
db eval {
SAVEPOINT x2;
CREATE TABLE t5(pqr);
INSERT INTO t2 VALUES($a,$b,$c);
ROLLBACK TO x2;
}

View File

@ -38,8 +38,10 @@ proc force_rollback {} {
db function force_rollback force_rollback
do_test tkt-f7772-1.2 {
breakpoint
catchsql {
BEGIN IMMEDIATE;
CREATE TABLE xyzzy(abc);
SELECT x, force_rollback(), EXISTS(SELECT 1 FROM t3 WHERE w=x) FROM t2;
}
} {1 {abort due to ROLLBACK}}
@ -67,7 +69,7 @@ do_test tkt-f7772-2.2 {
catchsql {
SELECT x, force_rollback(), EXISTS(SELECT 1 FROM t3 WHERE w=x) FROM t2
}
} {1 {callback requested query abort}}
} {1 {abort due to ROLLBACK}}
do_test tkt-f7772-2.3 {
sqlite3_get_autocommit db
} {1}

View File

@ -52,7 +52,7 @@ do_test trans3-1.4 {
db eval {SELECT * FROM t1}
} {1 2 3 4}
do_test trans3-1.5 {
db eval BEGIN
db eval {BEGIN; CREATE TABLE xyzzy(abc);}
db eval {INSERT INTO t1 VALUES(5);}
set ::ecode {}
set x [catch {