static VALUE oci8_bfile_initialize(int argc, VALUE *argv, VALUE self) { oci8_lob_t *lob = DATA_PTR(self); VALUE svc; VALUE dir_alias; VALUE filename; 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)); lob->base.type = OCI_DTYPE_LOB; lob->svc = svc; lob->pos = 0; lob->char_width = 1; lob->csfrm = SQLCS_IMPLICIT; lob->lobtype = OCI_TEMP_BLOB; lob->state = S_BFILE_CLOSE; if (argc != 1) { OCI8SafeStringValue(dir_alias); OCI8SafeStringValue(filename); oci8_bfile_set_name(self, dir_alias, filename); } oci8_link_to_parent((oci8_base_t*)lob, (oci8_base_t*)DATA_PTR(svc)); return Qnil; }
static VALUE oci8_lob_do_initialize(int argc, VALUE *argv, VALUE self, ub1 csfrm, ub1 lobtype) { oci8_lob_t *lob = DATA_PTR(self); VALUE svc; VALUE val; sword rv; rb_scan_args(argc, argv, "11", &svc, &val); TO_SVCCTX(svc); /* check argument type */ 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->svchp = NULL; lob->pos = 0; lob->char_width = 1; lob->csfrm = csfrm; lob->lobtype = lobtype; lob->state = S_NO_OPEN_CLOSE; oci8_link_to_parent((oci8_base_t*)lob, (oci8_base_t*)DATA_PTR(svc)); if (!NIL_P(val)) { if (have_OCILobCreateTemporary_nb) { 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)); lob->svchp = oci8_get_oci_svcctx(svc); oci8_lob_write(self, val); } else { rb_raise(rb_eRuntimeError, "creating a temporary lob is not supported on this Oracle version"); } } return Qnil; }
/* * @overload initialize(conn, directory = nil, filename = nil) * * Creates a BFILE object. * This is correspond to {BFILENAME}[https://docs.oracle.com/database/121/SQLRF/functions020.htm]. * * @param [OCI8] conn * @param [String] directory a directory object created by * {"CREATE DIRECTORY"}[http://docs.oracle.com/database/121/SQLRF/statements_5008.htm]. * @param [String] filename * @return [OCI8::BFILE] */ static VALUE oci8_bfile_initialize(int argc, VALUE *argv, VALUE self) { oci8_lob_t *lob = TO_LOB(self); VALUE svc; VALUE dir_alias; VALUE filename; oci8_svcctx_t *svcctx; int rv; rb_scan_args(argc, argv, "12", &svc, &dir_alias, &filename); svcctx = oci8_get_svcctx(svc); 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->pos = 0; lob->csfrm = SQLCS_IMPLICIT; lob->lobtype = OCI_TEMP_BLOB; lob->state = S_BFILE_CLOSE; if (argc != 1) { OCI8SafeStringValue(dir_alias); OCI8SafeStringValue(filename); oci8_bfile_set_name(self, dir_alias, filename); } oci8_link_to_parent(&lob->base, &svcctx->base); lob->svcctx = svcctx; return Qnil; }
static VALUE oci8_lob_do_initialize(int argc, VALUE *argv, VALUE self, ub1 csfrm, ub1 lobtype) { oci8_lob_t *lob = TO_LOB(self); VALUE svc; VALUE val; oci8_svcctx_t *svcctx; sword rv; rb_scan_args(argc, argv, "11", &svc, &val); svcctx = oci8_get_svcctx(svc); 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->pos = 0; lob->csfrm = csfrm; lob->lobtype = lobtype; lob->state = S_NO_OPEN_CLOSE; oci8_link_to_parent(&lob->base, &svcctx->base); lob->svcctx = svcctx; RB_OBJ_WRITTEN(self, Qundef, svc); if (!NIL_P(val)) { OCI8StringValue(val); chker2(OCILobCreateTemporary_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, 0, csfrm, lobtype, TRUE, OCI_DURATION_SESSION), &svcctx->base); oci8_lob_write(self, val); lob->pos = 0; /* reset the position */ } return Qnil; }
static void oci8_svcctx_init(oci8_base_t *base) { oci8_svcctx_t *svcctx = (oci8_svcctx_t *)base; VALUE obj; svcctx->executing_thread = Qnil; /* set session handle */ obj = rb_obj_alloc(cSession); rb_ivar_set(base->self, id_at_session_handle, obj); oci8_link_to_parent(DATA_PTR(obj), base); /* set server handle */ obj = rb_obj_alloc(cServer); rb_ivar_set(base->self, id_at_server_handle, obj); oci8_link_to_parent(DATA_PTR(obj), base); svcctx->pid = getpid(); svcctx->is_autocommit = 0; #ifdef HAVE_RB_THREAD_BLOCKING_REGION svcctx->non_blocking = 1; #endif svcctx->long_read_len = INT2FIX(65535); }
static void bind_ocitimestamp_tz_init(oci8_bind_t *obind, VALUE svc, VALUE val, VALUE length) { oci8_link_to_parent((oci8_base_t*)obind, (oci8_base_t*)oci8_get_svcctx(svc)); obind->value_sz = sizeof(OCIDateTime *); obind->alloc_sz = sizeof(OCIDateTime *); }