Forum: Ruby on Rails calling a stored procedure from activerecord

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vincent P. (Guest)
on 2007-07-28 00:58
I need to call a SQLServer stored procedure from activerecord.  It has
one string parameter.  How is this done?
Michael G. (Guest)
on 2007-07-28 01:05
(Received via mailing list)
On Jul 27, 2007, at 15:58 , Vincent P. wrote:

> I need to call a SQLServer stored procedure from activerecord.  It has
> one string parameter.  How is this done?

Take a look at ActiveRecord's #find_by_sql or #execute methods.

Michael G.
grzm seespotcode net
Brian H. (Guest)
on 2007-07-28 01:11
(Received via mailing list)
Assuming user class:

User.connection.execute("exec myproc.sp 'param'")

So basically, just like you would in any other language. However, I'd
bury
this.


class User < ActiveRecord::Base

   def self.myproc(param)
      self.connection.execute("exec myproc '#{param}'")
   end

end

That way you can call

   User.myproc("something")


When you call that, you get back a Mssql::Result class. You'll need to
look
at the api docs to figure out how to retrieve records, but it's
basically a
collection (think array)
Vincent P. (Guest)
on 2007-07-28 04:14
Can you tell me where you learned ActiveRecord?  I've been searching all
afternoon and I found no tutorials for beginners.

Brian H. wrote:
> Assuming user class:
>
> User.connection.execute("exec myproc.sp 'param'")
>
Jean N. (Guest)
on 2007-07-28 07:45
Vincent P. wrote:
> Can you tell me where you learned ActiveRecord?  I've been searching all
> afternoon and I found no tutorials for beginners.
>
> Brian H. wrote:
>> Assuming user class:
>>
>> User.connection.execute("exec myproc.sp 'param'")
>>

The Agile Web D. with Rails (2nd Edition) Chapter 17 is a great
start.

Rails Documentation: http://api.rubyonrails.org/
This topic is locked and can not be replied to.