diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-10-20 20:30:59 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-10-20 20:30:59 +0000 |
commit | 8949ce09824b8a6796c3257fd6ebb01d9014fe9c (patch) | |
tree | 0d1cf5f7152b241a43954912ecd831e0c1725b59 /activerecord | |
parent | 1742d0d707ce395398b43063aba37e8c3606d378 (diff) | |
download | rails-8949ce09824b8a6796c3257fd6ebb01d9014fe9c.tar.gz rails-8949ce09824b8a6796c3257fd6ebb01d9014fe9c.tar.bz2 rails-8949ce09824b8a6796c3257fd6ebb01d9014fe9c.zip |
MySQL: all_hashes compatibility with old MysqlRes class. Closes #6429.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5330 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index babc15361b..10ea2ec7f2 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* MySQL: all_hashes compatibility with old MysqlRes class. #6429 [Jeremy Kemper] + * Fix has_many :through to add the appropriate conditions when going through an association using STI. Closes #5783. [Jonathan Viney] * fix select_limited_ids_list issues in postgresql, retain current behavior in other adapters [Rick] diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 3b3c144274..036092bbdf 100755 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -3,14 +3,20 @@ require 'active_record/connection_adapters/abstract_adapter' module MysqlCompat # add all_hashes method to standard mysql-c bindings or pure ruby version def self.define_all_hashes_method! - raise 'Mysql not loaded' unless defined?(::Mysql::Result) - return if ::Mysql::Result.instance_methods.include?('all_hashes') + raise 'Mysql not loaded' unless defined?(::Mysql) + + # for compatibility + Object.const_set(:MysqlRes, Mysql::Result) unless defined?(::MysqlRes) + Object.const_set(:MysqlField, Mysql::Field) unless defined?(::MysqlField) + Object.const_set(:MysqlError, Mysql::Error) unless defined?(::MysqlError) + + return if ::MysqlRes.instance_methods.include?('all_hashes') # Ruby driver has a version string and returns null values in each_hash # C driver >= 2.7 returns null values in each_hash if Mysql.const_defined?(:VERSION) if Mysql::VERSION.is_a?(String) || Mysql::VERSION >= 20700 - ::Mysql::Result.class_eval <<-'end_eval' + ::MysqlRes.class_eval <<-'end_eval' def all_hashes rows = [] each_hash { |row| rows << row } @@ -22,7 +28,7 @@ module MysqlCompat # adapters before 2.7 don't have a version constant # and don't return null values in each_hash else - ::Mysql::Result.class_eval <<-'end_eval' + ::MysqlRes.class_eval <<-'end_eval' def all_hashes rows = [] all_fields = fetch_fields.inject({}) { |fields, f| fields[f.name] = nil; fields } |