[python-sybase] Problem with calling stored procedures

Harri Pasanen harri.pasanen at bigfoot.com
Tue, 2 Apr 2002 19:46:21 +0200


On Tuesday 02 April 2002 14:31, Dave Cole wrote:
> > Hello, I think the old problem with calling some stored procedures
> > still seems to be there.
> >
> > Namely, I still can't get any sensible results from calling
> > sp_helpindex.  The code is something like:
> >
> >
> > def getindex(table):
> >     print "getindex", table
> >     c = cnx.cursor()
> >     c.callproc("sp_helpindex", [table])
> >     l = c.fetchall()
> >     print l
> >     while c.nextset():
> >         l = c.fetchall()
> >         print l
> >
> > cnx=Sybase.connect("<server>","<uname>","<pass>")
> > cnx.cursor().execute("use mydb")
> >
> > getindex("mytable")
>
> Hmm...  It Seems To Work For Me With 0.34 (TM)
>
> >>> import Sybase
> >>> db = Sybase.connect('SYBASE', 'sa', '')
> >>> db.cursor().execute('use pubs2')
> >>> c = db.cursor()
> >>> c.callproc('sp_helpindex', ['titles'])
> >>> for r in c.fetchall():
>
> ...     print r
> ...
> ('titleidind          ', 'clustered, unique located on default             
>       ', ' title_id', 0, 0, 0) ('titleind            ', 'nonclustered
> located on default                         ', ' title', 0, 0, 0)
>
> >>> c.nextset()
>
> 1
>
> >>> for r in c.fetchall():
>
> ...     print r
> ...
> (0,)
>
> >>> c.nextset()
>
> - Dave

I finally fished from my disk the old testcase I sent your way last November, 
which still should exhibit the problem:

I wrote:

After some tests, I got a fairly minimal test case that should also fail for
you.  The preceding 'select' somehow throws the 'sp_helpindex' call off
balance.

-Harri

------8<------8<------8<------8<------8<------8<------8<------8<--------
import Sybase
Sybase._ctx.debug = 1
db = Sybase.connect('SYBASE', 'sa', '', 'pubs2')

def test(table):
    print "Test table:", table
    c = db.cursor()
    c.execute('select * from '+table)
    c.fetchall()
    c.close()
    cmd = "sp_helpindex %s" % table
    print db.execute(cmd)

test('authors')