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

Why does MySQL report an error when using bool #88

Closed
go-ltbf opened this issue Sep 6, 2021 · 4 comments
Closed

Why does MySQL report an error when using bool #88

go-ltbf opened this issue Sep 6, 2021 · 4 comments
Assignees

Comments

@go-ltbf
Copy link

go-ltbf commented Sep 6, 2021

Your Question

// definition
// ...
Visible   bool `json:"visible" gorm:"column:visible"`
Shareable bool `json:"shareable" gorm:"column:shareable"`
// ...

problem, err := p.Where(p.Visible.Is(true)).Where(p.ID.Eq(id)).First()

err:

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? AND `problem`.`id` = ? ORDER BY `problem`.`id` LIMIT 1' at line 1

debug sql:

SELECT * FROM `problem` WHERE `problem`.`visible` IS true AND `problem`.`id` = 1 ORDER BY `problem`.`id` LIMIT 1

I use this sql in cli is ok.

Expected answer

How to use bool type in query?

@go-ltbf
Copy link
Author

go-ltbf commented Sep 6, 2021

If I delete p.Visible.Is(true), no error will be reported

@go-ltbf
Copy link
Author

go-ltbf commented Sep 7, 2021

I found

var user User
db.Debug().Where("`users`.`status` IS true").First(&user, 1)

is ok.

but

var user User
db.Debug().Where("`users`.`status` IS ?", true).First(&user, 1)

will report err

@tr1v3r
Copy link
Member

tr1v3r commented Sep 7, 2021

yeah,

Where("`users`.`status` = ?", true)

is ok, too. I will fix it ASAP

@go-ltbf go-ltbf closed this as completed Sep 7, 2021
@tr1v3r
Copy link
Member

tr1v3r commented Sep 7, 2021

fix commit: 84b7f5d

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

3 participants