boardtc
asked on
successive table record count problems
I present a list of databases to the user, as they scroll through them I show among other things the record count. Each time I reset the databasename and tablename for the table and call the function TableCount as follows:
label1.Caption := IntToStr(TableCount(table1 .DBHandle) );
where
function TableCount(hDb: hDBIDb): longint;
{to use the function, pass in either TDatabase.handle or
TTable.DBHandle. The TDatabase or TTable must be open in both cases}
var
hCur: hDBICur;
begin
Result := 0;
Check(DbiOpenTableList(hDb ,FALSE, FALSE, '*.*', hCur));
try
Check(DbiGetRecordCount(hC ur, Result));
finally
Check(DbiCloseCursor(hCur) );
end;
end;
The problem is that the record count does not update after the first time, it returns the same number of records everytime. Any ideas?
Thanks, Tom.
label1.Caption := IntToStr(TableCount(table1
where
function TableCount(hDb: hDBIDb): longint;
{to use the function, pass in either TDatabase.handle or
TTable.DBHandle. The TDatabase or TTable must be open in both cases}
var
hCur: hDBICur;
begin
Result := 0;
Check(DbiOpenTableList(hDb
try
Check(DbiGetRecordCount(hC
finally
Check(DbiCloseCursor(hCur)
end;
end;
The problem is that the record count does not update after the first time, it returns the same number of records everytime. Any ideas?
Thanks, Tom.
ASKER
I only do what I show. I was lead to understand that there was more overhead using recordcount. For example it's more efficient to check if both BOF and EOF are True to see if a table is empty than checking recordcount is zero. Tom.
is the line Check(DbiCloseCursor(hCur) ) always executed after the first try?
ASKER
Yes, every time a new database is selected I do
label1.Caption := IntToStr(TableCount(table1 .DBHandle) );
label1.Caption := IntToStr(TableCount(table1
So table1.Dbhandle changes from table to table? Or not? If Table1 stays table1 it's normal you don't see any change in the record count when you just browse through the table. Record count just gives the total of records.
I think you should pass the table Handle and not the Table DBHandle.
In this case you will get a compilation error because DbiOpenTableList takes a DBHandle but DbiGetRecordCount takes a handle, so I don't know how you find the Handle out of the DBHandle.
In this case you will get a compilation error because DbiOpenTableList takes a DBHandle but DbiGetRecordCount takes a handle, so I don't know how you find the Handle out of the DBHandle.
ASKER
DBHandle does change I checked that....go figure. Interesting Ronit.
Ronit...your on the right path...
Check(DbiOpenTableList(hDb ,FALSE, FALSE, '*.*', hCur));
This bde call returns the cursor to a table of all tables in the Database...in hCur
So you should always get the same value...the total number of tables
Change it to something like...
function TableCount(Value: TTable): longint;
{to use the function, pass in TTable}
var
hCur: hDBICur;
begin
Result := 0;
Check(dbiGetCursorForTable (Value.DbH andle, pchar(Value), nil, hCur));
try
Check(DbiGetRecordCount(hC ur, Result));
finally
Check(DbiCloseCursor(hCur) );
end;
end;
Rick
Check(DbiOpenTableList(hDb
This bde call returns the cursor to a table of all tables in the Database...in hCur
So you should always get the same value...the total number of tables
Change it to something like...
function TableCount(Value: TTable): longint;
{to use the function, pass in TTable}
var
hCur: hDBICur;
begin
Result := 0;
Check(dbiGetCursorForTable
try
Check(DbiGetRecordCount(hC
finally
Check(DbiCloseCursor(hCur)
end;
end;
Rick
ASKER
Rick,
Thanks for the respose. I tried your implementation, passing in ttable (tablename and databasename set, active is True) I get the error - unable to open object on the line:
Check(dbiGetCursorForTable (Value.DbH andle, pchar(Value), nil, hCur));
Any ideas? Thanks, Tom.
Thanks for the respose. I tried your implementation, passing in ttable (tablename and databasename set, active is True) I get the error - unable to open object on the line:
Check(dbiGetCursorForTable
Any ideas? Thanks, Tom.
Okay this works...opps on the pchar value...should be pchar(Value.TableName) not pchar(Value)
function TForm1.TableCount(Value: TTable): longint;
{to use the function, pass in TTable}
var
hCur: hDBICur;
begin
if not Value.Active then
Value.open;
Result := 0;
Check(dbiGetCursorForTable (Value.DbH andle, pchar(Value.TableName), nil, hCur));
Check(DbiGetRecordCount(hC ur, Result));
(* Check(DbiCloseCursor(hCur) );
Don't need to close as dbiGetCursorForTable only returns an existing cursor.
*)
end;
function TForm1.TableCount(Value: TTable): longint;
{to use the function, pass in TTable}
var
hCur: hDBICur;
begin
if not Value.Active then
Value.open;
Result := 0;
Check(dbiGetCursorForTable
Check(DbiGetRecordCount(hC
(* Check(DbiCloseCursor(hCur)
Don't need to close as dbiGetCursorForTable only returns an existing cursor.
*)
end;
ASKER
Rick,
That worked geat, I shoud have checked the BDE help myself. Thanks for the DBiCloseCursor info. Put in a dummy answer and I'll grade. Tom.
That worked geat, I shoud have checked the BDE help myself. Thanks for the DBiCloseCursor info. Put in a dummy answer and I'll grade. Tom.
Tom...this one's on me...
I owe you...for that last one...
Also you don't need to even use...
Check(dbiGetCursorForTable (Value.DbH andle, pchar(Value.TableName), nil, hCur));
since Table1.handle is a hDBICur.
from TBDEDataSet help
property Handle: HDBICur;
Rick
I owe you...for that last one...
Also you don't need to even use...
Check(dbiGetCursorForTable
since Table1.handle is a hDBICur.
from TBDEDataSet help
property Handle: HDBICur;
Rick
ASKER
Rick,
Nice one. After all that it come down to:
function TableCount(tbl: TTable): longint;
{ the TTable must be open }
begin
Check(DbiGetRecordCount(tb l.Handle, Result));
end;
That's generous of you. Should I just delete?
Tom.
Nice one. After all that it come down to:
function TableCount(tbl: TTable): longint;
{ the TTable must be open }
begin
Check(DbiGetRecordCount(tb
end;
That's generous of you. Should I just delete?
Tom.
Yes...
Rick
Rick
or just set the value to 0
Rick
Rick
ASKER
Thing is I'd like to make this available, you can't decrease the points. I have no worries giving them to you. Tom.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
why don't u use the recordcount property?