Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-101693: In sqlite3, deprecate using named placeholders with parameters supplied as a sequence#101698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes from2 commits
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
b693895
gh-101698: Deprecate using named placeholders with sequences
erlend-aaslandFeb 8, 2023
483e4d6
Update docs
erlend-aaslandFeb 8, 2023
e826428
Document deprecation in reference
erlend-aaslandFeb 8, 2023
132a6ee
Also test executemany
erlend-aaslandFeb 8, 2023
31cc188
Revert "Also test executemany"
erlend-aaslandFeb 8, 2023
660a742
Sync with main
erlend-aaslandFeb 9, 2023
a18d0bb
Address review: add test for query with more than one named param
erlend-aaslandFeb 9, 2023
3f94201
Address review: add PyErr_WarnFormat error handling
erlend-aaslandFeb 9, 2023
997ccc6
Sync with main
erlend-aaslandFeb 10, 2023
cb091af
Pull in main
erlend-aaslandFeb 14, 2023
450cdcc
Fixup
erlend-aaslandFeb 14, 2023
841e8a4
Apply Serhiy's suggestion
erlend-aaslandFeb 14, 2023
3e7b680
Pull in main
erlend-aaslandFeb 14, 2023
38d1110
Address Alex's review
erlend-aaslandFeb 14, 2023
cf3cfc8
Also amend NEWS and What's New
erlend-aaslandFeb 14, 2023
1687b65
Use deprecated-removed
erlend-aaslandFeb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletionDoc/library/sqlite3.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1950,7 +1950,7 @@ question marks (qmark style) or named placeholders (named style).
For the qmark style, *parameters* must be a
:term:`sequence` whose length must match the number of placeholders,
or a :exc:`ProgrammingError` is raised.
For the named style, *parameters*should be
For the named style, *parameters*must be
an instance of a :class:`dict` (or a subclass),
which must contain keys for all named parameters;
any extra items are ignored.
Expand DownExpand Up@@ -1980,6 +1980,12 @@ Here's an example of both styles:

[('C', 1972)]

.. deprecated-removed:: 3.12 3.14

If named placeholders are used and *parameters* is a sequence,
:exc:`DeprecationWarning` is raised.
Starting with Python 3.14, :exc:`ProgrammingError` will be raised.

.. note::

:pep:`249` numeric placeholders are *not* supported.
Expand Down
7 changes: 7 additions & 0 deletionsDoc/whatsnew/3.12.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,6 +415,13 @@ Deprecated
and tailor them to your needs.
(Contributed by Erlend E. Aasland in :gh:`90016`.)

* In :meth:`~sqlite3.Cursor.execute`, :exc:`DeprecationWarning` is now raised
when :ref:`named placeholders <sqlite3-placeholders>` are used together with
parameters supplied as a :term:`sequence`.
Starting from Python 3.14, using named placeholders with parameters supplied
as a sequence will raise a :exc:`~sqlite3.ProgrammingError`.
(Contributed by Erlend E. Aasland in :gh:`101698`.)

* The 3-arg signatures (type, value, traceback) of :meth:`~coroutine.throw`,
:meth:`~generator.throw` and :meth:`~agen.athrow` are deprecated and
may be removed in a future version of Python. Use the single-arg versions
Expand Down
14 changes: 14 additions & 0 deletionsLib/test/test_sqlite3/test_dbapi.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -861,6 +861,20 @@ def __getitem__(slf, x):
with self.assertRaises(ZeroDivisionError):
self.cu.execute("select name from test where name=?", L())

def test_execute_named_param_and_sequence(self):
dataset = (
("select :a", (1,)),
("select :a, ?, ?", (1, 2, 3)),
("select ?, :b, ?", (1, 2, 3)),
("select ?, ?, :c", (1, 2, 3)),
)
msg = "Binding.*is a named parameter"
for query, params in dataset:
with self.subTest(query=query, params=params):
with self.assertWarnsRegex(DeprecationWarning, msg) as cm:
self.cu.execute(query, params)
self.assertEqual(cm.filename, __file__)

def test_execute_too_many_params(self):
category = sqlite.SQLITE_LIMIT_VARIABLE_NUMBER
msg = "too many SQL variables"
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
In:meth:`sqlite3.Cursor.execute`,:exc:`DeprecationWarning` is now raised
when:ref:`named placeholders<sqlite3-placeholders>` are used together with
parameters supplied as a:term:`sequence`.
Starting from Python 3.14, using named placeholders with parameters supplied
as a sequence will raise a:exc:`~sqlite3.ProgrammingError`.
Patch by Erlend E. Aasland.
11 changes: 11 additions & 0 deletionsModules/_sqlite/cursor.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -662,6 +662,17 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
return;
}
for (i = 0; i < num_params; i++) {
const char *name = sqlite3_bind_parameter_name(self->st, i+1);
if (name != NULL) {
PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"Binding %d ('%s') is a named parameter, "
"but you supplied a sequence which requires "
"nameless (qmark) placeholders. "
"Starting with Python 3.14 an "
"sqlite3.ProgrammingError will be raised.",
i+1, name);
}

if (PyTuple_CheckExact(parameters)) {
PyObject *item = PyTuple_GET_ITEM(parameters, i);
current_param = Py_NewRef(item);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp