| Issue 41: | .Execute returns an integer rather than a cursor object | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Hello all; I have a rather interesting problem. I'm using Python to insert a large amount of data into a MS SQL database. A portion of this data is HTML code. When I attempt to run the queries that I have generated, the shorter ones work fine, but the HTML insertion ones fail. And by fail, I mean that the connection.execute(query) command returns an integer rather than a cursor object. What steps will reproduce the problem? 1. Execute the attatched query through pyodbc's connection.execute What is the expected output? What do you see instead? The expected output is a cursor object, containing one tuple with one value in it. Instead, I am seeing an integer ... in this case, 1. What version of the product are you using? On what operating system? I'm running Windows XP, and I am using Python 2.6.1 and pyodbc-2.1.3.win32- py. Any help you can provide would be greatly appreciated. Thanks!
Mar 18, 2009
Thank you for the very prompt response! I've tried out the new version that you put up, but I either am not installing it correctly or else the bug is still there. (I've uninstalled the current version and then run python setup.py install). Is it just something I am doing wrong? Thanks!
Mar 18, 2009
At this point I'm confused. If you could provide a small program to reproduce this,
it would help. I have tried the code you provided, but obviously I had to modify the
SQL since it was invalid example SQL.
When you say "seeing an integer", do you mean at the 'print cursor' line. (It would
help me if the print statements had an indication of what we are looking at, like
'print "cursor:", cursor'. I definitely see a Cursor there.
Executing SQL like yours, however, raises an error:
...
File "C:\dev\x\pyodbc\tmp\test.PY", line 59, in getQueryResults
row = cursor.fetchone()
pyodbc.ProgrammingError: No results. Previous SQL was not a query.
First, you built *and* installed from the github source? I added 3 unit tests to the
SQL Server sqlservertests.py file just for this. For example, see the
test_retcursor_xxx functions.
Can you add the following to your test so we can rule out version mismatches:
print 'version:', pyodbc.version
Second, instead of looping in getQueryResults, you can simplify it to just this:
def getQueryResults(query):
return connect(query).fetchall()
You don't actually need to close cursors or database objects as long as references
aren't kept since the C implementation of Python (normal Python) uses reference
counting. Much easier.
Mar 18, 2009
(No comment was entered for this change.)
Status:
Investigating
May 14, 2009
I definitely identified this in 2.1.5 and fixed what I found. I'm pretty sure that it fixes the entire issue so I'm going to close this. If anyone still has problems, feel free to reopen. Thanks.
Status:
Verified
Apr 3, 2010
I am new in pyodbc programming and i try to get some integer values from from a MDB file and the script return a number like this for the integer: 3750193. Please help to find out where is my mistake. Thank yo
Nov 21, 2010
(No comment was entered for this change.)
Status:
Complete
|
Labels: -Priority-Medium Priority-Critical