1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-10-25 09:59:22 +03:00
Files
sqlite/test/pragma3.test
drh d7107b3852 Update the PRAGMA data_version command so that it reponse to changes made
by a shared-cache database connection, and also to changes made by the same
database connection.  Add test cases to verify the new behavior.

FossilOrigin-Name: 44ee538374940c50198949f2cbb9213ba2375b6a
2014-12-20 14:34:02 +00:00

159 lines
4.4 KiB
Plaintext

# 2014-12-19
#
# 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for PRAGMA data_version command.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_execsql_test pragma3-100 {
PRAGMA data_version;
} {1}
do_execsql_test pragma3-101 {
PRAGMA temp.data_version;
} {1}
# Writing to the pragma is a no-op
do_execsql_test pragma3-102 {
PRAGMA main.data_version=1234;
PRAGMA main.data_version;
} {1 1}
# EVIDENCE-OF: R-27726-60934 The "PRAGMA data_version" command provides
# an indication that the database file has been modified.
#
# EVIDENCE-OF: R-30058-27547 The integer values returned by two
# invocations of "PRAGMA data_version" will be different if changes
# where committed to that database in between the two invocations.
#
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# In this test, it response to two separate changes on the same database
# connection.
#
do_execsql_test pragma3-110 {
CREATE TABLE t1(a);
INSERT INTO t1 VALUES(100),(200),(300);
SELECT * FROM t1;
PRAGMA data_version;
} {100 200 300 3}
sqlite3 db2 test.db
do_test pragma3-120 {
db2 eval {
SELECT * FROM t1;
PRAGMA data_version;
}
} {100 200 300 1}
do_execsql_test pragma3-130 {
INSERT INTO t1 VALUES(400),(500);
SELECT * FROM t1;
PRAGMA data_version;
} {100 200 300 400 500 4}
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# In these test, it response to changes in a different database connection
# part of the same process.
#
do_test pragma3-140 {
db2 eval {
SELECT * FROM t1;
PRAGMA data_version;
UPDATE t1 SET a=a+1;
SELECT * FROM t1;
PRAGMA data_version;
}
} {100 200 300 400 500 2 101 201 301 401 501 3}
do_execsql_test pragma3-150 {
SELECT * FROM t1;
PRAGMA data_version;
} {101 201 301 401 501 5}
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# This test verifies behavior when a separate process changes the database
# file.
#
do_test pragma3-200 {
set fd [open pragma3.txt wb]
puts $fd {
sqlite3 db test.db;
db eval {DELETE FROM t1 WHERE a>300};
db close;
exit;
}
close $fd
exec [info nameofexec] pragma3.txt
forcedelete pragma3.txt
db eval {
PRAGMA data_version;
SELECT * FROM t1;
}
} {6 101 201}
db2 close
db close
# EVIDENCE-OF: R-10201-09349 The "PRAGMA data_version" command responses
# to changes committed by the same database connection, by database
# connections sharing a cache in shared cache mode, and by completely
# independent database connections including connections in separate
# threads and processes.
#
# The next series of tests verifies the behavior for shared-cache
# database connections.
#
ifcapable shared_cache {
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
sqlite3 db test.db
sqlite3 db2 test.db
do_test pragma3-300 {
db eval {
PRAGMA data_version;
CREATE TABLE t3(a,b,c);
PRAGMA data_version;
}
} {1 2}
do_test pragma3-310 {
db2 eval {
PRAGMA data_version;
INSERT INTO t3(a,b,c) VALUES('abc','def','ghi');
SELECT * FROM t3;
PRAGMA data_version;
}
} {2 abc def ghi 3}
do_test pragma3-320 {
db eval {
PRAGMA data_version;
SELECT * FROM t3;
}
} {3 abc def ghi}
db2 close
sqlite3_enable_shared_cache $::enable_shared_cache
}
finish_test