xref: /sqlite-3.40.0/test/fts3fault.test (revision e25ac099)
1*e25ac099Sdan# 2010 June 15
2*e25ac099Sdan#
3*e25ac099Sdan# The author disclaims copyright to this source code.  In place of
4*e25ac099Sdan# a legal notice, here is a blessing:
5*e25ac099Sdan#
6*e25ac099Sdan#    May you do good and not evil.
7*e25ac099Sdan#    May you find forgiveness for yourself and forgive others.
8*e25ac099Sdan#    May you share freely, never taking more than you give.
9*e25ac099Sdan#
10*e25ac099Sdan#***********************************************************************
11*e25ac099Sdan#
12*e25ac099Sdan
13*e25ac099Sdanset testdir [file dirname $argv0]
14*e25ac099Sdansource $testdir/tester.tcl
15*e25ac099Sdan
16*e25ac099Sdanset ::testprefix fts3fault
17*e25ac099Sdan
18*e25ac099Sdan# Test error handling in the sqlite3Fts3Init() function. This is the
19*e25ac099Sdan# function that registers the FTS3 module and various support functions
20*e25ac099Sdan# with SQLite.
21*e25ac099Sdan#
22*e25ac099Sdando_faultsim_test 1 -body {
23*e25ac099Sdan  sqlite3 db test.db
24*e25ac099Sdan  expr 0
25*e25ac099Sdan} -test {
26*e25ac099Sdan  catch { db close }
27*e25ac099Sdan}
28*e25ac099Sdan
29*e25ac099Sdan# Test error handling in an "ALTER TABLE ... RENAME TO" statement on an
30*e25ac099Sdan# FTS3 table. Specifically, test renaming the table within a transaction
31*e25ac099Sdan# after it has been written to.
32*e25ac099Sdan#
33*e25ac099Sdanfaultsim_delete_and_reopen
34*e25ac099Sdando_execsql_test 2.0 {
35*e25ac099Sdan  CREATE VIRTUAL TABLE t1 USING fts3;
36*e25ac099Sdan  INSERT INTO t1 VALUES('test renaming the table');
37*e25ac099Sdan  INSERT INTO t1 VALUES(' after it has been written');
38*e25ac099Sdan}
39*e25ac099Sdando_faultsim_test 2 -prep {
40*e25ac099Sdan  sqlite3 db test.db
41*e25ac099Sdan  execsql {
42*e25ac099Sdan    BEGIN;
43*e25ac099Sdan      INSERT INTO t1 VALUES('registers the FTS3 module');
44*e25ac099Sdan      INSERT INTO t1 VALUES('various support functions');
45*e25ac099Sdan  }
46*e25ac099Sdan} -body {
47*e25ac099Sdan  execsql { ALTER TABLE t1 RENAME TO t2 }
48*e25ac099Sdan} -test {
49*e25ac099Sdan  faultsim_test_result {0 {}}
50*e25ac099Sdan}
51*e25ac099Sdan
52*e25ac099Sdan# Test error handling in the special case where a single prefix query
53*e25ac099Sdan# matches terms that reside on a large range of leaf nodes.
54*e25ac099Sdan#
55*e25ac099Sdando_test fts3fault-3.0 {
56*e25ac099Sdan  sqlite3 db test.db
57*e25ac099Sdan  execsql { CREATE VIRTUAL TABLE t3 USING fts4; }
58*e25ac099Sdan  execsql { INSERT INTO t3(t3) VALUES('nodesize=50') }
59*e25ac099Sdan  execsql { BEGIN }
60*e25ac099Sdan  for {set i 0} {$i < 1000} {incr i} {
61*e25ac099Sdan    execsql { INSERT INTO t3 VALUES('aaa' || $i) }
62*e25ac099Sdan  }
63*e25ac099Sdan  execsql { COMMIT }
64*e25ac099Sdan} {}
65*e25ac099Sdan
66*e25ac099Sdando_faultsim_test 3 -faults oom-transient -prep {
67*e25ac099Sdan  sqlite3 db test.db
68*e25ac099Sdan  execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' }
69*e25ac099Sdan} -body {
70*e25ac099Sdan  execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' }
71*e25ac099Sdan} -test {
72*e25ac099Sdan  faultsim_test_result {0 1000}
73*e25ac099Sdan}
74*e25ac099Sdan
75*e25ac099Sdando_test fts3fault-4.0 {
76*e25ac099Sdan  faultsim_delete_and_reopen
77*e25ac099Sdan  execsql {
78*e25ac099Sdan    CREATE VIRTUAL TABLE t4 USING fts4;
79*e25ac099Sdan    INSERT INTO t4 VALUES('The British Government called on');
80*e25ac099Sdan    INSERT INTO t4 VALUES('as pesetas then became much');
81*e25ac099Sdan  }
82*e25ac099Sdan} {}
83*e25ac099Sdanfaultsim_save_and_close
84*e25ac099Sdando_faultsim_test 4 -prep {
85*e25ac099Sdan  faultsim_restore_and_reopen
86*e25ac099Sdan  execsql { SELECT content FROM t4 }
87*e25ac099Sdan} -body {
88*e25ac099Sdan  execsql { SELECT optimize(t4) FROM t4 LIMIT 1 }
89*e25ac099Sdan} -test {
90*e25ac099Sdan  faultsim_test_result {0 {{Index optimized}}}
91*e25ac099Sdan}
92*e25ac099Sdan
93*e25ac099Sdando_test fts3fault-5.0 {
94*e25ac099Sdan  faultsim_delete_and_reopen
95*e25ac099Sdan  execsql {
96*e25ac099Sdan    CREATE VIRTUAL TABLE t5 USING fts4;
97*e25ac099Sdan    INSERT INTO t5 VALUES('The British Government called on');
98*e25ac099Sdan    INSERT INTO t5 VALUES('as pesetas then became much');
99*e25ac099Sdan  }
100*e25ac099Sdan} {}
101*e25ac099Sdanfaultsim_save_and_close
102*e25ac099Sdando_faultsim_test 5 -prep {
103*e25ac099Sdan  faultsim_restore_and_reopen
104*e25ac099Sdan  execsql {
105*e25ac099Sdan    BEGIN;
106*e25ac099Sdan      INSERT INTO t5 VALUES('influential in shaping his future outlook');
107*e25ac099Sdan      INSERT INTO t5 VALUES('might be acceptable to the British electorate');
108*e25ac099Sdan  }
109*e25ac099Sdan} -body {
110*e25ac099Sdan  execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' }
111*e25ac099Sdan} -test {
112*e25ac099Sdan  faultsim_test_result {0 {1 4}}
113*e25ac099Sdan}
114*e25ac099Sdan
115*e25ac099Sdando_test fts3fault-6.0 {
116*e25ac099Sdan  faultsim_delete_and_reopen
117*e25ac099Sdan  execsql { CREATE VIRTUAL TABLE t6 USING fts4 }
118*e25ac099Sdan} {}
119*e25ac099Sdanfaultsim_save_and_close
120*e25ac099Sdando_faultsim_test 6 -prep {
121*e25ac099Sdan  faultsim_restore_and_reopen
122*e25ac099Sdan  execsql { SELECT rowid FROM t6 }
123*e25ac099Sdan} -body {
124*e25ac099Sdan  execsql { DROP TABLE t6 }
125*e25ac099Sdan} -test {
126*e25ac099Sdan  faultsim_test_result {0 {}}
127*e25ac099Sdan}
128*e25ac099Sdan
129*e25ac099Sdanfinish_test
130