* Finds an external protocol by passed in protocol name. * Errors if no such protocol exist, or if no function to * execute this protocol exists (for read or write separately). * * Returns the protocol function to use. */
| 274 | * Returns the protocol function to use. |
| 275 | */ |
| 276 | Oid |
| 277 | LookupExtProtocolFunction(const char *prot_name, |
| 278 | ExtPtcFuncType prot_type, |
| 279 | bool error) |
| 280 | { |
| 281 | Relation rel; |
| 282 | Oid funcOid = InvalidOid; |
| 283 | ScanKeyData skey; |
| 284 | SysScanDesc scan; |
| 285 | HeapTuple tup; |
| 286 | Form_pg_extprotocol extprot; |
| 287 | |
| 288 | rel = table_open(ExtprotocolRelationId, AccessShareLock); |
| 289 | |
| 290 | /* |
| 291 | * Check the pg_extprotocol relation to be certain the protocol |
| 292 | * is there. |
| 293 | */ |
| 294 | ScanKeyInit(&skey, |
| 295 | Anum_pg_extprotocol_ptcname, |
| 296 | BTEqualStrategyNumber, F_NAMEEQ, |
| 297 | CStringGetDatum(prot_name)); |
| 298 | scan = systable_beginscan(rel, ExtprotocolPtcnameIndexId, true, |
| 299 | NULL, 1, &skey); |
| 300 | tup = systable_getnext(scan); |
| 301 | |
| 302 | if (!HeapTupleIsValid(tup)) |
| 303 | ereport(ERROR, |
| 304 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 305 | errmsg("protocol \"%s\" does not exist", |
| 306 | prot_name))); |
| 307 | |
| 308 | extprot = (Form_pg_extprotocol) GETSTRUCT(tup); |
| 309 | |
| 310 | switch (prot_type) |
| 311 | { |
| 312 | case EXTPTC_FUNC_READER: |
| 313 | funcOid = extprot->ptcreadfn; |
| 314 | break; |
| 315 | case EXTPTC_FUNC_WRITER: |
| 316 | funcOid = extprot->ptcwritefn; |
| 317 | break; |
| 318 | case EXTPTC_FUNC_VALIDATOR: |
| 319 | funcOid = extprot->ptcvalidatorfn; |
| 320 | break; |
| 321 | default: |
| 322 | elog(ERROR, "internal error in pg_extprotocol:func_type_to_attnum"); |
| 323 | break; |
| 324 | } |
| 325 | systable_endscan(scan); |
| 326 | table_close(rel, AccessShareLock); |
| 327 | |
| 328 | if (!OidIsValid(funcOid) && error) |
| 329 | ereport(ERROR, |
| 330 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 331 | errmsg("protocol '%s' has no %s function defined", |
| 332 | prot_name, func_type_to_name(prot_type)))); |
| 333 |
no test coverage detected