Bug #69445 Reusing Named Parameters
Submitted: 11 Jun 2013 21:30 Modified: 11 Jun 2013 21:33
Reporter: n/a Kuzma Email Updates:
Status: Open Impact on me:
None 
Category:Connector / Python Severity:S4 (Feature request)
Version:5.5.31 OS:Linux (Ubuntu 12.04)
Assigned to: CPU Architecture:Any
Tags: dict, dictionary, named, Parameter

[11 Jun 2013 21:30] n/a Kuzma
Description:
When using named parameters (i.e. passing a dict as the second parameter to MySQLCursor.execute()), the module complains that the syntax of the statement is incorrect if a parameter is reused in the query.

How to repeat:
x = mysql.connection.connect(**db_kwargs)
y = x.cursor()

y.execute('SELECT * FROM example WHERE %(test)s = %(test)s', {'test':1})

Suggested fix:
File attached. (There's two places str.replace() is called with a third parameter of 1; simply remove that parameter in these two places.)
[11 Jun 2013 21:31] n/a Kuzma
My Quick Fix

Attachment: patched_cursor.py (text/x-python), 26.10 KiB.

[11 Jun 2013 21:33] n/a Kuzma
Oh yeah... here's the specific error response:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%(test)s' at line 1