[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Encode strings for bytea (postgres) with dbi

Martin Kaletsch

5/16/2005 2:17:00 PM


Hello!

I don't know if I just don't get it, but are there any functions encoding
binary data for inserting into bytea columns in a postgresql db? All I
found in dbi (0.0.23) and ruby-postgres (0.7.1) seems rather low-level.
Does anybody have an example handy, or should I do the escapes by hand?

--
Martin Kaletsch
1 Answer

Luca Pireddu

5/18/2005 3:46:00 PM

0

Martin Kaletsch wrote:

>
> Hello!
>
> I don't know if I just don't get it, but are there any functions encoding
> binary data for inserting into bytea columns in a postgresql db? All I
> found in dbi (0.0.23) and ruby-postgres (0.7.1) seems rather low-level.
> Does anybody have an example handy, or should I do the escapes by hand?
>
> --
> Martin Kaletsch

The ruby postgres library has what you need, though it doesn't seem to be
documented. PGconn has the following class methods:
["escape_bytea", "connect", "setdb", "quote", "escape", "setdblogin"]

I think PGconn.escape_bytea is what you want. Pass it your binary data as an
argument and you'll get back an escaped string to send to the DB. Don't
forget to quote the result.

Luca