MCPcopy Create free account
hub / github.com/apache/cloudberry / PQputCopyData

Function PQputCopyData

src/interfaces/libpq/fe-exec.c:2582–2628  ·  view source on GitHub ↗

* PQputCopyData - send some data to the backend during COPY IN or COPY BOTH * * Returns 1 if successful, 0 if data could not be sent (only possible * in nonblock mode), or -1 if an error occurs. */

Source from the content-addressed store, hash-verified

2580 * in nonblock mode), or -1 if an error occurs.
2581 */
2582int
2583PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
2584{
2585 if (!conn)
2586 return -1;
2587 if (conn->asyncStatus != PGASYNC_COPY_IN &&
2588 conn->asyncStatus != PGASYNC_COPY_BOTH)
2589 {
2590 appendPQExpBufferStr(&conn->errorMessage,
2591 libpq_gettext("no COPY in progress\n"));
2592 return -1;
2593 }
2594
2595 /*
2596 * Process any NOTICE or NOTIFY messages that might be pending in the
2597 * input buffer. Since the server might generate many notices during the
2598 * COPY, we want to clean those out reasonably promptly to prevent
2599 * indefinite expansion of the input buffer. (Note: the actual read of
2600 * input data into the input buffer happens down inside pqSendSome, but
2601 * it's not authorized to get rid of the data again.)
2602 */
2603 parseInput(conn);
2604
2605 if (nbytes > 0)
2606 {
2607 /*
2608 * Try to flush any previously sent data in preference to growing the
2609 * output buffer. If we can't enlarge the buffer enough to hold the
2610 * data, return 0 in the nonblock case, else hard error. (For
2611 * simplicity, always assume 5 bytes of overhead.)
2612 */
2613 if ((conn->outBufSize - conn->outCount - 5) < nbytes)
2614 {
2615 if (pqFlush(conn) < 0)
2616 return -1;
2617 if (pqCheckOutBufferSpace(conn->outCount + 5 + (size_t) nbytes,
2618 conn))
2619 return pqIsnonblocking(conn) ? 0 : -1;
2620 }
2621 /* Send the data (too simple to delegate to fe-protocol files) */
2622 if (pqPutMsgStart('d', conn) < 0 ||
2623 pqPutnchar(buffer, nbytes, conn) < 0 ||
2624 pqPutMsgEnd(conn) < 0)
2625 return -1;
2626 }
2627 return 1;
2628}
2629
2630/*
2631 * PQputCopyEnd - send EOF indication to the backend during COPY IN

Callers 8

libpqrcv_sendFunction · 0.85
cdbCopySendDataFunction · 0.85
PQputnbytesFunction · 0.85
fetch_file_rangeFunction · 0.85
handleCopyInFunction · 0.85
ExecuteSqlCommandBufFunction · 0.85
sendFeedbackFunction · 0.85
sendFeedbackFunction · 0.85

Calls 8

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
parseInputFunction · 0.85
pqFlushFunction · 0.85
pqCheckOutBufferSpaceFunction · 0.85
pqPutMsgStartFunction · 0.85
pqPutncharFunction · 0.85
pqPutMsgEndFunction · 0.85

Tested by

no test coverage detected