Skip to content

Commit 0e03913

Browse files
yahondajoschugclaude
committed
Use type_owner for cross-schema type lookups
The get_field_definitions and get_element_definition methods used @schema_name when querying type metadata from ALL_PLSQL_TYPE_ATTRS, ALL_TAB_COLS, ALL_PLSQL_COLL_TYPES, and ALL_COLL_TYPES. This fails when a procedure parameter references a type owned by a different schema. Use argument_metadata[:type_owner] instead. Based on rsim#208 Co-Authored-By: Jochen Schug <4573581+joschug@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 39cf870 commit 0e03913

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

lib/plsql/procedure.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def get_field_definitions(argument_metadata) # :nodoc:
361361
WHERE t.OWNER = :owner AND t.type_name = :type_name AND t.package_name = :package_name
362362
AND ta.OWNER = t.owner AND ta.TYPE_NAME = t.TYPE_NAME AND ta.PACKAGE_NAME = t.PACKAGE_NAME
363363
ORDER BY attr_no",
364-
@schema_name, argument_metadata[:type_name], argument_metadata[:type_subname]) do |r|
364+
argument_metadata[:type_owner], argument_metadata[:type_name], argument_metadata[:type_subname]) do |r|
365365

366366
attr_no, attr_name, attr_type_owner, attr_type_name, attr_type_package, attr_length, attr_precision, attr_scale, attr_char_used = r
367367

@@ -393,7 +393,7 @@ def get_field_definitions(argument_metadata) # :nodoc:
393393
"SELECT column_id, column_name, data_type, data_length, data_precision, data_scale, char_length, char_used
394394
FROM ALL_TAB_COLS WHERE OWNER = :owner AND TABLE_NAME = :type_name
395395
ORDER BY column_id",
396-
@schema_name, argument_metadata[:type_name]) do |r|
396+
argument_metadata[:type_owner], argument_metadata[:type_name]) do |r|
397397

398398
col_no, col_name, col_type_name, col_length, col_precision, col_scale, col_char_length, col_char_used = r
399399

@@ -426,7 +426,7 @@ def get_element_definition(argument_metadata) # :nodoc:
426426
"SELECT elem_type_owner, elem_type_name, elem_type_package, length, precision, scale, char_used, index_by
427427
FROM ALL_PLSQL_COLL_TYPES t
428428
WHERE t.OWNER = :owner AND t.TYPE_NAME = :type_name AND t.PACKAGE_NAME = :package_name",
429-
@schema_name, argument_metadata[:type_name], argument_metadata[:type_subname])
429+
argument_metadata[:type_owner], argument_metadata[:type_name], argument_metadata[:type_subname])
430430

431431
elem_type_owner, elem_type_name, elem_type_package, elem_length, elem_precision, elem_scale, elem_char_used, index_by = r
432432

@@ -466,7 +466,7 @@ def get_element_definition(argument_metadata) # :nodoc:
466466
"SELECT elem_type_owner, elem_type_name, length, precision, scale, char_used
467467
FROM ALL_COLL_TYPES t
468468
WHERE t.owner = :owner AND t.TYPE_NAME = :type_name",
469-
@schema_name, argument_metadata[:type_name]
469+
argument_metadata[:type_owner], argument_metadata[:type_name]
470470
)
471471
elem_type_owner, elem_type_name, elem_length, elem_precision, elem_scale, elem_char_used = r
472472

spec/plsql/procedure_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,3 +2385,38 @@ def new_candidate(status)
23852385
expect { plsql.test_func(p_STRING: "xxx") }.not_to raise_error
23862386
end
23872387
end
2388+
2389+
describe "Function with cross-schema type reference" do
2390+
before(:all) do
2391+
plsql.connect! CONNECTION_PARAMS
2392+
@second_user = DATABASE_USERS_AND_PASSWORDS[1][0].upcase
2393+
2394+
# Create type in second schema and grant to current schema
2395+
plsql.execute "CREATE OR REPLACE TYPE #{@second_user}.t_cross_schema_record AS OBJECT (id NUMBER, name VARCHAR2(50))"
2396+
plsql.execute "GRANT EXECUTE ON #{@second_user}.t_cross_schema_record TO #{DATABASE_USERS_AND_PASSWORDS[0][0]}"
2397+
2398+
plsql.execute <<-SQL
2399+
CREATE OR REPLACE FUNCTION test_cross_schema_fn(p_rec #{@second_user}.t_cross_schema_record)
2400+
RETURN NUMBER
2401+
IS
2402+
BEGIN
2403+
RETURN p_rec.id;
2404+
END;
2405+
SQL
2406+
end
2407+
2408+
after(:all) do
2409+
plsql.execute "DROP FUNCTION test_cross_schema_fn" rescue nil
2410+
plsql.execute "DROP TYPE #{@second_user}.t_cross_schema_record" rescue nil
2411+
plsql.logoff
2412+
end
2413+
2414+
it "should resolve type from another schema" do
2415+
expect(PLSQL::Procedure.find(plsql, :test_cross_schema_fn)).not_to be_nil
2416+
end
2417+
2418+
it "should execute function with cross-schema type parameter" do
2419+
result = plsql.test_cross_schema_fn(id: 42, name: "test")
2420+
expect(result).to eq(42)
2421+
end
2422+
end

0 commit comments

Comments
 (0)