OLD | NEW |
| (Empty) |
1 # 2014 Dec 20 | |
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 # Tests focusing on the fts5 xSetAuxdata() and xGetAuxdata() APIs. | |
13 # | |
14 | |
15 source [file join [file dirname [info script]] fts5_common.tcl] | |
16 set testprefix fts5auxdata | |
17 | |
18 # If SQLITE_ENABLE_FTS5 is 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(a, b); | |
26 INSERT INTO f1(rowid, a, b) VALUES(1, 'a', 'b1'); | |
27 INSERT INTO f1(rowid, a, b) VALUES(2, 'a', 'b2'); | |
28 INSERT INTO f1(rowid, a, b) VALUES(3, 'a', 'b3'); | |
29 INSERT INTO f1(rowid, a, b) VALUES(4, 'a', 'b4'); | |
30 INSERT INTO f1(rowid, a, b) VALUES(5, 'a', 'b5'); | |
31 } | |
32 | |
33 proc aux_function_1 {cmd tn} { | |
34 switch [$cmd xRowid] { | |
35 1 { | |
36 do_test $tn.1 [list $cmd xGetAuxdata 0 ] {} | |
37 $cmd xSetAuxdata "one" | |
38 } | |
39 | |
40 2 { | |
41 do_test $tn.2 [list $cmd xGetAuxdata 0 ] {one} | |
42 $cmd xSetAuxdata "two" | |
43 } | |
44 | |
45 3 { | |
46 do_test $tn.3 [list $cmd xGetAuxdata 0 ] {two} | |
47 } | |
48 | |
49 4 { | |
50 do_test $tn.4 [list $cmd xGetAuxdata 1 ] {two} | |
51 } | |
52 | |
53 5 { | |
54 do_test $tn.5 [list $cmd xGetAuxdata 0 ] {} | |
55 } | |
56 } | |
57 } | |
58 | |
59 sqlite3_fts5_create_function db aux_function_1 aux_function_1 | |
60 db eval { | |
61 SELECT aux_function_1(f1, 1) FROM f1 WHERE f1 MATCH 'a' | |
62 ORDER BY rowid ASC | |
63 } | |
64 | |
65 proc aux_function_2 {cmd tn inst} { | |
66 if {$inst == "A"} { | |
67 switch [$cmd xRowid] { | |
68 1 { | |
69 do_test $tn.1.$inst [list $cmd xGetAuxdata 0 ] {} | |
70 $cmd xSetAuxdata "one $inst" | |
71 } | |
72 2 { | |
73 do_test $tn.2.$inst [list $cmd xGetAuxdata 0 ] "one $inst" | |
74 $cmd xSetAuxdata "two $inst" | |
75 } | |
76 3 { | |
77 do_test $tn.3.$inst [list $cmd xGetAuxdata 0 ] "two $inst" | |
78 } | |
79 4 { | |
80 do_test $tn.4.$inst [list $cmd xGetAuxdata 1 ] "two $inst" | |
81 } | |
82 5 { | |
83 do_test $tn.5.$inst [list $cmd xGetAuxdata 0 ] {} | |
84 } | |
85 } | |
86 } else { | |
87 switch [$cmd xRowid] { | |
88 1 { | |
89 do_test $tn.1.$inst [list $cmd xGetAuxdata 0 ] "one A" | |
90 } | |
91 2 { | |
92 do_test $tn.2.$inst [list $cmd xGetAuxdata 0 ] "two A" | |
93 } | |
94 3 { | |
95 do_test $tn.3.$inst [list $cmd xGetAuxdata 0 ] "two A" | |
96 } | |
97 4 { | |
98 do_test $tn.4.$inst [list $cmd xGetAuxdata 0 ] {} | |
99 } | |
100 5 { | |
101 do_test $tn.5.$inst [list $cmd xGetAuxdata 0 ] {} | |
102 } | |
103 } | |
104 } | |
105 } | |
106 | |
107 sqlite3_fts5_create_function db aux_function_2 aux_function_2 | |
108 db eval { | |
109 SELECT aux_function_2(f1, 2, 'A'), aux_function_2(f1, 2, 'B') | |
110 FROM f1 WHERE f1 MATCH 'a' | |
111 ORDER BY rowid ASC | |
112 } | |
113 | |
114 finish_test | |
115 | |
OLD | NEW |