[ruby-oci8-commit] [286] trunk/ruby-oci8: * ext/oci8/apiwrap.yml: OCINumberSign is unavailable on Oracle 8.

nobody at rubyforge.org nobody at rubyforge.org
Thu Aug 28 02:03:07 EDT 2008


Revision: 286
Author:   kubo
Date:     2008-08-28 02:03:07 -0400 (Thu, 28 Aug 2008)

Log Message:
-----------
* ext/oci8/apiwrap.yml: OCINumberSign is unavailable on Oracle 8.
* lib/DBD/OCI8/OCI8.rb: A data dictionary all_constraints doesn't have
    index_name column on Oracle 8i or lower. Rewrite
    DBI::DBD::OCI8::Database#column by using all_cons_columns.
* lib/oci8/metadata.rb: raise an error when using 
* test/config.rb: Oracle 8 desn't have database_compatible_level data
    dictionary.
* test/test_metadata.rb: fix test codes for Oracle 8i or lower.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/apiwrap.yml
    trunk/ruby-oci8/lib/DBD/OCI8/OCI8.rb
    trunk/ruby-oci8/lib/oci8/metadata.rb
    trunk/ruby-oci8/test/config.rb
    trunk/ruby-oci8/test/test_metadata.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2008-08-26 13:39:59 UTC (rev 285)
+++ trunk/ruby-oci8/ChangeLog	2008-08-28 06:03:07 UTC (rev 286)
@@ -1,3 +1,13 @@
+2008-08-28  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/apiwrap.yml: OCINumberSign is unavailable on Oracle 8.
+	* lib/DBD/OCI8/OCI8.rb: A data dictionary all_constraints doesn't have
+	    index_name column on Oracle 8i or lower. Rewrite
+	    DBI::DBD::OCI8::Database#column by using all_cons_columns.
+	* lib/oci8/metadata.rb: raise an error when using 
+	* test/config.rb: Oracle 8 desn't have database_compatible_level data
+	    dictionary.
+	* test/test_metadata.rb: fix test codes for Oracle 8i or lower.
+
 2008-08-26  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/metadata.c: fix bugs when trying to use already freed
 	    OCI8::Metadata::*.

Modified: trunk/ruby-oci8/ext/oci8/apiwrap.yml
===================================================================
--- trunk/ruby-oci8/ext/oci8/apiwrap.yml	2008-08-26 13:39:59 UTC (rev 285)
+++ trunk/ruby-oci8/ext/oci8/apiwrap.yml	2008-08-28 06:03:07 UTC (rev 286)
@@ -595,13 +595,6 @@
             - OCINumber *num
 
 # round trip: 0
-OCINumberSign:
-  :version: 800
-  :args:    - OCIError *err
-            - const OCINumber *number
-            - sword *result
-
-# round trip: 0
 OCINumberSin:
   :version: 800
   :args:    - OCIError *err
@@ -991,6 +984,31 @@
             - OCINumber *result
 
 # round trip: 0
+OCINumberSign:
+  :version: 810
+  :args:    - OCIError *err
+            - const OCINumber *number
+            - sword *result
+  :code_if_not_found: |
+    /* pseude code
+     *   number <=> 0
+     */
+    OCINumber zero;
+    sword rv;
+    sword cmp;
+    OCINumberSetZero(err, &zero);
+    rv = oci8_OCINumberCmp(err, number, &zero, &cmp, file, line);
+    if (rv != OCI_SUCCESS)
+        return rv;
+    if (cmp > 0)
+        *result = 1;
+    else if (cmp < 0)
+        *result = -1;
+    else
+        *result = 0;
+    return OCI_SUCCESS;
+
+# round trip: 0
 OCIReset:
   :version: 810
   :args:    - dvoid *hndlp

Modified: trunk/ruby-oci8/lib/DBD/OCI8/OCI8.rb
===================================================================
--- trunk/ruby-oci8/lib/DBD/OCI8/OCI8.rb	2008-08-26 13:39:59 UTC (rev 285)
+++ trunk/ruby-oci8/lib/DBD/OCI8/OCI8.rb	2008-08-28 06:03:07 UTC (rev 286)
@@ -219,19 +219,21 @@
 
     dbh = DBI::DatabaseHandle.new(self)
 
