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

Function PQexecStart

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

* Common code for PQexec and sibling routines: prepare to send command */

Source from the content-addressed store, hash-verified

2311 * Common code for PQexec and sibling routines: prepare to send command
2312 */
2313static bool
2314PQexecStart(PGconn *conn)
2315{
2316 PGresult *result;
2317
2318 if (!conn)
2319 return false;
2320
2321 if (conn->pipelineStatus != PQ_PIPELINE_OFF)
2322 {
2323 appendPQExpBufferStr(&conn->errorMessage,
2324 libpq_gettext("synchronous command execution functions are not allowed in pipeline mode\n"));
2325 return false;
2326 }
2327
2328 /*
2329 * Since this is the beginning of a query cycle, reset the error buffer.
2330 */
2331 resetPQExpBuffer(&conn->errorMessage);
2332
2333 /*
2334 * Silently discard any prior query result that application didn't eat.
2335 * This is probably poor design, but it's here for backward compatibility.
2336 */
2337 while ((result = PQgetResult(conn)) != NULL)
2338 {
2339 ExecStatusType resultStatus = result->resultStatus;
2340
2341 PQclear(result); /* only need its status */
2342 if (resultStatus == PGRES_COPY_IN)
2343 {
2344 /* get out of a COPY IN state */
2345 if (PQputCopyEnd(conn,
2346 libpq_gettext("COPY terminated by new PQexec")) < 0)
2347 return false;
2348 /* keep waiting to swallow the copy's failure message */
2349 }
2350 else if (resultStatus == PGRES_COPY_OUT)
2351 {
2352 /*
2353 * Get out of a COPY OUT state: we just switch back to BUSY and
2354 * allow the remaining COPY data to be dropped on the floor.
2355 */
2356 conn->asyncStatus = PGASYNC_BUSY;
2357 /* keep waiting to swallow the copy's completion message */
2358 }
2359 else if (resultStatus == PGRES_COPY_BOTH)
2360 {
2361 /* We don't allow PQexec during COPY BOTH */
2362 appendPQExpBufferStr(&conn->errorMessage,
2363 libpq_gettext("PQexec not allowed during COPY BOTH\n"));
2364 return false;
2365 }
2366 /* check for loss of connection, too */
2367 if (conn->status == CONNECTION_BAD)
2368 return false;
2369 }
2370

Callers 6

PQexecFunction · 0.85
PQexecParamsFunction · 0.85
PQprepareFunction · 0.85
PQexecPreparedFunction · 0.85
PQdescribePreparedFunction · 0.85
PQdescribePortalFunction · 0.85

Calls 6

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
resetPQExpBufferFunction · 0.85
PQgetResultFunction · 0.85
PQclearFunction · 0.85
PQputCopyEndFunction · 0.85

Tested by

no test coverage detected