LCOV - differential code coverage report
Current view: top level - contrib/lo - lo.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 89.2 % 37 33 4 33
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 3 3 3
Baseline: 16@8cea358b128 Branches: 50.0 % 38 19 19 19
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 89.2 % 37 33 4 33
Function coverage date bins:
(240..) days: 100.0 % 3 3 3
Branch coverage date bins:
(240..) days: 50.0 % 38 19 19 19

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  *  PostgreSQL definitions for managed Large Objects.
                                  3                 :                :  *
                                  4                 :                :  *  contrib/lo/lo.c
                                  5                 :                :  *
                                  6                 :                :  */
                                  7                 :                : 
                                  8                 :                : #include "postgres.h"
                                  9                 :                : 
                                 10                 :                : #include "commands/trigger.h"
                                 11                 :                : #include "executor/spi.h"
                                 12                 :                : #include "utils/builtins.h"
                                 13                 :                : #include "utils/rel.h"
                                 14                 :                : 
 6529 tgl@sss.pgh.pa.us          15                 :CBC           1 : PG_MODULE_MAGIC;
                                 16                 :                : 
                                 17                 :                : 
                                 18                 :                : /*
                                 19                 :                :  * This is the trigger that protects us from orphaned large objects
                                 20                 :                :  */
 8546                            21                 :              2 : PG_FUNCTION_INFO_V1(lo_manage);
                                 22                 :                : 
                                 23                 :                : Datum
 8721                            24                 :              3 : lo_manage(PG_FUNCTION_ARGS)
                                 25                 :                : {
                                 26                 :              3 :     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                 :                : 
 2489                            35   [ +  -  -  + ]:              3 :     if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
 1472 tgl@sss.pgh.pa.us          36         [ #  # ]:UBC           0 :         elog(ERROR, "lo_manage: not fired by trigger manager");
                                 37                 :                : 
 2489 tgl@sss.pgh.pa.us          38         [ -  + ]:CBC           3 :     if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event)) /* internal error */
 3795 tgl@sss.pgh.pa.us          39         [ #  # ]:UBC           0 :         elog(ERROR, "%s: must be fired for row",
                                 40                 :                :              trigdata->tg_trigger->tgname);
                                 41                 :                : 
                                 42                 :                :     /*
                                 43                 :                :      * Fetch some values from trigdata
                                 44                 :                :      */
 8721 tgl@sss.pgh.pa.us          45                 :CBC           3 :     newtuple = trigdata->tg_newtuple;
                                 46                 :              3 :     trigtuple = trigdata->tg_trigtuple;
                                 47                 :              3 :     tupdesc = trigdata->tg_relation->rd_att;
                                 48                 :              3 :     args = trigdata->tg_trigger->tgargs;
                                 49                 :                : 
 3795                            50         [ -  + ]:              3 :     if (args == NULL)           /* internal error */
 3795 tgl@sss.pgh.pa.us          51         [ #  # ]:UBC           0 :         elog(ERROR, "%s: no column name provided in the trigger definition",
                                 52                 :                :              trigdata->tg_trigger->tgname);
                                 53                 :                : 
                                 54                 :                :     /* tuple to return to Executor */
 8721 tgl@sss.pgh.pa.us          55         [ +  + ]:CBC           3 :     if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
 9091 bruce@momjian.us           56                 :              2 :         rettuple = newtuple;
                                 57                 :                :     else
                                 58                 :              1 :         rettuple = trigtuple;
                                 59                 :                : 
                                 60                 :                :     /* Are we deleting the row? */
 8721 tgl@sss.pgh.pa.us          61                 :              3 :     isdelete = TRIGGER_FIRED_BY_DELETE(trigdata->tg_event);
                                 62                 :                : 
                                 63                 :                :     /* Get the column we're interested in */
 9091 bruce@momjian.us           64                 :              3 :     attnum = SPI_fnumber(tupdesc, args[0]);
                                 65                 :                : 
 6870 tgl@sss.pgh.pa.us          66         [ -  + ]:              3 :     if (attnum <= 0)
 3795 tgl@sss.pgh.pa.us          67         [ #  # ]:UBC           0 :         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                 :                :      */
 1497 peter@eisentraut.org       76   [ +  +  +  + ]:CBC           5 :     if (newtuple != NULL &&
                                 77                 :              2 :         bms_is_member(attnum - FirstLowInvalidHeapAttributeNumber, trigdata->tg_updatedcols))
                                 78                 :                :     {
 9091 bruce@momjian.us           79                 :              1 :         char       *orig = SPI_getvalue(trigtuple, tupdesc, attnum);
                                 80                 :              1 :         char       *newv = SPI_getvalue(newtuple, tupdesc, attnum);
                                 81                 :                : 
 6870 tgl@sss.pgh.pa.us          82   [ +  -  +  -  :              1 :         if (orig != NULL && (newv == NULL || strcmp(orig, newv) != 0))
                                              +  - ]
 2665 peter_e@gmx.net            83                 :              1 :             DirectFunctionCall1(be_lo_unlink,
                                 84                 :                :                                 ObjectIdGetDatum(atooid(orig)));
                                 85                 :                : 
 9091 bruce@momjian.us           86         [ +  - ]:              1 :         if (newv)
                                 87                 :              1 :             pfree(newv);
                                 88         [ +  - ]:              1 :         if (orig)
                                 89                 :              1 :             pfree(orig);
                                 90                 :                :     }
                                 91                 :                : 
                                 92                 :                :     /*
                                 93                 :                :      * Handle deleting of rows
                                 94                 :                :      *
                                 95                 :                :      * Here, we unlink the large object associated with the managed attribute
                                 96                 :                :      */
                                 97         [ +  + ]:              3 :     if (isdelete)
                                 98                 :                :     {
                                 99                 :              1 :         char       *orig = SPI_getvalue(trigtuple, tupdesc, attnum);
                                100                 :                : 
                                101         [ +  - ]:              1 :         if (orig != NULL)
                                102                 :                :         {
 2665 peter_e@gmx.net           103                 :              1 :             DirectFunctionCall1(be_lo_unlink,
                                104                 :                :                                 ObjectIdGetDatum(atooid(orig)));
                                105                 :                : 
 9091 bruce@momjian.us          106                 :              1 :             pfree(orig);
                                107                 :                :         }
                                108                 :                :     }
                                109                 :                : 
 8721 tgl@sss.pgh.pa.us         110                 :              3 :     return PointerGetDatum(rettuple);
                                111                 :                : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622