[ruby-oci8-commit] [488] trunk/ruby-oci8: fix "wrong number of arguments (1 for 2)" when date datatype in a object type is gotten.

nobody at rubyforge.org nobody at rubyforge.org
Thu Dec 15 09:40:28 EST 2011


Revision: 488
Author:   kubo
Date:     2011-12-15 09:40:27 -0500 (Thu, 15 Dec 2011)

Log Message:
-----------
fix "wrong number of arguments (1 for 2)" when date datatype in a object type is gotten.

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	2011-12-13 10:46:02 UTC (rev 487)
+++ trunk/ruby-oci8/ChangeLog	2011-12-15 14:40:27 UTC (rev 488)
@@ -1,3 +1,9 @@
+2011-12-15  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/oci8/object.rb, test/setup_test_object.sql, test/test_object.rb:
+	    fix "wrong number of arguments (1 for 2)" when date datatype in a object
+	    type is gotten.
+	    (repored by Leoš Bitto)
+
 2011-12-13  KUBO Takehiro  <kubo at jiubao.org>
 	* VERSION: update to 2.1.0.
 	* ext/oci8/error.c, ext/oci8/oci8.c, ext/oci8/oci8.h, ext/oci8/ocidatetime.c,

Modified: trunk/ruby-oci8/lib/oci8/object.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/object.rb	2011-12-13 10:46:02 UTC (rev 487)
+++ trunk/ruby-oci8/lib/oci8/object.rb	2011-12-15 14:40:27 UTC (rev 488)
@@ -443,7 +443,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) end, # get_proc
+         Proc.new do |val| array_to_datetime(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	2011-12-13 10:46:02 UTC (rev 487)
+++ trunk/ruby-oci8/test/setup_test_object.sql	2011-12-15 14:40:27 UTC (rev 488)
@@ -33,6 +33,8 @@
 /
 create or replace type rb_test_obj_elem_ary_of_ary as array(50) of rb_test_obj_elem_array
 /
+--create or replace type rb_test_date_array as array(50) of date
+--/
 create type rb_test_obj as object (
   int_val integer,
   flt_val float,
@@ -51,6 +53,8 @@
   raw_array_val rb_test_raw_array,
   obj_array_val rb_test_obj_elem_array,
   obj_ary_of_ary_val rb_test_obj_elem_ary_of_ary,
+  date_val date,
+--  date_array_val rb_test_date_array,
 
   constructor function rb_test_obj(n number) return self as result,
   static function class_func(n number) return rb_test_obj,
@@ -63,6 +67,15 @@
 create or replace type body rb_test_obj is
 
   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') ||
+                     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') ||
+                     to_char(mod(round(n) * 11, 60), 'FM00') ||
+                     to_char(mod(round(n) * 13, 60), 'FM00'), 'yyyymmddhh24miss');
+    end;
   begin
     self.int_val := n;
     self.flt_val := n;
@@ -72,6 +85,7 @@
     self.str_val := to_char(n);
     self.raw_val := utl_raw.cast_to_raw(to_char(n));
     self.obj_val := rb_test_obj_elem(n, n + 1);
+    self.date_val := to_test_date(n);
     if self.int_val != 1 then
       self.int_array_val := rb_test_int_array(n, n + 1, n + 2);
       self.flt_array_val := rb_test_flt_array(n, n + 1, n + 2);
@@ -86,6 +100,9 @@
                                                    rb_test_obj_elem(n + 1, n + 2),
                                                    rb_test_obj_elem(n + 2, n + 3));
       self.obj_ary_of_ary_val := rb_test_obj_elem_ary_of_ary(self.obj_array_val);
+--      self.date_array_val := rb_test_date_array(to_test_date(n),
+--                                                to_test_date(n + 1),
+--                                                to_test_date(n + 2));
     end if;
     return;
   end;

Modified: trunk/ruby-oci8/test/test_object.rb
===================================================================
--- trunk/ruby-oci8/test/test_object.rb	2011-12-13 10:46:02 UTC (rev 487)
+++ trunk/ruby-oci8/test/test_object.rb	2011-12-15 14:40:27 UTC (rev 488)
@@ -50,11 +50,25 @@
     attr_reader :raw_array_val
     attr_reader :obj_array_val
     attr_reader :obj_ary_of_ary_val
+    attr_reader :date_val
+#    attr_reader :date_array_val
 
     def initialize
       @n = 0.0
     end
 
+    @@offset = ::Time.local(2007).utc_offset.to_r / 86400
+    def to_test_date(n)
+      year = (1000 + n * 10).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)
+    end
+    private :to_test_date
+
     def next
       @n += 1.2
       @n = (@n * 10).round / 10.0
@@ -67,6 +81,7 @@
       @str_val = $` if /.0$/ =~ @str_val
       @raw_val = @str_val
       @obj_val = ExpectedValObjElem.new(@int_val, @int_val + 1)
+      @date_val = to_test_date(@n)
       if @int_val == 1
         @int_array_val = nil
         @flt_array_val = nil
@@ -77,6 +92,7 @@
         @raw_array_val = nil
         @obj_array_val = nil
         @obj_ary_of_ary_val = nil
+#        @date_array_val = nil
       else
         @int_array_val = []
         @flt_array_val = []
@@ -87,6 +103,7 @@
         @raw_array_val = []
         @obj_array_val = []
         @obj_ary_of_ary_val = []
+#        @date_array_val = []
         0.upto(2) do |i|
           ival = @n.round
           val = (@n + i).to_s
@@ -99,6 +116,7 @@
           @str_array_val[i] = val
           @raw_array_val[i] = val
           @obj_array_val[i] = ExpectedValObjElem.new(@int_val + i, @int_val + i + 1)
+#          @date_array_val[i] = to_test_date(@n + i)
         end
         @obj_ary_of_ary_val[0] = @obj_array_val
       end
@@ -124,6 +142,8 @@
         raw_array_val = val[14]
         obj_array_val = val[15]
         obj_ary_of_ary_val = val[16]
+        date_val = val[17]
+#        date_array_val = val[18]
       else
         assert_instance_of(RbTestObj, val)
         int_val = val.int_val
@@ -143,6 +163,8 @@
         raw_array_val = val.raw_array_val
         obj_array_val = val.obj_array_val
         obj_ary_of_ary_val = val.obj_ary_of_ary_val
+        date_val = val.date_val
+#        date_array_val = val.date_array_val
       end
 
       assert_equal(@int_val, int_val)
@@ -162,6 +184,8 @@
       assert_equal(@raw_array_val, raw_array_val && raw_array_val.to_ary)
       assert_equal(@obj_array_val, obj_array_val && obj_array_val.to_ary)
       assert_equal(@obj_ary_of_ary_val, obj_ary_of_ary_val && obj_ary_of_ary_val.to_ary.collect { |elem| elem.to_ary })
+      assert_equal(@date_val, date_val)
+#      assert_equal(@date_array_val, date_array_val && date_array_val.to_ary)
     end
 
     def assert_array_in_delta(exp, val)
@@ -189,11 +213,17 @@
 
   def test_select2
     expected_val = ExpectedVal.new
-    @conn.exec("select * from rb_test_obj_tab2 order by int_val") do |row|
-      assert(expected_val.next)
-      expected_val.should_be_equal(row)
+    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)
+        expected_val.should_be_equal(row)
+      end
+      assert(!expected_val.next)
+    ensure
+      OCI8::BindType::Mapping[:date] = orig_val
     end
-    assert(!expected_val.next)
   end
 
   def test_select3




More information about the ruby-oci8-commit mailing list