Sha256: 48b54959faaa58da999e6369549ccb47dc89873c5d2f028d221a994ac2d420ff

Contents?: true

Size: 1.45 KB

Versions: 13

Compression:

Stored size: 1.45 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(rowid_arg_t *arg)
{
    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(rowid_arg_t *arg)
{
    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

13 entries across 13 versions & 1 rubygems

Version Path
ruby-oci8-2.2.7 ext/oci8/attr.c
ruby-oci8-2.2.6.1 ext/oci8/attr.c
ruby-oci8-2.2.6 ext/oci8/attr.c
ruby-oci8-2.2.5.1 ext/oci8/attr.c
ruby-oci8-2.2.5 ext/oci8/attr.c
ruby-oci8-2.2.4.1 ext/oci8/attr.c
ruby-oci8-2.2.4 ext/oci8/attr.c
ruby-oci8-2.2.3 ext/oci8/attr.c
ruby-oci8-2.2.2 ext/oci8/attr.c
ruby-oci8-2.2.1 ext/oci8/attr.c
ruby-oci8-2.2.0.2 ext/oci8/attr.c
ruby-oci8-2.2.0.1 ext/oci8/attr.c
ruby-oci8-2.1.8 ext/oci8/attr.c