From 292384fc69334e4224ede7e323ef64ccda4275b3 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Tue, 14 Jun 2011 14:41:58 -0700 Subject: [PATCH 1/3] turn off casting by default in AR adapter so it can lazily cast values as they're accessed - this should help performance for tables with complex types like Date, Time or BigDecimal --- .../connection_adapters/mysql2_adapter.rb | 53 +------------------ 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/lib/active_record/connection_adapters/mysql2_adapter.rb b/lib/active_record/connection_adapters/mysql2_adapter.rb index fb14cb723..c1a00e834 100644 --- a/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -38,59 +38,10 @@ def extract_default(default) end def has_default? - return false if sql_type =~ /blob/i || type == :text #mysql forbids defaults on blob and text columns + return false if sql_type =~ /blob/i || type == :text # mysql forbids defaults on blob and text columns super end - # Returns the Ruby class that corresponds to the abstract data type. - def klass - case type - when :integer then Fixnum - when :float then Float - when :decimal then BigDecimal - when :datetime then Time - when :date then Date - when :timestamp then Time - when :time then Time - when :text, :string then String - when :binary then String - when :boolean then Object - end - end - - def type_cast(value) - return nil if value.nil? - case type - when :string then value - when :text then value - when :integer then value.to_i rescue value ? 1 : 0 - when :float then value.to_f # returns self if it's already a Float - when :decimal then self.class.value_to_decimal(value) - when :datetime, :timestamp then value.class == Time ? value : self.class.string_to_time(value) - when :time then value.class == Time ? value : self.class.string_to_dummy_time(value) - when :date then value.class == Date ? value : self.class.string_to_date(value) - when :binary then value - when :boolean then self.class.value_to_boolean(value) - else value - end - end - - def type_cast_code(var_name) - case type - when :string then nil - when :text then nil - when :integer then "#{var_name}.to_i rescue #{var_name} ? 1 : 0" - when :float then "#{var_name}.to_f" - when :decimal then "#{self.class.name}.value_to_decimal(#{var_name})" - when :datetime, :timestamp then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_time(#{var_name})" - when :time then "#{var_name}.class == Time ? #{var_name} : #{self.class.name}.string_to_dummy_time(#{var_name})" - when :date then "#{var_name}.class == Date ? #{var_name} : #{self.class.name}.string_to_date(#{var_name})" - when :binary then nil - when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})" - else nil - end - end - private def simplified_type(field_type) return :boolean if Mysql2Adapter.emulate_booleans && field_type.downcase.index(BOOL) @@ -611,7 +562,7 @@ def connect end def configure_connection - @connection.query_options.merge!(:as => :array) + @connection.query_options.merge!(:as => :array, :cast => false) # By default, MySQL 'where id is null' selects the last inserted id. # Turn this off. http://dev.rubyonrails.org/ticket/6778 From 2afef408b5a60ae09e665a933bd88eb7859c3be9 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Tue, 14 Jun 2011 15:34:22 -0700 Subject: [PATCH 2/3] eager-casting is enabled by default --- lib/mysql2/client.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/mysql2/client.rb b/lib/mysql2/client.rb index 0cc99dee7..aac779c89 100644 --- a/lib/mysql2/client.rb +++ b/lib/mysql2/client.rb @@ -9,7 +9,8 @@ class Client :database_timezone => :local, # timezone Mysql2 will assume datetime objects are stored in :application_timezone => nil, # timezone Mysql2 will convert to before handing the object back to the caller :cache_rows => true, # tells Mysql2 to use it's internal row cache for results - :connect_flags => REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION + :connect_flags => REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION, + :cast => true } def initialize(opts = {}) From 1e909c9d8234951e50790bd7e537e04f288fcf42 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Tue, 14 Jun 2011 15:34:43 -0700 Subject: [PATCH 3/3] update files for 0.2.8 release --- CHANGELOG.md | 8 ++++++-- lib/mysql2/version.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b28585e..c1185a63d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Changelog -## In Git -* Avoid thread blocking on Ruby 1.9.x under Windows. Patch by Roger Pack. +## 0.2.8 (June 14th, 2011) +* disable async support, and access to the underlying file descriptor under Windows. It's never worked reliably and ruby-core has a lot of work to do in order to make it possible. +* added support for turning eager-casting off. This is especially useful in ORMs that will lazily cast values upon access. +* added a warning if a 0.2.x release is being used with ActiveRecord 3.1 since both the 0.2.x releases and AR 3.1 have mysql2 adapters, we want you to use the one in AR 3.1 +* added Mysql2::Client.escape (class-level method) +* disabled eager-casting in the bundled ActiveRecord adapter (for Rails 3.0 or less) ## 0.2.7 (March 28th, 2011) * various fixes for em_mysql2 and fiber usage diff --git a/lib/mysql2/version.rb b/lib/mysql2/version.rb index 17aaa2910..68342e6d9 100644 --- a/lib/mysql2/version.rb +++ b/lib/mysql2/version.rb @@ -1,3 +1,3 @@ module Mysql2 - VERSION = "0.2.7" + VERSION = "0.2.8" end \ No newline at end of file