summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Modules/_sqlite
diff options
context:
space:
mode:
authorshadchin <[email protected]>2026-02-03 21:59:07 +0300
committershadchin <[email protected]>2026-02-03 22:28:51 +0300
commitbce46f28de392862d5c6c3b185d844ee7c623be3 (patch)
tree424878b5b90144f98970ce4a2745990c77330ad2 /contrib/tools/python3/Modules/_sqlite
parent0e0ee9fa48ce9411b4038aa769493d22ff6c10a2 (diff)
Import Python 3.13.11
commit_hash:bbb53cefb159aa3e7afaa475fd19d5a03b66945f
Diffstat (limited to 'contrib/tools/python3/Modules/_sqlite')
-rw-r--r--contrib/tools/python3/Modules/_sqlite/blob.c27
-rw-r--r--contrib/tools/python3/Modules/_sqlite/clinic/_sqlite3.connect.c.h31
-rw-r--r--contrib/tools/python3/Modules/_sqlite/clinic/blob.c.h18
-rw-r--r--contrib/tools/python3/Modules/_sqlite/clinic/connection.c.h283
-rw-r--r--contrib/tools/python3/Modules/_sqlite/clinic/cursor.c.h64
-rw-r--r--contrib/tools/python3/Modules/_sqlite/clinic/module.c.h13
-rw-r--r--contrib/tools/python3/Modules/_sqlite/clinic/row.c.h8
-rw-r--r--contrib/tools/python3/Modules/_sqlite/connection.c252
-rw-r--r--contrib/tools/python3/Modules/_sqlite/connection.h1
-rw-r--r--contrib/tools/python3/Modules/_sqlite/cursor.c145
-rw-r--r--contrib/tools/python3/Modules/_sqlite/cursor.h3
-rw-r--r--contrib/tools/python3/Modules/_sqlite/microprotocols.c13
-rw-r--r--contrib/tools/python3/Modules/_sqlite/microprotocols.h1
-rw-r--r--contrib/tools/python3/Modules/_sqlite/module.c90
-rw-r--r--contrib/tools/python3/Modules/_sqlite/module.h1
-rw-r--r--contrib/tools/python3/Modules/_sqlite/row.c4
-rw-r--r--contrib/tools/python3/Modules/_sqlite/row.h1
-rw-r--r--contrib/tools/python3/Modules/_sqlite/statement.h1
-rw-r--r--contrib/tools/python3/Modules/_sqlite/util.c7
-rw-r--r--contrib/tools/python3/Modules/_sqlite/util.h1
-rw-r--r--contrib/tools/python3/Modules/_sqlite/ya.make4
21 files changed, 621 insertions, 347 deletions
diff --git a/contrib/tools/python3/Modules/_sqlite/blob.c b/contrib/tools/python3/Modules/_sqlite/blob.c
index 76d261baf00..6ad3f9c0968 100644
--- a/contrib/tools/python3/Modules/_sqlite/blob.c
+++ b/contrib/tools/python3/Modules/_sqlite/blob.c
@@ -1,5 +1,10 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
#include "blob.h"
#include "util.h"
+#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
#define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
#include "clinic/blob.c.h"
@@ -47,9 +52,7 @@ blob_dealloc(pysqlite_Blob *self)
close_blob(self);
- if (self->in_weakreflist != NULL) {
- PyObject_ClearWeakRefs((PyObject*)self);
- }
+ FT_CLEAR_WEAKREFS((PyObject*)self, self->in_weakreflist);
tp->tp_clear((PyObject *)self);
tp->tp_free(self);
Py_DECREF(tp);
@@ -97,10 +100,12 @@ pysqlite_close_all_blobs(pysqlite_Connection *self)
{
for (int i = 0; i < PyList_GET_SIZE(self->blobs); i++) {
PyObject *weakref = PyList_GET_ITEM(self->blobs, i);
- PyObject *blob = PyWeakref_GetObject(weakref);
- if (!Py_IsNone(blob)) {
- close_blob((pysqlite_Blob *)blob);
+ PyObject *blob;
+ if (!PyWeakref_GetRef(weakref, &blob)) {
+ continue;
}
+ close_blob((pysqlite_Blob *)blob);
+ Py_DECREF(blob);
}
}
@@ -108,14 +113,6 @@ static void
blob_seterror(pysqlite_Blob *self, int rc)
{
assert(self->connection != NULL);
-#if SQLITE_VERSION_NUMBER < 3008008
- // SQLite pre 3.8.8 does not set this blob error on the connection
- if (rc == SQLITE_ABORT) {
- PyErr_SetString(self->connection->OperationalError,
- "Cannot operate on an expired blob handle");
- return;
- }
-#endif
_pysqlite_seterror(self->connection->state, self->connection->db);
}
@@ -578,7 +575,7 @@ static PyMethodDef blob_methods[] = {
};
static struct PyMemberDef blob_members[] = {
- {"__weaklistoffset__", T_PYSSIZET, offsetof(pysqlite_Blob, in_weakreflist), READONLY},
+ {"__weaklistoffset__", Py_T_PYSSIZET, offsetof(pysqlite_Blob, in_weakreflist), Py_READONLY},
{NULL},
};
diff --git a/contrib/tools/python3/Modules/_sqlite/clinic/_sqlite3.connect.c.h b/contrib/tools/python3/Modules/_sqlite/clinic/_sqlite3.connect.c.h
new file mode 100644
index 00000000000..1bcda7702c2
--- /dev/null
+++ b/contrib/tools/python3/Modules/_sqlite/clinic/_sqlite3.connect.c.h
@@ -0,0 +1,31 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
+#endif
+#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
+
+PyDoc_STRVAR(pysqlite_connect__doc__,
+"connect($module, /, database, timeout=5.0, detect_types=0,\n"
+" isolation_level=\'\', check_same_thread=True,\n"
+" factory=ConnectionType, cached_statements=128, uri=False, *,\n"
+" autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)\n"
+"--\n"
+"\n"
+"Open a connection to the SQLite database file \'database\'.\n"
+"\n"
+"You can use \":memory:\" to open a database connection to a database that\n"
+"resides in RAM instead of on disk.\n"
+"\n"
+"Note: Passing more than 1 positional argument to _sqlite3.connect() is\n"
+"deprecated. Parameters \'timeout\', \'detect_types\', \'isolation_level\',\n"
+"\'check_same_thread\', \'factory\', \'cached_statements\' and \'uri\' will\n"
+"become keyword-only parameters in Python 3.15.\n"
+"");
+
+#define PYSQLITE_CONNECT_METHODDEF \
+ {"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__},
+/*[clinic end generated code: output=69b9b00da71c3c0a input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Modules/_sqlite/clinic/blob.c.h b/contrib/tools/python3/Modules/_sqlite/clinic/blob.c.h
index f3d8a35be46..b95ba948aaf 100644
--- a/contrib/tools/python3/Modules/_sqlite/clinic/blob.c.h
+++ b/contrib/tools/python3/Modules/_sqlite/clinic/blob.c.h
@@ -2,11 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
+#include "pycore_modsupport.h" // _PyArg_CheckPositional()
PyDoc_STRVAR(blob_close__doc__,
"close($self, /)\n"
@@ -57,7 +53,7 @@ blob_read(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
if (nargs < 1) {
goto skip_optional;
}
- length = _PyLong_AsInt(args[0]);
+ length = PyLong_AsInt(args[0]);
if (length == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -92,10 +88,6 @@ blob_write(pysqlite_Blob *self, PyObject *arg)
if (PyObject_GetBuffer(arg, &data, PyBUF_SIMPLE) != 0) {
goto exit;
}
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
- goto exit;
- }
return_value = blob_write_impl(self, &data);
exit:
@@ -133,14 +125,14 @@ blob_seek(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
goto exit;
}
- offset = _PyLong_AsInt(args[0]);
+ offset = PyLong_AsInt(args[0]);
if (offset == -1 && PyErr_Occurred()) {
goto exit;
}
if (nargs < 2) {
goto skip_optional;
}
- origin = _PyLong_AsInt(args[1]);
+ origin = PyLong_AsInt(args[1]);
if (origin == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -219,4 +211,4 @@ blob_exit(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=ad6a402f70e85977 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=31abd55660e0c5af input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Modules/_sqlite/clinic/connection.c.h b/contrib/tools/python3/Modules/_sqlite/clinic/connection.c.h
index 93e4a0f3282..c44b761aca6 100644
--- a/contrib/tools/python3/Modules/_sqlite/clinic/connection.c.h
+++ b/contrib/tools/python3/Modules/_sqlite/clinic/connection.c.h
@@ -3,10 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
+#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
static int
pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
@@ -16,6 +16,17 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
int cache_size, int uri,
enum autocommit_mode autocommit);
+// Emit compiler warnings when we get to Python 3.15.
+#if PY_VERSION_HEX >= 0x030f00C0
+# error "Update the clinic input of '_sqlite3.Connection.__init__'."
+#elif PY_VERSION_HEX >= 0x030f00A0
+# ifdef _MSC_VER
+# pragma message ("Update the clinic input of '_sqlite3.Connection.__init__'.")
+# else
+# warning "Update the clinic input of '_sqlite3.Connection.__init__'."
+# endif
+#endif
+
static int
pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
{
@@ -59,6 +70,17 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
int uri = 0;
enum autocommit_mode autocommit = LEGACY_TRANSACTION_CONTROL;
+ if (nargs > 1 && nargs <= 8) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing more than 1 positional argument to _sqlite3.Connection()"
+ " is deprecated. Parameters 'timeout', 'detect_types', "
+ "'isolation_level', 'check_same_thread', 'factory', "
+ "'cached_statements' and 'uri' will become keyword-only "
+ "parameters in Python 3.15.", 1))
+ {
+ goto exit;
+ }
+ }
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 8, 0, argsbuf);
if (!fastargs) {
goto exit;
@@ -83,7 +105,7 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
if (fastargs[2]) {
- detect_types = _PyLong_AsInt(fastargs[2]);
+ detect_types = PyLong_AsInt(fastargs[2]);
if (detect_types == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -115,7 +137,7 @@ pysqlite_connection_init(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
if (fastargs[6]) {
- cache_size = _PyLong_AsInt(fastargs[6]);
+ cache_size = PyLong_AsInt(fastargs[6]);
if (cache_size == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -207,7 +229,7 @@ exit:
}
PyDoc_STRVAR(blobopen__doc__,
-"blobopen($self, table, column, row, /, *, readonly=False, name=\'main\')\n"
+"blobopen($self, table, column, rowid, /, *, readonly=False, name=\'main\')\n"
"--\n"
"\n"
"Open and return a BLOB object.\n"
@@ -216,8 +238,8 @@ PyDoc_STRVAR(blobopen__doc__,
" Table name.\n"
" column\n"
" Column name.\n"
-" row\n"
-" Row index.\n"
+" rowid\n"
+" Row id.\n"
" readonly\n"
" Open the BLOB without write permissions.\n"
" name\n"
@@ -396,7 +418,12 @@ PyDoc_STRVAR(pysqlite_connection_create_function__doc__,
"create_function($self, /, name, narg, func, *, deterministic=False)\n"
"--\n"
"\n"
-"Creates a new function.");
+"Creates a new function.\n"
+"\n"
+"Note: Passing keyword arguments \'name\', \'narg\' and \'func\' to\n"
+"_sqlite3.Connection.create_function() is deprecated. Parameters\n"
+"\'name\', \'narg\' and \'func\' will become positional-only in Python 3.15.\n"
+"");
#define PYSQLITE_CONNECTION_CREATE_FUNCTION_METHODDEF \
{"create_function", _PyCFunction_CAST(pysqlite_connection_create_function), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_function__doc__},
@@ -407,6 +434,17 @@ pysqlite_connection_create_function_impl(pysqlite_Connection *self,
int narg, PyObject *func,
int deterministic);
+// Emit compiler warnings when we get to Python 3.15.
+#if PY_VERSION_HEX >= 0x030f00C0
+# error "Update the clinic input of '_sqlite3.Connection.create_function'."
+#elif PY_VERSION_HEX >= 0x030f00A0
+# ifdef _MSC_VER
+# pragma message ("Update the clinic input of '_sqlite3.Connection.create_function'.")
+# else
+# warning "Update the clinic input of '_sqlite3.Connection.create_function'."
+# endif
+#endif
+
static PyObject *
pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
@@ -447,6 +485,16 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls
if (!args) {
goto exit;
}
+ if (nargs < 3) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing keyword arguments 'name', 'narg' and 'func' to "
+ "_sqlite3.Connection.create_function() is deprecated. Parameters "
+ "'name', 'narg' and 'func' will become positional-only in Python "
+ "3.15.", 1))
+ {
+ goto exit;
+ }
+ }
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("create_function", "argument 'name'", "str", args[0]);
goto exit;
@@ -460,7 +508,7 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- narg = _PyLong_AsInt(args[1]);
+ narg = PyLong_AsInt(args[1]);
if (narg == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -543,7 +591,7 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- num_params = _PyLong_AsInt(args[1]);
+ num_params = PyLong_AsInt(args[1]);
if (num_params == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -560,7 +608,13 @@ PyDoc_STRVAR(pysqlite_connection_create_aggregate__doc__,
"create_aggregate($self, /, name, n_arg, aggregate_class)\n"
"--\n"
"\n"
-"Creates a new aggregate.");
+"Creates a new aggregate.\n"
+"\n"
+"Note: Passing keyword arguments \'name\', \'n_arg\' and \'aggregate_class\'\n"
+"to _sqlite3.Connection.create_aggregate() is deprecated. Parameters\n"
+"\'name\', \'n_arg\' and \'aggregate_class\' will become positional-only in\n"
+"Python 3.15.\n"
+"");
#define PYSQLITE_CONNECTION_CREATE_AGGREGATE_METHODDEF \
{"create_aggregate", _PyCFunction_CAST(pysqlite_connection_create_aggregate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_create_aggregate__doc__},
@@ -571,6 +625,17 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
const char *name, int n_arg,
PyObject *aggregate_class);
+// Emit compiler warnings when we get to Python 3.15.
+#if PY_VERSION_HEX >= 0x030f00C0
+# error "Update the clinic input of '_sqlite3.Connection.create_aggregate'."
+#elif PY_VERSION_HEX >= 0x030f00A0
+# ifdef _MSC_VER
+# pragma message ("Update the clinic input of '_sqlite3.Connection.create_aggregate'.")
+# else
+# warning "Update the clinic input of '_sqlite3.Connection.create_aggregate'."
+# endif
+#endif
+
static PyObject *
pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
@@ -609,6 +674,16 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl
if (!args) {
goto exit;
}
+ if (nargs < 3) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing keyword arguments 'name', 'n_arg' and 'aggregate_class' "
+ "to _sqlite3.Connection.create_aggregate() is deprecated. "
+ "Parameters 'name', 'n_arg' and 'aggregate_class' will become "
+ "positional-only in Python 3.15.", 1))
+ {
+ goto exit;
+ }
+ }
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("create_aggregate", "argument 'name'", "str", args[0]);
goto exit;
@@ -622,7 +697,7 @@ pysqlite_connection_create_aggregate(pysqlite_Connection *self, PyTypeObject *cl
PyErr_SetString(PyExc_ValueError, "embedded null character");
goto exit;
}
- n_arg = _PyLong_AsInt(args[1]);
+ n_arg = PyLong_AsInt(args[1]);
if (n_arg == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -637,7 +712,12 @@ PyDoc_STRVAR(pysqlite_connection_set_authorizer__doc__,
"set_authorizer($self, /, authorizer_callback)\n"
"--\n"
"\n"
-"Sets authorizer callback.");
+"Set authorizer callback.\n"
+"\n"
+"Note: Passing keyword argument \'authorizer_callback\' to\n"
+"_sqlite3.Connection.set_authorizer() is deprecated. Parameter\n"
+"\'authorizer_callback\' will become positional-only in Python 3.15.\n"
+"");
#define PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF \
{"set_authorizer", _PyCFunction_CAST(pysqlite_connection_set_authorizer), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_authorizer__doc__},
@@ -647,6 +727,17 @@ pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
PyTypeObject *cls,
PyObject *callable);
+// Emit compiler warnings when we get to Python 3.15.
+#if PY_VERSION_HEX >= 0x030f00C0
+# error "Update the clinic input of '_sqlite3.Connection.set_authorizer'."
+#elif PY_VERSION_HEX >= 0x030f00A0
+# ifdef _MSC_VER
+# pragma message ("Update the clinic input of '_sqlite3.Connection.set_authorizer'.")
+# else
+# warning "Update the clinic input of '_sqlite3.Connection.set_authorizer'."
+# endif
+#endif
+
static PyObject *
pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
@@ -683,6 +774,16 @@ pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls,
if (!args) {
goto exit;
}
+ if (nargs < 1) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing keyword argument 'authorizer_callback' to "
+ "_sqlite3.Connection.set_authorizer() is deprecated. Parameter "
+ "'authorizer_callback' will become positional-only in Python "
+ "3.15.", 1))
+ {
+ goto exit;
+ }
+ }
callable = args[0];
return_value = pysqlite_connection_set_authorizer_impl(self, cls, callable);
@@ -694,7 +795,22 @@ PyDoc_STRVAR(pysqlite_connection_set_progress_handler__doc__,
"set_progress_handler($self, /, progress_handler, n)\n"
"--\n"
"\n"
-"Sets progress handler callback.");
+"Set progress handler callback.\n"
+"\n"
+" progress_handler\n"
+" A callable that takes no arguments.\n"
+" If the callable returns non-zero, the current query is terminated,\n"
+" and an exception is raised.\n"
+" n\n"
+" The number of SQLite virtual machine instructions that are\n"
+" executed between invocations of \'progress_handler\'.\n"
+"\n"
+"If \'progress_handler\' is None or \'n\' is 0, the progress handler is disabled.\n"
+"\n"
+"Note: Passing keyword argument \'progress_handler\' to\n"
+"_sqlite3.Connection.set_progress_handler() is deprecated. Parameter\n"
+"\'progress_handler\' will become positional-only in Python 3.15.\n"
+"");
#define PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF \
{"set_progress_handler", _PyCFunction_CAST(pysqlite_connection_set_progress_handler), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_progress_handler__doc__},
@@ -704,6 +820,17 @@ pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
PyTypeObject *cls,
PyObject *callable, int n);
+// Emit compiler warnings when we get to Python 3.15.
+#if PY_VERSION_HEX >= 0x030f00C0
+# error "Update the clinic input of '_sqlite3.Connection.set_progress_handler'."
+#elif PY_VERSION_HEX >= 0x030f00A0
+# ifdef _MSC_VER
+# pragma message ("Update the clinic input of '_sqlite3.Connection.set_progress_handler'.")
+# else
+# warning "Update the clinic input of '_sqlite3.Connection.set_progress_handler'."
+# endif
+#endif
+
static PyObject *
pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
@@ -741,8 +868,18 @@ pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject
if (!args) {
goto exit;
}
+ if (nargs < 1) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing keyword argument 'progress_handler' to "
+ "_sqlite3.Connection.set_progress_handler() is deprecated. "
+ "Parameter 'progress_handler' will become positional-only in "
+ "Python 3.15.", 1))
+ {
+ goto exit;
+ }
+ }
callable = args[0];
- n = _PyLong_AsInt(args[1]);
+ n = PyLong_AsInt(args[1]);
if (n == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -756,7 +893,12 @@ 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).");
+"Set a trace callback called for each SQL statement (passed as unicode).\n"
+"\n"
+"Note: Passing keyword argument \'trace_callback\' to\n"
+"_sqlite3.Connection.set_trace_callback() is deprecated. Parameter\n"
+"\'trace_callback\' will become positional-only in Python 3.15.\n"
+"");
#define PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF \
{"set_trace_callback", _PyCFunction_CAST(pysqlite_connection_set_trace_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_set_trace_callback__doc__},
@@ -766,6 +908,17 @@ pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
PyTypeObject *cls,
PyObject *callable);
+// Emit compiler warnings when we get to Python 3.15.
+#if PY_VERSION_HEX >= 0x030f00C0
+# error "Update the clinic input of '_sqlite3.Connection.set_trace_callback'."
+#elif PY_VERSION_HEX >= 0x030f00A0
+# ifdef _MSC_VER
+# pragma message ("Update the clinic input of '_sqlite3.Connection.set_trace_callback'.")
+# else
+# warning "Update the clinic input of '_sqlite3.Connection.set_trace_callback'."
+# endif
+#endif
+
static PyObject *
pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
@@ -802,6 +955,16 @@ pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject *
if (!args) {
goto exit;
}
+ if (nargs < 1) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing keyword argument 'trace_callback' to "
+ "_sqlite3.Connection.set_trace_callback() is deprecated. "
+ "Parameter 'trace_callback' will become positional-only in Python"
+ " 3.15.", 1))
+ {
+ goto exit;
+ }
+ }
callable = args[0];
return_value = pysqlite_connection_set_trace_callback_impl(self, cls, callable);
@@ -966,9 +1129,6 @@ pysqlite_connection_execute(pysqlite_Connection *self, PyObject *const *args, Py
_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;
@@ -1008,9 +1168,6 @@ pysqlite_connection_executemany(pysqlite_Connection *self, PyObject *const *args
_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);
@@ -1047,21 +1204,67 @@ pysqlite_connection_interrupt(pysqlite_Connection *self, PyObject *Py_UNUSED(ign
}
PyDoc_STRVAR(pysqlite_connection_iterdump__doc__,
-"iterdump($self, /)\n"
+"iterdump($self, /, *, filter=None)\n"
"--\n"
"\n"
-"Returns iterator to the dump of the database in an SQL text format.");
+"Returns iterator to the dump of the database in an SQL text format.\n"
+"\n"
+" filter\n"
+" An optional LIKE pattern for database objects to dump");
#define PYSQLITE_CONNECTION_ITERDUMP_METHODDEF \
- {"iterdump", (PyCFunction)pysqlite_connection_iterdump, METH_NOARGS, pysqlite_connection_iterdump__doc__},
+ {"iterdump", _PyCFunction_CAST(pysqlite_connection_iterdump), METH_FASTCALL|METH_KEYWORDS, pysqlite_connection_iterdump__doc__},
static PyObject *
-pysqlite_connection_iterdump_impl(pysqlite_Connection *self);
+pysqlite_connection_iterdump_impl(pysqlite_Connection *self,
+ PyObject *filter);
static PyObject *
-pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
+pysqlite_connection_iterdump(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
- return pysqlite_connection_iterdump_impl(self);
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 1
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(filter), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"filter", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "iterdump",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[1];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
+ PyObject *filter = Py_None;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_kwonly;
+ }
+ filter = args[0];
+skip_optional_kwonly:
+ return_value = pysqlite_connection_iterdump_impl(self, filter);
+
+exit:
+ return return_value;
}
PyDoc_STRVAR(pysqlite_connection_backup__doc__,
@@ -1130,7 +1333,7 @@ pysqlite_connection_backup(pysqlite_Connection *self, PyObject *const *args, Py_
goto skip_optional_kwonly;
}
if (args[1]) {
- pages = _PyLong_AsInt(args[1]);
+ pages = PyLong_AsInt(args[1]);
if (pages == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -1394,16 +1597,14 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
if (ptr == NULL) {
goto exit;
}
- PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
+ if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) {
+ goto exit;
+ }
}
else { /* any bytes-like object */
if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
goto exit;
}
- if (!PyBuffer_IsContiguous(&data, 'C')) {
- _PyArg_BadArgument("deserialize", "argument 1", "contiguous buffer", args[0]);
- goto exit;
- }
}
if (!noptargs) {
goto skip_optional_kwonly;
@@ -1522,11 +1723,11 @@ setlimit(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
if (!_PyArg_CheckPositional("setlimit", nargs, 2, 2)) {
goto exit;
}
- category = _PyLong_AsInt(args[0]);
+ category = PyLong_AsInt(args[0]);
if (category == -1 && PyErr_Occurred()) {
goto exit;
}
- limit = _PyLong_AsInt(args[1]);
+ limit = PyLong_AsInt(args[1]);
if (limit == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -1557,7 +1758,7 @@ getlimit(pysqlite_Connection *self, PyObject *arg)
PyObject *return_value = NULL;
int category;
- category = _PyLong_AsInt(arg);
+ category = PyLong_AsInt(arg);
if (category == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -1592,7 +1793,7 @@ setconfig(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs)
if (!_PyArg_CheckPositional("setconfig", nargs, 1, 2)) {
goto exit;
}
- op = _PyLong_AsInt(args[0]);
+ op = PyLong_AsInt(args[0]);
if (op == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -1632,7 +1833,7 @@ getconfig(pysqlite_Connection *self, PyObject *arg)
int op;
int _return_value;
- op = _PyLong_AsInt(arg);
+ op = PyLong_AsInt(arg);
if (op == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -1665,4 +1866,4 @@ exit:
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=305d580e3eaa622d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=fa34f4c5f8837a7c input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Modules/_sqlite/clinic/cursor.c.h b/contrib/tools/python3/Modules/_sqlite/clinic/cursor.c.h
index 43e912d1347..56b849dc0b6 100644
--- a/contrib/tools/python3/Modules/_sqlite/clinic/cursor.c.h
+++ b/contrib/tools/python3/Modules/_sqlite/clinic/cursor.c.h
@@ -3,10 +3,11 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
+#include "pycore_long.h" // _PyLong_Size_t_Converter()
+#include "pycore_modsupport.h" // _PyArg_CheckPositional()
static int
pysqlite_cursor_init_impl(pysqlite_Cursor *self,
@@ -65,9 +66,6 @@ pysqlite_cursor_execute(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t
_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;
@@ -107,9 +105,6 @@ pysqlite_cursor_executemany(pysqlite_Cursor *self, PyObject *const *args, Py_ssi
_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);
@@ -187,7 +182,7 @@ PyDoc_STRVAR(pysqlite_cursor_fetchmany__doc__,
{"fetchmany", _PyCFunction_CAST(pysqlite_cursor_fetchmany), METH_FASTCALL|METH_KEYWORDS, pysqlite_cursor_fetchmany__doc__},
static PyObject *
-pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows);
+pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, size_t maxrows);
static PyObject *
pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
@@ -220,7 +215,7 @@ pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize
#undef KWTUPLE
PyObject *argsbuf[1];
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
- int maxrows = self->arraysize;
+ size_t maxrows = ((pysqlite_Cursor *)self)->arraysize;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
if (!args) {
@@ -229,8 +224,7 @@ pysqlite_cursor_fetchmany(pysqlite_Cursor *self, PyObject *const *args, Py_ssize
if (!noptargs) {
goto skip_optional_pos;
}
- maxrows = _PyLong_AsInt(args[0]);
- if (maxrows == -1 && PyErr_Occurred()) {
+ if (!_PyLong_Size_t_Converter(args[0], &maxrows)) {
goto exit;
}
skip_optional_pos:
@@ -319,4 +313,46 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
{
return pysqlite_cursor_close_impl(self);
}
-/*[clinic end generated code: output=1f82e3c9791bb9a5 input=a9049054013a1b77]*/
+
+#if !defined(_sqlite3_Cursor_arraysize_DOCSTR)
+# define _sqlite3_Cursor_arraysize_DOCSTR NULL
+#endif
+#if defined(_SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF)
+# undef _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF
+# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, (setter)_sqlite3_Cursor_arraysize_set, _sqlite3_Cursor_arraysize_DOCSTR},
+#else
+# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, NULL, _sqlite3_Cursor_arraysize_DOCSTR},
+#endif
+
+static PyObject *
+_sqlite3_Cursor_arraysize_get_impl(pysqlite_Cursor *self);
+
+static PyObject *
+_sqlite3_Cursor_arraysize_get(pysqlite_Cursor *self, void *Py_UNUSED(context))
+{
+ return _sqlite3_Cursor_arraysize_get_impl(self);
+}
+
+#if !defined(_sqlite3_Cursor_arraysize_DOCSTR)
+# define _sqlite3_Cursor_arraysize_DOCSTR NULL
+#endif
+#if defined(_SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF)
+# undef _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF
+# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", (getter)_sqlite3_Cursor_arraysize_get, (setter)_sqlite3_Cursor_arraysize_set, _sqlite3_Cursor_arraysize_DOCSTR},
+#else
+# define _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF {"arraysize", NULL, (setter)_sqlite3_Cursor_arraysize_set, NULL},
+#endif
+
+static int
+_sqlite3_Cursor_arraysize_set_impl(pysqlite_Cursor *self, PyObject *value);
+
+static int
+_sqlite3_Cursor_arraysize_set(pysqlite_Cursor *self, PyObject *value, void *Py_UNUSED(context))
+{
+ int return_value;
+
+ return_value = _sqlite3_Cursor_arraysize_set_impl(self, value);
+
+ return return_value;
+}
+/*[clinic end generated code: output=332c298249ae57b0 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Modules/_sqlite/clinic/module.c.h b/contrib/tools/python3/Modules/_sqlite/clinic/module.c.h
index 12f60835880..529dc4e281e 100644
--- a/contrib/tools/python3/Modules/_sqlite/clinic/module.c.h
+++ b/contrib/tools/python3/Modules/_sqlite/clinic/module.c.h
@@ -3,10 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
+#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(pysqlite_complete_statement__doc__,
"complete_statement($module, /, statement)\n"
@@ -133,9 +133,6 @@ pysqlite_register_converter(PyObject *module, PyObject *const *args, Py_ssize_t
_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);
@@ -162,7 +159,7 @@ pysqlite_enable_callback_trace(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int enable;
- enable = _PyLong_AsInt(arg);
+ enable = PyLong_AsInt(arg);
if (enable == -1 && PyErr_Occurred()) {
goto exit;
}
@@ -211,4 +208,4 @@ skip_optional:
exit:
return return_value;
}
-/*[clinic end generated code: output=39d38c6cfc455042 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=457ab0fdbb9e1880 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Modules/_sqlite/clinic/row.c.h b/contrib/tools/python3/Modules/_sqlite/clinic/row.c.h
index 89a48fd52da..e8d1dbf2ba8 100644
--- a/contrib/tools/python3/Modules/_sqlite/clinic/row.c.h
+++ b/contrib/tools/python3/Modules/_sqlite/clinic/row.c.h
@@ -2,11 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
+#include "pycore_modsupport.h" // _PyArg_CheckPositional()
static PyObject *
pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,
@@ -60,4 +56,4 @@ pysqlite_row_keys(pysqlite_Row *self, PyObject *Py_UNUSED(ignored))
{
return pysqlite_row_keys_impl(self);
}
-/*[clinic end generated code: output=157b31ac3f6af1ba input=a9049054013a1b77]*/
+/*[clinic end generated code: output=788bf817acc02b8e input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Modules/_sqlite/connection.c b/contrib/tools/python3/Modules/_sqlite/connection.c
index 1450037ca95..a359fdc855c 100644
--- a/contrib/tools/python3/Modules/_sqlite/connection.c
+++ b/contrib/tools/python3/Modules/_sqlite/connection.c
@@ -21,8 +21,12 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
#include "module.h"
-#include "structmember.h" // PyMemberDef
+
#include "connection.h"
#include "statement.h"
#include "cursor.h"
@@ -30,11 +34,13 @@
#include "prepare_protocol.h"
#include "util.h"
-#include <stdbool.h>
+#include "pycore_import.h" // _PyImport_GetModuleAttrString()
+#include "pycore_modsupport.h" // _PyArg_NoKeywords()
+#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
+#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
+#include "pycore_weakref.h"
-#if SQLITE_VERSION_NUMBER >= 3014000
-#define HAVE_TRACE_V2
-#endif
+#include <stdbool.h>
#if SQLITE_VERSION_NUMBER >= 3025000
#define HAVE_WINDOW_FUNCTIONS
@@ -70,16 +76,10 @@ isolation_level_converter(PyObject *str_or_none, const char **result)
*result = NULL;
}
else if (PyUnicode_Check(str_or_none)) {
- Py_ssize_t sz;
- const char *str = PyUnicode_AsUTF8AndSize(str_or_none, &sz);
+ const char *str = _PyUnicode_AsUTF8NoNUL(str_or_none);
if (str == NULL) {
return 0;
}
- if (strlen(str) != (size_t)sz) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- return 0;
- }
-
const char *level = get_isolation_level(str);
if (level == NULL) {
return 0;
@@ -142,7 +142,7 @@ class _sqlite3.Connection "pysqlite_Connection *" "clinic_state()->ConnectionTyp
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=67369db2faf80891]*/
-static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
+static int _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self);
static void free_callback_context(callback_context *ctx);
static void set_callback_context(callback_context **ctx_pp,
callback_context *ctx);
@@ -209,11 +209,11 @@ class sqlite3_int64_converter(CConverter):
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=dff8760fb1eba6a1]*/
-// NB: This needs to be in sync with the sqlite3.connect docstring
/*[clinic input]
_sqlite3.Connection.__init__ as pysqlite_connection_init
database: object
+ * [from 3.15]
timeout: double = 5.0
detect_types: int = 0
isolation_level: IsolationLevel = ""
@@ -232,7 +232,7 @@ pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
int check_same_thread, PyObject *factory,
int cache_size, int uri,
enum autocommit_mode autocommit)
-/*[clinic end generated code: output=cba057313ea7712f input=9b0ab6c12f674fa3]*/
+/*[clinic end generated code: output=cba057313ea7712f input=219c3dbecbae7d99]*/
{
if (PySys_Audit("sqlite3.connect", "O", database) < 0) {
return -1;
@@ -348,6 +348,34 @@ error:
return -1;
}
+/*[clinic input]
+# Create a new destination 'connect' for the docstring and methoddef only.
+# This makes it possible to keep the signatures for Connection.__init__ and
+# sqlite3.connect() synchronised.
+output push
+destination connect new file '{dirname}/clinic/_sqlite3.connect.c.h'
+
+# Only output the docstring and the PyMethodDef entry.
+output everything suppress
+output docstring_definition connect
+output methoddef_define connect
+
+# Define the sqlite3.connect function by cloning Connection.__init__.
+_sqlite3.connect as pysqlite_connect = _sqlite3.Connection.__init__
+
+Open a connection to the SQLite database file 'database'.
+
+You can use ":memory:" to open a database connection to a database that
+resides in RAM instead of on disk.
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=92260edff95d1720]*/
+
+/*[clinic input]
+# Restore normal Argument Clinic operation for the rest of this file.
+output pop
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b899ba9273edcce7]*/
+
#define VISIT_CALLBACK_CONTEXT(ctx) \
do { \
if (ctx) { \
@@ -406,16 +434,11 @@ free_callback_contexts(pysqlite_Connection *self)
static void
remove_callbacks(sqlite3 *db)
{
- assert(db != NULL);
/* None of these APIs can fail, as long as they are given a valid
* database pointer. */
- int rc;
-#ifdef HAVE_TRACE_V2
- rc = sqlite3_trace_v2(db, SQLITE_TRACE_STMT, 0, 0);
+ assert(db != NULL);
+ int rc = sqlite3_trace_v2(db, SQLITE_TRACE_STMT, 0, 0);
assert(rc == SQLITE_OK), (void)rc;
-#else
- sqlite3_trace(db, 0, (void*)0);
-#endif
sqlite3_progress_handler(db, 0, 0, (void *)0);
@@ -467,6 +490,14 @@ connection_finalize(PyObject *self)
}
/* Clean up if user has not called .close() explicitly. */
+ if (con->db) {
+ if (PyErr_ResourceWarning(self, 1, "unclosed database in %R", self)) {
+ /* Spurious errors can appear at shutdown */
+ if (PyErr_ExceptionMatches(PyExc_Warning)) {
+ PyErr_WriteUnraisable(self);
+ }
+ }
+ }
if (connection_close(con) < 0) {
if (teardown) {
PyErr_Clear();
@@ -525,7 +556,10 @@ pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
return NULL;
}
- _pysqlite_drop_unused_cursor_references(self);
+ if (_pysqlite_drop_unused_cursor_references(self) < 0) {
+ Py_DECREF(cursor);
+ return NULL;
+ }
if (cursor && self->row_factory != Py_None) {
Py_INCREF(self->row_factory);
@@ -542,8 +576,8 @@ _sqlite3.Connection.blobopen as blobopen
Table name.
column as col: str
Column name.
- row: sqlite3_int64
- Row index.
+ rowid as row: sqlite3_int64
+ Row id.
/
*
readonly: bool = False
@@ -557,7 +591,7 @@ Open and return a BLOB object.
static PyObject *
blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
sqlite3_int64 row, int readonly, const char *name)
-/*[clinic end generated code: output=6a02d43efb885d1c input=23576bd1108d8774]*/
+/*[clinic end generated code: output=6a02d43efb885d1c input=cc3d4b47dac08401]*/
{
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
@@ -1023,35 +1057,36 @@ error:
PyGILState_Release(threadstate);
}
-static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
+static int
+_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;
+ return 0;
}
self->created_cursors = 0;
- new_list = PyList_New(0);
+ PyObject* new_list = PyList_New(0);
if (!new_list) {
- return;
+ return -1;
}
- 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;
- }
+ assert(PyList_CheckExact(self->cursors));
+ Py_ssize_t imax = PyList_GET_SIZE(self->cursors);
+ for (Py_ssize_t i = 0; i < imax; i++) {
+ PyObject* weakref = PyList_GET_ITEM(self->cursors, i);
+ if (_PyWeakref_IsDead(weakref)) {
+ continue;
+ }
+ if (PyList_Append(new_list, weakref) != 0) {
+ Py_DECREF(new_list);
+ return -1;
}
}
Py_SETREF(self->cursors, new_list);
+ return 0;
}
/* Allocate a UDF/callback context structure. In order to ensure that the state
@@ -1113,6 +1148,7 @@ _sqlite3.Connection.create_function as pysqlite_connection_create_function
name: str
narg: int
func: object
+ / [from 3.15]
*
deterministic: bool = False
@@ -1124,7 +1160,7 @@ pysqlite_connection_create_function_impl(pysqlite_Connection *self,
PyTypeObject *cls, const char *name,
int narg, PyObject *func,
int deterministic)
-/*[clinic end generated code: output=8a811529287ad240 input=b3e8e1d8ddaffbef]*/
+/*[clinic end generated code: output=8a811529287ad240 input=c7c313b0ca8b519e]*/
{
int rc;
int flags = SQLITE_UTF8;
@@ -1134,18 +1170,7 @@ pysqlite_connection_create_function_impl(pysqlite_Connection *self,
}
if (deterministic) {
-#if SQLITE_VERSION_NUMBER < 3008003
- PyErr_SetString(self->NotSupportedError,
- "deterministic=True requires SQLite 3.8.3 or higher");
- return NULL;
-#else
- if (sqlite3_libversion_number() < 3008003) {
- PyErr_SetString(self->NotSupportedError,
- "deterministic=True requires SQLite 3.8.3 or higher");
- return NULL;
- }
flags |= SQLITE_DETERMINISTIC;
-#endif
}
callback_context *ctx = create_callback_context(cls, func);
if (ctx == NULL) {
@@ -1326,6 +1351,7 @@ _sqlite3.Connection.create_aggregate as pysqlite_connection_create_aggregate
name: str
n_arg: int
aggregate_class: object
+ / [from 3.15]
Creates a new aggregate.
[clinic start generated code]*/
@@ -1335,7 +1361,7 @@ pysqlite_connection_create_aggregate_impl(pysqlite_Connection *self,
PyTypeObject *cls,
const char *name, int n_arg,
PyObject *aggregate_class)
-/*[clinic end generated code: output=1b02d0f0aec7ff96 input=68a2a26366d4c686]*/
+/*[clinic end generated code: output=1b02d0f0aec7ff96 input=8087056db6eae1cf]*/
{
int rc;
@@ -1381,7 +1407,7 @@ authorizer_callback(void *ctx, int action, const char *arg1,
}
else {
if (PyLong_Check(ret)) {
- rc = _PyLong_AsInt(ret);
+ rc = PyLong_AsInt(ret);
if (rc == -1 && PyErr_Occurred()) {
print_or_clear_traceback(ctx);
rc = SQLITE_DENY;
@@ -1424,7 +1450,6 @@ progress_callback(void *ctx)
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
@@ -1433,16 +1458,10 @@ progress_callback(void *ctx)
*/
static int
trace_callback(unsigned int type, void *ctx, void *stmt, void *sql)
-#else
-static void
-trace_callback(void *ctx, const char *sql)
-#endif
{
-#ifdef HAVE_TRACE_V2
if (type != SQLITE_TRACE_STMT) {
return 0;
}
-#endif
PyGILState_STATE gilstate = PyGILState_Ensure();
@@ -1451,7 +1470,6 @@ trace_callback(void *ctx, const char *sql)
assert(state != NULL);
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);
@@ -1471,15 +1489,6 @@ trace_callback(void *ctx, const char *sql)
py_statement = PyUnicode_FromString(expanded_sql);
sqlite3_free((void *)expanded_sql);
}
-#else
- if (sql == NULL) {
- PyErr_SetString(state->DataError,
- "Expanded SQL string exceeds the maximum string length");
- print_or_clear_traceback((callback_context *)ctx);
- goto exit;
- }
- py_statement = PyUnicode_FromString(sql);
-#endif
if (py_statement) {
PyObject *callable = ((callback_context *)ctx)->callable;
PyObject *ret = PyObject_CallOneArg(callable, py_statement);
@@ -1492,26 +1501,24 @@ trace_callback(void *ctx, const char *sql)
exit:
PyGILState_Release(gilstate);
-#ifdef HAVE_TRACE_V2
return 0;
-#endif
}
/*[clinic input]
_sqlite3.Connection.set_authorizer as pysqlite_connection_set_authorizer
cls: defining_class
- /
authorizer_callback as callable: object
+ / [from 3.15]
-Sets authorizer callback.
+Set authorizer callback.
[clinic start generated code]*/
static PyObject *
pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
PyTypeObject *cls,
PyObject *callable)
-/*[clinic end generated code: output=75fa60114fc971c3 input=605d32ba92dd3eca]*/
+/*[clinic end generated code: output=75fa60114fc971c3 input=a52bd4937c588752]*/
{
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
@@ -1543,18 +1550,25 @@ pysqlite_connection_set_authorizer_impl(pysqlite_Connection *self,
_sqlite3.Connection.set_progress_handler as pysqlite_connection_set_progress_handler
cls: defining_class
- /
progress_handler as callable: object
+ A callable that takes no arguments.
+ If the callable returns non-zero, the current query is terminated,
+ and an exception is raised.
+ / [from 3.15]
n: int
+ The number of SQLite virtual machine instructions that are
+ executed between invocations of 'progress_handler'.
-Sets progress handler callback.
+Set progress handler callback.
+
+If 'progress_handler' is None or 'n' is 0, the progress handler is disabled.
[clinic start generated code]*/
static PyObject *
pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
PyTypeObject *cls,
PyObject *callable, int n)
-/*[clinic end generated code: output=0739957fd8034a50 input=f7c1837984bd86db]*/
+/*[clinic end generated code: output=0739957fd8034a50 input=b4d6e2ef8b4d32f9]*/
{
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
@@ -1580,17 +1594,17 @@ pysqlite_connection_set_progress_handler_impl(pysqlite_Connection *self,
_sqlite3.Connection.set_trace_callback as pysqlite_connection_set_trace_callback
cls: defining_class
- /
trace_callback as callable: object
+ / [from 3.15]
-Sets a trace callback called for each SQL statement (passed as unicode).
+Set 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,
PyTypeObject *cls,
PyObject *callable)
-/*[clinic end generated code: output=d91048c03bfcee05 input=351a94210c5f81bb]*/
+/*[clinic end generated code: output=d91048c03bfcee05 input=d705d592ec03cf28]*/
{
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
@@ -1604,11 +1618,7 @@ pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
* - 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
set_callback_context(&self->trace_ctx, NULL);
}
else {
@@ -1616,11 +1626,7 @@ pysqlite_connection_set_trace_callback_impl(pysqlite_Connection *self,
if (ctx == NULL) {
return NULL;
}
-#ifdef HAVE_TRACE_V2
sqlite3_trace_v2(self->db, SQLITE_TRACE_STMT, trace_callback, ctx);
-#else
- sqlite3_trace(self->db, trace_callback, ctx);
-#endif
set_callback_context(&self->trace_ctx, ctx);
}
@@ -1985,12 +1991,17 @@ finally:
/*[clinic input]
_sqlite3.Connection.iterdump as pysqlite_connection_iterdump
+ *
+ filter: object = None
+ An optional LIKE pattern for database objects to dump
+
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]*/
+pysqlite_connection_iterdump_impl(pysqlite_Connection *self,
+ PyObject *filter)
+/*[clinic end generated code: output=fd81069c4bdeb6b0 input=4ae6d9a898f108df]*/
{
if (!pysqlite_check_connection(self)) {
return NULL;
@@ -2004,9 +2015,16 @@ pysqlite_connection_iterdump_impl(pysqlite_Connection *self)
}
return NULL;
}
-
- PyObject *retval = PyObject_CallOneArg(iterdump, (PyObject *)self);
+ PyObject *args[3] = {NULL, (PyObject *)self, filter};
+ PyObject *kwnames = Py_BuildValue("(s)", "filter");
+ if (!kwnames) {
+ Py_DECREF(iterdump);
+ return NULL;
+ }
+ Py_ssize_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
+ PyObject *retval = PyObject_Vectorcall(iterdump, args + 1, nargsf, kwnames);
Py_DECREF(iterdump);
+ Py_DECREF(kwnames);
return retval;
}
@@ -2048,15 +2066,6 @@ pysqlite_connection_backup_impl(pysqlite_Connection *self,
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(self->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;
@@ -2419,12 +2428,8 @@ is_int_config(const int op)
switch (op) {
case SQLITE_DBCONFIG_ENABLE_FKEY:
case SQLITE_DBCONFIG_ENABLE_TRIGGER:
-#if SQLITE_VERSION_NUMBER >= 3012002
case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
-#endif
-#if SQLITE_VERSION_NUMBER >= 3013000
case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
-#endif
#if SQLITE_VERSION_NUMBER >= 3016000
case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
#endif
@@ -2568,6 +2573,12 @@ set_autocommit(pysqlite_Connection *self, PyObject *val, void *Py_UNUSED(ctx))
return 0;
}
+static PyObject *
+get_sig(PyObject *self, void *Py_UNUSED(ctx))
+{
+ return PyUnicode_FromString("(sql, /)");
+}
+
static const char connection_doc[] =
PyDoc_STR("SQLite database connection object.");
@@ -2577,6 +2588,7 @@ static PyGetSetDef connection_getset[] = {
{"total_changes", (getter)pysqlite_connection_get_total_changes, (setter)0},
{"in_transaction", (getter)pysqlite_connection_get_in_transaction, (setter)0},
{"autocommit", (getter)get_autocommit, (setter)set_autocommit},
+ {"__text_signature__", get_sig, (setter)0},
{NULL}
};
@@ -2614,18 +2626,18 @@ static PyMethodDef connection_methods[] = {
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)},
+ {"Warning", _Py_T_OBJECT, offsetof(pysqlite_Connection, Warning), Py_READONLY},
+ {"Error", _Py_T_OBJECT, offsetof(pysqlite_Connection, Error), Py_READONLY},
+ {"InterfaceError", _Py_T_OBJECT, offsetof(pysqlite_Connection, InterfaceError), Py_READONLY},
+ {"DatabaseError", _Py_T_OBJECT, offsetof(pysqlite_Connection, DatabaseError), Py_READONLY},
+ {"DataError", _Py_T_OBJECT, offsetof(pysqlite_Connection, DataError), Py_READONLY},
+ {"OperationalError", _Py_T_OBJECT, offsetof(pysqlite_Connection, OperationalError), Py_READONLY},
+ {"IntegrityError", _Py_T_OBJECT, offsetof(pysqlite_Connection, IntegrityError), Py_READONLY},
+ {"InternalError", _Py_T_OBJECT, offsetof(pysqlite_Connection, InternalError), Py_READONLY},
+ {"ProgrammingError", _Py_T_OBJECT, offsetof(pysqlite_Connection, ProgrammingError), Py_READONLY},
+ {"NotSupportedError", _Py_T_OBJECT, offsetof(pysqlite_Connection, NotSupportedError), Py_READONLY},
+ {"row_factory", _Py_T_OBJECT, offsetof(pysqlite_Connection, row_factory)},
+ {"text_factory", _Py_T_OBJECT, offsetof(pysqlite_Connection, text_factory)},
{NULL}
};
diff --git a/contrib/tools/python3/Modules/_sqlite/connection.h b/contrib/tools/python3/Modules/_sqlite/connection.h
index 1df92065a58..7a748ee3ea0 100644
--- a/contrib/tools/python3/Modules/_sqlite/connection.h
+++ b/contrib/tools/python3/Modules/_sqlite/connection.h
@@ -23,7 +23,6 @@
#ifndef PYSQLITE_CONNECTION_H
#define PYSQLITE_CONNECTION_H
-#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pythread.h"
#include "structmember.h"
diff --git a/contrib/tools/python3/Modules/_sqlite/cursor.c b/contrib/tools/python3/Modules/_sqlite/cursor.c
index d489d2b3dc2..cc014c37323 100644
--- a/contrib/tools/python3/Modules/_sqlite/cursor.c
+++ b/contrib/tools/python3/Modules/_sqlite/cursor.c
@@ -21,11 +21,18 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
#include "cursor.h"
#include "microprotocols.h"
#include "module.h"
#include "util.h"
+#include "pycore_pyerrors.h" // _PyErr_FormatFromCause()
+#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
+
typedef enum {
TYPE_LONG,
TYPE_FLOAT,
@@ -174,9 +181,7 @@ cursor_dealloc(pysqlite_Cursor *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
- if (self->in_weakreflist != NULL) {
- PyObject_ClearWeakRefs((PyObject*)self);
- }
+ FT_CLEAR_WEAKREFS((PyObject*)self, self->in_weakreflist);
tp->tp_clear((PyObject *)self);
tp->tp_free(self);
Py_DECREF(tp);
@@ -461,6 +466,9 @@ static int check_cursor(pysqlite_Cursor* cur)
return 0;
}
+ assert(cur->connection != NULL);
+ assert(cur->connection->state != NULL);
+
if (cur->closed) {
PyErr_SetString(cur->connection->state->ProgrammingError,
"Cannot operate on a closed cursor.");
@@ -557,43 +565,40 @@ bind_param(pysqlite_state *state, pysqlite_Statement *self, int pos,
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);
+ rc = (value == -1 && PyErr_Occurred())
+ ? SQLITE_ERROR
+ : 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);
- }
+ rc = (value == -1 && PyErr_Occurred())
+ ? SQLITE_ERROR
+ : sqlite3_bind_double(self->st, pos, value);
break;
}
case TYPE_UNICODE:
string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
- if (string == NULL)
- return -1;
+ if (string == NULL) {
+ return SQLITE_ERROR;
+ }
if (buflen > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"string longer than INT_MAX bytes");
- return -1;
+ return SQLITE_ERROR;
}
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) {
- return -1;
+ return SQLITE_ERROR;
}
if (view.len > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"BLOB longer than INT_MAX bytes");
PyBuffer_Release(&view);
- return -1;
+ return SQLITE_ERROR;
}
rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
PyBuffer_Release(&view);
@@ -603,7 +608,7 @@ bind_param(pysqlite_state *state, pysqlite_Statement *self, int pos,
PyErr_Format(state->ProgrammingError,
"Error binding parameter %d: type '%s' is not supported",
pos, Py_TYPE(parameter)->tp_name);
- rc = -1;
+ rc = SQLITE_ERROR;
}
final:
@@ -715,7 +720,6 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
} 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
@@ -727,23 +731,17 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
}
binding_name++; /* skip first char (the colon) */
- binding_name_obj = PyUnicode_FromString(binding_name);
- if (!binding_name_obj) {
+ PyObject *current_param = NULL;
+ int found = PyMapping_GetOptionalItemString(parameters,
+ binding_name,
+ &current_param);
+ if (found == -1) {
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(state->ProgrammingError,
- "You did not supply a value for binding "
- "parameter :%s.", binding_name);
- }
+ else if (found == 0) {
+ PyErr_Format(state->ProgrammingError,
+ "You did not supply a value for binding "
+ "parameter :%s.", binding_name);
return;
}
@@ -1162,35 +1160,37 @@ pysqlite_cursor_fetchone_impl(pysqlite_Cursor *self)
/*[clinic input]
_sqlite3.Cursor.fetchmany as pysqlite_cursor_fetchmany
- size as maxrows: int(c_default='self->arraysize') = 1
+ size as maxrows: size_t(c_default='((pysqlite_Cursor *)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]*/
+pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, size_t maxrows)
+/*[clinic end generated code: output=8bff46d4f24c9e84 input=5485f1f2ae46c2ff]*/
{
+ if (maxrows > (size_t)UINT32_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "Python int too large for C uint32_t");
+ return NULL;
+ }
+
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;
- }
+ while (maxrows > 0 && (row = pysqlite_cursor_iternext(self))) {
+ int rc = PyList_Append(list, row);
Py_DECREF(row);
-
- if (++counter == maxrows) {
+ if (rc < 0) {
break;
}
+ maxrows--;
}
if (PyErr_Occurred()) {
@@ -1304,6 +1304,40 @@ pysqlite_cursor_close_impl(pysqlite_Cursor *self)
Py_RETURN_NONE;
}
+/*[clinic input]
+@getter
+_sqlite3.Cursor.arraysize
+[clinic start generated code]*/
+
+static PyObject *
+_sqlite3_Cursor_arraysize_get_impl(pysqlite_Cursor *self)
+/*[clinic end generated code: output=e0919d97175e6c50 input=3278f8d3ecbd90e3]*/
+{
+ return PyLong_FromSize_t(self->arraysize);
+}
+
+/*[clinic input]
+@setter
+_sqlite3.Cursor.arraysize
+[clinic start generated code]*/
+
+static int
+_sqlite3_Cursor_arraysize_set_impl(pysqlite_Cursor *self, PyObject *value)
+/*[clinic end generated code: output=af59a6b09f8cce6e input=ace48cb114e26060]*/
+{
+ size_t converted;
+ if (!_PyLong_Size_t_Converter(value, &converted)) {
+ return -1;
+ }
+ if (converted > (size_t)UINT32_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "Python int too large to convert to C uint32_t");
+ return -1;
+ }
+ self->arraysize = (uint32_t)converted;
+ return 0;
+}
+
static PyMethodDef cursor_methods[] = {
PYSQLITE_CURSOR_CLOSE_METHODDEF
PYSQLITE_CURSOR_EXECUTEMANY_METHODDEF
@@ -1319,16 +1353,20 @@ static PyMethodDef cursor_methods[] = {
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},
+ {"connection", _Py_T_OBJECT, offsetof(pysqlite_Cursor, connection), Py_READONLY},
+ {"description", _Py_T_OBJECT, offsetof(pysqlite_Cursor, description), Py_READONLY},
+ {"lastrowid", _Py_T_OBJECT, offsetof(pysqlite_Cursor, lastrowid), Py_READONLY},
+ {"rowcount", Py_T_LONG, offsetof(pysqlite_Cursor, rowcount), Py_READONLY},
+ {"row_factory", _Py_T_OBJECT, offsetof(pysqlite_Cursor, row_factory), 0},
+ {"__weaklistoffset__", Py_T_PYSSIZET, offsetof(pysqlite_Cursor, in_weakreflist), Py_READONLY},
{NULL}
};
+static struct PyGetSetDef cursor_getsets[] = {
+ _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF
+ {NULL},
+};
+
static const char cursor_doc[] =
PyDoc_STR("SQLite database cursor class.");
@@ -1339,6 +1377,7 @@ static PyType_Slot cursor_slots[] = {
{Py_tp_iternext, pysqlite_cursor_iternext},
{Py_tp_methods, cursor_methods},
{Py_tp_members, cursor_members},
+ {Py_tp_getset, cursor_getsets},
{Py_tp_init, pysqlite_cursor_init},
{Py_tp_traverse, cursor_traverse},
{Py_tp_clear, cursor_clear},
diff --git a/contrib/tools/python3/Modules/_sqlite/cursor.h b/contrib/tools/python3/Modules/_sqlite/cursor.h
index 0bcdddc3e29..c840a3d7ed0 100644
--- a/contrib/tools/python3/Modules/_sqlite/cursor.h
+++ b/contrib/tools/python3/Modules/_sqlite/cursor.h
@@ -23,7 +23,6 @@
#ifndef PYSQLITE_CURSOR_H
#define PYSQLITE_CURSOR_H
-#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "statement.h"
@@ -36,7 +35,7 @@ typedef struct
pysqlite_Connection* connection;
PyObject* description;
PyObject* row_cast_map;
- int arraysize;
+ uint32_t arraysize;
PyObject* lastrowid;
long rowcount;
PyObject* row_factory;
diff --git a/contrib/tools/python3/Modules/_sqlite/microprotocols.c b/contrib/tools/python3/Modules/_sqlite/microprotocols.c
index 148220d0f91..f77458d94a8 100644
--- a/contrib/tools/python3/Modules/_sqlite/microprotocols.c
+++ b/contrib/tools/python3/Modules/_sqlite/microprotocols.c
@@ -85,20 +85,19 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
if (!key) {
return NULL;
}
- adapter = PyDict_GetItemWithError(state->psyco_adapters, key);
+ if (PyDict_GetItemRef(state->psyco_adapters, key, &adapter) < 0) {
+ Py_DECREF(key);
+ return NULL;
+ }
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_LookupAttr(proto, state->str___adapt__, &adapter) < 0) {
+ if (PyObject_GetOptionalAttr(proto, state->str___adapt__, &adapter) < 0) {
return NULL;
}
if (adapter) {
@@ -117,7 +116,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
}
/* and finally try to have the object adapt itself */
- if (_PyObject_LookupAttr(obj, state->str___conform__, &adapter) < 0) {
+ if (PyObject_GetOptionalAttr(obj, state->str___conform__, &adapter) < 0) {
return NULL;
}
if (adapter) {
diff --git a/contrib/tools/python3/Modules/_sqlite/microprotocols.h b/contrib/tools/python3/Modules/_sqlite/microprotocols.h
index 6bde9d01f45..8a8c33525ee 100644
--- a/contrib/tools/python3/Modules/_sqlite/microprotocols.h
+++ b/contrib/tools/python3/Modules/_sqlite/microprotocols.h
@@ -26,7 +26,6 @@
#ifndef PSYCOPG_MICROPROTOCOLS_H
#define PSYCOPG_MICROPROTOCOLS_H 1
-#define PY_SSIZE_T_CLEAN
#include <Python.h>
/** exported functions **/
diff --git a/contrib/tools/python3/Modules/_sqlite/module.c b/contrib/tools/python3/Modules/_sqlite/module.c
index 27bd42f4595..3d828abdd80 100644
--- a/contrib/tools/python3/Modules/_sqlite/module.c
+++ b/contrib/tools/python3/Modules/_sqlite/module.c
@@ -21,6 +21,10 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
#include "connection.h"
#include "statement.h"
#include "cursor.h"
@@ -29,8 +33,10 @@
#include "row.h"
#include "blob.h"
-#if SQLITE_VERSION_NUMBER < 3007015
-#error "SQLite 3.7.15 or higher required"
+#include "pycore_import.h" // _PyImport_GetModuleAttrString()
+
+#if SQLITE_VERSION_NUMBER < 3015002
+#error "SQLite 3.15.2 or higher required"
#endif
#define clinic_state() (pysqlite_get_state(module))
@@ -42,31 +48,33 @@ module _sqlite3
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
-// NB: This needs to be in sync with the Connection.__init__ docstring.
-PyDoc_STRVAR(module_connect_doc,
-"connect($module, /, database, timeout=5.0, detect_types=0,\n"
-" isolation_level='', check_same_thread=True,\n"
-" factory=ConnectionType, cached_statements=128, uri=False, *,\n"
-" autocommit=sqlite3.LEGACY_TRANSACTION_CONTROL)\n"
-"--\n"
-"\n"
-"Opens a connection to the SQLite database file database.\n"
-"\n"
-"You can use \":memory:\" to open a database connection to a database that resides\n"
-"in RAM instead of on disk.");
-
-#define PYSQLITE_CONNECT_METHODDEF \
- {"connect", _PyCFunction_CAST(module_connect), METH_FASTCALL|METH_KEYWORDS, module_connect_doc},
+/*
+ * We create 'clinic/_sqlite3.connect.c.h' in connection.c, in order to
+ * keep the signatures of sqlite3.Connection.__init__ and
+ * sqlite3.connect() synchronised.
+ */
+#include "clinic/_sqlite3.connect.c.h"
static PyObject *
-module_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
- PyObject *kwnames)
+pysqlite_connect(PyObject *module, PyObject *const *args, Py_ssize_t nargsf,
+ PyObject *kwnames)
{
pysqlite_state *state = pysqlite_get_state(module);
PyObject *factory = (PyObject *)state->ConnectionType;
static const int FACTORY_POS = 5;
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ if (nargs > 1 && nargs <= 8) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "Passing more than 1 positional argument to sqlite3.connect()"
+ " is deprecated. Parameters 'timeout', 'detect_types', "
+ "'isolation_level', 'check_same_thread', 'factory', "
+ "'cached_statements' and 'uri' will become keyword-only "
+ "parameters in Python 3.15.", 1))
+ {
+ return NULL;
+ }
+ }
if (nargs > FACTORY_POS) {
factory = args[FACTORY_POS];
}
@@ -236,7 +244,7 @@ load_functools_lru_cache(PyObject *module)
static PyMethodDef module_methods[] = {
PYSQLITE_ADAPT_METHODDEF
PYSQLITE_COMPLETE_STATEMENT_METHODDEF
- PYSQLITE_CONNECT_METHODDEF
+ {"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__},
PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
PYSQLITE_REGISTER_ADAPTER_METHODDEF
PYSQLITE_REGISTER_CONVERTER_METHODDEF
@@ -245,12 +253,6 @@ static PyMethodDef module_methods[] = {
/* SQLite C API result codes. See also:
* - https://www.sqlite.org/c3ref/c_abort_rollback.html
- * - https://sqlite.org/changes.html#version_3_3_8
- * - https://sqlite.org/changes.html#version_3_7_16
- * - https://sqlite.org/changes.html#version_3_7_17
- * - https://sqlite.org/changes.html#version_3_8_0
- * - https://sqlite.org/changes.html#version_3_8_3
- * - https://sqlite.org/changes.html#version_3_14
*
* Note: the SQLite changelogs rarely mention new result codes, so in order to
* keep the 'error_codes' table in sync with SQLite, we must manually inspect
@@ -294,10 +296,8 @@ static const struct {
DECLARE_ERROR_CODE(SQLITE_ROW),
DECLARE_ERROR_CODE(SQLITE_SCHEMA),
DECLARE_ERROR_CODE(SQLITE_TOOBIG),
-#if SQLITE_VERSION_NUMBER >= 3007017
DECLARE_ERROR_CODE(SQLITE_NOTICE),
DECLARE_ERROR_CODE(SQLITE_WARNING),
-#endif
// Extended result code list
DECLARE_ERROR_CODE(SQLITE_ABORT_ROLLBACK),
DECLARE_ERROR_CODE(SQLITE_BUSY_RECOVERY),
@@ -331,7 +331,6 @@ static const struct {
DECLARE_ERROR_CODE(SQLITE_LOCKED_SHAREDCACHE),
DECLARE_ERROR_CODE(SQLITE_READONLY_CANTLOCK),
DECLARE_ERROR_CODE(SQLITE_READONLY_RECOVERY),
-#if SQLITE_VERSION_NUMBER >= 3007016
DECLARE_ERROR_CODE(SQLITE_CONSTRAINT_CHECK),
DECLARE_ERROR_CODE(SQLITE_CONSTRAINT_COMMITHOOK),
DECLARE_ERROR_CODE(SQLITE_CONSTRAINT_FOREIGNKEY),
@@ -342,39 +341,20 @@ static const struct {
DECLARE_ERROR_CODE(SQLITE_CONSTRAINT_UNIQUE),
DECLARE_ERROR_CODE(SQLITE_CONSTRAINT_VTAB),
DECLARE_ERROR_CODE(SQLITE_READONLY_ROLLBACK),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3007017
DECLARE_ERROR_CODE(SQLITE_IOERR_MMAP),
DECLARE_ERROR_CODE(SQLITE_NOTICE_RECOVER_ROLLBACK),
DECLARE_ERROR_CODE(SQLITE_NOTICE_RECOVER_WAL),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3008000
DECLARE_ERROR_CODE(SQLITE_BUSY_SNAPSHOT),
DECLARE_ERROR_CODE(SQLITE_IOERR_GETTEMPPATH),
DECLARE_ERROR_CODE(SQLITE_WARNING_AUTOINDEX),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3008001
DECLARE_ERROR_CODE(SQLITE_CANTOPEN_CONVPATH),
DECLARE_ERROR_CODE(SQLITE_IOERR_CONVPATH),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3008002
DECLARE_ERROR_CODE(SQLITE_CONSTRAINT_ROWID),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3008003
DECLARE_ERROR_CODE(SQLITE_READONLY_DBMOVED),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3008007
DECLARE_ERROR_CODE(SQLITE_AUTH_USER),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3009000
DECLARE_ERROR_CODE(SQLITE_IOERR_VNODE),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3010000
DECLARE_ERROR_CODE(SQLITE_IOERR_AUTH),
-#endif
-#if SQLITE_VERSION_NUMBER >= 3014001
DECLARE_ERROR_CODE(SQLITE_OK_LOAD_PERMANENTLY),
-#endif
#if SQLITE_VERSION_NUMBER >= 3021000
DECLARE_ERROR_CODE(SQLITE_IOERR_BEGIN_ATOMIC),
DECLARE_ERROR_CODE(SQLITE_IOERR_COMMIT_ATOMIC),
@@ -481,9 +461,7 @@ add_integer_constants(PyObject *module) {
ADD_INT(SQLITE_DROP_VTABLE);
ADD_INT(SQLITE_FUNCTION);
ADD_INT(SQLITE_SAVEPOINT);
-#if SQLITE_VERSION_NUMBER >= 3008003
ADD_INT(SQLITE_RECURSIVE);
-#endif
// Run-time limit categories
ADD_INT(SQLITE_LIMIT_LENGTH);
ADD_INT(SQLITE_LIMIT_SQL_LENGTH);
@@ -496,9 +474,7 @@ add_integer_constants(PyObject *module) {
ADD_INT(SQLITE_LIMIT_LIKE_PATTERN_LENGTH);
ADD_INT(SQLITE_LIMIT_VARIABLE_NUMBER);
ADD_INT(SQLITE_LIMIT_TRIGGER_DEPTH);
-#if SQLITE_VERSION_NUMBER >= 3008007
ADD_INT(SQLITE_LIMIT_WORKER_THREADS);
-#endif
/*
* Database connection configuration options.
@@ -506,12 +482,8 @@ add_integer_constants(PyObject *module) {
*/
ADD_INT(SQLITE_DBCONFIG_ENABLE_FKEY);
ADD_INT(SQLITE_DBCONFIG_ENABLE_TRIGGER);
-#if SQLITE_VERSION_NUMBER >= 3012002
ADD_INT(SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER);
-#endif
-#if SQLITE_VERSION_NUMBER >= 3013000
ADD_INT(SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION);
-#endif
#if SQLITE_VERSION_NUMBER >= 3016000
ADD_INT(SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE);
#endif
@@ -678,8 +650,8 @@ do { \
static int
module_exec(PyObject *module)
{
- if (sqlite3_libversion_number() < 3007015) {
- PyErr_SetString(PyExc_ImportError, MODULE_NAME ": SQLite 3.7.15 or higher required");
+ if (sqlite3_libversion_number() < 3015002) {
+ PyErr_SetString(PyExc_ImportError, MODULE_NAME ": SQLite 3.15.2 or higher required");
return -1;
}
@@ -779,13 +751,13 @@ module_exec(PyObject *module)
return 0;
error:
- sqlite3_shutdown();
return -1;
}
static struct PyModuleDef_Slot module_slots[] = {
{Py_mod_exec, module_exec},
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+ {Py_mod_gil, Py_MOD_GIL_NOT_USED},
{0, NULL},
};
diff --git a/contrib/tools/python3/Modules/_sqlite/module.h b/contrib/tools/python3/Modules/_sqlite/module.h
index daa22091d38..a4ca45cf632 100644
--- a/contrib/tools/python3/Modules/_sqlite/module.h
+++ b/contrib/tools/python3/Modules/_sqlite/module.h
@@ -23,7 +23,6 @@
#ifndef PYSQLITE_MODULE_H
#define PYSQLITE_MODULE_H
-#define PY_SSIZE_T_CLEAN
#include "Python.h"
#define LEGACY_TRANSACTION_CONTROL -1
diff --git a/contrib/tools/python3/Modules/_sqlite/row.c b/contrib/tools/python3/Modules/_sqlite/row.c
index 6179e279678..3427fae373d 100644
--- a/contrib/tools/python3/Modules/_sqlite/row.c
+++ b/contrib/tools/python3/Modules/_sqlite/row.c
@@ -21,6 +21,10 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
#include "row.h"
#include "cursor.h"
diff --git a/contrib/tools/python3/Modules/_sqlite/row.h b/contrib/tools/python3/Modules/_sqlite/row.h
index b5190981758..d42b781e493 100644
--- a/contrib/tools/python3/Modules/_sqlite/row.h
+++ b/contrib/tools/python3/Modules/_sqlite/row.h
@@ -23,7 +23,6 @@
#ifndef PYSQLITE_ROW_H
#define PYSQLITE_ROW_H
-#define PY_SSIZE_T_CLEAN
#include "Python.h"
typedef struct _Row
diff --git a/contrib/tools/python3/Modules/_sqlite/statement.h b/contrib/tools/python3/Modules/_sqlite/statement.h
index 11a6464b1a1..b18f170ebb0 100644
--- a/contrib/tools/python3/Modules/_sqlite/statement.h
+++ b/contrib/tools/python3/Modules/_sqlite/statement.h
@@ -23,7 +23,6 @@
#ifndef PYSQLITE_STATEMENT_H
#define PYSQLITE_STATEMENT_H
-#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "connection.h"
diff --git a/contrib/tools/python3/Modules/_sqlite/util.c b/contrib/tools/python3/Modules/_sqlite/util.c
index c521fc5ad6b..b0622e66928 100644
--- a/contrib/tools/python3/Modules/_sqlite/util.c
+++ b/contrib/tools/python3/Modules/_sqlite/util.c
@@ -21,7 +21,12 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
+#ifndef Py_BUILD_CORE_BUILTIN
+# define Py_BUILD_CORE_MODULE 1
+#endif
+
#include "module.h"
+#include "pycore_long.h" // _PyLong_AsByteArray()
#include "connection.h"
// Returns non-NULL if a new exception should be raised
@@ -158,7 +163,7 @@ _pysqlite_long_as_int64(PyObject * py_val)
sqlite_int64 int64val;
if (_PyLong_AsByteArray((PyLongObject *)py_val,
(unsigned char *)&int64val, sizeof(int64val),
- IS_LITTLE_ENDIAN, 1 /* signed */) >= 0) {
+ IS_LITTLE_ENDIAN, 1 /* signed */, 0) >= 0) {
return int64val;
}
}
diff --git a/contrib/tools/python3/Modules/_sqlite/util.h b/contrib/tools/python3/Modules/_sqlite/util.h
index a22bcd82d2a..68b1a8cb67a 100644
--- a/contrib/tools/python3/Modules/_sqlite/util.h
+++ b/contrib/tools/python3/Modules/_sqlite/util.h
@@ -23,7 +23,6 @@
#ifndef PYSQLITE_UTIL_H
#define PYSQLITE_UTIL_H
-#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pythread.h"
#include "sqlite3.h"
diff --git a/contrib/tools/python3/Modules/_sqlite/ya.make b/contrib/tools/python3/Modules/_sqlite/ya.make
index bf957b0a3aa..eef017d69e9 100644
--- a/contrib/tools/python3/Modules/_sqlite/ya.make
+++ b/contrib/tools/python3/Modules/_sqlite/ya.make
@@ -2,9 +2,9 @@
PY3_LIBRARY()
-VERSION(3.12.12)
+VERSION(3.13.11)
-ORIGINAL_SOURCE(https://github.com/python/cpython/archive/v3.12.12.tar.gz)
+ORIGINAL_SOURCE(https://github.com/python/cpython/archive/v3.13.11.tar.gz)
LICENSE(Python-2.0)