CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
snapshot_up.test186 linesDownload Raw Back to test
1# 2018 August 62#3# The author disclaims copyright to this source code.  In place of4# 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 already13# a read transaction open on the database.14#15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18ifcapable !snapshot {finish_test; return}19set testprefix snapshot_up20 21# This test does not work with the inmemory_journal permutation. The reason22# is that each connection opened as part of this permutation executes23# "PRAGMA journal_mode=memory", which fails if the database is in wal mode24# and there are one or more existing connections.25if {[permutation]=="inmemory_journal"} {26  finish_test27  return28}29 30db timeout 100031 32do_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 40do_test 1.1 {41  execsql BEGIN42  set ::snap1 [sqlite3_snapshot_get db main]43  execsql COMMIT44  execsql { INSERT INTO t1 VALUES(10, 11, 12); }45  execsql BEGIN46  set ::snap2 [sqlite3_snapshot_get db main]47  execsql COMMIT48  execsql { INSERT INTO t1 VALUES(13, 14, 15); }49  execsql BEGIN50  set ::snap3 [sqlite3_snapshot_get db main]51  execsql COMMIT52} {}53 54do_execsql_test 1.2 {55  BEGIN;56    SELECT * FROM t157} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}58 59do_test 1.3 {60  sqlite3_snapshot_open db main $::snap161  execsql { SELECT * FROM t1 }62} {1 2 3 4 5 6 7 8 9}63 64do_test 1.4 {65  sqlite3_snapshot_open db main $::snap266  execsql { SELECT * FROM t1 }67} {1 2 3 4 5 6 7 8 9 10 11 12}68 69do_test 1.5 {70  sqlite3 db2 test.db71  execsql { PRAGMA wal_checkpoint } db272} {0 5 4}73 74do_execsql_test 1.6 {75  SELECT * FROM t176} {1 2 3 4 5 6 7 8 9 10 11 12}77 78do_test 1.7 {79  list [catch { sqlite3_snapshot_open db main $::snap1 } msg] $msg80} {1 SQLITE_ERROR_SNAPSHOT}81 82do_execsql_test 1.8 {83  SELECT * FROM t184} {1 2 3 4 5 6 7 8 9 10 11 12}85 86do_test 1.9 {87  execsql { COMMIT ; BEGIN }88  list [catch { sqlite3_snapshot_open db main $::snap1 } msg] $msg89} {1 SQLITE_ERROR_SNAPSHOT}90 91do_test 1.10 {92  execsql { COMMIT }93  execsql {94    PRAGMA wal_checkpoint;95    DELETE FROM t1 WHERE a = 1;96  } db297  execsql BEGIN98  set ::snap4 [sqlite3_snapshot_get db main]99  execsql COMMIT100  execsql {101    DELETE FROM t1 WHERE a = 4;102  } db2103} {}104 105do_test 1.11 {106  execsql { 107    BEGIN;108      SELECT * FROM t1109  }110} {7 8 9 10 11 12 13 14 15}111do_test 1.12 {112  sqlite3_snapshot_open db main $::snap4113  execsql { SELECT * FROM t1 }114} {4 5 6 7 8 9 10 11 12 13 14 15}115 116do_test 1.13 {117  list [catch { sqlite3_snapshot_open db main $::snap3 } msg] $msg118} {1 SQLITE_ERROR_SNAPSHOT}119do_test 1.14 {120  execsql { SELECT * FROM t1 }121} {4 5 6 7 8 9 10 11 12 13 14 15}122 123db close124db2 close125sqlite3 db test.db126do_execsql_test 1.15 {127  BEGIN;128    SELECT * FROM t1129} {7 8 9 10 11 12 13 14 15}130do_test 1.16 {131  list [catch { sqlite3_snapshot_open db main $::snap4 } msg] $msg132} {1 SQLITE_ERROR_SNAPSHOT}133do_execsql_test 1.17 { COMMIT }134 135sqlite3_snapshot_free $::snap1136sqlite3_snapshot_free $::snap2137sqlite3_snapshot_free $::snap3138sqlite3_snapshot_free $::snap4139 140#-------------------------------------------------------------------------141catch { db close }142sqlite3 db test.db143sqlite3 db2 test.db144sqlite3 db3 test.db145 146proc xBusy {args} { return 1 }147db3 busy xBusy148 149do_test 2.1 {150  execsql { INSERT INTO t1 VALUES(16, 17, 18) } db2151  execsql BEGIN152  set ::snap1 [sqlite3_snapshot_get db main]153  execsql COMMIT154  execsql { INSERT INTO t1 VALUES(19, 20, 21) } db2155  execsql BEGIN156  set ::snap2 [sqlite3_snapshot_get db main]157  execsql COMMIT158  set {} {}159} {}160 161do_execsql_test -db db2 2.2 {162  BEGIN;163    INSERT INTO t1 VALUES(19, 20, 21);164}165 166do_test 2.3 {167  execsql BEGIN168  sqlite3_snapshot_open db main $::snap1169  execsql { SELECT * FROM t1 }170} {7 8 9 10 11 12 13 14 15 16 17 18}171 172proc xBusy {args} { 173  set ::res [list [catch { sqlite3_snapshot_open db main $::snap2 } msg] $msg]174  return 1175}176db3 busy xBusy177do_test 2.4 {178  execsql {PRAGMA wal_checkpoint = restart} db3179  set ::res180} {1 SQLITE_BUSY}181 182sqlite3_snapshot_free $::snap1183sqlite3_snapshot_free $::snap2184 185finish_test186