[ruby-oci8-commit] [390] trunk/ruby-oci8: * ext/oci8/lob.c, ext/oci8/object.c, ext/oci8/oci8.h ,

nobody at rubyforge.org nobody at rubyforge.org
Tue Apr 27 10:31:26 EDT 2010


Revision: 390
Author:   kubo
Date:     2010-04-27 10:31:26 -0400 (Tue, 27 Apr 2010)

Log Message:
-----------
* ext/oci8/lob.c, ext/oci8/object.c, ext/oci8/oci8.h,
  ext/oci8/stmt.c: refactor code to prepare character length
    semantics support.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    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/stmt.c

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2010-04-27 12:50:42 UTC (rev 389)
+++ trunk/ruby-oci8/ChangeLog	2010-04-27 14:31:26 UTC (rev 390)
@@ -1,4 +1,9 @@
 2010-04-27  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/lob.c, ext/oci8/object.c, ext/oci8/oci8.h,
+	  ext/oci8/stmt.c: refactor code to prepare character length
+	    semantics support.
+
+2010-04-27  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/encoding.c: add new methods OCI8.nls_ratio
 	    and OCI8.nls_ratio=. Comments for rdoc are added and
 	    revised for OCI8#charset_name2id, OCI8#charset_name2id=,

Modified: trunk/ruby-oci8/ext/oci8/lob.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/lob.c	2010-04-27 12:50:42 UTC (rev 389)
+++ trunk/ruby-oci8/ext/oci8/lob.c	2010-04-27 14:31:26 UTC (rev 390)
@@ -634,6 +634,13 @@
     } while (++idx < obind->maxar_sz);
 }
 
+static void bind_lob_post_bind_hook_for_nclob(oci8_bind_t *obind)
+{
+    ub1 csfrm = SQLCS_NCHAR;
+
+    oci_lc(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp));
+}
+
 static const oci8_bind_lob_class_t bind_clob_class = {
     {
         {
@@ -668,7 +675,7 @@
         NULL,
         NULL,
         SQLT_CLOB,
-        SQLCS_NCHAR,
+        bind_lob_post_bind_hook_for_nclob,
     },
     &cOCI8NCLOB
 };

Modified: trunk/ruby-oci8/ext/oci8/object.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/object.c	2010-04-27 12:50:42 UTC (rev 389)
+++ trunk/ruby-oci8/ext/oci8/object.c	2010-04-27 14:31:26 UTC (rev 390)
@@ -581,6 +581,21 @@
     } while (++idx < obind->maxar_sz);
 }
 
+static void bind_name_type_post_bind_hook(oci8_bind_t *obind)
+{
+    oci8_base_t *tdo = DATA_PTR(obind->tdo);
+    switch (obind->base.type) {
+    case OCI_HTYPE_DEFINE:
+        oci_lc(OCIDefineObject(obind->base.hp.dfn, oci8_errhp, tdo->hp.tdo,
+                               obind->valuep, 0, obind->u.null_structs, 0));
+        break;
+    case OCI_HTYPE_BIND:
+        oci_lc(OCIBindObject(obind->base.hp.bnd, oci8_errhp, tdo->hp.tdo,
+                             obind->valuep, 0, obind->u.null_structs, 0));
+        break;
+    }
+}
+
 static const oci8_bind_class_t bind_named_type_class = {
     {
         bind_named_type_mark,
@@ -594,7 +609,8 @@
     NULL,
     NULL,
     NULL,
-    SQLT_NTY
+    SQLT_NTY,
+    bind_name_type_post_bind_hook,
 };
 
 void Init_oci_object(VALUE cOCI8)

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2010-04-27 12:50:42 UTC (rev 389)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2010-04-27 14:31:26 UTC (rev 390)
@@ -261,7 +261,7 @@
     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;
+    void (*post_bind_hook)(oci8_bind_t *obind);
 };
 
 struct oci8_base {

Modified: trunk/ruby-oci8/ext/oci8/stmt.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/stmt.c	2010-04-27 12:50:42 UTC (rev 389)
+++ trunk/ruby-oci8/ext/oci8/stmt.c	2010-04-27 14:31:26 UTC (rev 390)
@@ -120,19 +120,14 @@
     if (NIL_P(obind->tdo) && obind->maxar_sz > 0) {
         oci_lc(OCIDefineArrayOfStruct(obind->base.hp.dfn, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0));
     }
-    if (RTEST(obind->tdo)) {
-        oci8_base_t *tdo = DATA_PTR(obind->tdo);
-        oci_lc(OCIDefineObject(obind->base.hp.dfn, oci8_errhp, tdo->hp.tdo,
-                               obind->valuep, 0, obind->u.null_structs, 0));
-    }
     if (position - 1 < RARRAY_LEN(stmt->defns)) {
         VALUE old_value = RARRAY_PTR(stmt->defns)[position - 1];
         if (!NIL_P(old_value)) {
             oci8_base_free((oci8_base_t*)oci8_get_bind(old_value));
         }
     }
-    if (bind_class->csfrm != 0) {
-        oci_lc(OCIAttrSet(obind->base.hp.ptr, OCI_HTYPE_DEFINE, (void*)&bind_class->csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp));
+    if (bind_class->post_bind_hook != NULL) {
+        bind_class->post_bind_hook(obind);
     }
     rb_ary_store(stmt->defns, position - 1, obind->base.self);
     oci8_unlink_from_parent((oci8_base_t*)obind);
@@ -200,14 +195,9 @@
     if (NIL_P(obind->tdo) && obind->maxar_sz > 0) {
         oci_lc(OCIBindArrayOfStruct(obind->base.hp.bnd, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0));
     }
-    if (!NIL_P(obind->tdo)) {
-        oci8_base_t *tdo = DATA_PTR(obind->tdo);
-        oci_lc(OCIBindObject(obind->base.hp.bnd, oci8_errhp, tdo->hp.tdo,
-                             obind->valuep, 0, obind->u.null_structs, 0));
+    if (bind_class->post_bind_hook != NULL) {
+        bind_class->post_bind_hook(obind);
     }
-    if (bind_class->csfrm != 0) {
-        oci_lc(OCIAttrSet(obind->base.hp.ptr, OCI_HTYPE_BIND, (void*)&bind_class->csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp));
-    }
     old_value = rb_hash_aref(stmt->binds, vplaceholder);
     if (!NIL_P(old_value)) {
         oci8_base_free((oci8_base_t*)oci8_get_bind(old_value));




More information about the ruby-oci8-commit mailing list