Skip to content

Commit

Permalink
Merge pull request rails#6397 from kennyj/fix_translate_exception
Browse files Browse the repository at this point in the history
Fix a problem of translate_exception method in a Japanese (non English) environment.
  • Loading branch information
tenderlove committed May 19, 2012
2 parents 23fad29 + 2fe2813 commit fa41c92
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,15 @@ def postgresql_version
@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
Expand Down

0 comments on commit fa41c92

Please sign in to comment.