Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased


- Improve handling of FTS5 hidden columns (https://github.com/sqldelight/sql-psi/pull/717)

## [0.7.0] - 2025-09-02
[0.7.0]: https://github.com/sqldelight/sql-psi/releases/tag/0.7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,31 @@ internal abstract class CreateVirtualTableMixin(
)
.mapNotNull { it.moduleArgumentDef?.moduleColumnDef?.columnName ?: it.moduleArgumentDef?.columnDef?.columnName }

val synthesizedColumns = if (usesFtsModule) {
val columnNames = columnNameElements.map { it.name }

listOf(
SynthesizedColumn(
table = this,
acceptableValues = listOf("docid", "rowid", "oid", "_rowid_", tableName.name)
.filter { it !in columnNames },
),
)
} else {
emptyList()
val synthesizedColumns = when {
usesFts3Module || usesFts4Module -> {
val columnNames = columnNameElements.map { it.name }

listOf(
SynthesizedColumn(
table = this,
acceptableValues = listOf("docid", "rowid", "oid", "_rowid_", tableName.name)
.filter { it !in columnNames },
),
)
}
usesFts5Module -> {
val columnNames = columnNameElements.map { it.name }

listOf(
SynthesizedColumn(
table = this,
acceptableValues = listOf("rowid", "_row_id_", "rank", tableName.name)
.filter { it !in columnNames },
),
)
}

else -> emptyList()
}

return LazyQuery(tableName) {
Expand All @@ -77,3 +90,12 @@ internal class CreateVirtualTableElementType(name: String) :

val SqlCreateVirtualTableStmt.usesFtsModule: Boolean
get() = this.moduleName?.text?.startsWith(prefix = "fts", ignoreCase = true) == true

val SqlCreateVirtualTableStmt.usesFts3Module: Boolean
get() = this.moduleName?.text?.startsWith(prefix = "fts3", ignoreCase = true) == true

val SqlCreateVirtualTableStmt.usesFts4Module: Boolean
get() = this.moduleName?.text?.startsWith(prefix = "fts4", ignoreCase = true) == true

val SqlCreateVirtualTableStmt.usesFts5Module: Boolean
get() = this.moduleName?.text?.startsWith(prefix = "fts5", ignoreCase = true) == true
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE VIRTUAL TABLE data USING fts5(text, content=other_table, content_rowid=rowid, prefix='2 3 4 5 6');

SELECT rank, rowid
FROM data
WHERE text MATCH 'fts5';

SELECT rank, rowid
FROM data
WHERE text MATCH 'fts5' ORDER BY rank;

-- Expected failure - it's not valid to query for oid or docid in FTS5 tables.
SELECT oid
FROM data
WHERE text MATCH 'fts5';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test.s line 12:7 - No column found with name oid