OLD | NEW |
1 # 2007 April 6 | 1 # 2007 April 6 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # This file implements regression tests for SQLite library. | 11 # This file implements regression tests for SQLite library. |
12 # | 12 # |
13 # This file implements tests to verify database file format. | 13 # This file implements tests to verify database file format. |
14 # | 14 # |
15 # $Id: filefmt.test,v 1.3 2009/06/18 11:34:43 drh Exp $ | 15 # $Id: filefmt.test,v 1.3 2009/06/18 11:34:43 drh Exp $ |
16 | 16 |
17 set testdir [file dirname $argv0] | 17 set testdir [file dirname $argv0] |
18 source $testdir/tester.tcl | 18 source $testdir/tester.tcl |
| 19 |
| 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). |
| 22 # |
| 23 do_not_use_codec |
| 24 |
19 db close | 25 db close |
20 file delete -force test.db test.db-journal | 26 file delete -force test.db test.db-journal |
21 | 27 |
22 # Database begins with valid 16-byte header string. | 28 # Database begins with valid 16-byte header string. |
23 # | 29 # |
24 do_test filefmt-1.1 { | 30 do_test filefmt-1.1 { |
25 sqlite3 db test.db | 31 sqlite3 db test.db |
26 db eval {CREATE TABLE t1(x)} | 32 db eval {CREATE TABLE t1(x)} |
27 db close | 33 db close |
28 hexio_read test.db 0 16 | 34 hexio_read test.db 0 16 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 db eval {PRAGMA page_size=512; CREATE TABLE t1(x)} | 110 db eval {PRAGMA page_size=512; CREATE TABLE t1(x)} |
105 db close | 111 db close |
106 hexio_write test.db 20 21 | 112 hexio_write test.db 20 21 |
107 sqlite3 db test.db | 113 sqlite3 db test.db |
108 catchsql { | 114 catchsql { |
109 SELECT count(*) FROM sqlite_master | 115 SELECT count(*) FROM sqlite_master |
110 } | 116 } |
111 } {1 {file is encrypted or is not a database}} | 117 } {1 {file is encrypted or is not a database}} |
112 } | 118 } |
113 | 119 |
| 120 #------------------------------------------------------------------------- |
| 121 # The following block of tests - filefmt-2.* - test that versions 3.7.0 |
| 122 # and later can read and write databases that have been modified or created |
| 123 # by 3.6.23.1 and earlier. The difference difference is that 3.7.0 stores |
| 124 # the size of the database in the database file header, whereas 3.6.23.1 |
| 125 # always derives this from the size of the file. |
| 126 # |
| 127 db close |
| 128 file delete -force test.db |
| 129 |
| 130 set a_string_counter 1 |
| 131 proc a_string {n} { |
| 132 incr ::a_string_counter |
| 133 string range [string repeat "${::a_string_counter}." $n] 1 $n |
| 134 } |
| 135 sqlite3 db test.db |
| 136 db func a_string a_string |
| 137 |
| 138 do_execsql_test filefmt-2.1.1 { |
| 139 PRAGMA page_size = 1024; |
| 140 PRAGMA auto_vacuum = 0; |
| 141 CREATE TABLE t1(a); |
| 142 CREATE INDEX i1 ON t1(a); |
| 143 INSERT INTO t1 VALUES(a_string(3000)); |
| 144 CREATE TABLE t2(a); |
| 145 INSERT INTO t2 VALUES(1); |
| 146 } {} |
| 147 do_test filefmt-2.1.2 { |
| 148 hexio_read test.db 28 4 |
| 149 } {00000009} |
| 150 |
| 151 do_test filefmt-2.1.3 { |
| 152 sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } |
| 153 } {} |
| 154 |
| 155 do_execsql_test filefmt-2.1.4 { INSERT INTO t2 VALUES(2) } {} |
| 156 integrity_check filefmt-2.1.5 |
| 157 do_test filefmt-2.1.6 { hexio_read test.db 28 4 } {00000010} |
| 158 |
| 159 db close |
| 160 file delete -force test.db |
| 161 sqlite3 db test.db |
| 162 db func a_string a_string |
| 163 |
| 164 do_execsql_test filefmt-2.2.1 { |
| 165 PRAGMA page_size = 1024; |
| 166 PRAGMA auto_vacuum = 0; |
| 167 CREATE TABLE t1(a); |
| 168 CREATE INDEX i1 ON t1(a); |
| 169 INSERT INTO t1 VALUES(a_string(3000)); |
| 170 CREATE TABLE t2(a); |
| 171 INSERT INTO t2 VALUES(1); |
| 172 } {} |
| 173 do_test filefmt-2.2.2 { |
| 174 hexio_read test.db 28 4 |
| 175 } {00000009} |
| 176 |
| 177 do_test filefmt-2.2.3 { |
| 178 sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } |
| 179 } {} |
| 180 |
| 181 do_execsql_test filefmt-2.2.4 { |
| 182 PRAGMA integrity_check; |
| 183 BEGIN; |
| 184 INSERT INTO t2 VALUES(2); |
| 185 SAVEPOINT a; |
| 186 INSERT INTO t2 VALUES(3); |
| 187 ROLLBACK TO a; |
| 188 } {ok} |
| 189 |
| 190 integrity_check filefmt-2.2.5 |
| 191 do_execsql_test filefmt-2.2.6 { COMMIT } {} |
| 192 db close |
| 193 sqlite3 db test.db |
| 194 integrity_check filefmt-2.2.7 |
114 | 195 |
115 finish_test | 196 finish_test |
OLD | NEW |