Skip to content

Commit ecd8956

Browse files
Fixed bug when getting a record type based on a table (%ROWTYPE) (#123).
1 parent d73e43a commit ecd8956

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Thin Mode Changes
1818
(`issue 112 <https://github.com/oracle/python-oracledb/issues/112>`__).
1919
#) Fixed bug when binding OUT a NULL boolean value.
2020
(`issue 119 <https://github.com/oracle/python-oracledb/issues/119>`__).
21+
#) Fixed bug when getting a record type based on a table (%ROWTYPE)
22+
(`issue 123 <https://github.com/oracle/python-oracledb/issues/123>`__).
2123

2224
Thick Mode Changes
2325
++++++++++++++++++

src/oracledb/impl/thin/dbobject.pyx

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2022, 2023, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -719,23 +719,35 @@ cdef class ThinDbObjectTypeCache:
719719
t_SuperTypeOwner varchar2(128);
720720
t_SuperTypeName varchar2(128);
721721
t_SubTypeRefCursor sys_refcursor;
722+
t_Pos pls_integer;
722723
begin
723724
:ret_val := dbms_pickler.get_type_shape(:full_name, :oid,
724725
:version, :tds, t_Instantiable, t_SuperTypeOwner,
725726
t_SuperTypeName, :attrs_rc, t_SubTypeRefCursor);
726727
:package_name := null;
727-
begin
728-
select owner, type_name
729-
into :schema, :name
730-
from all_types
731-
where type_oid = :oid;
732-
exception
733-
when no_data_found then
734-
select owner, package_name, type_name
735-
into :schema, :package_name, :name
736-
from all_plsql_types
737-
where type_oid = :oid;
738-
end;
728+
if substr(:full_name, length(:full_name) - 7) = '%ROWTYPE' then
729+
t_Pos := instr(:full_name, '.');
730+
:schema := substr(:full_name, 1, t_Pos - 1);
731+
:name := substr(:full_name, t_Pos + 1);
732+
else
733+
begin
734+
select owner, type_name
735+
into :schema, :name
736+
from all_types
737+
where type_oid = :oid;
738+
exception
739+
when no_data_found then
740+
begin
741+
select owner, package_name, type_name
742+
into :schema, :package_name, :name
743+
from all_plsql_types
744+
where type_oid = :oid;
745+
exception
746+
when no_data_found then
747+
null;
748+
end;
749+
end;
750+
end if;
739751
end;""")
740752
self.meta_cursor = cursor
741753

@@ -939,17 +951,23 @@ cdef class ThinDbObjectTypeCache:
939951
"""
940952
cdef:
941953
ThinDbObjectTypeImpl typ_impl
942-
str full_name
954+
str full_name, name, suffix
943955
while self.partial_types:
944956
typ_impl = self.partial_types.pop()
945957
if self.meta_cursor is None:
946958
self._init_meta_cursor(conn)
959+
suffix = "%ROWTYPE"
960+
if typ_impl.name.endswith(suffix):
961+
name = typ_impl.name[:-len(suffix)]
962+
else:
963+
name = typ_impl.name
964+
suffix = ""
947965
if typ_impl.package_name is not None:
948966
full_name = f'"{typ_impl.schema}".' + \
949967
f'"{typ_impl.package_name}".' + \
950-
f'"{typ_impl.name}"'
968+
f'"{name}"{suffix}'
951969
else:
952-
full_name = f'"{typ_impl.schema}"."{typ_impl.name}"'
970+
full_name = f'"{typ_impl.schema}"."{name}"{suffix}'
953971
self._populate_type_info(full_name, typ_impl)
954972

955973

tests/sql/create_schema.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,10 @@ end;
10351035

10361036
create or replace package &main_user..pkg_TestBindObject as
10371037

1038+
subtype udt_RowType is TestTempTable%rowtype;
1039+
1040+
type udt_CollectionRowType is table of udt_RowType index by binary_integer;
1041+
10381042
function GetStringRep (
10391043
a_Object udt_Object
10401044
) return varchar2;

tests/test_3200_features_12_1.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -539,5 +539,16 @@ def test_3227_batch_error_multiple_execute(self):
539539
for e in self.cursor.getbatcherrors()]
540540
self.assertEqual(actual_errors, expected_errors)
541541

542+
def test_3228_record_based_on_table_type(self):
543+
"3228 - test %ROWTYPE record type"
544+
type_obj = self.connection.gettype("TESTTEMPTABLE%ROWTYPE")
545+
self.assertEqual(type_obj.attributes[3].name, "NUMBERCOL")
546+
547+
def test_3229_collection_of_records_based_on_table_type(self):
548+
"3229 - test collection of %ROWTYPE record type"
549+
type_name = "PKG_TESTBINDOBJECT.UDT_COLLECTIONROWTYPE"
550+
type_obj = self.connection.gettype(type_name)
551+
self.assertEqual(type_obj.element_type.attributes[3].name, "NUMBERCOL")
552+
542553
if __name__ == "__main__":
543554
test_env.run_test_cases()

0 commit comments

Comments
 (0)