Home > Back-end >  UniQuery1 wanted to get all the name of the table, how to write the code?
UniQuery1 wanted to get all the name of the table, how to write the code?

Time:12-08

Use UniQuery1 control link to the MYSQL database, access to all the name of the table in the database, check it on the website, MYSQL instruction is: show tables, under the mode of CMD can show all the name of the table, but use controls how operation?

UniQuery1. SQL. The Clear;
UniQuery1. SQL. Text:='show tables;
UniQuery1. Execute;

This is how the output results, read out?

CodePudding user response:

Return should use open recordset

CodePudding user response:

reference 1st floor jjpweb response:
returns the record set should use open


After the OPEN, how to write??????? Can write an example?

CodePudding user response:

Close:
SQL. Text:='select table_name from information_schema. The tables where table_schema=' 'CSDB' 'and table_type=' 'base table' ' '.
The open;
Dbgrid shows it directly,
Or
Eof do
whilt not query.The begin
Showmessage (query. Fieldbyname (" table_name "). Asstring) are identical.
Query. Next;
end;

Without mysql environment, you try,

CodePudding user response:

The
reference 3 floor jjpweb response:
close:
SQL. Text:='select table_name from information_schema. The tables where table_schema=' 'CSDB' 'and table_type=' 'base table' ' '.
The open;
Dbgrid shows it directly,
Or
Eof do
whilt not query.The begin
Showmessage (query. Fieldbyname (" table_name "). Asstring) are identical.
Query. Next;
end;

Without mysql environment, you try it,


No, this method, can only be used in the select * from (table name) after this command, the problem is that I now even the table names I don't know, need to process through the show tables to display all the name of the table, in one by one query data, I search the Internet for half a day, only to find a method code is as follows:

Form2. UniQuery2. Close;
Form2. UniQuery2. SQL. The Clear;
Form2. UniQuery2. Fields. The Clear;
Form2. UniQuery2. SQL. The Add (' show tables');
Form2. UniQuery2. Open;
STR:=Form2. UniQuery2. Fields. [0] AsString;

But this method has a problem, can only get the first name of the table, the second is to obtain an item, don't know why,

CodePudding user response:

Eof do whilt not Form2. UniQuery2.
The begin
Showmessage (Form2. UniQuery2. Fields. [0] AsString) are identical.
Query. Next;
end;

CodePudding user response:

Eof do whilt not Form2. UniQuery2.
The begin
Showmessage (Form2. UniQuery2. Fields. [0] AsString) are identical.
Form2. UniQuery2. Next;
end;

CodePudding user response:

Var tblList: TStringList;

TADOConnection after connecting to the database,
ADOConnection1. GetTableNames (tblList);

All can obtain the database, table,

CodePudding user response:

Var
LstTables: TStrings;
The begin
.
//TODO open connection
.
UniConnection1. GetTableNames (lstTables, true);
  • Related