1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

MySQL: more robust test for nullified result hashes. References #3124.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3246 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2005-12-08 05:07:45 +00:00
parent df901ce345
commit cf54a71352
2 changed files with 4 additions and 8 deletions

View file

@ -1,5 +1,7 @@
*SVN* *SVN*
* MySQL: more robust test for nullified result hashes. #3124 [Stefan Kaes]
* SQLite: find database file when RAILS_ROOT is a symlink. #3116 [anna@wota.jp] * SQLite: find database file when RAILS_ROOT is a symlink. #3116 [anna@wota.jp]
* Reloading an instance refreshes its aggregations as well as its associations. #3024 [François Beausolei] * Reloading an instance refreshes its aggregations as well as its associations. #3024 [François Beausolei]

View file

@ -8,14 +8,10 @@ module ActiveRecord
unless defined? Mysql unless defined? Mysql
begin begin
require_library_or_gem 'mysql' require_library_or_gem 'mysql'
# The C version of mysql returns null fields in each_hash if Mysql::VERSION is defined
ConnectionAdapters::MysqlAdapter.null_values_in_each_hash = Mysql.const_defined?(:VERSION)
rescue LoadError => cannot_require_mysql rescue LoadError => cannot_require_mysql
# Only use the supplied backup Ruby/MySQL driver if no driver is already in place # Only use the supplied backup Ruby/MySQL driver if no driver is already in place
begin begin
require 'active_record/vendor/mysql' require 'active_record/vendor/mysql'
# The ruby version of mysql returns null fields in each_hash
ConnectionAdapters::MysqlAdapter.null_values_in_each_hash = true
rescue LoadError rescue LoadError
raise cannot_require_mysql raise cannot_require_mysql
end end
@ -77,9 +73,6 @@ module ActiveRecord
@@emulate_booleans = true @@emulate_booleans = true
cattr_accessor :emulate_booleans cattr_accessor :emulate_booleans
cattr_accessor :null_values_in_each_hash
@@null_values_in_each_hash = false
LOST_CONNECTION_ERROR_MESSAGES = [ LOST_CONNECTION_ERROR_MESSAGES = [
"Server shutdown in progress", "Server shutdown in progress",
"Broken pipe", "Broken pipe",
@ -90,6 +83,7 @@ module ActiveRecord
def initialize(connection, logger, connection_options=nil, config={}) def initialize(connection, logger, connection_options=nil, config={})
super(connection, logger) super(connection, logger)
@connection_options = connection_options @connection_options = connection_options
@null_values_in_each_hash = Mysql.const_defined?(:VERSION)
@config = config @config = config
connect connect
end end
@ -332,7 +326,7 @@ module ActiveRecord
@connection.query_with_result = true @connection.query_with_result = true
result = execute(sql, name) result = execute(sql, name)
rows = [] rows = []
if @@null_values_in_each_hash if @null_values_in_each_hash
result.each_hash { |row| rows << row } result.each_hash { |row| rows << row }
else else
all_fields = result.fetch_fields.inject({}) { |fields, f| fields[f.name] = nil; fields } all_fields = result.fetch_fields.inject({}) { |fields, f| fields[f.name] = nil; fields }