summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2020-12-18 14:25:35 (GMT)
committerGitHub <noreply@github.com>2020-12-18 14:25:35 (GMT)
commit1ba82bbc50a52f40ad05f3c4aaf2e159e0ce126d (patch)
tree682d8168ef78bbe50f3288525073743a07973644 /Modules
parent84ebcf271a2cc8bfd1762acb279502b8b6ef236e (diff)
downloadcpython-1ba82bbc50a52f40ad05f3c4aaf2e159e0ce126d.zip
cpython-1ba82bbc50a52f40ad05f3c4aaf2e159e0ce126d.tar.gz
cpython-1ba82bbc50a52f40ad05f3c4aaf2e159e0ce126d.tar.bz2
bpo-40956: Convert _sqlite3.Connection to Argument Clinic (GH-23341)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sqlite/clinic/connection.c.h490
-rw-r--r--Modules/_sqlite/connection.c344
-rw-r--r--Modules/_sqlite/connection.h3
3 files changed, 702 insertions, 135 deletions
diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h
new file mode 100644
index 0000000..6b0ff4d
--- /dev/null
+++ b/Modules/_sqlite/clinic/connection.c.h
@@ -0,0 +1,490 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(pysqlite_connection_cursor__doc__,
+"cursor($self, /, factory=<unrepresentable>)\n"
+"--\n"
+"\n"
+"Return a cursor for the connection.");
+
+#define PYSQLITE_CONNECTION_CURSOR_METHODDEF \
+ {"cursor", (PyCFunction)(void(*)(void))pysqlite_connection_cursor, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_cursor__doc__},
+
+static PyObject *
+pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory);
+
+static PyObject *
+pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"factory", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "cursor", 0};
+ PyObject *argsbuf[1];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
+ PyObject *factory = NULL;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ factory = args[0];
+skip_optional_pos:
+ return_value = pysqlite_connection_cursor_impl(self, factory);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(pysqlite_connection_close__doc__,
+"close($self, /)\n"
+"--\n"
+"\n"
+"Closes the connection.");
+
+#define PYSQLITE_CONNECTION_CLOSE_METHODDEF \
+ {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS, pysqlite_connection_close__doc__},
+
+static PyObject *
+pysqlite_connection_close_impl(pysqlite_Connection *self);
+
+static PyObject *
+pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+{
+ return pysqlite_connection_close_impl(self);
+}
+
+PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
+"rollback($self, /)\n"
+"--\n"
+"\n"
+"Roll back the current transaction.");
+
+#define PYSQLITE_CONNECTION_ROLLBACK_METHODDEF \
+ {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS, pysqlite_connection_rollback__doc__},
+
+static PyObject *
+pysqlite_connection_rollback_impl(pysqlite_Connection *self);
+
+static PyObject *
+pysqlite_connection_rollback(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+{
+ return pysqlite_connection_rollback_impl(self);
+}
+
+PyDoc_STRVAR(pysqlite_connection_create_function__doc__,
+"create_function($self, /, name, narg, func, *, deterministic=False)\n"
+"--\n"
+"\n"
+"Creates a new function. Non-standard.");
+
+#define PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF \
+ {"create_function", (PyCFunction)(void(*)(void))pysqlite_connection_create_function, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_function__doc__},
+
+static PyObject *
+pysqlite_connection_create_function_impl(pysqlite_Connection *self,
+ const char *name, int narg,
+ PyObject *func, int deterministic);
+
+static PyObject *
+pysqlite_connection_create_function(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"name", "narg", "func", "deterministic", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "create_function", 0};
+ PyObject *argsbuf[4];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
+ const char *name;
+ int narg;
+ PyObject *func;
+ int deterministic = 0;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
+ goto exit;
+ }
+ Py_ssize_t name_length;
+ name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+ if (name == NULL) {
+ goto exit;
+ }
+ if (strlen(name) != (size_t)name_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ narg = _PyLong_AsInt(args[1]);
+ if (narg == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ func = args[2];
+ if (!noptargs) {
+ goto skip_optional_kwonly;
+ }
+ deterministic = PyObject_IsTrue(args[3]);
+ if (deterministic < 0) {
+ goto exit;
+ }
+skip_optional_kwonly:
+ return_value = pysqlite_connection_create_function_impl(self, name, narg, func, deterministic);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(pysqlite_connection_create_aggregate__doc__,
+"create_aggregate($self, /, name, n_arg, aggregate_class)\n"
+"--\n"
+"\n"
+"Creates a new aggregate. Non-standard.");
+
+#define PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF \
+ {"create_aggregate", (PyCFunction)(void(*)(void))pysqlite_connection_create_aggregate, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_aggregate__doc__},
+
+static PyObject *
+pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
+ const char *name, int n_arg,
+ PyObject *aggregate_class);
+
+static PyObject *
+pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"name", "n_arg", "aggregate_class", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "create_aggregate", 0};
+ PyObject *argsbuf[3];
+ const char *name;
+ int n_arg;
+ PyObject *aggregate_class;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
+ goto exit;
+ }
+ Py_ssize_t name_length;
+ name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
+ if (name == NULL) {
+ goto exit;
+ }
+ if (strlen(name) != (size_t)name_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ n_arg = _PyLong_AsInt(args[1]);
+ if (n_arg == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ aggregate_class = args[2];
+ return_value = pysqlite_connection_create_aggregate_impl(self, name, n_arg, aggregate_class);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(pysqlite_connection_set_authorizer__doc__,
+"set_authorizer($self, /, authorizer_callback)\n"
+"--\n"
+"\n"
+"Sets authorizer callback. Non-standard.");
+
+#define PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF \
+ {"set_authorizer", (PyCFunction)(void(*)(void))pysqlite_connection_set_authorizer, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_authorizer__doc__},
+
+static PyObject *
+pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
+ PyObject *authorizer_cb);
+
+static PyObject *
+pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"authorizer_callback", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "set_authorizer", 0};
+ PyObject *argsbuf[1];
+ PyObject *authorizer_cb;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ authorizer_cb = args[0];
+ return_value = pysqlite_connection_set_authorizer_impl(self, authorizer_cb);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(pysqlite_connection_set_progress_handler__doc__,
+"set_progress_handler($self, /, progress_handler, n)\n"
+"--\n"
+"\n"
+"Sets progress handler callback. Non-standard.");
+
+#define PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF \
+ {"set_progress_handler", (PyCFunction)(void(*)(void))pysqlite_connection_set_progress_handler, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_progress_handler__doc__},
+
+static PyObject *
+pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
+ PyObject *progress_handler,
+ int n);
+
+static PyObject *
+pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"progress_handler", "n", NULL};
+ static _PyArg_Parser _parser = {NULL, _keywords, "set_progress_handler", 0};
+ PyObject *argsbuf[2];
+ PyObject *progress_handler;
+ int n;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ progress_handler = args[0];
+ n = _PyLong_AsInt(args[1]);
+ if (n == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = pysqlite_connection_set_progress_handler_impl(self, progress_handler, n);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(pysqlite_connection_set_trace_callback__doc__,
+"set_trace_callback($self, trace_callback, /)\n"
+"--\n"
+"\n"
+"Sets a trace callback called for each SQL statement (passed as unicode).\n"
+"\n"
+"Non-standard.");
+
+#define PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF \
+ {"set_trace_callback", (PyCFunction)pysqlite_connection_set_trace_callback, METH_O, pysqlite_connection_set_trace_callback__doc__},
+
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
+
+PyDoc_STRVAR(pysqlite_connection_enable_load_extension__doc__,
+"enable_load_extension($self, enable, /)\n"
+"--\n"
+"\n"
+"Enable dynamic loading of SQLite extension modules. Non-standard.");
+
+#define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF \
+ {"enable_load_extension", (PyCFunction)pysqlite_connection_enable_load_extension, METH_O, pysqlite_connection_enable_load_extension__doc__},
+
+static PyObject *
+pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
+ int onoff);
+
+static PyObject *
+pysqlite_connection_enable_load_extension(pysqlite_Connection *self, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int onoff;
+
+ onoff = _PyLong_AsInt(arg);
+ if (onoff == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = pysqlite_connection_enable_load_extension_impl(self, onoff);
+
+exit:
+ return return_value;
+}
+
+#endif /* !defined(SQLITE_OMIT_LOAD_EXTENSION) */
+
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
+
+PyDoc_STRVAR(pysqlite_connection_load_extension__doc__,
+"load_extension($self, name, /)\n"
+"--\n"
+"\n"
+"Load SQLite extension module. Non-standard.");
+
+#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF \
+ {"load_extension", (PyCFunction)pysqlite_connection_load_extension, METH_O, pysqlite_connection_load_extension__doc__},
+
+static PyObject *
+pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
+ const char *extension_name);
+
+static PyObject *
+pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ const char *extension_name;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("load_extension", "argument", "str", arg);
+ goto exit;
+ }
+ Py_ssize_t extension_name_length;
+ extension_name = PyUnicode_AsUTF8AndSize(arg, &extension_name_length);
+ if (extension_name == NULL) {
+ goto exit;
+ }
+ if (strlen(extension_name) != (size_t)extension_name_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ return_value = pysqlite_connection_load_extension_impl(self, extension_name);
+
+exit:
+ return return_value;
+}
+
+#endif /* !defined(SQLITE_OMIT_LOAD_EXTENSION) */
+
+PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
+"interrupt($self, /)\n"
+"--\n"
+"\n"
+"Abort any pending database operation. Non-standard.");
+
+#define PYSQLITE_CONNECTION_INTERRUPT_METHODDEF \
+ {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS, pysqlite_connection_interrupt__doc__},
+
+static PyObject *
+pysqlite_connection_interrupt_impl(pysqlite_Connection *self);
+
+static PyObject *
+pysqlite_connection_interrupt(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+{
+ return pysqlite_connection_interrupt_impl(self);
+}
+
+PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
+"iterdump($self, /)\n"
+"--\n"
+"\n"
+"Returns iterator to the dump of the database in an SQL text format.\n"
+"\n"
+"Non-standard.");
+
+#define PYSQLITE_CONNECTION_ITERDUMP_METHODDEF \
+ {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS, pysqlite_connection_iterdump__doc__},
+
+static PyObject *
+pysqlite_connection_iterdump_impl(pysqlite_Connection *self);
+
+static PyObject *
+pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+{
+ return pysqlite_connection_iterdump_impl(self);
+}
+
+PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
+"create_collation($self, name, callback, /)\n"
+"--\n"
+"\n"
+"Creates a collation function. Non-standard.");
+
+#define PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF \
+ {"create_collation", (PyCFunction)(void(*)(void))pysqlite_connection_create_collation, METH_FASTCALL, pysqlite_connection_create_collation__doc__},
+
+static PyObject *
+pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
+ PyObject *name, PyObject *callable);
+
+static PyObject *
+pysqlite_connection_create_collation(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *name;
+ PyObject *callable;
+
+ if (!_PyArg_CheckPositional("create_collation", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[0])) {
+ _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
+ goto exit;
+ }
+ if (PyUnicode_READY(args[0]) == -1) {
+ goto exit;
+ }
+ name = args[0];
+ callable = args[1];
+ return_value = pysqlite_connection_create_collation_impl(self, name, callable);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(pysqlite_connection_enter__doc__,
+"__enter__($self, /)\n"
+"--\n"
+"\n"
+"Called when the connection is used as a context manager.\n"
+"\n"
+"Returns itself as a convenience to the caller.");
+
+#define PYSQLITE_CONNECTION_ENTER_METHODDEF \
+ {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS, pysqlite_connection_enter__doc__},
+
+static PyObject *
+pysqlite_connection_enter_impl(pysqlite_Connection *self);
+
+static PyObject *
+pysqlite_connection_enter(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+{
+ return pysqlite_connection_enter_impl(self);
+}
+
+PyDoc_STRVAR(pysqlite_connection_exit__doc__,
+"__exit__($self, type, value, traceback, /)\n"
+"--\n"
+"\n"
+"Called when the connection is used as a context manager.\n"
+"\n"
+"If there was any exception, a rollback takes place; otherwise we commit.");
+
+#define PYSQLITE_CONNECTION_EXIT_METHODDEF \
+ {"__exit__", (PyCFunction)(void(*)(void))pysqlite_connection_exit, METH_FASTCALL, pysqlite_connection_exit__doc__},
+
+static PyObject *
+pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
+ PyObject *exc_value, PyObject *exc_tb);
+
+static PyObject *
+pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *exc_type;
+ PyObject *exc_value;
+ PyObject *exc_tb;
+
+ if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
+ goto exit;
+ }
+ exc_type = args[0];
+ exc_value = args[1];
+ exc_tb = args[2];
+ return_value = pysqlite_connection_exit_impl(self, exc_type, exc_value, exc_tb);
+
+exit:
+ return return_value;
+}
+
+#ifndef PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
+ #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
+#endif /* !defined(PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF) */
+
+#ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
+ #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
+#endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
+/*[clinic end generated code: output=e14085c0abc0a407 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 69203f8..1c8f37e 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -37,6 +37,13 @@
#define HAVE_TRACE_V2
#endif
+#include "clinic/connection.c.h"
+/*[clinic input]
+module _sqlite3
+class _sqlite3.Connection "pysqlite_Connection *" "pysqlite_ConnectionType"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=aa796073bd8f69db]*/
+
_Py_IDENTIFIER(cursor);
static const char * const begin_statements[] = {
@@ -269,17 +276,20 @@ error:
return 0;
}
-PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
+/*[clinic input]
+_sqlite3.Connection.cursor as pysqlite_connection_cursor
+
+ factory: object = NULL
+
+Return a cursor for the connection.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
+/*[clinic end generated code: output=562432a9e6af2aa1 input=4127345aa091b650]*/
{
- static char *kwlist[] = {"factory", NULL};
- PyObject* factory = NULL;
PyObject* cursor;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist,
- &factory)) {
- return NULL;
- }
-
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
@@ -309,7 +319,15 @@ PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args,
return cursor;
}
-PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args)
+/*[clinic input]
+_sqlite3.Connection.close as pysqlite_connection_close
+
+Closes the connection.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_connection_close_impl(pysqlite_Connection *self)
+/*[clinic end generated code: output=a546a0da212c9b97 input=3d58064bbffaa3d3]*/
{
int rc;
@@ -431,7 +449,15 @@ error:
}
}
-PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args)
+/*[clinic input]
+_sqlite3.Connection.rollback as pysqlite_connection_rollback
+
+Roll back the current transaction.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_connection_rollback_impl(pysqlite_Connection *self)
+/*[clinic end generated code: output=b66fa0d43e7ef305 input=12d4e8d068942830]*/
{
int rc;
const char* tail;
@@ -780,27 +806,31 @@ static void _destructor(void* args)
Py_DECREF((PyObject*)args);
}
-PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
-{
- static char *kwlist[] = {"name", "narg", "func", "deterministic", NULL};
+/*[clinic input]
+_sqlite3.Connection.create_function as pysqlite_connection_create_function
+
+ name: str
+ narg: int
+ func: object
+ *
+ deterministic: bool = False
+
+Creates a new function. Non-standard.
+[clinic start generated code]*/
- PyObject* func;
- char* name;
- int narg;
+static PyObject *
+pysqlite_connection_create_function_impl(pysqlite_Connection *self,
+ const char *name, int narg,
+ PyObject *func, int deterministic)
+/*[clinic end generated code: output=07d1877dd98c0308 input=f2edcf073e815beb]*/
+{
int rc;
- int deterministic = 0;
int flags = SQLITE_UTF8;
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO|$p", kwlist,
- &name, &narg, &func, &deterministic))
- {
- return NULL;
- }
-
if (deterministic) {
#if SQLITE_VERSION_NUMBER < 3008003
PyErr_SetString(pysqlite_NotSupportedError,
@@ -834,23 +864,28 @@ PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObjec
Py_RETURN_NONE;
}
-PyObject* pysqlite_connection_create_aggregate(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
-{
- PyObject* aggregate_class;
+/*[clinic input]
+_sqlite3.Connection.create_aggregate as pysqlite_connection_create_aggregate
- int n_arg;
- char* name;
- static char *kwlist[] = { "name", "n_arg", "aggregate_class", NULL };
+ name: str
+ n_arg: int
+ aggregate_class: object
+
+Creates a new aggregate. Non-standard.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
+ const char *name, int n_arg,
+ PyObject *aggregate_class)
+/*[clinic end generated code: output=fbb2f858cfa4d8db input=c2e13bbf234500a5]*/
+{
int rc;
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO:create_aggregate",
- kwlist, &name, &n_arg, &aggregate_class)) {
- return NULL;
- }
Py_INCREF(aggregate_class);
rc = sqlite3_create_function_v2(self->db,
name,
@@ -982,22 +1017,25 @@ static void _trace_callback(void* user_arg, const char* statement_string)
#endif
}
-static PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
-{
- PyObject* authorizer_cb;
+/*[clinic input]
+_sqlite3.Connection.set_authorizer as pysqlite_connection_set_authorizer
+
+ authorizer_callback as authorizer_cb: object
+
+Sets authorizer callback. Non-standard.
+[clinic start generated code]*/
- static char *kwlist[] = { "authorizer_callback", NULL };
+static PyObject *
+pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
+ PyObject *authorizer_cb)
+/*[clinic end generated code: output=f18ba575d788b35c input=df079724c020d2f2]*/
+{
int rc;
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:set_authorizer",
- kwlist, &authorizer_cb)) {
- return NULL;
- }
-
rc = sqlite3_set_authorizer(self->db, _authorizer_callback, (void*)authorizer_cb);
if (rc != SQLITE_OK) {
PyErr_SetString(pysqlite_OperationalError, "Error setting authorizer callback");
@@ -1010,19 +1048,22 @@ static PyObject* pysqlite_connection_set_authorizer(pysqlite_Connection* self, P
Py_RETURN_NONE;
}
-static PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
-{
- PyObject* progress_handler;
- int n;
+/*[clinic input]
+_sqlite3.Connection.set_progress_handler as pysqlite_connection_set_progress_handler
- static char *kwlist[] = { "progress_handler", "n", NULL };
+ progress_handler: object
+ n: int
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
+Sets progress handler callback. Non-standard.
+[clinic start generated code]*/
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oi:set_progress_handler",
- kwlist, &progress_handler, &n)) {
+static PyObject *
+pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
+ PyObject *progress_handler,
+ int n)
+/*[clinic end generated code: output=35a7c10364cb1b04 input=857696c25f964c64]*/
+{
+ if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
@@ -1038,28 +1079,34 @@ static PyObject* pysqlite_connection_set_progress_handler(pysqlite_Connection* s
Py_RETURN_NONE;
}
-/*
- * Ref.
- * - https://sqlite.org/c3ref/c_trace.html
- * - https://sqlite.org/c3ref/trace_v2.html
- */
-static PyObject* pysqlite_connection_set_trace_callback(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
-{
- PyObject* trace_callback;
+/*[clinic input]
+_sqlite3.Connection.set_trace_callback as pysqlite_connection_set_trace_callback
- static char *kwlist[] = { "trace_callback", NULL };
+ trace_callback: object
+ /
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
+Sets a trace callback called for each SQL statement (passed as unicode).
+
+Non-standard.
+[clinic start generated code]*/
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:set_trace_callback",
- kwlist, &trace_callback)) {
+static PyObject *
+pysqlite_connection_set_trace_callback(pysqlite_Connection *self,
+ PyObject *trace_callback)
+/*[clinic end generated code: output=efd1bf439e81696c input=05a4a14360e0e034]*/
+{
+ if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
if (trace_callback == Py_None) {
- /* None clears the trace callback previously set */
+ /*
+ * None clears the trace callback previously set
+ *
+ * Ref.
+ * - https://sqlite.org/c3ref/c_trace.html
+ * - https://sqlite.org/c3ref/trace_v2.html
+ */
#ifdef HAVE_TRACE_V2
sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, 0, 0);
#else
@@ -1080,19 +1127,26 @@ static PyObject* pysqlite_connection_set_trace_callback(pysqlite_Connection* sel
}
#ifndef SQLITE_OMIT_LOAD_EXTENSION
-static PyObject* pysqlite_enable_load_extension(pysqlite_Connection* self, PyObject* args)
+/*[clinic input]
+_sqlite3.Connection.enable_load_extension as pysqlite_connection_enable_load_extension
+
+ enable as onoff: int
+ /
+
+Enable dynamic loading of SQLite extension modules. Non-standard.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
+ int onoff)
+/*[clinic end generated code: output=9cac37190d388baf input=7df2986f1602d6bd]*/
{
int rc;
- int onoff;
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
- if (!PyArg_ParseTuple(args, "i", &onoff)) {
- return NULL;
- }
-
rc = sqlite3_enable_load_extension(self->db, onoff);
if (rc != SQLITE_OK) {
@@ -1103,20 +1157,27 @@ static PyObject* pysqlite_enable_load_extension(pysqlite_Connection* self, PyObj
}
}
-static PyObject* pysqlite_load_extension(pysqlite_Connection* self, PyObject* args)
+/*[clinic input]
+_sqlite3.Connection.load_extension as pysqlite_connection_load_extension
+
+ name as extension_name: str
+ /
+
+Load SQLite extension module. Non-standard.
+[clinic start generated code]*/
+
+static PyObject *
+pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
+ const char *extension_name)
+/*[clinic end generated code: output=47eb1d7312bc97a7 input=0b711574560db9fc]*/
{
int rc;
- char* extension_name;
char* errmsg;
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
- if (!PyArg_ParseTuple(args, "s", &extension_name)) {
- return NULL;
- }
-
rc = sqlite3_load_extension(self->db, extension_name, 0, &errmsg);
if (rc != 0) {
PyErr_SetString(pysqlite_OperationalError, errmsg);
@@ -1421,8 +1482,15 @@ finally:
return result;
}
+/*[clinic input]
+_sqlite3.Connection.interrupt as pysqlite_connection_interrupt
+
+Abort any pending database operation. Non-standard.
+[clinic start generated code]*/
+
static PyObject *
-pysqlite_connection_interrupt(pysqlite_Connection* self, PyObject* args)
+pysqlite_connection_interrupt_impl(pysqlite_Connection *self)
+/*[clinic end generated code: output=f193204bc9e70b47 input=4bd0ad083cf93aa7]*/
{
PyObject* retval = NULL;
@@ -1443,8 +1511,17 @@ finally:
* Class method of Connection to call the Python function _iterdump
* of the sqlite3 module.
*/
+/*[clinic input]
+_sqlite3.Connection.iterdump as pysqlite_connection_iterdump
+
+Returns iterator to the dump of the database in an SQL text format.
+
+Non-standard.
+[clinic start generated code]*/
+
static PyObject *
-pysqlite_connection_iterdump(pysqlite_Connection* self, PyObject* args)
+pysqlite_connection_iterdump_impl(pysqlite_Connection *self)
+/*[clinic end generated code: output=586997aaf9808768 input=53bc907cb5eedb85]*/
{
_Py_IDENTIFIER(_iterdump);
PyObject* retval = NULL;
@@ -1637,12 +1714,22 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *args, PyObject *
}
}
+/*[clinic input]
+_sqlite3.Connection.create_collation as pysqlite_connection_create_collation
+
+ name: unicode
+ callback as callable: object
+ /
+
+Creates a collation function. Non-standard.
+[clinic start generated code]*/
+
static PyObject *
-pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
+pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
+ PyObject *name, PyObject *callable)
+/*[clinic end generated code: output=0f63b8995565ae22 input=5c3898813a776cf2]*/
{
- PyObject* callable;
PyObject* uppercase_name = 0;
- PyObject* name;
PyObject* retval;
Py_ssize_t i, len;
_Py_IDENTIFIER(upper);
@@ -1655,11 +1742,6 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args)
goto finally;
}
- if (!PyArg_ParseTuple(args, "UO:create_collation(name, callback)",
- &name, &callable)) {
- goto finally;
- }
-
uppercase_name = _PyObject_CallMethodIdOneArg((PyObject *)&PyUnicode_Type,
&PyId_upper, name);
if (!uppercase_name) {
@@ -1725,28 +1807,43 @@ finally:
return retval;
}
-/* Called when the connection is used as a context manager. Returns itself as a
- * convenience to the caller. */
+/*[clinic input]
+_sqlite3.Connection.__enter__ as pysqlite_connection_enter
+
+Called when the connection is used as a context manager.
+
+Returns itself as a convenience to the caller.
+[clinic start generated code]*/
+
static PyObject *
-pysqlite_connection_enter(pysqlite_Connection* self, PyObject* args)
+pysqlite_connection_enter_impl(pysqlite_Connection *self)
+/*[clinic end generated code: output=457b09726d3e9dcd input=127d7a4f17e86d8f]*/
{
Py_INCREF(self);
return (PyObject*)self;
}
-/** Called when the connection is used as a context manager. If there was any
- * exception, a rollback takes place; otherwise we commit. */
+/*[clinic input]
+_sqlite3.Connection.__exit__ as pysqlite_connection_exit
+
+ type as exc_type: object
+ value as exc_value: object
+ traceback as exc_tb: object
+ /
+
+Called when the connection is used as a context manager.
+
+If there was any exception, a rollback takes place; otherwise we commit.
+[clinic start generated code]*/
+
static PyObject *
-pysqlite_connection_exit(pysqlite_Connection* self, PyObject* args)
+pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
+ PyObject *exc_value, PyObject *exc_tb)
+/*[clinic end generated code: output=0705200e9321202a input=bd66f1532c9c54a7]*/
{
- PyObject* exc_type, *exc_value, *exc_tb;
const char* method_name;
PyObject* result;
- if (!PyArg_ParseTuple(args, "OOO", &exc_type, &exc_value, &exc_tb)) {
- return NULL;
- }
-
if (exc_type == Py_None && exc_value == Py_None && exc_tb == Py_None) {
method_name = "commit";
} else {
@@ -1773,48 +1870,31 @@ static PyGetSetDef connection_getset[] = {
};
static PyMethodDef connection_methods[] = {
- {"cursor", (PyCFunction)(void(*)(void))pysqlite_connection_cursor, METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("Return a cursor for the connection.")},
- {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS,
- PyDoc_STR("Closes the connection.")},
+ PYSQLITE_CONNECTION_CLOSE_METHODDEF
+ PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF
+ PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF
+ PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF
+ PYSQLITE_CONNECTION_CURSOR_METHODDEF
+ PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
+ PYSQLITE_CONNECTION_ENTER_METHODDEF
+ PYSQLITE_CONNECTION_EXIT_METHODDEF
+ PYSQLITE_CONNECTION_INTERRUPT_METHODDEF
+ PYSQLITE_CONNECTION_ITERDUMP_METHODDEF
+ PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
+ PYSQLITE_CONNECTION_ROLLBACK_METHODDEF
+ PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF
+ PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF
+ PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF
{"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS,
PyDoc_STR("Commit the current transaction.")},
- {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS,
- PyDoc_STR("Roll back the current transaction.")},
- {"create_function", (PyCFunction)(void(*)(void))pysqlite_connection_create_function, METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("Creates a new function. Non-standard.")},
- {"create_aggregate", (PyCFunction)(void(*)(void))pysqlite_connection_create_aggregate, METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("Creates a new aggregate. Non-standard.")},
- {"set_authorizer", (PyCFunction)(void(*)(void))pysqlite_connection_set_authorizer, METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("Sets authorizer callback. Non-standard.")},
- #ifndef SQLITE_OMIT_LOAD_EXTENSION
- {"enable_load_extension", (PyCFunction)pysqlite_enable_load_extension, METH_VARARGS,
- PyDoc_STR("Enable dynamic loading of SQLite extension modules. Non-standard.")},
- {"load_extension", (PyCFunction)pysqlite_load_extension, METH_VARARGS,
- PyDoc_STR("Load SQLite extension module. Non-standard.")},
- #endif
- {"set_progress_handler", (PyCFunction)(void(*)(void))pysqlite_connection_set_progress_handler, METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("Sets progress handler callback. Non-standard.")},
- {"set_trace_callback", (PyCFunction)(void(*)(void))pysqlite_connection_set_trace_callback, METH_VARARGS|METH_KEYWORDS,
- PyDoc_STR("Sets a trace callback called for each SQL statement (passed as unicode). Non-standard.")},
{"execute", (PyCFunction)pysqlite_connection_execute, METH_VARARGS,
PyDoc_STR("Executes a SQL statement. Non-standard.")},
{"executemany", (PyCFunction)pysqlite_connection_executemany, METH_VARARGS,
PyDoc_STR("Repeatedly executes a SQL statement. Non-standard.")},
{"executescript", (PyCFunction)pysqlite_connection_executescript, METH_VARARGS,
PyDoc_STR("Executes a multiple SQL statements at once. Non-standard.")},
- {"create_collation", (PyCFunction)pysqlite_connection_create_collation, METH_VARARGS,
- PyDoc_STR("Creates a collation function. Non-standard.")},
- {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS,
- PyDoc_STR("Abort any pending database operation. Non-standard.")},
- {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS,
- PyDoc_STR("Returns iterator to the dump of the database in an SQL text format. Non-standard.")},
{"backup", (PyCFunction)(void(*)(void))pysqlite_connection_backup, METH_VARARGS | METH_KEYWORDS,
PyDoc_STR("Makes a backup of the database. Non-standard.")},
- {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS,
- PyDoc_STR("For context manager. Non-standard.")},
- {"__exit__", (PyCFunction)pysqlite_connection_exit, METH_VARARGS,
- PyDoc_STR("For context manager. Non-standard.")},
{NULL, NULL}
};
diff --git a/Modules/_sqlite/connection.h b/Modules/_sqlite/connection.h
index aadf439..341ef01 100644
--- a/Modules/_sqlite/connection.h
+++ b/Modules/_sqlite/connection.h
@@ -110,11 +110,8 @@ extern PyTypeObject *pysqlite_ConnectionType;
PyObject* pysqlite_connection_alloc(PyTypeObject* type, int aware);
void pysqlite_connection_dealloc(pysqlite_Connection* self);
-PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);
-PyObject* pysqlite_connection_close(pysqlite_Connection* self, PyObject* args);
PyObject* _pysqlite_connection_begin(pysqlite_Connection* self);
PyObject* pysqlite_connection_commit(pysqlite_Connection* self, PyObject* args);
-PyObject* pysqlite_connection_rollback(pysqlite_Connection* self, PyObject* args);
PyObject* pysqlite_connection_new(PyTypeObject* type, PyObject* args, PyObject* kw);
int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject* kwargs);