PostgreSQL Source Code: src/pl/plpython/plpy_plpymodule.c Source File (original) (raw)
1
2
3
4
5
6
8
19
21
22
28
29
40
41
42
49
51#include "spiexceptions.h"
53};
54
56
57
58
66
67
68
69
71
72
73
74
76
77
78
79
83
84
85
86
88
89
90
91
93
94
95
96
99
101};
102
106
109 .m_name = "plpy",
110 .m_size = -1,
112};
113
116 .m_name = "spiexceptions",
117 .m_size = -1,
119};
120
121
122
123
124
127{
129
131 if (m == NULL)
133
135
140
141 return m;
142}
143
144static void
146{
149
151 "Error", plpy);
153 "Fatal", plpy);
155 "SPIError", plpy);
156
159 PLy_elog(ERROR, "could not create the spiexceptions module");
160
165
167
169 {
171 PLy_elog(ERROR, "could not add the spiexceptions module");
172 }
173}
174
175
176
177
178
179
183{
185
187 if (exc == NULL)
189
190
191
192
193
194
195
197
199 {
202 }
203
204 return exc;
205}
206
207
208
209
210static void
212{
213 int i;
214
216 {
217 bool found;
222
225
227 if (sqlstate == NULL)
228 PLy_elog(ERROR, "could not generate SPI exceptions");
229
232
235
239 entry->exc = exc;
240 }
241}
242
243
244
245
246
247
250
256
262
268
274
280
286
292
295{
296 const char *str;
297 char *quoted;
299
302
306
307 return ret;
308}
309
312{
313 const char *str;
314 char *quoted;
316
319
322
326
327 return ret;
328}
329
332{
333 const char *str;
334 const char *quoted;
336
339
342
343 return ret;
344}
345
346
347static char *
349{
350 if (obj)
351 {
353
355 {
356 char *str;
357
360
361 return str;
362 }
363 }
364
366}
367
370{
371 int sqlstate = 0;
373 char *volatile message = NULL;
374 char *volatile detail = NULL;
375 char *volatile hint = NULL;
376 char *volatile column_name = NULL;
377 char *volatile constraint_name = NULL;
378 char *volatile datatype_name = NULL;
379 char *volatile table_name = NULL;
380 char *volatile schema_name = NULL;
386
388 {
389
390
391
392
394
396 PLy_elog(ERROR, "could not unpack arguments in plpy.elog");
398 }
399 else
401
403 {
405 message = dgettext(TEXTDOMAIN, "could not parse error message in plpy.elog");
406 }
407 message = pstrdup(message);
408
410
412 {
414 {
416
417 if (strcmp(keyword, "message") == 0)
418 {
419
421 {
424 }
425
426 if (message)
429 }
430 else if (strcmp(keyword, "detail") == 0)
432 else if (strcmp(keyword, "hint") == 0)
434 else if (strcmp(keyword, "sqlstate") == 0)
436 else if (strcmp(keyword, "schema_name") == 0)
438 else if (strcmp(keyword, "table_name") == 0)
440 else if (strcmp(keyword, "column_name") == 0)
442 else if (strcmp(keyword, "datatype_name") == 0)
444 else if (strcmp(keyword, "constraint_name") == 0)
446 else
447 {
449 "'%s' is an invalid keyword argument for this function",
450 keyword);
452 }
453 }
454 }
455
457 {
459 {
462 }
463
464 if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
465 {
468 }
469
475 }
476
479 {
480 if (message != NULL)
482 if (detail != NULL)
484 if (hint != NULL)
486 if (schema_name != NULL)
488 if (table_name != NULL)
490 if (column_name != NULL)
492 if (datatype_name != NULL)
494 if (constraint_name != NULL)
496
498 ((sqlstate != 0) ? errcode(sqlstate) : 0,
501 (hint != NULL) ? errhint("%s", hint) : 0,
502 (column_name != NULL) ?
504 (constraint_name != NULL) ?
506 (datatype_name != NULL) ?
508 (table_name != NULL) ?
510 (schema_name != NULL) ?
512 }
514 {
516
520
523
525 }
527
528
529
530
532}
#define Assert(condition)
void(* pg_funcptr_t)(void)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
void FreeErrorData(ErrorData *edata)
ErrorData * CopyErrorData(void)
void FlushErrorState(void)
int errcode(int sqlerrcode)
char * unpack_sql_state(int sql_state)
int err_generic_string(int field, const char *str)
int int errdetail_internal(const char *fmt,...) pg_attribute_printf(1
int errhint(const char *fmt,...) pg_attribute_printf(1
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
#define ereport(elevel,...)
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
PyObject * PLy_cursor(PyObject *self, PyObject *args)
void PLy_cursor_init_type(void)
PyObject * PLy_exc_spi_error
void PLy_exception_set_with_details(PyObject *excclass, ErrorData *edata)
void PLy_exception_set(PyObject *exc, const char *fmt,...)
void PLy_plan_init_type(void)
PyMODINIT_FUNC PyInit_plpy(void)
static PyObject * PLy_notice(PyObject *self, PyObject *args, PyObject *kw)
static PyMethodDef PLy_exc_methods[]
static PyObject * PLy_quote_ident(PyObject *self, PyObject *args)
static char * object_to_string(PyObject *obj)
static PyObject * PLy_debug(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * PLy_quote_nullable(PyObject *self, PyObject *args)
static void PLy_generate_spi_exceptions(PyObject *mod, PyObject *base)
static PyModuleDef PLy_module
static PyObject * PLy_error(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * PLy_log(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * PLy_warning(PyObject *self, PyObject *args, PyObject *kw)
static PyObject * PLy_create_exception(char *name, PyObject *base, PyObject *dict, const char *modname, PyObject *mod)
static PyObject * PLy_quote_literal(PyObject *self, PyObject *args)
static PyMethodDef PLy_methods[]
static PyModuleDef PLy_exc_module
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
static PyObject * PLy_info(PyObject *self, PyObject *args, PyObject *kw)
HTAB * PLy_spi_exceptions
static PyObject * PLy_fatal(PyObject *self, PyObject *args, PyObject *kw)
static const ExceptionMap exception_map[]
static void PLy_add_exceptions(PyObject *plpy)
void PLy_result_init_type(void)
PyObject * PLy_spi_prepare(PyObject *self, PyObject *args)
PyObject * PLy_commit(PyObject *self, PyObject *args)
PyObject * PLy_rollback(PyObject *self, PyObject *args)
PyObject * PLy_spi_execute(PyObject *self, PyObject *args)
PyObject * PLy_subtransaction_new(PyObject *self, PyObject *unused)
void PLy_subtransaction_init_type(void)
char * PLyUnicode_AsString(PyObject *unicode)
PyObject * PLyUnicode_FromString(const char *s)
#define PG_DIAG_SCHEMA_NAME
#define PG_DIAG_CONSTRAINT_NAME
#define PG_DIAG_DATATYPE_NAME
#define PG_DIAG_TABLE_NAME
#define PG_DIAG_COLUMN_NAME
char * quote_literal_cstr(const char *rawstr)
const char * quote_identifier(const char *ident)