From e39d2f799d14b495596dade12cf40b15e453b08f Mon Sep 17 00:00:00 2001 From: jshiwam <41477104+jshiwam@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:14:27 +0530 Subject: [PATCH] Used Prepared Statements for GetChannel in clickhousereader (#1414) * feat: used db.Preparex --- pkg/query-service/app/clickhouseReader/reader.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index 6716373c8b..a1f86c7413 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -374,14 +374,21 @@ func (r *ClickHouseReader) GetChannel(id string) (*model.ChannelItem, *model.Api idInt, _ := strconv.Atoi(id) channel := model.ChannelItem{} - query := fmt.Sprintf("SELECT id, created_at, updated_at, name, type, data data FROM notification_channels WHERE id=%d", idInt) + query := "SELECT id, created_at, updated_at, name, type, data data FROM notification_channels WHERE id=? " - err := r.localDB.Get(&channel, query) + stmt, err := r.localDB.Preparex(query) - zap.S().Info(query) + zap.S().Info(query, idInt) if err != nil { - zap.S().Debug("Error in processing sql query: ", err) + zap.S().Debug("Error in preparing sql query for GetChannel : ", err) + return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err} + } + + err = stmt.Get(&channel, idInt) + + if err != nil { + zap.S().Debug(fmt.Sprintf("Error in getting channel with id=%d : ", idInt), err) return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err} }