Add SQL rows.Err handling

This commit is contained in:
Marco Realacci 2022-12-06 22:33:10 +01:00
parent d20b0029bb
commit 4fed541bb7
5 changed files with 21 additions and 2 deletions

View file

@ -110,8 +110,6 @@ func (db *appdbimpl) GetComments(uid string, photo_id int64, requesting_uid stri
return ERR_INTERNAL, nil, err return ERR_INTERNAL, nil, err
} }
defer rows.Close()
comments := make([]structures.Comment, 0) comments := make([]structures.Comment, 0)
defer rows.Close() defer rows.Close()
@ -124,6 +122,10 @@ func (db *appdbimpl) GetComments(uid string, photo_id int64, requesting_uid stri
} }
comments = append(comments, c) comments = append(comments, c)
} }
// We check if the iteration ended prematurely
if err = rows.Err(); err != nil {
return ERR_INTERNAL, nil, err
}
return SUCCESS, &comments, nil return SUCCESS, &comments, nil
} }

View file

@ -48,6 +48,10 @@ func (db *appdbimpl) GetPhotoLikes(uid string, photo int64, requesting_uid strin
} }
likes = append(likes, structures.UIDName{UID: uid, Name: name}) likes = append(likes, structures.UIDName{UID: uid, Name: name})
} }
// We check if the iteration ended prematurely
if err = rows.Err(); err != nil {
return ERR_INTERNAL, nil, err
}
return SUCCESS, &likes, nil return SUCCESS, &likes, nil
} }

View file

@ -105,6 +105,10 @@ func (db *appdbimpl) GetUserPhotos(uid string, requesting_uid string, start_inde
} }
photos = append(photos, photo) photos = append(photos, photo)
} }
// We check if the iteration ended prematurely
if err = rows.Err(); err != nil {
return nil, err
}
return &photos, nil return &photos, nil
} }

View file

@ -46,6 +46,10 @@ func (db *appdbimpl) GetUserStream(uid string, start_index int, limit int) (*[]s
} }
photos = append(photos, photo) photos = append(photos, photo)
} }
// We check if the iteration ended prematurely
if err = rows.Err(); err != nil {
return nil, err
}
return &photos, nil return &photos, nil
} }

View file

@ -162,6 +162,11 @@ func (db *appdbimpl) uidNameQuery(rows *sql.Rows, err error) (*[]structures.UIDN
} }
followers = append(followers, structures.UIDName{UID: uid, Name: name}) followers = append(followers, structures.UIDName{UID: uid, Name: name})
} }
// We check if the iteration ended prematurely
if err = rows.Err(); err != nil {
return nil, err
}
return &followers, nil return &followers, nil
} }