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 9ddaf75

Browse filesBrowse files
miss-islingtonerlend-aaslandaisk
authored
[3.12] gh-117995: Don't raise DeprecationWarnings for indexed nameless params (GH-118001) (#118142)
Filter out '?NNN' placeholders when looking for named params. (cherry picked from commit 550483b) Co-authored-by: Erlend E. Aasland <erlend@python.org> Co-authored-by: AN Long <aisk@users.noreply.github.com>
1 parent 6d87cb4 commit 9ddaf75
Copy full SHA for 9ddaf75

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,
@@ -899,6 +900,19 @@ def test_execute_named_param_and_sequence(self):
899900
self.cu.execute(query, params)
900901
self.assertEqual(cm.filename, __file__)
901902

903+
def test_execute_indexed_nameless_params(self):
904+
# See gh-117995: "'?1' is considered a named placeholder"
905+
for query, params, expected in (
906+
("select ?1, ?2", (1, 2), (1, 2)),
907+
("select ?2, ?1", (1, 2), (2, 1)),
908+
):
909+
with self.subTest(query=query, params=params):
910+
with warnings.catch_warnings():
911+
warnings.simplefilter("error", DeprecationWarning)
912+
cu = self.cu.execute(query, params)
913+
actual, = cu.fetchall()
914+
self.assertEqual(actual, expected)
915+
902916
def test_execute_too_many_params(self):
903917
category = sqlite.SQLITE_LIMIT_VARIABLE_NUMBER
904918
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
@@ -663,7 +663,7 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self,
663663
}
664664
for (i = 0; i < num_params; i++) {
665665
const char *name = sqlite3_bind_parameter_name(self->st, i+1);
666-
if (name != NULL) {
666+
if (name != NULL && name[0] != '?') {
667667
int ret = PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
668668
"Binding %d ('%s') is a named parameter, but you "
669669
"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.