0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2024-12-15 06:19:42 +00:00
libsql/libsql-sqlite3/test/snapshot_up.test
Pekka Enberg 9ed72eb5ae Merge upstream SQLite 3.45.1
This merges the version-3.45.1 tag from upstream SQLite git repository
to libSQL with the following conflicts resolved:

Conflicts:
      README.md
      ext/jni/src/org/sqlite/jni/capi/ConfigSqllogCallback.java
      libsql-sqlite3/configure
      libsql-sqlite3/doc/jsonb.md
      libsql-sqlite3/ext/fts5/test/fts5faultH.test
      libsql-sqlite3/ext/fts5/test/fts5origintext.test
      libsql-sqlite3/ext/fts5/test/fts5origintext2.test
      libsql-sqlite3/ext/fts5/test/fts5origintext3.test
      libsql-sqlite3/ext/fts5/test/fts5origintext4.test
      libsql-sqlite3/ext/fts5/test/fts5origintext5.test
      libsql-sqlite3/ext/fts5/test/fts5secure8.test
      libsql-sqlite3/ext/fts5/test/fts5tokenizer2.test
      libsql-sqlite3/ext/fts5/test/fts5trigram2.test
      libsql-sqlite3/ext/jni/src/org/sqlite/jni/annotation/Experimental.java
      libsql-sqlite3/ext/jni/src/org/sqlite/jni/capi/ConfigSqlLogCallback.java
      libsql-sqlite3/ext/jni/src/org/sqlite/jni/capi/ConfigSqllogCallback.java
      libsql-sqlite3/ext/jni/src/org/sqlite/jni/wrapper1/WindowFunction.java
      libsql-sqlite3/ext/wasm/GNUmakefile
      libsql-sqlite3/ext/wasm/batch-runner-sahpool.html
      libsql-sqlite3/ext/wasm/batch-runner-sahpool.js
      libsql-sqlite3/src/pager.c
      libsql-sqlite3/src/shell.c.in
      libsql-sqlite3/src/sqliteInt.h
      libsql-sqlite3/src/wal.c
      libsql-sqlite3/test/fts3integrity.test
      libsql-sqlite3/test/json/jsonb-q1.txt
      libsql-sqlite3/test/json106.test
      libsql-sqlite3/test/json107.test
      libsql-sqlite3/test/jsonb01.test
      libsql-sqlite3/test/mmapcorrupt.test
      libsql-sqlite3/test/releasetest_data.tcl
      libsql-sqlite3/test/shell9.test
      libsql-sqlite3/test/wapp.tcl
      libsql-sqlite3/test/wapptest.tcl
2024-07-25 13:45:06 +03:00

186 lines
4.3 KiB
Plaintext

# 2018 August 6
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Tests for calling sqlite3_snapshot_open() when there is already
# a read transaction open on the database.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !snapshot {finish_test; return}
set testprefix snapshot_up
# This test does not work with the inmemory_journal permutation. The reason
# is that each connection opened as part of this permutation executes
# "PRAGMA journal_mode=memory", which fails if the database is in wal mode
# and there are one or more existing connections.
if {[permutation]=="inmemory_journal"} {
finish_test
return
}
db timeout 1000
do_execsql_test 1.0 {
CREATE TABLE t1(a, b, c);
PRAGMA journal_mode = wal;
INSERT INTO t1 VALUES(1, 2, 3);
INSERT INTO t1 VALUES(4, 5, 6);
INSERT INTO t1 VALUES(7, 8, 9);
} {wal}
do_test 1.1 {
execsql BEGIN
set ::snap1 [sqlite3_snapshot_get db main]
execsql COMMIT
execsql { INSERT INTO t1 VALUES(10, 11, 12); }
execsql BEGIN
set ::snap2 [sqlite3_snapshot_get db main]
execsql COMMIT
execsql { INSERT INTO t1 VALUES(13, 14, 15); }
execsql BEGIN
set ::snap3 [sqlite3_snapshot_get db main]
execsql COMMIT
} {}
do_execsql_test 1.2 {
BEGIN;
SELECT * FROM t1
} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}
do_test 1.3 {
sqlite3_snapshot_open db main $::snap1
execsql { SELECT * FROM t1 }
} {1 2 3 4 5 6 7 8 9}
do_test 1.4 {
sqlite3_snapshot_open db main $::snap2
execsql { SELECT * FROM t1 }
} {1 2 3 4 5 6 7 8 9 10 11 12}
do_test 1.5 {
sqlite3 db2 test.db
execsql { PRAGMA wal_checkpoint } db2
} {0 5 4}
do_execsql_test 1.6 {
SELECT * FROM t1
} {1 2 3 4 5 6 7 8 9 10 11 12}
do_test 1.7 {
list [catch { sqlite3_snapshot_open db main $::snap1 } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}
do_execsql_test 1.8 {
SELECT * FROM t1
} {1 2 3 4 5 6 7 8 9 10 11 12}
do_test 1.9 {
execsql { COMMIT ; BEGIN }
list [catch { sqlite3_snapshot_open db main $::snap1 } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}
do_test 1.10 {
execsql { COMMIT }
execsql {
PRAGMA wal_checkpoint;
DELETE FROM t1 WHERE a = 1;
} db2
execsql BEGIN
set ::snap4 [sqlite3_snapshot_get db main]
execsql COMMIT
execsql {
DELETE FROM t1 WHERE a = 4;
} db2
} {}
do_test 1.11 {
execsql {
BEGIN;
SELECT * FROM t1
}
} {7 8 9 10 11 12 13 14 15}
do_test 1.12 {
sqlite3_snapshot_open db main $::snap4
execsql { SELECT * FROM t1 }
} {4 5 6 7 8 9 10 11 12 13 14 15}
do_test 1.13 {
list [catch { sqlite3_snapshot_open db main $::snap3 } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}
do_test 1.14 {
execsql { SELECT * FROM t1 }
} {4 5 6 7 8 9 10 11 12 13 14 15}
db close
db2 close
sqlite3 db test.db
do_execsql_test 1.15 {
BEGIN;
SELECT * FROM t1
} {7 8 9 10 11 12 13 14 15}
do_test 1.16 {
list [catch { sqlite3_snapshot_open db main $::snap4 } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}
do_execsql_test 1.17 { COMMIT }
sqlite3_snapshot_free $::snap1
sqlite3_snapshot_free $::snap2
sqlite3_snapshot_free $::snap3
sqlite3_snapshot_free $::snap4
#-------------------------------------------------------------------------
catch { db close }
sqlite3 db test.db
sqlite3 db2 test.db
sqlite3 db3 test.db
proc xBusy {args} { return 1 }
db3 busy xBusy
do_test 2.1 {
execsql { INSERT INTO t1 VALUES(16, 17, 18) } db2
execsql BEGIN
set ::snap1 [sqlite3_snapshot_get db main]
execsql COMMIT
execsql { INSERT INTO t1 VALUES(19, 20, 21) } db2
execsql BEGIN
set ::snap2 [sqlite3_snapshot_get db main]
execsql COMMIT
set {} {}
} {}
do_execsql_test -db db2 2.2 {
BEGIN;
INSERT INTO t1 VALUES(19, 20, 21);
}
do_test 2.3 {
execsql BEGIN
sqlite3_snapshot_open db main $::snap1
execsql { SELECT * FROM t1 }
} {7 8 9 10 11 12 13 14 15 16 17 18}
proc xBusy {args} {
set ::res [list [catch { sqlite3_snapshot_open db main $::snap2 } msg] $msg]
return 1
}
db3 busy xBusy
do_test 2.4 {
execsql {PRAGMA wal_checkpoint = restart} db3
set ::res
} {1 SQLITE_BUSY}
sqlite3_snapshot_free $::snap1
sqlite3_snapshot_free $::snap2
finish_test