I have tried ActiveRecord-JDBC 0.5 with Oracle JDBC driver taken from version
10.2.0.3, the only version
that supports retrieving auto-generated keys.
I encountered error "Invalid column type: getLong not
implemented for class
oracle.jdbc.driver.T4CRowidAccessor: INSERT INTO emp
(empno, comm, hiredate, mgr, deptno, ename, job, sal"
inside JdbcAdapterInternalService.execute_insert
I end-up with a simple solution that modified ruby code of ActiveRecord-JDBC to
avoid using
JdbcAdapterInternalService.execute_insert as follows
module ActiveRecord
class Base
def attributes_with_quotes(include_primary_key =true) #:nodoc:
aq = attributes_with_quotes_pre_oracle(include_primary_key)
if connection.class ==ConnectionAdapters::JdbcAdapter &&
connection.is_a?(JdbcSpec::Mimer)
aq[self.class.primary_key] = "?" if include_primary_key &&
aq[self.class.primary_key].nil?
end
if connection.class ==ConnectionAdapters::JdbcAdapter &&
connection.is_a?(JdbcSpec::Oracle)
aq[self.class.primary_key] = "?" if include_primary_key
end
aq
end
end
end
module ::JdbcSpec
module Oracle
def insert(sql, name = nil, pk = nil, id_value =nil, sequence_name = nil)
#:nodoc:
if pk.nil? # Who called us? What does the sql look like? No idea!
execute sql, name
else # Assume the sql contains a bind-variable for the id
id_value = select_one("select #{sequence_name}.nextval id from
dual")['id'].to_i unless id_value
log(sql, name) {
@connection.execute_id_insert(sql,id_value)
}
end
id_value
end
end
end
Verification code is below
require 'rubygems'
gem 'ActiveRecord-JDBC','0.5'
require 'jdbc_adapter'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'oracle.jdbc.driver.OracleDriver',
:url => 'jdbc:oracle:thin:@localhost:1521:DEV',
:username => "scott",
:password => "tiger",
)
class Emp < ActiveRecord::Base
set_table_name 'emp'
set_primary_key 'empno'
end
emp = Emp.new
emp.id = 9999
emp.save
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the
tools to get online.
http://smallbusiness.yahoo.com/webhosting
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel