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

Function PLy_modify_tuple

src/pl/plpython/plpy_exec.c:925–1055  ·  view source on GitHub ↗

* Apply changes requested by a MODIFY return from a trigger function. */

Source from the content-addressed store, hash-verified

923 * Apply changes requested by a MODIFY return from a trigger function.
924 */
925static HeapTuple
926PLy_modify_tuple(PLyProcedure *proc, PyObject *pltd, TriggerData *tdata,
927 HeapTuple otup)
928{
929 HeapTuple rtup;
930 PyObject *volatile plntup;
931 PyObject *volatile plkeys;
932 PyObject *volatile plval;
933 Datum *volatile modvalues;
934 bool *volatile modnulls;
935 bool *volatile modrepls;
936 ErrorContextCallback plerrcontext;
937
938 plerrcontext.callback = plpython_trigger_error_callback;
939 plerrcontext.previous = error_context_stack;
940 error_context_stack = &plerrcontext;
941
942 plntup = plkeys = plval = NULL;
943 modvalues = NULL;
944 modnulls = NULL;
945 modrepls = NULL;
946
947 PG_TRY();
948 {
949 TupleDesc tupdesc;
950 int nkeys,
951 i;
952
953 if ((plntup = PyDict_GetItemString(pltd, "new")) == NULL)
954 ereport(ERROR,
955 (errcode(ERRCODE_UNDEFINED_OBJECT),
956 errmsg("TD[\"new\"] deleted, cannot modify row")));
957 Py_INCREF(plntup);
958 if (!PyDict_Check(plntup))
959 ereport(ERROR,
960 (errcode(ERRCODE_DATATYPE_MISMATCH),
961 errmsg("TD[\"new\"] is not a dictionary")));
962
963 plkeys = PyDict_Keys(plntup);
964 nkeys = PyList_Size(plkeys);
965
966 tupdesc = RelationGetDescr(tdata->tg_relation);
967
968 modvalues = (Datum *) palloc0(tupdesc->natts * sizeof(Datum));
969 modnulls = (bool *) palloc0(tupdesc->natts * sizeof(bool));
970 modrepls = (bool *) palloc0(tupdesc->natts * sizeof(bool));
971
972 for (i = 0; i < nkeys; i++)
973 {
974 PyObject *platt;
975 char *plattstr;
976 int attn;
977 PLyObToDatum *att;
978
979 platt = PyList_GetItem(plkeys, i);
980 if (PyString_Check(platt))
981 plattstr = PyString_AsString(platt);
982 else if (PyUnicode_Check(platt))

Callers 1

PLy_exec_triggerFunction · 0.85

Calls 8

PLyUnicode_AsStringFunction · 0.85
SPI_fnumberFunction · 0.85
PLy_output_convertFunction · 0.85
heap_modify_tupleFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
palloc0Function · 0.50
pfreeFunction · 0.50

Tested by

no test coverage detected