2014-12-19 23:27:02 +03:00
|
|
|
# 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
|
2016-03-14 21:34:42 +03:00
|
|
|
do_not_use_codec
|
2014-12-19 23:27:02 +03:00
|
|
|
|
|
|
|
do_execsql_test pragma3-100 {
|
|
|
|
PRAGMA data_version;
|
|
|
|
} {1}
|
|
|
|
do_execsql_test pragma3-101 {
|
|
|
|
PRAGMA temp.data_version;
|
|
|
|
} {1}
|
|
|
|
|
2014-12-20 17:34:02 +03:00
|
|
|
# Writing to the pragma is a no-op
|
2014-12-19 23:27:02 +03:00
|
|
|
do_execsql_test pragma3-102 {
|
|
|
|
PRAGMA main.data_version=1234;
|
|
|
|
PRAGMA main.data_version;
|
|
|
|
} {1 1}
|
|
|
|
|
2014-12-20 17:34:02 +03:00
|
|
|
# EVIDENCE-OF: R-27726-60934 The "PRAGMA data_version" command provides
|
|
|
|
# an indication that the database file has been modified.
|
|
|
|
#
|
2014-12-23 01:02:20 +03:00
|
|
|
# EVIDENCE-OF: R-47505-58569 The "PRAGMA data_version" value is
|
|
|
|
# unchanged for commits made on the same database connection.
|
2014-12-20 17:34:02 +03:00
|
|
|
#
|
2014-12-19 23:27:02 +03:00
|
|
|
do_execsql_test pragma3-110 {
|
2014-12-22 21:41:21 +03:00
|
|
|
PRAGMA data_version;
|
|
|
|
BEGIN IMMEDIATE;
|
|
|
|
PRAGMA data_version;
|
2014-12-19 23:27:02 +03:00
|
|
|
CREATE TABLE t1(a);
|
|
|
|
INSERT INTO t1 VALUES(100),(200),(300);
|
2014-12-22 21:41:21 +03:00
|
|
|
PRAGMA data_version;
|
|
|
|
COMMIT;
|
2014-12-19 23:27:02 +03:00
|
|
|
SELECT * FROM t1;
|
|
|
|
PRAGMA data_version;
|
2014-12-22 21:41:21 +03:00
|
|
|
} {1 1 1 100 200 300 1}
|
2014-12-19 23:27:02 +03:00
|
|
|
|
|
|
|
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 {
|
2014-12-22 21:41:21 +03:00
|
|
|
PRAGMA data_version;
|
|
|
|
BEGIN IMMEDIATE;
|
|
|
|
PRAGMA data_version;
|
2014-12-19 23:27:02 +03:00
|
|
|
INSERT INTO t1 VALUES(400),(500);
|
2014-12-22 21:41:21 +03:00
|
|
|
PRAGMA data_version;
|
|
|
|
COMMIT;
|
2014-12-19 23:27:02 +03:00
|
|
|
SELECT * FROM t1;
|
|
|
|
PRAGMA data_version;
|
2014-12-31 17:18:48 +03:00
|
|
|
PRAGMA shrink_memory;
|
2014-12-22 21:41:21 +03:00
|
|
|
} {1 1 1 100 200 300 400 500 1}
|
2014-12-19 23:27:02 +03:00
|
|
|
|
2014-12-22 21:41:21 +03:00
|
|
|
# EVIDENCE-OF: R-63005-41812 The integer values returned by two
|
|
|
|
# invocations of "PRAGMA data_version" from the same connection will be
|
|
|
|
# different if changes were committed to the database by any other
|
|
|
|
# connection in the interim.
|
2014-12-20 17:34:02 +03:00
|
|
|
#
|
2014-12-22 21:41:21 +03:00
|
|
|
# Value went from 1 in pragma3-120 to 2 here.
|
2014-12-20 17:34:02 +03:00
|
|
|
#
|
2014-12-19 23:27:02 +03:00
|
|
|
do_test pragma3-140 {
|
|
|
|
db2 eval {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
PRAGMA data_version;
|
2014-12-22 21:41:21 +03:00
|
|
|
BEGIN IMMEDIATE;
|
|
|
|
PRAGMA data_version;
|
2014-12-19 23:27:02 +03:00
|
|
|
UPDATE t1 SET a=a+1;
|
2014-12-22 21:41:21 +03:00
|
|
|
COMMIT;
|
2014-12-19 23:27:02 +03:00
|
|
|
SELECT * FROM t1;
|
|
|
|
PRAGMA data_version;
|
|
|
|
}
|
2014-12-22 21:41:21 +03:00
|
|
|
} {100 200 300 400 500 2 2 101 201 301 401 501 2}
|
2014-12-19 23:27:02 +03:00
|
|
|
do_execsql_test pragma3-150 {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
PRAGMA data_version;
|
2014-12-22 21:41:21 +03:00
|
|
|
} {101 201 301 401 501 2}
|
2014-12-19 23:27:02 +03:00
|
|
|
|
2014-12-20 17:34:02 +03:00
|
|
|
#
|
2014-12-22 21:41:21 +03:00
|
|
|
do_test pragma3-160 {
|
|
|
|
db eval {
|
|
|
|
BEGIN;
|
|
|
|
PRAGMA data_version;
|
|
|
|
UPDATE t1 SET a=555 WHERE a=501;
|
|
|
|
PRAGMA data_version;
|
|
|
|
SELECT * FROM t1 ORDER BY a;
|
|
|
|
PRAGMA data_version;
|
|
|
|
}
|
|
|
|
} {2 2 101 201 301 401 555 2}
|
|
|
|
do_test pragma3-170 {
|
|
|
|
db2 eval {
|
|
|
|
PRAGMA data_version;
|
|
|
|
}
|
|
|
|
} {2}
|
|
|
|
do_test pragma3-180 {
|
|
|
|
db eval {
|
|
|
|
COMMIT;
|
|
|
|
PRAGMA data_version;
|
|
|
|
}
|
|
|
|
} {2}
|
|
|
|
do_test pragma3-190 {
|
|
|
|
db2 eval {
|
|
|
|
PRAGMA data_version;
|
|
|
|
}
|
|
|
|
} {3}
|
|
|
|
|
|
|
|
# EVIDENCE-OF: R-19326-44825 The "PRAGMA data_version" value is a local
|
|
|
|
# property of each database connection and so values returned by two
|
|
|
|
# concurrent invocations of "PRAGMA data_version" on separate database
|
|
|
|
# connections are often different even though the underlying database is
|
|
|
|
# identical.
|
|
|
|
#
|
|
|
|
do_test pragma3-195 {
|
|
|
|
expr {[db eval {PRAGMA data_version}]!=[db2 eval {PRAGMA data_version}]}
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
# EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
|
|
|
|
# the same for all database connections, including database connections
|
|
|
|
# in separate processes and shared cache database connections.
|
|
|
|
#
|
|
|
|
# The next block checks the behavior for separate processes.
|
2014-12-20 17:34:02 +03:00
|
|
|
#
|
|
|
|
do_test pragma3-200 {
|
2014-12-22 21:41:21 +03:00
|
|
|
db eval {PRAGMA data_version; SELECT * FROM t1;}
|
|
|
|
} {2 101 201 301 401 555}
|
|
|
|
do_test pragma3-201 {
|
2014-12-20 17:34:02 +03:00
|
|
|
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;
|
|
|
|
}
|
2014-12-22 21:41:21 +03:00
|
|
|
} {3 101 201}
|
2014-12-19 23:27:02 +03:00
|
|
|
db2 close
|
2014-12-20 17:34:02 +03:00
|
|
|
db close
|
|
|
|
|
2014-12-22 21:41:21 +03:00
|
|
|
# EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
|
|
|
|
# the same for all database connections, including database connections
|
|
|
|
# in separate processes and shared cache database connections.
|
2014-12-20 17:34:02 +03:00
|
|
|
#
|
2014-12-22 21:41:21 +03:00
|
|
|
# The next block checks that behavior is the same for shared-cache.
|
2014-12-20 17:34:02 +03:00
|
|
|
#
|
|
|
|
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;
|
2014-12-22 21:41:21 +03:00
|
|
|
BEGIN;
|
2014-12-20 17:34:02 +03:00
|
|
|
CREATE TABLE t3(a,b,c);
|
2014-12-22 21:41:21 +03:00
|
|
|
CREATE TABLE t4(x,y,z);
|
|
|
|
INSERT INTO t4 VALUES(123,456,789);
|
|
|
|
PRAGMA data_version;
|
|
|
|
COMMIT;
|
2014-12-20 17:34:02 +03:00
|
|
|
PRAGMA data_version;
|
|
|
|
}
|
2014-12-22 21:41:21 +03:00
|
|
|
} {1 1 1}
|
2014-12-20 17:34:02 +03:00
|
|
|
do_test pragma3-310 {
|
|
|
|
db2 eval {
|
|
|
|
PRAGMA data_version;
|
2014-12-22 21:41:21 +03:00
|
|
|
BEGIN;
|
2014-12-20 17:34:02 +03:00
|
|
|
INSERT INTO t3(a,b,c) VALUES('abc','def','ghi');
|
|
|
|
SELECT * FROM t3;
|
|
|
|
PRAGMA data_version;
|
|
|
|
}
|
2014-12-22 21:41:21 +03:00
|
|
|
} {2 abc def ghi 2}
|
|
|
|
# The transaction in db2 has not yet committed, so the data_version in
|
|
|
|
# db is unchanged.
|
2014-12-20 17:34:02 +03:00
|
|
|
do_test pragma3-320 {
|
2014-12-22 21:41:21 +03:00
|
|
|
db eval {
|
|
|
|
PRAGMA data_version;
|
|
|
|
SELECT * FROM t4;
|
|
|
|
}
|
|
|
|
} {1 123 456 789}
|
|
|
|
do_test pragma3-330 {
|
|
|
|
db2 eval {
|
|
|
|
COMMIT;
|
|
|
|
PRAGMA data_version;
|
|
|
|
SELECT * FROM t4;
|
|
|
|
}
|
|
|
|
} {2 123 456 789}
|
|
|
|
do_test pragma3-340 {
|
2014-12-20 17:34:02 +03:00
|
|
|
db eval {
|
|
|
|
PRAGMA data_version;
|
|
|
|
SELECT * FROM t3;
|
2014-12-22 21:41:21 +03:00
|
|
|
SELECT * FROM t4;
|
2014-12-20 17:34:02 +03:00
|
|
|
}
|
2014-12-22 21:41:21 +03:00
|
|
|
} {2 abc def ghi 123 456 789}
|
2014-12-20 17:34:02 +03:00
|
|
|
db2 close
|
2014-12-20 17:50:28 +03:00
|
|
|
db close
|
2014-12-20 17:34:02 +03:00
|
|
|
sqlite3_enable_shared_cache $::enable_shared_cache
|
|
|
|
}
|
|
|
|
|
2014-12-20 17:50:28 +03:00
|
|
|
# Make sure this also works in WAL mode
|
|
|
|
#
|
2014-12-30 21:07:34 +03:00
|
|
|
# This will not work with the in-memory journal permutation, as opening
|
|
|
|
# [db2] switches the journal mode back to "memory"
|
|
|
|
#
|
2016-04-27 21:54:49 +03:00
|
|
|
if {[wal_is_capable]} {
|
2014-12-30 21:07:34 +03:00
|
|
|
if {[permutation]!="inmemory_journal"} {
|
|
|
|
|
2014-12-20 17:50:28 +03:00
|
|
|
sqlite3 db test.db
|
|
|
|
db eval {PRAGMA journal_mode=WAL}
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
do_test pragma3-400 {
|
|
|
|
db eval {
|
|
|
|
PRAGMA data_version;
|
|
|
|
PRAGMA journal_mode;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
}
|
2014-12-22 21:41:21 +03:00
|
|
|
} {2 wal 101 201}
|
2014-12-20 17:50:28 +03:00
|
|
|
do_test pragma3-410 {
|
|
|
|
db2 eval {
|
|
|
|
PRAGMA data_version;
|
|
|
|
PRAGMA journal_mode;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
}
|
|
|
|
} {2 wal 101 201}
|
|
|
|
do_test pragma3-420 {
|
|
|
|
db eval {UPDATE t1 SET a=111*(a/100); PRAGMA data_version; SELECT * FROM t1}
|
2014-12-22 21:41:21 +03:00
|
|
|
} {2 111 222}
|
2014-12-20 17:50:28 +03:00
|
|
|
do_test pragma3-430 {
|
|
|
|
db2 eval {PRAGMA data_version; SELECT * FROM t1;}
|
|
|
|
} {3 111 222}
|
|
|
|
db2 close
|
|
|
|
}
|
2014-12-30 21:07:34 +03:00
|
|
|
}
|
2014-12-20 17:50:28 +03:00
|
|
|
|
2014-12-19 23:27:02 +03:00
|
|
|
finish_test
|