]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117995: Don't raise DeprecationWarnings for indexed nameless params (#118001)
authorErlend E. Aasland <erlend@python.org>
Mon, 22 Apr 2024 06:43:20 +0000 (08:43 +0200)
committerGitHub <noreply@github.com>
Mon, 22 Apr 2024 06:43:20 +0000 (08:43 +0200)
Filter out '?NNN' placeholders when looking for named params.

Co-authored-by: AN Long <aisk@users.noreply.github.com>
Lib/test/test_sqlite3/test_dbapi.py
Misc/NEWS.d/next/Library/2024-04-17-19-41-59.gh-issue-117995.Vt76Rv.rst [new file with mode: 0644]
Modules/_sqlite/cursor.c

index 4182de246a071b065cfe84c70c75cd1a65e6a4ce..6d8744ca5f7969925f16f408be8cd8d2fe7c451a 100644 (file)
@@ -28,6 +28,7 @@ import sys
 import threading
 import unittest
 import urllib.parse
+import warnings
 
 from test.support import (
     SHORT_TIMEOUT, check_disallow_instantiation, requires_subprocess,
@@ -887,6 +888,19 @@ class CursorTests(unittest.TestCase):
                     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"
diff --git a/Misc/NEWS.d/next/Library/2024-04-17-19-41-59.gh-issue-117995.Vt76Rv.rst b/Misc/NEWS.d/next/Library/2024-04-17-19-41-59.gh-issue-117995.Vt76Rv.rst
new file mode 100644 (file)
index 0000000..a289939
--- /dev/null
@@ -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`.
index f95df612328e5777dcacbdcd64656328e57a6020..950596ea82b5683c4868f37e2c3905f801636f77 100644 (file)
@@ -669,7 +669,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) "