Skip to content

Commit a3565cc

Browse files
aidanharanwpolicarpo
authored andcommitted
Adapter does not use prepared statement cache
1 parent 64f38c5 commit a3565cc

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

test/cases/coerced_tests.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,27 @@ def test_belongs_to_with_primary_key_joins_on_correct_column_coerced
145145

146146
module ActiveRecord
147147
class BindParameterTest < ActiveRecord::TestCase
148-
# Never finds `sql` since we use `EXEC sp_executesql` wrappers.
148+
# Same as original coerced test except log is found using `EXEC sp_executesql` wrapper.
149149
coerce_tests! :test_binds_are_logged
150+
def test_binds_are_logged_coerced
151+
sub = Arel::Nodes::BindParam.new(1)
152+
binds = [Relation::QueryAttribute.new("id", 1, Type::Value.new)]
153+
sql = "select * from topics where id = #{sub.to_sql}"
154+
155+
@connection.exec_query(sql, "SQL", binds)
156+
157+
logged_sql = "EXEC sp_executesql N'#{sql}', N'#{sub.to_sql} int', #{sub.to_sql} = 1"
158+
message = @subscriber.calls.find { |args| args[4][:sql] == logged_sql }
159+
160+
assert_equal binds, message[4][:binds]
161+
end
162+
163+
# SQL Server adapter does not use a statement cache as query plans are already reused using `EXEC sp_executesql`.
164+
coerce_tests! :test_statement_cache
165+
coerce_tests! :test_statement_cache_with_query_cache
166+
coerce_tests! :test_statement_cache_with_find_by
167+
coerce_tests! :test_statement_cache_with_in_clause
168+
coerce_tests! :test_statement_cache_with_sql_string_literal
150169
end
151170
end
152171

0 commit comments

Comments
 (0)