Forum: JRuby Active record - Oracle DATE/TIMESTAMP issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Adrian M. (Guest)
on 2009-04-15 19:40
Hi,

I am new to active record so apologies for the newbie question, but I am
trying to set it up to access an Oracle database. Please note, this not
a rails app and never will be. I want to use JRuby to write dashboard
scripts for monitoring an number of back-end ETL data interfaces for
which I am primarily responsible.

My config is as follows:

Client PC running Windows
  JRuby 1.2.0
  Java 1.6.0_07
  Oracle driver - ojdbc14.jar
  activerecord-2.3.2
  activerecord-jdbc-adapter-0.9.1

Remote database hosted on Solaris
  Oracle 10.2.03

My problem is that active record is failing to typecast date and time
fields at all.

For example, the following cutdown example attempts to access 'RUN_DT'
which is defined in the database as a DATE (I am seeing the same issue
on TIMESTAMP fields too)...


require 'java'
require 'ojdbc14.jar'

puts "Starting active record"
require 'rubygems'
gem 'activerecord-jdbc-adapter'
require 'jdbc_adapter'
require 'active_record'

puts "Connecting to MXGN"
ActiveRecord::Base.establish_connection(
:adapter => 'jdbc',
:driver => 'oracle.jdbc.OracleDriver',
:url => 'jdbc:oracle:thin:@MYHOST:1550:THEDB',
:username => 'FOO',
:password => 'bar'
)
puts "Running a query"

class TblMigrationWork < ActiveRecord::Base
set_table_name "tblmigrationwork"
end

result = TblMigrationWork.find(:first, :conditions => 'run_id = 1')
puts result.run_dt


Produces....


Starting active record
Connecting to MXGN
Running a query
C:/gems/gems/activerecord-2.3.2/lib/active_record/base.rb:1964:in
`method_missing': undefined method `string_to_time' for
#<Class:0x755866> (NoMethodError)
from
C:/gems/gems/activerecord-jdbc-adapter-0.9.1/lib/jdbc_adapter/jdbc_oracle.rb:58:in
`string_to_time'
from
C:/gems/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:211:in
`run_dt'
from
C:/gems/gems/activerecord-2.3.2/lib/active_record/attribute_methods.rb:244:in
`method_missing'
from H:\sandbox\DBPlay\lib\main.rb:25


I can query VARCHAR and NUMERIC fields with no problems.

I have had a good look round the forums but I cannot find any reference
to this kind of problem. Can you please suggest a solution or where the
problem may be ocurring?

Many Thanks

Adrian
This topic is locked and can not be replied to.