Header And Logo

PostgreSQL
| The world's most advanced open source database.

plpy_planobject.c

Go to the documentation of this file.
00001 /*
00002  * the PLyPlan class
00003  *
00004  * src/pl/plpython/plpy_planobject.c
00005  */
00006 
00007 #include "postgres.h"
00008 
00009 #include "plpython.h"
00010 
00011 #include "plpy_planobject.h"
00012 
00013 #include "plpy_elog.h"
00014 
00015 
00016 static void PLy_plan_dealloc(PyObject *arg);
00017 static PyObject *PLy_plan_status(PyObject *self, PyObject *args);
00018 
00019 static char PLy_plan_doc[] = {
00020     "Store a PostgreSQL plan"
00021 };
00022 
00023 static PyMethodDef PLy_plan_methods[] = {
00024     {"status", PLy_plan_status, METH_VARARGS, NULL},
00025     {NULL, NULL, 0, NULL}
00026 };
00027 
00028 static PyTypeObject PLy_PlanType = {
00029     PyVarObject_HEAD_INIT(NULL, 0)
00030     "PLyPlan",                  /* tp_name */
00031     sizeof(PLyPlanObject),      /* tp_size */
00032     0,                          /* tp_itemsize */
00033 
00034     /*
00035      * methods
00036      */
00037     PLy_plan_dealloc,           /* tp_dealloc */
00038     0,                          /* tp_print */
00039     0,                          /* tp_getattr */
00040     0,                          /* tp_setattr */
00041     0,                          /* tp_compare */
00042     0,                          /* tp_repr */
00043     0,                          /* tp_as_number */
00044     0,                          /* tp_as_sequence */
00045     0,                          /* tp_as_mapping */
00046     0,                          /* tp_hash */
00047     0,                          /* tp_call */
00048     0,                          /* tp_str */
00049     0,                          /* tp_getattro */
00050     0,                          /* tp_setattro */
00051     0,                          /* tp_as_buffer */
00052     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   /* tp_flags */
00053     PLy_plan_doc,               /* tp_doc */
00054     0,                          /* tp_traverse */
00055     0,                          /* tp_clear */
00056     0,                          /* tp_richcompare */
00057     0,                          /* tp_weaklistoffset */
00058     0,                          /* tp_iter */
00059     0,                          /* tp_iternext */
00060     PLy_plan_methods,           /* tp_tpmethods */
00061 };
00062 
00063 void
00064 PLy_plan_init_type(void)
00065 {
00066     if (PyType_Ready(&PLy_PlanType) < 0)
00067         elog(ERROR, "could not initialize PLy_PlanType");
00068 }
00069 
00070 PyObject *
00071 PLy_plan_new(void)
00072 {
00073     PLyPlanObject *ob;
00074 
00075     if ((ob = PyObject_New(PLyPlanObject, &PLy_PlanType)) == NULL)
00076         return NULL;
00077 
00078     ob->plan = NULL;
00079     ob->nargs = 0;
00080     ob->types = NULL;
00081     ob->values = NULL;
00082     ob->args = NULL;
00083 
00084     return (PyObject *) ob;
00085 }
00086 
00087 bool
00088 is_PLyPlanObject(PyObject *ob)
00089 {
00090     return ob->ob_type == &PLy_PlanType;
00091 }
00092 
00093 static void
00094 PLy_plan_dealloc(PyObject *arg)
00095 {
00096     PLyPlanObject *ob = (PLyPlanObject *) arg;
00097 
00098     if (ob->plan)
00099         SPI_freeplan(ob->plan);
00100     if (ob->types)
00101         PLy_free(ob->types);
00102     if (ob->values)
00103         PLy_free(ob->values);
00104     if (ob->args)
00105     {
00106         int         i;
00107 
00108         for (i = 0; i < ob->nargs; i++)
00109             PLy_typeinfo_dealloc(&ob->args[i]);
00110         PLy_free(ob->args);
00111     }
00112 
00113     arg->ob_type->tp_free(arg);
00114 }
00115 
00116 
00117 static PyObject *
00118 PLy_plan_status(PyObject *self, PyObject *args)
00119 {
00120     if (PyArg_ParseTuple(args, ""))
00121     {
00122         Py_INCREF(Py_True);
00123         return Py_True;
00124         /* return PyInt_FromLong(self->status); */
00125     }
00126     PLy_exception_set(PLy_exc_error, "plan.status takes no arguments");
00127     return NULL;
00128 }