Skip to content

Commit

Permalink
Merge pull request #35 from IdlePhysicist/fix/null_values
Browse files Browse the repository at this point in the history
Resolve #34
  • Loading branch information
IdlePhysicist authored Sep 6, 2021
2 parents 4fea37c + 1ed593e commit 4df9d39
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions internal/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,20 @@ func (reg *Register) GetAllCavers() ([]*model.Caver, error) {

cavers := make([]*model.Caver, 0)
for result.Next() {
var c model.Caver
var (
c model.Caver
lastTrip sql.NullString
)

err = result.Scan(&c.ID, &c.Name, &c.Club, &c.Count, &c.LastTrip)
err = result.Scan(&c.ID, &c.Name, &c.Club, &c.Count, &lastTrip)
if err != nil {
reg.log.Errorf("Scan: %v", err)
}

if lastTrip.Valid {
c.LastTrip = lastTrip.String
}

cavers = append(cavers, &c)
}
if err = result.Err(); err != nil {
Expand Down Expand Up @@ -315,14 +323,22 @@ func (reg *Register) GetCaver(id string) (*model.Caver, error) {
}
defer result.Close()

var caver model.Caver
var (
caver model.Caver
lastTrip sql.NullString
)
for result.Next() {

err = result.Scan(&caver.ID, &caver.Name, &caver.Club, &caver.Count, &caver.LastTrip, &caver.Notes)
err = result.Scan(&caver.ID, &caver.Name, &caver.Club, &caver.Count, &lastTrip, &caver.Notes)
if err != nil {
reg.log.Errorf("reg.scan", err)
return nil, err
}

if lastTrip.Valid {
caver.LastTrip = lastTrip.String
}

}
if err = result.Err(); err != nil {
reg.log.Errorf("reg.get: Step error: %s", err)
Expand Down Expand Up @@ -363,12 +379,20 @@ func (reg *Register) GetAllCaves() ([]*model.Cave, error) {

caves := make([]*model.Cave, 0)
for result.Next() {
var c model.Cave
var (
c model.Cave
lastVisit sql.NullString
)

err = result.Scan(&c.ID, &c.Name, &c.Region, &c.Country, &c.SRT, &c.Visits, &c.LastVisit)
err = result.Scan(&c.ID, &c.Name, &c.Region, &c.Country, &c.SRT, &c.Visits, &lastVisit)
if err != nil {
reg.log.Errorf("Scan: %v", err)
}

if lastVisit.Valid {
c.LastVisit = lastVisit.String
}

caves = append(caves, &c)
}
if err = result.Err(); err != nil {
Expand Down Expand Up @@ -406,13 +430,20 @@ func (reg *Register) GetCave(id string) (*model.Cave, error) {
}
defer result.Close()

var cave model.Cave
var (
cave model.Cave
lastVisit sql.NullString
)
for result.Next() {
err = result.Scan(&cave.ID, &cave.Name, &cave.Region, &cave.Country, &cave.SRT, &cave.Visits, &cave.LastVisit, &cave.Notes)
err = result.Scan(&cave.ID, &cave.Name, &cave.Region, &cave.Country, &cave.SRT, &cave.Visits, &lastVisit, &cave.Notes)
if err != nil {
reg.log.Error(err)
return nil, err
}

if lastVisit.Valid {
cave.LastVisit = lastVisit.String
}
}
if err = result.Err(); err != nil {
reg.log.Errorf("reg.get: Step error: %s", err)
Expand Down

0 comments on commit 4df9d39

Please sign in to comment.