# Mysql stored procedures from Rails

**URL:** <https://www.ruby-forum.com/t/mysql-stored-procedures-from-rails/89335>\
**Category:** Rails\
**Created:** [March 28, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/mysql-stored-procedures-from-rails/89335 "2006-03-28T20:31:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Larsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a4c791/32.png) [@Tomas\_Larsson](https://www.ruby-forum.com/u/Tomas_Larsson)\
**Post date:** [March 28, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/mysql-stored-procedures-from-rails/89335/1 "2006-03-28T20:31:56Z")

</div>

Hi all,

I know stored procedures are considered evil around, but there are times  
when you just have to use them. In the project I’m working on, I needed  
to call a mysql5 stored procedure, but I only got an error message  
saying “ActiveRecord::StatementInvalid: Mysql::Error: PROCEDURE  
vc.testsp can’t return a result set in the given context: call testsp()”  
I found out from here: [http://bugs.mysql.com/bug.php?id=2658](http://bugs.mysql.com/bug.php?id=2658) that mysql  
needs the flag CLIENT\_MULTI\_RESULTS set if you want to be able to return  
result sets from stored procedures. The problem is that mysql\_adapter.rb  
doesn’t pass the flag parameter to the mysql connect function. When I  
hacked it in there myself, things worked perfectly.

Am I going to about this the wrong way? Even though things work fine  
now, I don’t want to have to hack this fix back in when new versions of  
rails are released…

Cheers,  
tomas

---

<div class="post-metadata">

**Author:** ![Tomas\_Larsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a4c791/32.png) [@Tomas\_Larsson](https://www.ruby-forum.com/u/Tomas_Larsson)\
**Post date:** [April 11, 2006, 9:53pm UTC](https://www.ruby-forum.com/t/mysql-stored-procedures-from-rails/89335/2 "2006-04-11T21:53:09Z")

</div>

Tomas Larsson wrote:

> Hi all,
> 
> I know stored procedures are considered evil around, but there are times  
> when you just have to use them. In the project I’m working on, I needed  
> to call a mysql5 stored procedure, but I only got an error message  
> saying “ActiveRecord::StatementInvalid: Mysql::Error: PROCEDURE  
> vc.testsp can’t return a result set in the given context: call testsp()”  
> I found out from here: [http://bugs.mysql.com/bug.php?id=2658](http://bugs.mysql.com/bug.php?id=2658) that mysql  
> needs the flag CLIENT\_MULTI\_RESULTS set if you want to be able to return  
> result sets from stored procedures. The problem is that mysql\_adapter.rb  
> doesn’t pass the flag parameter to the mysql connect function. When I  
> hacked it in there myself, things worked perfectly.
> 
> Am I going to about this the wrong way? Even though things work fine  
> now, I don’t want to have to hack this fix back in when new versions of  
> rails are released…
> 
> Cheers,  
> tomas

Could you possibly post the changes you made to mysql\_adapter.rb? I  
need to get a result set from a stored procedure into RoR too! Thanks  
-T

---

<div class="post-metadata">

**Author:** ![Tomas\_Larsson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a4c791/32.png) [@Tomas\_Larsson](https://www.ruby-forum.com/u/Tomas_Larsson)\
**Post date:** [April 11, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/mysql-stored-procedures-from-rails/89335/3 "2006-04-11T23:00:15Z")

</div>

Mabye the changes you made could be patched into the core file for  
future  
releases of RoR. I’d also suggest you post a diff of the file or just  
the  
changes you made to the adapter.

Best,  
Ryan
