[ruby-oci8-commit] [236] trunk/ruby-oci8: * ext/oci8/oci8.h, ext/oci8/stmt.c: 1.

nobody at rubyforge.org nobody at rubyforge.org
Fri Jan 4 07:53:00 EST 2008


Revision: 236
Author:   kubo
Date:     2008-01-04 07:52:59 -0500 (Fri, 04 Jan 2008)

Log Message:
-----------
* ext/oci8/oci8.h, ext/oci8/stmt.c: 1. add a 'pre_fetch_hook'
    callback function to oci8_bind_class_t. This function is
    called before OCIStmtFetch in OCI8::Cursor#fetch.
    2. allocate OCIStmt handle by pre_fetch_hook when a result set
    has cursors.
    3. change 'init' callback function's prototype in
    oci8_bind_class_t.
* ext/oci8/bind.c, ext/oci8/lob.c, ext/oci8/object.c,
  ext/oci8/ocidatetime.c, ext/oci8/ocinumber.c,
  ext/oci8/oradate.c, ext/oci8/rowid.c: changes causes by above 1
    and 3.
* test/test_oci8.rb: delete re-defining in a test case for cursors
    in a result set.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/bind.c
    trunk/ruby-oci8/ext/oci8/lob.c
    trunk/ruby-oci8/ext/oci8/object.c
    trunk/ruby-oci8/ext/oci8/oci8.h
    trunk/ruby-oci8/ext/oci8/ocidatetime.c
    trunk/ruby-oci8/ext/oci8/ocinumber.c
    trunk/ruby-oci8/ext/oci8/oradate.c
    trunk/ruby-oci8/ext/oci8/rowid.c
    trunk/ruby-oci8/ext/oci8/stmt.c
    trunk/ruby-oci8/test/test_oci8.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ChangeLog	2008-01-04 12:52:59 UTC (rev 236)
@@ -1,3 +1,18 @@
+2008-01-04  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/oci8.h, ext/oci8/stmt.c: 1. add a 'pre_fetch_hook'
+	    callback function to oci8_bind_class_t. This function is
+	    called before OCIStmtFetch in OCI8::Cursor#fetch.
+	    2. allocate OCIStmt handle by pre_fetch_hook when a result set
+	    has cursors.
+	    3. change 'init' callback function's prototype in
+	    oci8_bind_class_t.
+	* ext/oci8/bind.c, ext/oci8/lob.c, ext/oci8/object.c,
+	  ext/oci8/ocidatetime.c, ext/oci8/ocinumber.c,
+	  ext/oci8/oradate.c, ext/oci8/rowid.c: changes causes by above 1
+	    and 3.
+	* test/test_oci8.rb: delete re-defining in a test case for cursors
+	    in a result set.
+
 2008-01-03  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/error.c: fix a SEGV bug when an error is raised in GC.
 	    make a custom backtrace entry only when 'caller' returns an Array.

Modified: trunk/ruby-oci8/ext/oci8/bind.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/bind.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/bind.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -35,15 +35,15 @@
     vstr->size = RSTRING_LEN(val);
 }
 
-static void bind_string_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_string_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     sb4 sz;
     if (NIL_P(length)) {
-        if (NIL_P(*val)) {
+        if (NIL_P(val)) {
             rb_raise(rb_eArgError, "value and length are both null.");
         }
-        StringValue(*val);
-        sz = RSTRING_LEN(*val);
+        StringValue(val);
+        sz = RSTRING_LEN(val);
     } else {
         sz = NUM2INT(length);
     }
@@ -67,6 +67,7 @@
     NULL,
     NULL,
     NULL,
+    NULL,
     SQLT_LVC
 };
 
@@ -85,6 +86,7 @@
     NULL,
     NULL,
     NULL,
+    NULL,
     SQLT_LVB
 };
 
@@ -123,7 +125,7 @@
     bl->obj = rb_str_dup(val);
 }
 
-static void bind_long_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_long_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     sb4 sz = 0;
 
@@ -198,6 +200,7 @@
     bind_long_init_elem,
     bind_long_in,
     bind_long_out,
+    NULL,
     SQLT_CHR
 };
 
@@ -216,6 +219,7 @@
     bind_long_init_elem,
     bind_long_in,
     bind_long_out,
+    NULL,
     SQLT_BIN
 };
 
@@ -233,7 +237,7 @@
     *(long*)data = FIX2LONG(val);
 }
 
-static void bind_fixnum_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_fixnum_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = sizeof(long);
     obind->alloc_sz = sizeof(long);
@@ -251,6 +255,7 @@
     NULL,
     NULL,
     NULL,
+    NULL,
     SQLT_INT
 };
 
@@ -268,7 +273,7 @@
     *(double*)data = RFLOAT_VALUE(val);
 }
 
-static void bind_float_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_float_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = sizeof(double);
     obind->alloc_sz = sizeof(double);
