reportbug is "finished"

just need to update database!

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
Sindre Kjelsrud 2024-01-10 13:05:58 +01:00
parent deb7d05b98
commit 113b0fb4b7
Signed by untrusted user who does not match committer: sidski
GPG key ID: D2BBDF3EDE6BA9A6
6 changed files with 135 additions and 17 deletions

View file

@ -0,0 +1,48 @@
package db
import (
"database/sql"
"fmt"
"log"
_ "github.com/lib/pq"
)
func InsertBugReport(bugText string) (error) {
// Connection string
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
"password=%s dbname=%s sslmode=disable",
host, port, user, password, dbname)
// Connect to the database
db, err := sql.Open("postgres", psqlInfo)
if err != nil {
log.Fatalf("Error opening database: %v\n", err)
}
defer db.Close()
// Check the connection
err = db.Ping()
if err != nil {
log.Fatalf("Error connecting to the database: %v\n", err)
}
insertStatement := `
INSERT INTO FeilRapport (feilTekst)
VALUES ($1)
`
stmt, err := db.Prepare(insertStatement)
if err != nil {
log.Fatalf("Error preparing statement: %v\n", err)
}
defer stmt.Close()
_, err = stmt.Exec(bugText)
if err != nil {
log.Fatalf("Error executing statement: %v\n", err)
}
fmt.Print("Inserted bug successfully")
return nil
}