[ruby-oci8-commit] [459] trunk/ruby-oci8: add OCI8#last_error and OCI8#last_error=.

nobody at rubyforge.org nobody at rubyforge.org
Sat Oct 22 09:32:50 EDT 2011


Revision: 459
Author:   kubo
Date:     2011-10-22 09:32:49 -0400 (Sat, 22 Oct 2011)

Log Message:
-----------
add OCI8#last_error and OCI8#last_error=.
When an exception is raised associated with a connection, the
exception is set to OCI8#last_error. No OCISuccessWithInfo excpetion
is raised from now on. It is set to OCI8#last_error instead.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/attr.c
    trunk/ruby-oci8/ext/oci8/bind.c
    trunk/ruby-oci8/ext/oci8/connection_pool.c
    trunk/ruby-oci8/ext/oci8/error.c
    trunk/ruby-oci8/ext/oci8/lob.c
    trunk/ruby-oci8/ext/oci8/metadata.c
    trunk/ruby-oci8/ext/oci8/object.c
    trunk/ruby-oci8/ext/oci8/oci8.c
    trunk/ruby-oci8/ext/oci8/oci8.h
    trunk/ruby-oci8/ext/oci8/oci8lib.c
    trunk/ruby-oci8/ext/oci8/ocidatetime.c
    trunk/ruby-oci8/ext/oci8/ocihandle.c
    trunk/ruby-oci8/ext/oci8/ocinumber.c
    trunk/ruby-oci8/ext/oci8/stmt.c

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ChangeLog	2011-10-22 13:32:49 UTC (rev 459)
@@ -1,4 +1,15 @@
 2011-10-22  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/attr.c, ext/oci8/bind.c, ext/oci8/connection_pool.c,
+	  ext/oci8/error.c, ext/oci8/lob.c, ext/oci8/metadata.c,
+	  ext/oci8/object.c, ext/oci8/oci8.c, ext/oci8/oci8.h,
+	  ext/oci8/oci8lib.c, ext/oci8/ocidatetime.c, ext/oci8/ocihandle.c,
+	  ext/oci8/ocinumber.c, ext/oci8/stmt.c: add OCI8#last_error and
+	    OCI8#last_error=. When an exception is raised associated with a
+	    connection, the exception is set to OCI8#last_error.
+	    No OCISuccessWithInfo excpetion is raised from now on. It is
+	    set to OCI8#last_error instead.
+
+2011-10-22  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/error.c, test/test_break.rb, test/test_error.rb: change the super
 	    class of OCINoData from OCIException to OCIError and fix testcases for
 	    OCIError and its subclasses.

Modified: trunk/ruby-oci8/ext/oci8/attr.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/attr.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/attr.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -6,47 +6,39 @@
  */
 #include "oci8.h"
 
-VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype)
+VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp)
 {
     sb1 val;
-    sword rv;
 
-    rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp);
-    if (rv != OCI_SUCCESS)
-        oci8_raise(oci8_errhp, rv, NULL);
+    chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp),
+           base, stmtp);
     return INT2FIX(val);
 }
 
-VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype)
+VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp)
 {
     ub2 val;
-    sword rv;
 
-    rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp);
-    if (rv != OCI_SUCCESS)
-        oci8_raise(oci8_errhp, rv, NULL);
+    chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp),
+           base, stmtp);
     return INT2FIX(val);
 }
 
-VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype)
+VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp)
 {
     sb2 val;
-    sword rv;
 
-    rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp);
-    if (rv != OCI_SUCCESS)
-        oci8_raise(oci8_errhp, rv, NULL);
+    chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp),
+           base, stmtp);
     return INT2FIX(val);
 }
 
-VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype)
+VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp)
 {
     ub4 val;
-    sword rv;
 
-    rv = OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp);
-    if (rv != OCI_SUCCESS)
-        oci8_raise(oci8_errhp, rv, NULL);
+    chker3(OCIAttrGet(base->hp.ptr, base->type, &val, NULL, attrtype, oci8_errhp),
+           base, stmtp);
 #if SIZEOF_LONG > 4
     return LONG2FIX(val);
 #else
@@ -54,15 +46,13 @@
 #endif
 }
 
-VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype)
+VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp)
 {
     text *val;
     ub4 size;
-    sword rv;
 
-    rv = OCIAttrGet(base->hp.ptr, base->type, &val, &size, attrtype, oci8_errhp);
-    if (rv != OCI_SUCCESS)
-        oci8_raise(oci8_errhp, rv, NULL);
+    chker3(OCIAttrGet(base->hp.ptr, base->type, &val, &size, attrtype, oci8_errhp),
+           base, stmtp);
     return rb_external_str_new_with_enc(TO_CHARPTR(val), size, oci8_encoding);
 }
 
@@ -70,6 +60,7 @@
 
 typedef struct {
     oci8_base_t *base;
+    OCIStmt *stmtp;
     ub4 attrtype;
     OCIRowid *ridp;
 } rowid_arg_t;
@@ -86,52 +77,12 @@
     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);
-    }
+    chker3(OCIAttrGet(base->hp.ptr, base->type, arg->ridp, 0, attrtype, oci8_errhp),
+           base, arg->stmtp);
     /* 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;
-        oci8_exec_sql_var_t define_var;
-        oci8_exec_sql_var_t bind_var;
-
-        /* 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!!");
-            }
-        }
-        /* :strval */
-        define_var.valuep = buf;
-        define_var.value_sz = sizeof(buf);
-        define_var.dty = SQLT_CHR;
-        define_var.indp = NULL;
-        define_var.alenp = &buflen;
-        /* :rowid */
-        bind_var.valuep = &arg->ridp;
-        bind_var.value_sz = sizeof(void *);
-        bind_var.dty = SQLT_RDD;
-        bind_var.indp = NULL;
-        bind_var.alenp = NULL;
-        /* convert the rowid descriptor to a string value by querying Oracle server. */
-        oci8_exec_sql((oci8_svcctx_t*)svc, "SELECT :rid FROM dual", 1, &define_var, 1, &bind_var, 1);
-        if (buflen == 0) {
-            return Qnil;
-        }
-    }
+    buflen = MAX_ROWID_LEN;
+    chker3(OCIRowidToChar(arg->ridp, TO_ORATEXT(buf), &buflen, oci8_errhp),
+           base, arg->stmtp);
     return rb_external_str_new_with_enc(buf, buflen, rb_usascii_encoding());
 }
 
@@ -143,10 +94,11 @@
     return Qnil;
 }
 
-VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype)
+VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp)
 {
     rowid_arg_t arg;
     arg.base = base;
+    arg.stmtp = stmtp;
     arg.attrtype = attrtype;
     arg.ridp = NULL;
     return rb_ensure(get_rowid_attr, (VALUE)&arg, rowid_ensure, (VALUE)&arg);

Modified: trunk/ruby-oci8/ext/oci8/bind.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/bind.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/bind.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -97,9 +97,11 @@
     oci8_bind_string_t *obs = (oci8_bind_string_t *)obind;
 
     if (obs->charlen != 0) {
-        oci_lc(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->charlen, 0, OCI_ATTR_MAXCHAR_SIZE, oci8_errhp));
+        chker2(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->charlen, 0, OCI_ATTR_MAXCHAR_SIZE, oci8_errhp),
+               &obind->base);
     }
-    oci_lc(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp));
+    chker2(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&obs->csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp),
+           &obind->base);
 }
 
 static const oci8_bind_vtable_t bind_string_vtable = {

Modified: trunk/ruby-oci8/ext/oci8/connection_pool.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/connection_pool.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/connection_pool.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -124,7 +124,7 @@
         oci8_env_raise(oci8_envhp, rv);
     cpool->base.type = OCI_HTYPE_CPOOL;
 
-    oci_lc(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
+    chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
                                    &pool_name, &pool_name_len,
                                    NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname),
                                    NIL_P(dbname) ? 0 : RSTRING_LEN(dbname),
@@ -134,7 +134,8 @@
                                    NIL_P(username) ? 0 : RSTRING_LEN(username),
                                    NIL_P(password) ? NULL : RSTRING_ORATEXT(password),
                                    NIL_P(password) ? 0 : RSTRING_LEN(password),
-                                   OCI_DEFAULT));
+                                   OCI_DEFAULT),
+           &cpool->base);
     cpool->pool_name = rb_str_new(TO_CHARPTR(pool_name), pool_name_len);
     rb_str_freeze(cpool->pool_name);
     return Qnil;
@@ -158,11 +159,12 @@
     Check_Type(conn_max, T_FIXNUM);
     Check_Type(conn_incr, T_FIXNUM);
 
-    oci_lc(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
+    chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
                                    &pool_name, &pool_name_len, NULL, 0, 
                                    FIX2UINT(conn_min), FIX2UINT(conn_max),
                                    FIX2UINT(conn_incr),
-                                   NULL, 0, NULL, 0, OCI_CPOOL_REINITIALIZE));
+                                   NULL, 0, NULL, 0, OCI_CPOOL_REINITIALIZE),
+           &cpool->base);
     return self;
 }
 

Modified: trunk/ruby-oci8/ext/oci8/error.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/error.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/error.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -75,7 +75,7 @@
     return rb_external_str_new_with_enc(errbuf, len, oci8_encoding);
 }
 
-VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line)
+static VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line)
 {
     VALUE exc;
     char errmsg[128];
@@ -244,7 +244,7 @@
 
     if (have_OCIMessageGet) {
         if (msghp == NULL) {
-            oci_lc(OCIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_ORATEXT("rdbms"), TO_ORATEXT("ora"), OCI_DURATION_PROCESS));
+            chkerr(OCIMessageOpen(oci8_envhp, oci8_errhp, &msghp, TO_ORATEXT("rdbms"), TO_ORATEXT("ora"), OCI_DURATION_PROCESS));
         }
         errmsg = TO_CHARPTR(OCIMessageGet(msghp, msgno, NULL, 0));
     }
@@ -270,6 +270,23 @@
     rb_exc_raise(set_backtrace(exc, file, line));
 }
 
+void oci8_check_error_(sword status, oci8_base_t *base, OCIStmt *stmthp, const char *file, int line)
+{
+    if (status != OCI_SUCCESS) {
+        VALUE exc = oci8_make_exc(oci8_errhp, status, OCI_HTYPE_ERROR, stmthp, file, line);
+        while (base != NULL) {
+            if (base->type == OCI_HTYPE_SVCCTX) {
+                rb_ivar_set(exc, oci8_id_at_last_error, exc);
+                break;
+            }
+            base = base->parent;
+        }
+        if (status != OCI_SUCCESS_WITH_INFO) {
+            rb_exc_raise(exc);
+        }
+    }
+}
+
 /*
  * Document-class: OCIException
  *

Modified: trunk/ruby-oci8/ext/oci8/lob.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/lob.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/lob.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -41,7 +41,8 @@
     lob_obj = rb_funcall(klass, oci8_id_new, 1, svcctx->base.self);
     lob = DATA_PTR(lob_obj);
     /* If 's' is a temporary lob, use OCILobLocatorAssign instead. */
-    oci_lc(OCILobAssign(oci8_envhp, oci8_errhp, s, &lob->base.hp.lob));
+    chker2(OCILobAssign(oci8_envhp, oci8_errhp, s, &lob->base.hp.lob),
+           &svcctx->base);
     return lob_obj;
 }
 
@@ -68,7 +69,7 @@
 static void oci8_assign_lob(VALUE klass, oci8_svcctx_t *svcctx, VALUE lob, OCILobLocator **dest)
 {
     oci8_base_t *base = oci8_get_handle(lob, klass);
-    oci_lc(OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, base->hp.lob, dest));
+    chker2(OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, base->hp.lob, dest), base);
 }
 
 void oci8_assign_clob(oci8_svcctx_t *svcctx, VALUE lob, OCILobLocator **dest)
@@ -124,7 +125,8 @@
     oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
     ub4 len;
 
-    oci_lc(OCILobGetLength_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len));
+    chker2(OCILobGetLength_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len),
+           &svcctx->base);
     return len;
 }
 
@@ -133,7 +135,8 @@
     if (lob->state == S_CLOSE) {
         oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
 
-        oci_lc(OCILobOpen_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, OCI_DEFAULT));
+        chker2(OCILobOpen_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, OCI_DEFAULT),
+               &svcctx->base);
         lob->state = S_OPEN;
     }
 }
@@ -143,7 +146,8 @@
     if (lob->state == S_OPEN) {
         oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
 
-        oci_lc(OCILobClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob));
+        chker2(OCILobClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob),
+               &svcctx->base);
         lob->state = S_CLOSE;
     }
 }
@@ -153,7 +157,8 @@
     if (lob->state == S_BFILE_OPEN) {
         oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
 
-        oci_lc(OCILobFileClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob));
+        chker2(OCILobFileClose_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob),
+               &svcctx->base);
         lob->state = S_BFILE_CLOSE;
     }
 }
@@ -190,7 +195,8 @@
     if (!NIL_P(val)) {
         oci8_svcctx_t *svcctx = oci8_get_svcctx(svc);
         OCI8StringValue(val);
-        oci_lc(OCILobCreateTemporary_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, 0, csfrm, lobtype, TRUE, OCI_DURATION_SESSION));
+        chker2(OCILobCreateTemporary_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, 0, csfrm, lobtype, TRUE, OCI_DURATION_SESSION),
+               &svcctx->base);
         lob->svchp = oci8_get_oci_svcctx(svc);
         oci8_lob_write(self, val);
     }
@@ -233,7 +239,8 @@
     oci8_lob_t *lob = DATA_PTR(self);
     boolean is_initialized;
 
-    oci_lc(OCILobLocatorIsInit(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_initialized));
+    chker2(OCILobLocatorIsInit(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_initialized),
+           &lob->base);
     return is_initialized ? Qtrue : Qfalse;
 }
 
@@ -294,7 +301,8 @@
     oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
 
     lob_open(lob);
-    oci_lc(OCILobTrim_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, NUM2UINT(len)));
+    chker2(OCILobTrim_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, NUM2UINT(len)),
+           &svcctx->base);
     return self;
 }
 
@@ -346,11 +354,11 @@
                         }
                     }
                 }
-                oci_lc(OCILobFileCloseAll_nb(svcctx, svcctx->base.hp.svc, oci8_errhp));
+                chker2(OCILobFileCloseAll_nb(svcctx, svcctx->base.hp.svc, oci8_errhp),
+                       &svcctx->base);
                 continue;
             }
-            if (rv != OCI_SUCCESS)
-                oci8_raise(oci8_errhp, rv, NULL);
+            chker2(rv, &svcctx->base);
             lob->state = S_BFILE_OPEN;
         }
         /* initialize buf in zeros everytime to check a nul characters. */
@@ -361,8 +369,9 @@
             if (lob->state == S_BFILE_CLOSE)
                 continue;
         }
-        if (rv != OCI_SUCCESS && rv != OCI_NEED_DATA)
-            oci8_raise(oci8_errhp, rv, NULL);
+        if (rv != OCI_SUCCESS && rv != OCI_NEED_DATA) {
+            chker2(rv, &svcctx->base);
+        }
 
         /* Workaround when using Oracle 10.2.0.4 or 11.1.0.6 client and
          * variable-length character set (e.g. AL32UTF8).
@@ -418,7 +427,8 @@
     }
     RB_GC_GUARD(data);
     amt = RSTRING_LEN(data);
-    oci_lc(OCILobWrite_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &amt, lob->pos + 1, RSTRING_PTR(data), amt, OCI_ONE_PIECE, NULL, NULL, 0, lob->csfrm));
+    chker2(OCILobWrite_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &amt, lob->pos + 1, RSTRING_PTR(data), amt, OCI_ONE_PIECE, NULL, NULL, 0, lob->csfrm),
+           &svcctx->base);
     lob->pos += amt;
     return UINT2NUM(amt);
 }
@@ -455,7 +465,8 @@
     oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
     ub4 len;
 
-    oci_lc(OCILobGetChunkSize_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len));
+    chker2(OCILobGetChunkSize_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &len),
+           &svcctx->base);
     return UINT2NUM(len);
 }
 
@@ -464,7 +475,6 @@
     oci8_lob_t *lob = DATA_PTR(self);
     oci8_lob_t *newlob;
     VALUE newobj;
-    sword rv;
     boolean is_temporary;
 
     newobj = rb_funcall(CLASS_OF(self), oci8_id_new, 1, lob->svc);
@@ -472,13 +482,11 @@
     if (OCILobIsTemporary(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_temporary) == OCI_SUCCESS
         && is_temporary) {
         oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
-        rv = OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob);
+        chker2(OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob),
+               &svcctx->base);
     } else {
-        rv = OCILobAssign(oci8_envhp, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob);
+        chker2(OCILobAssign(oci8_envhp, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob), &lob->base);
     }
-    if (rv != OCI_SUCCESS) {
-        oci8_raise(oci8_errhp, rv, NULL);
-    }
     return newobj;
 }
 
@@ -504,7 +512,8 @@
         VALUE dir_alias;
         VALUE filename;
 
-        oci_lc(OCILobFileGetName(oci8_envhp, oci8_errhp, lob->base.hp.lob, TO_ORATEXT(d_buf), &d_length, TO_ORATEXT(f_buf), &f_length));
+        chker2(OCILobFileGetName(oci8_envhp, oci8_errhp, lob->base.hp.lob, TO_ORATEXT(d_buf), &d_length, TO_ORATEXT(f_buf), &f_length),
+               &lob->base);
         dir_alias = rb_external_str_new_with_enc(d_buf, d_length, oci8_encoding);
         filename = rb_external_str_new_with_enc(f_buf, f_length, oci8_encoding);
         rb_ivar_set(self, id_dir_alias, dir_alias);
@@ -529,9 +538,10 @@
     if (RSTRING_LEN(filename) > UB2MAXVAL) {
         rb_raise(rb_eRuntimeError, "filename is too long.");
     }
-    oci_lc(OCILobFileSetName(oci8_envhp, oci8_errhp, &lob->base.hp.lob,
+    chker2(OCILobFileSetName(oci8_envhp, oci8_errhp, &lob->base.hp.lob,
                              RSTRING_ORATEXT(dir_alias), (ub2)RSTRING_LEN(dir_alias),
-                             RSTRING_ORATEXT(filename), (ub2)RSTRING_LEN(filename)));
+                             RSTRING_ORATEXT(filename), (ub2)RSTRING_LEN(filename)),
+           &lob->base);
 }
 
 static VALUE oci8_bfile_initialize(int argc, VALUE *argv, VALUE self)
@@ -540,10 +550,14 @@
     VALUE svc;
     VALUE dir_alias;
     VALUE filename;
+    int rv;
 
     rb_scan_args(argc, argv, "12", &svc, &dir_alias, &filename);
     TO_SVCCTX(svc); /* check argument type */
-    oci_lc(OCIDescriptorAlloc(oci8_envhp, &lob->base.hp.ptr, OCI_DTYPE_LOB, 0, NULL));
+    rv = OCIDescriptorAlloc(oci8_envhp, &lob->base.hp.ptr, OCI_DTYPE_LOB, 0, NULL);
+    if (rv != OCI_SUCCESS) {
+        oci8_env_raise(oci8_envhp, rv);
+    }
     lob->base.type = OCI_DTYPE_LOB;
     lob->svc = svc;
     lob->pos = 0;
@@ -604,7 +618,8 @@
     oci8_svcctx_t *svcctx = oci8_get_svcctx(lob->svc);
     boolean flag;
 
-    oci_lc(OCILobFileExists_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &flag));
+    chker2(OCILobFileExists_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &flag),
+           &svcctx->base);
     return flag ? Qtrue : Qfalse;
 }
 
@@ -664,7 +679,8 @@
 {
     ub1 csfrm = SQLCS_NCHAR;
 
-    oci_lc(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp));
+    chker2(OCIAttrSet(obind->base.hp.ptr, obind->base.type, (void*)&csfrm, 0, OCI_ATTR_CHARSET_FORM, oci8_errhp),
+           &obind->base);
 }
 
 static const oci8_bind_lob_vtable_t bind_clob_vtable = {

Modified: trunk/ruby-oci8/ext/oci8/metadata.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/metadata.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/metadata.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -40,7 +40,7 @@
 
     p = oci8_get_handle(parent, oci8_cOCIHandle);
 
-    oci_lc(OCIAttrGet(parmhp, OCI_DTYPE_PARAM, &ptype, &size, OCI_ATTR_PTYPE, oci8_errhp));
+    chker2(OCIAttrGet(parmhp, OCI_DTYPE_PARAM, &ptype, &size, OCI_ATTR_PTYPE, oci8_errhp), p);
     klass = rb_hash_aref(ptype_to_class, INT2FIX(ptype));
     if (NIL_P(klass))
         rb_raise(rb_eRuntimeError, "unknown parameter type %d", ptype);
@@ -88,7 +88,8 @@
 
     Check_Type(idx, T_FIXNUM);
     /* Is it remote call? */
-    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &value, &size, FIX2INT(idx), oci8_errhp));
+    chker2(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &value, &size, FIX2INT(idx), oci8_errhp),
+           &svcctx->base);
     if (size != sizeof(OCIParam *)) {
         rb_raise(rb_eRuntimeError, "Invalid attribute size. expect %d, but %d", (sb4)sizeof(OCIParam *), size);
     }
@@ -103,7 +104,8 @@
     oci8_metadata_t *md = DATA_PTR(self);
     OCIParam *value;
 
-    oci_lc(OCIParamGet(md->base.hp.ptr, md->base.type, oci8_errhp, (dvoid *)&value, FIX2INT(idx)));
+    chker2(OCIParamGet(md->base.hp.ptr, md->base.type, oci8_errhp, (dvoid *)&value, FIX2INT(idx)),
+           &md->base);
     return oci8_metadata_create(value, md->svc, self);
 }
 
@@ -133,22 +135,29 @@
     VALUE type;
     VALUE obj;
     oci8_base_t *desc;
+    int rv;
 
     /* make a describe handle object */
     obj = rb_obj_alloc(oci8_cOCIHandle);
     desc = DATA_PTR(obj);
-    oci_lc(OCIHandleAlloc(oci8_envhp, (dvoid *)&desc->hp.dschp, OCI_HTYPE_DESCRIBE, 0, 0));
+    rv = OCIHandleAlloc(oci8_envhp, (dvoid *)&desc->hp.dschp, OCI_HTYPE_DESCRIBE, 0, 0);
+    if (rv != OCI_SUCCESS) {
+        oci8_env_raise(oci8_envhp, rv);
+    }
     desc->type = OCI_HTYPE_DESCRIBE;
 
     type = rb_hash_aref(class_to_ptype, klass);
     if (RTEST(check_public)) {
         sb4 val = -1;
         /* size of OCI_ATTR_DESC_PUBLIC is undocumented. */
-        oci_lc(OCIAttrSet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &val, 0, OCI_ATTR_DESC_PUBLIC, oci8_errhp));
+        chker2(OCIAttrSet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &val, 0, OCI_ATTR_DESC_PUBLIC, oci8_errhp),
+               &svcctx->base);
     }
-    oci_lc(OCIDescribeAny_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, objptr, objlen,
-                             objtype, OCI_DEFAULT, (ub1)FIX2INT(type), desc->hp.dschp));
-    oci_lc(OCIAttrGet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &parmhp, 0, OCI_ATTR_PARAM, oci8_errhp));
+    chker2(OCIDescribeAny_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, objptr, objlen,
+                             objtype, OCI_DEFAULT, (ub1)FIX2INT(type), desc->hp.dschp),
+           &svcctx->base);
+    chker2(OCIAttrGet(desc->hp.dschp, OCI_HTYPE_DESCRIBE, &parmhp, 0, OCI_ATTR_PARAM, oci8_errhp),
+           &svcctx->base);
     return oci8_metadata_create(parmhp, self, obj);
 }
 
@@ -168,7 +177,8 @@
     OCIRef *ref = NULL;
 
     /* remote call */
-    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp));
+    chker2(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp),
+           &svcctx->base);
     return oci8_do_describe(md->svc, ref, 0, OCI_OTYPE_REF, klass, Qfalse);
 }
 
@@ -179,11 +189,14 @@
     OCIRef *tdo_ref = NULL;
     void *tdo;
 
-    oci_lc(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp));
+    chker2(OCIAttrGet_nb(svcctx, md->base.hp.ptr, md->base.type, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp),
+           &svcctx->base);
     if (tdo_ref == NULL)
         return Qnil;
-    oci_lc(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo));
-    oci_lc(OCIObjectUnpin(oci8_envhp, oci8_errhp, tdo));
+    chker2(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo),
+           &svcctx->base);
+    chker2(OCIObjectUnpin(oci8_envhp, oci8_errhp, tdo),
+           &svcctx->base);
 #if SIZEOF_LONG == SIZEOF_VOIDP
     return ((VALUE)tdo | (VALUE)1);
 #else

Modified: trunk/ruby-oci8/ext/oci8/object.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/object.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/object.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -80,10 +80,12 @@
         OCIObjectUnpin(oci8_envhp, oci8_errhp, tdo->hp.tdo);
         tdo->hp.tdo = NULL;
     }
-    oci_lc(OCIAttrGet(md->hp.ptr, OCI_DTYPE_PARAM, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp));
+    chker2(OCIAttrGet(md->hp.ptr, OCI_DTYPE_PARAM, &tdo_ref, NULL, OCI_ATTR_REF_TDO, oci8_errhp),
+           &svcctx->base);
     if (tdo_ref == NULL)
         return Qnil;
-    oci_lc(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo->hp.ptr));
+    chker2(OCIObjectPin_nb(svcctx, oci8_envhp, oci8_errhp, tdo_ref, 0, OCI_PIN_ANY, OCI_DURATION_SESSION, OCI_LOCK_NONE, &tdo->hp.ptr),
+           &svcctx->base);
     oci8_link_to_parent(tdo, &svcctx->base);
     return self;
 }
@@ -233,11 +235,11 @@
     if (*ind) {
         return Qnil;
     }
-    oci_lc(OCICollSize(oci8_envhp, oci8_errhp, coll, &size));
+    chker2(OCICollSize(oci8_envhp, oci8_errhp, coll, &size), &obj->base);
     ary = rb_ary_new2(size);
     for (idx = 0; idx < size; idx++) {
         boolean exists;
-        oci_lc(OCICollGetElem(oci8_envhp, oci8_errhp, coll, idx, &exists, &data, (dvoid**)&ind));
+        chker2(OCICollGetElem(oci8_envhp, oci8_errhp, coll, idx, &exists, &data, (dvoid**)&ind), &obj->base);
         if (exists) {
             void *tmp;
             if (datatype == INT2FIX(ATTR_NAMED_COLLECTION)) {
@@ -330,11 +332,13 @@
     cb_data.coll = (OCIColl*)*obj->instancep;
     switch (FIX2INT(datatype)) {
     case ATTR_STRING:
-        oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_VARCHAR2, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr));
+        chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_VARCHAR2, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr),
+               svcctx);
         cb_data.indp = &cb_data.ind;
         break;
     case ATTR_RAW:
-        oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_RAW, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr));
+        chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_RAW, NULL, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr),
+               svcctx);
         cb_data.indp = &cb_data.ind;
         break;
     case ATTR_OCINUMBER:
@@ -357,14 +361,18 @@
     case ATTR_NAMED_TYPE:
         Check_Object(typeinfo, cOCI8TDO);
         tdo = DATA_PTR(typeinfo);
-        oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_OBJECT, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr));
-        oci_lc(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp));
+        chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_OBJECT, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr),
+               svcctx);
+        chker2(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp),
+               svcctx);
         break;
     case ATTR_NAMED_COLLECTION:
         Check_Object(typeinfo, cOCI8TDO);
         tdo = DATA_PTR(typeinfo);
-        oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_NAMEDCOLLECTION, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr));
-        oci_lc(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp));
+        chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->hp.svc, OCI_TYPECODE_NAMEDCOLLECTION, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, &cb_data.data.ptr),
+               svcctx);
+        chker2(OCIObjectGetInd(oci8_envhp, oci8_errhp, cb_data.data.ptr, (dvoid**)&cb_data.indp),
+               svcctx);
         break;
     case ATTR_CLOB:
     case ATTR_NCLOB:
@@ -395,9 +403,9 @@
     sb4 idx;
     void *elem_ptr;
 
-    oci_lc(OCICollSize(oci8_envhp, oci8_errhp, coll, &size));
+    chkerr(OCICollSize(oci8_envhp, oci8_errhp, coll, &size));
     if (RARRAY_LEN(val) < size) {
-        oci_lc(OCICollTrim(oci8_envhp, oci8_errhp, size - RARRAY_LEN(val), coll));
+        chkerr(OCICollTrim(oci8_envhp, oci8_errhp, size - RARRAY_LEN(val), coll));
     }
     for (idx = 0; idx < RARRAY_LEN(val); idx++) {
         switch (FIX2INT(datatype)) {
@@ -422,9 +430,9 @@
             break;
         }
         if (idx < size) {
-            oci_lc(OCICollAssignElem(oci8_envhp, oci8_errhp, idx, elem_ptr, cb_data->indp, cb_data->coll));
+            chkerr(OCICollAssignElem(oci8_envhp, oci8_errhp, idx, elem_ptr, cb_data->indp, cb_data->coll));
         } else {
-            oci_lc(OCICollAppend(oci8_envhp, oci8_errhp, elem_ptr, cb_data->indp, coll));
+            chkerr(OCICollAppend(oci8_envhp, oci8_errhp, elem_ptr, cb_data->indp, coll));
         }
     }
     return Qnil;
@@ -468,13 +476,13 @@
     switch (FIX2INT(datatype)) {
     case ATTR_STRING:
         OCI8StringValue(val);
-        oci_lc(OCIStringAssignText(oci8_envhp, oci8_errhp,
+        chkerr(OCIStringAssignText(oci8_envhp, oci8_errhp,
                                    RSTRING_ORATEXT(val), RSTRING_LEN(val),
                                    (OCIString **)data));
         break;
     case ATTR_RAW:
         StringValue(val);
-        oci_lc(OCIRawAssignBytes(oci8_envhp, oci8_errhp,
+        chkerr(OCIRawAssignBytes(oci8_envhp, oci8_errhp,
                                  RSTRING_ORATEXT(val), RSTRING_LEN(val),
                                  (OCIRaw **)data));
         break;
@@ -624,8 +632,10 @@
         obj->null_structp = (char**)&obind->u.null_structs[idx];
         oci8_link_to_parent(&obj->base, &obind->base);
 
-        oci_lc(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->base.hp.svc, tc, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, (dvoid**)obj->instancep));
-        oci_lc(OCIObjectGetInd(oci8_envhp, oci8_errhp, (dvoid*)*obj->instancep, (dvoid**)obj->null_structp));
+        chker2(OCIObjectNew(oci8_envhp, oci8_errhp, svcctx->base.hp.svc, tc, tdo->hp.tdo, NULL, OCI_DURATION_SESSION, TRUE, (dvoid**)obj->instancep),
+               &svcctx->base);
+        chker2(OCIObjectGetInd(oci8_envhp, oci8_errhp, (dvoid*)*obj->instancep, (dvoid**)obj->null_structp),
+               &svcctx->base);
         *(OCIInd*)*obj->null_structp = -1;
     } while (++idx < obind->maxar_sz);
 }
@@ -635,12 +645,14 @@
     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));
