Icon Verifying and Repairing Tables

Introduction
Verifying and repairing tables is accomplished through the VerifyTable and RepairTable methods of the TDBISAMTable component. The properties used by the VerifyTable and RepairTable methods include the DatabaseName, TableName, and Exists properties. Verifying a table will check the table for any corruption and indicate whether the table is valid or whether it is corrupted. Repairing a table will perform the actual repair of a table, which is primarily making sure that the table is structurally sound, and indicate whether the table was valid or whether it was corrupted.

Verifying a Table
To verify a table, you must specify the DatabaseName and TableName properties of the TDBISAMTable component and then call the VerifyTable method. The VerifyTable method returns True if the table is valid and False if the table is corrupted. The table component must be closed and the Active property must be False. It is usually good practice to also examine the Exists property of the TDBISAMTable component first to make sure that you don't attempt to verify a non-existent table. If you do attempt to verify a non-existent table an EDBISAMEngineError exception will be raised. The error code given when a table verification fails due to the table not existing is 11010 and is defined as DBISAM_OSENOENT in the dbisamcn unit (Delphi) or dbisamcn header file (C++). DBISAM will attempt to open the table exclusively before verifying the table. If another session has the table open then an EDBISAMEngineError exception will be raised when this method is called. The error code given when verifying a table fails due to the table being open by another session is 11013 and is defined as DBISAM_OSEACCES in the dbisamcn unit (Delphi) or dbisamcn header file (C++).

The following example shows how to verify the "customer" table using the VerifyTable method:

begin
   with MyTable do
      begin
      DatabaseName:='d:\temp';
      TableName:='customer';
      if Exists then
         begin
         if VerifyTable then
            ShowMessage('Table is valid')
         else
            ShowMessage('Table is corrupted');
         end;
      end;
end;

In addition to using the TDBISAMTable VerifyTable method for verifying tables, DBISAM also allows the use of the VERIFY TABLE SQL statement.

Logging Verification Messages
During the verification process, DBISAM will relay detailed log messages regarding the process start and stop times and any information it deems pertinent. You can trap these log messages for further display or analysis via the TDBISAMTable and TDBISAMQuery OnVerifyLog events.

Tracking the Verification Progress
To take care of tracking the progress of the verification we have provided the TDBISAMTable and TDBISAMQuery OnVerifyProgress events.

Repairing a Table
To repair a table, you must specify the DatabaseName and TableName properties of the TDBISAMTable component and then call the RepairTable method. The RepairTable method returns True if the table was valid and False if the table was corrupted and needed to be repaired. The table component must be closed and the Active property must be False. It is usually good practice to also examine the Exists property of the TDBISAMTable component first to make sure that you don't attempt to repair a non-existent table. If you do attempt to repair a non-existent table an EDBISAMEngineError exception will be raised. The error code given when a table verification fails due to the table not existing is 11010 and is defined as DBISAM_OSENOENT in the dbisamcn unit (Delphi) or dbisamcn header file (C++). DBISAM will attempt to open the table exclusively before repairing the table. If another session has the table open then an EDBISAMEngineError exception will be raised when this method is called. The error code given when repairing a table fails due to the table being open by another session is 11013 and is defined as DBISAM_OSEACCES in the dbisamcn unit (Delphi) or dbisamcn header file (C++).

The following example shows how to repair the "customer" table using the RepairTable method:

begin
   with MyTable do
      begin
      DatabaseName:='d:\temp';
      TableName:='customer';
      if Exists then
         begin
         if RepairTable then
            ShowMessage('Table was valid')
         else
            ShowMessage('Table was corrupted, check the log '+
                        'messages for repair status');
         end;
      end;
end;

In addition to using the TDBISAMTable RepairTable method for repairing tables, DBISAM also allows the use of the REPAIR TABLE SQL statement.

Logging Repair Messages
During the repair process, DBISAM will relay detailed log messages regarding the process start and stop times and any information it deems pertinent. You can trap these log messages for further display or analysis via the TDBISAMTable and TDBISAMQuery OnRepairLog events.

Tracking the Repair Progress
To take care of tracking the progress of the repair we have provided the TDBISAMTable and TDBISAMQuery OnRepairProgress events.
Image