Skip to content

Commit

Permalink
use ? syntax instead of $ in sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 authored and ChrisSchinnerl committed Dec 3, 2024
1 parent 4d8970c commit ce4b79d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions stores/sql/sqlite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,20 +1074,20 @@ func (tx *MainDatabaseTx) UpdateHostBlocklistEntries(ctx context.Context, add, r

joinStmt, err := tx.Prepare(ctx, `
INSERT OR IGNORE INTO host_blocklist_entry_hosts (db_blocklist_entry_id, db_host_id)
SELECT $1, id FROM (
SELECT ?, id FROM (
SELECT id
FROM hosts
WHERE net_address == $2 OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') == $3 OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') LIKE $4
WHERE net_address == ? OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') == ? OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') LIKE ?
)
UNION ALL
SELECT $1, db_host_id FROM (
SELECT ?, db_host_id FROM (
SELECT db_host_id
FROM host_addresses
WHERE net_address == $2 OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') == $3 OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') LIKE $4
WHERE net_address == ? OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') == ? OR
rtrim(rtrim(net_address, replace(net_address, ':', '')),':') LIKE ?
)`)
if err != nil {
return fmt.Errorf("failed to prepare join statement: %w", err)
Expand All @@ -1099,7 +1099,7 @@ func (tx *MainDatabaseTx) UpdateHostBlocklistEntries(ctx context.Context, add, r
return fmt.Errorf("failed to insert host blocklist entry: %w", err)
} else if entryID, err := res.LastInsertId(); err != nil {
return fmt.Errorf("failed to fetch host blocklist entry id: %w", err)
} else if _, err := joinStmt.Exec(ctx, entryID, entry, entry, fmt.Sprintf("%%.%s", entry)); err != nil {
} else if _, err := joinStmt.Exec(ctx, entryID, entry, entry, fmt.Sprintf("%%.%s", entry), entryID, entry, entry, fmt.Sprintf("%%.%s", entry)); err != nil {
return fmt.Errorf("failed to join host blocklist entry: %w", err)
}
}
Expand Down

0 comments on commit ce4b79d

Please sign in to comment.