From 1ed4d3b3a45bc365bbc0900a1f1269ac4b5755d3 Mon Sep 17 00:00:00 2001 From: Lorin Thwaits Date: Wed, 19 Jul 2023 09:29:01 +0100 Subject: [PATCH] [Fixes #54] Apply connection configuration when connecting --- lib/active_record/connection_adapters/trilogy_adapter.rb | 2 ++ .../connection_adapters/trilogy_adapter_test.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/active_record/connection_adapters/trilogy_adapter.rb b/lib/active_record/connection_adapters/trilogy_adapter.rb index 2c64755..87122dc 100644 --- a/lib/active_record/connection_adapters/trilogy_adapter.rb +++ b/lib/active_record/connection_adapters/trilogy_adapter.rb @@ -202,6 +202,7 @@ def reconnect! @lock.synchronize do disconnect! connect + configure_connection end end @@ -297,6 +298,7 @@ def error_number(exception) def connect self.connection = self.class.new_client(@config) + configure_connection end def reconnect diff --git a/test/lib/active_record/connection_adapters/trilogy_adapter_test.rb b/test/lib/active_record/connection_adapters/trilogy_adapter_test.rb index 0f6c4b5..957e41e 100644 --- a/test/lib/active_record/connection_adapters/trilogy_adapter_test.rb +++ b/test/lib/active_record/connection_adapters/trilogy_adapter_test.rb @@ -874,6 +874,12 @@ class Post < ActiveRecord::Base; end assert adapter.active? end + test "sql_mode is applied correctly" do + adapter = trilogy_adapter(variables: { sql_mode: "STRICT_ALL_TABLES" }) + current_sql_mode = adapter.execute('SELECT @@SESSION.sql_mode;').rows.first + assert_equal current_sql_mode, ["STRICT_ALL_TABLES"] + end + def trilogy_adapter_with_connection(connection, **config_overrides) ActiveRecord::ConnectionAdapters::TrilogyAdapter .new(connection, nil, {}, @configuration.merge(config_overrides))