Skip to content

Commit 7dabfb1

Browse files
committed
Adjust error message when connection is dead
TinyTDS returns false instead of raising an exception if connection fails while executing a query. Getting around this by raising an exception ourselves while this PR rails-sqlserver/tiny_tds#469 is not released. The solution came from #717 and #818, I am just adjusting the error message to make it the same as that TinyTDS PR.
1 parent 60e2f0c commit 7dabfb1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [#812](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/812) Rails 6: Coerce ReloadModelsTest test on Windows
1111
- [#818](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/818) Handle false return by TinyTDS if connection fails and fixed CI
1212
- [#819](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/819) Fix Ruby 2.7 kwargs warnings
13+
- [#825](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/825) Adjust error message when connection is dead
1314

1415
#### Changed
1516

lib/active_record/connection_adapters/sqlserver/database_statements.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,12 @@ def raw_connection_do(sql)
353353
case @connection_options[:mode]
354354
when :dblib
355355
result = @connection.execute(sql)
356-
# If connection fails then TinyTDS returns false instead of an exception (see https://github.com/rails-sqlserver/tiny_tds/issues/464)
357-
if result == false
358-
raise TinyTds::Error, 'TinyTDS execute returned false instead of results'
359-
end
356+
357+
# TinyTDS returns false instead of raising an exception if connection fails.
358+
# Getting around this by raising an exception ourselves while this PR
359+
# https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
360+
raise TinyTds::Error, 'failed to execute statement' if result.is_a?(FalseClass)
361+
360362
result.do
361363
end
362364
ensure

0 commit comments

Comments
 (0)