Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/snapshot_up.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / snapshot_up.test` 185 lines ยท 4357 bytes Raw Blame History 1 # 2018 August 6 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 # Tests for calling sqlite3_snapshot_open() when there is already 13 # a read transaction open on the database. 14 # 15 16 set testdir [file dirname $argv0] 17 source $testdir/tester.tcl 18 ifcapable !snapshot {finish_test; return} 19 set testprefix snapshot_up 20 21 # This test does not work with the inmemory_journal permutation. The reason 22 # is that each connection opened as part of this permutation executes 23 # "PRAGMA journal_mode=memory", which fails if the database is in wal mode 24 # and there are one or more existing connections. 25 if {[permutation]=="inmemory_journal"} { 26 finish_test 27 return 28 } 29 30 db timeout 1000 31 32 do_execsql_test 1.0 { 33 CREATE TABLE t1(a, b, c); 34 PRAGMA journal_mode = wal; 35 INSERT INTO t1 VALUES(1, 2, 3); 36 INSERT INTO t1 VALUES(4, 5, 6); 37 INSERT INTO t1 VALUES(7, 8, 9); 38 } {wal} 39 40 do_test 1.1 { 41 execsql BEGIN 42 set ::snap1 [sqlite3_snapshot_get db main] 43 execsql COMMIT 44 execsql { INSERT INTO t1 VALUES(10, 11, 12); } 45 execsql BEGIN 46 set ::snap2 [sqlite3_snapshot_get db main] 47 execsql COMMIT 48 execsql { INSERT INTO t1 VALUES(13, 14, 15); } 49 execsql BEGIN 50 set ::snap3 [sqlite3_snapshot_get db main] 51 execsql COMMIT 52 } {} 53 54 do_execsql_test 1.2 { 55 BEGIN; 56 SELECT * FROM t1 57 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15} 58 59 do_test 1.3 { 60 sqlite3_snapshot_open db main $::snap1 61 execsql { SELECT * FROM t1 } 62 } {1 2 3 4 5 6 7 8 9} 63 64 do_test 1.4 { 65 sqlite3_snapshot_open db main $::snap2 66 execsql { SELECT * FROM t1 } 67 } {1 2 3 4 5 6 7 8 9 10 11 12} 68 69 do_test 1.5 { 70 sqlite3 db2 test.db 71 execsql { PRAGMA wal_checkpoint } db2 72 } {0 5 4} 73 74 do_execsql_test 1.6 { 75 SELECT * FROM t1 76 } {1 2 3 4 5 6 7 8 9 10 11 12} 77 78 do_test 1.7 { 79 list [catch { sqlite3_snapshot_open db main $::snap1 } msg] $msg 80 } {1 SQLITE_ERROR_SNAPSHOT} 81 82 do_execsql_test 1.8 { 83 SELECT * FROM t1 84 } {1 2 3 4 5 6 7 8 9 10 11 12} 85 86 do_test 1.9 { 87 execsql { COMMIT ; BEGIN } 88 list [catch { sqlite3_snapshot_open db main $::snap1 } msg] $msg 89 } {1 SQLITE_ERROR_SNAPSHOT} 90 91 do_test 1.10 { 92 execsql { COMMIT } 93 execsql { 94 PRAGMA wal_checkpoint; 95 DELETE FROM t1 WHERE a = 1; 96 } db2 97 execsql BEGIN 98 set ::snap4 [sqlite3_snapshot_get db main] 99 execsql COMMIT 100 execsql { 101 DELETE FROM t1 WHERE a = 4; 102 } db2 103 } {} 104 105 do_test 1.11 { 106 execsql { 107 BEGIN; 108 SELECT * FROM t1 109 } 110 } {7 8 9 10 11 12 13 14 15} 111 do_test 1.12 { 112 sqlite3_snapshot_open db main $::snap4 113 execsql { SELECT * FROM t1 } 114 } {4 5 6 7 8 9 10 11 12 13 14 15} 115 116 do_test 1.13 { 117 list [catch { sqlite3_snapshot_open db main $::snap3 } msg] $msg 118 } {1 SQLITE_ERROR_SNAPSHOT} 119 do_test 1.14 { 120 execsql { SELECT * FROM t1 } 121 } {4 5 6 7 8 9 10 11 12 13 14 15} 122 123 db close 124 db2 close 125 sqlite3 db test.db 126 do_execsql_test 1.15 { 127 BEGIN; 128 SELECT * FROM t1 129 } {7 8 9 10 11 12 13 14 15} 130 do_test 1.16 { 131 list [catch { sqlite3_snapshot_open db main $::snap4 } msg] $msg 132 } {1 SQLITE_ERROR_SNAPSHOT} 133 do_execsql_test 1.17 { COMMIT } 134 135 sqlite3_snapshot_free $::snap1 136 sqlite3_snapshot_free $::snap2 137 sqlite3_snapshot_free $::snap3 138 sqlite3_snapshot_free $::snap4 139 140 #------------------------------------------------------------------------- 141 catch { db close } 142 sqlite3 db test.db 143 sqlite3 db2 test.db 144 sqlite3 db3 test.db 145 146 proc xBusy {args} { return 1 } 147 db3 busy xBusy 148 149 do_test 2.1 { 150 execsql { INSERT INTO t1 VALUES(16, 17, 18) } db2 151 execsql BEGIN 152 set ::snap1 [sqlite3_snapshot_get db main] 153 execsql COMMIT 154 execsql { INSERT INTO t1 VALUES(19, 20, 21) } db2 155 execsql BEGIN 156 set ::snap2 [sqlite3_snapshot_get db main] 157 execsql COMMIT 158 set {} {} 159 } {} 160 161 do_execsql_test -db db2 2.2 { 162 BEGIN; 163 INSERT INTO t1 VALUES(19, 20, 21); 164 } 165 166 do_test 2.3 { 167 execsql BEGIN 168 sqlite3_snapshot_open db main $::snap1 169 execsql { SELECT * FROM t1 } 170 } {7 8 9 10 11 12 13 14 15 16 17 18} 171 172 proc xBusy {args} { 173 set ::res [list [catch { sqlite3_snapshot_open db main $::snap2 } msg] $msg] 174 return 1 175 } 176 db3 busy xBusy 177 do_test 2.4 { 178 execsql {PRAGMA wal_checkpoint = restart} db3 179 set ::res 180 } {1 SQLITE_BUSY} 181 182 sqlite3_snapshot_free $::snap1 183 sqlite3_snapshot_free $::snap2 184 185 finish_test