diff --git a/pkg/services/sqlstore/alert.go b/pkg/services/sqlstore/alert.go index 5a430238823..64a4a6b3d8a 100644 --- a/pkg/services/sqlstore/alert.go +++ b/pkg/services/sqlstore/alert.go @@ -92,7 +92,7 @@ func HandleAlertsQuery(query *m.GetAlertsQuery) error { params = append(params, query.Limit) } - sql.WriteString("ORDER BY name ASC") + sql.WriteString(" ORDER BY name ASC") alerts := make([]*m.Alert, 0) if err := x.Sql(sql.String(), params...).Find(&alerts); err != nil { diff --git a/pkg/services/sqlstore/alert_notification.go b/pkg/services/sqlstore/alert_notification.go index 5105ca39eff..5acb53c3c09 100644 --- a/pkg/services/sqlstore/alert_notification.go +++ b/pkg/services/sqlstore/alert_notification.go @@ -66,7 +66,8 @@ func GetAlertNotificationsToSend(query *m.GetAlertNotificationsToSendQuery) erro sql.WriteString(` WHERE alert_notification.org_id = ?`) params = append(params, query.OrgId) - sql.WriteString(` AND ((alert_notification.is_default = 1)`) + sql.WriteString(` AND ((alert_notification.is_default = ?)`) + params = append(params, dialect.BooleanStr(true)) if len(query.Ids) > 0 { sql.WriteString(` OR alert_notification.id IN (?` + strings.Repeat(",?", len(query.Ids)-1) + ")") for _, v := range query.Ids { diff --git a/pkg/services/sqlstore/annotation.go b/pkg/services/sqlstore/annotation.go index 1b0f02fce09..3ea8647d3fa 100644 --- a/pkg/services/sqlstore/annotation.go +++ b/pkg/services/sqlstore/annotation.go @@ -75,7 +75,7 @@ func (r *SqlAnnotationRepo) Find(query *annotations.ItemQuery) ([]*annotations.I query.Limit = 10 } - sql.WriteString(fmt.Sprintf("ORDER BY epoch DESC LIMIT %v", query.Limit)) + sql.WriteString(fmt.Sprintf(" ORDER BY epoch DESC LIMIT %v", query.Limit)) items := make([]*annotations.Item, 0) if err := x.Sql(sql.String(), params...).Find(&items); err != nil { diff --git a/pkg/services/sqlstore/migrator/dialect.go b/pkg/services/sqlstore/migrator/dialect.go index 0c94eb82234..4473b560428 100644 --- a/pkg/services/sqlstore/migrator/dialect.go +++ b/pkg/services/sqlstore/migrator/dialect.go @@ -18,6 +18,7 @@ type Dialect interface { SupportEngine() bool LikeStr() string Default(col *Column) string + BooleanStr(bool) string CreateIndexSql(tableName string, index *Index) string CreateTableSql(table *Table) string diff --git a/pkg/services/sqlstore/migrator/mysql_dialect.go b/pkg/services/sqlstore/migrator/mysql_dialect.go index 195d52d1934..fc64842bd07 100644 --- a/pkg/services/sqlstore/migrator/mysql_dialect.go +++ b/pkg/services/sqlstore/migrator/mysql_dialect.go @@ -29,6 +29,10 @@ func (db *Mysql) AutoIncrStr() string { return "AUTO_INCREMENT" } +func (db *Mysql) BooleanStr(value bool) string { + return strconv.FormatBool(value) +} + func (db *Mysql) SqlType(c *Column) string { var res string switch c.Type { diff --git a/pkg/services/sqlstore/migrator/postgres_dialect.go b/pkg/services/sqlstore/migrator/postgres_dialect.go index 826a00a1410..5500b9f1684 100644 --- a/pkg/services/sqlstore/migrator/postgres_dialect.go +++ b/pkg/services/sqlstore/migrator/postgres_dialect.go @@ -36,6 +36,10 @@ func (db *Postgres) AutoIncrStr() string { return "" } +func (db *Postgres) BooleanStr(value bool) string { + return strconv.FormatBool(value) +} + func (b *Postgres) Default(col *Column) string { if col.Type == DB_Bool { if col.Default == "0" { diff --git a/pkg/services/sqlstore/migrator/sqlite_dialect.go b/pkg/services/sqlstore/migrator/sqlite_dialect.go index 8555754ab92..fe1e781c8df 100644 --- a/pkg/services/sqlstore/migrator/sqlite_dialect.go +++ b/pkg/services/sqlstore/migrator/sqlite_dialect.go @@ -29,6 +29,13 @@ func (db *Sqlite3) AutoIncrStr() string { return "AUTOINCREMENT" } +func (db *Sqlite3) BooleanStr(value bool) string { + if value { + return "1" + } + return "0" +} + func (db *Sqlite3) SqlType(c *Column) string { switch c.Type { case DB_Date, DB_DateTime, DB_TimeStamp, DB_Time: