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

Commit 550483b

Browse filesBrowse files
erlend-aaslandaisk
andauthored
gh-117995: Don't raise DeprecationWarnings for indexed nameless params (#118001)
Filter out '?NNN' placeholders when looking for named params. Co-authored-by: AN Long <aisk@users.noreply.github.com>
1 parent 8b541c0 commit 550483b
Copy full SHA for 550483b

File tree

Expand file treeCollapse file tree

3 files changed

+17
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-1
lines changed

‎Lib/test/test_sqlite3/test_dbapi.py

Copy file name to clipboardExpand all lines: Lib/test/test_sqlite3/test_dbapi.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import threading
2929
import unittest
3030
import urllib.parse
31+
import warnings
3132

3233
from test.support import (
3334
SHORT_TIMEOUT, check_disallow_instantiation, requires_subprocess,
@@ -887,6 +888,19 @@ def test_execute_named_param_and_sequence(self):
887888
self.cu.execute(query, params)
888889
self.assertEqual(cm.filename, __file__)
889890

891+
def test_execute_indexed_nameless_params(self):
892+
# See gh-117995: "'?1' is considered a named placeholder"
893+
for query, params, expected in (
894+
("select ?1, ?2", (1, 2), (1, 2)),
895+
("select ?2, ?1", (1, 2), (2, 1)),
896+
):
897+
with self.subTest(query=query, params=params):
898+
with warnings.catch_warnings():
899+
warnings.simplefilter("error", DeprecationWarning)
900+
cu = self.cu.execute(query, params)
901+
actual, = cu.fetchall()
902+
self.assertEqual(actual, expected)
903+
890904
def test_execute_too_many_params(self):
891905
category = sqlite.SQLITE_LIMIT_VARIABLE_NUMBER
892906
msg = "too many SQL variables"
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Don't raise :exc:`DeprecationWarning` when a :term:`sequence` of parameters
2+
is used to bind indexed, nameless placeholders. See also :gh:`100668`.

‎Modules/_sqlite/cursor.c

Copy file name to clipboardExpand all lines: Modules/_sqlite/cursor.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
669669
}
670670
for (i = 0; i < num_params; i++) {
671671
const char *name = sqlite3_bind_parameter_name(self->st, i+1);
672-
if (name != NULL) {
672+
if (name != NULL && name[0] != '?') {
673673
int ret = PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
674674
"Binding %d ('%s') is a named parameter, but you "
675675
"supplied a sequence which requires nameless (qmark) "

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.