[ruby-oci8-commit] [252] trunk/ruby-oci8: * ext/oci8/extconf.rb, ext/oci8/oci8lib.c, ext/oci8/ rowid.c:

nobody at rubyforge.org nobody at rubyforge.org
Fri Mar 7 22:10:53 EST 2008


Revision: 252
Author:   kubo
Date:     2008-03-07 22:10:53 -0500 (Fri, 07 Mar 2008)

Log Message:
-----------
* ext/oci8/extconf.rb, ext/oci8/oci8lib.c, ext/oci8/rowid.c:
    rowid.c is deleted. OCIRowid is no longer in use.
* ext/oci8/oci8.h, ext/oci8/attr.c: oci8_get_rowid_attr()
    is moved from rowid.c and returns a String instead of
    an OCIRowid object.
* ext/oci8/stmt.c: fix a rdoc comment of OCI8::Cursor#rowid.
* lib/oci8/oci8.rb: fetch a rowid value as a String.
* test/test_all.rb, test/test_rowid.rb: add a rowid testcase.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/attr.c
    trunk/ruby-oci8/ext/oci8/extconf.rb
    trunk/ruby-oci8/ext/oci8/oci8.h
    trunk/ruby-oci8/ext/oci8/oci8lib.c
    trunk/ruby-oci8/ext/oci8/stmt.c
    trunk/ruby-oci8/lib/oci8/oci8.rb
    trunk/ruby-oci8/test/test_all.rb

Added Paths:
-----------
    trunk/ruby-oci8/test/test_rowid.rb

Removed Paths:
-------------
    trunk/ruby-oci8/ext/oci8/rowid.c

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/ChangeLog	2008-03-08 03:10:53 UTC (rev 252)
@@ -1,3 +1,13 @@
+2008-03-08  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/extconf.rb, ext/oci8/oci8lib.c, ext/oci8/rowid.c:
+	    rowid.c is deleted. OCIRowid is no longer in use.
+	* ext/oci8/oci8.h, ext/oci8/attr.c: oci8_get_rowid_attr()
+	    is moved from rowid.c and returns a String instead of
+	    an OCIRowid object.
+	* ext/oci8/stmt.c: fix a rdoc comment of OCI8::Cursor#rowid.
+	* lib/oci8/oci8.rb: fetch a rowid value as a String.
+	* test/test_all.rb, test/test_rowid.rb: add a rowid testcase.
+
 2008-03-07  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/apiwrap.c.tmpl, ext/oci8/apiwrap.rb, ext/oci8/apiwrap.yml:
 	    add all OCI functions to 'apiwrap.yml'.

Modified: trunk/ruby-oci8/ext/oci8/attr.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/attr.c	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/ext/oci8/attr.c	2008-03-08 03:10:53 UTC (rev 252)
@@ -68,3 +68,96 @@
         oci8_raise(oci8_errhp, rv, NULL);
     return rb_str_new(TO_CHARPTR(val), size);
 }
+
+#define MAX_ROWID_LEN 128
+
+typedef struct {
+    oci8_base_t *base;
+    ub4 attrtype;
+    OCIRowid *ridp;
+    OCIStmt *stmtp;
+} rowid_arg_t;
+
+static VALUE get_rowid_attr(rowid_arg_t *arg)
+{
+    oci8_base_t *base = arg->base;
+    ub4 attrtype = arg->attrtype;
+    char buf[MAX_ROWID_LEN];
+    ub2 buflen;
+    sword rv;
+
+	/* get a rowid descriptor from OCIHandle */
+    rv = OCIDescriptorAlloc(oci8_envhp, (dvoid*)&arg->ridp, OCI_DTYPE_ROWID, 0, NULL);
+    if (rv != OCI_SUCCESS)
+        oci8_env_raise(oci8_envhp, rv);
+    rv = OCIAttrGet(base->hp.ptr, base->type, arg->ridp, 0, attrtype, oci8_errhp);
+    if (rv != OCI_SUCCESS) {
+        oci8_raise(oci8_errhp, rv, NULL);
+    }
+    /* convert the rowid descriptor to a string. */
+    if (have_OCIRowidToChar) {
+        /* If OCIRowidToChar is available, use it. */
+        buflen = MAX_ROWID_LEN;
+        rv = OCIRowidToChar(arg->ridp, TO_ORATEXT(buf), &buflen, oci8_errhp);
+        if (rv != OCI_SUCCESS) {
+            oci8_raise(oci8_errhp, rv, NULL);
+        }
+    } else {
+        /* If OCIRowidToChar is not available, convert it on
+         * Oracle Server.
+         */
+        oci8_base_t *svc;
+        OCIBind *bind1 = NULL;
+        OCIBind *bind2 = NULL;
+        sword rv;
+
+        /* search a connection from the handle */
+        svc = base;
+        while (svc->type != OCI_HTYPE_SVCCTX) {
+            svc = svc->parent;
+            if (svc == NULL) {
+                rb_raise(rb_eRuntimeError, "No connection is found!!");
+            }
+        }
+        /*
+         * equivalent code:
+         *   cursor = conn.parse("BEGIN :1 := :2; END;")
+         *   cursor.bind(1, nil, String, MAX_ROWID_LEN)
+         *   cursor.bind(2, rowid, OCIRowid)
+         *   cursor.exec()
+         *   cursor[1] # => rowid's string representation
+         */
+#define ROWIDTOCHAR_SQL "BEGIN :1 := :2; END;"
+        buflen = 0;
+        rv = OCIHandleAlloc(oci8_envhp, (dvoid*)&arg->stmtp, OCI_HTYPE_STMT, 0, NULL);
+        if (rv != OCI_SUCCESS) {
+            oci8_env_raise(oci8_envhp, rv);
+        }
+        oci_lc(OCIStmtPrepare(arg->stmtp, oci8_errhp, (text*)ROWIDTOCHAR_SQL, strlen(ROWIDTOCHAR_SQL), OCI_NTV_SYNTAX, OCI_DEFAULT));
+        oci_lc(OCIBindByPos(arg->stmtp, &bind1, oci8_errhp, 1, buf, MAX_ROWID_LEN, SQLT_STR, NULL, &buflen, 0, 0, 0, OCI_DEFAULT));
+        oci_lc(OCIBindByPos(arg->stmtp, &bind2, oci8_errhp, 2, (dvoid*)&arg->ridp, sizeof(void*), SQLT_RDD, NULL, NULL, 0, 0, 0, OCI_DEFAULT));
+        oci_lc(OCIStmtExecute_nb((oci8_svcctx_t*)svc, svc->hp.svc, arg->stmtp, oci8_errhp, 1, 0, NULL, NULL, OCI_DEFAULT));
+    }
+    return rb_str_new(buf, buflen);
+}
+
+static VALUE rowid_ensure(rowid_arg_t *arg)
+{
+    if (arg->stmtp != NULL) {
+        OCIHandleFree(arg->stmtp, OCI_HTYPE_STMT);
+    }
+    if (arg->ridp != NULL) {
+        OCIDescriptorFree(arg->ridp, OCI_DTYPE_ROWID);
+    }
+    return Qnil;
+}
+
+VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype)
+{
+    rowid_arg_t arg;
+    arg.base = base;
+    arg.attrtype = attrtype;
+    arg.ridp = NULL;
+    arg.stmtp = NULL;
+    return rb_ensure(get_rowid_attr, (VALUE)&arg, rowid_ensure, (VALUE)&arg);
+}

Modified: trunk/ruby-oci8/ext/oci8/extconf.rb
===================================================================
--- trunk/ruby-oci8/ext/oci8/extconf.rb	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/ext/oci8/extconf.rb	2008-03-08 03:10:53 UTC (rev 252)
@@ -69,7 +69,7 @@
 
 $objs = ["oci8lib.o", "env.o", "error.o", "oci8.o",
          "stmt.o", "bind.o", "metadata.o", "attr.o",
-         "rowid.o", "lob.o", "oradate.o",
+         "lob.o", "oradate.o",
          "ocinumber.o", "ocidatetime.o", "object.o", "apiwrap.o",
          "xmldb.o"]
 

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2008-03-08 03:10:53 UTC (rev 252)
@@ -312,10 +312,6 @@
 void Init_oci8_bind(VALUE cOCIBind);
 oci8_bind_t *oci8_get_bind(VALUE obj);
 
-/* rowid.c */
-void Init_oci8_rowid(void);
-VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype);
-
 /* metadata.c */
 extern VALUE cOCI8MetadataBase;
 void Init_oci8_metadata(VALUE cOCI8);
