diff options
author | Stephen Blackstone <sblackstone@gmail.com> | 2015-12-21 22:04:53 -0500 |
---|---|---|
committer | Stephen Blackstone <sblackstone@gmail.com> | 2015-12-22 02:47:29 -0500 |
commit | fdb0234434ae37885bf03b76319e8bee01b55071 (patch) | |
tree | 7089b0b4f13c934863efb71eeb8260a1916123a2 /activerecord | |
parent | 17a4e450489a785af53d3e11f5a35ec1e8ea0903 (diff) | |
download | rails-fdb0234434ae37885bf03b76319e8bee01b55071.tar.gz rails-fdb0234434ae37885bf03b76319e8bee01b55071.tar.bz2 rails-fdb0234434ae37885bf03b76319e8bee01b55071.zip |
Add support for passing flags to MySQL2 adapter by array
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/mysql2/connection_test.rb | 9 |
2 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 6590e0140d..f4686b680c 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -11,8 +11,13 @@ module ActiveRecord config[:username] = 'root' if config[:username].nil? config[:flags] ||= 0 + if Mysql2::Client.const_defined? :FOUND_ROWS - config[:flags] |= Mysql2::Client::FOUND_ROWS + if config[:flags].kind_of? Array + config[:flags].push "FOUND_ROWS".freeze + else + config[:flags] |= Mysql2::Client::FOUND_ROWS + end end client = Mysql2::Client.new(config) diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index f344f99e85..575138eb2a 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -87,7 +87,14 @@ class Mysql2ConnectionTest < ActiveRecord::Mysql2TestCase assert_equal (Mysql2::Client::COMPRESS | Mysql2::Client::FOUND_ROWS), ActiveRecord::Base.connection.raw_connection.query_options[:flags] end end - + + def test_passing_flags_by_array_to_adapter + run_without_connection do |orig_connection| + ActiveRecord::Base.establish_connection(orig_connection.merge({flags: ['COMPRESS'] })) + assert_equal ["COMPRESS", "FOUND_ROWS"], ActiveRecord::Base.connection.raw_connection.query_options[:flags] + end + end + def test_mysql_strict_mode_specified_default run_without_connection do |orig_connection| ActiveRecord::Base.establish_connection(orig_connection.merge({strict: :default})) |