Article View: borland.public.delphi.database
Article #2046Re: ADO
From: Ray Porter
Date: Thu, 17 Dec 1998 00:00
Date: Thu, 17 Dec 1998 00:00
76 lines
3802 bytes
3802 bytes
ADO is Microsoft's new 'universal' data access technology (I think the acronym stands for 'ActiveX Data Objects') built atop OLE DB. That probably means that the original poster has imported the ADO type library or is using CreateOleObject and variants to get to ADO (i.e., no BDE). However, Marco's reasoning is still probably correct. In many cases, regardless of whether you are using the BDE, Jet/DAO or direct ODBC or any other data transport layer, RecordCount is unreliable until you have fetched all the records in the resultset. I haven't used ADO yet myself but my guess is that this is what is happening. Marco's suggestions are your best bet for getting an accurate count. On Wed, 16 Dec 1998 12:09:41 GMT, mrocciNOSPAM@tin.it (Marco Rocci) wrote: >Hi, > >On Mon, 7 Dec 1998 23:07:03 +0100, "Stefan Gevaert" ><stefan.gevaert@ping.be> wrote: > >>I am experimenting with ADO and Delphi. Everything works fine, except the >>RecordCount Property of the Recordset always returns -1. > >(I don't know what ADO is, but...) > >RecordCount=-1 means BDE does not know yet how many records there will >be. BDE does not support RecordCount for most SQL engines unless you >do a fetch all. This is logical as one of the reasons to use engines >is to reduce network traffic. To know how many records there are, >these MUST be fetched from the engine. Since fetching the entire >result set just to know how many records there are is not very >efficient (read: it is potentially TIME CONSUMING) then BDE will not >do it just because you access the RecordCount property. > >If you really need to know the number of records, then I suggest: > > * if the result set is small (10 records) and you intend to read >through it programmatically anyway, then: > Last; > First; > This will fetch the records, and you should be able to have a >proper RecordCount value. The fetched data should then be cached and >a following While Not Eof loop should not create any more network >traffic. > > * if you have no idea of how big the result set will be, if you are >certain it will be big or if you are not sure you will read through it >anyway then: > use a second TQuery similar to: > SELECT COUNT(*) FROM ...<same as 1st query>... > and have the engine calculate the number of records in the result >set. > >Last but not Least, if you only need to test IF there are ANY records >(RecordCount>0 or RecordCount=0), than use the boolean IsEmpty method >instead of the RecordCount property. This does not fetch all the >data. > >Regards, > >-- >Marco Rocci >MicroEra srl >Turin, Italy ================================== Ray Porter Applications Analyst Programmer Administrative Information Services The University of North Carolina at Chapel Hill Phone: 919-966-5878 Home Page: http://www.unc.edu/~dragon/ "Meddle not in the affairs of dragons, for you are crunchy and taste good with ketchup."
Technical Details
Message-ID:
<36790604.4314156@news.oit.unc.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<74hjcm$t5t$1@news3.Belgium.EU.net> <367786d9.2581448@tor-nn1-ca.netcom.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: ffff5,b5e688e60f91bc45 X-Google-Attributes: gidffff5,public X-Google-Thread: f6386,b5e688e60f91bc45 X-Google-Attributes: gidf6386,public X-Google-Thread: 115d96,b5e688e60f91bc45 X-Google-Attributes: gid115d96,public X-Google-Thread: fd196,b5e688e60f91bc45 X-Google-Attributes: gidfd196,public From: lrp@email.ais.unc.edu (Ray Porter) Subject: Re: ADO Date: 1998/12/17 Message-ID: <36790604.4314156@news.oit.unc.edu> X-Deja-AN: 423253702 References: <74hjcm$t5t$1@news3.Belgium.EU.net> <367786d9.2581448@tor-nn1-ca.netcom.ca> Organization: Administrative Information Services, UNC-CH Newsgroups: borland.public.delphi.database,borland.public.delphi.database.multi-tier,borland.public.delphi.oleautomation,comp.lang.pascal.delphi.databases