From 70ec3f1f8f0b753c38a1a582280a02930d7cac5f Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 25 Feb 2017 08:42:25 -0500 Subject: PL/Python: Add cursor and execute methods to plan object Instead of plan = plpy.prepare(...) res = plpy.execute(plan, ...) you can now write plan = plpy.prepare(...) res = plan.execute(...) or even res = plpy.prepare(...).execute(...) and similarly for the cursor() method. This is more in object oriented style, and makes the hybrid nature of the existing execute() function less confusing. Reviewed-by: Andrew Dunstan --- src/pl/plpython/plpy_planobject.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/pl/plpython/plpy_planobject.c') diff --git a/src/pl/plpython/plpy_planobject.c b/src/pl/plpython/plpy_planobject.c index 16c39a05ddf..390b4e90d45 100644 --- a/src/pl/plpython/plpy_planobject.c +++ b/src/pl/plpython/plpy_planobject.c @@ -10,11 +10,15 @@ #include "plpy_planobject.h" +#include "plpy_cursorobject.h" #include "plpy_elog.h" +#include "plpy_spi.h" #include "utils/memutils.h" static void PLy_plan_dealloc(PyObject *arg); +static PyObject *PLy_plan_cursor(PyObject *self, PyObject *args); +static PyObject *PLy_plan_execute(PyObject *self, PyObject *args); static PyObject *PLy_plan_status(PyObject *self, PyObject *args); static char PLy_plan_doc[] = { @@ -22,6 +26,8 @@ static char PLy_plan_doc[] = { }; static PyMethodDef PLy_plan_methods[] = { + {"cursor", PLy_plan_cursor, METH_VARARGS, NULL}, + {"execute", PLy_plan_execute, METH_VARARGS, NULL}, {"status", PLy_plan_status, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; @@ -111,6 +117,31 @@ PLy_plan_dealloc(PyObject *arg) } +static PyObject * +PLy_plan_cursor(PyObject *self, PyObject *args) +{ + PyObject *planargs = NULL; + + if (!PyArg_ParseTuple(args, "|O", &planargs)) + return NULL; + + return PLy_cursor_plan(self, planargs); +} + + +static PyObject * +PLy_plan_execute(PyObject *self, PyObject *args) +{ + PyObject *list = NULL; + long limit = 0; + + if (!PyArg_ParseTuple(args, "|Ol", &list, &limit)) + return NULL; + + return PLy_spi_execute_plan(self, list, limit); +} + + static PyObject * PLy_plan_status(PyObject *self, PyObject *args) { -- cgit v1.2.3