Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL/MariaDB strict mode disabled by setting sql_mode=ANSI_QUOTES #611

Closed
julianbrost opened this issue Jun 27, 2023 · 1 comment · Fixed by #699
Closed

MySQL/MariaDB strict mode disabled by setting sql_mode=ANSI_QUOTES #611

julianbrost opened this issue Jun 27, 2023 · 1 comment · Fixed by #699
Assignees
Milestone

Comments

@julianbrost
Copy link
Contributor

Looking into Icinga/icinga2#9794 (comment) showed that this line has unintended side effects:

config.Params = map[string]string{"sql_mode": "ANSI_QUOTES"}

Add the following code to log the sql_mode after connecting to the database:

diff --git a/cmd/icingadb/main.go b/cmd/icingadb/main.go
index 1c22afc..f26a0a4 100644
--- a/cmd/icingadb/main.go
+++ b/cmd/icingadb/main.go
@@ -68,6 +68,10 @@ func run() int {
                if err != nil {
                        logger.Fatalf("%+v", errors.Wrap(err, "can't connect to database"))
                }
+
+               var sqlMode string
+               err = db.Get(&sqlMode, "SELECT @@sql_mode")
+               logger.Infow("sql mode", zap.String("sql_mode", sqlMode), zap.Error(err))
        }
 
        if err := db.CheckSchema(context.Background()); err != nil {

This will log:

sql mode        {"sql_mode": "ANSI_QUOTES"}

Now additionally comment out the line mentioned above that sets sql_mode, run it again and now it logs (and crashes shortly afterwards as MariaDB no longer understands the queries):

sql mode        {"sql_mode": "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"}

So setting sql_mode=ANSI_QUOTES made MariaDB (and probably MySQL, but I didn't perform any extra tests with that) less strict. This will make it silently "fix" out-of-range values for numeric columns for example.

@lippserd
Copy link
Member

I'll fix that.

@julianbrost julianbrost changed the title MariaDB strict mode disabled by settings sql_mode=ANSI_QUOTES MariaDB strict mode disabled by setting sql_mode=ANSI_QUOTES Jun 27, 2023
@julianbrost julianbrost added this to the 1.2.0 milestone Jul 26, 2023
@julianbrost julianbrost modified the milestones: 1.1.1, 1.2.0 Aug 1, 2023
@lippserd lippserd changed the title MariaDB strict mode disabled by setting sql_mode=ANSI_QUOTES MySQL/MariaDB strict mode disabled by setting sql_mode=ANSI_QUOTES Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants