Bug #89112 | Cannot use lists or tuples as arguments for WHERE/IN clauses | ||
---|---|---|---|
Submitted: | 4 Jan 2018 22:53 | Modified: | 11 Oct 2018 10:43 |
Reporter: | Chris Foresman | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | Connector / Python | Severity: | S4 (Feature request) |
Version: | 8.0.5b1, 8.0.12 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[4 Jan 2018 22:53]
Chris Foresman
[11 Oct 2018 10:43]
MySQL Verification Team
Hello Chris Foresman, Thank you for the feature request! regards, Umesh
[14 Apr 2021 21:27]
Jeff Stein
This is another pattern that is supported by both pymysql and mysqlclient that would also be nice to include. ```python query = """SELECT * FROM table WHERE (thing1, thing2) IN (%s);""" cursor.execute(query, [('red', 'blue'), ('old', 'new')]) ```
[6 Jun 2021 6:43]
PHILIP COLEMAN
Changing method "_process_params_dict" in "cursor.py" to following solved the problem for me: def _process_params_dict(self, params): """Process query parameters given as dictionary""" try: to_mysql = self._connection.converter.to_mysql escape = self._connection.converter.escape quote = self._connection.converter.quote res = {} for key, value in list(params.items()): ### Begin additions if type(value) is tuple: res[key.encode()] = b'' for subvalue in value: conv = subvalue conv = to_mysql(conv) conv = escape(conv) conv = quote(conv) res[key.encode()] = res[key.encode()] + b',' + conv if len(res[key.encode()]) else conv else: ### End additions conv = value conv = to_mysql(conv) conv = escape(conv) conv = quote(conv) res[key.encode()] = conv except Exception as err: raise errors.ProgrammingError( "Failed processing pyformat-parameters; %s" % err) else: print('result: ', res) return res