agora inbox for pgsql-interfaces@postgresql.org  
help / color / mirror / Atom feed
From: Pavel Golub <pavel@microolap.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
To: pgsql-interfaces@postgresql.org
Subject: Re: PQdeleteTuple function in libpq
Date: Thu, 2 Jun 2011 11:44:51 +0300
Message-ID: <1055779970.20110602114451@gf.microolap.com> (raw)
In-Reply-To: <147534417.20110601184310@gf.microolap.com>
References: <147534417.20110601184310@gf.microolap.com>

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




view thread (17+ messages)  latest in thread

Message-ID: <1055779970.20110602114451@gf.microolap.com>
Permalink:  ../1055779970.20110602114451@gf.microolap.com/
Also on:    postgresql.org/message-id/1055779970.20110602114451@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, pgsql-hackers@postgresql.org
  Subject: Re: PQdeleteTuple function in libpq
  In-Reply-To: <1055779970.20110602114451@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox