diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-06-01 04:00:05 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-12-06 21:30:25 +0900 |
commit | 49edce37f92b1dcad4b67b3eb35922e7cec88726 (patch) | |
tree | eaf97037eb42a02eceefef408cfc13418e67cc47 /activerecord/lib/active_record/connection_adapters | |
parent | cf6c2948d5e0e0d40a03f6858179a659a0a6ed7a (diff) | |
download | rails-49edce37f92b1dcad4b67b3eb35922e7cec88726.tar.gz rails-49edce37f92b1dcad4b67b3eb35922e7cec88726.tar.bz2 rails-49edce37f92b1dcad4b67b3eb35922e7cec88726.zip |
Translate numeric value out of range to the specific exception
Raise `ActiveRecord::RangeError` when values that executed are out of range.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 0e4bc1afcb..84589bd5f2 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -738,6 +738,7 @@ module ActiveRecord ER_DO_NOT_HAVE_DEFAULT = 1364 ER_NO_REFERENCED_ROW_2 = 1452 ER_DATA_TOO_LONG = 1406 + ER_OUT_OF_RANGE = 1264 ER_LOCK_DEADLOCK = 1213 ER_CANNOT_ADD_FOREIGN = 1215 ER_CANNOT_CREATE_TABLE = 1005 @@ -758,6 +759,8 @@ module ActiveRecord end when ER_DATA_TOO_LONG ValueTooLong.new(message) + when ER_OUT_OF_RANGE + RangeError.new(message) when ER_NOT_NULL_VIOLATION, ER_DO_NOT_HAVE_DEFAULT NotNullViolation.new(message) when ER_LOCK_DEADLOCK diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 5262141995..33cdcf9a76 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -408,6 +408,7 @@ module ActiveRecord # See http://www.postgresql.org/docs/current/static/errcodes-appendix.html VALUE_LIMIT_VIOLATION = "22001" + NUMERIC_VALUE_OUT_OF_RANGE = "22003" NOT_NULL_VIOLATION = "23502" FOREIGN_KEY_VIOLATION = "23503" UNIQUE_VIOLATION = "23505" @@ -424,6 +425,8 @@ module ActiveRecord InvalidForeignKey.new(message) when VALUE_LIMIT_VIOLATION ValueTooLong.new(message) + when NUMERIC_VALUE_OUT_OF_RANGE + RangeError.new(message) when NOT_NULL_VIOLATION NotNullViolation.new(message) when SERIALIZATION_FAILURE |