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

Function pqEndcopy3

src/interfaces/libpq/fe-protocol3.c:2059–2145  ·  view source on GitHub ↗

* PQendcopy * * See fe-exec.c for documentation. */

Source from the content-addressed store, hash-verified

2057 * See fe-exec.c for documentation.
2058 */
2059int
2060pqEndcopy3(PGconn *conn)
2061{
2062 PGresult *result;
2063
2064 if (conn->asyncStatus != PGASYNC_COPY_IN &&
2065 conn->asyncStatus != PGASYNC_COPY_OUT &&
2066 conn->asyncStatus != PGASYNC_COPY_BOTH)
2067 {
2068 appendPQExpBufferStr(&conn->errorMessage,
2069 libpq_gettext("no COPY in progress\n"));
2070 return 1;
2071 }
2072
2073 /* Send the CopyDone message if needed */
2074 if (conn->asyncStatus == PGASYNC_COPY_IN ||
2075 conn->asyncStatus == PGASYNC_COPY_BOTH)
2076 {
2077 if (pqPutMsgStart('c', conn) < 0 ||
2078 pqPutMsgEnd(conn) < 0)
2079 return 1;
2080
2081 /*
2082 * If we sent the COPY command in extended-query mode, we must issue a
2083 * Sync as well.
2084 */
2085 if (conn->cmd_queue_head &&
2086 conn->cmd_queue_head->queryclass != PGQUERY_SIMPLE)
2087 {
2088 if (pqPutMsgStart('S', conn) < 0 ||
2089 pqPutMsgEnd(conn) < 0)
2090 return 1;
2091 }
2092 }
2093
2094 /*
2095 * make sure no data is waiting to be sent, abort if we are non-blocking
2096 * and the flush fails
2097 */
2098 if (pqFlush(conn) && pqIsnonblocking(conn))
2099 return 1;
2100
2101 /* Return to active duty */
2102 conn->asyncStatus = PGASYNC_BUSY;
2103
2104 /*
2105 * Non blocking connections may have to abort at this point. If everyone
2106 * played the game there should be no problem, but in error scenarios the
2107 * expected messages may not have arrived yet. (We are assuming that the
2108 * backend's packetizing will ensure that CommandComplete arrives along
2109 * with the CopyDone; are there corner cases where that doesn't happen?)
2110 */
2111 if (pqIsnonblocking(conn) && PQisBusy(conn))
2112 return 1;
2113
2114 /* Wait for the completion response */
2115 result = PQgetResult(conn);
2116

Callers 1

PQendcopyFunction · 0.85

Calls 9

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
pqPutMsgStartFunction · 0.85
pqPutMsgEndFunction · 0.85
pqFlushFunction · 0.85
PQisBusyFunction · 0.85
PQgetResultFunction · 0.85
PQclearFunction · 0.85
pqInternalNoticeFunction · 0.85

Tested by

no test coverage detected