[egenix-users] cursor.rowcount abnormalities and performance question

Tim Golden tim.golden at viacom-outdoor.co.uk
Thu Jul 31 11:41:40 CEST 2003


> From: stuff at mailzilla.net [mailto:stuff at mailzilla.net]
> I guess I shouldn't be too surprised that MS doesn't provide a mechanism
> for retrieving the number of rows but it is rather comical that they do
> provide 2 distinct values which you can at least (hopefully, correctly)  
> infer that there are 0 rows that match -or- at least 1 row that matches.  
> You'd think that they could go the proverbial extra mile and provide a
> real value in the latter case, but then again, it would probably put a
> huge load on SQL Server.  Cynicism of MS aside, at least I can safely test

> for the existence of data using cursor.rowcount != 0.

I haven't tried out the ODBC issues discussed 
 in this thread already, but just for the record,
 SQL Server *itself* does provide a rowcount so if I do
 something like this in Query Analyzer:

<code>
SELECT client_code
FROM clients
WHERE client_code BETWEEN 1000200 AND 1000205

SELECT @@ROWCOUNT
</code>

I get this:

<results>
client_code 
----------- 
1000200
1000201
1000202
1000203
1000204
1000205

(6 row(s) affected)
           
----------- 
6

(1 row(s) affected)
</results> 

and if I do the same thing using Dave Cole's MSSQL module:

<code>

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MSSQL
>>> db = MSSQL.connect ("VODEV1", "", "", "DEV")
>>> q = db.cursor ()
>>> q.execute ("SELECT client_code FROM clients WHERE client_code BETWEEN
1000200 AND 1000210")
>>> q.rowcount
-1
>>> y = db.cursor ()
>>> y.execute ("SELECT @@ROWCOUNT")
>>> y.fetchone ()
(11,)
>>> q.rowcount
-1
>>> rows = q.fetchone ()
>>> q.rowcount
-1
>>> rows = q.fetchall ()
>>> q.rowcount
-1

</code>

Don't know if that helps, but it was fun finding out.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the egenix-users mailing list