Skip to content

Nested records types - Unable to assign values #466

@theObserver1

Description

@theObserver1

What versions are you using?

database: 19c
platform.platform: Windows-10-10.0.19045-SP0
sys.maxsize > 2**32: True
platform.python_version: 3.12.8
oracledb.version: 3.0.01

Is it an error or a hang or a crash?

Error

What error(s) or behavior you are seeing?

Similar to bug: #456

I need to work with a PLSQL record types defined inside a PLSQL package. The each record type will contain several other custom RECORD TYPES and TABLE collections defined as variables. The TABLE collections are working as expected so I omitted them from the code.

The issue is I cannot assign or access any values to DbObjectType record nested as an attribute inside a parent DbObjectType object created with GetType(). The script fails with a "OCI-21602: operation does not support the specified typecode" error. Please see Code Snippet.

Does your application call init_oracle_client()?

Yes.

Include a runnable Python script that shows the problem.

import oracledb

DB_DSN='dsn'
DB_USER='user'
DB_PASSWORD='password'

DDLS = [
"""
CREATE OR REPLACE PACKAGE test_pkg AS

TYPE NestedRecord_T IS RECORD (
  Amount                      VARCHAR2(8),
  Field2                      VARCHAR2(1)
);

TYPE main_t IS RECORD (
  RecordDate                  VARCHAR2(8),
  NestedRecord                NestedRecord_T
);

FUNCTION parse(TestData in out nocopy test_pkg.main_t) RETURN varchar2;

END test_pkg;
""",

"""
CREATE OR REPLACE PACKAGE BODY test_pkg AS

FUNCTION parse(TestData in out nocopy test_pkg.main_t) RETURN varchar2
IS
  result varchar2(8);
BEGIN
  return TestData.NestedRecord.Amount;

END parse;

END test_pkg;
"""
]

oracledb.init_oracle_client()
with oracledb.connect(user=DB_USER, password=DB_PASSWORD, dsn=DB_DSN) as db_conn:
    with db_conn.cursor() as cursor:
        for ddl in DDLS:
            cursor.execute(ddl)

        transaction_type_obj = db_conn.gettype('TEST_PKG.MAIN_T')
        trn_obj = transaction_type_obj.newobject()
        for each_field in trn_obj.type.attributes:

            if isinstance(each_field.type, oracledb.DbObjectType):
                print(f"Found nested DbObject type: {each_field.type.schema}.{each_field.type.name}")
                nested_obj = each_field.type.newobject()
                for attr in nested_obj.type.attributes:
                    print(f"Initializing attribute {attr.name} of type {attr.type.name}")
                    setattr(nested_obj, attr.name, "B")
                # Script will fail at this point with :- oracledb.exceptions.DatabaseError: OCI-21602: operation does not support the specified typecode
                setattr(trn_obj, each_field.name, nested_obj)

            else:
                print(f"Setting {each_field.name} to default value")
                setattr(trn_obj, each_field.name, "A")

        cursor_var =cursor.var(oracledb.STRING)
        result = cursor.callfunc("TEST_PKG.PARSE", oracledb.DB_TYPE_VARCHAR, [trn_obj])
        print(f"Func output is : '{result}' ")

        assert trn_obj.RECORDDATE == "A"
        assert trn_obj.NESTEDRECORD is not None
        assert trn_obj.NESTEDRECORD.FIELD2 == "B"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Client Library or DatabaseAn issue with Oracle Client library or Oracle DatabasequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions