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

Stored Procedure returned status code is not extracted immediately when calling through QueryContext #775

Open
mihailboev opened this issue Dec 2, 2022 · 1 comment

Comments

@mihailboev
Copy link

mihailboev commented Dec 2, 2022

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.

@Breeze0806
Copy link

It is not a bug. You'd better get error from Rows.Error() after Rows.Next()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants