Skip to content

callproc requires nextset to be called before it returns results #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ramiro
Copy link
Contributor

@ramiro ramiro commented Apr 30, 2014

I am creating a new issue that more correctly defines what someone stumbled upon with issue #98. That issue is a little confusing so I closed it and opened this one.

The problem is that callproc does not return resultsets for a stored proc, until you call nextset.

Results of an example program at https://gist.github.com/msabramo/6747703

(mysql.venv)vagrant@lucid64:~/dev/git-repos/pymssql$ python callproc_comparison.py
******************************************************************************
Test MySQLdb
******************************************************************************

first use cursor.execute with a proc that returns 0 rows and then 3 rows and print out the rows and get an empty set:
()
then call nextset and get the 3 rows:
(('Tom',), ('Dick',), ('Harry',))

now use cursor.callproc, get an empty set
()
then call nextset and get the 3 rows:
(('Tom',), ('Dick',), ('Harry',))

******************************************************************************
Test pymssql
******************************************************************************

first use cursor.execute with a proc that returns 0 rows and then 3 rows and print out the rows and get an empty set:
[]
then call nextset and get the 3 rows:
[(u'Tom',), (u'Dick',), (u'Harry',)]

now use cursor.callproc, get an empty set
[]
then call nextset and get the 3 rows:
[]

The bug is that cursor.callproc is not returning the 3 rows.

The fix is easy and I will post it shortly... Basically, it's just to call nextset() in callproc.

@ghost ghost assigned msabramo Sep 28, 2013
@msabramo
Copy link
Contributor Author

There are also fetchone calls commented out in test_sprocs.py -- I think these were commented out because of failures due to the same issue -- this should be checked and maybe these lines can be put back.

@msabramo
Copy link
Contributor Author

Hmmm, fix is not that easy. My fix worked with FreeTDS 0.82 but it causes some undesirable behavior with FreeTDS 0.91.

@msabramo
Copy link
Contributor Author

msabramo commented Oct 4, 2013

The fix I alluded to above is 6db0897

@msabramo
Copy link
Contributor Author

msabramo commented Oct 4, 2013

I mucked around and the first thing I came up with was:

6db0897

which is simply just calling nextset() in callproc after executing the procedure.

At first, I thought this solved things and perhaps it's a step in the right direction. Before adding this line, I was getting an exception ("Statement not executed or executed statement has no resultset") when trying to fetch rows after calling callproc. After adding this line, the exception went away and I got rows back and IIRC it was doing the right thing if the stored proc returned one resultset with rows. However, if the stored proc returned two resultsets where the first had no rows, then it would skip over the 0 row resultset and go straight to the second resultset (and executing a "EXEC storedproc" query didn't do this). I have not been able to find a way to not have the exception and also not skip over a blank resultset. I've been testing my using the script at https://gist.github.com/msabramo/6747703 -- which compares the execute and callproc ways of running the stored proc and does it for both MySQLdb and pymssql. MySQLdb seems to have the desirable behavior here where execute and callproc are always consistent -- I haven't been able to achieve this with pymssql.

Based on Marc's script.

[skip ci]
@rsyring rsyring added this to the 2.2.0 milestone Oct 25, 2014
@termim termim mentioned this pull request Oct 1, 2022
termim added a commit to termim/pymssql that referenced this pull request Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants