mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
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
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user