Issue 150: cursor.executemany() weirdness in v 2.1.8
Status:  NoFix
Owner: ----
Closed:  Feb 2011
Reported by drben...@gmail.com, Jan 11, 2011
What steps will reproduce the problem?
1. cursor.executemany with a SELECT statement returns only the final SELECT from the params list

What is the expected output? What do you see instead?
>>> c.executemany("select * from DiagnosticCodesEN where CODE=?",[("A62",), ("E53",)])
>>> c.fetchall()
[(u'E53', None, u'Severe pulmonary hypertension')]

ie. i should get:
>>> [(u'A62', None, u'Normal mitral valve morphology and function'),(u'E53', None, u'Severe pulmonary hypertension')]



What version of the product are you using? On what operating system?
'2.1.8'; Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32

Please provide any additional information below.
- Thanks for pyodbc!
- It would real nice if you could pass a simpler params list. right now if i pass ['A62','E53'] it raises a TypeError, instead i have to generate a list of tuples as above [("A62",), ("E53",)])
Jan 13, 2011
#1 lukedell...@gmail.com
executemany is not intended for use with SELECT statements.  See PEP249:
http://www.python.org/dev/peps/pep-0249/

Quoting from the specification of the executemany method:
    "Use of this method for an operation which produces one or more result sets constitutes undefined behavior, and the implementation is permitted (but not required) to raise an exception when it detects that a result set has been created by an invocation of the operation."

To amend your example, a correct way to perform this operation would be to use:
    c.execute("select * from DiagnosticCodesEN where CODE IN (?,?)", ["A62", "E53"])

Jan 14, 2011
#2 drben...@gmail.com
thanks for the info. you learn something new every day :-) 
maybe consider adding a comment to the wiki to point this out.
thanks
ben
Feb 6, 2011
Project Member #3 mkleehammer
(No comment was entered for this change.)
Status: NoFix