Field of the BIT type

0 like 0 dislike
Try to be specific and clear.
In mysql a field of type bit(2) is used as a flag, i.e. for example the first bit — the recipient has deleted the message, the second bit of the sender deleted the message, a kind of double Boolean, the question of how to change each bit without removing the previous one?
I read somewhere about this but can not find.
To dig in the direction of the displacements?
by | 38 views

3 Answers

0 like 0 dislike
to set the rightmost bit 1: update the bitset set data=data | 1
to set the rightmost bit to 0: update the bitset set data=data &~ 1
other bits as well (2, 4, 8, 16 ...)
0 like 0 dislike
There are 2 links at the top, well, on the topic of the author, plus in the comments.
To this
Plus don't forget about the feature BIT in the mysql portability issues, etc.
If You talk about "each bit separately, without removing previous", then bits is still physically extracted, before your new bit will be recorded. Therefore, it is only about sql-change record a bit. Hence the binary operation is suitable.
PS: Incidentally, I note that a search on fucking again, not working. Well, it is, for lovers of shit and all, to know the place.
0 like 0 dislike
Use an integer field through the layer. NULL is understood as a FALSE unity 1 is TRUE.
The result:
1. Crossbase. At any time you can move from SQLite to MySQL and MySQL to PostgreSQL and Oracle, as well as exotic, and even a nosql database. Everything that supports the layer. If does not support — just write a new driver for the layer.
2. Not noticeable any significant changes in productivity and resources. Honestly, not much!
3. Convenient to use, convenient for programming, it is very convenient for standardization.
4. At any time you can extend the number of States of the entity. Pro stock there are 4 billion options...
110,608 questions
257,186 answers
32,904 users