static void copy_session_handle(oci8_svcctx_t *svcctx) { VALUE obj = rb_ivar_get(svcctx->base.self, id_at_session_handle); oci8_base_t *base; Check_Handle(obj, cSession, base); base->type = OCI_HTYPE_SESSION; base->hp.usrhp = svcctx->usrhp; }
static void copy_server_handle(oci8_svcctx_t *svcctx) { VALUE obj = rb_ivar_get(svcctx->base.self, id_at_server_handle); oci8_base_t *base; Check_Handle(obj, cServer, base); base->type = OCI_HTYPE_SERVER; base->hp.srvhp = svcctx->srvhp; }
oci8_svcctx_t *oci8_get_svcctx(VALUE obj) { oci8_base_t *base; Check_Handle(obj, cOCI8, base); if (base->type == 0) { rb_raise(eOCIException, "invalid argument %s was freed already.", rb_class2name(CLASS_OF(obj))); } return (oci8_svcctx_t *)base; }
/* =begin --- OCIStmt#execute(svc [, iters [, mode]]) execute statement at the ((<service context handle|OCISvcCtx>)). :svc ((<service context handle|OCISvcCtx>)) :iters the number of iterations to execute. For select statement, if there are columns which is not defined by ((<OCIStmt#defineByPos>)) and this value is positive, it raises exception. If zero, no exception. In any case you must define all columns before you call ((<OCIStmt#fetch>)). For non-select statement, use positive value. Default value is 0 for select statement, 1 for non-select statement. note: Current implemantation doesn't support array fetch and batch mode, so valid value is 0 or 1. :mode ((|OCI_DEFAULT|)), ((|OCI_BATCH_ERRORS|)), ((|OCI_COMMIT_ON_SUCCESS|)), ((|OCI_DESCRIBE_ONLY|)), ((|OCI_EXACT_FETCH|)), ((|OCI_PARSE_ONLY|)), any combinations of previous values, or ((|OCI_STMT_SCROLLABLE_READONLY|)). Default value is ((|OCI_DEFAULT|)). ((|OCI_BATCH_ERRORS|)) and ((|OCI_STMT_SCROLLABLE_READONLY|)) are not supported by current implementation. correspond native OCI function: ((|OCIStmtExecute|)) =end */ static VALUE oci8_stmt_execute(int argc, VALUE *argv, VALUE self) { VALUE vsvc; VALUE viters; VALUE vmode; oci8_handle_t *h; oci8_handle_t *svch; ub4 mode; ub4 iters; ub2 stmt_type; sword rv; rb_scan_args(argc, argv, "12", &vsvc, &viters, &vmode); Get_Handle(self, h); /* 0 */ Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */ if (argc >= 2) { iters = NUM2UINT(viters); /* 2 */ } else { rv = OCIAttrGet(h->hp, OCI_HTYPE_STMT, &stmt_type, 0, OCI_ATTR_STMT_TYPE, h->errhp); if (rv != OCI_SUCCESS) { oci8_raise(h->errhp, rv, h->hp); } if (stmt_type == OCI_STMT_SELECT) { /* for select statement, default value 0. */ iters = 0; } else { /* for non-select statement, default value 0. */ iters = 1; } } Get_Int_With_Default(argc, 3, vmode, mode, OCI_DEFAULT); /* 3 */ if (iters > 1) { rb_raise(rb_eArgError, "current implementation doesn't support array fatch or batch mode"); } rv = OCIStmtExecute(svch->hp, h->hp, h->errhp, iters, 0, NULL, NULL, mode); if (rv == OCI_ERROR) { sb4 errcode; OCIErrorGet(h->errhp, 1, NULL, &errcode, NULL, 0, OCI_HTYPE_ERROR); if (errcode == 1000) { /* run GC to close unreferred cursors when ORA-01000 (maximum open cursors exceeded). */ rb_gc(); rv = OCIStmtExecute(svch->hp, h->hp, h->errhp, iters, 0, NULL, NULL, mode); } } if (IS_OCI_ERROR(rv)) { oci8_raise(h->errhp, rv, h->hp); } return self; }
/* =begin --- OCISession#end(svc [, vmode]) terminate user Authentication Context :svc ((<OCISvcCtx>)). :mode ((|OCI_DEFAULT|)) only valid. Defalt value is ((|OCI_DEFAULT|)). correspond native OCI function: ((|OCISessionEnd|)) =end */ static VALUE oci8_session_end(int argc, VALUE *argv, VALUE self) { VALUE vsvc, vmode; oci8_handle_t *h; oci8_handle_t *svch; ub4 mode; sword rv; rb_scan_args(argc, argv, "11", &vsvc, &vmode); Get_Handle(self, h); /* 0 */ Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */ Get_Int_With_Default(argc, 2, vmode, mode, OCI_DEFAULT); /* 2 */ rv = OCISessionEnd(svch->hp, h->errhp, h->hp, mode); if (rv != OCI_SUCCESS) oci8_raise(h->errhp, rv, NULL); return self; }
/* THIS WILL BE DELETED IN FUTURE RELEASE. */ static VALUE oci8_describe_any(VALUE self, VALUE vdsc, VALUE vname, VALUE vtype) { oci8_handle_t *h; oci8_handle_t *dsch; oci8_string_t name; ub1 type; sword rv; Get_Handle(self, h); /* 0 */ Check_Handle(vdsc, OCIDescribe, dsch); /* 1 */ Get_String(vname, name); /* 2 */ type = FIX2INT(vtype); /* 3 */ rv = OCIDescribeAny(h->hp, h->errhp, name.ptr, name.len, OCI_OTYPE_NAME, OCI_DEFAULT, type, dsch->hp); if (rv != OCI_SUCCESS) { oci8_raise(h->errhp, rv, NULL); } return self; }
oci8_bind_t *oci8_get_bind(VALUE obj) { oci8_base_t *base; Check_Handle(obj, cOCI8BindTypeBase, base); return (oci8_bind_t *)base; }