• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 2012 January 4 {}
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.
12#
13# Test recover module syntax.
14#
15# $Id$
16
17# TODO(shess): Test with attached databases.
18
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
21# feasible.
22
23set testdir [file dirname $argv0]
24source $testdir/tester.tcl
25
26db eval {
27  DROP TABLE IF EXISTS backing;
28  CREATE TABLE backing (t TEXT);
29
30  DROP TABLE IF EXISTS backing2;
31  CREATE TABLE backing2 (id INTEGER PRIMARY KEY, t TEXT);
32}
33
34# Baseline create works.
35do_test recover-syntax-0.0 {
36  db eval {DROP TABLE IF EXISTS temp.syntax}
37  catchsql {
38    CREATE VIRTUAL TABLE temp.syntax USING recover(
39      backing,
40      t TEXT
41    );
42  }
43} {0 {}}
44
45# Can specify database.
46do_test recover-syntax-0.1 {
47  db eval {DROP TABLE IF EXISTS temp.syntax}
48  catchsql {
49    CREATE VIRTUAL TABLE temp.syntax USING recover(
50      main.backing,
51      t TEXT
52    );
53  }
54} {0 {}}
55
56# Can specify sqlite_master.
57do_test recover-syntax-0.2 {
58  db eval {DROP TABLE IF EXISTS temp.syntax}
59  catchsql {
60    CREATE VIRTUAL TABLE temp.syntax USING recover(
61      sqlite_master,
62      type TEXT,
63      name TEXT,
64      tbl_name TEXT,
65      rootpage INTEGER,
66      sql TEXT
67    );
68  }
69} {0 {}}
70
71# Fails if virtual table is not in the temp database.
72do_test recover-syntax-1.0 {
73  db eval {DROP TABLE IF EXISTS temp.syntax;}
74  catchsql {
75    CREATE VIRTUAL TABLE syntax USING recover(
76      backing,
77      t TEXT
78    );
79  }
80} {1 {recover table must be in temp database}}
81
82# Fails if mentions missing table.
83do_test recover-syntax-2.0 {
84  db eval {DROP TABLE IF EXISTS temp.syntax;}
85  catchsql {
86    CREATE VIRTUAL TABLE temp.syntax USING recover(
87      snacking,
88      t TEXT
89    );
90  }
91} {1 {unable to find backing table}}
92
93# Fails if mentions missing database.
94do_test recover-syntax-2.1 {
95  db eval {DROP TABLE IF EXISTS temp.syntax;}
96  catchsql {
97    CREATE VIRTUAL TABLE temp.syntax USING recover(
98      db.backing,
99      t TEXT
100    );
101  }
102} {1 {unable to find backing table}}
103
104# Fails if mentions garbage backing.
105do_test recover-syntax-2.2 {
106  db eval {DROP TABLE IF EXISTS temp.syntax;}
107  catchsql {
108    CREATE VIRTUAL TABLE temp.syntax USING recover(
109      main.backing excess,
110      t TEXT
111    );
112  }
113} {1 {unable to find backing table}}
114
115# Database only fails.
116do_test recover-syntax-2.3 {
117  db eval {DROP TABLE IF EXISTS temp.syntax;}
118  catchsql {
119    CREATE VIRTUAL TABLE temp.syntax USING recover(
120      main.,
121      t TEXT
122    );
123  }
124} {1 {ill-formed table specifier}}
125
126# Table only fails.
127do_test recover-syntax-2.4 {
128  db eval {DROP TABLE IF EXISTS temp.syntax;}
129  catchsql {
130    CREATE VIRTUAL TABLE temp.syntax USING recover(
131      .backing,
132      t TEXT
133    );
134  }
135} {1 {ill-formed table specifier}}
136
137# Manifest typing.
138do_test recover-syntax-3.0 {
139  db eval {DROP TABLE IF EXISTS temp.syntax}
140  execsql {
141    CREATE VIRTUAL TABLE temp.syntax USING recover(
142      backing,
143      t
144    );
145    PRAGMA table_info(syntax);
146  }
147} {0 t {} 0 {} 0}
148
149# ANY as an alternative for manifest typing.
150do_test recover-syntax-3.1 {
151  db eval {DROP TABLE IF EXISTS temp.syntax}
152  execsql {
153    CREATE VIRTUAL TABLE temp.syntax USING recover(
154      backing,
155      t ANY
156    );
157    PRAGMA table_info(syntax);
158  }
159} {0 t {} 0 {} 0}
160
161# ANY NOT NULL
162do_test recover-syntax-3.2 {
163  db eval {DROP TABLE IF EXISTS temp.syntax}
164  execsql {
165    CREATE VIRTUAL TABLE temp.syntax USING recover(
166      backing,
167      t ANY NOT NULL
168    );
169    PRAGMA table_info(syntax);
170  }
171} {0 t {} 1 {} 0}
172
173# ANY STRICT is not sensible.
174do_test recover-syntax-3.3 {
175  db eval {DROP TABLE IF EXISTS temp.syntax}
176  catchsql {
177    CREATE VIRTUAL TABLE temp.syntax USING recover(
178      backing,
179      v ANY STRICT
180    );
181    PRAGMA table_info(syntax);
182  }
183} {1 {unable to parse column 0}}
184
185# TEXT column by type works.
186do_test recover-syntax-4.0 {
187  db eval {DROP TABLE IF EXISTS temp.syntax}
188  execsql {
189    CREATE VIRTUAL TABLE temp.syntax USING recover(
190      backing,
191      t TEXT
192    );
193    PRAGMA table_info(syntax);
194  }
195} {0 t TEXT 0 {} 0}
196
197# TEXT NOT NULL
198do_test recover-syntax-4.1 {
199  db eval {DROP TABLE IF EXISTS temp.syntax}
200  execsql {
201    CREATE VIRTUAL TABLE temp.syntax USING recover(
202      backing,
203      t TEXT NOT NULL
204    );
205    PRAGMA table_info(syntax);
206  }
207} {0 t TEXT 1 {} 0}
208
209# TEXT STRICT
210do_test recover-syntax-4.2 {
211  db eval {DROP TABLE IF EXISTS temp.syntax}
212  execsql {
213    CREATE VIRTUAL TABLE temp.syntax USING recover(
214      backing,
215      t TEXT STRICT
216    );
217    PRAGMA table_info(syntax);
218  }
219} {0 t TEXT 0 {} 0}
220
221# TEXT STRICT NOT NULL
222do_test recover-syntax-4.3 {
223  db eval {DROP TABLE IF EXISTS temp.syntax}
224  execsql {
225    CREATE VIRTUAL TABLE temp.syntax USING recover(
226      backing,
227      t TEXT STRICT NOT NULL
228    );
229    PRAGMA table_info(syntax);
230  }
231} {0 t TEXT 1 {} 0}
232
233# INTEGER
234do_test recover-syntax-5.0 {
235  db eval {DROP TABLE IF EXISTS temp.syntax}
236  execsql {
237    CREATE VIRTUAL TABLE temp.syntax USING recover(
238      backing,
239      i INTEGER
240    );
241    PRAGMA table_info(syntax);
242  }
243} {0 i INTEGER 0 {} 0}
244
245# INTEGER NOT NULL
246do_test recover-syntax-5.1 {
247  db eval {DROP TABLE IF EXISTS temp.syntax}
248  execsql {
249    CREATE VIRTUAL TABLE temp.syntax USING recover(
250      backing,
251      i INTEGER NOT NULL
252    );
253    PRAGMA table_info(syntax);
254  }
255} {0 i INTEGER 1 {} 0}
256
257# INTEGER STRICT
258do_test recover-syntax-5.2 {
259  db eval {DROP TABLE IF EXISTS temp.syntax}
260  execsql {
261    CREATE VIRTUAL TABLE temp.syntax USING recover(
262      backing,
263      i INTEGER STRICT
264    );
265    PRAGMA table_info(syntax);
266  }
267} {0 i INTEGER 0 {} 0}
268
269# INTEGER STRICT NOT NULL
270do_test recover-syntax-5.3 {
271  db eval {DROP TABLE IF EXISTS temp.syntax}
272  execsql {
273    CREATE VIRTUAL TABLE temp.syntax USING recover(
274      backing,
275      i INTEGER STRICT NOT NULL
276    );
277    PRAGMA table_info(syntax);
278  }
279} {0 i INTEGER 1 {} 0}
280
281# BLOB
282do_test recover-syntax-6.0 {
283  db eval {DROP TABLE IF EXISTS temp.syntax}
284  execsql {
285    CREATE VIRTUAL TABLE temp.syntax USING recover(
286      backing,
287      b BLOB
288    );
289    PRAGMA table_info(syntax);
290  }
291} {0 b BLOB 0 {} 0}
292
293# BLOB NOT NULL
294do_test recover-syntax-6.1 {
295  db eval {DROP TABLE IF EXISTS temp.syntax}
296  execsql {
297    CREATE VIRTUAL TABLE temp.syntax USING recover(
298      backing,
299      b BLOB NOT NULL
300    );
301    PRAGMA table_info(syntax);
302  }
303} {0 b BLOB 1 {} 0}
304
305# BLOB STRICT
306do_test recover-syntax-6.2 {
307  db eval {DROP TABLE IF EXISTS temp.syntax}
308  execsql {
309    CREATE VIRTUAL TABLE temp.syntax USING recover(
310      backing,
311      b BLOB STRICT
312    );
313    PRAGMA table_info(syntax);
314  }
315} {0 b BLOB 0 {} 0}
316
317# BLOB STRICT NOT NULL
318do_test recover-syntax-6.3 {
319  db eval {DROP TABLE IF EXISTS temp.syntax}
320  execsql {
321    CREATE VIRTUAL TABLE temp.syntax USING recover(
322      backing,
323      b BLOB STRICT NOT NULL
324    );
325    PRAGMA table_info(syntax);
326  }
327} {0 b BLOB 1 {} 0}
328
329# FLOAT
330do_test recover-syntax-7.0 {
331  db eval {DROP TABLE IF EXISTS temp.syntax}
332  execsql {
333    CREATE VIRTUAL TABLE temp.syntax USING recover(
334      backing,
335      f FLOAT
336    );
337    PRAGMA table_info(syntax);
338  }
339} {0 f FLOAT 0 {} 0}
340
341# FLOAT NOT NULL
342do_test recover-syntax-7.1 {
343  db eval {DROP TABLE IF EXISTS temp.syntax}
344  execsql {
345    CREATE VIRTUAL TABLE temp.syntax USING recover(
346      backing,
347      f FLOAT NOT NULL
348    );
349    PRAGMA table_info(syntax);
350  }
351} {0 f FLOAT 1 {} 0}
352
353# FLOAT STRICT
354do_test recover-syntax-7.2 {
355  db eval {DROP TABLE IF EXISTS temp.syntax}
356  execsql {
357    CREATE VIRTUAL TABLE temp.syntax USING recover(
358      backing,
359      f FLOAT STRICT
360    );
361    PRAGMA table_info(syntax);
362  }
363} {0 f FLOAT 0 {} 0}
364
365# FLOAT STRICT NOT NULL
366do_test recover-syntax-7.3 {
367  db eval {DROP TABLE IF EXISTS temp.syntax}
368  execsql {
369    CREATE VIRTUAL TABLE temp.syntax USING recover(
370      backing,
371      f FLOAT STRICT NOT NULL
372    );
373    PRAGMA table_info(syntax);
374  }
375} {0 f FLOAT 1 {} 0}
376
377# NUMERIC
378do_test recover-syntax-8.0 {
379  db eval {DROP TABLE IF EXISTS temp.syntax}
380  execsql {
381    CREATE VIRTUAL TABLE temp.syntax USING recover(
382      backing,
383      f NUMERIC
384    );
385    PRAGMA table_info(syntax);
386  }
387} {0 f NUMERIC 0 {} 0}
388
389# NUMERIC NOT NULL
390do_test recover-syntax-8.1 {
391  db eval {DROP TABLE IF EXISTS temp.syntax}
392  execsql {
393    CREATE VIRTUAL TABLE temp.syntax USING recover(
394      backing,
395      f NUMERIC NOT NULL
396    );
397    PRAGMA table_info(syntax);
398  }
399} {0 f NUMERIC 1 {} 0}
400
401# NUMERIC STRICT
402do_test recover-syntax-8.2 {
403  db eval {DROP TABLE IF EXISTS temp.syntax}
404  execsql {
405    CREATE VIRTUAL TABLE temp.syntax USING recover(
406      backing,
407      f NUMERIC STRICT
408    );
409    PRAGMA table_info(syntax);
410  }
411} {0 f NUMERIC 0 {} 0}
412
413# NUMERIC STRICT NOT NULL
414do_test recover-syntax-8.3 {
415  db eval {DROP TABLE IF EXISTS temp.syntax}
416  execsql {
417    CREATE VIRTUAL TABLE temp.syntax USING recover(
418      backing,
419      f NUMERIC STRICT NOT NULL
420    );
421    PRAGMA table_info(syntax);
422  }
423} {0 f NUMERIC 1 {} 0}
424
425# ROWID
426do_test recover-syntax-9.0 {
427  db eval {DROP TABLE IF EXISTS temp.syntax}
428  execsql {
429    CREATE VIRTUAL TABLE temp.syntax USING recover(
430      backing2,
431      id ROWID,
432      v
433    );
434    PRAGMA table_info(syntax);
435  }
436} {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
437
438# ROWID NOT NULL (is default)
439do_test recover-syntax-9.1 {
440  db eval {DROP TABLE IF EXISTS temp.syntax}
441  execsql {
442    CREATE VIRTUAL TABLE temp.syntax USING recover(
443      backing2,
444      id ROWID NOT NULL,
445      v
446    );
447    PRAGMA table_info(syntax);
448  }
449} {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
450
451# ROWID STRICT
452do_test recover-syntax-9.0 {
453  db eval {DROP TABLE IF EXISTS temp.syntax}
454  execsql {
455    CREATE VIRTUAL TABLE temp.syntax USING recover(
456      backing2,
457      id ROWID STRICT,
458      v
459    );
460    PRAGMA table_info(syntax);
461  }
462} {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
463
464# ROWID STRICT NOT NULL (is default)
465do_test recover-syntax-9.1 {
466  db eval {DROP TABLE IF EXISTS temp.syntax}
467  execsql {
468    CREATE VIRTUAL TABLE temp.syntax USING recover(
469      backing2,
470      id ROWID STRICT NOT NULL,
471      v
472    );
473    PRAGMA table_info(syntax);
474  }
475} {0 id INTEGER 1 {} 0 1 v {} 0 {} 0}
476
477# Invalid type info is not ignored.
478do_test recover-syntax-10.0 {
479  db eval {DROP TABLE IF EXISTS temp.syntax}
480  catchsql {
481    CREATE VIRTUAL TABLE temp.syntax USING recover(
482      backing,
483      v GARBAGE
484    );
485  }
486} {1 {unable to parse column 0}}
487
488# Extraneous type info is not ignored.
489do_test recover-syntax-10.1 {
490  db eval {DROP TABLE IF EXISTS temp.syntax}
491  catchsql {
492    CREATE VIRTUAL TABLE temp.syntax USING recover(
493      backing,
494      v INTEGER GARBAGE
495    );
496  }
497} {1 {unable to parse column 0}}
498
499# Extraneous type info is not ignored.
500do_test recover-syntax-10.2 {
501  db eval {DROP TABLE IF EXISTS temp.syntax}
502  catchsql {
503    CREATE VIRTUAL TABLE temp.syntax USING recover(
504      backing,
505      v INTEGER NOT NULL GARBAGE
506    );
507  }
508} {1 {unable to parse column 0}}
509
510# Multiple types don't work.
511do_test recover-syntax-10.3 {
512  db eval {DROP TABLE IF EXISTS temp.syntax}
513  catchsql {
514    CREATE VIRTUAL TABLE temp.syntax USING recover(
515      backing,
516      v INTEGER FLOAT BLOB
517    );
518  }
519} {1 {unable to parse column 0}}
520
521# Multiple types don't work.
522do_test recover-syntax-10.4 {
523  db eval {DROP TABLE IF EXISTS temp.syntax}
524  catchsql {
525    CREATE VIRTUAL TABLE temp.syntax USING recover(
526      backing,
527      v INTEGER NOT NULL TEXT
528    );
529  }
530} {1 {unable to parse column 0}}
531
532finish_test
533