Encode strings for bytea (postgres) with dbi

M

Martin Kaletsch

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?
 
L

Luca Pireddu

Martin said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top