Re: Insert and Retrieve unsigned char sequences using C

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: vinicius_bra <viniciusams(at)yahoo(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Insert and Retrieve unsigned char sequences using C
Date: 2010-07-21 13:27:52
Message-ID: AANLkTim20LThxT_kBIPHDSx_AtY0hgjdKxJ6CZLJRa2u@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jul 19, 2010 at 8:14 PM, vinicius_bra <viniciusams(at)yahoo(dot)com(dot)br> wrote:
>
> Hi All,
>
> I'm developing a system in C and I have a unsigned char pointer that
> represents a struct and I like to store it in a bytea column in postgreSQL.
> How can I do it?
> Example:

you have several options:
*) encode the memory for the structure PQescapeStringConn and send to
PQexec (my least favorite method)
*) set up a call to PQexecParams (more work, but faster and no escaping)
*) make a composite type on the server and send your structure in a
more classical SQL way
*) use libpqtypes (this is the most set up work, but the best in the
long run) :-)

w/libpqtypes:
PGbytea b = {sizeof(s), &s};
PGresult *res = PQexecf(conn, "insert into t values (%bytea)", b);
PQclear(res);

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martin Gainty 2010-07-21 13:45:52 Re: Oracle Spatial and PostGis
Previous Message Geoffrey 2010-07-21 13:01:19 locating cities within a radius of another