-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Go version
go version go1.25.0 linux/amd64
GoFrame version
v2 (master branch, commit sha: latest)
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
Called AllAndCount(true) with multiple fields specified:
result, count, err := db.Model(table).Fields("id, nickname").AllAndCount(true)Test case reference: Test_Model_AllAndCount_MultipleFields_WithTotal in PR #4703
What did you see happen?
The framework generated invalid COUNT SQL with field list instead of COUNT(*):
SELECT COUNT(id, nickname) FROM `user_xxx`
^^ Invalid - COUNT takes 1 argumentSQL execution error:
Error 1064 (42000): You have an error in your SQL syntax ... near ', nickname) FROM ...'
Root cause: When AllAndCount(true) is used with multiple fields, the COUNT query incorrectly includes the field list.
What did you expect to see?
When using AllAndCount(true) with any fields configuration:
-- Data query (correct)
SELECT id, nickname FROM `user_xxx`
-- Count query (should always use COUNT(*) or COUNT(1))
SELECT COUNT(*) FROM `user_xxx`The count query should always use COUNT(*) or COUNT(1), regardless of the fields specified in the data query.
Additional Context
- Parent issue: contrib/drivers: comprehensive database driver test coverage improvement plan #4689 (comprehensive database driver test coverage)
- Discovered in: PR test(mysql): add pagination and error handling tests #4703 while adding pagination tests
- Affected drivers: All database drivers
- Regression test: Added in PR test(mysql): add pagination and error handling tests #4703
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels