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. Advertisements

  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. Advertisements

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:
    566
  2. Steve

    Postgres BYTEA problems

    Steve, Mar 3, 2004, in forum: Python
    Replies:
    1
    Views:
    790
    Ivan Voras
    Mar 4, 2004
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    1,115
    Malcolm
    Jun 24, 2006
  4. George Moschovitis

    [Q] Postgres bytea columns and Marshal load

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

    DBI and postgres

    Dominik Werder, Feb 16, 2005, in forum: Ruby
    Replies:
    1
    Views:
    170
    Michael Neumann
    Feb 16, 2005
  6. snacktime

    postgres dbd driver for ruby dbi

    snacktime, Sep 23, 2005, in forum: Ruby
    Replies:
    0
    Views:
    179
    snacktime
    Sep 23, 2005
  7. Chris Newman

    postgres DBI question

    Chris Newman, Oct 25, 2005, in forum: Ruby
    Replies:
    2
    Views:
    213
    Kirk Haines
    Oct 25, 2005
  8. Nick Black
    Replies:
    1
    Views:
    333
    Kashia Buch
    Nov 16, 2006
Loading...