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

Function prepare_foreign_modify

contrib/postgres_fdw/postgres_fdw.c:4208–4252  ·  view source on GitHub ↗

* prepare_foreign_modify * Establish a prepared statement for execution of INSERT/UPDATE/DELETE */

Source from the content-addressed store, hash-verified

4206 * Establish a prepared statement for execution of INSERT/UPDATE/DELETE
4207 */
4208static void
4209prepare_foreign_modify(PgFdwModifyState *fmstate)
4210{
4211 char prep_name[NAMEDATALEN];
4212 char *p_name;
4213 PGresult *res;
4214
4215 /*
4216 * The caller would already have processed a pending asynchronous request
4217 * if any, so no need to do it here.
4218 */
4219
4220 /* Construct name we'll use for the prepared statement. */
4221 snprintf(prep_name, sizeof(prep_name), "pgsql_fdw_prep_%u",
4222 GetPrepStmtNumber(fmstate->conn));
4223 p_name = pstrdup(prep_name);
4224
4225 /*
4226 * We intentionally do not specify parameter types here, but leave the
4227 * remote server to derive them by default. This avoids possible problems
4228 * with the remote server using different type OIDs than we do. All of
4229 * the prepared statements we use in this module are simple enough that
4230 * the remote server will make the right choices.
4231 */
4232 if (!PQsendPrepare(fmstate->conn,
4233 p_name,
4234 fmstate->query,
4235 0,
4236 NULL))
4237 pgfdw_report_error(ERROR, NULL, fmstate->conn, false, fmstate->query);
4238
4239 /*
4240 * Get the result, and check for success.
4241 *
4242 * We don't use a PG_TRY block here, so be careful not to throw error
4243 * without releasing the PGresult.
4244 */
4245 res = pgfdw_get_result(fmstate->conn, fmstate->query);
4246 if (PQresultStatus(res) != PGRES_COMMAND_OK)
4247 pgfdw_report_error(ERROR, res, fmstate->conn, true, fmstate->query);
4248 PQclear(res);
4249
4250 /* This action shows that the prepare has been done. */
4251 fmstate->p_name = p_name;
4252}
4253
4254/*
4255 * convert_prep_stmt_params

Callers 1

execute_foreign_modifyFunction · 0.85

Calls 7

GetPrepStmtNumberFunction · 0.85
PQsendPrepareFunction · 0.85
pgfdw_report_errorFunction · 0.85
pgfdw_get_resultFunction · 0.85
PQresultStatusFunction · 0.85
PQclearFunction · 0.85
pstrdupFunction · 0.50

Tested by

no test coverage detected