-    pk_index_name = nil
+    primaries = {}
     dbh.select_all(<<EOS, tab.obj_schema, tab.obj_name) do |row|
-select index_name
-  from all_constraints
- where constraint_type = 'P'
-   and owner = :1
-   and table_name = :2
+select column_name
+  from all_cons_columns a, all_constraints b
+ where a.owner = b.owner
+   and a.constraint_name = b.constraint_name
+   and a.table_name = b.table_name
+   and b.constraint_type = 'P'
+   and b.owner = :1
+   and b.table_name = :2
 EOS
-      pk_index_name = row[0]
+      primaries[row[0]] = true
     end
 
     indices = {}
-    primaries = {}
     uniques = {}
     dbh.select_all(<<EOS, tab.obj_schema, tab.obj_name) do |row|
 select a.column_name, a.index_name, b.uniqueness
@@ -243,7 +245,6 @@
 EOS
       col_name, index_name, uniqueness = row
       indices[col_name] = true
-      primaries[col_name] = true if index_name == pk_index_name
       uniques[col_name] = true if uniqueness == 'UNIQUE'
     end
 

Modified: trunk/ruby-oci8/lib/oci8/metadata.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/metadata.rb	2008-08-26 13:39:59 UTC (rev 285)
+++ trunk/ruby-oci8/lib/oci8/metadata.rb	2008-08-28 06:03:07 UTC (rev 286)
@@ -1654,8 +1654,14 @@
 
       ## Table 6-15 List Attributes
 
-      def ltype
-        __ub2(OCI_ATTR_LTYPE)
+      if OCI8::oracle_client_version < OCI8::ORAVER_8_1
+        def ltype
+          raise "This feature is unavailable on Oracle 8.0"
+        end
+      else
+        def ltype
+          __ub2(OCI_ATTR_LTYPE)
+        end
       end
 
       # convert to array

Modified: trunk/ruby-oci8/test/config.rb
===================================================================
--- trunk/ruby-oci8/test/config.rb	2008-08-26 13:39:59 UTC (rev 285)
+++ trunk/ruby-oci8/test/config.rb	2008-08-28 06:03:07 UTC (rev 286)
@@ -24,9 +24,14 @@
 # $oracle_client_version: Oracle client library version for which oci8 is compiled.
 # $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('.').collect do |v| v.to_i; end
-  $oracle_server_version = (ver[0] << 24) + (ver[1] << 20) + (ver[2] << 12)
+begin
+  conn.exec('select value from database_compatible_level') do |row|
+    ver = row[0].split('.').collect do |v| v.to_i; end
+    $oracle_server_version = (ver[0] << 24) + (ver[1] << 20) + (ver[2] << 12)
+  end
+rescue OCIError
+  raise if $!.code != 942 # ORA-00942: table or view does not exist
+  $oracle_server_version = OCI8::ORAVER_8_0
 end
 conn.logoff
 

Modified: trunk/ruby-oci8/test/test_metadata.rb
===================================================================
--- trunk/ruby-oci8/test/test_metadata.rb	2008-08-26 13:39:59 UTC (rev 285)
+++ trunk/ruby-oci8/test/test_metadata.rb	2008-08-28 06:03:07 UTC (rev 286)
@@ -13,25 +13,40 @@
   end
 
   def test_metadata
+    if $oracle_version < OCI8::ORAVER_8_1
+      begin
+        @conn.describe_table('tab').columns
+      rescue RuntimeError
+        assert_equal("This feature is unavailable on Oracle 8.0", $!.to_s)
+      end
+      return
+    end
+
     # data_size factor for nchar charset_form.
-    cursor = @conn.exec("select CAST('1' AS NCHAR(1)) from dual")
+    cursor = @conn.exec("select N'1' from dual")
     cfrm = cursor.column_metadata[0].data_size
     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
