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

Append sql_mode instead of overwriting in strict mode #24167

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Mar 12, 2016

For keep the default SQL mode.

This is an alternative of #23448.

r? @jeremy Do you think this is a good?

@kamipo kamipo force-pushed the append_sql_mode_instead_of_overwriting_in_strict_mode branch 3 times, most recently from df9d24b to 262bd9e Compare March 12, 2016 08:34
sql_mode = "REPLACE(#{sql_mode}, 'STRICT_ALL_TABLES', '')"
sql_mode = "REPLACE(#{sql_mode}, 'TRADITIONAL', '')"
end
variables['sql_mode'] = -> { sql_mode }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Treating callable values as unquoted is clever but it's not clear, particularly since we're using rescue to handle the condition.

We could omit this from variables and add to the set statement ourselves, like we do with encoding config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example,

sql_mode = "@@SESSION.sql_mode = #{sql_mode_change}"

@connection.query  "SET #{encoding} #{sql_mode} #{variable_assignments}"

@jeremy
Copy link
Member

jeremy commented Mar 12, 2016

References #16065, #17370, #17654.

@jeremy jeremy added this to the 5.0.0 milestone Mar 12, 2016
@jeremy jeremy self-assigned this Mar 12, 2016
@kamipo kamipo force-pushed the append_sql_mode_instead_of_overwriting_in_strict_mode branch 2 times, most recently from ff6252e to eb3dcac Compare March 13, 2016 03:18
end
sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omitted sql_mode from variables and added to the set statement ourselves!

@kamipo kamipo force-pushed the append_sql_mode_instead_of_overwriting_in_strict_mode branch from eb3dcac to 5ad6ed9 Compare March 13, 2016 03:31
end
sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omitted sql_mode from variables and added to the set statement ourselves!

@jeremy jeremy merged commit 5ad6ed9 into rails:master Mar 23, 2016
jeremy added a commit that referenced this pull request Mar 23, 2016
…writing_in_strict_mode

Append sql_mode instead of overwriting in strict mode
@jeremy
Copy link
Member

jeremy commented Mar 23, 2016

Thank you @kamipo!

@kamipo kamipo deleted the append_sql_mode_instead_of_overwriting_in_strict_mode branch March 23, 2016 20:32
ochaochaocha3 added a commit to cre-ne-jp/log-archiver that referenced this pull request Oct 6, 2018
MySQL 5.7.5以降では、SELECT DISTINCTとORDER BYを組み合わせるとき
ORDER BYで指定する列をSELECTにも含めなければならなくなった。
その結果、ログ表示画面で年月の一覧を取得するときにエラーが発生する。

データベースの設定でMySQLのSQLモードをTRADITIONALに設定することで
MySQL 5.6以前と同じ挙動になるようにする。

参考文献:
1. https://blog.kamipo.net/entry/2015/12/14/171838
2. rails/rails#24167
3. rails/rails#25924 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants