Re: Loading/Retrieving bytea fields?

Поиск
Список
Период
Сортировка
От Daniel Verite
Тема Re: Loading/Retrieving bytea fields?
Дата
Msg-id 20040728164529.5143560@uruguay.brainstorm.fr
обсуждение исходный текст
Ответ на Loading/Retrieving bytea fields?  (Jerry LeVan <jerry.levan@eku.edu>)
Список pgsql-general
     Jerry LeVan writes

> Has anyone found some C code that shows how to load/extract data from a
> bytea column?

This works for me:

int size;
const char* contents;
PGresult* res;
res = PQexecParams(pgconn,
        "SELECT contents FROM tblob WHERE pkey=value",
        0, NULL,NULL,NULL,NULL,   /* no input parameters */
        1  /* output in binary format */ );

if (res && PQresultStatus(res)==PGRES_TUPLES_OK) {
  size = PQgetlength(res, 0, 0);
  contents = PQgetvalue(res, 0, 0);    /* binary representation */
}

I believe that you may also use the plain PQexec instead of PQexecParams,
but then you would have to call PQunescapeBytea() on the bytea column in the
results, so it's likely to be less efficient. I haven't tried that, though.

--
 Daniel
 PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org

В списке pgsql-general по дате отправления:

Предыдущее
От: Mike Nolan
Дата:
Сообщение: Re: Before/After trigger sequencing questiont
Следующее
От: Tom Lane
Дата:
Сообщение: Re: tablename type?