Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dbconsole support to adapter #2308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 22 additions & 6 deletions lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,22 @@

module ActiveRecord
module ConnectionHandling # :nodoc:
# Establishes a connection to the database that's used by all Active Record objects.
def oracle_enhanced_connection(config) # :nodoc:
def oracle_enhanced_adapter_class # :nodoc:
if config[:emulate_oracle_adapter] == true
# allows the enhanced adapter to look like the OracleAdapter. Useful to pick up
# conditionals in the rails activerecord test suite
require "active_record/connection_adapters/emulation/oracle_adapter"
ConnectionAdapters::OracleAdapter.new(
ConnectionAdapters::OracleEnhanced::Connection.create(config), logger, config)
ConnectionAdapters::OracleAdapter
else
ConnectionAdapters::OracleEnhancedAdapter.new(
ConnectionAdapters::OracleEnhanced::Connection.create(config), logger, config)
ConnectionAdapters::OracleEnhancedAdapter
end
end

# Establishes a connection to the database that's used by all Active Record objects.
def oracle_enhanced_connection(config) # :nodoc:
oracle_enhanced_adapter_class.new(
ConnectionAdapters::OracleEnhanced::Connection.create(config), logger, config)
end
end

module ConnectionAdapters # :nodoc:
Expand Down Expand Up @@ -275,6 +278,19 @@ def arel_visitor # :nodoc:
end
end

def self.dbconsole(config, options = {})
oracle_config = config.configuration_hash
logon = ""

if config[:username]
logon = oracle_config[:username].dup
logon << "/#{oracle_config[:password]}" if oracle_config[:password] && options[:include_password]
logon << "@#{config.database}" if config.database
end

find_cmd_and_exec("sqlplus", logon)
end

def build_statement_pool
StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit]))
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

describe "Oracle Enhanced adapter dbconsole" do
subject { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter }

it "uses sqlplus to connect to database" do
expect(subject).to receive(:find_cmd_and_exec).with("sqlplus", "user@db")

config = make_db_config(adapter: "oracle", database: "db", username: "user", password: "secret")

subject.dbconsole(config)
end

it "uses sqlplus with password when specified" do
expect(subject).to receive(:find_cmd_and_exec).with("sqlplus", "user/secret@db")

config = make_db_config(adapter: "oracle", database: "db", username: "user", password: "secret")

subject.dbconsole(config, include_password: true)
end

private

def make_db_config(config)
ActiveRecord::DatabaseConfigurations::HashConfig.new("test", "primary", config)
end
end