Skip to content

Commit 4a13a9d

Browse files
authored
Merge pull request #2035 from yahonda/support_jdbc_service_name
Support JDBC service name syntax
2 parents b818d53 + c334166 commit 4a13a9d

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ jobs:
1515
2.6,
1616
2.5,
1717
ruby-head,
18-
ruby-debug
18+
ruby-debug,
19+
jruby,
20+
jruby-head
1921
]
2022
env:
2123
ORACLE_HOME: /usr/lib/oracle/18.5/client64
@@ -64,6 +66,9 @@ jobs:
6466
- name: Run RSpec
6567
run: |
6668
bundle exec rspec
69+
- name: Workaround jruby-head failure by removing Gemfile.lock
70+
run: |
71+
rm Gemfile.lock
6772
- name: Run bug report templates
6873
run: |
6974
ruby guides/bug_report_templates/active_record_gem.rb

lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def new_connection(config)
115115
else
116116
unless database.match?(/^(\:|\/)/)
117117
# assume database is a SID if no colon or slash are supplied (backward-compatibility)
118-
database = ":#{database}"
118+
database = "/#{database}"
119119
end
120-
url = config[:url] || "jdbc:oracle:thin:@#{host || 'localhost'}:#{port || 1521}#{database}"
120+
url = config[:url] || "jdbc:oracle:thin:@//#{host || 'localhost'}:#{port || 1521}#{database}"
121121
end
122122

123123
prefetch_rows = config[:prefetch_rows] || 100

spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
ActiveRecord::Base.establish_connection(SYSTEM_CONNECTION_PARAMS.merge(cursor_sharing: :exact))
4141
expect(ActiveRecord::Base.connection.select_value("select value from v$parameter where name = 'cursor_sharing'")).to eq("EXACT")
4242
end
43+
44+
it "should connect to database using service_name" do
45+
ActiveRecord::Base.establish_connection(SERVICE_NAME_CONNECTION_PARAMS)
46+
expect(ActiveRecord::Base.connection).not_to be_nil
47+
expect(ActiveRecord::Base.connection.class).to eq(ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter)
48+
end
4349
end
4450

4551
describe "OracleEnhancedConnection" do

spec/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ def dump_table_schema(table, connection = ActiveRecord::Base.connection)
185185
password: DATABASE_SYS_PASSWORD
186186
}
187187

188+
SERVICE_NAME_CONNECTION_PARAMS = {
189+
adapter: "oracle_enhanced",
190+
database: "/#{DATABASE_NAME}",
191+
host: DATABASE_HOST,
192+
port: DATABASE_PORT,
193+
username: DATABASE_USER,
194+
password: DATABASE_PASSWORD
195+
}
196+
188197
DATABASE_NON_DEFAULT_TABLESPACE = config["database"]["non_default_tablespace"] || ENV["DATABASE_NON_DEFAULT_TABLESPACE"] || "SYSTEM"
189198

190199
# set default time zone in TZ environment variable

0 commit comments

Comments
 (0)