version 2004 (Modified)
Definition
4th Dimension supports the BLOB (Binary Large OBjects) data type.
You can define BLOB fields and BLOB variables:
To create a BLOB field, select BLOB in the Field type drop-down-list within the Field Properties window.
To create a BLOB variable, use the compiler declaration command C_BLOB. You can create local, process, and interprocess variables of type BLOB.
Note: There is no array for BLOBs.
Within 4th Dimension, a BLOB is a contiguous series of variable length bytes, which can be treated as one whole object or whose bytes can be addressed individually. A BLOB can be empty (null length) or can contain up to 2147483647 bytes (2 GB).
BLOBs and Memory
A BLOB is loaded into memory in its entirety. A BLOB variable is held and exists in memory only. A BLOB field is loaded into memory from the disk, like the rest of the record to which it belongs.
Like the other field types that can retain a large amount of data (Picture and subtable field types), BLOB fields are not duplicated in memory when you modify a record. Consequently, the result returned by the commands Old and Modified is not significant when applied to a BLOB field.
Displaying BLOBs
A BLOB can retain any type of data, so it has no default representation on the screen. If you display a BLOB field or variable in a form, it will always appear blank, whatever its contents.
BLOB fields
You can use BLOB fields to store any kind of data, up to 2 GB. You cannot index a BLOB field, so you must use a formula in order to search records on values stored in a BLOB field.
Parameter passing, Pointers and function results
4th Dimension BLOBs can be passed as parameters to 4D commands or plug-in routines that expect a BLOB parameters. BLOBS can also be passed as parameters to a user method or be returned as a function result.
To pass a BLOB to your own methods, you can also define a pointer to the BLOB and pass the pointer as parameter.
Examples:
` Declare a variable of type BLOB C_BLOB (anyBlobVar) ` The BLOB is passed as parameter to a 4D command SET BLOB SIZE (anyBlobVar;1024*1024) ` The BLOB is passed as parameter to an external routine $errCode:= Do Something With This BLOB (anyBlobVar) ` The BLOB is passed as a parameter to a method that returns a BLOB C_BLOB (retrieveBlob) retrieveBlob:=Fill_Blob (anyBlobVar) ` A pointer to the BLOB is passed as parameter to a user method COMPUTE BLOB (->anyBlobVar )
Note for Plug-in developers: A BLOB parameter is declared as "&O" (the letter "O", not the digit "0").
Assignment
You can assign BLOBs to each other.
Example:
` Declare two variables of type BLOB C_BLOB (vBlobA;vBlobB) ` Set the size of the first BLOB to 10K SET BLOB SIZE (vBlobA;10*1024) ` Assign the first BLOB to the second one vBlobB:=vBlobA
However, no operator can be applied to BLOBs; there is no expression of type BLOB.
Addressing BLOB contents
You can address each byte of a BLOB individually using the curly brackets symbols {...}. Within a BLOB, bytes are numbered from 0 to N-1, where N is the size of the BLOB. Example:
` Declare a variable of type BLOB C_BLOB (vBlob) ` Set the size of the BLOB to 256 bytes SET BLOB SIZE (vBlob;256) ` The loop below initializes the 256 bytes of the BLOB to zero For ( vByte ; 0 ; BLOB size (vBlob)-1) vBlob{vByte}:=0 End for
Because you can address all the bytes of a BLOB individually, you can actually store whatever you want in a BLOB field or variable.
BLOBs 4th Dimension commands
4th Dimension provides the following commands for working BLOBS:
SET BLOB SIZE resizes a BLOB field or variable.
BLOB size returns the size of a BLOB.
DOCUMENT TO BLOB and BLOB TO DOCUMENT enable you to load and write a whole document to and from a BLOB (optionally, the data and resource forks on Macintosh).
VARIABLE TO BLOB and BLOB TO VARIABLE as well as LIST TO BLOB and BLOB to list allow you to store and retrieve 4D variables in BLOBs.
COMPRESS BLOB, EXPAND BLOB and BLOB PROPERTIES allow you to work with compressed BLOBs
The commands BLOB to integer, BLOB to longint, BLOB to real, BLOB to text, INTEGER TO BLOB, LONGINT TO BLOB, REAL TO BLOB and TEXT TO BLOB enable you to manipulate any structured data coming from disk, resources, OS, and so on.
DELETE FROM BLOB, INSERT IN BLOB and COPY BLOB allow quick handling of large chunks of data within BLOBs.
ENCRYPT BLOB and DECRYPT BLOB allow you to encrypt and decrypt data in a 4D database.
These commands are described in this chapter.
In addition:
C_BLOB declares a variable of type BLOB. Refer to the Compiler chapter for more information.
GET CLIPBOARD and APPEND TO CLIPBOARD enable you to deal with any data type stored in the Clipboard. Refer to the Clipboard chapter for more information.
GET RESOURCE and SET RESOURCE enable you to work with any type stored of resource stored on disk. Refer to the Resources chapter for more information.
SEND HTML BLOB enable you to send any type of data to a Web browser. Refer to the Web Server chapter for more information.
PICTURE TO BLOB, BLOB TO PICTURE and PICTURE TO GIF allow you to open and convert pictures. Refer to the Pictures chapter for more information.
GENERATE ENCRYPTION KEYPAIR and GENERATE CERTIFICATE REQUEST are encryption commands used by the SSL (Secured Socket Layer) secured connection protocol. Refer to the Secured Protocol chapter for more information.