Forum: Ruby on Rails Active Record, MySQL 5 BIT field

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
John M Lauck (Guest)
on 2007-01-17 23:01
(Received via mailing list)
I have a an AR object model/table with a bit field of size 7.   When
creating a new record rails has no problem if I just specify an integer
value in place of the bit field value (ideally it should be able to
handle b'1010101' as mysql does).   Pulling the data out of the table
is a bit strange.  I've been experimenting with
model.field.unpack('B*').  This should return all the bits in the
field, which I would assume is a string of 7 bits. However, this isn't
the case.  Instead it returns a string of 8 bits.  Using unpack('B7')
it chops off the least significant bit.  Apparently there is a '0' bit
appended to the bit string in the place of the most significant bit.

I'm not sure if this is an issue with Rails' ActiveRecord, ruby, mysql
5, my ignorance or some combination of these.

Does anyone have any ideas or an explanation?


This topic is locked and can not be replied to.