ef4ac8f9df
SQLite version 2 and SQLite version 3 can be used by Tcl at the same time. (CVS 1626) FossilOrigin-Name: d705d051bed2b92b6c3bbcc75fe5b056633b9c31
342 lines
6.8 KiB
Plaintext
342 lines
6.8 KiB
Plaintext
# 2002 March 6
|
|
#
|
|
# The author disclaims copyright to this source code. In place of
|
|
# a legal notice, here is a blessing:
|
|
#
|
|
# 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 SQLite library.
|
|
#
|
|
# This file implements tests for the PRAGMA command.
|
|
#
|
|
# $Id: pragma.test,v 1.13 2004/06/19 00:16:31 drh Exp $
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
# Delete the preexisting database to avoid the special setup
|
|
# that the "all.test" script does.
|
|
#
|
|
db close
|
|
file delete test.db
|
|
set DB [sqlite3 db test.db]
|
|
|
|
do_test pragma-1.1 {
|
|
execsql {
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {2000 2000 1 1}
|
|
do_test pragma-1.2 {
|
|
execsql {
|
|
PRAGMA cache_size=1234;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {1234 2000 1 1}
|
|
do_test pragma-1.3 {
|
|
db close
|
|
sqlite3 db test.db
|
|
execsql {
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {2000 2000 1 1}
|
|
do_test pragma-1.4 {
|
|
execsql {
|
|
PRAGMA synchronous=OFF;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {2000 2000 0 1}
|
|
do_test pragma-1.5 {
|
|
execsql {
|
|
PRAGMA cache_size=4321;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {4321 2000 0 1}
|
|
do_test pragma-1.6 {
|
|
execsql {
|
|
PRAGMA synchronous=ON;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {4321 2000 1 1}
|
|
do_test pragma-1.7 {
|
|
db close
|
|
sqlite3 db test.db
|
|
execsql {
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {2000 2000 1 1}
|
|
do_test pragma-1.8 {
|
|
execsql {
|
|
PRAGMA default_synchronous=OFF;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {2000 2000 0 0}
|
|
do_test pragma-1.9 {
|
|
execsql {
|
|
PRAGMA default_cache_size=123;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {123 123 0 0}
|
|
do_test pragma-1.10 {
|
|
db close
|
|
set ::DB [sqlite3 db test.db]
|
|
execsql {
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {123 123 0 0}
|
|
do_test pragma-1.11 {
|
|
execsql {
|
|
PRAGMA synchronous=NORMAL;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {123 123 1 0}
|
|
do_test pragma-1.12 {
|
|
execsql {
|
|
PRAGMA synchronous=FULL;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {123 123 2 0}
|
|
do_test pragma-1.13 {
|
|
db close
|
|
set ::DB [sqlite3 db test.db]
|
|
execsql {
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {123 123 0 0}
|
|
do_test pragma-1.14 {
|
|
execsql {
|
|
PRAGMA default_synchronous=FULL;
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {123 123 2 2}
|
|
do_test pragma-1.15 {
|
|
db close
|
|
set ::DB [sqlite3 db test.db]
|
|
execsql {
|
|
PRAGMA cache_size;
|
|
PRAGMA default_cache_size;
|
|
PRAGMA synchronous;
|
|
PRAGMA default_synchronous;
|
|
}
|
|
} {123 123 2 2}
|
|
|
|
# Construct a corrupted index and make sure the integrity_check
|
|
# pragma finds it.
|
|
#
|
|
if {![sqlite3 -has-codec]} {
|
|
do_test pragma-3.1 {
|
|
execsql {
|
|
BEGIN;
|
|
CREATE TABLE t2(a,b,c);
|
|
CREATE INDEX i2 ON t2(a);
|
|
INSERT INTO t2 VALUES(11,2,3);
|
|
INSERT INTO t2 VALUES(22,3,4);
|
|
COMMIT;
|
|
SELECT rowid, * from t2;
|
|
}
|
|
} {1 11 2 3 2 22 3 4}
|
|
do_test pragma-3.2 {
|
|
set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}]
|
|
set db [btree_open test.db 100 0]
|
|
btree_begin_transaction $db
|
|
set c [btree_cursor $db $rootpage 1]
|
|
btree_first $c
|
|
btree_delete $c
|
|
btree_commit $db
|
|
btree_close $db
|
|
execsql {PRAGMA integrity_check}
|
|
} {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
|
}; # endif has-codec
|
|
|
|
# Test the temp_store and default_temp_store pragmas
|
|
#
|
|
do_test pragma-4.2 {
|
|
execsql {
|
|
PRAGMA temp_store='default';
|
|
PRAGMA temp_store;
|
|
}
|
|
} {0}
|
|
do_test pragma-4.3 {
|
|
execsql {
|
|
PRAGMA temp_store='file';
|
|
PRAGMA temp_store;
|
|
}
|
|
} {1}
|
|
do_test pragma-4.4 {
|
|
execsql {
|
|
PRAGMA temp_store='memory';
|
|
PRAGMA temp_store;
|
|
}
|
|
} {2}
|
|
do_test pragma-4.5 {
|
|
execsql {
|
|
PRAGMA default_temp_store='default';
|
|
PRAGMA default_temp_store;
|
|
}
|
|
} {0}
|
|
do_test pragma-4.6 {
|
|
execsql {
|
|
PRAGMA temp_store;
|
|
}
|
|
} {2}
|
|
do_test pragma-4.7 {
|
|
db close
|
|
sqlite3 db test.db
|
|
execsql {
|
|
PRAGMA temp_store;
|
|
}
|
|
} {0}
|
|
do_test pragma-4.8 {
|
|
execsql {
|
|
PRAGMA default_temp_store;
|
|
}
|
|
} {0}
|
|
do_test pragma-4.9 {
|
|
execsql {
|
|
PRAGMA default_temp_store='file';
|
|
PRAGMA default_temp_store;
|
|
}
|
|
} {1}
|
|
do_test pragma-4.10 {
|
|
execsql {
|
|
PRAGMA temp_store;
|
|
}
|
|
} {0}
|
|
do_test pragma-4.11 {
|
|
db close
|
|
sqlite3 db test.db
|
|
execsql {
|
|
PRAGMA temp_store;
|
|
}
|
|
} {1}
|
|
do_test pragma-4.12 {
|
|
execsql {
|
|
PRAGMA default_temp_store;
|
|
}
|
|
} {1}
|
|
do_test pragma-4.13 {
|
|
execsql {
|
|
PRAGMA default_temp_store='memory';
|
|
PRAGMA default_temp_store;
|
|
}
|
|
} {2}
|
|
do_test pragma-4.14 {
|
|
execsql {
|
|
PRAGMA temp_store;
|
|
}
|
|
} {1}
|
|
do_test pragma-4.15 {
|
|
db close
|
|
sqlite3 db test.db
|
|
execsql {
|
|
PRAGMA temp_store;
|
|
}
|
|
} {2}
|
|
do_test pragma-4.16 {
|
|
execsql {
|
|
PRAGMA default_temp_store;
|
|
}
|
|
} {2}
|
|
do_test pragma-4.17 {
|
|
execsql {
|
|
PRAGMA temp_store='file';
|
|
PRAGMA temp_store
|
|
}
|
|
} {1}
|
|
do_test pragma-4.18 {
|
|
execsql {
|
|
PRAGMA default_temp_store
|
|
}
|
|
} {2}
|
|
do_test pragma-4.19 {
|
|
db close
|
|
sqlite3 db test.db
|
|
execsql {
|
|
PRAGMA temp_store
|
|
}
|
|
} {2}
|
|
|
|
# Changing the TEMP_STORE deletes any existing temporary tables
|
|
#
|
|
do_test pragma-4.20 {
|
|
execsql {SELECT name FROM sqlite_temp_master}
|
|
} {}
|
|
do_test pragma-4.21 {
|
|
execsql {
|
|
CREATE TEMP TABLE test1(a,b,c);
|
|
SELECT name FROM sqlite_temp_master;
|
|
}
|
|
} {test1}
|
|
do_test pragma-4.22 {
|
|
execsql {
|
|
PRAGMA temp_store='file';
|
|
SELECT name FROM sqlite_temp_master;
|
|
}
|
|
} {}
|
|
do_test pragma-4.23 {
|
|
execsql {
|
|
CREATE TEMP TABLE test1(a,b,c);
|
|
SELECT name FROM sqlite_temp_master;
|
|
}
|
|
} {test1}
|
|
do_test pragma-4.24 {
|
|
execsql {
|
|
PRAGMA temp_store='memory';
|
|
SELECT name FROM sqlite_temp_master;
|
|
}
|
|
} {}
|
|
do_test pragma-4.25 {
|
|
catchsql {
|
|
BEGIN;
|
|
PRAGMA temp_store='default';
|
|
COMMIT;
|
|
}
|
|
} {1 {temporary storage cannot be changed from within a transaction}}
|
|
catchsql {COMMIT}
|
|
|
|
finish_test
|