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/fts5blob.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 / fts5blob.test` 166 lines ยท 4670 bytes Raw Blame History 1 # 2024 July 30 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 verifies that: 13 # 14 # * blob values may be written to locale=0 tables. 15 # 16 # * blob values - other than fts5_locale() values - may not be written 17 # to locale=0 tables. This is an SQLITE_MISMATCH error 18 # 19 # * blob values may be returned by queries on the external-content table 20 # of a locale=0 table. 21 # 22 # * blob values not may be returned by queries on the external-content 23 # table of a locale=1 table, apart from fts5_locale() blobs. This is an 24 # SQLITE_MISMATCH error. 25 # 26 27 source [file join [file dirname [info script]] fts5_common.tcl] 28 set testprefix fts5blob 29 30 # If SQLITE_ENABLE_FTS5 is not defined, omit this file. 31 ifcapable !fts5 { 32 finish_test 33 return 34 } 35 36 # Test that blobs may be stored in normal locale=0 tables. 37 # 38 foreach {tn enc} { 39 1 utf8 40 2 utf16 41 } { 42 reset_db 43 fts5_aux_test_functions db 44 45 execsql "PRAGMA encoding = $enc" 46 47 execsql " 48 CREATE VIRTUAL TABLE t1 USING fts5(x, y); 49 " 50 do_execsql_test 1.$tn.0 { 51 CREATE VIRTUAL TABLE tt USING fts5vocab('t1', 'instance'); 52 INSERT INTO t1(rowid, x, y) VALUES(1, 555, X'`0000000041424320444546`'); 53 INSERT INTO t1(rowid, x, y) VALUES(2, 666, X'`41424300444546`'); 54 INSERT INTO t1(rowid, x, y) VALUES(3, 777, 'xyz'); 55 } 56 57 do_execsql_test 1.$tn.1 { 58 SELECT rowid, quote(x), quote(y) FROM t1 59 } { 60 1 555 X'`0000000041424320444546`' 61 2 666 X'`41424300444546`' 62 3 777 'xyz' 63 } 64 65 do_execsql_test 1.$tn.2 { 66 DELETE FROM t1 WHERE rowid=2; 67 DELETE FROM t1 WHERE rowid=1; 68 } 69 70 do_execsql_test 1.$tn.3 { 71 PRAGMA integrity_check; 72 } {ok} 73 } 74 75 #-------------------------------------------------------------------------- 76 # Test that a blob may be stored and retrieved in an unindexed column of 77 # a regular table with locale=1. 78 # 79 reset_db 80 do_execsql_test 2.0 { 81 CREATE VIRTUAL TABLE t1 USING fts5(x, y UNINDEXED, locale=1); 82 INSERT INTO t1(rowid, x, y) VALUES(12, 'twelve', X'`0000000041424320444546`'); 83 } 84 85 do_execsql_test 2.1 { 86 select rowid, x, quote(y) FROM t1 87 } { 88 12 twelve X'`0000000041424320444546`' 89 } 90 91 #-------------------------------------------------------------------------- 92 # Test that blobs may not be written to any type of table with locale=1 93 # set. Except, they may be written to UNINDEXED columns. 94 # 95 reset_db 96 do_execsql_test 3.0 { 97 CREATE TABLE t1(a, b); 98 99 CREATE VIRTUAL TABLE x1 USING fts5(a, b, locale=1); 100 CREATE VIRTUAL TABLE x2 USING fts5(a, b, locale=1, content=t2); 101 CREATE VIRTUAL TABLE x3 USING fts5(a, b, locale=1, content=); 102 } 103 104 do_catchsql_test 3.1 { 105 INSERT INTO x1(rowid, a, b) VALUES(113, 'hello world', X'123456'); 106 } {0 {}} 107 do_catchsql_test 3.2 { 108 INSERT INTO x2(rowid, a, b) VALUES(113, 'hello world', X'123456'); 109 } {0 {}} 110 do_catchsql_test 3.3 { 111 INSERT INTO x3(rowid, a, b) VALUES(113, 'hello world', X'123456'); 112 } {0 {}} 113 114 115 #-------------------------------------------------------------------------- 116 # Test that fts5_locale() values may not be written to any type of table 117 # without locale=1 set. Even to an UNINDEXED column. 118 # 119 reset_db 120 do_execsql_test 3.0 { 121 CREATE TABLE t1(a, b); 122 123 CREATE VIRTUAL TABLE x1 USING fts5(a, b); 124 CREATE VIRTUAL TABLE x2 USING fts5(a, b, content=t2); 125 CREATE VIRTUAL TABLE x3 USING fts5(a, b, content=); 126 127 CREATE VIRTUAL TABLE x4 USING fts5(a, b, c UNINDEXED); 128 } 129 130 do_catchsql_test 3.1 { 131 INSERT INTO x1(rowid, a, b) 132 VALUES(113, 'hello world', fts5_locale('en_AU', 'abc')); 133 } {1 {fts5_locale() requires locale=1}} 134 do_catchsql_test 3.2 { 135 INSERT INTO x2(rowid, a, b) 136 VALUES(113, 'hello world', fts5_locale('en_AU', 'abc')); 137 } {1 {fts5_locale() requires locale=1}} 138 do_catchsql_test 3.3 { 139 INSERT INTO x3(rowid, a, b) 140 VALUES(113, 'hello world', fts5_locale('en_AU', 'abc')); 141 } {1 {fts5_locale() requires locale=1}} 142 do_catchsql_test 3.4 { 143 INSERT INTO x4(rowid, a, b, c) 144 VALUES(113, 'hello world', 'yesno', fts5_locale('en_AU', 'abc')); 145 } {1 {fts5_locale() requires locale=1}} 146 147 148 #------------------------------------------------------------------------- 149 # 150 reset_db 151 do_execsql_test 4.0 { 152 CREATE VIRTUAL TABLE x1 USING fts5(x); 153 } 154 155 foreach {tn sql} { 156 1 { INSERT INTO x1(rowid, x) VALUES(4.5, 'abcd') } 157 2 { INSERT INTO x1(rowid, x) VALUES('xyz', 'abcd') } 158 3 { INSERT INTO x1(rowid, x) VALUES(X'001122', 'abcd') } 159 } { 160 do_catchsql_test 4.1.$tn $sql {1 {datatype mismatch}} 161 } 162 163 164 finish_test 165 166