Re: [GENERAL] Lifetime of PQexecPrepared() returned value

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [GENERAL] Lifetime of PQexecPrepared() returned value
Дата
Msg-id 19607.1501880476@sss.pgh.pa.us
обсуждение исходный текст
Ответ на [GENERAL] Lifetime of PQexecPrepared() returned value  (Igor Korot <ikorot01@gmail.com>)
Ответы Re: [GENERAL] Lifetime of PQexecPrepared() returned value
Список pgsql-general
Igor Korot <ikorot01@gmail.com> writes:
> 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 );
> }

What I'm wondering about is whether the MyObject constructor is making
copies of the strings it's passed, or whether it thinks it can just hold
onto those pointers.  The pointers would be dangling once you do PQclear.
Now, if the MyObject has gone out of scope and been destroyed, which
this coding suggests would happen, then that shouldn't matter ... but
maybe the pointers got copied to somewhere longer-lived?  Anyway, there's
nothing visibly wrong with what you showed us, so the problem is somewhere
else.

            regards, tom lane


В списке pgsql-general по дате отправления:

Предыдущее
От: Igor Korot
Дата:
Сообщение: Re: [GENERAL] Lifetime of PQexecPrepared() returned value
Следующее
От: Alexander Farber
Дата:
Сообщение: [GENERAL] Type cast in PHP PDO (does not work like in Java?)