Open
Description
openedon Jul 9, 2024
Describe the bug
RowsAffected()
returned incorrect value.
To Reproduce
package main
import (
"context"
"database/sql"
"fmt"
"log"
_ "github.com/microsoft/go-mssqldb"
)
func main() {
server := "???"
user := "???"
password := "???"
port := 1433
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d", server, user, password, port)
conn, err := sql.Open("mssql", connString)
if err != nil {
panic(err)
}
defer conn.Close()
ctx := context.Background()
countrow := conn.QueryRow("select count(id) from objects where id = 1;")
if err := countrow.Err(); err != nil {
panic(err)
}
var count int64
err = countrow.Scan(&count)
if err != nil {
panic(err)
}
log.Println("count", count) // output: 1
result, err := conn.ExecContext(ctx, "update objects set value = 'test' where id = 1;")
if err != nil {
panic(err)
}
rowsAffected, _ := result.RowsAffected()
log.Println("rowsAffected", rowsAffected) // output: 3
}
Output
2024/07/09 13:28:15 count 1
2024/07/09 13:28:15 rowsAffected 3
Expected behavior
Following the reproduce code, it should be 1 that returned from result.RowsAffected()
.
Further technical details
SQL Server version: SQL Server 2017
go-mssqldb: v1.7.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels