in reply to Flipping bits and using flags
One thing you will need to be aware of when dealing with MySQL SET types is that unless you are using a perl that is built for either a 64-bit platform, or has been built to enable 64-bit ints, if you attempt to manipulate them using the math operators, you are likely to come unstuck, as they will probably be converted to doubles and they only support 53-bits of precision.
If your on a 32-bit platform you should treat them as 8 byte strings (carefully avoiding allowing them to get treated as unicode!), and only use vec to access the bits. The downside of that is that depending upon your platform vec may index the bits in a different order to the way they are described by the MySQL docs. That's most likely to be the case if (for example), the MySQL server was running on a Solaris box and your program on Intel; or vice versa; or many other combinations.
The only sure way to know will be to experiment with setting a few bits, insert them into your DB and then query the DB via it's own client to see which interpretation it puts upon the bits you set.
The alternative would be to use pack & unpack with either 'b64' or 'B64' as appropriate to expand the bits into an array. If your program needs to run cross platform, you could do something like:
use Config; my $setTemplate; if( $Config{ byteorder } eq '1234' ) { $setTemplate = 'B64'; } elsif( $Config{ byteorder } eq '3412' ) { $setTemplate = 'b64'; } else { die "What kind of cpu are you using for dogs sake:)!"; } ...
Note: The above is untested and I probably have guessed wrong about which template goes with which ordering!
|
|---|