From 9e7f109af5af8740b348bdae9d838615efac5cfe Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 31 Jul 2023 16:22:18 +0200 Subject: [PATCH] MySQL: Use strict SQL mode instead of just ANSI_QUOTES --- pkg/config/database.go | 3 ++- pkg/icingadb/quoter.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/config/database.go b/pkg/config/database.go index b42ff8e1c..9f886ebef 100644 --- a/pkg/config/database.go +++ b/pkg/config/database.go @@ -61,7 +61,8 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) { config.DBName = d.Database config.Timeout = time.Minute - config.Params = map[string]string{"sql_mode": "ANSI_QUOTES"} + // Set strict SQL mode, i.e. trigger an error if an incorrect value is inserted into a column. + config.Params = map[string]string{"sql_mode": "TRADITIONAL"} tlsConfig, err := d.TlsOptions.MakeConfig(d.Host) if err != nil { diff --git a/pkg/icingadb/quoter.go b/pkg/icingadb/quoter.go index b3cae860c..3726695dc 100644 --- a/pkg/icingadb/quoter.go +++ b/pkg/icingadb/quoter.go @@ -20,7 +20,7 @@ func NewQuoter(db *sqlx.DB) *Quoter { switch db.DriverName() { case driver.MySQL: - qc = `"` + qc = "`" case driver.PostgreSQL: qc = `"` default: