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

Open
lcgfxy opened this issue May 5, 2021 · 1 comment
Open

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

lcgfxy opened this issue May 5, 2021 · 1 comment

Comments

@lcgfxy
Copy link

@lcgfxy 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants