Skip to content

Commit ece4f99

Browse files
author
Eygin Semen Leonidovich
committed
return ServerError when failed to get cancelation confirmation
1 parent 85e531a commit ece4f99

File tree

4 files changed

+28
-33
lines changed

4 files changed

+28
-33
lines changed

mssql.go

+25-23
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323

2424
// ReturnStatus may be used to return the return value from a proc.
2525
//
26-
// var rs mssql.ReturnStatus
27-
// _, err := db.Exec("theproc", &rs)
28-
// log.Printf("return status = %d", rs)
26+
// var rs mssql.ReturnStatus
27+
// _, err := db.Exec("theproc", &rs)
28+
// log.Printf("return status = %d", rs)
2929
type ReturnStatus int32
3030

3131
var driverInstance = &Driver{processQueryText: true}
@@ -243,8 +243,6 @@ func (c *Conn) checkBadConn(ctx context.Context, err error, mayRetry bool) error
243243
return nil
244244
case io.EOF:
245245
c.connectionGood = false
246-
case ErrorCancelConfirmation:
247-
c.connectionGood = false
248246
case driver.ErrBadConn:
249247
// It is an internal programming error if driver.ErrBadConn
250248
// is ever passed to this function. driver.ErrBadConn should
@@ -879,22 +877,24 @@ func (r *Rows) ColumnTypeDatabaseTypeName(index int) string {
879877
// not a variable length type ok should return false.
880878
// If length is not limited other than system limits, it should return math.MaxInt64.
881879
// The following are examples of returned values for various types:
882-
// TEXT (math.MaxInt64, true)
883-
// varchar(10) (10, true)
884-
// nvarchar(10) (10, true)
885-
// decimal (0, false)
886-
// int (0, false)
887-
// bytea(30) (30, true)
880+
//
881+
// TEXT (math.MaxInt64, true)
882+
// varchar(10) (10, true)
883+
// nvarchar(10) (10, true)
884+
// decimal (0, false)
885+
// int (0, false)
886+
// bytea(30) (30, true)
888887
func (r *Rows) ColumnTypeLength(index int) (int64, bool) {
889888
return makeGoLangTypeLength(r.cols[index].ti)
890889
}
891890

892891
// It should return
893892
// the precision and scale for decimal types. If not applicable, ok should be false.
894893
// The following are examples of returned values for various types:
895-
// decimal(38, 4) (38, 4, true)
896-
// int (0, 0, false)
897-
// decimal (math.MaxInt64, math.MaxInt64, true)
894+
//
895+
// decimal(38, 4) (38, 4, true)
896+
// int (0, 0, false)
897+
// decimal (math.MaxInt64, math.MaxInt64, true)
898898
func (r *Rows) ColumnTypePrecisionScale(index int) (int64, int64, bool) {
899899
return makeGoLangTypePrecisionScale(r.cols[index].ti)
900900
}
@@ -1321,22 +1321,24 @@ func (r *Rowsq) ColumnTypeDatabaseTypeName(index int) string {
13211321
// not a variable length type ok should return false.
13221322
// If length is not limited other than system limits, it should return math.MaxInt64.
13231323
// The following are examples of returned values for various types:
1324-
// TEXT (math.MaxInt64, true)
1325-
// varchar(10) (10, true)
1326-
// nvarchar(10) (10, true)
1327-
// decimal (0, false)
1328-
// int (0, false)
1329-
// bytea(30) (30, true)
1324+
//
1325+
// TEXT (math.MaxInt64, true)
1326+
// varchar(10) (10, true)
1327+
// nvarchar(10) (10, true)
1328+
// decimal (0, false)
1329+
// int (0, false)
1330+
// bytea(30) (30, true)
13301331
func (r *Rowsq) ColumnTypeLength(index int) (int64, bool) {
13311332
return makeGoLangTypeLength(r.cols[index].ti)
13321333
}
13331334

13341335
// It should return
13351336
// the precision and scale for decimal types. If not applicable, ok should be false.
13361337
// The following are examples of returned values for various types:
1337-
// decimal(38, 4) (38, 4, true)
1338-
// int (0, 0, false)
1339-
// decimal (math.MaxInt64, math.MaxInt64, true)
1338+
//
1339+
// decimal(38, 4) (38, 4, true)
1340+
// int (0, 0, false)
1341+
// decimal (math.MaxInt64, math.MaxInt64, true)
13401342
func (r *Rowsq) ColumnTypePrecisionScale(index int) (int64, int64, bool) {
13411343
return makeGoLangTypePrecisionScale(r.cols[index].ti)
13421344
}

mssql_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ func TestCheckBadConn(t *testing.T) {
127127
{io.EOF, true, false, newRetryableError(io.EOF), false},
128128
{io.EOF, false, true, io.EOF, false},
129129
{io.EOF, true, true, io.EOF, false},
130-
{ErrorCancelConfirmation, false, false, ErrorCancelConfirmation, false},
131-
{ErrorCancelConfirmation, true, false, newRetryableError(ErrorCancelConfirmation), false},
132-
{ErrorCancelConfirmation, false, true, ErrorCancelConfirmation, false},
133-
{ErrorCancelConfirmation, true, true, ErrorCancelConfirmation, false},
134130
{netErr, false, false, netErr, false},
135131
{netErr, true, false, newRetryableError(netErr), false},
136132
{netErr, false, true, netErr, false},

queries_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,8 @@ func TestProcessQueryCancelConfirmationError(t *testing.T) {
14191419
t.Error("processQueryResponse expected to fail but it succeeded")
14201420
}
14211421
// should not fail with ErrBadConn because query was successfully sent to server
1422-
if err != ErrorCancelConfirmation {
1423-
t.Error("processQueryResponse expected to fail with ErrorCancelConfirmation error but failed with other error: ", err)
1422+
if !errors.As(err, &ServerError{}) {
1423+
t.Error("processQueryResponse expected to fail with ServerError error but failed with other error: ", err)
14241424
}
14251425

14261426
if conn.connectionGood {

token.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package mssql
33
import (
44
"context"
55
"encoding/binary"
6-
"errors"
76
"fmt"
87
"io"
98
"io/ioutil"
@@ -99,8 +98,6 @@ const (
9998
// TODO implement more flags
10099
)
101100

102-
var ErrorCancelConfirmation = errors.New("did not get cancellation confirmation from the server")
103-
104101
// interface for all tokens
105102
type tokenStruct interface{}
106103

@@ -961,7 +958,7 @@ func (t tokenProcessor) nextToken() (tokenStruct, error) {
961958
}
962959
// we did not get cancellation confirmation, something is not
963960
// right, this connection is not usable anymore
964-
return nil, ErrorCancelConfirmation
961+
return nil, ServerError{Error{Message: "did not get cancellation confirmation from the server"}}
965962
}
966963
}
967964

0 commit comments

Comments
 (0)