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

Implement stringer interface #746

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions error.go
Expand Up @@ -14,7 +14,7 @@ type Error struct {
Number int32
State uint8
Class uint8
Message string
Message Message
ServerName string
ProcName string
LineNo int32
Expand All @@ -23,8 +23,14 @@ type Error struct {
All []Error
}

type Message string

func (e Error) Error() string {
return "mssql: " + e.Message
return "mssql: " + e.Message.String()
}

func (m Message) String() string {
return string(m)
}

// SQLErrorNumber returns the SQL Server error number.
Expand All @@ -41,7 +47,7 @@ func (e Error) SQLErrorClass() uint8 {
}

func (e Error) SQLErrorMessage() string {
return e.Message
return e.Message.String()
}

func (e Error) SQLErrorServerName() string {
Expand Down
4 changes: 2 additions & 2 deletions queries_go19_test.go
Expand Up @@ -1125,10 +1125,10 @@ func TestMessageQueue(t *testing.T) {
active := true

msgs := []interface{}{
sqlexp.MsgNotice{Message: "msg1"},
sqlexp.MsgNotice{Message: Message("msg1")},
sqlexp.MsgNext{},
sqlexp.MsgRowsAffected{Count: 1},
sqlexp.MsgNotice{Message: "msg2"},
sqlexp.MsgNotice{Message: Message("msg2")},
sqlexp.MsgNextResultSet{},
}
i := 0
Expand Down
8 changes: 4 additions & 4 deletions token.go
Expand Up @@ -601,7 +601,7 @@ func parseError72(r *tdsBuffer) (res Error) {
res.Number = r.int32()
res.State = r.byte()
res.Class = r.byte()
res.Message = r.UsVarChar()
res.Message = Message(r.UsVarChar())
res.ServerName = r.BVarChar()
res.ProcName = r.BVarChar()
res.LineNo = r.int32()
Expand All @@ -615,7 +615,7 @@ func parseInfo(r *tdsBuffer) (res Error) {
res.Number = r.int32()
res.State = r.byte()
res.Class = r.byte()
res.Message = r.UsVarChar()
res.Message = Message(r.UsVarChar())
res.ServerName = r.BVarChar()
res.ProcName = r.BVarChar()
res.LineNo = r.int32()
Expand Down Expand Up @@ -773,7 +773,7 @@ func processSingleResponse(ctx context.Context, sess *tdsSession, ch chan tokenS
}
errs = append(errs, err)
if sess.logFlags&logErrors != 0 {
sess.logger.Log(ctx, msdsn.LogErrors, err.Message)
sess.logger.Log(ctx, msdsn.LogErrors, err.Message.String())
}
if outs.msgq != nil {
_ = sqlexp.ReturnMessageEnqueue(ctx, outs.msgq, sqlexp.MsgError{Error: err})
Expand All @@ -784,7 +784,7 @@ func processSingleResponse(ctx context.Context, sess *tdsSession, ch chan tokenS
sess.logger.Log(ctx, msdsn.LogDebug, fmt.Sprintf("got INFO %d %s", info.Number, info.Message))
}
if sess.logFlags&logMessages != 0 {
sess.logger.Log(ctx, msdsn.LogMessages, info.Message)
sess.logger.Log(ctx, msdsn.LogMessages, info.Message.String())
}
if outs.msgq != nil {
_ = sqlexp.ReturnMessageEnqueue(ctx, outs.msgq, sqlexp.MsgNotice{Message: info.Message})
Expand Down