docs(06-03): add SAFETY comments to all 12 hand-crafted SQL statements

- 7 SAFETY comments in search.go (FTS5 MATCH/INSERT/DELETE operations)
- 3 SAFETY comments in library.go (FTS5 INSERT/DELETE in commitNewAudioFile, updateAudioFileMetadata)
- 1 SAFETY comment in rescan.go (FTS5 DELETE in clearAllLibraryData)
- 1 SAFETY comment in persistence.go (variable-count multi-row INSERT)
- Cross-references link library.go/rescan.go back to search.go
- Two-part format: why sqlc can't handle it + what makes it safe
This commit is contained in:
2026-03-04 19:33:55 -05:00
parent 2221a68459
commit 7dfe003e63
4 changed files with 12 additions and 0 deletions
+3
View File
@@ -793,6 +793,7 @@ func (l *Library) saveAudioFile(
album := tags.Album
// SAFETY: FTS5 virtual table, see search.go:InsertSearchIndex. All values parameterized.
if _, err := tx.ExecContext(
l.ctx,
`INSERT INTO search_index(rowid, file_path, title, artist, album)
@@ -874,6 +875,7 @@ func (l *Library) updateAudioFileMetadata(
album := tags.Album
// SAFETY: FTS5 virtual table, see search.go:DeleteSearchIndex. Rowid parameterized.
if _, err := tx.ExecContext(
l.ctx,
`DELETE FROM search_index WHERE rowid = ?`,
@@ -888,6 +890,7 @@ func (l *Library) updateAudioFileMetadata(
metrics.addWarning(result.absolutePath, "commit", err)
}
// SAFETY: FTS5 virtual table, see search.go:InsertSearchIndex. All values parameterized.
if _, err := tx.ExecContext(
l.ctx,
`INSERT INTO search_index(rowid, file_path, title, artist, album)
+1
View File
@@ -161,6 +161,7 @@ func (l *Library) clearLibraryTables() error {
}
// Clear FTS5 search index.
// SAFETY: FTS5 virtual table, see search.go:ClearSearchIndex. No parameters; unconditional delete.
if _, err := tx.ExecContext(
l.ctx, `DELETE FROM search_index`,
); err != nil {