KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Steps to repurpose a blob or picture field
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: July 25, 2013

It is not uncommon for developers to change the data type of a field. If a field type is picture or blob and needs to be repurposed, the developer needs to keep in mind that any existing records created prior to changing the field type will cause an orphan blob.

To avoid the creation of orphan blobs, it is best to delete all records prior to changing the field type. However, this is not always a viable solution because data may be stored in the other fields of the table. One way to avoid orphan blobs while preserving the data is to set all blob/picture sizes to zero for the fields that are being repurposed.

Example for blob field:

C_BLOB($blob)

ALL RECORDS([Table_1])
While (Not(End Selection([Table_1])))
 $blob:=[Table_1]Field_1
 SET BLOB SIZE($blob;0)
 [Table_1]Field_1:=$blob
 SAVE RECORD([Table_1])
 NEXT RECORD([Table_1])
End While


The SET BLOB SIZE command clears the blob by setting the size to zero.

For picture fields, the pictures can be reassigned to an empty picture, as follows:

C_PICTURE($picture)

ALL RECORDS([Table_1])
While (Not(End Selection([Table_1])))
 [Table_1]Field_1:=$picture
 SAVE RECORD([Table_1])
 NEXT RECORD([Table_1])
End While


Once the blob or picture field is set to zero, the developer can change the field type without causing orphan blobs.

See Also: