[yunqa.de] Re: DISQLite and record count

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Fri, 26 Jun 2009 18:10:14 +0200

At 08:29 25.06.2009, Gregory Whitesides wrote:

>How to get record count (row count) for this query?

You can retrieve the record count for any query by simply wrapping your query 
like this:

  SELECT count() FROM (SELECT ...);

>const
>  SQL_SELECT =
>'SELECT otip.name tip, ovid.name vid, number, SUM(prob) FROM auto '+
>'JOIN others otip ON otip.id=auto.idt '+
>'JOIN others ovid ON ovid.id=auto.idk '+
>'JOIN data ON (dateb>=? AND dateb<=?) AND auto.idt IN (31,32,33,37) AND 
>data.ida=auto.id '+
>'GROUP BY number '+
>'ORDER BY tip, vid';
>
>      Stmt := DM.DB.Prepare16(SQL_SELECT);
>      try
>        Stmt.Bind_Double(1, beg);
>        Stmt.Bind_Double(2, fin);
>        while Stmt.Step = SQLITE_ROW do 
>        begin
>          // some actions with the result values
>        end;
>      finally
>        Stmt.Free;
>      end;
>
>Basically, all I need the Record Count for is to set the max property of a 
>progress bar. 

Please know that counting does not come for free. DISQLite3 must iterate all 
records to determine the record count. With counting, you will end up running 
the query twice: One time to count the records, and a second time to retrieve 
the data. It goes without saying that two runs will take more time than just a 
single one to read the records without prior counting.

Ralf 

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: