Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/plsql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def logoff
# Current Oracle schema name
def schema_name
return nil unless connection
@schema_name ||= select_first("SELECT SYS_CONTEXT('userenv','session_user') FROM dual")[0]
@schema_name ||= select_first("SELECT SYS_CONTEXT('userenv','current_schema') FROM dual")[0]
end

# Default timezone to which database values will be converted - :utc or :local
Expand Down
39 changes: 38 additions & 1 deletion spec/plsql/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
END test_procedure;
END;
SQL

end

after(:all) do
Expand Down Expand Up @@ -67,6 +66,44 @@
end
end

context "with a user with execute privilege who is not the package owner" do
before(:all) do
plsql.execute("grant execute on TEST_PACKAGE to #{DATABASE_USERS_AND_PASSWORDS[1][0]}")
@original_connection = plsql.connection
@conn = get_connection(1)
end

before(:each) do
# resetting connection clears cached package objects and schema name
plsql.connection = @conn
end

after(:all) do
plsql.logoff
plsql.connection = @original_connection
end

it "should not find existing package" do
expect(PLSQL::Package.find(plsql, :test_package)).to be_nil
end

context "who sets current_schema to match the package owner" do
before(:all) do
plsql.execute "ALTER SESSION set current_schema=#{DATABASE_USERS_AND_PASSWORDS[0][0]}"
end

it "should find existing package" do
expect(PLSQL::Package.find(plsql, :test_package)).not_to be_nil
end

it "should report an existing procedure as existing" do
expect(plsql.test_package.procedure_defined?(:test_procedure)).to be_truthy
end

end

end

describe "variables" do
it "should set and get package variable value" do
plsql.test_package.test_variable = 1
Expand Down
7 changes: 7 additions & 0 deletions spec/plsql/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
end

it 'should match altered current_schema in database session' do
plsql.connection = @conn
expected_current_schema = DATABASE_USERS_AND_PASSWORDS[1][0]
plsql.execute "ALTER SESSION set current_schema=#{expected_current_schema}"
expect(plsql.schema_name).to eq(expected_current_schema.upcase)
end

it "should return new schema name after reconnection" do
plsql.connection = @conn
expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
Expand Down