Tom Lane wrote:
Andrew Chernow <[EMAIL PROTECTED]> 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/

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to