From c9d3c48dc6389feb2001372cd76e96274e773c9b Mon Sep 17 00:00:00 2001 From: Justin Bailey Date: Mon, 14 Sep 2009 17:53:04 -0700 Subject: Enable use of MySQL stored procedures by default. [#3204 state:committed] Signed-off-by: Jeremy Kemper --- activerecord/lib/active_record/connection_adapters/mysql_adapter.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index 1bb1c0bc15..1072eb7ac1 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -65,12 +65,15 @@ module ActiveRecord raise end end + MysqlCompat.define_all_hashes_method! mysql = Mysql.init mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher]) if config[:sslca] || config[:sslkey] - ConnectionAdapters::MysqlAdapter.new(mysql, logger, [host, username, password, database, port, socket], config) + default_flags = Mysql.const_defined?(:CLIENT_MULTI_RESULTS) ? Mysql::CLIENT_MULTI_RESULTS : 0 + options = [host, username, password, database, port, socket, default_flags] + ConnectionAdapters::MysqlAdapter.new(mysql, logger, options, config) end end -- cgit v1.2.3 From 7701c6f1c012abb09cd61d3092fbb40fc77aeb6d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 17 Sep 2009 16:15:04 -0700 Subject: Collapse nested conditional --- activerecord/lib/active_record/base.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index afa4185c60..1adab2e832 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1654,22 +1654,20 @@ module ActiveRecord #:nodoc: if subclass_name.empty? allocate - else - # Ignore type if no column is present since it was probably - # pulled in from a sloppy join. - unless columns_hash.include?(inheritance_column) - allocate + # Ignore type if no column is present since it was probably + # pulled in from a sloppy join. + elsif !columns_hash.include?(inheritance_column) + allocate - else - begin - compute_type(subclass_name).allocate - rescue NameError - raise SubclassNotFound, - "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " + - "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + - "Please rename this column if you didn't intend it to be used for storing the inheritance class " + - "or overwrite #{self.to_s}.inheritance_column to use another column for that information." - end + else + begin + compute_type(subclass_name).allocate + rescue NameError + raise SubclassNotFound, + "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " + + "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + + "Please rename this column if you didn't intend it to be used for storing the inheritance class " + + "or overwrite #{self.to_s}.inheritance_column to use another column for that information." end end else -- cgit v1.2.3 From 3fc2d1ebd932428548961ce509c55fecc00f448e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 17 Sep 2009 17:26:29 -0700 Subject: Extract class-finder method from instantiate --- activerecord/lib/active_record/base.rb | 46 ++++++++++++++-------------------- 1 file changed, 19 insertions(+), 27 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 1adab2e832..502fe0442e 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1648,34 +1648,10 @@ module ActiveRecord #:nodoc: # single-table inheritance model that makes it possible to create # objects of different types from the same table. def instantiate(record) - object = - if subclass_name = record[inheritance_column] - # No type given. - if subclass_name.empty? - allocate + object = find_sti_class(record[inheritance_column]).allocate - # Ignore type if no column is present since it was probably - # pulled in from a sloppy join. - elsif !columns_hash.include?(inheritance_column) - allocate - - else - begin - compute_type(subclass_name).allocate - rescue NameError - raise SubclassNotFound, - "The single-table inheritance mechanism failed to locate the subclass: '#{record[inheritance_column]}'. " + - "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + - "Please rename this column if you didn't intend it to be used for storing the inheritance class " + - "or overwrite #{self.to_s}.inheritance_column to use another column for that information." - end - end - else - allocate - end - - object.instance_variable_set("@attributes", record) - object.instance_variable_set("@attributes_cache", Hash.new) + object.instance_variable_set(:'@attributes', record) + object.instance_variable_set(:'@attributes_cache', {}) object.send(:_run_find_callbacks) object.send(:_run_initialize_callbacks) @@ -1683,6 +1659,22 @@ module ActiveRecord #:nodoc: object end + def find_sti_class(type_name) + if type_name.blank? || !columns_hash.include?(inheritance_column) + self + else + begin + compute_type(type_name) + rescue NameError + raise SubclassNotFound, + "The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " + + "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " + + "Please rename this column if you didn't intend it to be used for storing the inheritance class " + + "or overwrite #{name}.inheritance_column to use another column for that information." + end + end + end + # Nest the type name in the same module as this class. # Bar is "MyApp::Business::Bar" relative to MyApp::Business::Foo def type_name_with_module(type_name) -- cgit v1.2.3