Last active
June 2, 2017 17:17
-
-
Save JosiahSiegel/19c77e045c906f7f97be to your computer and use it in GitHub Desktop.
#Rails Call stored procedure and retrieve return value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StoredProcedure | |
def self.return_value name, *args | |
ActiveRecord::Base.connection_pool.with_connection do |connection| | |
args = args.map{|e| connection.quote e} | |
output = connection.select_all("Declare @status int;" + | |
"EXEC @status = #{name} #{args.join(',')};" + | |
"select @status as status;") | |
return_value = Hash[*output] | |
return_value["status"] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment