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 #72

Open
PhoenixL0911 opened this issue Sep 14, 2023 · 0 comments
Open

按条件判断拼接查询bug #72

PhoenixL0911 opened this issue Sep 14, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@PhoenixL0911
Copy link
Contributor

PhoenixL0911 commented Sep 14, 2023

伪代码如下:

        // 变量 user 为入参
	query, u := gplus.NewQuery[User]()
	query.Eq(&u.Password, "12345678").Or(func(q *gplus.QueryCond[User]) {
		q.EqCond(user.Id > 0,&u.Id, user.Id).
			Or().EqCond(len(user.Account) > 0, &u.Account, user.Account).
			Or().EqCond(len(user.Email) > 0, &u.Email, user.Email).
			Or().EqCond(len(user.Phone) > 0, &u.Phone, user.Phone)
	}).OrderByAsc(&u.Id)

当条件为false时,EqCond的条件不会加入到sql中,但是因为前面用了一个Or()作为条件关系,会出现这种情况:

SELECT * FROM `user` WHERE password = '12345678' OR ( id = 0 OR account = 'admin' OR )  ORDER BY id ASC LIMIT 1

应该所有的*Cond条件函数,在使用Or()或者And()之后都会出现这种情况,需要做特殊的适配,AndCond()和OrCond()没办法用在这种条件分组的情况

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants