aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-05-19 11:46:13 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-05-19 11:46:13 -0700
commitfa41c929306857182168a014939a5fe7ed7f7567 (patch)
tree21b2894e6f6273d7f9341923cece750540191490 /activerecord
parent23fad29c1932119898259eab557162c1326fd325 (diff)
parent2fe281323c8ccebc592d423b69b5b03ac9254b29 (diff)
downloadrails-fa41c929306857182168a014939a5fe7ed7f7567.tar.gz
rails-fa41c929306857182168a014939a5fe7ed7f7567.tar.bz2
rails-fa41c929306857182168a014939a5fe7ed7f7567.zip
Merge pull request #6397 from kennyj/fix_translate_exception
Fix a problem of translate_exception method in a Japanese (non English) environment.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 14bc95abfe..15c3d7be36 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1336,11 +1336,15 @@ module ActiveRecord
@connection.server_version
end
+ # See http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html
+ FOREIGN_KEY_VIOLATION = "23503"
+ UNIQUE_VIOLATION = "23505"
+
def translate_exception(exception, message)
- case exception.message
- when /duplicate key value violates unique constraint/
+ case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE)
+ when UNIQUE_VIOLATION
RecordNotUnique.new(message, exception)
- when /violates foreign key constraint/
+ when FOREIGN_KEY_VIOLATION
InvalidForeignKey.new(message, exception)
else
super