Skip to content

Commit

Permalink
pythongh-117995: Don't raise DeprecationWarnings for indexed nameless…
Browse files Browse the repository at this point in the history
… params

Filter out '?NNN' type placeholders when looking for named params.
  • Loading branch information
erlend-aasland committed Apr 17, 2024
1 parent b6c62c7 commit f0ddf10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,17 @@ 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):
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 Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) "
Expand Down

0 comments on commit f0ddf10

Please sign in to comment.