Skip to content

Commit

Permalink
coerce types for config parameters; add missing config parameters rec…
Browse files Browse the repository at this point in the history
…ognized by TinyTDS -- Issue rails-sqlserver#740

Signed-off-by: mystic knight <[email protected]>
  • Loading branch information
PaulCharlton committed Mar 17, 2020
1 parent 0a0ee51 commit ca1e2e5
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/active_record/connection_adapters/sqlserver_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def dblib_connect(config)
TinyTds::Client.new(
dataserver: config[:dataserver],
host: config[:host],
port: config[:port],
port: config_port(config),
username: config[:username],
password: config[:password],
database: config[:database],
Expand All @@ -385,8 +385,10 @@ def dblib_connect(config)
login_timeout: config_login_timeout(config),
timeout: config_timeout(config),
encoding: config_encoding(config),
azure: config[:azure],
contained: config[:contained]
azure: config_azure(config),
contained: config_contained(config),
use_utf16: config_use_utf16(config),
message_handler: config_message_handler(config)
).tap do |client|
if config[:azure]
client.execute('SET ANSI_NULLS ON').do
Expand All @@ -408,6 +410,10 @@ def config_appname(config)
config[:appname] || configure_application_name || Rails.application.class.name.split('::').first rescue nil
end

def config_port(config)
config[:port].present? ? config[:port].to_i : nil
end

def config_login_timeout(config)
config[:login_timeout].present? ? config[:login_timeout].to_i : nil
end
Expand All @@ -420,6 +426,22 @@ def config_encoding(config)
config[:encoding].present? ? config[:encoding] : nil
end

def config_azure(config)
config[:azure].present? ? !!ActiveModel::Type::Boolean.new.cast(config[:azure]) : nil
end

def config_contained(config)
config[:contained].present? ? !!ActiveModel::Type::Boolean.new.cast(config[:contained]) : nil
end

def config_use_utf16(config)
config[:use_utf16].present? ? !!ActiveModel::Type::Boolean.new.cast(config[:use_utf16]) : true
end

def config_message_handler(config)
config[:message_handler].present? ? config[:message_handler] : nil
end

def configure_connection ; end

def configure_application_name ; end
Expand Down

0 comments on commit ca1e2e5

Please sign in to comment.