Go to the documentation of this file.00001
00002
00003
00004
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",
00031 sizeof(PLyPlanObject),
00032 0,
00033
00034
00035
00036
00037 PLy_plan_dealloc,
00038 0,
00039 0,
00040 0,
00041 0,
00042 0,
00043 0,
00044 0,
00045 0,
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00053 PLy_plan_doc,
00054 0,
00055 0,
00056 0,
00057 0,
00058 0,
00059 0,
00060 PLy_plan_methods,
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
00125 }
00126 PLy_exception_set(PLy_exc_error, "plan.status takes no arguments");
00127 return NULL;
00128 }