Forum > Databases

Problem with select queries.

(1/1)

nazim:
I'm currently using embedded Firebird 1.5 with the SQLdb components. If I use code such as that below, without going through a data source and db components, and ask for the record count of the query, I only ever get a maximum of 10 results. However, when I attach a data source along with a db grid, I can see all of the results.


--- Code: ---with query do
begin
  close;
  sql.clear;
  sql.add('SELECT * FROM table;');
  open;

  if RecordCount > 0 then
  begin
    StringGrid1.RowCount := RecordCount + 1;

    for i := 1 to RecordCount do
    begin
      StringGrid1.Cells[1, i] := fields.FieldByName('id').AsString;
      next;
    end;
  end;
end;

--- End code ---


I've also tried using the FIBL and Interbase components and have observed the same behaviour, although I did not have this problem with the ZEOS library (which I cannot use because of the problem with the date fields).

Does any one know what I'm doing wrong?

Many thanks.

jesusr:
What happen is that dataset has a default buffer count of 10, so when you open the query that's the max amount of records already on buffers, this is further enforced by the fact that you use a for loop limited by the amout of 10 records.

this variant might help:

--- Code: ---
with query do
begin
 close;
 sql.clear;
 sql.add('SELECT * FROM table;');
 open;
 i:=0;
 StringGrid1.RowCount:=1; // just the column headers :)
 while not EOF do
 begin
  inc(i);
  StringGrid1.RowCount := i+1;
  StringGrid1.Cells[1, i] := FieldByName('id').AsString;
  next;
 end;
end;

--- End code ---


Untested!, you might consider to retrieve the amount of records by a query like 'SELECT COUNT(id) from Table' if you really want that.

nazim:
Thank you very much Jesus, the alterations you made work perfectly.

Navigation

[0] Message Index

Go to full version