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 # Test recover module syntax.
17 # TODO(shess): Test with attached databases.
19 # TODO(shess): Handle column mismatches? As things stand, the code
20 # only needs to pull the root page, so that may not be completely
23 set testdir [file dirname $argv0]
24 source $testdir/tester.tcl
27 DROP TABLE IF EXISTS backing;
28 CREATE TABLE backing (t TEXT);
30 DROP TABLE IF EXISTS backing2;
31 CREATE TABLE backing2 (id INTEGER PRIMARY KEY, t TEXT);
34 # Baseline create works.
35 do_test recover-syntax-0.0 {
36 db eval {DROP TABLE IF EXISTS temp.syntax}
38 CREATE VIRTUAL TABLE temp.syntax USING recover(
45 # Can specify database.
46 do_test recover-syntax-0.1 {
47 db eval {DROP TABLE IF EXISTS temp.syntax}
49 CREATE VIRTUAL TABLE temp.syntax USING recover(
56 # Can specify sqlite_master.
57 do_test recover-syntax-0.2 {
58 db eval {DROP TABLE IF EXISTS temp.syntax}
60 CREATE VIRTUAL TABLE temp.syntax USING recover(
71 # Fails if virtual table is not in the temp database.
72 do_test recover-syntax-1.0 {
73 db eval {DROP TABLE IF EXISTS temp.syntax;}
75 CREATE VIRTUAL TABLE syntax USING recover(
80 } {1 {recover table must be in temp database}}
82 # Fails if mentions missing table.
83 do_test recover-syntax-2.0 {
84 db eval {DROP TABLE IF EXISTS temp.syntax;}
86 CREATE VIRTUAL TABLE temp.syntax USING recover(
91 } {1 {unable to find backing table}}
93 # Fails if mentions missing database.
94 do_test recover-syntax-2.1 {
95 db eval {DROP TABLE IF EXISTS temp.syntax;}
97 CREATE VIRTUAL TABLE temp.syntax USING recover(
102 } {1 {unable to find backing table}}
104 # Fails if mentions garbage backing.
105 do_test recover-syntax-2.2 {
106 db eval {DROP TABLE IF EXISTS temp.syntax;}
108 CREATE VIRTUAL TABLE temp.syntax USING recover(
113 } {1 {unable to find backing table}}
115 # Database only fails.
116 do_test recover-syntax-2.3 {
117 db eval {DROP TABLE IF EXISTS temp.syntax;}
119 CREATE VIRTUAL TABLE temp.syntax USING recover(
124 } {1 {ill-formed table specifier}}
127 do_test recover-syntax-2.4 {
128 db eval {DROP TABLE IF EXISTS temp.syntax;}
130 CREATE VIRTUAL TABLE temp.syntax USING recover(
135 } {1 {ill-formed table specifier}}
138 do_test recover-syntax-3.0 {
139 db eval {DROP TABLE IF EXISTS temp.syntax}
141 CREATE VIRTUAL TABLE temp.syntax USING recover(
145 PRAGMA table_info(syntax);
149 # ANY as an alternative for manifest typing.
150 do_test recover-syntax-3.1 {
151 db eval {DROP TABLE IF EXISTS temp.syntax}
153 CREATE VIRTUAL TABLE temp.syntax USING recover(
157 PRAGMA table_info(syntax);
162 do_test recover-syntax-3.2 {
163 db eval {DROP TABLE IF EXISTS temp.syntax}
165 CREATE VIRTUAL TABLE temp.syntax USING recover(
169 PRAGMA table_info(syntax);
173 # ANY STRICT is not sensible.
174 do_test recover-syntax-3.3 {
175 db eval {DROP TABLE IF EXISTS temp.syntax}
177 CREATE VIRTUAL TABLE temp.syntax USING recover(
181 PRAGMA table_info(syntax);
183 } {1 {unable to parse column 0}}
185 # TEXT column by type works.
186 do_test recover-syntax-4.0 {
187 db eval {DROP TABLE IF EXISTS temp.syntax}
189 CREATE VIRTUAL TABLE temp.syntax USING recover(
193 PRAGMA table_info(syntax);
198 do_test recover-syntax-4.1 {
199 db eval {DROP TABLE IF EXISTS temp.syntax}
201 CREATE VIRTUAL TABLE temp.syntax USING recover(
205 PRAGMA table_info(syntax);
210 do_test recover-syntax-4.2 {
211 db eval {DROP TABLE IF EXISTS temp.syntax}
213 CREATE VIRTUAL TABLE temp.syntax USING recover(
217 PRAGMA table_info(syntax);
221 # TEXT STRICT NOT NULL
222 do_test recover-syntax-4.3 {
223 db eval {DROP TABLE IF EXISTS temp.syntax}
225 CREATE VIRTUAL TABLE temp.syntax USING recover(
227 t TEXT STRICT NOT NULL
229 PRAGMA table_info(syntax);
234 do_test recover-syntax-5.0 {
235 db eval {DROP TABLE IF EXISTS temp.syntax}
237 CREATE VIRTUAL TABLE temp.syntax USING recover(
241 PRAGMA table_info(syntax);
243 } {0 i INTEGER 0 {} 0}
246 do_test recover-syntax-5.1 {
247 db eval {DROP TABLE IF EXISTS temp.syntax}
249 CREATE VIRTUAL TABLE temp.syntax USING recover(
253 PRAGMA table_info(syntax);
255 } {0 i INTEGER 1 {} 0}
258 do_test recover-syntax-5.2 {
259 db eval {DROP TABLE IF EXISTS temp.syntax}
261 CREATE VIRTUAL TABLE temp.syntax USING recover(
265 PRAGMA table_info(syntax);
267 } {0 i INTEGER 0 {} 0}
269 # INTEGER STRICT NOT NULL
270 do_test recover-syntax-5.3 {
271 db eval {DROP TABLE IF EXISTS temp.syntax}
273 CREATE VIRTUAL TABLE temp.syntax USING recover(
275 i INTEGER STRICT NOT NULL
277 PRAGMA table_info(syntax);
279 } {0 i INTEGER 1 {} 0}
282 do_test recover-syntax-6.0 {
283 db eval {DROP TABLE IF EXISTS temp.syntax}
285 CREATE VIRTUAL TABLE temp.syntax USING recover(
289 PRAGMA table_info(syntax);
294 do_test recover-syntax-6.1 {
295 db eval {DROP TABLE IF EXISTS temp.syntax}
297 CREATE VIRTUAL TABLE temp.syntax USING recover(
301 PRAGMA table_info(syntax);
306 do_test recover-syntax-6.2 {
307 db eval {DROP TABLE IF EXISTS temp.syntax}
309 CREATE VIRTUAL TABLE temp.syntax USING recover(
313 PRAGMA table_info(syntax);
317 # BLOB STRICT NOT NULL
318 do_test recover-syntax-6.3 {
319 db eval {DROP TABLE IF EXISTS temp.syntax}
321 CREATE VIRTUAL TABLE temp.syntax USING recover(
323 b BLOB STRICT NOT NULL
325 PRAGMA table_info(syntax);
330 do_test recover-syntax-7.0 {
331 db eval {DROP TABLE IF EXISTS temp.syntax}
333 CREATE VIRTUAL TABLE temp.syntax USING recover(
337 PRAGMA table_info(syntax);
342 do_test recover-syntax-7.1 {
343 db eval {DROP TABLE IF EXISTS temp.syntax}
345 CREATE VIRTUAL TABLE temp.syntax USING recover(
349 PRAGMA table_info(syntax);
354 do_test recover-syntax-7.2 {
355 db eval {DROP TABLE IF EXISTS temp.syntax}
357 CREATE VIRTUAL TABLE temp.syntax USING recover(
361 PRAGMA table_info(syntax);
365 # FLOAT STRICT NOT NULL
366 do_test recover-syntax-7.3 {
367 db eval {DROP TABLE IF EXISTS temp.syntax}
369 CREATE VIRTUAL TABLE temp.syntax USING recover(
371 f FLOAT STRICT NOT NULL
373 PRAGMA table_info(syntax);
378 do_test recover-syntax-8.0 {
379 db eval {DROP TABLE IF EXISTS temp.syntax}
381 CREATE VIRTUAL TABLE temp.syntax USING recover(
385 PRAGMA table_info(syntax);
387 } {0 f NUMERIC 0 {} 0}
390 do_test recover-syntax-8.1 {
391 db eval {DROP TABLE IF EXISTS temp.syntax}
393 CREATE VIRTUAL TABLE temp.syntax USING recover(
397 PRAGMA table_info(syntax);
399 } {0 f NUMERIC 1 {} 0}
402 do_test recover-syntax-8.2 {
403 db eval {DROP TABLE IF EXISTS temp.syntax}
405 CREATE VIRTUAL TABLE temp.syntax USING recover(
409 PRAGMA table_info(syntax);
411 } {0 f NUMERIC 0 {} 0}
413 # NUMERIC STRICT NOT NULL
414 do_test recover-syntax-8.3 {
415 db eval {DROP TABLE IF EXISTS temp.syntax}
417 CREATE VIRTUAL TABLE temp.syntax USING recover(
419 f NUMERIC STRICT NOT NULL
421 PRAGMA table_info(syntax);
423 } {0 f NUMERIC 1 {} 0}
426 do_test recover-syntax-9.0 {
427 db eval {DROP TABLE IF EXISTS temp.syntax}
429 CREATE VIRTUAL TABLE temp.syntax USING recover(
434 PRAGMA table_info(syntax);
436 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
438 # ROWID NOT NULL (is default)
439 do_test recover-syntax-9.1 {
440 db eval {DROP TABLE IF EXISTS temp.syntax}
442 CREATE VIRTUAL TABLE temp.syntax USING recover(
447 PRAGMA table_info(syntax);
449 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
452 do_test recover-syntax-9.0 {
453 db eval {DROP TABLE IF EXISTS temp.syntax}
455 CREATE VIRTUAL TABLE temp.syntax USING recover(
460 PRAGMA table_info(syntax);
462 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
464 # ROWID STRICT NOT NULL (is default)
465 do_test recover-syntax-9.1 {
466 db eval {DROP TABLE IF EXISTS temp.syntax}
468 CREATE VIRTUAL TABLE temp.syntax USING recover(
470 id ROWID STRICT NOT NULL,
473 PRAGMA table_info(syntax);
475 } {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
477 # Invalid type info is not ignored.
478 do_test recover-syntax-10.0 {
479 db eval {DROP TABLE IF EXISTS temp.syntax}
481 CREATE VIRTUAL TABLE temp.syntax USING recover(
486 } {1 {unable to parse column 0}}
488 # Extraneous type info is not ignored.
489 do_test recover-syntax-10.1 {
490 db eval {DROP TABLE IF EXISTS temp.syntax}
492 CREATE VIRTUAL TABLE temp.syntax USING recover(
497 } {1 {unable to parse column 0}}
499 # Extraneous type info is not ignored.
500 do_test recover-syntax-10.2 {
501 db eval {DROP TABLE IF EXISTS temp.syntax}
503 CREATE VIRTUAL TABLE temp.syntax USING recover(
505 v INTEGER NOT NULL GARBAGE
508 } {1 {unable to parse column 0}}
510 # Multiple types don't work.
511 do_test recover-syntax-10.3 {
512 db eval {DROP TABLE IF EXISTS temp.syntax}
514 CREATE VIRTUAL TABLE temp.syntax USING recover(
519 } {1 {unable to parse column 0}}
521 # Multiple types don't work.
522 do_test recover-syntax-10.4 {
523 db eval {DROP TABLE IF EXISTS temp.syntax}
525 CREATE VIRTUAL TABLE temp.syntax USING recover(
527 v INTEGER NOT NULL TEXT
530 } {1 {unable to parse column 0}}