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
20 do_execsql_test pragma3-100 {
23 do_execsql_test pragma3-101 {
24 PRAGMA temp.data_version;
27 # Writing to the pragma is a no-op
28 do_execsql_test pragma3-102 {
29 PRAGMA main.data_version=1234;
30 PRAGMA main.data_version;
33 # EVIDENCE-OF: R-27726-60934 The "PRAGMA data_version" command provides
34 # an indication that the database file has been modified.
36 # EVIDENCE-OF: R-47505-58569 The "PRAGMA data_version" value is
37 # unchanged for commits made on the same database connection.
39 do_execsql_test pragma3-110 {
44 INSERT INTO t1 VALUES(100),(200),(300);
49 } {1 1 1 100 200 300 1}
59 do_execsql_test pragma3-130 {
63 INSERT INTO t1 VALUES(400),(500);
69 } {1 1 1 100 200 300 400 500 1}
71 # EVIDENCE-OF: R-63005-41812 The integer values returned by two
72 # invocations of "PRAGMA data_version" from the same connection will be
73 # different if changes were committed to the database by any other
74 # connection in the interim.
76 # Value went from 1 in pragma3-120 to 2 here.
89 } {100 200 300 400 500 2 2 101 201 301 401 501 2}
90 do_execsql_test pragma3-150 {
93 } {101 201 301 401 501 2}
100 UPDATE t1 SET a=555 WHERE a=501;
102 SELECT * FROM t1 ORDER BY a;
105 } {2 2 101 201 301 401 555 2}
106 do_test pragma3-170 {
111 do_test pragma3-180 {
117 do_test pragma3-190 {
123 # EVIDENCE-OF: R-19326-44825 The "PRAGMA data_version" value is a local
124 # property of each database connection and so values returned by two
125 # concurrent invocations of "PRAGMA data_version" on separate database
126 # connections are often different even though the underlying database is
129 do_test pragma3-195 {
130 expr {[db eval {PRAGMA data_version}]!=[db2 eval {PRAGMA data_version}]}
133 # EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
134 # the same for all database connections, including database connections
135 # in separate processes and shared cache database connections.
137 # The next block checks the behavior for separate processes.
139 do_test pragma3-200 {
140 db eval {PRAGMA data_version; SELECT * FROM t1;}
141 } {2 101 201 301 401 555}
142 do_test pragma3-201 {
143 set fd [open pragma3.txt wb]
146 db eval {DELETE FROM t1 WHERE a>300};
151 exec [info nameofexec] pragma3.txt
152 forcedelete pragma3.txt
161 # EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
162 # the same for all database connections, including database connections
163 # in separate processes and shared cache database connections.
165 # The next block checks that behavior is the same for shared-cache.
167 ifcapable shared_cache {
168 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
171 do_test pragma3-300 {
175 CREATE TABLE t3(a,b,c);
176 CREATE TABLE t4(x,y,z);
177 INSERT INTO t4 VALUES(123,456,789);
183 do_test pragma3-310 {
187 INSERT INTO t3(a,b,c) VALUES('abc','def','ghi');
192 # The transaction in db2 has not yet committed, so the data_version in
194 do_test pragma3-320 {
200 do_test pragma3-330 {
207 do_test pragma3-340 {
213 } {2 abc def ghi 123 456 789}
216 sqlite3_enable_shared_cache $::enable_shared_cache
219 # Make sure this also works in WAL mode
221 # This will not work with the in-memory journal permutation, as opening
222 # [db2] switches the journal mode back to "memory"
224 if {[wal_is_capable]} {
225 if {[permutation]!="inmemory_journal"} {
228 db eval {PRAGMA journal_mode=WAL}
230 do_test pragma3-400 {
237 do_test pragma3-410 {
244 do_test pragma3-420 {
245 db eval {UPDATE t1 SET a=111*(a/100); PRAGMA data_version; SELECT * FROM t1}
247 do_test pragma3-430 {
248 db2 eval {PRAGMA data_version; SELECT * FROM t1;}