#include "dpiImpl.h"
int dpiObjectAttr__allocate(dpiObjectType *objType, void *param,
dpiObjectAttr **attr, dpiError *error)
{
dpiObjectAttr *tempAttr;
*attr = NULL;
if (dpiGen__allocate(DPI_HTYPE_OBJECT_ATTR, objType->env,
(void**) &tempAttr, error) < 0)
return DPI_FAILURE;
dpiGen__setRefCount(objType, error, 1);
tempAttr->belongsToType = objType;
if (dpiUtils__getAttrStringWithDup("get name", param, DPI_OCI_DTYPE_PARAM,
DPI_OCI_ATTR_NAME, &tempAttr->name, &tempAttr->nameLength,
error) < 0) {
dpiObjectAttr__free(tempAttr, error);
return DPI_FAILURE;
}
if (dpiOracleType__populateTypeInfo(objType->conn, param,
DPI_OCI_DTYPE_PARAM, &tempAttr->typeInfo, error) < 0) {
dpiObjectAttr__free(tempAttr, error);
return DPI_FAILURE;
}
*attr = tempAttr;
return DPI_SUCCESS;
}
void dpiObjectAttr__free(dpiObjectAttr *attr, dpiError *error)
{
if (attr->belongsToType) {
dpiGen__setRefCount(attr->belongsToType, error, -1);
attr->belongsToType = NULL;
}
if (attr->typeInfo.objectType) {
dpiGen__setRefCount(attr->typeInfo.objectType, error, -1);
attr->typeInfo.objectType = NULL;
}
if (attr->name) {
dpiUtils__freeMemory((void*) attr->name);
attr->name = NULL;
}
dpiUtils__freeMemory(attr);
}
int dpiObjectAttr_addRef(dpiObjectAttr *attr)
{
return dpiGen__addRef(attr, DPI_HTYPE_OBJECT_ATTR, __func__);
}
int dpiObjectAttr_getInfo(dpiObjectAttr *attr, dpiObjectAttrInfo *info)
{
dpiError error;
if (dpiGen__startPublicFn(attr, DPI_HTYPE_OBJECT_ATTR, __func__,
&error) < 0)
return dpiGen__endPublicFn(attr, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(attr, info)
info->name = attr->name;
info->nameLength = attr->nameLength;
if (attr->env->context->dpiMinorVersion > 1) {
info->typeInfo = attr->typeInfo;
} else if (attr->env->context->dpiMinorVersion == 1) {
memcpy(&info->typeInfo, &attr->typeInfo, sizeof(dpiDataTypeInfo__v51));
} else {
memcpy(&info->typeInfo, &attr->typeInfo, sizeof(dpiDataTypeInfo__v50));
}
return dpiGen__endPublicFn(attr, DPI_SUCCESS, &error);
}
int dpiObjectAttr_release(dpiObjectAttr *attr)
{
return dpiGen__release(attr, DPI_HTYPE_OBJECT_ATTR, __func__);
}