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

Function lo_manage

contrib/lo/lo.c:23–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21PG_FUNCTION_INFO_V1(lo_manage);
22
23Datum
24lo_manage(PG_FUNCTION_ARGS)
25{
26 TriggerData *trigdata = (TriggerData *) fcinfo->context;
27 int attnum; /* attribute number to monitor */
28 char **args; /* Args containing attr name */
29 TupleDesc tupdesc; /* Tuple Descriptor */
30 HeapTuple rettuple; /* Tuple to be returned */
31 bool isdelete; /* are we deleting? */
32 HeapTuple newtuple; /* The new value for tuple */
33 HeapTuple trigtuple; /* The original value of tuple */
34
35 if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
36 elog(ERROR, "lo_manage: not fired by trigger manager");
37
38 if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) /* internal error */
39 elog(ERROR, "%s: must be fired for row",
40 trigdata->tg_trigger->tgname);
41
42 /*
43 * Fetch some values from trigdata
44 */
45 newtuple = trigdata->tg_newtuple;
46 trigtuple = trigdata->tg_trigtuple;
47 tupdesc = trigdata->tg_relation->rd_att;
48 args = trigdata->tg_trigger->tgargs;
49
50 if (args == NULL) /* internal error */
51 elog(ERROR, "%s: no column name provided in the trigger definition",
52 trigdata->tg_trigger->tgname);
53
54 /* tuple to return to Executor */
55 if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
56 rettuple = newtuple;
57 else
58 rettuple = trigtuple;
59
60 /* Are we deleting the row? */
61 isdelete = TRIGGER_FIRED_BY_DELETE(trigdata->tg_event);
62
63 /* Get the column we're interested in */
64 attnum = SPI_fnumber(tupdesc, args[0]);
65
66 if (attnum <= 0)
67 elog(ERROR, "%s: column \"%s\" does not exist",
68 trigdata->tg_trigger->tgname, args[0]);
69
70 /*
71 * Handle updates
72 *
73 * Here, if the value of the monitored attribute changes, then the large
74 * object associated with the original value is unlinked.
75 */
76 if (newtuple != NULL &&
77 bms_is_member(attnum - FirstLowInvalidHeapAttributeNumber, trigdata->tg_updatedcols))
78 {
79 char *orig = SPI_getvalue(trigtuple, tupdesc, attnum);
80 char *newv = SPI_getvalue(newtuple, tupdesc, attnum);

Callers

nothing calls this directly

Calls 5

SPI_fnumberFunction · 0.85
bms_is_memberFunction · 0.85
SPI_getvalueFunction · 0.85
ObjectIdGetDatumFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected