mirror of
https://github.com/berkeleydb/libdb.git
synced 2024-11-16 09:06:25 +00:00
210 lines
3.9 KiB
Text
210 lines
3.9 KiB
Text
#
|
|
# 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
|