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 12:47:26
Message-ID: 47FE0C5E.6030103@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Andrew Chernow <ac(at)esilo(dot)com> writes:
>>>> What parts of PGconn/PGresult do you need to touch that aren't exposed
>>>> already?
>
>> Don't need direct access to PGconn at all.
>
> Oh, good, that makes things much easier.
>

Shoot! Feels like you always miss something.

The patch uses PGconn's PQExpBuffer to set errors on a conn. Currently,
there is no access to this buffer other than PQerrorMessage. Is the
below okay?

extern PQExpBuffer *PQgetErrorBuffer(PGconn *conn);
// OR PQsetErrorMessage(conn, errstr) -- this felt strange to me

The expbuffer API is public, so managing the returned PQExpBuffer would
not require any additional API calls.

While I am on the subject of things I missed, the patch also uses
pqSetResultError (mostly during PQgetf).

We no longer need direct access to anything inside pg_result. However,
we would need 3 new API calls that would dup a result, set field descs
and add tuples to a result. Below are prototypes of what I have so far
(small footprint for all 3, maybe 100-150 lines).

/* numParameters, paramDescs, errFields, curBlock,
* curOffset and spaceLeft are not assigned at all,
* initialized to zero. errMsg is handled by
* PQmakeEmptyPGresult. attDescs and tuples are not
* duplicated, only allocated based on 'ntups' and
* 'numAttributes'. The idea is to dup the result
* but customize attDescs and tuples.
*/
PGresult *PQresultDup(
PGconn *conn,
PGresult *source,
int ntups,
int numAttributes);

/* Only for results returned by PQresultDup. This
* will set the field descs for 'field_num'. The
* PGresAttDesc struct was not used to avoid
* exposing it.
*/
int PQresultSetFieldDesc(
PGresult *res,
int field_num,
const char *name,
Oid tableid,
int columnid,
int format,
Oid typid,
int typlen,
int typmod)

/* 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);

The above would allow an external app to dup a result and customize its
rows and columns. Our patch uses this for arrays and composites.

--
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 Peter Eisentraut 2008-04-10 12:50:12 Re: Separate psql commands from arguments
Previous Message Alvaro Herrera 2008-04-10 12:46:08 Re: Commit fest queue

Browse pgsql-patches by date

  From Date Subject
Next Message Alvaro Herrera 2008-04-10 13:08:53 Re: Fix for win32 stat() problems
Previous Message Teodor Sigaev 2008-04-10 11:53:32 Re: Partial match in GIN