#include "dpiImpl.h"
int dpiRowid__allocate(dpiConn *conn, dpiRowid **rowid, dpiError *error)
{
dpiRowid *tempRowid;
if (dpiGen__allocate(DPI_HTYPE_ROWID, conn->env, (void**) &tempRowid,
error) < 0)
return DPI_FAILURE;
if (dpiOci__descriptorAlloc(conn->env->handle, &tempRowid->handle,
DPI_OCI_DTYPE_ROWID, "allocate descriptor", error) < 0) {
dpiRowid__free(tempRowid, error);
return DPI_FAILURE;
}
*rowid = tempRowid;
return DPI_SUCCESS;
}
void dpiRowid__free(dpiRowid *rowid, UNUSED dpiError *error)
{
if (rowid->handle) {
dpiOci__descriptorFree(rowid->handle, DPI_OCI_DTYPE_ROWID);
rowid->handle = NULL;
}
if (rowid->buffer) {
dpiUtils__freeMemory(rowid->buffer);
rowid->buffer = NULL;
}
dpiUtils__freeMemory(rowid);
}
int dpiRowid_addRef(dpiRowid *rowid)
{
return dpiGen__addRef(rowid, DPI_HTYPE_ROWID, __func__);
}
int dpiRowid_getStringValue(dpiRowid *rowid, const char **value,
uint32_t *valueLength)
{
char temp, *adjustedBuffer, *sourcePtr;
uint16_t *targetPtr;
dpiError error;
uint16_t i;
if (dpiGen__startPublicFn(rowid, DPI_HTYPE_ROWID, __func__, &error) < 0)
return dpiGen__endPublicFn(rowid, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(rowid, value)
DPI_CHECK_PTR_NOT_NULL(rowid, valueLength)
if (!rowid->buffer) {
rowid->bufferLength = 0;
dpiOci__rowidToChar(rowid, &temp, &rowid->bufferLength, &error);
if (dpiUtils__allocateMemory(1, rowid->bufferLength, 0,
"allocate rowid buffer", (void**) &rowid->buffer, &error) < 0)
return dpiGen__endPublicFn(rowid, DPI_FAILURE, &error);
if (dpiOci__rowidToChar(rowid, rowid->buffer, &rowid->bufferLength,
&error) < 0)
return dpiGen__endPublicFn(rowid, DPI_FAILURE, &error);
if (rowid->env->charsetId == DPI_CHARSET_ID_UTF16) {
if (dpiUtils__allocateMemory(2, rowid->bufferLength, 0,
"allocate rowid buffer", (void**) &adjustedBuffer,
&error) < 0) {
dpiUtils__freeMemory(rowid->buffer);
rowid->bufferLength = 0;
rowid->buffer = NULL;
return dpiGen__endPublicFn(rowid, DPI_FAILURE, &error);
}
sourcePtr = rowid->buffer;
targetPtr = (uint16_t*) adjustedBuffer;
for (i = 0; i < rowid->bufferLength; i++)
*targetPtr++ = (uint16_t) *sourcePtr++;
dpiUtils__freeMemory(rowid->buffer);
rowid->buffer = adjustedBuffer;
rowid->bufferLength *= 2;
}
}
*value = rowid->buffer;
*valueLength = rowid->bufferLength;
return dpiGen__endPublicFn(rowid, DPI_SUCCESS, &error);
}
int dpiRowid_release(dpiRowid *rowid)
{
return dpiGen__release(rowid, DPI_HTYPE_ROWID, __func__);
}