PostgreSQL Source Code git master
Functions | Variables
plpy_elog.c File Reference
#include "postgres.h"
#include "lib/stringinfo.h"
#include "plpy_elog.h"
#include "plpy_main.h"
#include "plpy_procedure.h"
#include "plpy_util.h"
Include dependency graph for plpy_elog.c:

Go to the source code of this file.

Functions

static void  PLy_traceback (PyObject *e, PyObject *v, PyObject *tb, char *volatile *xmsg, char *volatile *tbmsg, int *tb_depth)
 
static void  PLy_get_spi_error_data (PyObject *exc, int *sqlerrcode, char **detail, char **hint, char **query, int *position, char **schema_name, char **table_name, char **column_name, char **datatype_name, char **constraint_name)
 
static void  PLy_get_error_data (PyObject *exc, int *sqlerrcode, char **detail, char **hint, char **schema_name, char **table_name, char **column_name, char **datatype_name, char **constraint_name)
 
static char *  get_source_line (const char *src, int lineno)
 
static void  get_string_attr (PyObject *obj, char *attrname, char **str)
 
static bool  set_string_attr (PyObject *obj, char *attrname, char *str)
 
void  PLy_elog_impl (int elevel, const char *fmt,...)
 
static void  PLy_get_sqlerrcode (PyObject *exc, int *sqlerrcode)
 
void  PLy_exception_set (PyObject *exc, const char *fmt,...)
 
void  PLy_exception_set_plural (PyObject *exc, const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
 
void  PLy_exception_set_with_details (PyObject *excclass, ErrorData *edata)
 

Variables

PyObject *  PLy_exc_error = NULL
 
PyObject *  PLy_exc_fatal = NULL
 
PyObject *  PLy_exc_spi_error = NULL
 

Function Documentation

get_source_line()

static char * get_source_line ( const char *  src,
int  lineno 
)
static

Definition at line 435 of file plpy_elog.c.

436{
437 const char *s = NULL;
438 const char *next = src;
439 int current = 0;
440
441 /* sanity check */
442 if (lineno <= 0)
443 return NULL;
444
445 while (current < lineno)
446 {
447 s = next;
448 next = strchr(s + 1, '\n');
449 current++;
450 if (next == NULL)
451 break;
452 }
453
454 if (current != lineno)
455 return NULL;
456
457 while (*s && isspace((unsigned char) *s))
458 s++;
459
460 if (next == NULL)
461 return pstrdup(s);
462
463 /*
464 * Sanity check, next < s if the line was all-whitespace, which should
465 * never happen if Python reported a frame created on that line, but check
466 * anyway.
467 */
468 if (next < s)
469 return NULL;
470
471 return pnstrdup(s, next - s);
472}
static int32 next
Definition: blutils.c:224
char * pstrdup(const char *in)
Definition: mcxt.c:1759
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1770

References next, pnstrdup(), and pstrdup().

Referenced by PLy_traceback().

get_string_attr()

static void get_string_attr ( PyObject *  obj,
char *  attrname,
char **  str 
)
static

Definition at line 567 of file plpy_elog.c.

568{
569 PyObject *val;
570
571 val = PyObject_GetAttrString(obj, attrname);
572 if (val != NULL && val != Py_None)
573 {
575 }
576 Py_XDECREF(val);
577}
const char * str
long val
Definition: informix.c:689
char * PLyUnicode_AsString(PyObject *unicode)
Definition: plpy_util.c:81

References PLyUnicode_AsString(), pstrdup(), str, and val.

Referenced by PLy_get_error_data().

PLy_elog_impl()

void PLy_elog_impl ( int  elevel,
const char *  fmt,
  ... 
)

Definition at line 44 of file plpy_elog.c.

45{
46 int save_errno = errno;
47 char *volatile xmsg = NULL;
48 char *volatile tbmsg = NULL;
49 int tb_depth;
50 StringInfoData emsg;
51 PyObject *exc,
52 *val,
53 *tb;
54
55 /* If we'll need emsg, must initialize it before entering PG_TRY */
56 if (fmt)
57 initStringInfo(&emsg);
58
59 PyErr_Fetch(&exc, &val, &tb);
60
61 /* Use a PG_TRY block to ensure we release the PyObjects just acquired */
62 PG_TRY();
63 {
64 const char *primary = NULL;
65 int sqlerrcode = 0;
66 char *detail = NULL;
67 char *hint = NULL;
68 char *query = NULL;
69 int position = 0;
70 char *schema_name = NULL;
71 char *table_name = NULL;
72 char *column_name = NULL;
73 char *datatype_name = NULL;
74 char *constraint_name = NULL;
75
76 if (exc != NULL)
77 {
78 PyErr_NormalizeException(&exc, &val, &tb);
79
80 if (PyErr_GivenExceptionMatches(val, PLy_exc_spi_error))
81 PLy_get_spi_error_data(val, &sqlerrcode,
82 &detail, &hint, &query, &position,
83 &schema_name, &table_name, &column_name,
84 &datatype_name, &constraint_name);
85 else if (PyErr_GivenExceptionMatches(val, PLy_exc_error))
86 PLy_get_error_data(val, &sqlerrcode, &detail, &hint,
87 &schema_name, &table_name, &column_name,
88 &datatype_name, &constraint_name);
89 else if (PyErr_GivenExceptionMatches(val, PLy_exc_fatal))
90 elevel = FATAL;
91 }
92
93 PLy_traceback(exc, val, tb,
94 &xmsg, &tbmsg, &tb_depth);
95
96 if (fmt)
97 {
98 for (;;)
99 {
100 va_list ap;
101 int needed;
102
103 errno = save_errno;
104 va_start(ap, fmt);
105 needed = appendStringInfoVA(&emsg, dgettext(TEXTDOMAIN, fmt), ap);
106 va_end(ap);
107 if (needed == 0)
108 break;
109 enlargeStringInfo(&emsg, needed);
110 }
111 primary = emsg.data;
112
113 /* If there's an exception message, it goes in the detail. */
114 if (xmsg)
115 detail = xmsg;
116 }
117 else
118 {
119 if (xmsg)
120 primary = xmsg;
121 }
122
123 ereport(elevel,
124 (errcode(sqlerrcode ? sqlerrcode : ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
125 errmsg_internal("%s", primary ? primary : "no exception data"),
126 (detail) ? errdetail_internal("%s", detail) : 0,
127 (tb_depth > 0 && tbmsg) ? errcontext("%s", tbmsg) : 0,
128 (hint) ? errhint("%s", hint) : 0,
129 (query) ? internalerrquery(query) : 0,
130 (position) ? internalerrposition(position) : 0,
132 schema_name) : 0,
134 table_name) : 0,
136 column_name) : 0,
138 datatype_name) : 0,
140 constraint_name) : 0));
141 }
142 PG_FINALLY();
143 {
144 Py_XDECREF(exc);
145 Py_XDECREF(val);
146 /* Must release all the objects in the traceback stack */
147 while (tb != NULL && tb != Py_None)
148 {
149 PyObject *tb_prev = tb;
150
151 tb = PyObject_GetAttrString(tb, "tb_next");
152 Py_DECREF(tb_prev);
153 }
154 /* For neatness' sake, also release our string buffers */
155 if (fmt)
156 pfree(emsg.data);
157 if (xmsg)
158 pfree(xmsg);
159 if (tbmsg)
160 pfree(tbmsg);
161 }
162 PG_END_TRY();
163}
#define dgettext(d, x)
Definition: c.h:1179
int err_generic_string(int field, const char *str)
Definition: elog.c:1537
int internalerrquery(const char *query)
Definition: elog.c:1507
int internalerrposition(int cursorpos)
Definition: elog.c:1487
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1161
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1234
int errhint(const char *fmt,...)
Definition: elog.c:1321
int errcode(int sqlerrcode)
Definition: elog.c:854
#define errcontext
Definition: elog.h:198
#define FATAL
Definition: elog.h:41
#define PG_TRY(...)
Definition: elog.h:372
#define PG_END_TRY(...)
Definition: elog.h:397
#define TEXTDOMAIN
Definition: elog.h:153
#define PG_FINALLY(...)
Definition: elog.h:389
#define ereport(elevel,...)
Definition: elog.h:150
void pfree(void *pointer)
Definition: mcxt.c:1594
PyObject * PLy_exc_error
Definition: plpy_elog.c:15
static void PLy_get_error_data(PyObject *exc, int *sqlerrcode, char **detail, char **hint, char **schema_name, char **table_name, char **column_name, char **datatype_name, char **constraint_name)
Definition: plpy_elog.c:417
PyObject * PLy_exc_spi_error
Definition: plpy_elog.c:17
static void PLy_get_spi_error_data(PyObject *exc, int *sqlerrcode, char **detail, char **hint, char **query, int *position, char **schema_name, char **table_name, char **column_name, char **datatype_name, char **constraint_name)
Definition: plpy_elog.c:381
static void PLy_traceback(PyObject *e, PyObject *v, PyObject *tb, char *volatile *xmsg, char *volatile *tbmsg, int *tb_depth)
Definition: plpy_elog.c:173
PyObject * PLy_exc_fatal
Definition: plpy_elog.c:16
#define PG_DIAG_SCHEMA_NAME
Definition: postgres_ext.h:65
#define PG_DIAG_CONSTRAINT_NAME
Definition: postgres_ext.h:69
#define PG_DIAG_DATATYPE_NAME
Definition: postgres_ext.h:68
#define PG_DIAG_TABLE_NAME
Definition: postgres_ext.h:66
#define PG_DIAG_COLUMN_NAME
Definition: postgres_ext.h:67
int appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
Definition: stringinfo.c:187
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:337
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
char * data
Definition: stringinfo.h:48