@@ -368,6 +364,7 @@
 VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype);
 VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype);
 VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype);
+VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype);
 
 #include "apiwrap.h"
 

Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c	2008-03-08 03:10:53 UTC (rev 252)
@@ -148,7 +148,6 @@
     Init_oci8_stmt(cOCI8);
 
     /* register allocators */
-    Init_oci8_rowid();
     Init_oci8_metadata(cOCI8);
     Init_oci8_lob(cOCI8);
 

Deleted: trunk/ruby-oci8/ext/oci8/rowid.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/rowid.c	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/ext/oci8/rowid.c	2008-03-08 03:10:53 UTC (rev 252)
@@ -1,341 +0,0 @@
-/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
-/*
-  descriptor.c - part of ruby-oci8
-
-  Copyright (C) 2002-2007 KUBO Takehiro <kubo at jiubao.org>
-*/
-#include "oci8.h"
-
-static VALUE cOCIRowid;
-
-#if defined(RUNTIME_API_CHECK)
-#define USE_ROWID1
-#define USE_ROWID2
-#elif have_OCIRowidToChar
-#define USE_ROWID1
-#define Init_oci8_rowid1 Init_oci8_rowid
-#define oci8_get_rowid1_attr oci8_get_rowid_attr
-#else
-#define USE_ROWID2
-#define Init_oci8_rowid2 Init_oci8_rowid
-#define oci8_get_rowid2_attr oci8_get_rowid_attr
-#endif
-
-#ifdef USE_ROWID1
-/* use OCIRowidToChar. */
-
-#define MAX_ROWID_LEN 128
-
-typedef struct {
-    oci8_base_t base;
-    char id[MAX_ROWID_LEN + 1];
-} oci8_rowid1_t;
-
-static oci8_base_class_t oci8_rowid1_class = {
-    NULL,
-    NULL,
-    sizeof(oci8_rowid1_t),
-};
-
-static void oci8_rowid1_set(VALUE self, char *ptr, ub4 len)
-{
-    oci8_rowid1_t *rowid = DATA_PTR(self);
-
-    if (len > MAX_ROWID_LEN) {
-        rb_raise(rb_eArgError, "too long String to set. (%u for %d)", len, MAX_ROWID_LEN);
-    }
-    memcpy(rowid->id, ptr, len);
-    rowid->id[len] = '\0';
-}
-
-static VALUE oci8_rowid1_initialize(VALUE self, VALUE val)
-{
-    oci8_rowid1_t *rowid = DATA_PTR(self);
-
-    rowid->base.hp.ptr = NULL;
-    rowid->base.type = 0;
-    if (!NIL_P(val)) {
-        StringValue(val);
-        oci8_rowid1_set(self, RSTRING_PTR(val), RSTRING_LEN(val));
-    } else {
-        rowid->id[0] = '\0';
-    }
-    return Qnil;
-}
-
-static VALUE oci8_rowid1_initialize_copy(VALUE lhs, VALUE rhs)
-{
-    oci8_rowid1_t *l, *r;
-
-    rb_obj_init_copy(lhs, rhs);
-    l = DATA_PTR(lhs);
-    r = DATA_PTR(rhs);
-    memcpy(l->id, r->id, sizeof(l->id));
-    return lhs;
-}
-
-/*
- * bind_rowid
- */
-#define BIND_ROWID1_SIZE (((sizeof(oci8_vstr_t) + MAX_ROWID_LEN) + 3) & ~3)
-static VALUE bind_rowid1_get(oci8_bind_t *obind, void *data, void *null_struct)
-{
-    VALUE rowid = rb_funcall(cOCIRowid, oci8_id_new, 1, Qnil);
-    oci8_vstr_t *vstr = (oci8_vstr_t *)data;
-    oci8_rowid1_set(rowid, vstr->buf, vstr->size);
-    return rowid;
-}
-
-static void bind_rowid1_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
-{
-    oci8_rowid1_t *rowid;
-    oci8_vstr_t *vstr = (oci8_vstr_t *)data;
-    if (!rb_obj_is_instance_of(val, cOCIRowid))
-        rb_raise(rb_eArgError, "Invalid argument: %s (expect OCIRowid)", rb_class2name(CLASS_OF(val)));
-    rowid = DATA_PTR(val);
-    memcpy(vstr->buf, rowid->id, sizeof(rowid->id));
-    vstr->size = strlen(rowid->id);
-}
-
-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;
-}
-
-static oci8_bind_class_t bind_rowid1_class = {
-    {
-        NULL,
-        oci8_bind_free,
-        sizeof(oci8_bind_t)
-    },
-    bind_rowid1_get,
-    bind_rowid1_set,
-    bind_rowid1_init,
-    NULL,
-    NULL,
-    NULL,
-    NULL,
-    SQLT_LVC
-};
-
-VALUE oci8_get_rowid1_attr(oci8_base_t *base, ub4 attrtype)
-{
-    OCIRowid *riddp;
-    VALUE rowid;
-    sword rv;
-    OraText buf[MAX_ROWID_LEN];
-    ub2 buflen = MAX_ROWID_LEN;
-
-    rv = OCIDescriptorAlloc(oci8_envhp, (dvoid*)&riddp, OCI_DTYPE_ROWID, 0, NULL);
-    if (rv != OCI_SUCCESS)
-        oci8_env_raise(oci8_envhp, rv);
-    rv = OCIAttrGet(base->hp.ptr, base->type, riddp, 0, attrtype, oci8_errhp);
-    if (rv != OCI_SUCCESS) {
-        OCIDescriptorFree(riddp, OCI_DTYPE_ROWID);
-        oci8_raise(oci8_errhp, rv, NULL);
-    }
-    rv = OCIRowidToChar(riddp, buf, &buflen, oci8_errhp);
-    if (rv != OCI_SUCCESS) {
-        OCIDescriptorFree(riddp, OCI_DTYPE_ROWID);
-        oci8_raise(oci8_errhp, rv, NULL);
-    }
-    OCIDescriptorFree(riddp, OCI_DTYPE_ROWID);
-
-    rowid = rb_funcall(cOCIRowid, oci8_id_new, 1, Qnil);
-    oci8_rowid1_set(rowid, TO_CHARPTR(buf), buflen);
-    return rowid;
-}
-
-static VALUE oci8_rowid1_to_s(VALUE self)
-{
-    oci8_rowid1_t *rowid = DATA_PTR(self);
-
-    return rb_str_new2(rowid->id);
-}
-
-static VALUE oci8_rowid1_inspect(VALUE self)
-{
-    oci8_rowid1_t *rowid = DATA_PTR(self);
-    char *name = rb_class2name(CLASS_OF(self));
-    char *str = ALLOCA_N(char, strlen(name) + strlen(rowid->id) + 5);
-
-    sprintf(str, "#<%s:%s>", name, rowid->id);
-    return rb_str_new2(str);
-}
-
-/*
- *  call-seq:
- *    rowid._dump   => string
- *
- *  Dump <i>rowid</i> for marshaling.
- */
-static VALUE oci8_rowid1_dump(int argc, VALUE *argv, VALUE self)
-{
-    oci8_rowid1_t *rowid = DATA_PTR(self);
-    VALUE dummy;
-
-    rb_scan_args(argc, argv, "01", &dummy);
-    return rb_str_new2(rowid->id);
-}
-
-/*
- *  call-seq:
- *    OCIRowid._load(string)   => ocinumber
- *
- *  Unmarshal a dumped <code>OCIRowid</code> object.
- */
-static VALUE oci8_rowid1_s_load(VALUE klass, VALUE str)
-{
-    VALUE rowid;
-    StringValue(str);
-
-    rowid = rb_funcall(klass, oci8_id_new, 1, Qnil);
-    oci8_rowid1_set(rowid, RSTRING_PTR(str), RSTRING_LEN(str));
-    return rowid;
-}
-
-void Init_oci8_rowid1(void)
-{
-    cOCIRowid = oci8_define_class("OCIRowid", &oci8_rowid1_class);
-    rb_define_method(cOCIRowid, "initialize", oci8_rowid1_initialize, 1);
-    oci8_define_bind_class("OCIRowid", &bind_rowid1_class);
-
-    rb_define_method(cOCIRowid, "to_s", oci8_rowid1_to_s, 0);
-    rb_define_method(cOCIRowid, "inspect", oci8_rowid1_inspect, 0);
-
-    rb_define_method(cOCIRowid, "initialize_copy", oci8_rowid1_initialize_copy, 1);
-    rb_define_method(cOCIRowid, "_dump", oci8_rowid1_dump, -1);
-    rb_define_singleton_method(cOCIRowid, "_load", oci8_rowid1_s_load, 1);
-}
-#endif /* USE_ROWID2 */
-
-#ifdef USE_ROWID2
-/* don't use OCIRowidToChar. */
-
-typedef struct {
-    oci8_base_t base;
-} oci8_rowid2_t;
-
-static oci8_base_class_t oci8_rowid2_class = {
-    NULL,
-    NULL,
-    sizeof(oci8_rowid2_t),
-};
-
-static VALUE oci8_rowid2_initialize(VALUE self)
-{
-    oci8_rowid2_t *rowid = DATA_PTR(self);
-    sword rv;
-
-    rv = OCIDescriptorAlloc(oci8_envhp, &rowid->base.hp.ptr, OCI_DTYPE_ROWID, 0, NULL);
-    if (rv != OCI_SUCCESS)
-        oci8_env_raise(oci8_envhp, rv);
-    rowid->base.type = OCI_DTYPE_ROWID;
-    return Qnil;
-}
-
-static VALUE oci8_rowid2_initialize_copy(VALUE lhs, VALUE rhs)
-{
-    rb_notimplement();
-}
-
-/*
- * bind_rowid
- */
-static VALUE bind_rowid2_get(oci8_bind_t *obind, void *data, void *null_struct)
-{
-    oci8_hp_obj_t *oho = (oci8_hp_obj_t *)data;
-    return oho->obj;
-}
-
-static void bind_rowid2_set(oci8_bind_t *obind, void *data, void **null_structp, VALUE val)
-{
-    oci8_hp_obj_t *oho = (oci8_hp_obj_t *)data;
-    oci8_base_t *h;
-
-    if (!rb_obj_is_instance_of(val, cOCIRowid))
-        rb_raise(rb_eArgError, "Invalid argument: %s (expect OCIRowid)", rb_class2name(CLASS_OF(val)));
-    h = DATA_PTR(val);
-    oho->hp = h->hp.ptr;
-    oho->obj = val;
-}
-
-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);
-}
-
-static void bind_rowid2_init_elem(oci8_bind_t *obind, VALUE svc)
-{
-    oci8_hp_obj_t *oho = (oci8_hp_obj_t *)obind->valuep;
-    oci8_base_t *h;
-    ub4 idx = 0;
-
-    do {
-        oho[idx].obj = rb_funcall(cOCIRowid, oci8_id_new, 0);
-        h = DATA_PTR(oho[idx].obj);
-        oho[idx].hp = h->hp.ptr;
-    } while (++idx < obind->maxar_sz);
-}
-
-static oci8_bind_class_t bind_rowid2_class = {
-    {
-        oci8_bind_hp_obj_mark,
-        oci8_bind_free,
-        sizeof(oci8_bind_t)
-    },
-    bind_rowid2_get,
-    bind_rowid2_set,
-    bind_rowid2_init,
-    bind_rowid2_init_elem,
-    NULL,
-    NULL,
-    SQLT_RDD
-};
-
-VALUE oci8_get_rowid2_attr(oci8_base_t *base, ub4 attrtype)
-{
-    oci8_base_t *rowid;
-    VALUE obj;
-    sword rv;
-
-    obj = rb_funcall(cOCIRowid, oci8_id_new, 0);
-    rowid = DATA_PTR(obj);
-    rv = OCIAttrGet(base->hp.ptr, base->type, rowid->hp.ptr, 0, attrtype, oci8_errhp);
-    if (rv != OCI_SUCCESS) {
-        oci8_base_free(rowid);
-        oci8_raise(oci8_errhp, rv, NULL);
-    }
-    return obj;
-}
-
-void Init_oci8_rowid2(void)
-{
-    cOCIRowid = oci8_define_class("OCIRowid", &oci8_rowid2_class);
-    rb_define_method(cOCIRowid, "initialize", oci8_rowid2_initialize, 0);
-    rb_define_method(cOCIRowid, "initialize_copy", oci8_rowid2_initialize_copy, 1);
-    oci8_define_bind_class("OCIRowid", &bind_rowid2_class);
-}
-#endif /* USE_ROWID2 */
-
-#ifdef RUNTIME_API_CHECK
-void Init_oci8_rowid(void)
-{
-    if (have_OCIRowidToChar) {
-        Init_oci8_rowid1();
-    } else {
-        Init_oci8_rowid2();
-    }
-}
-
-VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype)
-{
-    if (have_OCIRowidToChar) {
-        return oci8_get_rowid1_attr(base, attrtype);
-    } else {
-        return oci8_get_rowid2_attr(base, attrtype);
-    }
-}
-#endif /* RUNTIME_API_CHECK */

