Skip to content

Commit

Permalink
return ServerError when failed to get cancelation confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eygin Semen Leonidovich committed Nov 15, 2022
1 parent 85e531a commit ece4f99
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
48 changes: 25 additions & 23 deletions mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

// ReturnStatus may be used to return the return value from a proc.
//
// var rs mssql.ReturnStatus
// _, err := db.Exec("theproc", &rs)
// log.Printf("return status = %d", rs)
// var rs mssql.ReturnStatus
// _, err := db.Exec("theproc", &rs)
// log.Printf("return status = %d", rs)
type ReturnStatus int32

var driverInstance = &Driver{processQueryText: true}
Expand Down Expand Up @@ -243,8 +243,6 @@ func (c *Conn) checkBadConn(ctx context.Context, err error, mayRetry bool) error
return nil
case io.EOF:
c.connectionGood = false
case ErrorCancelConfirmation:
c.connectionGood = false
case driver.ErrBadConn:
// It is an internal programming error if driver.ErrBadConn
// is ever passed to this function. driver.ErrBadConn should
Expand Down Expand Up @@ -879,22 +877,24 @@ func (r *Rows) ColumnTypeDatabaseTypeName(index int) string {
// not a variable length type ok should return false.
// If length is not limited other than system limits, it should return math.MaxInt64.
// The following are examples of returned values for various types:
// TEXT (math.MaxInt64, true)
// varchar(10) (10, true)
// nvarchar(10) (10, true)
// decimal (0, false)
// int (0, false)
// bytea(30) (30, true)
//
// TEXT (math.MaxInt64, true)
// varchar(10) (10, true)
// nvarchar(10) (10, true)
// decimal (0, false)
// int (0, false)
// bytea(30) (30, true)
func (r *Rows) ColumnTypeLength(index int) (int64, bool) {
return makeGoLangTypeLength(r.cols[index].ti)
}

// It should return
// the precision and scale for decimal types. If not applicable, ok should be false.
// The following are examples of returned values for various types:
// decimal(38, 4) (38, 4, true)
// int (0, 0, false)
// decimal (math.MaxInt64, math.MaxInt64, true)
//
// decimal(38, 4) (38, 4, true)
// int (0, 0, false)
// decimal (math.MaxInt64, math.MaxInt64, true)
func (r *Rows) ColumnTypePrecisionScale(index int) (int64, int64, bool) {
return makeGoLangTypePrecisionScale(r.cols[index].ti)
}
Expand Down Expand Up @@ -1321,22 +1321,24 @@ func (r *Rowsq) ColumnTypeDatabaseTypeName(index int) string {
// not a variable length type ok should return false.
// If length is not limited other than system limits, it should return math.MaxInt64.
// The following are examples of returned values for various types:
// TEXT (math.MaxInt64, true)
// varchar(10) (10, true)
// nvarchar(10) (10, true)
// decimal (0, false)
// int (0, false)
// bytea(30) (30, true)
//
// TEXT (math.MaxInt64, true)
// varchar(10) (10, true)
// nvarchar(10) (10, true)
// decimal (0, false)
// int (0, false)
// bytea(30) (30, true)
func (r *Rowsq) ColumnTypeLength(index int) (int64, bool) {
return makeGoLangTypeLength(r.cols[index].ti)
}

// It should return
// the precision and scale for decimal types. If not applicable, ok should be false.
// The following are examples of returned values for various types:
// decimal(38, 4) (38, 4, true)
// int (0, 0, false)
// decimal (math.MaxInt64, math.MaxInt64, true)
//
// decimal(38, 4) (38, 4, true)
// int (0, 0, false)
// decimal (math.MaxInt64, math.MaxInt64, true)
func (r *Rowsq) ColumnTypePrecisionScale(index int) (int64, int64, bool) {
return makeGoLangTypePrecisionScale(r.cols[index].ti)
}
Expand Down
4 changes: 0 additions & 4 deletions mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ func TestCheckBadConn(t *testing.T) {
{io.EOF, true, false, newRetryableError(io.EOF), false},
{io.EOF, false, true, io.EOF, false},
{io.EOF, true, true, io.EOF, false},
{ErrorCancelConfirmation, false, false, ErrorCancelConfirmation, false},
{ErrorCancelConfirmation, true, false, newRetryableError(ErrorCancelConfirmation), false},
{ErrorCancelConfirmation, false, true, ErrorCancelConfirmation, false},
{ErrorCancelConfirmation, true, true, ErrorCancelConfirmation, false},
{netErr, false, false, netErr, false},
{netErr, true, false, newRetryableError(netErr), false},
{netErr, false, true, netErr, false},
Expand Down
4 changes: 2 additions & 2 deletions queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,8 @@ func TestProcessQueryCancelConfirmationError(t *testing.T) {
t.Error("processQueryResponse expected to fail but it succeeded")
}
// should not fail with ErrBadConn because query was successfully sent to server
if err != ErrorCancelConfirmation {
t.Error("processQueryResponse expected to fail with ErrorCancelConfirmation error but failed with other error: ", err)
if !errors.As(err, &ServerError{}) {
t.Error("processQueryResponse expected to fail with ServerError error but failed with other error: ", err)
}

if conn.connectionGood {
Expand Down
5 changes: 1 addition & 4 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mssql
import (
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -99,8 +98,6 @@ const (
// TODO implement more flags
)

var ErrorCancelConfirmation = errors.New("did not get cancellation confirmation from the server")

// interface for all tokens
type tokenStruct interface{}

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

Expand Down

0 comments on commit ece4f99

Please sign in to comment.