| 320 | PG_FUNCTION_INFO_V1(plpgsql_inline_handler); |
| 321 | |
| 322 | Datum |
| 323 | plpgsql_inline_handler(PG_FUNCTION_ARGS) |
| 324 | { |
| 325 | LOCAL_FCINFO(fake_fcinfo, 0); |
| 326 | InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0))); |
| 327 | PLpgSQL_function *func; |
| 328 | FmgrInfo flinfo; |
| 329 | EState *simple_eval_estate; |
| 330 | ResourceOwner simple_eval_resowner; |
| 331 | Datum retval; |
| 332 | int rc; |
| 333 | |
| 334 | /* |
| 335 | * Connect to SPI manager |
| 336 | */ |
| 337 | if ((rc = SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC)) != SPI_OK_CONNECT) |
| 338 | elog(ERROR, "SPI_connect failed: %s", SPI_result_code_string(rc)); |
| 339 | |
| 340 | /* Compile the anonymous code block */ |
| 341 | func = plpgsql_compile_inline(codeblock->source_text); |
| 342 | |
| 343 | /* Mark the function as busy, just pro forma */ |
| 344 | func->use_count++; |
| 345 | |
| 346 | /* |
| 347 | * Set up a fake fcinfo with just enough info to satisfy |
| 348 | * plpgsql_exec_function(). In particular note that this sets things up |
| 349 | * with no arguments passed. |
| 350 | */ |
| 351 | MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0)); |
| 352 | MemSet(&flinfo, 0, sizeof(flinfo)); |
| 353 | fake_fcinfo->flinfo = &flinfo; |
| 354 | flinfo.fn_oid = InvalidOid; |
| 355 | flinfo.fn_mcxt = CurrentMemoryContext; |
| 356 | |
| 357 | /* |
| 358 | * Create a private EState and resowner for simple-expression execution. |
| 359 | * Notice that these are NOT tied to transaction-level resources; they |
| 360 | * must survive any COMMIT/ROLLBACK the DO block executes, since we will |
| 361 | * unconditionally try to clean them up below. (Hence, be wary of adding |
| 362 | * anything that could fail between here and the PG_TRY block.) See the |
| 363 | * comments for shared_simple_eval_estate. |
| 364 | * |
| 365 | * Because this resowner isn't tied to the calling transaction, we can |
| 366 | * also use it as the "procedure" resowner for any CALL statements. That |
| 367 | * helps reduce the opportunities for failure here. |
| 368 | */ |
| 369 | simple_eval_estate = CreateExecutorState(); |
| 370 | simple_eval_resowner = |
| 371 | ResourceOwnerCreate(NULL, "PL/pgSQL DO block simple expressions"); |
| 372 | |
| 373 | /* And run the function */ |
| 374 | PG_TRY(); |
| 375 | { |
| 376 | retval = plpgsql_exec_function(func, fake_fcinfo, |
| 377 | simple_eval_estate, |
| 378 | simple_eval_resowner, |
| 379 | simple_eval_resowner, /* see above */ |
nothing calls this directly
no test coverage detected