Sha256: 5390e9d456f6cd720ece100d65631de501f690d5c63ef7eca039d1826b3f39e0

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/*
 * attr.c
 *
 * Copyright (C) 2002-2012 KUBO Takehiro <kubo@jiubao.org>
 */
#include "oci8.h"

#define MAX_ROWID_LEN 128

typedef struct {
    oci8_base_t *base;
    OCIStmt *stmtp;
    ub4 attrtype;
    OCIRowid *ridp;
} rowid_arg_t;

static VALUE get_rowid_attr(VALUE varg)
{
    rowid_arg_t *arg = (rowid_arg_t *)varg;
    oci8_base_t *base = arg->base;
    ub4 attrtype = arg->attrtype;
    char buf[MAX_ROWID_LEN];
    ub2 buflen;
    sword rv;

    /* get a rowid descriptor from OCIHandle */
    rv = OCIDescriptorAlloc(oci8_envhp, (dvoid*)&arg->ridp, OCI_DTYPE_ROWID, 0, NULL);
    if (rv != OCI_SUCCESS)
        oci8_env_raise(oci8_envhp, rv);
    chker3(OCIAttrGet(base->hp.ptr, base->type, arg->ridp, 0, attrtype, oci8_errhp),
           base, arg->stmtp);
    /* convert the rowid descriptor to a string. */
    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());
}

static VALUE rowid_ensure(VALUE varg)
{
    rowid_arg_t *arg = (rowid_arg_t *)varg;
    if (arg->ridp != NULL) {
        OCIDescriptorFree(arg->ridp, OCI_DTYPE_ROWID);
    }
    return Qnil;
}

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);
}

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ruby-oci8-2.2.14 ext/oci8/attr.c
ruby-oci8-2.2.13 ext/oci8/attr.c
ruby-staci-2.2.9 ext/oci8/attr.c
ruby-oci8-2.2.12 ext/oci8/attr.c
ruby-oci8-2.2.11 ext/oci8/attr.c
ruby-oci8-2.2.10 ext/oci8/attr.c
ruby-oci8-2.2.9 ext/oci8/attr.c
ruby-oci8-2.2.8 ext/oci8/attr.c