Skip to content

Commit 3ccef1c

Browse files
author
Erlend Egeberg Aasland
authored
bpo-40956: Convert _sqlite3.Connection to Argument Clinic, part 2 (GH-23838)
1 parent b02ad24 commit 3ccef1c

File tree

4 files changed

+297
-77
lines changed

4 files changed

+297
-77
lines changed

Modules/_sqlite/clinic/connection.c.h

+209-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored
5757
return pysqlite_connection_close_impl(self);
5858
}
5959

60+
PyDoc_STRVAR(pysqlite_connection_commit__doc__,
61+
"commit($self, /)\n"
62+
"--\n"
63+
"\n"
64+
"Commit the current transaction.");
65+
66+
#define PYSQLITE_CONNECTION_COMMIT_METHODDEF \
67+
{"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, pysqlite_connection_commit__doc__},
68+
69+
static PyObject *
70+
pysqlite_connection_commit_impl(pysqlite_Connection *self);
71+
72+
static PyObject *
73+
pysqlite_connection_commit(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
74+
{
75+
return pysqlite_connection_commit_impl(self);
76+
}
77+
6078
PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
6179
"rollback($self, /)\n"
6280
"--\n"
@@ -373,6 +391,95 @@ pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *arg)
373391

374392
#endif /* !defined(SQLITE_OMIT_LOAD_EXTENSION) */
375393

394+
PyDoc_STRVAR(pysqlite_connection_execute__doc__,
395+
"execute($self, sql, parameters=<unrepresentable>, /)\n"
396+
"--\n"
397+
"\n"
398+
"Executes a SQL statement. Non-standard.");
399+
400+
#define PYSQLITE_CONNECTION_EXECUTE_METHODDEF \
401+
{"execute", (PyCFunction)(void(*)(void))pysqlite_connection_execute, METH_FASTCALL, pysqlite_connection_execute__doc__},
402+
403+
static PyObject *
404+
pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
405+
PyObject *parameters);
406+
407+
static PyObject *
408+
pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
409+
{
410+
PyObject *return_value = NULL;
411+
PyObject *sql;
412+
PyObject *parameters = NULL;
413+
414+
if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
415+
goto exit;
416+
}
417+
if (!PyUnicode_Check(args[0])) {
418+
_PyArg_BadArgument("execute", "argument 1", "str", args[0]);
419+
goto exit;
420+
}
421+
if (PyUnicode_READY(args[0]) == -1) {
422+
goto exit;
423+
}
424+
sql = args[0];
425+
if (nargs < 2) {
426+
goto skip_optional;
427+
}
428+
parameters = args[1];
429+
skip_optional:
430+
return_value = pysqlite_connection_execute_impl(self, sql, parameters);
431+
432+
exit:
433+
return return_value;
434+
}
435+
436+
PyDoc_STRVAR(pysqlite_connection_executemany__doc__,
437+
"executemany($self, sql, parameters, /)\n"
438+
"--\n"
439+
"\n"
440+
"Repeatedly executes a SQL statement. Non-standard.");
441+
442+
#define PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF \
443+
{"executemany", (PyCFunction)(void(*)(void))pysqlite_connection_executemany, METH_FASTCALL, pysqlite_connection_executemany__doc__},
444+
445+
static PyObject *
446+
pysqlite_connection_executemany_impl(pysqlite_Connection *self,
447+
PyObject *sql, PyObject *parameters);
448+
449+
static PyObject *
450+
pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
451+
{
452+
PyObject *return_value = NULL;
453+
PyObject *sql;
454+
PyObject *parameters;
455+
456+
if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
457+
goto exit;
458+
}
459+
if (!PyUnicode_Check(args[0])) {
460+
_PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
461+
goto exit;
462+
}
463+
if (PyUnicode_READY(args[0]) == -1) {
464+
goto exit;
465+
}
466+
sql = args[0];
467+
parameters = args[1];
468+
return_value = pysqlite_connection_executemany_impl(self, sql, parameters);
469+
470+
exit:
471+
return return_value;
472+
}
473+
474+
PyDoc_STRVAR(pysqlite_connection_executescript__doc__,
475+
"executescript($self, sql_script, /)\n"
476+
"--\n"
477+
"\n"
478+
"Executes a multiple SQL statements at once. Non-standard.");
479+
480+
#define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF \
481+
{"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__},
482+
376483
PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
377484
"interrupt($self, /)\n"
378485
"--\n"
@@ -411,6 +518,107 @@ pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *Py_UNUSED(igno
411518
return pysqlite_connection_iterdump_impl(self);
412519
}
413520

521+
PyDoc_STRVAR(pysqlite_connection_backup__doc__,
522+
"backup($self, /, target=<unrepresentable>, *, pages=-1, progress=None,\n"
523+
" name=\'main\', sleep=0.25)\n"
524+
"--\n"
525+
"\n"
526+
"Makes a backup of the database. Non-standard.");
527+
528+
#define PYSQLITE_CONNECTION_BACKUP_METHODDEF \
529+
{"backup", (PyCFunction)(void(*)(void))pysqlite_connection_backup, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_backup__doc__},
530+
531+
static PyObject *
532+
pysqlite_connection_backup_impl(pysqlite_Connection *self,
533+
pysqlite_Connection *target, int pages,
534+
PyObject *progress, const char *name,
535+
double sleep);
536+
537+
static PyObject *
538+
pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
539+
{
540+
PyObject *return_value = NULL;
541+
static const char * const _keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
542+
static _PyArg_Parser _parser = {NULL, _keywords, "backup", 0};
543+
PyObject *argsbuf[5];
544+
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
545+
pysqlite_Connection *target = NULL;
546+
int pages = -1;
547+
PyObject *progress = Py_None;
548+
const char *name = "main";
549+
double sleep = 0.25;
550+
551+
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
552+
if (!args) {
553+
goto exit;
554+
}
555+
if (!noptargs) {
556+
goto skip_optional_pos;
557+
}
558+
if (args[0]) {
559+
if (!PyObject_TypeCheck(args[0], pysqlite_ConnectionType)) {
560+
_PyArg_BadArgument("backup", "argument 'target'", (pysqlite_ConnectionType)->tp_name, args[0]);
561+
goto exit;
562+
}
563+
target = (pysqlite_Connection *)args[0];
564+
if (!--noptargs) {
565+
goto skip_optional_pos;
566+
}
567+
}
568+
skip_optional_pos:
569+
if (!noptargs) {
570+
goto skip_optional_kwonly;
571+
}
572+
if (args[1]) {
573+
pages = _PyLong_AsInt(args[1]);
574+
if (pages == -1 && PyErr_Occurred()) {
575+
goto exit;
576+
}
577+
if (!--noptargs) {
578+
goto skip_optional_kwonly;
579+
}
580+
}
581+
if (args[2]) {
582+
progress = args[2];
583+
if (!--noptargs) {
584+
goto skip_optional_kwonly;
585+
}
586+
}
587+
if (args[3]) {
588+
if (!PyUnicode_Check(args[3])) {
589+
_PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
590+
goto exit;
591+
}
592+
Py_ssize_t name_length;
593+
name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
594+
if (name == NULL) {
595+
goto exit;
596+
}
597+
if (strlen(name) != (size_t)name_length) {
598+
PyErr_SetString(PyExc_ValueError, "embedded null character");
599+
goto exit;
600+
}
601+
if (!--noptargs) {
602+
goto skip_optional_kwonly;
603+
}
604+
}
605+
if (PyFloat_CheckExact(args[4])) {
606+
sleep = PyFloat_AS_DOUBLE(args[4]);
607+
}
608+
else
609+
{
610+
sleep = PyFloat_AsDouble(args[4]);
611+
if (sleep == -1.0 && PyErr_Occurred()) {
612+
goto exit;
613+
}
614+
}
615+
skip_optional_kwonly:
616+
return_value = pysqlite_connection_backup_impl(self, target, pages, progress, name, sleep);
617+
618+
exit:
619+
return return_value;
620+
}
621+
414622
PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
415623
"create_collation($self, name, callback, /)\n"
416624
"--\n"
@@ -511,4 +719,4 @@ pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ss
511719
#ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
512720
#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
513721
#endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
514-
/*[clinic end generated code: output=eb14a52e4c682f3b input=a9049054013a1b77]*/
722+
/*[clinic end generated code: output=7cb13d491a5970aa input=a9049054013a1b77]*/

0 commit comments

Comments
 (0)