aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMichael Pearson <mipearson@gmail.com>2012-04-30 09:46:08 +1000
committerMichael Pearson <mipearson@gmail.com>2012-05-05 17:17:04 +1000
commit4b905606e33f0adba61c2032f0972623ba40e5e5 (patch)
tree5591eb6d60b39bcb6d2da0f8daea6f0910d42464 /activerecord
parenta9721d89417c3912944d26610b4df370c56be8ae (diff)
downloadrails-4b905606e33f0adba61c2032f0972623ba40e5e5.tar.gz
rails-4b905606e33f0adba61c2032f0972623ba40e5e5.tar.bz2
rails-4b905606e33f0adba61c2032f0972623ba40e5e5.zip
Default to 'strict mode' in MySQL
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb5
2 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index 92908d9599..41195dd8e3 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -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
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 724dbff1f0..f74febba75 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -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 = [])