Re: [PATCHES] libpq type system 0.9a

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, Greg Sabino Mullane <greg(at)turnstep(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCHES] libpq type system 0.9a
Date: 2008-04-10 15:16:37
Message-ID: 47FE2F55.1000208@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Andrew Chernow wrote:
>
> /* Only for results returned by PQresultDup. This
> * will append a new tuple to res. A PGresAttValue
> * is allocated and put at index 'res->ntups'. This
> * is similar to pqAddTuple except that the tuples
> * table has been pre-allocated. In our case, ntups
> * and numAttributes are known when calling resultDup.
> */
> int PQresultAddTuple(
> PGresult *res,
> char *value,
> int len);
>

PQresultAddTuple is not quite correct. The below is its replacement:

int PQresultSetFieldValue(
PGresult *res,
int tup_num,
int field_num,
char *value,
int len)

Recap: PQresultDup, PQresultSetFieldDesc and PQresultSetFieldValue.

We feel this approach, which we initially thought wouldn't work, is
better than making pg_result public.

These functions could be useful outside of pqtypes, providing a way of
filtering/modifying a result object ... consider:

PGresult *execit(conn, stmt)
{
res = PQexec(conn, stmt);
if(some_app_cond_is_true)
{
newres = PQresultDup();
// ... customize tups and fields
//PQresultSetFieldDesc and PQresultSetFieldValue
PQclear(res);
res = newres;
}
return res;
}

// res could be custom built
res = execit(conn, stmt);
PQclear(res);

This is not an everyday need, but I'm sure it could provide some niche
app functionality currently unavailable. Possibly useful to libpq
wrapper APIs. Either way, it works great for pqtypes and avoids
exposing pg_result.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2008-04-10 15:16:58 Re: Commit fest queue
Previous Message Aidan Van Dyk 2008-04-10 15:15:08 Re: Commit fest queue

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-04-10 16:35:56 Re: [PATCHES] libpq type system 0.9a
Previous Message Magnus Hagander 2008-04-10 15:16:01 Re: Fix for win32 stat() problems