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

database/sql: Tx.Prepare documentation should match Tx.PrepareContext #45978

Closed
lcgfxy opened this issue May 5, 2021 · 2 comments
Closed

database/sql: Tx.Prepare documentation should match Tx.PrepareContext #45978

lcgfxy opened this issue May 5, 2021 · 2 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@lcgfxy
Copy link

lcgfxy commented May 5, 2021

What version of Go are you using (go version)?

$ go version
go version go1.14 linux/amd64

What did you do?

Tx.PrepareContext explicitly says that the returned statement "will be closed when the transaction has been committed or rolled back.". But The Tx.Prepare description just says the returned statement "can no longer be used once the transaction has been committed or rolled back."

It gave me the impression that Tx.Prepare caller needs to take care of closing the returned statement, so does the example as well.

What did you expect to see?

Since Tx.Prepare is just a call to Tx.PrepareContext with background context, I expected the document to state that returned statement "will be closed when the transaction has been committed or rolled back.", i.e. the same way as the Tx.PrepareContext description.

@lcgfxy
Copy link
Author

lcgfxy commented May 5, 2021

Just want to follow up about the Tx.Prepare example. It has the following:

	stmt, err := tx.Prepare("INSERT INTO projects(id, mascot, release, category) VALUES( ?, ?, ?, ? )")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close() // Prepared statements take up server resources and should be closed after use.

The line

defer stmt.Close()
further conveys the impression that Tx.Prepare caller needs to take care of closing the statement.

@seankhliao seankhliao changed the title https://golang.org/pkg/database/sql/#Tx.Prepare documentation is not accurate database/sql: Tx.Prepare documentation should match Tx.PrepareContext May 5, 2021
@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label May 5, 2021
@gopherbot
Copy link

Change https://golang.org/cl/339291 mentions this issue: sql: fix tx.Prepare documentation

@golang golang locked and limited conversation to collaborators Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants