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

Function PQputCopyEnd

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

* PQputCopyEnd - send EOF indication to the backend during COPY IN * * After calling this, use PQgetResult() to check command completion status. * * 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

2636 * in nonblock mode), or -1 if an error occurs.
2637 */
2638int
2639PQputCopyEnd(PGconn *conn, const char *errormsg)
2640{
2641 if (!conn)
2642 return -1;
2643 if (conn->asyncStatus != PGASYNC_COPY_IN &&
2644 conn->asyncStatus != PGASYNC_COPY_BOTH)
2645 {
2646 appendPQExpBufferStr(&conn->errorMessage,
2647 libpq_gettext("no COPY in progress\n"));
2648 return -1;
2649 }
2650
2651 /*
2652 * Send the COPY END indicator. This is simple enough that we don't
2653 * bother delegating it to the fe-protocol files.
2654 */
2655 if (errormsg)
2656 {
2657 /* Send COPY FAIL */
2658 if (pqPutMsgStart('f', conn) < 0 ||
2659 pqPuts(errormsg, conn) < 0 ||
2660 pqPutMsgEnd(conn) < 0)
2661 return -1;
2662 }
2663 else
2664 {
2665 /* Send COPY DONE */
2666 if (pqPutMsgStart('c', conn) < 0 ||
2667 pqPutMsgEnd(conn) < 0)
2668 return -1;
2669 }
2670
2671 /*
2672 * If we sent the COPY command in extended-query mode, we must issue a
2673 * Sync as well.
2674 */
2675 if (conn->cmd_queue_head &&
2676 conn->cmd_queue_head->queryclass != PGQUERY_SIMPLE)
2677 {
2678 if (pqPutMsgStart('S', conn) < 0 ||
2679 pqPutMsgEnd(conn) < 0)
2680 return -1;
2681 }
2682
2683 /* Return to active duty */
2684 if (conn->asyncStatus == PGASYNC_COPY_BOTH)
2685 conn->asyncStatus = PGASYNC_COPY_OUT;
2686 else
2687 conn->asyncStatus = PGASYNC_BUSY;
2688
2689 /* Try to flush data */
2690 if (pqFlush(conn) < 0)
2691 return -1;
2692
2693 return 1;
2694}
2695

Callers 10

libpqrcv_endstreamingFunction · 0.85
cdbCopyEndInternalFunction · 0.85
PQexecStartFunction · 0.85
libpq_executeFileMapFunction · 0.85
handleCopyInFunction · 0.85
EndDBCopyModeFunction · 0.85
prepareToTerminateFunction · 0.85
ProcessXLogDataMsgFunction · 0.85
HandleEndOfCopyStreamFunction · 0.85
CheckCopyStreamStopFunction · 0.85

Calls 6

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
pqPutMsgStartFunction · 0.85
pqPutsFunction · 0.85
pqPutMsgEndFunction · 0.85
pqFlushFunction · 0.85

Tested by

no test coverage detected