+        chker2(OCIDefineObject(obind->base.hp.dfn, oci8_errhp, tdo->hp.tdo,
+                               obind->valuep, 0, obind->u.null_structs, 0),
+               &obind->base);
         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));
+        chker2(OCIBindObject(obind->base.hp.bnd, oci8_errhp, tdo->hp.tdo,
+                             obind->valuep, 0, obind->u.null_structs, 0),
+               &obind->base);
         break;
     }
 }

Modified: trunk/ruby-oci8/ext/oci8/oci8.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/oci8.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -358,20 +358,23 @@
     }
 
     /* logon */
-    oci_lc(OCILogon_nb(svcctx, oci8_envhp, oci8_errhp, &svcctx->base.hp.svc,
+    chker2(OCILogon_nb(svcctx, oci8_envhp, oci8_errhp, &svcctx->base.hp.svc,
                        RSTRING_ORATEXT(username), RSTRING_LEN(username),
                        RSTRING_ORATEXT(password), RSTRING_LEN(password),
                        NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname),
-                       NIL_P(dbname) ? 0 : RSTRING_LEN(dbname)));
+                       NIL_P(dbname) ? 0 : RSTRING_LEN(dbname)),
+           &svcctx->base);
     svcctx->base.type = OCI_HTYPE_SVCCTX;
     svcctx->logoff_strategy = &simple_logoff;
 
     /* setup the session handle */
-    oci_lc(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->usrhp, 0, OCI_ATTR_SESSION, oci8_errhp));
+    chker2(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->usrhp, 0, OCI_ATTR_SESSION, oci8_errhp),
+           &svcctx->base);
     copy_session_handle(svcctx);
 
     /* setup the server handle */
-    oci_lc(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->srvhp, 0, OCI_ATTR_SERVER, oci8_errhp));
+    chker2(OCIAttrGet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX, &svcctx->srvhp, 0, OCI_ATTR_SERVER, oci8_errhp),
+           &svcctx->base);
     copy_server_handle(svcctx);
 
     return Qnil;
@@ -469,13 +472,15 @@
     Check_Type(mode, T_FIXNUM);
 
     /* attach to the server */
-    oci_lc(OCIServerAttach_nb(svcctx, svcctx->srvhp, oci8_errhp,
+    chker2(OCIServerAttach_nb(svcctx, svcctx->srvhp, oci8_errhp,
                               NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname),
                               NIL_P(dbname) ? 0 : RSTRING_LEN(dbname),
-                              FIX2UINT(mode)));
-    oci_lc(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX,
+                              FIX2UINT(mode)),
+           &svcctx->base);
+    chker2(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX,
                       svcctx->srvhp, 0, OCI_ATTR_SERVER,
-                      oci8_errhp));
+                      oci8_errhp),
+           &svcctx->base);
     svcctx->state |= OCI8_STATE_SERVER_ATTACH_WAS_CALLED;
     return self;
 }
@@ -504,12 +509,14 @@
     Check_Type(mode, T_FIXNUM);
 
     /* begin session */
-    oci_lc(OCISessionBegin_nb(svcctx, svcctx->base.hp.ptr, oci8_errhp,
+    chker2(OCISessionBegin_nb(svcctx, svcctx->base.hp.ptr, oci8_errhp,
                               svcctx->usrhp, FIX2UINT(cred),
-                              FIX2UINT(mode)));
-    oci_lc(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX,
+                              FIX2UINT(mode)),
+           &svcctx->base);
+    chker2(OCIAttrSet(svcctx->base.hp.ptr, OCI_HTYPE_SVCCTX,
                       svcctx->usrhp, 0, OCI_ATTR_SESSION,
-                      oci8_errhp));
+                      oci8_errhp),
+           &svcctx->base);
     svcctx->state |= OCI8_STATE_SESSION_BEGIN_WAS_CALLED;
     return Qnil;
 }
@@ -533,7 +540,7 @@
         void *data = strategy->prepare(svcctx);
         svcctx->base.type = 0;
         svcctx->logoff_strategy = NULL;
-        oci_lc(oci8_blocking_region(svcctx, strategy->execute, data));
+        chker2(oci8_blocking_region(svcctx, strategy->execute, data), &svcctx->base);
     }
     return Qtrue;
 }
@@ -563,7 +570,7 @@
 static VALUE oci8_commit(VALUE self)
 {
     oci8_svcctx_t *svcctx = DATA_PTR(self);
-    oci_lc(OCITransCommit_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT));
+    chker2(OCITransCommit_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT), &svcctx->base);
     return self;
 }
 
@@ -576,7 +583,7 @@
 static VALUE oci8_rollback(VALUE self)
 {
     oci8_svcctx_t *svcctx = DATA_PTR(self);
-    oci_lc(OCITransRollback_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT));
+    chker2(OCITransRollback_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, OCI_DEFAULT), &svcctx->base);
     return self;
 }
 
@@ -597,7 +604,7 @@
 #else
     sb1 non_blocking;
 
-    oci_lc(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp));
+    chker2(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp), &svcctx->base);
     return non_blocking ? Qtrue : Qfalse;
 #endif
 }
@@ -647,10 +654,10 @@
 #else
     sb1 non_blocking;
 
-    oci_lc(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp));
+    chker2(OCIAttrGet(svcctx->srvhp, OCI_HTYPE_SERVER, &non_blocking, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp), &svcctx->base);
     if ((RTEST(val) && !non_blocking) || (!RTEST(val) && non_blocking)) {
         /* toggle blocking / non-blocking. */
-        oci_lc(OCIAttrSet(svcctx->srvhp, OCI_HTYPE_SERVER, 0, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp));
+        chker2(OCIAttrSet(svcctx->srvhp, OCI_HTYPE_SERVER, 0, 0, OCI_ATTR_NONBLOCKING_MODE, oci8_errhp), &svcctx->base);
     }
 #endif
     return val;
@@ -729,17 +736,12 @@
 static VALUE oci8_break(VALUE self)
 {
     oci8_svcctx_t *svcctx = DATA_PTR(self);
-#ifndef HAVE_RB_THREAD_BLOCKING_REGION
-    sword rv;
-#endif
 
     if (NIL_P(svcctx->executing_thread)) {
         return Qfalse;
     }
 #ifndef HAVE_RB_THREAD_BLOCKING_REGION
-    rv = OCIBreak(svcctx->base.hp.ptr, oci8_errhp);
-    if (rv != OCI_SUCCESS)
-        oci8_raise(oci8_errhp, rv, NULL);
+    chker2(OCIBreak(svcctx->base.hp.ptr, oci8_errhp), &svcctx->base);
 #endif
     rb_thread_wakeup(svcctx->executing_thread);
     return Qtrue;
@@ -777,9 +779,8 @@
     oci8_svcctx_t *svcctx = DATA_PTR(self);
     char buf[100];
     ub4 version;
-    char *p;
 
-    oci_lc(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version));
+    chker2(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version), &svcctx->base);
     return UINT2NUM(version);
 }
 
@@ -862,8 +863,9 @@
         if (size > 0 && ptr[0] == ':') {
             rb_raise(rb_eArgError, "client identifier should not start with ':'.");
         }
-        oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
-                          size, OCI_ATTR_CLIENT_IDENTIFIER, oci8_errhp));
+        chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
+                          size, OCI_ATTR_CLIENT_IDENTIFIER, oci8_errhp),
+               DATA_PTR(self));
     } else {
         /* Workaround for Bug 2449486 */
         oci8_exec_sql_var_t bind_vars[1];
@@ -932,8 +934,9 @@
     }
     if (oracle_client_version >= ORAVER_10_1) {
         /* Oracle 10g or upper */
-        oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
-                          size, OCI_ATTR_MODULE, oci8_errhp));
+        chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
+                          size, OCI_ATTR_MODULE, oci8_errhp),
+               DATA_PTR(self));
     } else {
         /* Oracle 9i or lower */
         oci8_exec_sql_var_t bind_vars[1];
@@ -1001,8 +1004,9 @@
     }
     if (oracle_client_version >= ORAVER_10_1) {
         /* Oracle 10g or upper */
-        oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
-                          size, OCI_ATTR_ACTION, oci8_errhp));
+        chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
+                          size, OCI_ATTR_ACTION, oci8_errhp),
+               DATA_PTR(self));
     } else {
         /* Oracle 9i or lower */
         oci8_exec_sql_var_t bind_vars[1];
@@ -1063,8 +1067,9 @@
     }
     if (oracle_client_version >= ORAVER_10_1) {
         /* Oracle 10g or upper */
-        oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
-                          size, OCI_ATTR_CLIENT_INFO, oci8_errhp));
+        chker2(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr,
+                          size, OCI_ATTR_CLIENT_INFO, oci8_errhp),
+               DATA_PTR(self));
     } else {
         /* Oracle 9i or lower */
         oci8_exec_sql_var_t bind_vars[1];
@@ -1137,6 +1142,7 @@
     rb_define_method(cOCI8, "module=", oci8_set_module, 1);
     rb_define_method(cOCI8, "action=", oci8_set_action, 1);
     rb_define_method(cOCI8, "client_info=", oci8_set_client_info, 1);
+    rb_define_attr(cOCI8, "last_error", 1, 1);
     return cOCI8;
 }
 

Modified: trunk/ruby-oci8/ext/oci8/oci8.h
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.h	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/oci8.h	2011-10-22 13:32:49 UTC (rev 459)
@@ -371,13 +371,9 @@
 #define oci8_raise_init_error() oci8_do_raise_init_error(__FILE__, __LINE__)
 #define oci8_raise_by_msgno(msgno, default_msg) oci8_do_raise_by_msgno(msgno, default_msg, __FILE__, __LINE__)
 
