Search Postgresql Archives

libpq in Asynchronous mode and COPY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 can wait 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


 






-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux