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 the PRAGMA command.
15 # $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Do not use a codec for tests in this file, as the database file is
21 # manipulated directly using tcl scripts (using the [hexio_write] command).
27 # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
28 # pragma-2.*: Test synchronous on attached db.
29 # pragma-3.*: Test detection of table/index inconsistency by integrity_check.
30 # pragma-4.*: Test cache_size and default_cache_size on attached db.
31 # pragma-5.*: Test that pragma synchronous may not be used inside of a
33 # pragma-6.*: Test schema-query pragmas.
34 # pragma-7.*: Miscellaneous tests.
35 # pragma-8.*: Test user_version and schema_version pragmas.
36 # pragma-9.*: Test temp_store and temp_store_directory.
37 # pragma-10.*: Test the count_changes pragma in the presence of triggers.
38 # pragma-11.*: Test the collation_list pragma.
39 # pragma-14.*: Test the page_count pragma.
40 # pragma-15.*: Test that the value set using the cache_size pragma is not
41 # reset when the schema is reloaded.
42 # pragma-16.*: Test proxy locking
50 # Delete the preexisting database to avoid the special setup
51 # that the "all.test" script does.
54 file delete test.db test.db-journal
55 file delete test3.db test3.db-journal
56 sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
59 ifcapable pager_pragmas {
60 set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
61 set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
65 PRAGMA default_cache_size;
68 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
71 PRAGMA synchronous=OFF;
72 PRAGMA cache_size=1234;
74 PRAGMA default_cache_size;
77 } [list 1234 $DFLT_CACHE_SZ 0]
83 PRAGMA default_cache_size;
86 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
89 PRAGMA synchronous=OFF;
91 PRAGMA default_cache_size;
94 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
97 PRAGMA cache_size=-4321;
99 PRAGMA default_cache_size;
102 } [list 4321 $DFLT_CACHE_SZ 0]
105 PRAGMA synchronous=ON;
107 PRAGMA default_cache_size;
110 } [list 4321 $DFLT_CACHE_SZ 1]
116 PRAGMA default_cache_size;
119 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
122 PRAGMA default_cache_size=-123;
124 PRAGMA default_cache_size;
128 do_test pragma-1.9.1 {
130 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
133 PRAGMA default_cache_size;
138 do_test pragma-1.9.2 {
142 PRAGMA default_cache_size;
147 do_test pragma-1.10 {
149 PRAGMA synchronous=NORMAL;
151 PRAGMA default_cache_size;
155 do_test pragma-1.11 {
157 PRAGMA synchronous=FULL;
159 PRAGMA default_cache_size;
163 do_test pragma-1.12 {
165 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
168 PRAGMA default_cache_size;
173 # Make sure the pragma handler understands numeric values in addition
174 # to keywords like "off" and "full".
176 do_test pragma-1.13 {
178 PRAGMA synchronous=0;
182 do_test pragma-1.14 {
184 PRAGMA synchronous=2;
188 } ;# ifcapable pager_pragmas
190 # Test turning "flag" pragmas on and off.
193 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG
195 do_test pragma-1.15 {
197 PRAGMA vdbe_listing=YES;
201 do_test pragma-1.16 {
203 PRAGMA vdbe_listing=NO;
209 do_test pragma-1.17 {
211 PRAGMA parser_trace=ON;
212 PRAGMA parser_trace=OFF;
215 do_test pragma-1.18 {
217 PRAGMA bogus = -1234; -- Parsing of negative values
221 # Test modifying the safety_level of an attached database.
222 ifcapable pager_pragmas&&attach {
224 file delete -force test2.db
225 file delete -force test2.db-journal
227 ATTACH 'test2.db' AS aux;
232 pragma aux.synchronous;
237 pragma aux.synchronous = OFF;
238 pragma aux.synchronous;
244 pragma aux.synchronous = ON;
246 pragma aux.synchronous;
249 } ;# ifcapable pager_pragmas
251 # Construct a corrupted index and make sure the integrity_check
254 # These tests won't work if the database is encrypted
258 file delete -force test.db test.db-journal
261 PRAGMA auto_vacuum=OFF;
263 CREATE TABLE t2(a,b,c);
264 CREATE INDEX i2 ON t2(a);
265 INSERT INTO t2 VALUES(11,2,3);
266 INSERT INTO t2 VALUES(22,3,4);
268 SELECT rowid, * from t2;
270 } {1 11 2 3 2 22 3 4}
272 if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
274 db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
275 set pgsz [db eval {PRAGMA page_size}]
276 # overwrite the header on the rootpage of the index in order to
277 # make the index appear to be empty.
279 set offset [expr {$pgsz*($rootpage-1)}]
280 hexio_write test.db $offset 0a00000000040000000000
283 execsql {PRAGMA integrity_check}
284 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
286 execsql {PRAGMA integrity_check=1}
287 } {{rowid 1 missing from index i2}}
290 ATTACH DATABASE 'test.db' AS t2;
291 PRAGMA integrity_check
293 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
296 PRAGMA integrity_check=4
298 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
301 PRAGMA integrity_check=xyz
303 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
306 PRAGMA integrity_check=0
308 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
310 # Add additional corruption by appending unused pages to the end of
311 # the database file testerr.db
315 file delete -force testerr.db testerr.db-journal
316 set out [open testerr.db w]
317 fconfigure $out -translation binary
318 set in [open test.db r]
319 fconfigure $in -translation binary
320 puts -nonewline $out [read $in]
322 puts -nonewline $out [read $in]
325 hexio_write testerr.db 28 00000000
327 execsql {PRAGMA integrity_check}
329 do_test pragma-3.8.1 {
330 execsql {PRAGMA quick_check}
334 ATTACH 'testerr.db' AS t2;
335 PRAGMA integrity_check
337 } {{*** in database t2 ***
340 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
341 do_test pragma-3.10 {
343 PRAGMA integrity_check=1
345 } {{*** in database t2 ***
346 Page 4 is never used}}
347 do_test pragma-3.11 {
349 PRAGMA integrity_check=5
351 } {{*** in database t2 ***
354 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}}
355 do_test pragma-3.12 {
357 PRAGMA integrity_check=4
359 } {{*** in database t2 ***
362 Page 6 is never used} {rowid 1 missing from index i2}}
363 do_test pragma-3.13 {
365 PRAGMA integrity_check=3
367 } {{*** in database t2 ***
370 Page 6 is never used}}
371 do_test pragma-3.14 {
373 PRAGMA integrity_check(2)
375 } {{*** in database t2 ***
377 Page 5 is never used}}
378 do_test pragma-3.15 {
380 ATTACH 'testerr.db' AS t3;
381 PRAGMA integrity_check
383 } {{*** in database t2 ***
386 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
389 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
390 do_test pragma-3.16 {
392 PRAGMA integrity_check(10)
394 } {{*** in database t2 ***
397 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
400 Page 6 is never used} {rowid 1 missing from index i2}}
401 do_test pragma-3.17 {
403 PRAGMA integrity_check=8
405 } {{*** in database t2 ***
408 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
410 Page 5 is never used}}
411 do_test pragma-3.18 {
413 PRAGMA integrity_check=4
415 } {{*** in database t2 ***
418 Page 6 is never used} {rowid 1 missing from index i2}}
420 do_test pragma-3.19 {
422 file delete -force test.db test.db-journal
424 db eval {PRAGMA integrity_check}
429 # Test modifying the cache_size of an attached database.
430 ifcapable pager_pragmas&&attach {
433 ATTACH 'test2.db' AS aux;
434 pragma aux.cache_size;
435 pragma aux.default_cache_size;
437 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
440 pragma aux.cache_size = 50;
441 pragma aux.cache_size;
442 pragma aux.default_cache_size;
444 } [list 50 $DFLT_CACHE_SZ]
447 pragma aux.default_cache_size = 456;
448 pragma aux.cache_size;
449 pragma aux.default_cache_size;
455 pragma default_cache_size;
457 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
461 ATTACH 'test3.db' AS aux;
462 pragma aux.cache_size;
463 pragma aux.default_cache_size;
465 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
469 ATTACH 'test2.db' AS aux;
470 pragma aux.cache_size;
471 pragma aux.default_cache_size;
474 } ;# ifcapable pager_pragmas
476 # Test that modifying the sync-level in the middle of a transaction is
478 ifcapable pager_pragmas {
487 pragma synchronous = OFF;
489 } {1 {Safety level may not be changed inside a transaction}}
496 } ;# ifcapable pager_pragmas
498 # Test schema-query pragmas
500 ifcapable schema_pragmas {
501 ifcapable tempdb&&attach {
504 execsql {SELECT * FROM sqlite_temp_master}
505 foreach {idx name file} [execsql {pragma database_list}] {
506 lappend res $idx $name
509 } {0 main 1 temp 2 aux}
513 CREATE TABLE t2(a,b,c);
514 pragma table_info(t2)
516 } {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
517 do_test pragma-6.2.1 {
522 db nullvalue <<NULL>>
523 do_test pragma-6.2.2 {
526 a TEXT DEFAULT CURRENT_TIMESTAMP,
529 d INTEGER DEFAULT NULL,
532 PRAGMA table_info(t5);
534 } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 0}
536 ifcapable {foreignkey} {
537 do_test pragma-6.3.1 {
539 CREATE TABLE t3(a int references t2(b), b UNIQUE);
540 pragma foreign_key_list(t3);
542 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
543 do_test pragma-6.3.2 {
545 pragma foreign_key_list;
548 do_test pragma-6.3.3 {
550 pragma foreign_key_list(t3_bogus);
553 do_test pragma-6.3.4 {
555 pragma foreign_key_list(t5);
560 pragma index_list(t3);
562 } {0 sqlite_autoindex_t3_1 1}
564 ifcapable {!foreignkey} {
565 execsql {CREATE TABLE t3(a,b UNIQUE)}
567 do_test pragma-6.5.1 {
569 CREATE INDEX t3i1 ON t3(a,b);
570 pragma index_info(t3i1);
573 do_test pragma-6.5.2 {
575 pragma index_info(t3i1_bogus);
580 # Test for ticket #3320. When a temp table of the same name exists, make
581 # sure the schema of the main table can still be queried using
582 # "pragma table_info":
583 do_test pragma-6.6.1 {
585 CREATE TABLE trial(col_main);
586 CREATE TEMP TABLE trial(col_temp);
589 do_test pragma-6.6.2 {
591 PRAGMA table_info(trial);
593 } {0 col_temp {} 0 {} 0}
594 do_test pragma-6.6.3 {
596 PRAGMA temp.table_info(trial);
598 } {0 col_temp {} 0 {} 0}
599 do_test pragma-6.6.4 {
601 PRAGMA main.table_info(trial);
603 } {0 col_main {} 0 {} 0}
608 CREATE TABLE test_table(
609 one INT NOT NULL DEFAULT -1,
611 three VARCHAR(45, 65) DEFAULT 'abcde',
612 four REAL DEFAULT X'abcdef',
613 five DEFAULT CURRENT_TIME
615 PRAGMA table_info(test_table);
619 {1 two text 0 {} 0} \
620 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
621 {3 four REAL 0 X'abcdef' 0} \
622 {4 five {} 0 CURRENT_TIME 0} \
624 } ;# ifcapable schema_pragmas
625 # Miscellaneous tests
627 ifcapable schema_pragmas {
628 do_test pragma-7.1.1 {
629 # Make sure a pragma knows to read the schema if it needs to
633 pragma index_list(t3);
635 } {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
636 do_test pragma-7.1.2 {
638 pragma index_list(t3_bogus);
641 } ;# ifcapable schema_pragmas
643 if {[permutation] == ""} {
648 pragma encoding=bogus;
650 } {1 {unsupported encoding: bogus}}
660 } {main unlocked temp closed}
672 #----------------------------------------------------------------------
673 # Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
674 # user_version" statements.
676 # pragma-8.1: PRAGMA schema_version
677 # pragma-8.2: PRAGMA user_version
680 ifcapable schema_version {
682 # First check that we can set the schema version and then retrieve the
684 do_test pragma-8.1.1 {
686 PRAGMA schema_version = 105;
689 do_test pragma-8.1.2 {
691 PRAGMA schema_version;
693 } {schema_version 105}
694 do_test pragma-8.1.3 {
696 PRAGMA schema_version = 106;
699 do_test pragma-8.1.4 {
701 PRAGMA schema_version;
705 # Check that creating a table modifies the schema-version (this is really
706 # to verify that the value being read is in fact the schema version).
707 do_test pragma-8.1.5 {
709 CREATE TABLE t4(a, b, c);
710 INSERT INTO t4 VALUES(1, 2, 3);
714 do_test pragma-8.1.6 {
716 PRAGMA schema_version;
720 # Now open a second connection to the database. Ensure that changing the
721 # schema-version using the first connection forces the second connection
722 # to reload the schema. This has to be done using the C-API test functions,
723 # because the TCL API accounts for SCHEMA_ERROR and retries the query.
724 do_test pragma-8.1.7 {
725 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
730 do_test pragma-8.1.8 {
732 PRAGMA schema_version = 108;
735 do_test pragma-8.1.9 {
736 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
739 do_test pragma-8.1.10 {
740 sqlite3_finalize $::STMT
743 # Make sure the schema-version can be manipulated in an attached database.
744 file delete -force test2.db
745 file delete -force test2.db-journal
747 do_test pragma-8.1.11 {
749 ATTACH 'test2.db' AS aux;
750 CREATE TABLE aux.t1(a, b, c);
751 PRAGMA aux.schema_version = 205;
754 do_test pragma-8.1.12 {
756 PRAGMA aux.schema_version;
760 do_test pragma-8.1.13 {
762 PRAGMA schema_version;
766 # And check that modifying the schema-version in an attached database
767 # forces the second connection to reload the schema.
769 do_test pragma-8.1.14 {
770 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
772 ATTACH 'test2.db' AS aux;
773 SELECT * FROM aux.t1;
776 do_test pragma-8.1.15 {
778 PRAGMA aux.schema_version = 206;
781 do_test pragma-8.1.16 {
782 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
785 do_test pragma-8.1.17 {
786 sqlite3_finalize $::STMT
788 do_test pragma-8.1.18 {
793 # Now test that the user-version can be read and written (and that we aren't
794 # accidentally manipulating the schema-version instead).
795 do_test pragma-8.2.1 {
800 do_test pragma-8.2.2 {
802 PRAGMA user_version = 2;
805 do_test pragma-8.2.3.1 {
810 do_test pragma-8.2.3.2 {
817 do_test pragma-8.2.4.1 {
819 PRAGMA schema_version;
823 do_test pragma-8.2.4.2 {
829 do_test pragma-8.2.4.3 {
831 PRAGMA schema_version;
837 db eval {ATTACH 'test2.db' AS aux}
839 # Check that the user-version in the auxilary database can be manipulated (
840 # and that we aren't accidentally manipulating the same in the main db).
841 do_test pragma-8.2.5 {
843 PRAGMA aux.user_version;
846 do_test pragma-8.2.6 {
848 PRAGMA aux.user_version = 3;
851 do_test pragma-8.2.7 {
853 PRAGMA aux.user_version;
856 do_test pragma-8.2.8 {
858 PRAGMA main.user_version;
862 # Now check that a ROLLBACK resets the user-version if it has been modified
863 # within a transaction.
864 do_test pragma-8.2.9 {
867 PRAGMA aux.user_version = 10;
868 PRAGMA user_version = 11;
871 do_test pragma-8.2.10 {
873 PRAGMA aux.user_version;
876 do_test pragma-8.2.11 {
878 PRAGMA main.user_version;
881 do_test pragma-8.2.12 {
884 PRAGMA aux.user_version;
887 do_test pragma-8.2.13 {
889 PRAGMA main.user_version;
894 # Try a negative value for the user-version
895 do_test pragma-8.2.14 {
897 PRAGMA user_version = -450;
900 do_test pragma-8.2.15 {
905 } ; # ifcapable schema_version
907 # Check to see if TEMP_STORE is memory or disk. Return strings
908 # "memory" or "disk" as appropriate.
910 proc check_temp_store {} {
911 db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}
912 db eval {PRAGMA database_list} {
914 set bt [btree_from_db db 1]
915 if {[btree_ismemdb $bt]} {
925 # Test temp_store and temp_store_directory pragmas
927 ifcapable pager_pragmas {
935 if {$TEMP_STORE<=1} {
936 do_test pragma-9.1.1 {
940 do_test pragma-9.1.1 {
949 PRAGMA temp_store=file;
953 if {$TEMP_STORE==3} {
954 # When TEMP_STORE is 3, always use memory regardless of pragma settings.
955 do_test pragma-9.2.1 {
959 do_test pragma-9.2.1 {
968 PRAGMA temp_store=memory;
972 if {$TEMP_STORE==0} {
973 # When TEMP_STORE is 0, always use the disk regardless of pragma settings.
974 do_test pragma-9.3.1 {
978 do_test pragma-9.3.1 {
985 PRAGMA temp_store_directory;
990 set pwd [string map {' ''} [file nativename [pwd]]]
992 PRAGMA temp_store_directory='$pwd';
997 PRAGMA temp_store_directory;
999 } [list [file nativename [pwd]]]
1000 do_test pragma-9.7 {
1002 PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
1004 } {1 {not a writable directory}}
1005 do_test pragma-9.8 {
1007 PRAGMA temp_store_directory='';
1010 if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
1012 do_test pragma-9.9 {
1014 PRAGMA temp_store_directory;
1015 PRAGMA temp_store=FILE;
1016 CREATE TEMP TABLE temp_store_directory_test(a integer);
1017 INSERT INTO temp_store_directory_test values (2);
1018 SELECT * FROM temp_store_directory_test;
1021 do_test pragma-9.10 {
1023 PRAGMA temp_store_directory='$pwd';
1024 SELECT * FROM temp_store_directory_test;
1026 } {1 {no such table: temp_store_directory_test}}
1030 do_test pragma-9.11 {
1032 PRAGMA temp_store = 0;
1036 do_test pragma-9.12 {
1038 PRAGMA temp_store = 1;
1042 do_test pragma-9.13 {
1044 PRAGMA temp_store = 2;
1048 do_test pragma-9.14 {
1050 PRAGMA temp_store = 3;
1054 do_test pragma-9.15 {
1057 CREATE TEMP TABLE temp_table(t);
1058 INSERT INTO temp_table VALUES('valuable data');
1059 PRAGMA temp_store = 1;
1061 } {1 {temporary storage cannot be changed from within a transaction}}
1062 do_test pragma-9.16 {
1064 SELECT * FROM temp_table;
1069 do_test pragma-9.17 {
1071 INSERT INTO temp_table VALUES('valuable data II');
1072 SELECT * FROM temp_table;
1074 } {{valuable data} {valuable data II}}
1076 do_test pragma-9.18 {
1078 db eval {SELECT t FROM temp_table} {
1079 execsql {pragma temp_store = 1}
1083 } {1 {temporary storage cannot be changed from within a transaction}}
1085 } ;# ifcapable pager_pragmas
1089 do_test pragma-10.0 {
1094 PRAGMA count_changes = 1;
1096 CREATE TABLE t1(a PRIMARY KEY);
1097 CREATE TABLE t1_mirror(a);
1098 CREATE TABLE t1_mirror2(a);
1099 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
1100 INSERT INTO t1_mirror VALUES(new.a);
1102 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
1103 INSERT INTO t1_mirror2 VALUES(new.a);
1105 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
1106 UPDATE t1_mirror SET a = new.a WHERE a = old.a;
1108 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
1109 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
1111 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
1112 DELETE FROM t1_mirror WHERE a = old.a;
1114 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
1115 DELETE FROM t1_mirror2 WHERE a = old.a;
1120 do_test pragma-10.1 {
1122 INSERT INTO t1 VALUES(randstr(10,10));
1125 do_test pragma-10.2 {
1127 UPDATE t1 SET a = randstr(10,10);
1130 do_test pragma-10.3 {
1136 } ;# ifcapable trigger
1138 ifcapable schema_pragmas {
1139 do_test pragma-11.1 {
1141 pragma collation_list;
1143 } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}
1144 do_test pragma-11.2 {
1145 db collate New_Collation blah...
1147 pragma collation_list;
1149 } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}
1152 ifcapable schema_pragmas&&tempdb {
1153 do_test pragma-12.1 {
1156 PRAGMA temp.table_info('abc');
1161 do_test pragma-12.2 {
1164 PRAGMA temp.default_cache_size = 200;
1165 PRAGMA temp.default_cache_size;
1170 do_test pragma-12.3 {
1173 PRAGMA temp.cache_size = 400;
1174 PRAGMA temp.cache_size;
1182 do_test pragma-13.1 {
1184 DROP TABLE IF EXISTS t4;
1185 PRAGMA vdbe_trace=on;
1186 PRAGMA vdbe_listing=on;
1187 PRAGMA sql_trace=on;
1188 CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
1189 INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
1190 INSERT INTO t4(b) VALUES(randstr(30,30));
1191 INSERT INTO t4(b) VALUES(1.23456);
1192 INSERT INTO t4(b) VALUES(NULL);
1193 INSERT INTO t4(b) VALUES(0);
1194 INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
1198 PRAGMA vdbe_trace=off;
1199 PRAGMA vdbe_listing=off;
1200 PRAGMA sql_trace=off;
1204 } ;# ifcapable bloblit
1206 ifcapable pager_pragmas {
1208 file delete -force test.db
1211 do_test pragma-14.1 {
1212 execsql { pragma auto_vacuum = 0 }
1213 execsql { pragma page_count }
1216 do_test pragma-14.2 {
1218 CREATE TABLE abc(a, b, c);
1223 do_test pragma-14.3 {
1226 CREATE TABLE def(a, b, c);
1231 do_test pragma-14.4 {
1232 set page_size [db one {pragma page_size}]
1233 expr [file size test.db] / $page_size
1236 do_test pragma-14.5 {
1243 do_test pragma-14.6 {
1244 file delete -force test2.db
1245 sqlite3 db2 test2.db
1247 PRAGMA auto_vacuum = 0;
1248 CREATE TABLE t1(a, b, c);
1249 CREATE TABLE t2(a, b, c);
1250 CREATE TABLE t3(a, b, c);
1251 CREATE TABLE t4(a, b, c);
1255 ATTACH 'test2.db' AS aux;
1256 PRAGMA aux.page_count;
1261 # Test that the value set using the cache_size pragma is not reset when the
1262 # schema is reloaded.
1264 ifcapable pager_pragmas {
1267 do_test pragma-15.1 {
1269 PRAGMA cache_size=59;
1273 do_test pragma-15.2 {
1276 CREATE TABLE newtable(a, b, c);
1280 do_test pragma-15.3 {
1281 # Evaluating this statement will cause the schema to be reloaded (because
1282 # the schema was changed by another connection in pragma-15.2). At one
1283 # point there was a bug that reset the cache_size to its default value
1284 # when this happened.
1285 execsql { SELECT * FROM sqlite_master }
1286 execsql { PRAGMA cache_size }
1290 # Reset the sqlite3_temp_directory variable for the next run of tests:
1291 sqlite3 dbX :memory:
1292 dbX eval {PRAGMA temp_store_directory = ""}
1295 ifcapable lock_proxy_pragmas&&prefer_proxy_locking {
1296 set sqlite_hostid_num 1
1299 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
1300 set using_proxy $value
1303 # Test the lock_proxy_file pragmas.
1306 set env(SQLITE_FORCE_PROXY_LOCKING) "0"
1309 do_test pragma-16.1 {
1311 PRAGMA lock_proxy_file="mylittleproxy";
1312 select * from sqlite_master;
1315 PRAGMA lock_proxy_file;
1319 do_test pragma-16.2 {
1322 PRAGMA lock_proxy_file="mylittleproxy";
1327 do_test pragma-16.2.1 {
1330 PRAGMA lock_proxy_file=":auto:";
1331 select * from sqlite_master;
1334 PRAGMA lock_proxy_file;
1339 do_test pragma-16.3 {
1342 PRAGMA lock_proxy_file="myotherproxy";
1345 select * from sqlite_master;
1347 } {1 {database is locked}}
1349 do_test pragma-16.4 {
1354 PRAGMA lock_proxy_file="myoriginalproxy";
1355 PRAGMA lock_proxy_file="myotherproxy";
1356 PRAGMA lock_proxy_file;
1361 set env(SQLITE_FORCE_PROXY_LOCKING) "1"
1362 do_test pragma-16.5 {
1365 PRAGMA lock_proxy_file=":auto:";
1366 PRAGMA lock_proxy_file;
1370 do_test pragma-16.6 {
1372 sqlite3 db2 test2.db
1373 set lockpath [execsql {
1374 PRAGMA lock_proxy_file=":auto:";
1375 PRAGMA lock_proxy_file;
1377 string match "*test2.db:auto:" $lockpath
1380 set sqlite_hostid_num 2
1381 do_test pragma-16.7 {
1385 PRAGMA lock_proxy_file=":auto:";
1386 select * from sqlite_master;
1389 } {1 {database is locked}}
1392 do_test pragma-16.8 {
1395 execsql { select * from sqlite_master }
1397 } {1 {database is locked}}
1400 do_test pragma-16.8.1 {
1402 PRAGMA lock_proxy_file="yetanotherproxy";
1403 PRAGMA lock_proxy_file;
1406 do_test pragma-16.8.2 {
1408 create table mine(x);
1413 do_test pragma-16.9 {
1414 sqlite3 db proxytest.db
1415 set lockpath2 [execsql {
1416 PRAGMA lock_proxy_file=":auto:";
1417 PRAGMA lock_proxy_file;
1419 string match "*proxytest.db:auto:" $lockpath2
1422 set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
1423 set sqlite_hostid_num 0
1426 # Parsing of auto_vacuum settings.
1428 foreach {autovac_setting val} {
1444 do_test pragma-17.1.$autovac_setting {
1448 PRAGMA auto_vacuum=$::autovac_setting;
1454 # Parsing of temp_store settings.
1456 foreach {temp_setting val} {
1469 do_test pragma-18.1.$temp_setting {
1473 PRAGMA temp_store=$::temp_setting;
1474 PRAGMA temp_store=$::temp_setting;