Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error if client is unable to execute statement #469

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Improve handling of network related timeouts
* Fix error reporting when preceded by info message
* Raise error if client is unable to execute statement

## 2.1.3

Expand Down
4 changes: 2 additions & 2 deletions ext/tiny_tds/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ static VALUE rb_tinytds_execute(VALUE self, VALUE sql) {
REQUIRE_OPEN_CLIENT(cwrap);
dbcmd(cwrap->client, StringValueCStr(sql));
if (dbsqlsend(cwrap->client) == FAIL) {
rb_warn("TinyTds: dbsqlsend() returned FAIL.\n");
return Qfalse;
rb_raise(cTinyTdsError, "failed to execute statement");
return self;
}
cwrap->userdata->dbsql_sent = 1;
result = rb_tinytds_new_result_obj(cwrap);
Expand Down
19 changes: 19 additions & 0 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ class ClientTest < TinyTds::TestCase
end
end

it 'raises TinyTds exception when tcp socket is down' do
skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
begin
client = new_connection timeout: 2, port: 1234
assert_client_works(client)
action = lambda { client.execute("waitfor delay '00:00:01'").do }

# Use toxiproxy to close the TCP socket immediately.
# We want TinyTds to fail to execute the statement and raise an error immediately.
Toxiproxy[:sqlserver_test].down do
assert_raise_tinytds_error(action) do |e|
assert_match %r{failed to execute statement}i, e.message, 'ignore if non-english test run'
end
end
ensure
assert_new_connections_work
end
end

it 'raises TinyTds exception with tcp socket network failure' do
skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
begin
Expand Down