Changeset 5533
- Timestamp:
- 11/16/06 01:41:22 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r5520 r5533 38 38 * Document other options available to migration's add_column. #6419 [grg] 39 39 40 * MySQL: all_hashes compatibility with old MysqlRes class. #6429 [Jeremy Kemper]40 * MySQL: all_hashes compatibility with old MysqlRes class. #6429, #6601 [Jeremy Kemper] 41 41 42 42 * Fix has_many :through to add the appropriate conditions when going through an association using STI. Closes #5783. [Jonathan Viney] trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
r5384 r5533 6 6 raise 'Mysql not loaded' unless defined?(::Mysql) 7 7 8 # for compatibility 9 Object.const_set(:MysqlRes, Mysql::Result) unless defined?(::MysqlRes) 10 Object.const_set(:MysqlField, Mysql::Field) unless defined?(::MysqlField) 11 Object.const_set(:MysqlError, Mysql::Error) unless defined?(::MysqlError) 12 13 return if ::MysqlRes.instance_methods.include?('all_hashes') 8 target = defined?(Mysql::Result) ? Mysql::Result : MysqlRes 9 return if target.instance_methods.include?('all_hashes') 14 10 15 11 # Ruby driver has a version string and returns null values in each_hash 16 12 # C driver >= 2.7 returns null values in each_hash 17 if Mysql.const_defined?(:VERSION) 18 if Mysql::VERSION.is_a?(String) || Mysql::VERSION >= 20700 19 ::MysqlRes.class_eval <<-'end_eval' 20 def all_hashes 21 rows = [] 22 each_hash { |row| rows << row } 23 rows 24 end 25 end_eval 26 end 13 if Mysql.const_defined?(:VERSION) && (Mysql::VERSION.is_a?(String) || Mysql::VERSION >= 20700) 14 target.class_eval <<-'end_eval' 15 def all_hashes 16 rows = [] 17 each_hash { |row| rows << row } 18 rows 19 end 20 end_eval 27 21 28 22 # adapters before 2.7 don't have a version constant 29 23 # and don't return null values in each_hash 30 24 else 31 ::MysqlRes.class_eval <<-'end_eval'25 target.class_eval <<-'end_eval' 32 26 def all_hashes 33 27 rows = [] … … 38 32 end_eval 39 33 end 34 35 unless target.instance_methods.include?('all_hashes') 36 raise "Failed to defined #{target.name}#all_hashes method. Mysql::VERSION = #{Mysql::VERSION.inspect}" 37 end 40 38 end 41 39 end … … 43 41 module ActiveRecord 44 42 class Base 45 # Establishes a connection to the database that's used by all Active Record objects. 46 def self.mysql_connection(config) # :nodoc: 47 # Only include the MySQL driver if one hasn't already been loaded 43 def self.require_mysql 44 # Include the MySQL driver if one hasn't already been loaded 48 45 unless defined? Mysql 49 46 begin 50 47 require_library_or_gem 'mysql' 51 48 rescue LoadError => cannot_require_mysql 52 # Only use the supplied backupRuby/MySQL driver if no driver is already in place49 # Use the bundled Ruby/MySQL driver if no driver is already in place 53 50 begin 54 51 require 'active_record/vendor/mysql' … … 61 58 # Define Mysql::Result.all_hashes 62 59 MysqlCompat.define_all_hashes_method! 63 60 end 61 62 # Establishes a connection to the database that's used by all Active Record objects. 63 def self.mysql_connection(config) # :nodoc: 64 64 config = config.symbolize_keys 65 65 host = config[:host] … … 75 75 end 76 76 77 require_mysql 77 78 mysql = Mysql.init 78 79 mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslkey] 80 79 81 ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config) 80 82 end