Skip to content

Commit

Permalink
Merge pull request #5173 from kennyj/fix_3931-2
Browse files Browse the repository at this point in the history
Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931 (Try again).
  • Loading branch information
tenderlove committed Feb 27, 2012
2 parents 9ad7767 + fe7cacb commit a19dd29
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -484,15 +484,26 @@ def rename_column(table_name, column_name, new_column_name) #:nodoc:


# Maps logical Rails types to MySQL-specific data types. # Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil) def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer' case type.to_s

when 'integer'
case limit case limit
when 1; 'tinyint' when 1; 'tinyint'
when 2; 'smallint' when 2; 'smallint'
when 3; 'mediumint' when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default when nil, 4, 11; 'int(11)' # compatibility with MySQL default
when 5..8; 'bigint' when 5..8; 'bigint'
else raise(ActiveRecordError, "No integer type has byte size #{limit}") else raise(ActiveRecordError, "No integer type has byte size #{limit}")
end
when 'text'
case limit
when 0..0xff; 'tinytext'
when nil, 0x100..0xffff; 'text'
when 0x10000..0xffffff; 'mediumtext'
when 0x1000000..0xffffffff; 'longtext'
else raise(ActiveRecordError, "No text type has character length #{limit}")
end
else
super
end end
end end


Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/schema/mysql2_specific_schema.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
ActiveRecord::Schema.define do ActiveRecord::Schema.define do
create_table :binary_fields, :force => true, :options => 'CHARACTER SET latin1' do |t| create_table :binary_fields, :force => true do |t|
t.binary :tiny_blob, :limit => 255 t.binary :tiny_blob, :limit => 255
t.binary :normal_blob, :limit => 65535 t.binary :normal_blob, :limit => 65535
t.binary :medium_blob, :limit => 16777215 t.binary :medium_blob, :limit => 16777215
Expand Down Expand Up @@ -32,4 +32,4 @@
) CHARACTER SET utf8 COLLATE utf8_general_ci ) CHARACTER SET utf8 COLLATE utf8_general_ci
SQL SQL


end end
2 changes: 1 addition & 1 deletion activerecord/test/schema/mysql_specific_schema.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
ActiveRecord::Schema.define do ActiveRecord::Schema.define do
create_table :binary_fields, :force => true, :options => 'CHARACTER SET latin1' do |t| create_table :binary_fields, :force => true do |t|
t.binary :tiny_blob, :limit => 255 t.binary :tiny_blob, :limit => 255
t.binary :normal_blob, :limit => 65535 t.binary :normal_blob, :limit => 65535
t.binary :medium_blob, :limit => 16777215 t.binary :medium_blob, :limit => 16777215
Expand Down

0 comments on commit a19dd29

Please sign in to comment.