Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.postgresql > #774

Re: Anyone here do anything with libpq?

Path csiph.com!weretis.net!feeder6.news.weretis.net!news.glorb.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!post02.iad.highwinds-media.com!fx43.iad.POSTED!not-for-mail
From DFS <nospam@dfs.com>
Subject Re: Anyone here do anything with libpq?
Newsgroups comp.databases.postgresql
References <P6jSA.83362$qj5.21666@fx39.iad> <871srq6sfx.fsf@doppelsaurus.mobileactivedefense.com>
X-Mozilla-News-Host news://usnews.blocknews.net
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0
MIME-Version 1.0
In-Reply-To <871srq6sfx.fsf@doppelsaurus.mobileactivedefense.com>
Content-Type text/plain; charset=utf-8; format=flowed
Content-Language en-US
Content-Transfer-Encoding 7bit
Lines 50
Message-ID <weESA.199699$kI.27501@fx43.iad> (permalink)
X-Complaints-To abuse@blocknews.net
NNTP-Posting-Date Tue, 16 May 2017 14:43:40 UTC
Organization blocknews - www.blocknews.net
Date Tue, 16 May 2017 10:45:56 -0400
X-Received-Bytes 2512
X-Received-Body-CRC 862722182
Xref csiph.com comp.databases.postgresql:774

Show key headers only | View raw


On 5/15/2017 11:38 AM, Rainer Weikusat wrote:
> DFS <nospam@dfs.com> writes:
>> https://www.postgresql.org/docs/9.6/static/libpq.html
>>
>> <quote>
>> PQclear
>> Frees the storage associated with a PGresult. Every command result
>> should be freed via PQclear when it is no longer needed.
>>
>> void PQclear(PGresult *res);
>>
>> You can keep a PGresult object around for as long as you need it; it
>> does not go away when you issue a new command, nor even if you close
>> the connection. To get rid of it, you must call PQclear. Failure to do
>> this will result in memory leaks in your application.
>> </quote>
>>
>> 'when it is no longer needed' sounds like it can be cleared once, at
>> the end of the script.
> 
> There seems to be some kind of fundamental misunderstanding about the
> nature of 'a result set' here. Specifically,
> 
> PGresult *res;
> 
> is a C pointer to a PGresult (structure) and in order to avoid memory
> leaks, the result this pointer points to has to be freed before the
> pointer is overwritten aka reused.
> 
> There's no need to free the result if the pointer won't be reused, IOW,
> if the application is going to end next, anyway.

The question is, if I use a PGresult 10x during a program, should I 
clear it between each use, or is one clear at the end OK?


In VB it's not necessary but I always closed them before the next usage.

Set rs = db.openrecordset("SELECT DATA;")
if rs.recordcount > 0 then
   ... do things
endif
rs.close

Set rs = db.openrecordset("SELECT DATA 2nd time;")
if rs.recordcount > 0 then
   ... do things
endif
rs.close

Back to comp.databases.postgresql | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Anyone here do anything with libpq? DFS <nospam@dfs.com> - 2017-05-15 10:41 -0400
  Re: Anyone here do anything with libpq? Rainer Weikusat <rweikusat@talktalk.net> - 2017-05-15 16:38 +0100
    Re: Anyone here do anything with libpq? DFS <nospam@dfs.com> - 2017-05-16 10:45 -0400
      Re: Anyone here do anything with libpq? Rainer Weikusat <rweikusat@talktalk.net> - 2017-05-16 20:52 +0100
  Re: Anyone here do anything with libpq? Robert Klemme <shortcutter@googlemail.com> - 2017-05-15 19:54 +0200
    Re: Anyone here do anything with libpq? DFS <nospam@dfs.com> - 2017-05-16 14:01 -0400
      Re: Anyone here do anything with libpq? Robert Klemme <shortcutter@googlemail.com> - 2017-05-16 23:04 +0200
      Re: Anyone here do anything with libpq? George Neuner <gneuner2@comcast.net> - 2017-05-17 08:40 -0400

csiph-web