I need to call a SQLServer stored procedure from activerecord. It has
one string parameter. How is this done?
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
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. 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/
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’”)