Skip to content

Commit

Permalink
Merge pull request #57 from lorint/rails_pr_48109
Browse files Browse the repository at this point in the history
Incorporate Rails PR #48109
  • Loading branch information
bensheldon authored Aug 12, 2023
2 parents 4f7b8d7 + df559d6 commit db3d9f9
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 192 deletions.
13 changes: 2 additions & 11 deletions lib/active_record/connection_adapters/trilogy_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

require "active_record/tasks/trilogy_database_tasks"
require "active_record/connection_adapters/trilogy/database_statements"
require "trilogy_adapter/lost_connection_exception_translator"

module ActiveRecord
# ActiveRecord <= 6.1 support
Expand Down Expand Up @@ -61,7 +60,9 @@ def resolve(config) # :nodoc:
module ConnectionAdapters
class TrilogyAdapter < ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
ER_BAD_DB_ERROR = 1049
ER_DBACCESS_DENIED_ERROR = 1044
ER_ACCESS_DENIED_ERROR = 1045
ER_SERVER_SHUTDOWN = 1053

ADAPTER_NAME = "Trilogy"

Expand Down Expand Up @@ -341,16 +342,6 @@ def default_timezone
end
end

def translate_exception(exception, message:, sql:, binds:)
if exception.is_a?(::Trilogy::TimeoutError) && !exception.error_code
return ActiveRecord::AdapterTimeout.new(message, sql: sql, binds: binds)
end
error_code = exception.error_code if exception.respond_to?(:error_code)

::TrilogyAdapter::LostConnectionExceptionTranslator.
new(exception, message, error_code).translate || super
end

def default_prepared_statements
false
end
Expand Down
1 change: 0 additions & 1 deletion lib/activerecord-trilogy-adapter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# frozen_string_literal: true

require "active_record"
require "trilogy_adapter/errors"
require "trilogy_adapter/railtie"
54 changes: 0 additions & 54 deletions lib/trilogy_adapter/errors.rb

This file was deleted.

60 changes: 0 additions & 60 deletions lib/trilogy_adapter/lost_connection_exception_translator.rb

This file was deleted.

15 changes: 4 additions & 11 deletions test/lib/active_record/connection_adapters/trilogy_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ class ActiveRecord::ConnectionAdapters::TrilogyAdapterTest < TestCase
end
end

test ".new_client on access denied error" do
configuration = @configuration.merge(username: "unknown")
assert_raises ActiveRecord::DatabaseConnectionError do
@adapter.class.new_client(configuration)
end
end

test ".new_client on host error" do
configuration = @configuration.merge(host: "unknown")
assert_raises ActiveRecord::DatabaseConnectionError do
Expand Down Expand Up @@ -457,7 +450,7 @@ class Post < ActiveRecord::Base; end
server_shutdown_error.instance_variable_set(:@error_code, 1053)
mock_connection.expect(:query, nil) { raise server_shutdown_error }

assert_raises(TrilogyAdapter::Errors::ServerShutdown) do
assert_raises(ActiveRecord::StatementInvalid) do
adapter.execute "SELECT * FROM posts;"
end

Expand Down Expand Up @@ -772,13 +765,13 @@ class Post < ActiveRecord::Base; end
assert_equal 123, @adapter.send(:error_number, exception)
end

test "read timeout raises ActiveRecord::AdapterTimeout" do
test "read timeout raises ActiveRecord::StatementInvalid" do
ActiveRecord::Base.establish_connection(@configuration.merge("read_timeout" => 1))

error = assert_raises(ActiveRecord::AdapterTimeout) do
error = assert_raises(ActiveRecord::StatementInvalid) do
ActiveRecord::Base.connection.execute("SELECT SLEEP(2)")
end
assert_kind_of ActiveRecord::QueryAborted, error
assert_kind_of ActiveRecord::StatementInvalid, error

assert_equal Trilogy::TimeoutError, error.cause.class
end
Expand Down

This file was deleted.

0 comments on commit db3d9f9

Please sign in to comment.