From 34cf35dac41fed3c2fb28bace73e6d11f51c1185 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Thu, 18 Dec 2008 18:31:38 +0000 Subject: [PATCH] Increase test coverage of new savepoint code. (CVS 6040) FossilOrigin-Name: d915718d0b346982d686d131a159b67e28fc02a8 --- manifest | 19 +++++++------ manifest.uuid | 2 +- src/pager.c | 11 +++++++- src/vdbe.c | 13 ++++----- test/savepoint.test | 67 +++++++++++++++++++++++++++++++++++++++++++- test/savepoint2.test | 8 +----- test/savepoint3.test | 63 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 157 insertions(+), 26 deletions(-) create mode 100644 test/savepoint3.test diff --git a/manifest b/manifest index 2cf6bf4a78..2cda36e9ed 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssavepoint2.test,\sa\sfile\scontaining\ssavepoint\stests\ssimilar\sto\stests\sin\strans.test\sand\savtrans.test.\sAnd\sa\sfew\ssavepoint\sbug\sfixes.\s(CVS\s6039) -D 2008-12-18T15:45:07 +C Increase\stest\scoverage\sof\snew\ssavepoint\scode.\s(CVS\s6040) +D 2008-12-18T18:31:39 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in f7e4c81c347b04f7b0f1c1b081a168645d7b8af7 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -141,7 +141,7 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60 F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5 F src/os_unix.c 96b4a6e87335ba943455740f311b4dfb63f26756 F src/os_win.c 496e3ceb499aedc63622a89ef76f7af2dd902709 -F src/pager.c 9c1663c9406743f30cdad532c01c47f71bfac577 +F src/pager.c fa8a93afc5374ccb7345fc46cfd959d31fd2bde3 F src/pager.h 7191294438881eb4d13eedade97891e8dc993905 F src/parse.y 4d0e33a702dc3ea7b69d8ae1914b3fbd32e46057 F src/pcache.c 16dc8da6e6ba6250f8dfd9ee46036db1cbceedc6 @@ -196,7 +196,7 @@ F src/update.c 080889d241e4dcd1c545c8051eb6de86f4939295 F src/utf.c 1da9c832dba0fa8f865b5b902d93f420a1ee4245 F src/util.c ea62608f66f33a7e8322de83024ae37c415c0c7f F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9 -F src/vdbe.c 79d3ec97b28e2a95ad2c43ecf2d757de312cb989 +F src/vdbe.c e9a7825d25496343937852fa70b993ee217f924e F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6 F src/vdbeInt.h e6e80a99ce634983b7cc2498843b4d2e5540900a F src/vdbeapi.c 85c33cfbfa56249cbe627831610afafba754477d @@ -490,8 +490,9 @@ F test/rollback.test 1f70ab4301d8d105d41438a436cad1fc8897f5e5 F test/rowid.test 1c8fc43c60d273e6ea44dfb992db587f3164312c F test/rtree.test b85fd4f0861a40ca366ac195e363be2528dcfadf F test/safety.test b69e2b2dd5d52a3f78e216967086884bbc1a09c6 -F test/savepoint.test fdad3b61f4a00a96cd773ca0c758cf2f53918ae3 -F test/savepoint2.test dcaf442a9eea4e91c27fce339fd74c3eaa66577e +F test/savepoint.test 24b7d67971c0b7a8d22ba1cabbfd846e72f21594 +F test/savepoint2.test 65fed3f179cff053e0a75864b1afc13e100fce1f +F test/savepoint3.test b3c9aa5af3f777ccb8b9e15597c75c93eb5bc369 F test/schema.test a8b000723375fd42c68d310091bdbd744fde647c F test/schema2.test 35e1c9696443d6694c8980c411497c2b5190d32e F test/select1.test d0a4cad954fd41c030ec16ffbd2d08a4c0548742 @@ -680,7 +681,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P b9c722bd96b44e0fabd1564ddd982d2aabb7047c -R e8991f966fc1a93805d33d53f39d5eb2 +P 98a53d91f6c0c2692d3b56687fdaba8eeab0959d +R 62d8e49e78bd385c3c1bd94a9682f5e4 U danielk1977 -Z 23f7ea8ae683063fc7d5590449b66501 +Z 22b6c1944a6bc7d00fc6f077bed85661 diff --git a/manifest.uuid b/manifest.uuid index 89e756499c..a182d096c3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -98a53d91f6c0c2692d3b56687fdaba8eeab0959d \ No newline at end of file +d915718d0b346982d686d131a159b67e28fc02a8 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index e73b57eec8..b005a230a6 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.516 2008/12/18 15:45:07 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.517 2008/12/18 18:31:39 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -922,6 +922,11 @@ static void pager_reset(Pager *pPager){ sqlite3PcacheClear(pPager->pPCache); } +/* +** Free all structures in the Pager.aSavepoint[] array and set both +** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal +** if it is open and the pager is not in exclusive mode. +*/ static void releaseAllSavepoint(Pager *pPager){ int ii; for(ii=0; iinSavepoint; ii++){ @@ -935,6 +940,10 @@ static void releaseAllSavepoint(Pager *pPager){ pPager->nSavepoint = 0; } +/* +** Set the bit number pgno in the PagerSavepoint.pInSavepoint bitvecs of +** all open savepoints. +*/ static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){ int ii; for(ii=0; iinSavepoint; ii++){ diff --git a/src/vdbe.c b/src/vdbe.c index 22cc31fd1f..48f89058d9 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.804 2008/12/17 17:30:26 danielk1977 Exp $ +** $Id: vdbe.c,v 1.805 2008/12/18 18:31:39 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -2395,7 +2395,7 @@ case OP_Savepoint: { assert( checkSavepointCount(db) ); if( p1==SAVEPOINT_BEGIN ){ - if( db->writeVdbeCnt>1 ){ + if( db->writeVdbeCnt>0 ){ /* A new savepoint cannot be created if there are active write ** statements (i.e. open read/write incremental blob handles). */ @@ -2457,14 +2457,11 @@ case OP_Savepoint: { }else{ /* Determine whether or not this is a transaction savepoint. If so, - ** operate on the currently open transaction. If this is a RELEASE - ** command, then the transaction is committed. If it is a ROLLBACK - ** command, then all changes made by the current transaction are - ** reverted, but the transaction is not actually closed. + ** and this is a RELEASE command, then the current transaction + ** is committed. */ int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint; if( isTransaction && p1==SAVEPOINT_RELEASE ){ - db->isTransactionSavepoint = 0; db->autoCommit = 1; if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ p->pc = pc; @@ -2472,6 +2469,8 @@ case OP_Savepoint: { p->rc = rc = SQLITE_BUSY; goto vdbe_return; } + db->isTransactionSavepoint = 0; + rc = p->rc; }else{ int ii; iSavepoint = db->nSavepoint - iSavepoint - 1; diff --git a/test/savepoint.test b/test/savepoint.test index 289709dbf8..2034250565 100644 --- a/test/savepoint.test +++ b/test/savepoint.test @@ -9,7 +9,7 @@ # #*********************************************************************** # -# $Id: savepoint.test,v 1.1 2008/12/17 17:30:26 danielk1977 Exp $ +# $Id: savepoint.test,v 1.2 2008/12/18 18:31:39 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -265,5 +265,70 @@ do_test savepoint-4.8 { execsql COMMIT } {} +#------------------------------------------------------------------------ +# Test some logic errors to do with the savepoint feature. +# + +do_test savepoint-5.1.1 { + execsql { + CREATE TABLE blobs(x); + INSERT INTO blobs VALUES('a twentyeight character blob'); + } + set fd [db incrblob blobs x 1] + puts -nonewline $fd "hello" + catchsql {SAVEPOINT abc} +} {1 {cannot open savepoint - SQL statements in progress}} +do_test savepoint-5.1.2 { + close $fd + catchsql {SAVEPOINT abc} +} {0 {}} + +do_test savepoint-5.2 { + execsql {RELEASE abc} + catchsql {RELEASE abc} +} {1 {no such savepoint: abc}} + +do_test savepoint-5.3.1 { + execsql {SAVEPOINT abc} + catchsql {ROLLBACK TO def} +} {1 {no such savepoint: def}} +do_test savepoint-5.3.2 { + execsql {SAVEPOINT def} + set fd [db incrblob -readonly blobs x 1] + catchsql {ROLLBACK TO def} +} {1 {cannot rollback savepoint - SQL statements in progress}} +do_test savepoint-5.3.3 { + catchsql {RELEASE def} +} {0 {}} +do_test savepoint-5.3.4 { + close $fd + execsql {savepoint def} + set fd [db incrblob blobs x 1] + catchsql {release def} +} {1 {cannot release savepoint - SQL statements in progress}} +do_test savepoint-5.3.5 { + close $fd + execsql {release abc} +} {} + +do_test savepoint-5.4.1 { + execsql { + SAVEPOINT main; + INSERT INTO blobs VALUES('another blob'); + } +} {} +do_test savepoint-5.4.2 { + sqlite3 db2 test.db + execsql { BEGIN ; SELECT * FROM blobs } db2 + catchsql { RELEASE main } +} {1 {database is locked}} +do_test savepoint-5.4.3 { + db2 close + catchsql { RELEASE main } +} {0 {}} +do_test savepoint-5.4.4 { + execsql { SELECT x FROM blobs WHERE rowid = 2 } +} {{another blob}} + finish_test diff --git a/test/savepoint2.test b/test/savepoint2.test index bd259ab917..dff8a8e85f 100644 --- a/test/savepoint2.test +++ b/test/savepoint2.test @@ -9,7 +9,7 @@ # #*********************************************************************** # -# $Id: savepoint2.test,v 1.1 2008/12/18 15:45:07 danielk1977 Exp $ +# $Id: savepoint2.test,v 1.2 2008/12/18 18:31:39 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -22,15 +22,9 @@ proc signature {} { return [db eval {SELECT count(*), md5sum(x) FROM t3}] } - - do_test savepoint2-1 { execsql { PRAGMA cache_size=10; - } - db close - sqlite3 db test.db - execsql { BEGIN; CREATE TABLE t3(x TEXT); INSERT INTO t3 VALUES(randstr(10,400)); diff --git a/test/savepoint3.test b/test/savepoint3.test new file mode 100644 index 0000000000..9ef318f9cc --- /dev/null +++ b/test/savepoint3.test @@ -0,0 +1,63 @@ +# 2008 December 15 +# +# 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. +# +#*********************************************************************** +# +# $Id: savepoint3.test,v 1.1 2008/12/18 18:31:39 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +source $testdir/malloc_common.tcl + +do_malloc_test savepoint3-1 -sqlprep { + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES(1, 2, 3); +} -sqlbody { + SAVEPOINT one; + INSERT INTO t1 VALUES(4, 5, 6); + SAVEPOINT two; + DELETE FROM t1; + ROLLBACK TO two; + RELEASE one; +} + +do_malloc_test savepoint3-1 -sqlprep { + PRAGMA cache_size = 10; + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES(randstr(400,400), randstr(400,400), randstr(400,400)); + INSERT INTO t1 SELECT + randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; + INSERT INTO t1 + SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; + INSERT INTO t1 + SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; + INSERT INTO t1 + SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; + INSERT INTO t1 + SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; + INSERT INTO t1 + SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; + INSERT INTO t1 + SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; + INSERT INTO t1 + SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1; +} -sqlbody { + PRAGMA cache_size = 10; + SAVEPOINT one; + DELETE FROM t1 WHERE rowid < 5; + SAVEPOINT two; + DELETE FROM t1 WHERE rowid > 10; + ROLLBACK TO two; + ROLLBACK TO one; + RELEASE one; +} + +finish_test +