4D v14

BLOBs

Home

 
4D v14
BLOBs

BLOBs    


 

 

In addition to the manipulations explained in the video, you should also note the following:

When starting out, we always ask the same questions:

  • What good can this serve and under what circumstances?
  • I’m fine with putting “things” inside, but how? and in what order will I get them back out?

Let’s start by tackling the second question:

Even though we can access any byte of the BLOB, in most cases we’ll use what we call FIFO (First In First Out). This means that you retrieve the content of the BLOB in the order in which you put it into the BLOB.
To make a simple analogy, let’s take a bookshelf where you put away books from left to right. You start by putting away a small book on the left and then a large book next to the first one, and then another big book and then a picture of your mother-in-law and a knick-knack from last summer’s vacation, etc. When its time to dust the bookshelf, you don’t think about how many inches from the left side a book is located. You take them in the order they are and you adjust your gaze (and hands) depending on the size of the last object picked.

It’s the same thing in a BLOB, especially because you know what you put away in the BLOB.

For example, when you put away:

  • an integer, it’s 2 bytes
  • a long integer is 4 bytes
  • while a date is 6 bytes long
  • and so on.
  • For text, you indicate how you want it put away and how the length of the text is expressed (C string, Pascal string, etc.).

When re-reading, you will take the information in the same order again and put it away in variables that are adapted to the expected content (typed correctly).

This way the BLOB is read in a consistent manner.
Here’s the answer to the first question (what is the purpose of a BLOB?) You can use a BLOB, for example, in the following cases:

  • To store variables, hierarchical lists, arrays
  • To exchange documents between client and server
  • To protect confidential data in an encrypted BLOB
  • To save variables containing plug-ins
  • To send pictures, texts, or documents to a Web browser
  • To communicate with a web service.

The VARIABLE TO BLOB command stores the data in a format internal to 4D. That’s why the required space is slightly greater than the raw data size. The advantage of this command is that it keeps you from having to manage Byte Swapping (position of the most significant byte) when working cross-platform.

When you fill a BLOB, you can use the * character instead of the $PositionInBlob variable that we used.

When you use this parameter, 4D understands that it must store the variable at the end of the BLOB and increase its size as a result.

Now let's imagine that you have a number of parameters in your database that must be taken into account for each user (or each site where your application is installed):

  • the startup screen
  • the background color
  • the font and size of characters
  • and so on.
    They are really just user preferences.

To keep them, there are several solutions (create a table, a text file, an XML file, etc.).

In our case, we will keep these preferences in a BLOB, which is stored in a file on your disk.

The read and write commands for BLOBs are BLOB TO DOCUMENT and DOCUMENT TO BLOB.

To save space and/or transfer time, you may also want to consider compressing your BLOBs.

Remember that 4D only compresses BLOBs if their size is greater than 255 bytes.

When decompressing BLOBs, remember to check to see whether the BLOB is actually compressed. Otherwise, trying to decompress it will generate an error.

 
 

 
PROPERTIES 

Product: 4D
Theme: BLOBs

 
ARTICLE USAGE

Self-training ( 4D v13)
Self-training ( 4D v14)