CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
fts3fault.test272 linesDownload Raw Back to test
1# 2010 June 152#3# The author disclaims copyright to this source code.  In place of4# 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#12 13set testdir [file dirname $argv0]14source $testdir/tester.tcl15 16set ::testprefix fts3fault17 18# If SQLITE_ENABLE_FTS3 is not defined, omit this file.19ifcapable !fts3 { finish_test ; return }20 21set ::TMPDBERROR [list 1 \22  {unable to open a temporary database file for storing temporary tables}23]24 25# Test error handling in the sqlite3Fts3Init() function. This is the 26# function that registers the FTS3 module and various support functions27# with SQLite.28#29do_faultsim_test 1 -body { 30  sqlite3 db test.db 31  expr 032} -test {33  catch { db close }34}35 36# Test error handling in an "ALTER TABLE ... RENAME TO" statement on an37# FTS3 table. Specifically, test renaming the table within a transaction38# after it has been written to.39#40faultsim_delete_and_reopen41do_execsql_test 2.0 {42  CREATE VIRTUAL TABLE t1 USING fts3;43  INSERT INTO t1 VALUES('test renaming the table');44  INSERT INTO t1 VALUES(' after it has been written');45}46do_faultsim_test 2 -prep { 47  sqlite3 db test.db48  execsql {49    BEGIN;50      INSERT INTO t1 VALUES('registers the FTS3 module');51      INSERT INTO t1 VALUES('various support functions');52  }53} -body {54  execsql { ALTER TABLE t1 RENAME TO t2 }55} -test {56  faultsim_test_result {0 {}} $::TMPDBERROR57}58 59# Test error handling in the special case where a single prefix query 60# matches terms that reside on a large range of leaf nodes.61#62do_test fts3fault-3.0 {63  sqlite3 db test.db64  execsql { CREATE VIRTUAL TABLE t3 USING fts4; }65  execsql { INSERT INTO t3(t3) VALUES('nodesize=50') }66  execsql { BEGIN }67  for {set i 0} {$i < 1000} {incr i} {68    execsql { INSERT INTO t3 VALUES('aaa' || $i) }69  }70  execsql { COMMIT }71} {}72 73do_faultsim_test 3 -faults oom-transient -prep { 74  sqlite3 db test.db75  execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' }76} -body {77  execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' }78} -test {79  faultsim_test_result {0 1000} 80}81 82do_test fts3fault-4.0 {83  faultsim_delete_and_reopen84  execsql { 85    CREATE VIRTUAL TABLE t4 USING fts4; 86    INSERT INTO t4 VALUES('The British Government called on');87    INSERT INTO t4 VALUES('as pesetas then became much');88  }89} {}90faultsim_save_and_close91do_faultsim_test 4 -prep { 92  faultsim_restore_and_reopen93  execsql { SELECT content FROM t4 }94} -body {95  execsql { SELECT optimize(t4) FROM t4 LIMIT 1 }96} -test {97  faultsim_test_result {0 {{Index optimized}}}98}99 100do_test fts3fault-5.0 {101  faultsim_delete_and_reopen102  execsql { 103    CREATE VIRTUAL TABLE t5 USING fts4; 104    INSERT INTO t5 VALUES('The British Government called on');105    INSERT INTO t5 VALUES('as pesetas then became much');106  }107} {}108faultsim_save_and_close109do_faultsim_test 5 -prep { 110  faultsim_restore_and_reopen111  execsql { 112    BEGIN;113      INSERT INTO t5 VALUES('influential in shaping his future outlook');114      INSERT INTO t5 VALUES('might be acceptable to the British electorate');115  }116} -body {117  execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' }118} -test {119  faultsim_test_result {0 {1 4}}120}121 122do_test fts3fault-6.0 {123  faultsim_delete_and_reopen124  execsql { CREATE VIRTUAL TABLE t6 USING fts4 }125} {}126faultsim_save_and_close127do_faultsim_test 6 -prep { 128  faultsim_restore_and_reopen129  execsql { SELECT rowid FROM t6 }130} -body {131  execsql { DROP TABLE t6 }132} -test {133  faultsim_test_result {0 {}}134}135 136# Test various malloc failures while processing FTS4 parameters.137#138do_faultsim_test 7.1 -prep { 139  faultsim_delete_and_reopen140} -body {141  execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) }142} -test {143  faultsim_test_result {0 {}}144}145do_faultsim_test 7.2 -prep { 146  faultsim_delete_and_reopen147} -body {148  execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) }149} -test {150  faultsim_test_result {1 {unrecognized matchinfo: fs3}} \151                       {1 {vtable constructor failed: t1}} \152                       {1 {SQL logic error}}153}154do_faultsim_test 7.3 -prep { 155  faultsim_delete_and_reopen156} -body {157  execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) }158} -test {159  faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \160                       {1 {vtable constructor failed: t1}} \161                       {1 {SQL logic error}}162}163 164 165proc mit {blob} {166  set scan(littleEndian) i*167  set scan(bigEndian) I*168  binary scan $blob $scan($::tcl_platform(byteOrder)) r169  return $r170}171 172do_test 8.0 {173  faultsim_delete_and_reopen174  execsql { CREATE VIRTUAL TABLE t8 USING fts4 }175  execsql "INSERT INTO t8 VALUES('a b c')"176  execsql "INSERT INTO t8 VALUES('b b b')"177  execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')"178  execsql "INSERT INTO t8 VALUES('d d d')"179  execsql "INSERT INTO t8 VALUES('e e e')"180  execsql "INSERT INTO t8(t8) VALUES('optimize')"181  faultsim_save_and_close182} {}183 184ifcapable fts4_deferred {185  do_faultsim_test 8.1 -faults oom-t* -prep { 186    faultsim_restore_and_reopen187    db func mit mit188  } -body {189    execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }190  } -test {191    faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}192  }193}194 195do_faultsim_test 8.2 -faults oom-t* -prep { 196  faultsim_restore_and_reopen197  db func mit mit198} -body {199  execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }200} -test {201  faultsim_test_result {0 3} $::TMPDBERROR202}203do_faultsim_test 8.3 -prep { 204  faultsim_restore_and_reopen205  db func mit mit206} -body {207  execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }208} -test {209  faultsim_test_result {0 10002}210}211do_faultsim_test 8.4 -prep { 212  faultsim_restore_and_reopen213  db func mit mit214} -body {215  execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }216} -test {217  faultsim_test_result {0 3}218}219do_faultsim_test 8.5 -prep { 220  faultsim_restore_and_reopen221  db func mit mit222} -body {223  execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH '"a b c"' }224} -test {225  faultsim_test_result {0 3}226}227 228do_test 9.0 {229  faultsim_delete_and_reopen230  execsql {231    CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);232    INSERT INTO t9 VALUES(233      'this record is used toooooooooooooooooooooooooooooooooooooo try to'234    );235    SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';236  }237  faultsim_save_and_close238} {}239do_faultsim_test 9.1 -prep {240  faultsim_restore_and_reopen241} -body {242  execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }243} -test {244  faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}245}246 247do_faultsim_test 10.1 -prep {248  faultsim_delete_and_reopen249} -body {250  execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) }251} -test {252  faultsim_test_result {0 {}}253}254 255#-------------------------------------------------------------------------256reset_db257do_execsql_test 11.0 {258  CREATE VIRTUAL TABLE t1 USING fts3(a, b);259}260faultsim_save_and_close261 262do_faultsim_test 11 -faults oom* -prep {263  faultsim_restore_and_reopen264} -body {265  execsql { DROP TABLE t1 }266} -test {267  faultsim_test_result {0 {}}268}269 270 271finish_test272