| 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.1 Functions for Sending COPY Data
These functions are used to send data during COPY FROM STDIN.
They will fail if called when the connection is not in COPY_IN
state.
PQputCopyData-
Sends data to the server during
COPY_INstate.int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);Transmits theCOPYdata in the specifiedbuffer, of lengthnbytes, to the server. The result is 1 if the data was sent, zero if it was not sent because the attempt would block (this case is only possible if the connection is in nonblocking mode), or -1 if an error occurred. (UsePQerrorMessageto retrieve details if the return value is -1. If the value is zero, wait for write-ready and try again.) The application may divide theCOPYdata stream into buffer loads of any convenient size. Buffer-load boundaries have no semantic significance when sending. The contents of the data stream must match the data format expected by theCOPYcommand; seeCOPYfor details. PQputCopyEnd-
Sends end-of-data indication to the server during
COPY_INstate.int PQputCopyEnd(PGconn *conn, const char *errormsg);Ends theCOPY_INoperation successfully iferrormsgisNULL. Iferrormsgis notNULLthen theCOPYis forced to fail, with the string pointed to byerrormsgused as the error message. (One should not assume that this exact error message will come back from the server, however, as the server might have already failed theCOPYfor its own reasons. Also note that the option to force failure does not work when using pre-3.0-protocol connections.) The result is 1 if the termination data was sent, zero if it was not sent because the attempt would block (this case is only possible if the connection is in nonblocking mode), or -1 if an error occurred. (UsePQerrorMessageto retrieve details if the return value is -1. If the value is zero, wait for write-ready and try again.) After successfully callingPQputCopyEnd, 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 |