sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / test / tkt-2d1a5c67d.test
| 1 | # 2011 May 19 |
| 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 | # This file implements regression tests for SQLite library. Specifically, |
| 12 | # it tests that ticket [2d1a5c67dfc2363e44f29d9bbd57f7331851390a] has |
| 13 | # been resolved. |
| 14 | # |
| 15 | # |
| 16 | # |
| 17 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | set testprefix tkt-2d1a5c67d |
| 21 | |
| 22 | ifcapable {!vtab || !incrblob} {finish_test; return} |
| 23 | if {[wal_is_capable]==0} {finish_test; return} |
| 24 | |
| 25 | for {set ii 1} {$ii<=10} {incr ii} { |
| 26 | do_test tkt-2d1a5c67d.1.$ii { |
| 27 | db close |
| 28 | forcedelete test.db test.db-wal |
| 29 | sqlite3 db test.db |
| 30 | db eval "PRAGMA cache_size=$::ii" |
| 31 | db eval { |
| 32 | PRAGMA journal_mode=WAL; |
| 33 | CREATE TABLE t1(a,b); |
| 34 | CREATE INDEX t1b ON t1(b); |
| 35 | CREATE TABLE t2(x,y UNIQUE); |
| 36 | INSERT INTO t2 VALUES(3,4); |
| 37 | BEGIN; |
| 38 | INSERT INTO t1(a,b) VALUES(1,2); |
| 39 | SELECT 'A', * FROM t2 WHERE y=4; |
| 40 | SELECT 'B', * FROM t1; |
| 41 | COMMIT; |
| 42 | SELECT 'C', * FROM t1; |
| 43 | } |
| 44 | } {wal A 3 4 B 1 2 C 1 2} |
| 45 | } |
| 46 | |
| 47 | db close |
| 48 | forcedelete test.db test.db-wal |
| 49 | sqlite3 db test.db |
| 50 | load_static_extension db wholenumber |
| 51 | db eval { |
| 52 | PRAGMA journal_mode=WAL; |
| 53 | CREATE TABLE t1(a,b); |
| 54 | CREATE INDEX t1b ON t1(b); |
| 55 | CREATE TABLE t2(x,y); |
| 56 | CREATE VIRTUAL TABLE nums USING wholenumber; |
| 57 | INSERT INTO t2 SELECT value, randomblob(1000) FROM nums |
| 58 | WHERE value BETWEEN 1 AND 1000; |
| 59 | } |
| 60 | |
| 61 | for {set ii 1} {$ii<=10} {incr ii} { |
| 62 | do_test tkt-2d1a5c67d.2.$ii { |
| 63 | db eval "PRAGMA cache_size=$::ii" |
| 64 | db eval { |
| 65 | DELETE FROM t1; |
| 66 | BEGIN; |
| 67 | INSERT INTO t1(a,b) VALUES(1,2); |
| 68 | SELECT sum(length(y)) FROM t2; |
| 69 | COMMIT; |
| 70 | SELECT * FROM t1; |
| 71 | } |
| 72 | } {1000000 1 2} |
| 73 | } |
| 74 | |
| 75 | db close |
| 76 | sqlite3 db test.db |
| 77 | |
| 78 | |
| 79 | do_execsql_test 3.1 { |
| 80 | PRAGMA cache_size = 10; |
| 81 | CREATE TABLE t3(a INTEGER PRIMARY KEY, b); |
| 82 | CREATE TABLE t4(a); |
| 83 | } |
| 84 | |
| 85 | do_execsql_test 3.2 { |
| 86 | INSERT INTO t3 VALUES(NULL, randomblob(500)); |
| 87 | INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 2 |
| 88 | INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 4 |
| 89 | INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 8 |
| 90 | INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 16 |
| 91 | INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 32 |
| 92 | INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 64 |
| 93 | INSERT INTO t3 SELECT NULL, b||b FROM t3; -- 128 |
| 94 | } |
| 95 | |
| 96 | do_execsql_test 3.3 { |
| 97 | BEGIN; |
| 98 | INSERT INTO t4 VALUES('xyz'); |
| 99 | } |
| 100 | |
| 101 | do_test 3.4 { |
| 102 | set blobs [list] |
| 103 | for {set i 1} {$i<100} {incr i} { |
| 104 | set b [db incrblob -readonly t3 b $i] |
| 105 | fconfigure $b -translation binary |
| 106 | read $b |
| 107 | lappend blobs $b |
| 108 | } |
| 109 | |
| 110 | execsql COMMIT |
| 111 | execsql { SELECT * FROM t4 WHERE a = 'xyz' } |
| 112 | } {xyz} |
| 113 | |
| 114 | do_test 3.5 { |
| 115 | foreach b $blobs { close $b } |
| 116 | execsql { SELECT * FROM t4 WHERE a = 'xyz' } |
| 117 | } {xyz} |
| 118 | |
| 119 | # Check that recovery works on the WAL file. |
| 120 | # |
| 121 | forcedelete test.db2-wal test.db2 |
| 122 | do_test 3.6 { |
| 123 | copy_file test.db-wal test.db2-wal |
| 124 | copy_file test.db test.db2 |
| 125 | sqlite3 db2 test.db2 |
| 126 | execsql { SELECT * FROM t4 WHERE a = 'xyz' } db2 |
| 127 | } {xyz} |
| 128 | |
| 129 | finish_test |