[python-sybase] Fix for rowcount

Shai.Berger@sungard.com Shai.Berger at sungard.com
Thu, 29 May 2003 11:48:46 +0300


I have never seen Sybase -- or Oracle, for that matter -- give
indications of result-set size before fetching; I would be happy if you
could point me to such APIs.

Thanks,
	Shai.


-----Original Message-----
From: Peter Hopfgartner [mailto:hopfgartner@rolmail.net]=20
Sent: Wednesday, May 28, 2003 23:03
To: Berger, Shai
Cc: python-sybase@object-craft.com.au
Subject: Re: [python-sybase] Fix for rowcount


Shai.Berger@sungard.com wrote:

>I believe the current behavior is correct according to
>the DB API spec, because when a query is executed, but
>no fetch has been performed, the interface cannot determine
>the number of rows produced (second clause, not first).
> =20
>
Why? The database APIs that I have worked with give some information=20
about the size of the resultset exactly at this stage. There are of =20
minor use in a later state.

>    The attribute is -1 in case no executeXXX() has been performed on
>    the cursor or the rowcount of the last operation is not
determinable
>    by the interface.[7]
> =20
>

Well, I'm using the Sybase mudule since last summer. The behaviour=20
changed exactly with the new fetcher classes, which are new to version=20
0.36. So, until now, the interface WAS able to determine if there were=20
or were not rows.

>Peter's problems with his patch indicate that the Sybase
>module decides on its own when exactly to perform fetches
>(until the time they are actually needed, of course). In
>this case, the consistent behavior of returning -1 until
>the user actually tries to fetch something sounds preferable.
>
>To the best of my knowledge, Sybase libraries do not reliably
>report an empty query until you actually try to fetch something,
>so the problem is not with the Python module.
>
>Peter: If you absolutely need to know the number of rows before
>you try to fetch anything, you can select count(*) with the same
>tables and conditions, before your query. This will always return
>one row... In theory, it could be done in the same query (using
>the Sybase "compute" clause, returning a separate result set),=20
>but IIRC the compute results are returned only after the "regular"
>results, so you could only get to the rowcount this way by first
>discarding all the rows.
> =20
>
Well, this would blow and uglify the code in an inappropriate way. Being

forced to fire 2 queries, when only 1 is needed, means that there are=20
serious problems in the API. Then it would be preferable to catch the=20
appropriate exception.

In any case, I'm still convinced, that this is a minor bug and not a=20
fundamental issue, since it worked fine until version 0.36. But, if it=20
comes to the Sybase API, I must admit complete ingnorance.

>Hope this helps,
>	Shai.
>
> =20
>
Thank you very much for your interest,

Peter