PostgreSQL Source Code git master
Loading...
Searching...
No Matches
plpy_resultobject.c File Reference
#include "postgres.h"
#include "plpy_elog.h"
#include "plpy_resultobject.h"
#include "plpy_util.h"
Include dependency graph for plpy_resultobject.c:

Go to the source code of this file.

Functions

static void PLy_result_dealloc (PLyResultObject *self)
 
static PyObjectPLy_result_colnames (PyObject *self, PyObject *unused)
 
static PyObjectPLy_result_coltypes (PyObject *self, PyObject *unused)
 
static PyObjectPLy_result_coltypmods (PyObject *self, PyObject *unused)
 
static PyObjectPLy_result_nrows (PyObject *self, PyObject *args)
 
static PyObjectPLy_result_status (PyObject *self, PyObject *args)
 
static Py_ssize_t PLy_result_length (PyObject *arg)
 
static PyObjectPLy_result_item (PyObject *arg, Py_ssize_t idx)
 
static PyObjectPLy_result_str (PyObject *arg)
 
static PyObjectPLy_result_subscript (PyObject *arg, PyObject *item)
 
static int PLy_result_ass_subscript (PyObject *arg, PyObject *item, PyObject *value)
 
void PLy_result_init_type (void)
 
PyObjectPLy_result_new (void)
 

Variables

static char PLy_result_doc [] = "Results of a PostgreSQL query"
 
static PyMethodDef PLy_result_methods []
 
static PyType_Slot PLyResult_slots []
 
static PyType_Spec PLyResult_spec
 
static PyTypeObjectPLy_ResultType
 

Function Documentation

◆ PLy_result_ass_subscript()

static int PLy_result_ass_subscript ( PyObject arg,
PyObject item,
PyObject value 
)
static

Definition at line 276 of file plpy_resultobject.c.

277{
279
280 return PyObject_SetItem(ob->rows, item, value);
281}
static struct @172 value
void * arg
static int fb(int x)

References arg, fb(), and value.

◆ PLy_result_colnames()

static PyObject * PLy_result_colnames ( PyObject self,
PyObject unused 
)
static

Definition at line 140 of file plpy_resultobject.c.

141{
143 PyObject *list;
144 int i;
145
146 if (!ob->tupdesc)
147 {
148 PLy_exception_set(PLy_exc_error, "command did not produce a result set");
149 return NULL;
150 }
151
152 list = PyList_New(ob->tupdesc->natts);
153 if (!list)
154 return NULL;
155 for (i = 0; i < ob->tupdesc->natts; i++)
156 {
157 Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
158
159 PyList_SetItem(list, i, PLyUnicode_FromString(NameStr(attr->attname)));
160 }
161
162 return list;
163}
#define NameStr(name)
Definition c.h:765
int i
Definition isn.c:77
FormData_pg_attribute * Form_pg_attribute
PyObject * PLy_exc_error
Definition plpy_elog.c:15
void PLy_exception_set(PyObject *exc, const char *fmt,...)
Definition plpy_elog.c:490
PyObject * PLyUnicode_FromString(const char *s)
Definition plpy_util.c:116
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition tupdesc.h:160

References fb(), i, NameStr, PLy_exc_error, PLy_exception_set(), PLyUnicode_FromString(), and TupleDescAttr().

◆ PLy_result_coltypes()

static PyObject * PLy_result_coltypes ( PyObject self,
PyObject unused 
)
static

Definition at line 166 of file plpy_resultobject.c.

167{
169 PyObject *list;
170 int i;
171
172 if (!ob->tupdesc)
173 {
174 PLy_exception_set(PLy_exc_error, "command did not produce a result set");
175 return NULL;
176 }
177
178 list = PyList_New(ob->tupdesc->natts);
179 if (!list)
180 return NULL;
181 for (i = 0; i < ob->tupdesc->natts; i++)
182 {
183 Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
184
185 PyList_SetItem(list, i, PyLong_FromLong(attr->atttypid));
186 }
187
188 return list;
189}

References fb(), i, PLy_exc_error, PLy_exception_set(), and TupleDescAttr().

◆ PLy_result_coltypmods()

static PyObject * PLy_result_coltypmods ( PyObject self,
PyObject unused 
)
static

Definition at line 192 of file plpy_resultobject.c.

193{
195 PyObject *list;
196 int i;
197
198 if (!ob->tupdesc)
199 {
200 PLy_exception_set(PLy_exc_error, "command did not produce a result set");
201 return NULL;
202 }
203
204 list = PyList_New(ob->tupdesc->natts);
205 if (!list)
206 return NULL;
207 for (i = 0; i < ob->tupdesc->natts; i++)
208 {
209 Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
210
211 PyList_SetItem(list, i, PyLong_FromLong(attr->atttypmod));
212 }
213
214 return list;
215}

References fb(), i, PLy_exc_error, PLy_exception_set(), and TupleDescAttr().

◆ PLy_result_dealloc()

static void PLy_result_dealloc ( PLyResultObject self)
static

Definition at line 117 of file plpy_resultobject.c.

118{
119#if PY_VERSION_HEX >= 0x03080000
120 PyTypeObject *tp = Py_TYPE(self);
121#endif
122
123 Py_XDECREF(self->nrows);
124 Py_XDECREF(self->rows);
125 Py_XDECREF(self->status);
126 if (self->tupdesc)
127 {
128 FreeTupleDesc(self->tupdesc);
129 self->tupdesc = NULL;
130 }
131
132 PyObject_Free(self);
133#if PY_VERSION_HEX >= 0x03080000
134 /* This was not needed before Python 3.8 (Python issue 35810) */
135 Py_DECREF(tp);
136#endif
137}
PyObject_HEAD PyObject * nrows
void FreeTupleDesc(TupleDesc tupdesc)
Definition tupdesc.c:502

References fb(), FreeTupleDesc(), PLyResultObject::nrows, PLyResultObject::rows, PLyResultObject::status, and PLyResultObject::tupdesc.

◆ PLy_result_init_type()

void PLy_result_init_type ( void  )

Definition at line 81 of file plpy_resultobject.c.

82{
84 if (!PLy_ResultType)
85 elog(ERROR, "could not initialize PLy_ResultType");
86}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
static PyType_Spec PLyResult_spec
static PyTypeObject * PLy_ResultType

References elog, ERROR, fb(), PLy_ResultType, and PLyResult_spec.

Referenced by PyInit_plpy().

◆ PLy_result_item()

static PyObject * PLy_result_item ( PyObject arg,
Py_ssize_t  idx 
)
static

Definition at line 244 of file plpy_resultobject.c.

245{
246 PyObject *rv;
248
249 rv = PyList_GetItem(ob->rows, idx);
250 if (rv != NULL)
251 Py_INCREF(rv);
252 return rv;
253}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262

References arg, fb(), and idx().

◆ PLy_result_length()

static Py_ssize_t PLy_result_length ( PyObject arg)
static

Definition at line 236 of file plpy_resultobject.c.

237{
239
240 return PyList_Size(ob->rows);
241}

References arg, and fb().

◆ PLy_result_new()

PyObject * PLy_result_new ( void  )

Definition at line 89 of file plpy_resultobject.c.

90{
92
94 return NULL;
95#if PY_VERSION_HEX < 0x03080000
96 /* Workaround for Python issue 35810; no longer necessary in Python 3.8 */
98#endif
99
100 /* ob->tuples = NULL; */
101
103 ob->status = Py_None;
104 ob->nrows = PyLong_FromLong(-1);
105 ob->rows = PyList_New(0);
106 ob->tupdesc = NULL;
107 if (!ob->rows)
108 {
109 Py_DECREF(ob);
110 return NULL;
111 }
112
113 return (PyObject *) ob;
114}

