mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Redefine the way PRAGMA data_version works: It continues to change when
any other connection commits, including shared-cache connections, but does not change if the local connection commits. FossilOrigin-Name: 7a97826f33460f3b4f3890c9cf97116c3355eeda
This commit is contained in:
@ -32,25 +32,20 @@ do_execsql_test pragma3-102 {
|
||||
# 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.
|
||||
# EVIDENCE-OF: R-25838-33704 The "PRAGMA data_version" value is
|
||||
# unchanced for commits made on the same database connection.
|
||||
#
|
||||
do_execsql_test pragma3-110 {
|
||||
PRAGMA data_version;
|
||||
BEGIN IMMEDIATE;
|
||||
PRAGMA data_version;
|
||||
CREATE TABLE t1(a);
|
||||
INSERT INTO t1 VALUES(100),(200),(300);
|
||||
PRAGMA data_version;
|
||||
COMMIT;
|
||||
SELECT * FROM t1;
|
||||
PRAGMA data_version;
|
||||
} {100 200 300 3}
|
||||
} {1 1 1 100 200 300 1}
|
||||
|
||||
sqlite3 db2 test.db
|
||||
do_test pragma3-120 {
|
||||
@ -61,44 +56,88 @@ do_test pragma3-120 {
|
||||
} {100 200 300 1}
|
||||
|
||||
do_execsql_test pragma3-130 {
|
||||
PRAGMA data_version;
|
||||
BEGIN IMMEDIATE;
|
||||
PRAGMA data_version;
|
||||
INSERT INTO t1 VALUES(400),(500);
|
||||
PRAGMA data_version;
|
||||
COMMIT;
|
||||
SELECT * FROM t1;
|
||||
PRAGMA data_version;
|
||||
} {100 200 300 400 500 4}
|
||||
} {1 1 1 100 200 300 400 500 1}
|
||||
|
||||
# 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.
|
||||
# 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.
|
||||
#
|
||||
# In these test, it response to changes in a different database connection
|
||||
# part of the same process.
|
||||
# Value went from 1 in pragma3-120 to 2 here.
|
||||
#
|
||||
do_test pragma3-140 {
|
||||
db2 eval {
|
||||
SELECT * FROM t1;
|
||||
PRAGMA data_version;
|
||||
BEGIN IMMEDIATE;
|
||||
PRAGMA data_version;
|
||||
UPDATE t1 SET a=a+1;
|
||||
COMMIT;
|
||||
SELECT * FROM t1;
|
||||
PRAGMA data_version;
|
||||
}
|
||||
} {100 200 300 400 500 2 101 201 301 401 501 3}
|
||||
} {100 200 300 400 500 2 2 101 201 301 401 501 2}
|
||||
do_execsql_test pragma3-150 {
|
||||
SELECT * FROM t1;
|
||||
PRAGMA data_version;
|
||||
} {101 201 301 401 501 5}
|
||||
} {101 201 301 401 501 2}
|
||||
|
||||
# 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-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.
|
||||
#
|
||||
do_test pragma3-200 {
|
||||
db eval {PRAGMA data_version; SELECT * FROM t1;}
|
||||
} {2 101 201 301 401 555}
|
||||
do_test pragma3-201 {
|
||||
set fd [open pragma3.txt wb]
|
||||
puts $fd {
|
||||
sqlite3 db test.db;
|
||||
@ -113,18 +152,15 @@ do_test pragma3-200 {
|
||||
PRAGMA data_version;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {6 101 201}
|
||||
} {3 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.
|
||||
# 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 series of tests verifies the behavior for shared-cache
|
||||
# database connections.
|
||||
# The next block checks that behavior is the same for shared-cache.
|
||||
#
|
||||
ifcapable shared_cache {
|
||||
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
|
||||
@ -133,24 +169,46 @@ ifcapable shared_cache {
|
||||
do_test pragma3-300 {
|
||||
db eval {
|
||||
PRAGMA data_version;
|
||||
BEGIN;
|
||||
CREATE TABLE t3(a,b,c);
|
||||
CREATE TABLE t4(x,y,z);
|
||||
INSERT INTO t4 VALUES(123,456,789);
|
||||
PRAGMA data_version;
|
||||
COMMIT;
|
||||
PRAGMA data_version;
|
||||
}
|
||||
} {1 2}
|
||||
} {1 1 1}
|
||||
do_test pragma3-310 {
|
||||
db2 eval {
|
||||
PRAGMA data_version;
|
||||
BEGIN;
|
||||
INSERT INTO t3(a,b,c) VALUES('abc','def','ghi');
|
||||
SELECT * FROM t3;
|
||||
PRAGMA data_version;
|
||||
}
|
||||
} {2 abc def ghi 3}
|
||||
} {2 abc def ghi 2}
|
||||
# The transaction in db2 has not yet committed, so the data_version in
|
||||
# db is unchanged.
|
||||
do_test pragma3-320 {
|
||||
db eval {
|
||||
PRAGMA data_version;
|
||||
SELECT * FROM t3;
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {3 abc def ghi}
|
||||
} {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 {
|
||||
db eval {
|
||||
PRAGMA data_version;
|
||||
SELECT * FROM t3;
|
||||
SELECT * FROM t4;
|
||||
}
|
||||
} {2 abc def ghi 123 456 789}
|
||||
db2 close
|
||||
db close
|
||||
sqlite3_enable_shared_cache $::enable_shared_cache
|
||||
@ -168,7 +226,7 @@ ifcapable wal {
|
||||
PRAGMA journal_mode;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {3 wal 101 201}
|
||||
} {2 wal 101 201}
|
||||
do_test pragma3-410 {
|
||||
db2 eval {
|
||||
PRAGMA data_version;
|
||||
@ -178,7 +236,7 @@ ifcapable wal {
|
||||
} {2 wal 101 201}
|
||||
do_test pragma3-420 {
|
||||
db eval {UPDATE t1 SET a=111*(a/100); PRAGMA data_version; SELECT * FROM t1}
|
||||
} {4 111 222}
|
||||
} {2 111 222}
|
||||
do_test pragma3-430 {
|
||||
db2 eval {PRAGMA data_version; SELECT * FROM t1;}
|
||||
} {3 111 222}
|
||||
|
Reference in New Issue
Block a user