Tom Lane wrote:
> Andrew Chernow <ac@esilo.com> writes:
>> PGresult *PQresultDup(
>> PGconn *conn,
>> PGresult *res,
>> int ntups,
>> int numAttributes,
>> PGresAttDesc *attDescs);
>
> I don't understand why this is a "dup" operation. How can you "dup"
> if you are specifying a new tuple descriptor? I'd have expected
> something like
>
> PGresult *PQmakeResult(PGconn *conn, int numAttributes, PGresAttDesc *attDescs)
>
> producing a zero-row PGRES_TUPLES_OK result that you can then load with
> data via PQresultSetFieldValue calls. (Even the conn argument is a bit
> of a wart, but I think we probably need it so we can copy some of its
> private fields.)
>
> Copying an existing PGresult might have some use too, but surely that
> can't change its tuple descriptor.
>
> regards, tom lane
>
Yeah, "dup" wasn't the best name.
You need more arguments to makeresult though, since you reomved the
'source' result. You need binary, cmdStatus, noticeHooks and
client_encoding.
PQmakeResult(conn, PQcmdStatus(res), PQbinaryTuples(res), ?client_encoding?, ?noticeHooks?, ntups, /* this
interactswith setfieldvalue */ numAttributes, attDescs);
For client_encoding and noticeHooks, the conn can be NULL. Previously,
we copied this info from the source result when conn was NULL.
> producing a zero-row PGRES_TUPLES_OK result that you can then>load with data via PQresultSetFieldValue calls.
I like this idea but you removed the 'ntups' argument. There is no way
to adjust ntups after the makeresult call, its a private member and
setfieldvalue has no concept of incrementing ntups. Since you are not
appending a tuple like pqAddTuple, or inserting one, you can't increment
ntups in setfieldvalue.
But, you could have a function like PQresultAddEmptyTuple(res) which
would have to be called before you can set field values on a tup_num.
The empty tuple would grow tuples when needed and increment ntups. The
new tuple would be zerod (all NULL values).
....something like below
res = PQmakeResult(...);
for(ntups)
{ PQresultAddEmptyTuple(res); // or PQresultMakeEmptyTuple? for(nfields) PQresultSetFieldValue(res, tup_num,
field_num,....);
}
--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/