2 * the PLySubtransaction class
4 * src/pl/plpython/plpy_subxactobject.c
22"PostgreSQL subtransaction context manager";
27 /* user-friendly names for Python <2.6 */
48 .name =
"PLySubtransaction",
50 .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
62 elog(
ERROR,
"could not initialize PLy_SubtransactionType");
65/* s = plpy.subtransaction() */
74#if PY_VERSION_HEX < 0x03080000
75 /* Workaround for Python issue 35810; no longer necessary in Python 3.8 */
82 return (PyObject *) ob;
86 * subxact.__enter__() or subxact.enter()
88 * Start an explicit subtransaction. SPI calls within an explicit
89 * subtransaction will not start another one, so you can atomically
90 * execute many SPI calls and still get a controllable exception if
102 PLy_exception_set(PyExc_ValueError,
"this subtransaction has already been entered");
108 PLy_exception_set(PyExc_ValueError,
"this subtransaction has already been exited");
124 /* Be sure that cells of explicit_subtransactions list are long-lived */
128 /* Caller wants to stay in original memory context */
136 * subxact.__exit__(exc_type, exc, tb) or subxact.exit(exc_type, exc, tb)
138 * Exit an explicit subtransaction. exc_type is an exception type, exc
139 * is the exception object, tb is the traceback. If exc_type is None,
140 * commit the subtransaction, if not abort it.
142 * The method signature is chosen to allow subtransaction objects to
143 * be used as context managers as described in
144 * <http://www.python.org/dev/peps/pep-0343/>.
155 if (!PyArg_ParseTuple(
args,
"OOO", &
type, &
value, &traceback))
166 PLy_exception_set(PyExc_ValueError,
"this subtransaction has already been exited");
180 /* Abort the inner transaction */
List * list_delete_first(List *list)
List * lcons(void *datum, List *list)
void * MemoryContextAlloc(MemoryContext context, Size size)
MemoryContext TopTransactionContext
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
void PLy_exception_set(PyObject *exc, const char *fmt,...)
static PyObject * PLy_subtransaction_exit(PyObject *self, PyObject *args)
PyObject * PLy_subtransaction_new(PyObject *self, PyObject *unused)
static PyMethodDef PLy_subtransaction_methods[]
static PyTypeObject * PLy_SubtransactionType
static PyObject * PLy_subtransaction_enter(PyObject *self, PyObject *unused)
static char PLy_subtransaction_doc[]
static PyType_Spec PLySubtransaction_spec
List * explicit_subtransactions
void PLy_subtransaction_init_type(void)
static PyType_Slot PLySubtransaction_slots[]
struct PLySubtransactionObject PLySubtransactionObject
ResourceOwner CurrentResourceOwner
PyObject_HEAD bool started
void BeginInternalSubTransaction(const char *name)
void RollbackAndReleaseCurrentSubTransaction(void)
void ReleaseCurrentSubTransaction(void)