[ruby-oci8-commit] [522] trunk/ruby-oci8: fix methods of OCI8::Metadata:: Sequence and add testcases for them.

nobody at rubyforge.org nobody at rubyforge.org
Sun May 20 06:51:31 UTC 2012


Revision: 522
Author:   kubo
Date:     2012-05-20 06:51:31 +0000 (Sun, 20 May 2012)
Log Message:
-----------
fix methods of OCI8::Metadata::Sequence and add testcases for them.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/ocihandle.c
    trunk/ruby-oci8/lib/oci8/metadata.rb
    trunk/ruby-oci8/test/test_metadata.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2012-05-12 13:03:51 UTC (rev 521)
+++ trunk/ruby-oci8/ChangeLog	2012-05-20 06:51:31 UTC (rev 522)
@@ -1,3 +1,7 @@
+2012-05-20  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/ocihandle.c, lib/oci8/metadata.rb, test/test_metadata.rb:
+	    fix methods of OCI8::Metadata::Sequence and add testcases for them.
+
 2012-05-12  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/extconf.rb, lib/oci8.rb.in: refactor code which generates the
 	    C extention name.

Modified: trunk/ruby-oci8/ext/oci8/ocihandle.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocihandle.c	2012-05-12 13:03:51 UTC (rev 521)
+++ trunk/ruby-oci8/ext/oci8/ocihandle.c	2012-05-20 06:51:31 UTC (rev 522)
@@ -419,8 +419,9 @@
 static VALUE attr_get_integer(VALUE self, VALUE attr_type)
 {
     oci8_base_t *base = DATA_PTR(self);
+    OCINumber onum;
     union {
-        OCINumber *value;
+        void *value;
         ub8 dummy; /* padding for incorrect attrtype to protect the stack */
     } v;
     ub4 size = 0;
@@ -428,7 +429,11 @@
     v.dummy = 0;
     Check_Type(attr_type, T_FIXNUM);
     chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
-    return oci8_make_integer(v.value, oci8_errhp);
+
+    memset(&onum, 0, sizeof(onum));
+    onum.OCINumberPart[0] = size;
+    memcpy(&onum.OCINumberPart[1], v.value, size);
+    return oci8_make_integer(&onum, oci8_errhp);
 }
 
 /*

Modified: trunk/ruby-oci8/lib/oci8/metadata.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/metadata.rb	2012-05-12 13:03:51 UTC (rev 521)
+++ trunk/ruby-oci8/lib/oci8/metadata.rb	2012-05-20 06:51:31 UTC (rev 522)
@@ -1338,22 +1338,22 @@
 
       # minimum value
       def min
-        __oraint(OCI_ATTR_MIN)
+        attr_get_integer(OCI_ATTR_MIN)
       end
 
       # maximum value
       def max
-        __oraint(OCI_ATTR_MAX)
+        attr_get_integer(OCI_ATTR_MAX)
       end
 
       # increment
       def incr
-        __oraint(OCI_ATTR_INCR)
+        attr_get_integer(OCI_ATTR_INCR)
       end
 
       # number of sequence numbers cached; zero if the sequence is not a cached sequence.
       def cache
-        __oraint(OCI_ATTR_CACHE)
+        attr_get_integer(OCI_ATTR_CACHE)
       end
 
       # whether the sequence is ordered
@@ -1363,7 +1363,7 @@
 
       # high-water mark
       def hw_mark
-        __oraint(OCI_ATTR_HW_MARK)
+        attr_get_integer(OCI_ATTR_HW_MARK)
       end
     end
 

Modified: trunk/ruby-oci8/test/test_metadata.rb
===================================================================
--- trunk/ruby-oci8/test/test_metadata.rb	2012-05-12 13:03:51 UTC (rev 521)
+++ trunk/ruby-oci8/test/test_metadata.rb	2012-05-20 06:51:31 UTC (rev 522)
@@ -1406,4 +1406,74 @@
     drop_table('test_table')
   end # test_column_metadata
 
+  def test_sequence
+    begin
+      @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
+    rescue OCIError
+      raise if $!.code != 2289 # ORA-02289: sequence does not exist
+    end
+    @conn.exec(<<-EOS)
+CREATE SEQUENCE TEST_SEQ_OCI8
+    INCREMENT BY 2
+    START WITH 100
+    MAXVALUE 1000
+    MINVALUE 10
+    CYCLE
+    CACHE 5
+    ORDER
+EOS
+    [
+     @conn.describe_any('test_seq_oci8'),
+     @conn.describe_sequence('test_seq_oci8'),
+     @conn.describe_schema(@conn.username).objects.detect do |obj|
+       obj.obj_name == 'TEST_SEQ_OCI8'
+     end
+    ].each do |desc|
+      # defined in OCI8::Metadata::Base
+      assert_object_id('TEST_SEQ_OCI8', desc.obj_id)
+      assert_equal('TEST_SEQ_OCI8', desc.obj_name, 'obj_name')
+      assert_equal(@conn.username, desc.obj_schema, 'obj_schema')
+      # defined in OCI8::Metadata::Sequence
+      assert_object_id('TEST_SEQ_OCI8', desc.objid)
+      assert_equal(10, desc.min, 'min')
+      assert_equal(1000, desc.max, 'max')
+      assert_equal(2, desc.incr, 'incr')
+      assert_equal(5, desc.cache, 'cache')
+      assert(desc.order?, 'order?')
+      assert_equal(100, desc.hw_mark, 'hw_mark')
+    end
+
+    @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
+    @conn.exec(<<-EOS)
+CREATE SEQUENCE TEST_SEQ_OCI8
+    INCREMENT BY -1
+    NOMAXVALUE
+    NOMINVALUE
+    NOCYCLE
+    NOCACHE
+    NOORDER
+EOS
+    [
+     @conn.describe_any('test_seq_oci8'),
+     @conn.describe_sequence('test_seq_oci8'),
+     @conn.describe_schema(@conn.username).objects.detect do |obj|
+       obj.obj_name == 'TEST_SEQ_OCI8'
+     end
+    ].each do |desc|
+      # defined in OCI8::Metadata::Base
+      assert_object_id('TEST_SEQ_OCI8', desc.obj_id)
+      assert_equal('TEST_SEQ_OCI8', desc.obj_name, 'obj_name')
+      assert_equal(@conn.username, desc.obj_schema, 'obj_schema')
+      # defined in OCI8::Metadata::Sequence
+      assert_object_id('TEST_SEQ_OCI8', desc.objid)
+      assert_equal(-99999999999999999999999999, desc.min, 'min')
+      assert_equal(-1, desc.max, 'max')
+      assert_equal(-1, desc.incr, 'incr')
+      assert_equal(0, desc.cache, 'cache')
+      assert(!desc.order?, 'order?')
+      assert_equal(-1, desc.hw_mark, 'hw_mark')
+    end
+    @conn.exec("DROP SEQUENCE TEST_SEQ_OCI8")
+  end
+
 end # TestMetadata



More information about the ruby-oci8-commit mailing list