-/* raise on error */
-#define oci_lc(rv) do { \
-    sword __rv = (rv); \
-    if (__rv != OCI_SUCCESS) { \
-        oci8_raise(oci8_errhp, __rv, NULL); \
-    } \
-} while(0)
+#define chkerr(status) oci8_check_error_((status), NULL, NULL, __FILE__, __LINE__)
+#define chker2(status, base) oci8_check_error_((status), (base), NULL, __FILE__, __LINE__)
+#define chker3(status, base, stmt) oci8_check_error_((status), (base), (stmt), __FILE__, __LINE__)
 
 #if SIZEOF_LONG > 4
 #define UB4_TO_NUM INT2FIX
@@ -419,6 +415,7 @@
 void Init_oci8_env(void);
 
 /* oci8lib.c */
+extern ID oci8_id_at_last_error;
 extern ID oci8_id_new;
 extern ID oci8_id_get;
 extern ID oci8_id_set;
@@ -453,14 +450,13 @@
 /* error.c */
 extern VALUE eOCIException;
 extern VALUE eOCIBreak;
-VALUE oci8_make_exc(dvoid *errhp, sword status, ub4 type, OCIStmt *stmthp, const char *file, int line);
 void Init_oci8_error(void);
-NORETURN(void oci8_do_raise(OCIError *, sword status, OCIStmt *, const char *file, int line));
 NORETURN(void oci8_do_env_raise(OCIEnv *, sword status, const char *file, int line));
 NORETURN(void oci8_do_raise_init_error(const char *file, int line));
 sb4 oci8_get_error_code(OCIError *errhp);
 VALUE oci8_get_error_message(ub4 msgno, const char *default_msg);
 NORETURN(void oci8_do_raise_by_msgno(ub4 msgno, const char *default_msg, const char *file, int line));
+void oci8_check_error_(sword status, oci8_base_t *base, OCIStmt *stmthp, const char *file, int line);
 
 /* ocihandle.c */
 void Init_oci8_handle(void);
@@ -538,12 +534,12 @@
 void Init_oci_object(VALUE mOCI);
 
 /* attr.c */
-VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype);
-VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype);
-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);
+VALUE oci8_get_sb1_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp);
+VALUE oci8_get_ub2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp);
+VALUE oci8_get_sb2_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp);
+VALUE oci8_get_ub4_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp);
+VALUE oci8_get_string_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp);
+VALUE oci8_get_rowid_attr(oci8_base_t *base, ub4 attrtype, OCIStmt *stmtp);
 
 /* encoding.c */
 void Init_oci8_encoding(VALUE cOCI8);

Modified: trunk/ruby-oci8/ext/oci8/oci8lib.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8lib.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/oci8lib.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -10,6 +10,7 @@
 #include <signal.h>
 #endif
 
+ID oci8_id_at_last_error;
 ID oci8_id_new;
 ID oci8_id_get;
 ID oci8_id_set;
@@ -75,6 +76,7 @@
     }
 #endif
 
+    oci8_id_at_last_error = rb_intern("@last_error");
     oci8_id_new = rb_intern("new");
     oci8_id_get = rb_intern("get");
     oci8_id_set = rb_intern("set");
@@ -361,23 +363,26 @@
     if (rv != OCI_SUCCESS) {
         oci8_env_raise(oci8_envhp, rv);
     }
-    oci_lc(OCIStmtPrepare(arg->stmtp, oci8_errhp, (text*)arg->sql_text,
-                          strlen(arg->sql_text), OCI_NTV_SYNTAX, OCI_DEFAULT));
+    chker2(OCIStmtPrepare(arg->stmtp, oci8_errhp, (text*)arg->sql_text,
+                          strlen(arg->sql_text), OCI_NTV_SYNTAX, OCI_DEFAULT),
+           &arg->svcctx->base);
     for (pos = 0; pos < arg->num_define_vars; pos++) {
         arg->define_vars[pos].hp = NULL;
-        oci_lc(OCIDefineByPos(arg->stmtp, (OCIDefine**)&arg->define_vars[pos].hp,
+        chker3(OCIDefineByPos(arg->stmtp, (OCIDefine**)&arg->define_vars[pos].hp,
                               oci8_errhp, pos + 1, arg->define_vars[pos].valuep,
                               arg->define_vars[pos].value_sz,
                               arg->define_vars[pos].dty, arg->define_vars[pos].indp,
-                              arg->define_vars[pos].alenp, NULL, OCI_DEFAULT));
+                              arg->define_vars[pos].alenp, NULL, OCI_DEFAULT),
+               &arg->svcctx->base, arg->stmtp);
     }
     for (pos = 0; pos < arg->num_bind_vars; pos++) {
         arg->bind_vars[pos].hp = NULL;
-        oci_lc(OCIBindByPos(arg->stmtp, (OCIBind**)&arg->bind_vars[pos].hp,
+        chker3(OCIBindByPos(arg->stmtp, (OCIBind**)&arg->bind_vars[pos].hp,
                             oci8_errhp, pos + 1, arg->bind_vars[pos].valuep,
                             arg->bind_vars[pos].value_sz, arg->bind_vars[pos].dty,
                             arg->bind_vars[pos].indp, arg->bind_vars[pos].alenp,
-                            NULL, 0, NULL, OCI_DEFAULT));
+                            NULL, 0, NULL, OCI_DEFAULT),
+               &arg->svcctx->base, arg->stmtp);
     }
     rv = OCIStmtExecute_nb(arg->svcctx, arg->svcctx->base.hp.svc, arg->stmtp, oci8_errhp, 1, 0, NULL, NULL, OCI_DEFAULT);
     if (rv == OCI_ERROR) {
@@ -390,7 +395,7 @@
         }
     }
     if (arg->raise_on_error) {
-        oci_lc(rv);
+        chker3(rv, &arg->svcctx->base, arg->stmtp);
     }
     return (VALUE)rv;
 }

Modified: trunk/ruby-oci8/ext/oci8/ocidatetime.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocidatetime.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/ocidatetime.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -113,10 +113,10 @@
     sb1 tz_hour;
     sb1 tz_minute;
 
-    oci_lc(OCIDateTimeGetDate(oci8_envhp, oci8_errhp, dttm, &year, &month, &day));
-    oci_lc(OCIDateTimeGetTime(oci8_envhp, oci8_errhp, dttm, &hour, &minute, &sec, &fsec));
+    chkerr(OCIDateTimeGetDate(oci8_envhp, oci8_errhp, dttm, &year, &month, &day));
+    chkerr(OCIDateTimeGetTime(oci8_envhp, oci8_errhp, dttm, &hour, &minute, &sec, &fsec));
     if (have_tz) {
-        oci_lc(OCIDateTimeGetTimeZoneOffset(oci8_envhp, oci8_errhp, dttm, &tz_hour, &tz_minute));
+        chkerr(OCIDateTimeGetTimeZoneOffset(oci8_envhp, oci8_errhp, dttm, &tz_hour, &tz_minute));
     }
     return rb_ary_new3(9,
                        INT2FIX(year),
@@ -200,7 +200,7 @@
         tzlen = strlen(tz_str);
     }
     /* construct */
-    oci_lc(OCIDateTimeConstruct(seshp ? (void*)seshp : (void*)oci8_envhp, oci8_errhp, dttm,
+    chkerr(OCIDateTimeConstruct(seshp ? (void*)seshp : (void*)oci8_envhp, oci8_errhp, dttm,
                                 (sb2)year,
                                 (ub1)month,
                                 (ub1)day,
@@ -307,7 +307,7 @@
     sb4 year;
     sb4 month;
 
-    oci_lc(OCIIntervalGetYearMonth(oci8_envhp, oci8_errhp, &year, &month, s));
+    chkerr(OCIIntervalGetYearMonth(oci8_envhp, oci8_errhp, &year, &month, s));
     return rb_ary_new3(2, INT2FIX(year), INT2FIX(month));
 }
 
@@ -323,7 +323,7 @@
     year = NUM2INT(RARRAY_PTR(val)[0]);
     month = NUM2INT(RARRAY_PTR(val)[1]);
     if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) {
-        oci_lc(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp,
+        chkerr(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp,
                                        year, month, intvl));
     } else {
         /* Workaround for Bug 2227982 */
@@ -340,7 +340,7 @@
             month = -month;
         }
         sprintf(buf, "%s%d-%d", sign, year, month);
-        oci_lc(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl));
+        chkerr(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl));
     }
     return intvl;
 }
@@ -353,7 +353,7 @@
     sb4 sec;
     sb4 fsec;
 
-    oci_lc(OCIIntervalGetDaySecond(oci8_envhp, oci8_errhp, &day, &hour, &minute, &sec, &fsec, s));
+    chkerr(OCIIntervalGetDaySecond(oci8_envhp, oci8_errhp, &day, &hour, &minute, &sec, &fsec, s));
     return rb_ary_new3(5,
                        INT2FIX(day), INT2FIX(hour),
                        INT2FIX(minute), INT2FIX(sec),
@@ -378,7 +378,7 @@
     sec = NUM2INT(RARRAY_PTR(val)[3]);
     fsec = NUM2INT(RARRAY_PTR(val)[4]);
     if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) {
-        oci_lc(OCIIntervalSetDaySecond(oci8_envhp, oci8_errhp,
+        chkerr(OCIIntervalSetDaySecond(oci8_envhp, oci8_errhp,
                                        day, hour, minute, sec, fsec, intvl));
     } else {
         /* Workaround for Bug 2227982 */
@@ -401,7 +401,7 @@
             }
         }
         sprintf(buf, "%s%d %02d:%02d:%02d.%09d", sign, day, hour, minute, sec, fsec);
-        oci_lc(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl));
+        chkerr(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl));
     }
     return intvl;
 }

Modified: trunk/ruby-oci8/ext/oci8/ocihandle.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocihandle.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/ocihandle.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -123,7 +123,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return INT2FIX(v.value);
 }
 
@@ -145,7 +145,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return INT2FIX(v.value);
 }
 
@@ -167,7 +167,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return UINT2NUM(v.value);
 }
 
@@ -189,7 +189,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return ULL2NUM(v.value);
 }
 
@@ -211,7 +211,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return INT2FIX(v.value);
 }
 
@@ -233,7 +233,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return INT2FIX(v.value);
 }
 
@@ -255,7 +255,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return INT2NUM(v.value);
 }
 
@@ -277,7 +277,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return LL2NUM(v.value);
 }
 
@@ -299,7 +299,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, NULL, FIX2INT(attr_type), oci8_errhp), base);
     return v.value ? Qtrue : Qfalse;
 }
 
