Recent

Author Topic: Problem with select queries.  (Read 4612 times)

nazim

  • Guest
Problem with select queries.
« on: December 05, 2005, 12:12:34 am »
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: [Select]
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;


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

  • Sr. Member
  • ****
  • Posts: 491
RE: Problem with select queries.
« Reply #1 on: December 05, 2005, 07:52:41 am »
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: [Select]

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;


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

  • Guest
Problem with select queries.
« Reply #2 on: December 05, 2005, 07:41:26 pm »
Thank you very much Jesus, the alterations you made work perfectly.

 

TinyPortal © 2005-2018