[ruby-oci8-commit] [314] trunk/ruby-oci8: * lib/dbd/OCI8.rb: add code for ruby-dbi 0. 4 type conversion.

nobody at rubyforge.org nobody at rubyforge.org
Sun Feb 1 10:07:18 EST 2009


Revision: 314
Author:   kubo
Date:     2009-02-01 10:07:17 -0500 (Sun, 01 Feb 2009)

Log Message:
-----------
* lib/dbd/OCI8.rb: add code for ruby-dbi 0.4 type conversion.
* test/test_dbi.rb: suppress deprecated warnings while running
    test_bind_dbi_data_type.
* test/test_dbi_clob.rb: fix a problem when running this
    file directly.

Modified Paths:
--------------
    branches/ruby-oci8-1.0/lib/dbd/OCI8.rb
    branches/ruby-oci8-1.0/test/test_dbi.rb
    branches/ruby-oci8-1.0/test/test_dbi_clob.rb
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/lib/dbd/OCI8.rb
    trunk/ruby-oci8/test/test_dbi.rb
    trunk/ruby-oci8/test/test_dbi_clob.rb

Modified: branches/ruby-oci8-1.0/lib/dbd/OCI8.rb
===================================================================
--- branches/ruby-oci8-1.0/lib/dbd/OCI8.rb	2009-02-01 15:05:35 UTC (rev 313)
+++ branches/ruby-oci8-1.0/lib/dbd/OCI8.rb	2009-02-01 15:07:17 UTC (rev 314)
@@ -48,6 +48,27 @@
   "OCI8"
 end
 
+# type converstion handler to bind values. (ruby-dbi 0.4)
+if DBI.const_defined?(:TypeUtil)
+  DBI::TypeUtil.register_conversion("OCI8") do |obj|
+    case obj
+    when ::TrueClass
+      ['1', false]
+    when ::FalseClass
+      ['0', false]
+    else
+      [obj, false]
+    end
+  end
+end
+
+# no type converstion is required for result set. (ruby-dbi 0.4)
+class NoTypeConversion
+  def self.parse(obj)
+    obj
+  end
+end
+
 module Util
 
   ERROR_MAP = {
@@ -138,6 +159,7 @@
       'nullable' => col.nullable?,
       'precision' => precision,
       'scale' => scale,
+      'dbi_type' => NoTypeConversion,
     }
   end
   private :column_metadata_to_column_info

Modified: branches/ruby-oci8-1.0/test/test_dbi.rb
===================================================================
--- branches/ruby-oci8-1.0/test/test_dbi.rb	2009-02-01 15:05:35 UTC (rev 313)
+++ branches/ruby-oci8-1.0/test/test_dbi.rb	2009-02-01 15:07:17 UTC (rev 314)
@@ -146,17 +146,27 @@
   end
 
   def test_bind_dbi_data_type
-    inval = DBI::Date.new(2004, 3, 20)
-    sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
-    outval = sth.func(:bind_value, 1)
-    assert_instance_of(DBI::Date, outval)
-    assert_equal(inval.to_time, outval.to_time)
+    begin
+      if DBI::VERSION >= '0.4.0'
+        # suppress deprecated warnings while running this test.
+        saved_action = Deprecated.action
+        Deprecated.set_action(Proc.new {})
+      end
 
-    inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
-    sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
-    outval = sth.func(:bind_value, 1)
-    assert_instance_of(DBI::Timestamp, outval)
-    assert_equal(inval.to_time, outval.to_time)
+      inval = DBI::Date.new(2004, 3, 20)
+      sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
+      outval = sth.func(:bind_value, 1)
+      assert_instance_of(DBI::Date, outval)
+      assert_equal(inval.to_time, outval.to_time)
+
+      inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
+      sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
+      outval = sth.func(:bind_value, 1)
+      assert_instance_of(DBI::Timestamp, outval)
+      assert_equal(inval.to_time, outval.to_time)
+    ensure
+      Deprecated.set_action(saved_action) if saved_action
+    end
   end
 
   def test_column_info

Modified: branches/ruby-oci8-1.0/test/test_dbi_clob.rb
===================================================================
--- branches/ruby-oci8-1.0/test/test_dbi_clob.rb	2009-02-01 15:05:35 UTC (rev 313)
+++ branches/ruby-oci8-1.0/test/test_dbi_clob.rb	2009-02-01 15:07:17 UTC (rev 314)
@@ -54,5 +54,5 @@
 end
 
 if $0 == __FILE__
-  RUNIT::CUI::TestRunner.run(TestCLob.suite())
+  RUNIT::CUI::TestRunner.run(TestDbiCLob.suite())
 end

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2009-02-01 15:05:35 UTC (rev 313)
+++ trunk/ruby-oci8/ChangeLog	2009-02-01 15:07:17 UTC (rev 314)
@@ -1,3 +1,10 @@
+2009-02-01  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/dbd/OCI8.rb: add code for ruby-dbi 0.4 type conversion.
+	* test/test_dbi.rb: suppress deprecated warnings while running
+	    test_bind_dbi_data_type.
+	* test/test_dbi_clob.rb: fix a problem when running this
+	    file directly.
+
 2009-01-31  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/oraconf.rb: fix for Oracle 11.1.0.7.0 instant
 	    client rpm package. The directory tree is a bit different

Modified: trunk/ruby-oci8/lib/dbd/OCI8.rb
===================================================================
--- trunk/ruby-oci8/lib/dbd/OCI8.rb	2009-02-01 15:05:35 UTC (rev 313)
+++ trunk/ruby-oci8/lib/dbd/OCI8.rb	2009-02-01 15:07:17 UTC (rev 314)
@@ -48,6 +48,27 @@
   "OCI8"
 end
 
+# type converstion handler to bind values. (ruby-dbi 0.4)
+if DBI.const_defined?(:TypeUtil)
+  DBI::TypeUtil.register_conversion("OCI8") do |obj|
+    case obj
+    when ::TrueClass
+      ['1', false]
+    when ::FalseClass
+      ['0', false]
+    else
+      [obj, false]
+    end
+  end
+end
+
+# no type converstion is required for result set. (ruby-dbi 0.4)
+class NoTypeConversion
+  def self.parse(obj)
+    obj
+  end
+end
+
 module Util
 
   ERROR_MAP = {
@@ -138,6 +159,7 @@
       'nullable' => col.nullable?,
       'precision' => precision,
       'scale' => scale,
+      'dbi_type' => NoTypeConversion,
     }
   end
   private :column_metadata_to_column_info

Modified: trunk/ruby-oci8/test/test_dbi.rb
===================================================================
--- trunk/ruby-oci8/test/test_dbi.rb	2009-02-01 15:05:35 UTC (rev 313)
+++ trunk/ruby-oci8/test/test_dbi.rb	2009-02-01 15:07:17 UTC (rev 314)
@@ -166,17 +166,27 @@
   end
 
   def test_bind_dbi_data_type
-    inval = DBI::Date.new(2004, 3, 20)
-    sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
-    outval = sth.func(:bind_value, 1)
-    assert_instance_of(DBI::Date, outval)
-    assert_equal(inval.to_time, outval.to_time)
+    begin
+      if DBI::VERSION >= '0.4.0'
+        # suppress deprecated warnings while running this test.
+        saved_action = Deprecated.action
+        Deprecated.set_action(Proc.new {})
+      end
 
-    inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
-    sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
-    outval = sth.func(:bind_value, 1)
-    assert_instance_of(DBI::Timestamp, outval)
-    assert_equal(inval.to_time, outval.to_time)
+      inval = DBI::Date.new(2004, 3, 20)
+      sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Date, inval)
+      outval = sth.func(:bind_value, 1)
+      assert_instance_of(DBI::Date, outval)
+      assert_equal(inval.to_time, outval.to_time)
+
+      inval = DBI::Timestamp.new(2004, 3, 20, 18, 26, 33)
+      sth = @dbh.execute("BEGIN ? := ?; END;", DBI::Timestamp, inval)
+      outval = sth.func(:bind_value, 1)
+      assert_instance_of(DBI::Timestamp, outval)
+      assert_equal(inval.to_time, outval.to_time)
+    ensure
+      Deprecated.set_action(saved_action) if saved_action
+    end
   end
 
   def test_column_info

Modified: trunk/ruby-oci8/test/test_dbi_clob.rb
===================================================================
--- trunk/ruby-oci8/test/test_dbi_clob.rb	2009-02-01 15:05:35 UTC (rev 313)
+++ trunk/ruby-oci8/test/test_dbi_clob.rb	2009-02-01 15:07:17 UTC (rev 314)
@@ -1,4 +1,5 @@
 require 'dbi'
+require 'oci8'
 require 'test/unit'
 require File.dirname(__FILE__) + '/config'
 




More information about the ruby-oci8-commit mailing list