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

Appearance settings

[3.12] gh-117995: Don't raise DeprecationWarnings for indexed nameless params (GH-118001) #118142

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions 14 Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import threading
import unittest
import urllib.parse
import warnings

from test.support import (
SHORT_TIMEOUT, check_disallow_instantiation, requires_subprocess,
Expand Down Expand Up @@ -899,6 +900,19 @@ def test_execute_named_param_and_sequence(self):
self.cu.execute(query, params)
self.assertEqual(cm.filename, __file__)

def test_execute_indexed_nameless_params(self):
# See gh-117995: "'?1' is considered a named placeholder"
for query, params, expected in (
("select ?1, ?2", (1, 2), (1, 2)),
("select ?2, ?1", (1, 2), (2, 1)),
):
with self.subTest(query=query, params=params):
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
cu = self.cu.execute(query, params)
actual, = cu.fetchall()
self.assertEqual(actual, expected)

def test_execute_too_many_params(self):
category = sqlite.SQLITE_LIMIT_VARIABLE_NUMBER
msg = "too many SQL variables"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Don't raise :exc:`DeprecationWarning` when a :term:`sequence` of parameters
is used to bind indexed, nameless placeholders. See also :gh:`100668`.
2 changes: 1 addition & 1 deletion 2 Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
}
for (i = 0; i < num_params; i++) {
const char *name = sqlite3_bind_parameter_name(self->st, i+1);
if (name != NULL) {
if (name != NULL && name[0] != '?') {
int ret = PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"Binding %d ('%s') is a named parameter, but you "
"supplied a sequence which requires nameless (qmark) "
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.