dan | f577875 | 2018-08-28 11:23:52 +0000 | [diff] [blame] | 1 | # 2018 August 28 |
| 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. The focus |
| 12 | # of this file is the sqlite3_snapshot_xxx() APIs. |
| 13 | # |
| 14 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
| 17 | ifcapable !snapshot {finish_test; return} |
| 18 | set testprefix snapshot4 |
| 19 | |
| 20 | # This test does not work with the inmemory_journal permutation. The reason |
| 21 | # is that each connection opened as part of this permutation executes |
| 22 | # "PRAGMA journal_mode=memory", which fails if the database is in wal mode |
| 23 | # and there are one or more existing connections. |
| 24 | if {[permutation]=="inmemory_journal"} { |
| 25 | finish_test |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | sqlite3 db2 test.db |
| 30 | |
| 31 | do_execsql_test 1.0 { |
| 32 | PRAGMA cache_size = 10; |
| 33 | CREATE TABLE t1(a, b); |
| 34 | INSERT INTO t1 VALUES(1, randomblob(400)); |
| 35 | PRAGMA journal_mode = wal; |
| 36 | WITH s(i) AS ( |
| 37 | SELECT 2 UNION ALL SELECT i+1 FROM s WHERE i<100 |
| 38 | ) |
| 39 | INSERT INTO t1 SELECT i, randomblob(400) FROM s; |
| 40 | } {wal} |
| 41 | |
| 42 | do_test 1.1 { |
| 43 | execsql { |
| 44 | BEGIN; |
| 45 | SELECT count(*) FROM t1; |
| 46 | } |
| 47 | } {100} |
| 48 | |
| 49 | do_test 1.2 { |
| 50 | db2 eval { |
| 51 | SELECT count(*) FROM t1; |
| 52 | CREATE TABLE t2(x); |
| 53 | } |
| 54 | } {100} |
| 55 | |
| 56 | do_test 1.3 { |
| 57 | set ::snap [sqlite3_snapshot_get_blob db main] |
| 58 | db2 eval { PRAGMA wal_checkpoint } |
| 59 | } {0 54 52} |
| 60 | |
| 61 | do_test 1.4 { |
| 62 | execsql { |
| 63 | COMMIT; |
| 64 | SELECT * FROM sqlite_master; |
| 65 | BEGIN; |
| 66 | } |
| 67 | sqlite3_snapshot_open_blob db main $::snap |
| 68 | execsql { |
| 69 | SELECT count(*) FROM t1 |
| 70 | } |
| 71 | } {100} |
| 72 | |
| 73 | |
| 74 | finish_test |