* fetch_cursor_param_value * * Fetch the string value of a param, verifying it is of type REFCURSOR. */
| 530 | * Fetch the string value of a param, verifying it is of type REFCURSOR. |
| 531 | */ |
| 532 | static char * |
| 533 | fetch_cursor_param_value(ExprContext *econtext, int paramId) |
| 534 | { |
| 535 | ParamListInfo paramInfo = econtext->ecxt_param_list_info; |
| 536 | |
| 537 | if (paramInfo && |
| 538 | paramId > 0 && paramId <= paramInfo->numParams) |
| 539 | { |
| 540 | ParamExternData *prm; |
| 541 | ParamExternData prmdata; |
| 542 | |
| 543 | /* give hook a chance in case parameter is dynamic */ |
| 544 | if (paramInfo->paramFetch != NULL) |
| 545 | prm = paramInfo->paramFetch(paramInfo, paramId, false, &prmdata); |
| 546 | else |
| 547 | prm = ¶mInfo->params[paramId - 1]; |
| 548 | |
| 549 | if (OidIsValid(prm->ptype) && !prm->isnull) |
| 550 | { |
| 551 | /* safety check in case hook did something unexpected */ |
| 552 | if (prm->ptype != REFCURSOROID) |
| 553 | ereport(ERROR, |
| 554 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 555 | errmsg("type of parameter %d (%s) does not match that when preparing the plan (%s)", |
| 556 | paramId, |
| 557 | format_type_be(prm->ptype), |
| 558 | format_type_be(REFCURSOROID)))); |
| 559 | |
| 560 | /* We know that refcursor uses text's I/O routines */ |
| 561 | return TextDatumGetCString(prm->value); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | ereport(ERROR, |
| 566 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 567 | errmsg("no value found for parameter %d", paramId))); |
| 568 | return NULL; |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * search_plan_tree |
no test coverage detected