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

Merged
merged 1 commit into from Mar 23, 2016

Conversation

Projects
None yet
3 participants
@kamipo
Member

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 kamipo:append_sql_mode_instead_of_overwriting_in_strict_mode branch 3 times, most recently Mar 12, 2016

@jeremy

View changes

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb Outdated
sql_mode = "REPLACE(#{sql_mode}, 'STRICT_ALL_TABLES', '')"
sql_mode = "REPLACE(#{sql_mode}, 'TRADITIONAL', '')"
end
variables['sql_mode'] = -> { sql_mode }

This comment has been minimized.

@jeremy

jeremy Mar 12, 2016

Member

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.

This comment has been minimized.

@jeremy

jeremy Mar 12, 2016

Member

For example,

sql_mode = "@@SESSION.sql_mode = #{sql_mode_change}"@connection.query  "SET #{encoding} #{sql_mode} #{variable_assignments}"
@jeremy

This comment has been minimized.

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 kamipo:append_sql_mode_instead_of_overwriting_in_strict_mode branch 2 times, most recently Mar 13, 2016

@kamipo

View changes

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb Outdated
end
sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode

This comment has been minimized.

@kamipo

kamipo Mar 13, 2016

Member

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

Append sql_mode instead of overwriting in strict mode
For keep the default SQL mode.

@kamipo kamipo force-pushed the kamipo:append_sql_mode_instead_of_overwriting_in_strict_mode branch to 5ad6ed9 Mar 13, 2016

end
sql_mode_assignment = "@@SESSION.sql_mode = #{sql_mode}, " if sql_mode

This comment has been minimized.

@kamipo

kamipo Mar 13, 2016

Member

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

@jeremy jeremy merged commit 5ad6ed9 into rails:master Mar 23, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

jeremy added a commit that referenced this pull request Mar 23, 2016

Merge pull request #24167 from kamipo/append_sql_mode_instead_of_over…
…writing_in_strict_mode

Append sql_mode instead of overwriting in strict mode
@jeremy

This comment has been minimized.

Member

jeremy commented Mar 23, 2016

Thank you @kamipo!

@kamipo kamipo deleted the kamipo:append_sql_mode_instead_of_overwriting_in_strict_mode branch Mar 23, 2016

ochaochaocha3 added a commit to cre-ne-jp/log-archiver that referenced this pull request Oct 6, 2018

MySQLのSQLモードをTRADITIONALに変更する
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