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.
Facc5387a195549b6d7a86c3257027bf?d=identicon&s=25 Vincent Predoehl (vpredoehl)
on 2007-07-27 22:58
I need to call a SQLServer stored procedure from activerecord.  It has
one string parameter.  How is this done?
Ae82cad40a0caca9c932d45c7a9eb3cd?d=identicon&s=25 Michael Glaesemann (Guest)
on 2007-07-27 23:05
(Received via mailing list)
On Jul 27, 2007, at 15:58 , Vincent Predoehl 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 Glaesemann
grzm seespotcode net
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2007-07-27 23: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)
Facc5387a195549b6d7a86c3257027bf?d=identicon&s=25 Vincent Predoehl (vpredoehl)
on 2007-07-28 02:14
Can you tell me where you learned ActiveRecord?  I've been searching all
afternoon and I found no tutorials for beginners.

Brian Hogan wrote:
> Assuming user class:
>
> User.connection.execute("exec myproc.sp 'param'")
>
9f4e11fd04ca1e5a56d00ff3531104ed?d=identicon&s=25 Jean Nibee (jeannibee)
on 2007-07-28 05:45
Vincent Predoehl wrote:
> Can you tell me where you learned ActiveRecord?  I've been searching all
> afternoon and I found no tutorials for beginners.
>
> Brian Hogan wrote:
>> Assuming user class:
>>
>> User.connection.execute("exec myproc.sp 'param'")
>>

The Agile Web Development 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.