diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 2de7f35a64e7d387285a6472ffc96ec4f051f3ad..855ea9cfbc62bdc7a2ed7afbc9da6f695d38125f 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed a bug in the Ruby/MySQL that caused binary content to be escaped badly and come back mangled #405 [Tobias Luetke] + * Added block-style for callbacks #332 [bitsweat]. Before: diff --git a/activerecord/lib/active_record/vendor/mysql.rb b/activerecord/lib/active_record/vendor/mysql.rb index 4970f77bd383dba3248f49caf676a17d67ca68b5..84f5d2533c9455869dce781ee338679ea356715e 100644 --- a/activerecord/lib/active_record/vendor/mysql.rb +++ b/activerecord/lib/active_record/vendor/mysql.rb @@ -1091,7 +1091,7 @@ def escape_string(str) when "\0" then "\\0" when "\n" then "\\n" when "\r" then "\\r" - when "\032" then "\Z" + when "\032" then "\\Z" else "\\"+$1 end end diff --git a/activerecord/test/binary_test.rb b/activerecord/test/binary_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..b63fbbaede7b1eb3cbe6808d8362e4ce2e77d827 --- /dev/null +++ b/activerecord/test/binary_test.rb @@ -0,0 +1,37 @@ +require 'abstract_unit' +require 'fixtures/binary' + +class BinaryTest < Test::Unit::TestCase + def setup + @data = create_data_fixture + end + + def test_load_save + bin = Binary.new + bin.data = @data + + assert bin.data == @data, + "Assigned data differs from file data" + + bin.save + + assert bin.data == @data, + "Assigned data differs from file data after save" + + db_bin = Binary.find(bin.id) + + assert db_bin.data == bin.data, + "Loaded binary data differes from memory version" + + assert db_bin.data == File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read, + "Loaded binary data differes from file version" + end + + private + + def create_data_fixture + Binary.connection.execute("DELETE FROM binaries") + File.new(File.dirname(__FILE__)+"/fixtures/associations.png","rb").read + end + +end \ No newline at end of file diff --git a/activerecord/test/fixtures/associations.png b/activerecord/test/fixtures/associations.png new file mode 100644 index 0000000000000000000000000000000000000000..661c7a8bbc87282503dc6984a1d9a6161c36f900 Binary files /dev/null and b/activerecord/test/fixtures/associations.png differ diff --git a/activerecord/test/fixtures/binary.rb b/activerecord/test/fixtures/binary.rb new file mode 100644 index 0000000000000000000000000000000000000000..950c45919999176822d5ab8530913562571d35eb --- /dev/null +++ b/activerecord/test/fixtures/binary.rb @@ -0,0 +1,2 @@ +class Binary < ActiveRecord::Base +end \ No newline at end of file diff --git a/activerecord/test/fixtures/db_definitions/mysql.sql b/activerecord/test/fixtures/db_definitions/mysql.sql index ec27a524452cc05b69ed13a1a4c809f508fec193..3758f19bfa9afe0ed0b5e9426109f0867e8b5a8a 100755 --- a/activerecord/test/fixtures/db_definitions/mysql.sql +++ b/activerecord/test/fixtures/db_definitions/mysql.sql @@ -115,4 +115,10 @@ CREATE TABLE `people` ( `id` INTEGER NOT NULL PRIMARY KEY, `first_name` VARCHAR(40) NOT NULL, `lock_version` INTEGER NOT NULL DEFAULT 0 +); + +CREATE TABLE `binaries` ( + `id` int(11) NOT NULL auto_increment, + `data` mediumblob, + PRIMARY KEY (`id`) ); \ No newline at end of file diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql index 6d8222cfd6001b334f8a72813b8da355590feae5..8f6587f96166f90c1054a9b4bafb902efbde1621 100644 --- a/activerecord/test/fixtures/db_definitions/postgresql.sql +++ b/activerecord/test/fixtures/db_definitions/postgresql.sql @@ -133,4 +133,10 @@ CREATE TABLE people ( first_name text, lock_version integer default 0, PRIMARY KEY (id) +); + +CREATE TABLE binaries ( + id serial , + data bytea, + PRIMARY KEY (id) ); \ No newline at end of file diff --git a/activerecord/test/fixtures/db_definitions/sqlite.sql b/activerecord/test/fixtures/db_definitions/sqlite.sql index 5c27832056150c410ea5a7c29865a002405d5762..65b24a9333a293de0198f054ccc5bd01690baa31 100644 --- a/activerecord/test/fixtures/db_definitions/sqlite.sql +++ b/activerecord/test/fixtures/db_definitions/sqlite.sql @@ -103,4 +103,9 @@ CREATE TABLE 'people' ( 'id' INTEGER NOT NULL PRIMARY KEY, 'first_name' VARCHAR(40) DEFAULT NULL, 'lock_version' INTEGER NOT NULL DEFAULT 0 +); + +CREATE TABLE 'binaries' ( + 'id' INTEGER NOT NULL PRIMARY KEY, + 'data' BLOB DEFAULT NULL ); \ No newline at end of file diff --git a/activerecord/test/fixtures/db_definitions/sqlserver.sql b/activerecord/test/fixtures/db_definitions/sqlserver.sql index 74cd381ba3d41653f1ff06d611fc7dd64c4c16c1..023ab634068014f47dc116804c6f47c92ad343ff 100644 --- a/activerecord/test/fixtures/db_definitions/sqlserver.sql +++ b/activerecord/test/fixtures/db_definitions/sqlserver.sql @@ -109,10 +109,17 @@ CREATE TABLE mixins ( PRIMARY KEY (id) ); - CREATE TABLE people ( id int NOT NULL IDENTITY(1, 1), first_name varchar(40) NULL, lock_version int default 0, PRIMARY KEY (id) -); \ No newline at end of file +); + +CREATE TABLE binaries ( + id int NOT NULL IDENTITY(1, 1), + data blob NULL, + PRIMARY KEY (id) +); + +