[ruby-oci8-commit] [232] branches/ruby-oci8-1.0: * lib/oci8.rb.in: support cursors in a result set.

nobody at rubyforge.org nobody at rubyforge.org
Sat Dec 29 08:32:19 EST 2007


Revision: 232
Author:   kubo
Date:     2007-12-29 08:32:18 -0500 (Sat, 29 Dec 2007)

Log Message:
-----------
* lib/oci8.rb.in: support cursors in a result set. For example:
    SELECT column1 A, column2 B, CURSOR(SELECT * FROM table2) C
      FROM table1
    (contributed by Randy Gordon)
* test/test_oci8.rb: add a testcase for cursors in a result set.

Modified Paths:
--------------
    branches/ruby-oci8-1.0/ChangeLog
    branches/ruby-oci8-1.0/lib/oci8.rb.in
    branches/ruby-oci8-1.0/test/test_oci8.rb

Modified: branches/ruby-oci8-1.0/ChangeLog
===================================================================
--- branches/ruby-oci8-1.0/ChangeLog	2007-12-23 15:29:22 UTC (rev 231)
+++ branches/ruby-oci8-1.0/ChangeLog	2007-12-29 13:32:18 UTC (rev 232)
@@ -1,3 +1,10 @@
+2007-12-29  KUBO Takehiro  <kubo at jiubao.org>
+	* lib/oci8.rb.in: support cursors in a result set. For example:
+	    SELECT column1 A, column2 B, CURSOR(SELECT * FROM table2) C
+	      FROM table1
+	    (contributed by Randy Gordon)
+	* test/test_oci8.rb: add a testcase for cursors in a result set.
+
 2007-12-23  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/oraconf.rb: fix for official x86_64 rpms.
 	    (contributed by Pat.)

Modified: branches/ruby-oci8-1.0/lib/oci8.rb.in
===================================================================
--- branches/ruby-oci8-1.0/lib/oci8.rb.in	2007-12-23 15:29:22 UTC (rev 231)
+++ branches/ruby-oci8-1.0/lib/oci8.rb.in	2007-12-29 13:32:18 UTC (rev 232)
@@ -29,9 +29,10 @@
 
 class OCIDefine # :nodoc:
   # define handle of OCILobLocator needs @env and @svc.
-  def set_handle(env, svc) 
+  def set_handle(env, svc, ctx) 
     @env = env
     @svc = svc
+    @ctx = ctx
   end
 end
 
@@ -855,11 +856,10 @@
         else
           b = @stmt.bindByName(key, type, option)
         end
-        b.set_handle(@env, @svc, @ctx)
       when :define
         b = @stmt.defineByPos(key, type, option)
-        b.set_handle(@env, @svc)
       end
+      b.set_handle(@env, @svc, @ctx)
 
       if binder && binder.respond_to?(:decorate)
         # decorate the bind handle.
@@ -1259,6 +1259,9 @@
     BindType::Mapping[OCI8::SQLT_IBFLOAT] = BindType::Float
     BindType::Mapping[OCI8::SQLT_IBDOUBLE] = BindType::Float
   end
+
+  # cursor in result set.
+  BindType::Mapping[SQLT_RSET] = BindType::Cursor
 end # OCI8
 
 class OraDate

Modified: branches/ruby-oci8-1.0/test/test_oci8.rb
===================================================================
--- branches/ruby-oci8-1.0/test/test_oci8.rb	2007-12-23 15:29:22 UTC (rev 231)
+++ branches/ruby-oci8-1.0/test/test_oci8.rb	2007-12-29 13:32:18 UTC (rev 232)
@@ -158,6 +158,46 @@
     drop_table('test_table')
   end
 
+  def test_cursor_in_result_set
+    drop_table('test_table')
+    sql = <<-EOS
+CREATE TABLE test_table (N NUMBER(10, 2))
+STORAGE (
+   INITIAL 4k
+   NEXT 4k
+   MINEXTENTS 1
+   MAXEXTENTS UNLIMITED
+   PCTINCREASE 0)
+EOS
+    @conn.exec(sql)
+    cursor = @conn.parse("INSERT INTO test_table VALUES (:1)")
+    1.upto(10) do |i|
+      cursor.exec(i)
+    end
+    cursor.close
+    cursor = @conn.exec(<<EOS)
+select a.n, cursor (select a.n + b.n
+                      from test_table b
+                     order by n)
+  from test_table a
+ order by n
+EOS
+    1.upto(10) do |i|
+      row = cursor.fetch
+      assert_equal(i, row[0])
+      cursor_in_result_set = row[1]
+      1.upto(10) do |j|
+        row2 = cursor_in_result_set.fetch
+        assert_equal(i + j, row2[0])
+      end
+      assert_nil(cursor_in_result_set.fetch) # check end of row data
+      cursor_in_result_set.close
+      cursor.define(2, OCI8::Cursor) # bad hack. fix later.
+    end
+    assert_nil(cursor.fetch) # check end of row data
+    drop_table('test_table')
+  end
+
   if $oracle_version >= 1000
     # Oracle 10g or upper
     def test_binary_float




More information about the ruby-oci8-commit mailing list