@@ -286,6 +291,7 @@
     NULL,
     NULL,
     NULL,
+    NULL,
     SQLT_FLT
 };
 
@@ -302,6 +308,7 @@
     NULL,
     NULL,
     NULL,
+    NULL,
     SQLT_BDOUBLE
 };
 #endif
@@ -396,7 +403,7 @@
     obind->curar_sz = 0;
     if (obind->maxar_sz > 0)
         cnt = obind->maxar_sz;
-    bind_class->init(obind, svc, &val, length);
+    bind_class->init(obind, svc, val, length);
     if (obind->alloc_sz > 0) {
         obind->valuep = xmalloc(obind->alloc_sz * cnt);
         memset(obind->valuep, 0, obind->alloc_sz * cnt);

Modified: trunk/ruby-oci8/ext/oci8/lob.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/lob.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/lob.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -576,7 +576,7 @@
     oho->obj = val;
 }
 
-static void bind_lob_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_lob_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = sizeof(void *);
     obind->alloc_sz = sizeof(oci8_hp_obj_t);
@@ -609,6 +609,7 @@
         bind_lob_init_elem,
         NULL,
         NULL,
+        NULL,
         SQLT_CLOB
     },
     &cOCI8CLOB
@@ -627,6 +628,7 @@
         bind_lob_init_elem,
         NULL,
         NULL,
+        NULL,
         SQLT_CLOB,
         SQLCS_NCHAR,
     },
@@ -646,6 +648,7 @@
         bind_lob_init_elem,
         NULL,
         NULL,
+        NULL,
         SQLT_BLOB
     },
     &cOCI8BLOB
@@ -664,6 +667,7 @@
         bind_lob_init_elem,
         NULL,
         NULL,
+        NULL,
         SQLT_BFILE
     },
     &cOCI8BFILE

Modified: trunk/ruby-oci8/ext/oci8/object.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/object.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/object.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -509,7 +509,7 @@
     rb_raise(rb_eRuntimeError, "not supported");
 }
 
-static void bind_named_type_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_named_type_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     VALUE tdo_obj = length;
 
@@ -564,6 +564,7 @@
     bind_named_type_init_elem,
     NULL,
     NULL,
+    NULL,
     SQLT_NTY
 };
 

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2008-01-04 12:52:59 UTC (rev 236)
@@ -124,10 +124,11 @@
     oci8_base_class_t base;
     VALUE (*get)(oci8_bind_t *obind, void *data, void *null_struct);
     void (*set)(oci8_bind_t *obind, void *data, void **null_structp, VALUE val);
-    void (*init)(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length);
+    void (*init)(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length);
     void (*init_elem)(oci8_bind_t *obind, VALUE svc);
     ub1 (*in)(oci8_bind_t *obind, ub4 idx, ub1 piece, void **valuepp, ub4 **alenpp, void **indpp);
     void (*out)(oci8_bind_t *obind, ub4 idx, ub1 piece, void **valuepp, ub4 **alenpp, void **indpp);
+    void (*pre_fetch_hook)(oci8_bind_t *obind, VALUE svc);
     ub2 dty;
     ub1 csfrm;
 };

Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocidatetime.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/ocidatetime.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -392,7 +392,7 @@
                                 strlen(tz_str)));
 }
 
-static void bind_datetime_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_datetime_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     oci8_bind_dsc_t *obind_dsc = (oci8_bind_dsc_t *)obind;
 
@@ -481,7 +481,7 @@
                                    *intvlpp));
 }
 
-static void bind_interval_ym_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_interval_ym_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     oci8_bind_dsc_t *obind_dsc = (oci8_bind_dsc_t *)obind;
 
@@ -625,7 +625,7 @@
                                    day, hour, minute, sec, fsec, *intvlpp));
 }
 
-static void bind_interval_ds_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_interval_ds_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     oci8_bind_dsc_t *obind_dsc = (oci8_bind_dsc_t *)obind;
 
@@ -658,6 +658,7 @@
     bind_datetime_init_elem,
     NULL,
     NULL,
+    NULL,
     SQLT_TIMESTAMP_TZ
 };
 
@@ -673,6 +674,7 @@
     bind_interval_ym_init_elem,
     NULL,
     NULL,
+    NULL,
     SQLT_INTERVAL_YM
 };
 
@@ -688,6 +690,7 @@
     bind_interval_ds_init_elem,
     NULL,
     NULL,
+    NULL,
     SQLT_INTERVAL_DS
 };
 

Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocinumber.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/ocinumber.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -1033,7 +1033,7 @@
     oci_lc(OCINumberTrunc(oci8_errhp, &num, 0, (OCINumber*)data));
 }
 
-static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = sizeof(OCINumber);
     obind->alloc_sz = sizeof(OCINumber);
