[lazarus] TDBGrid question
marc.weustink at cuperus.nl
Fri May 23 04:29:03 EDT 2003
+ From: michael at idefix.wisa.be [mailto:michael at idefix.wisa.be]On Behalf Of
+ On Fri, 23 May 2003 hernan.et at pg.com wrote:
+ > Hi Jesus,
+ > The scrollbars work for me now just fine. Here is what I did.
+ > I created another TIBQuery, this will just tell me how many
+ > records are returned based on the SQL passed. I don't
+ > understand why I can't get the number of records when using
+ > pure sql, e.g.
+ > myIBQry.SQL.Clear;
+ > myIBQry.SQL.Add('Select * from items');
+ > myIBQry.Open;
+ > myIBQry.RecordCount does not work (myIBQuery is of type TIBQuery).
+ The only way to get the number of records returned by a query,
+ is to scroll to the last record. IB does not return the number of
+ records in a result set.
+ > my second query looks like this
+ > myIBSecond.SQL.Clear;
+ > myIBSecond.SQL.Add('Select count(ID) as NumOfItems from items');
+ > myIBSecond.Open;
+ > myTDBGrid.RowCount := IntToStr(myIBSecond.Fields.AsString); //note no
+ > AsInteger I don't know why
+ > myTDBGrid.BufferCount := myTDBGrid.RowCount; //this will update
+ This is VERY bad, it will allocate a HUGE amount of memory when
+ your query returns a lot of things.
Indeed, you don't want all data at once.
Besides that. When working with databases, cursors, and transactions, there
is no one who can garantee that your second query returns the same amount of
rows as the first.
Example (based on Oracle, don't know much internal aboput other DBs)
User1: starts a transaction and adds/removes a lot of rows.
User2: runs your example part1, creating a cursor to fetch the records
User1: commits his/her changes
User2: hits your example part2, creating a cursor to fetch the count
now the number rows is different.
In general, when working with multiuser environments, you never ever even
want to think about using such constructions.
+ The buffercount of the grid (and dataset) should equal the number of
+ rows that are displayed on the screen.
More information about the Lazarus