JRuby

Oracle behind ActiveRecord-JDBC fails with "Invalid column index"

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1
  • Fix Version/s: JRuby 1.1
  • Component/s: None
  • Labels:
    None
  • Environment:
    Oracle, ARJDBC 0.7.1, Rails 1.2.3
  • Number of attachments :
    0

Description

A simple insert with ARJDBC & Oracle fails with the following error:

ActiveRecord::ActiveRecordError: Invalid column index: INSERT INTO SomeTable (col_1, col_2) VALUES(empty_blob(), 'test')

Activity

Hide
K Venkatasubramaniyan added a comment -

Upon investigation I found the following to be the cause of the issue:

In file jdbc_adapter.rb,the following method adds the bind variable where pk will be generated and assigned from a sequence:

alias :attributes_with_quotes_pre_oracle :attributes_with_quotes
def attributes_with_quotes(*args) #:nodoc:
aq = attributes_with_quotes_pre_oracle(*args)
if connection.class == ConnectionAdapters::JdbcAdapter && (connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer))
aq[self.class.primary_key] = "?" if args.first && aq[self.class.primary_key].nil?
end
aq
end

The code will never add a bind variable when no arguments are supplied to the method "attributes_with_quotes". This is due the fact that in the method attributes_with_quotes, the first argument "include_primary_key" is true by default when no value is passed. Many methods in AR::Base, call this method without supplying arguments and going by default behavior.

The line " aq[self.class.primary_key] = "?" if args.first && aq[self.class.primary_key].nil?
" should be modified as follows to make this work:

aq[self.class.primary_key] = "?" if (args.size == 0 || args.first) && aq[self.class.primary_key].nil?

The above code assumes the first argument to be true by default.

Hope this helps.

Show
K Venkatasubramaniyan added a comment - Upon investigation I found the following to be the cause of the issue: In file jdbc_adapter.rb,the following method adds the bind variable where pk will be generated and assigned from a sequence: alias :attributes_with_quotes_pre_oracle :attributes_with_quotes def attributes_with_quotes(*args) #:nodoc: aq = attributes_with_quotes_pre_oracle(*args) if connection.class == ConnectionAdapters::JdbcAdapter && (connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer)) aq[self.class.primary_key] = "?" if args.first && aq[self.class.primary_key].nil? end aq end The code will never add a bind variable when no arguments are supplied to the method "attributes_with_quotes". This is due the fact that in the method attributes_with_quotes, the first argument "include_primary_key" is true by default when no value is passed. Many methods in AR::Base, call this method without supplying arguments and going by default behavior. The line " aq[self.class.primary_key] = "?" if args.first && aq[self.class.primary_key].nil? " should be modified as follows to make this work: aq[self.class.primary_key] = "?" if (args.size == 0 || args.first) && aq[self.class.primary_key].nil? The above code assumes the first argument to be true by default. Hope this helps.
Hide
Ola Bini added a comment -

Fixed on AR-JDBC trunk.

Show
Ola Bini added a comment - Fixed on AR-JDBC trunk.
Hide
David M. Holmes added a comment -

I need this fix badly. How can I get a build of AR-JDBC 886?

Show
David M. Holmes added a comment - I need this fix badly. How can I get a build of AR-JDBC 886?
Hide
K Venkatasubramaniyan added a comment -

David:

You can check out the ARJDBC trunk from

http://jruby-extras.rubyforge.org/svn/trunk/activerecord-jdbc

And run the rake on top of JRuby 1.1 RC1 to build.

You can just copy the dir http://jruby-extras.rubyforge.org/svn/trunk/activerecord-jdbc/lib and update the corresponding lib dir inside your gem install.

Show
K Venkatasubramaniyan added a comment - David: You can check out the ARJDBC trunk from http://jruby-extras.rubyforge.org/svn/trunk/activerecord-jdbc And run the rake on top of JRuby 1.1 RC1 to build. You can just copy the dir http://jruby-extras.rubyforge.org/svn/trunk/activerecord-jdbc/lib and update the corresponding lib dir inside your gem install.
Hide
David M. Holmes added a comment -

Thanks K V. I did the check out and copy earlier to patch my existing gem.

Show
David M. Holmes added a comment - Thanks K V. I did the check out and copy earlier to patch my existing gem.
Hide
Charles Oliver Nutter added a comment -

Marking bugs with invalid "fixed for release" as fixed in 1.1.

Show
Charles Oliver Nutter added a comment - Marking bugs with invalid "fixed for release" as fixed in 1.1.
Hide
Navjeet added a comment -

I am using jruby 1.3.1 and jdbc-adaptor 0.9.1 and I am seeing this issue when I run db:migrate rake task on an oracle 10g database where I am trying to load data into legacy tables in a rails app.

Show
Navjeet added a comment - I am using jruby 1.3.1 and jdbc-adaptor 0.9.1 and I am seeing this issue when I run db:migrate rake task on an oracle 10g database where I am trying to load data into legacy tables in a rails app.
Hide
Charles Oliver Nutter added a comment -

Navjeet: Open a new bug with the activerecord-jdbc project on kenai.com please. This one has been marked fixed for a long time.

Show
Charles Oliver Nutter added a comment - Navjeet: Open a new bug with the activerecord-jdbc project on kenai.com please. This one has been marked fixed for a long time.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: