KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Saving database table information to a file
PRODUCT: 4th Dimension | VERSION: 2003.2 | PLATFORM: Mac & Win
Published On: March 18, 2004

Before performing 'Recover by Tag' using 4D tools, it is a good practice to take note of the number of records before recovery and after recovery to check if data has been lost. The code below will allow you to get the names of the tables and the number of records per table, and then, save the information to a file.

C_INTEGER($numTables)
C_INTEGER($numRecords;$Spaces)
C_TIME(vhDocRef)

vhDocRef:=Create document("C:\\RecordCount.txt")  `Modify document name after database recovery
$numTables:=Count tables  `count number of tables
SEND PACKET(vhDocRef;" Number of Tables : "+String($numTables)+Char(13)+Char(10))
SEND PACKET(vhDocRef;" Table Name        - # of Records "+Char(13)+Char(10))
ARRAY STRING(50;asTables;$numTables)

For ($vlTable;1;Size of array(asTables))
  asTables{$vlTable}:=Table name($vlTable)  ` get table name
  TablePtr:=Table($vlTable)
  $numRecords:=Records in table(TablePtr->)  ` get number of records of table
  SEND PACKET(vhDocRef;" "+asTables{$vlTable})
  $Spaces:=30-Length(asTables{$vlTable})
  If ($Spaces>0)  ` fill spaces
   For ($index;1;$Spaces)
    SEND PACKET(vhDocRef;" ")
   End for
  End if
  SEND PACKET(vhDocRef;" - "+String($numRecords)+Char(13) +Char(10))
End for

SEND PACKET(vhDocRef;Char(13)+Char(10))
CLOSE DOCUMENT(vhDocRef)