| 370 | } |
| 371 | |
| 372 | static PyObject * |
| 373 | PLy_cursor_fetch(PyObject *self, PyObject *args) |
| 374 | { |
| 375 | PLyCursorObject *cursor; |
| 376 | int count; |
| 377 | PLyResultObject *ret; |
| 378 | PLyExecutionContext *exec_ctx = PLy_current_execution_context(); |
| 379 | volatile MemoryContext oldcontext; |
| 380 | volatile ResourceOwner oldowner; |
| 381 | Portal portal; |
| 382 | |
| 383 | if (!PyArg_ParseTuple(args, "i:fetch", &count)) |
| 384 | return NULL; |
| 385 | |
| 386 | cursor = (PLyCursorObject *) self; |
| 387 | |
| 388 | if (cursor->closed) |
| 389 | { |
| 390 | PLy_exception_set(PyExc_ValueError, "fetch from a closed cursor"); |
| 391 | return NULL; |
| 392 | } |
| 393 | |
| 394 | portal = GetPortalByName(cursor->portalname); |
| 395 | if (!PortalIsValid(portal)) |
| 396 | { |
| 397 | PLy_exception_set(PyExc_ValueError, |
| 398 | "iterating a cursor in an aborted subtransaction"); |
| 399 | return NULL; |
| 400 | } |
| 401 | |
| 402 | ret = (PLyResultObject *) PLy_result_new(); |
| 403 | if (ret == NULL) |
| 404 | return NULL; |
| 405 | |
| 406 | oldcontext = CurrentMemoryContext; |
| 407 | oldowner = CurrentResourceOwner; |
| 408 | |
| 409 | if(!PLy_spi_subtransaction_begin(oldcontext, oldowner)) |
| 410 | return NULL; |
| 411 | |
| 412 | PG_TRY(); |
| 413 | { |
| 414 | SPI_cursor_fetch(portal, true, count); |
| 415 | |
| 416 | Py_DECREF(ret->status); |
| 417 | ret->status = PyInt_FromLong(SPI_OK_FETCH); |
| 418 | |
| 419 | Py_DECREF(ret->nrows); |
| 420 | ret->nrows = PyLong_FromUnsignedLongLong(SPI_processed); |
| 421 | |
| 422 | if (SPI_processed != 0) |
| 423 | { |
| 424 | uint64 i; |
| 425 | |
| 426 | /* |
| 427 | * PyList_New() and PyList_SetItem() use Py_ssize_t for list size |
| 428 | * and list indices; so we cannot support a result larger than |
| 429 | * PY_SSIZE_T_MAX. |
nothing calls this directly
no test coverage detected