[ruby-oci8-commit] [530] trunk/ruby-oci8: Change the ruby type which corresponds to Oracle object type' s DATE field from DateTime to Time.

nobody at rubyforge.org nobody at rubyforge.org
Sun Aug 5 13:06:34 UTC 2012


Revision: 530
Author:   kubo
Date:     2012-08-05 13:06:33 +0000 (Sun, 05 Aug 2012)
Log Message:
-----------
Change the ruby type which corresponds to Oracle object type's DATE field from DateTime to Time.
fix github issue #17.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/lib/oci8/object.rb
    trunk/ruby-oci8/test/setup_test_object.sql
    trunk/ruby-oci8/test/test_object.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2012-07-31 11:21:28 UTC (rev 529)
+++ trunk/ruby-oci8/ChangeLog	2012-08-05 13:06:33 UTC (rev 530)
@@ -1,3 +1,9 @@
+2012-08-05  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/oci8/object.rb: Change the ruby type which corresponds to
+	    Oracle object type's DATE field from DateTime to Time.
+	* test/setup_test_object.sql, test/test_object.rb:
+	    Fix github issue #17 reported by Yasuo Honda.
+
 2012-07-31  KUBO Takehiro  <kubo at jiubao.org>
 	* test/config.rb, test/test_datetime.rb: refactor test code by adding
 	    global functions convert_to_time() and convert_to_datetime(),

Modified: trunk/ruby-oci8/lib/oci8/object.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/object.rb	2012-07-31 11:21:28 UTC (rev 529)
+++ trunk/ruby-oci8/lib/oci8/object.rb	2012-08-05 13:06:33 UTC (rev 530)
@@ -466,7 +466,7 @@
       when :date
         [ATTR_OCIDATE,   nil, SIZE_OF_OCIDATE, 2, ALIGNMENT_OF_OCIDATE,
          Proc.new do |val| datetime_to_array(val, :date) end, # set_proc
-         Proc.new do |val| array_to_datetime(val, :local) end, # get_proc
+         Proc.new do |val| array_to_time(val, :local) end, # get_proc
         ]
       when :binary_double
         [ATTR_BINARY_DOUBLE, nil, SIZE_OF_DOUBLE, 2, ALIGNMENT_OF_DOUBLE]

Modified: trunk/ruby-oci8/test/setup_test_object.sql
===================================================================
--- trunk/ruby-oci8/test/setup_test_object.sql	2012-07-31 11:21:28 UTC (rev 529)
+++ trunk/ruby-oci8/test/setup_test_object.sql	2012-08-05 13:06:33 UTC (rev 530)
@@ -60,6 +60,7 @@
 --  date_array_val rb_test_date_array,
 
   constructor function rb_test_obj(n number) return self as result,
+  static function test_object_version return integer,
   static function class_func(n number) return rb_test_obj,
   static procedure class_proc1(obj out rb_test_obj, n number),
   static procedure class_proc2(obj in out rb_test_obj),
@@ -72,7 +73,7 @@
   constructor function rb_test_obj(n number) return self as result is
     function to_test_date(n number) return date is
     begin
-      return to_date(to_char(1000 + n * 10, 'FM0000') ||
+      return to_date(to_char(1990 + n, 'FM0000') ||
                      to_char(mod(round(n) * 5, 12) + 1, 'FM00') ||
                      to_char(mod(round(n) * 7, 27) + 1, 'FM00') ||
                      to_char(mod(round(n) * 9, 24), 'FM00') ||
@@ -113,6 +114,11 @@
     return;
   end;
 
+  static function test_object_version return integer is
+  begin
+    return 2;
+  end;
+
   static function class_func(n number) return rb_test_obj is
   begin
     return rb_test_obj(n);

Modified: trunk/ruby-oci8/test/test_object.rb
===================================================================
--- trunk/ruby-oci8/test/test_object.rb	2012-07-31 11:21:28 UTC (rev 529)
+++ trunk/ruby-oci8/test/test_object.rb	2012-08-05 13:06:33 UTC (rev 530)
@@ -3,6 +3,7 @@
 require File.dirname(__FILE__) + '/config'
 
 conn = OCI8.new($dbuser, $dbpass, $dbname)
+error_message = nil
 begin
   conn.describe_type('rb_test_int_array')
   conn.describe_type('rb_test_flt_array')
@@ -16,23 +17,34 @@
   conn.describe_type('rb_test_obj')
   conn.describe_table('rb_test_obj_tab1')
   conn.describe_table('rb_test_obj_tab2')
+
+  class RbTestObj < OCI8::Object::Base
+  end
+
+  begin
+    version = RbTestObj.test_object_version(conn)
+    error_message = "Invalid test object version" if version != 2
+  rescue NoMethodError
+    raise unless $!.to_s.include?('test_object_version')
+    error_message = "rb_test_obj.test_object_version is not declared."
+  end
 rescue OCIError
   raise if $!.code != 4043
-  raise <<EOS
+  error_message = $!.to_s
+ensure
+  conn.logoff
+end
 
-#{$!}
+raise <<EOS if error_message
+
+#{error_message}
 You need to execute SQL statements in #{File.dirname(__FILE__)}/setup_test_object.sql as follows:
 
   $ sqlplus USERNAME/PASSWORD
   SQL> @test/setup_test_object.sql
 
 EOS
-ensure
-  conn.logoff
-end
 
-class RbTestObj < OCI8::Object::Base
-end
 
 class RbTestIntArray < OCI8::Object::Base
 end
@@ -89,15 +101,14 @@
       @n = 0.0
     end
 
-    @@offset = ::Time.local(2007).utc_offset.to_r / 86400
     def to_test_date(n)
-      year = (1000 + n * 10).round
+      year = (1990 + n).round
       month = (n.round * 5) % 12 + 1
       mday = (n.round * 7) % 27 + 1
       hour = (n.round * 9) % 24
       minute = (n.round * 11) % 60
       sec = (n.round * 13) % 60
-      ::DateTime.civil(year, month, mday, hour, minute, sec, @@offset)
+      convert_to_time(year, month, mday, hour, minute, sec, 0, nil)
     end
     private :to_test_date
 
@@ -258,7 +269,6 @@
   def test_select2
     expected_val = ExpectedVal.new
     orig_val = OCI8::BindType::Mapping[:date]
-    OCI8::BindType::Mapping[:date] = OCI8::BindType::DateTime # TODO: Delete this line later.
     begin
       @conn.exec("select * from rb_test_obj_tab2 order by int_val") do |row|
         assert(expected_val.next)



More information about the ruby-oci8-commit mailing list