[ruby-oci8-commit] [285] trunk/ruby-oci8: * ext/oci8/metadata.c: fix bugs when trying to use already freed

nobody at rubyforge.org nobody at rubyforge.org
Tue Aug 26 09:40:00 EDT 2008


Revision: 285
Author:   kubo
Date:     2008-08-26 09:39:59 -0400 (Tue, 26 Aug 2008)

Log Message:
-----------
* ext/oci8/metadata.c: fix bugs when trying to use already freed
    OCI8::Metadata::*.
* ext/oci8/ocidatetime.c: fix OCI8::BindType::OCIDate#set().
* ext/oci8/ocinumber.c: undef OraNumber#round_prec and OraNumber
    #shift when using Oracle 8.0.
* lib/oci8/datetime.rb, lib/oci8/metadata.rb: fix bugs when using
    Oracle 8.0.
* test/config.rb, test/test_dbi.rb, test/test_metadata.rb,
  test/test_oci8.rb, test/test_oranumber.rb: do same with the
    previous commit.
* test/test_datetime.rb: disable some test cases when Oracle 8.1
    or lower.
* test/test_dbi_clob.rb: fix when testing in a deep directory.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/metadata.c
    trunk/ruby-oci8/ext/oci8/ocidatetime.c
    trunk/ruby-oci8/ext/oci8/ocinumber.c
    trunk/ruby-oci8/lib/oci8/datetime.rb
    trunk/ruby-oci8/lib/oci8/metadata.rb
    trunk/ruby-oci8/test/config.rb
    trunk/ruby-oci8/test/test_datetime.rb
    trunk/ruby-oci8/test/test_dbi.rb
    trunk/ruby-oci8/test/test_dbi_clob.rb
    trunk/ruby-oci8/test/test_metadata.rb
    trunk/ruby-oci8/test/test_oci8.rb
    trunk/ruby-oci8/test/test_oranumber.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/ChangeLog	2008-08-26 13:39:59 UTC (rev 285)
@@ -1,4 +1,19 @@
 2008-08-26  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/metadata.c: fix bugs when trying to use already freed
+	    OCI8::Metadata::*.
+	* ext/oci8/ocidatetime.c: fix OCI8::BindType::OCIDate#set().
+	* ext/oci8/ocinumber.c: undef OraNumber#round_prec and OraNumber
+	    #shift when using Oracle 8.0.
+	* lib/oci8/datetime.rb, lib/oci8/metadata.rb: fix bugs when using
+	    Oracle 8.0.
+	* test/config.rb, test/test_dbi.rb, test/test_metadata.rb,
+	  test/test_oci8.rb, test/test_oranumber.rb: do same with the
+	    previous commit.
+	* test/test_datetime.rb: disable some test cases when Oracle 8.1
+	    or lower.
+	* test/test_dbi_clob.rb: fix when testing in a deep directory.
+
+2008-08-26  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/apiwrap.c.tmpl, ext/oci8/apiwrap.h.tmpl, ext/oci8/apiwrap.rb
 	  ext/oci8/apiwrap.yml, ext/oci8/bind.c, ext/oci8/extconf.rb,
 	  ext/oci8/oci8.h, ext/oci8/ocidatetime.c, ext/oci8/xmldb.c,

Modified: trunk/ruby-oci8/ext/oci8/metadata.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/metadata.c	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/ext/oci8/metadata.c	2008-08-26 13:39:59 UTC (rev 285)
@@ -75,7 +75,7 @@
     ub1 value = 0;
     ub4 size = sizeof(value);
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != 1) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect 1, but %d", size);
     }
@@ -88,7 +88,7 @@
     ub2 value = 0;
     ub4 size = sizeof(value);
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != 2) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect 2, but %d", size);
     }
@@ -101,7 +101,7 @@
     oci8_base_t *base = DATA_PTR(self);
     ub2 value = 0;
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, 0, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, 0, FIX2INT(idx), oci8_errhp));
     return INT2FIX(value);
 }
 