@@ -1060,6 +1060,7 @@
     bind_ocinumber_init_elem,
     NULL,
     NULL,
+    NULL,
     SQLT_VNU,
 };
 
@@ -1075,6 +1076,7 @@
     bind_ocinumber_init_elem,
     NULL,
     NULL,
+    NULL,
     SQLT_VNU,
 };
 

Modified: trunk/ruby-oci8/ext/oci8/oradate.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oradate.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/oradate.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -384,7 +384,7 @@
     memcpy(data, od, sizeof(ora_date_t));
 }
 
-static void bind_oradate_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_oradate_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = sizeof(ora_date_t);
     obind->alloc_sz = sizeof(ora_date_t);
@@ -411,6 +411,7 @@
     bind_oradate_init_elem,
     NULL,
     NULL,
+    NULL,
     SQLT_DAT,
 };
 

Modified: trunk/ruby-oci8/ext/oci8/rowid.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/rowid.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/rowid.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -97,7 +97,7 @@
     vstr->size = strlen(rowid->id);
 }
 
-static void bind_rowid1_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_rowid1_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = BIND_ROWID1_SIZE;
     obind->alloc_sz = BIND_ROWID1_SIZE;
@@ -115,6 +115,7 @@
     NULL,
     NULL,
     NULL,
+    NULL,
     SQLT_LVC
 };
 
@@ -260,7 +261,7 @@
     oho->obj = val;
 }
 
-static void bind_rowid2_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_rowid2_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = sizeof(void *);
     obind->alloc_sz = sizeof(oci8_hp_obj_t);

Modified: trunk/ruby-oci8/ext/oci8/stmt.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/stmt.c	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/ext/oci8/stmt.c	2008-01-04 12:52:59 UTC (rev 236)
@@ -21,6 +21,7 @@
 static ID id_at_column_metadata;
 static ID id_at_names;
 static ID id_at_con;
+static ID id_set;
 
 VALUE cOCIStmt;
 
@@ -333,6 +334,16 @@
     oci8_bind_t *obind;
     oci8_bind_class_t *bind_class;
 
+    obind = (oci8_bind_t *)stmt->base.children;
+    do {
+        if (obind->base.type == OCI_HTYPE_DEFINE) {
+            bind_class = (oci8_bind_class_t *)obind->base.klass;
+            if (bind_class->pre_fetch_hook != NULL) {
+                bind_class->pre_fetch_hook(obind, stmt->svc);
+            }
+        }
+        obind = (oci8_bind_t *)obind->base.next;
+    } while (obind != (oci8_bind_t*)stmt->base.children);
     rv = OCIStmtFetch_nb(svcctx, stmt->base.hp.stmt, oci8_errhp, 1, OCI_FETCH_NEXT, OCI_DEFAULT);
     while (rv == OCI_NEED_DATA) {
         /* get piece info. */
@@ -647,13 +658,10 @@
     oho->obj = val;
 }
 
-static void bind_stmt_init(oci8_bind_t *obind, VALUE svc, VALUE *val, VALUE length)
+static void bind_stmt_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)
 {
     obind->value_sz = sizeof(void *);
     obind->alloc_sz = sizeof(oci8_hp_obj_t);
-    if (NIL_P(*val)) {
-        *val = rb_funcall(cOCIStmt, oci8_id_new, 1, svc);
-    }
 }
 
 static void bind_stmt_init_elem(oci8_bind_t *obind, VALUE svc)
@@ -681,6 +689,7 @@
     bind_stmt_init_elem,
     NULL,
     NULL,
+    bind_stmt_init_elem,
     SQLT_RSET
 };
 
@@ -701,6 +710,7 @@
     id_at_column_metadata = rb_intern("@column_metadata");
     id_at_names = rb_intern("@names");
     id_at_con = rb_intern("@con");
+    id_set = rb_intern("set");
 
     rb_define_private_method(cOCIStmt, "initialize", oci8_stmt_initialize, -1);
     rb_define_private_method(cOCIStmt, "__define", oci8_define_by_pos, 2);

Modified: trunk/ruby-oci8/test/test_oci8.rb
===================================================================
--- trunk/ruby-oci8/test/test_oci8.rb	2008-01-04 10:52:44 UTC (rev 235)
+++ trunk/ruby-oci8/test/test_oci8.rb	2008-01-04 12:52:59 UTC (rev 236)
@@ -153,7 +153,7 @@
     end
     cursor.close
     plsql = @conn.parse("BEGIN OPEN :cursor FOR SELECT * FROM test_table ORDER BY c; END;")
-    plsql.bind_param(':cursor', OCI8::Cursor)
+    plsql.bind_param(':cursor', nil, OCI8::Cursor)
     plsql.exec
     cursor = plsql[':cursor']
     cursor.define(5, Time) # define 5th column as Time
@@ -220,7 +220,6 @@
       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')




More information about the ruby-oci8-commit mailing list