1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#
# 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 the persistent pragma API.
#
set testdir [file dirname $argv0]/../../lang/sql/sqlite/test
source $testdir/tester.tcl
# Test that pragma journal_size_limit works as expected.
#
set ::pragmafile test.db-journal/pragma
# Get the value of a persistent pragma that has not been set
do_test persistent-1.1.0 {
execsql {
PRAGMA persistent_echo;
}
} {{}}
# Get the schema version
do_test persistent-1.1.1 {
execsql {
PRAGMA persistent_version;
}
} {1.0}
# Test that calling the pragma did not create the file
do_test persistent-1.2 {
file exists $::pragmafile
} {0}
# Set the persistent pragma
do_test persistent-1.3 {
execsql {
PRAGMA persistent_echo="test";
}
} {test}
# Test that setting the pragma did create the file
do_test persistent-1.4 {
file exists $::pragmafile
} {1}
# Get the pragma
do_test persistent-1.5 {
execsql {
PRAGMA persistent_echo;
}
} {test}
db close
sqlite3 db test.db
# Test that the pragma is still set after closing the database
do_test persistent-1.6 {
execsql {
PRAGMA persistent_echo;
}
} {test}
# Set the pragma to a new value
do_test persistent-1.7 {
execsql {
PRAGMA persistent_echo="test2";
}
} {test2}
# Get the pragma
do_test persistent-1.8 {
execsql {
PRAGMA persistent_echo;
}
} {test2}
# Get the schema version again
do_test persistent-1.8.1 {
execsql {
PRAGMA persistent_version;
}
} {1.0}
# Corrupt the journal directory and get the pragma again. [#19811]
do_test persistent-1.9 {
# Corrupt the journal directory
set filename "test.db-journal"
file rename -force $filename "tmpdir"
set fileId [open $filename "w"]
puts $fileId "Corrupt the directory with this data"
close $fileId
# Get the pragma again to see if the error is correctly handled
execsql {
PRAGMA persistent_echo;
}
# Restore the juronal file
file delete -force $filename
file rename -force "tmpdir" $filename
} {}
db close
#corrupt the pragma file
set out [open $::pragmafile w]
puts $out "This is not a valid pragma file"
close $out
sqlite3 db test.db
#Test that a corrupted pragma file is handled correctly
do_test persistent-2.0 {
catchsql { PRAGMA persistent_echo; }
} {1 {Persistent pragma database corrupted. All persistent pragma values lost. Please re-enter all pragmas.}}
# Test that the corrupted pragma file has been deleted
do_test persistent-2.1 {
file exists $::pragmafile
} {0}
# Set the pragma, recreating the file
do_test persistent-2.2 {
execsql {
PRAGMA persistent_echo="test3";
}
} {test3}
# Get the pragma
do_test persistent-2.3 {
execsql {
PRAGMA persistent_echo;
}
} {test3}
# Test that the pragma file has been recreated
do_test persistent-2.4 {
file exists $::pragmafile
} {1}
# Test the persistent_version pragma
do_test persistent-3.0 {
execsql {
PRAGMA persistent_version;
}
} {1.0}
# Setting the persistent_version value does nothing.
do_test persistent-3.1 {
execsql {
PRAGMA persistent_version="2.0";
}
} {1.0}
db close
sqlite3 db test.db
# Test that a value set before opening the environment
# exists after opening it.
do_test persistent-4.0 {
execsql {
PRAGMA persistent_echo="test3";
}
} {test3}
do_test persistent-4.1 {
execsql {
create table t1(a);
}
} {}
do_test persistent-4.2 {
execsql {
PRAGMA persistent_echo;
}
} {test3}
# Test that updating a value 3 times does not corrupt it
do_test persistent-5.0 {
execsql {
PRAGMA persistent_echo=test4;
}
} {test4}
do_test persistent-5.1 {
execsql {
PRAGMA persistent_echo=test4;
}
} {test4}
do_test persistent-5.2 {
execsql {
PRAGMA persistent_echo=test4;
}
} {test4}
do_test persistent-5.3 {
execsql {
PRAGMA persistent_echo;
}
} {test4}
finish_test
|