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

Fix redundant rows.Close() calls in queryCode.tmpl #3856

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lushenle
Copy link

Description

This pull request addresses an issue in the generated query code template queryCode.tmpl where rows.Close() was being called multiple times. This change ensures that rows.Close() is only called once using defer, which is a best practice for resource management in Go.

Changes

  • Updated the queryCode.tmpl template to use defer rows.Close() for ensuring the rows are closed properly.
  • Removed the redundant rows.Close() call after the loop.

Rationale

Calling rows.Close() multiple times is unnecessary and can lead to potential issues. Using defer to close the rows ensures that the resource is properly released exactly once, following Go's best practices.

- Updated queryCode.tmpl to use defer for rows.Close()
- Ensured rows.Close() is called only once
- Improved resource management following Go best practices
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🔧 golang labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XS This PR changes 0-9 lines, ignoring generated files. 🔧 golang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant