Tech Tip: Generic method to resave (massage) all data
PRODUCT: 4D | VERSION: 12.1 | PLATFORM: Mac & Win
Published On: May 20, 2011
Here is a generic method that loops through an entire database and resaves all of the data contained within:
C_LONGINT($numTables;$tableNum;$numFields;$fieldNum) C_POINTER($fieldPtr) C_TEXT($field) $numTables:=Get last table number If ($numTables>0) For ($tableNum;0;$numTables) If (Is table number valid($tableNum)) ALL RECORDS(Table($tableNum)->) While (Not(End selection(Table($tableNum)->))) $numFields:=Get last field number($tableNum) For ($fieldNum;0;$numFields) If (Is field number valid($tableNum;$fieldNum)) $fieldPtr:=Field($tableNum;$fieldNum) $field:="id_added_by_converter" If (Type($fieldPtr->)#Is Subtable) & (Field name($fieldPtr)#$field) // does not work for subtable field $fieldPtr->:=$fieldPtr-> End if End if End for SAVE RECORD(Table($tableNum)->) NEXT RECORD(Table($tableNum)->) End while End if End for End if |
This may be useful in certain situations where you think that the saved data may not represent the defined data type. This can happen, for example, if you change the type of a field after already creating records. The data that was previously saved does not get altered when making this type of structure change.