* Add all the autogenerated exceptions as subclasses of SPIError */
| 253 | * Add all the autogenerated exceptions as subclasses of SPIError |
| 254 | */ |
| 255 | static void |
| 256 | PLy_generate_spi_exceptions(PyObject *mod, PyObject *base) |
| 257 | { |
| 258 | int i; |
| 259 | |
| 260 | for (i = 0; exception_map[i].name != NULL; i++) |
| 261 | { |
| 262 | bool found; |
| 263 | PyObject *exc; |
| 264 | PLyExceptionEntry *entry; |
| 265 | PyObject *sqlstate; |
| 266 | PyObject *dict = PyDict_New(); |
| 267 | |
| 268 | if (dict == NULL) |
| 269 | PLy_elog(ERROR, NULL); |
| 270 | |
| 271 | sqlstate = PyString_FromString(unpack_sql_state(exception_map[i].sqlstate)); |
| 272 | if (sqlstate == NULL) |
| 273 | PLy_elog(ERROR, "could not generate SPI exceptions"); |
| 274 | |
| 275 | PyDict_SetItemString(dict, "sqlstate", sqlstate); |
| 276 | Py_DECREF(sqlstate); |
| 277 | |
| 278 | exc = PLy_create_exception(exception_map[i].name, base, dict, |
| 279 | exception_map[i].classname, mod); |
| 280 | |
| 281 | entry = hash_search(PLy_spi_exceptions, &exception_map[i].sqlstate, |
| 282 | HASH_ENTER, &found); |
| 283 | Assert(!found); |
| 284 | entry->exc = exc; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /* |
no test coverage detected