Forum: Ruby on Rails Rails and PostgreSQL bytea

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
rickthemick (Guest)
on 2006-01-18 12:11
Hi!
I'm trying to insert binary data into a PostgreSQL database where the
field is of type 'bytea'. This works fine if a do Base64 encoding but I
just want to do character escaping. How do I do this????.

What I get is this:
ActiveRecord::StatementInvalid in Init_test#save_file

ArgumentError: Invalid Ruby/cstring: INSERT INTO
globalfiles(chksum,block,directory,filename,blocksize,time,data)
VALUES('10fcfa244eb972c6de695be235d11f98', '0', 'test', 'myfilename',
'500000', 'NOW()', '�B��H�3�!g1hV��9 blaaaahh more binary 
data...'

I have got a indication that this should be done automatically, but does
this hold for the postgres-pr module?

Best Regards
Rickard

Btw, I'm using Ruby 1.8.2, postgres-pr 0.4.0 and Rails 1.0.0
rickthemick (Guest)
on 2006-01-19 19:22
Hi again!
I would really appreciate input from you guys who know this or have
tried it.

Any one having ideas?

My problem is also described here:
http://www.postgresql.org/docs/7.4/interactive/dat...
I have read and tried, I just can get it to run properly. I always get
the error described below. I hope there would be some nice "the Rails
way..."

Many thanx in advance!

Best Regards
Rickard


rickthemick wrote:
> Hi!
> I'm trying to insert binary data into a PostgreSQL database where the
> field is of type 'bytea'. This works fine if a do Base64 encoding but I
> just want to do character escaping. How do I do this????.
>
> When I just to a plain insert as if it were ASCII data I get:
> ActiveRecord::StatementInvalid in Init_test#save_file
>
> ArgumentError: Invalid Ruby/cstring: INSERT INTO
> globalfiles(chksum,block,directory,filename,blocksize,time,data)
> VALUES('10fcfa244eb972c6de695be235d11f98', '0', 'test', 'myfilename',
> '500000', 'NOW()', '�B��H�3�!g1hV��9 blaaaahh more binary data...'
>
> I have got a indication that this should be done automatically, but does
> this hold for the postgres-pr module?
>
> Best Regards
> Rickard
>
> Btw, I'm using Ruby 1.8.2, postgres-pr 0.4.0 and Rails 1.0.0
This topic is locked and can not be replied to.