Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931 (Try again). #5173

Merged
merged 1 commit into from Feb 27, 2012

Conversation

Projects
None yet
2 participants
Contributor

kennyj commented Feb 25, 2012

The original issue is #3931.

First, add the following line.

t.text :example, :limit => 0x555555 (5592405) # means `mediumtext`

Second, migrate and be generated schema.rb. I'll see

t.text "example", :limit => 16777215 # `longtext` !

I think that the cause of problem is mysql behavior difference by character encoding.

If we use latin1 encoding, the limit is 16777215.
But if we use utf-8 encoding, the limit is 16777215 / 3 = 5592405.

Thus, I should fix binary_fields test, because I guess that we usually use utf-8 encoding.

Please see also #3931 and #4382.

Closes #3931.

tenderlove merged commit a19dd29 into rails:master Feb 27, 2012

Owner

tenderlove commented Feb 27, 2012

Should this be backported to 3.2 and 3.1?

Contributor

kennyj commented Feb 27, 2012

Yes, I think this should be merged on 3-1-stable and 3-2-stable.

@pixeltrix pixeltrix added a commit to pixeltrix/mysql2 that referenced this pull request Aug 4, 2012

@pixeltrix pixeltrix Backport of fix from rails/rails#5173
Rather than use the MySQL specific TINYTEXT, MEDIUMTEXT and LONGTEXT
datatypes, Active Record migrations use TEXT(n) where n is the limit
specified by the developer. Unfortunately how MySQL interprets n
depends on the column's encoding so any limit above 5592405 will be
interpreted as a LONGTEXT.

This commit fixes this by interpreting the limit within the adapter
and using the specific MySQL datatype as appropriate.
3105855

@pixeltrix pixeltrix added a commit that referenced this pull request Aug 4, 2012

@pixeltrix pixeltrix Backport of fix from #5173 - fixes #7252
Rather than use the MySQL specific TINYTEXT, MEDIUMTEXT and LONGTEXT
datatypes, Active Record migrations use TEXT(n) where n is the limit
specified by the developer. Unfortunately how MySQL interprets n
depends on the column's encoding so any limit above 5592405 will be
interpreted as a LONGTEXT when the encoding is UTF-8.

This commit fixes this by interpreting the limit within the adapter
and using the specific MySQL datatype as appropriate.
f07c708

@kronn kronn added a commit to kronn/activerecord-mysql2-adapter that referenced this pull request Aug 5, 2012

@pixeltrix @kronn pixeltrix + kronn Backport of fix from rails/rails#5173
Rather than use the MySQL specific TINYTEXT, MEDIUMTEXT and LONGTEXT
datatypes, Active Record migrations use TEXT(n) where n is the limit
specified by the developer. Unfortunately how MySQL interprets n
depends on the column's encoding so any limit above 5592405 will be
interpreted as a LONGTEXT.

This commit fixes this by interpreting the limit within the adapter
and using the specific MySQL datatype as appropriate.
d057a3c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment