MCPcopy Create free account
hub / github.com/apache/cloudberry / PLy_cursor_iternext

Function PLy_cursor_iternext

src/pl/plpython/plpy_cursorobject.c:309–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307}
308
309static PyObject *
310PLy_cursor_iternext(PyObject *self)
311{
312 PLyCursorObject *cursor;
313 PyObject *ret;
314 PLyExecutionContext *exec_ctx = PLy_current_execution_context();
315 volatile MemoryContext oldcontext;
316 volatile ResourceOwner oldowner;
317 Portal portal;
318
319 cursor = (PLyCursorObject *) self;
320
321 if (cursor->closed)
322 {
323 PLy_exception_set(PyExc_ValueError, "iterating a closed cursor");
324 return NULL;
325 }
326
327 portal = GetPortalByName(cursor->portalname);
328 if (!PortalIsValid(portal))
329 {
330 PLy_exception_set(PyExc_ValueError,
331 "iterating a cursor in an aborted subtransaction");
332 return NULL;
333 }
334
335 oldcontext = CurrentMemoryContext;
336 oldowner = CurrentResourceOwner;
337
338 if(!PLy_spi_subtransaction_begin(oldcontext, oldowner))
339 return NULL;
340
341 PG_TRY();
342 {
343 SPI_cursor_fetch(portal, true, 1);
344 if (SPI_processed == 0)
345 {
346 PyErr_SetNone(PyExc_StopIteration);
347 ret = NULL;
348 }
349 else
350 {
351 PLy_input_setup_tuple(&cursor->result, SPI_tuptable->tupdesc,
352 exec_ctx->curr_proc);
353
354 ret = PLy_input_from_tuple(&cursor->result, SPI_tuptable->vals[0],
355 SPI_tuptable->tupdesc, true);
356 }
357
358 SPI_freetuptable(SPI_tuptable);
359
360 PLy_spi_subtransaction_commit(oldcontext, oldowner);
361 }
362 PG_CATCH();
363 {
364 PLy_spi_subtransaction_abort(oldcontext, oldowner);
365 return NULL;
366 }

Callers

nothing calls this directly

Calls 10

PLy_exception_setFunction · 0.85
GetPortalByNameFunction · 0.85
SPI_cursor_fetchFunction · 0.85
PLy_input_setup_tupleFunction · 0.85
PLy_input_from_tupleFunction · 0.85
SPI_freetuptableFunction · 0.85

Tested by

no test coverage detected