Using Fetchall and fetchrows

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ChuckBBN
Posts: 1
Joined: Sun 29 Mar 2009 06:07

Using Fetchall and fetchrows

Post by ChuckBBN » Sun 29 Mar 2009 06:13

OK, maybe this is a dumb question as I'm just getting up to speed on these components.

I need to retrieve a small number of records on each search as I could have potentially several hundred to a thousand or more for any given search match. I only need to look at them 20 or so at a time.

To test the fetchall=false for TMyquery I set fetchrows to 5 to make sure it was working, with display in a TDBGrid.

No matter what I set for FetchRows I get all the records that match the SQL search, not the first X records. That is I set it to 5, but the grid shows all the records that match, in this case 10 records.

Here's the SQL if that's relevant:

MyQuery1.Close;{close the query}
//assign new SQL expression
MyQuery1.SQL.Clear;
MyQuery1.SQL.Add ('Select *');
MyQuery1.SQL.Add ('FROM clients');
MyQuery1.SQL.Add ('WHERE last_name LIKE '''+SearchName.Text+'%''');
MyQuery1.Open;

Any ideas what stupid thing I'm doing wrong? Thanks in advance.

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

Post by Dimon » Mon 30 Mar 2009 07:00

When you set the FetchAll property to False, then on opening dataset the FetchRows rows will be fetched from database and control will be returned to the application. But the rest of the records will be retrieved when a data-aware component or a program requests it. In you case the TDBGrid component requests as many records as it can show on display.
If you need to get only X records with one SQL query you should use the LIMIT statement in your query.

Post Reply