45 Py_tp_iter, PyObject_SelfIter
62 .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
73 elog(
ERROR,
"could not initialize PLy_CursorType");
81 PyObject *planargs = NULL;
83 if (PyArg_ParseTuple(
args,
"s", &query))
88 if (PyArg_ParseTuple(
args,
"O|O", &
plan, &planargs))
106#if PY_VERSION_HEX < 0x03080000
110 cursor->portalname = NULL;
113 "PL/Python cursor context",
143 elog(
ERROR,
"SPI_cursor_open() failed: %s",
160 return (PyObject *)
cursor;
175 if (!PySequence_Check(
args) || PyUnicode_Check(
args))
177 PLy_exception_set(PyExc_TypeError,
"plpy.cursor takes a sequence as its second argument");
180 nargs = PySequence_Length(
args);
187 if (nargs !=
plan->nargs)
190 PyObject *so = PyObject_Str(
args);
196 "Expected sequence of %d argument, got %d: %s",
197 "Expected sequence of %d arguments, got %d: %s",
199 plan->nargs, nargs, sv);
207#if PY_VERSION_HEX < 0x03080000
211 cursor->portalname = NULL;
214 "PL/Python cursor context",
232 char *
volatile nulls;
240 "PL/Python temporary context",
247 nulls = (
char *)
palloc(nargs *
sizeof(
char));
255 for (
j = 0;
j < nargs;
j++)
260 elem = PySequence_GetItem(
args,
j);
266 nulls[
j] = isnull ?
'n' :
' ';
280 elog(
ERROR,
"SPI_cursor_open() failed: %s",
300 return (PyObject *)
cursor;
306#if PY_VERSION_HEX >= 0x03080000
307 PyTypeObject *tp = Py_TYPE(self);
329#if PY_VERSION_HEX >= 0x03080000
357 "iterating a cursor in an aborted subtransaction");
371 PyErr_SetNone(PyExc_StopIteration);
408 if (!PyArg_ParseTuple(
args,
"i:fetch", &count))
423 "iterating a cursor in an aborted subtransaction");
443 Py_DECREF(ret->
nrows);
457 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
458 errmsg(
"query result has too many rows to fit in a Python list")));
460 Py_DECREF(ret->
rows);
479 PyList_SetItem(ret->
rows,
i, row);
495 return (PyObject *) ret;
510 "closing a cursor in an aborted subtransaction");
static Datum values[MAXATTR]
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Assert(PointerIsAligned(start, uint64))
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
char * MemoryContextStrdup(MemoryContext context, const char *string)
MemoryContext TopMemoryContext
MemoryContext CurTransactionContext
MemoryContext CurrentMemoryContext
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define ALLOCSET_SMALL_SIZES
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static PyType_Spec PLyCursor_spec
PyObject * PLy_cursor(PyObject *self, PyObject *args)
PyObject * PLy_cursor_plan(PyObject *ob, PyObject *args)
static PyMethodDef PLy_cursor_methods[]
static PyObject * PLy_cursor_query(const char *query)
static PyObject * PLy_cursor_fetch(PyObject *self, PyObject *args)
static PyObject * PLy_cursor_iternext(PyObject *self)
static PyObject * PLy_cursor_close(PyObject *self, PyObject *unused)
static PyTypeObject * PLy_CursorType
static PyType_Slot PLyCursor_slots[]
static void PLy_cursor_dealloc(PLyCursorObject *self)
void PLy_cursor_init_type(void)
static const char PLy_cursor_doc[]
struct PLyCursorObject PLyCursorObject
void PLy_exception_set(PyObject *exc, const char *fmt,...)
void PLy_exception_set_plural(PyObject *exc, const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
PLyExecutionContext * PLy_current_execution_context(void)
PyObject * PLy_result_new(void)
void PLy_spi_subtransaction_commit(MemoryContext oldcontext, ResourceOwner oldowner)
void PLy_spi_subtransaction_abort(MemoryContext oldcontext, ResourceOwner oldowner)
void PLy_spi_subtransaction_begin(MemoryContext oldcontext, ResourceOwner oldowner)
void PLy_input_setup_func(PLyDatumToOb *arg, MemoryContext arg_mcxt, Oid typeOid, int32 typmod, PLyProcedure *proc)
PyObject * PLy_input_from_tuple(PLyDatumToOb *arg, HeapTuple tuple, TupleDesc desc, bool include_generated)
void PLy_input_setup_tuple(PLyDatumToOb *arg, TupleDesc desc, PLyProcedure *proc)
Datum PLy_output_convert(PLyObToDatum *arg, PyObject *val, bool *isnull)
char * PLyUnicode_AsString(PyObject *unicode)
void PinPortal(Portal portal)
void UnpinPortal(Portal portal)
Portal GetPortalByName(const char *name)
ResourceOwner CurrentResourceOwner
int SPI_freeplan(SPIPlanPtr plan)
const char * SPI_result_code_string(int code)
SPITupleTable * SPI_tuptable
void SPI_cursor_fetch(Portal portal, bool forward, long count)
void SPI_freetuptable(SPITupleTable *tuptable)
Portal SPI_cursor_open(const char *name, SPIPlanPtr plan, Datum *Values, const char *Nulls, bool read_only)
SPIPlanPtr SPI_prepare(const char *src, int nargs, Oid *argtypes)
void SPI_cursor_close(Portal portal)
PyObject_HEAD char * portalname
PyObject_HEAD PyObject * nrows