@@ -111,7 +111,7 @@
     ub4 value = 0;
     ub4 size = sizeof(value);
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != 4) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect 4, but %d", size);
     }
@@ -128,7 +128,7 @@
     sb1 value = 0;
     ub4 size = sizeof(value);
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != 1) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect 1, but %d", size);
     }
@@ -141,7 +141,7 @@
     sb2 value = 0;
     ub4 size = sizeof(value);
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != 2) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect 2, but %d", size);
     }
@@ -154,7 +154,7 @@
     sb4 value = 0;
     ub4 size = sizeof(value);
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != 4) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect 4, but %d", size);
     }
@@ -173,7 +173,7 @@
     ub4 size;
 
     /* remote call sometimes? */
-    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &value, &size, FIX2INT(idx), oci8_errhp));
     return rb_str_new(TO_CHARPTR(value), size);
 }
 
@@ -185,7 +185,7 @@
     static VALUE cOraDate = Qnil;
     VALUE obj;
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != 7) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect 7, but %d", size);
     }
@@ -203,7 +203,7 @@
     ub4 size = 21;
     OCINumber on;
 
-    oci_lc(OCIAttrGet(base->hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size >= 22) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect less than 22, but %d", size);
     }
@@ -221,7 +221,7 @@
     ub4 size = sizeof(value);
 
     /* remote call? */
-    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, OCI_DTYPE_PARAM, &value, &size, FIX2INT(idx), oci8_errhp));
+    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &value, &size, FIX2INT(idx), oci8_errhp));
     if (size != sizeof(OCIParam *)) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect %d, but %d", (sb4)sizeof(OCIParam *), size);
     }
@@ -233,7 +233,7 @@
     oci8_metadata_t *md = DATA_PTR(self);
     OCIParam *value;
 
-    oci_lc(OCIParamGet(md->base.hp.ptr, OCI_DTYPE_PARAM, oci8_errhp, (dvoid *)&value, FIX2INT(idx)));
+    oci_lc(OCIParamGet(md->base.hp.ptr, md->base.type, oci8_errhp, (dvoid *)&value, FIX2INT(idx)));
     return oci8_metadata_create(value, md->svc, self);
 }
 
@@ -298,7 +298,7 @@
     OCIRef *ref = NULL;
 
     /* remote call */
-    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, OCI_DTYPE_PARAM, &ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp));
+    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp));
     return oci8_do_describe(md->svc, ref, 0, OCI_OTYPE_REF, klass, Qfalse);
 }
 
@@ -309,7 +309,7 @@
     OCIRef *tdo_ref = NULL;
     void *tdo;
 
-    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, OCI_DTYPE_PARAM, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp));
+    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp));
     if (tdo_ref == NULL)
         return Qnil;
     oci_lc(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo));

Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocidatetime.c	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/ext/oci8/ocidatetime.c	2008-08-26 13:39:59 UTC (rev 285)
@@ -58,7 +58,7 @@
     if (minute < 0 || 59 < minute) {
         rb_raise(rb_eRuntimeError, "out of minute range: %ld", minute);
     }
-    od->OCIDateTime.OCITimeHH = (ub1)minute;
+    od->OCIDateTime.OCITimeMI = (ub1)minute;
     /* second */
     second = NUM2LONG(RARRAY_PTR(val)[5]);
     if (second < 0 || 59 < second) {

Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocinumber.c	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/ext/oci8/ocinumber.c	2008-08-26 13:39:59 UTC (rev 285)
@@ -782,10 +782,6 @@
 {
     OCINumber r;
 
-    if (!have_OCINumberPrec) {
-        rb_raise(rb_eNotImpError, "The Oracle client version is too lower to use %s#round_prec",
-                 rb_obj_classname(self));
-    }
     oci_lc(OCINumberPrec(oci8_errhp, _NUMBER(self), NUM2INT(ndigs), &r));
     return oci8_make_ocinumber(&r);
 }
@@ -951,10 +947,6 @@
 {
     OCINumber result;
 
-    if (!have_OCINumberShift) {
-        rb_raise(rb_eNotImpError, "The Oracle client version is too lower to use %s#shift",
-                 rb_obj_classname(self));
-    }
     oci_lc(OCINumberShift(oci8_errhp, _NUMBER(self), NUM2INT(exp), &result));
     return oci8_make_ocinumber(&result);
 }
@@ -1187,7 +1179,9 @@
     rb_define_method(cOCINumber, "ceil", onum_ceil, 0);
     rb_define_method(cOCINumber, "round", onum_round, -1);
     rb_define_method(cOCINumber, "truncate", onum_trunc, -1);
-    rb_define_method(cOCINumber, "round_prec", onum_round_prec, 1);
+    if (have_OCINumberPrec) {
+        rb_define_method(cOCINumber, "round_prec", onum_round_prec, 1);
+    }
 
     rb_define_method(cOCINumber, "to_s", onum_to_s, 0);
     rb_define_method(cOCINumber, "to_char", onum_to_char, -1);
@@ -1197,7 +1191,9 @@
 
     rb_define_method(cOCINumber, "zero?", onum_zero_p, 0);
     rb_define_method(cOCINumber, "abs", onum_abs, 0);
-    rb_define_method(cOCINumber, "shift", onum_shift, 1);
+    if (have_OCINumberShift) {
+        rb_define_method(cOCINumber, "shift", onum_shift, 1);
+    }
 
     rb_define_method_nodoc(cOCINumber, "hash", onum_hash, 0);
     rb_define_method_nodoc(cOCINumber, "inspect", onum_inspect, 0);

Modified: trunk/ruby-oci8/lib/oci8/datetime.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/datetime.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/lib/oci8/datetime.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -91,8 +91,8 @@
         begin
           ::Time.local(year, month, day, hour, minute, sec)
         rescue StandardError
+          ocidate_to_datetime(ary)
         end
-        ocidate_to_datetime(ary)
       end
 
       if OCI8.oracle_client_version >= ORAVER_9_1

Modified: trunk/ruby-oci8/lib/oci8/metadata.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/metadata.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/lib/oci8/metadata.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -279,7 +279,7 @@
                           Proc.new do |p|
                             if p.charset_form == :nchar
                               "NVARCHAR2(#{p.char_size})"
-                            elsif (p.respond_to? :char_used?) && (p.char_used?)
+                            elsif p.char_used?
                               "VARCHAR2(#{p.char_size} CHAR)"
                             else
                               "VARCHAR2(#{p.data_size})"
@@ -329,7 +329,7 @@
                            Proc.new do |p|
                              if p.charset_form == :nchar
                                "NCHAR(#{p.char_size})"
-                             elsif (p.respond_to? :char_used?) && (p.char_used?)
+                             elsif p.char_used?
                                "CHAR(#{p.char_size} CHAR)"
                              else
                                "CHAR(#{p.data_size})"
@@ -1350,6 +1350,10 @@
         def char_size
           __ub2(OCI_ATTR_CHAR_SIZE)
         end
+      else
+        def char_used?
+          false
+        end
       end
 
       # The maximum size of the column. This length is

Modified: trunk/ruby-oci8/test/config.rb
===================================================================
--- trunk/ruby-oci8/test/config.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/test/config.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -25,26 +25,20 @@
 # $oracle_version: lower value of $oracle_server_version and $oracle_client_version.
 conn = OCI8.new($dbuser, $dbpass, $dbname)
 conn.exec('select value from database_compatible_level') do |row|
-  ver = row[0].split('.')
-  $oracle_server_version = (ver[0] + ver[1] + ver[2]).to_i
+  ver = row[0].split('.').collect do |v| v.to_i; end
+  $oracle_server_version = (ver[0] << 24) + (ver[1] << 20) + (ver[2] << 12)
 end
 conn.logoff
 
-$oracle_client_version = OCI8.oracle_client_version
-if $oracle_server_version < $oracle_client_version
+if $oracle_server_version < OCI8.oracle_client_version
   $oracle_version = $oracle_server_version
 else
-  $oracle_version = $oracle_client_version
+  $oracle_version = OCI8.oracle_client_version
 end
 
-if $oracle_version <= 805
-  $describe_need_object_mode = true
+if $oracle_version < OCI8::ORAVER_8_1
   $test_clob = false
-elsif $oracle_version < 810
-  $describe_need_object_mode = false
-  $test_clob = false
 else
-  $describe_need_object_mode = false
   $test_clob = true
 end
 
@@ -83,7 +77,7 @@
       end
 
       def drop_table(table_name)
-        if $oracle_server_version < 1000
+        if $oracle_server_version < OCI8::ORAVER_10_1
           # Oracle 8 - 9i
           sql = "DROP TABLE #{table_name}"
         else

Modified: trunk/ruby-oci8/test/test_datetime.rb
===================================================================
--- trunk/ruby-oci8/test/test_datetime.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/test/test_datetime.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -71,6 +71,8 @@
   end
 
   def test_timestamp_select
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     ['2005-12-31 23:59:59.999999000',
      '2006-01-01 00:00:00.000000000'].each do |date|
       @conn.exec(<<-EOS) do |row|
@@ -82,6 +84,8 @@
   end
 
   def test_timestamp_out_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 BEGIN
   :out := TO_TIMESTAMP(:in, 'YYYY-MM-DD HH24:MI:SS.FF');
@@ -99,6 +103,8 @@
   end
 
   def test_timestamp_in_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 BEGIN
   :out := TO_CHAR(:in, 'YYYY-MM-DD HH24:MI:SS.FF');
@@ -116,6 +122,8 @@
   end
 
   def test_timestamp_tz_select
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     ['2005-12-31 23:59:59.999999000 +08:30',
      '2006-01-01 00:00:00.000000000 -08:30'].each do |date|
       @conn.exec(<<-EOS) do |row|
@@ -127,6 +135,8 @@
   end
 
   def test_timestamp_tz_out_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 BEGIN
   :out := TO_TIMESTAMP_TZ(:in, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM');
@@ -144,6 +154,8 @@
   end
 
   def test_timestamp_tz_in_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 BEGIN
   :out := TO_CHAR(:in, 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM');
@@ -215,6 +227,8 @@
   end
 
   def test_interval_ym_select
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     [['2006-01-01', '2004-03-01'],
      ['2006-01-01', '2005-03-01'],
      ['2006-01-01', '2006-03-01'],
@@ -231,6 +245,8 @@
   end
 
   def test_interval_ym_out_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 DECLARE
   ts1 TIMESTAMP;
@@ -258,6 +274,8 @@
   end
 
   def test_interval_ym_in_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 DECLARE
   ts1 TIMESTAMP;
@@ -283,6 +301,8 @@
   end
 
   def test_interval_ds_select
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     [['2006-01-01', '2004-03-01'],
      ['2006-01-01', '2005-03-01'],
      ['2006-01-01', '2006-03-01'],
@@ -309,6 +329,8 @@
   end
 
   def test_interval_ds_out_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 DECLARE
   ts1 TIMESTAMP;
@@ -346,6 +368,8 @@
   end
 
   def test_interval_ds_in_bind
+    return if $oracle_version < OCI8::ORAVER_9_1
+
     cursor = @conn.parse(<<-EOS)
 DECLARE
   ts1 TIMESTAMP;

Modified: trunk/ruby-oci8/test/test_dbi.rb
===================================================================
--- trunk/ruby-oci8/test/test_dbi.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/test/test_dbi.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -168,7 +168,7 @@
     # data_size factor for nchar charset_form.
     sth = @dbh.execute("select CAST('1' AS NCHAR(1)) from dual")
     cfrm = sth.column_info[0]['precision']
-    if $oracle_version >=  900
+    if $oracle_version >=  OCI8::ORAVER_9_1
       # data_size factor for char semantics.
       sth = @dbh.execute("select CAST('1' AS CHAR(1 char)) from dual")
       csem = sth.column_info[0]['precision']

Modified: trunk/ruby-oci8/test/test_dbi_clob.rb
===================================================================
--- trunk/ruby-oci8/test/test_dbi_clob.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/test/test_dbi_clob.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -9,13 +9,14 @@
   end
 
   def test_insert
-    @dbh.do("DELETE FROM test_clob WHERE filename = :1", $lobfile)
+    filename = File.basename($lobfile)
+    @dbh.do("DELETE FROM test_clob WHERE filename = :1", filename)
 
     # insert an empty clob and get the rowid.
-    rowid = @dbh.execute("INSERT INTO test_clob(filename, content) VALUES (:1, EMPTY_CLOB())", $lobfile) do |sth|
+    rowid = @dbh.execute("INSERT INTO test_clob(filename, content) VALUES (:1, EMPTY_CLOB())", filename) do |sth|
       sth.func(:rowid)
     end
-    lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", $lobfile)[0]
+    lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[0]
     begin
       open($lobfile) do |f|
         while f.gets()
@@ -28,8 +29,9 @@
   end
 
   def test_read
+    filename = File.basename($lobfile)
     test_insert() # first insert data.
-    lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", $lobfile)[0]
+    lob = @dbh.select_one("SELECT content FROM test_clob WHERE filename = :1 FOR UPDATE", filename)[0]
     begin
       open($lobfile) do |f|
         while buf = lob.read($lobreadnum)

Modified: trunk/ruby-oci8/test/test_metadata.rb
===================================================================
--- trunk/ruby-oci8/test/test_metadata.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/test/test_metadata.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -16,7 +16,7 @@
     # data_size factor for nchar charset_form.
     cursor = @conn.exec("select CAST('1' AS NCHAR(1)) from dual")
     cfrm = cursor.column_metadata[0].data_size
-    if $oracle_version >=  900
+    if $oracle_version >=  OCI8::ORAVER_9_1
       # data_size factor for char semantics.
       cursor = @conn.exec("select CAST('1' AS CHAR(1 char)) from dual")
       csem = cursor.column_metadata[0].data_size
@@ -163,7 +163,7 @@
       assert_equal(coldef[i][3], md.charset_form, "'#{coldef[i][1]}': charset_form")
       assert_equal(coldef[i][4], md.nullable?, "'#{coldef[i][1]}': nullable? ")
       # string type
-      if $oracle_version >=  900
+      if $oracle_version >= OCI8::ORA_VER_9_1
         assert_equal(coldef[i][5], md.char_used?, "'#{coldef[i][1]}': char_used? ")
         assert_equal(coldef[i][6], md.char_size, "'#{coldef[i][1]}': char_size")
       end
@@ -199,7 +199,7 @@
       assert_equal(coldef[i][3], md.charset_form, "'#{coldef[i][1]}': charset_form")
       assert_equal(coldef[i][4], md.nullable?, "'#{coldef[i][1]}': nullable? ")
       # string type
-      if $oracle_version >=  900
+      if $oracle_version >=  OCI8::ORA_VER_9_1
         assert_equal(coldef[i][5], md.char_used?, "'#{coldef[i][1]}': char_used? ")
         assert_equal(coldef[i][6], md.char_size, "'#{coldef[i][1]}': char_size")
       end

Modified: trunk/ruby-oci8/test/test_oci8.rb
===================================================================
--- trunk/ruby-oci8/test/test_oci8.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/test/test_oci8.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -225,42 +225,44 @@
     drop_table('test_table')
   end
 
-  if $oracle_version >= 1000
+  def test_binary_float
+    return if $oracle_version < OCI8::ORAVER_10_1
+
     # Oracle 10g or upper
-    def test_binary_float
-      cursor = @conn.parse("select CAST(:1 AS BINARY_FLOAT), CAST(:2 AS BINARY_DOUBLE) from dual")
-      bind_val = -1.0
-      cursor.bind_param(1, 10.0, :binary_double)
-      cursor.bind_param(2, nil, :binary_double)
-      while bind_val < 10.0
-        cursor[2] = bind_val
-        cursor.exec
-        rv = cursor.fetch
-        assert_equal(10.0, rv[0])
-        assert_equal(bind_val, rv[1])
-        bind_val += 1.234
+    cursor = @conn.parse("select CAST(:1 AS BINARY_FLOAT), CAST(:2 AS BINARY_DOUBLE) from dual")
+    bind_val = -1.0
+    cursor.bind_param(1, 10.0, :binary_double)
+    cursor.bind_param(2, nil, :binary_double)
+    while bind_val < 10.0
+      cursor[2] = bind_val
+      cursor.exec
+      rv = cursor.fetch
+      assert_equal(10.0, rv[0])
+      assert_equal(bind_val, rv[1])
+      bind_val += 1.234
+    end
+    [-1.0/0.0, # -Infinite
+     +1.0/0.0, # +Infinite
+     0.0/0.0   # NaN
+    ].each do |num|
+      cursor[1] = num
+      cursor[2] = num
+      cursor.exec
+      rv = cursor.fetch
+      if num.nan?
+        assert(rv[0].nan?)
+        assert(rv[1].nan?)
+      else
+        assert_equal(num, rv[0])
+        assert_equal(num, rv[1])
       end
-      [-1.0/0.0, # -Infinite
-       +1.0/0.0, # +Infinite
-       0.0/0.0   # NaN
-      ].each do |num|
-        cursor[1] = num
-        cursor[2] = num
-        cursor.exec
-        rv = cursor.fetch
-        if num.nan?
-          assert(rv[0].nan?)
-          assert(rv[1].nan?)
-        else
-          assert_equal(num, rv[0])
-          assert_equal(num, rv[1])
-        end
-      end
-      cursor.close
     end
+    cursor.close
   end
 
   def test_clob_nclob_and_blob
+    return if OCI8::oracle_client_version < OCI8::ORAVER_8_1
+
     drop_table('test_table')
     sql = <<-EOS
 CREATE TABLE test_table (id number(5), C CLOB, NC NCLOB, B BLOB)

Modified: trunk/ruby-oci8/test/test_oranumber.rb
===================================================================
--- trunk/ruby-oci8/test/test_oranumber.rb	2008-08-26 09:00:33 UTC (rev 284)
+++ trunk/ruby-oci8/test/test_oranumber.rb	2008-08-26 13:39:59 UTC (rev 285)
@@ -382,7 +382,7 @@
 
   # onum.round_prec(digits) -> ocinumber
   def test_round_prec
-    if OCI8::oracle_client_version >= 810
+    if OCI8::oracle_client_version >= OCI8::ORAVER_8_1
       # Oracle 8.1 client or upper
       compare_with_float2(LARGE_RANGE_VALUES, [1, 2, 3, 5, 10, 20],
                           Proc.new {|x, y|
@@ -393,7 +393,7 @@
                           Proc.new {|x, y| x.round_prec(y)})
     else
       # Oracle 8.0 client
-      assert_raise RuntimeError do
+      assert_raise NoMethodError do
         OraNumber.new(1).round_prec(1)
       end
     end
@@ -401,14 +401,14 @@
 
   # onum.shift(fixnum) -> ocinumber
   def test_shift
-    if OCI8::oracle_client_version >= 810
+    if OCI8::oracle_client_version >= OCI8::ORAVER_8_1
       # Oracle 8.1 client or upper
       compare_with_float2(LARGE_RANGE_VALUES, [-5, -4, -3, -1, 0, 1, 2, 3, 4, 5],
                           Proc.new {|x, y| x * (10 ** y)},
                           Proc.new {|x, y| x.shift(y)})
     else
       # Oracle 8.0 client
-      assert_raise RuntimeError do
+      assert_raise NoMethodError do
         OraNumber.new(1).shift(1)
       end
     end




More information about the ruby-oci8-commit mailing list