+    else
+      csem = 1
     end
 
+    ora80 = OCI8::ORAVER_8_0
+    ora81 = OCI8::ORAVER_8_1
+    ora91 = OCI8::ORAVER_8_1
+    ora101 = OCI8::ORAVER_10_1
     coldef =
       [
        # oracle_version, definition,    data_type,  csfrm,    null?,csem?,csize, data_size,prec,scale,fsprec,lfprec
-       [800, "CHAR(10) NOT NULL",       :char,      :implicit, false, false, 10,        10,   0,    0,    0,    0],
-       [900, "CHAR(10 CHAR)",           :char,      :implicit, true,  true,  10, 10 * csem,   0,    0,    0,    0],
-       [800, "NCHAR(10)",               :char,      :nchar,    true,  true,  10, 10 * cfrm,   0,    0,    0,    0],
-       [800, "VARCHAR2(10)",            :varchar2,  :implicit, true,  false, 10,        10,   0,    0,    0,    0],
-       [900, "VARCHAR2(10 CHAR)",       :varchar2,  :implicit, true,  true,  10, 10 * csem,   0,    0,    0,    0],
-       [800, "NVARCHAR2(10)",           :varchar2,  :nchar,    true,  true,  10, 10 * cfrm,   0,    0,    0,    0],
-       [800, "RAW(10)",                 :raw,       nil,       true,  false,  0,        10,   0,    0,    0,    0],
+       [ora80, "CHAR(10) NOT NULL",       :char,      :implicit, false, false, 10,        10,   0,    0,    0,    0],
+       [ora91, "CHAR(10 CHAR)",           :char,      :implicit, true,  true,  10, 10 * csem,   0,    0,    0,    0],
+       [ora80, "NCHAR(10)",               :char,      :nchar,    true,  true,  10, 10 * cfrm,   0,    0,    0,    0],
+       [ora80, "VARCHAR2(10)",            :varchar2,  :implicit, true,  false, 10,        10,   0,    0,    0,    0],
+       [ora91, "VARCHAR2(10 CHAR)",       :varchar2,  :implicit, true,  true,  10, 10 * csem,   0,    0,    0,    0],
+       [ora80, "NVARCHAR2(10)",           :varchar2,  :nchar,    true,  true,  10, 10 * cfrm,   0,    0,    0,    0],
+       [ora80, "RAW(10)",                 :raw,       nil,       true,  false,  0,        10,   0,    0,    0,    0],
 
        # Don't check data_size of CLOB, NCLOB and BLOB.
        #
@@ -42,11 +57,11 @@
        #   | implicit |   4000    |  <= OCI8::Cursor#column_metadata
        #   | explicit |     86    |  <= OCI8.describe_table('table_name').columns
        #   +----------+-----------+
-       [800, "CLOB",                    :clob,      :implicit, true,  false,  0,       :nc,   0,    0,    0,    0],
-       [800, "NCLOB",                   :clob,      :nchar,    true,  false,  0,       :nc,   0,    0,    0,    0],
-       [800, "BLOB",                    :blob,      nil,       true,  false,  0,       :nc,   0,    0,    0,    0],
+       [ora81, "CLOB",                    :clob,      :implicit, true,  false,  0,       :nc,   0,    0,    0,    0],
+       [ora81, "NCLOB",                   :clob,      :nchar,    true,  false,  0,       :nc,   0,    0,    0,    0],
+       [ora80, "BLOB",                    :blob,      nil,       true,  false,  0,       :nc,   0,    0,    0,    0],
 
-       [800, "BFILE",                   :bfile,     nil,       true,  false,  0,       530,   0,    0,    0,    0],
+       [ora80, "BFILE",                   :bfile,     nil,       true,  false,  0,       530,   0,    0,    0,    0],
 
        # Don't check fsprecision and lfprecision for NUMBER and FLOAT
        #
@@ -69,15 +84,15 @@
        #   | FLOAT(10)      | implicit |     129     |     10      |
        #   |                | explicit |      10     |    129      |
        #   +----------------+----------+-------------+-------------+
-       [800, "NUMBER",                  :number,    nil,       true,  false,  0,        22,   0, -127,  :nc,  :nc],
-       [800, "NUMBER(10)",              :number,    nil,       true,  false,  0,        22,  10,    0,  :nc,  :nc],
-       [800, "NUMBER(10,2)",            :number,    nil,       true,  false,  0,        22,  10,    2,  :nc,  :nc],
-       [800, "FLOAT",                   :number,    nil,       true,  false,  0,        22, 126, -127,  :nc,  :nc],
-       [800, "FLOAT(10)",               :number,    nil,       true,  false,  0,        22,  10, -127,  :nc,  :nc],
+       [ora80, "NUMBER",                  :number,    nil,       true,  false,  0,        22,   0, $oracle_version >= ora91 ? -127 : 0,  :nc,  :nc],
+       [ora80, "NUMBER(10)",              :number,    nil,       true,  false,  0,        22,  10,    0,  :nc,  :nc],
+       [ora80, "NUMBER(10,2)",            :number,    nil,       true,  false,  0,        22,  10,    2,  :nc,  :nc],
+       [ora80, "FLOAT",                   :number,    nil,       true,  false,  0,        22, 126, -127,  :nc,  :nc],
+       [ora80, "FLOAT(10)",               :number,    nil,       true,  false,  0,        22,  10, -127,  :nc,  :nc],
 
-       [1000,"BINARY_FLOAT",            :binary_float,  nil,   true,  false,  0,         4,   0,    0,    0,    0],
-       [1000,"BINARY_DOUBLE",           :binary_double, nil,   true,  false,  0,         8,   0,    0,    0,    0],
-       [800, "DATE",                    :date,      nil,       true,  false,  0,         7,   0,    0,    0,    0],
+       [ora101,"BINARY_FLOAT",            :binary_float,  nil,   true,  false,  0,         4,   0,    0,    0,    0],
+       [ora101,"BINARY_DOUBLE",           :binary_double, nil,   true,  false,  0,         8,   0,    0,    0,    0],
+       [ora80, "DATE",                    :date,      nil,       true,  false,  0,         7,   0,    0,    0,    0],
 
        # Don't check precision and lfprecision for TIMESTAMP
        #
@@ -103,12 +118,12 @@
        #   | TIMESTAMP(9) WITH LOCAL TIME ZONE | implicit |     0     |      0      |
        #   |                                   | explicit |     9     |      9      |
        #   +-----------------------------------+----------+-----------+-------------+
-       [900, "TIMESTAMP",                         :timestamp,     nil, true, false, 0,  11, :nc,    6,    6,  :nc],
-       [900, "TIMESTAMP(9)",                      :timestamp,     nil, true, false, 0,  11, :nc,    9,    9,  :nc],
-       [900, "TIMESTAMP WITH TIME ZONE",          :timestamp_tz,  nil, true, false, 0,  13, :nc,    6,    6,  :nc],
-       [900, "TIMESTAMP(9) WITH TIME ZONE",       :timestamp_tz,  nil, true, false, 0,  13, :nc,    9,    9,  :nc],
-       [900, "TIMESTAMP WITH LOCAL TIME ZONE",    :timestamp_ltz, nil, true, false, 0,  11, :nc,    6,    6,  :nc],
-       [900, "TIMESTAMP(9) WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0,  11, :nc,    9,    9,  :nc],
+       [ora91, "TIMESTAMP",                         :timestamp,     nil, true, false, 0,  11, :nc,    6,    6,  :nc],
+       [ora91, "TIMESTAMP(9)",                      :timestamp,     nil, true, false, 0,  11, :nc,    9,    9,  :nc],
+       [ora91, "TIMESTAMP WITH TIME ZONE",          :timestamp_tz,  nil, true, false, 0,  13, :nc,    6,    6,  :nc],
+       [ora91, "TIMESTAMP(9) WITH TIME ZONE",       :timestamp_tz,  nil, true, false, 0,  13, :nc,    9,    9,  :nc],
+       [ora91, "TIMESTAMP WITH LOCAL TIME ZONE",    :timestamp_ltz, nil, true, false, 0,  11, :nc,    6,    6,  :nc],
+       [ora91, "TIMESTAMP(9) WITH LOCAL TIME ZONE", :timestamp_ltz, nil, true, false, 0,  11, :nc,    9,    9,  :nc],
 
        # Don't check scale and fsprecision for INTERVAL YEAR TO MONTH
        #
@@ -122,8 +137,8 @@
        #   | INTERVAL YEAR(4) TO MONTH    | implicit |     0     |      0      |
        #   |                              | explicit |     4     |      4      |
        #   +------------------------------+----------+-----------+-------------+
-       [900, "INTERVAL YEAR TO MONTH",      :interval_ym, nil, true,  false,  0,         5,   2,  :nc,  :nc,    2],
-       [900, "INTERVAL YEAR(4) TO MONTH",   :interval_ym, nil, true,  false,  0,         5,   4,  :nc,  :nc,    4],
+       [ora91, "INTERVAL YEAR TO MONTH",      :interval_ym, nil, true,  false,  0,         5,   2,  :nc,  :nc,    2],
+       [ora91, "INTERVAL YEAR(4) TO MONTH",   :interval_ym, nil, true,  false,  0,         5,   4,  :nc,  :nc,    4],
 
        # Don't check precision and scale for INTERVAL DAY TO SECOND
        #
@@ -137,8 +152,8 @@
        #   | INTERVAL DAY(4) TO SECOND(9) | implicit |     4     |     9     |
        #   |                              | explicit |     9     |     4     |
        #   +------------------------------+----------+-----------+-----------+
-       [900, "INTERVAL DAY TO SECOND",      :interval_ds, nil, true,  false,  0,        11, :nc,  :nc,    6,    2],
-       [900, "INTERVAL DAY(4) TO SECOND(9)",:interval_ds, nil, true,  false,  0,        11, :nc,  :nc,    9,    4],
+       [ora91, "INTERVAL DAY TO SECOND",      :interval_ds, nil, true,  false,  0,        11, :nc,  :nc,    6,    2],
+       [ora91, "INTERVAL DAY(4) TO SECOND(9)",:interval_ds, nil, true,  false,  0,        11, :nc,  :nc,    9,    4],
       ]
 
     coldef.reject! do |c| c[0] > $oracle_version end
@@ -163,7 +178,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 >= OCI8::ORA_VER_9_1
+      if $oracle_version >= OCI8::ORAVER_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
@@ -171,8 +186,10 @@
       # number, timestamp and interval type
       assert_equal(coldef[i][8], md.precision, "'#{coldef[i][1]}': precision") if coldef[i][8] != :nc
       assert_equal(coldef[i][9], md.scale, "'#{coldef[i][1]}': scale") if coldef[i][9] != :nc
-      assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
-      assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
+      if $oracle_version >= OCI8::ORAVER_9_1
+        assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
+        assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
+      end
     end
 
     # temporarily change OCI8::BindType::Mapping.
@@ -199,7 +216,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 >=  OCI8::ORA_VER_9_1
+      if $oracle_version >=  OCI8::ORAVER_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
@@ -207,8 +224,10 @@
       # number, timestamp and interval type
       assert_equal(coldef[i][8], md.precision, "'#{coldef[i][1]}': precision") if coldef[i][8] != :nc
       assert_equal(coldef[i][9], md.scale, "'#{coldef[i][1]}': scale") if coldef[i][9] != :nc
-      assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
-      assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
+      if $oracle_version >= OCI8::ORAVER_9_1
+        assert_equal(coldef[i][10], md.fsprecision, "'#{coldef[i][1]}': fsprecision") if coldef[i][10] != :nc
+        assert_equal(coldef[i][11], md.lfprecision, "'#{coldef[i][1]}': lfprecision") if coldef[i][11] != :nc
+      end
     end
 
     drop_table('test_table')




More information about the ruby-oci8-commit mailing list