PostgreSQL Source Code  git master
plpy_planobject.c File Reference
#include "postgres.h"
#include "plpython.h"
#include "plpy_planobject.h"
#include "plpy_cursorobject.h"
#include "plpy_elog.h"
#include "plpy_spi.h"
#include "utils/memutils.h"
Include dependency graph for plpy_planobject.c:

Go to the source code of this file.

Functions

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)
 
void PLy_plan_init_type (void)
 
PyObject * PLy_plan_new (void)
 
bool is_PLyPlanObject (PyObject *ob)
 

Variables

static char PLy_plan_doc []
 
static PyMethodDef PLy_plan_methods []
 
static PyTypeObject PLy_PlanType
 

Function Documentation

◆ is_PLyPlanObject()

bool is_PLyPlanObject ( PyObject *  ob)

Definition at line 71 of file plpy_planobject.c.

References PLy_PlanType.

Referenced by PLy_spi_execute().

72 {
73  return ob->ob_type == &PLy_PlanType;
74 }
static PyTypeObject PLy_PlanType

◆ PLy_plan_cursor()

static PyObject * PLy_plan_cursor ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 96 of file plpy_planobject.c.

References PLy_cursor_plan().

97 {
98  PyObject *planargs = NULL;
99 
100  if (!PyArg_ParseTuple(args, "|O", &planargs))
101  return NULL;
102 
103  return PLy_cursor_plan(self, planargs);
104 }
PyObject * PLy_cursor_plan(PyObject *ob, PyObject *args)

◆ PLy_plan_dealloc()

static void PLy_plan_dealloc ( PyObject *  arg)
static

Definition at line 77 of file plpy_planobject.c.

References PLyPlanObject::mcxt, MemoryContextDelete(), PLyPlanObject::plan, and SPI_freeplan().

78 {
80 
81  if (ob->plan)
82  {
83  SPI_freeplan(ob->plan);
84  ob->plan = NULL;
85  }
86  if (ob->mcxt)
87  {
89  ob->mcxt = NULL;
90  }
91  arg->ob_type->tp_free(arg);
92 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
PyObject_HEAD SPIPlanPtr plan
MemoryContext mcxt
int SPI_freeplan(SPIPlanPtr plan)
Definition: spi.c:801
void * arg

◆ PLy_plan_execute()

static PyObject * PLy_plan_execute ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 108 of file plpy_planobject.c.

References sort-test::list, and PLy_spi_execute_plan().

109 {
110  PyObject *list = NULL;
111  long limit = 0;
112 
113  if (!PyArg_ParseTuple(args, "|Ol", &list, &limit))
114  return NULL;
115 
116  return PLy_spi_execute_plan(self, list, limit);
117 }
PyObject * PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit)
Definition: plpy_spi.c:181

◆ PLy_plan_init_type()

void PLy_plan_init_type ( void  )

Definition at line 46 of file plpy_planobject.c.

References elog, ERROR, and PLy_PlanType.

Referenced by PLy_init_plpy().

47 {
48  if (PyType_Ready(&PLy_PlanType) < 0)
49  elog(ERROR, "could not initialize PLy_PlanType");
50 }
#define ERROR
Definition: elog.h:43
static PyTypeObject PLy_PlanType
#define elog(elevel,...)
Definition: elog.h:226

◆ PLy_plan_new()

PyObject* PLy_plan_new ( void  )

Definition at line 53 of file plpy_planobject.c.

References PLyPlanObject::args, PLyPlanObject::mcxt, PLyPlanObject::nargs, PLyPlanObject::plan, PLy_PlanType, PLyPlanObject::types, and PLyPlanObject::values.

Referenced by PLy_spi_prepare().

54 {
55  PLyPlanObject *ob;
56 
57  if ((ob = PyObject_New(PLyPlanObject, &PLy_PlanType)) == NULL)
58  return NULL;
59 
60  ob->plan = NULL;
61  ob->nargs = 0;
62  ob->types = NULL;
63  ob->values = NULL;
64  ob->args = NULL;
65  ob->mcxt = NULL;
66 
67  return (PyObject *) ob;
68 }
static PyTypeObject PLy_PlanType
PLyObToDatum * args
PyObject_HEAD SPIPlanPtr plan
MemoryContext mcxt

◆ PLy_plan_status()

static PyObject * PLy_plan_status ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 121 of file plpy_planobject.c.

122 {
123  if (PyArg_ParseTuple(args, ":status"))
124  {
125  Py_INCREF(Py_True);
126  return Py_True;
127  /* return PyInt_FromLong(self->status); */
128  }
129  return NULL;
130 }

Variable Documentation

◆ PLy_plan_doc

char PLy_plan_doc[]
static
Initial value:
= {
"Store a PostgreSQL plan"
}

Definition at line 24 of file plpy_planobject.c.

◆ PLy_plan_methods

PyMethodDef PLy_plan_methods[]
static
Initial value:
= {
{"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}
}
static PyObject * PLy_plan_status(PyObject *self, PyObject *args)
static PyObject * PLy_plan_execute(PyObject *self, PyObject *args)
static PyObject * PLy_plan_cursor(PyObject *self, PyObject *args)

Definition at line 28 of file plpy_planobject.c.

◆ PLy_PlanType

PyTypeObject PLy_PlanType
static
Initial value:
= {
.tp_name = "PLyPlan",
.tp_basicsize = sizeof(PLyPlanObject),
.tp_dealloc = PLy_plan_dealloc,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = PLy_plan_doc,
.tp_methods = PLy_plan_methods,
}
#define PyVarObject_HEAD_INIT(type, size)
Definition: plpython.h:113
static char PLy_plan_doc[]
static PyMethodDef PLy_plan_methods[]
static void PLy_plan_dealloc(PyObject *arg)
struct PLyPlanObject PLyPlanObject

Definition at line 35 of file plpy_planobject.c.

Referenced by is_PLyPlanObject(), PLy_plan_init_type(), and PLy_plan_new().