4 * src/pl/plpython/plpy_planobject.c
9 #include "plpy_cursorobject.h"
10 #include "plpy_planobject.h"
13 #include "utils/memutils.h"
15 static void PLy_plan_dealloc(PyObject
*arg
);
16 static PyObject
*PLy_plan_cursor(PyObject
*self
, PyObject
*args
);
17 static PyObject
*PLy_plan_execute(PyObject
*self
, PyObject
*args
);
18 static PyObject
*PLy_plan_status(PyObject
*self
, PyObject
*args
);
20 static char PLy_plan_doc
[] = "Store a PostgreSQL plan";
22 static PyMethodDef PLy_plan_methods
[] = {
23 {"cursor", PLy_plan_cursor
, METH_VARARGS
, NULL
},
24 {"execute", PLy_plan_execute
, METH_VARARGS
, NULL
},
25 {"status", PLy_plan_status
, METH_VARARGS
, NULL
},
29 static PyTypeObject PLy_PlanType
= {
30 PyVarObject_HEAD_INIT(NULL
, 0)
32 .tp_basicsize
= sizeof(PLyPlanObject
),
33 .tp_dealloc
= PLy_plan_dealloc
,
34 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
35 .tp_doc
= PLy_plan_doc
,
36 .tp_methods
= PLy_plan_methods
,
40 PLy_plan_init_type(void)
42 if (PyType_Ready(&PLy_PlanType
) < 0)
43 elog(ERROR
, "could not initialize PLy_PlanType");
51 if ((ob
= PyObject_New(PLyPlanObject
, &PLy_PlanType
)) == NULL
)
61 return (PyObject
*) ob
;
65 is_PLyPlanObject(PyObject
*ob
)
67 return ob
->ob_type
== &PLy_PlanType
;
71 PLy_plan_dealloc(PyObject
*arg
)
73 PLyPlanObject
*ob
= (PLyPlanObject
*) arg
;
77 SPI_freeplan(ob
->plan
);
82 MemoryContextDelete(ob
->mcxt
);
85 arg
->ob_type
->tp_free(arg
);
90 PLy_plan_cursor(PyObject
*self
, PyObject
*args
)
92 PyObject
*planargs
= NULL
;
94 if (!PyArg_ParseTuple(args
, "|O", &planargs
))
97 return PLy_cursor_plan(self
, planargs
);
102 PLy_plan_execute(PyObject
*self
, PyObject
*args
)
104 PyObject
*list
= NULL
;
107 if (!PyArg_ParseTuple(args
, "|Ol", &list
, &limit
))
110 return PLy_spi_execute_plan(self
, list
, limit
);
115 PLy_plan_status(PyObject
*self
, PyObject
*args
)
117 if (PyArg_ParseTuple(args
, ":status"))
121 /* return PyLong_FromLong(self->status); */