Skip to content

Commit

Permalink
don't break when err in add to DB
Browse files Browse the repository at this point in the history
  • Loading branch information
gagarinfan committed Dec 20, 2018
1 parent 1b48c8e commit e7c70ff
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions SQL4/sqljson.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ func dodaj(cnstr string, name string, location string) (int64, error) {
var err error
db, ctx, errdb := connopen(cnstr)
if errdb != nil {
log.Fatal("Problem z db prepare: ", err.Error())
log.Println("Problem z db prepare: ", err.Error())
}
var zapins = "insert into TestSchema.Employees (name, location) values (@name,@location); select @@identity;"

skladnia, err := db.Prepare(zapins)
if err != nil {
log.Fatal("Problem z db prepare: ", err.Error())
log.Println("Problem z db prepare: ", err.Error())
}
defer skladnia.Close()
//var name, location string
Expand All @@ -105,9 +105,8 @@ func dodaj(cnstr string, name string, location string) (int64, error) {
var noweid int64
err = row.Scan(&noweid)
if err != nil {
log.Fatal("Błąd w wyniku zapytania: ", err.Error())
log.Println("Błąd w wyniku zapytania: ", err.Error())
}
log.Println("Gicior")
connclose(db)
return noweid, err
}
Expand Down Expand Up @@ -233,10 +232,7 @@ func CreatePersonEndpoint(w http.ResponseWriter, r *http.Request) {
person.Location = params["location"]
people = append(people, person)
json.NewEncoder(w).Encode(people)
_, errnew := dodaj(cnstr, person.Name, person.Location)
if errnew != nil {
log.Fatal("Cannot save. Caused by: ", errnew)
}
_, _ = dodaj(cnstr, person.Name, person.Location)
}
func DeletePersonEndpoint(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
Expand Down

0 comments on commit e7c70ff

Please sign in to comment.