Bug #81572 Allow MySQLCursorPrepared.execute() to accept %(key_name)s in operations and dic
Submitted: 24 May 2016 13:28 Modified: 25 May 2016 5:21
Reporter: OCA Admin (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:2.1.3 OS:Any
Assigned to: CPU Architecture:Any

[24 May 2016 13:28] OCA Admin
Description:
This bug tracks a contribution by Luke Weber (Github user: lukeweber) as described in http://github.com/mysql/mysql-connector-python/pull/19

How to repeat:
See description

Suggested fix:
See contribution code attached
[24 May 2016 13:28] OCA Admin
Contribution submitted via Github - Allow MySQLCursorPrepared.execute() to accept %(key_name)s in operations and dic 
(*) Contribution by Luke Weber (Github lukeweber, mysql-connector-python/pull/19#issuecomment-221028191): I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: git_patch_69942485.txt (text/plain), 5.10 KiB.

[25 May 2016 5:21] Umesh Shastry
Hello Luke Weber,

Thank you for the report and contribution.

Thanks,
Umesh
[7 Jul 2016 15:56] Luke Weber
Take into replacements in query being duplicate

Attachment: updated_changes.patch (application/octet-stream, text), 2.00 KiB.

[7 Jul 2016 15:58] Luke Weber
Please note the validation of query parameters in the previous patch would not allow for duplicates replacements from a single key in a dictionary. There are many cases where this could be useful, but one example:

INSERT INTO `table_name` SET `colum1`= %(column1)s,  `colum2`= %(column2)sON DUPLICATE KEY UPDATE SET `colum1`= %(column1)s;

data = dict(column1="testdata1", column2="testdata2")

In this case the replacements(3) would not equal the count of keys, but would be valid.

I've added a new patch file and checked if len(set(query_replacement_keys)) != len(params) and also check for KeyError on replacement in case the dictionary does not define one of the parameters.