PostgreSQL Source Code  git master
plpy_plpymodule.c File Reference
#include "postgres.h"
#include "access/xact.h"
#include "mb/pg_wchar.h"
#include "plpy_cursorobject.h"
#include "plpy_elog.h"
#include "plpy_main.h"
#include "plpy_planobject.h"
#include "plpy_plpymodule.h"
#include "plpy_resultobject.h"
#include "plpy_spi.h"
#include "plpy_subxactobject.h"
#include "plpython.h"
#include "utils/builtins.h"
#include "utils/snapmgr.h"
#include "spiexceptions.h"
Include dependency graph for plpy_plpymodule.c:

Go to the source code of this file.

Data Structures

struct  ExceptionMap
 

Typedefs

typedef struct ExceptionMap ExceptionMap
 

Functions

static void PLy_add_exceptions (PyObject *plpy)
 
static PyObject * PLy_create_exception (char *name, PyObject *base, PyObject *dict, const char *modname, PyObject *mod)
 
static void PLy_generate_spi_exceptions (PyObject *mod, PyObject *base)
 
static PyObject * PLy_debug (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * PLy_log (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * PLy_info (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * PLy_notice (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * PLy_warning (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * PLy_error (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * PLy_fatal (PyObject *self, PyObject *args, PyObject *kw)
 
static PyObject * PLy_quote_literal (PyObject *self, PyObject *args)
 
static PyObject * PLy_quote_nullable (PyObject *self, PyObject *args)
 
static PyObject * PLy_quote_ident (PyObject *self, PyObject *args)
 
static PyObject * PLy_commit (PyObject *self, PyObject *args)
 
static PyObject * PLy_rollback (PyObject *self, PyObject *args)
 
void PLy_init_plpy (void)
 
static PyObject * PLy_output (volatile int level, PyObject *self, PyObject *args, PyObject *kw)
 
static char * object_to_string (PyObject *obj)
 

Variables

HTABPLy_spi_exceptions = NULL
 
static const ExceptionMap exception_map []
 
static PyMethodDef PLy_methods []
 
static PyMethodDef PLy_exc_methods []
 

Typedef Documentation

◆ ExceptionMap

typedef struct ExceptionMap ExceptionMap

Function Documentation

◆ object_to_string()

static char* object_to_string ( PyObject *  obj)
static

Definition at line 396 of file plpy_plpymodule.c.

References pstrdup(), and generate_unaccent_rules::str.

Referenced by PLy_output().

397 {
398  if (obj)
399  {
400  PyObject *so = PyObject_Str(obj);
401 
402  if (so != NULL)
403  {
404  char *str;
405 
406  str = pstrdup(PyString_AsString(so));
407  Py_DECREF(so);
408 
409  return str;
410  }
411  }
412 
413  return NULL;
414 }
char * pstrdup(const char *in)
Definition: mcxt.c:1186

◆ PLy_add_exceptions()

static void PLy_add_exceptions ( PyObject *  plpy)
static

Definition at line 189 of file plpy_plpymodule.c.

References HASHCTL::entrysize, ERROR, HASH_BLOBS, hash_create(), HASH_ELEM, HASHCTL::keysize, PLy_create_exception(), PLy_elog, PLy_exc_error, PLy_exc_fatal, PLy_exc_methods, PLy_exc_spi_error, and PLy_generate_spi_exceptions().

Referenced by PLy_init_plpy().

190 {
191  PyObject *excmod;
192  HASHCTL hash_ctl;
193 
194 #if PY_MAJOR_VERSION < 3
195  excmod = Py_InitModule("spiexceptions", PLy_exc_methods);
196 #else
197  excmod = PyModule_Create(&PLy_exc_module);
198 #endif
199  if (excmod == NULL)
200  PLy_elog(ERROR, "could not create the spiexceptions module");
201 
202  /*
203  * PyModule_AddObject does not add a refcount to the object, for some odd
204  * reason; we must do that.
205  */
206  Py_INCREF(excmod);
207  if (PyModule_AddObject(plpy, "spiexceptions", excmod) < 0)
208  PLy_elog(ERROR, "could not add the spiexceptions module");
209 
210  PLy_exc_error = PLy_create_exception("plpy.Error", NULL, NULL,
211  "Error", plpy);
212  PLy_exc_fatal = PLy_create_exception("plpy.Fatal", NULL, NULL,
213  "Fatal", plpy);
214  PLy_exc_spi_error = PLy_create_exception("plpy.SPIError", NULL, NULL,
215  "SPIError", plpy);
216 
217  memset(&hash_ctl, 0, sizeof(hash_ctl));
218  hash_ctl.keysize = sizeof(int);
219  hash_ctl.entrysize = sizeof(PLyExceptionEntry);
220  PLy_spi_exceptions = hash_create("PL/Python SPI exceptions", 256,
221  &hash_ctl, HASH_ELEM | HASH_BLOBS);
222 
224 }
#define HASH_ELEM
Definition: hsearch.h:87
Size entrysize
Definition: hsearch.h:73
PyObject * PLy_exc_error
Definition: plpy_elog.c:15
static void PLy_generate_spi_exceptions(PyObject *mod, PyObject *base)
#define ERROR
Definition: elog.h:43
#define PLy_elog
static PyObject * PLy_create_exception(char *name, PyObject *base, PyObject *dict, const char *modname, PyObject *mod)
#define HASH_BLOBS
Definition: hsearch.h:88
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:316
Size keysize
Definition: hsearch.h:72
static PyMethodDef PLy_exc_methods[]
PyObject * PLy_exc_fatal
Definition: plpy_elog.c:16
struct PLyExceptionEntry PLyExceptionEntry
HTAB * PLy_spi_exceptions
PyObject * PLy_exc_spi_error
Definition: plpy_elog.c:17

◆ PLy_commit()

static PyObject * PLy_commit ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 583 of file plpy_plpymodule.c.

References PLy_current_execution_context(), PLyExecutionContext::scratch_ctx, SPI_commit(), and SPI_start_transaction().

584 {
586 
587  SPI_commit();
589 
590  /* was cleared at transaction end, reset pointer */
591  exec_ctx->scratch_ctx = NULL;
592 
593  Py_RETURN_NONE;
594 }
MemoryContext scratch_ctx
Definition: plpy_main.h:21
PLyExecutionContext * PLy_current_execution_context(void)
Definition: plpy_main.c:410
void SPI_commit(void)
Definition: spi.c:278
void SPI_start_transaction(void)
Definition: spi.c:212

◆ PLy_create_exception()

static PyObject * PLy_create_exception ( char *  name,
PyObject *  base,
PyObject *  dict,
const char *  modname,
PyObject *  mod 
)
static

Definition at line 230 of file plpy_plpymodule.c.

References ERROR, and PLy_elog.

Referenced by PLy_add_exceptions(), and PLy_generate_spi_exceptions().

232 {
233  PyObject *exc;
234 
235  exc = PyErr_NewException(name, base, dict);
236  if (exc == NULL)
237  PLy_elog(ERROR, NULL);
238 
239  /*
240  * PyModule_AddObject does not add a refcount to the object, for some odd
241  * reason; we must do that.
242  */
243  Py_INCREF(exc);
244  PyModule_AddObject(mod, modname, exc);
245 
246  /*
247  * The caller will also store a pointer to the exception object in some
248  * permanent variable, so add another ref to account for that. This is
249  * probably excessively paranoid, but let's be sure.
250  */
251  Py_INCREF(exc);
252  return exc;
253 }
#define ERROR
Definition: elog.h:43
#define PLy_elog
const char * name
Definition: encode.c:521

◆ PLy_debug()

static PyObject * PLy_debug ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 300 of file plpy_plpymodule.c.

References DEBUG2, and PLy_output().

301 {
302  return PLy_output(DEBUG2, self, args, kw);
303 }
#define DEBUG2
Definition: elog.h:24
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)

◆ PLy_error()

static PyObject * PLy_error ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 330 of file plpy_plpymodule.c.

References ERROR, and PLy_output().

331 {
332  return PLy_output(ERROR, self, args, kw);
333 }
#define ERROR
Definition: elog.h:43
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)

◆ PLy_fatal()

static PyObject * PLy_fatal ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 336 of file plpy_plpymodule.c.

References FATAL, and PLy_output().

337 {
338  return PLy_output(FATAL, self, args, kw);
339 }
#define FATAL
Definition: elog.h:52
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)

◆ PLy_generate_spi_exceptions()

static void PLy_generate_spi_exceptions ( PyObject *  mod,
PyObject *  base 
)
static

Definition at line 259 of file plpy_plpymodule.c.

References generate_unaccent_rules::args, Assert, ExceptionMap::classname, ERROR, PLyExceptionEntry::exc, HASH_ENTER, hash_search(), i, ExceptionMap::name, PLy_create_exception(), PLy_elog, PLy_output(), ExceptionMap::sqlstate, and unpack_sql_state().

Referenced by PLy_add_exceptions().

260 {
261  int i;
262 
263  for (i = 0; exception_map[i].name != NULL; i++)
264  {
265  bool found;
266  PyObject *exc;
267  PLyExceptionEntry *entry;
268  PyObject *sqlstate;
269  PyObject *dict = PyDict_New();
270 
271  if (dict == NULL)
272  PLy_elog(ERROR, NULL);
273 
274  sqlstate = PyString_FromString(unpack_sql_state(exception_map[i].sqlstate));
275  if (sqlstate == NULL)
276  PLy_elog(ERROR, "could not generate SPI exceptions");
277 
278  PyDict_SetItemString(dict, "sqlstate", sqlstate);
279  Py_DECREF(sqlstate);
280 
281  exc = PLy_create_exception(exception_map[i].name, base, dict,
282  exception_map[i].classname, mod);
283 
284  entry = hash_search(PLy_spi_exceptions, &exception_map[i].sqlstate,
285  HASH_ENTER, &found);
286  Assert(!found);
287  entry->exc = exc;
288  }
289 }
char * unpack_sql_state(int sql_state)
Definition: elog.c:2939
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:906
#define ERROR
Definition: elog.h:43
#define PLy_elog
static const ExceptionMap exception_map[]
static PyObject * PLy_create_exception(char *name, PyObject *base, PyObject *dict, const char *modname, PyObject *mod)
#define Assert(condition)
Definition: c.h:739
HTAB * PLy_spi_exceptions
const char * name
Definition: encode.c:521
int i
PyObject * exc
Definition: plpy_spi.h:18

◆ PLy_info()

static PyObject * PLy_info ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 312 of file plpy_plpymodule.c.

References INFO, and PLy_output().

313 {
314  return PLy_output(INFO, self, args, kw);
315 }
#define INFO
Definition: elog.h:33
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)

◆ PLy_init_plpy()

void PLy_init_plpy ( void  )

Definition at line 147 of file plpy_plpymodule.c.

References ERROR, PLy_add_exceptions(), PLy_cursor_init_type(), PLy_elog, PLy_methods, PLy_plan_init_type(), PLy_result_init_type(), and PLy_subtransaction_init_type().

Referenced by PLy_initialize().

148 {
149  PyObject *main_mod,
150  *main_dict,
151  *plpy_mod;
152 
153 #if PY_MAJOR_VERSION < 3
154  PyObject *plpy;
155 #endif
156 
157  /*
158  * initialize plpy module
159  */
164 
165 #if PY_MAJOR_VERSION >= 3
166  PyModule_Create(&PLy_module);
167  /* for Python 3 we initialized the exceptions in PyInit_plpy */
168 #else
169  plpy = Py_InitModule("plpy", PLy_methods);
170  PLy_add_exceptions(plpy);
171 #endif
172 
173  /* PyDict_SetItemString(plpy, "PlanType", (PyObject *) &PLy_PlanType); */
174 
175  /*
176  * initialize main module, and add plpy
177  */
178  main_mod = PyImport_AddModule("__main__");
179  main_dict = PyModule_GetDict(main_mod);
180  plpy_mod = PyImport_AddModule("plpy");
181  if (plpy_mod == NULL)
182  PLy_elog(ERROR, "could not import \"plpy\" module");
183  PyDict_SetItemString(main_dict, "plpy", plpy_mod);
184  if (PyErr_Occurred())
185  PLy_elog(ERROR, "could not import \"plpy\" module");
186 }
void PLy_plan_init_type(void)
static void PLy_add_exceptions(PyObject *plpy)
#define ERROR
Definition: elog.h:43
void PLy_cursor_init_type(void)
void PLy_subtransaction_init_type(void)
#define PLy_elog
void PLy_result_init_type(void)
static PyMethodDef PLy_methods[]

◆ PLy_log()

static PyObject * PLy_log ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 306 of file plpy_plpymodule.c.

References LOG, and PLy_output().

307 {
308  return PLy_output(LOG, self, args, kw);
309 }
#define LOG
Definition: elog.h:26
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)

◆ PLy_notice()

static PyObject * PLy_notice ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 318 of file plpy_plpymodule.c.

References NOTICE, and PLy_output().

319 {
320  return PLy_output(NOTICE, self, args, kw);
321 }
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
#define NOTICE
Definition: elog.h:37

◆ PLy_output()

static PyObject * PLy_output ( volatile int  level,
PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 417 of file plpy_plpymodule.c.

References CopyErrorData(), CurrentMemoryContext, dgettext, ereport, err_generic_string(), errcode(), errdetail_internal(), errhint(), errmsg_internal(), ERROR, FlushErrorState(), FreeErrorData(), sort-test::key, MAKE_SQLSTATE, MemoryContextSwitchTo(), object_to_string(), pfree(), PG_CATCH, PG_DIAG_COLUMN_NAME, PG_DIAG_CONSTRAINT_NAME, PG_DIAG_DATATYPE_NAME, PG_DIAG_SCHEMA_NAME, PG_DIAG_TABLE_NAME, PG_END_TRY, PG_TRY, pg_verifymbstr(), PLy_elog, PLy_exc_error, PLy_exception_set(), PLy_exception_set_with_details(), pstrdup(), ExceptionMap::sqlstate, TEXTDOMAIN, and value.

Referenced by PLy_debug(), PLy_error(), PLy_fatal(), PLy_generate_spi_exceptions(), PLy_info(), PLy_log(), PLy_notice(), and PLy_warning().

418 {
419  int sqlstate = 0;
420  char *volatile sqlstatestr = NULL;
421  char *volatile message = NULL;
422  char *volatile detail = NULL;
423  char *volatile hint = NULL;
424  char *volatile column_name = NULL;
425  char *volatile constraint_name = NULL;
426  char *volatile datatype_name = NULL;
427  char *volatile table_name = NULL;
428  char *volatile schema_name = NULL;
429  volatile MemoryContext oldcontext;
430  PyObject *key,
431  *value;
432  PyObject *volatile so;
433  Py_ssize_t pos = 0;
434 
435  if (PyTuple_Size(args) == 1)
436  {
437  /*
438  * Treat single argument specially to avoid undesirable ('tuple',)
439  * decoration.
440  */
441  PyObject *o;
442 
443  if (!PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o))
444  PLy_elog(ERROR, "could not unpack arguments in plpy.elog");
445  so = PyObject_Str(o);
446  }
447  else
448  so = PyObject_Str(args);
449 
450  if (so == NULL || ((message = PyString_AsString(so)) == NULL))
451  {
452  level = ERROR;
453  message = dgettext(TEXTDOMAIN, "could not parse error message in plpy.elog");
454  }
455  message = pstrdup(message);
456 
457  Py_XDECREF(so);
458 
459  if (kw != NULL)
460  {
461  while (PyDict_Next(kw, &pos, &key, &value))
462  {
463  char *keyword = PyString_AsString(key);
464 
465  if (strcmp(keyword, "message") == 0)
466  {
467  /* the message should not be overwritten */
468  if (PyTuple_Size(args) != 0)
469  {
470  PLy_exception_set(PyExc_TypeError, "argument 'message' given by name and position");
471  return NULL;
472  }
473 
474  if (message)
475  pfree(message);
476  message = object_to_string(value);
477  }
478  else if (strcmp(keyword, "detail") == 0)
479  detail = object_to_string(value);
480  else if (strcmp(keyword, "hint") == 0)
481  hint = object_to_string(value);
482  else if (strcmp(keyword, "sqlstate") == 0)
483  sqlstatestr = object_to_string(value);
484  else if (strcmp(keyword, "schema_name") == 0)
485  schema_name = object_to_string(value);
486  else if (strcmp(keyword, "table_name") == 0)
487  table_name = object_to_string(value);
488  else if (strcmp(keyword, "column_name") == 0)
489  column_name = object_to_string(value);
490  else if (strcmp(keyword, "datatype_name") == 0)
491  datatype_name = object_to_string(value);
492  else if (strcmp(keyword, "constraint_name") == 0)
493  constraint_name = object_to_string(value);
494  else
495  {
496  PLy_exception_set(PyExc_TypeError,
497  "'%s' is an invalid keyword argument for this function",
498  keyword);
499  return NULL;
500  }
501  }
502  }
503 
504  if (sqlstatestr != NULL)
505  {
506  if (strlen(sqlstatestr) != 5)
507  {
508  PLy_exception_set(PyExc_ValueError, "invalid SQLSTATE code");
509  return NULL;
510  }
511 
512  if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
513  {
514  PLy_exception_set(PyExc_ValueError, "invalid SQLSTATE code");
515  return NULL;
516  }
517 
518  sqlstate = MAKE_SQLSTATE(sqlstatestr[0],
519  sqlstatestr[1],
520  sqlstatestr[2],
521  sqlstatestr[3],
522  sqlstatestr[4]);
523  }
524 
525  oldcontext = CurrentMemoryContext;
526  PG_TRY();
527  {
528  if (message != NULL)
529  pg_verifymbstr(message, strlen(message), false);
530  if (detail != NULL)
531  pg_verifymbstr(detail, strlen(detail), false);
532  if (hint != NULL)
533  pg_verifymbstr(hint, strlen(hint), false);
534  if (schema_name != NULL)
535  pg_verifymbstr(schema_name, strlen(schema_name), false);
536  if (table_name != NULL)
537  pg_verifymbstr(table_name, strlen(table_name), false);
538  if (column_name != NULL)
539  pg_verifymbstr(column_name, strlen(column_name), false);
540  if (datatype_name != NULL)
541  pg_verifymbstr(datatype_name, strlen(datatype_name), false);
542  if (constraint_name != NULL)
543  pg_verifymbstr(constraint_name, strlen(constraint_name), false);
544 
545  ereport(level,
546  ((sqlstate != 0) ? errcode(sqlstate) : 0,
547  (message != NULL) ? errmsg_internal("%s", message) : 0,
548  (detail != NULL) ? errdetail_internal("%s", detail) : 0,
549  (hint != NULL) ? errhint("%s", hint) : 0,
550  (column_name != NULL) ?
551  err_generic_string(PG_DIAG_COLUMN_NAME, column_name) : 0,
552  (constraint_name != NULL) ?
553  err_generic_string(PG_DIAG_CONSTRAINT_NAME, constraint_name) : 0,
554  (datatype_name != NULL) ?
555  err_generic_string(PG_DIAG_DATATYPE_NAME, datatype_name) : 0,
556  (table_name != NULL) ?
557  err_generic_string(PG_DIAG_TABLE_NAME, table_name) : 0,
558  (schema_name != NULL) ?
559  err_generic_string(PG_DIAG_SCHEMA_NAME, schema_name) : 0));
560  }
561  PG_CATCH();
562  {
563  ErrorData *edata;
564 
565  MemoryContextSwitchTo(oldcontext);
566  edata = CopyErrorData();
567  FlushErrorState();
568 
570  FreeErrorData(edata);
571 
572  return NULL;
573  }
574  PG_END_TRY();
575 
576  /*
577  * return a legal object so the interpreter will continue on its merry way
578  */
579  Py_RETURN_NONE;
580 }
int errhint(const char *fmt,...)
Definition: elog.c:1069
#define PG_DIAG_SCHEMA_NAME
Definition: postgres_ext.h:65
#define TEXTDOMAIN
Definition: elog.h:144
ErrorData * CopyErrorData(void)
Definition: elog.c:1584
#define PG_DIAG_COLUMN_NAME
Definition: postgres_ext.h:67
#define MAKE_SQLSTATE(ch1, ch2, ch3, ch4, ch5)
Definition: elog.h:62
char * pstrdup(const char *in)
Definition: mcxt.c:1186
#define PG_DIAG_TABLE_NAME
Definition: postgres_ext.h:66
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static struct @145 value
int errcode(int sqlerrcode)
Definition: elog.c:608
PyObject * PLy_exc_error
Definition: plpy_elog.c:15
void PLy_exception_set(PyObject *exc, const char *fmt,...)
Definition: plpy_elog.c:487
void FlushErrorState(void)
Definition: elog.c:1678
int Py_ssize_t
Definition: plpython.h:66
int errdetail_internal(const char *fmt,...)
Definition: elog.c:982
void pfree(void *pointer)
Definition: mcxt.c:1056
void FreeErrorData(ErrorData *edata)
Definition: elog.c:1640
#define ERROR
Definition: elog.h:43
#define PLy_elog
void PLy_exception_set_with_details(PyObject *excclass, ErrorData *edata)
Definition: plpy_elog.c:519
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define ereport(elevel, rest)
Definition: elog.h:141
#define dgettext(d, x)
Definition: c.h:1133
#define PG_DIAG_DATATYPE_NAME
Definition: postgres_ext.h:68
#define PG_DIAG_CONSTRAINT_NAME
Definition: postgres_ext.h:69
int errmsg_internal(const char *fmt,...)
Definition: elog.c:909
#define PG_CATCH()
Definition: elog.h:332
bool pg_verifymbstr(const char *mbstr, int len, bool noError)
Definition: wchar.c:1914
int err_generic_string(int field, const char *str)
Definition: elog.c:1273
#define PG_TRY()
Definition: elog.h:322
static char * object_to_string(PyObject *obj)
#define PG_END_TRY()
Definition: elog.h:347

◆ PLy_quote_ident()

static PyObject * PLy_quote_ident ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 379 of file plpy_plpymodule.c.

References quote_identifier(), and generate_unaccent_rules::str.

380 {
381  const char *str;
382  const char *quoted;
383  PyObject *ret;
384 
385  if (!PyArg_ParseTuple(args, "s:quote_ident", &str))
386  return NULL;
387 
388  quoted = quote_identifier(str);
389  ret = PyString_FromString(quoted);
390 
391  return ret;
392 }
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10640

◆ PLy_quote_literal()

static PyObject * PLy_quote_literal ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 342 of file plpy_plpymodule.c.

References pfree(), quote_literal_cstr(), and generate_unaccent_rules::str.

343 {
344  const char *str;
345  char *quoted;
346  PyObject *ret;
347 
348  if (!PyArg_ParseTuple(args, "s:quote_literal", &str))
349  return NULL;
350 
351  quoted = quote_literal_cstr(str);
352  ret = PyString_FromString(quoted);
353  pfree(quoted);
354 
355  return ret;
356 }
char * quote_literal_cstr(const char *rawstr)
Definition: quote.c:102
void pfree(void *pointer)
Definition: mcxt.c:1056

◆ PLy_quote_nullable()

static PyObject * PLy_quote_nullable ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 359 of file plpy_plpymodule.c.

References pfree(), quote_literal_cstr(), and generate_unaccent_rules::str.

360 {
361  const char *str;
362  char *quoted;
363  PyObject *ret;
364 
365  if (!PyArg_ParseTuple(args, "z:quote_nullable", &str))
366  return NULL;
367 
368  if (str == NULL)
369  return PyString_FromString("NULL");
370 
371  quoted = quote_literal_cstr(str);
372  ret = PyString_FromString(quoted);
373  pfree(quoted);
374 
375  return ret;
376 }
char * quote_literal_cstr(const char *rawstr)
Definition: quote.c:102
void pfree(void *pointer)
Definition: mcxt.c:1056

◆ PLy_rollback()

static PyObject * PLy_rollback ( PyObject *  self,
PyObject *  args 
)
static

Definition at line 597 of file plpy_plpymodule.c.

References PLy_current_execution_context(), PLyExecutionContext::scratch_ctx, SPI_rollback(), and SPI_start_transaction().

598 {
600 
601  SPI_rollback();
603 
604  /* was cleared at transaction end, reset pointer */
605  exec_ctx->scratch_ctx = NULL;
606 
607  Py_RETURN_NONE;
608 }
MemoryContext scratch_ctx
Definition: plpy_main.h:21
PLyExecutionContext * PLy_current_execution_context(void)
Definition: plpy_main.c:410
void SPI_rollback(void)
Definition: spi.c:333
void SPI_start_transaction(void)
Definition: spi.c:212

◆ PLy_warning()

static PyObject * PLy_warning ( PyObject *  self,
PyObject *  args,
PyObject *  kw 
)
static

Definition at line 324 of file plpy_plpymodule.c.

References PLy_output(), and WARNING.

325 {
326  return PLy_output(WARNING, self, args, kw);
327 }
static PyObject * PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
#define WARNING
Definition: elog.h:40

Variable Documentation

◆ exception_map

const ExceptionMap exception_map[]
static
Initial value:
= {
{NULL, NULL, 0}
}

Definition at line 55 of file plpy_plpymodule.c.

◆ PLy_exc_methods

PyMethodDef PLy_exc_methods[]
static
Initial value:
= {
{NULL, NULL, 0, NULL}
}

Definition at line 108 of file plpy_plpymodule.c.

Referenced by PLy_add_exceptions().

◆ PLy_methods

PyMethodDef PLy_methods[]
static

Definition at line 60 of file plpy_plpymodule.c.

Referenced by PLy_init_plpy().

◆ PLy_spi_exceptions

HTAB* PLy_spi_exceptions = NULL

Definition at line 23 of file plpy_plpymodule.c.

Referenced by PLy_spi_subtransaction_abort().