
Iterable_params = Ĭould be done better, but I couldn't find a solution using a dict of named parameters instead of an ordered tuple. My solution was to format the query string to explode the parameter into several parameters, and then construct the parameter dict with these new params: from typing import Iterable Maybe a little late to the question, but I stumbled upon a similar problem, but I wanted to use a dict of named parameters instead of a tuple (because if I want to modify the parameters to add or remove some, I don't want to re-construct the tuple, messing the order can be very easy and bug-inducing.). "Failed processing pyformat-parameters %s" % err) Res = res + b',' + conv if len(res) else conv Note that the data ( listofids) is going directly to mysqls driver, as a. If type(value) is tuple: # BEGIN MY ADDITIONS Use the listofids directly: formatstrings .join ( s len (listofids)) cursor.execute ('DELETE FROM foo.bar WHERE baz IN (s)' formatstrings, tuple (listofids)) That way you avoid having to quote yourself, and avoid all kinds of sql injection. """Process query parameters given as dictionary"""

We also define the database in a global variable called DBNAME, which enables you to easily use a different schema.

MySQL Connector API is implemented using pure Python and does not require any third-party library. The preceding code shows how we are storing the CREATE statements in a Python dictionary called TABLES. This Python MySQL library allows the conversion between Python and MySQL data types.
#Mysql in python driver#
This appears to still be a problem with Python3 in 2021, as pointed out in the comment by Rubms to the answer by markk.Īdding about 9 lines of code to the method "_process_params_dict" in "cursor.py" in the mysql connector package to handle tuples solved the problem for me: def _process_params_dict(self, params): Python MySQL Connector is a Python driver that helps to integrate Python and MySQL.
