| OLD | NEW |
| 1 # 2015 April 21 | 1 # 2015 April 21 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 proc random_doc {vocab nWord} { | 57 proc random_doc {vocab nWord} { |
| 58 set doc "" | 58 set doc "" |
| 59 set nVocab [llength $vocab] | 59 set nVocab [llength $vocab] |
| 60 for {set i 0} {$i<$nWord} {incr i} { | 60 for {set i 0} {$i<$nWord} {incr i} { |
| 61 set j [expr {int(rand() * $nVocab)}] | 61 set j [expr {int(rand() * $nVocab)}] |
| 62 lappend doc [lindex $vocab $j] | 62 lappend doc [lindex $vocab $j] |
| 63 } | 63 } |
| 64 return $doc | 64 return $doc |
| 65 } | 65 } |
| 66 | 66 |
| 67 set vocab [build_vocab1] | 67 foreach_detail_mode $testprefix { |
| 68 db func r random_doc | |
| 69 | 68 |
| 70 do_execsql_test 1.0 { | 69 set vocab [build_vocab1] |
| 71 CREATE VIRTUAL TABLE eee USING fts5(e, ee); | 70 db func r random_doc |
| 72 BEGIN; | 71 |
| 73 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100) | 72 do_execsql_test 1.0 { |
| 74 INSERT INTO eee SELECT r($vocab, 5), r($vocab, 7) FROM ii; | 73 CREATE VIRTUAL TABLE eee USING fts5(e, ee, detail=%DETAIL%); |
| 74 BEGIN; |
| 75 WITH ii(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<100) |
| 76 INSERT INTO eee SELECT r($vocab, 5), r($vocab, 7) FROM ii; |
| 77 INSERT INTO eee(eee) VALUES('integrity-check'); |
| 78 COMMIT; |
| 75 INSERT INTO eee(eee) VALUES('integrity-check'); | 79 INSERT INTO eee(eee) VALUES('integrity-check'); |
| 76 COMMIT; | 80 } |
| 77 INSERT INTO eee(eee) VALUES('integrity-check'); | 81 |
| 78 } | 82 set hash [sqlite3_fts5_token_hash 1024 xyz] |
| 83 set vocab [build_vocab1 -prefix xyz -hash $hash] |
| 84 lappend vocab xyz |
| 85 |
| 86 do_execsql_test 1.1 { |
| 87 CREATE VIRTUAL TABLE vocab USING fts5vocab(eee, 'row'); |
| 88 BEGIN; |
| 89 } |
| 90 do_test 1.2 { |
| 91 for {set i 1} {$i <= 100} {incr i} { |
| 92 execsql { INSERT INTO eee VALUES( r($vocab, 5), r($vocab, 7) ) } |
| 93 } |
| 94 } {} |
| 95 |
| 96 do_test 1.3 { |
| 97 db eval { SELECT term, doc FROM vocab } { |
| 98 set nRow [db one {SELECT count(*) FROM eee WHERE eee MATCH $term}] |
| 99 if {$nRow != $doc} { |
| 100 error "term=$term fts5vocab=$doc cnt=$nRow" |
| 101 } |
| 102 } |
| 103 set {} {} |
| 104 } {} |
| 105 |
| 106 do_execsql_test 1.4 { |
| 107 COMMIT; |
| 108 INSERT INTO eee(eee) VALUES('integrity-check'); |
| 109 } |
| 79 | 110 |
| 80 set hash [sqlite3_fts5_token_hash 1024 xyz] | 111 #----------------------------------------------------------------------- |
| 81 set vocab [build_vocab1 -prefix xyz -hash $hash] | 112 # Add a small and very large token with the same hash value to an |
| 82 lappend vocab xyz | 113 # empty table. At one point this would provoke an asan error. |
| 114 # |
| 115 do_test 2.0 { |
| 116 set big [string repeat 12345 40] |
| 117 set hash [sqlite3_fts5_token_hash 1024 $big] |
| 118 while {1} { |
| 119 set small [random_token] |
| 120 if {[sqlite3_fts5_token_hash 1024 $small]==$hash} break |
| 121 } |
| 83 | 122 |
| 84 do_execsql_test 1.1 { | 123 execsql { CREATE VIRTUAL TABLE t2 USING fts5(x, detail=%DETAIL%) } |
| 85 CREATE VIRTUAL TABLE vocab USING fts5vocab(eee, 'row'); | 124 breakpoint |
| 86 BEGIN; | 125 execsql { |
| 87 } | 126 INSERT INTO t2 VALUES($small || ' ' || $big); |
| 88 do_test 1.2 { | |
| 89 for {set i 1} {$i <= 100} {incr i} { | |
| 90 execsql { INSERT INTO eee VALUES( r($vocab, 5), r($vocab, 7) ) } | |
| 91 } | |
| 92 } {} | |
| 93 | |
| 94 do_test 1.2 { | |
| 95 db eval { SELECT term, doc FROM vocab } { | |
| 96 set nRow [db one {SELECT count(*) FROM eee WHERE eee MATCH $term}] | |
| 97 if {$nRow != $doc} { | |
| 98 error "term=$term fts5vocab=$doc cnt=$nRow" | |
| 99 } | 127 } |
| 100 } | 128 } {} |
| 101 set {} {} | |
| 102 } {} | |
| 103 | 129 |
| 104 do_execsql_test 1.3 { | 130 } ;# foreach_detail_mode |
| 105 COMMIT; | |
| 106 INSERT INTO eee(eee) VALUES('integrity-check'); | |
| 107 } | |
| 108 | 131 |
| 109 finish_test | 132 finish_test |
| 110 | 133 |
| OLD | NEW |