Query that does not return rows

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
palmquist
Posts: 4
Joined: Fri 21 Aug 2009 12:04

Query that does not return rows

Post by palmquist » Fri 21 Aug 2009 12:37

I'm kind of a beginner in the MyDac components and therefore have a question that i hope someone can answer.

i.e I would like to count the rows in a whole table. What I've done so far is:

TableName->FilterSQL = ""; // To remove earlier FilterSQL properties.
IntVar = TableName->RecordCount;

This is however pretty slow when the amount of rows exceeds 10000 and more. And I was thinking if I could let the MySQL server handle this calculation by calling a Query like:

SELECT COUNT (*) FROM TableName;

Am I right if I'm saying that this function does not return any rows however it return a INT value. How do I extract this value?

How would I do this? What Components would I use? A simple example would be very much appreciated :D

Best regards,
Hannes Palmquist

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 25 Aug 2009 14:42

To solve this problem you can use the TMyQuery component and the following code:

Code: Select all

MyQuery.SQL.Clear;
MyQuery.SQL.Add('SELECT COUNT (*) FROM TableName;');
MyQuery.Open;
RecCount := MyQuery.Fields[0].AsInteger;

palmquist
Posts: 4
Joined: Fri 21 Aug 2009 12:04

Post by palmquist » Tue 01 Sep 2009 11:22

Thank you very much for the reply Dimon!

I've cut the calculation times with 74% with this solution!

Thanks again! :D

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 01 Sep 2009 14:15

It is good to see that this problem has been solved. If any other questions come up, please contact me.

Post Reply