@@ -327,7 +327,7 @@
 
     v.dummy = MAGIC_NUMBER;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
     return rb_external_str_new_with_enc(v.value, size, oci8_encoding);
 }
 
@@ -354,7 +354,7 @@
 
     v.dummy = 0;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
     return rb_tainted_str_new(v.value, size);
 }
 
@@ -381,7 +381,7 @@
 
     v.dummy = 0;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
     return oci8_make_integer(v.value, oci8_errhp);
 }
 
@@ -409,7 +409,7 @@
 
     v.dummy = 0;
     Check_Type(attr_type, T_FIXNUM);
-    oci_lc(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrGet(base->hp.ptr, base->type, &v.value, &size, FIX2INT(attr_type), oci8_errhp), base);
     if (NIL_P(cOraDate))
         cOraDate = rb_eval_string("OraDate");
     return rb_funcall(cOraDate, oci8_id_new, 6,
@@ -441,7 +441,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = (ub1)check_data_range(val, 0, UCHAR_MAX, "ub1");
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -465,7 +465,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = (ub2)check_data_range(val, 0, USHRT_MAX, "ub2");
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -489,7 +489,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = NUM2UINT(val);
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -513,7 +513,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = NUM2ULL(val);
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -537,7 +537,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = (sb1)check_data_range(val, CHAR_MIN, CHAR_MAX, "sb1");
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -561,7 +561,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = (sb2)check_data_range(val, SHRT_MIN, SHRT_MAX, "sb2");
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -585,7 +585,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = NUM2INT(val);
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -609,7 +609,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = NUM2LL(val);
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -633,7 +633,7 @@
     Check_Type(attr_type, T_FIXNUM);
     value = RTEST(val) ? TRUE : FALSE;
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -655,7 +655,7 @@
     Check_Type(attr_type, T_FIXNUM);
     OCI8SafeStringValue(val);
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -675,7 +675,7 @@
     Check_Type(attr_type, T_FIXNUM);
     SafeStringValue(val);
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, RSTRING_PTR(val), RSTRING_LEN(val), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 
@@ -698,7 +698,7 @@
     Check_Type(attr_type, T_FIXNUM);
     oci8_set_integer(&value, val, oci8_errhp);
     /* set attribute */
-    oci_lc(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp));
+    chker2(OCIAttrSet(base->hp.ptr, base->type, &value, sizeof(value), FIX2INT(attr_type), oci8_errhp), base);
     return self;
 }
 

Modified: trunk/ruby-oci8/ext/oci8/ocinumber.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/ocinumber.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/ocinumber.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -119,7 +119,7 @@
     OCINumber *d;
 
     obj = Data_Make_Struct(cOCINumber, OCINumber, NULL, xfree, d);
-    oci_lc(OCINumberAssign(errhp, s, d));
+    chkerr(OCINumberAssign(errhp, s, d));
     return obj;
 }
 
@@ -184,7 +184,7 @@
         nls_params_ptr = RSTRING_ORATEXT(nls_params);
         nls_params_len = RSTRING_LEN(nls_params);
     }
-    oci_lc(OCINumberFromText(errhp,
+    chkerr(OCINumberFromText(errhp,
                              RSTRING_ORATEXT(str), RSTRING_LEN(str),
                              fmt_ptr, fmt_len, nls_params_ptr, nls_params_len,
                              result));
@@ -205,7 +205,7 @@
     case T_FIXNUM:
         /* set from long. */
         sl = NUM2LONG(num);
-        oci_lc(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result));
+        chkerr(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result));
         return 1;
     case T_FLOAT:
         /* set from double. */
@@ -219,7 +219,7 @@
     }
     if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) {
         /* OCI::Number */
-        oci_lc(OCINumberAssign(errhp, DATA_PTR(num), result));
+        chkerr(OCINumberAssign(errhp, DATA_PTR(num), result));
         return 1;
     }
     if (rb_respond_to(num, id_split)) {
@@ -257,11 +257,11 @@
             }
             exponent = FIX2INT(ary[3]);
 
-            oci_lc(OCINumberShift(errhp, &digits, exponent - digits_len, &work));
+            chkerr(OCINumberShift(errhp, &digits, exponent - digits_len, &work));
             if (sign >= 0) {
-                oci_lc(OCINumberAssign(errhp, &work, result));
+                chkerr(OCINumberAssign(errhp, &work, result));
             } else {
-                oci_lc(OCINumberNeg(errhp, &work, result));
+                chkerr(OCINumberNeg(errhp, &work, result));
             }
             return 1;
         }
@@ -274,7 +274,7 @@
 
         if (set_oci_number_from_num(&numerator, rb_funcall(num, id_numerator, 0), 0, errhp) &&
             set_oci_number_from_num(&denominator, rb_funcall(num, id_denominator, 0), 0, errhp)) {
-            oci_lc(OCINumberDiv(errhp, &numerator, &denominator, result));
+            chkerr(OCINumberDiv(errhp, &numerator, &denominator, result));
             return 1;
         }
     }
@@ -299,7 +299,7 @@
     OCINumber work;
 
     set_oci_number_from_num(&work, self, 1, errhp);
-    oci_lc(OCINumberTrunc(errhp, &work, 0, result));
+    chkerr(OCINumberTrunc(errhp, &work, 0, result));
     return result;
 }
 
@@ -325,7 +325,7 @@
     } else {
         double dbl;
 
-        oci_lc(OCINumberToReal(errhp, s, sizeof(double), &dbl));
+        chkerr(OCINumberToReal(errhp, s, sizeof(double), &dbl));
         return dbl;
     }
 }
@@ -356,7 +356,7 @@
             oci8_raise_by_msgno(rv, NULL);
         }
     } else {
-        oci_lc(OCINumberFromReal(errhp, &dbl, sizeof(dbl), result));
+        chkerr(OCINumberFromReal(errhp, &dbl, sizeof(dbl), result));
     }
     return result;
 }
@@ -380,9 +380,9 @@
     set_oci_number_from_num(&nX, Xcoordinate, 1, errhp);
     set_oci_number_from_num(&nY, Ycoordinate, 1, errhp);
     /* check zero */
-    oci_lc(OCINumberIsZero(errhp, &nX, &is_zero));
+    chkerr(OCINumberIsZero(errhp, &nX, &is_zero));
     if (is_zero) {
-        oci_lc(OCINumberSign(errhp, &nY, &sign));
+        chkerr(OCINumberSign(errhp, &nY, &sign));
         switch (sign) {
         case 0:
             return INT2FIX(0); /* atan2(0, 0) => 0 or ERROR? */
@@ -393,7 +393,7 @@
         }
     }
     /* atan2 */
-    oci_lc(OCINumberArcTan2(errhp, &nY, &nX, &rv));
+    chkerr(OCINumberArcTan2(errhp, &nY, &nX, &rv));
     return oci8_make_ocinumber(&rv, errhp);
 }
 
@@ -410,7 +410,7 @@
     OCINumber r;
     OCINumber rv;
 
-    oci_lc(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv));
+    chkerr(OCINumberCos(errhp, TO_OCINUM(&r, radian, errhp), &rv));
     return oci8_make_ocinumber(&rv, errhp);
 }
 
@@ -427,7 +427,7 @@
     OCINumber r;
     OCINumber rv;
 
-    oci_lc(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv));
+    chkerr(OCINumberSin(errhp, TO_OCINUM(&r, radian, errhp), &rv));
     return oci8_make_ocinumber(&rv, errhp);
 }
 
@@ -443,7 +443,7 @@
     OCINumber r;
     OCINumber rv;
 
-    oci_lc(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv));
+    chkerr(OCINumberTan(errhp, TO_OCINUM(&r, radian, errhp), &rv));
     return oci8_make_ocinumber(&rv, errhp);
 }
 
@@ -462,15 +462,15 @@
 
     set_oci_number_from_num(&n, num, 1, errhp);
     /* check upper bound */
-    oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
+    chkerr(OCINumberCmp(errhp, &n, &const_p1, &sign));
     if (sign > 0)
         rb_raise(rb_eRangeError, "out of range for acos");
     /* check lower bound */
-    oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
+    chkerr(OCINumberCmp(errhp, &n, &const_m1, &sign));
     if (sign < 0)
         rb_raise(rb_eRangeError, "out of range for acos");
     /* acos */
