kubo / ruby-oci8

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

Nil comparison error in cursor.rb when calling PL/SQL procedure #61

Closed mike-bourgeous closed 9 years ago

mike-bourgeous commented 10 years ago

Occasionally when I use the ruby-plsql gem to call a particular PL/SQL procedure, I get the following error in OCI8::Cursor:

comparison of Fixnum with nil failed
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:510:in `>'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:510:in `upto'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:510:in `define_columns'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-oci8-2.1.7/lib/oci8/cursor.rb:127:in `exec'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-plsql-0.5.0/lib/plsql/oci_connection.rb:97:in `exec'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-plsql-0.5.0/lib/plsql/oci_connection.rb:82:in `new_from_query'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-plsql-0.5.0/lib/plsql/oci_connection.rb:132:in `cursor_from_query'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-plsql-0.5.0/lib/plsql/connection.rb:102:in `select_first'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-plsql-0.5.0/lib/plsql/sql_statements.rb:5:in `select_first'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-plsql-0.5.0/lib/plsql/schema.rb:196:in `find_database_object'
    /home/username/.rvm/gems/ruby-2.1.1@gemset_name/gems/ruby-plsql-0.5.0/lib/plsql/schema.rb:179:in `method_missing'
    /home/username/devel/application/lib/application_name/oracle/module_name.rb:37:in `block in apply'

The PL/SQL method signature looks like this, and typically returns NULL in errbuf and retcode:

   PROCEDURE apply (p_id      IN NUMBER,
                    p_val1    IN VARCHAR2,
                    p_val2    IN VARCHAR2,
                    p_amount  IN NUMBER,
                    errbuf    OUT NOCOPY VARCHAR2,
                    retcode   OUT NOCOPY VARCHAR2);

I call the procedure like this:

plsql.package_name.apply(12345678, 'abcdefgh', 'ijklmnop', 0)
# => {:errbuf => nil, :retcode => nil}

I'm not sure what exactly the ruby-plsql gem does from there.

mike-bourgeous commented 10 years ago

This can be reproduced using the scripts from issue #62: https://gist.github.com/mike-bourgeous/07d65f63d6b448de9a38

kubo commented 9 years ago

62 and this issue is caused by bugs in both ruby-oci8 and ruby-plsql.

Ruby-plsql may close cursors used in other threads and try to use a closed cursor. In ruby-oci8, using a closed cursor causes various problems such as segmentation fault, nil comparison error in cursor.rb and so on. 6dc961bd0255f4b2ad8d960e02107245216e2dc4 fix it by raising an exception in the case.