Rails and PostgreSQL bytea

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

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:

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