From c60625940e35c2a2ae48310e0cfdac5d3bc1e782 Mon Sep 17 00:00:00 2001 From: Elias Ohm Date: Thu, 4 Oct 2018 14:34:30 +0200 Subject: [PATCH] expose object type of ObjectAttributes expose VarTypes for ObjectAttributes and for collection members of ObjectType --- .gitmodules | 3 ++- odpi | 2 +- src/cxoModule.h | 3 +++ src/cxoObjectAttr.c | 6 ++++++ src/cxoObjectType.c | 8 ++++++++ src/cxoVarType.c | 12 ++++++++++++ 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9e4b5b20..002723b3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "odpi"] path = odpi - url = https://github.com/oracle/odpi.git + url = git@github.com:Elias481/odpi.git + branch = object-raw-attributes diff --git a/odpi b/odpi index 9902a600..47367fe4 160000 --- a/odpi +++ b/odpi @@ -1 +1 @@ -Subproject commit 9902a60068042e7409b7806b5e73fe7e66200cae +Subproject commit 47367fe4eca82f89acac2883dec0ef2d4fe9107a diff --git a/src/cxoModule.h b/src/cxoModule.h index ba5ea60b..7344773b 100644 --- a/src/cxoModule.h +++ b/src/cxoModule.h @@ -335,6 +335,7 @@ struct cxoObjectAttr { dpiOracleTypeNum oracleTypeNum; cxoTransformNum transformNum; cxoObjectType *type; + PyTypeObject *varType; }; struct cxoObjectType { @@ -348,6 +349,7 @@ struct cxoObjectType { dpiOracleTypeNum elementOracleTypeNum; cxoTransformNum elementTransformNum; PyObject *elementType; + PyTypeObject *elementVartype; char isCollection; }; @@ -529,6 +531,7 @@ int cxoUtils_processSodaDocArg(cxoSodaDatabase *db, PyObject *arg, cxoVarType *cxoVarType_fromDataTypeInfo(dpiDataTypeInfo *info); cxoVarType *cxoVarType_fromPythonType(PyTypeObject *type); +cxoVarType *cxoVarType_fromTransformNum(cxoTransformNum transformNum); cxoVarType *cxoVarType_fromPythonValue(PyObject *value, int *isArray, Py_ssize_t *size, Py_ssize_t *numElements, int plsql); diff --git a/src/cxoObjectAttr.c b/src/cxoObjectAttr.c index f8cce7ea..fb079b1b 100644 --- a/src/cxoObjectAttr.c +++ b/src/cxoObjectAttr.c @@ -21,6 +21,8 @@ static PyObject *cxoObjectAttr_repr(cxoObjectAttr*); //----------------------------------------------------------------------------- static PyMemberDef cxoObjectAttrMembers[] = { { "name", T_OBJECT, offsetof(cxoObjectAttr, name), READONLY }, + { "vartype", T_OBJECT, offsetof(cxoObjectAttr, varType), READONLY }, + { "type", T_OBJECT, offsetof(cxoObjectAttr, type), READONLY }, { NULL } }; @@ -81,6 +83,7 @@ static int cxoObjectAttr_initialize(cxoObjectAttr *attr, cxoConnection *connection) { dpiObjectAttrInfo info; + cxoVarType *vartype; if (dpiObjectAttr_getInfo(attr->handle, &info) < 0) return cxoError_raiseAndReturnInt(); @@ -90,6 +93,9 @@ static int cxoObjectAttr_initialize(cxoObjectAttr *attr, connection->encodingInfo.encoding, NULL); if (!attr->name) return -1; + vartype = cxoVarType_fromTransformNum(attr->transformNum); + if (vartype) + attr->varType = vartype->pythonType; if (info.typeInfo.objectType) { attr->type = cxoObjectType_new(connection, info.typeInfo.objectType); diff --git a/src/cxoObjectType.c b/src/cxoObjectType.c index bd4f99cd..3182bbf2 100644 --- a/src/cxoObjectType.c +++ b/src/cxoObjectType.c @@ -43,6 +43,8 @@ static PyMemberDef cxoObjectTypeMembers[] = { READONLY }, { "iscollection", T_BOOL, offsetof(cxoObjectType, isCollection), READONLY }, + { "elementVartype", T_OBJECT, offsetof(cxoObjectType, elementVartype), + READONLY }, { NULL } }; @@ -105,6 +107,7 @@ static int cxoObjectType_initialize(cxoObjectType *objType, dpiObjectAttr **attributes; dpiObjectTypeInfo info; cxoObjectAttr *attr; + cxoVarType *vartype; uint16_t i; // get object type information @@ -124,6 +127,11 @@ static int cxoObjectType_initialize(cxoObjectType *objType, objType->elementOracleTypeNum = info.elementTypeInfo.oracleTypeNum; objType->elementTransformNum = cxoTransform_getNumFromDataTypeInfo(&info.elementTypeInfo); + + vartype = cxoVarType_fromTransformNum(objType->elementTransformNum); + if (vartype) + objType->elementVartype = vartype->pythonType; + if (info.elementTypeInfo.objectType) { objType->elementType = (PyObject*) cxoObjectType_new(connection, info.elementTypeInfo.objectType); diff --git a/src/cxoVarType.c b/src/cxoVarType.c index c987d3d9..13f80740 100644 --- a/src/cxoVarType.c +++ b/src/cxoVarType.c @@ -195,6 +195,18 @@ cxoVarType *cxoVarType_fromPythonType(PyTypeObject *type) return &cxoAllVarTypes[transformNum]; } +//----------------------------------------------------------------------------- +// cxoVarType_fromTransformNum() +// Return a variable type a cxoTransformNum or NULL for +// CXO_TRANSFORM_UNSUPPORTED +//----------------------------------------------------------------------------- +cxoVarType *cxoVarType_fromTransformNum(cxoTransformNum transformNum) +{ + if (transformNum == CXO_TRANSFORM_UNSUPPORTED) { + return NULL; + } + return &cxoAllVarTypes[transformNum]; +} //----------------------------------------------------------------------------- // cxoVarType_calculateSize()