CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
savepointfault.test138 linesDownload Raw Back to test
1# 2008 December 152#3# The author disclaims copyright to this source code.  In place of4# a legal notice, here is a blessing:5#6#    May you do good and not evil.7#    May you find forgiveness for yourself and forgive others.8#    May you share freely, never taking more than you give.9#10#***********************************************************************11#12 13set testdir [file dirname $argv0]14source $testdir/tester.tcl15 16source $testdir/malloc_common.tcl17 18set testprefix savepointfault19 20do_malloc_test 1 -sqlprep {21  CREATE TABLE t1(a, b, c);22  INSERT INTO t1 VALUES(1, 2, 3);23} -sqlbody {24  SAVEPOINT one;25    INSERT INTO t1 VALUES(4, 5, 6);26    SAVEPOINT two;27      DELETE FROM t1;28    ROLLBACK TO two;29  RELEASE one;30}31 32do_malloc_test 2 -sqlprep {33  PRAGMA cache_size = 10;34  CREATE TABLE t1(a, b, c);35  INSERT INTO t1 VALUES(randstr(400,400), randstr(400,400), randstr(400,400));36  INSERT INTO t1 SELECT 37    randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;38  INSERT INTO t1 39    SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;40  INSERT INTO t1 41    SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;42  INSERT INTO t1 43    SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;44  INSERT INTO t1 45    SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;46  INSERT INTO t1 47    SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;48  INSERT INTO t1 49    SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;50  INSERT INTO t1 51    SELECT randstr(400,400), randstr(400,400), randstr(400,400) FROM t1;52} -sqlbody {53  PRAGMA cache_size = 10;54  SAVEPOINT one;55    DELETE FROM t1 WHERE rowid < 5;56    SAVEPOINT two;57      DELETE FROM t1 WHERE rowid > 10;58    ROLLBACK TO two;59  ROLLBACK TO one;60  RELEASE one;61}62 63do_ioerr_test 3 -sqlprep {64  CREATE TABLE t1(a, b, c);65  INSERT INTO t1 VALUES(1, randstr(1000,1000), randstr(1000,1000));66  INSERT INTO t1 VALUES(2, randstr(1000,1000), randstr(1000,1000));67} -sqlbody {68  BEGIN;69    UPDATE t1 SET a = 3 WHERE a = 1;70    SAVEPOINT one;71      UPDATE t1 SET a = 4 WHERE a = 2;72  COMMIT;73} -cleanup {74  db eval {75    SAVEPOINT one;76    RELEASE one;77  }78}79 80# The following test does a really big savepoint rollback. One involving81# more than 4000 pages. The idea is to get a specific sqlite3BitvecSet()82# operation in pagerPlaybackSavepoint() to fail.83#do_malloc_test 4 -sqlprep {84#  BEGIN;85#    CREATE TABLE t1(a, b);86#    CREATE INDEX i1 ON t1(a);87#    CREATE INDEX i2 ON t1(b);88#    INSERT INTO t1 VALUES(randstr(500,500), randstr(500,500));        --     189#    INSERT INTO t1 VALUES(randstr(500,500), randstr(500,500));        --     290#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --     491#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --     892#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --    1693#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --    3294#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --    6495#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --   12896#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --   25697#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --   51298#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --  102499#    INSERT INTO t1 SELECT randstr(500,500), randstr(500,500) FROM t1; --  2048100#  COMMIT;101#  BEGIN;102#    SAVEPOINT abc;103#      UPDATE t1 SET a = randstr(500,500);104#} -sqlbody {105#    ROLLBACK TO abc;106#}107 108 109# Cause a specific malloc in savepoint rollback code to fail.110#111do_malloc_test 4 -start 7 -sqlprep {112  PRAGMA auto_vacuum = incremental;113  PRAGMA cache_size = 1000;114 115  CREATE TABLE t1(a, b);116  CREATE TABLE t2(a, b);117  CREATE TABLE t3(a, b);118  INSERT INTO t1 VALUES(1, randstr(500,500));119  INSERT INTO t1 VALUES(2, randstr(500,500));120  INSERT INTO t1 VALUES(3, randstr(500,500));121  DELETE FROM t1;122 123  BEGIN;124    INSERT INTO t1 VALUES(1, randstr(500,500));125    INSERT INTO t1 VALUES(2, randstr(500,500));126    INSERT INTO t1 VALUES(3, randstr(500,500));127    DROP TABLE t3;                  -- Page 5 of the database file is now free.128    DROP TABLE t2;                  -- Page 4 of the database file is now free.129 130    SAVEPOINT abc;131      PRAGMA incremental_vacuum;132} -sqlbody {133  ROLLBACK TO abc;134}135 136 137finish_test138