Skip to content

fix(database/gdb): handle empty string in Fields() gracefully#4700

Merged
gqcn merged 1 commit intogogf:masterfrom
lingcoder:fix/issue-4697-fields-empty-string
Feb 26, 2026
Merged

fix(database/gdb): handle empty string in Fields() gracefully#4700
gqcn merged 1 commit intogogf:masterfrom
lingcoder:fix/issue-4697-fields-empty-string

Conversation

@lingcoder
Copy link
Copy Markdown
Contributor

@lingcoder lingcoder commented Feb 13, 2026

Summary

Fix bug where Fields("") with empty string generates invalid SQL SELECT FROM table.

Root Cause

mappingAndFilterToTableFields method doesn't skip empty strings when processing fields:

  • gstr.SplitAndTrim("", ",") returns empty array
  • No fields added to query
  • Results in invalid SQL: SELECT FROM table

Fix

Skip empty string fields in mappingAndFilterToTableFields (line 97-100):

// Skip empty string fields
if fieldStr == "" {
    continue
}

Behavior Changes

  • Fields("") → SELECT * FROM table (uses default)
  • Fields("", "id") → SELECT id FROM table (ignores empty string)
  • Fields("id", "", "nickname") → SELECT id, nickname FROM table

Tests

Added Test_Issue4697 with 3 scenarios covering all cases above.

Related

Fixes #4697
Ref #4703 (discovered during pagination test development)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lingcoder lingcoder force-pushed the fix/issue-4697-fields-empty-string branch from 2c45f57 to a6bd50f Compare February 26, 2026 03:07
@lingcoder
Copy link
Copy Markdown
Contributor Author

已调整

@lingcoder lingcoder force-pushed the fix/issue-4697-fields-empty-string branch from a6bd50f to c0faf36 Compare February 26, 2026 05:43
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
@lingcoder lingcoder force-pushed the fix/issue-4697-fields-empty-string branch from c0faf36 to ec14131 Compare February 26, 2026 06:32
@gqcn gqcn changed the title fix(gdb): handle empty string in Fields() gracefully fix(database/gdb): handle empty string in Fields() gracefully Feb 26, 2026
@gqcn gqcn merged commit e0c032d into gogf:master Feb 26, 2026
18 checks passed
@lingcoder lingcoder deleted the fix/issue-4697-fields-empty-string branch February 28, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

database/gdb: Fields with empty string generates invalid SQL

3 participants