From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Pavel Golub <pavel(at)gf(dot)microolap(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, pgsql-interfaces(at)postgresql(dot)org |
Subject: | Re: PQdeleteTuple function in libpq |
Date: | 2011-06-01 16:24:25 |
Message-ID: | BANLkTim8BxvLLnLL15WjgpVpNX_O0qVAxw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers Postg토토 핫SQL : Postg토토 |
2011/6/1 Pavel Golub <pavel(at)microolap(dot)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. :)
well, you have PQaddTuple, but this was exposed mainly for the purpose
of building a PQresult from outside the libpq library -- not so much
to remove the 'constness' property of the PGResult. I have no
philosophical objection to making the PGresult able to be manipulated
in that fashion (although others might). You could maybe just NULL
out tuples[i] and add some logic to various places to check that, like
in PQgetvalue.
But before going down that road you need to make the case why this
should be handled in the library and not in your code -- PGresult
memory is slab allocated and therefore can only grow in size -- not
shrink and as such is not so much designed as a general purpose client
side dataset in the high level sense.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Merlin Moncure | 2011-06-01 16:49:32 | Re: Any idea for serializing INSERTING SERIAL column? |
Previous Message | Florian Pflug | 2011-06-01 16:16:21 | Re: Another issue with invalid XML values |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Chernow | 2011-06-01 20:48:55 | Re: PQdeleteTuple function in libpq |
Previous Message | Pavel Golub | 2011-06-01 15:43:10 | PQdeleteTuple function in libpq |