-    oci_lc(OCINumberArcCos(errhp, &n, &r));
+    chkerr(OCINumberArcCos(errhp, &n, &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -489,15 +489,15 @@
 
     set_oci_number_from_num(&n, num, 1, errhp);
     /* check upper bound */
-    oci_lc(OCINumberCmp(errhp, &n, &const_p1, &sign));
+    chkerr(OCINumberCmp(errhp, &n, &const_p1, &sign));
     if (sign > 0)
         rb_raise(rb_eRangeError, "out of range for asin");
     /* check lower bound */
-    oci_lc(OCINumberCmp(errhp, &n, &const_m1, &sign));
+    chkerr(OCINumberCmp(errhp, &n, &const_m1, &sign));
     if (sign < 0)
         rb_raise(rb_eRangeError, "out of range for asin");
     /* asin */
-    oci_lc(OCINumberArcSin(errhp, &n, &r));
+    chkerr(OCINumberArcSin(errhp, &n, &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -513,7 +513,7 @@
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r));
+    chkerr(OCINumberArcTan(errhp, TO_OCINUM(&n, num, errhp), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -529,7 +529,7 @@
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r));
+    chkerr(OCINumberHypCos(errhp, TO_OCINUM(&n, num, errhp), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -546,7 +546,7 @@
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r));
+    chkerr(OCINumberHypSin(errhp, TO_OCINUM(&n, num, errhp), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -563,7 +563,7 @@
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r));
+    chkerr(OCINumberHypTan(errhp, TO_OCINUM(&n, num, errhp), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -579,7 +579,7 @@
     OCINumber n;
     OCINumber r;
 
-    oci_lc(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r));
+    chkerr(OCINumberExp(errhp, TO_OCINUM(&n, num, errhp), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -602,20 +602,20 @@
 
     rb_scan_args(argc, argv, "11", &num, &base);
     set_oci_number_from_num(&n, num, 1, errhp);
-    oci_lc(OCINumberSign(errhp, &n, &sign));
+    chkerr(OCINumberSign(errhp, &n, &sign));
     if (sign <= 0)
         rb_raise(rb_eRangeError, "nonpositive value for log");
     if (NIL_P(base)) {
-        oci_lc(OCINumberLn(errhp, &n, &r));
+        chkerr(OCINumberLn(errhp, &n, &r));
     } else {
         set_oci_number_from_num(&b, base, 1, errhp);
-        oci_lc(OCINumberSign(errhp, &b, &sign));
+        chkerr(OCINumberSign(errhp, &b, &sign));
         if (sign <= 0)
             rb_raise(rb_eRangeError, "nonpositive value for the base of log");
-        oci_lc(OCINumberCmp(errhp, &b, &const_p1, &sign));
+        chkerr(OCINumberCmp(errhp, &b, &const_p1, &sign));
         if (sign == 0)
             rb_raise(rb_eRangeError, "base 1 for log");
-        oci_lc(OCINumberLog(errhp, &b, &n, &r));
+        chkerr(OCINumberLog(errhp, &b, &n, &r));
     }
     return oci8_make_ocinumber(&r, errhp);
 }
@@ -634,10 +634,10 @@
     sword sign;
 
     set_oci_number_from_num(&n, num, 1, errhp);
-    oci_lc(OCINumberSign(errhp, &n, &sign));
+    chkerr(OCINumberSign(errhp, &n, &sign));
     if (sign <= 0)
         rb_raise(rb_eRangeError, "nonpositive value for log10");
-    oci_lc(OCINumberLog(errhp, &const_p10, &n, &r));
+    chkerr(OCINumberLog(errhp, &const_p10, &n, &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -656,12 +656,12 @@
 
     set_oci_number_from_num(&n, num, 1, errhp);
     /* check whether num is negative */
-    oci_lc(OCINumberSign(errhp, &n, &sign));
+    chkerr(OCINumberSign(errhp, &n, &sign));
     if (sign < 0) {
         errno = EDOM;
         rb_sys_fail("sqrt");
     }
-    oci_lc(OCINumberSqrt(errhp, &n, &r));
+    chkerr(OCINumberSqrt(errhp, &n, &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -702,7 +702,7 @@
         rb_raise(rb_eTypeError, "invalid type: expected %s but %s",
                  rb_class2name(CLASS_OF(lhs)), rb_class2name(CLASS_OF(rhs)));
     }
-    oci_lc(OCINumberAssign(oci8_errhp, _NUMBER(rhs), _NUMBER(lhs)));
+    chkerr(OCINumberAssign(oci8_errhp, _NUMBER(rhs), _NUMBER(lhs)));
     return lhs;
 }
 
@@ -714,7 +714,7 @@
     switch(rboci8_type(other)) {
     case T_FIXNUM:
         sl = NUM2LONG(other);
-        oci_lc(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &n));
+        chkerr(OCINumberFromInt(oci8_errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, &n));
         return rb_assoc_new(oci8_make_ocinumber(&n, oci8_errhp), self);
     case T_BIGNUM:
         /* change via string. */
@@ -743,7 +743,7 @@
     OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberNeg(errhp, _NUMBER(self), &r));
+    chkerr(OCINumberNeg(errhp, _NUMBER(self), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -764,12 +764,12 @@
     case T_FIXNUM:
     case T_BIGNUM:
         if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
-            oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r));
+            chkerr(OCINumberAdd(errhp, _NUMBER(lhs), &n, &r));
             return oci8_make_ocinumber(&r, errhp);
         }
         break;
     case RBOCI8_T_ORANUMBER:
-        oci_lc(OCINumberAdd(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
+        chkerr(OCINumberAdd(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
         return oci8_make_ocinumber(&r, errhp);
     case T_FLOAT:
         return rb_funcall(onum_to_f(lhs), oci8_id_add_op, 1, rhs);
@@ -798,12 +798,12 @@
     case T_FIXNUM:
     case T_BIGNUM:
         if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
-            oci_lc(OCINumberSub(errhp, _NUMBER(lhs), &n, &r));
+            chkerr(OCINumberSub(errhp, _NUMBER(lhs), &n, &r));
             return oci8_make_ocinumber(&r, errhp);
         }
         break;
     case RBOCI8_T_ORANUMBER:
-        oci_lc(OCINumberSub(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
+        chkerr(OCINumberSub(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
         return oci8_make_ocinumber(&r, errhp);
     case T_FLOAT:
         return rb_funcall(onum_to_f(lhs), oci8_id_sub_op, 1, rhs);
@@ -831,12 +831,12 @@
     case T_FIXNUM:
     case T_BIGNUM:
         if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
-            oci_lc(OCINumberMul(errhp, _NUMBER(lhs), &n, &r));
+            chkerr(OCINumberMul(errhp, _NUMBER(lhs), &n, &r));
             return oci8_make_ocinumber(&r, errhp);
         }
         break;
     case RBOCI8_T_ORANUMBER:
-        oci_lc(OCINumberMul(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
+        chkerr(OCINumberMul(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
         return oci8_make_ocinumber(&r, errhp);
     case T_FLOAT:
         return rb_funcall(onum_to_f(lhs), oci8_id_mul_op, 1, rhs);
@@ -869,16 +869,16 @@
         }
     case T_BIGNUM:
         if (set_oci_number_from_num(&n, rhs, 0, errhp)) {
-            oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r));
+            chkerr(OCINumberDiv(errhp, _NUMBER(lhs), &n, &r));
             return oci8_make_ocinumber(&r, errhp);
         }
         break;
     case RBOCI8_T_ORANUMBER:
-        oci_lc(OCINumberIsZero(errhp, _NUMBER(rhs), &is_zero));
+        chkerr(OCINumberIsZero(errhp, _NUMBER(rhs), &is_zero));
         if (is_zero) {
             rb_num_zerodiv();
         }
-        oci_lc(OCINumberDiv(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
+        chkerr(OCINumberDiv(errhp, _NUMBER(lhs), _NUMBER(rhs), &r));
         return oci8_make_ocinumber(&r, errhp);
     case T_FLOAT:
         return rb_funcall(onum_to_f(lhs), oci8_id_div_op, 1, rhs);
@@ -907,11 +907,11 @@
     if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_bin(lhs, rhs, '%');
     /* check whether argument is not zero. */
-    oci_lc(OCINumberIsZero(errhp, &n, &is_zero));
+    chkerr(OCINumberIsZero(errhp, &n, &is_zero));
     if (is_zero)
         rb_num_zerodiv();
     /* modulo */
-    oci_lc(OCINumberMod(errhp, _NUMBER(lhs), &n, &r));
+    chkerr(OCINumberMod(errhp, _NUMBER(lhs), &n, &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -928,12 +928,12 @@
     OCINumber r;
 
     if (FIXNUM_P(rhs)) {
-        oci_lc(OCINumberIntPower(errhp, _NUMBER(lhs), FIX2INT(rhs), &r));
+        chkerr(OCINumberIntPower(errhp, _NUMBER(lhs), FIX2INT(rhs), &r));
     } else {
         /* change to OCINumber */
         if (!set_oci_number_from_num(&n, rhs, 0, errhp))
             return rb_num_coerce_bin(lhs, rhs, id_power);
-        oci_lc(OCINumberPower(errhp, _NUMBER(lhs), &n, &r));
+        chkerr(OCINumberPower(errhp, _NUMBER(lhs), &n, &r));
     }
     return oci8_make_ocinumber(&r, errhp);
 }
@@ -956,7 +956,7 @@
     if (!set_oci_number_from_num(&n, rhs, 0, errhp))
         return rb_num_coerce_cmp(lhs, rhs, id_cmp);
     /* compare */
-    oci_lc(OCINumberCmp(errhp, _NUMBER(lhs), &n, &r));
+    chkerr(OCINumberCmp(errhp, _NUMBER(lhs), &n, &r));
     if (r > 0) {
         return INT2FIX(1);
     } else if (r == 0) {
@@ -977,7 +977,7 @@
     OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberFloor(errhp, _NUMBER(self), &r));
+    chkerr(OCINumberFloor(errhp, _NUMBER(self), &r));
     return oci8_make_integer(&r, errhp);
 }
 
@@ -993,7 +993,7 @@
     OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberCeil(errhp, _NUMBER(self), &r));
+    chkerr(OCINumberCeil(errhp, _NUMBER(self), &r));
     return oci8_make_integer(&r, errhp);
 }
 
@@ -1016,7 +1016,7 @@
     OCINumber r;
 
     rb_scan_args(argc, argv, "01", &decplace /* 0 */);
-    oci_lc(OCINumberRound(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
+    chkerr(OCINumberRound(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
     if (argc == 0) {
         return oci8_make_integer(&r, errhp);
     } else {
@@ -1039,7 +1039,7 @@
     OCINumber r;
 
     rb_scan_args(argc, argv, "01", &decplace /* 0 */);
-    oci_lc(OCINumberTrunc(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
+    chkerr(OCINumberTrunc(errhp, _NUMBER(self), NIL_P(decplace) ? 0 : NUM2INT(decplace), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -1059,7 +1059,7 @@
     OCIError *errhp = oci8_errhp;
     OCINumber r;
 
-    oci_lc(OCINumberPrec(errhp, _NUMBER(self), NUM2INT(ndigs), &r));
+    chkerr(OCINumberPrec(errhp, _NUMBER(self), NUM2INT(ndigs), &r));
     return oci8_make_ocinumber(&r, errhp);
 }
 
@@ -1115,7 +1115,7 @@
             if (NIL_P(fmt)) /* implicit conversion */
                 return rb_usascii_str_new_cstr("overflow");
         }
-        oci8_raise(errhp, rv, NULL);
+        chkerr(rv);
     }
     return rb_usascii_str_new(buf, buf_size);
 }
@@ -1142,7 +1142,7 @@
     OCIError *errhp = oci8_errhp;
     OCINumber num;
 
-    oci_lc(OCINumberTrunc(errhp, _NUMBER(self), 0, &num));
+    chkerr(OCINumberTrunc(errhp, _NUMBER(self), 0, &num));
     return oci8_make_integer(&num, errhp);
 }
 
@@ -1173,15 +1173,15 @@
     int current = 0;
     boolean is_int;
 
-    oci_lc(OCINumberAssign(oci8_errhp, _NUMBER(self), &onum[0]));
+    chkerr(OCINumberAssign(oci8_errhp, _NUMBER(self), &onum[0]));
 
     for (;;) {
-        oci_lc(OCINumberIsInt(oci8_errhp, &onum[current], &is_int));
+        chkerr(OCINumberIsInt(oci8_errhp, &onum[current], &is_int));
         if (is_int) {
             break;
         }
         nshift++;
-        oci_lc(OCINumberShift(oci8_errhp, &onum[current], 1, &onum[1 - current]));
+        chkerr(OCINumberShift(oci8_errhp, &onum[current], 1, &onum[1 - current]));
         current = 1 - current;
     }
     x = oci8_make_integer(&onum[current], oci8_errhp);
@@ -1224,7 +1224,7 @@
         rb_require("bigdecimal");
         cBigDecimal = rb_const_get(rb_cObject, id_BigDecimal);
     }
-    oci_lc(OCINumberToText(errhp, num, (const oratext *)fmt, strlen(fmt),
+    chkerr(OCINumberToText(errhp, num, (const oratext *)fmt, strlen(fmt),
                            NULL, 0, &buf_size, TO_ORATEXT(buf)));
     return rb_funcall(rb_cObject, id_BigDecimal, 1, rb_usascii_str_new(buf, buf_size));
 }
@@ -1243,7 +1243,7 @@
     OCIError *errhp = oci8_errhp;
     boolean result;
 
-    oci_lc(OCINumberIsInt(errhp, _NUMBER(self), &result));
+    chkerr(OCINumberIsInt(errhp, _NUMBER(self), &result));
     return result ? Qfalse : Qtrue;
 }
 
@@ -1271,7 +1271,7 @@
     OCIError *errhp = oci8_errhp;
     boolean result;
 
-    oci_lc(OCINumberIsZero(errhp, _NUMBER(self), &result));
+    chkerr(OCINumberIsZero(errhp, _NUMBER(self), &result));
     return result ? Qtrue : Qfalse;
 }
 
@@ -1287,7 +1287,7 @@
     OCIError *errhp = oci8_errhp;
     OCINumber result;
 
-    oci_lc(OCINumberAbs(errhp, _NUMBER(self), &result));
+    chkerr(OCINumberAbs(errhp, _NUMBER(self), &result));
     return oci8_make_ocinumber(&result, errhp);
 }
 
@@ -1303,7 +1303,7 @@
     OCIError *errhp = oci8_errhp;
     OCINumber result;
 
-    oci_lc(OCINumberShift(errhp, _NUMBER(self), NUM2INT(exp), &result));
+    chkerr(OCINumberShift(errhp, _NUMBER(self), NUM2INT(exp), &result));
     return oci8_make_ocinumber(&result, errhp);
 }
 
@@ -1423,7 +1423,8 @@
     OCINumber num;
 
     set_oci_number_from_num(&num, val, 1, errhp);
-    oci_lc(OCINumberTrunc(errhp, &num, 0, (OCINumber*)data));
+    chker2(OCINumberTrunc(errhp, &num, 0, (OCINumber*)data),
+           &obind->base);
 }
 
 static void bind_ocinumber_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length)

Modified: trunk/ruby-oci8/ext/oci8/stmt.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/stmt.c	2011-10-22 11:21:44 UTC (rev 458)
+++ trunk/ruby-oci8/ext/oci8/stmt.c	2011-10-22 13:32:49 UTC (rev 459)
@@ -87,7 +87,7 @@
     if (argc > 1) {
         rv = OCIStmtPrepare(stmt->base.hp.stmt, oci8_errhp, RSTRING_ORATEXT(sql), RSTRING_LEN(sql), OCI_NTV_SYNTAX, OCI_DEFAULT);
         if (IS_OCI_ERROR(rv)) {
-            oci8_raise(oci8_errhp, rv, stmt->base.hp.stmt);
+            chker3(rv, &stmt->base, stmt->base.hp.stmt);
         }
     }
     oci8_link_to_parent((oci8_base_t*)stmt, (oci8_base_t*)DATA_PTR(svc));
@@ -110,7 +110,7 @@
     vptr = (const oci8_bind_vtable_t *)obind->base.vptr;
     status = OCIDefineByPos(stmt->base.hp.stmt, &obind->base.hp.dfn, oci8_errhp, position, obind->valuep, obind->value_sz, vptr->dty, NIL_P(obind->tdo) ? obind->u.inds : NULL, NULL, 0, OCI_DEFAULT);
     if (status != OCI_SUCCESS) {
-        oci8_raise(oci8_errhp, status, stmt->base.hp.ptr);
+        chker3(status, &stmt->base, stmt->base.hp.ptr);
     }
     obind->base.type = OCI_HTYPE_DEFINE;
     /* link to the parent as soon as possible to preserve deallocation order. */
@@ -118,7 +118,7 @@
     oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt);
 
     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));
+        chker2(OCIDefineArrayOfStruct(obind->base.hp.dfn, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0), &stmt->base);
     }
     if (vptr->post_bind_hook != NULL) {
         vptr->post_bind_hook(obind);
@@ -181,7 +181,7 @@
         status = OCIBindByName(stmt->base.hp.stmt, &obind->base.hp.bnd, oci8_errhp, TO_ORATEXT(placeholder_ptr), placeholder_len, obind->valuep, obind->value_sz, vptr->dty, indp, NULL, 0, 0, 0, OCI_DEFAULT);
     }
     if (status != OCI_SUCCESS) {
-        oci8_raise(oci8_errhp, status, stmt->base.hp.stmt);
+        chker3(status, &stmt->base, stmt->base.hp.stmt);
     }
     obind->base.type = OCI_HTYPE_BIND;
     /* link to the parent as soon as possible to preserve deallocation order. */
@@ -189,7 +189,8 @@
     oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)stmt);
 
     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));
+        chker2(OCIBindArrayOfStruct(obind->base.hp.bnd, oci8_errhp, obind->alloc_sz, sizeof(sb2), 0, 0),
+               &stmt->base);
     }
     if (vptr->post_bind_hook != NULL) {
         vptr->post_bind_hook(obind);
@@ -225,9 +226,8 @@
     oci8_svcctx_t *svcctx = oci8_get_svcctx(stmt->svc);
     ub4 iters;
     ub4 mode;
-    sword rv;
 
-    if (oci8_get_ub2_attr(&stmt->base, OCI_ATTR_STMT_TYPE) == INT2FIX(OCI_STMT_SELECT)) {
+    if (oci8_get_ub2_attr(&stmt->base, OCI_ATTR_STMT_TYPE, stmt->base.hp.stmt) == INT2FIX(OCI_STMT_SELECT)) {
         iters = 0;
         mode = OCI_DEFAULT;
     } else {
@@ -237,10 +237,8 @@
             iters = 1;
         mode = svcctx->is_autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT;
     }
-    rv = oci8_call_stmt_execute(svcctx, stmt, iters, mode);
-    if (IS_OCI_ERROR(rv)) {
-        oci8_raise(oci8_errhp, rv, stmt->base.hp.stmt);
-    }
+    chker3(oci8_call_stmt_execute(svcctx, stmt, iters, mode),
+           &stmt->base, stmt->base.hp.stmt);
     return self;
 }
 
@@ -294,9 +292,7 @@
     if (rv == OCI_NO_DATA) {
         return Qnil;
     }
-    if (IS_OCI_ERROR(rv)) {
-        oci8_raise(oci8_errhp, rv, stmt->base.hp.stmt);
-    }
+    chker3(rv, &svcctx->base, stmt->base.hp.stmt);
     ary = rb_ary_new2(RARRAY_LEN(stmt->defns));
     for (idx = 0; idx < RARRAY_LEN(stmt->defns); idx++) {
         rb_ary_store(ary, idx, oci8_bind_get_data(RARRAY_PTR(stmt->defns)[idx]));
@@ -343,7 +339,7 @@
     Check_Type(pos, T_FIXNUM); /* 1 */
     rv = OCIParamGet(stmt->base.hp.stmt, OCI_HTYPE_STMT, oci8_errhp, (dvoid *)&parmhp, FIX2INT(pos));
     if (rv != OCI_SUCCESS) {
-        oci8_raise(oci8_errhp, rv, NULL);
+        chker3(rv, &stmt->base, stmt->base.hp.stmt);
     }
     return oci8_metadata_create(parmhp, stmt->svc, self);
 }
@@ -368,7 +364,8 @@
  */
 static VALUE oci8_stmt_get_stmt_type(VALUE self)
 {
-    VALUE stmt_type = oci8_get_ub2_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_STMT_TYPE);
+    oci8_base_t *base = oci8_get_handle(self, cOCIStmt);
+    VALUE stmt_type = oci8_get_ub2_attr(base, OCI_ATTR_STMT_TYPE, base->hp.stmt);
     switch (FIX2INT(stmt_type)) {
     case OCI_STMT_SELECT:
         return oci8_sym_select_stmt;
@@ -398,7 +395,8 @@
  */
 static VALUE oci8_stmt_get_row_count(VALUE self)
 {
-    return oci8_get_ub4_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_ROW_COUNT);
+    oci8_base_t *base = oci8_get_handle(self, cOCIStmt);
+    return oci8_get_ub4_attr(base, OCI_ATTR_ROW_COUNT, base->hp.stmt);
 }
 
 /*
@@ -417,12 +415,14 @@
  */
 static VALUE oci8_stmt_get_rowid(VALUE self)
 {
-    return oci8_get_rowid_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_ROWID);
+    oci8_base_t *base = oci8_get_handle(self, cOCIStmt);
+    return oci8_get_rowid_attr(base, OCI_ATTR_ROWID, base->hp.stmt);
 }
 
 static VALUE oci8_stmt_get_param_count(VALUE self)
 {
-    return oci8_get_ub4_attr(oci8_get_handle(self, cOCIStmt), OCI_ATTR_PARAM_COUNT);
+    oci8_base_t *base = oci8_get_handle(self, cOCIStmt);
+    return oci8_get_ub4_attr(base, OCI_ATTR_PARAM_COUNT, base->hp.stmt);
 }
 
 /*
@@ -566,7 +566,8 @@
     oci8_stmt_t *stmt = TO_STMT(self);
     ub4 num = NUM2UINT(rows);
 
-    oci_lc(OCIAttrSet(stmt->base.hp.ptr, OCI_HTYPE_STMT, &num, 0, OCI_ATTR_PREFETCH_ROWS, oci8_errhp));
+    chker2(OCIAttrSet(stmt->base.hp.ptr, OCI_HTYPE_STMT, &num, 0, OCI_ATTR_PREFETCH_ROWS, oci8_errhp),
+           &stmt->base);
     return Qfalse;
 }
 




More information about the ruby-oci8-commit mailing list