My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
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
Status:  Complete
Owner:  ----
Closed:  May 2009


 
Reported by testfish...@gmail.com, Mar 18, 2009
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!


PythonCode.txt
707 bytes   View   Download
query.txt
10.8 KB   View   Download
Mar 18, 2009
Project Member #1 mkleehammer
You are absolutely correct.  The 2.0.x branch was inconsistent, but the 2.1.x
versions were *supposed* to always return Cursor.  I have no idea how this was missed.

This has been fixed in 2.1.5-beta7 9c34c6a79c291a4ed17596f4bae72ce7ed04f314 on github
if you want to test it.  Otherwise it will be in 2.1.5 as soon as I build and release it.

(I'm trying to verify as many fixes as possible before making the new release.)
Status: Fixed
Labels: -Priority-Medium Priority-Critical
Mar 18, 2009
#2 testfish...@gmail.com
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
Project Member #3 mkleehammer
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
Project Member #4 mkleehammer
(No comment was entered for this change.)
Status: Investigating
May 14, 2009
Project Member #5 mkleehammer
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
#6 danh...@gmail.com
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
ivoirdata2.py
668 bytes   View   Download
Nov 21, 2010
Project Member #7 mkleehammer
(No comment was entered for this change.)
Status: Complete

Powered by Google Project Hosting