Skip site navigation (1) Skip section navigation (2)

Re: libpq object hooks (libpq events)

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: libpq object hooks (libpq events)
Date: 2008-05-20 02:21:07
Message-ID: 48323593.4060302@esilo.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Will make all of those changes.  We appreciate the help.

1. remove global registration :(

2. New Name: PGCallback

3. use instanceData and passThrough names (passThrough with upper 'T')

3. separate getters for conn/result instanceData and passthrough

4. add a setter for result instance data
   - There should also be a PQsetInstanceData(PGconn*, ...)
   - I see no need for a passThrough setter

5. move callback stuff to its own header, maybe pgcallback.h?

No issue with any of them.  Although, small issue below:

> Maybe instead of having the ResultCreate
> callback scribble on the event data structure, provide an additional
> API routine to store the pointer:
> 	PQresultSetInstanceData(PGresult *res, PGeventProc proc,
> 				void *instanceData);

Adding PQresultSetInstanceData doesn't removes the need for a resultcreate 
callback event.  This is an event the callbacks are informed about (instanceData 
or not).  It does remove the need for an instance data member in all event info 
structures, just use the getter/setter when desired.  If the passThrough is 
needed, one can use the public getters.

 > hooks registered.  Also, meseems you need such a callback anyway:
 > what if the hook library desires to realloc its instance data
 > larger?
 >

With your suggestions, this would work:

res = PQexec(conn, "blah");
data = PQresultInstanceData(res, cbfunc);
data = realloc(data, 1024);
PQresultSetInstanceData(res, cbfunc, data);

The API user should have a valid instanceData whenever libpq returns a result, 
assuming they registered a callback that allocates instance data during a 
resultcreate event.

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

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2008-05-20 02:37:58
Subject: Re: libpq object hooks (libpq events)
Previous:From: Tom LaneDate: 2008-05-20 01:53:03
Subject: Re: triggers on prepare, commit, rollback... ?

pgsql-patches by date

Next:From: Tom LaneDate: 2008-05-20 02:29:04
Subject: Re: Simplify formatting.c
Previous:From: Bruce MomjianDate: 2008-05-20 01:41:40
Subject: Simplify formatting.c

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group