in reply to Re: Flipping bits and using flags
in thread Flipping bits and using flags

Hey this is much appreciated but you missed the mark on this one unfortunately. In MySQL the sets can either be inserted by name or by inserting a number that corresponds to the numeric value given that element that is in the set. For example:

In a table I have a field of type SET that is defined this way:

"Dog","Cat","Bird","Reptile","Horse","Fish"

MySQL allows you to either insert the set as one or many of the elements.

A person says they have a Dog, Cat and a Fish. So it can be inserted as a list: 'Dog','Cat','Fish'

The other way it can be inserted is by a number that represents the binary value. MySQL assigns a numberic value to each of the set's elements like so:

"Dog" => 1, "Cat" => 2, "Bird" => 4, "Reptile" => 8, "Horse" => 16, "Fish" => 32

Basically it's like a bit flag. MySQL allows up to 64 elements in a set. So if I were to insert by number I would add up the values for the elements. 1+2+4 = 7, when you insert 7, MySQL takes it as inserting 'Dog','Cat','Bird'. It's like using a binary flag.

BMaximus