Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Table names and number of rows

Posted on 2006-05-09
7
Medium Priority
?
699 Views
Last Modified: 2009-07-29
Hi Experts,

after selecting the database I'd like to get the table names of this database into a grid with the actual number of it's rows. Could somebody help me?

wbr Janos
0
Comment
Question by:kacor
7 Comments
 
LVL 12

Expert Comment

by:AmigoJack
ID: 16638239
that is a question on which dbms you rely.

on mysql you can use the queries SHOW TABLES; and DESC TABLE_NAME;
on oracle you have to use the queries SELECT TABLE_NAME FROM USER_ALL_TABLES; and DESC TABLE_NAME;

those queries come up with all table names and then all table collumns. if you mean "with the actual number of it's rows" that you only want to count tupels of each table, use SELECT COUNT(*) FROM TABLE_NAME; instead of DESC...
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 16638323
Hello,

Are you using BDE, ADO or what?, and which DB?

here's code to help you to return the table names using BDE and ADO, then you could easily know the number of records for each table by using "select count(*) from mytable"

for BDE, then you could use GetTableNames method to return the list of selected DB

  Database1.Aliasname := 'DBDEMOS';
  Database1.DatabaseName :='DB';
  DataBase1.GetTableNames(ListBox1.Items);

with ADO

// ConnectionString will point to your .mdb file
  AdoConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.mdb';
  AdoConnection1.Open();

//GetTableNames will bring all the tables in your mdb file, use False to not show the sytem tables
  AdoConnection1.GetTableNames(ListBox1.Items,False);

Regards,
Mohammed
0
 
LVL 10

Author Comment

by:kacor
ID: 16638562
Hi Mohammed,

thanks for your quick answer. I forgot to tell I use Interbase. I connect to the database with IBX components (D7 Interbase menu) and this method don't work. I tried to use the TSession but in this environment don't work too :-(

Janos
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Author Comment

by:kacor
ID: 16638581
AmigoJack,
 
sorry but your comment didn't appeared only the message from Mohammed. Thanks for your comment too!!

Janos
0
 
LVL 1

Accepted Solution

by:
josmx earned 2000 total points
ID: 16642322
Hello, I use Firebird 1.0.x and D7 Ent.

------ add
    Button1: TButton;
    ListBox1: TListBox;
    IBDatabase1: TIBDatabase;
    IBQuery1: TIBQuery;
    IBTransaction1: TIBTransaction;

--------- connect
    IBDatabase1 -> "database/user/password"
    IBTransaction1  -> IBDatabase1
    IBQuery1  -> IBDatabase1
    IBQuery1  -> IBTransaction1
 
--------- code
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
    tableList: TStringlist;
begin
  tableList:= TStringlist.Create;
  ListBox1.Items.Clear;
  try
    IBDatabase1.Connected:=true;
    IBDatabase1.GetTableNames(tableList,false);
    for i:=0 to tableList.Count-1 do begin
      IBQuery1.close;
      IBQuery1.SQL.Text:='select count(*) as totalrows from '+tableList.Strings[i];
      IBQuery1.Open;
      // you can change/add code here to fill Dataset + Grid
      ListBox1.Items.Add(tableList.Strings[i]+'='+IBQuery1.FieldByName('totalrows').AsString)
    end;
    IBQuery1.close;
    IBDatabase1.Connected:=false;
  finally
    tableList.Free;
  end;
end;
--------
(also have demo app)

regards
Jesus Obregon
0
 
LVL 10

Author Comment

by:kacor
ID: 16685983
Hi Jesus Obregon,

thanks for your help. I tried to run your solution above. I'm sure this is the good solution but I get the following error message:

---------------------------
Debugger Exception Notification
---------------------------
Project XX.exe raised exception class EIBClientError with message 'Operation cancelled at user's request'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

I don't made cancel. I don't understand this message.

Janos
0
 
LVL 10

Author Comment

by:kacor
ID: 16686109
Everything ok. I forgot to set the user/pw

thanks!
Janos
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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