mysql connector/python executemany() is broken in conjunction with the default paramstyle

Asked by Mike Bayer

I'm assuming this is the current system of reporting bugs, as there appear to be no other links enabled for reporting bugs.

Test case is as follows - .paramstyle reports "pyformat" as the default parameter style, however this format is broken when using executemany().

This is against mysql-connector as returned by "bzr clone lp:myconnpy"

from mysql import connector

# from pep-249
# paramstyle
#
# String constant stating the type of parameter marker
# formatting expected by the interface. Possible values are
# ...
# 'pyformat' Python extended format codes,
# e.g. '...WHERE name=%(name)s'
assert connector.paramstyle == 'pyformat'

conn = connector.connect(user='scott', password='tiger',
                            database='test', host='localhost')

cursor = conn.cursor()

cursor.execute("""
create table if not exists test( x integer, y integer) engine='InnoDB'
""")

# 'format' style with executemany() - works
cursor.executemany("insert into test(x, y) values (%s, %s)",
      [(1, 2), (3, 4)]
)

# 'pyformat' with execute() - works
cursor.execute("insert into test(x, y) values (%(x)s, %(y)s)",
      {"x": 1, "y": 2}
)

# 'pyformat' style with executemany() - broken
cursor.executemany("insert into test(x, y) values (%(x)s, %(y)s)",
      [{"x":1, "y":2}, {"x":3, "y":4}]
)

"""
output:

Traceback (most recent call last):
  File "mysqlconnector_execmany.py", line 21, in <module>
    [{"x":1, "y":2}, {"x":3, "y":4}]
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mysql/connector/cursor.py", line 437, in executemany
    values.append(fmt % self._process_params(params))
ValueError: incomplete format
"""

- mike (<email address hidden>)

Question information

Language:
English Edit question
Status:
Expired
For:
MySQL Connector/Python Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Mike Bayer (zzzeek) said :
#1

also note mysql-connector is non-functional with SQLAlchemy with this issue.

Revision history for this message
Launchpad Janitor (janitor) said :
#2

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Geert JM Vanderkelen (geertjmvdk) said :
#3

Sorry, I missed this question's email.

Please open a bug reports on bugs.mysql.com. I will check this.

Revision history for this message
Mike Bayer (zzzeek) said :
#4