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

Function GetForeignServerExtended

src/backend/foreign/foreign.c:211–277  ·  view source on GitHub ↗

* GetForeignServerExtended - look up the foreign server definition. If * flags uses FSV_MISSING_OK, return NULL if the object cannot be found * instead of raising an error. */

Source from the content-addressed store, hash-verified

209 * instead of raising an error.
210 */
211ForeignServer *
212GetForeignServerExtended(Oid serverid, bits16 flags)
213{
214 Form_pg_foreign_server serverform;
215 ForeignServer *server;
216 HeapTuple tp;
217 Datum datum;
218 bool isnull;
219
220 tp = SearchSysCache1(FOREIGNSERVEROID, ObjectIdGetDatum(serverid));
221
222 if (!HeapTupleIsValid(tp))
223 {
224 if ((flags & FSV_MISSING_OK) == 0)
225 elog(ERROR, "cache lookup failed for foreign server %u", serverid);
226 return NULL;
227 }
228
229 serverform = (Form_pg_foreign_server) GETSTRUCT(tp);
230
231 server = (ForeignServer *) palloc(sizeof(ForeignServer));
232 server->serverid = serverid;
233 server->servername = pstrdup(NameStr(serverform->srvname));
234 server->owner = serverform->srvowner;
235 server->fdwid = serverform->srvfdw;
236
237 /* Extract server type */
238 datum = SysCacheGetAttr(FOREIGNSERVEROID,
239 tp,
240 Anum_pg_foreign_server_srvtype,
241 &isnull);
242 server->servertype = isnull ? NULL : TextDatumGetCString(datum);
243
244 /* Extract server version */
245 datum = SysCacheGetAttr(FOREIGNSERVEROID,
246 tp,
247 Anum_pg_foreign_server_srvversion,
248 &isnull);
249 server->serverversion = isnull ? NULL : TextDatumGetCString(datum);
250
251 /* Extract the srvoptions */
252 datum = SysCacheGetAttr(FOREIGNSERVEROID,
253 tp,
254 Anum_pg_foreign_server_srvoptions,
255 &isnull);
256 if (isnull)
257 server->options = NIL;
258 else
259 server->options = untransformRelOptions(datum);
260
261 server->exec_location = SeparateOutMppExecute(&server->options);
262 if (server->exec_location == FTEXECLOCATION_NOT_DEFINED)
263 {
264 ForeignDataWrapper *fdw = GetForeignDataWrapper(server->fdwid);
265 server->exec_location = fdw->exec_location;
266 }
267
268 server->num_segments = SeparateOutNumSegments(&server->options);

Callers 5

GetForeignServerFunction · 0.85
getObjectDescriptionFunction · 0.85
getObjectIdentityPartsFunction · 0.85

Calls 11

SearchSysCache1Function · 0.85
ObjectIdGetDatumFunction · 0.85
SysCacheGetAttrFunction · 0.85
untransformRelOptionsFunction · 0.85
SeparateOutMppExecuteFunction · 0.85
GetForeignDataWrapperFunction · 0.85
SeparateOutNumSegmentsFunction · 0.85
getgpsegmentCountFunction · 0.85
ReleaseSysCacheFunction · 0.85
pallocFunction · 0.50
pstrdupFunction · 0.50

Tested by

no test coverage detected