Correctly obey MySQL MAX PACKET

Use String's bytesize instead of size, because we're talking about byte length,
not string length. This resolves a problem on Ruby 1.9 with multi-byte
characters.
This commit is contained in:
Jamie Cobbett 2011-05-08 21:35:47 +00:00
parent 5b3740e0f2
commit 6555fd70ba
2 changed files with 22 additions and 3 deletions

View file

@ -1,3 +1,4 @@
# encoding: UTF-8
def should_support_mysql_import_functionality
describe "building insert value sets" do
@ -25,6 +26,24 @@ def should_support_mysql_import_functionality
assert_equal values[1], value_sets[1].first
assert_equal values[2], value_sets[2].first
end
context "data contains multi-byte chars" do
it "should properly build insert value set based on max packet allowed" do
# each accented e should be 2 bytes, so each entry is 6 bytes instead of 5
values = [
"('é')",
"('é')" ]
adapter = ActiveRecord::Base.connection.class
base_sql_size_in_bytes = 15
max_bytes = 26
values_size_in_bytes = adapter.sum_sizes( *values )
value_sets = adapter.get_insert_value_sets( values, base_sql_size_in_bytes, max_bytes )
assert_equal 2, value_sets.size, 'Two value sets were expected!'
end
end
end
describe "#import with :on_duplicate_key_update option (mysql specific functionality)" do