References appendStringInfoVA(), StringInfoData::data, dgettext, enlargeStringInfo(), ereport, err_generic_string(), errcode(), errcontext, errdetail_internal(), errhint(), errmsg_internal(), FATAL, initStringInfo(), internalerrposition(), internalerrquery(), pfree(), PG_DIAG_COLUMN_NAME, PG_DIAG_CONSTRAINT_NAME, PG_DIAG_DATATYPE_NAME, PG_DIAG_SCHEMA_NAME, PG_DIAG_TABLE_NAME, PG_END_TRY, PG_FINALLY, PG_TRY, PLy_exc_error, PLy_exc_fatal, PLy_exc_spi_error, PLy_get_error_data(), PLy_get_spi_error_data(), PLy_traceback(), TEXTDOMAIN, and val.

Referenced by _PG_init().

PLy_exception_set()

void PLy_exception_set ( PyObject *  exc,
const char *  fmt,
  ... 
)

Definition at line 477 of file plpy_elog.c.

478{
479 char buf[1024];
480 va_list ap;
481
482 va_start(ap, fmt);
483 vsnprintf(buf, sizeof(buf), dgettext(TEXTDOMAIN, fmt), ap);
484 va_end(ap);
485
486 PyErr_SetString(exc, buf);
487}
static char * buf
Definition: pg_test_fsync.c:72
#define vsnprintf
Definition: port.h:238

References buf, dgettext, TEXTDOMAIN, and vsnprintf.

Referenced by PLy_cursor(), PLy_cursor_close(), PLy_cursor_fetch(), PLy_cursor_iternext(), PLy_cursor_plan(), PLy_output(), PLy_result_colnames(), PLy_result_coltypes(), PLy_result_coltypmods(), PLy_spi_execute(), PLy_spi_execute_plan(), PLy_spi_execute_query(), PLy_spi_prepare(), PLy_subtransaction_enter(), and PLy_subtransaction_exit().

PLy_exception_set_plural()

void PLy_exception_set_plural ( PyObject *  exc,
const char *  fmt_singular,
const char *  fmt_plural,
unsigned long  n,
  ... 
)

Definition at line 491 of file plpy_elog.c.

494{
495 char buf[1024];
496 va_list ap;
497
498 va_start(ap, n);
499 vsnprintf(buf, sizeof(buf),
500 dngettext(TEXTDOMAIN, fmt_singular, fmt_plural, n),
501 ap);
502 va_end(ap);
503
504 PyErr_SetString(exc, buf);
505}
#define dngettext(d, s, p, n)
Definition: c.h:1181

References buf, dngettext, TEXTDOMAIN, and vsnprintf.

Referenced by PLy_cursor_plan(), and PLy_spi_execute_plan().

PLy_exception_set_with_details()

void PLy_exception_set_with_details ( PyObject *  excclass,
ErrorDataedata 
)

Definition at line 509 of file plpy_elog.c.

510{
511 PyObject *args = NULL;
512 PyObject *error = NULL;
513
514 args = Py_BuildValue("(s)", edata->message);
515 if (!args)
516 goto failure;
517
518 /* create a new exception with the error message as the parameter */
519 error = PyObject_CallObject(excclass, args);
520 if (!error)
521 goto failure;
522
523 if (!set_string_attr(error, "sqlstate",
525 goto failure;
526
527 if (!set_string_attr(error, "detail", edata->detail))
528 goto failure;
529
530 if (!set_string_attr(error, "hint", edata->hint))
531 goto failure;
532
533 if (!set_string_attr(error, "query", edata->internalquery))
534 goto failure;
535
536 if (!set_string_attr(error, "schema_name", edata->schema_name))
537 goto failure;
538
539 if (!set_string_attr(error, "table_name", edata->table_name))
540 goto failure;
541
542 if (!set_string_attr(error, "column_name", edata->column_name))
543 goto failure;
544
545 if (!set_string_attr(error, "datatype_name", edata->datatype_name))
546 goto failure;
547
548 if (!set_string_attr(error, "constraint_name", edata->constraint_name))
549 goto failure;
550
551 PyErr_SetObject(excclass, error);
552
553 Py_DECREF(args);
554 Py_DECREF(error);
555
556 return;
557
558failure:
559 Py_XDECREF(args);
560 Py_XDECREF(error);
561
562 elog(ERROR, "could not convert error to Python exception");
563}
char * unpack_sql_state(int sql_state)
Definition: elog.c:3213
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
static bool set_string_attr(PyObject *obj, char *attrname, char *str)
Definition: plpy_elog.c:583
static void error(void)
Definition: sql-dyntest.c:147
char * schema_name
Definition: elog.h:439
char * internalquery
Definition: elog.h:446
int sqlerrcode
Definition: elog.h:431
char * datatype_name
Definition: elog.h:442
char * detail
Definition: elog.h:433
char * table_name
Definition: elog.h:440
char * message
Definition: elog.h:432
char * hint
Definition: elog.h:435
char * constraint_name
Definition: elog.h:443
char * column_name
Definition: elog.h:441

References generate_unaccent_rules::args, ErrorData::column_name, ErrorData::constraint_name, ErrorData::datatype_name, ErrorData::detail, elog, ERROR, error(), ErrorData::hint, ErrorData::internalquery, ErrorData::message, ErrorData::schema_name, set_string_attr(), ErrorData::sqlerrcode, ErrorData::table_name, and unpack_sql_state().

Referenced by PLy_output().

PLy_get_error_data()

static void PLy_get_error_data ( PyObject *  exc,
int *  sqlerrcode,
char **  detail,
char **  hint,
char **  schema_name,
char **  table_name,
char **  column_name,
char **  datatype_name,
char **  constraint_name 
)
static

Definition at line 417 of file plpy_elog.c.

420{
421 PLy_get_sqlerrcode(exc, sqlerrcode);
422 get_string_attr(exc, "detail", detail);
423 get_string_attr(exc, "hint", hint);
424 get_string_attr(exc, "schema_name", schema_name);
425 get_string_attr(exc, "table_name", table_name);
426 get_string_attr(exc, "column_name", column_name);
427 get_string_attr(exc, "datatype_name", datatype_name);
428 get_string_attr(exc, "constraint_name", constraint_name);
429}
static void get_string_attr(PyObject *obj, char *attrname, char **str)
Definition: plpy_elog.c:567
static void PLy_get_sqlerrcode(PyObject *exc, int *sqlerrcode)
Definition: plpy_elog.c:357

References get_string_attr(), and PLy_get_sqlerrcode().

Referenced by PLy_elog_impl().

PLy_get_spi_error_data()

static void PLy_get_spi_error_data ( PyObject *  exc,
int *  sqlerrcode,
char **  detail,
char **  hint,
char **  query,
int *  position,
char **  schema_name,
char **  table_name,
char **  column_name,
char **  datatype_name,
char **  constraint_name 
)
static

Definition at line 381 of file plpy_elog.c.

386{
387 PyObject *spidata;
388
389 spidata = PyObject_GetAttrString(exc, "spidata");
390
391 if (spidata != NULL)
392 {
393 PyArg_ParseTuple(spidata, "izzzizzzzz",
394 sqlerrcode, detail, hint, query, position,
395 schema_name, table_name, column_name,
396 datatype_name, constraint_name);
397 }
398 else
399 {
400 /*
401 * If there's no spidata, at least set the sqlerrcode. This can happen
402 * if someone explicitly raises a SPI exception from Python code.
403 */
404 PLy_get_sqlerrcode(exc, sqlerrcode);
405 }
406
407 Py_XDECREF(spidata);
408}

References PLy_get_sqlerrcode().

Referenced by PLy_elog_impl().

PLy_get_sqlerrcode()

static void PLy_get_sqlerrcode ( PyObject *  exc,
int *  sqlerrcode 
)
static

Definition at line 357 of file plpy_elog.c.

358{
359 PyObject *sqlstate;
360 char *buffer;
361
362 sqlstate = PyObject_GetAttrString(exc, "sqlstate");
363 if (sqlstate == NULL)
364 return;
365
366 buffer = PLyUnicode_AsString(sqlstate);
367 if (strlen(buffer) == 5 &&
368 strspn(buffer, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") == 5)
369 {
370 *sqlerrcode = MAKE_SQLSTATE(buffer[0], buffer[1], buffer[2],
371 buffer[3], buffer[4]);
372 }
373
374 Py_DECREF(sqlstate);
375}
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:56

References MAKE_SQLSTATE, and PLyUnicode_AsString().

Referenced by PLy_get_error_data(), and PLy_get_spi_error_data().

PLy_traceback()

static void PLy_traceback ( PyObject *  e,
PyObject *  v,
PyObject *  tb,
char *volatile *  xmsg,
char *volatile *  tbmsg,
int *  tb_depth 
)
static

Definition at line 173 of file plpy_elog.c.

175{
176 PyObject *volatile e_type_o = NULL;
177 PyObject *volatile e_module_o = NULL;
178 PyObject *volatile vob = NULL;
179 StringInfoData tbstr;
180
181 /*
182 * if no exception, return nulls
183 */
184 if (e == NULL)
185 {
186 *xmsg = NULL;
187 *tbmsg = NULL;
188 *tb_depth = 0;
189
190 return;
191 }
192
193 /*
194 * Format the exception and its value and put it in xmsg.
195 */
196 PG_TRY();
197 {
198 char *e_type_s = NULL;
199 char *e_module_s = NULL;
200 const char *vstr;
201 StringInfoData xstr;
202
203 e_type_o = PyObject_GetAttrString(e, "__name__");
204 e_module_o = PyObject_GetAttrString(e, "__module__");
205 if (e_type_o)
206 e_type_s = PLyUnicode_AsString(e_type_o);
207 if (e_module_o)
208 e_module_s = PLyUnicode_AsString(e_module_o);
209
210 if (v && ((vob = PyObject_Str(v)) != NULL))
211 vstr = PLyUnicode_AsString(vob);
212 else
213 vstr = "unknown";
214
215 initStringInfo(&xstr);
216 if (!e_type_s || !e_module_s)
217 {
218 /* shouldn't happen */
219 appendStringInfoString(&xstr, "unrecognized exception");
220 }
221 /* mimics behavior of traceback.format_exception_only */
222 else if (strcmp(e_module_s, "builtins") == 0
223 || strcmp(e_module_s, "__main__") == 0
224 || strcmp(e_module_s, "exceptions") == 0)
225 appendStringInfoString(&xstr, e_type_s);
226 else
227 appendStringInfo(&xstr, "%s.%s", e_module_s, e_type_s);
228 appendStringInfo(&xstr, ": %s", vstr);
229
230 *xmsg = xstr.data;
231 }
232 PG_FINALLY();
233 {
234 Py_XDECREF(e_type_o);
235 Py_XDECREF(e_module_o);
236 Py_XDECREF(vob);
237 }
238 PG_END_TRY();
239
240 /*
241 * Now format the traceback and put it in tbmsg.
242 */
243 *tb_depth = 0;
244 initStringInfo(&tbstr);
245 /* Mimic Python traceback reporting as close as possible. */
246 appendStringInfoString(&tbstr, "Traceback (most recent call last):");
247 while (tb != NULL && tb != Py_None)
248 {
249 PyObject *volatile frame = NULL;
250 PyObject *volatile code = NULL;
251 PyObject *volatile name = NULL;
252 PyObject *volatile lineno = NULL;
253 PyObject *volatile filename = NULL;
254
255 PG_TRY();
256 {
257 lineno = PyObject_GetAttrString(tb, "tb_lineno");
258 if (lineno == NULL)
259 elog(ERROR, "could not get line number from Python traceback");
260
261 frame = PyObject_GetAttrString(tb, "tb_frame");
262 if (frame == NULL)
263 elog(ERROR, "could not get frame from Python traceback");
264
265 code = PyObject_GetAttrString(frame, "f_code");
266 if (code == NULL)
267 elog(ERROR, "could not get code object from Python frame");
268
269 name = PyObject_GetAttrString(code, "co_name");
270 if (name == NULL)
271 elog(ERROR, "could not get function name from Python code object");
272
273 filename = PyObject_GetAttrString(code, "co_filename");
274 if (filename == NULL)
275 elog(ERROR, "could not get file name from Python code object");
276
277 /* The first frame always points at <module>, skip it. */
278 if (*tb_depth > 0)
279 {
281 char *proname;
282 char *fname;
283 char *line;
284 char *plain_filename;
285 long plain_lineno;
286
287 /*
288 * The second frame points at the internal function, but to
289 * mimic Python error reporting we want to say <module>.
290 */
291 if (*tb_depth == 1)
292 fname = "<module>";
293 else
294 fname = PLyUnicode_AsString(name);
295
297 plain_filename = PLyUnicode_AsString(filename);
298 plain_lineno = PyLong_AsLong(lineno);
299
300 if (proname == NULL)
301 appendStringInfo(&tbstr, "\n PL/Python anonymous code block, line %ld, in %s",
302 plain_lineno - 1, fname);
303 else
304 appendStringInfo(&tbstr, "\n PL/Python function \"%s\", line %ld, in %s",
305 proname, plain_lineno - 1, fname);
306
307 /*
308 * function code object was compiled with "<string>" as the
309 * filename
310 */
311 if (exec_ctx->curr_proc && plain_filename != NULL &&
312 strcmp(plain_filename, "<string>") == 0)
313 {
314 /*
315 * If we know the current procedure, append the exact line
316 * from the source, again mimicking Python's traceback.py
317 * module behavior. We could store the already line-split
318 * source to avoid splitting it every time, but producing
319 * a traceback is not the most important scenario to
320 * optimize for. But we do not go as far as traceback.py
321 * in reading the source of imported modules.
322 */
323 line = get_source_line(exec_ctx->curr_proc->src, plain_lineno);
324 if (line)
325 {
326 appendStringInfo(&tbstr, "\n %s", line);
327 pfree(line);
328 }
329 }
330 }
331 }
332 PG_FINALLY();
333 {
334 Py_XDECREF(frame);
335 Py_XDECREF(code);
336 Py_XDECREF(name);
337 Py_XDECREF(lineno);
338 Py_XDECREF(filename);
339 }
340 PG_END_TRY();
341
342 /* Advance to the next frame. */
343 tb = PyObject_GetAttrString(tb, "tb_next");
344 if (tb == NULL)
345 elog(ERROR, "could not traverse Python traceback");
346 (*tb_depth)++;
347 }
348
349 /* Return the traceback. */
350 *tbmsg = tbstr.data;
351}
static char * filename
Definition: pg_dumpall.c:120
NameData proname
Definition: pg_proc.h:35
static char * get_source_line(const char *src, int lineno)
Definition: plpy_elog.c:435
PLyExecutionContext * PLy_current_execution_context(void)
Definition: plpy_main.c:391
char * PLy_procedure_name(PLyProcedure *proc)
Definition: plpy_procedure.c:46
e
e
Definition: preproc-init.c:82
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
PLyProcedure * curr_proc
Definition: plpy_main.h:20
char * src
Definition: plpy_procedure.h:49
const char * name

References appendStringInfo(), appendStringInfoString(), PLyExecutionContext::curr_proc, StringInfoData::data, elog, ERROR, filename, get_source_line(), initStringInfo(), name, pfree(), PG_END_TRY, PG_FINALLY, PG_TRY, PLy_current_execution_context(), PLy_procedure_name(), PLyUnicode_AsString(), proname, and PLyProcedure::src.

Referenced by PLy_elog_impl().

set_string_attr()

static bool set_string_attr ( PyObject *  obj,
char *  attrname,
char *  str 
)
static

Definition at line 583 of file plpy_elog.c.

584{
585 int result;
586 PyObject *val;
587
588 if (str != NULL)
589 {
591 if (!val)
592 return false;
593 }
594 else
595 {
596 val = Py_None;
597 Py_INCREF(Py_None);
598 }
599
600 result = PyObject_SetAttrString(obj, attrname, val);
601 Py_DECREF(val);
602
603 return result != -1;
604}
PyObject * PLyUnicode_FromString(const char *s)
Definition: plpy_util.c:116

References PLyUnicode_FromString(), str, and val.

Referenced by PLy_exception_set_with_details().

Variable Documentation

PLy_exc_error

PyObject* PLy_exc_error = NULL

Definition at line 15 of file plpy_elog.c.

Referenced by PLy_add_exceptions(), PLy_cursor(), PLy_elog_impl(), PLy_output(), PLy_result_colnames(), PLy_result_coltypes(), PLy_result_coltypmods(), and PLy_spi_execute().

PLy_exc_fatal

PyObject* PLy_exc_fatal = NULL

Definition at line 16 of file plpy_elog.c.

Referenced by PLy_add_exceptions(), and PLy_elog_impl().

PLy_exc_spi_error

PyObject* PLy_exc_spi_error = NULL

Definition at line 17 of file plpy_elog.c.

Referenced by PLy_add_exceptions(), PLy_commit(), PLy_elog_impl(), PLy_rollback(), PLy_spi_execute_plan(), PLy_spi_execute_query(), and PLy_spi_subtransaction_abort().

AltStyle によって変換されたページ (->オリジナル) /