LCOV - code coverage report
Current view: top level - Modules/_sqlite/clinic - connection.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 0 373 0.0 %
Date: 2023-03-20 08:15:36 Functions: 0 22 0.0 %
Branches: 0 328 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_connection_init_impl(pysqlite_Connection *self, PyObject *database,
      13                 :            :                               double timeout, int detect_types,
      14                 :            :                               const char *isolation_level,
      15                 :            :                               int check_same_thread, PyObject *factory,
      16                 :            :                               int cache_size, int uri,
      17                 :            :                               enum autocommit_mode autocommit);
      18                 :            : 
      19                 :            : static int
      20                 :          0 : pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
      21                 :            : {
      22                 :          0 :     int return_value = -1;
      23                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      24                 :            : 
      25                 :            :     #define NUM_KEYWORDS 9
      26                 :            :     static struct {
      27                 :            :         PyGC_Head _this_is_not_used;
      28                 :            :         PyObject_VAR_HEAD
      29                 :            :         PyObject *ob_item[NUM_KEYWORDS];
      30                 :            :     } _kwtuple = {
      31                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
      32                 :            :         .ob_item = { &_Py_ID(database), &_Py_ID(timeout), &_Py_ID(detect_types), &_Py_ID(isolation_level), &_Py_ID(check_same_thread), &_Py_ID(factory), &_Py_ID(cached_statements), &_Py_ID(uri), &_Py_ID(autocommit), },
      33                 :            :     };
      34                 :            :     #undef NUM_KEYWORDS
      35                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
      36                 :            : 
      37                 :            :     #else  // !Py_BUILD_CORE
      38                 :            :     #  define KWTUPLE NULL
      39                 :            :     #endif  // !Py_BUILD_CORE
      40                 :            : 
      41                 :            :     static const char * const _keywords[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", "uri", "autocommit", NULL};
      42                 :            :     static _PyArg_Parser _parser = {
      43                 :            :         .keywords = _keywords,
      44                 :            :         .fname = "Connection",
      45                 :            :         .kwtuple = KWTUPLE,
      46                 :            :     };
      47                 :            :     #undef KWTUPLE
      48                 :            :     PyObject *argsbuf[9];
      49                 :            :     PyObject * const *fastargs;
      50                 :          0 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
      51         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
      52                 :            :     PyObject *database;
      53                 :          0 :     double timeout = 5.0;
      54                 :          0 :     int detect_types = 0;
      55                 :          0 :     const char *isolation_level = "";
      56                 :          0 :     int check_same_thread = 1;
      57                 :          0 :     PyObject *factory = (PyObject*)clinic_state()->ConnectionType;
      58                 :          0 :     int cache_size = 128;
      59                 :          0 :     int uri = 0;
      60                 :          0 :     enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
      61                 :            : 
      62   [ #  #  #  #  :          0 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
             #  #  #  # ]
      63         [ #  # ]:          0 :     if (!fastargs) {
      64                 :          0 :         goto exit;
      65                 :            :     }
      66                 :          0 :     database = fastargs[0];
      67         [ #  # ]:          0 :     if (!noptargs) {
      68                 :          0 :         goto skip_optional_pos;
      69                 :            :     }
      70         [ #  # ]:          0 :     if (fastargs[1]) {
      71         [ #  # ]:          0 :         if (PyFloat_CheckExact(fastargs[1])) {
      72                 :          0 :             timeout = PyFloat_AS_DOUBLE(fastargs[1]);
      73                 :            :         }
      74                 :            :         else
      75                 :            :         {
      76                 :          0 :             timeout = PyFloat_AsDouble(fastargs[1]);
      77   [ #  #  #  # ]:          0 :             if (timeout == -1.0 && PyErr_Occurred()) {
      78                 :          0 :                 goto exit;
      79                 :            :             }
      80                 :            :         }
      81         [ #  # ]:          0 :         if (!--noptargs) {
      82                 :          0 :             goto skip_optional_pos;
      83                 :            :         }
      84                 :            :     }
      85         [ #  # ]:          0 :     if (fastargs[2]) {
      86                 :          0 :         detect_types = _PyLong_AsInt(fastargs[2]);
      87   [ #  #  #  # ]:          0 :         if (detect_types == -1 && PyErr_Occurred()) {
      88                 :          0 :             goto exit;
      89                 :            :         }
      90         [ #  # ]:          0 :         if (!--noptargs) {
      91                 :          0 :             goto skip_optional_pos;
      92                 :            :         }
      93                 :            :     }
      94         [ #  # ]:          0 :     if (fastargs[3]) {
      95         [ #  # ]:          0 :         if (!isolation_level_converter(fastargs[3], &isolation_level)) {
      96                 :          0 :             goto exit;
      97                 :            :         }
      98         [ #  # ]:          0 :         if (!--noptargs) {
      99                 :          0 :             goto skip_optional_pos;
     100                 :            :         }
     101                 :            :     }
     102         [ #  # ]:          0 :     if (fastargs[4]) {
     103                 :          0 :         check_same_thread = PyObject_IsTrue(fastargs[4]);
     104         [ #  # ]:          0 :         if (check_same_thread < 0) {
     105                 :          0 :             goto exit;
     106                 :            :         }
     107         [ #  # ]:          0 :         if (!--noptargs) {
     108                 :          0 :             goto skip_optional_pos;
     109                 :            :         }
     110                 :            :     }
     111         [ #  # ]:          0 :     if (fastargs[5]) {
     112                 :          0 :         factory = fastargs[5];
     113         [ #  # ]:          0 :         if (!--noptargs) {
     114                 :          0 :             goto skip_optional_pos;
     115                 :            :         }
     116                 :            :     }
     117         [ #  # ]:          0 :     if (fastargs[6]) {
     118                 :          0 :         cache_size = _PyLong_AsInt(fastargs[6]);
     119   [ #  #  #  # ]:          0 :         if (cache_size == -1 && PyErr_Occurred()) {
     120                 :          0 :             goto exit;
     121                 :            :         }
     122         [ #  # ]:          0 :         if (!--noptargs) {
     123                 :          0 :             goto skip_optional_pos;
     124                 :            :         }
     125                 :            :     }
     126         [ #  # ]:          0 :     if (fastargs[7]) {
     127                 :          0 :         uri = PyObject_IsTrue(fastargs[7]);
     128         [ #  # ]:          0 :         if (uri < 0) {
     129                 :          0 :             goto exit;
     130                 :            :         }
     131         [ #  # ]:          0 :         if (!--noptargs) {
     132                 :          0 :             goto skip_optional_pos;
     133                 :            :         }
     134                 :            :     }
     135                 :          0 : skip_optional_pos:
     136         [ #  # ]:          0 :     if (!noptargs) {
     137                 :          0 :         goto skip_optional_kwonly;
     138                 :            :     }
     139         [ #  # ]:          0 :     if (!autocommit_converter(fastargs[8], &autocommit)) {
     140                 :          0 :         goto exit;
     141                 :            :     }
     142                 :          0 : skip_optional_kwonly:
     143                 :          0 :     return_value = pysqlite_connection_init_impl((pysqlite_Connection *)self, database, timeout, detect_types, isolation_level, check_same_thread, factory, cache_size, uri, autocommit);
     144                 :            : 
     145                 :          0 : exit:
     146                 :          0 :     return return_value;
     147                 :            : }
     148                 :            : 
     149                 :            : PyDoc_STRVAR(pysqlite_connection_cursor__doc__,
     150                 :            : "cursor($self, /, factory=<unrepresentable>)\n"
     151                 :            : "--\n"
     152                 :            : "\n"
     153                 :            : "Return a cursor for the connection.");
     154                 :            : 
     155                 :            : #define PYSQLITE_CONNECTION_CURSOR_METHODDEF    \
     156                 :            :     {"cursor", _PyCFunction_CAST(pysqlite_connection_cursor), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_cursor__doc__},
     157                 :            : 
     158                 :            : static PyObject *
     159                 :            : pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory);
     160                 :            : 
     161                 :            : static PyObject *
     162                 :          0 : pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     163                 :            : {
     164                 :          0 :     PyObject *return_value = NULL;
     165                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     166                 :            : 
     167                 :            :     #define NUM_KEYWORDS 1
     168                 :            :     static struct {
     169                 :            :         PyGC_Head _this_is_not_used;
     170                 :            :         PyObject_VAR_HEAD
     171                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     172                 :            :     } _kwtuple = {
     173                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     174                 :            :         .ob_item = { &_Py_ID(factory), },
     175                 :            :     };
     176                 :            :     #undef NUM_KEYWORDS
     177                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     178                 :            : 
     179                 :            :     #else  // !Py_BUILD_CORE
     180                 :            :     #  define KWTUPLE NULL
     181                 :            :     #endif  // !Py_BUILD_CORE
     182                 :            : 
     183                 :            :     static const char * const _keywords[] = {"factory", NULL};
     184                 :            :     static _PyArg_Parser _parser = {
     185                 :            :         .keywords = _keywords,
     186                 :            :         .fname = "cursor",
     187                 :            :         .kwtuple = KWTUPLE,
     188                 :            :     };
     189                 :            :     #undef KWTUPLE
     190                 :            :     PyObject *argsbuf[1];
     191         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     192                 :          0 :     PyObject *factory = NULL;
     193                 :            : 
     194   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
             #  #  #  # ]
     195         [ #  # ]:          0 :     if (!args) {
     196                 :          0 :         goto exit;
     197                 :            :     }
     198         [ #  # ]:          0 :     if (!noptargs) {
     199                 :          0 :         goto skip_optional_pos;
     200                 :            :     }
     201                 :          0 :     factory = args[0];
     202                 :          0 : skip_optional_pos:
     203                 :          0 :     return_value = pysqlite_connection_cursor_impl(self, factory);
     204                 :            : 
     205                 :          0 : exit:
     206                 :          0 :     return return_value;
     207                 :            : }
     208                 :            : 
     209                 :            : PyDoc_STRVAR(blobopen__doc__,
     210                 :            : "blobopen($self, table, column, row, /, *, readonly=False, name=\'main\')\n"
     211                 :            : "--\n"
     212                 :            : "\n"
     213                 :            : "Open and return a BLOB object.\n"
     214                 :            : "\n"
     215                 :            : "  table\n"
     216                 :            : "    Table name.\n"
     217                 :            : "  column\n"
     218                 :            : "    Column name.\n"
     219                 :            : "  row\n"
     220                 :            : "    Row index.\n"
     221                 :            : "  readonly\n"
     222                 :            : "    Open the BLOB without write permissions.\n"
     223                 :            : "  name\n"
     224                 :            : "    Database name.");
     225                 :            : 
     226                 :            : #define BLOBOPEN_METHODDEF    \
     227                 :            :     {"blobopen", _PyCFunction_CAST(blobopen), METH_FASTCALL|METH_KEYWORDS, blobopen__doc__},
     228                 :            : 
     229                 :            : static PyObject *
     230                 :            : blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
     231                 :            :               int row, int readonly, const char *name);
     232                 :            : 
     233                 :            : static PyObject *
     234                 :          0 : blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     235                 :            : {
     236                 :          0 :     PyObject *return_value = NULL;
     237                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     238                 :            : 
     239                 :            :     #define NUM_KEYWORDS 2
     240                 :            :     static struct {
     241                 :            :         PyGC_Head _this_is_not_used;
     242                 :            :         PyObject_VAR_HEAD
     243                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     244                 :            :     } _kwtuple = {
     245                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     246                 :            :         .ob_item = { &_Py_ID(readonly), &_Py_ID(name), },
     247                 :            :     };
     248                 :            :     #undef NUM_KEYWORDS
     249                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     250                 :            : 
     251                 :            :     #else  // !Py_BUILD_CORE
     252                 :            :     #  define KWTUPLE NULL
     253                 :            :     #endif  // !Py_BUILD_CORE
     254                 :            : 
     255                 :            :     static const char * const _keywords[] = {"", "", "", "readonly", "name", NULL};
     256                 :            :     static _PyArg_Parser _parser = {
     257                 :            :         .keywords = _keywords,
     258                 :            :         .fname = "blobopen",
     259                 :            :         .kwtuple = KWTUPLE,
     260                 :            :     };
     261                 :            :     #undef KWTUPLE
     262                 :            :     PyObject *argsbuf[5];
     263         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
     264                 :            :     const char *table;
     265                 :            :     const char *col;
     266                 :            :     int row;
     267                 :          0 :     int readonly = 0;
     268                 :          0 :     const char *name = "main";
     269                 :            : 
     270   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
             #  #  #  # ]
     271         [ #  # ]:          0 :     if (!args) {
     272                 :          0 :         goto exit;
     273                 :            :     }
     274         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
     275                 :          0 :         _PyArg_BadArgument("blobopen", "argument 1", "str", args[0]);
     276                 :          0 :         goto exit;
     277                 :            :     }
     278                 :            :     Py_ssize_t table_length;
     279                 :          0 :     table = PyUnicode_AsUTF8AndSize(args[0], &table_length);
     280         [ #  # ]:          0 :     if (table == NULL) {
     281                 :          0 :         goto exit;
     282                 :            :     }
     283         [ #  # ]:          0 :     if (strlen(table) != (size_t)table_length) {
     284                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     285                 :          0 :         goto exit;
     286                 :            :     }
     287         [ #  # ]:          0 :     if (!PyUnicode_Check(args[1])) {
     288                 :          0 :         _PyArg_BadArgument("blobopen", "argument 2", "str", args[1]);
     289                 :          0 :         goto exit;
     290                 :            :     }
     291                 :            :     Py_ssize_t col_length;
     292                 :          0 :     col = PyUnicode_AsUTF8AndSize(args[1], &col_length);
     293         [ #  # ]:          0 :     if (col == NULL) {
     294                 :          0 :         goto exit;
     295                 :            :     }
     296         [ #  # ]:          0 :     if (strlen(col) != (size_t)col_length) {
     297                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     298                 :          0 :         goto exit;
     299                 :            :     }
     300                 :          0 :     row = _PyLong_AsInt(args[2]);
     301   [ #  #  #  # ]:          0 :     if (row == -1 && PyErr_Occurred()) {
     302                 :          0 :         goto exit;
     303                 :            :     }
     304         [ #  # ]:          0 :     if (!noptargs) {
     305                 :          0 :         goto skip_optional_kwonly;
     306                 :            :     }
     307         [ #  # ]:          0 :     if (args[3]) {
     308                 :          0 :         readonly = PyObject_IsTrue(args[3]);
     309         [ #  # ]:          0 :         if (readonly < 0) {
     310                 :          0 :             goto exit;
     311                 :            :         }
     312         [ #  # ]:          0 :         if (!--noptargs) {
     313                 :          0 :             goto skip_optional_kwonly;
     314                 :            :         }
     315                 :            :     }
     316         [ #  # ]:          0 :     if (!PyUnicode_Check(args[4])) {
     317                 :          0 :         _PyArg_BadArgument("blobopen", "argument 'name'", "str", args[4]);
     318                 :          0 :         goto exit;
     319                 :            :     }
     320                 :            :     Py_ssize_t name_length;
     321                 :          0 :     name = PyUnicode_AsUTF8AndSize(args[4], &name_length);
     322         [ #  # ]:          0 :     if (name == NULL) {
     323                 :          0 :         goto exit;
     324                 :            :     }
     325         [ #  # ]:          0 :     if (strlen(name) != (size_t)name_length) {
     326                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     327                 :          0 :         goto exit;
     328                 :            :     }
     329                 :          0 : skip_optional_kwonly:
     330                 :          0 :     return_value = blobopen_impl(self, table, col, row, readonly, name);
     331                 :            : 
     332                 :          0 : exit:
     333                 :          0 :     return return_value;
     334                 :            : }
     335                 :            : 
     336                 :            : PyDoc_STRVAR(pysqlite_connection_close__doc__,
     337                 :            : "close($self, /)\n"
     338                 :            : "--\n"
     339                 :            : "\n"
     340                 :            : "Close the database connection.\n"
     341                 :            : "\n"
     342                 :            : "Any pending transaction is not committed implicitly.");
     343                 :            : 
     344                 :            : #define PYSQLITE_CONNECTION_CLOSE_METHODDEF    \
     345                 :            :     {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS, pysqlite_connection_close__doc__},
     346                 :            : 
     347                 :            : static PyObject *
     348                 :            : pysqlite_connection_close_impl(pysqlite_Connection *self);
     349                 :            : 
     350                 :            : static PyObject *
     351                 :          0 : pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
     352                 :            : {
     353                 :          0 :     return pysqlite_connection_close_impl(self);
     354                 :            : }
     355                 :            : 
     356                 :            : PyDoc_STRVAR(pysqlite_connection_commit__doc__,
     357                 :            : "commit($self, /)\n"
     358                 :            : "--\n"
     359                 :            : "\n"
     360                 :            : "Commit any pending transaction to the database.\n"
     361                 :            : "\n"
     362                 :            : "If there is no open transaction, this method is a no-op.");
     363                 :            : 
     364                 :            : #define PYSQLITE_CONNECTION_COMMIT_METHODDEF    \
     365                 :            :     {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, pysqlite_connection_commit__doc__},
     366                 :            : 
     367                 :            : static PyObject *
     368                 :            : pysqlite_connection_commit_impl(pysqlite_Connection *self);
     369                 :            : 
     370                 :            : static PyObject *
     371                 :          0 : pysqlite_connection_commit(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
     372                 :            : {
     373                 :          0 :     return pysqlite_connection_commit_impl(self);
     374                 :            : }
     375                 :            : 
     376                 :            : PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
     377                 :            : "rollback($self, /)\n"
     378                 :            : "--\n"
     379                 :            : "\n"
     380                 :            : "Roll back to the start of any pending transaction.\n"
     381                 :            : "\n"
     382                 :            : "If there is no open transaction, this method is a no-op.");
     383                 :            : 
     384                 :            : #define PYSQLITE_CONNECTION_ROLLBACK_METHODDEF    \
     385                 :            :     {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS, pysqlite_connection_rollback__doc__},
     386                 :            : 
     387                 :            : static PyObject *
     388                 :            : pysqlite_connection_rollback_impl(pysqlite_Connection *self);
     389                 :            : 
     390                 :            : static PyObject *
     391                 :          0 : pysqlite_connection_rollback(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
     392                 :            : {
     393                 :          0 :     return pysqlite_connection_rollback_impl(self);
     394                 :            : }
     395                 :            : 
     396                 :            : PyDoc_STRVAR(pysqlite_connection_create_function__doc__,
     397                 :            : "create_function($self, /, name, narg, func, *, deterministic=False)\n"
     398                 :            : "--\n"
     399                 :            : "\n"
     400                 :            : "Creates a new function.");
     401                 :            : 
     402                 :            : #define PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF    \
     403                 :            :     {"create_function", _PyCFunction_CAST(pysqlite_connection_create_function), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_function__doc__},
     404                 :            : 
     405                 :            : static PyObject *
     406                 :            : pysqlite_connection_create_function_impl(pysqlite_Connection *self,
     407                 :            :                                          PyTypeObject *cls, const char *name,
     408                 :            :                                          int narg, PyObject *func,
     409                 :            :                                          int deterministic);
     410                 :            : 
     411                 :            : static PyObject *
     412                 :          0 : pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     413                 :            : {
     414                 :          0 :     PyObject *return_value = NULL;
     415                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     416                 :            : 
     417                 :            :     #define NUM_KEYWORDS 4
     418                 :            :     static struct {
     419                 :            :         PyGC_Head _this_is_not_used;
     420                 :            :         PyObject_VAR_HEAD
     421                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     422                 :            :     } _kwtuple = {
     423                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     424                 :            :         .ob_item = { &_Py_ID(name), &_Py_ID(narg), &_Py_ID(func), &_Py_ID(deterministic), },
     425                 :            :     };
     426                 :            :     #undef NUM_KEYWORDS
     427                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     428                 :            : 
     429                 :            :     #else  // !Py_BUILD_CORE
     430                 :            :     #  define KWTUPLE NULL
     431                 :            :     #endif  // !Py_BUILD_CORE
     432                 :            : 
     433                 :            :     static const char * const _keywords[] = {"name", "narg", "func", "deterministic", NULL};
     434                 :            :     static _PyArg_Parser _parser = {
     435                 :            :         .keywords = _keywords,
     436                 :            :         .fname = "create_function",
     437                 :            :         .kwtuple = KWTUPLE,
     438                 :            :     };
     439                 :            :     #undef KWTUPLE
     440                 :            :     PyObject *argsbuf[4];
     441         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
     442                 :            :     const char *name;
     443                 :            :     int narg;
     444                 :            :     PyObject *func;
     445                 :          0 :     int deterministic = 0;
     446                 :            : 
     447   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
             #  #  #  # ]
     448         [ #  # ]:          0 :     if (!args) {
     449                 :          0 :         goto exit;
     450                 :            :     }
     451         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
     452                 :          0 :         _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
     453                 :          0 :         goto exit;
     454                 :            :     }
     455                 :            :     Py_ssize_t name_length;
     456                 :          0 :     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     457         [ #  # ]:          0 :     if (name == NULL) {
     458                 :          0 :         goto exit;
     459                 :            :     }
     460         [ #  # ]:          0 :     if (strlen(name) != (size_t)name_length) {
     461                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     462                 :          0 :         goto exit;
     463                 :            :     }
     464                 :          0 :     narg = _PyLong_AsInt(args[1]);
     465   [ #  #  #  # ]:          0 :     if (narg == -1 && PyErr_Occurred()) {
     466                 :          0 :         goto exit;
     467                 :            :     }
     468                 :          0 :     func = args[2];
     469         [ #  # ]:          0 :     if (!noptargs) {
     470                 :          0 :         goto skip_optional_kwonly;
     471                 :            :     }
     472                 :          0 :     deterministic = PyObject_IsTrue(args[3]);
     473         [ #  # ]:          0 :     if (deterministic < 0) {
     474                 :          0 :         goto exit;
     475                 :            :     }
     476                 :          0 : skip_optional_kwonly:
     477                 :          0 :     return_value = pysqlite_connection_create_function_impl(self, cls, name, narg, func, deterministic);
     478                 :            : 
     479                 :          0 : exit:
     480                 :          0 :     return return_value;
     481                 :            : }
     482                 :            : 
     483                 :            : #if defined(HAVE_WINDOW_FUNCTIONS)
     484                 :            : 
     485                 :            : PyDoc_STRVAR(create_window_function__doc__,
     486                 :            : "create_window_function($self, name, num_params, aggregate_class, /)\n"
     487                 :            : "--\n"
     488                 :            : "\n"
     489                 :            : "Creates or redefines an aggregate window function. Non-standard.\n"
     490                 :            : "\n"
     491                 :            : "  name\n"
     492                 :            : "    The name of the SQL aggregate window function to be created or\n"
     493                 :            : "    redefined.\n"
     494                 :            : "  num_params\n"
     495                 :            : "    The number of arguments the step and inverse methods takes.\n"
     496                 :            : "  aggregate_class\n"
     497                 :            : "    A class with step(), finalize(), value(), and inverse() methods.\n"
     498                 :            : "    Set to None to clear the window function.");
     499                 :            : 
     500                 :            : #define CREATE_WINDOW_FUNCTION_METHODDEF    \
     501                 :            :     {"create_window_function", _PyCFunction_CAST(create_window_function), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, create_window_function__doc__},
     502                 :            : 
     503                 :            : static PyObject *
     504                 :            : create_window_function_impl(pysqlite_Connection *self, PyTypeObject *cls,
     505                 :            :                             const char *name, int num_params,
     506                 :            :                             PyObject *aggregate_class);
     507                 :            : 
     508                 :            : static PyObject *
     509                 :          0 : create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     510                 :            : {
     511                 :          0 :     PyObject *return_value = NULL;
     512                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     513                 :            :     #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
     514                 :            :     #else
     515                 :            :     #  define KWTUPLE NULL
     516                 :            :     #endif
     517                 :            : 
     518                 :            :     static const char * const _keywords[] = {"", "", "", NULL};
     519                 :            :     static _PyArg_Parser _parser = {
     520                 :            :         .keywords = _keywords,
     521                 :            :         .fname = "create_window_function",
     522                 :            :         .kwtuple = KWTUPLE,
     523                 :            :     };
     524                 :            :     #undef KWTUPLE
     525                 :            :     PyObject *argsbuf[3];
     526                 :            :     const char *name;
     527                 :            :     int num_params;
     528                 :            :     PyObject *aggregate_class;
     529                 :            : 
     530   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
             #  #  #  # ]
     531         [ #  # ]:          0 :     if (!args) {
     532                 :          0 :         goto exit;
     533                 :            :     }
     534         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
     535                 :          0 :         _PyArg_BadArgument("create_window_function", "argument 1", "str", args[0]);
     536                 :          0 :         goto exit;
     537                 :            :     }
     538                 :            :     Py_ssize_t name_length;
     539                 :          0 :     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     540         [ #  # ]:          0 :     if (name == NULL) {
     541                 :          0 :         goto exit;
     542                 :            :     }
     543         [ #  # ]:          0 :     if (strlen(name) != (size_t)name_length) {
     544                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     545                 :          0 :         goto exit;
     546                 :            :     }
     547                 :          0 :     num_params = _PyLong_AsInt(args[1]);
     548   [ #  #  #  # ]:          0 :     if (num_params == -1 && PyErr_Occurred()) {
     549                 :          0 :         goto exit;
     550                 :            :     }
     551                 :          0 :     aggregate_class = args[2];
     552                 :          0 :     return_value = create_window_function_impl(self, cls, name, num_params, aggregate_class);
     553                 :            : 
     554                 :          0 : exit:
     555                 :          0 :     return return_value;
     556                 :            : }
     557                 :            : 
     558                 :            : #endif /* defined(HAVE_WINDOW_FUNCTIONS) */
     559                 :            : 
     560                 :            : PyDoc_STRVAR(pysqlite_connection_create_aggregate__doc__,
     561                 :            : "create_aggregate($self, /, name, n_arg, aggregate_class)\n"
     562                 :            : "--\n"
     563                 :            : "\n"
     564                 :            : "Creates a new aggregate.");
     565                 :            : 
     566                 :            : #define PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF    \
     567                 :            :     {"create_aggregate", _PyCFunction_CAST(pysqlite_connection_create_aggregate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_aggregate__doc__},
     568                 :            : 
     569                 :            : static PyObject *
     570                 :            : pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
     571                 :            :                                           PyTypeObject *cls,
     572                 :            :                                           const char *name, int n_arg,
     573                 :            :                                           PyObject *aggregate_class);
     574                 :            : 
     575                 :            : static PyObject *
     576                 :          0 : pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     577                 :            : {
     578                 :          0 :     PyObject *return_value = NULL;
     579                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     580                 :            : 
     581                 :            :     #define NUM_KEYWORDS 3
     582                 :            :     static struct {
     583                 :            :         PyGC_Head _this_is_not_used;
     584                 :            :         PyObject_VAR_HEAD
     585                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     586                 :            :     } _kwtuple = {
     587                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     588                 :            :         .ob_item = { &_Py_ID(name), &_Py_ID(n_arg), &_Py_ID(aggregate_class), },
     589                 :            :     };
     590                 :            :     #undef NUM_KEYWORDS
     591                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     592                 :            : 
     593                 :            :     #else  // !Py_BUILD_CORE
     594                 :            :     #  define KWTUPLE NULL
     595                 :            :     #endif  // !Py_BUILD_CORE
     596                 :            : 
     597                 :            :     static const char * const _keywords[] = {"name", "n_arg", "aggregate_class", NULL};
     598                 :            :     static _PyArg_Parser _parser = {
     599                 :            :         .keywords = _keywords,
     600                 :            :         .fname = "create_aggregate",
     601                 :            :         .kwtuple = KWTUPLE,
     602                 :            :     };
     603                 :            :     #undef KWTUPLE
     604                 :            :     PyObject *argsbuf[3];
     605                 :            :     const char *name;
     606                 :            :     int n_arg;
     607                 :            :     PyObject *aggregate_class;
     608                 :            : 
     609   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
             #  #  #  # ]
     610         [ #  # ]:          0 :     if (!args) {
     611                 :          0 :         goto exit;
     612                 :            :     }
     613         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
     614                 :          0 :         _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
     615                 :          0 :         goto exit;
     616                 :            :     }
     617                 :            :     Py_ssize_t name_length;
     618                 :          0 :     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
     619         [ #  # ]:          0 :     if (name == NULL) {
     620                 :          0 :         goto exit;
     621                 :            :     }
     622         [ #  # ]:          0 :     if (strlen(name) != (size_t)name_length) {
     623                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     624                 :          0 :         goto exit;
     625                 :            :     }
     626                 :          0 :     n_arg = _PyLong_AsInt(args[1]);
     627   [ #  #  #  # ]:          0 :     if (n_arg == -1 && PyErr_Occurred()) {
     628                 :          0 :         goto exit;
     629                 :            :     }
     630                 :          0 :     aggregate_class = args[2];
     631                 :          0 :     return_value = pysqlite_connection_create_aggregate_impl(self, cls, name, n_arg, aggregate_class);
     632                 :            : 
     633                 :          0 : exit:
     634                 :          0 :     return return_value;
     635                 :            : }
     636                 :            : 
     637                 :            : PyDoc_STRVAR(pysqlite_connection_set_authorizer__doc__,
     638                 :            : "set_authorizer($self, /, authorizer_callback)\n"
     639                 :            : "--\n"
     640                 :            : "\n"
     641                 :            : "Sets authorizer callback.");
     642                 :            : 
     643                 :            : #define PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF    \
     644                 :            :     {"set_authorizer", _PyCFunction_CAST(pysqlite_connection_set_authorizer), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_authorizer__doc__},
     645                 :            : 
     646                 :            : static PyObject *
     647                 :            : pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
     648                 :            :                                         PyTypeObject *cls,
     649                 :            :                                         PyObject *callable);
     650                 :            : 
     651                 :            : static PyObject *
     652                 :          0 : pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     653                 :            : {
     654                 :          0 :     PyObject *return_value = NULL;
     655                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     656                 :            : 
     657                 :            :     #define NUM_KEYWORDS 1
     658                 :            :     static struct {
     659                 :            :         PyGC_Head _this_is_not_used;
     660                 :            :         PyObject_VAR_HEAD
     661                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     662                 :            :     } _kwtuple = {
     663                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     664                 :            :         .ob_item = { &_Py_ID(authorizer_callback), },
     665                 :            :     };
     666                 :            :     #undef NUM_KEYWORDS
     667                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     668                 :            : 
     669                 :            :     #else  // !Py_BUILD_CORE
     670                 :            :     #  define KWTUPLE NULL
     671                 :            :     #endif  // !Py_BUILD_CORE
     672                 :            : 
     673                 :            :     static const char * const _keywords[] = {"authorizer_callback", NULL};
     674                 :            :     static _PyArg_Parser _parser = {
     675                 :            :         .keywords = _keywords,
     676                 :            :         .fname = "set_authorizer",
     677                 :            :         .kwtuple = KWTUPLE,
     678                 :            :     };
     679                 :            :     #undef KWTUPLE
     680                 :            :     PyObject *argsbuf[1];
     681                 :            :     PyObject *callable;
     682                 :            : 
     683   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
             #  #  #  # ]
     684         [ #  # ]:          0 :     if (!args) {
     685                 :          0 :         goto exit;
     686                 :            :     }
     687                 :          0 :     callable = args[0];
     688                 :          0 :     return_value = pysqlite_connection_set_authorizer_impl(self, cls, callable);
     689                 :            : 
     690                 :          0 : exit:
     691                 :          0 :     return return_value;
     692                 :            : }
     693                 :            : 
     694                 :            : PyDoc_STRVAR(pysqlite_connection_set_progress_handler__doc__,
     695                 :            : "set_progress_handler($self, /, progress_handler, n)\n"
     696                 :            : "--\n"
     697                 :            : "\n"
     698                 :            : "Sets progress handler callback.");
     699                 :            : 
     700                 :            : #define PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF    \
     701                 :            :     {"set_progress_handler", _PyCFunction_CAST(pysqlite_connection_set_progress_handler), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_progress_handler__doc__},
     702                 :            : 
     703                 :            : static PyObject *
     704                 :            : pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
     705                 :            :                                               PyTypeObject *cls,
     706                 :            :                                               PyObject *callable, int n);
     707                 :            : 
     708                 :            : static PyObject *
     709                 :          0 : pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     710                 :            : {
     711                 :          0 :     PyObject *return_value = NULL;
     712                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     713                 :            : 
     714                 :            :     #define NUM_KEYWORDS 2
     715                 :            :     static struct {
     716                 :            :         PyGC_Head _this_is_not_used;
     717                 :            :         PyObject_VAR_HEAD
     718                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     719                 :            :     } _kwtuple = {
     720                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     721                 :            :         .ob_item = { &_Py_ID(progress_handler), &_Py_ID(n), },
     722                 :            :     };
     723                 :            :     #undef NUM_KEYWORDS
     724                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     725                 :            : 
     726                 :            :     #else  // !Py_BUILD_CORE
     727                 :            :     #  define KWTUPLE NULL
     728                 :            :     #endif  // !Py_BUILD_CORE
     729                 :            : 
     730                 :            :     static const char * const _keywords[] = {"progress_handler", "n", NULL};
     731                 :            :     static _PyArg_Parser _parser = {
     732                 :            :         .keywords = _keywords,
     733                 :            :         .fname = "set_progress_handler",
     734                 :            :         .kwtuple = KWTUPLE,
     735                 :            :     };
     736                 :            :     #undef KWTUPLE
     737                 :            :     PyObject *argsbuf[2];
     738                 :            :     PyObject *callable;
     739                 :            :     int n;
     740                 :            : 
     741   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
             #  #  #  # ]
     742         [ #  # ]:          0 :     if (!args) {
     743                 :          0 :         goto exit;
     744                 :            :     }
     745                 :          0 :     callable = args[0];
     746                 :          0 :     n = _PyLong_AsInt(args[1]);
     747   [ #  #  #  # ]:          0 :     if (n == -1 && PyErr_Occurred()) {
     748                 :          0 :         goto exit;
     749                 :            :     }
     750                 :          0 :     return_value = pysqlite_connection_set_progress_handler_impl(self, cls, callable, n);
     751                 :            : 
     752                 :          0 : exit:
     753                 :          0 :     return return_value;
     754                 :            : }
     755                 :            : 
     756                 :            : PyDoc_STRVAR(pysqlite_connection_set_trace_callback__doc__,
     757                 :            : "set_trace_callback($self, /, trace_callback)\n"
     758                 :            : "--\n"
     759                 :            : "\n"
     760                 :            : "Sets a trace callback called for each SQL statement (passed as unicode).");
     761                 :            : 
     762                 :            : #define PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF    \
     763                 :            :     {"set_trace_callback", _PyCFunction_CAST(pysqlite_connection_set_trace_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_trace_callback__doc__},
     764                 :            : 
     765                 :            : static PyObject *
     766                 :            : pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
     767                 :            :                                             PyTypeObject *cls,
     768                 :            :                                             PyObject *callable);
     769                 :            : 
     770                 :            : static PyObject *
     771                 :          0 : pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     772                 :            : {
     773                 :          0 :     PyObject *return_value = NULL;
     774                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     775                 :            : 
     776                 :            :     #define NUM_KEYWORDS 1
     777                 :            :     static struct {
     778                 :            :         PyGC_Head _this_is_not_used;
     779                 :            :         PyObject_VAR_HEAD
     780                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     781                 :            :     } _kwtuple = {
     782                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     783                 :            :         .ob_item = { &_Py_ID(trace_callback), },
     784                 :            :     };
     785                 :            :     #undef NUM_KEYWORDS
     786                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     787                 :            : 
     788                 :            :     #else  // !Py_BUILD_CORE
     789                 :            :     #  define KWTUPLE NULL
     790                 :            :     #endif  // !Py_BUILD_CORE
     791                 :            : 
     792                 :            :     static const char * const _keywords[] = {"trace_callback", NULL};
     793                 :            :     static _PyArg_Parser _parser = {
     794                 :            :         .keywords = _keywords,
     795                 :            :         .fname = "set_trace_callback",
     796                 :            :         .kwtuple = KWTUPLE,
     797                 :            :     };
     798                 :            :     #undef KWTUPLE
     799                 :            :     PyObject *argsbuf[1];
     800                 :            :     PyObject *callable;
     801                 :            : 
     802   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
             #  #  #  # ]
     803         [ #  # ]:          0 :     if (!args) {
     804                 :          0 :         goto exit;
     805                 :            :     }
     806                 :          0 :     callable = args[0];
     807                 :          0 :     return_value = pysqlite_connection_set_trace_callback_impl(self, cls, callable);
     808                 :            : 
     809                 :          0 : exit:
     810                 :          0 :     return return_value;
     811                 :            : }
     812                 :            : 
     813                 :            : #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
     814                 :            : 
     815                 :            : PyDoc_STRVAR(pysqlite_connection_enable_load_extension__doc__,
     816                 :            : "enable_load_extension($self, enable, /)\n"
     817                 :            : "--\n"
     818                 :            : "\n"
     819                 :            : "Enable dynamic loading of SQLite extension modules.");
     820                 :            : 
     821                 :            : #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF    \
     822                 :            :     {"enable_load_extension", (PyCFunction)pysqlite_connection_enable_load_extension, METH_O, pysqlite_connection_enable_load_extension__doc__},
     823                 :            : 
     824                 :            : static PyObject *
     825                 :            : pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
     826                 :            :                                                int onoff);
     827                 :            : 
     828                 :            : static PyObject *
     829                 :            : pysqlite_connection_enable_load_extension(pysqlite_Connection *self, PyObject *arg)
     830                 :            : {
     831                 :            :     PyObject *return_value = NULL;
     832                 :            :     int onoff;
     833                 :            : 
     834                 :            :     onoff = PyObject_IsTrue(arg);
     835                 :            :     if (onoff < 0) {
     836                 :            :         goto exit;
     837                 :            :     }
     838                 :            :     return_value = pysqlite_connection_enable_load_extension_impl(self, onoff);
     839                 :            : 
     840                 :            : exit:
     841                 :            :     return return_value;
     842                 :            : }
     843                 :            : 
     844                 :            : #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
     845                 :            : 
     846                 :            : #if defined(PY_SQLITE_ENABLE_LOAD_EXTENSION)
     847                 :            : 
     848                 :            : PyDoc_STRVAR(pysqlite_connection_load_extension__doc__,
     849                 :            : "load_extension($self, name, /)\n"
     850                 :            : "--\n"
     851                 :            : "\n"
     852                 :            : "Load SQLite extension module.");
     853                 :            : 
     854                 :            : #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF    \
     855                 :            :     {"load_extension", (PyCFunction)pysqlite_connection_load_extension, METH_O, pysqlite_connection_load_extension__doc__},
     856                 :            : 
     857                 :            : static PyObject *
     858                 :            : pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
     859                 :            :                                         const char *extension_name);
     860                 :            : 
     861                 :            : static PyObject *
     862                 :            : pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *arg)
     863                 :            : {
     864                 :            :     PyObject *return_value = NULL;
     865                 :            :     const char *extension_name;
     866                 :            : 
     867                 :            :     if (!PyUnicode_Check(arg)) {
     868                 :            :         _PyArg_BadArgument("load_extension", "argument", "str", arg);
     869                 :            :         goto exit;
     870                 :            :     }
     871                 :            :     Py_ssize_t extension_name_length;
     872                 :            :     extension_name = PyUnicode_AsUTF8AndSize(arg, &extension_name_length);
     873                 :            :     if (extension_name == NULL) {
     874                 :            :         goto exit;
     875                 :            :     }
     876                 :            :     if (strlen(extension_name) != (size_t)extension_name_length) {
     877                 :            :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     878                 :            :         goto exit;
     879                 :            :     }
     880                 :            :     return_value = pysqlite_connection_load_extension_impl(self, extension_name);
     881                 :            : 
     882                 :            : exit:
     883                 :            :     return return_value;
     884                 :            : }
     885                 :            : 
     886                 :            : #endif /* defined(PY_SQLITE_ENABLE_LOAD_EXTENSION) */
     887                 :            : 
     888                 :            : PyDoc_STRVAR(pysqlite_connection_execute__doc__,
     889                 :            : "execute($self, sql, parameters=<unrepresentable>, /)\n"
     890                 :            : "--\n"
     891                 :            : "\n"
     892                 :            : "Executes an SQL statement.");
     893                 :            : 
     894                 :            : #define PYSQLITE_CONNECTION_EXECUTE_METHODDEF    \
     895                 :            :     {"execute", _PyCFunction_CAST(pysqlite_connection_execute), METH_FASTCALL, pysqlite_connection_execute__doc__},
     896                 :            : 
     897                 :            : static PyObject *
     898                 :            : pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
     899                 :            :                                  PyObject *parameters);
     900                 :            : 
     901                 :            : static PyObject *
     902                 :          0 : pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
     903                 :            : {
     904                 :          0 :     PyObject *return_value = NULL;
     905                 :            :     PyObject *sql;
     906                 :          0 :     PyObject *parameters = NULL;
     907                 :            : 
     908   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
                   #  # ]
     909                 :          0 :         goto exit;
     910                 :            :     }
     911         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
     912                 :          0 :         _PyArg_BadArgument("execute", "argument 1", "str", args[0]);
     913                 :          0 :         goto exit;
     914                 :            :     }
     915         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
     916                 :          0 :         goto exit;
     917                 :            :     }
     918                 :          0 :     sql = args[0];
     919         [ #  # ]:          0 :     if (nargs < 2) {
     920                 :          0 :         goto skip_optional;
     921                 :            :     }
     922                 :          0 :     parameters = args[1];
     923                 :          0 : skip_optional:
     924                 :          0 :     return_value = pysqlite_connection_execute_impl(self, sql, parameters);
     925                 :            : 
     926                 :          0 : exit:
     927                 :          0 :     return return_value;
     928                 :            : }
     929                 :            : 
     930                 :            : PyDoc_STRVAR(pysqlite_connection_executemany__doc__,
     931                 :            : "executemany($self, sql, parameters, /)\n"
     932                 :            : "--\n"
     933                 :            : "\n"
     934                 :            : "Repeatedly executes an SQL statement.");
     935                 :            : 
     936                 :            : #define PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF    \
     937                 :            :     {"executemany", _PyCFunction_CAST(pysqlite_connection_executemany), METH_FASTCALL, pysqlite_connection_executemany__doc__},
     938                 :            : 
     939                 :            : static PyObject *
     940                 :            : pysqlite_connection_executemany_impl(pysqlite_Connection *self,
     941                 :            :                                      PyObject *sql, PyObject *parameters);
     942                 :            : 
     943                 :            : static PyObject *
     944                 :          0 : pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
     945                 :            : {
     946                 :          0 :     PyObject *return_value = NULL;
     947                 :            :     PyObject *sql;
     948                 :            :     PyObject *parameters;
     949                 :            : 
     950   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
                   #  # ]
     951                 :          0 :         goto exit;
     952                 :            :     }
     953         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
     954                 :          0 :         _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
     955                 :          0 :         goto exit;
     956                 :            :     }
     957         [ #  # ]:          0 :     if (PyUnicode_READY(args[0]) == -1) {
     958                 :          0 :         goto exit;
     959                 :            :     }
     960                 :          0 :     sql = args[0];
     961                 :          0 :     parameters = args[1];
     962                 :          0 :     return_value = pysqlite_connection_executemany_impl(self, sql, parameters);
     963                 :            : 
     964                 :          0 : exit:
     965                 :          0 :     return return_value;
     966                 :            : }
     967                 :            : 
     968                 :            : PyDoc_STRVAR(pysqlite_connection_executescript__doc__,
     969                 :            : "executescript($self, sql_script, /)\n"
     970                 :            : "--\n"
     971                 :            : "\n"
     972                 :            : "Executes multiple SQL statements at once.");
     973                 :            : 
     974                 :            : #define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF    \
     975                 :            :     {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__},
     976                 :            : 
     977                 :            : PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
     978                 :            : "interrupt($self, /)\n"
     979                 :            : "--\n"
     980                 :            : "\n"
     981                 :            : "Abort any pending database operation.");
     982                 :            : 
     983                 :            : #define PYSQLITE_CONNECTION_INTERRUPT_METHODDEF    \
     984                 :            :     {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS, pysqlite_connection_interrupt__doc__},
     985                 :            : 
     986                 :            : static PyObject *
     987                 :            : pysqlite_connection_interrupt_impl(pysqlite_Connection *self);
     988                 :            : 
     989                 :            : static PyObject *
     990                 :          0 : pysqlite_connection_interrupt(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
     991                 :            : {
     992                 :          0 :     return pysqlite_connection_interrupt_impl(self);
     993                 :            : }
     994                 :            : 
     995                 :            : PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
     996                 :            : "iterdump($self, /)\n"
     997                 :            : "--\n"
     998                 :            : "\n"
     999                 :            : "Returns iterator to the dump of the database in an SQL text format.");
    1000                 :            : 
    1001                 :            : #define PYSQLITE_CONNECTION_ITERDUMP_METHODDEF    \
    1002                 :            :     {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS, pysqlite_connection_iterdump__doc__},
    1003                 :            : 
    1004                 :            : static PyObject *
    1005                 :            : pysqlite_connection_iterdump_impl(pysqlite_Connection *self);
    1006                 :            : 
    1007                 :            : static PyObject *
    1008                 :          0 : pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
    1009                 :            : {
    1010                 :          0 :     return pysqlite_connection_iterdump_impl(self);
    1011                 :            : }
    1012                 :            : 
    1013                 :            : PyDoc_STRVAR(pysqlite_connection_backup__doc__,
    1014                 :            : "backup($self, /, target, *, pages=-1, progress=None, name=\'main\',\n"
    1015                 :            : "       sleep=0.25)\n"
    1016                 :            : "--\n"
    1017                 :            : "\n"
    1018                 :            : "Makes a backup of the database.");
    1019                 :            : 
    1020                 :            : #define PYSQLITE_CONNECTION_BACKUP_METHODDEF    \
    1021                 :            :     {"backup", _PyCFunction_CAST(pysqlite_connection_backup), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_backup__doc__},
    1022                 :            : 
    1023                 :            : static PyObject *
    1024                 :            : pysqlite_connection_backup_impl(pysqlite_Connection *self,
    1025                 :            :                                 pysqlite_Connection *target, int pages,
    1026                 :            :                                 PyObject *progress, const char *name,
    1027                 :            :                                 double sleep);
    1028                 :            : 
    1029                 :            : static PyObject *
    1030                 :          0 : pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    1031                 :            : {
    1032                 :          0 :     PyObject *return_value = NULL;
    1033                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
    1034                 :            : 
    1035                 :            :     #define NUM_KEYWORDS 5
    1036                 :            :     static struct {
    1037                 :            :         PyGC_Head _this_is_not_used;
    1038                 :            :         PyObject_VAR_HEAD
    1039                 :            :         PyObject *ob_item[NUM_KEYWORDS];
    1040                 :            :     } _kwtuple = {
    1041                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
    1042                 :            :         .ob_item = { &_Py_ID(target), &_Py_ID(pages), &_Py_ID(progress), &_Py_ID(name), &_Py_ID(sleep), },
    1043                 :            :     };
    1044                 :            :     #undef NUM_KEYWORDS
    1045                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
    1046                 :            : 
    1047                 :            :     #else  // !Py_BUILD_CORE
    1048                 :            :     #  define KWTUPLE NULL
    1049                 :            :     #endif  // !Py_BUILD_CORE
    1050                 :            : 
    1051                 :            :     static const char * const _keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
    1052                 :            :     static _PyArg_Parser _parser = {
    1053                 :            :         .keywords = _keywords,
    1054                 :            :         .fname = "backup",
    1055                 :            :         .kwtuple = KWTUPLE,
    1056                 :            :     };
    1057                 :            :     #undef KWTUPLE
    1058                 :            :     PyObject *argsbuf[5];
    1059         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
    1060                 :            :     pysqlite_Connection *target;
    1061                 :          0 :     int pages = -1;
    1062                 :          0 :     PyObject *progress = Py_None;
    1063                 :          0 :     const char *name = "main";
    1064                 :          0 :     double sleep = 0.25;
    1065                 :            : 
    1066   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
             #  #  #  # ]
    1067         [ #  # ]:          0 :     if (!args) {
    1068                 :          0 :         goto exit;
    1069                 :            :     }
    1070         [ #  # ]:          0 :     if (!PyObject_TypeCheck(args[0], clinic_state()->ConnectionType)) {
    1071                 :          0 :         _PyArg_BadArgument("backup", "argument 'target'", (clinic_state()->ConnectionType)->tp_name, args[0]);
    1072                 :          0 :         goto exit;
    1073                 :            :     }
    1074                 :          0 :     target = (pysqlite_Connection *)args[0];
    1075         [ #  # ]:          0 :     if (!noptargs) {
    1076                 :          0 :         goto skip_optional_kwonly;
    1077                 :            :     }
    1078         [ #  # ]:          0 :     if (args[1]) {
    1079                 :          0 :         pages = _PyLong_AsInt(args[1]);
    1080   [ #  #  #  # ]:          0 :         if (pages == -1 && PyErr_Occurred()) {
    1081                 :          0 :             goto exit;
    1082                 :            :         }
    1083         [ #  # ]:          0 :         if (!--noptargs) {
    1084                 :          0 :             goto skip_optional_kwonly;
    1085                 :            :         }
    1086                 :            :     }
    1087         [ #  # ]:          0 :     if (args[2]) {
    1088                 :          0 :         progress = args[2];
    1089         [ #  # ]:          0 :         if (!--noptargs) {
    1090                 :          0 :             goto skip_optional_kwonly;
    1091                 :            :         }
    1092                 :            :     }
    1093         [ #  # ]:          0 :     if (args[3]) {
    1094         [ #  # ]:          0 :         if (!PyUnicode_Check(args[3])) {
    1095                 :          0 :             _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
    1096                 :          0 :             goto exit;
    1097                 :            :         }
    1098                 :            :         Py_ssize_t name_length;
    1099                 :          0 :         name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
    1100         [ #  # ]:          0 :         if (name == NULL) {
    1101                 :          0 :             goto exit;
    1102                 :            :         }
    1103         [ #  # ]:          0 :         if (strlen(name) != (size_t)name_length) {
    1104                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1105                 :          0 :             goto exit;
    1106                 :            :         }
    1107         [ #  # ]:          0 :         if (!--noptargs) {
    1108                 :          0 :             goto skip_optional_kwonly;
    1109                 :            :         }
    1110                 :            :     }
    1111         [ #  # ]:          0 :     if (PyFloat_CheckExact(args[4])) {
    1112                 :          0 :         sleep = PyFloat_AS_DOUBLE(args[4]);
    1113                 :            :     }
    1114                 :            :     else
    1115                 :            :     {
    1116                 :          0 :         sleep = PyFloat_AsDouble(args[4]);
    1117   [ #  #  #  # ]:          0 :         if (sleep == -1.0 && PyErr_Occurred()) {
    1118                 :          0 :             goto exit;
    1119                 :            :         }
    1120                 :            :     }
    1121                 :          0 : skip_optional_kwonly:
    1122                 :          0 :     return_value = pysqlite_connection_backup_impl(self, target, pages, progress, name, sleep);
    1123                 :            : 
    1124                 :          0 : exit:
    1125                 :          0 :     return return_value;
    1126                 :            : }
    1127                 :            : 
    1128                 :            : PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
    1129                 :            : "create_collation($self, name, callback, /)\n"
    1130                 :            : "--\n"
    1131                 :            : "\n"
    1132                 :            : "Creates a collation function.");
    1133                 :            : 
    1134                 :            : #define PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF    \
    1135                 :            :     {"create_collation", _PyCFunction_CAST(pysqlite_connection_create_collation), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_collation__doc__},
    1136                 :            : 
    1137                 :            : static PyObject *
    1138                 :            : pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
    1139                 :            :                                           PyTypeObject *cls,
    1140                 :            :                                           const char *name,
    1141                 :            :                                           PyObject *callable);
    1142                 :            : 
    1143                 :            : static PyObject *
    1144                 :          0 : pysqlite_connection_create_collation(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    1145                 :            : {
    1146                 :          0 :     PyObject *return_value = NULL;
    1147                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
    1148                 :            :     #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
    1149                 :            :     #else
    1150                 :            :     #  define KWTUPLE NULL
    1151                 :            :     #endif
    1152                 :            : 
    1153                 :            :     static const char * const _keywords[] = {"", "", NULL};
    1154                 :            :     static _PyArg_Parser _parser = {
    1155                 :            :         .keywords = _keywords,
    1156                 :            :         .fname = "create_collation",
    1157                 :            :         .kwtuple = KWTUPLE,
    1158                 :            :     };
    1159                 :            :     #undef KWTUPLE
    1160                 :            :     PyObject *argsbuf[2];
    1161                 :            :     const char *name;
    1162                 :            :     PyObject *callable;
    1163                 :            : 
    1164   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
             #  #  #  # ]
    1165         [ #  # ]:          0 :     if (!args) {
    1166                 :          0 :         goto exit;
    1167                 :            :     }
    1168         [ #  # ]:          0 :     if (!PyUnicode_Check(args[0])) {
    1169                 :          0 :         _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
    1170                 :          0 :         goto exit;
    1171                 :            :     }
    1172                 :            :     Py_ssize_t name_length;
    1173                 :          0 :     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
    1174         [ #  # ]:          0 :     if (name == NULL) {
    1175                 :          0 :         goto exit;
    1176                 :            :     }
    1177         [ #  # ]:          0 :     if (strlen(name) != (size_t)name_length) {
    1178                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
    1179                 :          0 :         goto exit;
    1180                 :            :     }
    1181                 :          0 :     callable = args[1];
    1182                 :          0 :     return_value = pysqlite_connection_create_collation_impl(self, cls, name, callable);
    1183                 :            : 
    1184                 :          0 : exit:
    1185                 :          0 :     return return_value;
    1186                 :            : }
    1187                 :            : 
    1188                 :            : #if defined(PY_SQLITE_HAVE_SERIALIZE)
    1189                 :            : 
    1190                 :            : PyDoc_STRVAR(serialize__doc__,
    1191                 :            : "serialize($self, /, *, name=\'main\')\n"
    1192                 :            : "--\n"
    1193                 :            : "\n"
    1194                 :            : "Serialize a database into a byte string.\n"
    1195                 :            : "\n"
    1196                 :            : "  name\n"
    1197                 :            : "    Which database to serialize.\n"
    1198                 :            : "\n"
    1199                 :            : "For an ordinary on-disk database file, the serialization is just a copy of the\n"
    1200                 :            : "disk file. For an in-memory database or a \"temp\" database, the serialization is\n"
    1201                 :            : "the same sequence of bytes which would be written to disk if that database\n"
    1202                 :            : "were backed up to disk.");
    1203                 :            : 
    1204                 :            : #define SERIALIZE_METHODDEF    \
    1205                 :            :     {"serialize", _PyCFunction_CAST(serialize), METH_FASTCALL|METH_KEYWORDS, serialize__doc__},
    1206                 :            : 
    1207                 :            : static PyObject *
    1208                 :            : serialize_impl(pysqlite_Connection *self, const char *name);
    1209                 :            : 
    1210                 :            : static PyObject *
    1211                 :            : serialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    1212                 :            : {
    1213                 :            :     PyObject *return_value = NULL;
    1214                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
    1215                 :            : 
    1216                 :            :     #define NUM_KEYWORDS 1
    1217                 :            :     static struct {
    1218                 :            :         PyGC_Head _this_is_not_used;
    1219                 :            :         PyObject_VAR_HEAD
    1220                 :            :         PyObject *ob_item[NUM_KEYWORDS];
    1221                 :            :     } _kwtuple = {
    1222                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
    1223                 :            :         .ob_item = { &_Py_ID(name), },
    1224                 :            :     };
    1225                 :            :     #undef NUM_KEYWORDS
    1226                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
    1227                 :            : 
    1228                 :            :     #else  // !Py_BUILD_CORE
    1229                 :            :     #  define KWTUPLE NULL
    1230                 :            :     #endif  // !Py_BUILD_CORE
    1231                 :            : 
    1232                 :            :     static const char * const _keywords[] = {"name", NULL};
    1233                 :            :     static _PyArg_Parser _parser = {
    1234                 :            :         .keywords = _keywords,
    1235                 :            :         .fname = "serialize",
    1236                 :            :         .kwtuple = KWTUPLE,
    1237                 :            :     };
    1238                 :            :     #undef KWTUPLE
    1239                 :            :     PyObject *argsbuf[1];
    1240                 :            :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
    1241                 :            :     const char *name = "main";
    1242                 :            : 
    1243                 :            :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
    1244                 :            :     if (!args) {
    1245                 :            :         goto exit;
    1246                 :            :     }
    1247                 :            :     if (!noptargs) {
    1248                 :            :         goto skip_optional_kwonly;
    1249                 :            :     }
    1250                 :            :     if (!PyUnicode_Check(args[0])) {
    1251                 :            :         _PyArg_BadArgument("serialize", "argument 'name'", "str", args[0]);
    1252                 :            :         goto exit;
    1253                 :            :     }
    1254                 :            :     Py_ssize_t name_length;
    1255                 :            :     name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
    1256                 :            :     if (name == NULL) {
    1257                 :            :         goto exit;
    1258                 :            :     }
    1259                 :            :     if (strlen(name) != (size_t)name_length) {
    1260                 :            :         PyErr_SetString(PyExc_ValueError, "embedded null character");
    1261                 :            :         goto exit;
    1262                 :            :     }
    1263                 :            : skip_optional_kwonly:
    1264                 :            :     return_value = serialize_impl(self, name);
    1265                 :            : 
    1266                 :            : exit:
    1267                 :            :     return return_value;
    1268                 :            : }
    1269                 :            : 
    1270                 :            : #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
    1271                 :            : 
    1272                 :            : #if defined(PY_SQLITE_HAVE_SERIALIZE)
    1273                 :            : 
    1274                 :            : PyDoc_STRVAR(deserialize__doc__,
    1275                 :            : "deserialize($self, data, /, *, name=\'main\')\n"
    1276                 :            : "--\n"
    1277                 :            : "\n"
    1278                 :            : "Load a serialized database.\n"
    1279                 :            : "\n"
    1280                 :            : "  data\n"
    1281                 :            : "    The serialized database content.\n"
    1282                 :            : "  name\n"
    1283                 :            : "    Which database to reopen with the deserialization.\n"
    1284                 :            : "\n"
    1285                 :            : "The deserialize interface causes the database connection to disconnect from the\n"
    1286                 :            : "target database, and then reopen it as an in-memory database based on the given\n"
    1287                 :            : "serialized data.\n"
    1288                 :            : "\n"
    1289                 :            : "The deserialize interface will fail with SQLITE_BUSY if the database is\n"
    1290                 :            : "currently in a read transaction or is involved in a backup operation.");
    1291                 :            : 
    1292                 :            : #define DESERIALIZE_METHODDEF    \
    1293                 :            :     {"deserialize", _PyCFunction_CAST(deserialize), METH_FASTCALL|METH_KEYWORDS, deserialize__doc__},
    1294                 :            : 
    1295                 :            : static PyObject *
    1296                 :            : deserialize_impl(pysqlite_Connection *self, Py_buffer *data,
    1297                 :            :                  const char *name);
    1298                 :            : 
    1299                 :            : static PyObject *
    1300                 :            : deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
    1301                 :            : {
    1302                 :            :     PyObject *return_value = NULL;
    1303                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
    1304                 :            : 
    1305                 :            :     #define NUM_KEYWORDS 1
    1306                 :            :     static struct {
    1307                 :            :         PyGC_Head _this_is_not_used;
    1308                 :            :         PyObject_VAR_HEAD
    1309                 :            :         PyObject *ob_item[NUM_KEYWORDS];
    1310                 :            :     } _kwtuple = {
    1311                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
    1312                 :            :         .ob_item = { &_Py_ID(name), },
    1313                 :            :     };
    1314                 :            :     #undef NUM_KEYWORDS
    1315                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
    1316                 :            : 
    1317                 :            :     #else  // !Py_BUILD_CORE
    1318                 :            :     #  define KWTUPLE NULL
    1319                 :            :     #endif  // !Py_BUILD_CORE
    1320                 :            : 
    1321                 :            :     static const char * const _keywords[] = {"", "name", NULL};
    1322                 :            :     static _PyArg_Parser _parser = {
    1323                 :            :         .keywords = _keywords,
    1324                 :            :         .fname = "deserialize",
    1325                 :            :         .kwtuple = KWTUPLE,
    1326                 :            :     };
    1327                 :            :     #undef KWTUPLE
    1328                 :            :     PyObject *argsbuf[2];
    1329                 :            :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
    1330                 :            :     Py_buffer data = {NULL, NULL};
    1331                 :            :     const char *name = "main";
    1332                 :            : 
    1333                 :            :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
    1334                 :            :     if (!args) {
    1335                 :            :         goto exit;
    1336                 :            :     }
    1337                 :            :     if (PyUnicode_Check(args[0])) {
    1338                 :            :         Py_ssize_t len;
    1339                 :            :         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
    1340                 :            :         if (ptr == NULL) {
    1341                 :            :             goto exit;
    1342                 :            :         }
    1343                 :            :         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
    1344                 :            :     }
    1345                 :            :     else { /* any bytes-like object */
    1346                 :            :         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
    1347                 :            :             goto exit;
    1348                 :            :         }
    1349                 :            :         if (!PyBuffer_IsContiguous(&data, 'C')) {
    1350                 :            :             _PyArg_BadArgument("deserialize", "argument 1", "contiguous buffer", args[0]);
    1351                 :            :             goto exit;
    1352                 :            :         }
    1353                 :            :     }
    1354                 :            :     if (!noptargs) {
    1355                 :            :         goto skip_optional_kwonly;
    1356                 :            :     }
    1357                 :            :     if (!PyUnicode_Check(args[1])) {
    1358                 :            :         _PyArg_BadArgument("deserialize", "argument 'name'", "str", args[1]);
    1359                 :            :         goto exit;
    1360                 :            :     }
    1361                 :            :     Py_ssize_t name_length;
    1362                 :            :     name = PyUnicode_AsUTF8AndSize(args[1], &name_length);
    1363                 :            :     if (name == NULL) {
    1364                 :            :         goto exit;
    1365                 :            :     }
    1366                 :            :     if (strlen(name) != (size_t)name_length) {
    1367                 :            :         PyErr_SetString(PyExc_ValueError, "embedded null character");
    1368                 :            :         goto exit;
    1369                 :            :     }
    1370                 :            : skip_optional_kwonly:
    1371                 :            :     return_value = deserialize_impl(self, &data, name);
    1372                 :            : 
    1373                 :            : exit:
    1374                 :            :     /* Cleanup for data */
    1375                 :            :     if (data.obj) {
    1376                 :            :        PyBuffer_Release(&data);
    1377                 :            :     }
    1378                 :            : 
    1379                 :            :     return return_value;
    1380                 :            : }
    1381                 :            : 
    1382                 :            : #endif /* defined(PY_SQLITE_HAVE_SERIALIZE) */
    1383                 :            : 
    1384                 :            : PyDoc_STRVAR(pysqlite_connection_enter__doc__,
    1385                 :            : "__enter__($self, /)\n"
    1386                 :            : "--\n"
    1387                 :            : "\n"
    1388                 :            : "Called when the connection is used as a context manager.\n"
    1389                 :            : "\n"
    1390                 :            : "Returns itself as a convenience to the caller.");
    1391                 :            : 
    1392                 :            : #define PYSQLITE_CONNECTION_ENTER_METHODDEF    \
    1393                 :            :     {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS, pysqlite_connection_enter__doc__},
    1394                 :            : 
    1395                 :            : static PyObject *
    1396                 :            : pysqlite_connection_enter_impl(pysqlite_Connection *self);
    1397                 :            : 
    1398                 :            : static PyObject *
    1399                 :          0 : pysqlite_connection_enter(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
    1400                 :            : {
    1401                 :          0 :     return pysqlite_connection_enter_impl(self);
    1402                 :            : }
    1403                 :            : 
    1404                 :            : PyDoc_STRVAR(pysqlite_connection_exit__doc__,
    1405                 :            : "__exit__($self, type, value, traceback, /)\n"
    1406                 :            : "--\n"
    1407                 :            : "\n"
    1408                 :            : "Called when the connection is used as a context manager.\n"
    1409                 :            : "\n"
    1410                 :            : "If there was any exception, a rollback takes place; otherwise we commit.");
    1411                 :            : 
    1412                 :            : #define PYSQLITE_CONNECTION_EXIT_METHODDEF    \
    1413                 :            :     {"__exit__", _PyCFunction_CAST(pysqlite_connection_exit), METH_FASTCALL, pysqlite_connection_exit__doc__},
    1414                 :            : 
    1415                 :            : static PyObject *
    1416                 :            : pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
    1417                 :            :                               PyObject *exc_value, PyObject *exc_tb);
    1418                 :            : 
    1419                 :            : static PyObject *
    1420                 :          0 : pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
    1421                 :            : {
    1422                 :          0 :     PyObject *return_value = NULL;
    1423                 :            :     PyObject *exc_type;
    1424                 :            :     PyObject *exc_value;
    1425                 :            :     PyObject *exc_tb;
    1426                 :            : 
    1427   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
                   #  # ]
    1428                 :          0 :         goto exit;
    1429                 :            :     }
    1430                 :          0 :     exc_type = args[0];
    1431                 :          0 :     exc_value = args[1];
    1432                 :          0 :     exc_tb = args[2];
    1433                 :          0 :     return_value = pysqlite_connection_exit_impl(self, exc_type, exc_value, exc_tb);
    1434                 :            : 
    1435                 :          0 : exit:
    1436                 :          0 :     return return_value;
    1437                 :            : }
    1438                 :            : 
    1439                 :            : PyDoc_STRVAR(setlimit__doc__,
    1440                 :            : "setlimit($self, category, limit, /)\n"
    1441                 :            : "--\n"
    1442                 :            : "\n"
    1443                 :            : "Set connection run-time limits.\n"
    1444                 :            : "\n"
    1445                 :            : "  category\n"
    1446                 :            : "    The limit category to be set.\n"
    1447                 :            : "  limit\n"
    1448                 :            : "    The new limit. If the new limit is a negative number, the limit is\n"
    1449                 :            : "    unchanged.\n"
    1450                 :            : "\n"
    1451                 :            : "Attempts to increase a limit above its hard upper bound are silently truncated\n"
    1452                 :            : "to the hard upper bound. Regardless of whether or not the limit was changed,\n"
    1453                 :            : "the prior value of the limit is returned.");
    1454                 :            : 
    1455                 :            : #define SETLIMIT_METHODDEF    \
    1456                 :            :     {"setlimit", _PyCFunction_CAST(setlimit), METH_FASTCALL, setlimit__doc__},
    1457                 :            : 
    1458                 :            : static PyObject *
    1459                 :            : setlimit_impl(pysqlite_Connection *self, int category, int limit);
    1460                 :            : 
    1461                 :            : static PyObject *
    1462                 :          0 : setlimit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
    1463                 :            : {
    1464                 :          0 :     PyObject *return_value = NULL;
    1465                 :            :     int category;
    1466                 :            :     int limit;
    1467                 :            : 
    1468   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("setlimit", nargs, 2, 2)) {
                   #  # ]
    1469                 :          0 :         goto exit;
    1470                 :            :     }
    1471                 :          0 :     category = _PyLong_AsInt(args[0]);
    1472   [ #  #  #  # ]:          0 :     if (category == -1 && PyErr_Occurred()) {
    1473                 :          0 :         goto exit;
    1474                 :            :     }
    1475                 :          0 :     limit = _PyLong_AsInt(args[1]);
    1476   [ #  #  #  # ]:          0 :     if (limit == -1 && PyErr_Occurred()) {
    1477                 :          0 :         goto exit;
    1478                 :            :     }
    1479                 :          0 :     return_value = setlimit_impl(self, category, limit);
    1480                 :            : 
    1481                 :          0 : exit:
    1482                 :          0 :     return return_value;
    1483                 :            : }
    1484                 :            : 
    1485                 :            : PyDoc_STRVAR(getlimit__doc__,
    1486                 :            : "getlimit($self, category, /)\n"
    1487                 :            : "--\n"
    1488                 :            : "\n"
    1489                 :            : "Get connection run-time limits.\n"
    1490                 :            : "\n"
    1491                 :            : "  category\n"
    1492                 :            : "    The limit category to be queried.");
    1493                 :            : 
    1494                 :            : #define GETLIMIT_METHODDEF    \
    1495                 :            :     {"getlimit", (PyCFunction)getlimit, METH_O, getlimit__doc__},
    1496                 :            : 
    1497                 :            : static PyObject *
    1498                 :            : getlimit_impl(pysqlite_Connection *self, int category);
    1499                 :            : 
    1500                 :            : static PyObject *
    1501                 :          0 : getlimit(pysqlite_Connection *self, PyObject *arg)
    1502                 :            : {
    1503                 :          0 :     PyObject *return_value = NULL;
    1504                 :            :     int category;
    1505                 :            : 
    1506                 :          0 :     category = _PyLong_AsInt(arg);
    1507   [ #  #  #  # ]:          0 :     if (category == -1 && PyErr_Occurred()) {
    1508                 :          0 :         goto exit;
    1509                 :            :     }
    1510                 :          0 :     return_value = getlimit_impl(self, category);
    1511                 :            : 
    1512                 :          0 : exit:
    1513                 :          0 :     return return_value;
    1514                 :            : }
    1515                 :            : 
    1516                 :            : #ifndef CREATE_WINDOW_FUNCTION_METHODDEF
    1517                 :            :     #define CREATE_WINDOW_FUNCTION_METHODDEF
    1518                 :            : #endif /* !defined(CREATE_WINDOW_FUNCTION_METHODDEF) */
    1519                 :            : 
    1520                 :            : #ifndef PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
    1521                 :            :     #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
    1522                 :            : #endif /* !defined(PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF) */
    1523                 :            : 
    1524                 :            : #ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
    1525                 :            :     #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
    1526                 :            : #endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
    1527                 :            : 
    1528                 :            : #ifndef SERIALIZE_METHODDEF
    1529                 :            :     #define SERIALIZE_METHODDEF
    1530                 :            : #endif /* !defined(SERIALIZE_METHODDEF) */
    1531                 :            : 
    1532                 :            : #ifndef DESERIALIZE_METHODDEF
    1533                 :            :     #define DESERIALIZE_METHODDEF
    1534                 :            : #endif /* !defined(DESERIALIZE_METHODDEF) */
    1535                 :            : /*[clinic end generated code: output=f10306e10427488b input=a9049054013a1b77]*/

Generated by: LCOV version 1.14