# 2016 March 3 # # 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. # #*********************************************************************** set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix temptable2 do_execsql_test 1.1 { CREATE TEMP TABLE t1(a, b); CREATE INDEX i1 ON t1(a, b); } do_execsql_test 1.2 { WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<100000 ) INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM X; } {} do_execsql_test 1.3 { PRAGMA temp.integrity_check; } {ok} #------------------------------------------------------------------------- # reset_db do_execsql_test 2.1 { CREATE TEMP TABLE t2(a, b); INSERT INTO t2 VALUES(1, 2); } {} do_execsql_test 2.2 { BEGIN; INSERT INTO t2 VALUES(3, 4); SELECT * FROM t2; } {1 2 3 4} do_execsql_test 2.3 { ROLLBACK; SELECT * FROM t2; } {1 2} #------------------------------------------------------------------------- # reset_db do_execsql_test 3.1.1 { PRAGMA main.cache_size = 10; PRAGMA temp.cache_size = 10; CREATE TEMP TABLE t1(a, b); CREATE INDEX i1 ON t1(a, b); WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<1000 ) INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; SELECT count(*) FROM t1; } {1000} do_execsql_test 3.1.2 { BEGIN; UPDATE t1 SET b=randomblob(100) WHERE (rowid%10)==0; ROLLBACK; } do_execsql_test 3.1.3 { SELECT count(*) FROM t1; } {1000} do_execsql_test 3.1.4 { PRAGMA temp.integrity_check } {ok} do_execsql_test 3.2.1 { BEGIN; UPDATE t1 SET b=randomblob(100) WHERE (rowid%10)==0; SAVEPOINT abc; UPDATE t1 SET b=randomblob(100) WHERE (rowid%10)==1; ROLLBACK TO abc; UPDATE t1 SET b=randomblob(100) WHERE (rowid%10)==2; COMMIT; } do_execsql_test 3.2.2 { PRAGMA temp.integrity_check } {ok} #------------------------------------------------------------------------- # reset_db do_execsql_test 4.1.1 { PRAGMA main.cache_size = 10; PRAGMA temp.cache_size = 10; CREATE TEMP TABLE t1(a, b); CREATE INDEX i1 ON t1(a, b); WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<10 ) INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x; SELECT count(*) FROM t1; PRAGMA temp.page_count; } {10 9} do_execsql_test 4.1.2 { BEGIN; UPDATE t1 SET b=randomblob(100); ROLLBACK; } do_execsql_test 4.1.3 { CREATE TEMP TABLE t2(a, b); CREATE INDEX i2 ON t2(a, b); WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<500 ) INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM x; SELECT count(*) FROM t2; SELECT count(*) FROM t1; PRAGMA temp.page_count; } {500 10 292} do_execsql_test 4.1.4 { PRAGMA temp.integrity_check } {ok} #------------------------------------------------------------------------- # reset_db do_execsql_test 5.1.1 { PRAGMA main.cache_size = 10; PRAGMA temp.cache_size = 10; CREATE TEMP TABLE t2(a, b); CREATE INDEX i2 ON t2(a, b); WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<500 ) INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM x; CREATE TEMP TABLE t1(a, b); CREATE INDEX i1 ON t1(a, b); INSERT INTO t1 VALUES(1, 2); PRAGMA temp.page_count; } {286} do_execsql_test 5.1.2 { BEGIN; UPDATE t1 SET a=2; UPDATE t2 SET a=randomblob(100); SELECT count(*) FROM t1; ROLLBACK; } {1} do_execsql_test 5.1.3 { UPDATE t2 SET a=randomblob(100); SELECT * FROM t1; } {1 2} do_execsql_test 5.1.4 { PRAGMA temp.integrity_check } {ok} #------------------------------------------------------------------------- # Test this: # # 1. Page is DIRTY at the start of a transaction. # 2. Page is written out as part of the transaction. # 3. Page is then read back in. # 4. Transaction is rolled back. Is the page now clean or dirty? # # This actually does work. Step 4 marks the page as clean. But it also # writes to the database file itself. So marking it clean is correct - # the page does match the contents of the db file. # reset_db do_execsql_test 6.1 { PRAGMA main.cache_size = 10; PRAGMA temp.cache_size = 10; CREATE TEMP TABLE t1(x); INSERT INTO t1 VALUES('one'); CREATE TEMP TABLE t2(a, b); CREATE INDEX i2 ON t2(a, b); WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<500 ) INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM x; } do_execsql_test 6.2 { UPDATE t1 SET x='two'; -- step 1 BEGIN; UPDATE t2 SET a=randomblob(100); -- step 2 SELECT * FROM t1; -- step 3 ROLLBACK; -- step 4 SELECT count(*) FROM t2; SELECT * FROM t1; } {two 500 two} #------------------------------------------------------------------------- reset_db sqlite3 db "" do_execsql_test 7.1 { PRAGMA auto_vacuum=INCREMENTAL; CREATE TABLE t1(x); INSERT INTO t1 VALUES(zeroblob(900)); INSERT INTO t1 VALUES(zeroblob(900)); INSERT INTO t1 SELECT x FROM t1; INSERT INTO t1 SELECT x FROM t1; INSERT INTO t1 SELECT x FROM t1; INSERT INTO t1 SELECT x FROM t1; BEGIN; DELETE FROM t1 WHERE rowid%2; PRAGMA incremental_vacuum(4); ROLLBACK; PRAGMA integrity_check; } {ok} finish_test