Re: libpq patch for pqtypes hook api and PGresult creation - Mailing list pgsql-patches

From Andrew Chernow
Subject Re: libpq patch for pqtypes hook api and PGresult creation
Date
Msg-id 4800A72D.9020000@esilo.com
Whole thread Raw
In response to Re: libpq patch for pqtypes hook api and PGresult creation  ("Merlin Moncure" <mmoncure@gmail.com>)
Responses Re: libpq patch for pqtypes hook api and PGresult creation  (Andrew Chernow <ac@esilo.com>)
Re: libpq patch for pqtypes hook api and PGresult creation  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Merlin Moncure wrote:
> On Fri, Apr 11, 2008 at 1:47 PM, Andrew Chernow <ac@esilo.com> wrote:
>> Here are the changes to libpq.  It adds the ability to register an Object
>> Hook and create a home-grown result.  Patch adds 4 functions.
>>
>>  We changed the name of PQresultSetFieldValue to PQsetvalue, which better
>> compliments PQgetvalue.  If this patch is acceptable, we will move on to
>> making the required changes to pqtypes; some work has already been done.
>
> Whoops! One missing thing here...we forgot to make pqResultAlloc
> pubilc...pqResultAlloc -> PQresultAlloc (see discussion in -hackers).
> Also, we could use pqResultStrdup (or keep it private, in which case
> we can re-implement in libpqtypes).
>
> merlin
>

The connCreate and resultCreate hooks are in the wrong place.  I didn't
realize this until I started to implement the hook functions in pqtypes.

void (*connCreate)(const char *hookName, const PGconn *conn);

The requirements for the connCreate hook are that the PGconn is ready
for use.  I am currently hooking in connectDBStart, which is dead wrong.
  After some poking around, it looks like the correct place to hook
would be in PQconnectPoll ... does this sound correct?  There are 3
places PQconnectPoll returns PGRES_POLLING_OK: one is at the top of the
function and the other two are further down with "We are open for
business!" comments.  Would I be correct to hook in at these 3 places in
PQconnectPoll?

void (*resultCreate)(const char *hookName, const PGconn *conn,
   const PGresult *res);

The requirements for resultCreate are that the result is fully
constructed.  I am currently hooked in PQmakeEmptyResult, again dead
wrong.  Does PQgetResult sound correct?

Also, pqtypes is only interested in CONNECTION_OK and successfull
results.  But, these hooks are available to more than just pqtypes.
What should the "when to call connCreate and resultCreate" policy be?
Should the hook only be called when the conn or result was successfull
or should the hooks be called for failed connections/commands as well?

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

pgsql-patches by date:

Previous
From: "Brendan Jurd"
Date:
Subject: Re: printTable API (was: Show INHERIT in \du)
Next
From: Andrew Chernow
Date:
Subject: Re: libpq patch for pqtypes hook api and PGresult creation