Skip to content
Draft
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
8 changes: 4 additions & 4 deletions lib/active_record/connection_adapters/odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,29 @@ def supports_migrations?
# includes checking whether the database is actually capable of
# responding, i.e. whether the connection isn't stale.
def active?
@connection.connected?
@unconfigured_connection&.connected?
end

# Disconnects from the database if already connected, and establishes a
# new connection with the database.
def reconnect!
disconnect!
odbc_module = @config[:encoding] == 'utf8' ? ODBC_UTF8 : ODBC
@connection =
@unconfigured_connection =
if @config.key?(:dsn)
odbc_module.connect(@config[:dsn], @config[:username], @config[:password])
else
odbc_module::Database.new.drvconnect(@config[:driver])
end
configure_time_options(@connection)
configure_time_options(@unconfigured_connection)
super
end
alias reset! reconnect!

# Disconnects from the database if already connected. Otherwise, this
# method does nothing.
def disconnect!
@connection.disconnect if @connection.connected?
@unconfigured_connection.disconnect if @unconfigured_connection&.connected?
end

# Build a new column object from the given options. Effectively the same
Expand Down
20 changes: 11 additions & 9 deletions lib/odbc_adapter/database_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module DatabaseStatements
def execute(sql, name = nil, binds = [])
log(sql, name) do
if prepared_statements
@connection.do(prepare_statement_sub(sql), *prepared_binds(binds))
@unconfigured_connection.do(prepare_statement_sub(sql), *prepared_binds(binds))
else
@connection.do(sql)
@unconfigured_connection.do(sql)
end
end
end
Expand All @@ -24,9 +24,9 @@ def exec_query(sql, name = 'SQL', binds = [], prepare: false) # rubocop:disable
log(sql, name) do
stmt =
if prepared_statements
@connection.do(prepare_statement_sub(sql), *prepared_binds(binds))
@unconfigured_connection.do(prepare_statement_sub(sql), *prepared_binds(binds))
else
@connection.run(sql)
@unconfigured_connection.run(sql)
end

columns = stmt.columns
Expand All @@ -39,6 +39,8 @@ def exec_query(sql, name = 'SQL', binds = [], prepare: false) # rubocop:disable
end
end

alias internal_exec_query exec_query

# Executes delete +sql+ statement in the context of this connection using
# +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement.
Expand All @@ -49,20 +51,20 @@ def exec_delete(sql, name, binds)

# Begins the transaction (and turns off auto-committing).
def begin_db_transaction
@connection.autocommit = false
@unconfigured_connection.autocommit = false
end

# Commits the transaction (and turns on auto-committing).
def commit_db_transaction
@connection.commit
@connection.autocommit = true
@unconfigured_connection.commit
@unconfigured_connection.autocommit = true
end

# Rolls back the transaction (and turns on auto-committing). Must be
# done if the transaction block raises an exception or returns false.
def exec_rollback_db_transaction
@connection.rollback
@connection.autocommit = true
@unconfigured_connection.rollback
@unconfigured_connection.autocommit = true
end

# Returns the default sequence name for a table.
Expand Down
2 changes: 1 addition & 1 deletion lib/odbc_adapter/quoting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def quote_column_name(name)
# sequence, but not all ODBC drivers support them.
def quoted_date(value)
if value.acts_like?(:time)
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
zone_conversion_method = ActiveRecord.default_timezone == :utc ? :getutc : :getlocal

if value.respond_to?(zone_conversion_method)
value = value.send(zone_conversion_method)
Expand Down
10 changes: 5 additions & 5 deletions lib/odbc_adapter/schema_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def native_database_types
# Returns an array of table names, for database tables visible on the
# current connection.
def tables(_name = nil)
stmt = @connection.tables
stmt = @unconfigured_connection.tables
result = stmt.fetch_all || []
stmt.drop

Expand All @@ -28,7 +28,7 @@ def views

# Returns an array of indexes for the given table.
def indexes(table_name, _name = nil)
stmt = @connection.indexes(native_case(table_name.to_s))
stmt = @unconfigured_connection.indexes(native_case(table_name.to_s))
result = stmt.fetch_all || []
stmt.drop unless stmt.nil?

Expand Down Expand Up @@ -59,7 +59,7 @@ def indexes(table_name, _name = nil)
# Returns an array of Column objects for the table specified by
# +table_name+.
def columns(table_name, _name = nil)
stmt = @connection.columns(native_case(table_name.to_s))
stmt = @unconfigured_connection.columns(native_case(table_name.to_s))
result = stmt.fetch_all || []
stmt.drop

Expand Down Expand Up @@ -91,14 +91,14 @@ def columns(table_name, _name = nil)

# Returns just a table's primary key
def primary_key(table_name)
stmt = @connection.primary_keys(native_case(table_name.to_s))
stmt = @unconfigured_connection.primary_keys(native_case(table_name.to_s))
result = stmt.fetch_all || []
stmt.drop unless stmt.nil?
result[0] && result[0][3]
end

def foreign_keys(table_name)
stmt = @connection.foreign_keys(native_case(table_name.to_s))
stmt = @unconfigured_connection.foreign_keys(native_case(table_name.to_s))
result = stmt.fetch_all || []
stmt.drop unless stmt.nil?

Expand Down
2 changes: 1 addition & 1 deletion odbc_adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'activerecord', '>= 5.0.1'
spec.add_dependency 'activerecord', '>= 7.1.3'
spec.add_dependency 'ruby-odbc', '~> 0.9'

spec.add_development_dependency 'bundler', '>= 1.14'
Expand Down