Re: [HACKERS] Oid Questions

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [HACKERS] Oid Questions
Дата
Msg-id 199801222209.RAA15528@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] Oid Questions  (Zeev Suraski <bourbon@netvision.net.il>)
Ответы Re: [HACKERS] Oid Questions  (Zeev Suraski <bourbon@netvision.net.il>)
Список pgsql-hackers
>
> At 16:25 22/01/98 -0500, Bruce Momjian wrote:
> >A zero value for OID is reserved for an Invalid OID.  If it returns a
> >zero, I would pass it back to the application.  You may want to call
> >libpq's PQoidStatus() to get this information.  That is a new function
> >for 6.2.1.
>
> Ok, please tell me if this logic is correct.  It describes the logic behind
> the implementation of pg_exec() in PHP.
>
> First, the query is executed.  If the status is PGRES_EMPTY_QUERY or
> PGRES_BAD_RESPONSE or PGRES_NONFATAL_ERROR or PGRES_FATAL_ERROR, return
> FALSE (failure).
> If it returns PGRES_COMMAND_OK (which is, from what I understand, a
> successful query that is, by definition, not supposed to return rows) -
> check PQoidStatus().  If it's not null, atoi() of it is not 0, return its
> return value as a numeric integer.  If it is zero, assume that this was a
> successful query that didn't cause the oid to be updated, and return TRUE
> (successful query that does not return rows or oid).
> Otherwise, assume that that was a succesful query that returned rows -
> return a PostgresSQL result identifier.

Sorry, got lost in this paragraph.

>
> I guess that my key question is, whether or not it's correct to assume
> PGRES_COMMAND_OK + PQoidStatus() == 0 or "0"   => successful query that did
> not return rows and did not update the oid, OR, is it possible that
> PQoidStatus() of zero reflects some error, even though the return value was
> PGRES_COMMAND_OK?

It is the result status, PGRES_COMMAND_OK that is important. The
PQoidStatus() is really there just as an aid.  Only an INSERT returns an
OID as part of the result string.  We use this function to just pull it
out of the string.  If they do a SELECT ... INTO, they are inserting
zero or multiple OIDs, so this value is the last oid inserted.

We also have new in 6.2.1 PQcmdTuples(), which shows how many rows were
affected by the INSERT, UPDATE, or DELETE.  Again, it comes out of the
string returned in the Result structure.

See libpq/fe-exec.c for the source to both of these.

>
> PHP can return different datatypes from the same function, in case you were
> wondering :)

Yep, I remember.

--
Bruce Momjian
maillist@candle.pha.pa.us

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

Предыдущее
От: Zeev Suraski
Дата:
Сообщение: Re: [HACKERS] Oid Questions
Следующее
От: Zeev Suraski
Дата:
Сообщение: Re: [HACKERS] Oid Questions