Tech Tip: Clear the contents of a record
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: March 8, 2018
Here is a utility method to clear the contents of a record except for the fields that contain a primary key:
// ---------------------------------------------------------------------- // Name: CLEAR_RECORD_DATA // Description: Method will record selection and clear the contents of the // records except the fields that contain a primary key. // // Parameters: // $1 (POINTER) - Pointer to the table // ---------------------------------------------------------------------- C_POINTER($1;$table;$fieldPtr) C_LONGINT($i;$j;$tableNum;$fields;$pkFieldNum;$type) if (Count parameters=1) $table:=$1 $tableNum:=Table($table) $fields:=Get last field number($tableNum) // Checking for Primary Key Begin SQL SELECT COLUMN_ID FROM _USER_CONS_COLUMNS WHERE TABLE_ID = :$tableNum INTO :$pkFieldNum; End SQL For ($j;1;records in selection($table->)) For ($i;1;$fields) $fieldPtr:=Field($tableNum;$i) $type:=Type($fieldPtr->) If (is field number valid($tableNum;Field($fieldPtr))=true) If ($pkFieldNum#$i) Case of : ($type=Is alpha field) $fieldPtr->:="" : ($type=Is text) $fieldPtr->:="" : (($type=Is longint)|($type=Is integer 64 bits)|($type=Is integer)) $fieldPtr->:=0 : ($type=Is Boolean) $fieldPtr->:=False : ($type=Is real) $fieldPtr->:=0 : ($type=Is float) $fieldPtr->:=0 : ($type=Is time) $fieldPtr->:=Time(0) : ($type=Is date) $fieldPtr->:=Date("00/00/00") : ($type=Is BLOB) C_BLOB($blob) $fieldPtr->:=$blob : ($type=Is picture) C_PICTURE($pic) $fieldPtr->:=$pic : ($type=Is object) C_OBJECT($obj) $fieldPtr->:=$obj End case End if End if End for SAVE RECORD($table->) NEXT RECORD($table->) End for End if |
Here is an example of some data:
Here is example of clearing the data:
Query([Table_1];[Table_1]ID>=10) CLEAR_RECORD_DATA(->[Table_1]) |