Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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

Open
lushenle wants to merge 1 commit into sqlc-dev:main
base: main
Choose a base branch
Loading
from lushenle:fix-rows-close-issue

Conversation

Copy link

@lushenle lushenle commented Feb 21, 2025

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.

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🔧 golang labels Feb 21, 2025
- 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:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
size:L This PR changes 100-499 lines, ignoring generated files. 🔧 golang
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /