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
21 # Do not use a codec for tests in this file, as the database file is
22 # manipulated directly using tcl scripts (using the [hexio_write] command).
28 # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
29 # pragma-2.*: Test synchronous on attached db.
30 # pragma-3.*: Test detection of table/index inconsistency by integrity_check.
31 # pragma-4.*: Test cache_size and default_cache_size on attached db.
32 # pragma-5.*: Test that pragma synchronous may not be used inside of a
34 # pragma-6.*: Test schema-query pragmas.
35 # pragma-7.*: Miscellaneous tests.
36 # pragma-8.*: Test user_version and schema_version pragmas.
37 # pragma-9.*: Test temp_store and temp_store_directory.
38 # pragma-10.*: Test the count_changes pragma in the presence of triggers.
39 # pragma-11.*: Test the collation_list pragma.
40 # pragma-14.*: Test the page_count pragma.
41 # pragma-15.*: Test that the value set using the cache_size pragma is not
42 # reset when the schema is reloaded.
43 # pragma-16.*: Test proxy locking
44 # pragma-20.*: Test data_store_directory.
45 # pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db"
46 # directive - if it is present.
54 # Delete the preexisting database to avoid the special setup
55 # that the "all.test" script does.
58 delete_file test.db test.db-journal
59 delete_file test3.db test3.db-journal
60 sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
63 ifcapable pager_pragmas {
64 set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
65 set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
69 PRAGMA default_cache_size;
72 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
75 PRAGMA synchronous=OFF;
76 PRAGMA cache_size=1234;
78 PRAGMA default_cache_size;
81 } [list 1234 $DFLT_CACHE_SZ 0]
87 PRAGMA default_cache_size;
90 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
93 PRAGMA synchronous=OFF;
95 PRAGMA default_cache_size;
98 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
101 PRAGMA cache_size=-4321;
103 PRAGMA default_cache_size;
106 } [list -4321 $DFLT_CACHE_SZ 0]
109 PRAGMA synchronous=ON;
111 PRAGMA default_cache_size;
114 } [list -4321 $DFLT_CACHE_SZ 1]
120 PRAGMA default_cache_size;
123 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
126 PRAGMA default_cache_size=-123;
128 PRAGMA default_cache_size;
132 do_test pragma-1.9.1 {
134 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
137 PRAGMA default_cache_size;
142 do_test pragma-1.9.2 {
146 PRAGMA default_cache_size;
151 do_test pragma-1.10 {
153 PRAGMA synchronous=NORMAL;
155 PRAGMA default_cache_size;
159 do_test pragma-1.11 {
161 PRAGMA synchronous=FULL;
163 PRAGMA default_cache_size;
167 do_test pragma-1.12 {
169 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
172 PRAGMA default_cache_size;
177 # Make sure the pragma handler understands numeric values in addition
178 # to keywords like "off" and "full".
180 do_test pragma-1.13 {
182 PRAGMA synchronous=0;
186 do_test pragma-1.14 {
188 PRAGMA synchronous=2;
192 } ;# ifcapable pager_pragmas
194 # Test turning "flag" pragmas on and off.
197 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG
199 do_test pragma-1.15 {
201 PRAGMA vdbe_listing=YES;
205 do_test pragma-1.16 {
207 PRAGMA vdbe_listing=NO;
213 do_test pragma-1.17 {
215 PRAGMA parser_trace=ON;
216 PRAGMA parser_trace=OFF;
219 do_test pragma-1.18 {
221 PRAGMA bogus = -1234; -- Parsing of negative values
225 # Test modifying the safety_level of an attached database.
226 ifcapable pager_pragmas&&attach {
229 forcedelete test2.db-journal
231 ATTACH 'test2.db' AS aux;
236 pragma aux.synchronous;
241 pragma aux.synchronous = OFF;
242 pragma aux.synchronous;
248 pragma aux.synchronous = ON;
250 pragma aux.synchronous;
253 } ;# ifcapable pager_pragmas
255 # Construct a corrupted index and make sure the integrity_check
258 # These tests won't work if the database is encrypted
262 forcedelete test.db test.db-journal
265 PRAGMA auto_vacuum=OFF;
267 CREATE TABLE t2(a,b,c);
268 CREATE INDEX i2 ON t2(a);
269 INSERT INTO t2 VALUES(11,2,3);
270 INSERT INTO t2 VALUES(22,3,4);
272 SELECT rowid, * from t2;
274 } {1 11 2 3 2 22 3 4}
276 if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
278 db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
279 set pgsz [db eval {PRAGMA page_size}]
280 # overwrite the header on the rootpage of the index in order to
281 # make the index appear to be empty.
283 set offset [expr {$pgsz*($rootpage-1)}]
284 hexio_write test.db $offset 0a00000000040000000000
287 execsql {PRAGMA integrity_check}
288 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
290 execsql {PRAGMA integrity_check=1}
291 } {{row 1 missing from index i2}}
294 ATTACH DATABASE 'test.db' AS t2;
295 PRAGMA integrity_check
297 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
300 PRAGMA integrity_check=4
302 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}}
305 PRAGMA integrity_check=xyz
307 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
310 PRAGMA integrity_check=0
312 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
314 # Add additional corruption by appending unused pages to the end of
315 # the database file testerr.db
319 forcedelete testerr.db testerr.db-journal
320 set out [open testerr.db w]
321 fconfigure $out -translation binary
322 set in [open test.db r]
323 fconfigure $in -translation binary
324 puts -nonewline $out [read $in]
326 puts -nonewline $out [read $in]
329 hexio_write testerr.db 28 00000000
331 execsql {PRAGMA integrity_check}
333 do_test pragma-3.8.1 {
334 execsql {PRAGMA quick_check}
336 do_test pragma-3.8.2 {
337 execsql {PRAGMA QUICK_CHECK}
341 ATTACH 'testerr.db' AS t2;
342 PRAGMA integrity_check
344 } {{*** in database t2 ***
347 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
348 do_test pragma-3.10 {
350 PRAGMA integrity_check=1
352 } {{*** in database t2 ***
353 Page 4 is never used}}
354 do_test pragma-3.11 {
356 PRAGMA integrity_check=5
358 } {{*** in database t2 ***
361 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2}}
362 do_test pragma-3.12 {
364 PRAGMA integrity_check=4
366 } {{*** in database t2 ***
369 Page 6 is never used} {row 1 missing from index i2}}
370 do_test pragma-3.13 {
372 PRAGMA integrity_check=3
374 } {{*** in database t2 ***
377 Page 6 is never used}}
378 do_test pragma-3.14 {
380 PRAGMA integrity_check(2)
382 } {{*** in database t2 ***
384 Page 5 is never used}}
385 do_test pragma-3.15 {
387 ATTACH 'testerr.db' AS t3;
388 PRAGMA integrity_check
390 } {{*** in database t2 ***
393 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
396 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
397 do_test pragma-3.16 {
399 PRAGMA integrity_check(10)
401 } {{*** in database t2 ***
404 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
407 Page 6 is never used} {row 1 missing from index i2}}
408 do_test pragma-3.17 {
410 PRAGMA integrity_check=8
412 } {{*** in database t2 ***
415 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
417 Page 5 is never used}}
418 do_test pragma-3.18 {
420 PRAGMA integrity_check=4
422 } {{*** in database t2 ***
425 Page 6 is never used} {row 1 missing from index i2}}
427 do_test pragma-3.19 {
429 forcedelete test.db test.db-journal
431 db eval {PRAGMA integrity_check}
435 # Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL
436 # constraint violations.
438 do_execsql_test pragma-3.20 {
439 CREATE TABLE t1(a,b);
440 CREATE INDEX t1a ON t1(a);
441 INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6);
442 PRAGMA writable_schema=ON;
443 UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)'
445 UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)'
447 PRAGMA writable_schema=OFF;
448 ALTER TABLE t1 RENAME TO t1x;
449 PRAGMA integrity_check;
450 } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a} {NULL value in t1x.a}}
451 do_execsql_test pragma-3.21 {
452 PRAGMA integrity_check(3);
453 } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a}}
454 do_execsql_test pragma-3.22 {
455 PRAGMA integrity_check(2);
456 } {{non-unique entry in index t1a} {NULL value in t1x.a}}
457 do_execsql_test pragma-3.21 {
458 PRAGMA integrity_check(1);
459 } {{non-unique entry in index t1a}}
461 # Test modifying the cache_size of an attached database.
462 ifcapable pager_pragmas&&attach {
465 ATTACH 'test2.db' AS aux;
466 pragma aux.cache_size;
467 pragma aux.default_cache_size;
469 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
472 pragma aux.cache_size = 50;
473 pragma aux.cache_size;
474 pragma aux.default_cache_size;
476 } [list 50 $DFLT_CACHE_SZ]
479 pragma aux.default_cache_size = 456;
480 pragma aux.cache_size;
481 pragma aux.default_cache_size;
487 pragma default_cache_size;
489 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
493 ATTACH 'test3.db' AS aux;
494 pragma aux.cache_size;
495 pragma aux.default_cache_size;
497 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
501 ATTACH 'test2.db' AS aux;
502 pragma aux.cache_size;
503 pragma aux.default_cache_size;
506 } ;# ifcapable pager_pragmas
508 # Test that modifying the sync-level in the middle of a transaction is
510 ifcapable pager_pragmas {
519 pragma synchronous = OFF;
521 } {1 {Safety level may not be changed inside a transaction}}
528 } ;# ifcapable pager_pragmas
530 # Test schema-query pragmas
532 ifcapable schema_pragmas {
533 ifcapable tempdb&&attach {
536 execsql {SELECT * FROM sqlite_temp_master}
537 foreach {idx name file} [execsql {pragma database_list}] {
538 lappend res $idx $name
541 } {0 main 1 temp 2 aux}
545 CREATE TABLE t2(a,b,c);
546 pragma table_info(t2)
548 } {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
549 do_test pragma-6.2.1 {
554 db nullvalue <<NULL>>
555 do_test pragma-6.2.2 {
558 a TEXT DEFAULT CURRENT_TIMESTAMP,
561 d INTEGER DEFAULT NULL,
566 PRAGMA table_info(t5);
568 } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 1}
570 do_test pragma-6.2.3 {
572 CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
573 pragma table_info(t2_3)
575 } {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
576 ifcapable {foreignkey} {
577 do_test pragma-6.3.1 {
579 CREATE TABLE t3(a int references t2(b), b UNIQUE);
580 pragma foreign_key_list(t3);
582 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
583 do_test pragma-6.3.2 {
585 pragma foreign_key_list;
588 do_test pragma-6.3.3 {
590 pragma foreign_key_list(t3_bogus);
593 do_test pragma-6.3.4 {
595 pragma foreign_key_list(t5);
600 pragma index_list(t3);
602 } {0 sqlite_autoindex_t3_1 1}
604 ifcapable {!foreignkey} {
605 execsql {CREATE TABLE t3(a,b UNIQUE)}
607 do_test pragma-6.5.1 {
609 CREATE INDEX t3i1 ON t3(a,b);
610 pragma index_info(t3i1);
613 do_test pragma-6.5.2 {
615 pragma index_info(t3i1_bogus);
620 # Test for ticket #3320. When a temp table of the same name exists, make
621 # sure the schema of the main table can still be queried using
622 # "pragma table_info":
623 do_test pragma-6.6.1 {
625 CREATE TABLE trial(col_main);
626 CREATE TEMP TABLE trial(col_temp);
629 do_test pragma-6.6.2 {
631 PRAGMA table_info(trial);
633 } {0 col_temp {} 0 {} 0}
634 do_test pragma-6.6.3 {
636 PRAGMA temp.table_info(trial);
638 } {0 col_temp {} 0 {} 0}
639 do_test pragma-6.6.4 {
641 PRAGMA main.table_info(trial);
643 } {0 col_main {} 0 {} 0}
648 CREATE TABLE test_table(
649 one INT NOT NULL DEFAULT -1,
651 three VARCHAR(45, 65) DEFAULT 'abcde',
652 four REAL DEFAULT X'abcdef',
653 five DEFAULT CURRENT_TIME
655 PRAGMA table_info(test_table);
659 {1 two text 0 {} 0} \
660 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
661 {3 four REAL 0 X'abcdef' 0} \
662 {4 five {} 0 CURRENT_TIME 0} \
664 } ;# ifcapable schema_pragmas
665 # Miscellaneous tests
667 ifcapable schema_pragmas {
668 do_test pragma-7.1.1 {
669 # Make sure a pragma knows to read the schema if it needs to
673 pragma index_list(t3);
675 } {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
676 do_test pragma-7.1.2 {
678 pragma index_list(t3_bogus);
681 } ;# ifcapable schema_pragmas
683 if {[permutation] == ""} {
688 pragma encoding=bogus;
690 } {1 {unsupported encoding: bogus}}
700 } {main unlocked temp closed}
712 #----------------------------------------------------------------------
713 # Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
714 # user_version" statements.
716 # pragma-8.1: PRAGMA schema_version
717 # pragma-8.2: PRAGMA user_version
720 ifcapable schema_version {
722 # First check that we can set the schema version and then retrieve the
724 do_test pragma-8.1.1 {
726 PRAGMA schema_version = 105;
729 do_test pragma-8.1.2 {
731 PRAGMA schema_version;
733 } {schema_version 105}
734 do_test pragma-8.1.3 {
736 PRAGMA schema_version = 106;
739 do_test pragma-8.1.4 {
741 PRAGMA schema_version;
745 # Check that creating a table modifies the schema-version (this is really
746 # to verify that the value being read is in fact the schema version).
747 do_test pragma-8.1.5 {
749 CREATE TABLE t4(a, b, c);
750 INSERT INTO t4 VALUES(1, 2, 3);
754 do_test pragma-8.1.6 {
756 PRAGMA schema_version;
760 # Now open a second connection to the database. Ensure that changing the
761 # schema-version using the first connection forces the second connection
762 # to reload the schema. This has to be done using the C-API test functions,
763 # because the TCL API accounts for SCHEMA_ERROR and retries the query.
764 do_test pragma-8.1.7 {
765 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
770 do_test pragma-8.1.8 {
772 PRAGMA schema_version = 108;
775 do_test pragma-8.1.9 {
776 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
779 do_test pragma-8.1.10 {
780 sqlite3_finalize $::STMT
783 # Make sure the schema-version can be manipulated in an attached database.
785 forcedelete test2.db-journal
787 do_test pragma-8.1.11 {
789 ATTACH 'test2.db' AS aux;
790 CREATE TABLE aux.t1(a, b, c);
791 PRAGMA aux.schema_version = 205;
794 do_test pragma-8.1.12 {
796 PRAGMA aux.schema_version;
800 do_test pragma-8.1.13 {
802 PRAGMA schema_version;
806 # And check that modifying the schema-version in an attached database
807 # forces the second connection to reload the schema.
809 do_test pragma-8.1.14 {
810 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
812 ATTACH 'test2.db' AS aux;
813 SELECT * FROM aux.t1;
816 do_test pragma-8.1.15 {
818 PRAGMA aux.schema_version = 206;
821 do_test pragma-8.1.16 {
822 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
825 do_test pragma-8.1.17 {
826 sqlite3_finalize $::STMT
828 do_test pragma-8.1.18 {
833 # Now test that the user-version can be read and written (and that we aren't
834 # accidentally manipulating the schema-version instead).
835 do_test pragma-8.2.1 {
840 do_test pragma-8.2.2 {
842 PRAGMA user_version = 2;
845 do_test pragma-8.2.3.1 {
850 do_test pragma-8.2.3.2 {
857 do_test pragma-8.2.4.1 {
859 PRAGMA schema_version;
863 do_test pragma-8.2.4.2 {
869 do_test pragma-8.2.4.3 {
871 PRAGMA schema_version;
877 db eval {ATTACH 'test2.db' AS aux}
879 # Check that the user-version in the auxilary database can be manipulated (
880 # and that we aren't accidentally manipulating the same in the main db).
881 do_test pragma-8.2.5 {
883 PRAGMA aux.user_version;
886 do_test pragma-8.2.6 {
888 PRAGMA aux.user_version = 3;
891 do_test pragma-8.2.7 {
893 PRAGMA aux.user_version;
896 do_test pragma-8.2.8 {
898 PRAGMA main.user_version;
902 # Now check that a ROLLBACK resets the user-version if it has been modified
903 # within a transaction.
904 do_test pragma-8.2.9 {
907 PRAGMA aux.user_version = 10;
908 PRAGMA user_version = 11;
911 do_test pragma-8.2.10 {
913 PRAGMA aux.user_version;
916 do_test pragma-8.2.11 {
918 PRAGMA main.user_version;
921 do_test pragma-8.2.12 {
924 PRAGMA aux.user_version;
927 do_test pragma-8.2.13 {
929 PRAGMA main.user_version;
934 # Try a negative value for the user-version
935 do_test pragma-8.2.14 {
937 PRAGMA user_version = -450;
940 do_test pragma-8.2.15 {
945 } ; # ifcapable schema_version
947 # Check to see if TEMP_STORE is memory or disk. Return strings
948 # "memory" or "disk" as appropriate.
950 proc check_temp_store {} {
951 db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}
952 db eval {PRAGMA database_list} {
954 set bt [btree_from_db db 1]
955 if {[btree_ismemdb $bt]} {
966 do_test pragma-8.3.1 {
968 PRAGMA application_id;
971 do_test pragma-8.3.2 {
972 execsql {PRAGMA Application_ID(12345); PRAGMA application_id;}
975 # Test temp_store and temp_store_directory pragmas
977 ifcapable pager_pragmas {
985 if {$TEMP_STORE<=1} {
986 do_test pragma-9.1.1 {
990 do_test pragma-9.1.1 {
999 PRAGMA temp_store=file;
1003 if {$TEMP_STORE==3} {
1004 # When TEMP_STORE is 3, always use memory regardless of pragma settings.
1005 do_test pragma-9.2.1 {
1009 do_test pragma-9.2.1 {
1014 do_test pragma-9.3 {
1018 PRAGMA temp_store=memory;
1022 if {$TEMP_STORE==0} {
1023 # When TEMP_STORE is 0, always use the disk regardless of pragma settings.
1024 do_test pragma-9.3.1 {
1028 do_test pragma-9.3.1 {
1033 do_test pragma-9.4 {
1035 PRAGMA temp_store_directory;
1039 do_test pragma-9.5 {
1040 set pwd [string map {' ''} [file nativename [get_pwd]]]
1042 PRAGMA temp_store_directory='$pwd';
1045 do_test pragma-9.6 {
1047 PRAGMA temp_store_directory;
1049 } [list [file nativename [get_pwd]]]
1050 do_test pragma-9.7 {
1052 PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
1054 } {1 {not a writable directory}}
1055 do_test pragma-9.8 {
1057 PRAGMA temp_store_directory='';
1060 if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
1062 do_test pragma-9.9 {
1064 PRAGMA temp_store_directory;
1065 PRAGMA temp_store=FILE;
1066 CREATE TEMP TABLE temp_store_directory_test(a integer);
1067 INSERT INTO temp_store_directory_test values (2);
1068 SELECT * FROM temp_store_directory_test;
1071 do_test pragma-9.10 {
1073 PRAGMA temp_store_directory='$pwd';
1074 SELECT * FROM temp_store_directory_test;
1076 } {1 {no such table: temp_store_directory_test}}
1080 do_test pragma-9.11 {
1082 PRAGMA temp_store = 0;
1086 do_test pragma-9.12 {
1088 PRAGMA temp_store = 1;
1092 do_test pragma-9.13 {
1094 PRAGMA temp_store = 2;
1098 do_test pragma-9.14 {
1100 PRAGMA temp_store = 3;
1104 do_test pragma-9.15 {
1107 CREATE TEMP TABLE temp_table(t);
1108 INSERT INTO temp_table VALUES('valuable data');
1109 PRAGMA temp_store = 1;
1111 } {1 {temporary storage cannot be changed from within a transaction}}
1112 do_test pragma-9.16 {
1114 SELECT * FROM temp_table;
1119 do_test pragma-9.17 {
1121 INSERT INTO temp_table VALUES('valuable data II');
1122 SELECT * FROM temp_table;
1124 } {{valuable data} {valuable data II}}
1126 do_test pragma-9.18 {
1128 db eval {SELECT t FROM temp_table} {
1129 execsql {pragma temp_store = 1}
1133 } {1 {temporary storage cannot be changed from within a transaction}}
1135 } ;# ifcapable pager_pragmas
1139 do_test pragma-10.0 {
1144 PRAGMA count_changes = 1;
1146 CREATE TABLE t1(a PRIMARY KEY);
1147 CREATE TABLE t1_mirror(a);
1148 CREATE TABLE t1_mirror2(a);
1149 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
1150 INSERT INTO t1_mirror VALUES(new.a);
1152 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
1153 INSERT INTO t1_mirror2 VALUES(new.a);
1155 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
1156 UPDATE t1_mirror SET a = new.a WHERE a = old.a;
1158 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
1159 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
1161 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
1162 DELETE FROM t1_mirror WHERE a = old.a;
1164 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
1165 DELETE FROM t1_mirror2 WHERE a = old.a;
1170 do_test pragma-10.1 {
1172 INSERT INTO t1 VALUES(randstr(10,10));
1175 do_test pragma-10.2 {
1177 UPDATE t1 SET a = randstr(10,10);
1180 do_test pragma-10.3 {
1186 } ;# ifcapable trigger
1188 ifcapable schema_pragmas {
1189 do_test pragma-11.1 {
1191 pragma collation_list;
1193 } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}
1194 do_test pragma-11.2 {
1195 db collate New_Collation blah...
1197 pragma collation_list;
1199 } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}
1202 ifcapable schema_pragmas&&tempdb {
1203 do_test pragma-12.1 {
1206 PRAGMA temp.table_info('abc');
1211 do_test pragma-12.2 {
1214 PRAGMA temp.default_cache_size = 200;
1215 PRAGMA temp.default_cache_size;
1220 do_test pragma-12.3 {
1223 PRAGMA temp.cache_size = 400;
1224 PRAGMA temp.cache_size;
1232 do_test pragma-13.1 {
1234 DROP TABLE IF EXISTS t4;
1235 PRAGMA vdbe_trace=on;
1236 PRAGMA vdbe_listing=on;
1237 PRAGMA sql_trace=on;
1238 CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
1239 INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
1240 INSERT INTO t4(b) VALUES(randstr(30,30));
1241 INSERT INTO t4(b) VALUES(1.23456);
1242 INSERT INTO t4(b) VALUES(NULL);
1243 INSERT INTO t4(b) VALUES(0);
1244 INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
1248 PRAGMA vdbe_trace=off;
1249 PRAGMA vdbe_listing=off;
1250 PRAGMA sql_trace=off;
1254 } ;# ifcapable bloblit
1256 ifcapable pager_pragmas {
1261 do_test pragma-14.1 {
1262 execsql { pragma auto_vacuum = 0 }
1263 execsql { pragma page_count }
1266 do_test pragma-14.2 {
1268 CREATE TABLE abc(a, b, c);
1272 do_test pragma-14.2uc {
1273 execsql {pragma PAGE_COUNT}
1276 do_test pragma-14.3 {
1279 CREATE TABLE def(a, b, c);
1283 do_test pragma-14.3uc {
1284 execsql {pragma PAGE_COUNT}
1287 do_test pragma-14.4 {
1288 set page_size [db one {pragma page_size}]
1289 expr [file size test.db] / $page_size
1292 do_test pragma-14.5 {
1299 do_test pragma-14.6 {
1300 forcedelete test2.db
1301 sqlite3 db2 test2.db
1303 PRAGMA auto_vacuum = 0;
1304 CREATE TABLE t1(a, b, c);
1305 CREATE TABLE t2(a, b, c);
1306 CREATE TABLE t3(a, b, c);
1307 CREATE TABLE t4(a, b, c);
1311 ATTACH 'test2.db' AS aux;
1312 PRAGMA aux.page_count;
1315 do_test pragma-14.6uc {
1316 execsql {pragma AUX.PAGE_COUNT}
1320 # Test that the value set using the cache_size pragma is not reset when the
1321 # schema is reloaded.
1323 ifcapable pager_pragmas {
1326 do_test pragma-15.1 {
1328 PRAGMA cache_size=59;
1332 do_test pragma-15.2 {
1335 CREATE TABLE newtable(a, b, c);
1339 do_test pragma-15.3 {
1340 # Evaluating this statement will cause the schema to be reloaded (because
1341 # the schema was changed by another connection in pragma-15.2). At one
1342 # point there was a bug that reset the cache_size to its default value
1343 # when this happened.
1344 execsql { SELECT * FROM sqlite_master }
1345 execsql { PRAGMA cache_size }
1349 # Reset the sqlite3_temp_directory variable for the next run of tests:
1350 sqlite3 dbX :memory:
1351 dbX eval {PRAGMA temp_store_directory = ""}
1354 ifcapable lock_proxy_pragmas&&prefer_proxy_locking {
1355 set sqlite_hostid_num 1
1358 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
1359 set using_proxy $value
1362 # Test the lock_proxy_file pragmas.
1365 set env(SQLITE_FORCE_PROXY_LOCKING) "0"
1368 do_test pragma-16.1 {
1370 PRAGMA lock_proxy_file="mylittleproxy";
1371 select * from sqlite_master;
1374 PRAGMA lock_proxy_file;
1378 do_test pragma-16.2 {
1381 PRAGMA lock_proxy_file="mylittleproxy";
1386 do_test pragma-16.2.1 {
1389 PRAGMA lock_proxy_file=":auto:";
1390 select * from sqlite_master;
1393 PRAGMA lock_proxy_file;
1398 do_test pragma-16.3 {
1401 PRAGMA lock_proxy_file="myotherproxy";
1404 select * from sqlite_master;
1406 } {1 {database is locked}}
1408 do_test pragma-16.4 {
1413 PRAGMA lock_proxy_file="myoriginalproxy";
1414 PRAGMA lock_proxy_file="myotherproxy";
1415 PRAGMA lock_proxy_file;
1420 set env(SQLITE_FORCE_PROXY_LOCKING) "1"
1421 do_test pragma-16.5 {
1424 PRAGMA lock_proxy_file=":auto:";
1425 PRAGMA lock_proxy_file;
1429 do_test pragma-16.6 {
1431 sqlite3 db2 test2.db
1432 set lockpath [execsql {
1433 PRAGMA lock_proxy_file=":auto:";
1434 PRAGMA lock_proxy_file;
1436 string match "*test2.db:auto:" $lockpath
1439 set sqlite_hostid_num 2
1440 do_test pragma-16.7 {
1444 PRAGMA lock_proxy_file=":auto:";
1445 select * from sqlite_master;
1448 } {1 {database is locked}}
1451 do_test pragma-16.8 {
1454 execsql { select * from sqlite_master }
1456 } {1 {database is locked}}
1459 do_test pragma-16.8.1 {
1461 PRAGMA lock_proxy_file="yetanotherproxy";
1462 PRAGMA lock_proxy_file;
1465 do_test pragma-16.8.2 {
1467 create table mine(x);
1472 do_test pragma-16.9 {
1473 sqlite3 db proxytest.db
1474 set lockpath2 [execsql {
1475 PRAGMA lock_proxy_file=":auto:";
1476 PRAGMA lock_proxy_file;
1478 string match "*proxytest.db:auto:" $lockpath2
1481 set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
1482 set sqlite_hostid_num 0
1485 # Parsing of auto_vacuum settings.
1487 foreach {autovac_setting val} {
1503 do_test pragma-17.1.$autovac_setting {
1507 PRAGMA auto_vacuum=$::autovac_setting;
1513 # Parsing of temp_store settings.
1515 foreach {temp_setting val} {
1528 do_test pragma-18.1.$temp_setting {
1532 PRAGMA temp_store=$::temp_setting;
1533 PRAGMA temp_store=$::temp_setting;
1539 # The SQLITE_FCNTL_PRAGMA logic, with error handling.
1543 sqlite3 db test.db -vfs tvfs
1544 do_test pragma-19.1 {
1545 catchsql {PRAGMA error}
1546 } {1 {SQL logic error or missing database}}
1547 do_test pragma-19.2 {
1548 catchsql {PRAGMA error='This is the error message'}
1549 } {1 {This is the error message}}
1550 do_test pragma-19.3 {
1551 catchsql {PRAGMA error='7 This is the error message'}
1552 } {1 {This is the error message}}
1553 do_test pragma-19.4 {
1554 catchsql {PRAGMA error=7}
1555 } {1 {out of memory}}
1556 do_test pragma-19.5 {
1557 file tail [lindex [execsql {PRAGMA filename}] 0]
1560 if {$tcl_platform(platform)=="windows"} {
1561 # Test data_store_directory pragma
1566 do_test pragma-20.1 {
1567 catchsql {PRAGMA data_store_directory}
1569 do_test pragma-20.2 {
1570 set pwd [string map {' ''} [file nativename [get_pwd]]]
1571 catchsql "PRAGMA data_store_directory='$pwd';"
1573 do_test pragma-20.3 {
1574 catchsql {PRAGMA data_store_directory}
1575 } [list 0 [list [file nativename [get_pwd]]]]
1576 do_test pragma-20.4 {
1577 set pwd [string map {' ''} [file nativename \
1578 [file join [get_pwd] data_dir]]]
1579 catchsql "PRAGMA data_store_directory='$pwd';"
1581 do_test pragma-20.5 {
1582 sqlite3 db2 test2.db
1583 catchsql "PRAGMA database_list;" db2
1584 } [list 0 [list 0 main [file nativename \
1585 [file join [get_pwd] data_dir test2.db]]]]
1587 do_test pragma-20.6 {
1588 sqlite3 db2 [file join [get_pwd] test2.db]
1589 catchsql "PRAGMA database_list;" db2
1590 } [list 0 [list 0 main [file nativename \
1591 [file join [get_pwd] test2.db]]]]
1593 do_test pragma-20.7 {
1594 catchsql "PRAGMA data_store_directory='';"
1596 do_test pragma-20.8 {
1597 catchsql {PRAGMA data_store_directory}
1600 forcedelete data_dir
1603 database_may_be_corrupt
1606 # Create a corrupt database in testerr.db. And a non-corrupt at test.db.
1612 PRAGMA page_size = 1024;
1613 PRAGMA auto_vacuum = 0;
1614 CREATE TABLE t1(a PRIMARY KEY, b);
1615 INSERT INTO t1 VALUES(1, 1);
1617 for {set i 0} {$i < 10} {incr i} {
1618 execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 }
1621 forcecopy test.db testerr.db
1622 hexio_write testerr.db 15000 [string repeat 55 100]
1625 set mainerr {*** in database main ***
1626 Multiple uses for byte 672 of page 15}
1627 set auxerr {*** in database aux ***
1628 Multiple uses for byte 672 of page 15}
1630 set mainerr {/{\*\*\* in database main \*\*\*
1631 Multiple uses for byte 672 of page 15}.*/}
1632 set auxerr {/{\*\*\* in database aux \*\*\*
1633 Multiple uses for byte 672 of page 15}.*/}
1637 sqlite3 db testerr.db
1638 execsql { PRAGMA integrity_check }
1645 ATTACH 'testerr.db' AS 'aux';
1646 PRAGMA integrity_check;
1650 execsql { PRAGMA main.integrity_check; }
1653 execsql { PRAGMA aux.integrity_check; }
1658 sqlite3 db testerr.db
1660 ATTACH 'test.db' AS 'aux';
1661 PRAGMA integrity_check;
1665 execsql { PRAGMA main.integrity_check; }
1668 execsql { PRAGMA aux.integrity_check; }
1672 forcedelete test.db test.db-wal test.db-journal
1677 CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
1678 CREATE INDEX i1 ON t1(b,c);
1679 CREATE INDEX i2 ON t1(c,d);
1680 CREATE TABLE t2(x INTEGER REFERENCES t1);
1682 db2 eval {SELECT name FROM sqlite_master}
1687 CREATE INDEX i2 ON t1(c,d,b);
1689 db2 eval {PRAGMA index_info(i2)}
1690 } {0 2 c 1 3 d 2 1 b}
1693 CREATE INDEX i3 ON t1(d,b,c);
1695 db2 eval {PRAGMA index_list(t1)}
1696 } {0 i3 0 1 i2 0 2 i1 0}
1699 ALTER TABLE t1 ADD COLUMN e;
1702 PRAGMA table_info(t1);
1708 CREATE TABLE t2(x, y INTEGER REFERENCES t1);
1711 PRAGMA foreign_key_list(t2);
1713 } {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE}
1715 database_never_corrupt