libpq in Asynchronous mode and COPY

Поиск
Список
Период
Сортировка
От Michael Leib
Тема libpq in Asynchronous mode and COPY
Дата
Msg-id 450067.14381.qm@web50507.mail.re2.yahoo.com
обсуждение исходный текст
Ответы Re: libpq in Asynchronous mode and COPY  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hi -

I'm using v8.4.4 and have an application written using libpq
in Asynchronous Command Mode and primarily dealing with the
COPY related apis. I have been successful in getting my application
working, but have come across an issue that I would like to determine
if I have done something wrong (probably), it's FAD (functioning as
designed) or a defect (doubtful).

As an aside, I am using libev to handle my event processing.

Basically, here is my question - I do the following:

Issue "COPY tablename( columns ) FROM stdin with delimiter..." using
PQsendQueryParams() and go into ready state..

I get notified that an event is pending and enter my switchboard

I call PQconsumeInput() and PQtransactionStatus() returns PQTRANS_ACTIVE

I check for PQisBusy() == 0 and then call PQgetResult()

Then PQresultStatus() == PGRES_COPY_IN, so I start the using the COPY API's
PQputCopyData, PQputCopyEnd and then call PQgetResult() to determine the
status of PQputCopyEnd(). These are all successful and no errors are
returned. I then go into ready state...

I get notified that an event is pending and enter my switchboard

Here is where it gets interesting and I am having the problem:

1) If there was an error returned from the server that the COPY failed
(in my case, a foreign-key constraint was not met on one or more of
my rows), after doing the normal PQconsumeInput(), PQtransactionStatus()
and PQisBusy() checks (as described above), PQgetResult() returns the
fatal error after examining the PGresult via PQresultStatus().

This is all good.

2) If there was NO ERROR (and all the rows appear in the target table
within the db) my issue is that I DO get notified that the COPY completed
(because I receive  the pending event and my switchboard is called)
but, after doing PQconsumeInput(), PQtransactionStatus() (which is PQTRANS_ACTIVE) and PQisBusy(), when I call
PQgetResult()it returns NULL upon first call - I get no PGresult return. 

My issue/question is that I would expect to not have a NULL returned
and, rather, I was expecting to see a PGresult with a status of PGRES_COMMAND_OK.

Am I incorrect or is what I'm experiencing intended?

The doc states:

"After successfully calling PQputCopyEnd, call PQgetResult to obtain the final result status of the COPY command. One
canwait for this result to be available in the usual way. Then return to normal operation" 

Normal operation, to me at least, means I would get a GPRES_COMMAND_OK.
If I'm wrong, I apologize in advance. Just trying to see what I did
wrong, if anything.

Thanks,

Michael









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

Предыдущее
От: Mike Christensen
Дата:
Сообщение: Re: Best way to store case-insensitive data?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: libpq in Asynchronous mode and COPY