Re: Error in PQsetvalue - Mailing list pgsql-hackers

From Andrew Chernow
Subject Re: Error in PQsetvalue
Date
Msg-id 4DE94896.1060405@esilo.com
Whole thread Raw
In response to Re: Error in PQsetvalue  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-hackers
>>
>> At first glance (have not tested this theory), looks like pqAddTuple()
>> doesn't zero the newly allocated tuples slots like PQsetvalue() does.
>> PQsetvalue is depending on the unassigned tuple table slots to be NULL to
>> detect when a tuple must be allocated.  Around line 446 on fe-exec.c.  I
>> never tested this case since libpqtypes never tried to call PQsetvalue on a
>> PGresult created by the standard libpq library.
>>
>> The solution I see would be to zero the new table slots within pqAddTuple.
>>   Any other ideas?
>
> It might not be necessary to do that.  AIUI the tuple table slot guard
> is there essentially to let setval know if it needs to allocate tuple
> attributes, which always has to be done after a new tuple is created
> after a set.

Trying to append a tuple to a libpq generated PGresult will core dump 
due to the pqAddTuple issue, unless the append operation forces 
PQsetvalue to grow the tuple table; in which case new elements are 
zero'd.  OP attempted to append.

res = PQexec("returns 2 tuples");
PQsetvalue(res, PQntuples(res), ...);

-- 
Andrew Chernow
eSilo, LLC
global backup
http://www.esilo.com/


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Getting a bug tracker for the Postgres project
Next
From: Heikki Linnakangas
Date:
Subject: Re: SIREAD lock versus ACCESS EXCLUSIVE lock