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

Function PQgetResult

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

* PQgetResult * Get the next PGresult produced by a query. Returns NULL if no * query work remains or an error has occurred (e.g. out of * memory). * * In pipeline mode, once all the result of a query have been returned, * PQgetResult returns NULL to let the user know that the next * query is being processed. At the end of the pipeline, returns a * result with PQresultStatu

Source from the content-addressed store, hash-verified

2014 * result with PQresultStatus(result) == PGRES_PIPELINE_SYNC.
2015 */
2016PGresult *
2017PQgetResult(PGconn *conn)
2018{
2019 PGresult *res;
2020
2021 if (!conn)
2022 return NULL;
2023
2024 /* Parse any available data, if our state permits. */
2025 parseInput(conn);
2026
2027 /* If not ready to return something, block until we are. */
2028 while (conn->asyncStatus == PGASYNC_BUSY)
2029 {
2030 int flushResult;
2031
2032 /*
2033 * If data remains unsent, send it. Else we might be waiting for the
2034 * result of a command the backend hasn't even got yet.
2035 */
2036 while ((flushResult = pqFlush(conn)) > 0)
2037 {
2038 if (pqWait(false, true, conn))
2039 {
2040 flushResult = -1;
2041 break;
2042 }
2043 }
2044
2045 /*
2046 * Wait for some more data, and load it. (Note: if the connection has
2047 * been lost, pqWait should return immediately because the socket
2048 * should be read-ready, either with the last server data or with an
2049 * EOF indication. We expect therefore that this won't result in any
2050 * undue delay in reporting a previous write failure.)
2051 */
2052 if (flushResult ||
2053 pqWait(true, false, conn) ||
2054 pqReadData(conn) < 0)
2055 {
2056 /*
2057 * conn->errorMessage has been set by pqWait or pqReadData. We
2058 * want to append it to any already-received error message.
2059 */
2060 pqSaveErrorResult(conn);
2061 conn->asyncStatus = PGASYNC_IDLE;
2062 return pqPrepareAsyncResult(conn);
2063 }
2064
2065 /* Parse it. */
2066 parseInput(conn);
2067
2068 /*
2069 * If we had a write error, but nothing above obtained a query result
2070 * or detected a read error, report the write error.
2071 */
2072 if (conn->write_failed && conn->asyncStatus == PGASYNC_BUSY)
2073 {

Callers 15

pgfdw_get_resultFunction · 0.85
pgfdw_get_cleanup_resultFunction · 0.85
dblink_record_internalFunction · 0.85
materializeQueryResultFunction · 0.85
storeQueryResultFunction · 0.85
ftsReceiveFunction · 0.85
ManageCronTaskFunction · 0.85
libpqrcv_PQgetResultFunction · 0.85
cdbCopyEndInternalFunction · 0.85
cdbconn_discardResultsFunction · 0.85
processResultsFunction · 0.85
consumeQueryResultFunction · 0.85

Calls 15

parseInputFunction · 0.85
pqFlushFunction · 0.85
pqWaitFunction · 0.85
pqReadDataFunction · 0.85
pqSaveErrorResultFunction · 0.85
pqPrepareAsyncResultFunction · 0.85
pqSaveWriteErrorFunction · 0.85
resetPQExpBufferFunction · 0.85
pqPipelineProcessQueueFunction · 0.85
pqCommandQueueAdvanceFunction · 0.85
getCopyResultFunction · 0.85
appendPQExpBufferFunction · 0.85

Tested by 11

try_complete_stepFunction · 0.68
test_multi_pipelinesFunction · 0.68
test_nosyncFunction · 0.68
test_pipeline_abortFunction · 0.68
test_pipelined_insertFunction · 0.68
test_preparedFunction · 0.68
test_simple_pipelineFunction · 0.68
test_singlerowmodeFunction · 0.68
test_transactionFunction · 0.68
test_uniqviolFunction · 0.68
process_resultFunction · 0.68