Debian Codegraph @

Modules/_sqlite/clinic/connection.c.h

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