Go-CN / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

cursor.executemany() weirdness in v 2.1.8 #150

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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",)])

Original issue reported on code.google.com by drben...@gmail.com on 11 Jan 2011 at 4:26

GoogleCodeExporter commented 9 years ago
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"])

Original comment by lukedell...@gmail.com on 14 Jan 2011 at 5:26

GoogleCodeExporter commented 9 years ago
thanks for the info. you learn something new every day :-) 
maybe consider adding a comment to the wiki to point this out.
thanks
ben

Original comment by drben...@gmail.com on 14 Jan 2011 at 2:28

GoogleCodeExporter commented 9 years ago

Original comment by mkleehammer on 6 Feb 2011 at 7:41