diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index b384fa57da..30dd70df25 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* MySQL: fix show_variable. #8448 [matt, Jeremy Kemper] + * Fixtures: correctly delete and insert fixtures in a single transaction. #8553 [Michael Schuerig] * Fixtures: people(:technomancy, :josh) returns both fixtures. #7880 [technomancy, Josh Peek] diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 6ba973041b..7edf5b0f2d 100755 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -409,7 +409,8 @@ module ActiveRecord # SHOW VARIABLES LIKE 'name' def show_variable(name) - select_value "SHOW VARIABLES LIKE '#{name}'" + variables = select_all("SHOW VARIABLES LIKE '#{name}'") + variables.first['Value'] unless variables.empty? end private diff --git a/activerecord/test/adapter_test.rb b/activerecord/test/adapter_test.rb index 6d986d5dba..84af72bfa5 100644 --- a/activerecord/test/adapter_test.rb +++ b/activerecord/test/adapter_test.rb @@ -48,11 +48,19 @@ class AdapterTest < Test::Unit::TestCase if current_adapter?(:MysqlAdapter) def test_charset - assert @connection.charset + assert_not_nil @connection.charset + assert_not_equal 'character_set_database', @connection.charset + assert_equal @connection.show_variable('character_set_database'), @connection.charset end def test_collation - assert @connection.collation + assert_not_nil @connection.collation + assert_not_equal 'collation_database', @connection.collation + assert_equal @connection.show_variable('collation_database'), @connection.collation + end + + def test_show_nonexistent_variable_returns_nil + assert_nil @connection.show_variable('foo_bar_baz') end end