watchyourlan/internal/db/hist-edit.go
2023-10-06 13:36:11 +07:00

31 lines
945 B
Go

package db
import (
"fmt"
"github.com/aceberg/WatchYourLAN/internal/models"
)
// InsertHist - insert history into table
func InsertHist(path string, hist models.History) {
hist.Name = quoteStr(hist.Name)
hist.Hw = quoteStr(hist.Hw)
sqlStatement := `INSERT INTO "history" (HOST, NAME, IP, MAC, HW, DATE, KNOWN, STATE)
VALUES ('%d','%s','%s','%s','%s','%s','%d','%d');`
sqlStatement = fmt.Sprintf(sqlStatement, hist.Host, hist.Name, hist.IP, hist.Mac, hist.Hw, hist.Date, hist.Known, hist.State)
//fmt.Println("Insert statement:", sqlStatement)
dbExec(path, sqlStatement)
}
// DeleteHist - delete history from DB
func DeleteHist(path string, id int) {
sqlStatement := `DELETE FROM "history" WHERE ID='%d';`
sqlStatement = fmt.Sprintf(sqlStatement, id)
dbExec(path, sqlStatement)
}
// ClearHist - delete all history from table
func ClearHist(path string) {
sqlStatement := `DELETE FROM "history";`
dbExec(path, sqlStatement)
}