Skip to content

Commit

Permalink
allow non-string (number, symbol) username, password or database name
Browse files Browse the repository at this point in the history
  • Loading branch information
rsim committed Jan 5, 2011
1 parent 30e651b commit faac0a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ def new_connection(config)
config[:driver] ||= @raw_connection.meta_data.connection.java_class.name
username = @raw_connection.meta_data.user_name
else
username, password, database = config[:username], config[:password], config[:database]
privilege = config[:privilege] && config[:privilege].to_s
# to_s needed if username, password or database is specified as number in database.yml file
username = config[:username] && config[:username].to_s
password = config[:password] && config[:password].to_s
database = config[:database] && config[:database].to_s
host, port = config[:host], config[:port]
privilege = config[:privilege] && config[:privilege].to_s

# connection using TNS alias
if database && !host && !config[:url] && ENV['TNS_ADMIN']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ def create_time_with_default_timezone(value)
# configure an Oracle/OCI connection.
class OracleEnhancedOCIFactory #:nodoc:
def self.new_connection(config)
username, password, database = config[:username], config[:password], config[:database]
# to_s needed if username, password or database is specified as number in database.yml file
username = config[:username] && config[:username].to_s
password = config[:password] && config[:password].to_s
database = config[:database] && config[:database].to_s
host, port = config[:host], config[:port]
privilege = config[:privilege] && config[:privilege].to_sym
async = config[:allow_concurrency]
Expand All @@ -260,7 +263,6 @@ def self.new_connection(config)
# get session time_zone from configuration or from TZ environment variable
time_zone = config[:time_zone] || ENV['TZ']


# connection using TNS alias
# if TNS_ADMIN is not specified then $ORACLE_HOME/network/admin/ is used as default by Oracle client
connection_string = if database && !host && (ENV['TNS_ADMIN'] || ENV['ORACLE_HOME'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@
end
end

describe "with non-string parameters" do
before(:all) do
params = CONNECTION_PARAMS.dup
params[:username] = params[:username].to_sym
params[:password] = params[:password].to_sym
params[:database] = params[:database].to_sym
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
end

it "should create new connection" do
@conn.should be_active
end
end

if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'

describe "OracleEnhancedConnection create JDBC connection" do
describe "create JDBC connection" do

it "should create new connection using :url" do
params = CONNECTION_PARAMS.dup
Expand Down

0 comments on commit faac0a8

Please sign in to comment.