示例#1
0
文件: lob.c 项目: aq1018/ruby-oci8
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;
}
示例#2
0
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;
}