pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Golub <pavel@microolap.com>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [HACKERS] PQdeleteTuple function in libpq
Date: Thu, 2 Jun 2011 11:24:18 +0300
Message-ID: <16110385996.20110602112418@gf.microolap.com> (raw)
In-Reply-To: <BANLkTim8BxvLLnLL15WjgpVpNX_O0qVAxw@mail.gmail.com>
References: <147534417.20110601184310@gf.microolap.com>
	<BANLkTim8BxvLLnLL15WjgpVpNX_O0qVAxw@mail.gmail.com>

Hello, Merlin.

You wrote:

MM> 2011/6/1 Pavel Golub <pavel@microolap.com>:
>> Hello.
>>
>> I'm some kind of PQdeleteTuple function will be very usefull in libpq.
>> Because right now after deleting some record I need refetch result
>> set, or mark tuple as deleted and this is headache for me.
>>
>> So I checked fe-exec.c sources and wrote this:
>>
>> int PQdeleteTuple(PGresult *src, int tup_num)
>> {
>>        if (!src)
>>                return NULL;
>>
>>        int                     i,
>>                                field;
>>
>>        /* Invalid tup_num, must be < ntups */
>>        if (tup_num < 0 || tup_num >= src->ntups)
>>                return FALSE;
>>
>>        free(src->tuples[tup_num]);
>>
>>        for (i = tup_num; i < src->ntups - 1; i++)
>>        {
>>                src->tuples[i] = src->tuples[i + 1];
>>        }
>>        src->ntups--;
>>        return TRUE;
>> }
>>
>> But I'm pretty sure, that "free(src->tuples[tup_num])" is bullshit!
>> Because memory is allocated by pqResultAlloc, which in turn plays with
>> memory blocks and so on...
>>
>> Can anyone help me in this?
>>
>> PS I'm not a C guru, so don't please kick me hard. :)

MM> well, you have PQaddTuple, but this was exposed mainly for the purpose
MM> of building a PQresult from outside the libpq library -- not so much
MM> to remove the 'constness' property of the PGResult.  I have no
MM> philosophical objection to making the PGresult able to be manipulated
MM> in that fashion (although others might).

From this point of view why we have PQmakeEmptyPGresult, PQcopyResult,
PQsetResultAttrs, PQsetvalue and PQresultAlloc? If we have these
functions I suppose we must have one more to delete (or hide) some
tuples/attributes.

MM>  You could maybe just NULL
MM> out tuples[i] and add some logic to various places to check that, like
MM> in PQgetvalue.

This is what I call headache. In this case to know rows number I
cannot use PQntuples, but need to iterate through all tuples checking
them for NULL or smth.

MM> But before going down that road you need to make the case why this
MM> should be handled in the library and not in your code -- PGresult
MM> memory is slab allocated and therefore can only grow in size -- not
MM> shrink and as such is not so much designed as a general purpose client
MM> side dataset in the high level sense.

Thinking of this I propose to hide tuples and not to eliminate\free
them, because PQclear will free all PGResult resources.

MM> merlin



-- 
With best wishes,
 Pavel                          mailto:pavel@gf.microolap.com




view thread (17+ messages)  latest in thread

Message-ID: <16110385996.20110602112418@gf.microolap.com>
Permalink:  ../16110385996.20110602112418@gf.microolap.com/
Also on:    postgresql.org/message-id/16110385996.20110602112418@gf.microolap.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: pavel@microolap.com, mmoncure@gmail.com, pgsql-hackers@postgresql.org
  Subject: Re: [HACKERS] PQdeleteTuple function in libpq
  In-Reply-To: <16110385996.20110602112418@gf.microolap.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox