Jack Ling e0c032d1b1 fix(database/gdb): handle empty string in Fields() gracefully (#4700)
## 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):
```go
// 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)
2026-02-26 16:27:00 +08:00
2026-01-26 20:37:48 +08:00
dev
2017-07-04 18:31:39 +08:00
2025-12-27 16:07:23 +08:00
2026-01-26 20:37:48 +08:00

English | 简体中文

goframe logo

Go Reference GoFrame CI OpenSSF Scorecard CII Best Practices Go Report Card Code Coverage Production Ready License

Release GitHub pull requests GitHub closed pull requests GitHub issues GitHub closed issues Stars Forks Ask DeepWiki

A powerful framework for faster, easier, and more efficient project development.

Installation

go get -u github.com/gogf/gf/v2

Documentation

Contributors

💖 Thanks to all the contributors who made GoFrame possible 💖

goframe contributors

License

GoFrame is licensed under the MIT License, 100% free and open-source, forever.

Description
No description provided
Readme MIT 34 MiB
Languages
GO 100%