Skip to content

How can set/where Bitwise Operators #213

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

Closed
LH-gulongfei opened this issue Jul 8, 2020 · 4 comments · Fixed by #220
Closed

How can set/where Bitwise Operators #213

LH-gulongfei opened this issue Jul 8, 2020 · 4 comments · Fixed by #220

Comments

@LH-gulongfei
Copy link

I want
update table set tag = tag | 2 where tag & 2 = 2

@andruet
Copy link

andruet commented Jul 19, 2020

Have you found a solution? I encountered the same problem.

@jeffgbutler
Copy link
Member

You should be able to code your own functions for bitwise operators. You can use the included functions as examples: https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/main/java/org/mybatis/dynamic/sql/select/function

@andruet
Copy link

andruet commented Jul 19, 2020

Why not directly support these common operations? Or a simple construction method for these common operations.

@LH-gulongfei
Copy link
Author

Have you found a solution? I encountered the same problem.

public SqlColumn bitEquleTo(SqlColumn column, int bit){
return SqlTable.of("dynamic").column(String.format("%s & %s"),column.name(), bit),JDBCType,INTEGER);
}

demo:
// select * from table where flag & 4 = 4
mapper.select(x -> x.where(bitEqualTo(flag, 4), isEqualTo(4))

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

Successfully merging a pull request may close this issue.

3 participants