go-mssqldb
go-mssqldb copied to clipboard
Stored Procedure returned status code is not extracted immediately when calling through QueryContext
Given a procedure that returns both a status code and a recordset, e.g.
ALTER procedure [dbo].[LoadConfigs]
as
set nocount on
select
[IdConfig],
[Value]
from dbo.Config
return 101
called as
var rs mssql.ReturnStatus
rows, err := db.QueryContext(ctx, "theproc", &rs)
if err != nil {
return err
}
if rs != 0 {
return errors.New("SP returned non-zero status")
}
for rows.Next() {
err = rows.Scan(&val)
//Do stuff with val
}
we are expecting that the return status will be set immediately after QueryContext returns with no errors (based on the implementation in mssql.go, processQueryResponse())
What we are observing is that the return status remains zero because processQueryResponse() breaks its parsing of tokens as soon as it encounters a []columnStruct token.
Note: Return status is then filled by Rows.Next() when it encounters a Return Status token.
It is not a bug. You'd better get error from Rows.Error() after Rows.Next()