Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/fts5/test/fts5restart.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / fts5 / test / fts5restart.test` 152 lines ยท 3810 bytes Raw Blame History 1 # 2015 April 28 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 # 12 # This file focuses on testing the planner (xBestIndex function). 13 # 14 15 source [file join [file dirname [info script]] fts5_common.tcl] 16 set testprefix fts5restart 17 18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file. 19 ifcapable !fts5 { 20 finish_test 21 return 22 } 23 24 do_execsql_test 1.0 { 25 CREATE VIRTUAL TABLE f1 USING fts5(ff); 26 } 27 28 #------------------------------------------------------------------------- 29 # Run the 'optimize' command. Check that it does not disturb ongoing 30 # full-text queries. 31 # 32 unset -nocomplain lRowid 33 do_test 1.1 { 34 for {set i 1} {$i < 1000} {incr i} { 35 execsql { INSERT INTO f1 VALUES('a b c d e') } 36 lappend lRowid $i 37 } 38 } {} 39 40 do_execsql_test 1.2 { 41 SELECT rowid FROM f1 WHERE f1 MATCH 'c'; 42 } $lRowid 43 44 do_test 1.3 { 45 set res [list] 46 db eval { SELECT rowid FROM f1 WHERE f1 MATCH 'c' } { 47 if {$rowid == 100} { 48 execsql { INSERT INTO f1(f1) VALUES('optimize') } 49 } 50 lappend res $rowid 51 } 52 set res 53 } $lRowid 54 55 do_test 1.4.1 { 56 sqlite3 db2 test.db 57 set res [list] 58 db2 eval { SELECT rowid FROM f1 WHERE f1 MATCH 'c' } { 59 if {$rowid == 100} { 60 set cres [catchsql { INSERT INTO f1(f1) VALUES('optimize') }] 61 } 62 lappend res $rowid 63 } 64 set res 65 } $lRowid 66 67 do_test 1.4.2 { 68 db2 close 69 set cres 70 } {1 {database is locked}} 71 72 #------------------------------------------------------------------------- 73 # Open a couple of cursors. Then close them in the same order. 74 # 75 do_test 2.1 { 76 set ::s1 [sqlite3_prepare db "SELECT rowid FROM f1 WHERE f1 MATCH 'b'" -1 X] 77 set ::s2 [sqlite3_prepare db "SELECT rowid FROM f1 WHERE f1 MATCH 'c'" -1 X] 78 79 sqlite3_step $::s1 80 } {SQLITE_ROW} 81 do_test 2.2 { 82 sqlite3_step $::s2 83 } {SQLITE_ROW} 84 85 do_test 2.1 { 86 sqlite3_finalize $::s1 87 sqlite3_finalize $::s2 88 } {SQLITE_OK} 89 90 #------------------------------------------------------------------------- 91 # Copy data between two FTS5 tables. 92 # 93 do_execsql_test 3.1 { 94 CREATE VIRTUAL TABLE f2 USING fts5(gg); 95 INSERT INTO f2 SELECT ff FROM f1 WHERE f1 MATCH 'b+c+d'; 96 } 97 do_execsql_test 3.2 { 98 SELECT rowid FROM f2 WHERE f2 MATCH 'a+b+c+d+e' 99 } $lRowid 100 101 #------------------------------------------------------------------------- 102 # Remove the row that an FTS5 cursor is currently pointing to. And 103 # various other similar things. Check that this does not disturb 104 # ongoing scans. 105 # 106 do_execsql_test 4.0 { 107 CREATE VIRTUAL TABLE n4 USING fts5(n); 108 INSERT INTO n4(rowid, n) VALUES(100, '1 2 3 4 5'); 109 INSERT INTO n4(rowid, n) VALUES(200, '1 2 3 4'); 110 INSERT INTO n4(rowid, n) VALUES(300, '2 3 4'); 111 INSERT INTO n4(rowid, n) VALUES(400, '2 3'); 112 INSERT INTO n4(rowid, n) VALUES(500, '3'); 113 } 114 115 do_test 4.1 { 116 set res [list] 117 db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' } { 118 if {$rowid==300} { 119 execsql { DELETE FROM n4 WHERE rowid=300 } 120 } 121 lappend res $rowid 122 } 123 set res 124 } {100 200 300 400 500} 125 126 do_test 4.2 { 127 execsql { INSERT INTO n4(rowid, n) VALUES(300, '2 3 4') } 128 set res [list] 129 db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' ORDER BY rowid DESC} { 130 if {$rowid==300} { 131 execsql { DELETE FROM n4 WHERE rowid=300 } 132 } 133 lappend res $rowid 134 } 135 set res 136 } {500 400 300 200 100} 137 138 do_test 4.3 { 139 execsql { INSERT INTO n4(rowid, n) VALUES(300, '2 3 4') } 140 set res [list] 141 db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' ORDER BY rowid DESC} { 142 if {$rowid==300} { 143 execsql { DELETE FROM n4 } 144 } 145 lappend res $rowid 146 } 147 set res 148 } {500 400 300} 149 150 151 152 finish_test