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

[bug] ORM builder with OmitEmpty generate wrong SQL #2782

Closed
Agzer0 opened this issue Jul 19, 2023 · 0 comments
Closed

[bug] ORM builder with OmitEmpty generate wrong SQL #2782

Agzer0 opened this issue Jul 19, 2023 · 0 comments

Comments

@Agzer0
Copy link
Contributor

Agzer0 commented Jul 19, 2023

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

go1.20.3

2. What version of GoFrame are you using?

v2.4.0

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

Yes

4. What did you do?

table schema:

CREATE TABLE `doctor` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `mobile` varchar(15) NOT NULL,
  `name` varchar(50) NOT NULL ,
  `status` tinyint(1) unsigned NOT NULL DEFAULT '1' ,
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
// dao.Doctor is gf generate dao struct
m := dao.Doctor.Ctx(gctx.New())

var doctor entity.Doctor
_ = m.Where("mobile", "").
		Where(m.Builder().Where("id", 1).WhereOrLike("name", "foo")).
		Where("status", 2).
		OmitEmpty().Scan(&doctor)
// expect sql: 
// SELECT `id` FROM `doctor` WHERE ((`id`=1) OR (`name` LIKE 'foo')) AND (`status`=2) AND `deleted_at` IS NULL LIMIT 1

// But the generated SQL below is wrong:
// The first statement is filtered out, second is a nested statement, but it's been expanded to the level of the third statement
// SELECT `id` FROM `doctor` WHERE ((`id`=1) OR (`name` LIKE 'foo') AND (`status`=2)) AND `deleted_at` IS NULL LIMIT 1
@Agzer0 Agzer0 changed the title [bug] ORM builder with OmitEmpty generate SQL error [bug] ORM builder with OmitEmpty generate wrong SQL Jul 19, 2023
Agzer0 pushed a commit to Agzer0/gf that referenced this issue Jul 20, 2023
Agzer0 pushed a commit to Agzer0/gf that referenced this issue Jul 20, 2023
@Agzer0 Agzer0 closed this as completed Jul 31, 2023
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

No branches or pull requests

1 participant