LCOV - code coverage report
Current view: top level - Modules/_sqlite/clinic - cursor.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 0 97 0.0 %
Date: 2023-03-20 08:15:36 Functions: 0 9 0.0 %
Branches: 0 70 0.0 %

           Branch data     Line data    Source code
       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                 :          0 : pysqlite_cursor_init(PyObject *self, PyObject *args, PyObject *kwargs)
      17                 :            : {
      18                 :          0 :     int return_value = -1;
      19                 :          0 :     PyTypeObject *base_tp = clinic_state()->CursorType;
      20                 :            :     pysqlite_Connection *connection;
      21                 :            : 
      22         [ #  # ]:          0 :     if ((Py_IS_TYPE(self, base_tp) ||
      23   [ #  #  #  # ]:          0 :          Py_TYPE(self)->tp_new == base_tp->tp_new) &&
      24         [ #  # ]:          0 :         !_PyArg_NoKeywords("Cursor", kwargs)) {
      25                 :          0 :         goto exit;
      26                 :            :     }
      27   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("Cursor", PyTuple_GET_SIZE(args), 1, 1)) {
                   #  # ]
      28                 :          0 :         goto exit;
      29                 :            :     }
      30         [ #  # ]:          0 :     if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), clinic_state()->ConnectionType)) {
      31                 :          0 :         _PyArg_BadArgument("Cursor", "argument 1", (clinic_state()->ConnectionType)->tp_name, PyTuple_GET_ITEM(args, 0));
      32                 :          0 :         goto exit;
      33                 :            :     }
      34                 :          0 :     connection = (pysqlite_Connection *)PyTuple_GET_ITEM(args, 0);
      35                 :          0 :     return_value = pysqlite_cursor_init_impl((pysqlite_Cursor *)self, connection);
      36                 :            : 
      37                 :          0 : exit:
      38                 :          0 :     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                 :          0 : pysqlite_cursor_execute(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
      56                 :            : {
      57                 :          0 :     PyObject *return_value = NULL;
      58                 :            :     PyObject *sql;
      59                 :          0 :     PyObject *parameters = NULL;
      60                 :            : 
      61   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
                   #  # ]
      62                 :          0 :         goto exit;
      63                 :            :     }
      64         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
      65                 :          0 :         _PyArg_BadArgument("execute", "argument 1", "str", args[0]);
      66                 :          0 :         goto exit;
      67                 :            :     }
      68         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
      69                 :          0 :         goto exit;
      70                 :            :     }
      71                 :          0 :     sql = args[0];
      72         [ #  # ]:          0 :     if (nargs < 2) {
      73                 :          0 :         goto skip_optional;
      74                 :            :     }
      75                 :          0 :     parameters = args[1];
      76                 :          0 : skip_optional:
      77                 :          0 :     return_value = pysqlite_cursor_execute_impl(self, sql, parameters);
      78                 :            : 
      79                 :          0 : exit:
      80                 :          0 :     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                 :          0 : pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
      98                 :            : {
      99                 :          0 :     PyObject *return_value = NULL;
     100                 :            :     PyObject *sql;
     101                 :            :     PyObject *seq_of_parameters;
     102                 :            : 
     103   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
                   #  # ]
     104                 :          0 :         goto exit;
     105                 :            :     }
     106         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
     107                 :          0 :         _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
     108                 :          0 :         goto exit;
     109                 :            :     }
     110         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
     111                 :          0 :         goto exit;
     112                 :            :     }
     113                 :          0 :     sql = args[0];
     114                 :          0 :     seq_of_parameters = args[1];
     115                 :          0 :     return_value = pysqlite_cursor_executemany_impl(self, sql, seq_of_parameters);
     116                 :            : 
     117                 :          0 : exit:
     118                 :          0 :     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                 :          0 : pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *arg)
     136                 :            : {
     137                 :          0 :     PyObject *return_value = NULL;
     138                 :            :     const char *sql_script;
     139                 :            : 
     140         [ #  # ]:          0 :     if (!PyUnicode_Check(arg)) {
     141                 :          0 :         _PyArg_BadArgument("executescript", "argument", "str", arg);
     142                 :          0 :         goto exit;
     143                 :            :     }
     144                 :            :     Py_ssize_t sql_script_length;
     145                 :          0 :     sql_script = PyUnicode_AsUTF8AndSize(arg, &sql_script_length);
     146         [ #  # ]:          0 :     if (sql_script == NULL) {
     147                 :          0 :         goto exit;
     148                 :            :     }
     149         [ #  # ]:          0 :     if (strlen(sql_script) != (size_t)sql_script_length) {
     150                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     151                 :          0 :         goto exit;
     152                 :            :     }
     153                 :          0 :     return_value = pysqlite_cursor_executescript_impl(self, sql_script);
     154                 :            : 
     155                 :          0 : exit:
     156                 :          0 :     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                 :          0 : pysqlite_cursor_fetchone(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
     173                 :            : {
     174                 :          0 :     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                 :          0 : pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     194                 :            : {
     195                 :          0 :     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         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     223                 :          0 :     int maxrows = self->arraysize;
     224                 :            : 
     225   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
             #  #  #  # ]
     226         [ #  # ]:          0 :     if (!args) {
     227                 :          0 :         goto exit;
     228                 :            :     }
     229         [ #  # ]:          0 :     if (!noptargs) {
     230                 :          0 :         goto skip_optional_pos;
     231                 :            :     }
     232                 :          0 :     maxrows = _PyLong_AsInt(args[0]);
     233   [ #  #  #  # ]:          0 :     if (maxrows == -1 && PyErr_Occurred()) {
     234                 :          0 :         goto exit;
     235                 :            :     }
     236                 :          0 : skip_optional_pos:
     237                 :          0 :     return_value = pysqlite_cursor_fetchmany_impl(self, maxrows);
     238                 :            : 
     239                 :          0 : exit:
     240                 :          0 :     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                 :          0 : pysqlite_cursor_fetchall(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
     257                 :            : {
     258                 :          0 :     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                 :          0 : pysqlite_cursor_setoutputsize(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
     285                 :            : {
     286                 :          0 :     PyObject *return_value = NULL;
     287                 :            :     PyObject *size;
     288                 :          0 :     PyObject *column = Py_None;
     289                 :            : 
     290   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("setoutputsize", nargs, 1, 2)) {
                   #  # ]
     291                 :          0 :         goto exit;
     292                 :            :     }
     293                 :          0 :     size = args[0];
     294         [ #  # ]:          0 :     if (nargs < 2) {
     295                 :          0 :         goto skip_optional;
     296                 :            :     }
     297                 :          0 :     column = args[1];
     298                 :          0 : skip_optional:
     299                 :          0 :     return_value = pysqlite_cursor_setoutputsize_impl(self, size, column);
     300                 :            : 
     301                 :          0 : exit:
     302                 :          0 :     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                 :          0 : pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
     319                 :            : {
     320                 :          0 :     return pysqlite_cursor_close_impl(self);
     321                 :            : }
     322                 :            : /*[clinic end generated code: output=1f82e3c9791bb9a5 input=a9049054013a1b77]*/

Generated by: LCOV version 1.14