Check in the tables that appear in my first DBGrid

1

Follow the code:

var
  i : integer;
begin
  i := 0;

  DataModule1.ZConnection1.Database :=  edtDB.Text;
  DataModule1.ZConnection1.HostName := edtLocal.Text;
  DataModule1.ZConnection1.User := 'root';

  DataModule1.ZQuery1.Close;
  DataModule1.ZQuery1.SQL.Clear;
  DataModule1.ZQuery1.SQL.Add('SHOW TABLES FROM '+edtDB.Text);
  DataModule1.ZQuery1.Open;

  while not DataModule1.ZQuery1.Eof do
  begin
    inc(i);
    DataModule1.ZQuery2.Close;
    DataModule1.ZQuery2.SQL.Clear;
    DataModule1.ZQuery2.SQL.Add('CHECK TABLE ' + edtDB.Text + '.' +
      DataModule1.ZQuery1.FieldByName('Tables_in_' + edtDB.Text).asString);
    DataModule1.ZQuery2.ExecSQL;
    DataModule1.ZQuery1.Next;
  end;

What I want is that by the end of the lines found in showTables (which is situated in the first dbgrid), my check reads all lines (with tables) and consequently give a check in another dbgrid, how do I do this?

Updated Code

    
asked by anonymous 21.05.2014 / 14:01

1 answer

1

I can not be sure without seeing who dbShow is, but try the following:

   
DataModule1.ZQuery1.Close;
DataModule1.ZQuery1.SQL.Clear;
DataModule1.ZQuery1.SQL.Add('SHOW TABLES FROM '+edtDB.Text);
DataModule1.ZQuery1.Open;
while not DataModule1.ZQuery1.Eof do
begin
  DataModule1.ZQuery2.Close;
  DataModule1.ZQuery2.SQL.Clear;
  DataModule1.ZQuery2.SQL.Add('CHECK TABLES '+dbShow.Fields[i].Text);
  DataModule1.ZQuery2.ExecSQL;
  DataModule1.ZQuery1.Next;
end;

After knowing in the comments that this function should show the result of ZQuery2 in a dbgrid, follows change:

   
DataModule1.ZQuery1.Close;
DataModule1.ZQuery1.SQL.Clear;
DataModule1.ZQuery1.SQL.Add('SHOW TABLES FROM '+edtDB.Text);
DataModule1.ZQuery1.Open;
DataModule1.ZQuery1.First;
Parametro := '';
Parametro := edtDB.Text + '.' + DataModule1.ZQuery1.FieldByName('Tables_in_' + edtDB.Text).asString);
if DataModule1.ZQuery1.RecordCount > 1 then //Substitua pelo comando de quantidade de registros
  DataModule1.ZQuery1.Next;
while not DataModule1.ZQuery1.Eof do
begin
  Parametro := Parametro + ', ' + edtDB.Text + '.' + DataModule1.ZQuery1.FieldByName('Tables_in_' + edtDB.Text).asString);
  DataModule1.ZQuery1.Next;
end;
  DataModule1.ZQuery2.Close;
  DataModule1.ZQuery2.SQL.Clear;
  DataModule1.ZQuery2.Sql.Text := 'Check tables ' + Parametro;
  DataModule1.ZQuery2.Open;

If you debug the while, the parameter you create mounts the list of tables to be viewed in the Check Tables command. So Parameter = Parameter (all the tables you have made so far) +, + new table to be checked.

    
21.05.2014 / 14:18