Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlite): allow using fts5 table name in the where clause #3498

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions internal/endtoend/testdata/virtual_table/sqlite/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 74 additions & 7 deletions internal/endtoend/testdata/virtual_table/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions internal/endtoend/testdata/virtual_table/sqlite/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ WHERE b = ?;
SELECT c FROM tbl_ft
WHERE b = ?;

-- name: SelectAllColsTblFtEqualByTableName :many
SELECT * FROM tbl_ft
WHERE tbl_ft = ?;

-- name: SelectAllColsTblFtMatchByTableName :many
SELECT * FROM tbl_ft
WHERE tbl_ft MATCH ?;

-- name: SelectHightlighFunc :many
SELECT highlight(tbl_ft, 0, '<b>', '</b>') FROM tbl_ft
WHERE b MATCH ?;
Expand Down
6 changes: 6 additions & 0 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ func (c *cc) convertCreate_virtual_table_fts5(n *parser.Create_virtual_table_stm
}
}

stmt.Cols = append(stmt.Cols, &ast.ColumnDef{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine to include the fts5 table name in the column list, as SQLite supports this as well

sqlite> SELECT key, emails_fts FROM emails_fts limit 1;
┌───────────────────────────────────────────────────┬────────────┐
│                        key                        │ emails_fts │
├───────────────────────────────────────────────────┼────────────┤
│ 1708522984.M224116P268.c18ac5293f65,S=3578,W=3701 │ 5          │
└───────────────────────────────────────────────────┴────────────┘

Colname: identifier(stmt.Name.Name),
IsNotNull: true,
TypeName: &ast.TypeName{Name: "text"},
})

return stmt
}

Expand Down