Skip to content
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

mysql: In some cases, the generated sql statement has a BUG #2643

Closed
sanrentai opened this issue May 12, 2023 · 1 comment
Closed

mysql: In some cases, the generated sql statement has a BUG #2643

sanrentai opened this issue May 12, 2023 · 1 comment
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@sanrentai
Copy link
Contributor

1. What version of Go and system type/arch are you using?

go version go1.20.3 windows/amd64

2. What version of GoFrame are you using?

v2.4.1

3. Can this issue be re-produced with the latest release?

yes

4. What did you do?

// CREATE TABLE `tt` (
//	`id` INT(10) NULL DEFAULT NULL,
//	`name` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_0900_ai_ci',
//	`value` INT(10) NULL DEFAULT NULL,
//	`dept` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_0900_ai_ci'
//)
//COLLATE='utf8mb4_0900_ai_ci'
// ENGINE=InnoDB
g.DB().Model("tt").As("s").
		Fields(
			"s.name", // 这field写上会导致BUG出现
			"replace(concat_ws(',',lpad(s.id, 6, '0'),s.name),',','') `code`",
		).
		All()
g.DB().Model("tt").As("s").
		Fields(
			"CASE WHEN dept='物资部' THEN '物资部' ELSE '其他' END dept",
			"sum(s.value)",
		).Group("CASE WHEN dept='物资部' THEN '物资部' ELSE '其他' END"). // 这个CASE 会被引号包围
		All()

5. What did you expect to see?

SELECT s.name,replace(concat_ws(',',lpad(s.id,6,'0'),s.name),',','') `code` FROM `tt` AS s

SELECT CASE WHEN dept='物资部' THEN '物资部' ELSE '其他' END dept,sum(s.value) FROM `tt` AS s GROUP BY CASE WHEN dept='物资部' THEN '物资部' ELSE '其他' END

6. What did you see instead?

SELECT s.name,replace(concat_ws(',',lpad(s.id,'0'),s.name),',','') `code` FROM `tt` AS s

SELECT CASE WHEN dept='物资部' THEN '物资部' ELSE '其他' END dept,sum(s.value) FROM `tt` AS s GROUP BY `CASE` WHEN dept='物资部' THEN '物资部' ELSE '其他' END
@Issues-translate-bot Issues-translate-bot changed the title mysql: 某些情况下,生成的sql语句有BUG mysql: In some cases, the generated sql statement has a BUG May 12, 2023
@gqcn gqcn added the bug It is confirmed a bug, but don't worry, we'll handle it. label Aug 21, 2023
@gqcn gqcn self-assigned this Aug 21, 2023
@gqcn gqcn added the wip label Feb 5, 2024
gqcn added a commit that referenced this issue Feb 5, 2024
@gqcn gqcn added done This issue is done, which may be release in next version. and removed wip labels Feb 5, 2024
@gqcn
Copy link
Member

gqcn commented Feb 5, 2024

#3304

@gqcn gqcn closed this as completed Feb 5, 2024
gqcn added a commit that referenced this issue Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants