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

WhereHolder key with trailing spaces is incorrectly translated #1934

Closed
Hao-Wu opened this issue Jun 24, 2022 · 3 comments
Closed

WhereHolder key with trailing spaces is incorrectly translated #1934

Hao-Wu opened this issue Jun 24, 2022 · 3 comments
Labels
done This issue is done, which may be release in next version. enhancement inactive

Comments

@Hao-Wu
Copy link

Hao-Wu commented Jun 24, 2022

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

go version go1.17.3 darwin/amd64

2. What version of GoFrame are you using?

v2.0.4

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

Yes

4. What did you do?

Query ORM,
Note, there is a space before and after id

r, _ := g.Model("testTableName").Where(" id ", 1000).One()

5. What did you expect to see?

Correct Mysql query should be translated and executed

SELECT * FROM `testTableName` WHERE  id = '1000'  LIMIT 1

6. What did you see instead?

Wrong SQL is translated, the condition value is missing

2022-06-24 12:49:32.654 [ERRO] {3098224b3875fb16cd5b61186100e7ea} [ 27 ms] [default] [rows:0  ] SELECT * FROM `testTableName` WHERE  id  LIMIT 1
Error: sql: expected 0 arguments, got 1 

Summary:

It is very common for developers to add(or mistakenly add) spaces to the WhereHolder, could we do some improvements to make it be compatible with this scenario?

I made a debug of gdb, maybe Trim leading and trailing spaces on WhereHolder in formatWhereHolder() is an easy resolution.

@Hao-Wu
Copy link
Author

Hao-Wu commented Jun 24, 2022

If it is necessary, I'd like to make a PR to resolve this issue.

@gqcn
Copy link
Member

gqcn commented Oct 11, 2022

@Hao-Wu Good suggestion, let me handle this.

gqcn added a commit that referenced this issue Oct 11, 2022
@gqcn gqcn added the done This issue is done, which may be release in next version. label Oct 11, 2022
@gqcn gqcn closed this as completed Oct 11, 2022
gqcn added a commit that referenced this issue Oct 13, 2022
@Hao-Wu
Copy link
Author

Hao-Wu commented Oct 17, 2022

verified,
cool, thanks

houseme pushed a commit that referenced this issue Oct 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done This issue is done, which may be release in next version. enhancement inactive
Projects
None yet
Development

No branches or pull requests

2 participants