Derby binary object not saved correctly
---------------------------------------
Key: JRUBY-1204
URL: http://jira.codehaus.org/browse/JRUBY-1204
Project: JRuby
Issue Type: Bug
Components: ActiveRecord-JDBC
Affects Versions: JRuby 1.0.0
Environment: rails 1.2.3, derby 10.2.2.0, JRE 1.5.0_11, Windows XP Pro
SP2
Reporter: stoopidboi
Assignee: Thomas E Enebo
When trying to save a binary image to database using ActiveRecord into Derby,
the database image did not match actual image.
Migration script:
{code}
class CreatePicture < ActiveRecord::Migration
def self.up
create_table :pictures, :force => true do |table|
table.column :image_data, :binary
end
end
def self.down
drop_table :pictures
end
end
{code}
Model:
{code}
class Picture < ActiveRecord::Base
end
{code}
Controller:
{code}
def upload()
image = params[:image]
image_data = image.read
picture = Picture.new()
picture.image_data = image_data
picture.save()
end
{code}
Suspected causes:
- Conversion from bin to hex did not consider single digit results.
- Assignment did not convert binary data to hex.
Partial fix: (/lib/jdbc_adapter/jdbc_derby.rb Line 384)
{code}
"CAST(x'#{value.unpack("C*").collect {|v| v.to_s(16).rjust(2, "0")}.join}' AS
BLOB)"
{code}
With the partial fix I still need to convert to hex manually when saving the
image, not sure where this should be changed:
{code}
picture = Picture.new()
picture.image_data = image_data.unpack("C*").collect {|v| v.to_s(16).rjust(2,
"0")}.join
picture.save()
{code}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email