• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 #  include "pycore_gc.h"          // PyGC_Head
7 #  include "pycore_runtime.h"     // _Py_ID()
8 #endif
9 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
10 
11 static int
12 pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
13                               double timeout, int detect_types,
14                               const char *isolation_level,
15                               int check_same_thread, PyObject *factory,
16                               int cache_size, int uri,
17                               enum autocommit_mode autocommit);
18 
19 // Emit compiler warnings when we get to Python 3.15.
20 #if PY_VERSION_HEX >= 0x030f00C0
21 #  error "Update the clinic input of '_sqlite3.Connection.__init__'."
22 #elif PY_VERSION_HEX >= 0x030f00A0
23 #  ifdef _MSC_VER
24 #    pragma message ("Update the clinic input of '_sqlite3.Connection.__init__'.")
25 #  else
26 #    warning "Update the clinic input of '_sqlite3.Connection.__init__'."
27 #  endif
28 #endif
29 
30 static int
pysqlite_connection_init(PyObject * self,PyObject * args,PyObject * kwargs)31 pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
32 {
33     int return_value = -1;
34     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
35 
36     #define NUM_KEYWORDS 9
37     static struct {
38         PyGC_Head _this_is_not_used;
39         PyObject_VAR_HEAD
40         PyObject *ob_item[NUM_KEYWORDS];
41     } _kwtuple = {
42         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
43         .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), },
44     };
45     #undef NUM_KEYWORDS
46     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
47 
48     #else  // !Py_BUILD_CORE
49     #  define KWTUPLE NULL
50     #endif  // !Py_BUILD_CORE
51 
52     static const char * const _keywords[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", "uri", "autocommit", NULL};
53     static _PyArg_Parser _parser = {
54         .keywords = _keywords,
55         .fname = "Connection",
56         .kwtuple = KWTUPLE,
57     };
58     #undef KWTUPLE
59     PyObject *argsbuf[9];
60     PyObject * const *fastargs;
61     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
62     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
63     PyObject *database;
64     double timeout = 5.0;
65     int detect_types = 0;
66     const char *isolation_level = "";
67     int check_same_thread = 1;
68     PyObject *factory = (PyObject*)clinic_state()->ConnectionType;
69     int cache_size = 128;
70     int uri = 0;
71     enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
72 
73     if (nargs > 1 && nargs <= 8) {
74         if (PyErr_WarnEx(PyExc_DeprecationWarning,
75                 "Passing more than 1 positional argument to _sqlite3.Connection()"
76                 " is deprecated. Parameters 'timeout', 'detect_types', "
77                 "'isolation_level', 'check_same_thread', 'factory', "
78                 "'cached_statements' and 'uri' will become keyword-only "
79                 "parameters in Python 3.15.", 1))
80         {
81             goto exit;
82         }
83     }
84     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
85     if (!fastargs) {
86         goto exit;
87     }
88     database = fastargs[0];
89     if (!noptargs) {
90         goto skip_optional_pos;
91     }
92     if (fastargs[1]) {
93         if (PyFloat_CheckExact(fastargs[1])) {
94             timeout = PyFloat_AS_DOUBLE(fastargs[1]);
95         }
96         else
97         {
98             timeout = PyFloat_AsDouble(fastargs[1]);
99             if (timeout == -1.0 && PyErr_Occurred()) {
100                 goto exit;
101             }
102         }
103         if (!--noptargs) {
104             goto skip_optional_pos;
105         }
106     }
107     if (fastargs[2]) {
108         detect_types = PyLong_AsInt(fastargs[2]);
109         if (detect_types == -1 && PyErr_Occurred()) {
110             goto exit;
111         }
112         if (!--noptargs) {
113             goto skip_optional_pos;
114         }
115     }
116     if (fastargs[3]) {
117         if (!isolation_level_converter(fastargs[3], &isolation_level)) {
118             goto exit;
119         }
120         if (!--noptargs) {
121             goto skip_optional_pos;
122         }
123     }
124     if (fastargs[4]) {
125         check_same_thread = PyObject_IsTrue(fastargs[4]);
126         if (check_same_thread < 0) {
127             goto exit;
128         }
129         if (!--noptargs) {
130             goto skip_optional_pos;
131         }
132     }
133     if (fastargs[5]) {
134         factory = fastargs[5];
135         if (!--noptargs) {
136             goto skip_optional_pos;
137         }
138     }
139     if (fastargs[6]) {
140         cache_size = PyLong_AsInt(fastargs[6]);
141         if (cache_size == -1 && PyErr_Occurred()) {
142             goto exit;
143         }
144         if (!--noptargs) {
145             goto skip_optional_pos;
146         }
147     }
148     if (fastargs[7]) {
149         uri = PyObject_IsTrue(fastargs[7]);
150         if (uri < 0) {
151             goto exit;
152         }
153         if (!--noptargs) {
154             goto skip_optional_pos;
155         }
156     }
157 skip_optional_pos:
158     if (!noptargs) {
159         goto skip_optional_kwonly;
160     }
161     if (!autocommit_converter(fastargs[8], &autocommit)) {
162         goto exit;
163     }
164 skip_optional_kwonly:
165     return_value = pysqlite_connection_init_impl((pysqlite_Connection *)self, database, timeout, detect_types, isolation_level, check_same_thread, factory, cache_size, uri, autocommit);
166 
167 exit:
168     return return_value;
169 }
170 
171 PyDoc_STRVAR(pysqlite_connection_cursor__doc__,
172 "cursor($self, /, factory=<unrepresentable>)\n"
173 "--\n"
174 "\n"
175 "Return a cursor for the connection.");
176 
177 #define PYSQLITE_CONNECTION_CURSOR_METHODDEF    \
178     {"cursor", _PyCFunction_CAST(pysqlite_connection_cursor), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_cursor__doc__},
179 
180 static PyObject *
181 pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory);
182 
183 static PyObject *
pysqlite_connection_cursor(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)184 pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
185 {
186     PyObject *return_value = NULL;
187     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
188 
189     #define NUM_KEYWORDS 1
190     static struct {
191         PyGC_Head _this_is_not_used;
192         PyObject_VAR_HEAD
193         PyObject *ob_item[NUM_KEYWORDS];
194     } _kwtuple = {
195         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
196         .ob_item = { &_Py_ID(factory), },
197     };
198     #undef NUM_KEYWORDS
199     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
200 
201     #else  // !Py_BUILD_CORE
202     #  define KWTUPLE NULL
203     #endif  // !Py_BUILD_CORE
204 
205     static const char * const _keywords[] = {"factory", NULL};
206     static _PyArg_Parser _parser = {
207         .keywords = _keywords,
208         .fname = "cursor",
209         .kwtuple = KWTUPLE,
210     };
211     #undef KWTUPLE
212     PyObject *argsbuf[1];
213     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
214     PyObject *factory = NULL;
215 
216     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
217     if (!args) {
218         goto exit;
219     }
220     if (!noptargs) {
221         goto skip_optional_pos;
222     }
223     factory = args[0];
224 skip_optional_pos:
225     return_value = pysqlite_connection_cursor_impl(self, factory);
226 
227 exit:
228     return return_value;
229 }
230 
231 PyDoc_STRVAR(blobopen__doc__,
232 "blobopen($self, table, column, row, /, *, readonly=False, name=\'main\')\n"
233 "--\n"
234 "\n"
235 "Open and return a BLOB object.\n"
236 "\n"
237 "  table\n"
238 "    Table name.\n"
239 "  column\n"
240 "    Column name.\n"
241 "  row\n"
242 "    Row index.\n"
243 "  readonly\n"
244 "    Open the BLOB without write permissions.\n"
245 "  name\n"
246 "    Database name.");
247 
248 #define BLOBOPEN_METHODDEF    \
249     {"blobopen", _PyCFunction_CAST(blobopen), METH_FASTCALL|METH_KEYWORDS, blobopen__doc__},
250 
251 static PyObject *
252 blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
253               sqlite3_int64 row, int readonly, const char *name);
254 
255 static PyObject *
blobopen(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)256 blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
257 {
258     PyObject *return_value = NULL;
259     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
260 
261     #define NUM_KEYWORDS 2
262     static struct {
263         PyGC_Head _this_is_not_used;
264         PyObject_VAR_HEAD
265         PyObject *ob_item[NUM_KEYWORDS];
266     } _kwtuple = {
267         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
268         .ob_item = { &_Py_ID(readonly), &_Py_ID(name), },
269     };
270     #undef NUM_KEYWORDS
271     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
272 
273     #else  // !Py_BUILD_CORE
274     #  define KWTUPLE NULL
275     #endif  // !Py_BUILD_CORE
276 
277     static const char * const _keywords[] = {"", "", "", "readonly", "name", NULL};
278     static _PyArg_Parser _parser = {
279         .keywords = _keywords,
280         .fname = "blobopen",
281         .kwtuple = KWTUPLE,
282     };
283     #undef KWTUPLE
284     PyObject *argsbuf[5];
285     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
286     const char *table;
287     const char *col;
288     sqlite3_int64 row;
289     int readonly = 0;
290     const char *name = "main";
291 
292     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
293     if (!args) {
294         goto exit;
295     }
296     if (!PyUnicode_Check(args[0])) {
297         _PyArg_BadArgument("blobopen", "argument 1", "str", args[0]);
298         goto exit;
299     }
300     Py_ssize_t table_length;
301     table = PyUnicode_AsUTF8AndSize(args[0], &table_length);
302     if (table == NULL) {
303         goto exit;
304     }
305     if (strlen(table) != (size_t)table_length) {
306         PyErr_SetString(PyExc_ValueError, "embedded null character");
307         goto exit;
308     }
309     if (!PyUnicode_Check(args[1])) {
310         _PyArg_BadArgument("blobopen", "argument 2", "str", args[1]);
311         goto exit;
312     }
313     Py_ssize_t col_length;
314     col = PyUnicode_AsUTF8AndSize(args[1], &col_length);
315     if (col == NULL) {
316         goto exit;
317     }
318     if (strlen(col) != (size_t)col_length) {
319         PyErr_SetString(PyExc_ValueError, "embedded null character");
320         goto exit;
321     }
322     if (!sqlite3_int64_converter(args[2], &row)) {
323         goto exit;
324     }
325     if (!noptargs) {
326         goto skip_optional_kwonly;
327     }
328     if (args[3]) {
329         readonly = PyObject_IsTrue(args[3]);
330         if (readonly < 0) {
331             goto exit;
332         }
333         if (!--noptargs) {
334             goto skip_optional_kwonly;
335         }
336     }
337     if (!PyUnicode_Check(args[4])) {
338         _PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]);
339         goto exit;
340     }
341     Py_ssize_t name_length;
342     name = PyUnicode_AsUTF8AndSize(args[4], &name_length);
343     if (name == NULL) {
344         goto exit;
345     }
346     if (strlen(name) != (size_t)name_length) {
347         PyErr_SetString(PyExc_ValueError, "embedded null character");
348         goto exit;
349     }
350 skip_optional_kwonly:
351     return_value = blobopen_impl(self, table, col, row, readonly, name);
352 
353 exit:
354     return return_value;
355 }
356 
357 PyDoc_STRVAR(pysqlite_connection_close__doc__,
358 "close($self, /)\n"
359 "--\n"
360 "\n"
361 "Close the database connection.\n"
362 "\n"
363 "Any pending transaction is not committed implicitly.");
364 
365 #define PYSQLITE_CONNECTION_CLOSE_METHODDEF    \
366     {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS, pysqlite_connection_close__doc__},
367 
368 static PyObject *
369 pysqlite_connection_close_impl(pysqlite_Connection *self);
370 
371 static PyObject *
pysqlite_connection_close(pysqlite_Connection * self,PyObject * Py_UNUSED (ignored))372 pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
373 {
374     return pysqlite_connection_close_impl(self);
375 }
376 
377 PyDoc_STRVAR(pysqlite_connection_commit__doc__,
378 "commit($self, /)\n"
379 "--\n"
380 "\n"
381 "Commit any pending transaction to the database.\n"
382 "\n"
383 "If there is no open transaction, this method is a no-op.");
384 
385 #define PYSQLITE_CONNECTION_COMMIT_METHODDEF    \
386     {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, pysqlite_connection_commit__doc__},
387 
388 static PyObject *
389 pysqlite_connection_commit_impl(pysqlite_Connection *self);
390 
391 static PyObject *
pysqlite_connection_commit(pysqlite_Connection * self,PyObject * Py_UNUSED (ignored))392 pysqlite_connection_commit(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
393 {
394     return pysqlite_connection_commit_impl(self);
395 }
396 
397 PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
398 "rollback($self, /)\n"
399 "--\n"
400 "\n"
401 "Roll back to the start of any pending transaction.\n"
402 "\n"
403 "If there is no open transaction, this method is a no-op.");
404 
405 #define PYSQLITE_CONNECTION_ROLLBACK_METHODDEF    \
406     {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS, pysqlite_connection_rollback__doc__},
407 
408 static PyObject *
409 pysqlite_connection_rollback_impl(pysqlite_Connection *self);
410 
411 static PyObject *
pysqlite_connection_rollback(pysqlite_Connection * self,PyObject * Py_UNUSED (ignored))412 pysqlite_connection_rollback(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
413 {
414     return pysqlite_connection_rollback_impl(self);
415 }
416 
417 PyDoc_STRVAR(pysqlite_connection_create_function__doc__,
418 "create_function($self, /, name, narg, func, *, deterministic=False)\n"
419 "--\n"
420 "\n"
421 "Creates a new function.\n"
422 "\n"
423 "Note: Passing keyword arguments \'name\', \'narg\' and \'func\' to\n"
424 "_sqlite3.Connection.create_function() is deprecated. Parameters\n"
425 "\'name\', \'narg\' and \'func\' will become positional-only in Python 3.15.\n"
426 "");
427 
428 #define PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF    \
429     {"create_function", _PyCFunction_CAST(pysqlite_connection_create_function), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_function__doc__},
430 
431 static PyObject *
432 pysqlite_connection_create_function_impl(pysqlite_Connection *self,
433                                          PyTypeObject *cls, const char *name,
434                                          int narg, PyObject *func,
435                                          int deterministic);
436 
437 // Emit compiler warnings when we get to Python 3.15.
438 #if PY_VERSION_HEX >= 0x030f00C0
439 #  error "Update the clinic input of '_sqlite3.Connection.create_function'."
440 #elif PY_VERSION_HEX >= 0x030f00A0
441 #  ifdef _MSC_VER
442 #    pragma message ("Update the clinic input of '_sqlite3.Connection.create_function'.")
443 #  else
444 #    warning "Update the clinic input of '_sqlite3.Connection.create_function'."
445 #  endif
446 #endif
447 
448 static PyObject *
pysqlite_connection_create_function(pysqlite_Connection * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)449 pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
450 {
451     PyObject *return_value = NULL;
452     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
453 
454     #define NUM_KEYWORDS 4
455     static struct {
456         PyGC_Head _this_is_not_used;
457         PyObject_VAR_HEAD
458         PyObject *ob_item[NUM_KEYWORDS];
459     } _kwtuple = {
460         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
461         .ob_item = { &_Py_ID(name), &_Py_ID(narg), &_Py_ID(func), &_Py_ID(deterministic), },
462     };
463     #undef NUM_KEYWORDS
464     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
465 
466     #else  // !Py_BUILD_CORE
467     #  define KWTUPLE NULL
468     #endif  // !Py_BUILD_CORE
469 
470     static const char * const _keywords[] = {"name", "narg", "func", "deterministic", NULL};
471     static _PyArg_Parser _parser = {
472         .keywords = _keywords,
473         .fname = "create_function",
474         .kwtuple = KWTUPLE,
475     };
476     #undef KWTUPLE
477     PyObject *argsbuf[4];
478     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
479     const char *name;
480     int narg;
481     PyObject *func;
482     int deterministic = 0;
483 
484     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
485     if (!args) {
486         goto exit;
487     }
488     if (nargs < 3) {
489         if (PyErr_WarnEx(PyExc_DeprecationWarning,
490                 "Passing keyword arguments 'name', 'narg' and 'func' to "
491                 "_sqlite3.Connection.create_function() is deprecated. Parameters "
492                 "'name', 'narg' and 'func' will become positional-only in Python "
493                 "3.15.", 1))
494         {
495             goto exit;
496         }
497     }
498     if (!PyUnicode_Check(args[0])) {
499         _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
500         goto exit;
501     }
502     Py_ssize_t name_length;
503     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
504     if (name == NULL) {
505         goto exit;
506     }
507     if (strlen(name) != (size_t)name_length) {
508         PyErr_SetString(PyExc_ValueError, "embedded null character");
509         goto exit;
510     }
511     narg = PyLong_AsInt(args[1]);
512     if (narg == -1 && PyErr_Occurred()) {
513         goto exit;
514     }
515     func = args[2];
516     if (!noptargs) {
517         goto skip_optional_kwonly;
518     }
519     deterministic = PyObject_IsTrue(args[3]);
520     if (deterministic < 0) {
521         goto exit;
522     }
523 skip_optional_kwonly:
524     return_value = pysqlite_connection_create_function_impl(self, cls, name, narg, func, deterministic);
525 
526 exit:
527     return return_value;
528 }
529 
530 #if defined(HAVE_WINDOW_FUNCTIONS)
531 
532 PyDoc_STRVAR(create_window_function__doc__,
533 "create_window_function($self, name, num_params, aggregate_class, /)\n"
534 "--\n"
535 "\n"
536 "Creates or redefines an aggregate window function. Non-standard.\n"
537 "\n"
538 "  name\n"
539 "    The name of the SQL aggregate window function to be created or\n"
540 "    redefined.\n"
541 "  num_params\n"
542 "    The number of arguments the step and inverse methods takes.\n"
543 "  aggregate_class\n"
544 "    A class with step(), finalize(), value(), and inverse() methods.\n"
545 "    Set to None to clear the window function.");
546 
547 #define CREATE_WINDOW_FUNCTION_METHODDEF    \
548     {"create_window_function", _PyCFunction_CAST(create_window_function), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, create_window_function__doc__},
549 
550 static PyObject *
551 create_window_function_impl(pysqlite_Connection *self, PyTypeObject *cls,
552                             const char *name, int num_params,
553                             PyObject *aggregate_class);
554 
555 static PyObject *
create_window_function(pysqlite_Connection * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)556 create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
557 {
558     PyObject *return_value = NULL;
559     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
560     #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
561     #else
562     #  define KWTUPLE NULL
563     #endif
564 
565     static const char * const _keywords[] = {"", "", "", NULL};
566     static _PyArg_Parser _parser = {
567         .keywords = _keywords,
568         .fname = "create_window_function",
569         .kwtuple = KWTUPLE,
570     };
571     #undef KWTUPLE
572     PyObject *argsbuf[3];
573     const char *name;
574     int num_params;
575     PyObject *aggregate_class;
576 
577     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
578     if (!args) {
579         goto exit;
580     }
581     if (!PyUnicode_Check(args[0])) {
582         _PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]);
583         goto exit;
584     }
585     Py_ssize_t name_length;
586     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
587     if (name == NULL) {
588         goto exit;
589     }
590     if (strlen(name) != (size_t)name_length) {
591         PyErr_SetString(PyExc_ValueError, "embedded null character");
592         goto exit;
593     }
594     num_params = PyLong_AsInt(args[1]);
595     if (num_params == -1 && PyErr_Occurred()) {
596         goto exit;
597     }
598     aggregate_class = args[2];
599     return_value = create_window_function_impl(self, cls, name, num_params, aggregate_class);
600 
601 exit:
602     return return_value;
603 }
604 
605 #endif /* defined(HAVE_WINDOW_FUNCTIONS) */
606 
607 PyDoc_STRVAR(pysqlite_connection_create_aggregate__doc__,
608 "create_aggregate($self, /, name, n_arg, aggregate_class)\n"
609 "--\n"
610 "\n"
611 "Creates a new aggregate.\n"
612 "\n"
613 "Note: Passing keyword arguments \'name\', \'n_arg\' and \'aggregate_class\'\n"
614 "to _sqlite3.Connection.create_aggregate() is deprecated. Parameters\n"
615 "\'name\', \'n_arg\' and \'aggregate_class\' will become positional-only in\n"
616 "Python 3.15.\n"
617 "");
618 
619 #define PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF    \
620     {"create_aggregate", _PyCFunction_CAST(pysqlite_connection_create_aggregate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_aggregate__doc__},
621 
622 static PyObject *
623 pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
624                                           PyTypeObject *cls,
625                                           const char *name, int n_arg,
626                                           PyObject *aggregate_class);
627 
628 // Emit compiler warnings when we get to Python 3.15.
629 #if PY_VERSION_HEX >= 0x030f00C0
630 #  error "Update the clinic input of '_sqlite3.Connection.create_aggregate'."
631 #elif PY_VERSION_HEX >= 0x030f00A0
632 #  ifdef _MSC_VER
633 #    pragma message ("Update the clinic input of '_sqlite3.Connection.create_aggregate'.")
634 #  else
635 #    warning "Update the clinic input of '_sqlite3.Connection.create_aggregate'."
636 #  endif
637 #endif
638 
639 static PyObject *
pysqlite_connection_create_aggregate(pysqlite_Connection * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)640 pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
641 {
642     PyObject *return_value = NULL;
643     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
644 
645     #define NUM_KEYWORDS 3
646     static struct {
647         PyGC_Head _this_is_not_used;
648         PyObject_VAR_HEAD
649         PyObject *ob_item[NUM_KEYWORDS];
650     } _kwtuple = {
651         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
652         .ob_item = { &_Py_ID(name), &_Py_ID(n_arg), &_Py_ID(aggregate_class), },
653     };
654     #undef NUM_KEYWORDS
655     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
656 
657     #else  // !Py_BUILD_CORE
658     #  define KWTUPLE NULL
659     #endif  // !Py_BUILD_CORE
660 
661     static const char * const _keywords[] = {"name", "n_arg", "aggregate_class", NULL};
662     static _PyArg_Parser _parser = {
663         .keywords = _keywords,
664         .fname = "create_aggregate",
665         .kwtuple = KWTUPLE,
666     };
667     #undef KWTUPLE
668     PyObject *argsbuf[3];
669     const char *name;
670     int n_arg;
671     PyObject *aggregate_class;
672 
673     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
674     if (!args) {
675         goto exit;
676     }
677     if (nargs < 3) {
678         if (PyErr_WarnEx(PyExc_DeprecationWarning,
679                 "Passing keyword arguments 'name', 'n_arg' and 'aggregate_class' "
680                 "to _sqlite3.Connection.create_aggregate() is deprecated. "
681                 "Parameters 'name', 'n_arg' and 'aggregate_class' will become "
682                 "positional-only in Python 3.15.", 1))
683         {
684             goto exit;
685         }
686     }
687     if (!PyUnicode_Check(args[0])) {
688         _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
689         goto exit;
690     }
691     Py_ssize_t name_length;
692     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
693     if (name == NULL) {
694         goto exit;
695     }
696     if (strlen(name) != (size_t)name_length) {
697         PyErr_SetString(PyExc_ValueError, "embedded null character");
698         goto exit;
699     }
700     n_arg = PyLong_AsInt(args[1]);
701     if (n_arg == -1 && PyErr_Occurred()) {
702         goto exit;
703     }
704     aggregate_class = args[2];
705     return_value = pysqlite_connection_create_aggregate_impl(self, cls, name, n_arg, aggregate_class);
706 
707 exit:
708     return return_value;
709 }
710 
711 PyDoc_STRVAR(pysqlite_connection_set_authorizer__doc__,
712 "set_authorizer($self, /, authorizer_callback)\n"
713 "--\n"
714 "\n"
715 "Set authorizer callback.\n"
716 "\n"
717 "Note: Passing keyword argument \'authorizer_callback\' to\n"
718 "_sqlite3.Connection.set_authorizer() is deprecated. Parameter\n"
719 "\'authorizer_callback\' will become positional-only in Python 3.15.\n"
720 "");
721 
722 #define PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF    \
723     {"set_authorizer", _PyCFunction_CAST(pysqlite_connection_set_authorizer), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_authorizer__doc__},
724 
725 static PyObject *
726 pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
727                                         PyTypeObject *cls,
728                                         PyObject *callable);
729 
730 // Emit compiler warnings when we get to Python 3.15.
731 #if PY_VERSION_HEX >= 0x030f00C0
732 #  error "Update the clinic input of '_sqlite3.Connection.set_authorizer'."
733 #elif PY_VERSION_HEX >= 0x030f00A0
734 #  ifdef _MSC_VER
735 #    pragma message ("Update the clinic input of '_sqlite3.Connection.set_authorizer'.")
736 #  else
737 #    warning "Update the clinic input of '_sqlite3.Connection.set_authorizer'."
738 #  endif
739 #endif
740 
741 static PyObject *
pysqlite_connection_set_authorizer(pysqlite_Connection * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)742 pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
743 {
744     PyObject *return_value = NULL;
745     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
746 
747     #define NUM_KEYWORDS 1
748     static struct {
749         PyGC_Head _this_is_not_used;
750         PyObject_VAR_HEAD
751         PyObject *ob_item[NUM_KEYWORDS];
752     } _kwtuple = {
753         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
754         .ob_item = { &_Py_ID(authorizer_callback), },
755     };
756     #undef NUM_KEYWORDS
757     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
758 
759     #else  // !Py_BUILD_CORE
760     #  define KWTUPLE NULL
761     #endif  // !Py_BUILD_CORE
762 
763     static const char * const _keywords[] = {"authorizer_callback", NULL};
764     static _PyArg_Parser _parser = {
765         .keywords = _keywords,
766         .fname = "set_authorizer",
767         .kwtuple = KWTUPLE,
768     };
769     #undef KWTUPLE
770     PyObject *argsbuf[1];
771     PyObject *callable;
772 
773     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
774     if (!args) {
775         goto exit;
776     }
777     if (nargs < 1) {
778         if (PyErr_WarnEx(PyExc_DeprecationWarning,
779                 "Passing keyword argument 'authorizer_callback' to "
780                 "_sqlite3.Connection.set_authorizer() is deprecated. Parameter "
781                 "'authorizer_callback' will become positional-only in Python "
782                 "3.15.", 1))
783         {
784             goto exit;
785         }
786     }
787     callable = args[0];
788     return_value = pysqlite_connection_set_authorizer_impl(self, cls, callable);
789 
790 exit:
791     return return_value;
792 }
793 
794 PyDoc_STRVAR(pysqlite_connection_set_progress_handler__doc__,
795 "set_progress_handler($self, /, progress_handler, n)\n"
796 "--\n"
797 "\n"
798 "Set progress handler callback.\n"
799 "\n"
800 "  progress_handler\n"
801 "    A callable that takes no arguments.\n"
802 "    If the callable returns non-zero, the current query is terminated,\n"
803 "    and an exception is raised.\n"
804 "  n\n"
805 "    The number of SQLite virtual machine instructions that are\n"
806 "    executed between invocations of \'progress_handler\'.\n"
807 "\n"
808 "If \'progress_handler\' is None or \'n\' is 0, the progress handler is disabled.\n"
809 "\n"
810 "Note: Passing keyword argument \'progress_handler\' to\n"
811 "_sqlite3.Connection.set_progress_handler() is deprecated. Parameter\n"
812 "\'progress_handler\' will become positional-only in Python 3.15.\n"
813 "");
814 
815 #define PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF    \
816     {"set_progress_handler", _PyCFunction_CAST(pysqlite_connection_set_progress_handler), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_progress_handler__doc__},
817 
818 static PyObject *
819 pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
820                                               PyTypeObject *cls,
821                                               PyObject *callable, int n);
822 
823 // Emit compiler warnings when we get to Python 3.15.
824 #if PY_VERSION_HEX >= 0x030f00C0
825 #  error "Update the clinic input of '_sqlite3.Connection.set_progress_handler'."
826 #elif PY_VERSION_HEX >= 0x030f00A0
827 #  ifdef _MSC_VER
828 #    pragma message ("Update the clinic input of '_sqlite3.Connection.set_progress_handler'.")
829 #  else
830 #    warning "Update the clinic input of '_sqlite3.Connection.set_progress_handler'."
831 #  endif
832 #endif
833 
834 static PyObject *
pysqlite_connection_set_progress_handler(pysqlite_Connection * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)835 pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
836 {
837     PyObject *return_value = NULL;
838     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
839 
840     #define NUM_KEYWORDS 2
841     static struct {
842         PyGC_Head _this_is_not_used;
843         PyObject_VAR_HEAD
844         PyObject *ob_item[NUM_KEYWORDS];
845     } _kwtuple = {
846         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
847         .ob_item = { &_Py_ID(progress_handler), _Py_LATIN1_CHR('n'), },
848     };
849     #undef NUM_KEYWORDS
850     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
851 
852     #else  // !Py_BUILD_CORE
853     #  define KWTUPLE NULL
854     #endif  // !Py_BUILD_CORE
855 
856     static const char * const _keywords[] = {"progress_handler", "n", NULL};
857     static _PyArg_Parser _parser = {
858         .keywords = _keywords,
859         .fname = "set_progress_handler",
860         .kwtuple = KWTUPLE,
861     };
862     #undef KWTUPLE
863     PyObject *argsbuf[2];
864     PyObject *callable;
865     int n;
866 
867     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
868     if (!args) {
869         goto exit;
870     }
871     if (nargs < 1) {
872         if (PyErr_WarnEx(PyExc_DeprecationWarning,
873                 "Passing keyword argument 'progress_handler' to "
874                 "_sqlite3.Connection.set_progress_handler() is deprecated. "
875                 "Parameter 'progress_handler' will become positional-only in "
876                 "Python 3.15.", 1))
877         {
878             goto exit;
879         }
880     }
881     callable = args[0];
882     n = PyLong_AsInt(args[1]);
883     if (n == -1 && PyErr_Occurred()) {
884         goto exit;
885     }
886     return_value = pysqlite_connection_set_progress_handler_impl(self, cls, callable, n);
887 
888 exit:
889     return return_value;
890 }
891 
892 PyDoc_STRVAR(pysqlite_connection_set_trace_callback__doc__,
893 "set_trace_callback($self, /, trace_callback)\n"
894 "--\n"
895 "\n"
896 "Set a trace callback called for each SQL statement (passed as unicode).\n"
897 "\n"
898 "Note: Passing keyword argument \'trace_callback\' to\n"
899 "_sqlite3.Connection.set_trace_callback() is deprecated. Parameter\n"
900 "\'trace_callback\' will become positional-only in Python 3.15.\n"
901 "");
902 
903 #define PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF    \
904     {"set_trace_callback", _PyCFunction_CAST(pysqlite_connection_set_trace_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_trace_callback__doc__},
905 
906 static PyObject *
907 pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
908                                             PyTypeObject *cls,
909                                             PyObject *callable);
910 
911 // Emit compiler warnings when we get to Python 3.15.
912 #if PY_VERSION_HEX >= 0x030f00C0
913 #  error "Update the clinic input of '_sqlite3.Connection.set_trace_callback'."
914 #elif PY_VERSION_HEX >= 0x030f00A0
915 #  ifdef _MSC_VER
916 #    pragma message ("Update the clinic input of '_sqlite3.Connection.set_trace_callback'.")
917 #  else
918 #    warning "Update the clinic input of '_sqlite3.Connection.set_trace_callback'."
919 #  endif
920 #endif
921 
922 static PyObject *
pysqlite_connection_set_trace_callback(pysqlite_Connection * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)923 pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
924 {
925     PyObject *return_value = NULL;
926     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
927 
928     #define NUM_KEYWORDS 1
929     static struct {
930         PyGC_Head _this_is_not_used;
931         PyObject_VAR_HEAD
932         PyObject *ob_item[NUM_KEYWORDS];
933     } _kwtuple = {
934         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
935         .ob_item = { &_Py_ID(trace_callback), },
936     };
937     #undef NUM_KEYWORDS
938     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
939 
940     #else  // !Py_BUILD_CORE
941     #  define KWTUPLE NULL
942     #endif  // !Py_BUILD_CORE
943 
944     static const char * const _keywords[] = {"trace_callback", NULL};
945     static _PyArg_Parser _parser = {
946         .keywords = _keywords,
947         .fname = "set_trace_callback",
948         .kwtuple = KWTUPLE,
949     };
950     #undef KWTUPLE
951     PyObject *argsbuf[1];
952     PyObject *callable;
953 
954     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
955     if (!args) {
956         goto exit;
957     }
958     if (nargs < 1) {
959         if (PyErr_WarnEx(PyExc_DeprecationWarning,
960                 "Passing keyword argument 'trace_callback' to "
961                 "_sqlite3.Connection.set_trace_callback() is deprecated. "
962                 "Parameter 'trace_callback' will become positional-only in Python"
963                 " 3.15.", 1))
964         {
965             goto exit;
966         }
967     }
968     callable = args[0];
969     return_value = pysqlite_connection_set_trace_callback_impl(self, cls, callable);
970 
971 exit:
972     return return_value;
973 }
974 
975 #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
976 
977 PyDoc_STRVAR(pysqlite_connection_enable_load_extension__doc__,
978 "enable_load_extension($self, enable, /)\n"
979 "--\n"
980 "\n"
981 "Enable dynamic loading of SQLite extension modules.");
982 
983 #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF    \
984     {"enable_load_extension", (PyCFunction)pysqlite_connection_enable_load_extension, METH_O, pysqlite_connection_enable_load_extension__doc__},
985 
986 static PyObject *
987 pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
988                                                int onoff);
989 
990 static PyObject *
pysqlite_connection_enable_load_extension(pysqlite_Connection * self,PyObject * arg)991 pysqlite_connection_enable_load_extension(pysqlite_Connection *self, PyObject *arg)
992 {
993     PyObject *return_value = NULL;
994     int onoff;
995 
996     onoff = PyObject_IsTrue(arg);
997     if (onoff < 0) {
998         goto exit;
999     }
1000     return_value = pysqlite_connection_enable_load_extension_impl(self, onoff);
1001 
1002 exit:
1003     return return_value;
1004 }
1005 
1006 #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
1007 
1008 #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
1009 
1010 PyDoc_STRVAR(pysqlite_connection_load_extension__doc__,
1011 "load_extension($self, name, /, *, entrypoint=None)\n"
1012 "--\n"
1013 "\n"
1014 "Load SQLite extension module.");
1015 
1016 #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF    \
1017     {"load_extension", _PyCFunction_CAST(pysqlite_connection_load_extension), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_load_extension__doc__},
1018 
1019 static PyObject *
1020 pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
1021                                         const char *extension_name,
1022                                         const char *entrypoint);
1023 
1024 static PyObject *
pysqlite_connection_load_extension(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1025 pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1026 {
1027     PyObject *return_value = NULL;
1028     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1029 
1030     #define NUM_KEYWORDS 1
1031     static struct {
1032         PyGC_Head _this_is_not_used;
1033         PyObject_VAR_HEAD
1034         PyObject *ob_item[NUM_KEYWORDS];
1035     } _kwtuple = {
1036         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1037         .ob_item = { &_Py_ID(entrypoint), },
1038     };
1039     #undef NUM_KEYWORDS
1040     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1041 
1042     #else  // !Py_BUILD_CORE
1043     #  define KWTUPLE NULL
1044     #endif  // !Py_BUILD_CORE
1045 
1046     static const char * const _keywords[] = {"", "entrypoint", NULL};
1047     static _PyArg_Parser _parser = {
1048         .keywords = _keywords,
1049         .fname = "load_extension",
1050         .kwtuple = KWTUPLE,
1051     };
1052     #undef KWTUPLE
1053     PyObject *argsbuf[2];
1054     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1055     const char *extension_name;
1056     const char *entrypoint = NULL;
1057 
1058     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1059     if (!args) {
1060         goto exit;
1061     }
1062     if (!PyUnicode_Check(args[0])) {
1063         _PyArg_BadArgument("load_extension", "argument 1", "str", args[0]);
1064         goto exit;
1065     }
1066     Py_ssize_t extension_name_length;
1067     extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length);
1068     if (extension_name == NULL) {
1069         goto exit;
1070     }
1071     if (strlen(extension_name) != (size_t)extension_name_length) {
1072         PyErr_SetString(PyExc_ValueError, "embedded null character");
1073         goto exit;
1074     }
1075     if (!noptargs) {
1076         goto skip_optional_kwonly;
1077     }
1078     if (args[1] == Py_None) {
1079         entrypoint = NULL;
1080     }
1081     else if (PyUnicode_Check(args[1])) {
1082         Py_ssize_t entrypoint_length;
1083         entrypoint = PyUnicode_AsUTF8AndSize(args[1], &entrypoint_length);
1084         if (entrypoint == NULL) {
1085             goto exit;
1086         }
1087         if (strlen(entrypoint) != (size_t)entrypoint_length) {
1088             PyErr_SetString(PyExc_ValueError, "embedded null character");
1089             goto exit;
1090         }
1091     }
1092     else {
1093         _PyArg_BadArgument("load_extension", "argument 'entrypoint'", "str or None", args[1]);
1094         goto exit;
1095     }
1096 skip_optional_kwonly:
1097     return_value = pysqlite_connection_load_extension_impl(self, extension_name, entrypoint);
1098 
1099 exit:
1100     return return_value;
1101 }
1102 
1103 #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
1104 
1105 PyDoc_STRVAR(pysqlite_connection_execute__doc__,
1106 "execute($self, sql, parameters=<unrepresentable>, /)\n"
1107 "--\n"
1108 "\n"
1109 "Executes an SQL statement.");
1110 
1111 #define PYSQLITE_CONNECTION_EXECUTE_METHODDEF    \
1112     {"execute", _PyCFunction_CAST(pysqlite_connection_execute), METH_FASTCALL, pysqlite_connection_execute__doc__},
1113 
1114 static PyObject *
1115 pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
1116                                  PyObject *parameters);
1117 
1118 static PyObject *
pysqlite_connection_execute(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs)1119 pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
1120 {
1121     PyObject *return_value = NULL;
1122     PyObject *sql;
1123     PyObject *parameters = NULL;
1124 
1125     if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
1126         goto exit;
1127     }
1128     if (!PyUnicode_Check(args[0])) {
1129         _PyArg_BadArgument("execute", "argument 1", "str", args[0]);
1130         goto exit;
1131     }
1132     sql = args[0];
1133     if (nargs < 2) {
1134         goto skip_optional;
1135     }
1136     parameters = args[1];
1137 skip_optional:
1138     return_value = pysqlite_connection_execute_impl(self, sql, parameters);
1139 
1140 exit:
1141     return return_value;
1142 }
1143 
1144 PyDoc_STRVAR(pysqlite_connection_executemany__doc__,
1145 "executemany($self, sql, parameters, /)\n"
1146 "--\n"
1147 "\n"
1148 "Repeatedly executes an SQL statement.");
1149 
1150 #define PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF    \
1151     {"executemany", _PyCFunction_CAST(pysqlite_connection_executemany), METH_FASTCALL, pysqlite_connection_executemany__doc__},
1152 
1153 static PyObject *
1154 pysqlite_connection_executemany_impl(pysqlite_Connection *self,
1155                                      PyObject *sql, PyObject *parameters);
1156 
1157 static PyObject *
pysqlite_connection_executemany(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs)1158 pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
1159 {
1160     PyObject *return_value = NULL;
1161     PyObject *sql;
1162     PyObject *parameters;
1163 
1164     if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
1165         goto exit;
1166     }
1167     if (!PyUnicode_Check(args[0])) {
1168         _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
1169         goto exit;
1170     }
1171     sql = args[0];
1172     parameters = args[1];
1173     return_value = pysqlite_connection_executemany_impl(self, sql, parameters);
1174 
1175 exit:
1176     return return_value;
1177 }
1178 
1179 PyDoc_STRVAR(pysqlite_connection_executescript__doc__,
1180 "executescript($self, sql_script, /)\n"
1181 "--\n"
1182 "\n"
1183 "Executes multiple SQL statements at once.");
1184 
1185 #define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF    \
1186     {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__},
1187 
1188 PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
1189 "interrupt($self, /)\n"
1190 "--\n"
1191 "\n"
1192 "Abort any pending database operation.");
1193 
1194 #define PYSQLITE_CONNECTION_INTERRUPT_METHODDEF    \
1195     {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS, pysqlite_connection_interrupt__doc__},
1196 
1197 static PyObject *
1198 pysqlite_connection_interrupt_impl(pysqlite_Connection *self);
1199 
1200 static PyObject *
pysqlite_connection_interrupt(pysqlite_Connection * self,PyObject * Py_UNUSED (ignored))1201 pysqlite_connection_interrupt(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
1202 {
1203     return pysqlite_connection_interrupt_impl(self);
1204 }
1205 
1206 PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
1207 "iterdump($self, /, *, filter=None)\n"
1208 "--\n"
1209 "\n"
1210 "Returns iterator to the dump of the database in an SQL text format.\n"
1211 "\n"
1212 "  filter\n"
1213 "    An optional LIKE pattern for database objects to dump");
1214 
1215 #define PYSQLITE_CONNECTION_ITERDUMP_METHODDEF    \
1216     {"iterdump", _PyCFunction_CAST(pysqlite_connection_iterdump), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_iterdump__doc__},
1217 
1218 static PyObject *
1219 pysqlite_connection_iterdump_impl(pysqlite_Connection *self,
1220                                   PyObject *filter);
1221 
1222 static PyObject *
pysqlite_connection_iterdump(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1223 pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1224 {
1225     PyObject *return_value = NULL;
1226     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1227 
1228     #define NUM_KEYWORDS 1
1229     static struct {
1230         PyGC_Head _this_is_not_used;
1231         PyObject_VAR_HEAD
1232         PyObject *ob_item[NUM_KEYWORDS];
1233     } _kwtuple = {
1234         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1235         .ob_item = { &_Py_ID(filter), },
1236     };
1237     #undef NUM_KEYWORDS
1238     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1239 
1240     #else  // !Py_BUILD_CORE
1241     #  define KWTUPLE NULL
1242     #endif  // !Py_BUILD_CORE
1243 
1244     static const char * const _keywords[] = {"filter", NULL};
1245     static _PyArg_Parser _parser = {
1246         .keywords = _keywords,
1247         .fname = "iterdump",
1248         .kwtuple = KWTUPLE,
1249     };
1250     #undef KWTUPLE
1251     PyObject *argsbuf[1];
1252     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1253     PyObject *filter = Py_None;
1254 
1255     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
1256     if (!args) {
1257         goto exit;
1258     }
1259     if (!noptargs) {
1260         goto skip_optional_kwonly;
1261     }
1262     filter = args[0];
1263 skip_optional_kwonly:
1264     return_value = pysqlite_connection_iterdump_impl(self, filter);
1265 
1266 exit:
1267     return return_value;
1268 }
1269 
1270 PyDoc_STRVAR(pysqlite_connection_backup__doc__,
1271 "backup($self, /, target, *, pages=-1, progress=None, name=\'main\',\n"
1272 "       sleep=0.25)\n"
1273 "--\n"
1274 "\n"
1275 "Makes a backup of the database.");
1276 
1277 #define PYSQLITE_CONNECTION_BACKUP_METHODDEF    \
1278     {"backup", _PyCFunction_CAST(pysqlite_connection_backup), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_backup__doc__},
1279 
1280 static PyObject *
1281 pysqlite_connection_backup_impl(pysqlite_Connection *self,
1282                                 pysqlite_Connection *target, int pages,
1283                                 PyObject *progress, const char *name,
1284                                 double sleep);
1285 
1286 static PyObject *
pysqlite_connection_backup(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1287 pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1288 {
1289     PyObject *return_value = NULL;
1290     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1291 
1292     #define NUM_KEYWORDS 5
1293     static struct {
1294         PyGC_Head _this_is_not_used;
1295         PyObject_VAR_HEAD
1296         PyObject *ob_item[NUM_KEYWORDS];
1297     } _kwtuple = {
1298         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1299         .ob_item = { &_Py_ID(target), &_Py_ID(pages), &_Py_ID(progress), &_Py_ID(name), &_Py_ID(sleep), },
1300     };
1301     #undef NUM_KEYWORDS
1302     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1303 
1304     #else  // !Py_BUILD_CORE
1305     #  define KWTUPLE NULL
1306     #endif  // !Py_BUILD_CORE
1307 
1308     static const char * const _keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
1309     static _PyArg_Parser _parser = {
1310         .keywords = _keywords,
1311         .fname = "backup",
1312         .kwtuple = KWTUPLE,
1313     };
1314     #undef KWTUPLE
1315     PyObject *argsbuf[5];
1316     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1317     pysqlite_Connection *target;
1318     int pages = -1;
1319     PyObject *progress = Py_None;
1320     const char *name = "main";
1321     double sleep = 0.25;
1322 
1323     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1324     if (!args) {
1325         goto exit;
1326     }
1327     if (!PyObject_TypeCheck(args[0], clinic_state()->ConnectionType)) {
1328         _PyArg_BadArgument("backup", "argument 'target'", (clinic_state()->ConnectionType)->tp_name, args[0]);
1329         goto exit;
1330     }
1331     target = (pysqlite_Connection *)args[0];
1332     if (!noptargs) {
1333         goto skip_optional_kwonly;
1334     }
1335     if (args[1]) {
1336         pages = PyLong_AsInt(args[1]);
1337         if (pages == -1 && PyErr_Occurred()) {
1338             goto exit;
1339         }
1340         if (!--noptargs) {
1341             goto skip_optional_kwonly;
1342         }
1343     }
1344     if (args[2]) {
1345         progress = args[2];
1346         if (!--noptargs) {
1347             goto skip_optional_kwonly;
1348         }
1349     }
1350     if (args[3]) {
1351         if (!PyUnicode_Check(args[3])) {
1352             _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
1353             goto exit;
1354         }
1355         Py_ssize_t name_length;
1356         name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
1357         if (name == NULL) {
1358             goto exit;
1359         }
1360         if (strlen(name) != (size_t)name_length) {
1361             PyErr_SetString(PyExc_ValueError, "embedded null character");
1362             goto exit;
1363         }
1364         if (!--noptargs) {
1365             goto skip_optional_kwonly;
1366         }
1367     }
1368     if (PyFloat_CheckExact(args[4])) {
1369         sleep = PyFloat_AS_DOUBLE(args[4]);
1370     }
1371     else
1372     {
1373         sleep = PyFloat_AsDouble(args[4]);
1374         if (sleep == -1.0 && PyErr_Occurred()) {
1375             goto exit;
1376         }
1377     }
1378 skip_optional_kwonly:
1379     return_value = pysqlite_connection_backup_impl(self, target, pages, progress, name, sleep);
1380 
1381 exit:
1382     return return_value;
1383 }
1384 
1385 PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
1386 "create_collation($self, name, callback, /)\n"
1387 "--\n"
1388 "\n"
1389 "Creates a collation function.");
1390 
1391 #define PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF    \
1392     {"create_collation", _PyCFunction_CAST(pysqlite_connection_create_collation), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_collation__doc__},
1393 
1394 static PyObject *
1395 pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
1396                                           PyTypeObject *cls,
1397                                           const char *name,
1398                                           PyObject *callable);
1399 
1400 static PyObject *
pysqlite_connection_create_collation(pysqlite_Connection * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1401 pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1402 {
1403     PyObject *return_value = NULL;
1404     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1405     #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
1406     #else
1407     #  define KWTUPLE NULL
1408     #endif
1409 
1410     static const char * const _keywords[] = {"", "", NULL};
1411     static _PyArg_Parser _parser = {
1412         .keywords = _keywords,
1413         .fname = "create_collation",
1414         .kwtuple = KWTUPLE,
1415     };
1416     #undef KWTUPLE
1417     PyObject *argsbuf[2];
1418     const char *name;
1419     PyObject *callable;
1420 
1421     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
1422     if (!args) {
1423         goto exit;
1424     }
1425     if (!PyUnicode_Check(args[0])) {
1426         _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
1427         goto exit;
1428     }
1429     Py_ssize_t name_length;
1430     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
1431     if (name == NULL) {
1432         goto exit;
1433     }
1434     if (strlen(name) != (size_t)name_length) {
1435         PyErr_SetString(PyExc_ValueError, "embedded null character");
1436         goto exit;
1437     }
1438     callable = args[1];
1439     return_value = pysqlite_connection_create_collation_impl(self, cls, name, callable);
1440 
1441 exit:
1442     return return_value;
1443 }
1444 
1445 #if defined(PY_SQLITE_HAVE_SERIALIZE)
1446 
1447 PyDoc_STRVAR(serialize__doc__,
1448 "serialize($self, /, *, name=\'main\')\n"
1449 "--\n"
1450 "\n"
1451 "Serialize a database into a byte string.\n"
1452 "\n"
1453 "  name\n"
1454 "    Which database to serialize.\n"
1455 "\n"
1456 "For an ordinary on-disk database file, the serialization is just a copy of the\n"
1457 "disk file. For an in-memory database or a \"temp\" database, the serialization is\n"
1458 "the same sequence of bytes which would be written to disk if that database\n"
1459 "were backed up to disk.");
1460 
1461 #define SERIALIZE_METHODDEF    \
1462     {"serialize", _PyCFunction_CAST(serialize), METH_FASTCALL|METH_KEYWORDS, serialize__doc__},
1463 
1464 static PyObject *
1465 serialize_impl(pysqlite_Connection *self, const char *name);
1466 
1467 static PyObject *
serialize(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1468 serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1469 {
1470     PyObject *return_value = NULL;
1471     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1472 
1473     #define NUM_KEYWORDS 1
1474     static struct {
1475         PyGC_Head _this_is_not_used;
1476         PyObject_VAR_HEAD
1477         PyObject *ob_item[NUM_KEYWORDS];
1478     } _kwtuple = {
1479         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1480         .ob_item = { &_Py_ID(name), },
1481     };
1482     #undef NUM_KEYWORDS
1483     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1484 
1485     #else  // !Py_BUILD_CORE
1486     #  define KWTUPLE NULL
1487     #endif  // !Py_BUILD_CORE
1488 
1489     static const char * const _keywords[] = {"name", NULL};
1490     static _PyArg_Parser _parser = {
1491         .keywords = _keywords,
1492         .fname = "serialize",
1493         .kwtuple = KWTUPLE,
1494     };
1495     #undef KWTUPLE
1496     PyObject *argsbuf[1];
1497     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1498     const char *name = "main";
1499 
1500     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
1501     if (!args) {
1502         goto exit;
1503     }
1504     if (!noptargs) {
1505         goto skip_optional_kwonly;
1506     }
1507     if (!PyUnicode_Check(args[0])) {
1508         _PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]);
1509         goto exit;
1510     }
1511     Py_ssize_t name_length;
1512     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
1513     if (name == NULL) {
1514         goto exit;
1515     }
1516     if (strlen(name) != (size_t)name_length) {
1517         PyErr_SetString(PyExc_ValueError, "embedded null character");
1518         goto exit;
1519     }
1520 skip_optional_kwonly:
1521     return_value = serialize_impl(self, name);
1522 
1523 exit:
1524     return return_value;
1525 }
1526 
1527 #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
1528 
1529 #if defined(PY_SQLITE_HAVE_SERIALIZE)
1530 
1531 PyDoc_STRVAR(deserialize__doc__,
1532 "deserialize($self, data, /, *, name=\'main\')\n"
1533 "--\n"
1534 "\n"
1535 "Load a serialized database.\n"
1536 "\n"
1537 "  data\n"
1538 "    The serialized database content.\n"
1539 "  name\n"
1540 "    Which database to reopen with the deserialization.\n"
1541 "\n"
1542 "The deserialize interface causes the database connection to disconnect from the\n"
1543 "target database, and then reopen it as an in-memory database based on the given\n"
1544 "serialized data.\n"
1545 "\n"
1546 "The deserialize interface will fail with SQLITE_BUSY if the database is\n"
1547 "currently in a read transaction or is involved in a backup operation.");
1548 
1549 #define DESERIALIZE_METHODDEF    \
1550     {"deserialize", _PyCFunction_CAST(deserialize), METH_FASTCALL|METH_KEYWORDS, deserialize__doc__},
1551 
1552 static PyObject *
1553 deserialize_impl(pysqlite_Connection *self, Py_buffer *data,
1554                  const char *name);
1555 
1556 static PyObject *
deserialize(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1557 deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1558 {
1559     PyObject *return_value = NULL;
1560     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1561 
1562     #define NUM_KEYWORDS 1
1563     static struct {
1564         PyGC_Head _this_is_not_used;
1565         PyObject_VAR_HEAD
1566         PyObject *ob_item[NUM_KEYWORDS];
1567     } _kwtuple = {
1568         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1569         .ob_item = { &_Py_ID(name), },
1570     };
1571     #undef NUM_KEYWORDS
1572     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1573 
1574     #else  // !Py_BUILD_CORE
1575     #  define KWTUPLE NULL
1576     #endif  // !Py_BUILD_CORE
1577 
1578     static const char * const _keywords[] = {"", "name", NULL};
1579     static _PyArg_Parser _parser = {
1580         .keywords = _keywords,
1581         .fname = "deserialize",
1582         .kwtuple = KWTUPLE,
1583     };
1584     #undef KWTUPLE
1585     PyObject *argsbuf[2];
1586     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1587     Py_buffer data = {NULL, NULL};
1588     const char *name = "main";
1589 
1590     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1591     if (!args) {
1592         goto exit;
1593     }
1594     if (PyUnicode_Check(args[0])) {
1595         Py_ssize_t len;
1596         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1597         if (ptr == NULL) {
1598             goto exit;
1599         }
1600         if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) {
1601             goto exit;
1602         }
1603     }
1604     else { /* any bytes-like object */
1605         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1606             goto exit;
1607         }
1608     }
1609     if (!noptargs) {
1610         goto skip_optional_kwonly;
1611     }
1612     if (!PyUnicode_Check(args[1])) {
1613         _PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]);
1614         goto exit;
1615     }
1616     Py_ssize_t name_length;
1617     name = PyUnicode_AsUTF8AndSize(args[1], &name_length);
1618     if (name == NULL) {
1619         goto exit;
1620     }
1621     if (strlen(name) != (size_t)name_length) {
1622         PyErr_SetString(PyExc_ValueError, "embedded null character");
1623         goto exit;
1624     }
1625 skip_optional_kwonly:
1626     return_value = deserialize_impl(self, &data, name);
1627 
1628 exit:
1629     /* Cleanup for data */
1630     if (data.obj) {
1631        PyBuffer_Release(&data);
1632     }
1633 
1634     return return_value;
1635 }
1636 
1637 #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
1638 
1639 PyDoc_STRVAR(pysqlite_connection_enter__doc__,
1640 "__enter__($self, /)\n"
1641 "--\n"
1642 "\n"
1643 "Called when the connection is used as a context manager.\n"
1644 "\n"
1645 "Returns itself as a convenience to the caller.");
1646 
1647 #define PYSQLITE_CONNECTION_ENTER_METHODDEF    \
1648     {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS, pysqlite_connection_enter__doc__},
1649 
1650 static PyObject *
1651 pysqlite_connection_enter_impl(pysqlite_Connection *self);
1652 
1653 static PyObject *
pysqlite_connection_enter(pysqlite_Connection * self,PyObject * Py_UNUSED (ignored))1654 pysqlite_connection_enter(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
1655 {
1656     return pysqlite_connection_enter_impl(self);
1657 }
1658 
1659 PyDoc_STRVAR(pysqlite_connection_exit__doc__,
1660 "__exit__($self, type, value, traceback, /)\n"
1661 "--\n"
1662 "\n"
1663 "Called when the connection is used as a context manager.\n"
1664 "\n"
1665 "If there was any exception, a rollback takes place; otherwise we commit.");
1666 
1667 #define PYSQLITE_CONNECTION_EXIT_METHODDEF    \
1668     {"__exit__", _PyCFunction_CAST(pysqlite_connection_exit), METH_FASTCALL, pysqlite_connection_exit__doc__},
1669 
1670 static PyObject *
1671 pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
1672                               PyObject *exc_value, PyObject *exc_tb);
1673 
1674 static PyObject *
pysqlite_connection_exit(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs)1675 pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
1676 {
1677     PyObject *return_value = NULL;
1678     PyObject *exc_type;
1679     PyObject *exc_value;
1680     PyObject *exc_tb;
1681 
1682     if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
1683         goto exit;
1684     }
1685     exc_type = args[0];
1686     exc_value = args[1];
1687     exc_tb = args[2];
1688     return_value = pysqlite_connection_exit_impl(self, exc_type, exc_value, exc_tb);
1689 
1690 exit:
1691     return return_value;
1692 }
1693 
1694 PyDoc_STRVAR(setlimit__doc__,
1695 "setlimit($self, category, limit, /)\n"
1696 "--\n"
1697 "\n"
1698 "Set connection run-time limits.\n"
1699 "\n"
1700 "  category\n"
1701 "    The limit category to be set.\n"
1702 "  limit\n"
1703 "    The new limit. If the new limit is a negative number, the limit is\n"
1704 "    unchanged.\n"
1705 "\n"
1706 "Attempts to increase a limit above its hard upper bound are silently truncated\n"
1707 "to the hard upper bound. Regardless of whether or not the limit was changed,\n"
1708 "the prior value of the limit is returned.");
1709 
1710 #define SETLIMIT_METHODDEF    \
1711     {"setlimit", _PyCFunction_CAST(setlimit), METH_FASTCALL, setlimit__doc__},
1712 
1713 static PyObject *
1714 setlimit_impl(pysqlite_Connection *self, int category, int limit);
1715 
1716 static PyObject *
setlimit(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs)1717 setlimit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
1718 {
1719     PyObject *return_value = NULL;
1720     int category;
1721     int limit;
1722 
1723     if (!_PyArg_CheckPositional("setlimit", nargs, 2, 2)) {
1724         goto exit;
1725     }
1726     category = PyLong_AsInt(args[0]);
1727     if (category == -1 && PyErr_Occurred()) {
1728         goto exit;
1729     }
1730     limit = PyLong_AsInt(args[1]);
1731     if (limit == -1 && PyErr_Occurred()) {
1732         goto exit;
1733     }
1734     return_value = setlimit_impl(self, category, limit);
1735 
1736 exit:
1737     return return_value;
1738 }
1739 
1740 PyDoc_STRVAR(getlimit__doc__,
1741 "getlimit($self, category, /)\n"
1742 "--\n"
1743 "\n"
1744 "Get connection run-time limits.\n"
1745 "\n"
1746 "  category\n"
1747 "    The limit category to be queried.");
1748 
1749 #define GETLIMIT_METHODDEF    \
1750     {"getlimit", (PyCFunction)getlimit, METH_O, getlimit__doc__},
1751 
1752 static PyObject *
1753 getlimit_impl(pysqlite_Connection *self, int category);
1754 
1755 static PyObject *
getlimit(pysqlite_Connection * self,PyObject * arg)1756 getlimit(pysqlite_Connection *self, PyObject *arg)
1757 {
1758     PyObject *return_value = NULL;
1759     int category;
1760 
1761     category = PyLong_AsInt(arg);
1762     if (category == -1 && PyErr_Occurred()) {
1763         goto exit;
1764     }
1765     return_value = getlimit_impl(self, category);
1766 
1767 exit:
1768     return return_value;
1769 }
1770 
1771 PyDoc_STRVAR(setconfig__doc__,
1772 "setconfig($self, op, enable=True, /)\n"
1773 "--\n"
1774 "\n"
1775 "Set a boolean connection configuration option.\n"
1776 "\n"
1777 "  op\n"
1778 "    The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes.");
1779 
1780 #define SETCONFIG_METHODDEF    \
1781     {"setconfig", _PyCFunction_CAST(setconfig), METH_FASTCALL, setconfig__doc__},
1782 
1783 static PyObject *
1784 setconfig_impl(pysqlite_Connection *self, int op, int enable);
1785 
1786 static PyObject *
setconfig(pysqlite_Connection * self,PyObject * const * args,Py_ssize_t nargs)1787 setconfig(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
1788 {
1789     PyObject *return_value = NULL;
1790     int op;
1791     int enable = 1;
1792 
1793     if (!_PyArg_CheckPositional("setconfig", nargs, 1, 2)) {
1794         goto exit;
1795     }
1796     op = PyLong_AsInt(args[0]);
1797     if (op == -1 && PyErr_Occurred()) {
1798         goto exit;
1799     }
1800     if (nargs < 2) {
1801         goto skip_optional;
1802     }
1803     enable = PyObject_IsTrue(args[1]);
1804     if (enable < 0) {
1805         goto exit;
1806     }
1807 skip_optional:
1808     return_value = setconfig_impl(self, op, enable);
1809 
1810 exit:
1811     return return_value;
1812 }
1813 
1814 PyDoc_STRVAR(getconfig__doc__,
1815 "getconfig($self, op, /)\n"
1816 "--\n"
1817 "\n"
1818 "Query a boolean connection configuration option.\n"
1819 "\n"
1820 "  op\n"
1821 "    The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes.");
1822 
1823 #define GETCONFIG_METHODDEF    \
1824     {"getconfig", (PyCFunction)getconfig, METH_O, getconfig__doc__},
1825 
1826 static int
1827 getconfig_impl(pysqlite_Connection *self, int op);
1828 
1829 static PyObject *
getconfig(pysqlite_Connection * self,PyObject * arg)1830 getconfig(pysqlite_Connection *self, PyObject *arg)
1831 {
1832     PyObject *return_value = NULL;
1833     int op;
1834     int _return_value;
1835 
1836     op = PyLong_AsInt(arg);
1837     if (op == -1 && PyErr_Occurred()) {
1838         goto exit;
1839     }
1840     _return_value = getconfig_impl(self, op);
1841     if ((_return_value == -1) && PyErr_Occurred()) {
1842         goto exit;
1843     }
1844     return_value = PyBool_FromLong((long)_return_value);
1845 
1846 exit:
1847     return return_value;
1848 }
1849 
1850 #ifndef CREATE_WINDOW_FUNCTION_METHODDEF
1851     #define CREATE_WINDOW_FUNCTION_METHODDEF
1852 #endif /* !defined(CREATE_WINDOW_FUNCTION_METHODDEF) */
1853 
1854 #ifndef PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
1855     #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
1856 #endif /* !defined(PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF) */
1857 
1858 #ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
1859     #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
1860 #endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
1861 
1862 #ifndef SERIALIZE_METHODDEF
1863     #define SERIALIZE_METHODDEF
1864 #endif /* !defined(SERIALIZE_METHODDEF) */
1865 
1866 #ifndef DESERIALIZE_METHODDEF
1867     #define DESERIALIZE_METHODDEF
1868 #endif /* !defined(DESERIALIZE_METHODDEF) */
1869 /*[clinic end generated code: output=5d4d7e4abe17b164 input=a9049054013a1b77]*/
1870