提交 12cbc57a 编写于 作者: R Rafael Mendonça França

Merge pull request #9493 from kennyj/fix_wrong_exception

Wrong exception is occured when raising no translatable exception

Closes #8617
## Rails 4.0.0 (unreleased) ##
* Fix a problem wrong exception is occured
when raising no translatable exception in PostgreSQL.
*kennyj*
* Support PostgreSQL specific column types when using `change_table`.
Fixes #9480.
......
......@@ -675,6 +675,8 @@ def postgresql_version
UNIQUE_VIOLATION = "23505"
def translate_exception(exception, message)
return exception unless exception.respond_to?(:result)
case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE)
when UNIQUE_VIOLATION
RecordNotUnique.new(message, exception)
......
......@@ -250,6 +250,12 @@ def test_distinct_with_nulls
assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"])
end
def test_raise_error_when_cannot_translate_exception
assert_raise TypeError do
@connection.send(:log, nil) { @connection.execute(nil) }
end
end
private
def insert(ctx, data)
binds = data.map { |name, value|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册