-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Strict mode not actually strict #376
Comments
Looks like we can do the following for a workaround:
|
I would not say the functionality is wrong, but rather that the naming may need to be reconsidered. MySQL's "strict mode" setting is not strict enough to prevent a variety of silent and nasty bugs that will lead to problems in production, and has the same issues you mention about the warnings-to-errors flag in this driver. I've implemented functionality to check for warnings and promote them to errors in a variety of jobs I've had; usually only enabling in development, of course :) |
That's the first I've ever heard of that. Do you have examples or references?
It would be better to be able to type assert a |
If you're using a transactional table backend like InnoDB, it's much improved, because it rolls back the transaction when it hits a problem. There's also "TRADITIONAL" sql_mode, which is described as "turn warnings into errors", and is STRICT_ALL_TABLES plus some other stuff: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html I'm sure there might be yet more subtle problems, but it's a big step forwards. So I agree with @phemmer that the "strict" flag in this package is confusing if you know about MySQL's strict sql_mode, and it's not as strict as it could be. |
This option is stricter than "TRADITIONAL". (known as "kamipo traditional" in Japanese engineers).
|
Isn't it rather a documentation issue then? |
The strict mode may not be confused with the server-side strict mode set via the sql_mode system variable. Fixes #376
The strict mode may not be confused with the server-side strict mode set via the sql_mode system variable. Fixes #376 * README: Set strict mode via sql_mode in DSN example
The
strict
parameter is not using the MySQL strict mode, just returning errors when mysql throws a warning. This is extremely dangerous behavior that can lead to data corruption.MySQL has a strict mode that should be used for this: https://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
For example:
Which results in:
As you can see, the
INSERT
threw an error, but the insert was actually performed. I now have this row in my database that I'm not expecting to be there.If this had been an
UPDATE
, I could have overwritten valid data with now invalid, truncated, data.The text was updated successfully, but these errors were encountered: