Skip to content

Commit b808f01

Browse files
looimattn
authored andcommitted
Add FTS4 unicode61 tokenizer support
1 parent 0d2359b commit b808f01

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

sqlite3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package sqlite3
88
/*
99
#cgo CFLAGS: -std=gnu99
1010
#cgo CFLAGS: -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE
11-
#cgo CFLAGS: -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS
11+
#cgo CFLAGS: -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61
1212
#include <sqlite3-binding.h>
1313
#include <stdlib.h>
1414
#include <string.h>

sqlite3_fts3_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,47 @@ func TestFTS3(t *testing.T) {
8181
t.Fatal("Result should be only one")
8282
}
8383
}
84+
85+
func TestFTS4(t *testing.T) {
86+
tempFilename := TempFilename()
87+
db, err := sql.Open("sqlite3", tempFilename)
88+
if err != nil {
89+
t.Fatal("Failed to open database:", err)
90+
}
91+
defer os.Remove(tempFilename)
92+
defer db.Close()
93+
94+
_, err = db.Exec("DROP TABLE foo")
95+
_, err = db.Exec("CREATE VIRTUAL TABLE foo USING fts4(tokenize=unicode61, id INTEGER PRIMARY KEY, value TEXT)")
96+
if err != nil {
97+
t.Fatal("Failed to create table:", err)
98+
}
99+
100+
_, err = db.Exec("INSERT INTO foo(id, value) VALUES(?, ?)", 1, `février`)
101+
if err != nil {
102+
t.Fatal("Failed to insert value:", err)
103+
}
104+
105+
rows, err := db.Query("SELECT value FROM foo WHERE value MATCH 'fevrier'")
106+
if err != nil {
107+
t.Fatal("Unable to query foo table:", err)
108+
}
109+
defer rows.Close()
110+
111+
var value string
112+
if !rows.Next() {
113+
t.Fatal("Result should be only one")
114+
}
115+
116+
if err := rows.Scan(&value); err != nil {
117+
t.Fatal("Unable to scan results:", err)
118+
}
119+
120+
if value != `février` {
121+
t.Fatal("Value should be `février`, but:", value)
122+
}
123+
124+
if rows.Next() {
125+
t.Fatal("Result should be only one")
126+
}
127+
}

0 commit comments

Comments
 (0)