This project is archived and is in readonly mode.

#3151 ✓resolved
Justin Bailey

MySQL adapter update to enable use of stored procedures

Reported by Justin Bailey | September 5th, 2009 @ 05:13 PM | in 2.3.9

Rails apps running against MySQL databases cannot execute stored procedures. Passing the Mysql::CLIENT_MULTI_RESULTS flag to the native driver when the connection is first created fixes the issue. A Google search shows that this problem has been long-standing but unsolved.

This patch adds a configuration option to the MySQL adapter, :enable_call. If database.yml contains this option, the flag will be passed to the driver and the connection will be set up to allow stored procedures. For example, this database.yml uses the new option:

  adapter: mysql
  database: gamesite
  username: root
  enable_call: true
  host: localhost
  odbc-name: localhost_gamesite

The option is disabled by default, so the adapter continues to behave as before.

This patch is against the v2.3.4 tag. It adds a unit test to activerecord/test/cases/connection_test_mysql.rb which demonstrates the bug. A stored procedure has been added to the database schema for the test. It can be created by running "rake test_mysql TEST=test/cases/aaa_create_tables_test.rb". Right now, a number of tests are failing or throwing errors, but none of those are caused by my patch. "rake test_mysql' before my patch gives:

2115 tests, 6692 assertions, 3 failures, 86 errors

and afterward

2116 tests, 6694 assertions, 3 failures, 86 errors

Comments from reviewers welcome. Please let me know what I can do to get this patch committed.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Shared Ticket Bins

Referenced by