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

Function PLy_spi_exception_set

src/pl/plpython/plpy_spi.c:708–746  ·  view source on GitHub ↗

* Raise a SPIError, passing in it more error details, like the * internal query and error position. */

Source from the content-addressed store, hash-verified

706 * internal query and error position.
707 */
708static void
709PLy_spi_exception_set(PyObject *excclass, ErrorData *edata)
710{
711 PyObject *args = NULL;
712 PyObject *spierror = NULL;
713 PyObject *spidata = NULL;
714
715 args = Py_BuildValue("(s)", edata->message);
716 if (!args)
717 goto failure;
718
719 /* create a new SPI exception with the error message as the parameter */
720 spierror = PyObject_CallObject(excclass, args);
721 if (!spierror)
722 goto failure;
723
724 spidata = Py_BuildValue("(izzzizzzzz)", edata->sqlerrcode, edata->detail, edata->hint,
725 edata->internalquery, edata->internalpos,
726 edata->schema_name, edata->table_name, edata->column_name,
727 edata->datatype_name, edata->constraint_name);
728 if (!spidata)
729 goto failure;
730
731 if (PyObject_SetAttrString(spierror, "spidata", spidata) == -1)
732 goto failure;
733
734 PyErr_SetObject(excclass, spierror);
735
736 Py_DECREF(args);
737 Py_DECREF(spierror);
738 Py_DECREF(spidata);
739 return;
740
741failure:
742 Py_XDECREF(args);
743 Py_XDECREF(spierror);
744 Py_XDECREF(spidata);
745 elog(ERROR, "could not convert SPI error to Python exception");
746}

Callers 4

PLy_commitFunction · 0.85
PLy_rollbackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected