Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B7AE7B5F9C1; Wed, 1 Jun 2011 13:24:32 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 42415-03; Wed, 1 Jun 2011 16:24:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qw0-f46.google.com (mail-qw0-f46.google.com [209.85.216.46]) by mail.postgresql.org (Postfix) with ESMTP id 9DE4DB5F584; Wed, 1 Jun 2011 13:24:25 -0300 (ADT) Received: by qwk3 with SMTP id 3so2667060qwk.19 for ; Wed, 01 Jun 2011 09:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=9DMrwMYFamsT6R6kMO/mMe2D+g+qqnDRqRA0TAsdw3o=; b=lTJP0em/ZpLZ586EOXcbxzHwMNZTd56XfXTX5YI2Qw6DrthjzrzJpIqwNO7SaPopHg DspHKkouwHkdlAYsMXJqI84RbkPGe7jA54V2QsHRo9u573TArEE9RecwsTPoLGjz464w E4alzTDJVSXlwpCgK73+WVIa8O18S4JRmomfI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=xRAG5OgdRpU/H/yemUs3yaGAoks9sPf6b/fgHWUnKCkBUj1+9qhvwBCH8nveAr8MRC 3WRLc2h2PKKKiL4sspiecHcs1uk/34aKseqrNfML0ZG4Ug+NGZ0qM/V+fQkt+9ZrY2FH uO0FByHx+K24Ws8EhitV5LCRB98ZvdCm91LoE= MIME-Version: 1.0 Received: by 10.224.216.70 with SMTP id hh6mr87403qab.83.1306945465238; Wed, 01 Jun 2011 09:24:25 -0700 (PDT) Received: by 10.224.54.147 with HTTP; Wed, 1 Jun 2011 09:24:25 -0700 (PDT) In-Reply-To: <147534417.20110601184310@gf.microolap.com> References: <147534417.20110601184310@gf.microolap.com> Date: Wed, 1 Jun 2011 11:24:25 -0500 Message-ID: Subject: Re: PQdeleteTuple function in libpq From: Merlin Moncure To: Pavel Golub Cc: PostgreSQL Hackers , pgsql-interfaces@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/38 X-Sequence-Number: 188751 2011/6/1 Pavel Golub : > 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) > { > =A0 =A0 =A0 =A0if (!src) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return NULL; > > =A0 =A0 =A0 =A0int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 i, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0field; > > =A0 =A0 =A0 =A0/* Invalid tup_num, must be < ntups */ > =A0 =A0 =A0 =A0if (tup_num < 0 || tup_num >=3D src->ntups) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return FALSE; > > =A0 =A0 =A0 =A0free(src->tuples[tup_num]); > > =A0 =A0 =A0 =A0for (i =3D tup_num; i < src->ntups - 1; i++) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0src->tuples[i] =3D src->tuples[i + 1]; > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0src->ntups--; > =A0 =A0 =A0 =A0return 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