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\n"
822 " terminated, 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\n"
828 "disabled.\n"
829 "\n"
830 "Note: Passing keyword argument \'progress_handler\' to\n"
831 "_sqlite3.Connection.set_progress_handler() is deprecated. Parameter\n"
832 "\'progress_handler\' will become positional-only in Python 3.15.\n"
833 "");
834
835 #define PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF \
836 {"set_progress_handler", _PyCFunction_CAST(pysqlite_connection_set_progress_handler), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_progress_handler__doc__},
837
838 static PyObject *
839 pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
840 PyTypeObject *cls,
841 PyObject *callable, int n);
842
843 // Emit compiler warnings when we get to Python 3.15.
844 #if PY_VERSION_HEX >= 0x030f00C0
845 # error "Update the clinic input of '_sqlite3.Connection.set_progress_handler'."
846 #elif PY_VERSION_HEX >= 0x030f00A0
847 # ifdef _MSC_VER
848 # pragma message ("Update the clinic input of '_sqlite3.Connection.set_progress_handler'.")
849 # else
850 # warning "Update the clinic input of '_sqlite3.Connection.set_progress_handler'."
851 # endif
852 #endif
853
854 static PyObject *
855 pysqlite_connection_set_progress_handler(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
856 {
857 PyObject *return_value = NULL;
858 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
859
860 #define NUM_KEYWORDS 2
861 static struct {
862 PyGC_Head _this_is_not_used;
863 PyObject_VAR_HEAD
864 Py_hash_t ob_hash;
865 PyObject *ob_item[NUM_KEYWORDS];
866 } _kwtuple = {
867 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
868 .ob_hash = -1,
869 .ob_item = { &_Py_ID(progress_handler), _Py_LATIN1_CHR('n'), },
870 };
871 #undef NUM_KEYWORDS
872 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
873
874 #else // !Py_BUILD_CORE
875 # define KWTUPLE NULL
876 #endif // !Py_BUILD_CORE
877
878 static const char * const _keywords[] = {"progress_handler", "n", NULL};
879 static _PyArg_Parser _parser = {
880 .keywords = _keywords,
881 .fname = "set_progress_handler",
882 .kwtuple = KWTUPLE,
883 };
884 #undef KWTUPLE
885 PyObject *argsbuf[2];
886 PyObject *callable;
887 int n;
888
889 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
890 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
891 if (!args) {
892 goto exit;
893 }
894 if (nargs < 1) {
895 if (PyErr_WarnEx(PyExc_DeprecationWarning,
896 "Passing keyword argument 'progress_handler' to "
897 "_sqlite3.Connection.set_progress_handler() is deprecated. "
898 "Parameter 'progress_handler' will become positional-only in "
899 "Python 3.15.", 1))
900 {
901 goto exit;
902 }
903 }
904 callable = args[0];
905 n = PyLong_AsInt(args[1]);
906 if (n == -1 && PyErr_Occurred()) {
907 goto exit;
908 }
909 return_value = pysqlite_connection_set_progress_handler_impl((pysqlite_Connection *)self, cls, callable, n);
910
911 exit:
912 return return_value;
913 }
914
915 PyDoc_STRVAR(pysqlite_connection_set_trace_callback__doc__,
916 "set_trace_callback($self, /, trace_callback)\n"
917 "--\n"
918 "\n"
919 "Set a trace callback called for each SQL statement (passed as unicode).\n"
920 "\n"
921 "Note: Passing keyword argument \'trace_callback\' to\n"
922 "_sqlite3.Connection.set_trace_callback() is deprecated. Parameter\n"
923 "\'trace_callback\' will become positional-only in Python 3.15.\n"
924 "");
925
926 #define PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF \
927 {"set_trace_callback", _PyCFunction_CAST(pysqlite_connection_set_trace_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_trace_callback__doc__},
928
929 static PyObject *
930 pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
931 PyTypeObject *cls,
932 PyObject *callable);
933
934 // Emit compiler warnings when we get to Python 3.15.
935 #if PY_VERSION_HEX >= 0x030f00C0
936 # error "Update the clinic input of '_sqlite3.Connection.set_trace_callback'."
937 #elif PY_VERSION_HEX >= 0x030f00A0
938 # ifdef _MSC_VER
939 # pragma message ("Update the clinic input of '_sqlite3.Connection.set_trace_callback'.")
940 # else
941 # warning "Update the clinic input of '_sqlite3.Connection.set_trace_callback'."
942 # endif
943 #endif
944
945 static PyObject *
946 pysqlite_connection_set_trace_callback(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
947 {
948 PyObject *return_value = NULL;
949 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
950
951 #define NUM_KEYWORDS 1
952 static struct {
953 PyGC_Head _this_is_not_used;
954 PyObject_VAR_HEAD
955 Py_hash_t ob_hash;
956 PyObject *ob_item[NUM_KEYWORDS];
957 } _kwtuple = {
958 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
959 .ob_hash = -1,
960 .ob_item = { &_Py_ID(trace_callback), },
961 };
962 #undef NUM_KEYWORDS
963 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
964
965 #else // !Py_BUILD_CORE
966 # define KWTUPLE NULL
967 #endif // !Py_BUILD_CORE
968
969 static const char * const _keywords[] = {"trace_callback", NULL};
970 static _PyArg_Parser _parser = {
971 .keywords = _keywords,
972 .fname = "set_trace_callback",
973 .kwtuple = KWTUPLE,
974 };
975 #undef KWTUPLE
976 PyObject *argsbuf[1];
977 PyObject *callable;
978
979 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
980 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
981 if (!args) {
982 goto exit;
983 }
984 if (nargs < 1) {
985 if (PyErr_WarnEx(PyExc_DeprecationWarning,
986 "Passing keyword argument 'trace_callback' to "
987 "_sqlite3.Connection.set_trace_callback() is deprecated. "
988 "Parameter 'trace_callback' will become positional-only in Python"
989 " 3.15.", 1))
990 {
991 goto exit;
992 }
993 }
994 callable = args[0];
995 return_value = pysqlite_connection_set_trace_callback_impl((pysqlite_Connection *)self, cls, callable);
996
997 exit:
998 return return_value;
999 }
1000
1001 #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
1002
1003 PyDoc_STRVAR(pysqlite_connection_enable_load_extension__doc__,
1004 "enable_load_extension($self, enable, /)\n"
1005 "--\n"
1006 "\n"
1007 "Enable dynamic loading of SQLite extension modules.");
1008
1009 #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF \
1010 {"enable_load_extension", (PyCFunction)pysqlite_connection_enable_load_extension, METH_O, pysqlite_connection_enable_load_extension__doc__},
1011
1012 static PyObject *
1013 pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
1014 int onoff);
1015
1016 static PyObject *
1017 pysqlite_connection_enable_load_extension(PyObject *self, PyObject *arg)
1018 {
1019 PyObject *return_value = NULL;
1020 int onoff;
1021
1022 onoff = PyObject_IsTrue(arg);
1023 if (onoff < 0) {
1024 goto exit;
1025 }
1026 return_value = pysqlite_connection_enable_load_extension_impl((pysqlite_Connection *)self, onoff);
1027
1028 exit:
1029 return return_value;
1030 }
1031
1032 #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
1033
1034 #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
1035
1036 PyDoc_STRVAR(pysqlite_connection_load_extension__doc__,
1037 "load_extension($self, name, /, *, entrypoint=None)\n"
1038 "--\n"
1039 "\n"
1040 "Load SQLite extension module.");
1041
1042 #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF \
1043 {"load_extension", _PyCFunction_CAST(pysqlite_connection_load_extension), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_load_extension__doc__},
1044
1045 static PyObject *
1046 pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
1047 const char *extension_name,
1048 const char *entrypoint);
1049
1050 static PyObject *
1051 pysqlite_connection_load_extension(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1052 {
1053 PyObject *return_value = NULL;
1054 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1055
1056 #define NUM_KEYWORDS 1
1057 static struct {
1058 PyGC_Head _this_is_not_used;
1059 PyObject_VAR_HEAD
1060 Py_hash_t ob_hash;
1061 PyObject *ob_item[NUM_KEYWORDS];
1062 } _kwtuple = {
1063 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1064 .ob_hash = -1,
1065 .ob_item = { &_Py_ID(entrypoint), },
1066 };
1067 #undef NUM_KEYWORDS
1068 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1069
1070 #else // !Py_BUILD_CORE
1071 # define KWTUPLE NULL
1072 #endif // !Py_BUILD_CORE
1073
1074 static const char * const _keywords[] = {"", "entrypoint", NULL};
1075 static _PyArg_Parser _parser = {
1076 .keywords = _keywords,
1077 .fname = "load_extension",
1078 .kwtuple = KWTUPLE,
1079 };
1080 #undef KWTUPLE
1081 PyObject *argsbuf[2];
1082 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1083 const char *extension_name;
1084 const char *entrypoint = NULL;
1085
1086 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1087 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1088 if (!args) {
1089 goto exit;
1090 }
1091 if (!PyUnicode_Check(args[0])) {
1092 _PyArg_BadArgument("load_extension", "argument 1", "str", args[0]);
1093 goto exit;
1094 }
1095 Py_ssize_t extension_name_length;
1096 extension_name = PyUnicode_AsUTF8AndSize(args[0], &extension_name_length);
1097 if (extension_name == NULL) {
1098 goto exit;
1099 }
1100 if (strlen(extension_name) != (size_t)extension_name_length) {
1101 PyErr_SetString(PyExc_ValueError, "embedded null character");
1102 goto exit;
1103 }
1104 if (!noptargs) {
1105 goto skip_optional_kwonly;
1106 }
1107 if (args[1] == Py_None) {
1108 entrypoint = NULL;
1109 }
1110 else if (PyUnicode_Check(args[1])) {
1111 Py_ssize_t entrypoint_length;
1112 entrypoint = PyUnicode_AsUTF8AndSize(args[1], &entrypoint_length);
1113 if (entrypoint == NULL) {
1114 goto exit;
1115 }
1116 if (strlen(entrypoint) != (size_t)entrypoint_length) {
1117 PyErr_SetString(PyExc_ValueError, "embedded null character");
1118 goto exit;
1119 }
1120 }
1121 else {
1122 _PyArg_BadArgument("load_extension", "argument 'entrypoint'", "str or None", args[1]);
1123 goto exit;
1124 }
1125 skip_optional_kwonly:
1126 return_value = pysqlite_connection_load_extension_impl((pysqlite_Connection *)self, extension_name, entrypoint);
1127
1128 exit:
1129 return return_value;
1130 }
1131
1132 #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
1133
1134 PyDoc_STRVAR(pysqlite_connection_execute__doc__,
1135 "execute($self, sql, parameters=<unrepresentable>, /)\n"
1136 "--\n"
1137 "\n"
1138 "Executes an SQL statement.");
1139
1140 #define PYSQLITE_CONNECTION_EXECUTE_METHODDEF \
1141 {"execute", _PyCFunction_CAST(pysqlite_connection_execute), METH_FASTCALL, pysqlite_connection_execute__doc__},
1142
1143 static PyObject *
1144 pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
1145 PyObject *parameters);
1146
1147 static PyObject *
1148 pysqlite_connection_execute(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1149 {
1150 PyObject *return_value = NULL;
1151 PyObject *sql;
1152 PyObject *parameters = NULL;
1153
1154 if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
1155 goto exit;
1156 }
1157 if (!PyUnicode_Check(args[0])) {
1158 _PyArg_BadArgument("execute", "argument 1", "str", args[0]);
1159 goto exit;
1160 }
1161 sql = args[0];
1162 if (nargs < 2) {
1163 goto skip_optional;
1164 }
1165 parameters = args[1];
1166 skip_optional:
1167 return_value = pysqlite_connection_execute_impl((pysqlite_Connection *)self, sql, parameters);
1168
1169 exit:
1170 return return_value;
1171 }
1172
1173 PyDoc_STRVAR(pysqlite_connection_executemany__doc__,
1174 "executemany($self, sql, parameters, /)\n"
1175 "--\n"
1176 "\n"
1177 "Repeatedly executes an SQL statement.");
1178
1179 #define PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF \
1180 {"executemany", _PyCFunction_CAST(pysqlite_connection_executemany), METH_FASTCALL, pysqlite_connection_executemany__doc__},
1181
1182 static PyObject *
1183 pysqlite_connection_executemany_impl(pysqlite_Connection *self,
1184 PyObject *sql, PyObject *parameters);
1185
1186 static PyObject *
1187 pysqlite_connection_executemany(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1188 {
1189 PyObject *return_value = NULL;
1190 PyObject *sql;
1191 PyObject *parameters;
1192
1193 if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
1194 goto exit;
1195 }
1196 if (!PyUnicode_Check(args[0])) {
1197 _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
1198 goto exit;
1199 }
1200 sql = args[0];
1201 parameters = args[1];
1202 return_value = pysqlite_connection_executemany_impl((pysqlite_Connection *)self, sql, parameters);
1203
1204 exit:
1205 return return_value;
1206 }
1207
1208 PyDoc_STRVAR(pysqlite_connection_executescript__doc__,
1209 "executescript($self, sql_script, /)\n"
1210 "--\n"
1211 "\n"
1212 "Executes multiple SQL statements at once.");
1213
1214 #define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF \
1215 {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__},
1216
1217 static PyObject *
1218 pysqlite_connection_executescript_impl(pysqlite_Connection *self,
1219 PyObject *script_obj);
1220
1221 static PyObject *
1222 pysqlite_connection_executescript(PyObject *self, PyObject *script_obj)
1223 {
1224 PyObject *return_value = NULL;
1225
1226 return_value = pysqlite_connection_executescript_impl((pysqlite_Connection *)self, script_obj);
1227
1228 return return_value;
1229 }
1230
1231 PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
1232 "interrupt($self, /)\n"
1233 "--\n"
1234 "\n"
1235 "Abort any pending database operation.");
1236
1237 #define PYSQLITE_CONNECTION_INTERRUPT_METHODDEF \
1238 {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS, pysqlite_connection_interrupt__doc__},
1239
1240 static PyObject *
1241 pysqlite_connection_interrupt_impl(pysqlite_Connection *self);
1242
1243 static PyObject *
1244 pysqlite_connection_interrupt(PyObject *self, PyObject *Py_UNUSED(ignored))
1245 {
1246 return pysqlite_connection_interrupt_impl((pysqlite_Connection *)self);
1247 }
1248
1249 PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
1250 "iterdump($self, /, *, filter=None)\n"
1251 "--\n"
1252 "\n"
1253 "Returns iterator to the dump of the database in an SQL text format.\n"
1254 "\n"
1255 " filter\n"
1256 " An optional LIKE pattern for database objects to dump");
1257
1258 #define PYSQLITE_CONNECTION_ITERDUMP_METHODDEF \
1259 {"iterdump", _PyCFunction_CAST(pysqlite_connection_iterdump), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_iterdump__doc__},
1260
1261 static PyObject *
1262 pysqlite_connection_iterdump_impl(pysqlite_Connection *self,
1263 PyObject *filter);
1264
1265 static PyObject *
1266 pysqlite_connection_iterdump(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1267 {
1268 PyObject *return_value = NULL;
1269 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1270
1271 #define NUM_KEYWORDS 1
1272 static struct {
1273 PyGC_Head _this_is_not_used;
1274 PyObject_VAR_HEAD
1275 Py_hash_t ob_hash;
1276 PyObject *ob_item[NUM_KEYWORDS];
1277 } _kwtuple = {
1278 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1279 .ob_hash = -1,
1280 .ob_item = { &_Py_ID(filter), },
1281 };
1282 #undef NUM_KEYWORDS
1283 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1284
1285 #else // !Py_BUILD_CORE
1286 # define KWTUPLE NULL
1287 #endif // !Py_BUILD_CORE
1288
1289 static const char * const _keywords[] = {"filter", NULL};
1290 static _PyArg_Parser _parser = {
1291 .keywords = _keywords,
1292 .fname = "iterdump",
1293 .kwtuple = KWTUPLE,
1294 };
1295 #undef KWTUPLE
1296 PyObject *argsbuf[1];
1297 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1298 PyObject *filter = Py_None;
1299
1300 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1301 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1302 if (!args) {
1303 goto exit;
1304 }
1305 if (!noptargs) {
1306 goto skip_optional_kwonly;
1307 }
1308 filter = args[0];
1309 skip_optional_kwonly:
1310 return_value = pysqlite_connection_iterdump_impl((pysqlite_Connection *)self, filter);
1311
1312 exit:
1313 return return_value;
1314 }
1315
1316 PyDoc_STRVAR(pysqlite_connection_backup__doc__,
1317 "backup($self, /, target, *, pages=-1, progress=None, name=\'main\',\n"
1318 " sleep=0.25)\n"
1319 "--\n"
1320 "\n"
1321 "Makes a backup of the database.");
1322
1323 #define PYSQLITE_CONNECTION_BACKUP_METHODDEF \
1324 {"backup", _PyCFunction_CAST(pysqlite_connection_backup), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_backup__doc__},
1325
1326 static PyObject *
1327 pysqlite_connection_backup_impl(pysqlite_Connection *self,
1328 pysqlite_Connection *target, int pages,
1329 PyObject *progress, const char *name,
1330 double sleep);
1331
1332 static PyObject *
1333 pysqlite_connection_backup(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1334 {
1335 PyObject *return_value = NULL;
1336 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1337
1338 #define NUM_KEYWORDS 5
1339 static struct {
1340 PyGC_Head _this_is_not_used;
1341 PyObject_VAR_HEAD
1342 Py_hash_t ob_hash;
1343 PyObject *ob_item[NUM_KEYWORDS];
1344 } _kwtuple = {
1345 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1346 .ob_hash = -1,
1347 .ob_item = { &_Py_ID(target), &_Py_ID(pages), &_Py_ID(progress), &_Py_ID(name), &_Py_ID(sleep), },
1348 };
1349 #undef NUM_KEYWORDS
1350 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1351
1352 #else // !Py_BUILD_CORE
1353 # define KWTUPLE NULL
1354 #endif // !Py_BUILD_CORE
1355
1356 static const char * const _keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
1357 static _PyArg_Parser _parser = {
1358 .keywords = _keywords,
1359 .fname = "backup",
1360 .kwtuple = KWTUPLE,
1361 };
1362 #undef KWTUPLE
1363 PyObject *argsbuf[5];
1364 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1365 pysqlite_Connection *target;
1366 int pages = -1;
1367 PyObject *progress = Py_None;
1368 const char *name = "main";
1369 double sleep = 0.25;
1370
1371 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1372 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1373 if (!args) {
1374 goto exit;
1375 }
1376 if (!PyObject_TypeCheck(args[0], clinic_state()->ConnectionType)) {
1377 _PyArg_BadArgument("backup", "argument 'target'", (clinic_state()->ConnectionType)->tp_name, args[0]);
1378 goto exit;
1379 }
1380 target = (pysqlite_Connection *)args[0];
1381 if (!noptargs) {
1382 goto skip_optional_kwonly;
1383 }
1384 if (args[1]) {
1385 pages = PyLong_AsInt(args[1]);
1386 if (pages == -1 && PyErr_Occurred()) {
1387 goto exit;
1388 }
1389 if (!--noptargs) {
1390 goto skip_optional_kwonly;
1391 }
1392 }
1393 if (args[2]) {
1394 progress = args[2];
1395 if (!--noptargs) {
1396 goto skip_optional_kwonly;
1397 }
1398 }
1399 if (args[3]) {
1400 if (!PyUnicode_Check(args[3])) {
1401 _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
1402 goto exit;
1403 }
1404 Py_ssize_t name_length;
1405 name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
1406 if (name == NULL) {
1407 goto exit;
1408 }
1409 if (strlen(name) != (size_t)name_length) {
1410 PyErr_SetString(PyExc_ValueError, "embedded null character");
1411 goto exit;
1412 }
1413 if (!--noptargs) {
1414 goto skip_optional_kwonly;
1415 }
1416 }
1417 if (PyFloat_CheckExact(args[4])) {
1418 sleep = PyFloat_AS_DOUBLE(args[4]);
1419 }
1420 else
1421 {
1422 sleep = PyFloat_AsDouble(args[4]);
1423 if (sleep == -1.0 && PyErr_Occurred()) {
1424 goto exit;
1425 }
1426 }
1427 skip_optional_kwonly:
1428 return_value = pysqlite_connection_backup_impl((pysqlite_Connection *)self, target, pages, progress, name, sleep);
1429
1430 exit:
1431 return return_value;
1432 }
1433
1434 PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
1435 "create_collation($self, name, callback, /)\n"
1436 "--\n"
1437 "\n"
1438 "Creates a collation function.");
1439
1440 #define PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF \
1441 {"create_collation", _PyCFunction_CAST(pysqlite_connection_create_collation), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_collation__doc__},
1442
1443 static PyObject *
1444 pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
1445 PyTypeObject *cls,
1446 const char *name,
1447 PyObject *callable);
1448
1449 static PyObject *
1450 pysqlite_connection_create_collation(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1451 {
1452 PyObject *return_value = NULL;
1453 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1454 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
1455 #else
1456 # define KWTUPLE NULL
1457 #endif
1458
1459 static const char * const _keywords[] = {"", "", NULL};
1460 static _PyArg_Parser _parser = {
1461 .keywords = _keywords,
1462 .fname = "create_collation",
1463 .kwtuple = KWTUPLE,
1464 };
1465 #undef KWTUPLE
1466 PyObject *argsbuf[2];
1467 const char *name;
1468 PyObject *callable;
1469
1470 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1471 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1472 if (!args) {
1473 goto exit;
1474 }
1475 if (!PyUnicode_Check(args[0])) {
1476 _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
1477 goto exit;
1478 }
1479 Py_ssize_t name_length;
1480 name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
1481 if (name == NULL) {
1482 goto exit;
1483 }
1484 if (strlen(name) != (size_t)name_length) {
1485 PyErr_SetString(PyExc_ValueError, "embedded null character");
1486 goto exit;
1487 }
1488 callable = args[1];
1489 return_value = pysqlite_connection_create_collation_impl((pysqlite_Connection *)self, cls, name, callable);
1490
1491 exit:
1492 return return_value;
1493 }
1494
1495 #if defined(PY_SQLITE_HAVE_SERIALIZE)
1496
1497 PyDoc_STRVAR(serialize__doc__,
1498 "serialize($self, /, *, name=\'main\')\n"
1499 "--\n"
1500 "\n"
1501 "Serialize a database into a byte string.\n"
1502 "\n"
1503 " name\n"
1504 " Which database to serialize.\n"
1505 "\n"
1506 "For an ordinary on-disk database file, the serialization is just\n"
1507 "a copy of the disk file. For an in-memory database or a \"temp\"\n"
1508 "database, the serialization is the same sequence of bytes which\n"
1509 "would be written to disk if that database were backed up to disk.");
1510
1511 #define SERIALIZE_METHODDEF \
1512 {"serialize", _PyCFunction_CAST(serialize), METH_FASTCALL|METH_KEYWORDS, serialize__doc__},
1513
1514 static PyObject *
1515 serialize_impl(pysqlite_Connection *self, const char *name);
1516
1517 static PyObject *
1518 serialize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1519 {
1520 PyObject *return_value = NULL;
1521 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1522
1523 #define NUM_KEYWORDS 1
1524 static struct {
1525 PyGC_Head _this_is_not_used;
1526 PyObject_VAR_HEAD
1527 Py_hash_t ob_hash;
1528 PyObject *ob_item[NUM_KEYWORDS];
1529 } _kwtuple = {
1530 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1531 .ob_hash = -1,
1532 .ob_item = { &_Py_ID(name), },
1533 };
1534 #undef NUM_KEYWORDS
1535 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1536
1537 #else // !Py_BUILD_CORE
1538 # define KWTUPLE NULL
1539 #endif // !Py_BUILD_CORE
1540
1541 static const char * const _keywords[] = {"name", NULL};
1542 static _PyArg_Parser _parser = {
1543 .keywords = _keywords,
1544 .fname = "serialize",
1545 .kwtuple = KWTUPLE,
1546 };
1547 #undef KWTUPLE
1548 PyObject *argsbuf[1];
1549 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1550 const char *name = "main";
1551
1552 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1553 /*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1554 if (!args) {
1555 goto exit;
1556 }
1557 if (!noptargs) {
1558 goto skip_optional_kwonly;
1559 }
1560 if (!PyUnicode_Check(args[0])) {
1561 _PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]);
1562 goto exit;
1563 }
1564 Py_ssize_t name_length;
1565 name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
1566 if (name == NULL) {
1567 goto exit;
1568 }
1569 if (strlen(name) != (size_t)name_length) {
1570 PyErr_SetString(PyExc_ValueError, "embedded null character");
1571 goto exit;
1572 }
1573 skip_optional_kwonly:
1574 return_value = serialize_impl((pysqlite_Connection *)self, name);
1575
1576 exit:
1577 return return_value;
1578 }
1579
1580 #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
1581
1582 #if defined(PY_SQLITE_HAVE_SERIALIZE)
1583
1584 PyDoc_STRVAR(deserialize__doc__,
1585 "deserialize($self, data, /, *, name=\'main\')\n"
1586 "--\n"
1587 "\n"
1588 "Load a serialized database.\n"
1589 "\n"
1590 " data\n"
1591 " The serialized database content.\n"
1592 " name\n"
1593 " Which database to reopen with the deserialization.\n"
1594 "\n"
1595 "The deserialize interface causes the database connection to\n"
1596 "disconnect from the target database, and then reopen it as\n"
1597 "an in-memory database based on the given serialized data.\n"
1598 "\n"
1599 "The deserialize interface will fail with SQLITE_BUSY if the database\n"
1600 "is currently in a read transaction or is involved in a backup\n"
1601 "operation.");
1602
1603 #define DESERIALIZE_METHODDEF \
1604 {"deserialize", _PyCFunction_CAST(deserialize), METH_FASTCALL|METH_KEYWORDS, deserialize__doc__},
1605
1606 static PyObject *
1607 deserialize_impl(pysqlite_Connection *self, Py_buffer *data,
1608 const char *name);
1609
1610 static PyObject *
1611 deserialize(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1612 {
1613 PyObject *return_value = NULL;
1614 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1615
1616 #define NUM_KEYWORDS 1
1617 static struct {
1618 PyGC_Head _this_is_not_used;
1619 PyObject_VAR_HEAD
1620 Py_hash_t ob_hash;
1621 PyObject *ob_item[NUM_KEYWORDS];
1622 } _kwtuple = {
1623 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1624 .ob_hash = -1,
1625 .ob_item = { &_Py_ID(name), },
1626 };
1627 #undef NUM_KEYWORDS
1628 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1629
1630 #else // !Py_BUILD_CORE
1631 # define KWTUPLE NULL
1632 #endif // !Py_BUILD_CORE
1633
1634 static const char * const _keywords[] = {"", "name", NULL};
1635 static _PyArg_Parser _parser = {
1636 .keywords = _keywords,
1637 .fname = "deserialize",
1638 .kwtuple = KWTUPLE,
1639 };
1640 #undef KWTUPLE
1641 PyObject *argsbuf[2];
1642 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
1643 Py_buffer data = {NULL, NULL};
1644 const char *name = "main";
1645
1646 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1647 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1648 if (!args) {
1649 goto exit;
1650 }
1651 if (PyUnicode_Check(args[0])) {
1652 Py_ssize_t len;
1653 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1654 if (ptr == NULL) {
1655 goto exit;
1656 }
1657 if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) {
1658 goto exit;
1659 }
1660 }
1661 else { /* any bytes-like object */
1662 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1663 goto exit;
1664 }
1665 }
1666 if (!noptargs) {
1667 goto skip_optional_kwonly;
1668 }
1669 if (!PyUnicode_Check(args[1])) {
1670 _PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]);
1671 goto exit;
1672 }
1673 Py_ssize_t name_length;
1674 name = PyUnicode_AsUTF8AndSize(args[1], &name_length);
1675 if (name == NULL) {
1676 goto exit;
1677 }
1678 if (strlen(name) != (size_t)name_length) {
1679 PyErr_SetString(PyExc_ValueError, "embedded null character");
1680 goto exit;
1681 }
1682 skip_optional_kwonly:
1683 return_value = deserialize_impl((pysqlite_Connection *)self, &data, name);
1684
1685 exit:
1686 /* Cleanup for data */
1687 if (data.obj) {
1688 PyBuffer_Release(&data);
1689 }
1690
1691 return return_value;
1692 }
1693
1694 #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
1695
1696 PyDoc_STRVAR(pysqlite_connection_enter__doc__,
1697 "__enter__($self, /)\n"
1698 "--\n"
1699 "\n"
1700 "Called when the connection is used as a context manager.\n"
1701 "\n"
1702 "Returns itself as a convenience to the caller.");
1703
1704 #define PYSQLITE_CONNECTION_ENTER_METHODDEF \
1705 {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS, pysqlite_connection_enter__doc__},
1706
1707 static PyObject *
1708 pysqlite_connection_enter_impl(pysqlite_Connection *self);
1709
1710 static PyObject *
1711 pysqlite_connection_enter(PyObject *self, PyObject *Py_UNUSED(ignored))
1712 {
1713 return pysqlite_connection_enter_impl((pysqlite_Connection *)self);
1714 }
1715
1716 PyDoc_STRVAR(pysqlite_connection_exit__doc__,
1717 "__exit__($self, type, value, traceback, /)\n"
1718 "--\n"
1719 "\n"
1720 "Called when the connection is used as a context manager.\n"
1721 "\n"
1722 "If there was any exception, a rollback takes place; otherwise we\n"
1723 "commit.");
1724
1725 #define PYSQLITE_CONNECTION_EXIT_METHODDEF \
1726 {"__exit__", _PyCFunction_CAST(pysqlite_connection_exit), METH_FASTCALL, pysqlite_connection_exit__doc__},
1727
1728 static PyObject *
1729 pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
1730 PyObject *exc_value, PyObject *exc_tb);
1731
1732 static PyObject *
1733 pysqlite_connection_exit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1734 {
1735 PyObject *return_value = NULL;
1736 PyObject *exc_type;
1737 PyObject *exc_value;
1738 PyObject *exc_tb;
1739
1740 if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
1741 goto exit;
1742 }
1743 exc_type = args[0];
1744 exc_value = args[1];
1745 exc_tb = args[2];
1746 return_value = pysqlite_connection_exit_impl((pysqlite_Connection *)self, exc_type, exc_value, exc_tb);
1747
1748 exit:
1749 return return_value;
1750 }
1751
1752 PyDoc_STRVAR(setlimit__doc__,
1753 "setlimit($self, category, limit, /)\n"
1754 "--\n"
1755 "\n"
1756 "Set connection run-time limits.\n"
1757 "\n"
1758 " category\n"
1759 " The limit category to be set.\n"
1760 " limit\n"
1761 " The new limit. If the new limit is a negative number, the limit\n"
1762 " is unchanged.\n"
1763 "\n"
1764 "Attempts to increase a limit above its hard upper bound are silently\n"
1765 "truncated to the hard upper bound. Regardless of whether or not the\n"
1766 "limit was changed, the prior value of the limit is returned.");
1767
1768 #define SETLIMIT_METHODDEF \
1769 {"setlimit", _PyCFunction_CAST(setlimit), METH_FASTCALL, setlimit__doc__},
1770
1771 static PyObject *
1772 setlimit_impl(pysqlite_Connection *self, int category, int limit);
1773
1774 static PyObject *
1775 setlimit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1776 {
1777 PyObject *return_value = NULL;
1778 int category;
1779 int limit;
1780
1781 if (!_PyArg_CheckPositional("setlimit", nargs, 2, 2)) {
1782 goto exit;
1783 }
1784 category = PyLong_AsInt(args[0]);
1785 if (category == -1 && PyErr_Occurred()) {
1786 goto exit;
1787 }
1788 limit = PyLong_AsInt(args[1]);
1789 if (limit == -1 && PyErr_Occurred()) {
1790 goto exit;
1791 }
1792 return_value = setlimit_impl((pysqlite_Connection *)self, category, limit);
1793
1794 exit:
1795 return return_value;
1796 }
1797
1798 PyDoc_STRVAR(getlimit__doc__,
1799 "getlimit($self, category, /)\n"
1800 "--\n"
1801 "\n"
1802 "Get connection run-time limits.\n"
1803 "\n"
1804 " category\n"
1805 " The limit category to be queried.");
1806
1807 #define GETLIMIT_METHODDEF \
1808 {"getlimit", (PyCFunction)getlimit, METH_O, getlimit__doc__},
1809
1810 static PyObject *
1811 getlimit_impl(pysqlite_Connection *self, int category);
1812
1813 static PyObject *
1814 getlimit(PyObject *self, PyObject *arg)
1815 {
1816 PyObject *return_value = NULL;
1817 int category;
1818
1819 category = PyLong_AsInt(arg);
1820 if (category == -1 && PyErr_Occurred()) {
1821 goto exit;
1822 }
1823 return_value = getlimit_impl((pysqlite_Connection *)self, category);
1824
1825 exit:
1826 return return_value;
1827 }
1828
1829 PyDoc_STRVAR(setconfig__doc__,
1830 "setconfig($self, op, enable=True, /)\n"
1831 "--\n"
1832 "\n"
1833 "Set a boolean connection configuration option.\n"
1834 "\n"
1835 " op\n"
1836 " The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes.");
1837
1838 #define SETCONFIG_METHODDEF \
1839 {"setconfig", _PyCFunction_CAST(setconfig), METH_FASTCALL, setconfig__doc__},
1840
1841 static PyObject *
1842 setconfig_impl(pysqlite_Connection *self, int op, int enable);
1843
1844 static PyObject *
1845 setconfig(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1846 {
1847 PyObject *return_value = NULL;
1848 int op;
1849 int enable = 1;
1850
1851 if (!_PyArg_CheckPositional("setconfig", nargs, 1, 2)) {
1852 goto exit;
1853 }
1854 op = PyLong_AsInt(args[0]);
1855 if (op == -1 && PyErr_Occurred()) {
1856 goto exit;
1857 }
1858 if (nargs < 2) {
1859 goto skip_optional;
1860 }
1861 enable = PyObject_IsTrue(args[1]);
1862 if (enable < 0) {
1863 goto exit;
1864 }
1865 skip_optional:
1866 return_value = setconfig_impl((pysqlite_Connection *)self, op, enable);
1867
1868 exit:
1869 return return_value;
1870 }
1871
1872 PyDoc_STRVAR(getconfig__doc__,
1873 "getconfig($self, op, /)\n"
1874 "--\n"
1875 "\n"
1876 "Query a boolean connection configuration option.\n"
1877 "\n"
1878 " op\n"
1879 " The configuration verb; one of the sqlite3.SQLITE_DBCONFIG codes.");
1880
1881 #define GETCONFIG_METHODDEF \
1882 {"getconfig", (PyCFunction)getconfig, METH_O, getconfig__doc__},
1883
1884 static int
1885 getconfig_impl(pysqlite_Connection *self, int op);
1886
1887 static PyObject *
1888 getconfig(PyObject *self, PyObject *arg)
1889 {
1890 PyObject *return_value = NULL;
1891 int op;
1892 int _return_value;
1893
1894 op = PyLong_AsInt(arg);
1895 if (op == -1 && PyErr_Occurred()) {
1896 goto exit;
1897 }
1898 _return_value = getconfig_impl((pysqlite_Connection *)self, op);
1899 if ((_return_value == -1) && PyErr_Occurred()) {
1900 goto exit;
1901 }
1902 return_value = PyBool_FromLong((long)_return_value);
1903
1904 exit:
1905 return return_value;
1906 }
1907
1908 #ifndef CREATE_WINDOW_FUNCTION_METHODDEF
1909 #define CREATE_WINDOW_FUNCTION_METHODDEF
1910 #endif /* !defined(CREATE_WINDOW_FUNCTION_METHODDEF) */
1911
1912 #ifndef PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
1913 #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
1914 #endif /* !defined(PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF) */
1915
1916 #ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
1917 #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
1918 #endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
1919
1920 #ifndef SERIALIZE_METHODDEF
1921 #define SERIALIZE_METHODDEF
1922 #endif /* !defined(SERIALIZE_METHODDEF) */
1923
1924 #ifndef DESERIALIZE_METHODDEF
1925 #define DESERIALIZE_METHODDEF
1926 #endif /* !defined(DESERIALIZE_METHODDEF) */
1927 /*[clinic end generated code: output=072e199b0fc4a271 input=a9049054013a1b77]*/