Re: PQdeleteTuple function in libpq - Mailing list pgsql-interfaces

From Pavel Golub
Subject Re: PQdeleteTuple function in libpq
Date
Msg-id 1055779970.20110602114451@gf.microolap.com
Whole thread Raw
In response to PQdeleteTuple function in libpq  (Pavel Golub <pavel@microolap.com>)
List pgsql-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@gf.microolap.com



pgsql-interfaces by date:

Previous
From: Pavel Golub
Date:
Subject: Re: [HACKERS] PQdeleteTuple function in libpq
Next
From: "Miguel García"
Date:
Subject: ...