Skip to content

Commit

Permalink
Remove adapter connection method using jTDS, driver is not longer mai…
Browse files Browse the repository at this point in the history
…ntained
  • Loading branch information
JesseChavez committed Jul 11, 2024
1 parent 6035558 commit 796248e
Showing 1 changed file with 4 additions and 56 deletions.
60 changes: 4 additions & 56 deletions lib/arjdbc/mssql/connection_methods.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,8 @@
# frozen_string_literal: true

ArJdbc::ConnectionMethods.module_eval do

# Default connection method for MS-SQL adapter (`adapter: mssql`),
# uses the (open-source) jTDS driver.
# If you'd like to use the "official" MS's SQL-JDBC driver, it's preferable
# to use the {#sqlserver_connection} method (set `adapter: sqlserver`).
# NOTE: Assumes SQLServer SQL-JDBC driver on the class-path.
def mssql_connection(config)
# NOTE: this detection ain't perfect and is only meant as a temporary hack
# users will get a deprecation eventually to use `adapter: sqlserver` ...
if config[:driver] =~ /SQLServerDriver$/ || config[:url] =~ /^jdbc:sqlserver:/
return sqlserver_connection(config)
end

config = config.deep_dup

config[:adapter_spec] ||= ::ArJdbc::MSSQL
config[:adapter_class] = ActiveRecord::ConnectionAdapters::MSSQLAdapter unless config.key?(:adapter_class)

return jndi_connection(config) if jndi_config?(config)

begin
require 'jdbc/jtds'
# NOTE: the adapter has only support for working with the
# open-source jTDS driver (won't work with MS's driver) !
::Jdbc::JTDS.load_driver(:require) if defined?(::Jdbc::JTDS.load_driver)
rescue LoadError => e # assuming driver.jar is on the class-path
raise e unless e.message.to_s.index('no such file to load')
end

config[:host] ||= 'localhost'
config[:port] ||= 1433
config[:driver] ||= defined?(::Jdbc::JTDS.driver_name) ? ::Jdbc::JTDS.driver_name : 'net.sourceforge.jtds.jdbc.Driver'
config[:connection_alive_sql] ||= 'SELECT 1'

config[:url] ||= begin
url = ''.dup
url << "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}"
# Instance is often a preferrable alternative to port when dynamic ports are used.
# If instance is specified then port is essentially ignored.
url << ";instance=#{config[:instance]}" if config[:instance]
# This will enable windows domain-based authentication and will require the JTDS native libraries be available.
url << ";domain=#{config[:domain]}" if config[:domain]
# AppName is shown in sql server as additional information against the connection.
url << ";appname=#{config[:appname]}" if config[:appname]
url
end

unless config[:domain]
config[:username] ||= 'sa'
config[:password] ||= ''
end
jdbc_connection(config)
end
alias_method :jdbcmssql_connection, :mssql_connection

# @note Assumes SQLServer SQL-JDBC driver on the class-path.
def sqlserver_connection(config)
config = config.deep_dup

config[:adapter_spec] ||= ::ArJdbc::MSSQL
Expand Down Expand Up @@ -89,6 +35,8 @@ def sqlserver_connection(config)

jdbc_connection(config)
end
alias_method :jdbcsqlserver_connection, :sqlserver_connection

alias_method :jdbcmssql_connection, :mssql_connection
alias_method :sqlserver_connection, :mssql_connection
alias_method :jdbcsqlserver_connection, :mssql_connection
end

0 comments on commit 796248e

Please sign in to comment.