Closed 370750149 closed 3 years ago
I'm sorry for bad code.
my code:
_,err=tx.ExecContext(context.TODO(),"dbo.sp_xxx :flag,:msg", sql.Named("flag",sql.Out{Dest:&flag}),sql.Named("msg",sql.Out{Dest:&msg}))
and I get a mssql error like ''formal parameter @flag not defind to output..."
Two hours later,I read the source code,foud in file mssql.go at line 561:
decls[i] = fmt.Sprintf("%s %s", name, makeDecl(params[i+offset].ti))
the value like
@flag nvarchar(max)
but '@flag' is an output parameter
then I change to:
if params[i+offset].Flags==1 {
decls[i] = fmt.Sprintf("%s %s output", name, makeDecl(params[i+offset].ti))
} else {
decls[i] = fmt.Sprintf("%s %s", name, makeDecl(params[i+offset].ti))
}
the value like:
@flag nvarchar(max) output
and it run success!
I don't known what is the usuage that property 'Flags' in struct 'param',what trouble will be happend after the source code changed?
While I used and tracked the code,like: golang's version is 1.15.3,go-mssqldb's version is v0.9.0 1.my code: tx, err := db.Begin()
2.golang code 'database/sql.go' at line 1553
at:
parameter "dc.ci" is reference to "*.../go-mssqldb/Conn",then I read the source code,found the Struct "Conn" not implement the interface "driver.Execer" or "driver.ExecerContext" at last,the code run as the query statment and painc error,expect 0 arguments,got 2. What's the right way to call the procedure and handle output parameter values?