Skip to content

Commit

Permalink
Use ODPI-v4.6.0, add PackageName to ObjectType
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamás Gulácsi committed Nov 10, 2022
1 parent ad70b58 commit ed70469
Show file tree
Hide file tree
Showing 16 changed files with 710 additions and 519 deletions.
3 changes: 2 additions & 1 deletion obj.go
Expand Up @@ -829,7 +829,7 @@ type ObjectType struct {
Attributes map[string]ObjectAttribute
drv *drv
dpiObjectType *C.dpiObjectType
Schema, Name string
Schema, Name, PackageName string
DBSize, ClientSizeInBytes, CharSize int
mu sync.RWMutex
OracleTypeNum C.dpiOracleTypeNum
Expand Down Expand Up @@ -1043,6 +1043,7 @@ func (t *ObjectType) init(cache map[string]*ObjectType) error {
}
t.Schema = C.GoStringN(info.schema, C.int(info.schemaLength))
t.Name = C.GoStringN(info.name, C.int(info.nameLength))
t.PackageName = C.GoStringN(info.packageName, C.int(info.packageNameLength))
t.CollectionOf = nil

numAttributes := int(info.numAttributes)
Expand Down
2 changes: 1 addition & 1 deletion odpi/README.md
@@ -1,4 +1,4 @@
# ODPI-C version 4.4
# ODPI-C version 4.6 (Development)

Oracle Database Programming Interface for C (ODPI-C) is an open source library
of C code that simplifies access to Oracle Database for applications written in
Expand Down
19 changes: 17 additions & 2 deletions odpi/include/dpi.h
Expand Up @@ -69,8 +69,8 @@ extern "C" {

// define ODPI-C version information
#define DPI_MAJOR_VERSION 4
#define DPI_MINOR_VERSION 4
#define DPI_PATCH_LEVEL 1
#define DPI_MINOR_VERSION 6
#define DPI_PATCH_LEVEL 0
#define DPI_VERSION_SUFFIX

#define DPI_STR_HELPER(x) #x
Expand Down Expand Up @@ -681,6 +681,8 @@ struct dpiObjectTypeInfo {
int isCollection;
dpiDataTypeInfo elementTypeInfo;
uint16_t numAttributes;
const char *packageName;
uint32_t packageNameLength;
};

// structure used for creating pools
Expand Down Expand Up @@ -1005,6 +1007,13 @@ DPI_EXPORT int dpiConn_newDeqOptions(dpiConn *conn, dpiDeqOptions **options);
// create a new enqueue options object and return it
DPI_EXPORT int dpiConn_newEnqOptions(dpiConn *conn, dpiEnqOptions **options);

// create a new, empty JSON
DPI_EXPORT int dpiConn_newJson(dpiConn *conn, dpiJson **json);

// create a new AQ queue with JSON payload
DPI_EXPORT int dpiConn_newJsonQueue(dpiConn *conn, const char *name,
uint32_t nameLength, dpiQueue **queue);

// create a new message properties object and return it
DPI_EXPORT int dpiConn_newMsgProps(dpiConn *conn, dpiMsgProps **props);

Expand Down Expand Up @@ -1470,6 +1479,9 @@ DPI_EXPORT int dpiMsgProps_getOriginalMsgId(dpiMsgProps *props,
DPI_EXPORT int dpiMsgProps_getPayload(dpiMsgProps *props, dpiObject **obj,
const char **value, uint32_t *valueLength);

// return the payload of the message (JSON)
DPI_EXPORT int dpiMsgProps_getPayloadJson(dpiMsgProps *props, dpiJson **json);

// return the priority of the message
DPI_EXPORT int dpiMsgProps_getPriority(dpiMsgProps *props, int32_t *value);

Expand Down Expand Up @@ -1502,6 +1514,9 @@ DPI_EXPORT int dpiMsgProps_setOriginalMsgId(dpiMsgProps *props,
DPI_EXPORT int dpiMsgProps_setPayloadBytes(dpiMsgProps *props,
const char *value, uint32_t valueLength);

// set the payload of the message (as JSON)
DPI_EXPORT int dpiMsgProps_setPayloadJson(dpiMsgProps *props, dpiJson *json);

// set the payload of the message (as an object)
DPI_EXPORT int dpiMsgProps_setPayloadObject(dpiMsgProps *props,
dpiObject *obj);
Expand Down
59 changes: 55 additions & 4 deletions odpi/src/dpiConn.c
Expand Up @@ -722,10 +722,24 @@ static int dpiConn__getHandles(dpiConn *conn, dpiError *error)
}


//-----------------------------------------------------------------------------
// dpiConn__getJsonTDO() [INTERNAL]
// Internal method used for ensuring that the JSON TDO has been cached on the
// connection.
//-----------------------------------------------------------------------------
int dpiConn__getJsonTDO(dpiConn *conn, dpiError *error)
{
if (conn->jsonTDO)
return DPI_SUCCESS;
return dpiOci__typeByName(conn, "SYS", 3, "JSON", 4, &conn->jsonTDO,
error);
}


//-----------------------------------------------------------------------------
// dpiConn__getRawTDO() [INTERNAL]
// Internal method used for ensuring that the RAW TDO has been cached on the
//connection.
// connection.
//-----------------------------------------------------------------------------
int dpiConn__getRawTDO(dpiConn *conn, dpiError *error)
{
Expand Down Expand Up @@ -1986,8 +2000,8 @@ int dpiConn_getObjectType(dpiConn *conn, const char *name, uint32_t nameLength,
}

// create object type
status = dpiObjectType__allocate(conn, param, DPI_OCI_ATTR_NAME, objType,
&error);
status = dpiObjectType__allocate(conn, param, DPI_OCI_HTYPE_DESCRIBE,
objType, &error);
dpiOci__handleFree(describeHandle, DPI_OCI_HTYPE_DESCRIBE);
return dpiGen__endPublicFn(conn, status, &error);
}
Expand Down Expand Up @@ -2126,6 +2140,43 @@ int dpiConn_newEnqOptions(dpiConn *conn, dpiEnqOptions **options)
}


//-----------------------------------------------------------------------------
// dpiConn_newJson() [PUBLIC]
// Create a new JSON object and return it.
//-----------------------------------------------------------------------------
int dpiConn_newJson(dpiConn *conn, dpiJson **json)
{
dpiError error;
int status;

if (dpiConn__check(conn, __func__, &error) < 0)
return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(conn, json);
status = dpiJson__allocate(conn, json, &error);
return dpiGen__endPublicFn(conn, status, &error);
}


//-----------------------------------------------------------------------------
// dpiConn_newJsonQueue() [PUBLIC]
// Create a new AQ queue object with JSON payload and return it.
//-----------------------------------------------------------------------------
int dpiConn_newJsonQueue(dpiConn *conn, const char *name, uint32_t nameLength,
dpiQueue **queue)
{
dpiError error;
int status;

if (dpiConn__check(conn, __func__, &error) < 0)
return dpiGen__endPublicFn(conn, DPI_FAILURE, &error);
DPI_CHECK_PTR_AND_LENGTH(conn, name)
DPI_CHECK_PTR_NOT_NULL(conn, queue)
status = dpiQueue__allocate(conn, name, nameLength, NULL, queue, 1,
&error);
return dpiGen__endPublicFn(conn, status, &error);
}


//-----------------------------------------------------------------------------
// dpiConn_newTempLob() [PUBLIC]
// Create a new temporary LOB and return it.
Expand Down Expand Up @@ -2194,7 +2245,7 @@ int dpiConn_newQueue(dpiConn *conn, const char *name, uint32_t nameLength,
DPI_CHECK_PTR_AND_LENGTH(conn, name)
DPI_CHECK_PTR_NOT_NULL(conn, queue)
status = dpiQueue__allocate(conn, name, nameLength, payloadType, queue,
&error);
0, &error);
return dpiGen__endPublicFn(conn, status, &error);
}

Expand Down
2 changes: 0 additions & 2 deletions odpi/src/dpiContext.c
Expand Up @@ -218,8 +218,6 @@ int dpiContext_createWithParams(unsigned int majorVersion,
if (!localParams.loadErrorUrl)
localParams.loadErrorUrl = DPI_DEFAULT_LOAD_ERROR_URL;

if (dpiDebugLevel & DPI_DEBUG_LEVEL_FNS)
dpiDebug__print("fn start %s\n", __func__);
status = dpiContext__create(__func__, majorVersion, minorVersion,
&localParams, context, &error);
if (status < 0) {
Expand Down
2 changes: 1 addition & 1 deletion odpi/src/dpiErrorMessages.h
Expand Up @@ -107,7 +107,7 @@ static const char* const dpiErrorMessages[DPI_ERR_MAX - DPI_ERR_NO_ERR] = {
"DPI-1078: native type %d with Oracle type %d is not supported by JSON", // DPI_ERR_UNHANDLED_CONVERSION_TO_JSON
"DPI-1079: Oracle Client library is at version %d.%d but either version %d.%d (or later DBRU) or version %d.%d (or higher) is needed", // DPI_ERR_ORACLE_CLIENT_TOO_OLD_MULTI
"DPI-1080: connection was closed by ORA-%d", // DPI_ERR_CONN_CLOSED
"DPI-1081: invalid dpiAccessToken structure. Both the token and the private key must contain values", // DPI_ERR_TOKEN_BASED_AUTH
"DPI-1081: invalid dpiAccessToken structure. The token must contain a value", // DPI_ERR_TOKEN_BASED_AUTH
"DPI-1082: invalid connection pool configuration for token based authentication. Both homogeneous and externalAuth fields in the dpiPoolCreateParams structure must be set to 1", //DPI_ERR_POOL_TOKEN_BASED_AUTH
"DPI-1083: invalid standalone connection configuration for token based authentication. The externalAuth field in the dpiConnCreateParams structure must be set to 1", //DPI_ERR_STANDALONE_TOKEN_BASED_AUTH
};
12 changes: 8 additions & 4 deletions odpi/src/dpiGlobal.c
Expand Up @@ -68,7 +68,7 @@ static dpiMutexType dpiGlobalMutex;

// forward declarations of internal functions only used in this file
static int dpiGlobal__extendedInitialize(dpiContextCreateParams *params,
dpiError *error);
const char *fnName, dpiError *error);
static void dpiGlobal__finalize(void);
static int dpiGlobal__getErrorBuffer(const char *fnName, dpiError *error);

Expand Down Expand Up @@ -96,7 +96,7 @@ int dpiGlobal__ensureInitialized(const char *fnName,
if (!dpiGlobalInitialized) {
dpiMutex__acquire(dpiGlobalMutex);
if (!dpiGlobalInitialized)
dpiGlobal__extendedInitialize(params, error);
dpiGlobal__extendedInitialize(params, fnName, error);
dpiMutex__release(dpiGlobalMutex);
if (!dpiGlobalInitialized)
return DPI_FAILURE;
Expand All @@ -115,10 +115,15 @@ int dpiGlobal__ensureInitialized(const char *fnName,
// IANA or Oracle character set name.
//-----------------------------------------------------------------------------
static int dpiGlobal__extendedInitialize(dpiContextCreateParams *params,
dpiError *error)
const char *fnName, dpiError *error)
{
int status;

// initialize debugging
dpiDebug__initialize();
if (dpiDebugLevel & DPI_DEBUG_LEVEL_FNS)
dpiDebug__print("fn start %s\n", fnName);

// load OCI library
if (dpiOci__loadLib(params, &dpiGlobalClientVersionInfo, error) < 0)
return DPI_FAILURE;
Expand Down Expand Up @@ -276,7 +281,6 @@ DPI_INITIALIZER(dpiGlobal__initialize)
memset(&dpiGlobalErrorBuffer, 0, sizeof(dpiGlobalErrorBuffer));
strcpy(dpiGlobalErrorBuffer.encoding, DPI_CHARSET_NAME_UTF8);
dpiMutex__initialize(dpiGlobalMutex);
dpiDebug__initialize();
atexit(dpiGlobal__finalize);
}

Expand Down
25 changes: 17 additions & 8 deletions odpi/src/dpiImpl.h
Expand Up @@ -200,6 +200,7 @@ extern unsigned long dpiDebugLevel;
#define DPI_OCI_ATTR_SCHEMA_NAME 9
#define DPI_OCI_ATTR_ROW_COUNT 9
#define DPI_OCI_ATTR_PREFETCH_ROWS 11
#define DPI_OCI_ATTR_PACKAGE_NAME 12
#define DPI_OCI_ATTR_PARAM_COUNT 18
#define DPI_OCI_ATTR_ROWID 19
#define DPI_OCI_ATTR_USERNAME 22
Expand Down Expand Up @@ -343,10 +344,11 @@ extern unsigned long dpiDebugLevel;
#define DPI_OCI_ATTR_JSON_DOM_MUTABLE 609
#define DPI_OCI_ATTR_SODA_METADATA_CACHE 624
#define DPI_OCI_ATTR_SODA_HINT 627
#define DPI_OCI_ATTR_IAM_TOKEN 636
#define DPI_OCI_ATTR_TOKEN 636
#define DPI_OCI_ATTR_IAM_PRIVKEY 637
#define DPI_OCI_ATTR_IAM_CBK 638
#define DPI_OCI_ATTR_IAM_CBKCTX 639
#define DPI_OCI_ATTR_TOKEN_CBK 638
#define DPI_OCI_ATTR_TOKEN_CBKCTX 639
#define DPI_OCI_ATTR_TOKEN_ISBEARER 657

// define OCI object type constants
#define DPI_OCI_OTYPE_NAME 1
Expand Down Expand Up @@ -1244,8 +1246,8 @@ typedef struct {
dpiMsgProps **props; // array of dpiMsgProps handles
void **handles; // array of OCI msg prop handles
void **instances; // array of instances
void **indicators; // array of indicators
int16_t *rawIndicators; // array of indicators (RAW queues)
void **indicators; // array of indicator pointers
int16_t *scalarIndicators; // array of scalar indicator buffers
void **msgIds; // array of OCI message ids
} dpiQueueBuffer;

Expand Down Expand Up @@ -1289,6 +1291,7 @@ struct dpiConn {
const char *releaseString; // cached release string or NULL
uint32_t releaseStringLength; // cached release string length or 0
void *rawTDO; // cached RAW TDO
void *jsonTDO; // cached JSON TDO
dpiVersionInfo versionInfo; // Oracle database version info
uint32_t commitMode; // commit mode (for two-phase commits)
uint16_t charsetId; // database character set ID
Expand Down Expand Up @@ -1419,6 +1422,8 @@ struct dpiObjectType {
const char *schema; // schema owning type (CHAR encoding)
uint32_t schemaLength; // length of schema owning type
const char *name; // name of type (CHAR encoding)
uint32_t packageNameLength; // length of package name
const char *packageName; // package name of type (CHAR ENCODING)
uint32_t nameLength; // length of name of type
dpiDataTypeInfo elementTypeInfo; // type info of elements of collection
int isCollection; // is type a collection?
Expand Down Expand Up @@ -1494,6 +1499,7 @@ struct dpiMsgProps {
void *handle; // OCI message properties handle
dpiObject *payloadObj; // payload (object)
void *payloadRaw; // payload (RAW)
dpiJson *payloadJson; // payload (JSON)
void *msgIdRaw; // message ID (RAW)
};

Expand Down Expand Up @@ -1554,6 +1560,7 @@ struct dpiQueue {
dpiDeqOptions *deqOptions; // dequeue options
dpiEnqOptions *enqOptions; // enqueue options
dpiQueueBuffer buffer; // buffer area
int isJson; // is JSON payload?
};


Expand Down Expand Up @@ -1684,6 +1691,7 @@ int dpiConn__create(dpiConn *conn, const dpiContext *context,
const dpiCommonCreateParams *commonParams,
dpiConnCreateParams *createParams, dpiError *error);
void dpiConn__free(dpiConn *conn, dpiError *error);
int dpiConn__getJsonTDO(dpiConn *conn, dpiError *error);
int dpiConn__getRawTDO(dpiConn *conn, dpiError *error);
int dpiConn__getServerVersion(dpiConn *conn, int wantReleaseString,
dpiError *error);
Expand Down Expand Up @@ -1772,8 +1780,8 @@ void dpiObject__free(dpiObject *obj, dpiError *error);
//-----------------------------------------------------------------------------
// definition of internal dpiObjectType methods
//-----------------------------------------------------------------------------
int dpiObjectType__allocate(dpiConn *conn, void *param,
uint32_t nameAttribute, dpiObjectType **objType, dpiError *error);
int dpiObjectType__allocate(dpiConn *conn, void *handle, uint32_t handleType,
dpiObjectType **objType, dpiError *error);
void dpiObjectType__free(dpiObjectType *objType, dpiError *error);
int dpiObjectType__isXmlType(dpiObjectType *objType);

Expand Down Expand Up @@ -1860,7 +1868,8 @@ void dpiSodaDocCursor__free(dpiSodaDocCursor *cursor, dpiError *error);
// definition of internal dpiQueue methods
//-----------------------------------------------------------------------------
int dpiQueue__allocate(dpiConn *conn, const char *name, uint32_t nameLength,
dpiObjectType *payloadType, dpiQueue **queue, dpiError *error);
dpiObjectType *payloadType, dpiQueue **queue, int isJson,
dpiError *error);
void dpiQueue__free(dpiQueue *queue, dpiError *error);


Expand Down
38 changes: 38 additions & 0 deletions odpi/src/dpiMsgProps.c
Expand Up @@ -360,6 +360,23 @@ int dpiMsgProps_getPayload(dpiMsgProps *props, dpiObject **obj,
}


//-----------------------------------------------------------------------------
// dpiMsgProps_getPayloadJson() [PUBLIC]
// Get the JSON payload for the message (as a dpiJson).
//-----------------------------------------------------------------------------
int dpiMsgProps_getPayloadJson(dpiMsgProps *props, dpiJson **json)
{
dpiError error;

if (dpiGen__startPublicFn(props, DPI_HTYPE_MSG_PROPS, __func__,
&error) < 0)
return dpiGen__endPublicFn(props, DPI_FAILURE, &error);
DPI_CHECK_PTR_NOT_NULL(props, json)
*json = props->payloadJson;
return dpiGen__endPublicFn(props, DPI_SUCCESS, &error);
}


//-----------------------------------------------------------------------------
// dpiMsgProps_getPriority() [PUBLIC]
// Return the priority of the message.
Expand Down Expand Up @@ -493,6 +510,27 @@ int dpiMsgProps_setPayloadBytes(dpiMsgProps *props, const char *value,
}


//-----------------------------------------------------------------------------
// dpiMsgProps_setPayloadJson() [PUBLIC]
// Set the payload for the message (as a JSON object).
//-----------------------------------------------------------------------------
int dpiMsgProps_setPayloadJson(dpiMsgProps *props, dpiJson *json)
{
dpiError error;
if (dpiGen__startPublicFn(props, DPI_HTYPE_MSG_PROPS, __func__,
&error) < 0)
return dpiGen__endPublicFn(props, DPI_FAILURE, &error);
if (dpiGen__checkHandle(json, DPI_HTYPE_JSON, "check json object",
&error) < 0)
return dpiGen__endPublicFn(props, DPI_FAILURE, &error);
if (props->payloadJson)
dpiGen__setRefCount(props->payloadJson, &error, -1);
dpiGen__setRefCount(json, &error, 1);
props->payloadJson = json;
return dpiGen__endPublicFn(props, DPI_SUCCESS, &error);
}


//-----------------------------------------------------------------------------
// dpiMsgProps_setPayloadObject() [PUBLIC]
// Set the payload for the message (as an object).
Expand Down

0 comments on commit ed70469

Please sign in to comment.