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:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user