aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-05-19 11:46:13 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-30 11:05:03 -0200
commit564e32b71dfdf9b39ed243b25d9a3f090294ce9d (patch)
treeb3a38a798dd4e1649c1406a619c3eca01fddba02 /activerecord/lib
parentd7deec30f57a90991a0b4b5766d58a7090bb6c1f (diff)
downloadrails-564e32b71dfdf9b39ed243b25d9a3f090294ce9d.tar.gz
rails-564e32b71dfdf9b39ed243b25d9a3f090294ce9d.tar.bz2
rails-564e32b71dfdf9b39ed243b25d9a3f090294ce9d.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/lib')
-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 afc363c9b2..08ef704752 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1142,11 +1142,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