Skip to content

Commit

Permalink
Adjust error message when connection is dead
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wpolicarpo committed May 15, 2020
1 parent 60e2f0c commit 7dabfb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [#812](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/812) Rails 6: Coerce ReloadModelsTest test on Windows
- [#818](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/818) Handle false return by TinyTDS if connection fails and fixed CI
- [#819](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/819) Fix Ruby 2.7 kwargs warnings
- [#825](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/825) Adjust error message when connection is dead

#### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,12 @@ def raw_connection_do(sql)
case @connection_options[:mode]
when :dblib
result = @connection.execute(sql)
# If connection fails then TinyTDS returns false instead of an exception (see https://github.com/rails-sqlserver/tiny_tds/issues/464)
if result == false
raise TinyTds::Error, 'TinyTDS execute returned false instead of results'
end

# TinyTDS returns false instead of raising an exception if connection fails.
# Getting around this by raising an exception ourselves while this PR
# https://github.com/rails-sqlserver/tiny_tds/pull/469 is not released.
raise TinyTds::Error, 'failed to execute statement' if result.is_a?(FalseClass)

result.do
end
ensure
Expand Down

0 comments on commit 7dabfb1

Please sign in to comment.