Re: libpq patch for pqtypes hook api and PGresult creation

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: libpq patch for pqtypes hook api and PGresult creation
Date: 2008-04-12 12:12:29
Message-ID: 4800A72D.9020000@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Merlin Moncure wrote:
> On Fri, Apr 11, 2008 at 1:47 PM, Andrew Chernow <ac(at)esilo(dot)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/

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Andrew Chernow 2008-04-12 13:37:24 Re: libpq patch for pqtypes hook api and PGresult creation
Previous Message Brendan Jurd 2008-04-12 08:12:44 Re: printTable API (was: Show INHERIT in \du)