Re: [PATCHES] libpq type system 0.9a

Поиск
Список
Период
Сортировка
От Andrew Chernow
Тема Re: [PATCHES] libpq type system 0.9a
Дата
Msg-id 47FE2F55.1000208@esilo.com
обсуждение исходный текст
Ответ на Re: [PATCHES] libpq type system 0.9a  (Andrew Chernow <ac@esilo.com>)
Ответы Re: [PATCHES] libpq type system 0.9a  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Andrew Chernow wrote:
> 
> /* 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);
> 

PQresultAddTuple is not quite correct.  The below is its replacement:

int PQresultSetFieldValue(  PGresult *res,  int tup_num,  int field_num,  char *value,  int len)

Recap: PQresultDup, PQresultSetFieldDesc and PQresultSetFieldValue.

We feel this approach, which we initially thought wouldn't work, is 
better than making pg_result public.

These functions could be useful outside of pqtypes, providing a way of 
filtering/modifying a result object ... consider:

PGresult *execit(conn, stmt)
{  res = PQexec(conn, stmt);  if(some_app_cond_is_true)  {    newres = PQresultDup();    // ... customize tups and
fields   //PQresultSetFieldDesc and PQresultSetFieldValue    PQclear(res);    res = newres;  }  return res;
 
}

// res could be custom built
res = execit(conn, stmt);
PQclear(res);

This is not an everyday need, but I'm sure it could provide some niche 
app functionality currently unavailable.  Possibly useful to libpq 
wrapper APIs.  Either way, it works great for pqtypes and avoids 
exposing pg_result.

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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Aidan Van Dyk
Дата:
Сообщение: Re: Commit fest queue
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Commit fest queue