[GENERAL] Lifetime of PQexecPrepared() returned value - Mailing list pgsql-general

From Igor Korot
Subject [GENERAL] Lifetime of PQexecPrepared() returned value
Date
Msg-id CA+FnnTwG9qgqu3p0HcibiBq3=CN7wHoZxeNhtH8vy3+yVyFSCQ@mail.gmail.com
Whole thread Raw
Responses Re: [GENERAL] Lifetime of PQexecPrepared() returned value  (Michael Paquier <michael.paquier@gmail.com>)
Re: [GENERAL] Lifetime of PQexecPrepared() returned value  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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.


pgsql-general by date:

Previous
From: armand pirvu
Date:
Subject: Re: [GENERAL] hot standby questions
Next
From: Michael Paquier
Date:
Subject: Re: [GENERAL] Lifetime of PQexecPrepared() returned value