Re: [PATCHES] libpq type system 0.9a

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, Greg Sabino Mullane <greg(at)turnstep(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCHES] libpq type system 0.9a
Date: 2008-04-10 19:39:35
Message-ID: 47FE6CF7.8040502@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Andrew Chernow wrote:
>
> For client_encoding and noticeHooks, the conn can be NULL. Previously,
> we copied this info from the source result when conn was NULL.
>
>

Looks like we don't need client_encoding. My guess is, in our use case
noticeHooks can probably be NULL for the created result, when makeresult
is not provided a conn.

> ....something like below
>
> res = PQmakeResult(...);
> for(ntups)
> {
> PQresultAddEmptyTuple(res); // or PQresultMakeEmptyTuple?
> for(nfields)
> PQresultSetFieldValue(res, tup_num, field_num, ....);
> }
>
>

I think a better idea would be to make setfieldvalue more dynamic,
removing the need for PQresultAddEmptyTuple. Only allow tup_num to be
<= res->ntups. This will only allow adding one tuple at a time. The
other option would allow arbitray tup_nums to be passed in, like ntups
is 1 but the provided tup_num is 67. In this case, we would have to
back fill. It seems better to only grow by one tuple at a time. We can
get it working either way, we just prefer one tuple at a time allocation.

int PQresultSetFieldValue(
PGresult *res,
int tup_num,
int field_num,
char *value,
int len)
{
if(!check_field_value(res, field_num))
return FALSE;

if(tup_num > res->ntups)
// error, tup_num must be <= res->ntups

if(res->ntups >= res->tupArrSize)
// grow res->tuples

if(tup_num == res->ntups && !res->tuples[tup_num])
// need to allocate tuples[tup_num]

// blah ... blah ...
}

New PQmakeResult prototype:

PQmakeResult(
PGconn *conn,
const char *cmdStatus,
int binaryTuples,
int numAttributes,
PGresAttDesc *attDescs);

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Marc G. Fournier 2008-04-10 19:43:59 Re: Commit fest queue
Previous Message Alvaro Herrera 2008-04-10 19:37:48 Re: Commit fest queue

Browse pgsql-patches by date

  From Date Subject
Next Message Zdenek Kotala 2008-04-10 19:45:08 Re: Remove FATAL from pg_lzdecompress
Previous Message Bruce Momjian 2008-04-10 18:56:08 Re: [HACKERS] Including Snapshot Info with Indexes