diff --git a/CHANGELOG.md b/CHANGELOG.md index 594e4298..eaad58bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/ext/tiny_tds/client.c b/ext/tiny_tds/client.c index a65208df..0756cd03 100644 --- a/ext/tiny_tds/client.c +++ b/ext/tiny_tds/client.c @@ -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); diff --git a/test/client_test.rb b/test/client_test.rb index 15a0421e..88ab5b23 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -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