kubo / ruby-oci8

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

Unsupported Typecode Timestamp Error #185

Closed Sheafraidh closed 6 years ago

Sheafraidh commented 6 years ago

Hi,

I'm having an issue with timestamp variable, when passed to a procedure as an attribute of an object type. I'm getting this error: unsupported typecode timestamp. The code to reproduce the error is attached bellow. I know the error is self-explaining, but still I wonder if there's some workaround/patch how to overcome this, or some planned implementation in the near future.

Thank you in advance for your reply.

Best regards, Karel

Oracle scripts:

CREATE OR REPLACE TYPE TIMESTAMP_TYPE AS OBJECT (ATTR_TIMESTAMP TIMESTAMP);
/

CREATE OR REPLACE PACKAGE TIMESTAMP_TEST_PKG IS
  PROCEDURE test(input IN timestamp_type);
END TIMESTAMP_TEST_PKG;
/

CREATE OR REPLACE PACKAGE BODY TIMESTAMP_TEST_PKG IS
  PROCEDURE test(input IN timestamp_type) IS
  BEGIN
    NULL;
  END test;
END TIMESTAMP_TEST_PKG;
/

Ruby script:

require 'oci8'

class TimestampType < OCI8::Object::Base
  set_typename('timestamp_type')
end

conn = OCI8.new('user/password@database')

cursor = conn.parse("BEGIN TIMESTAMP_TEST_PKG.test(:input); END;")
data = {attr_timestamp: Time.now()}
cursor.bind_param(:input, {type: TimestampType, value: data})
cursor.exec

conn.logoff

Error I get:

C:\APPS\Ruby22-x64\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) L:/KarelS/eshop/CI_UnitTesty/timestamp.rb
C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:519:in `check_metadata': unsupported typecode timestamp (RuntimeError)
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:536:in `initialize'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:400:in `new'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:400:in `block in initialize_named_type'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:399:in `collect'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:399:in `initialize_named_type'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:388:in `initialize'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:27:in `new'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/object.rb:27:in `get_tdo_by_class'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/cursor.rb:488:in `make_bind_object'
    from C:/APPS/Ruby22-x64/lib/ruby/gems/2.2.0/gems/ruby-oci8-2.2.5.1-x64-mingw32/lib/oci8/cursor.rb:100:in `bind_param'
    from L:/KarelS/eshop/CI_UnitTesty/timestamp.rb:27:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

Process finished with exit code 1
kubo commented 6 years ago

I fixed it. Could you try the latest source in git?

Install devkit-mingw64-64 here in advance

git clone https://github.com/kubo/ruby-oci8.git # or download https://github.com/kubo/ruby-oci8/archive/master.zip and unzip it.
cd ruby-oci8
gem build ruby-oci8.gemspec
c:\devkit-mingw64-64\devkitvars.bat # if devkit-mingw64-64 is installed here.
gem install .\ruby-oci8-2.2.5.1.gem

I have not tested it enough yet. I'll add test cases for timestamp attributes later, probably at this weekend. Other timestamp datatypes such as timestamp with time zone will be supported later.

kubo commented 6 years ago

I added tests for timestamp datatype in object attributes. Timestamp with time zone is also supported.

It will be included in the next version. But I could not say when. It may not be in near future.

Could you build latest gem and install it as in my previous comment? Otherwise, could you build a binary gem and distribute it in your organization?

Install devkit-mingw64-64 here in advance.

git clone https://github.com/kubo/ruby-oci8.git # or download https://github.com/kubo/ruby-oci8/archive/master.zip and unzip it.
cd ruby-oci8
c:\devkit-mingw64-64\devkitvars.bat # if devkit-mingw64-64 is installed in c:\devkit-mingw64-64.
ruby setup.rb config -- --with-runtime-check
make
gem build ruby-oci8.gemspec -- current
Sheafraidh commented 6 years ago

Thank you very much for adding the timestamp!

I finally got some time and some machine where I could build it (ruby as a language is not much compatible with corporate restrictions). Anyway the build and the use of this feature worked seamlessly.

Thank you very much once more.

Best regards, Karel