kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

How to map results of following function in ruby? #119

Closed jgebal closed 8 years ago

jgebal commented 8 years ago

I'd like to be able to map objects returned by this function, any clues on how to do it in ryby, assuming that the base object can have many child objects?

create or replace type foo as object (
   dummy integer
) not final;

create or replace type bar under foo (
   text varchar2(100)
);

create or replace function get_object( use_bar boolean :=false ) return foo is
   begin
      return
         case
            when use_bar
            then bar(1,'bar')
            else foo(1)
            --and more coming
         end;
   end;

Any help and advice will be appreciated.

kubo commented 8 years ago

It can't for now. The following prints Foo objects only.

conn = OCI8.new(username, password)

class Foo < OCI8::Object::Base
end

class Bar < Foo
end

cursor = conn.parse("BEGIN :result := get_object(:use_var); END;")
cursor.bind_param(1, nil, Foo)
cursor.bind_param(2, false)
cursor.exec
p cursor[1]  # => Foo
cursor.bind_param(2, true)
cursor.exec
p cursor[1]  # => This should prints Bar, but Foo.

I'll fix it before the next ruby-oci8 release.

kubo commented 8 years ago

The issue was fixed by https://github.com/kubo/ruby-oci8/commit/4276bef164e69ee832cb2871a2eb8423f71b6912. Wait ruby-oci8 2.2.2 or use the master branch on github as follows.

$ git clone --depth=1 https://github.com/kubo/ruby-oci8.git
$ cd ruby-oci8
$ gem build ruby-oci8.gemspec       # create a gem file
$ gem install ./ruby-oci8-2.2.1.gem # install the created gem file