| 1 |
# 2016 March 3 |
| 2 |
# |
| 3 |
# The author disclaims copyright to this source code. In place of |
| 4 |
# 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 |
set testdir [file dirname $argv0] |
| 13 |
source $testdir/tester.tcl |
| 14 |
set testprefix tempdb2 |
| 15 |
|
| 16 |
db close |
| 17 |
sqlite3 db "" |
| 18 |
|
| 19 |
set unlocked unlocked |
| 20 |
if {$::TEMP_STORE>=2} { set unlocked unknown } |
| 21 |
|
| 22 |
proc int2str {i} { string range [string repeat "$i." 450] 0 899 } |
| 23 |
db func int2str int2str |
| 24 |
|
| 25 |
#------------------------------------------------------------------------- |
| 26 |
# |
| 27 |
# 1.1: Write a big transaction to the db. One so large that it forces |
| 28 |
# the file to be created and the cache flushed to disk on COMMIT. |
| 29 |
# |
| 30 |
# 1.2: Write a small transaction - one small enough that it remains in |
| 31 |
# memory on COMMIT. All the pages of table [t1] are now dirty. |
| 32 |
# |
| 33 |
# 1.3: Delete the contents of [t1]. This moves all of its leaves to the |
| 34 |
# free-list and causes the btree layer to call PagerDontWrite() on |
| 35 |
# each of them. |
| 36 |
# |
| 37 |
# Then do a big update on table [t2]. So big that the former leaves |
| 38 |
# of [t1] are forced out of the cache. Then roll back the transaction. |
| 39 |
# If the PagerDontWrite() calls are honoured and the data is not written |
| 40 |
# to disk, the update made in test 1.2 will be lost at this point. Or, if |
| 41 |
# they are ignored (as they should be for temp databases), the update |
| 42 |
# will be safely written out to disk before the cache entries are |
| 43 |
# discarded. |
| 44 |
# |
| 45 |
do_execsql_test 1.1 { |
| 46 |
PRAGMA page_size=1024; |
| 47 |
PRAGMA cache_size=50; |
| 48 |
|
| 49 |
BEGIN; |
| 50 |
CREATE TABLE t1(a INTEGER PRIMARY KEY, b); |
| 51 |
INSERT INTO t1 VALUES(1, int2str(1)); |
| 52 |
INSERT INTO t1 VALUES(2, int2str(1)); |
| 53 |
INSERT INTO t1 VALUES(3, int2str(1)); |
| 54 |
|
| 55 |
CREATE TABLE t2(a INTEGER PRIMARY KEY, b); |
| 56 |
WITH c(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100 ) |
| 57 |
INSERT INTO t2 SELECT x, int2str(x) FROM c; |
| 58 |
COMMIT; |
| 59 |
|
| 60 |
PRAGMA lock_status; |
| 61 |
} [list main $unlocked temp closed] |
| 62 |
|
| 63 |
do_execsql_test 1.2 { |
| 64 |
UPDATE t1 SET b=int2str(2); |
| 65 |
SELECT b=int2str(2) FROM t1 |
| 66 |
} {1 1 1} |
| 67 |
|
| 68 |
do_execsql_test 1.3 { |
| 69 |
BEGIN; |
| 70 |
DELETE FROM t1; |
| 71 |
UPDATE t2 SET b=int2str(a+1); |
| 72 |
ROLLBACK; |
| 73 |
} |
| 74 |
|
| 75 |
do_execsql_test 1.4 { |
| 76 |
SELECT b=int2str(2) FROM t1 |
| 77 |
} {1 1 1} |
| 78 |
|
| 79 |
#------------------------------------------------------------------------- |
| 80 |
db close |
| 81 |
sqlite3 db "" |
| 82 |
db func int2str int2str |
| 83 |
|
| 84 |
do_execsql_test 2.0 { |
| 85 |
PRAGMA cache_size = -100; |
| 86 |
CREATE TABLE t1(a INTEGER PRIMARY KEY, b); |
| 87 |
WITH c(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100 ) |
| 88 |
INSERT INTO t1 SELECT x, int2str(x) FROM c; |
| 89 |
} |
| 90 |
|
| 91 |
do_execsql_test 2.1 { |
| 92 |
INSERT INTO t1 VALUES(10001, int2str(1001) || int2str(1001) || int2str(1001)); |
| 93 |
} |
| 94 |
|
| 95 |
do_execsql_test 2.2 { |
| 96 |
SELECT b FROM t1 WHERE a = 10001; |
| 97 |
} "[int2str 1001][int2str 1001][int2str 1001]" |
| 98 |
|
| 99 |
finish_test |