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