I need to call a SQLServer stored procedure from activerecord. It has one string parameter. How is this done? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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)
On 7/27/07, Vincent Predoehl
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> I need to call a SQLServer stored procedure from activerecord. It has
> one string parameter. How is this done?
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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''") >-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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/ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---