Prev | Current Page 399 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

connection.select_all("exec sp_helprole")
roles.each do |rec|
puts rec["RoleName"]
end
This example shows a number of interesting differences between Oracle and SQL Server
in how they execute stored procedures. First, SQL Server requires that we set the connection
parameter of :autocommit to false. Second, to execute a SQL Server stored procedure, you use
the connection.select_all statement, instead of connection.execute like you do with Oracle
(calling the execute statement for SQL Server will not return results). Finally, you can see that
CHAPTER 7 ?–  WORKING WITH LEGACY SCHEMA 180
the select_all statement returned an Array of Hash values, so we are required to access the
data via this array and hash structure instead of as Active Record objects.
These differences alone should highlight the fact that working with stored procedures
from within your Active Record programs is a bit of headache and requires some research on
your part into how specifically your adapter can support them (as well as how your SQL syntax
can execute them).


Pages:
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411