This project is archived and is in readonly mode.
ActiveRecord: boolean support with bit(1) MySQL data type
Reported by Antonio Espinosa | December 2nd, 2010 @ 03:32 PM
BIT MySQL data type was added in MySQL 5.0.3 for MyISAM, and extended in 5.0.5 to MEMORY, InnoDB, BDB, and NDBCLUSTER. Before 5.0.3, BIT is a synonym for TINYINT(1).
os: Windows XP
gem mysql: 2.8.1
mysql server: 5.0.41
Activerecord#column_name? return false instead of true when using datatype "bit(1)" with mysql and the value in the database is 1 (true).
To support the bit data type, I have changed the following files:
def value_to_boolean(value) if value.is_a?(String) && value.blank? nil else +++ value = value.ord if value.is_a?(String) && value.ord < 2 # Support bit(1) mysql datatype for bool TRUE_VALUES.include?(value) end end
def simplified_type(field_type) # return :boolean if MysqlAdapter.emulate_booleans && field_type.downcase.index("tinyint(1)") +++ return :boolean if MysqlAdapter.emulate_booleans && field_type =~ /tinyint\(1\)|bit/i return :string if field_type =~ /enum/i super end
def extract_limit(sql_type) case sql_type when /blob|text/i case sql_type when /tiny/i 255 ... when /^tinyint/i; 1 +++ when /^bit/i; 1 else super end end
Comments and changes to this ticket
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>