Skip site navigation (1) Skip section navigation (2)

Re: PQdeleteTuple function in libpq

From: Pavel Golub <pavel(at)microolap(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: PQdeleteTuple function in libpq
Date: 2011-06-02 08:44:51
Message-ID: 1055779970.20110602114451@gf.microolap.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-interfaces
Hello.

So having studied the fe-exec.c sources, I came to this conclusion:
we may just ignore deleted tuple and it will be destroyed by
PQclear automatically, becuase PQclear deals with memory blocks.

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;

        for (i = tup_num; i < src->ntups - 1; i++)
        {
                src->tuples[i] = src->tuples[i + 1];
        }
        src->ntups--;
        return TRUE;
}

I also checked pqAddTuple, PQcopyResult and PQSetValue, they are OK with this
solution.

Am I correct with this?

You wrote:

PG> Hello.

PG> I'm some kind of PQdeleteTuple function will be very usefull in libpq.
PG> Because right now after deleting some record I need refetch result
PG> set, or mark tuple as deleted and this is headache for me.

PG> So I checked fe-exec.c sources and wrote this:

PG> int PQdeleteTuple(PGresult *src, int tup_num)
PG> {
PG>         if (!src)
PG>                 return NULL;

PG>         int                     i,
PG>                                 field;
PG>                                 
PG>         /* Invalid tup_num, must be < ntups */                  
PG>         if (tup_num < 0 || tup_num >= src->ntups)
PG>                 return FALSE;

PG>         free(src->tuples[tup_num]);
PG>         
PG>         for (i = tup_num; i < src->ntups - 1; i++)
PG>         {
PG>                 src->tuples[i] = src->tuples[i + 1];
PG>         }
PG>         src->ntups--;
PG>         return TRUE;
PG> }

PG> But I'm pretty sure, that "free(src->tuples[tup_num])" is bullshit!
PG> Because memory is allocated by pqResultAlloc, which in turn plays with
PG> memory blocks and so on...

PG> Can anyone help me in this?

PG> PS I'm not a C guru, so don't please kick me hard. :)

PG> Thanks.





-- 
With best wishes,
 Pavel                          mailto:pavel(at)gf(dot)microolap(dot)com


In response to

pgsql-hackers by date

Next:From: Teodor SigaevDate: 2011-06-02 08:45:41
Subject: Re: Cube Index Size
Previous:From: Pavel StehuleDate: 2011-06-02 08:39:05
Subject: patch: enhanced get diagnostics statement 2

pgsql-interfaces by date

Next:From: Miguel Garc&#xED;aDate: 2011-06-02 13:07:46
Subject:
Previous:From: Pavel GolubDate: 2011-06-02 08:28:26
Subject: Re: [HACKERS] PQdeleteTuple function in libpq

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group