| PostgreSQL Reference Manual - Volume 2 - Programming Guide by The PostgreSQL Global Development Group Paperback (6"x9"), 408 pages ISBN 0954612035 RRP £19.95 ($34.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |
1.8.2 Functions for Receiving COPY Data
These functions are used to receive data during COPY TO STDOUT.
They will fail if called when the connection is not in COPY_OUT
state.
PQgetCopyData-
Receives data from the server during
COPY_OUTstate.int PQgetCopyData(PGconn *conn, char **buffer, int async);Attempts to obtain another row of data from the server during aCOPY. Data is always returned one data row at a time; if only a partial row is available, it is not returned. Successful return of a data row involves allocating a chunk of memory to hold the data. Thebufferparameter must be non-NULL.*bufferis set to point to the allocated memory, or toNULLin cases where no buffer is returned. A non-NULLresult buffer must be freed usingPQfreememwhen no longer needed. When a row is successfully returned, the return value is the number of data bytes in the row (this will always be greater than zero). The returned string is always null-terminated, though this is probably only useful for textualCOPY. A result of zero indicates that theCOPYis still in progress, but no row is yet available (this is only possible whenasyncis true). A result of -1 indicates that theCOPYis done. A result of -2 indicates that an error occurred (consultPQerrorMessagefor the reason). Whenasyncis true (not zero),PQgetCopyDatawill not block waiting for input; it will return zero if theCOPYis still in progress but no complete row is available. (In this case wait for read-ready and then callPQconsumeInputbefore callingPQgetCopyDataagain.) Whenasyncis false (zero),PQgetCopyDatawill block until data is available or the operation completes. AfterPQgetCopyDatareturns -1, callPQgetResultto obtain the final result status of theCOPYcommand. One may wait for this result to be available in the usual way. Then return to normal operation.
| ISBN 0954612035 | PostgreSQL Reference Manual - Volume 2 - Programming Guide | See the print edition |