Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 937ECB612F5; Thu, 2 Jun 2011 05:45:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 53873-03; Thu, 2 Jun 2011 08:44:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com [209.85.161.46]) by mail.postgresql.org (Postfix) with ESMTP id 3712EB61729; Thu, 2 Jun 2011 05:44:56 -0300 (ADT) Received: by fxm17 with SMTP id 17so564910fxm.19 for ; Thu, 02 Jun 2011 01:44:55 -0700 (PDT) Received: by 10.223.77.92 with SMTP id f28mr506366fak.37.1307004295686; Thu, 02 Jun 2011 01:44:55 -0700 (PDT) Received: from [192.168.1.104] (161-32-133-95.pool.ukrtel.net [95.133.32.161]) by mx.google.com with ESMTPS id l26sm111787fah.14.2011.06.02.01.44.54 (version=SSLv3 cipher=OTHER); Thu, 02 Jun 2011 01:44:55 -0700 (PDT) Date: Thu, 2 Jun 2011 11:44:51 +0300 From: Pavel Golub Reply-To: Pavel Golub Organization: Microolap X-Priority: 3 (Normal) Message-ID: <1055779970.20110602114451@gf.microolap.com> To: PostgreSQL Hackers , Subject: Re: PQdeleteTuple function in libpq In-Reply-To: <147534417.20110601184310@gf.microolap.com> References: <147534417.20110601184310@gf.microolap.com> MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1251 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/4 X-Sequence-Number: 6949 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