fix(database/gdb): handle empty string in Fields() gracefully#4700
Merged
gqcn merged 1 commit intogogf:masterfrom Feb 26, 2026
Merged
fix(database/gdb): handle empty string in Fields() gracefully#4700gqcn merged 1 commit intogogf:masterfrom
gqcn merged 1 commit intogogf:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a gdb.Model.Fields("") edge case that could lead to generating invalid SQL (SELECT FROM table) by ignoring empty-string field inputs so the query falls back to the default field selection.
Changes:
- Skip empty-string field entries during field mapping/filtering in
mappingAndFilterToTableFields. - Add a MySQL driver regression test covering
Fields("")and mixed empty/non-empty field inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| database/gdb/gdb_model_utility.go | Ignores empty-string field tokens during field mapping to prevent empty select lists. |
| contrib/drivers/mysql/mysql_z_unit_issue_test.go | Adds regression coverage for issue #4697 (empty-string fields). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2c45f57 to
a6bd50f
Compare
Contributor
Author
|
已调整 |
gqcn
requested changes
Feb 26, 2026
a6bd50f to
c0faf36
Compare
When Fields("") is called with empty string parameter, it now ignores
the empty string and behaves as if Fields() was not called, resulting
in SELECT * instead of invalid SQL "SELECT FROM table".
Also handles mixed cases like Fields("", "id") and Fields("id", "", "nickname")
by filtering out empty strings while keeping valid field names.
Fixes gogf#4697
c0faf36 to
ec14131
Compare
gqcn
approved these changes
Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix bug where
Fields("")with empty string generates invalid SQLSELECT FROM table.Root Cause
mappingAndFilterToTableFieldsmethod doesn't skip empty strings when processing fields:gstr.SplitAndTrim("", ",")returns empty arraySELECT FROM tableFix
Skip empty string fields in
mappingAndFilterToTableFields(line 97-100):Behavior Changes
Fields("")→ SELECT * FROM table (uses default)Fields("", "id")→ SELECT id FROM table (ignores empty string)Fields("id", "", "nickname")→ SELECT id, nickname FROM tableTests
Added
Test_Issue4697with 3 scenarios covering all cases above.Related
Fixes #4697
Ref #4703 (discovered during pagination test development)