]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Increase test coverage of new savepoint code. (CVS 6040)
authordanielk1977 <danielk1977@noemail.net>
Thu, 18 Dec 2008 18:31:38 +0000 (18:31 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Thu, 18 Dec 2008 18:31:38 +0000 (18:31 +0000)
FossilOrigin-Name: d915718d0b346982d686d131a159b67e28fc02a8

manifest
manifest.uuid
src/pager.c
src/vdbe.c
test/savepoint.test
test/savepoint2.test
test/savepoint3.test [new file with mode: 0644]

index 2cf6bf4a78f1c73ef3a6eb86c65e78fd47f33274..2cda36e9ed9e2cf1c8b0268e245928790228e790 100644 (file)
--- 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
index 89e756499c042beee298663c8ea16f8b7f0aa71c..a182d096c3a7663affd88ce9c490140b4a89a6be 100644 (file)
@@ -1 +1 @@
-98a53d91f6c0c2692d3b56687fdaba8eeab0959d
\ No newline at end of file
+d915718d0b346982d686d131a159b67e28fc02a8
\ No newline at end of file
index e73b57eec8aa53d655175ac3ab3ee89756e4f048..b005a230a61aba0b42e7b4b0e7b9bb4fe4798b9f 100644 (file)
@@ -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; ii<pPager->nSavepoint; 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; ii<pPager->nSavepoint; ii++){
index 22cc31fd1fe83af995acfc42f9e40dd7553a3c4e..48f89058d958c548f00e1bd36f840ea565cc6c37 100644 (file)
@@ -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 <ctype.h>
@@ -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;
index 289709dbf869aad402f39e894594a735e30d08c1..20342505651f11d5cc68ad7a04d5c45dce5dc96d 100644 (file)
@@ -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
 
index bd259ab9179a1c87cc8ebde60530fae62fdd22f0..dff8a8e85f5091eb44c3a0e13994bcd7ad86c0d3 100644 (file)
@@ -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 (file)
index 0000000..9ef318f
--- /dev/null
@@ -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
+