kubo / ruby-oci8

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

unsupported typecode opaque #215

Open robin1607 opened 5 years ago

robin1607 commented 5 years ago

I'm getting 'unsupported typecode opaque' error when calling function which returns oracle json_object or json_array.

 `     RuntimeError:
   unsupported typecode opaque
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:529:in `check_metadata'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:546:in `initialize'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:400:in `new'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:400:in `block in initialize_named_type'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:399:in `collect'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:399:in `initialize_named_type'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:388:in `initialize'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:27:in `new'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/object.rb:27:in `get_tdo_by_class'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/cursor.rb:495:in `make_bind_object'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-oci8-2.2.7/lib/oci8/cursor.rb:104:in `bind_param'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-plsql-0.7.1/lib/plsql/oci_connection.rb:104:in `bind_param'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-plsql-0.7.1/lib/plsql/procedure_call.rb:23:in `block in exec'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-plsql-0.7.1/lib/plsql/procedure_call.rb:22:in `each'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-plsql-0.7.1/lib/plsql/procedure_call.rb:22:in `exec'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-plsql-0.7.1/lib/plsql/procedure.rb:266:in `exec'
 # /Users/usr/.rvm/gems/ruby-2.6.3/gems/ruby-plsql-0.7.1/lib/plsql/package.rb:67:in `method_missing'
 # ./spec/Packages/test/mytest.rb:41:in `block (3 levels) in <top (required)>'`
kubo commented 5 years ago

@robin1607 Could you post sample code to reproduce the issue?

robin1607 commented 5 years ago

PLSQL:

create or replace package testpackage as

function exampleFunction
    return json_object_t;

end testpackage;

create or replace package body testpackage as

function exampleFunction
return json_object_t
is
    example_json_object      json_object_t;
begin
    example_json_object := new json_object_t;
    example_json_object.put('testkey', 'testvalue');
    return example_json_object;
end exampleFunction;

end testpackage;
/

Ruby:

json_object = plsql.testpackage.exampleFunction # Throws Error
puts json_object
kubo commented 5 years ago

Could you change the return type from json_objec_t to varchar2 or clob?

Ruby-oci8 converts object type attribute values to ruby values. However there are no methods to convert opaque types. This issue will be fixed by redesign of object type support, which I have had in mind since decade ago, though I have not noticed the opaque type issue. Well, the priority is low for me as long as there are workarounds.

robin1607 commented 5 years ago

Thanks for your answer. We have already thought about the workarounds, but for unit tests of small methods we would have to change our clear and structured system design of JSON handling. So the workarounds are not the best solution for us.

I understand the the redesign of object types has a low priority so we will find another way.