Default to 'strict mode' in MySQL

This commit is contained in:
Michael Pearson 2012-04-30 09:46:08 +10:00
parent a9721d8941
commit 4b905606e3
2 changed files with 11 additions and 0 deletions

View File

@ -253,6 +253,12 @@ module ActiveRecord
# By default, MySQL 'where id is null' selects the last inserted id.
# Turn this off. http://dev.rubyonrails.org/ticket/6778
variable_assignments = ['SQL_AUTO_IS_NULL=0']
# Make MySQL reject illegal values rather than truncating or
# blanking them. See
# http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
variable_assignments << "SQL_MODE='STRICT_ALL_TABLES'"
encoding = @config[:encoding]
# make sure we set the encoding

View File

@ -404,6 +404,11 @@ module ActiveRecord
# By default, MySQL 'where id is null' selects the last inserted id.
# Turn this off. http://dev.rubyonrails.org/ticket/6778
execute("SET SQL_AUTO_IS_NULL=0", :skip_logging)
# Make MySQL reject illegal values rather than truncating or
# blanking them. See
# http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_strict_all_tables
execute("SET SQL_MODE='STRICT_ALL_TABLES'", :skip_logging)
end
def select(sql, name = nil, binds = [])