28 PyObject *base, PyObject *dict,
29 const char *modname, PyObject *mod);
33 static PyObject *
PLy_debug(PyObject *
self, PyObject *
args, PyObject *kw);
34 static PyObject *
PLy_log(PyObject *
self, PyObject *
args, PyObject *kw);
35 static PyObject *
PLy_info(PyObject *
self, PyObject *
args, PyObject *kw);
36 static PyObject *
PLy_notice(PyObject *
self, PyObject *
args, PyObject *kw);
37 static PyObject *
PLy_warning(PyObject *
self, PyObject *
args, PyObject *kw);
38 static PyObject *
PLy_error(PyObject *
self, PyObject *
args, PyObject *kw);
39 static PyObject *
PLy_fatal(PyObject *
self, PyObject *
args, PyObject *kw);
54 #include "spiexceptions.h"
103 {NULL, NULL, 0, NULL}
107 {NULL, NULL, 0, NULL}
111 PyModuleDef_HEAD_INIT,
118 PyModuleDef_HEAD_INIT,
119 .m_name =
"spiexceptions",
164 main_mod = PyImport_AddModule(
"__main__");
165 main_dict = PyModule_GetDict(main_mod);
166 plpy_mod = PyImport_AddModule(
"plpy");
167 if (plpy_mod == NULL)
169 PyDict_SetItemString(main_dict,
"plpy", plpy_mod);
170 if (PyErr_Occurred())
182 PLy_elog(
ERROR,
"could not create the spiexceptions module");
189 if (PyModule_AddObject(plpy,
"spiexceptions", excmod) < 0)
199 hash_ctl.
keysize =
sizeof(int);
212 const char *modname, PyObject *mod)
216 exc = PyErr_NewException(
name, base, dict);
225 PyModule_AddObject(mod, modname, exc);
250 PyObject *dict = PyDict_New();
256 if (sqlstate == NULL)
259 PyDict_SetItemString(dict,
"sqlstate", sqlstate);
277 static PyObject *
PLy_output(
volatile int level, PyObject *
self,
278 PyObject *
args, PyObject *kw);
329 if (!PyArg_ParseTuple(
args,
"s:quote_literal", &
str))
346 if (!PyArg_ParseTuple(
args,
"z:quote_nullable", &
str))
366 if (!PyArg_ParseTuple(
args,
"s:quote_ident", &
str))
381 PyObject *so = PyObject_Str(obj);
401 char *
volatile sqlstatestr = NULL;
402 char *
volatile message = NULL;
403 char *
volatile detail = NULL;
404 char *
volatile hint = NULL;
405 char *
volatile column_name = NULL;
406 char *
volatile constraint_name = NULL;
407 char *
volatile datatype_name = NULL;
408 char *
volatile table_name = NULL;
409 char *
volatile schema_name = NULL;
413 PyObject *
volatile so;
416 if (PyTuple_Size(
args) == 1)
424 if (!PyArg_UnpackTuple(
args,
"plpy.elog", 1, 1, &o))
426 so = PyObject_Str(o);
429 so = PyObject_Str(
args);
442 while (PyDict_Next(kw, &pos, &
key, &
value))
446 if (strcmp(keyword,
"message") == 0)
449 if (PyTuple_Size(
args) != 0)
451 PLy_exception_set(PyExc_TypeError,
"argument 'message' given by name and position");
459 else if (strcmp(keyword,
"detail") == 0)
461 else if (strcmp(keyword,
"hint") == 0)
463 else if (strcmp(keyword,
"sqlstate") == 0)
465 else if (strcmp(keyword,
"schema_name") == 0)
467 else if (strcmp(keyword,
"table_name") == 0)
469 else if (strcmp(keyword,
"column_name") == 0)
471 else if (strcmp(keyword,
"datatype_name") == 0)
473 else if (strcmp(keyword,
"constraint_name") == 0)
478 "'%s' is an invalid keyword argument for this function",
485 if (sqlstatestr != NULL)
487 if (strlen(sqlstatestr) != 5)
493 if (strspn(sqlstatestr,
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
515 if (schema_name != NULL)
517 if (table_name != NULL)
519 if (column_name != NULL)
521 if (datatype_name != NULL)
523 if (constraint_name != NULL)
527 ((sqlstate != 0) ?
errcode(sqlstate) : 0,
530 (hint != NULL) ?
errhint(
"%s", hint) : 0,
531 (column_name != NULL) ?
533 (constraint_name != NULL) ?
535 (datatype_name != NULL) ?
537 (table_name != NULL) ?
539 (schema_name != NULL) ?
#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, long nelem, const HASHCTL *info, int flags)
int err_generic_string(int field, const char *str)
int errmsg_internal(const char *fmt,...)
void FreeErrorData(ErrorData *edata)
int errdetail_internal(const char *fmt,...)
void FlushErrorState(void)
int errhint(const char *fmt,...)
char * unpack_sql_state(int sql_state)
int errcode(int sqlerrcode)
ErrorData * CopyErrorData(void)
#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
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)
static char * object_to_string(PyObject *obj)
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 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)
struct ExceptionMap ExceptionMap
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_spi_execute(PyObject *self, PyObject *args)
PyObject * PLy_rollback(PyObject *self, PyObject *args)
PyObject * PLy_commit(PyObject *self, PyObject *args)
struct PLyExceptionEntry PLyExceptionEntry
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)
MemoryContextSwitchTo(old_ctx)
const char * quote_identifier(const char *ident)