Chris Andrews
2005-Sep-17 22:23 UTC
ActiveRecord and oci8 vs. PL/SQL procedures returning cursors
Hi,
I''ve been trying to get a Rails app to run against an existing Oracle
schema. I have this patch for set_sequence_name applied to 0.13.1:
http://dev.rubyonrails.com/attachment/ticket/1798/oci_omnibus.3.patch
which gets basic ActiveRecord CRUD things working. However I need to
call a stored procedure which returns a cursor. The oci8 module can do
this, but the methods needed don''t seem to be exposed in OCIAdapter.
I want to say this:
conn = OCI8.new(''user'', ''pass'',
''tnsname'')
plsql = conn.parse("BEGIN some_proc(:in_param, :cursor); END;")
plsql.bind_param('':in_param'', in_param)
plsql.bind_param('':cursor'', OCI8::Cursor)
plsql.exec
cursor = plsql['':cursor'']
cursor.fetch do |r|
# do something with each row returned.
end
but that requires access to the low-level OCI8 connection object. If I
add an "attr_reader :connection" to OCIAdapter, then I can do:
conn = ActiveRecord::Base.connection.connection
to get what I need, but that''s pretty ugly. So what''s the
right way to
do this? A nicer way to get at the OCI8 object? Expose some more OCI8
methods in OCIAdapter? Teach OCIAdapter to handle these cases itself?
Thanks,
Chris.