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 # Capture the output of a pragma in a TEMP table.
56 proc capture_pragma {db tabname sql} {
57 $db eval "DROP TABLE IF EXISTS temp.$tabname"
62 set ins "INSERT INTO $tabname VALUES"
63 set crtab "CREATE TEMP TABLE $tabname "
66 append ins ${sep}\$x($col)
67 append crtab ${sep}\"$col\"
78 # Delete the preexisting database to avoid the special setup
79 # that the "all.test" script does.
82 delete_file test.db test.db-journal
83 delete_file test3.db test3.db-journal
84 sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
86 # EVIDENCE-OF: R-13861-56665 PRAGMA schema.cache_size; PRAGMA
87 # schema.cache_size = pages; PRAGMA schema.cache_size = -kibibytes;
88 # Query or change the suggested maximum number of database disk pages
89 # that SQLite will hold in memory at once per open database file.
91 ifcapable pager_pragmas {
92 set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
93 set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
97 PRAGMA default_cache_size;
100 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
102 # EVIDENCE-OF: R-42059-47211 If the argument N is positive then the
103 # suggested cache size is set to N.
105 PRAGMA synchronous=OFF;
106 PRAGMA cache_size=1234;
108 PRAGMA default_cache_size;
111 } [list 1234 $DFLT_CACHE_SZ 0]
117 PRAGMA default_cache_size;
120 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
123 PRAGMA synchronous=OFF;
125 PRAGMA default_cache_size;
128 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
131 PRAGMA cache_size=-4321;
133 PRAGMA default_cache_size;
136 } [list -4321 $DFLT_CACHE_SZ 0]
139 PRAGMA synchronous=ON;
141 PRAGMA default_cache_size;
144 } [list -4321 $DFLT_CACHE_SZ 1]
150 PRAGMA default_cache_size;
153 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
156 PRAGMA default_cache_size=-123;
158 PRAGMA default_cache_size;
162 do_test pragma-1.9.1 {
164 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
167 PRAGMA default_cache_size;
172 do_test pragma-1.9.2 {
176 PRAGMA default_cache_size;
181 do_test pragma-1.10 {
183 PRAGMA synchronous=NORMAL;
185 PRAGMA default_cache_size;
189 do_test pragma-1.11.1 {
191 PRAGMA synchronous=EXTRA;
193 PRAGMA default_cache_size;
197 do_test pragma-1.11.2 {
199 PRAGMA synchronous=FULL;
201 PRAGMA default_cache_size;
205 do_test pragma-1.12 {
207 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
210 PRAGMA default_cache_size;
215 # Make sure the pragma handler understands numeric values in addition
216 # to keywords like "off" and "full".
218 do_test pragma-1.13 {
220 PRAGMA synchronous=0;
224 do_test pragma-1.14 {
226 PRAGMA synchronous=2;
230 do_test pragma-1.14.1 {
232 PRAGMA synchronous=4;
236 do_test pragma-1.14.2 {
238 PRAGMA synchronous=3;
242 do_test pragma-1.14.3 {
244 PRAGMA synchronous=8;
248 do_test pragma-1.14.4 {
250 PRAGMA synchronous=10;
255 do_execsql_test 1.15.1 {
256 PRAGMA default_cache_size = 0;
258 do_execsql_test 1.15.2 {
259 PRAGMA default_cache_size;
261 do_execsql_test 1.15.3 {
262 PRAGMA default_cache_size = -500;
264 do_execsql_test 1.15.4 {
265 PRAGMA default_cache_size;
267 do_execsql_test 1.15.3 {
268 PRAGMA default_cache_size = 500;
270 do_execsql_test 1.15.4 {
271 PRAGMA default_cache_size;
274 hexio_write test.db 48 FFFFFF00
276 do_execsql_test 1.15.4 {
277 PRAGMA default_cache_size;
279 } ;# ifcapable pager_pragmas
281 # Test turning "flag" pragmas on and off.
284 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG
286 do_test pragma-1.15 {
288 PRAGMA vdbe_listing=YES;
292 do_test pragma-1.16 {
294 PRAGMA vdbe_listing=NO;
300 do_test pragma-1.17 {
302 PRAGMA parser_trace=ON;
303 PRAGMA parser_trace=OFF;
306 do_test pragma-1.18 {
308 PRAGMA bogus = -1234; -- Parsing of negative values
312 # Test modifying the safety_level of an attached database.
313 ifcapable pager_pragmas&&attach {
316 forcedelete test2.db-journal
318 ATTACH 'test2.db' AS aux;
323 pragma aux.synchronous;
328 pragma aux.synchronous = OFF;
329 pragma aux.synchronous;
335 pragma aux.synchronous = ON;
337 pragma aux.synchronous;
340 } ;# ifcapable pager_pragmas
342 # Construct a corrupted index and make sure the integrity_check
345 # These tests won't work if the database is encrypted
349 forcedelete test.db test.db-journal
352 PRAGMA auto_vacuum=OFF;
354 CREATE TABLE t2(a,b,c);
355 CREATE INDEX i2 ON t2(a);
356 INSERT INTO t2 VALUES(11,2,3);
357 INSERT INTO t2 VALUES(22,3,4);
359 SELECT rowid, * from t2;
361 } {1 11 2 3 2 22 3 4}
363 if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
365 db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
366 set pgsz [db eval {PRAGMA page_size}]
367 # overwrite the header on the rootpage of the index in order to
368 # make the index appear to be empty.
370 set offset [expr {$pgsz*($rootpage-1)}]
371 hexio_write test.db $offset 0a00000000040000000000
374 execsql {PRAGMA integrity_check}
375 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
377 execsql {PRAGMA integrity_check=1}
378 } {{row 1 missing from index i2}}
381 ATTACH DATABASE 'test.db' AS t2;
382 PRAGMA integrity_check
384 } {{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}}
387 PRAGMA integrity_check=4
389 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}}
390 do_catchsql_test pragma-3.6 {
391 PRAGMA integrity_check=xyz
392 } {1 {no such table: xyz}}
393 do_catchsql_test pragma-3.6b {
394 PRAGMA integrity_check=t2
395 } {0 {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}}
396 do_catchsql_test pragma-3.6c {
397 PRAGMA integrity_check=sqlite_schema
401 PRAGMA integrity_check=0
403 } {{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}}
405 # Add additional corruption by appending unused pages to the end of
406 # the database file testerr.db
410 forcedelete testerr.db testerr.db-journal
411 set out [open testerr.db w]
412 fconfigure $out -translation binary
413 set in [open test.db r]
414 fconfigure $in -translation binary
415 puts -nonewline $out [read $in]
417 puts -nonewline $out [read $in]
420 hexio_write testerr.db 28 00000000
422 execsql {PRAGMA integrity_check}
424 do_test pragma-3.8.1 {
425 execsql {PRAGMA quick_check}
427 do_test pragma-3.8.2 {
428 execsql {PRAGMA QUICK_CHECK}
430 do_test pragma-3.9a {
432 ATTACH 'testerr.db' AS t2;
433 PRAGMA integrity_check
435 } {{*** in database t2 ***
438 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
439 do_execsql_test pragma-3.9b {
440 PRAGMA t2.integrity_check=t2;
441 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
442 do_execsql_test pragma-3.9c {
443 PRAGMA t2.integrity_check=sqlite_schema;
445 do_test pragma-3.10 {
447 PRAGMA integrity_check=1
449 } {{*** in database t2 ***
450 Page 4 is never used}}
451 do_test pragma-3.11 {
453 PRAGMA integrity_check=5
455 } {{*** in database t2 ***
458 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2}}
459 do_test pragma-3.12 {
461 PRAGMA integrity_check=4
463 } {{*** in database t2 ***
466 Page 6 is never used} {row 1 missing from index i2}}
467 do_test pragma-3.13 {
469 PRAGMA integrity_check=3
471 } {{*** in database t2 ***
474 Page 6 is never used}}
475 do_test pragma-3.14 {
477 PRAGMA integrity_check(2)
479 } {{*** in database t2 ***
481 Page 5 is never used}}
482 do_test pragma-3.15 {
484 ATTACH 'testerr.db' AS t3;
485 PRAGMA integrity_check
487 } {{*** in database t2 ***
490 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 ***
493 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
494 do_test pragma-3.16 {
496 PRAGMA integrity_check(10)
498 } {{*** in database t2 ***
501 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 ***
504 Page 6 is never used} {row 1 missing from index i2}}
505 do_test pragma-3.17 {
507 PRAGMA integrity_check=8
509 } {{*** in database t2 ***
512 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 ***
514 Page 5 is never used}}
515 do_test pragma-3.18 {
517 PRAGMA integrity_check=4
519 } {{*** in database t2 ***
522 Page 6 is never used} {row 1 missing from index i2}}
524 do_test pragma-3.19 {
526 forcedelete test.db test.db-journal
528 db eval {PRAGMA integrity_check}
532 # Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL
533 # constraint violations.
535 ifcapable altertable {
536 sqlite3_db_config db DEFENSIVE 0
537 do_execsql_test pragma-3.20 {
538 CREATE TABLE t1(a,b);
539 CREATE INDEX t1a ON t1(a);
540 INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6);
541 PRAGMA writable_schema=ON;
542 UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)'
544 UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)'
546 PRAGMA writable_schema=OFF;
547 ALTER TABLE t1 RENAME TO t1x;
548 PRAGMA integrity_check;
549 } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a} {NULL value in t1x.a}}
550 do_execsql_test pragma-3.21 {
551 PRAGMA integrity_check(3);
552 } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a}}
553 do_execsql_test pragma-3.22 {
554 PRAGMA integrity_check(2);
555 } {{non-unique entry in index t1a} {NULL value in t1x.a}}
556 do_execsql_test pragma-3.23 {
557 PRAGMA integrity_check(1);
558 } {{non-unique entry in index t1a}}
561 # PRAGMA integrity check (or more specifically the sqlite3BtreeCount()
562 # interface) used to leave index cursors in an inconsistent state
563 # which could result in an assertion fault in sqlite3BtreeKey()
564 # called from saveCursorPosition() if content is removed from the
565 # index while the integrity_check is still running. This test verifies
566 # that problem has been fixed.
568 do_test pragma-3.30 {
573 CREATE TABLE t1(a,b,c);
575 c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100)
576 INSERT INTO t1(a,b,c) SELECT i, printf('xyz%08x',i), 2000-i FROM c;
577 CREATE INDEX t1a ON t1(a);
578 CREATE INDEX t1bc ON t1(b,c);
580 db eval {PRAGMA integrity_check} {
581 db eval {DELETE FROM t1}
585 # Test modifying the cache_size of an attached database.
586 ifcapable pager_pragmas&&attach {
589 ATTACH 'test2.db' AS aux;
590 pragma aux.cache_size;
591 pragma aux.default_cache_size;
593 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
596 pragma aux.cache_size = 50;
597 pragma aux.cache_size;
598 pragma aux.default_cache_size;
600 } [list 50 $DFLT_CACHE_SZ]
603 pragma aux.default_cache_size = 456;
604 pragma aux.cache_size;
605 pragma aux.default_cache_size;
611 pragma default_cache_size;
613 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
617 ATTACH 'test3.db' AS aux;
618 pragma aux.cache_size;
619 pragma aux.default_cache_size;
621 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
625 ATTACH 'test2.db' AS aux;
626 pragma aux.cache_size;
627 pragma aux.default_cache_size;
630 } ;# ifcapable pager_pragmas
632 # Test that modifying the sync-level in the middle of a transaction is
634 ifcapable pager_pragmas {
643 pragma synchronous = OFF;
645 } {1 {Safety level may not be changed inside a transaction}}
652 } ;# ifcapable pager_pragmas
654 # Test schema-query pragmas
656 ifcapable schema_pragmas {
657 ifcapable tempdb&&attach {
660 execsql {SELECT * FROM sqlite_temp_master}
661 foreach {idx name file} [execsql {pragma database_list}] {
662 lappend res $idx $name
665 } {0 main 1 temp 2 aux}
669 CREATE TABLE t2(a TYPE_X, b [TYPE_Y], c "TYPE_Z");
670 pragma table_info(t2)
672 } {0 a TYPE_X 0 {} 0 1 b TYPE_Y 0 {} 0 2 c TYPE_Z 0 {} 0}
673 do_test pragma-6.2.1 {
678 db nullvalue <<NULL>>
679 do_test pragma-6.2.2 {
682 a TEXT DEFAULT CURRENT_TIMESTAMP,
685 d INTEGER DEFAULT NULL,
690 PRAGMA table_info(t5);
692 } {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}
694 do_test pragma-6.2.3 {
696 CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
697 pragma table_info(t2_3)
699 } {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
700 ifcapable {foreignkey} {
701 do_test pragma-6.3.1 {
703 CREATE TABLE t3(a int references t2(b), b UNIQUE);
704 pragma foreign_key_list(t3);
706 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
707 do_test pragma-6.3.2 {
709 pragma foreign_key_list;
712 do_test pragma-6.3.3 {
714 pragma foreign_key_list(t3_bogus);
717 do_test pragma-6.3.4 {
719 pragma foreign_key_list(t5);
723 capture_pragma db out {
724 pragma index_list(t3);
726 db eval {SELECT seq, "name", "unique" FROM out ORDER BY seq}
727 } {0 sqlite_autoindex_t3_1 1}
729 ifcapable {!foreignkey} {
730 execsql {CREATE TABLE t3(a,b UNIQUE)}
732 do_test pragma-6.5.1 {
734 CREATE INDEX t3i1 ON t3(a,b);
736 capture_pragma db out {
737 pragma index_info(t3i1);
739 db eval {SELECT seqno, cid, name FROM out ORDER BY seqno}
742 # EVIDENCE-OF: R-23114-21695 The auxiliary index-columns are not shown
743 # by the index_info pragma, but they are listed by the index_xinfo
746 do_test pragma-6.5.1b {
747 capture_pragma db out {PRAGMA index_xinfo(t3i1)}
748 db eval {SELECT seqno, cid, name FROM out ORDER BY seqno}
749 } {0 0 a 1 1 b 2 -1 {}}
752 # EVIDENCE-OF: R-29448-60346 PRAGMA schema.index_info(index-name); This
753 # pragma returns one row for each key column in the named index.
755 # (The first column of output from PRAGMA index_info is...)
756 # EVIDENCE-OF: R-34186-52914 The rank of the column within the index. (0
759 # (The second column of output from PRAGMA index_info is...)
760 # EVIDENCE-OF: R-65019-08383 The rank of the column within the table
763 # (The third column of output from PRAGMA index_info is...)
764 # EVIDENCE-OF: R-09773-34266 The name of the column being indexed.
766 do_execsql_test pragma-6.5.1c {
767 CREATE INDEX t3i2 ON t3(b,a);
768 PRAGMA index_info='t3i2';
772 do_test pragma-6.5.2 {
774 pragma index_info(t3i1_bogus);
779 # Test for ticket #3320. When a temp table of the same name exists, make
780 # sure the schema of the main table can still be queried using
781 # "pragma table_info":
782 do_test pragma-6.6.1 {
784 CREATE TABLE trial(col_main);
785 CREATE TEMP TABLE trial(col_temp);
788 do_test pragma-6.6.2 {
790 PRAGMA table_info(trial);
792 } {0 col_temp {} 0 {} 0}
793 do_test pragma-6.6.3 {
795 PRAGMA temp.table_info(trial);
797 } {0 col_temp {} 0 {} 0}
798 do_test pragma-6.6.4 {
800 PRAGMA main.table_info(trial);
802 } {0 col_main {} 0 {} 0}
807 CREATE TABLE test_table(
808 one INT NOT NULL DEFAULT -1,
810 three VARCHAR(45, 65) DEFAULT 'abcde',
811 four REAL DEFAULT X'abcdef',
812 five DEFAULT CURRENT_TIME
815 capture_pragma db out {PRAGMA table_info(test_table)}
816 db eval {SELECT cid, "name", type, "notnull", dflt_value, pk FROM out
820 {1 two TEXT 0 {} 0} \
821 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
822 {3 four REAL 0 X'abcdef' 0} \
823 {4 five {} 0 CURRENT_TIME 0} \
827 CREATE TABLE t68(a,b,c,PRIMARY KEY(a,b,a,c));
828 PRAGMA table_info(t68);
835 } ;# ifcapable schema_pragmas
836 # Miscellaneous tests
838 ifcapable schema_pragmas {
839 # EVIDENCE-OF: R-64103-17776 PRAGMA schema.index_list(table-name); This
840 # pragma returns one row for each index associated with the given table.
842 do_test pragma-7.1.1 {
843 # Make sure a pragma knows to read the schema if it needs to
846 capture_pragma db out "PRAGMA index_list(t3)"
847 db eval {SELECT name, "origin" FROM out ORDER BY name DESC}
848 } {t3i1 c sqlite_autoindex_t3_1 u}
849 do_test pragma-7.1.2 {
851 pragma index_list(t3_bogus);
854 } ;# ifcapable schema_pragmas
856 if {[permutation] == ""} {
861 pragma encoding=bogus;
863 } {1 {unsupported encoding: bogus}}
873 } {main unlocked temp closed}
885 #----------------------------------------------------------------------
886 # Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
887 # user_version" statements.
889 # pragma-8.1: PRAGMA schema_version
890 # pragma-8.2: PRAGMA user_version
893 ifcapable schema_version {
895 # First check that we can set the schema version and then retrieve the
897 do_test pragma-8.1.1 {
899 PRAGMA schema_version = 105;
902 do_test pragma-8.1.2 {
904 PRAGMA schema_version;
906 } {schema_version 105}
907 sqlite3_db_config db DEFENSIVE 1
908 do_execsql_test pragma-8.1.3 {
909 PRAGMA schema_version = 106;
910 PRAGMA schema_version;
912 sqlite3_db_config db DEFENSIVE 0
913 do_execsql_test pragma-8.1.4 {
914 PRAGMA schema_version = 106;
915 PRAGMA schema_version;
918 # Check that creating a table modifies the schema-version (this is really
919 # to verify that the value being read is in fact the schema version).
920 do_test pragma-8.1.5 {
922 CREATE TABLE t4(a, b, c);
923 INSERT INTO t4 VALUES(1, 2, 3);
927 do_test pragma-8.1.6 {
929 PRAGMA schema_version;
933 # Now open a second connection to the database. Ensure that changing the
934 # schema-version using the first connection forces the second connection
935 # to reload the schema. This has to be done using the C-API test functions,
936 # because the TCL API accounts for SCHEMA_ERROR and retries the query.
937 do_test pragma-8.1.7 {
938 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
943 do_test pragma-8.1.8 {
945 PRAGMA schema_version = 108;
948 do_test pragma-8.1.9 {
949 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
952 do_test pragma-8.1.10 {
953 sqlite3_finalize $::STMT
956 # Make sure the schema-version can be manipulated in an attached database.
958 forcedelete test2.db-journal
960 do_test pragma-8.1.11 {
962 ATTACH 'test2.db' AS aux;
963 CREATE TABLE aux.t1(a, b, c);
964 PRAGMA aux.schema_version = 205;
967 do_test pragma-8.1.12 {
969 PRAGMA aux.schema_version;
973 do_test pragma-8.1.13 {
975 PRAGMA schema_version;
979 # And check that modifying the schema-version in an attached database
980 # forces the second connection to reload the schema.
982 do_test pragma-8.1.14 {
983 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
985 ATTACH 'test2.db' AS aux;
986 SELECT * FROM aux.t1;
989 do_test pragma-8.1.15 {
991 PRAGMA aux.schema_version = 206;
994 do_test pragma-8.1.16 {
995 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
998 do_test pragma-8.1.17 {
999 sqlite3_finalize $::STMT
1001 do_test pragma-8.1.18 {
1006 # Now test that the user-version can be read and written (and that we aren't
1007 # accidentally manipulating the schema-version instead).
1008 do_test pragma-8.2.1 {
1010 PRAGMA user_version;
1013 do_test pragma-8.2.2 {
1015 PRAGMA user_version = 2;
1018 do_test pragma-8.2.3.1 {
1020 PRAGMA user_version;
1023 do_test pragma-8.2.3.2 {
1027 PRAGMA user_version;
1030 do_test pragma-8.2.4.1 {
1032 PRAGMA schema_version;
1036 do_test pragma-8.2.4.2 {
1039 PRAGMA user_version;
1042 do_test pragma-8.2.4.3 {
1044 PRAGMA schema_version;
1050 db eval {ATTACH 'test2.db' AS aux}
1052 # Check that the user-version in the auxilary database can be manipulated (
1053 # and that we aren't accidentally manipulating the same in the main db).
1054 do_test pragma-8.2.5 {
1056 PRAGMA aux.user_version;
1059 do_test pragma-8.2.6 {
1061 PRAGMA aux.user_version = 3;
1064 do_test pragma-8.2.7 {
1066 PRAGMA aux.user_version;
1069 do_test pragma-8.2.8 {
1071 PRAGMA main.user_version;
1075 # Now check that a ROLLBACK resets the user-version if it has been modified
1076 # within a transaction.
1077 do_test pragma-8.2.9 {
1080 PRAGMA aux.user_version = 10;
1081 PRAGMA user_version = 11;
1084 do_test pragma-8.2.10 {
1086 PRAGMA aux.user_version;
1089 do_test pragma-8.2.11 {
1091 PRAGMA main.user_version;
1094 do_test pragma-8.2.12 {
1097 PRAGMA aux.user_version;
1100 do_test pragma-8.2.13 {
1102 PRAGMA main.user_version;
1107 # Try a negative value for the user-version
1108 do_test pragma-8.2.14 {
1110 PRAGMA user_version = -450;
1113 do_test pragma-8.2.15 {
1115 PRAGMA user_version;
1118 } ; # ifcapable schema_version
1120 # Check to see if TEMP_STORE is memory or disk. Return strings
1121 # "memory" or "disk" as appropriate.
1123 proc check_temp_store {} {
1125 PRAGMA temp.cache_size = 1;
1126 CREATE TEMP TABLE IF NOT EXISTS a(b);
1128 INSERT INTO a VALUES(randomblob(1000));
1129 INSERT INTO a SELECT * FROM a;
1130 INSERT INTO a SELECT * FROM a;
1131 INSERT INTO a SELECT * FROM a;
1132 INSERT INTO a SELECT * FROM a;
1133 INSERT INTO a SELECT * FROM a;
1134 INSERT INTO a SELECT * FROM a;
1135 INSERT INTO a SELECT * FROM a;
1136 INSERT INTO a SELECT * FROM a;
1138 db eval {PRAGMA database_list} {
1139 if {$name=="temp"} {
1140 set bt [btree_from_db db 1]
1141 if {[btree_ismemdb $bt]} {
1152 do_test pragma-8.3.1 {
1154 PRAGMA application_id;
1157 do_test pragma-8.3.2 {
1158 execsql {PRAGMA Application_ID(12345); PRAGMA application_id;}
1161 # Test temp_store and temp_store_directory pragmas
1163 ifcapable pager_pragmas {
1164 do_test pragma-9.1 {
1171 if {$TEMP_STORE<=1} {
1172 do_test pragma-9.1.1 {
1176 do_test pragma-9.1.1 {
1181 do_test pragma-9.2 {
1185 PRAGMA temp_store=file;
1189 if {$TEMP_STORE==3} {
1190 # When TEMP_STORE is 3, always use memory regardless of pragma settings.
1191 do_test pragma-9.2.1 {
1195 do_test pragma-9.2.1 {
1200 do_test pragma-9.3 {
1204 PRAGMA temp_store=memory;
1208 if {$TEMP_STORE==0} {
1209 # When TEMP_STORE is 0, always use the disk regardless of pragma settings.
1210 do_test pragma-9.3.1 {
1214 do_test pragma-9.3.1 {
1219 do_test pragma-9.4 {
1221 PRAGMA temp_store_directory;
1225 do_test pragma-9.5 {
1226 set pwd [string map {' ''} [file nativename [get_pwd]]]
1228 PRAGMA temp_store_directory='$pwd';
1231 do_test pragma-9.6 {
1233 PRAGMA temp_store_directory;
1235 } [list [file nativename [get_pwd]]]
1236 do_test pragma-9.7 {
1238 PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
1240 } {1 {not a writable directory}}
1241 do_test pragma-9.8 {
1243 PRAGMA temp_store_directory='';
1246 if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
1248 do_test pragma-9.9 {
1250 PRAGMA temp_store_directory;
1251 PRAGMA temp_store=FILE;
1252 CREATE TEMP TABLE temp_store_directory_test(a integer);
1253 INSERT INTO temp_store_directory_test values (2);
1254 SELECT * FROM temp_store_directory_test;
1257 do_test pragma-9.10 {
1259 PRAGMA temp_store_directory='$pwd';
1260 SELECT * FROM temp_store_directory_test;
1262 } {1 {no such table: temp_store_directory_test}}
1266 do_test pragma-9.11 {
1268 PRAGMA temp_store = 0;
1272 do_test pragma-9.12 {
1274 PRAGMA temp_store = 1;
1278 do_test pragma-9.13 {
1280 PRAGMA temp_store = 2;
1284 do_test pragma-9.14 {
1286 PRAGMA temp_store = 3;
1290 do_test pragma-9.15 {
1293 CREATE TEMP TABLE temp_table(t);
1294 INSERT INTO temp_table VALUES('valuable data');
1295 PRAGMA temp_store = 1;
1297 } {1 {temporary storage cannot be changed from within a transaction}}
1298 do_test pragma-9.16 {
1300 SELECT * FROM temp_table;
1305 do_test pragma-9.17 {
1307 INSERT INTO temp_table VALUES('valuable data II');
1308 SELECT * FROM temp_table;
1310 } {{valuable data} {valuable data II}}
1312 do_test pragma-9.18 {
1314 db eval {SELECT t FROM temp_table} {
1315 execsql {pragma temp_store = 1}
1319 } {1 {temporary storage cannot be changed from within a transaction}}
1321 } ;# ifcapable pager_pragmas
1325 do_test pragma-10.0 {
1330 PRAGMA count_changes = 1;
1332 CREATE TABLE t1(a PRIMARY KEY);
1333 CREATE TABLE t1_mirror(a);
1334 CREATE TABLE t1_mirror2(a);
1335 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
1336 INSERT INTO t1_mirror VALUES(new.a);
1338 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
1339 INSERT INTO t1_mirror2 VALUES(new.a);
1341 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
1342 UPDATE t1_mirror SET a = new.a WHERE a = old.a;
1344 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
1345 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
1347 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
1348 DELETE FROM t1_mirror WHERE a = old.a;
1350 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
1351 DELETE FROM t1_mirror2 WHERE a = old.a;
1356 do_test pragma-10.1 {
1358 INSERT INTO t1 VALUES(randstr(10,10));
1361 do_test pragma-10.2 {
1363 UPDATE t1 SET a = randstr(10,10);
1366 do_test pragma-10.3 {
1372 } ;# ifcapable trigger
1374 ifcapable schema_pragmas {
1375 do_test pragma-11.1 {
1377 pragma collation_list;
1379 } {seq 0 name RTRIM seq 1 name NOCASE seq 2 name BINARY}
1380 do_test pragma-11.2 {
1381 db collate New_Collation blah...
1383 pragma collation_list;
1385 } {0 New_Collation 1 RTRIM 2 NOCASE 3 BINARY}
1388 ifcapable schema_pragmas&&tempdb {
1389 do_test pragma-12.1 {
1392 PRAGMA temp.table_info('abc');
1397 do_test pragma-12.2 {
1400 PRAGMA temp.default_cache_size = 200;
1401 PRAGMA temp.default_cache_size;
1406 do_test pragma-12.3 {
1409 PRAGMA temp.cache_size = 400;
1410 PRAGMA temp.cache_size;
1418 do_test pragma-13.1 {
1420 DROP TABLE IF EXISTS t4;
1421 PRAGMA vdbe_trace=on;
1422 PRAGMA vdbe_listing=on;
1423 PRAGMA sql_trace=on;
1424 CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
1425 INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
1426 INSERT INTO t4(b) VALUES(randstr(30,30));
1427 INSERT INTO t4(b) VALUES(1.23456);
1428 INSERT INTO t4(b) VALUES(NULL);
1429 INSERT INTO t4(b) VALUES(0);
1430 INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
1434 PRAGMA vdbe_trace=off;
1435 PRAGMA vdbe_listing=off;
1436 PRAGMA sql_trace=off;
1440 } ;# ifcapable bloblit
1442 ifcapable pager_pragmas {
1447 # EVIDENCE-OF: R-15672-33611 PRAGMA schema.page_count; Return the total
1448 # number of pages in the database file.
1450 do_test pragma-14.1 {
1451 execsql { pragma auto_vacuum = 0 }
1452 execsql { pragma page_count; pragma main.page_count }
1455 do_test pragma-14.2 {
1457 CREATE TABLE abc(a, b, c);
1459 PRAGMA main.page_count;
1460 PRAGMA temp.page_count;
1463 do_test pragma-14.2uc {
1464 execsql {pragma PAGE_COUNT}
1467 do_test pragma-14.3 {
1470 CREATE TABLE def(a, b, c);
1474 do_test pragma-14.3uc {
1475 execsql {pragma PAGE_COUNT}
1478 do_test pragma-14.4 {
1479 set page_size [db one {pragma page_size}]
1480 expr [file size test.db] / $page_size
1483 do_test pragma-14.5 {
1490 do_test pragma-14.6 {
1491 forcedelete test2.db
1492 sqlite3 db2 test2.db
1494 PRAGMA auto_vacuum = 0;
1495 CREATE TABLE t1(a, b, c);
1496 CREATE TABLE t2(a, b, c);
1497 CREATE TABLE t3(a, b, c);
1498 CREATE TABLE t4(a, b, c);
1502 ATTACH 'test2.db' AS aux;
1503 PRAGMA aux.page_count;
1506 do_test pragma-14.6uc {
1507 execsql {pragma AUX.PAGE_COUNT}
1511 # Test that the value set using the cache_size pragma is not reset when the
1512 # schema is reloaded.
1514 ifcapable pager_pragmas {
1517 do_test pragma-15.1 {
1519 PRAGMA cache_size=59;
1523 do_test pragma-15.2 {
1526 CREATE TABLE newtable(a, b, c);
1530 do_test pragma-15.3 {
1531 # Evaluating this statement will cause the schema to be reloaded (because
1532 # the schema was changed by another connection in pragma-15.2). At one
1533 # point there was a bug that reset the cache_size to its default value
1534 # when this happened.
1535 execsql { SELECT * FROM sqlite_master }
1536 execsql { PRAGMA cache_size }
1540 # Reset the sqlite3_temp_directory variable for the next run of tests:
1541 sqlite3 dbX :memory:
1542 dbX eval {PRAGMA temp_store_directory = ""}
1545 ifcapable lock_proxy_pragmas&&prefer_proxy_locking {
1546 set sqlite_hostid_num 1
1549 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
1550 set using_proxy $value
1553 # Test the lock_proxy_file pragmas.
1556 set env(SQLITE_FORCE_PROXY_LOCKING) "0"
1559 do_test pragma-16.1 {
1561 PRAGMA lock_proxy_file="mylittleproxy";
1562 select * from sqlite_master;
1565 PRAGMA lock_proxy_file;
1569 do_test pragma-16.2 {
1572 PRAGMA lock_proxy_file="mylittleproxy";
1577 do_test pragma-16.2.1 {
1580 PRAGMA lock_proxy_file=":auto:";
1581 select * from sqlite_master;
1584 PRAGMA lock_proxy_file;
1589 do_test pragma-16.3 {
1592 PRAGMA lock_proxy_file="myotherproxy";
1595 select * from sqlite_master;
1597 } {1 {database is locked}}
1599 do_test pragma-16.4 {
1604 PRAGMA lock_proxy_file="myoriginalproxy";
1605 PRAGMA lock_proxy_file="myotherproxy";
1606 PRAGMA lock_proxy_file;
1611 set env(SQLITE_FORCE_PROXY_LOCKING) "1"
1612 do_test pragma-16.5 {
1615 PRAGMA lock_proxy_file=":auto:";
1616 PRAGMA lock_proxy_file;
1620 do_test pragma-16.6 {
1622 sqlite3 db2 test2.db
1623 set lockpath [execsql {
1624 PRAGMA lock_proxy_file=":auto:";
1625 PRAGMA lock_proxy_file;
1627 string match "*test2.db:auto:" $lockpath
1630 set sqlite_hostid_num 2
1631 do_test pragma-16.7 {
1635 PRAGMA lock_proxy_file=":auto:";
1636 select * from sqlite_master;
1639 } {1 {database is locked}}
1642 do_test pragma-16.8 {
1645 execsql { select * from sqlite_master }
1647 } {1 {database is locked}}
1650 do_test pragma-16.8.1 {
1652 PRAGMA lock_proxy_file="yetanotherproxy";
1653 PRAGMA lock_proxy_file;
1656 do_test pragma-16.8.2 {
1658 create table mine(x);
1663 do_test pragma-16.9 {
1664 sqlite3 db proxytest.db
1665 set lockpath2 [execsql {
1666 PRAGMA lock_proxy_file=":auto:";
1667 PRAGMA lock_proxy_file;
1669 string match "*proxytest.db:auto:" $lockpath2
1672 set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
1673 set sqlite_hostid_num 0
1676 # Parsing of auto_vacuum settings.
1678 foreach {autovac_setting val} {
1694 do_test pragma-17.1.$autovac_setting {
1698 PRAGMA auto_vacuum=$::autovac_setting;
1704 # Parsing of temp_store settings.
1706 foreach {temp_setting val} {
1719 do_test pragma-18.1.$temp_setting {
1723 PRAGMA temp_store=$::temp_setting;
1724 PRAGMA temp_store=$::temp_setting;
1730 # The SQLITE_FCNTL_PRAGMA logic, with error handling.
1734 sqlite3 db test.db -vfs tvfs
1735 do_test pragma-19.1 {
1736 catchsql {PRAGMA error}
1737 } {1 {SQL logic error}}
1738 do_test pragma-19.2 {
1739 catchsql {PRAGMA error='This is the error message'}
1740 } {1 {This is the error message}}
1741 do_test pragma-19.3 {
1742 catchsql {PRAGMA error='7 This is the error message'}
1743 } {1 {This is the error message}}
1744 do_test pragma-19.4 {
1745 catchsql {PRAGMA error=7}
1746 } {1 {out of memory}}
1747 do_test pragma-19.5 {
1748 file tail [lindex [execsql {PRAGMA filename}] 0]
1751 if {$tcl_platform(platform)=="windows"} {
1752 # Test data_store_directory pragma
1757 do_test pragma-20.1 {
1758 catchsql {PRAGMA data_store_directory}
1760 do_test pragma-20.2 {
1761 set pwd [string map {' ''} [file nativename [get_pwd]]]
1762 catchsql "PRAGMA data_store_directory='$pwd';"
1764 do_test pragma-20.3 {
1765 catchsql {PRAGMA data_store_directory}
1766 } [list 0 [list [file nativename [get_pwd]]]]
1767 do_test pragma-20.4 {
1768 set pwd [string map {' ''} [file nativename \
1769 [file join [get_pwd] data_dir]]]
1770 catchsql "PRAGMA data_store_directory='$pwd';"
1772 do_test pragma-20.5 {
1773 sqlite3 db2 test2.db
1774 catchsql "PRAGMA database_list;" db2
1775 } [list 0 [list 0 main [file nativename \
1776 [file join [get_pwd] data_dir test2.db]]]]
1778 do_test pragma-20.6 {
1779 sqlite3 db2 [file join [get_pwd] test2.db]
1780 catchsql "PRAGMA database_list;" db2
1781 } [list 0 [list 0 main [file nativename \
1782 [file join [get_pwd] test2.db]]]]
1784 do_test pragma-20.7 {
1785 catchsql "PRAGMA data_store_directory='';"
1787 do_test pragma-20.8 {
1788 catchsql {PRAGMA data_store_directory}
1791 forcedelete data_dir
1794 database_may_be_corrupt
1795 if {![nonzero_reserved_bytes]} {
1798 # Create a corrupt database in testerr.db. And a non-corrupt at test.db.
1804 PRAGMA page_size = 1024;
1805 PRAGMA auto_vacuum = 0;
1806 CREATE TABLE t1(a PRIMARY KEY, b);
1807 INSERT INTO t1 VALUES(1, 1);
1809 for {set i 0} {$i < 10} {incr i} {
1810 execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 }
1813 forcecopy test.db testerr.db
1814 hexio_write testerr.db 15000 [string repeat 55 100]
1817 set mainerr {*** in database main ***
1818 Multiple uses for byte 672 of page 15}
1819 set auxerr {*** in database aux ***
1820 Multiple uses for byte 672 of page 15}
1822 set mainerr {/{\*\*\* in database main \*\*\*
1823 Multiple uses for byte 672 of page 15}.*/}
1824 set auxerr {/{\*\*\* in database aux \*\*\*
1825 Multiple uses for byte 672 of page 15}.*/}
1829 sqlite3 db testerr.db
1830 execsql { PRAGMA integrity_check }
1837 ATTACH 'testerr.db' AS 'aux';
1838 PRAGMA integrity_check;
1842 execsql { PRAGMA main.integrity_check; }
1845 execsql { PRAGMA aux.integrity_check; }
1850 sqlite3 db testerr.db
1852 ATTACH 'test.db' AS 'aux';
1853 PRAGMA integrity_check;
1857 execsql { PRAGMA main.integrity_check; }
1860 execsql { PRAGMA aux.integrity_check; }
1865 forcedelete test.db test.db-wal test.db-journal
1870 CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
1871 CREATE INDEX i1 ON t1(b,c);
1872 CREATE INDEX i2 ON t1(c,d);
1873 CREATE INDEX i2x ON t1(d COLLATE nocase, c DESC);
1874 CREATE INDEX i3 ON t1(d,b+c,c);
1875 CREATE TABLE t2(x INTEGER REFERENCES t1);
1877 db2 eval {SELECT name FROM sqlite_master}
1878 } {t1 i1 i2 i2x i3 t2}
1882 CREATE INDEX i2 ON t1(c,d,b);
1884 capture_pragma db2 out {PRAGMA index_info(i2)}
1885 db2 eval {SELECT cid, name, '|' FROM out ORDER BY seqno}
1886 } {2 c | 3 d | 1 b |}
1888 # EVIDENCE-OF: R-56143-29319 PRAGMA schema.index_xinfo(index-name); This
1889 # pragma returns information about every column in an index.
1891 # EVIDENCE-OF: R-45970-35618 Unlike this index_info pragma, this pragma
1892 # returns information about every column in the index, not just the key
1896 capture_pragma db2 out {PRAGMA index_xinfo(i2)}
1897 db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno}
1898 } {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 | -1 {} 0 BINARY 0 |}
1900 # (The first column of output from PRAGMA index_xinfo is...)
1901 # EVIDENCE-OF: R-00197-14279 The rank of the column within the index. (0
1902 # means left-most. Key columns come before auxiliary columns.)
1904 # (The second column of output from PRAGMA index_xinfo is...)
1905 # EVIDENCE-OF: R-06603-49335 The rank of the column within the table
1906 # being indexed, or -1 if the index-column is the rowid of the table
1907 # being indexed and -2 if the index is on an expression.
1909 # (The third column of output from PRAGMA index_xinfo is...)
1910 # EVIDENCE-OF: R-40641-22898 The name of the column being indexed, or
1911 # NULL if the index-column is the rowid of the table being indexed or an
1914 # (The fourth column of output from PRAGMA index_xinfo is...)
1915 # EVIDENCE-OF: R-11847-09179 1 if the index-column is sorted in reverse
1916 # (DESC) order by the index and 0 otherwise.
1918 # (The fifth column of output from PRAGMA index_xinfo is...)
1919 # EVIDENCE-OF: R-15313-19540 The name for the collating sequence used to
1920 # compare values in the index-column.
1922 # (The sixth column of output from PRAGMA index_xinfo is...)
1923 # EVIDENCE-OF: R-14310-64553 1 if the index-column is a key column and 0
1924 # if the index-column is an auxiliary column.
1927 db2 eval {PRAGMA index_xinfo(i2)}
1928 } {0 2 c 0 BINARY 1 1 3 d 0 BINARY 1 2 1 b 0 BINARY 1 3 -1 {} 0 BINARY 0}
1930 db2 eval {PRAGMA index_xinfo(i2x)}
1931 } {0 3 d 0 nocase 1 1 2 c 1 BINARY 1 2 -1 {} 0 BINARY 0}
1933 db2 eval {PRAGMA index_xinfo(i3)}
1934 } {0 3 d 0 BINARY 1 1 -2 {} 0 BINARY 1 2 2 c 0 BINARY 1 3 -1 {} 0 BINARY 0}
1936 # EVIDENCE-OF: R-64103-17776 PRAGMA schema.index_list(table-name); This
1937 # pragma returns one row for each index associated with the given table.
1939 # (The first column of output from PRAGMA index_list is...)
1940 # EVIDENCE-OF: R-02753-24748 A sequence number assigned to each index
1941 # for internal tracking purposes.
1943 # (The second column of output from PRAGMA index_list is...)
1944 # EVIDENCE-OF: R-35496-03635 The name of the index.
1946 # (The third column of output from PRAGMA index_list is...)
1947 # EVIDENCE-OF: R-57301-64506 "1" if the index is UNIQUE and "0" if not.
1949 # (The fourth column of output from PRAGMA index_list is...)
1950 # EVIDENCE-OF: R-36609-39554 "c" if the index was created by a CREATE
1951 # INDEX statement, "u" if the index was created by a UNIQUE constraint,
1952 # or "pk" if the index was created by a PRIMARY KEY constraint.
1956 DROP INDEX IF EXISTS i3;
1957 CREATE INDEX i3 ON t1(d,b,c);
1959 capture_pragma db2 out {PRAGMA index_list(t1)}
1960 db2 eval {SELECT seq, name, "unique", origin, '|' FROM out ORDER BY seq}
1961 } {0 i3 0 c | 1 i2 0 c | 2 i2x 0 c | 3 i1 0 c |}
1962 ifcapable altertable {
1965 ALTER TABLE t1 ADD COLUMN e;
1968 PRAGMA table_info(t1);
1975 CREATE TABLE t2(x, y INTEGER REFERENCES t1);
1978 PRAGMA foreign_key_list(t2);
1980 } {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE}
1983 ifcapable !has_codec {
1985 do_execsql_test 24.0 {
1986 PRAGMA page_size = 1024;
1987 CREATE TABLE t1(a, b, c);
1988 CREATE INDEX i1 ON t1(b);
1989 INSERT INTO t1 VALUES('a', 'b', 'c');
1990 PRAGMA integrity_check;
1993 set r [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1'}]
1995 hexio_write test.db [expr $r*1024 - 16] 000000000000000701040f0f1f616263
1998 do_catchsql_test 24.1 {
2000 } {1 {database disk image is malformed}}
2001 do_catchsql_test 24.2 {
2002 PRAGMA integrity_check;
2003 } {0 {{database disk image is malformed}}}
2005 database_never_corrupt