3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for PRAGMA data_version command.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 if {[sqlite3 -has-codec]} {
24 do_execsql_test pragma3-100 {
27 do_execsql_test pragma3-101 {
28 PRAGMA temp.data_version;
31 # Writing to the pragma is a no-op
32 do_execsql_test pragma3-102 {
33 PRAGMA main.data_version=1234;
34 PRAGMA main.data_version;
37 # EVIDENCE-OF: R-27726-60934 The "PRAGMA data_version" command provides
38 # an indication that the database file has been modified.
40 # EVIDENCE-OF: R-47505-58569 The "PRAGMA data_version" value is
41 # unchanged for commits made on the same database connection.
43 do_execsql_test pragma3-110 {
48 INSERT INTO t1 VALUES(100),(200),(300);
53 } {1 1 1 100 200 300 1}
63 do_execsql_test pragma3-130 {
67 INSERT INTO t1 VALUES(400),(500);
73 } {1 1 1 100 200 300 400 500 1}
75 # EVIDENCE-OF: R-63005-41812 The integer values returned by two
76 # invocations of "PRAGMA data_version" from the same connection will be
77 # different if changes were committed to the database by any other
78 # connection in the interim.
80 # Value went from 1 in pragma3-120 to 2 here.
93 } {100 200 300 400 500 2 2 101 201 301 401 501 2}
94 do_execsql_test pragma3-150 {
97 } {101 201 301 401 501 2}
100 do_test pragma3-160 {
104 UPDATE t1 SET a=555 WHERE a=501;
106 SELECT * FROM t1 ORDER BY a;
109 } {2 2 101 201 301 401 555 2}
110 do_test pragma3-170 {
115 do_test pragma3-180 {
121 do_test pragma3-190 {
127 # EVIDENCE-OF: R-19326-44825 The "PRAGMA data_version" value is a local
128 # property of each database connection and so values returned by two
129 # concurrent invocations of "PRAGMA data_version" on separate database
130 # connections are often different even though the underlying database is
133 do_test pragma3-195 {
134 expr {[db eval {PRAGMA data_version}]!=[db2 eval {PRAGMA data_version}]}
137 # EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
138 # the same for all database connections, including database connections
139 # in separate processes and shared cache database connections.
141 # The next block checks the behavior for separate processes.
143 do_test pragma3-200 {
144 db eval {PRAGMA data_version; SELECT * FROM t1;}
145 } {2 101 201 301 401 555}
146 do_test pragma3-201 {
147 set fd [open pragma3.txt wb]
150 db eval {DELETE FROM t1 WHERE a>300};
155 exec [info nameofexec] pragma3.txt
156 forcedelete pragma3.txt
165 # EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
166 # the same for all database connections, including database connections
167 # in separate processes and shared cache database connections.
169 # The next block checks that behavior is the same for shared-cache.
171 ifcapable shared_cache {
172 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
175 do_test pragma3-300 {
179 CREATE TABLE t3(a,b,c);
180 CREATE TABLE t4(x,y,z);
181 INSERT INTO t4 VALUES(123,456,789);
187 do_test pragma3-310 {
191 INSERT INTO t3(a,b,c) VALUES('abc','def','ghi');
196 # The transaction in db2 has not yet committed, so the data_version in
198 do_test pragma3-320 {
204 do_test pragma3-330 {
211 do_test pragma3-340 {
217 } {2 abc def ghi 123 456 789}
220 sqlite3_enable_shared_cache $::enable_shared_cache
223 # Make sure this also works in WAL mode
225 # This will not work with the in-memory journal permutation, as opening
226 # [db2] switches the journal mode back to "memory"
228 if {[wal_is_capable]} {
229 if {[permutation]!="inmemory_journal"} {
232 db eval {PRAGMA journal_mode=WAL}
234 do_test pragma3-400 {
241 do_test pragma3-410 {
248 do_test pragma3-420 {
249 db eval {UPDATE t1 SET a=111*(a/100); PRAGMA data_version; SELECT * FROM t1}
251 do_test pragma3-430 {
252 db2 eval {PRAGMA data_version; SELECT * FROM t1;}
258 #-------------------------------------------------------------------------
259 # Check that empty write transactions do not cause the return of "PRAGMA
260 # data_version" to be decremented with journal_mode=PERSIST and
261 # locking_mode=EXCLUSIVE
267 PRAGMA journal_mode = PERSIST;
268 PRAGMA locking_mode = EXCLUSIVE;
274 do_execsql_test pragma3-510$tn {
275 CREATE TABLE t1(x, y);
276 INSERT INTO t1 VALUES(1, 2);
280 do_execsql_test pragma3-520$tn {