Skip to content

Commit 847953d

Browse files
committed
Raise error for Trilogy when prepared_statements is true
Trilogy doesn't currently support prepared statements. The error that applications would see is a `StatementInvalid` error. This doesn't quite point you to the fact this isn't supported. So raise a more appropriate error pointing to what to change.
1 parent 6e7ef7d commit 847953d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

activerecord/lib/active_record/connection_adapters/trilogy_adapter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ def initialize(config, *)
8383
# matched rather than number of rows updated.
8484
config[:found_rows] = true
8585

86+
if config[:prepared_statements]
87+
raise ArgumentError, "Trilogy currently doesn't support prepared statements. Remove `prepared_statements: true` from your database configuration."
88+
end
89+
8690
super
8791
end
8892

activerecord/test/cases/adapter_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_not_specifying_database_name_for_cross_database_selects
158158
end
159159
end
160160

161-
unless in_memory_db?
161+
unless in_memory_db? || current_adapter?(:TrilogyAdapter)
162162
def test_disable_prepared_statements
163163
original_prepared_statements = ActiveRecord.disable_prepared_statements
164164
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")

activerecord/test/cases/adapters/trilogy/trilogy_adapter_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,12 @@ class TrilogyAdapterTest < ActiveRecord::TrilogyTestCase
390390
end
391391
end
392392

393+
test "setting prepared_statements to true raises" do
394+
assert_raises ArgumentError do
395+
ActiveRecord::ConnectionAdapters::TrilogyAdapter.new(prepared_statements: true).connect!
396+
end
397+
end
398+
393399
# Create a temporary subscription to verify notification is sent.
394400
# Optionally verify the notification payload includes expected types.
395401
def assert_notification(notification, expected_payload = {}, &block)

0 commit comments

Comments
 (0)