Skip to content

Commit e8790dc

Browse files
author
Erlend E. Aasland
committed
Convert _sqlite3.Cursor to Argument Clinic
1 parent 2edfc86 commit e8790dc

File tree

3 files changed

+423
-68
lines changed

3 files changed

+423
-68
lines changed

Modules/_sqlite/clinic/cursor.c.h

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
/*[clinic input]
2+
preserve
3+
[clinic start generated code]*/
4+
5+
static int
6+
pysqlite_cursor_init_impl(pysqlite_Cursor *self,
7+
pysqlite_Connection *connection);
8+
9+
static int
10+
pysqlite_cursor_init(PyObject *self, PyObject *args, PyObject *kwargs)
11+
{
12+
int return_value = -1;
13+
pysqlite_Connection *connection;
14+
15+
if (Py_IS_TYPE(self, pysqlite_CursorType) &&
16+
!_PyArg_NoKeywords("Cursor", kwargs)) {
17+
goto exit;
18+
}
19+
if (!_PyArg_CheckPositional("Cursor", PyTuple_GET_SIZE(args), 1, 1)) {
20+
goto exit;
21+
}
22+
if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), pysqlite_ConnectionType)) {
23+
_PyArg_BadArgument("Cursor", "argument 1", (pysqlite_ConnectionType)->tp_name, PyTuple_GET_ITEM(args, 0));
24+
goto exit;
25+
}
26+
connection = (pysqlite_Connection *)PyTuple_GET_ITEM(args, 0);
27+
return_value = pysqlite_cursor_init_impl((pysqlite_Cursor *)self, connection);
28+
29+
exit:
30+
return return_value;
31+
}
32+
33+
PyDoc_STRVAR(pysqlite_cursor_execute__doc__,
34+
"execute($self, sql, parameters=<unrepresentable>, /)\n"
35+
"--\n"
36+
"\n"
37+
"Executes a SQL statement.");
38+
39+
#define PYSQLITE_CURSOR_EXECUTE_METHODDEF \
40+
{"execute", (PyCFunction)(void(*)(void))pysqlite_cursor_execute, METH_FASTCALL, pysqlite_cursor_execute__doc__},
41+
42+
static PyObject *
43+
pysqlite_cursor_execute_impl(pysqlite_Cursor *self, PyObject *sql,
44+
PyObject *parameters);
45+
46+
static PyObject *
47+
pysqlite_cursor_execute(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
48+
{
49+
PyObject *return_value = NULL;
50+
PyObject *sql;
51+
PyObject *parameters = NULL;
52+
53+
if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
54+
goto exit;
55+
}
56+
if (!PyUnicode_Check(args[0])) {
57+
_PyArg_BadArgument("execute", "argument 1", "str", args[0]);
58+
goto exit;
59+
}
60+
if (PyUnicode_READY(args[0]) == -1) {
61+
goto exit;
62+
}
63+
sql = args[0];
64+
if (nargs < 2) {
65+
goto skip_optional;
66+
}
67+
parameters = args[1];
68+
skip_optional:
69+
return_value = pysqlite_cursor_execute_impl(self, sql, parameters);
70+
71+
exit:
72+
return return_value;
73+
}
74+
75+
PyDoc_STRVAR(pysqlite_cursor_executemany__doc__,
76+
"executemany($self, sql, parameters=<unrepresentable>, /)\n"
77+
"--\n"
78+
"\n"
79+
"Repeatedly executes a SQL statement.");
80+
81+
#define PYSQLITE_CURSOR_EXECUTEMANY_METHODDEF \
82+
{"executemany", (PyCFunction)(void(*)(void))pysqlite_cursor_executemany, METH_FASTCALL, pysqlite_cursor_executemany__doc__},
83+
84+
static PyObject *
85+
pysqlite_cursor_executemany_impl(pysqlite_Cursor *self, PyObject *sql,
86+
PyObject *parameters);
87+
88+
static PyObject *
89+
pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
90+
{
91+
PyObject *return_value = NULL;
92+
PyObject *sql;
93+
PyObject *parameters = NULL;
94+
95+
if (!_PyArg_CheckPositional("executemany", nargs, 1, 2)) {
96+
goto exit;
97+
}
98+
if (!PyUnicode_Check(args[0])) {
99+
_PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
100+
goto exit;
101+
}
102+
if (PyUnicode_READY(args[0]) == -1) {
103+
goto exit;
104+
}
105+
sql = args[0];
106+
if (nargs < 2) {
107+
goto skip_optional;
108+
}
109+
parameters = args[1];
110+
skip_optional:
111+
return_value = pysqlite_cursor_executemany_impl(self, sql, parameters);
112+
113+
exit:
114+
return return_value;
115+
}
116+
117+
PyDoc_STRVAR(pysqlite_cursor_executescript__doc__,
118+
"executescript($self, sql_script, /)\n"
119+
"--\n"
120+
"\n"
121+
"Executes a multiple SQL statements at once. Non-standard.");
122+
123+
#define PYSQLITE_CURSOR_EXECUTESCRIPT_METHODDEF \
124+
{"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_O, pysqlite_cursor_executescript__doc__},
125+
126+
PyDoc_STRVAR(pysqlite_cursor_fetchone__doc__,
127+
"fetchone($self, /)\n"
128+
"--\n"
129+
"\n"
130+
"Fetches one row from the resultset.");
131+
132+
#define PYSQLITE_CURSOR_FETCHONE_METHODDEF \
133+
{"fetchone", (PyCFunction)pysqlite_cursor_fetchone, METH_NOARGS, pysqlite_cursor_fetchone__doc__},
134+
135+
static PyObject *
136+
pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self);
137+
138+
static PyObject *
139+
pysqlite_cursor_fetchone(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
140+
{
141+
return pysqlite_cursor_fetchone_impl(self);
142+
}
143+
144+
PyDoc_STRVAR(pysqlite_cursor_fetchmany__doc__,
145+
"fetchmany($self, /, size=cursor.arraysize)\n"
146+
"--\n"
147+
"\n"
148+
"Fetches several rows from the resultset.");
149+
150+
#define PYSQLITE_CURSOR_FETCHMANY_METHODDEF \
151+
{"fetchmany", (PyCFunction)(void(*)(void))pysqlite_cursor_fetchmany, METH_FASTCALL|METH_KEYWORDS, pysqlite_cursor_fetchmany__doc__},
152+
153+
static PyObject *
154+
pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows);
155+
156+
static PyObject *
157+
pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
158+
{
159+
PyObject *return_value = NULL;
160+
static const char * const _keywords[] = {"size", NULL};
161+
static _PyArg_Parser _parser = {NULL, _keywords, "fetchmany", 0};
162+
PyObject *argsbuf[1];
163+
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
164+
int maxrows = self->arraysize;
165+
166+
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
167+
if (!args) {
168+
goto exit;
169+
}
170+
if (!noptargs) {
171+
goto skip_optional_pos;
172+
}
173+
maxrows = _PyLong_AsInt(args[0]);
174+
if (maxrows == -1 && PyErr_Occurred()) {
175+
goto exit;
176+
}
177+
skip_optional_pos:
178+
return_value = pysqlite_cursor_fetchmany_impl(self, maxrows);
179+
180+
exit:
181+
return return_value;
182+
}
183+
184+
PyDoc_STRVAR(pysqlite_cursor_fetchall__doc__,
185+
"fetchall($self, /)\n"
186+
"--\n"
187+
"\n"
188+
"Fetches all rows from the resultset.");
189+
190+
#define PYSQLITE_CURSOR_FETCHALL_METHODDEF \
191+
{"fetchall", (PyCFunction)pysqlite_cursor_fetchall, METH_NOARGS, pysqlite_cursor_fetchall__doc__},
192+
193+
static PyObject *
194+
pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self);
195+
196+
static PyObject *
197+
pysqlite_cursor_fetchall(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
198+
{
199+
return pysqlite_cursor_fetchall_impl(self);
200+
}
201+
202+
PyDoc_STRVAR(pysqlite_cursor_setinputsizes__doc__,
203+
"setinputsizes($self, sizes=None, /)\n"
204+
"--\n"
205+
"\n"
206+
"Required by DB-API. Does nothing in pysqlite.");
207+
208+
#define PYSQLITE_CURSOR_SETINPUTSIZES_METHODDEF \
209+
{"setinputsizes", (PyCFunction)(void(*)(void))pysqlite_cursor_setinputsizes, METH_FASTCALL, pysqlite_cursor_setinputsizes__doc__},
210+
211+
static PyObject *
212+
pysqlite_cursor_setinputsizes_impl(pysqlite_Cursor *self, PyObject *sizes);
213+
214+
static PyObject *
215+
pysqlite_cursor_setinputsizes(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
216+
{
217+
PyObject *return_value = NULL;
218+
PyObject *sizes = Py_None;
219+
220+
if (!_PyArg_CheckPositional("setinputsizes", nargs, 0, 1)) {
221+
goto exit;
222+
}
223+
if (nargs < 1) {
224+
goto skip_optional;
225+
}
226+
sizes = args[0];
227+
skip_optional:
228+
return_value = pysqlite_cursor_setinputsizes_impl(self, sizes);
229+
230+
exit:
231+
return return_value;
232+
}
233+
234+
PyDoc_STRVAR(pysqlite_cursor_setoutputsize__doc__,
235+
"setoutputsize($self, size, column=None, /)\n"
236+
"--\n"
237+
"\n"
238+
"Required by DB-API. Does nothing in pysqlite.");
239+
240+
#define PYSQLITE_CURSOR_SETOUTPUTSIZE_METHODDEF \
241+
{"setoutputsize", (PyCFunction)(void(*)(void))pysqlite_cursor_setoutputsize, METH_FASTCALL, pysqlite_cursor_setoutputsize__doc__},
242+
243+
static PyObject *
244+
pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
245+
PyObject *column);
246+
247+
static PyObject *
248+
pysqlite_cursor_setoutputsize(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
249+
{
250+
PyObject *return_value = NULL;
251+
PyObject *size;
252+
PyObject *column = Py_None;
253+
254+
if (!_PyArg_CheckPositional("setoutputsize", nargs, 1, 2)) {
255+
goto exit;
256+
}
257+
size = args[0];
258+
if (nargs < 2) {
259+
goto skip_optional;
260+
}
261+
column = args[1];
262+
skip_optional:
263+
return_value = pysqlite_cursor_setoutputsize_impl(self, size, column);
264+
265+
exit:
266+
return return_value;
267+
}
268+
269+
PyDoc_STRVAR(pysqlite_cursor_close__doc__,
270+
"close($self, /)\n"
271+
"--\n"
272+
"\n"
273+
"Closes the cursor.");
274+
275+
#define PYSQLITE_CURSOR_CLOSE_METHODDEF \
276+
{"close", (PyCFunction)pysqlite_cursor_close, METH_NOARGS, pysqlite_cursor_close__doc__},
277+
278+
static PyObject *
279+
pysqlite_cursor_close_impl(pysqlite_Cursor *self);
280+
281+
static PyObject *
282+
pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
283+
{
284+
return pysqlite_cursor_close_impl(self);
285+
}
286+
/*[clinic end generated code: output=29b5b24ed34ba996 input=a9049054013a1b77]*/

0 commit comments

Comments
 (0)