Search code examples
pythonoracle-databasecx-oracleuser-defined-types

cx_Oracle - conversion between Oracle type 2010 and native type 3000 is not implemented


I am trying to extract data from User defined type (UDT) using cx_Oracle. I am able extract data for some UDT without problems but for one specific UDT I am not able to extract the data. Structure of types in Oracle:

CREATE OR REPLACE TYPE graphic_component AS OBJECT (
   type             NUMBER(6),
   source_type      NUMBER(4),
   meta_type_id     VARCHAR2(50 CHAR),
   name             VARCHAR2(100 CHAR),
   extension_info   VARCHAR2(500 CHAR),
   symbology_tokens VARCHAR2(2000 CHAR)
);

CREATE OR REPLACE TYPE graphic_component_array AS
      VARRAY (10000) OF graphic_component;

In Python using this code for extracting UDT (code from here):

def ObjectRepr(obj):
    if obj.type.iscollection:
        returnValue = []
        for value in obj.aslist():
            if isinstance(value, cx_Oracle.Object):
                value = ObjectRepr(value)
            returnValue.append(value)
    else:
        returnValue = {}
        for attr in obj.type.attributes:
            value = getattr(obj, attr.name)
            if value is None:
                continue
            elif isinstance(value, cx_Oracle.Object):
                value = ObjectRepr(value)
            returnValue[attr.name] = value
    return returnValue

Then if I try to extract data from UDT I am getting this error:

<cx_Oracle.Object GRAPHIC_COMPONENT_ARRAY at 0x26c9f10>
Traceback (most recent call last):
  File "C:/Users/petr.silhak/PycharmProjects/migration-to-postgresql/test_parsing.py", line 34, in <module>
    print(ObjectRepr(complex[0][0]))
  File "C:/Users/petr.silhak/PycharmProjects/migration-to-postgresql/test_parsing.py", line 9, in ObjectRepr
    value = ObjectRepr(value)
  File "C:/Users/petr.silhak/PycharmProjects/migration-to-postgresql/test_parsing.py", line 14, in ObjectRepr
    value = getattr(obj, attr.name)
cx_Oracle.DatabaseError: DPI-1014: conversion between Oracle type 2010 and native type 3000 is not implemented

It looks like a problem with Oracle odpi conversion of datatypes. In this specific example data looks something like this (from SQL developer):

GRAPHIC_COMPONENT(1007,17,'gtda_5012101_1',NULL,NULL,NULL,NULL)

Solution

  • Check your cx_Oracle version.
    It looks like that the support for conversion from DPI_ORACLE_TYPE_NUMBER(2010) to DPI_NATIVE_TYPE_INT64(3000) was added in September, 2017.