What's the benefit of using Oracle enhanced over
activerecord-jdbc-adapter? Is is any faster/more reliable?
I think I figured out the problem which imho is a bug in Oracle's
activerecord-jdbc-adapter. Through debugging I noticed that Rails
converts the date using the Oracle's TIMESTAMP function for example:
INSERT INTO <table_name> VALUES (TIMESTAMP'2010-03-29').
However Oracle expects TIMESTAMP to be ALWAYS invoked with the format
'YYYY-MM-DD H24:MI:SS'. That spells always, regardless of the
NLS_DATE_FORMAT or NLS_TIMESTAMP_FORMAT settings. If you the time
portion is not specified, the statement errors out with a "ORA-01861:
literal does not match format string" message.
Using the jdbc adapter from activerecord-jdbc-adapter 0.9.7 I found the
problem to be with the JdbcSpec::Oracle::quoted_date method:
module ::JdbcSpec
module Oracle
def quoted_date(value)
%Q{TIMESTAMP'#{super}'}
end
end
end
end
The method first converts the value to the db format as specified by:
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:db]
which is pre-set to Y-%m-%d".
which gets the date portion right will NEVER work with TIMESTAMP since
the time portion is missing. For zero times the DATE method should be
used instead. With the following fix everything works like a charm:
module ::JdbcSpec
module Oracle
def quoted_date(value)
if value.acts_like?(:time)
%Q{TIMESTAMP'#{super}'}
else
%Q{DATE'#{super}'}
end
end
end
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.