summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/_sqlite
diff options
context:
space:
mode:
authormonster <[email protected]>2022-07-07 14:41:37 +0300
committermonster <[email protected]>2022-07-07 14:41:37 +0300
commit06e5c21a835c0e923506c4ff27929f34e00761c2 (patch)
tree75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /contrib/tools/python3/src/Modules/_sqlite
parent03f024c4412e3aa613bb543cf1660176320ba8f4 (diff)
fix ya.make
Diffstat (limited to 'contrib/tools/python3/src/Modules/_sqlite')
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/cache.c351
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/cache.h68
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/clinic/connection.c.h709
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/clinic/cursor.c.h262
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/clinic/module.c.h225
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/clinic/row.c.h56
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/connection.c2027
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/connection.h119
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/cursor.c1072
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/cursor.h60
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/microprotocols.c148
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/microprotocols.h47
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/module.c444
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/module.h54
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.c74
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.h38
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/row.c272
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/row.h40
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/statement.c532
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/statement.h56
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/util.c124
-rw-r--r--contrib/tools/python3/src/Modules/_sqlite/util.h42
22 files changed, 0 insertions, 6820 deletions
diff --git a/contrib/tools/python3/src/Modules/_sqlite/cache.c b/contrib/tools/python3/src/Modules/_sqlite/cache.c
deleted file mode 100644
index fd4e619f6a0..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/cache.c
+++ /dev/null
@@ -1,351 +0,0 @@
-/* cache .c - a LRU cache
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "cache.h"
-#include <limits.h>
-
-/* only used internally */
-static pysqlite_Node *
-pysqlite_new_node(PyObject *key, PyObject *data)
-{
- pysqlite_Node* node;
-
- node = (pysqlite_Node*) (pysqlite_NodeType->tp_alloc(pysqlite_NodeType, 0));
- if (!node) {
- return NULL;
- }
-
- node->key = Py_NewRef(key);
- node->data = Py_NewRef(data);
-
- node->prev = NULL;
- node->next = NULL;
-
- return node;
-}
-
-static int
-node_traverse(pysqlite_Node *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- Py_VISIT(self->key);
- Py_VISIT(self->data);
- return 0;
-}
-
-static int
-node_clear(pysqlite_Node *self)
-{
- Py_CLEAR(self->key);
- Py_CLEAR(self->data);
- return 0;
-}
-
-static void
-pysqlite_node_dealloc(pysqlite_Node *self)
-{
- PyTypeObject *tp = Py_TYPE(self);
- PyObject_GC_UnTrack(self);
- tp->tp_clear((PyObject *)self);
- tp->tp_free(self);
- Py_DECREF(tp);
-}
-
-static int
-pysqlite_cache_init(pysqlite_Cache *self, PyObject *args, PyObject *kwargs)
-{
- PyObject* factory;
- int size = 10;
-
- self->factory = NULL;
-
- if (!PyArg_ParseTuple(args, "O|i", &factory, &size)) {
- return -1;
- }
-
- /* minimum cache size is 5 entries */
- if (size < 5) {
- size = 5;
- }
- self->size = size;
- self->first = NULL;
- self->last = NULL;
-
- self->mapping = PyDict_New();
- if (!self->mapping) {
- return -1;
- }
-
- self->factory = Py_NewRef(factory);
-
- self->decref_factory = 1;
-
- return 0;
-}
-
-static int
-cache_traverse(pysqlite_Cache *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- Py_VISIT(self->mapping);
- if (self->decref_factory) {
- Py_VISIT(self->factory);
- }
-
- pysqlite_Node *node = self->first;
- while (node) {
- Py_VISIT(node);
- node = node->next;
- }
- return 0;
-}
-
-static int
-cache_clear(pysqlite_Cache *self)
-{
- Py_CLEAR(self->mapping);
- if (self->decref_factory) {
- Py_CLEAR(self->factory);
- }
-
- /* iterate over all nodes and deallocate them */
- pysqlite_Node *node = self->first;
- self->first = NULL;
- while (node) {
- pysqlite_Node *delete_node = node;
- node = node->next;
- Py_CLEAR(delete_node);
- }
- return 0;
-}
-
-static void
-pysqlite_cache_dealloc(pysqlite_Cache *self)
-{
- if (!self->factory) {
- /* constructor failed, just get out of here */
- return;
- }
-
- PyObject_GC_UnTrack(self);
- PyTypeObject *tp = Py_TYPE(self);
- tp->tp_clear((PyObject *)self);
- tp->tp_free(self);
- Py_DECREF(tp);
-}
-
-PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* key)
-{
- pysqlite_Node* node;
- pysqlite_Node* ptr;
- PyObject* data;
-
- node = (pysqlite_Node*)PyDict_GetItemWithError(self->mapping, key);
- if (node) {
- /* an entry for this key already exists in the cache */
-
- /* increase usage counter of the node found */
- if (node->count < LONG_MAX) {
- node->count++;
- }
-
- /* if necessary, reorder entries in the cache by swapping positions */
- if (node->prev && node->count > node->prev->count) {
- ptr = node->prev;
-
- while (ptr->prev && node->count > ptr->prev->count) {
- ptr = ptr->prev;
- }
-
- if (node->next) {
- node->next->prev = node->prev;
- } else {
- self->last = node->prev;
- }
- if (node->prev) {
- node->prev->next = node->next;
- }
- if (ptr->prev) {
- ptr->prev->next = node;
- } else {
- self->first = node;
- }
-
- node->next = ptr;
- node->prev = ptr->prev;
- if (!node->prev) {
- self->first = node;
- }
- ptr->prev = node;
- }
- }
- else if (PyErr_Occurred()) {
- return NULL;
- }
- else {
- /* There is no entry for this key in the cache, yet. We'll insert a new
- * entry in the cache, and make space if necessary by throwing the
- * least used item out of the cache. */
-
- if (PyDict_GET_SIZE(self->mapping) == self->size) {
- if (self->last) {
- node = self->last;
-
- if (PyDict_DelItem(self->mapping, self->last->key) != 0) {
- return NULL;
- }
-
- if (node->prev) {
- node->prev->next = NULL;
- }
- self->last = node->prev;
- node->prev = NULL;
-
- Py_DECREF(node);
- }
- }
-
- /* We cannot replace this by PyObject_CallOneArg() since
- * PyObject_CallFunction() has a special case when using a
- * single tuple as argument. */
- data = PyObject_CallFunction(self->factory, "O", key);
-
- if (!data) {
- return NULL;
- }
-
- node = pysqlite_new_node(key, data);
- if (!node) {
- return NULL;
- }
- node->prev = self->last;
-
- Py_DECREF(data);
-
- if (PyDict_SetItem(self->mapping, key, (PyObject*)node) != 0) {
- Py_DECREF(node);
- return NULL;
- }
-
- if (self->last) {
- self->last->next = node;
- } else {
- self->first = node;
- }
- self->last = node;
- }
-
- return Py_NewRef(node->data);
-}
-
-static PyObject *
-pysqlite_cache_display(pysqlite_Cache *self, PyObject *args)
-{
- pysqlite_Node* ptr;
- PyObject* prevkey;
- PyObject* nextkey;
- PyObject* display_str;
-
- ptr = self->first;
-
- while (ptr) {
- if (ptr->prev) {
- prevkey = ptr->prev->key;
- } else {
- prevkey = Py_None;
- }
-
- if (ptr->next) {
- nextkey = ptr->next->key;
- } else {
- nextkey = Py_None;
- }
-
- display_str = PyUnicode_FromFormat("%S <- %S -> %S\n",
- prevkey, ptr->key, nextkey);
- if (!display_str) {
- return NULL;
- }
- PyObject_Print(display_str, stdout, Py_PRINT_RAW);
- Py_DECREF(display_str);
-
- ptr = ptr->next;
- }
-
- Py_RETURN_NONE;
-}
-
-static PyType_Slot node_slots[] = {
- {Py_tp_dealloc, pysqlite_node_dealloc},
- {Py_tp_traverse, node_traverse},
- {Py_tp_clear, node_clear},
- {0, NULL},
-};
-
-static PyType_Spec node_spec = {
- .name = MODULE_NAME ".Node",
- .basicsize = sizeof(pysqlite_Node),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
- .slots = node_slots,
-};
-PyTypeObject *pysqlite_NodeType = NULL;
-
-static PyMethodDef cache_methods[] = {
- {"get", (PyCFunction)pysqlite_cache_get, METH_O,
- PyDoc_STR("Gets an entry from the cache or calls the factory function to produce one.")},
- {"display", (PyCFunction)pysqlite_cache_display, METH_NOARGS,
- PyDoc_STR("For debugging only.")},
- {NULL, NULL}
-};
-
-static PyType_Slot cache_slots[] = {
- {Py_tp_dealloc, pysqlite_cache_dealloc},
- {Py_tp_methods, cache_methods},
- {Py_tp_init, pysqlite_cache_init},
- {Py_tp_traverse, cache_traverse},
- {Py_tp_clear, cache_clear},
- {0, NULL},
-};
-
-static PyType_Spec cache_spec = {
- .name = MODULE_NAME ".Cache",
- .basicsize = sizeof(pysqlite_Cache),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
- .slots = cache_slots,
-};
-PyTypeObject *pysqlite_CacheType = NULL;
-
-int
-pysqlite_cache_setup_types(PyObject *mod)
-{
- pysqlite_NodeType = (PyTypeObject *)PyType_FromModuleAndSpec(mod, &node_spec, NULL);
- if (pysqlite_NodeType == NULL) {
- return -1;
- }
-
- pysqlite_CacheType = (PyTypeObject *)PyType_FromModuleAndSpec(mod, &cache_spec, NULL);
- if (pysqlite_CacheType == NULL) {
- return -1;
- }
- return 0;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/cache.h b/contrib/tools/python3/src/Modules/_sqlite/cache.h
deleted file mode 100644
index 083356f93f9..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/cache.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* cache.h - definitions for the LRU cache
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_CACHE_H
-#define PYSQLITE_CACHE_H
-#include "module.h"
-
-/* The LRU cache is implemented as a combination of a doubly-linked with a
- * dictionary. The list items are of type 'Node' and the dictionary has the
- * nodes as values. */
-
-typedef struct _pysqlite_Node
-{
- PyObject_HEAD
- PyObject* key;
- PyObject* data;
- long count;
- struct _pysqlite_Node* prev;
- struct _pysqlite_Node* next;
-} pysqlite_Node;
-
-typedef struct
-{
- PyObject_HEAD
- int size;
-
- /* a dictionary mapping keys to Node entries */
- PyObject* mapping;
-
- /* the factory callable */
- PyObject* factory;
-
- pysqlite_Node* first;
- pysqlite_Node* last;
-
- /* if set, decrement the factory function when the Cache is deallocated.
- * this is almost always desirable, but not in the pysqlite context */
- int decref_factory;
-} pysqlite_Cache;
-
-extern PyTypeObject *pysqlite_NodeType;
-extern PyTypeObject *pysqlite_CacheType;
-
-PyObject* pysqlite_cache_get(pysqlite_Cache* self, PyObject* args);
-
-int pysqlite_cache_setup_types(PyObject *module);
-
-#endif
diff --git a/contrib/tools/python3/src/Modules/_sqlite/clinic/connection.c.h b/contrib/tools/python3/src/Modules/_sqlite/clinic/connection.c.h
deleted file mode 100644
index 9ddce41e90d..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/clinic/connection.c.h
+++ /dev/null
@@ -1,709 +0,0 @@
-/*[clinic input]
-preserve
-[clinic start generated code]*/
-
-PyDoc_STRVAR(pysqlite_connection_cursor__doc__,
-"cursor($self, /, factory=<unrepresentable>)\n"
-"--\n"
-"\n"
-"Return a cursor for the connection.");
-
-#define PYSQLITE_CONNECTION_CURSOR_METHODDEF \
- {"cursor", (PyCFunction)(void(*)(void))pysqlite_connection_cursor, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_cursor__doc__},
-
-static PyObject *
-pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory);
-
-static PyObject *
-pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"factory", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "cursor", 0};
- PyObject *argsbuf[1];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- PyObject *factory = NULL;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- factory = args[0];
-skip_optional_pos:
- return_value = pysqlite_connection_cursor_impl(self, factory);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_close__doc__,
-"close($self, /)\n"
-"--\n"
-"\n"
-"Closes the connection.");
-
-#define PYSQLITE_CONNECTION_CLOSE_METHODDEF \
- {"close", (PyCFunction)pysqlite_connection_close, METH_NOARGS, pysqlite_connection_close__doc__},
-
-static PyObject *
-pysqlite_connection_close_impl(pysqlite_Connection *self);
-
-static PyObject *
-pysqlite_connection_close(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_connection_close_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_connection_commit__doc__,
-"commit($self, /)\n"
-"--\n"
-"\n"
-"Commit the current transaction.");
-
-#define PYSQLITE_CONNECTION_COMMIT_METHODDEF \
- {"commit", (PyCFunction)pysqlite_connection_commit, METH_NOARGS, pysqlite_connection_commit__doc__},
-
-static PyObject *
-pysqlite_connection_commit_impl(pysqlite_Connection *self);
-
-static PyObject *
-pysqlite_connection_commit(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_connection_commit_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_connection_rollback__doc__,
-"rollback($self, /)\n"
-"--\n"
-"\n"
-"Roll back the current transaction.");
-
-#define PYSQLITE_CONNECTION_ROLLBACK_METHODDEF \
- {"rollback", (PyCFunction)pysqlite_connection_rollback, METH_NOARGS, pysqlite_connection_rollback__doc__},
-
-static PyObject *
-pysqlite_connection_rollback_impl(pysqlite_Connection *self);
-
-static PyObject *
-pysqlite_connection_rollback(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_connection_rollback_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_connection_create_function__doc__,
-"create_function($self, /, name, narg, func, *, deterministic=False)\n"
-"--\n"
-"\n"
-"Creates a new function.");
-
-#define PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF \
- {"create_function", (PyCFunction)(void(*)(void))pysqlite_connection_create_function, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_function__doc__},
-
-static PyObject *
-pysqlite_connection_create_function_impl(pysqlite_Connection *self,
- const char *name, int narg,
- PyObject *func, int deterministic);
-
-static PyObject *
-pysqlite_connection_create_function(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"name", "narg", "func", "deterministic", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "create_function", 0};
- PyObject *argsbuf[4];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
- const char *name;
- int narg;
- PyObject *func;
- int deterministic = 0;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
- goto exit;
- }
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
- if (name == NULL) {
- goto exit;
- }
- if (strlen(name) != (size_t)name_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
- narg = _PyLong_AsInt(args[1]);
- if (narg == -1 && PyErr_Occurred()) {
- goto exit;
- }
- func = args[2];
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- deterministic = PyObject_IsTrue(args[3]);
- if (deterministic < 0) {
- goto exit;
- }
-skip_optional_kwonly:
- return_value = pysqlite_connection_create_function_impl(self, name, narg, func, deterministic);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_create_aggregate__doc__,
-"create_aggregate($self, /, name, n_arg, aggregate_class)\n"
-"--\n"
-"\n"
-"Creates a new aggregate.");
-
-#define PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF \
- {"create_aggregate", (PyCFunction)(void(*)(void))pysqlite_connection_create_aggregate, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_aggregate__doc__},
-
-static PyObject *
-pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
- const char *name, int n_arg,
- PyObject *aggregate_class);
-
-static PyObject *
-pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"name", "n_arg", "aggregate_class", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "create_aggregate", 0};
- PyObject *argsbuf[3];
- const char *name;
- int n_arg;
- PyObject *aggregate_class;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
- goto exit;
- }
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[0], &name_length);
- if (name == NULL) {
- goto exit;
- }
- if (strlen(name) != (size_t)name_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
- n_arg = _PyLong_AsInt(args[1]);
- if (n_arg == -1 && PyErr_Occurred()) {
- goto exit;
- }
- aggregate_class = args[2];
- return_value = pysqlite_connection_create_aggregate_impl(self, name, n_arg, aggregate_class);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_set_authorizer__doc__,
-"set_authorizer($self, /, authorizer_callback)\n"
-"--\n"
-"\n"
-"Sets authorizer callback.");
-
-#define PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF \
- {"set_authorizer", (PyCFunction)(void(*)(void))pysqlite_connection_set_authorizer, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_authorizer__doc__},
-
-static PyObject *
-pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
- PyObject *authorizer_cb);
-
-static PyObject *
-pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"authorizer_callback", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "set_authorizer", 0};
- PyObject *argsbuf[1];
- PyObject *authorizer_cb;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- authorizer_cb = args[0];
- return_value = pysqlite_connection_set_authorizer_impl(self, authorizer_cb);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_set_progress_handler__doc__,
-"set_progress_handler($self, /, progress_handler, n)\n"
-"--\n"
-"\n"
-"Sets progress handler callback.");
-
-#define PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF \
- {"set_progress_handler", (PyCFunction)(void(*)(void))pysqlite_connection_set_progress_handler, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_progress_handler__doc__},
-
-static PyObject *
-pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
- PyObject *progress_handler,
- int n);
-
-static PyObject *
-pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"progress_handler", "n", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "set_progress_handler", 0};
- PyObject *argsbuf[2];
- PyObject *progress_handler;
- int n;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- progress_handler = args[0];
- n = _PyLong_AsInt(args[1]);
- if (n == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = pysqlite_connection_set_progress_handler_impl(self, progress_handler, n);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_set_trace_callback__doc__,
-"set_trace_callback($self, /, trace_callback)\n"
-"--\n"
-"\n"
-"Sets a trace callback called for each SQL statement (passed as unicode).");
-
-#define PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF \
- {"set_trace_callback", (PyCFunction)(void(*)(void))pysqlite_connection_set_trace_callback, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_trace_callback__doc__},
-
-static PyObject *
-pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
- PyObject *trace_callback);
-
-static PyObject *
-pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"trace_callback", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "set_trace_callback", 0};
- PyObject *argsbuf[1];
- PyObject *trace_callback;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- trace_callback = args[0];
- return_value = pysqlite_connection_set_trace_callback_impl(self, trace_callback);
-
-exit:
- return return_value;
-}
-
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
-
-PyDoc_STRVAR(pysqlite_connection_enable_load_extension__doc__,
-"enable_load_extension($self, enable, /)\n"
-"--\n"
-"\n"
-"Enable dynamic loading of SQLite extension modules.");
-
-#define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF \
- {"enable_load_extension", (PyCFunction)pysqlite_connection_enable_load_extension, METH_O, pysqlite_connection_enable_load_extension__doc__},
-
-static PyObject *
-pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
- int onoff);
-
-static PyObject *
-pysqlite_connection_enable_load_extension(pysqlite_Connection *self, PyObject *arg)
-{
- PyObject *return_value = NULL;
- int onoff;
-
- onoff = _PyLong_AsInt(arg);
- if (onoff == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = pysqlite_connection_enable_load_extension_impl(self, onoff);
-
-exit:
- return return_value;
-}
-
-#endif /* !defined(SQLITE_OMIT_LOAD_EXTENSION) */
-
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
-
-PyDoc_STRVAR(pysqlite_connection_load_extension__doc__,
-"load_extension($self, name, /)\n"
-"--\n"
-"\n"
-"Load SQLite extension module.");
-
-#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF \
- {"load_extension", (PyCFunction)pysqlite_connection_load_extension, METH_O, pysqlite_connection_load_extension__doc__},
-
-static PyObject *
-pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
- const char *extension_name);
-
-static PyObject *
-pysqlite_connection_load_extension(pysqlite_Connection *self, PyObject *arg)
-{
- PyObject *return_value = NULL;
- const char *extension_name;
-
- if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("load_extension", "argument", "str", arg);
- goto exit;
- }
- Py_ssize_t extension_name_length;
- extension_name = PyUnicode_AsUTF8AndSize(arg, &extension_name_length);
- if (extension_name == NULL) {
- goto exit;
- }
- if (strlen(extension_name) != (size_t)extension_name_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
- return_value = pysqlite_connection_load_extension_impl(self, extension_name);
-
-exit:
- return return_value;
-}
-
-#endif /* !defined(SQLITE_OMIT_LOAD_EXTENSION) */
-
-PyDoc_STRVAR(pysqlite_connection_execute__doc__,
-"execute($self, sql, parameters=<unrepresentable>, /)\n"
-"--\n"
-"\n"
-"Executes an SQL statement.");
-
-#define PYSQLITE_CONNECTION_EXECUTE_METHODDEF \
- {"execute", (PyCFunction)(void(*)(void))pysqlite_connection_execute, METH_FASTCALL, pysqlite_connection_execute__doc__},
-
-static PyObject *
-pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
- PyObject *parameters);
-
-static PyObject *
-pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *sql;
- PyObject *parameters = NULL;
-
- if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("execute", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
- sql = args[0];
- if (nargs < 2) {
- goto skip_optional;
- }
- parameters = args[1];
-skip_optional:
- return_value = pysqlite_connection_execute_impl(self, sql, parameters);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_executemany__doc__,
-"executemany($self, sql, parameters, /)\n"
-"--\n"
-"\n"
-"Repeatedly executes an SQL statement.");
-
-#define PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF \
- {"executemany", (PyCFunction)(void(*)(void))pysqlite_connection_executemany, METH_FASTCALL, pysqlite_connection_executemany__doc__},
-
-static PyObject *
-pysqlite_connection_executemany_impl(pysqlite_Connection *self,
- PyObject *sql, PyObject *parameters);
-
-static PyObject *
-pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *sql;
- PyObject *parameters;
-
- if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
- sql = args[0];
- parameters = args[1];
- return_value = pysqlite_connection_executemany_impl(self, sql, parameters);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_executescript__doc__,
-"executescript($self, sql_script, /)\n"
-"--\n"
-"\n"
-"Executes multiple SQL statements at once.");
-
-#define PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF \
- {"executescript", (PyCFunction)pysqlite_connection_executescript, METH_O, pysqlite_connection_executescript__doc__},
-
-PyDoc_STRVAR(pysqlite_connection_interrupt__doc__,
-"interrupt($self, /)\n"
-"--\n"
-"\n"
-"Abort any pending database operation.");
-
-#define PYSQLITE_CONNECTION_INTERRUPT_METHODDEF \
- {"interrupt", (PyCFunction)pysqlite_connection_interrupt, METH_NOARGS, pysqlite_connection_interrupt__doc__},
-
-static PyObject *
-pysqlite_connection_interrupt_impl(pysqlite_Connection *self);
-
-static PyObject *
-pysqlite_connection_interrupt(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_connection_interrupt_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
-"iterdump($self, /)\n"
-"--\n"
-"\n"
-"Returns iterator to the dump of the database in an SQL text format.");
-
-#define PYSQLITE_CONNECTION_ITERDUMP_METHODDEF \
- {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS, pysqlite_connection_iterdump__doc__},
-
-static PyObject *
-pysqlite_connection_iterdump_impl(pysqlite_Connection *self);
-
-static PyObject *
-pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_connection_iterdump_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_connection_backup__doc__,
-"backup($self, /, target, *, pages=-1, progress=None, name=\'main\',\n"
-" sleep=0.25)\n"
-"--\n"
-"\n"
-"Makes a backup of the database.");
-
-#define PYSQLITE_CONNECTION_BACKUP_METHODDEF \
- {"backup", (PyCFunction)(void(*)(void))pysqlite_connection_backup, METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_backup__doc__},
-
-static PyObject *
-pysqlite_connection_backup_impl(pysqlite_Connection *self,
- pysqlite_Connection *target, int pages,
- PyObject *progress, const char *name,
- double sleep);
-
-static PyObject *
-pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"target", "pages", "progress", "name", "sleep", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "backup", 0};
- PyObject *argsbuf[5];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
- pysqlite_Connection *target;
- int pages = -1;
- PyObject *progress = Py_None;
- const char *name = "main";
- double sleep = 0.25;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!PyObject_TypeCheck(args[0], pysqlite_ConnectionType)) {
- _PyArg_BadArgument("backup", "argument 'target'", (pysqlite_ConnectionType)->tp_name, args[0]);
- goto exit;
- }
- target = (pysqlite_Connection *)args[0];
- if (!noptargs) {
- goto skip_optional_kwonly;
- }
- if (args[1]) {
- pages = _PyLong_AsInt(args[1]);
- if (pages == -1 && PyErr_Occurred()) {
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[2]) {
- progress = args[2];
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (args[3]) {
- if (!PyUnicode_Check(args[3])) {
- _PyArg_BadArgument("backup", "argument 'name'", "str", args[3]);
- goto exit;
- }
- Py_ssize_t name_length;
- name = PyUnicode_AsUTF8AndSize(args[3], &name_length);
- if (name == NULL) {
- goto exit;
- }
- if (strlen(name) != (size_t)name_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
- if (!--noptargs) {
- goto skip_optional_kwonly;
- }
- }
- if (PyFloat_CheckExact(args[4])) {
- sleep = PyFloat_AS_DOUBLE(args[4]);
- }
- else
- {
- sleep = PyFloat_AsDouble(args[4]);
- if (sleep == -1.0 && PyErr_Occurred()) {
- goto exit;
- }
- }
-skip_optional_kwonly:
- return_value = pysqlite_connection_backup_impl(self, target, pages, progress, name, sleep);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_create_collation__doc__,
-"create_collation($self, name, callback, /)\n"
-"--\n"
-"\n"
-"Creates a collation function.");
-
-#define PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF \
- {"create_collation", (PyCFunction)(void(*)(void))pysqlite_connection_create_collation, METH_FASTCALL, pysqlite_connection_create_collation__doc__},
-
-static PyObject *
-pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
- PyObject *name, PyObject *callable);
-
-static PyObject *
-pysqlite_connection_create_collation(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *name;
- PyObject *callable;
-
- if (!_PyArg_CheckPositional("create_collation", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("create_collation", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
- name = args[0];
- callable = args[1];
- return_value = pysqlite_connection_create_collation_impl(self, name, callable);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_connection_enter__doc__,
-"__enter__($self, /)\n"
-"--\n"
-"\n"
-"Called when the connection is used as a context manager.\n"
-"\n"
-"Returns itself as a convenience to the caller.");
-
-#define PYSQLITE_CONNECTION_ENTER_METHODDEF \
- {"__enter__", (PyCFunction)pysqlite_connection_enter, METH_NOARGS, pysqlite_connection_enter__doc__},
-
-static PyObject *
-pysqlite_connection_enter_impl(pysqlite_Connection *self);
-
-static PyObject *
-pysqlite_connection_enter(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_connection_enter_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_connection_exit__doc__,
-"__exit__($self, type, value, traceback, /)\n"
-"--\n"
-"\n"
-"Called when the connection is used as a context manager.\n"
-"\n"
-"If there was any exception, a rollback takes place; otherwise we commit.");
-
-#define PYSQLITE_CONNECTION_EXIT_METHODDEF \
- {"__exit__", (PyCFunction)(void(*)(void))pysqlite_connection_exit, METH_FASTCALL, pysqlite_connection_exit__doc__},
-
-static PyObject *
-pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
- PyObject *exc_value, PyObject *exc_tb);
-
-static PyObject *
-pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *exc_type;
- PyObject *exc_value;
- PyObject *exc_tb;
-
- if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
- goto exit;
- }
- exc_type = args[0];
- exc_value = args[1];
- exc_tb = args[2];
- return_value = pysqlite_connection_exit_impl(self, exc_type, exc_value, exc_tb);
-
-exit:
- return return_value;
-}
-
-#ifndef PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
- #define PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
-#endif /* !defined(PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF) */
-
-#ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
- #define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
-#endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
-/*[clinic end generated code: output=2f3f3406ba6b4d2e input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/src/Modules/_sqlite/clinic/cursor.c.h b/contrib/tools/python3/src/Modules/_sqlite/clinic/cursor.c.h
deleted file mode 100644
index c6e35a23d65..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/clinic/cursor.c.h
+++ /dev/null
@@ -1,262 +0,0 @@
-/*[clinic input]
-preserve
-[clinic start generated code]*/
-
-static int
-pysqlite_cursor_init_impl(pysqlite_Cursor *self,
- pysqlite_Connection *connection);
-
-static int
-pysqlite_cursor_init(PyObject *self, PyObject *args, PyObject *kwargs)
-{
- int return_value = -1;
- pysqlite_Connection *connection;
-
- if (Py_IS_TYPE(self, pysqlite_CursorType) &&
- !_PyArg_NoKeywords("Cursor", kwargs)) {
- goto exit;
- }
- if (!_PyArg_CheckPositional("Cursor", PyTuple_GET_SIZE(args), 1, 1)) {
- goto exit;
- }
- if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), pysqlite_ConnectionType)) {
- _PyArg_BadArgument("Cursor", "argument 1", (pysqlite_ConnectionType)->tp_name, PyTuple_GET_ITEM(args, 0));
- goto exit;
- }
- connection = (pysqlite_Connection *)PyTuple_GET_ITEM(args, 0);
- return_value = pysqlite_cursor_init_impl((pysqlite_Cursor *)self, connection);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_cursor_execute__doc__,
-"execute($self, sql, parameters=(), /)\n"
-"--\n"
-"\n"
-"Executes an SQL statement.");
-
-#define PYSQLITE_CURSOR_EXECUTE_METHODDEF \
- {"execute", (PyCFunction)(void(*)(void))pysqlite_cursor_execute, METH_FASTCALL, pysqlite_cursor_execute__doc__},
-
-static PyObject *
-pysqlite_cursor_execute_impl(pysqlite_Cursor *self, PyObject *sql,
- PyObject *parameters);
-
-static PyObject *
-pysqlite_cursor_execute(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *sql;
- PyObject *parameters = NULL;
-
- if (!_PyArg_CheckPositional("execute", nargs, 1, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("execute", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
- sql = args[0];
- if (nargs < 2) {
- goto skip_optional;
- }
- parameters = args[1];
-skip_optional:
- return_value = pysqlite_cursor_execute_impl(self, sql, parameters);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_cursor_executemany__doc__,
-"executemany($self, sql, seq_of_parameters, /)\n"
-"--\n"
-"\n"
-"Repeatedly executes an SQL statement.");
-
-#define PYSQLITE_CURSOR_EXECUTEMANY_METHODDEF \
- {"executemany", (PyCFunction)(void(*)(void))pysqlite_cursor_executemany, METH_FASTCALL, pysqlite_cursor_executemany__doc__},
-
-static PyObject *
-pysqlite_cursor_executemany_impl(pysqlite_Cursor *self, PyObject *sql,
- PyObject *seq_of_parameters);
-
-static PyObject *
-pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *sql;
- PyObject *seq_of_parameters;
-
- if (!_PyArg_CheckPositional("executemany", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("executemany", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
- sql = args[0];
- seq_of_parameters = args[1];
- return_value = pysqlite_cursor_executemany_impl(self, sql, seq_of_parameters);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_cursor_executescript__doc__,
-"executescript($self, sql_script, /)\n"
-"--\n"
-"\n"
-"Executes multiple SQL statements at once.");
-
-#define PYSQLITE_CURSOR_EXECUTESCRIPT_METHODDEF \
- {"executescript", (PyCFunction)pysqlite_cursor_executescript, METH_O, pysqlite_cursor_executescript__doc__},
-
-PyDoc_STRVAR(pysqlite_cursor_fetchone__doc__,
-"fetchone($self, /)\n"
-"--\n"
-"\n"
-"Fetches one row from the resultset.");
-
-#define PYSQLITE_CURSOR_FETCHONE_METHODDEF \
- {"fetchone", (PyCFunction)pysqlite_cursor_fetchone, METH_NOARGS, pysqlite_cursor_fetchone__doc__},
-
-static PyObject *
-pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self);
-
-static PyObject *
-pysqlite_cursor_fetchone(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_cursor_fetchone_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_cursor_fetchmany__doc__,
-"fetchmany($self, /, size=1)\n"
-"--\n"
-"\n"
-"Fetches several rows from the resultset.\n"
-"\n"
-" size\n"
-" The default value is set by the Cursor.arraysize attribute.");
-
-#define PYSQLITE_CURSOR_FETCHMANY_METHODDEF \
- {"fetchmany", (PyCFunction)(void(*)(void))pysqlite_cursor_fetchmany, METH_FASTCALL|METH_KEYWORDS, pysqlite_cursor_fetchmany__doc__},
-
-static PyObject *
-pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows);
-
-static PyObject *
-pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"size", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "fetchmany", 0};
- PyObject *argsbuf[1];
- Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- int maxrows = self->arraysize;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!noptargs) {
- goto skip_optional_pos;
- }
- maxrows = _PyLong_AsInt(args[0]);
- if (maxrows == -1 && PyErr_Occurred()) {
- goto exit;
- }
-skip_optional_pos:
- return_value = pysqlite_cursor_fetchmany_impl(self, maxrows);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_cursor_fetchall__doc__,
-"fetchall($self, /)\n"
-"--\n"
-"\n"
-"Fetches all rows from the resultset.");
-
-#define PYSQLITE_CURSOR_FETCHALL_METHODDEF \
- {"fetchall", (PyCFunction)pysqlite_cursor_fetchall, METH_NOARGS, pysqlite_cursor_fetchall__doc__},
-
-static PyObject *
-pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self);
-
-static PyObject *
-pysqlite_cursor_fetchall(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_cursor_fetchall_impl(self);
-}
-
-PyDoc_STRVAR(pysqlite_cursor_setinputsizes__doc__,
-"setinputsizes($self, sizes, /)\n"
-"--\n"
-"\n"
-"Required by DB-API. Does nothing in sqlite3.");
-
-#define PYSQLITE_CURSOR_SETINPUTSIZES_METHODDEF \
- {"setinputsizes", (PyCFunction)pysqlite_cursor_setinputsizes, METH_O, pysqlite_cursor_setinputsizes__doc__},
-
-PyDoc_STRVAR(pysqlite_cursor_setoutputsize__doc__,
-"setoutputsize($self, size, column=None, /)\n"
-"--\n"
-"\n"
-"Required by DB-API. Does nothing in sqlite3.");
-
-#define PYSQLITE_CURSOR_SETOUTPUTSIZE_METHODDEF \
- {"setoutputsize", (PyCFunction)(void(*)(void))pysqlite_cursor_setoutputsize, METH_FASTCALL, pysqlite_cursor_setoutputsize__doc__},
-
-static PyObject *
-pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
- PyObject *column);
-
-static PyObject *
-pysqlite_cursor_setoutputsize(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *size;
- PyObject *column = Py_None;
-
- if (!_PyArg_CheckPositional("setoutputsize", nargs, 1, 2)) {
- goto exit;
- }
- size = args[0];
- if (nargs < 2) {
- goto skip_optional;
- }
- column = args[1];
-skip_optional:
- return_value = pysqlite_cursor_setoutputsize_impl(self, size, column);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_cursor_close__doc__,
-"close($self, /)\n"
-"--\n"
-"\n"
-"Closes the cursor.");
-
-#define PYSQLITE_CURSOR_CLOSE_METHODDEF \
- {"close", (PyCFunction)pysqlite_cursor_close, METH_NOARGS, pysqlite_cursor_close__doc__},
-
-static PyObject *
-pysqlite_cursor_close_impl(pysqlite_Cursor *self);
-
-static PyObject *
-pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_cursor_close_impl(self);
-}
-/*[clinic end generated code: output=9879e3a5d4ee3847 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/src/Modules/_sqlite/clinic/module.c.h b/contrib/tools/python3/src/Modules/_sqlite/clinic/module.c.h
deleted file mode 100644
index 2118cb7c424..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/clinic/module.c.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*[clinic input]
-preserve
-[clinic start generated code]*/
-
-PyDoc_STRVAR(pysqlite_complete_statement__doc__,
-"complete_statement($module, /, statement)\n"
-"--\n"
-"\n"
-"Checks if a string contains a complete SQL statement.");
-
-#define PYSQLITE_COMPLETE_STATEMENT_METHODDEF \
- {"complete_statement", (PyCFunction)(void(*)(void))pysqlite_complete_statement, METH_FASTCALL|METH_KEYWORDS, pysqlite_complete_statement__doc__},
-
-static PyObject *
-pysqlite_complete_statement_impl(PyObject *module, const char *statement);
-
-static PyObject *
-pysqlite_complete_statement(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"statement", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "complete_statement", 0};
- PyObject *argsbuf[1];
- const char *statement;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("complete_statement", "argument 'statement'", "str", args[0]);
- goto exit;
- }
- Py_ssize_t statement_length;
- statement = PyUnicode_AsUTF8AndSize(args[0], &statement_length);
- if (statement == NULL) {
- goto exit;
- }
- if (strlen(statement) != (size_t)statement_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
- return_value = pysqlite_complete_statement_impl(module, statement);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_enable_shared_cache__doc__,
-"enable_shared_cache($module, /, do_enable)\n"
-"--\n"
-"\n"
-"Enable or disable shared cache mode for the calling thread.\n"
-"\n"
-"This method is deprecated and will be removed in Python 3.12.\n"
-"Shared cache is strongly discouraged by the SQLite 3 documentation.\n"
-"If shared cache must be used, open the database in URI mode using\n"
-"the cache=shared query parameter.");
-
-#define PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF \
- {"enable_shared_cache", (PyCFunction)(void(*)(void))pysqlite_enable_shared_cache, METH_FASTCALL|METH_KEYWORDS, pysqlite_enable_shared_cache__doc__},
-
-static PyObject *
-pysqlite_enable_shared_cache_impl(PyObject *module, int do_enable);
-
-static PyObject *
-pysqlite_enable_shared_cache(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
-{
- PyObject *return_value = NULL;
- static const char * const _keywords[] = {"do_enable", NULL};
- static _PyArg_Parser _parser = {NULL, _keywords, "enable_shared_cache", 0};
- PyObject *argsbuf[1];
- int do_enable;
-
- args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
- if (!args) {
- goto exit;
- }
- do_enable = _PyLong_AsInt(args[0]);
- if (do_enable == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = pysqlite_enable_shared_cache_impl(module, do_enable);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_register_adapter__doc__,
-"register_adapter($module, type, caster, /)\n"
-"--\n"
-"\n"
-"Registers an adapter with sqlite3\'s adapter registry.");
-
-#define PYSQLITE_REGISTER_ADAPTER_METHODDEF \
- {"register_adapter", (PyCFunction)(void(*)(void))pysqlite_register_adapter, METH_FASTCALL, pysqlite_register_adapter__doc__},
-
-static PyObject *
-pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
- PyObject *caster);
-
-static PyObject *
-pysqlite_register_adapter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyTypeObject *type;
- PyObject *caster;
-
- if (!_PyArg_CheckPositional("register_adapter", nargs, 2, 2)) {
- goto exit;
- }
- type = (PyTypeObject *)args[0];
- caster = args[1];
- return_value = pysqlite_register_adapter_impl(module, type, caster);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_register_converter__doc__,
-"register_converter($module, name, converter, /)\n"
-"--\n"
-"\n"
-"Registers a converter with sqlite3.");
-
-#define PYSQLITE_REGISTER_CONVERTER_METHODDEF \
- {"register_converter", (PyCFunction)(void(*)(void))pysqlite_register_converter, METH_FASTCALL, pysqlite_register_converter__doc__},
-
-static PyObject *
-pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
- PyObject *callable);
-
-static PyObject *
-pysqlite_register_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *orig_name;
- PyObject *callable;
-
- if (!_PyArg_CheckPositional("register_converter", nargs, 2, 2)) {
- goto exit;
- }
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("register_converter", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
- orig_name = args[0];
- callable = args[1];
- return_value = pysqlite_register_converter_impl(module, orig_name, callable);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_enable_callback_trace__doc__,
-"enable_callback_tracebacks($module, enable, /)\n"
-"--\n"
-"\n"
-"Enable or disable callback functions throwing errors to stderr.");
-
-#define PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF \
- {"enable_callback_tracebacks", (PyCFunction)pysqlite_enable_callback_trace, METH_O, pysqlite_enable_callback_trace__doc__},
-
-static PyObject *
-pysqlite_enable_callback_trace_impl(PyObject *module, int enable);
-
-static PyObject *
-pysqlite_enable_callback_trace(PyObject *module, PyObject *arg)
-{
- PyObject *return_value = NULL;
- int enable;
-
- enable = _PyLong_AsInt(arg);
- if (enable == -1 && PyErr_Occurred()) {
- goto exit;
- }
- return_value = pysqlite_enable_callback_trace_impl(module, enable);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_adapt__doc__,
-"adapt($module, obj, proto=PrepareProtocolType, alt=<unrepresentable>, /)\n"
-"--\n"
-"\n"
-"Adapt given object to given protocol.");
-
-#define PYSQLITE_ADAPT_METHODDEF \
- {"adapt", (PyCFunction)(void(*)(void))pysqlite_adapt, METH_FASTCALL, pysqlite_adapt__doc__},
-
-static PyObject *
-pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
- PyObject *alt);
-
-static PyObject *
-pysqlite_adapt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
-{
- PyObject *return_value = NULL;
- PyObject *obj;
- PyObject *proto = (PyObject*)pysqlite_PrepareProtocolType;
- PyObject *alt = NULL;
-
- if (!_PyArg_CheckPositional("adapt", nargs, 1, 3)) {
- goto exit;
- }
- obj = args[0];
- if (nargs < 2) {
- goto skip_optional;
- }
- proto = args[1];
- if (nargs < 3) {
- goto skip_optional;
- }
- alt = args[2];
-skip_optional:
- return_value = pysqlite_adapt_impl(module, obj, proto, alt);
-
-exit:
- return return_value;
-}
-/*[clinic end generated code: output=6939849a4371122d input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/src/Modules/_sqlite/clinic/row.c.h b/contrib/tools/python3/src/Modules/_sqlite/clinic/row.c.h
deleted file mode 100644
index 7ff110940d0..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/clinic/row.c.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*[clinic input]
-preserve
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,
- PyObject *data);
-
-static PyObject *
-pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-{
- PyObject *return_value = NULL;
- pysqlite_Cursor *cursor;
- PyObject *data;
-
- if ((type == pysqlite_RowType) &&
- !_PyArg_NoKeywords("Row", kwargs)) {
- goto exit;
- }
- if (!_PyArg_CheckPositional("Row", PyTuple_GET_SIZE(args), 2, 2)) {
- goto exit;
- }
- if (!PyObject_TypeCheck(PyTuple_GET_ITEM(args, 0), pysqlite_CursorType)) {
- _PyArg_BadArgument("Row", "argument 1", (pysqlite_CursorType)->tp_name, PyTuple_GET_ITEM(args, 0));
- goto exit;
- }
- cursor = (pysqlite_Cursor *)PyTuple_GET_ITEM(args, 0);
- if (!PyTuple_Check(PyTuple_GET_ITEM(args, 1))) {
- _PyArg_BadArgument("Row", "argument 2", "tuple", PyTuple_GET_ITEM(args, 1));
- goto exit;
- }
- data = PyTuple_GET_ITEM(args, 1);
- return_value = pysqlite_row_new_impl(type, cursor, data);
-
-exit:
- return return_value;
-}
-
-PyDoc_STRVAR(pysqlite_row_keys__doc__,
-"keys($self, /)\n"
-"--\n"
-"\n"
-"Returns the keys of the row.");
-
-#define PYSQLITE_ROW_KEYS_METHODDEF \
- {"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS, pysqlite_row_keys__doc__},
-
-static PyObject *
-pysqlite_row_keys_impl(pysqlite_Row *self);
-
-static PyObject *
-pysqlite_row_keys(pysqlite_Row *self, PyObject *Py_UNUSED(ignored))
-{
- return pysqlite_row_keys_impl(self);
-}
-/*[clinic end generated code: output=8d29220b9cde035d input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/src/Modules/_sqlite/connection.c b/contrib/tools/python3/src/Modules/_sqlite/connection.c
deleted file mode 100644
index 68c5aee79ab..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/connection.c
+++ /dev/null
@@ -1,2027 +0,0 @@
-/* connection.c - the connection type
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "cache.h"
-#include "module.h"
-#include "structmember.h" // PyMemberDef
-#include "connection.h"
-#include "statement.h"
-#include "cursor.h"
-#include "prepare_protocol.h"
-#include "util.h"
-
-#define ACTION_FINALIZE 1
-#define ACTION_RESET 2
-
-#if SQLITE_VERSION_NUMBER >= 3014000
-#define HAVE_TRACE_V2
-#endif
-
-#include "clinic/connection.c.h"
-/*[clinic input]
-module _sqlite3
-class _sqlite3.Connection "pysqlite_Connection *" "pysqlite_ConnectionType"
-[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=aa796073bd8f69db]*/
-
-_Py_IDENTIFIER(cursor);
-
-static const char * const begin_statements[] = {
- "BEGIN ",
- "BEGIN DEFERRED",
- "BEGIN IMMEDIATE",
- "BEGIN EXCLUSIVE",
- NULL
-};
-
-static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored));
-static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
-
-static int
-pysqlite_connection_init(pysqlite_Connection *self, PyObject *args,
- PyObject *kwargs)
-{
- static char *kwlist[] = {
- "database", "timeout", "detect_types", "isolation_level",
- "check_same_thread", "factory", "cached_statements", "uri",
- NULL
- };
-
- const char* database;
- PyObject* database_obj;
- int detect_types = 0;
- PyObject* isolation_level = NULL;
- PyObject* factory = NULL;
- int check_same_thread = 1;
- int cached_statements = 100;
- int uri = 0;
- double timeout = 5.0;
- int rc;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|diOiOip", kwlist,
- PyUnicode_FSConverter, &database_obj, &timeout, &detect_types,
- &isolation_level, &check_same_thread,
- &factory, &cached_statements, &uri))
- {
- return -1;
- }
-
- if (PySys_Audit("sqlite3.connect", "O", database_obj) < 0) {
- Py_DECREF(database_obj);
- return -1;
- }
-
- database = PyBytes_AsString(database_obj);
-
- self->begin_statement = NULL;
-
- Py_CLEAR(self->statement_cache);
- Py_CLEAR(self->statements);
- Py_CLEAR(self->cursors);
-
- Py_INCREF(Py_None);
- Py_XSETREF(self->row_factory, Py_None);
-
- Py_INCREF(&PyUnicode_Type);
- Py_XSETREF(self->text_factory, (PyObject*)&PyUnicode_Type);
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_open_v2(database, &self->db,
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
- (uri ? SQLITE_OPEN_URI : 0), NULL);
- Py_END_ALLOW_THREADS
-
- Py_DECREF(database_obj);
-
- if (self->db == NULL && rc == SQLITE_NOMEM) {
- PyErr_NoMemory();
- return -1;
- }
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->db, NULL);
- return -1;
- }
-
- if (!isolation_level) {
- isolation_level = PyUnicode_FromString("");
- if (!isolation_level) {
- return -1;
- }
- } else {
- Py_INCREF(isolation_level);
- }
- Py_CLEAR(self->isolation_level);
- if (pysqlite_connection_set_isolation_level(self, isolation_level, NULL) != 0) {
- Py_DECREF(isolation_level);
- return -1;
- }
- Py_DECREF(isolation_level);
-
- self->statement_cache = (pysqlite_Cache*)PyObject_CallFunction((PyObject*)pysqlite_CacheType, "Oi", self, cached_statements);
- if (PyErr_Occurred()) {
- return -1;
- }
-
- self->created_statements = 0;
- self->created_cursors = 0;
-
- /* Create lists of weak references to statements/cursors */
- self->statements = PyList_New(0);
- self->cursors = PyList_New(0);
- if (!self->statements || !self->cursors) {
- return -1;
- }
-
- /* By default, the Cache class INCREFs the factory in its initializer, and
- * decrefs it in its deallocator method. Since this would create a circular
- * reference here, we're breaking it by decrementing self, and telling the
- * cache class to not decref the factory (self) in its deallocator.
- */
- self->statement_cache->decref_factory = 0;
- Py_DECREF(self);
-
- self->detect_types = detect_types;
- self->timeout = timeout;
- (void)sqlite3_busy_timeout(self->db, (int)(timeout*1000));
- self->thread_ident = PyThread_get_thread_ident();
- self->check_same_thread = check_same_thread;
-
- self->function_pinboard_trace_callback = NULL;
- self->function_pinboard_progress_handler = NULL;
- self->function_pinboard_authorizer_cb = NULL;
-
- Py_XSETREF(self->collations, PyDict_New());
- if (!self->collations) {
- return -1;
- }
-
- self->Warning = pysqlite_Warning;
- self->Error = pysqlite_Error;
- self->InterfaceError = pysqlite_InterfaceError;
- self->DatabaseError = pysqlite_DatabaseError;
- self->DataError = pysqlite_DataError;
- self->OperationalError = pysqlite_OperationalError;
- self->IntegrityError = pysqlite_IntegrityError;
- self->InternalError = pysqlite_InternalError;
- self->ProgrammingError = pysqlite_ProgrammingError;
- self->NotSupportedError = pysqlite_NotSupportedError;
-
- if (PySys_Audit("sqlite3.connect/handle", "O", self) < 0) {
- return -1;
- }
-
- self->initialized = 1;
-
- return 0;
-}
-
-/* action in (ACTION_RESET, ACTION_FINALIZE) */
-static void
-pysqlite_do_all_statements(pysqlite_Connection *self, int action,
- int reset_cursors)
-{
- int i;
- PyObject* weakref;
- PyObject* statement;
- pysqlite_Cursor* cursor;
-
- for (i = 0; i < PyList_Size(self->statements); i++) {
- weakref = PyList_GetItem(self->statements, i);
- statement = PyWeakref_GetObject(weakref);
- if (statement != Py_None) {
- Py_INCREF(statement);
- if (action == ACTION_RESET) {
- (void)pysqlite_statement_reset((pysqlite_Statement*)statement);
- } else {
- (void)pysqlite_statement_finalize((pysqlite_Statement*)statement);
- }
- Py_DECREF(statement);
- }
- }
-
- if (reset_cursors) {
- for (i = 0; i < PyList_Size(self->cursors); i++) {
- weakref = PyList_GetItem(self->cursors, i);
- cursor = (pysqlite_Cursor*)PyWeakref_GetObject(weakref);
- if ((PyObject*)cursor != Py_None) {
- cursor->reset = 1;
- }
- }
- }
-}
-
-static int
-connection_traverse(pysqlite_Connection *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- Py_VISIT(self->isolation_level);
- Py_VISIT(self->statement_cache);
- Py_VISIT(self->statements);
- Py_VISIT(self->cursors);
- Py_VISIT(self->row_factory);
- Py_VISIT(self->text_factory);
- Py_VISIT(self->function_pinboard_trace_callback);
- Py_VISIT(self->function_pinboard_progress_handler);
- Py_VISIT(self->function_pinboard_authorizer_cb);
- Py_VISIT(self->collations);
- return 0;
-}
-
-static int
-connection_clear(pysqlite_Connection *self)
-{
- Py_CLEAR(self->isolation_level);
- Py_CLEAR(self->statement_cache);
- Py_CLEAR(self->statements);
- Py_CLEAR(self->cursors);
- Py_CLEAR(self->row_factory);
- Py_CLEAR(self->text_factory);
- Py_CLEAR(self->function_pinboard_trace_callback);
- Py_CLEAR(self->function_pinboard_progress_handler);
- Py_CLEAR(self->function_pinboard_authorizer_cb);
- Py_CLEAR(self->collations);
- return 0;
-}
-
-static void
-connection_dealloc(pysqlite_Connection *self)
-{
- PyTypeObject *tp = Py_TYPE(self);
- PyObject_GC_UnTrack(self);
- tp->tp_clear((PyObject *)self);
-
- /* Clean up if user has not called .close() explicitly. */
- if (self->db) {
- sqlite3_close_v2(self->db);
- }
-
- tp->tp_free(self);
- Py_DECREF(tp);
-}
-
-/*
- * Registers a cursor with the connection.
- *
- * 0 => error; 1 => ok
- */
-int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor)
-{
- PyObject* weakref;
-
- weakref = PyWeakref_NewRef((PyObject*)cursor, NULL);
- if (!weakref) {
- goto error;
- }
-
- if (PyList_Append(connection->cursors, weakref) != 0) {
- Py_CLEAR(weakref);
- goto error;
- }
-
- Py_DECREF(weakref);
-
- return 1;
-error:
- return 0;
-}
-
-/*[clinic input]
-_sqlite3.Connection.cursor as pysqlite_connection_cursor
-
- factory: object = NULL
-
-Return a cursor for the connection.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
-/*[clinic end generated code: output=562432a9e6af2aa1 input=4127345aa091b650]*/
-{
- PyObject* cursor;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (factory == NULL) {
- factory = (PyObject*)pysqlite_CursorType;
- }
-
- cursor = PyObject_CallOneArg(factory, (PyObject *)self);
- if (cursor == NULL)
- return NULL;
- if (!PyObject_TypeCheck(cursor, pysqlite_CursorType)) {
- PyErr_Format(PyExc_TypeError,
- "factory must return a cursor, not %.100s",
- Py_TYPE(cursor)->tp_name);
- Py_DECREF(cursor);
- return NULL;
- }
-
- _pysqlite_drop_unused_cursor_references(self);
-
- if (cursor && self->row_factory != Py_None) {
- Py_INCREF(self->row_factory);
- Py_XSETREF(((pysqlite_Cursor *)cursor)->row_factory, self->row_factory);
- }
-
- return cursor;
-}
-
-/*[clinic input]
-_sqlite3.Connection.close as pysqlite_connection_close
-
-Closes the connection.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_close_impl(pysqlite_Connection *self)
-/*[clinic end generated code: output=a546a0da212c9b97 input=3d58064bbffaa3d3]*/
-{
- int rc;
-
- if (!pysqlite_check_thread(self)) {
- return NULL;
- }
-
- if (!self->initialized) {
- PyErr_SetString(pysqlite_ProgrammingError,
- "Base Connection.__init__ not called.");
- return NULL;
- }
-
- pysqlite_do_all_statements(self, ACTION_FINALIZE, 1);
-
- if (self->db) {
- rc = sqlite3_close_v2(self->db);
-
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->db, NULL);
- return NULL;
- } else {
- self->db = NULL;
- }
- }
-
- Py_RETURN_NONE;
-}
-
-/*
- * Checks if a connection object is usable (i. e. not closed).
- *
- * 0 => error; 1 => ok
- */
-int pysqlite_check_connection(pysqlite_Connection* con)
-{
- if (!con->initialized) {
- PyErr_SetString(pysqlite_ProgrammingError, "Base Connection.__init__ not called.");
- return 0;
- }
-
- if (!con->db) {
- PyErr_SetString(pysqlite_ProgrammingError, "Cannot operate on a closed database.");
- return 0;
- } else {
- return 1;
- }
-}
-
-PyObject* _pysqlite_connection_begin(pysqlite_Connection* self)
-{
- int rc;
- sqlite3_stmt* statement;
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare_v2(self->db, self->begin_statement, -1, &statement,
- NULL);
- Py_END_ALLOW_THREADS
-
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->db, statement);
- goto error;
- }
-
- rc = pysqlite_step(statement, self);
- if (rc != SQLITE_DONE) {
- _pysqlite_seterror(self->db, statement);
- }
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_finalize(statement);
- Py_END_ALLOW_THREADS
-
- if (rc != SQLITE_OK && !PyErr_Occurred()) {
- _pysqlite_seterror(self->db, NULL);
- }
-
-error:
- if (PyErr_Occurred()) {
- return NULL;
- } else {
- Py_RETURN_NONE;
- }
-}
-
-/*[clinic input]
-_sqlite3.Connection.commit as pysqlite_connection_commit
-
-Commit the current transaction.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_commit_impl(pysqlite_Connection *self)
-/*[clinic end generated code: output=3da45579e89407f2 input=39c12c04dda276a8]*/
-{
- int rc;
- sqlite3_stmt* statement;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (!sqlite3_get_autocommit(self->db)) {
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare_v2(self->db, "COMMIT", -1, &statement, NULL);
- Py_END_ALLOW_THREADS
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->db, NULL);
- goto error;
- }
-
- rc = pysqlite_step(statement, self);
- if (rc != SQLITE_DONE) {
- _pysqlite_seterror(self->db, statement);
- }
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_finalize(statement);
- Py_END_ALLOW_THREADS
- if (rc != SQLITE_OK && !PyErr_Occurred()) {
- _pysqlite_seterror(self->db, NULL);
- }
-
- }
-
-error:
- if (PyErr_Occurred()) {
- return NULL;
- } else {
- Py_RETURN_NONE;
- }
-}
-
-/*[clinic input]
-_sqlite3.Connection.rollback as pysqlite_connection_rollback
-
-Roll back the current transaction.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_rollback_impl(pysqlite_Connection *self)
-/*[clinic end generated code: output=b66fa0d43e7ef305 input=12d4e8d068942830]*/
-{
- int rc;
- sqlite3_stmt* statement;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (!sqlite3_get_autocommit(self->db)) {
- pysqlite_do_all_statements(self, ACTION_RESET, 1);
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare_v2(self->db, "ROLLBACK", -1, &statement, NULL);
- Py_END_ALLOW_THREADS
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->db, NULL);
- goto error;
- }
-
- rc = pysqlite_step(statement, self);
- if (rc != SQLITE_DONE) {
- _pysqlite_seterror(self->db, statement);
- }
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_finalize(statement);
- Py_END_ALLOW_THREADS
- if (rc != SQLITE_OK && !PyErr_Occurred()) {
- _pysqlite_seterror(self->db, NULL);
- }
-
- }
-
-error:
- if (PyErr_Occurred()) {
- return NULL;
- } else {
- Py_RETURN_NONE;
- }
-}
-
-static int
-_pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
-{
- if (py_val == Py_None) {
- sqlite3_result_null(context);
- } else if (PyLong_Check(py_val)) {
- sqlite_int64 value = _pysqlite_long_as_int64(py_val);
- if (value == -1 && PyErr_Occurred())
- return -1;
- sqlite3_result_int64(context, value);
- } else if (PyFloat_Check(py_val)) {
- double value = PyFloat_AsDouble(py_val);
- if (value == -1 && PyErr_Occurred()) {
- return -1;
- }
- sqlite3_result_double(context, value);
- } else if (PyUnicode_Check(py_val)) {
- Py_ssize_t sz;
- const char *str = PyUnicode_AsUTF8AndSize(py_val, &sz);
- if (str == NULL) {
- return -1;
- }
- if (sz > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "string is longer than INT_MAX bytes");
- return -1;
- }
- sqlite3_result_text(context, str, (int)sz, SQLITE_TRANSIENT);
- } else if (PyObject_CheckBuffer(py_val)) {
- Py_buffer view;
- if (PyObject_GetBuffer(py_val, &view, PyBUF_SIMPLE) != 0) {
- PyErr_SetString(PyExc_ValueError,
- "could not convert BLOB to buffer");
- return -1;
- }
- if (view.len > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "BLOB longer than INT_MAX bytes");
- PyBuffer_Release(&view);
- return -1;
- }
- sqlite3_result_blob(context, view.buf, (int)view.len, SQLITE_TRANSIENT);
- PyBuffer_Release(&view);
- } else {
- return -1;
- }
- return 0;
-}
-
-static PyObject *
-_pysqlite_build_py_params(sqlite3_context *context, int argc,
- sqlite3_value **argv)
-{
- PyObject* args;
- int i;
- sqlite3_value* cur_value;
- PyObject* cur_py_value;
-
- args = PyTuple_New(argc);
- if (!args) {
- return NULL;
- }
-
- for (i = 0; i < argc; i++) {
- cur_value = argv[i];
- switch (sqlite3_value_type(argv[i])) {
- case SQLITE_INTEGER:
- cur_py_value = PyLong_FromLongLong(sqlite3_value_int64(cur_value));
- break;
- case SQLITE_FLOAT:
- cur_py_value = PyFloat_FromDouble(sqlite3_value_double(cur_value));
- break;
- case SQLITE_TEXT: {
- sqlite3 *db = sqlite3_context_db_handle(context);
- const char *text = (const char *)sqlite3_value_text(cur_value);
-
- if (text == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
- PyErr_NoMemory();
- goto error;
- }
-
- Py_ssize_t size = sqlite3_value_bytes(cur_value);
- cur_py_value = PyUnicode_FromStringAndSize(text, size);
- break;
- }
- case SQLITE_BLOB: {
- sqlite3 *db = sqlite3_context_db_handle(context);
- const void *blob = sqlite3_value_blob(cur_value);
-
- if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
- PyErr_NoMemory();
- goto error;
- }
-
- Py_ssize_t size = sqlite3_value_bytes(cur_value);
- cur_py_value = PyBytes_FromStringAndSize(blob, size);
- break;
- }
- case SQLITE_NULL:
- default:
- cur_py_value = Py_NewRef(Py_None);
- }
-
- if (!cur_py_value) {
- goto error;
- }
-
- PyTuple_SET_ITEM(args, i, cur_py_value);
- }
-
- return args;
-
-error:
- Py_DECREF(args);
- return NULL;
-}
-
-static void
-_pysqlite_func_callback(sqlite3_context *context, int argc, sqlite3_value **argv)
-{
- PyObject* args;
- PyObject* py_func;
- PyObject* py_retval = NULL;
- int ok;
-
- PyGILState_STATE threadstate;
-
- threadstate = PyGILState_Ensure();
-
- py_func = (PyObject*)sqlite3_user_data(context);
-
- args = _pysqlite_build_py_params(context, argc, argv);
- if (args) {
- py_retval = PyObject_CallObject(py_func, args);
- Py_DECREF(args);
- }
-
- ok = 0;
- if (py_retval) {
- ok = _pysqlite_set_result(context, py_retval) == 0;
- Py_DECREF(py_retval);
- }
- if (!ok) {
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
- sqlite3_result_error(context, "user-defined function raised exception", -1);
- }
-
- PyGILState_Release(threadstate);
-}
-
-static void _pysqlite_step_callback(sqlite3_context *context, int argc, sqlite3_value** params)
-{
- PyObject* args;
- PyObject* function_result = NULL;
- PyObject* aggregate_class;
- PyObject** aggregate_instance;
- PyObject* stepmethod = NULL;
-
- PyGILState_STATE threadstate;
-
- threadstate = PyGILState_Ensure();
-
- aggregate_class = (PyObject*)sqlite3_user_data(context);
-
- aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, sizeof(PyObject*));
-
- if (*aggregate_instance == NULL) {
- *aggregate_instance = _PyObject_CallNoArg(aggregate_class);
-
- if (PyErr_Occurred()) {
- *aggregate_instance = 0;
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
- sqlite3_result_error(context, "user-defined aggregate's '__init__' method raised error", -1);
- goto error;
- }
- }
-
- stepmethod = PyObject_GetAttrString(*aggregate_instance, "step");
- if (!stepmethod) {
- goto error;
- }
-
- args = _pysqlite_build_py_params(context, argc, params);
- if (!args) {
- goto error;
- }
-
- function_result = PyObject_CallObject(stepmethod, args);
- Py_DECREF(args);
-
- if (!function_result) {
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
- sqlite3_result_error(context, "user-defined aggregate's 'step' method raised error", -1);
- }
-
-error:
- Py_XDECREF(stepmethod);
- Py_XDECREF(function_result);
-
- PyGILState_Release(threadstate);
-}
-
-static void
-_pysqlite_final_callback(sqlite3_context *context)
-{
- PyObject* function_result;
- PyObject** aggregate_instance;
- _Py_IDENTIFIER(finalize);
- int ok;
- PyObject *exception, *value, *tb;
-
- PyGILState_STATE threadstate;
-
- threadstate = PyGILState_Ensure();
-
- aggregate_instance = (PyObject**)sqlite3_aggregate_context(context, 0);
- if (aggregate_instance == NULL) {
- /* No rows matched the query; the step handler was never called. */
- goto error;
- }
- else if (!*aggregate_instance) {
- /* this branch is executed if there was an exception in the aggregate's
- * __init__ */
-
- goto error;
- }
-
- /* Keep the exception (if any) of the last call to step() */
- PyErr_Fetch(&exception, &value, &tb);
-
- function_result = _PyObject_CallMethodIdNoArgs(*aggregate_instance, &PyId_finalize);
-
- Py_DECREF(*aggregate_instance);
-
- ok = 0;
- if (function_result) {
- ok = _pysqlite_set_result(context, function_result) == 0;
- Py_DECREF(function_result);
- }
- if (!ok) {
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
- sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
- }
-
- /* Restore the exception (if any) of the last call to step(),
- but clear also the current exception if finalize() failed */
- PyErr_Restore(exception, value, tb);
-
-error:
- PyGILState_Release(threadstate);
-}
-
-static void _pysqlite_drop_unused_statement_references(pysqlite_Connection* self)
-{
- PyObject* new_list;
- PyObject* weakref;
- int i;
-
- /* we only need to do this once in a while */
- if (self->created_statements++ < 200) {
- return;
- }
-
- self->created_statements = 0;
-
- new_list = PyList_New(0);
- if (!new_list) {
- return;
- }
-
- for (i = 0; i < PyList_Size(self->statements); i++) {
- weakref = PyList_GetItem(self->statements, i);
- if (PyWeakref_GetObject(weakref) != Py_None) {
- if (PyList_Append(new_list, weakref) != 0) {
- Py_DECREF(new_list);
- return;
- }
- }
- }
-
- Py_SETREF(self->statements, new_list);
-}
-
-static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
-{
- PyObject* new_list;
- PyObject* weakref;
- int i;
-
- /* we only need to do this once in a while */
- if (self->created_cursors++ < 200) {
- return;
- }
-
- self->created_cursors = 0;
-
- new_list = PyList_New(0);
- if (!new_list) {
- return;
- }
-
- for (i = 0; i < PyList_Size(self->cursors); i++) {
- weakref = PyList_GetItem(self->cursors, i);
- if (PyWeakref_GetObject(weakref) != Py_None) {
- if (PyList_Append(new_list, weakref) != 0) {
- Py_DECREF(new_list);
- return;
- }
- }
- }
-
- Py_SETREF(self->cursors, new_list);
-}
-
-static void _destructor(void* args)
-{
- // This function may be called without the GIL held, so we need to ensure
- // that we destroy 'args' with the GIL
- PyGILState_STATE gstate;
- gstate = PyGILState_Ensure();
- Py_DECREF((PyObject*)args);
- PyGILState_Release(gstate);
-}
-
-/*[clinic input]
-_sqlite3.Connection.create_function as pysqlite_connection_create_function
-
- name: str
- narg: int
- func: object
- *
- deterministic: bool = False
-
-Creates a new function.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_create_function_impl(pysqlite_Connection *self,
- const char *name, int narg,
- PyObject *func, int deterministic)
-/*[clinic end generated code: output=07d1877dd98c0308 input=17e16b285ee44819]*/
-{
- int rc;
- int flags = SQLITE_UTF8;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (deterministic) {
-#if SQLITE_VERSION_NUMBER < 3008003
- PyErr_SetString(pysqlite_NotSupportedError,
- "deterministic=True requires SQLite 3.8.3 or higher");
- return NULL;
-#else
- if (sqlite3_libversion_number() < 3008003) {
- PyErr_SetString(pysqlite_NotSupportedError,
- "deterministic=True requires SQLite 3.8.3 or higher");
- return NULL;
- }
- flags |= SQLITE_DETERMINISTIC;
-#endif
- }
- rc = sqlite3_create_function_v2(self->db,
- name,
- narg,
- flags,
- (void*)Py_NewRef(func),
- _pysqlite_func_callback,
- NULL,
- NULL,
- &_destructor); // will decref func
-
- if (rc != SQLITE_OK) {
- /* Workaround for SQLite bug: no error code or string is available here */
- PyErr_SetString(pysqlite_OperationalError, "Error creating function");
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.Connection.create_aggregate as pysqlite_connection_create_aggregate
-
- name: str
- n_arg: int
- aggregate_class: object
-
-Creates a new aggregate.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
- const char *name, int n_arg,
- PyObject *aggregate_class)
-/*[clinic end generated code: output=fbb2f858cfa4d8db input=a17afd1fcc930ecf]*/
-{
- int rc;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- rc = sqlite3_create_function_v2(self->db,
- name,
- n_arg,
- SQLITE_UTF8,
- (void*)Py_NewRef(aggregate_class),
- 0,
- &_pysqlite_step_callback,
- &_pysqlite_final_callback,
- &_destructor); // will decref func
- if (rc != SQLITE_OK) {
- /* Workaround for SQLite bug: no error code or string is available here */
- PyErr_SetString(pysqlite_OperationalError, "Error creating aggregate");
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static int _authorizer_callback(void* user_arg, int action, const char* arg1, const char* arg2 , const char* dbname, const char* access_attempt_source)
-{
- PyObject *ret;
- int rc;
- PyGILState_STATE gilstate;
-
- gilstate = PyGILState_Ensure();
-
- ret = PyObject_CallFunction((PyObject*)user_arg, "issss", action, arg1, arg2, dbname, access_attempt_source);
-
- if (ret == NULL) {
- if (_pysqlite_enable_callback_tracebacks)
- PyErr_Print();
- else
- PyErr_Clear();
-
- rc = SQLITE_DENY;
- }
- else {
- if (PyLong_Check(ret)) {
- rc = _PyLong_AsInt(ret);
- if (rc == -1 && PyErr_Occurred()) {
- if (_pysqlite_enable_callback_tracebacks)
- PyErr_Print();
- else
- PyErr_Clear();
- rc = SQLITE_DENY;
- }
- }
- else {
- rc = SQLITE_DENY;
- }
- Py_DECREF(ret);
- }
-
- PyGILState_Release(gilstate);
- return rc;
-}
-
-static int _progress_handler(void* user_arg)
-{
- int rc;
- PyObject *ret;
- PyGILState_STATE gilstate;
-
- gilstate = PyGILState_Ensure();
- ret = _PyObject_CallNoArg((PyObject*)user_arg);
-
- if (!ret) {
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
-
- /* abort query if error occurred */
- rc = 1;
- } else {
- rc = (int)PyObject_IsTrue(ret);
- Py_DECREF(ret);
- }
-
- PyGILState_Release(gilstate);
- return rc;
-}
-
-#ifdef HAVE_TRACE_V2
-/*
- * From https://sqlite.org/c3ref/trace_v2.html:
- * The integer return value from the callback is currently ignored, though this
- * may change in future releases. Callback implementations should return zero
- * to ensure future compatibility.
- */
-static int
-_trace_callback(unsigned int type, void *callable, void *stmt, void *sql)
-#else
-static void
-_trace_callback(void *callable, const char *sql)
-#endif
-{
-#ifdef HAVE_TRACE_V2
- if (type != SQLITE_TRACE_STMT) {
- return 0;
- }
-#endif
-
- PyGILState_STATE gilstate = PyGILState_Ensure();
-
- PyObject *py_statement = NULL;
-#ifdef HAVE_TRACE_V2
- const char *expanded_sql = sqlite3_expanded_sql((sqlite3_stmt *)stmt);
- if (expanded_sql == NULL) {
- sqlite3 *db = sqlite3_db_handle((sqlite3_stmt *)stmt);
- if (sqlite3_errcode(db) == SQLITE_NOMEM) {
- (void)PyErr_NoMemory();
- goto exit;
- }
-
- PyErr_SetString(pysqlite_DataError,
- "Expanded SQL string exceeds the maximum string length");
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
-
- // Fall back to unexpanded sql
- py_statement = PyUnicode_FromString((const char *)sql);
- }
- else {
- py_statement = PyUnicode_FromString(expanded_sql);
- sqlite3_free((void *)expanded_sql);
- }
-#else
- if (sql == NULL) {
- PyErr_SetString(pysqlite_DataError,
- "Expanded SQL string exceeds the maximum string length");
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
- goto exit;
- }
- py_statement = PyUnicode_FromString(sql);
-#endif
- if (py_statement) {
- PyObject *ret = PyObject_CallOneArg((PyObject *)callable, py_statement);
- Py_DECREF(py_statement);
- Py_XDECREF(ret);
- }
- if (PyErr_Occurred()) {
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
- }
-
-exit:
- PyGILState_Release(gilstate);
-#ifdef HAVE_TRACE_V2
- return 0;
-#endif
-}
-
-/*[clinic input]
-_sqlite3.Connection.set_authorizer as pysqlite_connection_set_authorizer
-
- authorizer_callback as authorizer_cb: object
-
-Sets authorizer callback.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
- PyObject *authorizer_cb)
-/*[clinic end generated code: output=f18ba575d788b35c input=446676a87c949d68]*/
-{
- int rc;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- rc = sqlite3_set_authorizer(self->db, _authorizer_callback, (void*)authorizer_cb);
- if (rc != SQLITE_OK) {
- PyErr_SetString(pysqlite_OperationalError, "Error setting authorizer callback");
- Py_XSETREF(self->function_pinboard_authorizer_cb, NULL);
- return NULL;
- } else {
- Py_INCREF(authorizer_cb);
- Py_XSETREF(self->function_pinboard_authorizer_cb, authorizer_cb);
- }
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.Connection.set_progress_handler as pysqlite_connection_set_progress_handler
-
- progress_handler: object
- n: int
-
-Sets progress handler callback.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
- PyObject *progress_handler,
- int n)
-/*[clinic end generated code: output=35a7c10364cb1b04 input=d9379b629c7391c7]*/
-{
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (progress_handler == Py_None) {
- /* None clears the progress handler previously set */
- sqlite3_progress_handler(self->db, 0, 0, (void*)0);
- Py_XSETREF(self->function_pinboard_progress_handler, NULL);
- } else {
- sqlite3_progress_handler(self->db, n, _progress_handler, progress_handler);
- Py_INCREF(progress_handler);
- Py_XSETREF(self->function_pinboard_progress_handler, progress_handler);
- }
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.Connection.set_trace_callback as pysqlite_connection_set_trace_callback
-
- trace_callback: object
-
-Sets a trace callback called for each SQL statement (passed as unicode).
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
- PyObject *trace_callback)
-/*[clinic end generated code: output=fb0e307b9924d454 input=885e460ebbf79f0c]*/
-{
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (trace_callback == Py_None) {
- /*
- * None clears the trace callback previously set
- *
- * Ref.
- * - https://sqlite.org/c3ref/c_trace.html
- * - https://sqlite.org/c3ref/trace_v2.html
- */
-#ifdef HAVE_TRACE_V2
- sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, 0, 0);
-#else
- sqlite3_trace(self->db, 0, (void*)0);
-#endif
- Py_XSETREF(self->function_pinboard_trace_callback, NULL);
- } else {
-#ifdef HAVE_TRACE_V2
- sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, _trace_callback, trace_callback);
-#else
- sqlite3_trace(self->db, _trace_callback, trace_callback);
-#endif
- Py_INCREF(trace_callback);
- Py_XSETREF(self->function_pinboard_trace_callback, trace_callback);
- }
-
- Py_RETURN_NONE;
-}
-
-#ifndef SQLITE_OMIT_LOAD_EXTENSION
-/*[clinic input]
-_sqlite3.Connection.enable_load_extension as pysqlite_connection_enable_load_extension
-
- enable as onoff: bool(accept={int})
- /
-
-Enable dynamic loading of SQLite extension modules.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_enable_load_extension_impl(pysqlite_Connection *self,
- int onoff)
-/*[clinic end generated code: output=9cac37190d388baf input=5f00e93f7a9d3540]*/
-{
- int rc;
-
- if (PySys_Audit("sqlite3.enable_load_extension",
- "OO", self, onoff ? Py_True : Py_False) < 0) {
- return NULL;
- }
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- rc = sqlite3_enable_load_extension(self->db, onoff);
-
- if (rc != SQLITE_OK) {
- PyErr_SetString(pysqlite_OperationalError, "Error enabling load extension");
- return NULL;
- } else {
- Py_RETURN_NONE;
- }
-}
-
-/*[clinic input]
-_sqlite3.Connection.load_extension as pysqlite_connection_load_extension
-
- name as extension_name: str
- /
-
-Load SQLite extension module.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_load_extension_impl(pysqlite_Connection *self,
- const char *extension_name)
-/*[clinic end generated code: output=47eb1d7312bc97a7 input=edd507389d89d621]*/
-{
- int rc;
- char* errmsg;
-
- if (PySys_Audit("sqlite3.load_extension", "Os", self, extension_name) < 0) {
- return NULL;
- }
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- rc = sqlite3_load_extension(self->db, extension_name, 0, &errmsg);
- if (rc != 0) {
- PyErr_SetString(pysqlite_OperationalError, errmsg);
- return NULL;
- } else {
- Py_RETURN_NONE;
- }
-}
-#endif
-
-int pysqlite_check_thread(pysqlite_Connection* self)
-{
- if (self->check_same_thread) {
- if (PyThread_get_thread_ident() != self->thread_ident) {
- PyErr_Format(pysqlite_ProgrammingError,
- "SQLite objects created in a thread can only be used in that same thread. "
- "The object was created in thread id %lu and this is thread id %lu.",
- self->thread_ident, PyThread_get_thread_ident());
- return 0;
- }
-
- }
- return 1;
-}
-
-static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused)
-{
- if (!pysqlite_check_connection(self)) {
- return NULL;
- }
- return Py_NewRef(self->isolation_level);
-}
-
-static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self, void* unused)
-{
- if (!pysqlite_check_connection(self)) {
- return NULL;
- } else {
- return Py_BuildValue("i", sqlite3_total_changes(self->db));
- }
-}
-
-static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused)
-{
- if (!pysqlite_check_connection(self)) {
- return NULL;
- }
- if (!sqlite3_get_autocommit(self->db)) {
- Py_RETURN_TRUE;
- }
- Py_RETURN_FALSE;
-}
-
-static int
-pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored))
-{
- if (isolation_level == NULL) {
- PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
- return -1;
- }
- if (isolation_level == Py_None) {
- /* We might get called during connection init, so we cannot use
- * pysqlite_connection_commit() here. */
- if (self->db && !sqlite3_get_autocommit(self->db)) {
- int rc;
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_exec(self->db, "COMMIT", NULL, NULL, NULL);
- Py_END_ALLOW_THREADS
- if (rc != SQLITE_OK) {
- return _pysqlite_seterror(self->db, NULL);
- }
- }
-
- self->begin_statement = NULL;
- } else {
- const char * const *candidate;
- PyObject *uppercase_level;
- _Py_IDENTIFIER(upper);
-
- if (!PyUnicode_Check(isolation_level)) {
- PyErr_Format(PyExc_TypeError,
- "isolation_level must be a string or None, not %.100s",
- Py_TYPE(isolation_level)->tp_name);
- return -1;
- }
-
- uppercase_level = _PyObject_CallMethodIdOneArg(
- (PyObject *)&PyUnicode_Type, &PyId_upper,
- isolation_level);
- if (!uppercase_level) {
- return -1;
- }
- for (candidate = begin_statements; *candidate; candidate++) {
- if (_PyUnicode_EqualToASCIIString(uppercase_level, *candidate + 6))
- break;
- }
- Py_DECREF(uppercase_level);
- if (!*candidate) {
- PyErr_SetString(PyExc_ValueError,
- "invalid value for isolation_level");
- return -1;
- }
- self->begin_statement = *candidate;
- }
-
- Py_INCREF(isolation_level);
- Py_XSETREF(self->isolation_level, isolation_level);
- return 0;
-}
-
-static PyObject *
-pysqlite_connection_call(pysqlite_Connection *self, PyObject *args,
- PyObject *kwargs)
-{
- PyObject* sql;
- pysqlite_Statement* statement;
- PyObject* weakref;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (!_PyArg_NoKeywords(MODULE_NAME ".Connection", kwargs))
- return NULL;
-
- if (!PyArg_ParseTuple(args, "U", &sql))
- return NULL;
-
- _pysqlite_drop_unused_statement_references(self);
-
- statement = pysqlite_statement_create(self, sql);
- if (statement == NULL) {
- return NULL;
- }
-
- weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
- if (weakref == NULL)
- goto error;
- if (PyList_Append(self->statements, weakref) != 0) {
- Py_DECREF(weakref);
- goto error;
- }
- Py_DECREF(weakref);
-
- return (PyObject*)statement;
-
-error:
- Py_DECREF(statement);
- return NULL;
-}
-
-/*[clinic input]
-_sqlite3.Connection.execute as pysqlite_connection_execute
-
- sql: unicode
- parameters: object = NULL
- /
-
-Executes an SQL statement.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_execute_impl(pysqlite_Connection *self, PyObject *sql,
- PyObject *parameters)
-/*[clinic end generated code: output=5be05ae01ee17ee4 input=27aa7792681ddba2]*/
-{
- _Py_IDENTIFIER(execute);
- PyObject* cursor = 0;
- PyObject* result = 0;
-
- cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
- if (!cursor) {
- goto error;
- }
-
- result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_execute, sql, parameters, NULL);
- if (!result) {
- Py_CLEAR(cursor);
- }
-
-error:
- Py_XDECREF(result);
-
- return cursor;
-}
-
-/*[clinic input]
-_sqlite3.Connection.executemany as pysqlite_connection_executemany
-
- sql: unicode
- parameters: object
- /
-
-Repeatedly executes an SQL statement.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_executemany_impl(pysqlite_Connection *self,
- PyObject *sql, PyObject *parameters)
-/*[clinic end generated code: output=776cd2fd20bfe71f input=495be76551d525db]*/
-{
- _Py_IDENTIFIER(executemany);
- PyObject* cursor = 0;
- PyObject* result = 0;
-
- cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
- if (!cursor) {
- goto error;
- }
-
- result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_executemany, sql,
- parameters, NULL);
- if (!result) {
- Py_CLEAR(cursor);
- }
-
-error:
- Py_XDECREF(result);
-
- return cursor;
-}
-
-/*[clinic input]
-_sqlite3.Connection.executescript as pysqlite_connection_executescript
-
- sql_script as script_obj: object
- /
-
-Executes multiple SQL statements at once.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_executescript(pysqlite_Connection *self,
- PyObject *script_obj)
-/*[clinic end generated code: output=4c4f9d77aa0ae37d input=f6e5f1ccfa313db4]*/
-{
- _Py_IDENTIFIER(executescript);
- PyObject* cursor = 0;
- PyObject* result = 0;
-
- cursor = _PyObject_CallMethodIdNoArgs((PyObject*)self, &PyId_cursor);
- if (!cursor) {
- goto error;
- }
-
- result = _PyObject_CallMethodIdObjArgs(cursor, &PyId_executescript,
- script_obj, NULL);
- if (!result) {
- Py_CLEAR(cursor);
- }
-
-error:
- Py_XDECREF(result);
-
- return cursor;
-}
-
-/* ------------------------- COLLATION CODE ------------------------ */
-
-static int
-pysqlite_collation_callback(
- void* context,
- int text1_length, const void* text1_data,
- int text2_length, const void* text2_data)
-{
- PyObject* callback = (PyObject*)context;
- PyObject* string1 = 0;
- PyObject* string2 = 0;
- PyGILState_STATE gilstate;
- PyObject* retval = NULL;
- long longval;
- int result = 0;
- gilstate = PyGILState_Ensure();
-
- if (PyErr_Occurred()) {
- goto finally;
- }
-
- string1 = PyUnicode_FromStringAndSize((const char*)text1_data, text1_length);
- string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length);
-
- if (!string1 || !string2) {
- goto finally; /* failed to allocate strings */
- }
-
- retval = PyObject_CallFunctionObjArgs(callback, string1, string2, NULL);
-
- if (!retval) {
- /* execution failed */
- goto finally;
- }
-
- longval = PyLong_AsLongAndOverflow(retval, &result);
- if (longval == -1 && PyErr_Occurred()) {
- PyErr_Clear();
- result = 0;
- }
- else if (!result) {
- if (longval > 0)
- result = 1;
- else if (longval < 0)
- result = -1;
- }
-
-finally:
- Py_XDECREF(string1);
- Py_XDECREF(string2);
- Py_XDECREF(retval);
- PyGILState_Release(gilstate);
- return result;
-}
-
-/*[clinic input]
-_sqlite3.Connection.interrupt as pysqlite_connection_interrupt
-
-Abort any pending database operation.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_interrupt_impl(pysqlite_Connection *self)
-/*[clinic end generated code: output=f193204bc9e70b47 input=75ad03ade7012859]*/
-{
- PyObject* retval = NULL;
-
- if (!pysqlite_check_connection(self)) {
- goto finally;
- }
-
- sqlite3_interrupt(self->db);
-
- retval = Py_NewRef(Py_None);
-
-finally:
- return retval;
-}
-
-/* Function author: Paul Kippes <[email protected]>
- * Class method of Connection to call the Python function _iterdump
- * of the sqlite3 module.
- */
-/*[clinic input]
-_sqlite3.Connection.iterdump as pysqlite_connection_iterdump
-
-Returns iterator to the dump of the database in an SQL text format.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_iterdump_impl(pysqlite_Connection *self)
-/*[clinic end generated code: output=586997aaf9808768 input=1911ca756066da89]*/
-{
- _Py_IDENTIFIER(_iterdump);
- PyObject* retval = NULL;
- PyObject* module = NULL;
- PyObject* module_dict;
- PyObject* pyfn_iterdump;
-
- if (!pysqlite_check_connection(self)) {
- goto finally;
- }
-
- module = PyImport_ImportModule(MODULE_NAME ".dump");
- if (!module) {
- goto finally;
- }
-
- module_dict = PyModule_GetDict(module);
- if (!module_dict) {
- goto finally;
- }
-
- pyfn_iterdump = _PyDict_GetItemIdWithError(module_dict, &PyId__iterdump);
- if (!pyfn_iterdump) {
- if (!PyErr_Occurred()) {
- PyErr_SetString(pysqlite_OperationalError,
- "Failed to obtain _iterdump() reference");
- }
- goto finally;
- }
-
- retval = PyObject_CallOneArg(pyfn_iterdump, (PyObject *)self);
-
-finally:
- Py_XDECREF(module);
- return retval;
-}
-
-/*[clinic input]
-_sqlite3.Connection.backup as pysqlite_connection_backup
-
- target: object(type='pysqlite_Connection *', subclass_of='pysqlite_ConnectionType')
- *
- pages: int = -1
- progress: object = None
- name: str = "main"
- sleep: double = 0.250
-
-Makes a backup of the database.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_backup_impl(pysqlite_Connection *self,
- pysqlite_Connection *target, int pages,
- PyObject *progress, const char *name,
- double sleep)
-/*[clinic end generated code: output=306a3e6a38c36334 input=458a0b6997c4960b]*/
-{
- int rc;
- int sleep_ms = (int)(sleep * 1000.0);
- sqlite3 *bck_conn;
- sqlite3_backup *bck_handle;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- return NULL;
- }
-
- if (!pysqlite_check_connection(target)) {
- return NULL;
- }
-
- if (target == self) {
- PyErr_SetString(PyExc_ValueError, "target cannot be the same connection instance");
- return NULL;
- }
-
-#if SQLITE_VERSION_NUMBER < 3008008
- /* Since 3.8.8 this is already done, per commit
- https://www.sqlite.org/src/info/169b5505498c0a7e */
- if (!sqlite3_get_autocommit(target->db)) {
- PyErr_SetString(pysqlite_OperationalError, "target is in transaction");
- return NULL;
- }
-#endif
-
- if (progress != Py_None && !PyCallable_Check(progress)) {
- PyErr_SetString(PyExc_TypeError, "progress argument must be a callable");
- return NULL;
- }
-
- if (pages == 0) {
- pages = -1;
- }
-
- bck_conn = target->db;
-
- Py_BEGIN_ALLOW_THREADS
- bck_handle = sqlite3_backup_init(bck_conn, "main", self->db, name);
- Py_END_ALLOW_THREADS
-
- if (bck_handle == NULL) {
- _pysqlite_seterror(bck_conn, NULL);
- return NULL;
- }
-
- do {
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_backup_step(bck_handle, pages);
- Py_END_ALLOW_THREADS
-
- if (progress != Py_None) {
- int remaining = sqlite3_backup_remaining(bck_handle);
- int pagecount = sqlite3_backup_pagecount(bck_handle);
- PyObject *res = PyObject_CallFunction(progress, "iii", rc,
- remaining, pagecount);
- if (res == NULL) {
- /* Callback failed: abort backup and bail. */
- Py_BEGIN_ALLOW_THREADS
- sqlite3_backup_finish(bck_handle);
- Py_END_ALLOW_THREADS
- return NULL;
- }
- Py_DECREF(res);
- }
-
- /* Sleep for a while if there are still further pages to copy and
- the engine could not make any progress */
- if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
- Py_BEGIN_ALLOW_THREADS
- sqlite3_sleep(sleep_ms);
- Py_END_ALLOW_THREADS
- }
- } while (rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_backup_finish(bck_handle);
- Py_END_ALLOW_THREADS
-
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(bck_conn, NULL);
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.Connection.create_collation as pysqlite_connection_create_collation
-
- name: unicode
- callback as callable: object
- /
-
-Creates a collation function.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
- PyObject *name, PyObject *callable)
-/*[clinic end generated code: output=0f63b8995565ae22 input=eb2c4328dc493ee8]*/
-{
- PyObject* uppercase_name = 0;
- Py_ssize_t i, len;
- _Py_IDENTIFIER(upper);
- const char *uppercase_name_str;
- int rc;
- unsigned int kind;
- const void *data;
-
- if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
- goto finally;
- }
-
- uppercase_name = _PyObject_CallMethodIdOneArg((PyObject *)&PyUnicode_Type,
- &PyId_upper, name);
- if (!uppercase_name) {
- goto finally;
- }
-
- if (PyUnicode_READY(uppercase_name))
- goto finally;
- len = PyUnicode_GET_LENGTH(uppercase_name);
- kind = PyUnicode_KIND(uppercase_name);
- data = PyUnicode_DATA(uppercase_name);
- for (i=0; i<len; i++) {
- Py_UCS4 ch = PyUnicode_READ(kind, data, i);
- if ((ch >= '0' && ch <= '9')
- || (ch >= 'A' && ch <= 'Z')
- || (ch == '_'))
- {
- continue;
- } else {
- PyErr_SetString(pysqlite_ProgrammingError, "invalid character in collation name");
- goto finally;
- }
- }
-
- uppercase_name_str = PyUnicode_AsUTF8(uppercase_name);
- if (!uppercase_name_str)
- goto finally;
-
- if (callable != Py_None && !PyCallable_Check(callable)) {
- PyErr_SetString(PyExc_TypeError, "parameter must be callable");
- goto finally;
- }
-
- if (callable != Py_None) {
- if (PyDict_SetItem(self->collations, uppercase_name, callable) == -1)
- goto finally;
- } else {
- if (PyDict_DelItem(self->collations, uppercase_name) == -1)
- goto finally;
- }
-
- rc = sqlite3_create_collation(self->db,
- uppercase_name_str,
- SQLITE_UTF8,
- (callable != Py_None) ? callable : NULL,
- (callable != Py_None) ? pysqlite_collation_callback : NULL);
- if (rc != SQLITE_OK) {
- if (callable != Py_None) {
- if (PyDict_DelItem(self->collations, uppercase_name) < 0) {
- PyErr_Clear();
- }
- }
- _pysqlite_seterror(self->db, NULL);
- goto finally;
- }
-
-finally:
- Py_XDECREF(uppercase_name);
-
- if (PyErr_Occurred()) {
- return NULL;
- }
- return Py_NewRef(Py_None);
-}
-
-/*[clinic input]
-_sqlite3.Connection.__enter__ as pysqlite_connection_enter
-
-Called when the connection is used as a context manager.
-
-Returns itself as a convenience to the caller.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_enter_impl(pysqlite_Connection *self)
-/*[clinic end generated code: output=457b09726d3e9dcd input=127d7a4f17e86d8f]*/
-{
- return Py_NewRef((PyObject *)self);
-}
-
-/*[clinic input]
-_sqlite3.Connection.__exit__ as pysqlite_connection_exit
-
- type as exc_type: object
- value as exc_value: object
- traceback as exc_tb: object
- /
-
-Called when the connection is used as a context manager.
-
-If there was any exception, a rollback takes place; otherwise we commit.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_connection_exit_impl(pysqlite_Connection *self, PyObject *exc_type,
- PyObject *exc_value, PyObject *exc_tb)
-/*[clinic end generated code: output=0705200e9321202a input=bd66f1532c9c54a7]*/
-{
- int commit = 0;
- PyObject* result;
-
- if (exc_type == Py_None && exc_value == Py_None && exc_tb == Py_None) {
- commit = 1;
- result = pysqlite_connection_commit_impl(self);
- }
- else {
- result = pysqlite_connection_rollback_impl(self);
- }
-
- if (result == NULL) {
- if (commit) {
- /* Commit failed; try to rollback in order to unlock the database.
- * If rollback also fails, chain the exceptions. */
- PyObject *exc, *val, *tb;
- PyErr_Fetch(&exc, &val, &tb);
- result = pysqlite_connection_rollback_impl(self);
- if (result == NULL) {
- _PyErr_ChainExceptions(exc, val, tb);
- }
- else {
- Py_DECREF(result);
- PyErr_Restore(exc, val, tb);
- }
- }
- return NULL;
- }
- Py_DECREF(result);
-
- Py_RETURN_FALSE;
-}
-
-static const char connection_doc[] =
-PyDoc_STR("SQLite database connection object.");
-
-static PyGetSetDef connection_getset[] = {
- {"isolation_level", (getter)pysqlite_connection_get_isolation_level, (setter)pysqlite_connection_set_isolation_level},
- {"total_changes", (getter)pysqlite_connection_get_total_changes, (setter)0},
- {"in_transaction", (getter)pysqlite_connection_get_in_transaction, (setter)0},
- {NULL}
-};
-
-static PyMethodDef connection_methods[] = {
- PYSQLITE_CONNECTION_BACKUP_METHODDEF
- PYSQLITE_CONNECTION_CLOSE_METHODDEF
- PYSQLITE_CONNECTION_COMMIT_METHODDEF
- PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF
- PYSQLITE_CONNECTION_CREATE_COLLATION_METHODDEF
- PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF
- PYSQLITE_CONNECTION_CURSOR_METHODDEF
- PYSQLITE_CONNECTION_ENABLE_LOAD_EXTENSION_METHODDEF
- PYSQLITE_CONNECTION_ENTER_METHODDEF
- PYSQLITE_CONNECTION_EXECUTEMANY_METHODDEF
- PYSQLITE_CONNECTION_EXECUTESCRIPT_METHODDEF
- PYSQLITE_CONNECTION_EXECUTE_METHODDEF
- PYSQLITE_CONNECTION_EXIT_METHODDEF
- PYSQLITE_CONNECTION_INTERRUPT_METHODDEF
- PYSQLITE_CONNECTION_ITERDUMP_METHODDEF
- PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
- PYSQLITE_CONNECTION_ROLLBACK_METHODDEF
- PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF
- PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF
- PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF
- {NULL, NULL}
-};
-
-static struct PyMemberDef connection_members[] =
-{
- {"Warning", T_OBJECT, offsetof(pysqlite_Connection, Warning), READONLY},
- {"Error", T_OBJECT, offsetof(pysqlite_Connection, Error), READONLY},
- {"InterfaceError", T_OBJECT, offsetof(pysqlite_Connection, InterfaceError), READONLY},
- {"DatabaseError", T_OBJECT, offsetof(pysqlite_Connection, DatabaseError), READONLY},
- {"DataError", T_OBJECT, offsetof(pysqlite_Connection, DataError), READONLY},
- {"OperationalError", T_OBJECT, offsetof(pysqlite_Connection, OperationalError), READONLY},
- {"IntegrityError", T_OBJECT, offsetof(pysqlite_Connection, IntegrityError), READONLY},
- {"InternalError", T_OBJECT, offsetof(pysqlite_Connection, InternalError), READONLY},
- {"ProgrammingError", T_OBJECT, offsetof(pysqlite_Connection, ProgrammingError), READONLY},
- {"NotSupportedError", T_OBJECT, offsetof(pysqlite_Connection, NotSupportedError), READONLY},
- {"row_factory", T_OBJECT, offsetof(pysqlite_Connection, row_factory)},
- {"text_factory", T_OBJECT, offsetof(pysqlite_Connection, text_factory)},
- {NULL}
-};
-
-static PyType_Slot connection_slots[] = {
- {Py_tp_dealloc, connection_dealloc},
- {Py_tp_doc, (void *)connection_doc},
- {Py_tp_methods, connection_methods},
- {Py_tp_members, connection_members},
- {Py_tp_getset, connection_getset},
- {Py_tp_init, pysqlite_connection_init},
- {Py_tp_call, pysqlite_connection_call},
- {Py_tp_traverse, connection_traverse},
- {Py_tp_clear, connection_clear},
- {0, NULL},
-};
-
-static PyType_Spec connection_spec = {
- .name = MODULE_NAME ".Connection",
- .basicsize = sizeof(pysqlite_Connection),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = connection_slots,
-};
-
-PyTypeObject *pysqlite_ConnectionType = NULL;
-
-int
-pysqlite_connection_setup_types(PyObject *module)
-{
- pysqlite_ConnectionType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &connection_spec, NULL);
- if (pysqlite_ConnectionType == NULL) {
- return -1;
- }
- return 0;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/connection.h b/contrib/tools/python3/src/Modules/_sqlite/connection.h
deleted file mode 100644
index 8773c9eac08..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/connection.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/* connection.h - definitions for the connection type
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_CONNECTION_H
-#define PYSQLITE_CONNECTION_H
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "pythread.h"
-#include "structmember.h"
-
-#include "cache.h"
-#include "module.h"
-
-#include "sqlite3.h"
-
-typedef struct
-{
- PyObject_HEAD
- sqlite3* db;
-
- /* the type detection mode. Only 0, PARSE_DECLTYPES, PARSE_COLNAMES or a
- * bitwise combination thereof makes sense */
- int detect_types;
-
- /* the timeout value in seconds for database locks */
- double timeout;
-
- /* for internal use in the timeout handler: when did the timeout handler
- * first get called with count=0? */
- double timeout_started;
-
- /* None for autocommit, otherwise a PyUnicode with the isolation level */
- PyObject* isolation_level;
-
- /* NULL for autocommit, otherwise a string with the BEGIN statement */
- const char* begin_statement;
-
- /* 1 if a check should be performed for each API call if the connection is
- * used from the same thread it was created in */
- int check_same_thread;
-
- int initialized;
-
- /* thread identification of the thread the connection was created in */
- unsigned long thread_ident;
-
- pysqlite_Cache* statement_cache;
-
- /* Lists of weak references to statements and cursors used within this connection */
- PyObject* statements;
- PyObject* cursors;
-
- /* Counters for how many statements/cursors were created in the connection. May be
- * reset to 0 at certain intervals */
- int created_statements;
- int created_cursors;
-
- PyObject* row_factory;
-
- /* Determines how bytestrings from SQLite are converted to Python objects:
- * - PyUnicode_Type: Python Unicode objects are constructed from UTF-8 bytestrings
- * - PyBytes_Type: The bytestrings are returned as-is.
- * - Any custom callable: Any object returned from the callable called with the bytestring
- * as single parameter.
- */
- PyObject* text_factory;
-
- /* remember references to object used in trace_callback/progress_handler/authorizer_cb */
- PyObject* function_pinboard_trace_callback;
- PyObject* function_pinboard_progress_handler;
- PyObject* function_pinboard_authorizer_cb;
-
- /* a dictionary of registered collation name => collation callable mappings */
- PyObject* collations;
-
- /* Exception objects: borrowed refs. */
- PyObject* Warning;
- PyObject* Error;
- PyObject* InterfaceError;
- PyObject* DatabaseError;
- PyObject* DataError;
- PyObject* OperationalError;
- PyObject* IntegrityError;
- PyObject* InternalError;
- PyObject* ProgrammingError;
- PyObject* NotSupportedError;
-} pysqlite_Connection;
-
-extern PyTypeObject *pysqlite_ConnectionType;
-
-PyObject* _pysqlite_connection_begin(pysqlite_Connection* self);
-
-int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor);
-int pysqlite_check_thread(pysqlite_Connection* self);
-int pysqlite_check_connection(pysqlite_Connection* con);
-
-int pysqlite_connection_setup_types(PyObject *module);
-
-#endif
diff --git a/contrib/tools/python3/src/Modules/_sqlite/cursor.c b/contrib/tools/python3/src/Modules/_sqlite/cursor.c
deleted file mode 100644
index ac80c285fe9..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/cursor.c
+++ /dev/null
@@ -1,1072 +0,0 @@
-/* cursor.c - the cursor type
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "cursor.h"
-#include "module.h"
-#include "util.h"
-#include "clinic/cursor.c.h"
-
-static inline int
-check_cursor_locked(pysqlite_Cursor *cur)
-{
- if (cur->locked) {
- PyErr_SetString(pysqlite_ProgrammingError,
- "Recursive use of cursors not allowed.");
- return 0;
- }
- return 1;
-}
-
-/*[clinic input]
-module _sqlite3
-class _sqlite3.Cursor "pysqlite_Cursor *" "pysqlite_CursorType"
-[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b2072d8db95411d5]*/
-
-static const char errmsg_fetch_across_rollback[] = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from.";
-
-/*[clinic input]
-_sqlite3.Cursor.__init__ as pysqlite_cursor_init
-
- connection: object(type='pysqlite_Connection *', subclass_of='pysqlite_ConnectionType')
- /
-
-[clinic start generated code]*/
-
-static int
-pysqlite_cursor_init_impl(pysqlite_Cursor *self,
- pysqlite_Connection *connection)
-/*[clinic end generated code: output=ac59dce49a809ca8 input=a8a4f75ac90999b2]*/
-{
- if (!check_cursor_locked(self)) {
- return -1;
- }
-
- Py_INCREF(connection);
- Py_XSETREF(self->connection, connection);
- Py_CLEAR(self->statement);
- Py_CLEAR(self->next_row);
- Py_CLEAR(self->row_cast_map);
-
- Py_INCREF(Py_None);
- Py_XSETREF(self->description, Py_None);
-
- Py_INCREF(Py_None);
- Py_XSETREF(self->lastrowid, Py_None);
-
- self->arraysize = 1;
- self->closed = 0;
- self->reset = 0;
-
- self->rowcount = -1L;
-
- Py_INCREF(Py_None);
- Py_XSETREF(self->row_factory, Py_None);
-
- if (!pysqlite_check_thread(self->connection)) {
- return -1;
- }
-
- if (!pysqlite_connection_register_cursor(connection, (PyObject*)self)) {
- return -1;
- }
-
- self->initialized = 1;
-
- return 0;
-}
-
-static int
-cursor_traverse(pysqlite_Cursor *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- Py_VISIT(self->connection);
- Py_VISIT(self->description);
- Py_VISIT(self->row_cast_map);
- Py_VISIT(self->lastrowid);
- Py_VISIT(self->row_factory);
- Py_VISIT(self->statement);
- Py_VISIT(self->next_row);
- return 0;
-}
-
-static int
-cursor_clear(pysqlite_Cursor *self)
-{
- Py_CLEAR(self->connection);
- Py_CLEAR(self->description);
- Py_CLEAR(self->row_cast_map);
- Py_CLEAR(self->lastrowid);
- Py_CLEAR(self->row_factory);
- if (self->statement) {
- /* Reset the statement if the user has not closed the cursor */
- pysqlite_statement_reset(self->statement);
- Py_CLEAR(self->statement);
- }
- Py_CLEAR(self->next_row);
-
- return 0;
-}
-
-static void
-cursor_dealloc(pysqlite_Cursor *self)
-{
- PyTypeObject *tp = Py_TYPE(self);
- PyObject_GC_UnTrack(self);
- if (self->in_weakreflist != NULL) {
- PyObject_ClearWeakRefs((PyObject*)self);
- }
- tp->tp_clear((PyObject *)self);
- tp->tp_free(self);
- Py_DECREF(tp);
-}
-
-static PyObject *
-_pysqlite_get_converter(const char *keystr, Py_ssize_t keylen)
-{
- PyObject *key;
- PyObject *upcase_key;
- PyObject *retval;
- _Py_IDENTIFIER(upper);
-
- key = PyUnicode_FromStringAndSize(keystr, keylen);
- if (!key) {
- return NULL;
- }
- upcase_key = _PyObject_CallMethodIdNoArgs(key, &PyId_upper);
- Py_DECREF(key);
- if (!upcase_key) {
- return NULL;
- }
-
- retval = PyDict_GetItemWithError(_pysqlite_converters, upcase_key);
- Py_DECREF(upcase_key);
-
- return retval;
-}
-
-static int
-pysqlite_build_row_cast_map(pysqlite_Cursor* self)
-{
- int i;
- const char* pos;
- const char* decltype;
- PyObject* converter;
-
- if (!self->connection->detect_types) {
- return 0;
- }
-
- Py_XSETREF(self->row_cast_map, PyList_New(0));
- if (!self->row_cast_map) {
- return -1;
- }
-
- for (i = 0; i < sqlite3_column_count(self->statement->st); i++) {
- converter = NULL;
-
- if (self->connection->detect_types & PARSE_COLNAMES) {
- const char *colname = sqlite3_column_name(self->statement->st, i);
- if (colname == NULL) {
- PyErr_NoMemory();
- Py_CLEAR(self->row_cast_map);
- return -1;
- }
- const char *type_start = NULL;
- for (pos = colname; *pos != 0; pos++) {
- if (*pos == '[') {
- type_start = pos + 1;
- }
- else if (*pos == ']' && type_start != NULL) {
- converter = _pysqlite_get_converter(type_start, pos - type_start);
- if (!converter && PyErr_Occurred()) {
- Py_CLEAR(self->row_cast_map);
- return -1;
- }
- break;
- }
- }
- }
-
- if (!converter && self->connection->detect_types & PARSE_DECLTYPES) {
- decltype = sqlite3_column_decltype(self->statement->st, i);
- if (decltype) {
- for (pos = decltype;;pos++) {
- /* Converter names are split at '(' and blanks.
- * This allows 'INTEGER NOT NULL' to be treated as 'INTEGER' and
- * 'NUMBER(10)' to be treated as 'NUMBER', for example.
- * In other words, it will work as people expect it to work.*/
- if (*pos == ' ' || *pos == '(' || *pos == 0) {
- converter = _pysqlite_get_converter(decltype, pos - decltype);
- if (!converter && PyErr_Occurred()) {
- Py_CLEAR(self->row_cast_map);
- return -1;
- }
- break;
- }
- }
- }
- }
-
- if (!converter) {
- converter = Py_None;
- }
-
- if (PyList_Append(self->row_cast_map, converter) != 0) {
- Py_CLEAR(self->row_cast_map);
- return -1;
- }
- }
-
- return 0;
-}
-
-static PyObject *
-_pysqlite_build_column_name(pysqlite_Cursor *self, const char *colname)
-{
- const char* pos;
- Py_ssize_t len;
-
- if (self->connection->detect_types & PARSE_COLNAMES) {
- for (pos = colname; *pos; pos++) {
- if (*pos == '[') {
- if ((pos != colname) && (*(pos-1) == ' ')) {
- pos--;
- }
- break;
- }
- }
- len = pos - colname;
- }
- else {
- len = strlen(colname);
- }
- return PyUnicode_FromStringAndSize(colname, len);
-}
-
-/*
- * Returns a row from the currently active SQLite statement
- *
- * Precondidition:
- * - sqlite3_step() has been called before and it returned SQLITE_ROW.
- */
-static PyObject *
-_pysqlite_fetch_one_row(pysqlite_Cursor* self)
-{
- int i, numcols;
- PyObject* row;
- int coltype;
- PyObject* converter;
- PyObject* converted;
- Py_ssize_t nbytes;
- char buf[200];
- const char* colname;
- PyObject* error_msg;
-
- if (self->reset) {
- PyErr_SetString(pysqlite_InterfaceError, errmsg_fetch_across_rollback);
- return NULL;
- }
-
- Py_BEGIN_ALLOW_THREADS
- numcols = sqlite3_data_count(self->statement->st);
- Py_END_ALLOW_THREADS
-
- row = PyTuple_New(numcols);
- if (!row)
- return NULL;
-
- sqlite3 *db = self->connection->db;
- for (i = 0; i < numcols; i++) {
- if (self->connection->detect_types
- && self->row_cast_map != NULL
- && i < PyList_GET_SIZE(self->row_cast_map))
- {
- converter = PyList_GET_ITEM(self->row_cast_map, i);
- }
- else {
- converter = Py_None;
- }
-
- /*
- * Note, sqlite3_column_bytes() must come after sqlite3_column_blob()
- * or sqlite3_column_text().
- *
- * See https://sqlite.org/c3ref/column_blob.html for details.
- */
- if (converter != Py_None) {
- const void *blob = sqlite3_column_blob(self->statement->st, i);
- if (blob == NULL) {
- if (sqlite3_errcode(db) == SQLITE_NOMEM) {
- PyErr_NoMemory();
- goto error;
- }
- converted = Py_NewRef(Py_None);
- }
- else {
- nbytes = sqlite3_column_bytes(self->statement->st, i);
- PyObject *item = PyBytes_FromStringAndSize(blob, nbytes);
- if (item == NULL) {
- goto error;
- }
- converted = PyObject_CallOneArg(converter, item);
- Py_DECREF(item);
- }
- } else {
- Py_BEGIN_ALLOW_THREADS
- coltype = sqlite3_column_type(self->statement->st, i);
- Py_END_ALLOW_THREADS
- if (coltype == SQLITE_NULL) {
- converted = Py_NewRef(Py_None);
- } else if (coltype == SQLITE_INTEGER) {
- converted = PyLong_FromLongLong(sqlite3_column_int64(self->statement->st, i));
- } else if (coltype == SQLITE_FLOAT) {
- converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i));
- } else if (coltype == SQLITE_TEXT) {
- const char *text = (const char*)sqlite3_column_text(self->statement->st, i);
- if (text == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
- PyErr_NoMemory();
- goto error;
- }
-
- nbytes = sqlite3_column_bytes(self->statement->st, i);
- if (self->connection->text_factory == (PyObject*)&PyUnicode_Type) {
- converted = PyUnicode_FromStringAndSize(text, nbytes);
- if (!converted && PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {
- PyErr_Clear();
- colname = sqlite3_column_name(self->statement->st, i);
- if (colname == NULL) {
- PyErr_NoMemory();
- goto error;
- }
- PyOS_snprintf(buf, sizeof(buf) - 1, "Could not decode to UTF-8 column '%s' with text '%s'",
- colname , text);
- error_msg = PyUnicode_Decode(buf, strlen(buf), "ascii", "replace");
- if (!error_msg) {
- PyErr_SetString(pysqlite_OperationalError, "Could not decode to UTF-8");
- } else {
- PyErr_SetObject(pysqlite_OperationalError, error_msg);
- Py_DECREF(error_msg);
- }
- }
- } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) {
- converted = PyBytes_FromStringAndSize(text, nbytes);
- } else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) {
- converted = PyByteArray_FromStringAndSize(text, nbytes);
- } else {
- converted = PyObject_CallFunction(self->connection->text_factory, "y#", text, nbytes);
- }
- } else {
- /* coltype == SQLITE_BLOB */
- const void *blob = sqlite3_column_blob(self->statement->st, i);
- if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
- PyErr_NoMemory();
- goto error;
- }
-
- nbytes = sqlite3_column_bytes(self->statement->st, i);
- converted = PyBytes_FromStringAndSize(blob, nbytes);
- }
- }
-
- if (!converted) {
- goto error;
- }
- PyTuple_SET_ITEM(row, i, converted);
- }
-
- if (PyErr_Occurred())
- goto error;
-
- return row;
-
-error:
- Py_DECREF(row);
- return NULL;
-}
-
-/*
- * Checks if a cursor object is usable.
- *
- * 0 => error; 1 => ok
- */
-static int check_cursor(pysqlite_Cursor* cur)
-{
- if (!cur->initialized) {
- PyErr_SetString(pysqlite_ProgrammingError, "Base Cursor.__init__ not called.");
- return 0;
- }
-
- if (cur->closed) {
- PyErr_SetString(pysqlite_ProgrammingError, "Cannot operate on a closed cursor.");
- return 0;
- }
-
- return (pysqlite_check_thread(cur->connection)
- && pysqlite_check_connection(cur->connection)
- && check_cursor_locked(cur));
-}
-
-static PyObject *
-_pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument)
-{
- PyObject* parameters_list = NULL;
- PyObject* parameters_iter = NULL;
- PyObject* parameters = NULL;
- int i;
- int rc;
- PyObject* func_args;
- PyObject* result;
- int numcols;
- PyObject* column_name;
- sqlite_int64 lastrowid;
-
- if (!check_cursor(self)) {
- goto error;
- }
-
- self->locked = 1;
- self->reset = 0;
-
- Py_CLEAR(self->next_row);
-
- if (multiple) {
- if (PyIter_Check(second_argument)) {
- /* iterator */
- parameters_iter = Py_NewRef(second_argument);
- } else {
- /* sequence */
- parameters_iter = PyObject_GetIter(second_argument);
- if (!parameters_iter) {
- goto error;
- }
- }
- } else {
- parameters_list = PyList_New(0);
- if (!parameters_list) {
- goto error;
- }
-
- if (second_argument == NULL) {
- second_argument = PyTuple_New(0);
- if (!second_argument) {
- goto error;
- }
- } else {
- Py_INCREF(second_argument);
- }
- if (PyList_Append(parameters_list, second_argument) != 0) {
- Py_DECREF(second_argument);
- goto error;
- }
- Py_DECREF(second_argument);
-
- parameters_iter = PyObject_GetIter(parameters_list);
- if (!parameters_iter) {
- goto error;
- }
- }
-
- if (self->statement != NULL) {
- /* There is an active statement */
- pysqlite_statement_reset(self->statement);
- }
-
- /* reset description and rowcount */
- Py_INCREF(Py_None);
- Py_SETREF(self->description, Py_None);
- self->rowcount = 0L;
-
- func_args = PyTuple_New(1);
- if (!func_args) {
- goto error;
- }
- if (PyTuple_SetItem(func_args, 0, Py_NewRef(operation)) != 0) {
- goto error;
- }
-
- if (self->statement) {
- (void)pysqlite_statement_reset(self->statement);
- }
-
- Py_XSETREF(self->statement,
- (pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args));
- Py_DECREF(func_args);
-
- if (!self->statement) {
- goto error;
- }
-
- if (self->statement->in_use) {
- Py_SETREF(self->statement,
- pysqlite_statement_create(self->connection, operation));
- if (self->statement == NULL) {
- goto error;
- }
- }
-
- pysqlite_statement_reset(self->statement);
- pysqlite_statement_mark_dirty(self->statement);
-
- /* We start a transaction implicitly before a DML statement.
- SELECT is the only exception. See #9924. */
- if (self->connection->begin_statement && self->statement->is_dml) {
- if (sqlite3_get_autocommit(self->connection->db)) {
- result = _pysqlite_connection_begin(self->connection);
- if (!result) {
- goto error;
- }
- Py_DECREF(result);
- }
- }
-
- while (1) {
- parameters = PyIter_Next(parameters_iter);
- if (!parameters) {
- break;
- }
-
- pysqlite_statement_mark_dirty(self->statement);
-
- pysqlite_statement_bind_parameters(self->statement, parameters);
- if (PyErr_Occurred()) {
- goto error;
- }
-
- rc = pysqlite_step(self->statement->st, self->connection);
- if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
- if (PyErr_Occurred()) {
- /* there was an error that occurred in a user-defined callback */
- if (_pysqlite_enable_callback_tracebacks) {
- PyErr_Print();
- } else {
- PyErr_Clear();
- }
- }
- (void)pysqlite_statement_reset(self->statement);
- _pysqlite_seterror(self->connection->db, NULL);
- goto error;
- }
-
- if (pysqlite_build_row_cast_map(self) != 0) {
- _PyErr_FormatFromCause(pysqlite_OperationalError, "Error while building row_cast_map");
- goto error;
- }
-
- assert(rc == SQLITE_ROW || rc == SQLITE_DONE);
- Py_BEGIN_ALLOW_THREADS
- numcols = sqlite3_column_count(self->statement->st);
- Py_END_ALLOW_THREADS
- if (self->description == Py_None && numcols > 0) {
- Py_SETREF(self->description, PyTuple_New(numcols));
- if (!self->description) {
- goto error;
- }
- for (i = 0; i < numcols; i++) {
- const char *colname;
- colname = sqlite3_column_name(self->statement->st, i);
- if (colname == NULL) {
- PyErr_NoMemory();
- goto error;
- }
- column_name = _pysqlite_build_column_name(self, colname);
- if (column_name == NULL) {
- goto error;
- }
- PyObject *descriptor = PyTuple_Pack(7, column_name,
- Py_None, Py_None, Py_None,
- Py_None, Py_None, Py_None);
- Py_DECREF(column_name);
- if (descriptor == NULL) {
- goto error;
- }
- PyTuple_SET_ITEM(self->description, i, descriptor);
- }
- }
-
- if (self->statement->is_dml) {
- self->rowcount += (long)sqlite3_changes(self->connection->db);
- } else {
- self->rowcount= -1L;
- }
-
- if (!multiple) {
- Py_BEGIN_ALLOW_THREADS
- lastrowid = sqlite3_last_insert_rowid(self->connection->db);
- Py_END_ALLOW_THREADS
- Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid));
- if (self->lastrowid == NULL) {
- goto error;
- }
- }
-
- if (rc == SQLITE_ROW) {
- if (multiple) {
- PyErr_SetString(pysqlite_ProgrammingError, "executemany() can only execute DML statements.");
- goto error;
- }
-
- self->next_row = _pysqlite_fetch_one_row(self);
- if (self->next_row == NULL)
- goto error;
- } else if (rc == SQLITE_DONE && !multiple) {
- pysqlite_statement_reset(self->statement);
- Py_CLEAR(self->statement);
- }
-
- if (multiple) {
- pysqlite_statement_reset(self->statement);
- }
- Py_XDECREF(parameters);
- }
-
-error:
- Py_XDECREF(parameters);
- Py_XDECREF(parameters_iter);
- Py_XDECREF(parameters_list);
-
- self->locked = 0;
-
- if (PyErr_Occurred()) {
- self->rowcount = -1L;
- return NULL;
- } else {
- return Py_NewRef((PyObject *)self);
- }
-}
-
-/*[clinic input]
-_sqlite3.Cursor.execute as pysqlite_cursor_execute
-
- sql: unicode
- parameters: object(c_default = 'NULL') = ()
- /
-
-Executes an SQL statement.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_execute_impl(pysqlite_Cursor *self, PyObject *sql,
- PyObject *parameters)
-/*[clinic end generated code: output=d81b4655c7c0bbad input=a8e0200a11627f94]*/
-{
- return _pysqlite_query_execute(self, 0, sql, parameters);
-}
-
-/*[clinic input]
-_sqlite3.Cursor.executemany as pysqlite_cursor_executemany
-
- sql: unicode
- seq_of_parameters: object
- /
-
-Repeatedly executes an SQL statement.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_executemany_impl(pysqlite_Cursor *self, PyObject *sql,
- PyObject *seq_of_parameters)
-/*[clinic end generated code: output=2c65a3c4733fb5d8 input=0d0a52e5eb7ccd35]*/
-{
- return _pysqlite_query_execute(self, 1, sql, seq_of_parameters);
-}
-
-/*[clinic input]
-_sqlite3.Cursor.executescript as pysqlite_cursor_executescript
-
- sql_script as script_obj: object
- /
-
-Executes multiple SQL statements at once.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_executescript(pysqlite_Cursor *self, PyObject *script_obj)
-/*[clinic end generated code: output=115a8132b0f200fe input=75270e5bcdb4d6aa]*/
-{
- _Py_IDENTIFIER(commit);
- const char* script_cstr;
- sqlite3_stmt* statement;
- int rc;
- PyObject* result;
-
- if (!check_cursor(self)) {
- return NULL;
- }
-
- self->reset = 0;
-
- if (PyUnicode_Check(script_obj)) {
- script_cstr = PyUnicode_AsUTF8(script_obj);
- if (!script_cstr) {
- return NULL;
- }
- } else {
- PyErr_SetString(PyExc_ValueError, "script argument must be unicode.");
- return NULL;
- }
-
- /* commit first */
- result = _PyObject_CallMethodIdNoArgs((PyObject *)self->connection, &PyId_commit);
- if (!result) {
- goto error;
- }
- Py_DECREF(result);
-
- while (1) {
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare_v2(self->connection->db,
- script_cstr,
- -1,
- &statement,
- &script_cstr);
- Py_END_ALLOW_THREADS
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->connection->db, NULL);
- goto error;
- }
-
- /* execute statement, and ignore results of SELECT statements */
- do {
- rc = pysqlite_step(statement, self->connection);
- if (PyErr_Occurred()) {
- (void)sqlite3_finalize(statement);
- goto error;
- }
- } while (rc == SQLITE_ROW);
-
- if (rc != SQLITE_DONE) {
- (void)sqlite3_finalize(statement);
- _pysqlite_seterror(self->connection->db, NULL);
- goto error;
- }
-
- rc = sqlite3_finalize(statement);
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->connection->db, NULL);
- goto error;
- }
-
- if (*script_cstr == (char)0) {
- break;
- }
- }
-
-error:
- if (PyErr_Occurred()) {
- return NULL;
- } else {
- return Py_NewRef((PyObject *)self);
- }
-}
-
-static PyObject *
-pysqlite_cursor_iternext(pysqlite_Cursor *self)
-{
- PyObject* next_row_tuple;
- PyObject* next_row;
- int rc;
-
- if (!check_cursor(self)) {
- return NULL;
- }
-
- if (self->reset) {
- PyErr_SetString(pysqlite_InterfaceError, errmsg_fetch_across_rollback);
- return NULL;
- }
-
- if (!self->next_row) {
- if (self->statement) {
- (void)pysqlite_statement_reset(self->statement);
- Py_CLEAR(self->statement);
- }
- return NULL;
- }
-
- next_row_tuple = self->next_row;
- assert(next_row_tuple != NULL);
- self->next_row = NULL;
-
- if (self->row_factory != Py_None) {
- next_row = PyObject_CallFunction(self->row_factory, "OO", self, next_row_tuple);
- if (next_row == NULL) {
- self->next_row = next_row_tuple;
- return NULL;
- }
- Py_DECREF(next_row_tuple);
- } else {
- next_row = next_row_tuple;
- }
-
- if (self->statement) {
- rc = pysqlite_step(self->statement->st, self->connection);
- if (PyErr_Occurred()) {
- goto error;
- }
- if (rc != SQLITE_DONE && rc != SQLITE_ROW) {
- _pysqlite_seterror(self->connection->db, NULL);
- goto error;
- }
-
- if (rc == SQLITE_ROW) {
- self->locked = 1; // GH-80254: Prevent recursive use of cursors.
- self->next_row = _pysqlite_fetch_one_row(self);
- self->locked = 0;
- if (self->next_row == NULL) {
- goto error;
- }
- }
- }
-
- return next_row;
-
-error:
- (void)pysqlite_statement_reset(self->statement);
- Py_DECREF(next_row);
- return NULL;
-}
-
-/*[clinic input]
-_sqlite3.Cursor.fetchone as pysqlite_cursor_fetchone
-
-Fetches one row from the resultset.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self)
-/*[clinic end generated code: output=4bd2eabf5baaddb0 input=e78294ec5980fdba]*/
-{
- PyObject* row;
-
- row = pysqlite_cursor_iternext(self);
- if (!row && !PyErr_Occurred()) {
- Py_RETURN_NONE;
- }
-
- return row;
-}
-
-/*[clinic input]
-_sqlite3.Cursor.fetchmany as pysqlite_cursor_fetchmany
-
- size as maxrows: int(c_default='self->arraysize') = 1
- The default value is set by the Cursor.arraysize attribute.
-
-Fetches several rows from the resultset.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows)
-/*[clinic end generated code: output=a8ef31fea64d0906 input=c26e6ca3f34debd0]*/
-{
- PyObject* row;
- PyObject* list;
- int counter = 0;
-
- list = PyList_New(0);
- if (!list) {
- return NULL;
- }
-
- while ((row = pysqlite_cursor_iternext(self))) {
- if (PyList_Append(list, row) < 0) {
- Py_DECREF(row);
- break;
- }
- Py_DECREF(row);
-
- if (++counter == maxrows) {
- break;
- }
- }
-
- if (PyErr_Occurred()) {
- Py_DECREF(list);
- return NULL;
- } else {
- return list;
- }
-}
-
-/*[clinic input]
-_sqlite3.Cursor.fetchall as pysqlite_cursor_fetchall
-
-Fetches all rows from the resultset.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self)
-/*[clinic end generated code: output=d5da12aca2da4b27 input=f5d401086a8df25a]*/
-{
- PyObject* row;
- PyObject* list;
-
- list = PyList_New(0);
- if (!list) {
- return NULL;
- }
-
- while ((row = pysqlite_cursor_iternext(self))) {
- if (PyList_Append(list, row) < 0) {
- Py_DECREF(row);
- break;
- }
- Py_DECREF(row);
- }
-
- if (PyErr_Occurred()) {
- Py_DECREF(list);
- return NULL;
- } else {
- return list;
- }
-}
-
-/*[clinic input]
-_sqlite3.Cursor.setinputsizes as pysqlite_cursor_setinputsizes
-
- sizes: object
- /
-
-Required by DB-API. Does nothing in sqlite3.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_setinputsizes(pysqlite_Cursor *self, PyObject *sizes)
-/*[clinic end generated code: output=893c817afe9d08ad input=de7950a3aec79bdf]*/
-{
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.Cursor.setoutputsize as pysqlite_cursor_setoutputsize
-
- size: object
- column: object = None
- /
-
-Required by DB-API. Does nothing in sqlite3.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_setoutputsize_impl(pysqlite_Cursor *self, PyObject *size,
- PyObject *column)
-/*[clinic end generated code: output=018d7e9129d45efe input=607a6bece8bbb273]*/
-{
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.Cursor.close as pysqlite_cursor_close
-
-Closes the cursor.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_cursor_close_impl(pysqlite_Cursor *self)
-/*[clinic end generated code: output=b6055e4ec6fe63b6 input=08b36552dbb9a986]*/
-{
- if (!check_cursor_locked(self)) {
- return NULL;
- }
-
- if (!self->connection) {
- PyErr_SetString(pysqlite_ProgrammingError,
- "Base Cursor.__init__ not called.");
- return NULL;
- }
- if (!pysqlite_check_thread(self->connection) || !pysqlite_check_connection(self->connection)) {
- return NULL;
- }
-
- if (self->statement) {
- (void)pysqlite_statement_reset(self->statement);
- Py_CLEAR(self->statement);
- }
-
- self->closed = 1;
-
- Py_RETURN_NONE;
-}
-
-static PyMethodDef cursor_methods[] = {
- PYSQLITE_CURSOR_CLOSE_METHODDEF
- PYSQLITE_CURSOR_EXECUTEMANY_METHODDEF
- PYSQLITE_CURSOR_EXECUTESCRIPT_METHODDEF
- PYSQLITE_CURSOR_EXECUTE_METHODDEF
- PYSQLITE_CURSOR_FETCHALL_METHODDEF
- PYSQLITE_CURSOR_FETCHMANY_METHODDEF
- PYSQLITE_CURSOR_FETCHONE_METHODDEF
- PYSQLITE_CURSOR_SETINPUTSIZES_METHODDEF
- PYSQLITE_CURSOR_SETOUTPUTSIZE_METHODDEF
- {NULL, NULL}
-};
-
-static struct PyMemberDef cursor_members[] =
-{
- {"connection", T_OBJECT, offsetof(pysqlite_Cursor, connection), READONLY},
- {"description", T_OBJECT, offsetof(pysqlite_Cursor, description), READONLY},
- {"arraysize", T_INT, offsetof(pysqlite_Cursor, arraysize), 0},
- {"lastrowid", T_OBJECT, offsetof(pysqlite_Cursor, lastrowid), READONLY},
- {"rowcount", T_LONG, offsetof(pysqlite_Cursor, rowcount), READONLY},
- {"row_factory", T_OBJECT, offsetof(pysqlite_Cursor, row_factory), 0},
- {"__weaklistoffset__", T_PYSSIZET, offsetof(pysqlite_Cursor, in_weakreflist), READONLY},
- {NULL}
-};
-
-static const char cursor_doc[] =
-PyDoc_STR("SQLite database cursor class.");
-
-static PyType_Slot cursor_slots[] = {
- {Py_tp_dealloc, cursor_dealloc},
- {Py_tp_doc, (void *)cursor_doc},
- {Py_tp_iter, PyObject_SelfIter},
- {Py_tp_iternext, pysqlite_cursor_iternext},
- {Py_tp_methods, cursor_methods},
- {Py_tp_members, cursor_members},
- {Py_tp_init, pysqlite_cursor_init},
- {Py_tp_traverse, cursor_traverse},
- {Py_tp_clear, cursor_clear},
- {0, NULL},
-};
-
-static PyType_Spec cursor_spec = {
- .name = MODULE_NAME ".Cursor",
- .basicsize = sizeof(pysqlite_Cursor),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = cursor_slots,
-};
-
-PyTypeObject *pysqlite_CursorType = NULL;
-
-int
-pysqlite_cursor_setup_types(PyObject *module)
-{
- pysqlite_CursorType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &cursor_spec, NULL);
- if (pysqlite_CursorType == NULL) {
- return -1;
- }
- return 0;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/cursor.h b/contrib/tools/python3/src/Modules/_sqlite/cursor.h
deleted file mode 100644
index b26b2886746..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/cursor.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* cursor.h - definitions for the cursor type
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_CURSOR_H
-#define PYSQLITE_CURSOR_H
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-
-#include "statement.h"
-#include "connection.h"
-#include "module.h"
-
-typedef struct
-{
- PyObject_HEAD
- pysqlite_Connection* connection;
- PyObject* description;
- PyObject* row_cast_map;
- int arraysize;
- PyObject* lastrowid;
- long rowcount;
- PyObject* row_factory;
- pysqlite_Statement* statement;
- int closed;
- int reset;
- int locked;
- int initialized;
-
- /* the next row to be returned, NULL if no next row available */
- PyObject* next_row;
-
- PyObject* in_weakreflist; /* List of weak references */
-} pysqlite_Cursor;
-
-extern PyTypeObject *pysqlite_CursorType;
-
-int pysqlite_cursor_setup_types(PyObject *module);
-
-#define UNKNOWN (-1)
-#endif
diff --git a/contrib/tools/python3/src/Modules/_sqlite/microprotocols.c b/contrib/tools/python3/src/Modules/_sqlite/microprotocols.c
deleted file mode 100644
index e219a7239f8..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/microprotocols.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/* microprotocols.c - minimalist and non-validating protocols implementation
- *
- * Copyright (C) 2003-2004 Federico Di Gregorio <[email protected]>
- *
- * This file is part of psycopg and was adapted for pysqlite. Federico Di
- * Gregorio gave the permission to use it within pysqlite under the following
- * license:
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include <Python.h>
-
-#include "cursor.h"
-#include "microprotocols.h"
-#include "prepare_protocol.h"
-
-/** the adapters registry **/
-
-static PyObject *psyco_adapters = NULL;
-
-/* pysqlite_microprotocols_init - initialize the adapters dictionary */
-
-int
-pysqlite_microprotocols_init(PyObject *module)
-{
- /* create adapters dictionary and put it in module namespace */
- if ((psyco_adapters = PyDict_New()) == NULL) {
- return -1;
- }
-
- int res = PyModule_AddObjectRef(module, "adapters", psyco_adapters);
- Py_DECREF(psyco_adapters);
-
- return res;
-}
-
-
-/* pysqlite_microprotocols_add - add a reverse type-caster to the dictionary */
-
-int
-pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast)
-{
- PyObject* key;
- int rc;
-
- if (proto == NULL) proto = (PyObject*)pysqlite_PrepareProtocolType;
-
- key = Py_BuildValue("(OO)", (PyObject*)type, proto);
- if (!key) {
- return -1;
- }
-
- rc = PyDict_SetItem(psyco_adapters, key, cast);
- Py_DECREF(key);
-
- return rc;
-}
-
-/* pysqlite_microprotocols_adapt - adapt an object to the built-in protocol */
-
-PyObject *
-pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
-{
- _Py_IDENTIFIER(__adapt__);
- _Py_IDENTIFIER(__conform__);
- PyObject *adapter, *key, *adapted;
-
- /* we don't check for exact type conformance as specified in PEP 246
- because the pysqlite_PrepareProtocolType type is abstract and there is no
- way to get a quotable object to be its instance */
-
- /* look for an adapter in the registry */
- key = Py_BuildValue("(OO)", (PyObject*)Py_TYPE(obj), proto);
- if (!key) {
- return NULL;
- }
- adapter = PyDict_GetItemWithError(psyco_adapters, key);
- Py_DECREF(key);
- if (adapter) {
- Py_INCREF(adapter);
- adapted = PyObject_CallOneArg(adapter, obj);
- Py_DECREF(adapter);
- return adapted;
- }
- if (PyErr_Occurred()) {
- return NULL;
- }
-
- /* try to have the protocol adapt this object */
- if (_PyObject_LookupAttrId(proto, &PyId___adapt__, &adapter) < 0) {
- return NULL;
- }
- if (adapter) {
- adapted = PyObject_CallOneArg(adapter, obj);
- Py_DECREF(adapter);
-
- if (adapted == Py_None) {
- Py_DECREF(adapted);
- }
- else if (adapted || !PyErr_ExceptionMatches(PyExc_TypeError)) {
- return adapted;
- }
- else {
- PyErr_Clear();
- }
- }
-
- /* and finally try to have the object adapt itself */
- if (_PyObject_LookupAttrId(obj, &PyId___conform__, &adapter) < 0) {
- return NULL;
- }
- if (adapter) {
- adapted = PyObject_CallOneArg(adapter, proto);
- Py_DECREF(adapter);
-
- if (adapted == Py_None) {
- Py_DECREF(adapted);
- }
- else if (adapted || !PyErr_ExceptionMatches(PyExc_TypeError)) {
- return adapted;
- }
- else {
- PyErr_Clear();
- }
- }
-
- if (alt) {
- return Py_NewRef(alt);
- }
- /* else set the right exception and return NULL */
- PyErr_SetString(pysqlite_ProgrammingError, "can't adapt");
- return NULL;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/microprotocols.h b/contrib/tools/python3/src/Modules/_sqlite/microprotocols.h
deleted file mode 100644
index e9adef916e7..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/microprotocols.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* microprotocols.c - definitions for minimalist and non-validating protocols
- *
- * Copyright (C) 2003-2004 Federico Di Gregorio <[email protected]>
- *
- * This file is part of psycopg and was adapted for pysqlite. Federico Di
- * Gregorio gave the permission to use it within pysqlite under the following
- * license:
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PSYCOPG_MICROPROTOCOLS_H
-#define PSYCOPG_MICROPROTOCOLS_H 1
-
-#define PY_SSIZE_T_CLEAN
-#include <Python.h>
-
-/** the names of the three mandatory methods **/
-
-#define MICROPROTOCOLS_GETQUOTED_NAME "getquoted"
-#define MICROPROTOCOLS_GETSTRING_NAME "getstring"
-#define MICROPROTOCOLS_GETBINARY_NAME "getbinary"
-
-/** exported functions **/
-
-/* used by module.c to init the microprotocols system */
-extern int pysqlite_microprotocols_init(PyObject *module);
-extern int pysqlite_microprotocols_add(
- PyTypeObject *type, PyObject *proto, PyObject *cast);
-extern PyObject *pysqlite_microprotocols_adapt(
- PyObject *obj, PyObject *proto, PyObject *alt);
-
-#endif /* !defined(PSYCOPG_MICROPROTOCOLS_H) */
diff --git a/contrib/tools/python3/src/Modules/_sqlite/module.c b/contrib/tools/python3/src/Modules/_sqlite/module.c
deleted file mode 100644
index 8cff4e224d5..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/module.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/* module.c - the module itself
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "connection.h"
-#include "statement.h"
-#include "cursor.h"
-#include "cache.h"
-#include "prepare_protocol.h"
-#include "microprotocols.h"
-#include "row.h"
-
-#if SQLITE_VERSION_NUMBER < 3007015
-#error "SQLite 3.7.15 or higher required"
-#endif
-
-#include "clinic/module.c.h"
-/*[clinic input]
-module _sqlite3
-[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
-
-/* static objects at module-level */
-
-PyObject *pysqlite_Error = NULL;
-PyObject *pysqlite_Warning = NULL;
-PyObject *pysqlite_InterfaceError = NULL;
-PyObject *pysqlite_DatabaseError = NULL;
-PyObject *pysqlite_InternalError = NULL;
-PyObject *pysqlite_OperationalError = NULL;
-PyObject *pysqlite_ProgrammingError = NULL;
-PyObject *pysqlite_IntegrityError = NULL;
-PyObject *pysqlite_DataError = NULL;
-PyObject *pysqlite_NotSupportedError = NULL;
-
-PyObject* _pysqlite_converters = NULL;
-int _pysqlite_enable_callback_tracebacks = 0;
-int pysqlite_BaseTypeAdapted = 0;
-
-static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
- kwargs)
-{
- /* Python seems to have no way of extracting a single keyword-arg at
- * C-level, so this code is redundant with the one in connection_init in
- * connection.c and must always be copied from there ... */
-
- static char *kwlist[] = {
- "database", "timeout", "detect_types", "isolation_level",
- "check_same_thread", "factory", "cached_statements", "uri",
- NULL
- };
- PyObject* database;
- int detect_types = 0;
- PyObject* isolation_level;
- PyObject* factory = NULL;
- int check_same_thread = 1;
- int cached_statements;
- int uri = 0;
- double timeout = 5.0;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|diOiOip", kwlist,
- &database, &timeout, &detect_types,
- &isolation_level, &check_same_thread,
- &factory, &cached_statements, &uri))
- {
- return NULL;
- }
-
- if (factory == NULL) {
- factory = (PyObject*)pysqlite_ConnectionType;
- }
-
- return PyObject_Call(factory, args, kwargs);
-}
-
-PyDoc_STRVAR(module_connect_doc,
-"connect(database[, timeout, detect_types, isolation_level,\n\
- check_same_thread, factory, cached_statements, uri])\n\
-\n\
-Opens a connection to the SQLite database file *database*. You can use\n\
-\":memory:\" to open a database connection to a database that resides in\n\
-RAM instead of on disk.");
-
-/*[clinic input]
-_sqlite3.complete_statement as pysqlite_complete_statement
-
- statement: str
-
-Checks if a string contains a complete SQL statement.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_complete_statement_impl(PyObject *module, const char *statement)
-/*[clinic end generated code: output=e55f1ff1952df558 input=ac45d257375bb828]*/
-{
- if (sqlite3_complete(statement)) {
- return Py_NewRef(Py_True);
- } else {
- return Py_NewRef(Py_False);
- }
-}
-
-/*[clinic input]
-_sqlite3.enable_shared_cache as pysqlite_enable_shared_cache
-
- do_enable: int
-
-Enable or disable shared cache mode for the calling thread.
-
-This method is deprecated and will be removed in Python 3.12.
-Shared cache is strongly discouraged by the SQLite 3 documentation.
-If shared cache must be used, open the database in URI mode using
-the cache=shared query parameter.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_enable_shared_cache_impl(PyObject *module, int do_enable)
-/*[clinic end generated code: output=259c74eedee1516b input=26e40d5971d3487d]*/
-{
- int rc;
-
- rc = sqlite3_enable_shared_cache(do_enable);
-
- if (rc != SQLITE_OK) {
- PyErr_SetString(pysqlite_OperationalError, "Changing the shared_cache flag failed");
- return NULL;
- } else {
- Py_RETURN_NONE;
- }
-}
-
-/*[clinic input]
-_sqlite3.register_adapter as pysqlite_register_adapter
-
- type: object(type='PyTypeObject *')
- caster: object
- /
-
-Registers an adapter with sqlite3's adapter registry.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
- PyObject *caster)
-/*[clinic end generated code: output=a287e8db18e8af23 input=b4bd87afcadc535d]*/
-{
- int rc;
-
- /* a basic type is adapted; there's a performance optimization if that's not the case
- * (99 % of all usages) */
- if (type == &PyLong_Type || type == &PyFloat_Type
- || type == &PyUnicode_Type || type == &PyByteArray_Type) {
- pysqlite_BaseTypeAdapted = 1;
- }
-
- rc = pysqlite_microprotocols_add(type, (PyObject*)pysqlite_PrepareProtocolType, caster);
- if (rc == -1)
- return NULL;
-
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.register_converter as pysqlite_register_converter
-
- name as orig_name: unicode
- converter as callable: object
- /
-
-Registers a converter with sqlite3.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
- PyObject *callable)
-/*[clinic end generated code: output=a2f2bfeed7230062 input=90f645419425d6c4]*/
-{
- PyObject* name = NULL;
- PyObject* retval = NULL;
- _Py_IDENTIFIER(upper);
-
- /* convert the name to upper case */
- name = _PyObject_CallMethodIdNoArgs(orig_name, &PyId_upper);
- if (!name) {
- goto error;
- }
-
- if (PyDict_SetItem(_pysqlite_converters, name, callable) != 0) {
- goto error;
- }
-
- retval = Py_NewRef(Py_None);
-error:
- Py_XDECREF(name);
- return retval;
-}
-
-/*[clinic input]
-_sqlite3.enable_callback_tracebacks as pysqlite_enable_callback_trace
-
- enable: int
- /
-
-Enable or disable callback functions throwing errors to stderr.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_enable_callback_trace_impl(PyObject *module, int enable)
-/*[clinic end generated code: output=4ff1d051c698f194 input=cb79d3581eb77c40]*/
-{
- _pysqlite_enable_callback_tracebacks = enable;
-
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
-_sqlite3.adapt as pysqlite_adapt
-
- obj: object
- proto: object(c_default='(PyObject*)pysqlite_PrepareProtocolType') = PrepareProtocolType
- alt: object = NULL
- /
-
-Adapt given object to given protocol.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
- PyObject *alt)
-/*[clinic end generated code: output=0c3927c5fcd23dd9 input=46ca9564710ba48a]*/
-{
- return pysqlite_microprotocols_adapt(obj, proto, alt);
-}
-
-static int converters_init(PyObject* module)
-{
- _pysqlite_converters = PyDict_New();
- if (!_pysqlite_converters) {
- return -1;
- }
-
- int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters);
- Py_DECREF(_pysqlite_converters);
-
- return res;
-}
-
-static PyMethodDef module_methods[] = {
- {"connect", (PyCFunction)(void(*)(void))module_connect,
- METH_VARARGS | METH_KEYWORDS, module_connect_doc},
- PYSQLITE_ADAPT_METHODDEF
- PYSQLITE_COMPLETE_STATEMENT_METHODDEF
- PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
- PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF
- PYSQLITE_REGISTER_ADAPTER_METHODDEF
- PYSQLITE_REGISTER_CONVERTER_METHODDEF
- {NULL, NULL}
-};
-
-static int
-add_integer_constants(PyObject *module) {
-#define ADD_INT(ival) \
- do { \
- if (PyModule_AddIntConstant(module, #ival, ival) < 0) { \
- return -1; \
- } \
- } while (0); \
-
- ADD_INT(PARSE_DECLTYPES);
- ADD_INT(PARSE_COLNAMES);
- ADD_INT(SQLITE_OK);
- ADD_INT(SQLITE_DENY);
- ADD_INT(SQLITE_IGNORE);
- ADD_INT(SQLITE_CREATE_INDEX);
- ADD_INT(SQLITE_CREATE_TABLE);
- ADD_INT(SQLITE_CREATE_TEMP_INDEX);
- ADD_INT(SQLITE_CREATE_TEMP_TABLE);
- ADD_INT(SQLITE_CREATE_TEMP_TRIGGER);
- ADD_INT(SQLITE_CREATE_TEMP_VIEW);
- ADD_INT(SQLITE_CREATE_TRIGGER);
- ADD_INT(SQLITE_CREATE_VIEW);
- ADD_INT(SQLITE_DELETE);
- ADD_INT(SQLITE_DROP_INDEX);
- ADD_INT(SQLITE_DROP_TABLE);
- ADD_INT(SQLITE_DROP_TEMP_INDEX);
- ADD_INT(SQLITE_DROP_TEMP_TABLE);
- ADD_INT(SQLITE_DROP_TEMP_TRIGGER);
- ADD_INT(SQLITE_DROP_TEMP_VIEW);
- ADD_INT(SQLITE_DROP_TRIGGER);
- ADD_INT(SQLITE_DROP_VIEW);
- ADD_INT(SQLITE_INSERT);
- ADD_INT(SQLITE_PRAGMA);
- ADD_INT(SQLITE_READ);
- ADD_INT(SQLITE_SELECT);
- ADD_INT(SQLITE_TRANSACTION);
- ADD_INT(SQLITE_UPDATE);
- ADD_INT(SQLITE_ATTACH);
- ADD_INT(SQLITE_DETACH);
- ADD_INT(SQLITE_ALTER_TABLE);
- ADD_INT(SQLITE_REINDEX);
- ADD_INT(SQLITE_ANALYZE);
- ADD_INT(SQLITE_CREATE_VTABLE);
- ADD_INT(SQLITE_DROP_VTABLE);
- ADD_INT(SQLITE_FUNCTION);
- ADD_INT(SQLITE_SAVEPOINT);
-#if SQLITE_VERSION_NUMBER >= 3008003
- ADD_INT(SQLITE_RECURSIVE);
-#endif
- ADD_INT(SQLITE_DONE);
-#undef ADD_INT
- return 0;
-}
-
-static struct PyModuleDef _sqlite3module = {
- PyModuleDef_HEAD_INIT,
- "_sqlite3",
- NULL,
- -1,
- module_methods,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-#define ADD_TYPE(module, type) \
-do { \
- if (PyModule_AddType(module, &type) < 0) { \
- goto error; \
- } \
-} while (0)
-
-#define ADD_EXCEPTION(module, name, exc, base) \
-do { \
- exc = PyErr_NewException(MODULE_NAME "." name, base, NULL); \
- if (!exc) { \
- goto error; \
- } \
- int res = PyModule_AddObjectRef(module, name, exc); \
- Py_DECREF(exc); \
- if (res < 0) { \
- goto error; \
- } \
-} while (0)
-
-PyMODINIT_FUNC PyInit__sqlite3(void)
-{
- PyObject *module;
-
- if (sqlite3_libversion_number() < 3007015) {
- PyErr_SetString(PyExc_ImportError, MODULE_NAME ": SQLite 3.7.15 or higher required");
- return NULL;
- }
-
- int rc = sqlite3_initialize();
- if (rc != SQLITE_OK) {
- PyErr_SetString(PyExc_ImportError, sqlite3_errstr(rc));
- return NULL;
- }
-
- module = PyModule_Create(&_sqlite3module);
-
- if (!module ||
- (pysqlite_row_setup_types(module) < 0) ||
- (pysqlite_cursor_setup_types(module) < 0) ||
- (pysqlite_connection_setup_types(module) < 0) ||
- (pysqlite_cache_setup_types(module) < 0) ||
- (pysqlite_statement_setup_types(module) < 0) ||
- (pysqlite_prepare_protocol_setup_types(module) < 0)
- ) {
- goto error;
- }
-
- ADD_TYPE(module, *pysqlite_ConnectionType);
- ADD_TYPE(module, *pysqlite_CursorType);
- ADD_TYPE(module, *pysqlite_PrepareProtocolType);
- ADD_TYPE(module, *pysqlite_RowType);
-
- /*** Create DB-API Exception hierarchy */
- ADD_EXCEPTION(module, "Error", pysqlite_Error, PyExc_Exception);
- ADD_EXCEPTION(module, "Warning", pysqlite_Warning, PyExc_Exception);
-
- /* Error subclasses */
- ADD_EXCEPTION(module, "InterfaceError", pysqlite_InterfaceError, pysqlite_Error);
- ADD_EXCEPTION(module, "DatabaseError", pysqlite_DatabaseError, pysqlite_Error);
-
- /* pysqlite_DatabaseError subclasses */
- ADD_EXCEPTION(module, "InternalError", pysqlite_InternalError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "OperationalError", pysqlite_OperationalError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "ProgrammingError", pysqlite_ProgrammingError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "IntegrityError", pysqlite_IntegrityError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "DataError", pysqlite_DataError, pysqlite_DatabaseError);
- ADD_EXCEPTION(module, "NotSupportedError", pysqlite_NotSupportedError, pysqlite_DatabaseError);
-
- /* Set integer constants */
- if (add_integer_constants(module) < 0) {
- goto error;
- }
-
- if (PyModule_AddStringConstant(module, "version", PYSQLITE_VERSION) < 0) {
- goto error;
- }
-
- if (PyModule_AddStringConstant(module, "sqlite_version", sqlite3_libversion())) {
- goto error;
- }
-
- /* initialize microprotocols layer */
- if (pysqlite_microprotocols_init(module) < 0) {
- goto error;
- }
-
- /* initialize the default converters */
- if (converters_init(module) < 0) {
- goto error;
- }
-
- return module;
-
-error:
- sqlite3_shutdown();
- PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
- Py_XDECREF(module);
- return NULL;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/module.h b/contrib/tools/python3/src/Modules/_sqlite/module.h
deleted file mode 100644
index 9aede92ea33..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/module.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* module.h - definitions for the module
- *
- * Copyright (C) 2004-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_MODULE_H
-#define PYSQLITE_MODULE_H
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-
-#define PYSQLITE_VERSION "2.6.0"
-#define MODULE_NAME "sqlite3"
-
-extern PyObject* pysqlite_Error;
-extern PyObject* pysqlite_Warning;
-extern PyObject* pysqlite_InterfaceError;
-extern PyObject* pysqlite_DatabaseError;
-extern PyObject* pysqlite_InternalError;
-extern PyObject* pysqlite_OperationalError;
-extern PyObject* pysqlite_ProgrammingError;
-extern PyObject* pysqlite_IntegrityError;
-extern PyObject* pysqlite_DataError;
-extern PyObject* pysqlite_NotSupportedError;
-
-/* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter
- * functions, that convert the SQL value to the appropriate Python value.
- * The key is uppercase.
- */
-extern PyObject* _pysqlite_converters;
-
-extern int _pysqlite_enable_callback_tracebacks;
-extern int pysqlite_BaseTypeAdapted;
-
-#define PARSE_DECLTYPES 1
-#define PARSE_COLNAMES 2
-#endif
diff --git a/contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.c b/contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.c
deleted file mode 100644
index 800eef8794b..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/* prepare_protocol.c - the protocol for preparing values for SQLite
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "prepare_protocol.h"
-
-static int
-pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol *self, PyObject *args,
- PyObject *kwargs)
-{
- return 0;
-}
-
-static int
-pysqlite_prepare_protocol_traverse(PyObject *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- return 0;
-}
-
-static void
-pysqlite_prepare_protocol_dealloc(pysqlite_PrepareProtocol *self)
-{
- PyTypeObject *tp = Py_TYPE(self);
- PyObject_GC_UnTrack(self);
- tp->tp_free(self);
- Py_DECREF(tp);
-}
-
-static PyType_Slot type_slots[] = {
- {Py_tp_dealloc, pysqlite_prepare_protocol_dealloc},
- {Py_tp_init, pysqlite_prepare_protocol_init},
- {Py_tp_traverse, pysqlite_prepare_protocol_traverse},
- {0, NULL},
-};
-
-static PyType_Spec type_spec = {
- .name = MODULE_NAME ".PrepareProtocol",
- .basicsize = sizeof(pysqlite_PrepareProtocol),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = type_slots,
-};
-
-PyTypeObject *pysqlite_PrepareProtocolType = NULL;
-
-int
-pysqlite_prepare_protocol_setup_types(PyObject *module)
-{
- pysqlite_PrepareProtocolType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &type_spec, NULL);
- if (pysqlite_PrepareProtocolType == NULL) {
- return -1;
- }
- return 0;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.h b/contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.h
deleted file mode 100644
index 593961331c9..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/prepare_protocol.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* prepare_protocol.h - the protocol for preparing values for SQLite
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_PREPARE_PROTOCOL_H
-#define PYSQLITE_PREPARE_PROTOCOL_H
-#include "module.h"
-
-typedef struct
-{
- PyObject_HEAD
-} pysqlite_PrepareProtocol;
-
-extern PyTypeObject *pysqlite_PrepareProtocolType;
-
-int pysqlite_prepare_protocol_setup_types(PyObject *module);
-
-#define UNKNOWN (-1)
-#endif
diff --git a/contrib/tools/python3/src/Modules/_sqlite/row.c b/contrib/tools/python3/src/Modules/_sqlite/row.c
deleted file mode 100644
index 643194df040..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/row.c
+++ /dev/null
@@ -1,272 +0,0 @@
-/* row.c - an enhanced tuple for database rows
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "row.h"
-#include "cursor.h"
-#include "clinic/row.c.h"
-
-/*[clinic input]
-module _sqlite3
-class _sqlite3.Row "pysqlite_Row *" "pysqlite_RowType"
-[clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=384227da65f250fd]*/
-
-static int
-row_clear(pysqlite_Row *self)
-{
- Py_CLEAR(self->data);
- Py_CLEAR(self->description);
- return 0;
-}
-
-static int
-row_traverse(pysqlite_Row *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- Py_VISIT(self->data);
- Py_VISIT(self->description);
- return 0;
-}
-
-static void
-pysqlite_row_dealloc(PyObject *self)
-{
- PyTypeObject *tp = Py_TYPE(self);
- PyObject_GC_UnTrack(self);
- tp->tp_clear(self);
- tp->tp_free(self);
- Py_DECREF(tp);
-}
-
-/*[clinic input]
-@classmethod
-_sqlite3.Row.__new__ as pysqlite_row_new
-
- cursor: object(type='pysqlite_Cursor *', subclass_of='pysqlite_CursorType')
- data: object(subclass_of='&PyTuple_Type')
- /
-
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,
- PyObject *data)
-/*[clinic end generated code: output=10d58b09a819a4c1 input=f6cd7e6e0935828d]*/
-{
- pysqlite_Row *self;
-
- assert(type != NULL && type->tp_alloc != NULL);
-
- self = (pysqlite_Row *) type->tp_alloc(type, 0);
- if (self == NULL)
- return NULL;
-
- self->data = Py_NewRef(data);
- self->description = Py_NewRef(cursor->description);
-
- return (PyObject *) self;
-}
-
-PyObject* pysqlite_row_item(pysqlite_Row* self, Py_ssize_t idx)
-{
- PyObject *item = PyTuple_GetItem(self->data, idx);
- return Py_XNewRef(item);
-}
-
-static int
-equal_ignore_case(PyObject *left, PyObject *right)
-{
- int eq = PyObject_RichCompareBool(left, right, Py_EQ);
- if (eq) { /* equal or error */
- return eq;
- }
- if (!PyUnicode_Check(left) || !PyUnicode_Check(right)) {
- return 0;
- }
- if (!PyUnicode_IS_ASCII(left) || !PyUnicode_IS_ASCII(right)) {
- return 0;
- }
-
- Py_ssize_t len = PyUnicode_GET_LENGTH(left);
- if (PyUnicode_GET_LENGTH(right) != len) {
- return 0;
- }
- const Py_UCS1 *p1 = PyUnicode_1BYTE_DATA(left);
- const Py_UCS1 *p2 = PyUnicode_1BYTE_DATA(right);
- for (; len; len--, p1++, p2++) {
- if (Py_TOLOWER(*p1) != Py_TOLOWER(*p2)) {
- return 0;
- }
- }
- return 1;
-}
-
-static PyObject *
-pysqlite_row_subscript(pysqlite_Row *self, PyObject *idx)
-{
- Py_ssize_t _idx;
- Py_ssize_t nitems, i;
-
- if (PyLong_Check(idx)) {
- _idx = PyNumber_AsSsize_t(idx, PyExc_IndexError);
- if (_idx == -1 && PyErr_Occurred())
- return NULL;
- if (_idx < 0)
- _idx += PyTuple_GET_SIZE(self->data);
-
- PyObject *item = PyTuple_GetItem(self->data, _idx);
- return Py_XNewRef(item);
- } else if (PyUnicode_Check(idx)) {
- nitems = PyTuple_Size(self->description);
-
- for (i = 0; i < nitems; i++) {
- PyObject *obj;
- obj = PyTuple_GET_ITEM(self->description, i);
- obj = PyTuple_GET_ITEM(obj, 0);
- int eq = equal_ignore_case(idx, obj);
- if (eq < 0) {
- return NULL;
- }
- if (eq) {
- /* found item */
- PyObject *item = PyTuple_GetItem(self->data, i);
- return Py_XNewRef(item);
- }
- }
-
- PyErr_SetString(PyExc_IndexError, "No item with that key");
- return NULL;
- }
- else if (PySlice_Check(idx)) {
- return PyObject_GetItem(self->data, idx);
- }
- else {
- PyErr_SetString(PyExc_IndexError, "Index must be int or string");
- return NULL;
- }
-}
-
-static Py_ssize_t
-pysqlite_row_length(pysqlite_Row* self)
-{
- return PyTuple_GET_SIZE(self->data);
-}
-
-/*[clinic input]
-_sqlite3.Row.keys as pysqlite_row_keys
-
-Returns the keys of the row.
-[clinic start generated code]*/
-
-static PyObject *
-pysqlite_row_keys_impl(pysqlite_Row *self)
-/*[clinic end generated code: output=efe3dfb3af6edc07 input=7549a122827c5563]*/
-{
- PyObject* list;
- Py_ssize_t nitems, i;
-
- list = PyList_New(0);
- if (!list) {
- return NULL;
- }
- nitems = PyTuple_Size(self->description);
-
- for (i = 0; i < nitems; i++) {
- if (PyList_Append(list, PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0)) != 0) {
- Py_DECREF(list);
- return NULL;
- }
- }
-
- return list;
-}
-
-static PyObject* pysqlite_iter(pysqlite_Row* self)
-{
- return PyObject_GetIter(self->data);
-}
-
-static Py_hash_t pysqlite_row_hash(pysqlite_Row *self)
-{
- return PyObject_Hash(self->description) ^ PyObject_Hash(self->data);
-}
-
-static PyObject* pysqlite_row_richcompare(pysqlite_Row *self, PyObject *_other, int opid)
-{
- if (opid != Py_EQ && opid != Py_NE)
- Py_RETURN_NOTIMPLEMENTED;
-
- if (PyObject_TypeCheck(_other, pysqlite_RowType)) {
- pysqlite_Row *other = (pysqlite_Row *)_other;
- int eq = PyObject_RichCompareBool(self->description, other->description, Py_EQ);
- if (eq < 0) {
- return NULL;
- }
- if (eq) {
- return PyObject_RichCompare(self->data, other->data, opid);
- }
- return PyBool_FromLong(opid != Py_EQ);
- }
- Py_RETURN_NOTIMPLEMENTED;
-}
-
-static PyMethodDef row_methods[] = {
- PYSQLITE_ROW_KEYS_METHODDEF
- {NULL, NULL}
-};
-
-static PyType_Slot row_slots[] = {
- {Py_tp_dealloc, pysqlite_row_dealloc},
- {Py_tp_hash, pysqlite_row_hash},
- {Py_tp_methods, row_methods},
- {Py_tp_richcompare, pysqlite_row_richcompare},
- {Py_tp_iter, pysqlite_iter},
- {Py_mp_length, pysqlite_row_length},
- {Py_mp_subscript, pysqlite_row_subscript},
- {Py_sq_length, pysqlite_row_length},
- {Py_sq_item, pysqlite_row_item},
- {Py_tp_new, pysqlite_row_new},
- {Py_tp_traverse, row_traverse},
- {Py_tp_clear, row_clear},
- {0, NULL},
-};
-
-static PyType_Spec row_spec = {
- .name = MODULE_NAME ".Row",
- .basicsize = sizeof(pysqlite_Row),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = row_slots,
-};
-
-PyTypeObject *pysqlite_RowType = NULL;
-
-int
-pysqlite_row_setup_types(PyObject *module)
-{
- pysqlite_RowType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &row_spec, NULL);
- if (pysqlite_RowType == NULL) {
- return -1;
- }
- return 0;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/row.h b/contrib/tools/python3/src/Modules/_sqlite/row.h
deleted file mode 100644
index 2dac41e89e1..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/row.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* row.h - an enhanced tuple for database rows
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_ROW_H
-#define PYSQLITE_ROW_H
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-
-typedef struct _Row
-{
- PyObject_HEAD
- PyObject* data;
- PyObject* description;
-} pysqlite_Row;
-
-extern PyTypeObject *pysqlite_RowType;
-
-int pysqlite_row_setup_types(PyObject *module);
-
-#endif
diff --git a/contrib/tools/python3/src/Modules/_sqlite/statement.c b/contrib/tools/python3/src/Modules/_sqlite/statement.c
deleted file mode 100644
index 3bc86420aa0..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/statement.c
+++ /dev/null
@@ -1,532 +0,0 @@
-/* statement.c - the statement type
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "statement.h"
-#include "cursor.h"
-#include "connection.h"
-#include "microprotocols.h"
-#include "prepare_protocol.h"
-#include "util.h"
-
-/* prototypes */
-static int pysqlite_check_remaining_sql(const char* tail);
-
-typedef enum {
- LINECOMMENT_1,
- IN_LINECOMMENT,
- COMMENTSTART_1,
- IN_COMMENT,
- COMMENTEND_1,
- NORMAL
-} parse_remaining_sql_state;
-
-typedef enum {
- TYPE_LONG,
- TYPE_FLOAT,
- TYPE_UNICODE,
- TYPE_BUFFER,
- TYPE_UNKNOWN
-} parameter_type;
-
-pysqlite_Statement *
-pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql)
-{
- const char* tail;
- int rc;
- const char* sql_cstr;
- Py_ssize_t sql_cstr_len;
- const char* p;
-
- assert(PyUnicode_Check(sql));
-
- sql_cstr = PyUnicode_AsUTF8AndSize(sql, &sql_cstr_len);
- if (sql_cstr == NULL) {
- PyErr_Format(pysqlite_Warning,
- "SQL is of wrong type ('%s'). Must be string.",
- Py_TYPE(sql)->tp_name);
- return NULL;
- }
- if (strlen(sql_cstr) != (size_t)sql_cstr_len) {
- PyErr_SetString(PyExc_ValueError,
- "the query contains a null character");
- return NULL;
- }
-
- pysqlite_Statement *self = PyObject_GC_New(pysqlite_Statement,
- pysqlite_StatementType);
- if (self == NULL) {
- return NULL;
- }
-
- self->db = connection->db;
- self->st = NULL;
- self->sql = Py_NewRef(sql);
- self->in_use = 0;
- self->is_dml = 0;
- self->in_weakreflist = NULL;
-
- /* Determine if the statement is a DML statement.
- SELECT is the only exception. See #9924. */
- for (p = sql_cstr; *p != 0; p++) {
- switch (*p) {
- case ' ':
- case '\r':
- case '\n':
- case '\t':
- continue;
- }
-
- self->is_dml = (PyOS_strnicmp(p, "insert", 6) == 0)
- || (PyOS_strnicmp(p, "update", 6) == 0)
- || (PyOS_strnicmp(p, "delete", 6) == 0)
- || (PyOS_strnicmp(p, "replace", 7) == 0);
- break;
- }
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_prepare_v2(self->db,
- sql_cstr,
- -1,
- &self->st,
- &tail);
- Py_END_ALLOW_THREADS
-
- PyObject_GC_Track(self);
-
- if (rc != SQLITE_OK) {
- _pysqlite_seterror(self->db, NULL);
- goto error;
- }
-
- if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
- (void)sqlite3_finalize(self->st);
- self->st = NULL;
- PyErr_SetString(pysqlite_Warning,
- "You can only execute one statement at a time.");
- goto error;
- }
-
- return self;
-
-error:
- Py_DECREF(self);
- return NULL;
-}
-
-int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
-{
- int rc = SQLITE_OK;
- const char *string;
- Py_ssize_t buflen;
- parameter_type paramtype;
-
- if (parameter == Py_None) {
- rc = sqlite3_bind_null(self->st, pos);
- goto final;
- }
-
- if (PyLong_CheckExact(parameter)) {
- paramtype = TYPE_LONG;
- } else if (PyFloat_CheckExact(parameter)) {
- paramtype = TYPE_FLOAT;
- } else if (PyUnicode_CheckExact(parameter)) {
- paramtype = TYPE_UNICODE;
- } else if (PyLong_Check(parameter)) {
- paramtype = TYPE_LONG;
- } else if (PyFloat_Check(parameter)) {
- paramtype = TYPE_FLOAT;
- } else if (PyUnicode_Check(parameter)) {
- paramtype = TYPE_UNICODE;
- } else if (PyObject_CheckBuffer(parameter)) {
- paramtype = TYPE_BUFFER;
- } else {
- paramtype = TYPE_UNKNOWN;
- }
-
- switch (paramtype) {
- case TYPE_LONG: {
- sqlite_int64 value = _pysqlite_long_as_int64(parameter);
- if (value == -1 && PyErr_Occurred())
- rc = -1;
- else
- rc = sqlite3_bind_int64(self->st, pos, value);
- break;
- }
- case TYPE_FLOAT: {
- double value = PyFloat_AsDouble(parameter);
- if (value == -1 && PyErr_Occurred()) {
- rc = -1;
- }
- else {
- rc = sqlite3_bind_double(self->st, pos, value);
- }
- break;
- }
- case TYPE_UNICODE:
- string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
- if (string == NULL)
- return -1;
- if (buflen > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "string longer than INT_MAX bytes");
- return -1;
- }
- rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
- break;
- case TYPE_BUFFER: {
- Py_buffer view;
- if (PyObject_GetBuffer(parameter, &view, PyBUF_SIMPLE) != 0) {
- PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
- return -1;
- }
- if (view.len > INT_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "BLOB longer than INT_MAX bytes");
- PyBuffer_Release(&view);
- return -1;
- }
- rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
- PyBuffer_Release(&view);
- break;
- }
- case TYPE_UNKNOWN:
- rc = -1;
- }
-
-final:
- return rc;
-}
-
-/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
-static int _need_adapt(PyObject* obj)
-{
- if (pysqlite_BaseTypeAdapted) {
- return 1;
- }
-
- if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
- || PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
- return 0;
- } else {
- return 1;
- }
-}
-
-void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
-{
- PyObject* current_param;
- PyObject* adapted;
- const char* binding_name;
- int i;
- int rc;
- int num_params_needed;
- Py_ssize_t num_params;
-
- Py_BEGIN_ALLOW_THREADS
- num_params_needed = sqlite3_bind_parameter_count(self->st);
- Py_END_ALLOW_THREADS
-
- if (PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) || (!PyDict_Check(parameters) && PySequence_Check(parameters))) {
- /* parameters passed as sequence */
- if (PyTuple_CheckExact(parameters)) {
- num_params = PyTuple_GET_SIZE(parameters);
- } else if (PyList_CheckExact(parameters)) {
- num_params = PyList_GET_SIZE(parameters);
- } else {
- num_params = PySequence_Size(parameters);
- if (num_params == -1) {
- return;
- }
- }
- if (num_params != num_params_needed) {
- PyErr_Format(pysqlite_ProgrammingError,
- "Incorrect number of bindings supplied. The current "
- "statement uses %d, and there are %zd supplied.",
- num_params_needed, num_params);
- return;
- }
- for (i = 0; i < num_params; i++) {
- if (PyTuple_CheckExact(parameters)) {
- PyObject *item = PyTuple_GET_ITEM(parameters, i);
- current_param = Py_NewRef(item);
- } else if (PyList_CheckExact(parameters)) {
- PyObject *item = PyList_GetItem(parameters, i);
- current_param = Py_XNewRef(item);
- } else {
- current_param = PySequence_GetItem(parameters, i);
- }
- if (!current_param) {
- return;
- }
-
- if (!_need_adapt(current_param)) {
- adapted = current_param;
- } else {
- adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
- Py_DECREF(current_param);
- if (!adapted) {
- return;
- }
- }
-
- rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
- Py_DECREF(adapted);
-
- if (rc != SQLITE_OK) {
- if (!PyErr_Occurred()) {
- PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
- }
- return;
- }
- }
- } else if (PyDict_Check(parameters)) {
- /* parameters passed as dictionary */
- for (i = 1; i <= num_params_needed; i++) {
- PyObject *binding_name_obj;
- Py_BEGIN_ALLOW_THREADS
- binding_name = sqlite3_bind_parameter_name(self->st, i);
- Py_END_ALLOW_THREADS
- if (!binding_name) {
- PyErr_Format(pysqlite_ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i);
- return;
- }
-
- binding_name++; /* skip first char (the colon) */
- binding_name_obj = PyUnicode_FromString(binding_name);
- if (!binding_name_obj) {
- return;
- }
- if (PyDict_CheckExact(parameters)) {
- PyObject *item = PyDict_GetItemWithError(parameters, binding_name_obj);
- current_param = Py_XNewRef(item);
- } else {
- current_param = PyObject_GetItem(parameters, binding_name_obj);
- }
- Py_DECREF(binding_name_obj);
- if (!current_param) {
- if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
- PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding parameter :%s.", binding_name);
- }
- return;
- }
-
- if (!_need_adapt(current_param)) {
- adapted = current_param;
- } else {
- adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)pysqlite_PrepareProtocolType, current_param);
- Py_DECREF(current_param);
- if (!adapted) {
- return;
- }
- }
-
- rc = pysqlite_statement_bind_parameter(self, i, adapted);
- Py_DECREF(adapted);
-
- if (rc != SQLITE_OK) {
- if (!PyErr_Occurred()) {
- PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
- }
- return;
- }
- }
- } else {
- PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
- }
-}
-
-int pysqlite_statement_finalize(pysqlite_Statement* self)
-{
- int rc;
-
- rc = SQLITE_OK;
- if (self->st) {
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_finalize(self->st);
- Py_END_ALLOW_THREADS
- self->st = NULL;
- }
-
- self->in_use = 0;
-
- return rc;
-}
-
-int pysqlite_statement_reset(pysqlite_Statement* self)
-{
- int rc;
-
- rc = SQLITE_OK;
-
- if (self->in_use && self->st) {
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_reset(self->st);
- Py_END_ALLOW_THREADS
-
- if (rc == SQLITE_OK) {
- self->in_use = 0;
- }
- }
-
- return rc;
-}
-
-void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
-{
- self->in_use = 1;
-}
-
-static void
-stmt_dealloc(pysqlite_Statement *self)
-{
- PyTypeObject *tp = Py_TYPE(self);
- PyObject_GC_UnTrack(self);
- if (self->in_weakreflist != NULL) {
- PyObject_ClearWeakRefs((PyObject*)self);
- }
- if (self->st) {
- Py_BEGIN_ALLOW_THREADS
- sqlite3_finalize(self->st);
- Py_END_ALLOW_THREADS
- self->st = 0;
- }
- tp->tp_clear((PyObject *)self);
- tp->tp_free(self);
- Py_DECREF(tp);
-}
-
-static int
-stmt_clear(pysqlite_Statement *self)
-{
- Py_CLEAR(self->sql);
- return 0;
-}
-
-static int
-stmt_traverse(pysqlite_Statement *self, visitproc visit, void *arg)
-{
- Py_VISIT(Py_TYPE(self));
- Py_VISIT(self->sql);
- return 0;
-}
-
-/*
- * Checks if there is anything left in an SQL string after SQLite compiled it.
- * This is used to check if somebody tried to execute more than one SQL command
- * with one execute()/executemany() command, which the DB-API and we don't
- * allow.
- *
- * Returns 1 if there is more left than should be. 0 if ok.
- */
-static int pysqlite_check_remaining_sql(const char* tail)
-{
- const char* pos = tail;
-
- parse_remaining_sql_state state = NORMAL;
-
- for (;;) {
- switch (*pos) {
- case 0:
- return 0;
- case '-':
- if (state == NORMAL) {
- state = LINECOMMENT_1;
- } else if (state == LINECOMMENT_1) {
- state = IN_LINECOMMENT;
- }
- break;
- case ' ':
- case '\t':
- break;
- case '\n':
- case 13:
- if (state == IN_LINECOMMENT) {
- state = NORMAL;
- }
- break;
- case '/':
- if (state == NORMAL) {
- state = COMMENTSTART_1;
- } else if (state == COMMENTEND_1) {
- state = NORMAL;
- } else if (state == COMMENTSTART_1) {
- return 1;
- }
- break;
- case '*':
- if (state == NORMAL) {
- return 1;
- } else if (state == LINECOMMENT_1) {
- return 1;
- } else if (state == COMMENTSTART_1) {
- state = IN_COMMENT;
- } else if (state == IN_COMMENT) {
- state = COMMENTEND_1;
- }
- break;
- default:
- if (state == COMMENTEND_1) {
- state = IN_COMMENT;
- } else if (state == IN_LINECOMMENT) {
- } else if (state == IN_COMMENT) {
- } else {
- return 1;
- }
- }
-
- pos++;
- }
-
- return 0;
-}
-
-static PyMemberDef stmt_members[] = {
- {"__weaklistoffset__", T_PYSSIZET, offsetof(pysqlite_Statement, in_weakreflist), READONLY},
- {NULL},
-};
-static PyType_Slot stmt_slots[] = {
- {Py_tp_members, stmt_members},
- {Py_tp_dealloc, stmt_dealloc},
- {Py_tp_traverse, stmt_traverse},
- {Py_tp_clear, stmt_clear},
- {0, NULL},
-};
-
-static PyType_Spec stmt_spec = {
- .name = MODULE_NAME ".Statement",
- .basicsize = sizeof(pysqlite_Statement),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
- .slots = stmt_slots,
-};
-PyTypeObject *pysqlite_StatementType = NULL;
-
-int
-pysqlite_statement_setup_types(PyObject *module)
-{
- pysqlite_StatementType = (PyTypeObject *)PyType_FromModuleAndSpec(module, &stmt_spec, NULL);
- if (pysqlite_StatementType == NULL) {
- return -1;
- }
- return 0;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/statement.h b/contrib/tools/python3/src/Modules/_sqlite/statement.h
deleted file mode 100644
index e8c86a0ec96..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/statement.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* statement.h - definitions for the statement type
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_STATEMENT_H
-#define PYSQLITE_STATEMENT_H
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-
-#include "connection.h"
-#include "sqlite3.h"
-
-typedef struct
-{
- PyObject_HEAD
- sqlite3* db;
- sqlite3_stmt* st;
- PyObject* sql;
- int in_use;
- int is_dml;
- PyObject* in_weakreflist; /* List of weak references */
-} pysqlite_Statement;
-
-extern PyTypeObject *pysqlite_StatementType;
-
-pysqlite_Statement *pysqlite_statement_create(pysqlite_Connection *connection, PyObject *sql);
-
-int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter);
-void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters);
-
-int pysqlite_statement_finalize(pysqlite_Statement* self);
-int pysqlite_statement_reset(pysqlite_Statement* self);
-void pysqlite_statement_mark_dirty(pysqlite_Statement* self);
-
-int pysqlite_statement_setup_types(PyObject *module);
-
-#endif
diff --git a/contrib/tools/python3/src/Modules/_sqlite/util.c b/contrib/tools/python3/src/Modules/_sqlite/util.c
deleted file mode 100644
index 0f4eba0ab31..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/util.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/* util.c - various utility functions
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#include "module.h"
-#include "connection.h"
-
-int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection)
-{
- int rc;
-
- Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_step(statement);
- Py_END_ALLOW_THREADS
-
- return rc;
-}
-
-/**
- * Checks the SQLite error code and sets the appropriate DB-API exception.
- * Returns the error code (0 means no error occurred).
- */
-int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st)
-{
- int errorcode = sqlite3_errcode(db);
-
- switch (errorcode)
- {
- case SQLITE_OK:
- PyErr_Clear();
- break;
- case SQLITE_INTERNAL:
- case SQLITE_NOTFOUND:
- PyErr_SetString(pysqlite_InternalError, sqlite3_errmsg(db));
- break;
- case SQLITE_NOMEM:
- (void)PyErr_NoMemory();
- break;
- case SQLITE_ERROR:
- case SQLITE_PERM:
- case SQLITE_ABORT:
- case SQLITE_BUSY:
- case SQLITE_LOCKED:
- case SQLITE_READONLY:
- case SQLITE_INTERRUPT:
- case SQLITE_IOERR:
- case SQLITE_FULL:
- case SQLITE_CANTOPEN:
- case SQLITE_PROTOCOL:
- case SQLITE_EMPTY:
- case SQLITE_SCHEMA:
- PyErr_SetString(pysqlite_OperationalError, sqlite3_errmsg(db));
- break;
- case SQLITE_CORRUPT:
- PyErr_SetString(pysqlite_DatabaseError, sqlite3_errmsg(db));
- break;
- case SQLITE_TOOBIG:
- PyErr_SetString(pysqlite_DataError, sqlite3_errmsg(db));
- break;
- case SQLITE_CONSTRAINT:
- case SQLITE_MISMATCH:
- PyErr_SetString(pysqlite_IntegrityError, sqlite3_errmsg(db));
- break;
- case SQLITE_MISUSE:
- PyErr_SetString(pysqlite_ProgrammingError, sqlite3_errmsg(db));
- break;
- default:
- PyErr_SetString(pysqlite_DatabaseError, sqlite3_errmsg(db));
- break;
- }
-
- return errorcode;
-}
-
-#ifdef WORDS_BIGENDIAN
-# define IS_LITTLE_ENDIAN 0
-#else
-# define IS_LITTLE_ENDIAN 1
-#endif
-
-sqlite_int64
-_pysqlite_long_as_int64(PyObject * py_val)
-{
- int overflow;
- long long value = PyLong_AsLongLongAndOverflow(py_val, &overflow);
- if (value == -1 && PyErr_Occurred())
- return -1;
- if (!overflow) {
-# if SIZEOF_LONG_LONG > 8
- if (-0x8000000000000000LL <= value && value <= 0x7FFFFFFFFFFFFFFFLL)
-# endif
- return value;
- }
- else if (sizeof(value) < sizeof(sqlite_int64)) {
- sqlite_int64 int64val;
- if (_PyLong_AsByteArray((PyLongObject *)py_val,
- (unsigned char *)&int64val, sizeof(int64val),
- IS_LITTLE_ENDIAN, 1 /* signed */) >= 0) {
- return int64val;
- }
- }
- PyErr_SetString(PyExc_OverflowError,
- "Python int too large to convert to SQLite INTEGER");
- return -1;
-}
diff --git a/contrib/tools/python3/src/Modules/_sqlite/util.h b/contrib/tools/python3/src/Modules/_sqlite/util.h
deleted file mode 100644
index cff31cda957..00000000000
--- a/contrib/tools/python3/src/Modules/_sqlite/util.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* util.h - various utility functions
- *
- * Copyright (C) 2005-2010 Gerhard Häring <[email protected]>
- *
- * This file is part of pysqlite.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- */
-
-#ifndef PYSQLITE_UTIL_H
-#define PYSQLITE_UTIL_H
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "pythread.h"
-#include "sqlite3.h"
-#include "connection.h"
-
-int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection);
-
-/**
- * Checks the SQLite error code and sets the appropriate DB-API exception.
- * Returns the error code (0 means no error occurred).
- */
-int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st);
-
-sqlite_int64 _pysqlite_long_as_int64(PyObject * value);
-
-#endif