From 1044585b50a5aedb62ef84223cf213b51e71ab86 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 21 Mar 2022 15:42:05 +0100 Subject: [PATCH] Plugins: Fix problematic query (#46777) Fixes mysql error "sql: expected 0 arguments, got 1" introduced via #46283 --- pkg/services/sqlstore/plugin_setting.go | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/pkg/services/sqlstore/plugin_setting.go b/pkg/services/sqlstore/plugin_setting.go index 6b9c9afc2a2..b31d75625af 100644 --- a/pkg/services/sqlstore/plugin_setting.go +++ b/pkg/services/sqlstore/plugin_setting.go @@ -8,21 +8,24 @@ import ( ) func (ss *SQLStore) GetPluginSettings(ctx context.Context, orgID int64) ([]*models.PluginSetting, error) { - var rslt = make([]*models.PluginSetting, 0) + sql := `SELECT org_id, plugin_id, enabled, pinned, plugin_version + FROM plugin_setting ` + params := make([]interface{}, 0) + + if orgID != 0 { + sql += "WHERE org_id=?" + params = append(params, orgID) + } + + var rslt []*models.PluginSetting err := ss.WithDbSession(ctx, func(sess *DBSession) error { - if orgID != 0 { - sess.Where("org_id", orgID) - } - - err := sess.Find(&rslt) - if err != nil { - return err - } - - return nil + return sess.SQL(sql, params...).Find(&rslt) }) + if err != nil { + return nil, err + } - return rslt, err + return rslt, nil } func (ss *SQLStore) GetPluginSettingById(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {