Skip to content

Commit

Permalink
Fix sql.RawBytes corruption issue (#1523)
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 authored Dec 13, 2023
1 parent fc589cb commit 2cdf624
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3183,25 +3183,26 @@ func TestRawBytesAreNotModified(t *testing.T) {
if err != nil {
dbt.Fatal(err)
}
defer rows.Close()

var b int
var raw sql.RawBytes
for rows.Next() {
if err := rows.Scan(&b, &raw); err != nil {
dbt.Fatal(err)
}
if !rows.Next() {
dbt.Fatal("expected at least one row")
}
if err := rows.Scan(&b, &raw); err != nil {
dbt.Fatal(err)
}

before := string(raw)
// Ensure cancelling the query does not corrupt the contents of `raw`
cancel()
time.Sleep(time.Microsecond * 100)
after := string(raw)
before := string(raw)
// Ensure cancelling the query does not corrupt the contents of `raw`
cancel()
time.Sleep(time.Microsecond * 100)
after := string(raw)

if before != after {
dbt.Fatalf("the backing storage for sql.RawBytes has been modified (i=%v)", i)
}
if before != after {
dbt.Fatalf("the backing storage for sql.RawBytes has been modified (i=%v)", i)
}
rows.Close()
}()
}
})
Expand Down

0 comments on commit 2cdf624

Please sign in to comment.