summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/clinic
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2022-11-12 22:44:41 (GMT)
committerGitHub <noreply@github.com>2022-11-12 22:44:41 (GMT)
commitc95f554a408f76f96c14c006ebe8a0d3d3b40765 (patch)
tree28095c0d6ad6b85f09aeae6028038dc62131e6fd /Modules/_sqlite/clinic
parent99972dc7450f1266e39202012827f4f3c995b0ca (diff)
downloadcpython-c95f554a408f76f96c14c006ebe8a0d3d3b40765.zip
cpython-c95f554a408f76f96c14c006ebe8a0d3d3b40765.tar.gz
cpython-c95f554a408f76f96c14c006ebe8a0d3d3b40765.tar.bz2
gh-83638: Add sqlite3.Connection.autocommit for PEP 249 compliant behaviour (#93823)
Introduce the autocommit attribute to Connection and the autocommit parameter to connect() for PEP 249-compliant transaction handling. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: Géry Ogam <gery.ogam@gmail.com>
Diffstat (limited to 'Modules/_sqlite/clinic')
-rw-r--r--Modules/_sqlite/clinic/connection.c.h34
1 files changed, 24 insertions, 10 deletions
diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h
index e7e7870..1f9841c 100644
--- a/Modules/_sqlite/clinic/connection.c.h
+++ b/Modules/_sqlite/clinic/connection.c.h
@@ -13,7 +13,8 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
double timeout, int detect_types,
const char *isolation_level,
int check_same_thread, PyObject *factory,
- int cache_size, int uri);
+ int cache_size, int uri,
+ enum autocommit_mode autocommit);
static int
pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
@@ -21,14 +22,14 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
int return_value = -1;
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- #define NUM_KEYWORDS 8
+ #define NUM_KEYWORDS 9
static struct {
PyGC_Head _this_is_not_used;
PyObject_VAR_HEAD
PyObject *ob_item[NUM_KEYWORDS];
} _kwtuple = {
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
- .ob_item = { &_Py_ID(database), &_Py_ID(timeout), &_Py_ID(detect_types), &_Py_ID(isolation_level), &_Py_ID(check_same_thread), &_Py_ID(factory), &_Py_ID(cached_statements), &_Py_ID(uri), },
+ .ob_item = { &_Py_ID(database), &_Py_ID(timeout), &_Py_ID(detect_types), &_Py_ID(isolation_level), &_Py_ID(check_same_thread), &_Py_ID(factory), &_Py_ID(cached_statements), &_Py_ID(uri), &_Py_ID(autocommit), },
};
#undef NUM_KEYWORDS
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
@@ -37,14 +38,14 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
# define KWTUPLE NULL
#endif // !Py_BUILD_CORE
- static const char * const _keywords[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", "uri", NULL};
+ static const char * const _keywords[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", "uri", "autocommit", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "Connection",
.kwtuple = KWTUPLE,
};
#undef KWTUPLE
- PyObject *argsbuf[8];
+ PyObject *argsbuf[9];
PyObject * const *fastargs;
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
@@ -56,6 +57,7 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *factory = (PyObject*)clinic_state()->ConnectionType;
int cache_size = 128;
int uri = 0;
+ enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
if (!fastargs) {
@@ -121,12 +123,24 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
goto skip_optional_pos;
}
}
- uri = PyObject_IsTrue(fastargs[7]);
- if (uri < 0) {
- goto exit;
+ if (fastargs[7]) {
+ uri = PyObject_IsTrue(fastargs[7]);
+ if (uri < 0) {
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
}
skip_optional_pos:
- return_value = pysqlite_connection_init_impl((pysqlite_Connection *)self, database, timeout, detect_types, isolation_level, check_same_thread, factory, cache_size, uri);
+ if (!noptargs) {
+ goto skip_optional_kwonly;
+ }
+ if (!autocommit_converter(fastargs[8], &autocommit)) {
+ goto exit;
+ }
+skip_optional_kwonly:
+ return_value = pysqlite_connection_init_impl((pysqlite_Connection *)self, database, timeout, detect_types, isolation_level, check_same_thread, factory, cache_size, uri, autocommit);
exit:
return return_value;
@@ -1518,4 +1532,4 @@ exit:
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=beef3eac690a1f88 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=20e929a7a7d62a01 input=a9049054013a1b77]*/