Check the tables that appear on my first Dbgrid

Asked

Viewed 82 times

1

Follows 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 to the end of the lines found in showTables(which is situated on the first dbgrid), my check read all lines (With the Tables) and consequently give a check in another dbgrid, how do I do this?

Updated code

1 answer

1


I can’t 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 while, the created parameter mounts the list of tables to be viewed in the Check Tables command. Therefore Parameter = Parameter(all tables that Voce has done so far) + , + new table to be checked.

  • what would be the record quantity command you commented on?

  • it is giving a Syntax SQL error.

  • It depends on its component. In a TClientDataSet for example is CDS.RecordCount

  • Put a breakpoint on DataModule1.ZQuery2.Open; and pass me the value of DataModule1.ZQuery2.Sql.Text

  • he managed to make a test, the problem was in the parameter itself, ',' + He’s doing all the checking, but it doesn’t show everything.

  • It doesn’t show everything because you took out the comma! Put Parametro := Parametro + ', ' + edtDB.Text + '.' + DataModule1.ZQuery1.FieldByName('Tables_in_' + edtDB.Text).asString);

  • 1

    It worked, it worked!!!

  • I edited with the while explanation. As for the Pair, it’s another (almost)completely different story.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.