LCOV - differential code coverage report
Current view: top level - src/pl/plpython - plpy_planobject.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 88.1 % 42 37 5 37
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 7 7 7
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 88.1 % 42 37 5 37
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 7 7 7

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /*
                                  2                 :  * the PLyPlan class
                                  3                 :  *
                                  4                 :  * src/pl/plpython/plpy_planobject.c
                                  5                 :  */
                                  6                 : 
                                  7                 : #include "postgres.h"
                                  8                 : 
                                  9                 : #include "plpy_cursorobject.h"
                                 10                 : #include "plpy_elog.h"
                                 11                 : #include "plpy_planobject.h"
                                 12                 : #include "plpy_spi.h"
                                 13                 : #include "plpython.h"
                                 14                 : #include "utils/memutils.h"
                                 15                 : 
                                 16                 : static void PLy_plan_dealloc(PyObject *arg);
                                 17                 : static PyObject *PLy_plan_cursor(PyObject *self, PyObject *args);
                                 18                 : static PyObject *PLy_plan_execute(PyObject *self, PyObject *args);
                                 19                 : static PyObject *PLy_plan_status(PyObject *self, PyObject *args);
                                 20                 : 
                                 21                 : static char PLy_plan_doc[] = "Store a PostgreSQL plan";
                                 22                 : 
                                 23                 : static PyMethodDef PLy_plan_methods[] = {
                                 24                 :     {"cursor", PLy_plan_cursor, METH_VARARGS, NULL},
                                 25                 :     {"execute", PLy_plan_execute, METH_VARARGS, NULL},
                                 26                 :     {"status", PLy_plan_status, METH_VARARGS, NULL},
                                 27                 :     {NULL, NULL, 0, NULL}
                                 28                 : };
                                 29                 : 
                                 30                 : static PyTypeObject PLy_PlanType = {
                                 31                 :     PyVarObject_HEAD_INIT(NULL, 0)
                                 32                 :     .tp_name = "PLyPlan",
                                 33                 :     .tp_basicsize = sizeof(PLyPlanObject),
                                 34                 :     .tp_dealloc = PLy_plan_dealloc,
                                 35                 :     .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
                                 36                 :     .tp_doc = PLy_plan_doc,
                                 37                 :     .tp_methods = PLy_plan_methods,
                                 38                 : };
                                 39                 : 
                                 40                 : void
 4130 peter_e                    41 CBC          23 : PLy_plan_init_type(void)
                                 42                 : {
                                 43              23 :     if (PyType_Ready(&PLy_PlanType) < 0)
 4130 peter_e                    44 UBC           0 :         elog(ERROR, "could not initialize PLy_PlanType");
 4130 peter_e                    45 CBC          23 : }
                                 46                 : 
                                 47                 : PyObject *
                                 48              25 : PLy_plan_new(void)
                                 49                 : {
                                 50                 :     PLyPlanObject *ob;
                                 51                 : 
                                 52              25 :     if ((ob = PyObject_New(PLyPlanObject, &PLy_PlanType)) == NULL)
 4130 peter_e                    53 UBC           0 :         return NULL;
                                 54                 : 
 4130 peter_e                    55 CBC          25 :     ob->plan = NULL;
                                 56              25 :     ob->nargs = 0;
                                 57              25 :     ob->types = NULL;
                                 58              25 :     ob->values = NULL;
                                 59              25 :     ob->args = NULL;
 2712 tgl                        60              25 :     ob->mcxt = NULL;
                                 61                 : 
 4130 peter_e                    62              25 :     return (PyObject *) ob;
                                 63                 : }
                                 64                 : 
                                 65                 : bool
                                 66              21 : is_PLyPlanObject(PyObject *ob)
                                 67                 : {
                                 68              21 :     return ob->ob_type == &PLy_PlanType;
                                 69                 : }
                                 70                 : 
                                 71                 : static void
                                 72              21 : PLy_plan_dealloc(PyObject *arg)
                                 73                 : {
                                 74              21 :     PLyPlanObject *ob = (PLyPlanObject *) arg;
                                 75                 : 
                                 76              21 :     if (ob->plan)
                                 77                 :     {
                                 78              18 :         SPI_freeplan(ob->plan);
 2712 tgl                        79              18 :         ob->plan = NULL;
                                 80                 :     }
                                 81              21 :     if (ob->mcxt)
                                 82                 :     {
                                 83              21 :         MemoryContextDelete(ob->mcxt);
                                 84              21 :         ob->mcxt = NULL;
                                 85                 :     }
 4130 peter_e                    86              21 :     arg->ob_type->tp_free(arg);
                                 87              21 : }
                                 88                 : 
                                 89                 : 
                                 90                 : static PyObject *
 2234                            91               1 : PLy_plan_cursor(PyObject *self, PyObject *args)
                                 92                 : {
                                 93               1 :     PyObject   *planargs = NULL;
                                 94                 : 
                                 95               1 :     if (!PyArg_ParseTuple(args, "|O", &planargs))
 2234 peter_e                    96 UBC           0 :         return NULL;
                                 97                 : 
 2234 peter_e                    98 CBC           1 :     return PLy_cursor_plan(self, planargs);
                                 99                 : }
                                100                 : 
                                101                 : 
                                102                 : static PyObject *
                                103               1 : PLy_plan_execute(PyObject *self, PyObject *args)
                                104                 : {
                                105               1 :     PyObject   *list = NULL;
                                106               1 :     long        limit = 0;
                                107                 : 
                                108               1 :     if (!PyArg_ParseTuple(args, "|Ol", &list, &limit))
 2234 peter_e                   109 UBC           0 :         return NULL;
                                110                 : 
 2234 peter_e                   111 CBC           1 :     return PLy_spi_execute_plan(self, list, limit);
                                112                 : }
                                113                 : 
                                114                 : 
                                115                 : static PyObject *
 4130                           116               2 : PLy_plan_status(PyObject *self, PyObject *args)
                                117                 : {
 2355                           118               2 :     if (PyArg_ParseTuple(args, ":status"))
                                119                 :     {
 4130                           120               2 :         Py_INCREF(Py_True);
                                121               2 :         return Py_True;
                                122                 :         /* return PyLong_FromLong(self->status); */
                                123                 :     }
 4130 peter_e                   124 UBC           0 :     return NULL;
                                125                 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a