Modified: trunk/ruby-oci8/ext/oci8/stmt.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/stmt.c	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/ext/oci8/stmt.c	2008-03-08 03:10:53 UTC (rev 252)
@@ -549,9 +549,17 @@
 }
 
 /*
- * get the rowid of the last processed row.
- * This value is available as bind data.
- * On the other hand it isn't available for other purpose.
+ * Get the rowid of the last inserted/updated/deleted row.
+ * This cannot be used for select statements.
+ *
+ * example:
+ *   cursor = conn.parse('INSERT INTO foo_table values(:1, :2)', 1, 2)
+ *   cursor.exec
+ *   cursor.rowid # => the inserted row's rowid
+ *
+ * The return value is a String in ruby-oci8 2.0 or later.
+ *
+ * It is an OCIRowid object in ruby-oci8 1.0.
  */
 static VALUE oci8_stmt_get_rowid(VALUE self)
 {

Modified: trunk/ruby-oci8/lib/oci8/oci8.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/oci8.rb	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/lib/oci8/oci8.rb	2008-03-08 03:10:53 UTC (rev 252)
@@ -600,7 +600,6 @@
 OCI8::BindType::Mapping[Time]         = OCI8::BindType::Time
 OCI8::BindType::Mapping[Date]         = OCI8::BindType::Date
 OCI8::BindType::Mapping[DateTime]     = OCI8::BindType::DateTime
-OCI8::BindType::Mapping[OCIRowid]     = OCI8::BindType::OCIRowid
 OCI8::BindType::Mapping[OCI8::CLOB]   = OCI8::BindType::CLOB
 OCI8::BindType::Mapping[OCI8::NCLOB]  = OCI8::BindType::NCLOB
 OCI8::BindType::Mapping[OCI8::BLOB]   = OCI8::BindType::BLOB
@@ -669,7 +668,7 @@
 # datatype        type     size prec scale
 # -------------------------------------------------
 # ROWID         SQLT_RDD      4    0    0
-OCI8::BindType::Mapping[:rowid] = OCI8::BindType::OCIRowid
+OCI8::BindType::Mapping[:rowid] = OCI8::BindType::String
 
 # datatype           type     size prec scale
 # -----------------------------------------------------

Modified: trunk/ruby-oci8/test/test_all.rb
===================================================================
--- trunk/ruby-oci8/test/test_all.rb	2008-03-07 14:15:15 UTC (rev 251)
+++ trunk/ruby-oci8/test/test_all.rb	2008-03-08 03:10:53 UTC (rev 252)
@@ -18,6 +18,7 @@
 require "#{srcdir}/test_connstr"
 require "#{srcdir}/test_metadata"
 require "#{srcdir}/test_array_dml"
+require "#{srcdir}/test_rowid"
 
 # Ruby/DBI
 begin

Added: trunk/ruby-oci8/test/test_rowid.rb
===================================================================
--- trunk/ruby-oci8/test/test_rowid.rb	                        (rev 0)
+++ trunk/ruby-oci8/test/test_rowid.rb	2008-03-08 03:10:53 UTC (rev 252)
@@ -0,0 +1,32 @@
+require 'oci8'
+require 'test/unit'
+require './config'
+
+class TestRowid < Test::Unit::TestCase
+
+  def setup
+    @conn = get_oci8_connection
+  end
+
+  def test_rowid
+    drop_table('test_table')
+    sql = <<-EOS
+CREATE TABLE test_table (N NUMBER(38))
+EOS
+    @conn.exec(sql)
+    cursor = @conn.parse("INSERT INTO test_table values(1)");
+    cursor.exec
+    rid1 = cursor.rowid
+    cursor.close
+    rid2 = nil
+    @conn.exec('select rowid from test_table where rowid = :1', rid1) do |row|
+      rid2 = row[0]
+    end
+    assert_equal(rid2, rid1)
+    drop_table('test_table')
+  end
+
+  def teardown
+    @conn.logoff
+  end
+end




More information about the ruby-oci8-commit mailing list