2 # May you do good and not evil.
3 # May you find forgiveness for yourself and forgive others.
4 # May you share freely, never taking more than you give.
6 #***********************************************************************
7 # This file implements regression tests for the persistent pragma API.
11 set testdir [file dirname $argv0]/../../lang/sql/sqlite/test
12 source $testdir/tester.tcl
14 # Test that pragma journal_size_limit works as expected.
17 set ::pragmafile test.db-journal/pragma
19 # Get the value of a persistent pragma that has not been set
20 do_test persistent-1.1.0 {
22 PRAGMA persistent_echo;
26 # Get the schema version
27 do_test persistent-1.1.1 {
29 PRAGMA persistent_version;
33 # Test that calling the pragma did not create the file
34 do_test persistent-1.2 {
35 file exists $::pragmafile
38 # Set the persistent pragma
39 do_test persistent-1.3 {
41 PRAGMA persistent_echo="test";
45 # Test that setting the pragma did create the file
46 do_test persistent-1.4 {
47 file exists $::pragmafile
51 do_test persistent-1.5 {
53 PRAGMA persistent_echo;
61 # Test that the pragma is still set after closing the database
62 do_test persistent-1.6 {
64 PRAGMA persistent_echo;
68 # Set the pragma to a new value
69 do_test persistent-1.7 {
71 PRAGMA persistent_echo="test2";
76 do_test persistent-1.8 {
78 PRAGMA persistent_echo;
82 # Get the schema version again
83 do_test persistent-1.8.1 {
85 PRAGMA persistent_version;
89 # Corrupt the journal directory and get the pragma again. [#19811]
90 do_test persistent-1.9 {
91 # Corrupt the journal directory
92 set filename "test.db-journal"
93 file rename -force $filename "tmpdir"
94 set fileId [open $filename "w"]
95 puts $fileId "Corrupt the directory with this data"
98 # Get the pragma again to see if the error is correctly handled
100 PRAGMA persistent_echo;
103 # Restore the juronal file
104 file delete -force $filename
105 file rename -force "tmpdir" $filename
110 #corrupt the pragma file
111 set out [open $::pragmafile w]
112 puts $out "This is not a valid pragma file"
117 #Test that a corrupted pragma file is handled correctly
118 do_test persistent-2.0 {
119 catchsql { PRAGMA persistent_echo; }
120 } {1 {Persistent pragma database corrupted. All persistent pragma values lost. Please re-enter all pragmas.}}
122 # Test that the corrupted pragma file has been deleted
123 do_test persistent-2.1 {
124 file exists $::pragmafile
127 # Set the pragma, recreating the file
128 do_test persistent-2.2 {
130 PRAGMA persistent_echo="test3";
135 do_test persistent-2.3 {
137 PRAGMA persistent_echo;
141 # Test that the pragma file has been recreated
142 do_test persistent-2.4 {
143 file exists $::pragmafile
146 # Test the persistent_version pragma
147 do_test persistent-3.0 {
149 PRAGMA persistent_version;
153 # Setting the persistent_version value does nothing.
154 do_test persistent-3.1 {
156 PRAGMA persistent_version="2.0";
164 # Test that a value set before opening the environment
165 # exists after opening it.
166 do_test persistent-4.0 {
168 PRAGMA persistent_echo="test3";
172 do_test persistent-4.1 {
178 do_test persistent-4.2 {
180 PRAGMA persistent_echo;
184 # Test that updating a value 3 times does not corrupt it
185 do_test persistent-5.0 {
187 PRAGMA persistent_echo=test4;
191 do_test persistent-5.1 {
193 PRAGMA persistent_echo=test4;
197 do_test persistent-5.2 {
199 PRAGMA persistent_echo=test4;
203 do_test persistent-5.3 {
205 PRAGMA persistent_echo;