Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/plsql/procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_field_definitions(argument_metadata) # :nodoc:
WHERE t.OWNER = :owner AND t.type_name = :type_name AND t.package_name = :package_name
AND ta.OWNER = t.owner AND ta.TYPE_NAME = t.TYPE_NAME AND ta.PACKAGE_NAME = t.PACKAGE_NAME
ORDER BY attr_no",
@schema_name, argument_metadata[:type_name], argument_metadata[:type_subname]) do |r|
argument_metadata[:type_owner], argument_metadata[:type_name], argument_metadata[:type_subname]) do |r|

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

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

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

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

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

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

Expand Down
45 changes: 45 additions & 0 deletions spec/plsql/procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2385,3 +2385,48 @@ def new_candidate(status)
expect { plsql.test_func(p_STRING: "xxx") }.not_to raise_error
end
end

describe "Function with cross-schema type reference" do
before(:all) do
primary_user, _ = DATABASE_USERS_AND_PASSWORDS[0]
second_user, second_password = DATABASE_USERS_AND_PASSWORDS[1]
@second_schema = second_user.upcase

plsql.connect! CONNECTION_PARAMS

# Connect as second user to create type and grant execute to primary user
plsql2 = PLSQL::Schema.new
plsql2.connect! CONNECTION_PARAMS.merge(username: second_user, password: second_password)
plsql2.execute "CREATE OR REPLACE TYPE t_cross_schema_record AS OBJECT (id NUMBER, name VARCHAR2(50))"
plsql2.execute "GRANT EXECUTE ON t_cross_schema_record TO #{primary_user}"
plsql2.logoff

plsql.execute <<-SQL
CREATE OR REPLACE FUNCTION test_cross_schema_fn(p_rec #{@second_schema}.t_cross_schema_record)
RETURN NUMBER
IS
BEGIN
RETURN p_rec.id;
END;
SQL
end

after(:all) do
second_user, second_password = DATABASE_USERS_AND_PASSWORDS[1]
plsql.execute "DROP FUNCTION test_cross_schema_fn" rescue nil
plsql2 = PLSQL::Schema.new
plsql2.connect! CONNECTION_PARAMS.merge(username: second_user, password: second_password)
plsql2.execute "DROP TYPE t_cross_schema_record" rescue nil
plsql2.logoff
plsql.logoff
end

it "should resolve type from another schema" do
expect(PLSQL::Procedure.find(plsql, :test_cross_schema_fn)).not_to be_nil
end

it "should execute function with cross-schema type parameter" do
result = plsql.test_cross_schema_fn(id: 42, name: "test")
expect(result).to eq(42)
end
end
3 changes: 3 additions & 0 deletions spec/support/create_arunit_user.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
create user arunit identified by arunit;
grant create session to arunit;
grant create type to arunit;
grant create procedure to arunit;
grant unlimited tablespace to arunit;