#include "dpiImpl.h"
static const unsigned int dpiMajorVersion = DPI_MAJOR_VERSION;
static const unsigned int dpiMinorVersion = DPI_MINOR_VERSION;
static int dpiContext__create(const char *fnName, unsigned int majorVersion,
unsigned int minorVersion, dpiContext **context, dpiError *error)
{
dpiContext *tempContext;
if (dpiGlobal__initError(fnName, error) < 0)
return DPI_FAILURE;
if (!context)
return dpiError__set(error, "check context handle",
DPI_ERR_NULL_POINTER_PARAMETER, "context");
if (dpiMajorVersion != majorVersion || minorVersion > dpiMinorVersion)
return dpiError__set(error, "check version",
DPI_ERR_VERSION_NOT_SUPPORTED, majorVersion, majorVersion,
minorVersion, dpiMajorVersion, dpiMinorVersion);
if (dpiGen__allocate(DPI_HTYPE_CONTEXT, NULL, (void**) &tempContext,
error) < 0)
return DPI_FAILURE;
tempContext->dpiMinorVersion = (uint8_t) minorVersion;
dpiOci__clientVersion(tempContext);
*context = tempContext;
return DPI_SUCCESS;
}
void dpiContext__initCommonCreateParams(dpiCommonCreateParams *params)
{
memset(params, 0, sizeof(dpiCommonCreateParams));
}
void dpiContext__initConnCreateParams(dpiConnCreateParams *params)
{
memset(params, 0, sizeof(dpiConnCreateParams));
}
void dpiContext__initPoolCreateParams(dpiPoolCreateParams *params)
{
memset(params, 0, sizeof(dpiPoolCreateParams));
params->minSessions = 1;
params->maxSessions = 1;
params->sessionIncrement = 0;
params->homogeneous = 1;
params->getMode = DPI_MODE_POOL_GET_NOWAIT;
params->pingInterval = DPI_DEFAULT_PING_INTERVAL;
params->pingTimeout = DPI_DEFAULT_PING_TIMEOUT;
}
void dpiContext__initSodaOperOptions(dpiSodaOperOptions *options)
{
memset(options, 0, sizeof(dpiSodaOperOptions));
}
void dpiContext__initSubscrCreateParams(dpiSubscrCreateParams *params)
{
memset(params, 0, sizeof(dpiSubscrCreateParams));
params->subscrNamespace = DPI_SUBSCR_NAMESPACE_DBCHANGE;
params->groupingType = DPI_SUBSCR_GROUPING_TYPE_SUMMARY;
}
int dpiContext_create(unsigned int majorVersion, unsigned int minorVersion,
dpiContext **context, dpiErrorInfo *errorInfo)
{
dpiError error;
int status;
if (dpiDebugLevel & DPI_DEBUG_LEVEL_FNS)
dpiDebug__print("fn start %s\n", __func__);
status = dpiContext__create(__func__, majorVersion, minorVersion, context,
&error);
if (status < 0)
dpiError__getInfo(&error, errorInfo);
if (dpiDebugLevel & DPI_DEBUG_LEVEL_FNS)
dpiDebug__print("fn end %s -> %d\n", __func__, status);
return status;
}
int dpiContext_destroy(dpiContext *context)
{
char message[80];
dpiError error;
if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__,
&error) < 0)
return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
dpiUtils__clearMemory(&context->checkInt, sizeof(context->checkInt));
if (dpiDebugLevel & DPI_DEBUG_LEVEL_REFS)
dpiDebug__print("ref %p (%s) -> 0\n", context, context->typeDef->name);
if (dpiDebugLevel & DPI_DEBUG_LEVEL_FNS)
(void) sprintf(message, "fn end %s(%p) -> %d", __func__, context,
DPI_SUCCESS);
dpiUtils__freeMemory(context);
if (dpiDebugLevel & DPI_DEBUG_LEVEL_FNS)
dpiDebug__print("%s\n", message);
return DPI_SUCCESS;
}
int dpiContext_getClientVersion(const dpiContext *context,
dpiVersionInfo *versionInfo)
{
dpiError error;
if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__,
&error) < 0)
return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(context, versionInfo)
memcpy(versionInfo, context->versionInfo, sizeof(dpiVersionInfo));
return dpiGen__endPublicFn(context, DPI_SUCCESS, &error);
}
void dpiContext_getError(const dpiContext *context, dpiErrorInfo *info)
{
dpiError error;
dpiGlobal__initError(NULL, &error);
dpiGen__checkHandle(context, DPI_HTYPE_CONTEXT, "check handle", &error);
dpiError__getInfo(&error, info);
}
int dpiContext_initCommonCreateParams(const dpiContext *context,
dpiCommonCreateParams *params)
{
dpiError error;
if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__,
&error) < 0)
return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(context, params)
dpiContext__initCommonCreateParams(params);
return dpiGen__endPublicFn(context, DPI_SUCCESS, &error);
}
int dpiContext_initConnCreateParams(const dpiContext *context,
dpiConnCreateParams *params)
{
dpiConnCreateParams localParams;
dpiError error;
if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__,
&error) < 0)
return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(context, params)
if (context->dpiMinorVersion > 0)
dpiContext__initConnCreateParams(params);
else {
dpiContext__initConnCreateParams(&localParams);
memcpy(params, &localParams, sizeof(dpiConnCreateParams__v30));
}
return dpiGen__endPublicFn(context, DPI_SUCCESS, &error);
}
int dpiContext_initPoolCreateParams(const dpiContext *context,
dpiPoolCreateParams *params)
{
dpiPoolCreateParams localParams;
dpiError error;
if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__,
&error) < 0)
return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(context, params)
if (context->dpiMinorVersion > 0)
dpiContext__initPoolCreateParams(params);
else {
dpiContext__initPoolCreateParams(&localParams);
memcpy(params, &localParams, sizeof(dpiPoolCreateParams__v30));
}
return dpiGen__endPublicFn(context, DPI_SUCCESS, &error);
}
int dpiContext_initSodaOperOptions(const dpiContext *context,
dpiSodaOperOptions *options)
{
dpiError error;
if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__,
&error) < 0)
return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(context, options)
dpiContext__initSodaOperOptions(options);
return dpiGen__endPublicFn(context, DPI_SUCCESS, &error);
}
int dpiContext_initSubscrCreateParams(const dpiContext *context,
dpiSubscrCreateParams *params)
{
dpiSubscrCreateParams localParams;
dpiError error;
if (dpiGen__startPublicFn(context, DPI_HTYPE_CONTEXT, __func__,
&error) < 0)
return dpiGen__endPublicFn(context, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(context, params)
if (context->dpiMinorVersion > 1) {
dpiContext__initSubscrCreateParams(params);
} else {
dpiContext__initSubscrCreateParams(&localParams);
memcpy(params, &localParams, sizeof(dpiSubscrCreateParams__v30));
}
return dpiGen__endPublicFn(context, DPI_SUCCESS, &error);
}