Lifetime of PQexecPrepared() returned value

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Lifetime of PQexecPrepared() returned value
Date: 2017-08-04 19:12:37
Message-ID: CA+FnnTwG9qgqu3p0HcibiBq3=CN7wHoZxeNhtH8vy3+yVyFSCQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, ALL,
I have a following piece of code:

[code]
PGresult *res = PQexecPrepared();
status = PQresultStatue( res );
if( status == PGRES_TUPLES_OK )
{
for( int j = 0; j < PQntuples( res ); j++ )
{
char *foo = PQgetValue( res, j, 0 );
char *bar = PQgetValue( res, j, 1 );
MyObject *obj = new MyObject( foo, bar );
if( SetAdditionalProperties( obj ) )
{
result = 1;
break;
}
}
PQclear( res );
}

int SetAdditionalProperties(MyObject &obj)
{
// a call to PQexecParams() here
}
[/code]

If the call to SetAdditionalProperties() fails, I get a crash on
PQclear(), stating that
the pointer is not allocated.

Am I missing something? How do I fix the crash?

Thank you.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2017-08-04 19:26:55 Re: Lifetime of PQexecPrepared() returned value
Previous Message armand pirvu 2017-08-04 12:21:10 Re: hot standby questions