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

Commit f5f21c8

Browse files
committed
common: Allow SQLite R*Tree functions to work
Only tested with Live databases so far.
1 parent 9903c6d commit f5f21c8

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

common/sqlite.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ const (
127127
fnHighlight function = "highlight"
128128
fnSnippet function = "snippet"
129129

130+
// R*Tree functions: https://www.sqlite.org/rtree.html
131+
fnRTree function = "rtree"
132+
fnRTreei32 function = "rtree_i32"
133+
fnRTreeCheck function = "rtreecheck"
134+
130135
// Other functions we should allow
131136
fnVersion function = "sqlite_version"
132137
)
@@ -221,6 +226,9 @@ var SQLiteFunctions = []function{
221226
fnFts5Vocab,
222227
fnHighlight,
223228
fnSnippet,
229+
fnRTree,
230+
fnRTreei32,
231+
fnRTreeCheck,
224232
fnVersion,
225233
}
226234

@@ -232,11 +240,9 @@ func init() {
232240
}
233241

234242
// AuthorizerLive is a SQLite authorizer callback intended to allow almost anything. Except for loading extensions,
235-
// and running pragmas. Note that the "page_size" pragma is always allowed by SQLite, and can't be overridden (any
236-
// attempt to AuthDeny it is ignored)
243+
// and running pragmas.
237244
func AuthorizerLive(d interface{}, action sqlite.Action, tableName, funcName, dbName, triggerName string) sqlite.Auth {
238245
if SqliteDebug > 0 {
239-
// Display some useful debug info
240246
log.Printf("AuthorizerLive - action: '%s', table: '%s', function: '%s'", action, tableName, funcName)
241247
}
242248

@@ -251,6 +257,17 @@ func AuthorizerLive(d interface{}, action sqlite.Action, tableName, funcName, db
251257
if tableName == "data_version" {
252258
return sqlite.AuthOk
253259
}
260+
261+
// The "page_size" Pragma is needed when creating R*Tree virtual tables. Ironically, SQLite (3.41.2) ignores
262+
// any "Deny" of the "page_size" pragma when creating FTS tables. No idea why this difference in behaviour
263+
// exists, but it doesn't seem to hurt anything.
264+
if tableName == "page_size" {
265+
return sqlite.AuthOk
266+
}
267+
268+
if SqliteDebug > 0 {
269+
log.Printf("Denying pragma: '%s'", tableName)
270+
}
254271
return sqlite.AuthDeny
255272
case sqlite.Function:
256273
if funcName == "load_extension" {

0 commit comments

Comments
 (0)