Solved

successive table record count problems

Posted on 1998-05-26
17
226 Views
Last Modified: 2011-10-03
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(hCur, 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.
0
Comment
Question by:tomcorcoran
  • 7
  • 6
  • 2
  • +2
17 Comments
 
LVL 2

Expert Comment

by:kjteng
ID: 1347945
did u set any range limit?
why don't u use the recordcount property?
0
 

Author Comment

by:tomcorcoran
ID: 1347946
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.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347947
is the line Check(DbiCloseCursor(hCur)) always executed after the first try?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:tomcorcoran
ID: 1347948
Yes, every time a new database is selected I do
label1.Caption := IntToStr(TableCount(table1.DBHandle));

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347949
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.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1347950
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.
0
 

Author Comment

by:tomcorcoran
ID: 1347951
DBHandle does change I checked that....go figure. Interesting Ronit.
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347952
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.DbHandle, pchar(Value), nil, hCur));
   try
      Check(DbiGetRecordCount(hCur, Result));
   finally
      Check(DbiCloseCursor(hCur));
   end;
end;

Rick
0
 

Author Comment

by:tomcorcoran
ID: 1347953
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.DbHandle, pchar(Value), nil, hCur));

Any ideas? Thanks, Tom.        
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347954
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.DbHandle, pchar(Value.TableName), nil, hCur));
   Check(DbiGetRecordCount(hCur, Result));
(*     Check(DbiCloseCursor(hCur));
Don't need to close as dbiGetCursorForTable only returns an existing cursor.
*)
end;

0
 

Author Comment

by:tomcorcoran
ID: 1347955
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.
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347956
Tom...this one's on me...

I owe you...for that last one...

Also you don't need to even use...
   Check(dbiGetCursorForTable(Value.DbHandle, pchar(Value.TableName), nil, hCur));

since Table1.handle is a hDBICur.
from TBDEDataSet help
property Handle: HDBICur;

Rick
0
 

Author Comment

by:tomcorcoran
ID: 1347957
Rick,

Nice one. After all that it come down to:

function TableCount(tbl: TTable): longint;
{ the TTable must be open }
begin
   Check(DbiGetRecordCount(tbl.Handle, Result));
end;

That's generous of you. Should I just delete?

Tom.

0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347958
Yes...

Rick
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1347959
or just set the value to 0

Rick
0
 

Author Comment

by:tomcorcoran
ID: 1347960
Thing is I'd like to make this available, you can't decrease the points. I have no worries giving them to you. Tom.
0
 
LVL 3

Accepted Solution

by:
rickpet earned 50 total points
ID: 1347961
Okay then...I'll tell you what...I'll write a component for you...something like TStatusbar that will use what I call Beveled Labels.  They're like Labels(low on resources) but have bevels like panels.  Email me for the component rickpet@airmail.net

Rick
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question