Esempio n. 1
0
//-----------------------------------------------------------------------------
// dpiObject_setElementValueByIndex() [PUBLIC]
//   Set the element at the specified index to the given value.
//-----------------------------------------------------------------------------
int dpiObject_setElementValueByIndex(dpiObject *obj, int32_t index,
        dpiNativeTypeNum nativeTypeNum, dpiData *data)
{
    dpiOracleDataBuffer valueBuffer;
    int16_t scalarValueIndicator;
    void *indicator;
    dpiError error;
    void *ociValue;
    int status;

    if (dpiObject__checkIsCollection(obj, __func__, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(obj, data)
    if (dpiObject__toOracleValue(obj, &error, &obj->type->elementTypeInfo,
            &valueBuffer, &ociValue, &scalarValueIndicator,
            (void**) &indicator, nativeTypeNum, data) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    if (!indicator)
        indicator = &scalarValueIndicator;
    status = dpiOci__collAssignElem(obj->type->conn, index, ociValue,
            indicator, obj->instance, &error);
    dpiObject__clearOracleValue(obj, &error, &valueBuffer,
            obj->type->elementTypeInfo.oracleTypeNum);
    return dpiGen__endPublicFn(obj, status, &error);
}
//-----------------------------------------------------------------------------
// dpiSodaDocCursor_getNext() [PUBLIC]
//   Return the next document available from the cursor.
//-----------------------------------------------------------------------------
int dpiSodaDocCursor_getNext(dpiSodaDocCursor *cursor, uint32_t flags,
        dpiSodaDoc **doc)
{
    dpiError error;
    uint32_t mode;
    void *handle;

    if (dpiSodaDocCursor__check(cursor, __func__, &error) < 0)
        return dpiGen__endPublicFn(cursor, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(cursor, doc)
    mode = DPI_OCI_DEFAULT;
    if (flags & DPI_SODA_FLAGS_ATOMIC_COMMIT)
        mode |= DPI_OCI_SODA_ATOMIC_COMMIT;
    if (dpiOci__sodaDocGetNext(cursor, &handle, mode, &error) < 0)
        return dpiGen__endPublicFn(cursor, DPI_FAILURE, &error);
    *doc = NULL;
    if (handle) {
        if (dpiSodaDoc__allocate(cursor->coll->db, handle, doc, &error) < 0) {
            dpiOci__handleFree(handle, DPI_OCI_HTYPE_SODA_DOCUMENT);
            return dpiGen__endPublicFn(cursor, DPI_FAILURE, &error);
        }
        (*doc)->binaryContent = cursor->coll->binaryContent;
    }
    return dpiGen__endPublicFn(cursor, DPI_SUCCESS, &error);
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// dpiObject_deleteElementByIndex() [PUBLIC]
//   Delete the element at the specified index in the collection.
//-----------------------------------------------------------------------------
int dpiObject_deleteElementByIndex(dpiObject *obj, int32_t index)
{
    dpiError error;
    int status;

    if (dpiObject__checkIsCollection(obj, __func__, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    status = dpiOci__tableDelete(obj, index, &error);
    return dpiGen__endPublicFn(obj, status, &error);
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
// dpiObject_getSize() [PUBLIC]
//   Return the size of the collection.
//-----------------------------------------------------------------------------
int dpiObject_getSize(dpiObject *obj, int32_t *size)
{
    dpiError error;
    int status;

    if (dpiObject__checkIsCollection(obj, __func__, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(obj, size)
    status = dpiOci__collSize(obj->type->conn, obj->instance, size, &error);
    return dpiGen__endPublicFn(obj, status, &error);
}
Esempio n. 5
0
//-----------------------------------------------------------------------------
// dpiObject_trim() [PUBLIC]
//   Trim a number of elements from the end of the collection.
//-----------------------------------------------------------------------------
int dpiObject_trim(dpiObject *obj, uint32_t numToTrim)
{
    dpiError error;
    int status;

    if (dpiObject__checkIsCollection(obj, __func__, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    status = dpiOci__collTrim(obj->type->conn, numToTrim, obj->instance,
            &error);
    return dpiGen__endPublicFn(obj, status, &error);
}
//-----------------------------------------------------------------------------
// dpiSodaDocCursor_close() [PUBLIC]
//   Close the cursor.
//-----------------------------------------------------------------------------
int dpiSodaDocCursor_close(dpiSodaDocCursor *cursor)
{
    dpiError error;

    if (dpiSodaDocCursor__check(cursor, __func__, &error) < 0)
        return dpiGen__endPublicFn(cursor, DPI_FAILURE, &error);
    if (cursor->handle) {
        dpiOci__handleFree(cursor->handle, DPI_OCI_HTYPE_SODA_DOC_CURSOR);
        cursor->handle = NULL;
    }
    return dpiGen__endPublicFn(cursor, DPI_SUCCESS, &error);
}
Esempio n. 7
0
//-----------------------------------------------------------------------------
// dpiObject_getElementExistsByIndex() [PUBLIC]
//   Return boolean indicating if an element exists in the collection at the
// specified index.
//-----------------------------------------------------------------------------
int dpiObject_getElementExistsByIndex(dpiObject *obj, int32_t index,
        int *exists)
{
    dpiError error;
    int status;

    if (dpiObject__checkIsCollection(obj, __func__, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(obj, exists)
    status = dpiOci__tableExists(obj, index, exists, &error);
    return dpiGen__endPublicFn(obj, status, &error);
}
Esempio n. 8
0
//-----------------------------------------------------------------------------
// dpiObjectType_createObject() [PUBLIC]
//   Create a new object of the specified type and return it. Return NULL on
// error.
//-----------------------------------------------------------------------------
int dpiObjectType_createObject(dpiObjectType *objType, dpiObject **obj)
{
    dpiError error;
    int status;

    // validate parameters
    if (dpiObjectType__check(objType, __func__, &error) < 0)
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(objType, obj)
    status = dpiObject__allocate(objType, NULL, NULL, NULL, obj, &error);
    return dpiGen__endPublicFn(objType, status, &error);
}
Esempio n. 9
0
//-----------------------------------------------------------------------------
// dpiDeqOptions__setAttrValue() [INTERNAL]
//   Set the attribute value in OCI.
//-----------------------------------------------------------------------------
static int dpiDeqOptions__setAttrValue(dpiDeqOptions *options,
        uint32_t attribute, const char *fnName, const void *value,
        uint32_t valueLength)
{
    dpiError error;
    int status;

    if (dpiGen__startPublicFn(options, DPI_HTYPE_DEQ_OPTIONS, fnName, 1,
            &error) < 0)
        return dpiGen__endPublicFn(options, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(options, value)
    status = dpiOci__attrSet(options->handle, DPI_OCI_DTYPE_AQDEQ_OPTIONS,
            (void*) value, valueLength, attribute, "set attribute value",
            &error);
    return dpiGen__endPublicFn(options, status, &error);
}
Esempio n. 10
0
//-----------------------------------------------------------------------------
// dpiDeqOptions_getVisibility() [PUBLIC]
//   Return visibility associated with dequeue options.
//-----------------------------------------------------------------------------
int dpiDeqOptions_getVisibility(dpiDeqOptions *options, dpiVisibility *value)
{
    uint32_t ociValue;
    dpiError error;

    if (dpiGen__startPublicFn(options, DPI_HTYPE_DEQ_OPTIONS, __func__, 1,
            &error) < 0)
        return dpiGen__endPublicFn(options, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(options, value)
    if (dpiOci__attrGet(options->handle, DPI_OCI_DTYPE_AQDEQ_OPTIONS,
            &ociValue, NULL, DPI_OCI_ATTR_VISIBILITY, "get attribute value",
            &error) < 0)
        return dpiGen__endPublicFn(options, DPI_FAILURE, &error);
    *value = (dpiVisibility) ociValue;
    return dpiGen__endPublicFn(options, DPI_SUCCESS, &error);
}
Esempio n. 11
0
//-----------------------------------------------------------------------------
// dpiObjectType_getInfo() [PUBLIC]
//   Return information about the object type.
//-----------------------------------------------------------------------------
int dpiObjectType_getInfo(dpiObjectType *objType, dpiObjectTypeInfo *info)
{
    dpiError error;

    if (dpiGen__startPublicFn(objType, DPI_HTYPE_OBJECT_TYPE, __func__, 0,
            &error) < 0)
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(objType, info)
    info->name = objType->name;
    info->nameLength = objType->nameLength;
    info->schema = objType->schema;
    info->schemaLength = objType->schemaLength;
    info->isCollection = objType->isCollection;
    info->elementTypeInfo = objType->elementTypeInfo;
    info->numAttributes = objType->numAttributes;
    return dpiGen__endPublicFn(objType, DPI_SUCCESS, &error);
}
Esempio n. 12
0
//-----------------------------------------------------------------------------
// dpiObject_copy() [PUBLIC]
//   Create a copy of the object and return it. Return NULL upon error.
//-----------------------------------------------------------------------------
int dpiObject_copy(dpiObject *obj, dpiObject **copiedObj)
{
    dpiObject *tempObj;
    dpiError error;

    if (dpiObject__check(obj, __func__, &error) < 0)
        return DPI_FAILURE;
    DPI_CHECK_PTR_NOT_NULL(obj, copiedObj)
    if (dpiObject__allocate(obj->type, NULL, NULL, NULL, &tempObj, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    if (dpiOci__objectCopy(tempObj, obj->instance, obj->indicator,
            &error) < 0) {
        dpiObject__free(tempObj, &error);
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    }
    *copiedObj = tempObj;
    return dpiGen__endPublicFn(obj, DPI_SUCCESS, &error);
}
Esempio n. 13
0
//-----------------------------------------------------------------------------
// dpiObject_getLastIndex() [PUBLIC]
//   Return the index of the last entry in the collection.
//-----------------------------------------------------------------------------
int dpiObject_getLastIndex(dpiObject *obj, int32_t *index, int *exists)
{
    dpiError error;
    int32_t size;
    int status;

    if (dpiObject__checkIsCollection(obj, __func__, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(obj, index)
    DPI_CHECK_PTR_NOT_NULL(obj, exists)
    if (dpiOci__tableSize(obj, &size, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    *exists = (size != 0);
    if (*exists)
        status = dpiOci__tableLast(obj, index, &error);
    else status = DPI_SUCCESS;
    return dpiGen__endPublicFn(obj, status, &error);
}
Esempio n. 14
0
//-----------------------------------------------------------------------------
// dpiObject_getAttributeValue() [PUBLIC]
//   Get the value of the given attribute from the object.
//-----------------------------------------------------------------------------
int dpiObject_getAttributeValue(dpiObject *obj, dpiObjectAttr *attr,
        dpiNativeTypeNum nativeTypeNum, dpiData *data)
{
    int16_t scalarValueIndicator;
    void *valueIndicator, *tdo;
    dpiOracleData value;
    dpiError error;
    int status;

    // validate parameters
    if (dpiObject__check(obj, __func__, &error) < 0)
        return DPI_FAILURE;
    DPI_CHECK_PTR_NOT_NULL(obj, data)
    if (dpiGen__checkHandle(attr, DPI_HTYPE_OBJECT_ATTR, "get attribute value",
            &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    if (attr->belongsToType->tdo != obj->type->tdo) {
        dpiError__set(&error, "get attribute value", DPI_ERR_WRONG_ATTR,
                attr->nameLength, attr->name, obj->type->schemaLength,
                obj->type->schema, obj->type->nameLength, obj->type->name);
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    }

    // get attribute value
    if (dpiOci__objectGetAttr(obj, attr, &scalarValueIndicator,
            &valueIndicator, &value.asRaw, &tdo, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);

    // determine the proper null indicator
    if (!valueIndicator)
        valueIndicator = &scalarValueIndicator;

    // check to see if type is supported
    if (!attr->typeInfo.oracleTypeNum) {
        dpiError__set(&error, "get attribute value",
                DPI_ERR_UNHANDLED_DATA_TYPE, attr->typeInfo.ociTypeCode);
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    }

    // convert to output data format
    status = dpiObject__fromOracleValue(obj, &error, &attr->typeInfo, &value,
            (int16_t*) valueIndicator, nativeTypeNum, data);
    return dpiGen__endPublicFn(obj, status, &error);
}
Esempio n. 15
0
//-----------------------------------------------------------------------------
// dpiDeqOptions_getMsgId() [PUBLIC]
//   Return message id associated with dequeue options.
//-----------------------------------------------------------------------------
int dpiDeqOptions_getMsgId(dpiDeqOptions *options, const char **value,
        uint32_t *valueLength)
{
    dpiError error;
    void *rawValue;

    if (dpiGen__startPublicFn(options, DPI_HTYPE_DEQ_OPTIONS, __func__, 1,
            &error) < 0)
        return dpiGen__endPublicFn(options, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(options, value)
    DPI_CHECK_PTR_NOT_NULL(options, valueLength)
    if (dpiOci__attrGet(options->handle, DPI_OCI_DTYPE_AQDEQ_OPTIONS,
            &rawValue, NULL, DPI_OCI_ATTR_DEQ_MSGID, "get attribute value",
            &error) < 0)
        return dpiGen__endPublicFn(options, DPI_FAILURE, &error);
    dpiOci__rawPtr(options->env->handle, rawValue, (void**) value);
    dpiOci__rawSize(options->env->handle, rawValue, valueLength);
    return dpiGen__endPublicFn(options, DPI_SUCCESS, &error);
}
Esempio n. 16
0
//-----------------------------------------------------------------------------
// dpiObject_setAttributeValue() [PUBLIC]
//   Create a copy of the object and return it. Return NULL upon error.
//-----------------------------------------------------------------------------
int dpiObject_setAttributeValue(dpiObject *obj, dpiObjectAttr *attr,
        dpiNativeTypeNum nativeTypeNum, dpiData *data)
{
    void *valueIndicator, *ociValue;
    dpiOracleDataBuffer valueBuffer;
    int16_t scalarValueIndicator;
    dpiError error;
    int status;

    // validate parameters
    if (dpiObject__check(obj, __func__, &error) < 0)
        return DPI_FAILURE;
    DPI_CHECK_PTR_NOT_NULL(obj, data)
    if (dpiGen__checkHandle(attr, DPI_HTYPE_OBJECT_ATTR, "set attribute value",
            &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    if (attr->belongsToType->tdo != obj->type->tdo) {
        dpiError__set(&error, "set attribute value", DPI_ERR_WRONG_ATTR,
                attr->nameLength, attr->name, obj->type->schemaLength,
                obj->type->schema, obj->type->nameLength, obj->type->name);
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    }

    // check to see if type is supported
    if (!attr->typeInfo.oracleTypeNum) {
        dpiError__set(&error, "get attribute value",
                DPI_ERR_UNHANDLED_DATA_TYPE, attr->typeInfo.ociTypeCode);
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    }

    // convert to input data format
    if (dpiObject__toOracleValue(obj, &error, &attr->typeInfo, &valueBuffer,
            &ociValue, &scalarValueIndicator, &valueIndicator, nativeTypeNum,
            data) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);

    // set attribute value
    status = dpiOci__objectSetAttr(obj, attr, scalarValueIndicator,
            valueIndicator, ociValue, &error);
    dpiObject__clearOracleValue(obj, &error, &valueBuffer,
            attr->typeInfo.oracleTypeNum);
    return dpiGen__endPublicFn(obj, status, &error);
}
Esempio n. 17
0
//-----------------------------------------------------------------------------
// dpiDeqOptions_setMsgId() [PUBLIC]
//   Set the message id associated with dequeue options.
//-----------------------------------------------------------------------------
int dpiDeqOptions_setMsgId(dpiDeqOptions *options, const char *value,
        uint32_t valueLength)
{
    void *rawValue = NULL;
    dpiError error;
    int status;

    if (dpiGen__startPublicFn(options, DPI_HTYPE_DEQ_OPTIONS, __func__, 1,
            &error) < 0)
        return dpiGen__endPublicFn(options, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(options, value)
    if (dpiOci__rawAssignBytes(options->env->handle, value, valueLength,
            &rawValue, &error) < 0)
        return dpiGen__endPublicFn(options, DPI_FAILURE, &error);
    status = dpiOci__attrSet(options->handle, DPI_OCI_DTYPE_AQDEQ_OPTIONS,
            (void*) &rawValue, valueLength, DPI_OCI_ATTR_DEQ_MSGID,
            "set value", &error);
    dpiOci__rawResize(options->env->handle, &rawValue, 0, &error);
    return dpiGen__endPublicFn(options, status, &error);
}
Esempio n. 18
0
//-----------------------------------------------------------------------------
// dpiObject_getElementValueByIndex() [PUBLIC]
//   Return the element at the given index in the collection.
//-----------------------------------------------------------------------------
int dpiObject_getElementValueByIndex(dpiObject *obj, int32_t index,
        dpiNativeTypeNum nativeTypeNum, dpiData *data)
{
    dpiOracleData value;
    int exists, status;
    void *indicator;
    dpiError error;

    if (dpiObject__checkIsCollection(obj, __func__, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(obj, data)
    if (dpiOci__collGetElem(obj->type->conn, obj->instance, index, &exists,
            &value.asRaw, &indicator, &error) < 0)
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    if (!exists) {
        dpiError__set(&error, "get element value", DPI_ERR_INVALID_INDEX,
                index);
        return dpiGen__endPublicFn(obj, DPI_FAILURE, &error);
    }
    status = dpiObject__fromOracleValue(obj, &error,
            &obj->type->elementTypeInfo, &value, (int16_t*) indicator,
            nativeTypeNum, data);
    return dpiGen__endPublicFn(obj, status, &error);
}
Esempio n. 19
0
//-----------------------------------------------------------------------------
// dpiObjectType_getAttributes() [PUBLIC]
//   Get the attributes for the object type in the provided array.
//-----------------------------------------------------------------------------
int dpiObjectType_getAttributes(dpiObjectType *objType, uint16_t numAttributes,
        dpiObjectAttr **attributes)
{
    void *topLevelParam, *attrListParam, *attrParam, *describeHandle;
    dpiError error;
    uint16_t i;

    // validate object type and the number of attributes
    if (dpiObjectType__check(objType, __func__, &error) < 0)
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
    DPI_CHECK_PTR_NOT_NULL(objType, attributes)
    if (numAttributes < objType->numAttributes) {
        dpiError__set(&error, "get attributes", DPI_ERR_ARRAY_SIZE_TOO_SMALL,
                numAttributes);
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
    }
    if (numAttributes == 0)
        return dpiGen__endPublicFn(objType, DPI_SUCCESS, &error);

    // acquire a describe handle
    if (dpiOci__handleAlloc(objType->env->handle, &describeHandle,
            DPI_OCI_HTYPE_DESCRIBE, "allocate describe handle", &error) < 0)
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);

    // describe the type
    if (dpiOci__describeAny(objType->conn, objType->tdo, 0, DPI_OCI_OTYPE_PTR,
            describeHandle, &error) < 0) {
        dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
    }

    // get the top level parameter descriptor
    if (dpiOci__attrGet(describeHandle, DPI_OCI_HTYPE_DESCRIBE, &topLevelParam,
            0, DPI_OCI_ATTR_PARAM, "get top level param", &error) < 0) {
        dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
    }

    // get the attribute list parameter descriptor
    if (dpiOci__attrGet(topLevelParam, DPI_OCI_DTYPE_PARAM,
            (void*) &attrListParam, 0, DPI_OCI_ATTR_LIST_TYPE_ATTRS,
            "get attr list param", &error) < 0) {
        dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
        return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
    }

    // create attribute structure for each attribute
    for (i = 0; i < objType->numAttributes; i++) {
        if (dpiOci__paramGet(attrListParam, DPI_OCI_DTYPE_PARAM, &attrParam,
                (uint32_t) i + 1, "get attribute param", &error) < 0) {
            dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
            return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
        }
        if (dpiObjectAttr__allocate(objType, attrParam, &attributes[i],
                &error) < 0) {
            dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
            return dpiGen__endPublicFn(objType, DPI_FAILURE, &error);
        }
    }

    // free the describe handle
    dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);

    return dpiGen__endPublicFn(objType, DPI_SUCCESS, &error);
}