golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.98k stars 17.67k forks source link

database/sql if err == nil set needReset = true #49809

Closed mopo3ilo closed 2 years ago

mopo3ilo commented 2 years ago

If error == nil then the needReset set true and each db.Exec reseted session

$ go version go1.17.3 linux/amd64

https://github.com/golang/go/blob/bf88adadac9bbb1b190ba7af1010373823dabb06/src/database/sql/sql.go#L528-L530

https://github.com/golang/go/blob/bf88adadac9bbb1b190ba7af1010373823dabb06/src/database/sql/sql.go#L1445-L1450

seankhliao commented 2 years ago

What's the problem with that? From the CL that added it:

Most sessions have a way to reset the session state which is desirable to prevent one bad query from poisoning another later query with temp table name conflicts or other persistent session resources.

mopo3ilo commented 2 years ago

What's the problem with that? From the CL that added it:

Example: Parallel gorutines, in each first Exec create temporary tables, next execs use this tables and update data in db

seankhliao commented 2 years ago

That;s not safe, use DB.Conn if you need sessions