(root)/
Python-3.12.0/
Modules/
_sqlite/
clinic/
cursor.c.h
       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      if (PyUnicode_READY(args[0]) == -1) {
      69          goto exit;
      70      }
      71      sql = args[0];
      72      if (nargs < 2) {
      73          goto skip_optional;
      74      }
      75      parameters = args[1];
      76  skip_optional:
      77      return_value = pysqlite_cursor_execute_impl(self, sql, parameters);
      78  
      79  exit:
      80      return return_value;
      81  }
      82  
      83  PyDoc_STRVAR(pysqlite_cursor_executemany__doc__,
      84  "executemany($self, sql, seq_of_parameters, /)\n"
      85  "--\n"
      86  "\n"
      87  "Repeatedly executes an SQL statement.");
      88  
      89  #define PYSQLITE_CURSOR_EXECUTEMANY_METHODDEF    \
      90      {"executemany", _PyCFunction_CAST(pysqlite_cursor_executemany), METH_FASTCALL, pysqlite_cursor_executemany__doc__},
      91  
      92  static PyObject *
      93  pysqlite_cursor_executemany_impl(pysqlite_Cursor *self, PyObject *sql,
      94                                   PyObject *seq_of_parameters);
      95  
      96  static PyObject *
      97  pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
      98  {
      99      PyObject *return_value = NULL;
     100      PyObject *sql;
     101      PyObject *seq_of_parameters;
     102  
     103      if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
     104          goto exit;
     105      }
     106      if (!PyUnicode_Check(args[0])) {
     107          _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
     108          goto exit;
     109      }
     110      if (PyUnicode_READY(args[0]) == -1) {
     111          goto exit;
     112      }
     113      sql = args[0];
     114      seq_of_parameters = args[1];
     115      return_value = pysqlite_cursor_executemany_impl(self, sql, seq_of_parameters);
     116  
     117  exit:
     118      return return_value;
     119  }
     120  
     121  PyDoc_STRVAR(pysqlite_cursor_executescript__doc__,
     122  "executescript($self, sql_script, /)\n"
     123  "--\n"
     124  "\n"
     125  "Executes multiple SQL statements at once.");
     126  
     127  #define PYSQLITE_CURSOR_EXECUTESCRIPT_METHODDEF    \
     128      {"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_O, pysqlite_cursor_executescript__doc__},
     129  
     130  static PyObject *
     131  pysqlite_cursor_executescript_impl(pysqlite_Cursor *self,
     132                                     const char *sql_script);
     133  
     134  static PyObject *
     135  pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
     136  {
     137      PyObject *return_value = NULL;
     138      const char *sql_script;
     139  
     140      if (!PyUnicode_Check(arg)) {
     141          _PyArg_BadArgument("executescript", "argument", "str", arg);
     142          goto exit;
     143      }
     144      Py_ssize_t sql_script_length;
     145      sql_script = PyUnicode_AsUTF8AndSize(arg, &sql_script_length);
     146      if (sql_script == NULL) {
     147          goto exit;
     148      }
     149      if (strlen(sql_script) != (size_t)sql_script_length) {
     150          PyErr_SetString(PyExc_ValueError, "embedded null character");
     151          goto exit;
     152      }
     153      return_value = pysqlite_cursor_executescript_impl(self, sql_script);
     154  
     155  exit:
     156      return return_value;
     157  }
     158  
     159  PyDoc_STRVAR(pysqlite_cursor_fetchone__doc__,
     160  "fetchone($self, /)\n"
     161  "--\n"
     162  "\n"
     163  "Fetches one row from the resultset.");
     164  
     165  #define PYSQLITE_CURSOR_FETCHONE_METHODDEF    \
     166      {"fetchone", (PyCFunction)pysqlite_cursor_fetchone, METH_NOARGS, pysqlite_cursor_fetchone__doc__},
     167  
     168  static PyObject *
     169  pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self);
     170  
     171  static PyObject *
     172  pysqlite_cursor_fetchone(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
     173  {
     174      return pysqlite_cursor_fetchone_impl(self);
     175  }
     176  
     177  PyDoc_STRVAR(pysqlite_cursor_fetchmany__doc__,
     178  "fetchmany($self, /, size=1)\n"
     179  "--\n"
     180  "\n"
     181  "Fetches several rows from the resultset.\n"
     182  "\n"
     183  "  size\n"
     184  "    The default value is set by the Cursor.arraysize attribute.");
     185  
     186  #define PYSQLITE_CURSOR_FETCHMANY_METHODDEF    \
     187      {"fetchmany", _PyCFunction_CAST(pysqlite_cursor_fetchmany), METH_FASTCALL|METH_KEYWORDS, pysqlite_cursor_fetchmany__doc__},
     188  
     189  static PyObject *
     190  pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows);
     191  
     192  static PyObject *
     193  pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     194  {
     195      PyObject *return_value = NULL;
     196      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     197  
     198      #define NUM_KEYWORDS 1
     199      static struct {
     200          PyGC_Head _this_is_not_used;
     201          PyObject_VAR_HEAD
     202          PyObject *ob_item[NUM_KEYWORDS];
     203      } _kwtuple = {
     204          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     205          .ob_item = { &_Py_ID(size), },
     206      };
     207      #undef NUM_KEYWORDS
     208      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     209  
     210      #else  // !Py_BUILD_CORE
     211      #  define KWTUPLE NULL
     212      #endif  // !Py_BUILD_CORE
     213  
     214      static const char * const _keywords[] = {"size", NULL};
     215      static _PyArg_Parser _parser = {
     216          .keywords = _keywords,
     217          .fname = "fetchmany",
     218          .kwtuple = KWTUPLE,
     219      };
     220      #undef KWTUPLE
     221      PyObject *argsbuf[1];
     222      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     223      int maxrows = self->arraysize;
     224  
     225      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     226      if (!args) {
     227          goto exit;
     228      }
     229      if (!noptargs) {
     230          goto skip_optional_pos;
     231      }
     232      maxrows = _PyLong_AsInt(args[0]);
     233      if (maxrows == -1 && PyErr_Occurred()) {
     234          goto exit;
     235      }
     236  skip_optional_pos:
     237      return_value = pysqlite_cursor_fetchmany_impl(self, maxrows);
     238  
     239  exit:
     240      return return_value;
     241  }
     242  
     243  PyDoc_STRVAR(pysqlite_cursor_fetchall__doc__,
     244  "fetchall($self, /)\n"
     245  "--\n"
     246  "\n"
     247  "Fetches all rows from the resultset.");
     248  
     249  #define PYSQLITE_CURSOR_FETCHALL_METHODDEF    \
     250      {"fetchall", (PyCFunction)pysqlite_cursor_fetchall, METH_NOARGS, pysqlite_cursor_fetchall__doc__},
     251  
     252  static PyObject *
     253  pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self);
     254  
     255  static PyObject *
     256  pysqlite_cursor_fetchall(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
     257  {
     258      return pysqlite_cursor_fetchall_impl(self);
     259  }
     260  
     261  PyDoc_STRVAR(pysqlite_cursor_setinputsizes__doc__,
     262  "setinputsizes($self, sizes, /)\n"
     263  "--\n"
     264  "\n"
     265  "Required by DB-API. Does nothing in sqlite3.");
     266  
     267  #define PYSQLITE_CURSOR_SETINPUTSIZES_METHODDEF    \
     268      {"setinputsizes", (PyCFunction)pysqlite_cursor_setinputsizes, METH_O, pysqlite_cursor_setinputsizes__doc__},
     269  
     270  PyDoc_STRVAR(pysqlite_cursor_setoutputsize__doc__,
     271  "setoutputsize($self, size, column=None, /)\n"
     272  "--\n"
     273  "\n"
     274  "Required by DB-API. Does nothing in sqlite3.");
     275  
     276  #define PYSQLITE_CURSOR_SETOUTPUTSIZE_METHODDEF    \
     277      {"setoutputsize", _PyCFunction_CAST(pysqlite_cursor_setoutputsize), METH_FASTCALL, pysqlite_cursor_setoutputsize__doc__},
     278  
     279  static PyObject *
     280  pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
     281                                     PyObject *column);
     282  
     283  static PyObject *
     284  pysqlite_cursor_setoutputsize(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
     285  {
     286      PyObject *return_value = NULL;
     287      PyObject *size;
     288      PyObject *column = Py_None;
     289  
     290      if (!_PyArg_CheckPositional("setoutputsize", nargs, 1, 2)) {
     291          goto exit;
     292      }
     293      size = args[0];
     294      if (nargs < 2) {
     295          goto skip_optional;
     296      }
     297      column = args[1];
     298  skip_optional:
     299      return_value = pysqlite_cursor_setoutputsize_impl(self, size, column);
     300  
     301  exit:
     302      return return_value;
     303  }
     304  
     305  PyDoc_STRVAR(pysqlite_cursor_close__doc__,
     306  "close($self, /)\n"
     307  "--\n"
     308  "\n"
     309  "Closes the cursor.");
     310  
     311  #define PYSQLITE_CURSOR_CLOSE_METHODDEF    \
     312      {"close", (PyCFunction)pysqlite_cursor_close, METH_NOARGS, pysqlite_cursor_close__doc__},
     313  
     314  static PyObject *
     315  pysqlite_cursor_close_impl(pysqlite_Cursor *self);
     316  
     317  static PyObject *
     318  pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
     319  {
     320      return pysqlite_cursor_close_impl(self);
     321  }
     322  /*[clinic end generated code: output=1f82e3c9791bb9a5 input=a9049054013a1b77]*/