Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
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 :
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')
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.