| 411 | } |
| 412 | |
| 413 | static PyObject * |
| 414 | PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw) |
| 415 | { |
| 416 | int sqlstate = 0; |
| 417 | char *volatile sqlstatestr = NULL; |
| 418 | char *volatile message = NULL; |
| 419 | char *volatile detail = NULL; |
| 420 | char *volatile hint = NULL; |
| 421 | char *volatile column_name = NULL; |
| 422 | char *volatile constraint_name = NULL; |
| 423 | char *volatile datatype_name = NULL; |
| 424 | char *volatile table_name = NULL; |
| 425 | char *volatile schema_name = NULL; |
| 426 | volatile MemoryContext oldcontext; |
| 427 | PyObject *key, |
| 428 | *value; |
| 429 | PyObject *volatile so; |
| 430 | Py_ssize_t pos = 0; |
| 431 | |
| 432 | PLy_enter_python_intepreter = false; |
| 433 | if (PyTuple_Size(args) == 1) |
| 434 | { |
| 435 | /* |
| 436 | * Treat single argument specially to avoid undesirable ('tuple',) |
| 437 | * decoration. |
| 438 | */ |
| 439 | PyObject *o; |
| 440 | |
| 441 | if (!PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o)) |
| 442 | PLy_elog(ERROR, "could not unpack arguments in plpy.elog"); |
| 443 | so = PyObject_Str(o); |
| 444 | } |
| 445 | else |
| 446 | so = PyObject_Str(args); |
| 447 | |
| 448 | if (so == NULL || ((message = PyString_AsString(so)) == NULL)) |
| 449 | { |
| 450 | level = ERROR; |
| 451 | message = dgettext(TEXTDOMAIN, "could not parse error message in plpy.elog"); |
| 452 | } |
| 453 | message = pstrdup(message); |
| 454 | |
| 455 | Py_XDECREF(so); |
| 456 | |
| 457 | if (kw != NULL) |
| 458 | { |
| 459 | while (PyDict_Next(kw, &pos, &key, &value)) |
| 460 | { |
| 461 | char *keyword = PyString_AsString(key); |
| 462 | |
| 463 | if (strcmp(keyword, "message") == 0) |
| 464 | { |
| 465 | /* the message should not be overwritten */ |
| 466 | if (PyTuple_Size(args) != 0) |
| 467 | { |
| 468 | PLy_exception_set(PyExc_TypeError, "argument 'message' given by name and position"); |
| 469 | return NULL; |
| 470 | } |
no test coverage detected