Encode strings for bytea (postgres) with dbi

Discussion in 'Ruby' started by Martin Kaletsch, May 16, 2005.

  1. 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
     
    Martin Kaletsch, May 16, 2005
    #1
    1. Advertising

  2. Martin Kaletsch

    Luca Pireddu Guest

    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
     
    Luca Pireddu, May 18, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravi
    Replies:
    0
    Views:
    466
  2. Steve

    Postgres BYTEA problems

    Steve, Mar 3, 2004, in forum: Python
    Replies:
    1
    Views:
    725
    Ivan Voras
    Mar 4, 2004
  3. George Moschovitis

    [Q] Postgres bytea columns and Marshal load

    George Moschovitis, Oct 11, 2004, in forum: Ruby
    Replies:
    0
    Views:
    187
    George Moschovitis
    Oct 11, 2004
  4. Dominik Werder

    DBI and postgres

    Dominik Werder, Feb 16, 2005, in forum: Ruby
    Replies:
    1
    Views:
    100
    Michael Neumann
    Feb 16, 2005
  5. Nick Black
    Replies:
    1
    Views:
    181
    Kashia Buch
    Nov 16, 2006
Loading...

Share This Page