3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 source [file join [file dirname [info script]] rbu_common.tcl]
14 set ::testprefix rbutemplimit
20 proc setup_databases {} {
25 -- Create target database schema.
27 CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100));
28 CREATE TABLE t2(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100));
29 CREATE INDEX i1b ON t1(b);
30 CREATE INDEX i1c ON t1(c);
31 CREATE INDEX i2b ON t2(b);
32 CREATE INDEX i2c ON t2(c);
34 -- Create a large RBU database.
36 ATTACH 'test.db2' AS rbu;
37 CREATE TABLE rbu.data_t1(a, b, c, rbu_control);
39 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
41 INSERT INTO data_t1 SELECT i, randomblob(100), randomblob(100), 0 FROM s;
42 CREATE TABLE rbu.data_t2(a, b, c, rbu_control);
44 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<15000
46 INSERT INTO data_t2 SELECT i, randomblob(100), randomblob(100), 0 FROM s;
51 proc run_rbu_cachesize {target rbu cachesize temp_limit} {
52 sqlite3rbu rbu $target $rbu
53 rbu temp_size_limit $temp_limit
54 sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
57 set ::A([rbu temp_size]) 1
58 if {$rc!="SQLITE_OK"} break
60 list [catch {rbu close} msg] $msg
63 proc step_rbu_cachesize {target rbu stepsize cachesize temp_limit} {
66 sqlite3rbu rbu $target $rbu
67 rbu temp_size_limit $temp_limit
68 if { [rbu temp_size_limit -1]!=$temp_limit } { error "round trip problem!" }
69 sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
70 for {set i 0} {$i < $stepsize} {incr i} {
72 set ::A([rbu temp_size]) 1
73 if {$rc!="SQLITE_OK"} break
75 set res [list [catch {rbu close} msg] $msg]
76 if {$res != "0 SQLITE_OK"} break
81 do_test 1.1.0 { setup_databases } {}
85 run_rbu_cachesize test.db test.db2 10 0
88 do_test 1.1.2 { llength [array names ::A] } 3
91 foreach {a0 a1 a2} [lsort -integer [array names ::A]] {}
93 [expr $a1>1048576] [expr $a1<1200000] \
94 [expr $a2>1500000] [expr $a2<1700000]
99 run_rbu_cachesize test.db test.db2 10 1000000
101 do_test 1.2.2 { info commands rbu } {}
105 run_rbu_cachesize test.db test.db2 10 1300000
107 do_test 1.3.2 { info commands rbu } {}
111 run_rbu_cachesize test.db test.db2 10 1800000
113 do_test 1.4.2 { info commands rbu } {}
117 unset -nocomplain ::A
118 step_rbu_cachesize test.db test.db2 1000 10 2400000
120 do_test 1.5.2 { info commands rbu } {}
124 unset -nocomplain ::A
125 step_rbu_cachesize test.db test.db2 1000 10 1400000
127 do_test 1.6.2 { info commands rbu } {}