Page 1 of 1

Query that does not return rows

Posted: Fri 21 Aug 2009 12:37
by palmquist
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

Posted: Tue 25 Aug 2009 14:42
by Dimon
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;

Posted: Tue 01 Sep 2009 11:22
by palmquist
Thank you very much for the reply Dimon!

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

Thanks again! :D

Posted: Tue 01 Sep 2009 14:15
by Dimon
It is good to see that this problem has been solved. If any other questions come up, please contact me.