Skip to content

Commit d5baf45

Browse files
author
Erlend E. Aasland
committed
Convert Cursor
1 parent d21accb commit d5baf45

File tree

3 files changed

+424
-68
lines changed

3 files changed

+424
-68
lines changed

Modules/_sqlite/clinic/cursor.c.h

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

0 commit comments

Comments
 (0)