Skip to content

Commit

Permalink
Allow fts5vocab module (#1540)
Browse files Browse the repository at this point in the history
This module was inadvertently missed in the original allow list – it's a standard part of of FTS5. As per the docs: "[fts5vocab] is available whenever FTS5 is"

https://www.sqlite.org/fts5.html#the_fts5vocab_virtual_table_module
  • Loading branch information
mhart committed Jun 12, 2024
1 parent db13baf commit 360bbf6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/workerd/api/sql-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ async function test(storage) {
assert.throws(() => sql.exec('SAVEPOINT foo'), /not authorized/)

// Virtual tables
// Only fts5 module is allowed
// Only fts5 and fts5vocab modules are allowed
assert.throws(
() => sql.exec(`CREATE VIRTUAL TABLE test_fts USING fts5abcd(id);`),
/not authorized/
Expand All @@ -371,10 +371,19 @@ async function test(storage) {
);
`)

// Module name is case-insensitive
// Module names are case-insensitive
sql.exec(`
CREATE VIRTUAL TABLE documents_fts USING FtS5(id, title, content, tokenize = porter);
`)
sql.exec(`
CREATE VIRTUAL TABLE documents_fts_v_col USING fTs5VoCaB(documents_fts, col);
`)
sql.exec(`
CREATE VIRTUAL TABLE documents_fts_v_row USING FtS5vOcAb(documents_fts, row);
`)
sql.exec(`
CREATE VIRTUAL TABLE documents_fts_v_instance USING fTs5VoCaB(documents_fts, instance);
`)

sql.exec(`
CREATE TRIGGER documents_fts_insert
Expand Down
6 changes: 4 additions & 2 deletions src/workerd/util/sqlite.c++
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,12 @@ bool SqliteDatabase::isAuthorized(int actionCode,

case SQLITE_CREATE_VTABLE : /* Table Name Module Name */
case SQLITE_DROP_VTABLE : /* Table Name Module Name */
// Virtual tables are tables backed by some native-code callbacks. We don't support these except for FTS5 (Full Text Search) https://www.sqlite.org/fts5.html
// Virtual tables are tables backed by some native-code callbacks.
// We don't support these except for FTS5 (Full Text Search) https://www.sqlite.org/fts5.html
// (Which also includes fts5vocab: "[fts5vocab] is available whenever FTS5 is")
{
KJ_IF_SOME (moduleName, param2) {
if (strcasecmp(moduleName.begin(), "fts5") == 0) {
if (strcasecmp(moduleName.begin(), "fts5") == 0 || strcasecmp(moduleName.begin(), "fts5vocab") == 0) {
return true;
}
}
Expand Down

0 comments on commit 360bbf6

Please sign in to comment.