Skip to content

Commit 7a85608

Browse files
committed
Handle TinyTDS returning false as result of a query
Backport #818 to v5.2.
1 parent c941d93 commit 7a85608

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,14 @@ def sp_executesql_sql(sql, types, params, name)
318318
def raw_connection_do(sql)
319319
case @connection_options[:mode]
320320
when :dblib
321-
@connection.execute(sql).do
321+
result = @connection.execute(sql)
322+
323+
# TinyTDS returns false instead of raising an exception if connection fails.
324+
# Getting around this by raising an exception ourselves while this PR
325+
# https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
326+
raise TinyTds::Error, "failed to execute statement" if result.is_a?(FalseClass)
327+
328+
result.do
322329
end
323330
ensure
324331
@update_sql = false

0 commit comments

Comments
 (0)