From 4fed541bb7aeb9da94ae82fb8a97a29292749f4e Mon Sep 17 00:00:00 2001 From: Marco Realacci Date: Tue, 6 Dec 2022 22:33:10 +0100 Subject: [PATCH] Add SQL rows.Err handling --- service/database/db-comments.go | 6 ++++-- service/database/db-likes.go | 4 ++++ service/database/db-profile.go | 4 ++++ service/database/db-stream.go | 4 ++++ service/database/db-users.go | 5 +++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/service/database/db-comments.go b/service/database/db-comments.go index 96b2adb..9e4ff0c 100644 --- a/service/database/db-comments.go +++ b/service/database/db-comments.go @@ -110,8 +110,6 @@ func (db *appdbimpl) GetComments(uid string, photo_id int64, requesting_uid stri return ERR_INTERNAL, nil, err } - defer rows.Close() - comments := make([]structures.Comment, 0) defer rows.Close() @@ -124,6 +122,10 @@ func (db *appdbimpl) GetComments(uid string, photo_id int64, requesting_uid stri } 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 } diff --git a/service/database/db-likes.go b/service/database/db-likes.go index 2c763ff..a8b9a59 100644 --- a/service/database/db-likes.go +++ b/service/database/db-likes.go @@ -48,6 +48,10 @@ func (db *appdbimpl) GetPhotoLikes(uid string, photo int64, requesting_uid strin } 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 } diff --git a/service/database/db-profile.go b/service/database/db-profile.go index 3b3c8b4..94fa131 100644 --- a/service/database/db-profile.go +++ b/service/database/db-profile.go @@ -105,6 +105,10 @@ func (db *appdbimpl) GetUserPhotos(uid string, requesting_uid string, start_inde } photos = append(photos, photo) } + // We check if the iteration ended prematurely + if err = rows.Err(); err != nil { + return nil, err + } return &photos, nil } diff --git a/service/database/db-stream.go b/service/database/db-stream.go index 644b5b9..48644c4 100644 --- a/service/database/db-stream.go +++ b/service/database/db-stream.go @@ -46,6 +46,10 @@ func (db *appdbimpl) GetUserStream(uid string, start_index int, limit int) (*[]s } photos = append(photos, photo) } + // We check if the iteration ended prematurely + if err = rows.Err(); err != nil { + return nil, err + } return &photos, nil } diff --git a/service/database/db-users.go b/service/database/db-users.go index b711cd2..9f9f497 100644 --- a/service/database/db-users.go +++ b/service/database/db-users.go @@ -162,6 +162,11 @@ func (db *appdbimpl) uidNameQuery(rows *sql.Rows, err error) (*[]structures.UIDN } 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 }