Turns out that Oracle may return a Date object even if the SQL column is a timestamp if the hours, minutes and seconds are all 0.

The attached patch works around this. However, I don't know if this patch is a good idea, with the following code in the Oracle adapter:

        def guess_date_or_time(value)
          (value.hour == 0 and value.min == 0 and value.sec == 0) ?
            Date.new(value.year, value.month, value.day) : value
        end

Does this seem like such a good idea?  I tried this:

n = Node.find(:first)
n.created_at.class => Time
n.created_at = Date.new(2006, 6, 2)
n.save
n = Node.find(:first)
n.created_at.class => Date

So while you may have a timestamp column, if you store an timestamp at midnight, which is possible, you end up with a different object with different methods.

So maybe apply the patch to get the test to pass, but maybe we should consider changing Oracle's adapter.

Regards,
Blair

Michael Schoen wrote:
"bitsweat" has given AR/Oracle some love, but it's still unhappy...

http://dev.rubyonrails.org/changeset/4414
------------------------------------------------------------------------
r4414 | bitsweat | 2006-06-02 18:02:42 -0700 (Fri, 02 Jun 2006) | 1 line

Uncry thyself
------------------------------------------------------------------------

U  activesupport/lib/active_support/core_ext/hash/conversions.rb
Updated to revision 4414.

  1) Failure:
test_to_xml(BasicsTest) [./test/base_test.rb:1231]:
<false> is not true.

890 tests, 3132 assertions, 1 failures, 0 errors
rake aborted!
Command failed with status (1): [/usr/pkg/ruby184/bin/ruby -Ilib:test:test/...]

(See full trace by running task with --trace)

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core
Index: lib/active_record/base.rb
===================================================================
--- lib/active_record/base.rb   (revision 4414)
+++ lib/active_record/base.rb   (working copy)
@@ -1771,13 +1771,15 @@
           columns_hash = self.class.columns_hash
           a_names.each do |name|
 
+            type = columns_hash[name].type
+            value = self.send(name)
+
             # To be consistent with the ActiveRecord instance being
             # converted into a Hash using #attributes, convert SQL
             # type names.  Map the different "string" types all to
             # "string", as the client of the XML does not care if a
             # TEXT or VARCHAR column stores the value.
 
-            type = columns_hash[name].type
             case type
             when :text
               type = :string
@@ -1785,9 +1787,15 @@
               type = :datetime
             end
 
+            # The Oracle database adaptor may have the column type as
+            # a :datetime, but may return Date objects if the hours,
+            # minutes and seconds are all zero.
+            if :datetime == type && value.is_a?(::Date)
+              type = :date
+            end
+
             attributes = options[:skip_types] ? { } : { :type => type }
 
-            value = self.send(name)
             if dasherize
               name = name.dasherize
             end
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to