* command_update_txn_proc handles the update command invocation through a PostgreSQL procedure. * this function behaves the same way as command_update. */
| 464 | * this function behaves the same way as command_update. |
| 465 | */ |
| 466 | Datum |
| 467 | command_update_txn_proc(PG_FUNCTION_ARGS) |
| 468 | { |
| 469 | if (PG_ARGISNULL(1)) |
| 470 | { |
| 471 | ereport(ERROR, (errmsg("update document cannot be NULL"))); |
| 472 | } |
| 473 | |
| 474 | Datum databaseNameDatum = PG_ARGISNULL(0) ? (Datum) 0 : PG_GETARG_DATUM(0); |
| 475 | pgbson *updateSpec = PG_GETARG_PGBSON(1); |
| 476 | |
| 477 | pgbsonsequence *updateDocs = PG_GETARG_MAYBE_NULL_PGBSON_SEQUENCE(2); |
| 478 | |
| 479 | text *transactionId = NULL; |
| 480 | if (!PG_ARGISNULL(3)) |
| 481 | { |
| 482 | transactionId = PG_GETARG_TEXT_P(3); |
| 483 | } |
| 484 | |
| 485 | ReportFeatureUsage(FEATURE_COMMAND_UPDATE); |
| 486 | |
| 487 | bool isTopLevel = true; |
| 488 | if (IsInTransactionBlock(isTopLevel)) |
| 489 | { |
| 490 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_OPERATIONNOTSUPPORTEDINTRANSACTION), |
| 491 | errmsg("the update procedure cannot be used in transactions." |
| 492 | " Please use the update function instead"))); |
| 493 | } |
| 494 | |
| 495 | /* fetch TupleDesc for return value, not interested in resultTypeId */ |
| 496 | Oid *resultTypeId = NULL; |
| 497 | TupleDesc resultTupDesc; |
| 498 | TypeFuncClass resultTypeClass = |
| 499 | get_call_result_type(fcinfo, resultTypeId, &resultTupDesc); |
| 500 | |
| 501 | if (resultTypeClass != TYPEFUNC_COMPOSITE) |
| 502 | { |
| 503 | ereport(ERROR, (errmsg("return type must be a row type"))); |
| 504 | } |
| 505 | |
| 506 | /* Use function context as a stable memory context to store errors across transaction aborts */ |
| 507 | HeapTuple resultTuple = PerformUpdateCore(&databaseNameDatum, updateSpec, updateDocs, |
| 508 | transactionId, resultTupDesc, |
| 509 | WriteMode_Txn_Proc, |
| 510 | fcinfo->flinfo->fn_mcxt); |
| 511 | PG_RETURN_DATUM(HeapTupleGetDatum(resultTuple)); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /* |
nothing calls this directly
no test coverage detected