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