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