History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-2018
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Ola Bini
Reporter: K Venkatasubramaniyan
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

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

Created: 22/Jan/08 04:39 AM   Updated: 23/Apr/08 10:15 AM
Component/s: ActiveRecord-JDBC
Affects Version/s: JRuby 1.1
Fix Version/s: JRuby 1.1

Time Tracking:
Not Specified

Environment: Oracle, ARJDBC 0.7.1, Rails 1.2.3


 Description  « Hide
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')



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
K Venkatasubramaniyan - 22/Jan/08 04:43 AM
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.


Ola Bini - 24/Jan/08 05:00 PM
Fixed on AR-JDBC trunk.

David M. Holmes - 01/Feb/08 11:09 AM
I need this fix badly. How can I get a build of AR-JDBC 886?

K Venkatasubramaniyan - 01/Feb/08 09:39 PM
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.


David M. Holmes - 01/Feb/08 09:44 PM
Thanks K V. I did the check out and copy earlier to patch my existing gem.

Charles Oliver Nutter - 23/Apr/08 10:11 AM
Marking bugs with invalid "fixed for release" as fixed in 1.1.