Used Prepared Statements for GetChannel in clickhousereader (#1414)

* feat: used db.Preparex
This commit is contained in:
jshiwam 2022-07-28 10:14:27 +05:30 committed by GitHub
parent f8f903848e
commit e39d2f799d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}
}