Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Modules/_sqlite/clinic/cursor.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_cursor_init_impl(pysqlite_Cursor *self,
13
pysqlite_Connection *connection);
14
15
static int
16
pysqlite_cursor_init(PyObject *self, PyObject *args, PyObject *kwargs)
17
{
18
int return_value = -1;
19
PyTypeObject *base_tp = clinic_state()->CursorType;
20
pysqlite_Connection *connection;
21
22
if ((Py_IS_TYPE(self, base_tp) ||
23
Py_TYPE(self)->tp_new == base_tp->tp_new) &&
24
!_PyArg_NoKeywords("Cursor", kwargs)) {
25
goto exit;
26
}
27
if (!_PyArg_CheckPositional("Cursor", PyTuple_GET_SIZE(args), 1, 1)) {
28
goto exit;
29
}
30
if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), clinic_state()->ConnectionType)) {
31
_PyArg_BadArgument("Cursor", "argument 1", (clinic_state()->ConnectionType)->tp_name, PyTuple_GET_ITEM(args, 0));
32
goto exit;
33
}
34
connection = (pysqlite_Connection *)PyTuple_GET_ITEM(args, 0);
35
return_value = pysqlite_cursor_init_impl((pysqlite_Cursor *)self, connection);
36
37
exit:
38
return return_value;
39
}
40
41
PyDoc_STRVAR(pysqlite_cursor_execute__doc__,
42
"execute($self, sql, parameters=(), /)\n"
43
"--\n"
44
"\n"
45
"Executes an SQL statement.");
46
47
#define PYSQLITE_CURSOR_EXECUTE_METHODDEF \
48
{"execute", _PyCFunction_CAST(pysqlite_cursor_execute), METH_FASTCALL, pysqlite_cursor_execute__doc__},
49
50
static PyObject *
51
pysqlite_cursor_execute_impl(pysqlite_Cursor *self, PyObject *sql,
52
PyObject *parameters);
53
54
static PyObject *
55
pysqlite_cursor_execute(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
56
{
57
PyObject *return_value = NULL;
58
PyObject *sql;
59
PyObject *parameters = NULL;
60
61
if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
62
goto exit;
63
}
64
if (!PyUnicode_Check(args[0])) {
65
_PyArg_BadArgument("execute", "argument 1", "str", args[0]);
66
goto exit;
67
}
68
sql = args[0];
69
if (nargs < 2) {
70
goto skip_optional;
71
}
72
parameters = args[1];
73
skip_optional:
74
return_value = pysqlite_cursor_execute_impl(self, sql, parameters);
75
76
exit:
77
return return_value;
78
}
79
80
PyDoc_STRVAR(pysqlite_cursor_executemany__doc__,
81
"executemany($self, sql, seq_of_parameters, /)\n"
82
"--\n"
83
"\n"
84
"Repeatedly executes an SQL statement.");
85
86
#define PYSQLITE_CURSOR_EXECUTEMANY_METHODDEF \
87
{"executemany", _PyCFunction_CAST(pysqlite_cursor_executemany), METH_FASTCALL, pysqlite_cursor_executemany__doc__},
88
89
static PyObject *
90
pysqlite_cursor_executemany_impl(pysqlite_Cursor *self, PyObject *sql,
91
PyObject *seq_of_parameters);
92
93
static PyObject *
94
pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
95
{
96
PyObject *return_value = NULL;
97
PyObject *sql;
98
PyObject *seq_of_parameters;
99
100
if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
101
goto exit;
102
}
103
if (!PyUnicode_Check(args[0])) {
104
_PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
105
goto exit;
106
}
107
sql = args[0];
108
seq_of_parameters = args[1];
109
return_value = pysqlite_cursor_executemany_impl(self, sql, seq_of_parameters);
110
111
exit:
112
return return_value;
113
}
114
115
PyDoc_STRVAR(pysqlite_cursor_executescript__doc__,
116
"executescript($self, sql_script, /)\n"
117
"--\n"
118
"\n"
119
"Executes multiple SQL statements at once.");
120
121
#define PYSQLITE_CURSOR_EXECUTESCRIPT_METHODDEF \
122
{"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_O, pysqlite_cursor_executescript__doc__},
123
124
static PyObject *
125
pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
126
const char *sql_script);
127
128
static PyObject *
129
pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
130
{
131
PyObject *return_value = NULL;
132
const char *sql_script;
133
134
if (!PyUnicode_Check(arg)) {
135
_PyArg_BadArgument("executescript", "argument", "str", arg);
136
goto exit;
137
}
138
Py_ssize_t sql_script_length;
139
sql_script = PyUnicode_AsUTF8AndSize(arg, &sql_script_length);
140
if (sql_script == NULL) {
141
goto exit;
142
}
143
if (strlen(sql_script) != (size_t)sql_script_length) {
144
PyErr_SetString(PyExc_ValueError, "embedded null character");
145
goto exit;
146
}
147
return_value = pysqlite_cursor_executescript_impl(self, sql_script);
148
149
exit:
150
return return_value;
151
}
152
153
PyDoc_STRVAR(pysqlite_cursor_fetchone__doc__,
154
"fetchone($self, /)\n"
155
"--\n"
156
"\n"
157
"Fetches one row from the resultset.");
158
159
#define PYSQLITE_CURSOR_FETCHONE_METHODDEF \
160
{"fetchone", (PyCFunction)pysqlite_cursor_fetchone, METH_NOARGS, pysqlite_cursor_fetchone__doc__},
161
162
static PyObject *
163
pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self);
164
165
static PyObject *
166
pysqlite_cursor_fetchone(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
167
{
168
return pysqlite_cursor_fetchone_impl(self);
169
}
170
171
PyDoc_STRVAR(pysqlite_cursor_fetchmany__doc__,
172
"fetchmany($self, /, size=1)\n"
173
"--\n"
174
"\n"
175
"Fetches several rows from the resultset.\n"
176
"\n"
177
" size\n"
178
" The default value is set by the Cursor.arraysize attribute.");
179
180
#define PYSQLITE_CURSOR_FETCHMANY_METHODDEF \
181
{"fetchmany", _PyCFunction_CAST(pysqlite_cursor_fetchmany), METH_FASTCALL|METH_KEYWORDS, pysqlite_cursor_fetchmany__doc__},
182
183
static PyObject *
184
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows);
185
186
static PyObject *
187
pysqlite_cursor_fetchmany(pysqlite_Cursor *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
PyObject *ob_item[NUM_KEYWORDS];
197
} _kwtuple = {
198
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
199
.ob_item = { &_Py_ID(size), },
200
};
201
#undef NUM_KEYWORDS
202
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
203
204
#else // !Py_BUILD_CORE
205
# define KWTUPLE NULL
206
#endif // !Py_BUILD_CORE
207
208
static const char * const _keywords[] = {"size", NULL};
209
static _PyArg_Parser _parser = {
210
.keywords = _keywords,
211
.fname = "fetchmany",
212
.kwtuple = KWTUPLE,
213
};
214
#undef KWTUPLE
215
PyObject *argsbuf[1];
216
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
217
int maxrows = self->arraysize;
218
219
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
220
if (!args) {
221
goto exit;
222
}
223
if (!noptargs) {
224
goto skip_optional_pos;
225
}
226
maxrows = _PyLong_AsInt(args[0]);
227
if (maxrows == -1 && PyErr_Occurred()) {
228
goto exit;
229
}
230
skip_optional_pos:
231
return_value = pysqlite_cursor_fetchmany_impl(self, maxrows);
232
233
exit:
234
return return_value;
235
}
236
237
PyDoc_STRVAR(pysqlite_cursor_fetchall__doc__,
238
"fetchall($self, /)\n"
239
"--\n"
240
"\n"
241
"Fetches all rows from the resultset.");
242
243
#define PYSQLITE_CURSOR_FETCHALL_METHODDEF \
244
{"fetchall", (PyCFunction)pysqlite_cursor_fetchall, METH_NOARGS, pysqlite_cursor_fetchall__doc__},
245
246
static PyObject *
247
pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self);
248
249
static PyObject *
250
pysqlite_cursor_fetchall(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
251
{
252
return pysqlite_cursor_fetchall_impl(self);
253
}
254
255
PyDoc_STRVAR(pysqlite_cursor_setinputsizes__doc__,
256
"setinputsizes($self, sizes, /)\n"
257
"--\n"
258
"\n"
259
"Required by DB-API. Does nothing in sqlite3.");
260
261
#define PYSQLITE_CURSOR_SETINPUTSIZES_METHODDEF \
262
{"setinputsizes", (PyCFunction)pysqlite_cursor_setinputsizes, METH_O, pysqlite_cursor_setinputsizes__doc__},
263
264
PyDoc_STRVAR(pysqlite_cursor_setoutputsize__doc__,
265
"setoutputsize($self, size, column=None, /)\n"
266
"--\n"
267
"\n"
268
"Required by DB-API. Does nothing in sqlite3.");
269
270
#define PYSQLITE_CURSOR_SETOUTPUTSIZE_METHODDEF \
271
{"setoutputsize", _PyCFunction_CAST(pysqlite_cursor_setoutputsize), METH_FASTCALL, pysqlite_cursor_setoutputsize__doc__},
272
273
static PyObject *
274
pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
275
PyObject *column);
276
277
static PyObject *
278
pysqlite_cursor_setoutputsize(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
279
{
280
PyObject *return_value = NULL;
281
PyObject *size;
282
PyObject *column = Py_None;
283
284
if (!_PyArg_CheckPositional("setoutputsize", nargs, 1, 2)) {
285
goto exit;
286
}
287
size = args[0];
288
if (nargs < 2) {
289
goto skip_optional;
290
}
291
column = args[1];
292
skip_optional:
293
return_value = pysqlite_cursor_setoutputsize_impl(self, size, column);
294
295
exit:
296
return return_value;
297
}
298
299
PyDoc_STRVAR(pysqlite_cursor_close__doc__,
300
"close($self, /)\n"
301
"--\n"
302
"\n"
303
"Closes the cursor.");
304
305
#define PYSQLITE_CURSOR_CLOSE_METHODDEF \
306
{"close", (PyCFunction)pysqlite_cursor_close, METH_NOARGS, pysqlite_cursor_close__doc__},
307
308
static PyObject *
309
pysqlite_cursor_close_impl(pysqlite_Cursor *self);
310
311
static PyObject *
312
pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
313
{
314
return pysqlite_cursor_close_impl(self);
315
}
316
/*[clinic end generated code: output=831f7bc5256526d3 input=a9049054013a1b77]*/
317
318