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