| 326 | } |
| 327 | |
| 328 | static PyObject * |
| 329 | PLy_spi_execute_query(char *query, int64 limit) |
| 330 | { |
| 331 | int rv; |
| 332 | volatile MemoryContext oldcontext; |
| 333 | volatile ResourceOwner oldowner; |
| 334 | PyObject *ret = NULL; |
| 335 | |
| 336 | oldcontext = CurrentMemoryContext; |
| 337 | oldowner = CurrentResourceOwner; |
| 338 | |
| 339 | if(!PLy_spi_subtransaction_begin(oldcontext, oldowner)) |
| 340 | return NULL; |
| 341 | |
| 342 | PG_TRY(); |
| 343 | { |
| 344 | PLyExecutionContext *exec_ctx = PLy_current_execution_context(); |
| 345 | |
| 346 | pg_verifymbstr(query, strlen(query), false); |
| 347 | rv = SPI_execute(query, exec_ctx->curr_proc->fn_readonly, limit); |
| 348 | ret = PLy_spi_execute_fetch_result(SPI_tuptable, SPI_processed, rv); |
| 349 | |
| 350 | PLy_spi_subtransaction_commit(oldcontext, oldowner); |
| 351 | } |
| 352 | PG_CATCH(); |
| 353 | { |
| 354 | PLy_spi_subtransaction_abort(oldcontext, oldowner); |
| 355 | return NULL; |
| 356 | } |
| 357 | PG_END_TRY(); |
| 358 | |
| 359 | if (rv < 0) |
| 360 | { |
| 361 | Py_XDECREF(ret); |
| 362 | PLy_exception_set(PLy_exc_spi_error, |
| 363 | "SPI_execute failed: %s", |
| 364 | SPI_result_code_string(rv)); |
| 365 | return NULL; |
| 366 | } |
| 367 | |
| 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | static PyObject * |
| 372 | PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status) |
no test coverage detected