https://github.com/python/cpython/commit/9ddaf75a4c750bce0602f2274c645cffdd916274
commit: 9ddaf75a4c750bce0602f2274c645cffdd916274
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: erlend-aasland <[email protected]>
date: 2024-04-22T06:58:41Z
summary:

[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 550483b7e6c54b2a25d4db0c4ca41bd9c1132f93)

Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: AN Long <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-04-17-19-41-59.gh-issue-117995.Vt76Rv.rst
M Lib/test/test_sqlite3/test_dbapi.py
M Modules/_sqlite/cursor.c

diff --git a/Lib/test/test_sqlite3/test_dbapi.py 
b/Lib/test/test_sqlite3/test_dbapi.py
index 1a3bb6cc0b44a6..f0b99b13f6806f 100644
--- a/Lib/test/test_sqlite3/test_dbapi.py
+++ b/Lib/test/test_sqlite3/test_dbapi.py
@@ -28,6 +28,7 @@
 import threading
 import unittest
 import urllib.parse
+import warnings
 
 from test.support import (
     SHORT_TIMEOUT, check_disallow_instantiation, requires_subprocess,
@@ -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"
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
index 00000000000000..a289939d33e830
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-04-17-19-41-59.gh-issue-117995.Vt76Rv.rst
@@ -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`.
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index caeedbddb8d88b..d489d2b3dc2fd7 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -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) "

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to