Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enable use of MySQL stored procedures by default.

[#3204 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 4f5cac53b7ce2e8694c836a9dfe3619f9f7c9ccc 1 parent 179b451
@m4dc4p m4dc4p authored jeremy committed
View
5 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -64,12 +64,15 @@ def self.mysql_connection(config) # :nodoc:
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
View
8 activerecord/test/cases/connection_test_mysql.rb
@@ -41,6 +41,14 @@ def test_successful_reconnection_after_timeout_with_verify
sleep 2
@connection.verify!
assert @connection.active?
+ end
+
+ # Test that MySQL allows multiple results for stored procedures
+ if Mysql.const_defined?(:CLIENT_MULTI_RESULTS)
+ def test_multi_results
+ rows = ActiveRecord::Base.connection.select_rows('CALL ten();')
+ assert_equal 10, rows[0][0].to_i, "ten() did not return 10 as expected: #{rows.inspect}"
+ end
end
private
View
12 activerecord/test/schema/mysql_specific_schema.rb
@@ -9,4 +9,16 @@
t.text :medium_text, :limit => 16777215
t.text :long_text, :limit => 2147483647
end
+
+ ActiveRecord::Base.connection.execute <<-SQL
+DROP PROCEDURE IF EXISTS ten;
+SQL
+
+ ActiveRecord::Base.connection.execute <<-SQL
+CREATE PROCEDURE ten() SQL SECURITY INVOKER
+BEGIN
+ select 10;
+END
+SQL
+
end

1 comment on commit 4f5cac5

@asktoby

I'm running ruby 1.8.7 and rails 2.0.2, as installed by apt-get in Ubuntu. I want to use stored procedures, so your patch looks great, but don't really know where to start.

I've downloaded and extracted the source, now I have a bunch of files/folders* but no README or INSTALL file. Do I need to compile these to replace my installed Rails? I'm used to "./configure;make;make install" but this is different.

*(actionmailer actionpack activemodel activerecord activeresource activesupport ci doc pushgems.rb railties Rakefile release.rb)

Please sign in to comment.
Something went wrong with that request. Please try again.