Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 6dfce4f

Browse files
committed
common: Add FTS5 functions to the SQLite authorizer white list
1 parent 7725b35 commit 6dfce4f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

common/sqlite.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import (
1616
sqlite "github.com/gwenn/gosqlite"
1717
)
1818

19+
// SqliteDebug displays some SQLite related debugging information (on the backend), when set to a non-0 value
20+
const SqliteDebug = 0
21+
1922
// SQLite Functions
2023
type function string
2124

@@ -109,6 +112,13 @@ const (
109112
fnJsonEach function = "json_each"
110113
fnJsonTree function = "json_tree"
111114

115+
// FTS5 functions
116+
fnBm25 function = "bm25"
117+
fnFts function = "fts5"
118+
fnFts5Vocab function = "fts5vocab"
119+
fnHighlight function = "highlight"
120+
fnSnippet function = "snippet"
121+
112122
// Other functions we should allow
113123
fnVersion function = "sqlite_version"
114124
)
@@ -192,6 +202,11 @@ var SQLiteFunctions = []function{
192202
fnJsonGroupObject,
193203
fnJsonEach,
194204
fnJsonTree,
205+
fnBm25,
206+
fnFts,
207+
fnFts5Vocab,
208+
fnHighlight,
209+
fnSnippet,
195210
fnVersion,
196211
}
197212

@@ -205,6 +220,11 @@ func init() {
205220
// AuthorizerLive is a SQLite authorizer callback intended to allow almost anything. Except for loading extensions,
206221
// and running pragmas.
207222
func AuthorizerLive(d interface{}, action sqlite.Action, tableName, funcName, dbName, triggerName string) sqlite.Auth {
223+
if SqliteDebug > 0 {
224+
// Display some useful debug info
225+
log.Printf("AuthorizerLive - action: '%s', table: '%s', function: '%s'", action, tableName, funcName)
226+
}
227+
208228
switch action {
209229
case sqlite.Pragma:
210230
// The "index_info" and "table_info" Pragmas are allowed, as they're used by SQLite internally for things we need

0 commit comments

Comments
 (0)