* Raise a SPIError, passing in it more error details, like the * internal query and error position. */
| 706 | * internal query and error position. |
| 707 | */ |
| 708 | static void |
| 709 | PLy_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 | |
| 741 | failure: |
| 742 | Py_XDECREF(args); |
| 743 | Py_XDECREF(spierror); |
| 744 | Py_XDECREF(spidata); |
| 745 | elog(ERROR, "could not convert SPI error to Python exception"); |
| 746 | } |
no outgoing calls
no test coverage detected