diff options
author | Max Melentiev <printercu@gmail.com> | 2012-12-24 15:46:52 +0400 |
---|---|---|
committer | Max Melentiev <melentievm@gmail.com> | 2013-12-07 17:30:00 +0400 |
commit | c46ff516a25684a2d04d453b2db44d6fa224c350 (patch) | |
tree | 8c03f9bcb1b0143de1cb1f59e48dc1f9e88a361b | |
parent | 76dae289edf33d4b3fc937ecd9d2c77b294d8074 (diff) | |
download | rails-c46ff516a25684a2d04d453b2db44d6fa224c350.tar.gz rails-c46ff516a25684a2d04d453b2db44d6fa224c350.tar.bz2 rails-c46ff516a25684a2d04d453b2db44d6fa224c350.zip |
fix for messages in invalid encoding from db-drivers
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/abstract_adapter_test.rb | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 8aa1ce5c04..e3ff0fb2c5 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -358,7 +358,11 @@ module ActiveRecord :statement_name => statement_name, :binds => binds) { yield } rescue => e - message = "#{e.class.name}: #{e.message}: #{sql}" + begin + message = "#{e.class.name}: #{e.message}: #{sql}" + rescue Encoding::CompatibilityError + message = "#{e.class.name}: #{e.message.force_encoding sql.encoding}: #{sql}" + end @logger.error message if @logger exception = translate_exception(e, message) exception.set_backtrace e.backtrace diff --git a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb index eb2fe5639b..d6fd39cb09 100644 --- a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb +++ b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb @@ -1,3 +1,4 @@ +# -*- encoding : utf-8 -*- require "cases/helper" module ActiveRecord @@ -57,6 +58,14 @@ module ActiveRecord assert_equal adapter, pool.connection end + + def test_log_invalid_encoding + assert_raise ActiveRecord::StatementInvalid do + adapter.send :log, "SELECT 'ы' FROM DUAL" do + raise 'ы'.force_encoding(Encoding::ASCII_8BIT) + end + end + end end end end |