From c1b9982533f1b5286652b0637cf8160978c9e01a Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 1 Nov 2023 09:23:10 +0100 Subject: [PATCH] =?UTF-8?q?Leere=20Slices=20erstellen=20und=20mit=20append?= =?UTF-8?q?()=20anh=C3=A4ngen=20ersetzt,=20wo=20m=C3=B6glich?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/data/dbFuncs.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/data/dbFuncs.go b/packages/data/dbFuncs.go index 0a980c9..df89078 100644 --- a/packages/data/dbFuncs.go +++ b/packages/data/dbFuncs.go @@ -301,7 +301,7 @@ func (db *DB) GetQuestions(nums []string) ([]Question, error) { } func (db *DB) GetGivenAnswers(bid, pid int64, sq []Question) ([]int, error) { - answers := make([]int, 0) + answers := make([]int, len(sq)) query := ` SELECT given_answer FROM given_answers @@ -311,7 +311,7 @@ func (db *DB) GetGivenAnswers(bid, pid int64, sq []Question) ([]int, error) { question_id = ? ` - for _, q := range sq { + for i, q := range sq { var answer int row := db.QueryRow(query, bid, pid, q.ID) @@ -319,7 +319,7 @@ func (db *DB) GetGivenAnswers(bid, pid int64, sq []Question) ([]int, error) { return nil, fmt.Errorf("error: *DB.GetGivenAnswers: row.Scan(): %v", err) } - answers = append(answers, answer) + answers[i] = answer } return answers, nil