Thread: Re: VB6 and RowCount fix
-----Original Message----- From: Ludek Finstrle [mailto:luf@pzkagis.cz] Sent: Sun 12/18/2005 1:06 AM To: Dave Page Cc: pgsql-odbc@postgresql.org Subject: Re: [ODBC] VB6 and RowCount fix > I disagree. I try your example even againist MS SQL and it still returns > -1. The test suite for VB6 RowCount you sent me doesn't work at all. The test app works perfectly well - look at the source code; all it does is report the value from ADODB.Recordset.RowCount.What is not clear, is whether that ever worked for any data provider. I always use the "while notrs.EOF..." approach when I wrote VB code in the past. Regards, Dave
> > I disagree. I try your example even againist MS SQL and it still returns > > -1. The test suite for VB6 RowCount you sent me doesn't work at all. > > The test app works perfectly well - look at the source code; all it does I took a look at t source code. But I don't know VB. > is report the value from ADODB.Recordset.RowCount. What is not clear, > is whether that ever worked for any data provider. I always use the > "while not rs.EOF..." approach when I wrote VB code in the past. I think the question is how VB get RowCount value. It seems to me that VB counts it internaly from fetched rows. I close this chapter now if noone proof the opposite. Regards, Luf
I am coming late to this thread. The issue for RowCount is not in VB, but always in ADO regardless of language, although the overwhelming majority is in VB. The key to rs.RowCount behaviour is the type of recordset cursor you are opening. For example rs.CursorLocation = adUseClient rs.Open conn, sql, adOpenStatic debug.print rs.RowCount will pull all the records into a client side recordset. while rs.CursorLocation = adUseServer rs.Open conn, sql, adOpenForwardOnly debug.print rs.RowCount will attempt to open a server side cursor, When first opened the recordset will NOT know how many rows there are (rs.RowCount = -1). You have to iterate through a server side or ForwardOnly cursor to get a recordcount. The count may not be accurate until the end of the recordset. For small recordset, clearly the client side processing is better. For large sets, like table access to millions of records, I am not sure on what is the best approach. I typically try to redefine the approach, in those situations. I make everything I can a detached client side recordset. I am unclear on what calls the ADO will make to the ODBC driver, and if DECLARE/FETCH will be triggered based on the pgodbc setup. The only thing that should reliable in any case is rs.EOF. I have not seen your sample VB code, but things like this make a huge difference. Again, I am late in having this thread grab my attention. If my remarks are off-base, please ignore then and forgive me. Ludek Finstrle wrote: >>>I disagree. I try your example even againist MS SQL and it still returns >>>-1. The test suite for VB6 RowCount you sent me doesn't work at all. >> >>The test app works perfectly well - look at the source code; all it does > > > I took a look at t source code. But I don't know VB. > > >>is report the value from ADODB.Recordset.RowCount. What is not clear, >>is whether that ever worked for any data provider. I always use the >>"while not rs.EOF..." approach when I wrote VB code in the past. > > > I think the question is how VB get RowCount value. It seems to me that > VB counts it internaly from fetched rows. > > I close this chapter now if noone proof the opposite. > > Regards, > > Luf > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match
Attachment
> I think the question is how VB get RowCount value. It seems to me that > VB counts it internaly from fetched rows. From my past experience with VB and Access, I'd say that MS option was to update RowCount in a passive way, depending on the program travel behaviour and driver capabilities. In the VB6 help information, MS isn't very clear: - For RDO, it says 'RowCount doesn't indicate how many rows will be returned by an rdoResultset query until all rows have been accessed. After all rows have been accessed, the RowCount property reflects the total number of rows in the rdoResultset. Referencing the RowCount property causes RDO to fully-populate the result set - just as if you had executed a MoveLast method.' ; - For ADO, it says 'If the Recordset object supports approximate positioning or bookmarks-that is, Supports (adApproxPosition) or Supports (adBookmark), respectively, returns True-this value will be the exact number of records in the Recordset regardless of whether it has been fully populated. If the Recordset object does not support approximate positioning, this property may be a significant drain on resources because all records will have to be retrieved and counted to return an accurate RecordCount value.'; - For DAO, it says 'The RecordCount property doesn't indicate how many records are contained in a dynaset-, snapshot-, or forward-only-type Recordset object until all records have been accessed. Once the last record has been accessed, the RecordCount property indicates the total number of undeleted records in the Recordset or TableDef object. To force the last record to be accessed, use the MoveLast method on the Recordset object. You can also use an SQL Count function to determine the approximate number of records your query will return'. I never considered RowCount to be accurate before a MoveLast or a sequence of MoveNext calls reaching EOF, because of the apparent DAO inconsistency. (There was also another curious MS feature that I learned to live with and later gave me some headaches when I began using PostgreSQL... After opening some kind of non-empty recordset, RowCount would always be > 0, although not necessarily accurate). Considering the options, and in the absence of a formal rule, I'd be happy with a documented behaviour like: - After opening a recordset, EOF signals if the recordset is empty or not; - RowCount always returns an accurate value, either because all rows have been already accessed by MoveLast or a sequence of MoveNext calls reaching EOF or because in the absence of that information RowCount actively fetches ALL rows before returning. Hélder M. Vieira