Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Success of a Table Verify??
Wed, Mar 22 2023 6:30 PMPermanent Link

Ian Branch

Avatar

Hi Team,
I use the following on code to Verify a table..
{code}
....
 //
 try
   Memo1.Lines.Add('      - Verifying.');
   //
 var Thread := TThread.CreateAnonymousThread(
     procedure
     begin
       //
       DBC1.Execute('Verify Table ' + aDataTables[nXt, 0]);
       //
     end);
   try
     Thread.FreeOnTerminate := False;
     //
   var H := Thread.Handle;
     //
     Thread.Start;
     while MsgWaitForMultipleObjects(1, H, False, INFINITE, QS_ALLINPUT) = (WAIT_OBJECT_0 + 1) do
       Application.ProcessMessages;
   finally
     FreeAndNil(Thread);
   end;
   //
   Memo1.Lines.Add('      - Verification completed.');
   //
 except
   //
....
{code}

How can I determine if the Verify was successful or found an issue?

Regards & TIA,
Ian
Thu, Mar 23 2023 2:07 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Ian


Lazy way of answering your question I have a script

SCRIPT(IN TableName VARCHAR COLLATE ANSI_CI, IN StructureOnly BOOLEAN, OUT OK BOOLEAN)
BEGIN
DECLARE Stmt STATEMENT;
PREPARE Stmt FROM 'VERIFY TABLE '+QUOTEDSTR(TableName,'"') + IF(StructureOnly,' STRUCTURE ONLY','');
EXECUTE Stmt;
SET OK =  STMTRESULT(Stmt);
END

and check the OUT parameter OK. The Delphi procedure in full is

procedure TRandOTablesForm.DoItClick(Sender: TObject);
var
Cntr: integer;
DoFilter: boolean;
LogFile: string;
begin
slAll.Clear;
DoFilter := False;
if Mode.Checked[0] then iMode := 'VQ'
else if Mode.Checked[1] then iMode := 'VF'
else if Mode.Checked[2] then iMode := 'REPAIR'
else if Mode.Checked[3] then iMode := 'OPTIMIZE';
DoIt.Visible := False;
Update;
Progress.Visible := True;
for Cntr := 1 to 4 do TableList.DataStores[Cntr].Data.Clear;
TableList.Reset;
TableList.First;
while not TableList.Eof do begin
 slTable.Clear;
 Progress.BlankBar;
 if Tables.SelectedRows.CurrentRowSelected then begin
  UpdateDateTime(TableList_Started);
  Tables.SelectedRows.CurrentRowSelected := False;
  UpdateStatus('Processing');
  if iMode[1] = 'V' then begin
   Panel1.Visible := True;
   nlhWaiter1.Waiting := True;
   UpdateStatus('Checking');
   ValidateTable.Close;
   if not ValidateTable.Prepared then ValidateTable.Prepare;
   ValidateTable.ParamByName('TableName').AsString := TableList_Table.AsString;
   ValidateTable.ParamByName('StructureOnly').AsBoolean := iMode = 'VQ';
   ValidateTable.ExecScript;
   if not ValidateTable.ParamByName('OK').AsBoolean then UpdateStatus('ok') else begin
    UpdateStatus('NEEDS REPAIR');
    Tables.SelectedRows.CurrentRowSelected := True;
    DoFilter := True;
    slAll.Add(slTable.Text);
   end;
   ValidateTable.Close;
   nlhWaiter1.Waiting := False;
  end else if iMode[1] = 'R' then begin
   DeleteFile(TableList_Table.AsString + dm.TfrSession.LocalTableIndexExtension);
   Actioneer.Close;
   Actioneer.SQL.Text := 'REPAIR TABLE ' + TableList_Table.AsString;
   Progress.Initialise(0, 100, TableList_Table.AsString);
   Actioneer.ExecSQL;
   UpdateStatus('Repaired');
  end else if iMode[1] = 'O' then begin
   Actioneer.Close;
   Actioneer.SQL.Text := 'OPTIMIZE TABLE ' + TableList_Table.AsString;
   Progress.Initialise(0, 100, TableList_Table.AsString);
   Actioneer.ExecSQL;
   UpdateStatus('Optimised');
  end;
  UpdateDateTime(TableList_Finished);
 end else UpdateStatus('Not processed');
 TableList.Next;
end;
Actioneer.Close;
DoDBCleanup;
slTable.Clear;
if DoFilter then begin
 TableList.Filter := '_Status <> ''ok''';
 TableList.Filtered := True;
 TableList.First;
 Update;
 Cntr := 0;
 LogFile := 'Validation';
 while FileExists(TemporaryFile(LogFile + IntToStr(Cntr) + '.log')) do inc(Cntr);
 LogFile := TemporaryFile(LogFile + IntToStr(Cntr) + '.log');
 emfOpener.AddFileToRelease('Validation', LogFile);
 slAll.SaveToFile(LogFile);
 ShellExecute(Application.Handle, nil, PChar(LogFile), nil, nil, SW_SHOW);
end;
slAll.Clear;
DoIt.Visible := True;
Progress.Visible := False;
nlhWaiter1.Waiting := False;
Panel1.Visible := False;
end;


Roy Lambert
Image