Finally, I found the error with 'invalid date' on Oracle 8. Seems that
oracle not only allows 'null' dates, but also 'empty' dates. On 'empty'
dates, the error would come up!
Below is what I changed in oracle_enhanced_oci_connection.rb in
lib\ruby\gems\activerecord-oracle_enhanced-adapter-1.2.1\lib\connection_adapters\.
The changed lines are marked with #MVR as comment above it. Starts around
line 128:
# ruby-oci8 1.0 returns OraDate
when OraDate
# MVR: treat 'empty' date/time strings as null too!
if !(v.hour == 0 && v.minute == 0 && v.second == 0 && v.year
== 0 && v.month == 0 && v.day == 0)
# RSI: added emulate_dates_by_column_name functionality
if OracleEnhancedAdapter.emulate_dates && (v.hour == 0 &&
v.minute == 0 && v.second == 0)
v.to_date
else
# code from Time.time_with_datetime_fallback
begin
Time.send(Base.default_timezone, v.year, v.month,
v.day, v.hour, v.minute, v.second)
rescue
offset = Base.default_timezone.to_sym == :local ?
::DateTime.local_offset : 0
::DateTime.civil(v.year, v.month, v.day, v.hour,
v.minute, v.second, offset)
end
end
end
# ruby-oci8 2.0 returns Time or DateTime
when Time, DateTime
# MVR: treat 'empty' date/time strings as null too!
if !(v.hour == 0 && v.minute == 0 && v.second == 0 && v.year
== 0 && v.month == 0 && v.day == 0)
if OracleEnhancedAdapter.emulate_dates && (v.hour == 0 &&
v.min == 0 && v.sec == 0)
v.to_date
else
# recreate Time or DateTime using Base.default_timezone
begin
Time.send(Base.default_timezone, v.year, v.month,
v.day, v.hour, v.min, v.sec)
rescue
offset = Base.default_timezone.to_sym == :local ?
::DateTime.local_offset : 0
::DateTime.civil(v.year, v.month, v.day, v.hour,
v.min, v.sec, offset)
end
end
end
else v
end
Hope this is of any help to those fighting with Oracle ;) Cheers
On Wed, Sep 23, 2009 at 12:45 PM, Martijn van Rheenen <[email protected]>wrote:
> As far as I can see now, the problem is in the oracle_enhanced adapter or
> in ActiveRecord. I created this small Ruby script to test each component:
>
> ------------
> require 'rubygems'
> gem 'ruby-oci8'
> require 'oci8'
>
> gem 'activerecord'
> gem 'activerecord-oracle_enhanced-adapter'
> require 'activerecord'
>
> puts("Testing Oracle OCI gem by selecting record:")
> OCI8.new('ccems', 'ccems', 'XE').exec('SELECT * FROM filelist WHERE
> (filelist.fllid = 959)') do
> |r| puts r.join("\n")
> end
>
> puts("Testing oracle_enhanced installation:")
> ActiveRecord::Base.establish_connection(
> :adapter => "oracle_enhanced", :database => "XE", :username => "ccems",
> :password => "ccems")
>
> puts("oracle_enhanced connected succesfully")
>
> puts("Testing selection of one record")
> class Filelist < ActiveRecord::Base
> set_table_name 'filelist'
> set_primary_key 'fllid'
> #set_date_columns 'creation_datetime', 'modification_datetime',
> 'firstrecord_datetime'
> #ignore_table_columns 'creation_datetime', 'modification_datetime',
> 'firstrecord_datetime'
> end
>
> filelist = Filelist.find(959);
> ------------
>
> and, as expected, the very last line returns this error:
>
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:219:in
> `log': ArgumentError: invalid date: SELECT * FROM filelist WHERE
> (filelist.fllid = 959) (ActiveRecord::StatementInvalid)
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:958:in
> `select'
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in
> `select_all_without_query_cache'
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in
> `select_all'
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:661:in
> `find_by_sql'
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1548:in
> `find_every'
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1583:in
> `find_one'
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1569:in
> `find_from_ids'
> from
> D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:616:in
> `find'
> from test.rb:27
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---