References fb(), and PLy_ResultType.

Referenced by PLy_cursor_fetch(), and PLy_spi_execute_fetch_result().

◆ PLy_result_nrows()

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

Definition at line 218 of file plpy_resultobject.c.

219{
221
222 Py_INCREF(ob->nrows);
223 return ob->nrows;
224}

References fb().

◆ PLy_result_status()

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

Definition at line 227 of file plpy_resultobject.c.

228{
230
231 Py_INCREF(ob->status);
232 return ob->status;
233}

References fb().

◆ PLy_result_str()

static PyObject * PLy_result_str ( PyObject arg)
static

Definition at line 256 of file plpy_resultobject.c.

257{
259
260 return PyUnicode_FromFormat("<%s status=%S nrows=%S rows=%S>",
261 "PLyResult",
262 ob->status,
263 ob->nrows,
264 ob->rows);
265}

References arg, and fb().

◆ PLy_result_subscript()

static PyObject * PLy_result_subscript ( PyObject arg,
PyObject item 
)
static

Definition at line 268 of file plpy_resultobject.c.

269{
271
272 return PyObject_GetItem(ob->rows, item);
273}

References arg, and fb().

Variable Documentation

◆ PLy_result_doc

char PLy_result_doc[] = "Results of a PostgreSQL query"
static

Definition at line 25 of file plpy_resultobject.c.

◆ PLy_result_methods

PyMethodDef PLy_result_methods[]
static
Initial value:
= {
{NULL, NULL, 0, NULL}
}
static PyObject * PLy_result_nrows(PyObject *self, PyObject *args)
static PyObject * PLy_result_coltypmods(PyObject *self, PyObject *unused)
static PyObject * PLy_result_status(PyObject *self, PyObject *args)
static PyObject * PLy_result_coltypes(PyObject *self, PyObject *unused)
static PyObject * PLy_result_colnames(PyObject *self, PyObject *unused)

Definition at line 27 of file plpy_resultobject.c.

27 {
28 {"colnames", PLy_result_colnames, METH_NOARGS, NULL},
29 {"coltypes", PLy_result_coltypes, METH_NOARGS, NULL},
30 {"coltypmods", PLy_result_coltypmods, METH_NOARGS, NULL},
33 {NULL, NULL, 0, NULL}
34};

◆ PLy_ResultType

PyTypeObject* PLy_ResultType
static

Definition at line 78 of file plpy_resultobject.c.

Referenced by PLy_result_init_type(), and PLy_result_new().

◆ PLyResult_slots

PyType_Slot PLyResult_slots[]
static

Definition at line 36 of file plpy_resultobject.c.

37{
38 {
40 },
41 {
43 },
44 {
46 },
47 {
49 },
50 {
52 },
53 {
55 },
56 {
58 },
59 {
61 },
62 {
64 },
65 {
66 0, NULL
67 }
68};
static PyObject * PLy_result_str(PyObject *arg)
static PyObject * PLy_result_item(PyObject *arg, Py_ssize_t idx)
static void PLy_result_dealloc(PLyResultObject *self)
static char PLy_result_doc[]
static PyObject * PLy_result_subscript(PyObject *arg, PyObject *item)
static Py_ssize_t PLy_result_length(PyObject *arg)
static PyMethodDef PLy_result_methods[]
static int PLy_result_ass_subscript(PyObject *arg, PyObject *item, PyObject *value)

◆ PLyResult_spec

PyType_Spec PLyResult_spec
static
Initial value:
=
{
.name = "PLyResult",
.basicsize = sizeof(PLyResultObject),
.slots = PLyResult_slots,
}
static PyType_Slot PLyResult_slots[]

Definition at line 70 of file plpy_resultobject.c.

71{
72 .name = "PLyResult",
73 .basicsize = sizeof(PLyResultObject),
75 .slots = PLyResult_slots,
76};

Referenced by PLy_result_init_type().